Entity interface.

interface EntityInterface {
    $nymph: Nymph;
    cdate: null | number;
    guid: null | string;
    mdate: null | number;
    tags: string[];
    $addTag(...tags): void;
    $arraySearch(array, strict?): number;
    $clearCache(): void;
    $delete(): Promise<boolean>;
    $equals(object): boolean;
    $getClientEnabledMethods(): string[];
    $getCurrentAcValues(): ACProperties;
    $getData(includeSData?): EntityData;
    $getOriginalAcValues(): ACProperties;
    $getSData(): SerializedEntityData;
    $getTags(): string[];
    $getUniques(): Promise<string[]>;
    $getValidatable(): Object;
    $hasTag(...tags): boolean;
    $inArray(array, strict?): boolean;
    $is(object): boolean;
    $jsonAcceptData(input, allowConflict?): void;
    $jsonAcceptPatch(patch, allowConflict?): void;
    $putData(data, sdata?): void;
    $refresh(): Promise<boolean | 0>;
    $removeTag(...tags): void;
    $save(): Promise<boolean>;
    $toReference(): EntityInterface | EntityReference;
    $useSkipAc(useSkipAc): void;
}

Hierarchy (view full)

Implemented by

Properties

$nymph: Nymph

The instance of Nymph to use for queries.

cdate: null | number

The creation date of the entity as a Unix timestamp in milliseconds.

guid: null | string

The entity's Globally Unique ID.

This is a 12 byte number represented as a lower case HEX string (24 characters).

mdate: null | number

The modified date of the entity as a Unix timestamp in milliseconds.

tags: string[]

Array of the entity's tags.

Methods

  • Search the array for this object and return the corresponding index.

    If strict is false, is() is used to compare. If strict is true, equals() is used.

    Parameters

    • array: any[]

      The array to search.

    • Optional strict: boolean

      Whether to use stronger comparison.

    Returns number

    The index if the object is in the array, -1 if it isn't.

  • Replace any referenced entities in the data with sleeping references.

    Calling this function ensures that the next time a referenced entity is accessed, it will be retrieved from the DB (unless it is in Nymph's cache).

    Returns void

  • Get the client enabled methods.

    Returns string[]

    The names of methods allowed to be called by the frontend with serverCall.

  • Used to retrieve the data object.

    This should only be used by Nymph to save the data into storage.

    Parameters

    • Optional includeSData: boolean

      Whether to include the serialized data as well.

    Returns EntityData

    The entity's data object.

  • Used to retrieve the serialized data object.

    This should only be used by Nymph to save the data object into storage.

    This method is used by Nymph to avoid unserializing data that hasn't been requested yet.

    It should always be called after getData().

    Returns SerializedEntityData

    The entity's serialized data object.

  • Get the entity's tags.

    Using this instead of accessing the tags prop directly will wake sleeping references.

    Returns string[]

    The entity's tags.

  • Get an array of strings that must be unique across the current etype.

    When you try to save another entity with any of the same unique strings, Nymph will throw an error.

    The default implementation of this method returns an empty array, meaning there are no uniqueness constraints applied to its etype.

    Returns Promise<string[]>

    Resolves to an array of entity's unique constraint strings.

  • Get an object that holds the same data as the entity.

    This provides an object that can be validated.

    Returns Object

    A pure object representation of the entity.

  • Check that the entity has all of the given tags.

    Parameters

    • Rest ...tags: string[]

      List of tags.

    Returns boolean

    True or false.

  • Check whether this object is in an array.

    If strict is false, is() is used to compare. If strict is true, equals() is used.

    Parameters

    • array: any[]

      The array to search.

    • Optional strict: boolean

      Whether to use stronger comparison.

    Returns boolean

    True if the object is in the array, false if it isn't.

  • Accept JSON data from the client.

    This function uses the security protection lists:

    • $protectedTags
    • $protectedData
    • $allowlistTags
    • $allowlistData

    Parameters

    • input: EntityJson

      The input data. Please note, this will be modified (destroyed).

    • Optional allowConflict: boolean

      Allow to accept data that is older than the current data.

    Returns void

  • Accept JSON patch from the client.

    This function uses the security protection lists:

    • $protectedTags
    • $protectedData
    • $allowlistTags
    • $allowlistData

    Parameters

    • patch: EntityPatch

      The patch data. Please note, this will be modified (destroyed).

    • Optional allowConflict: boolean

      Allow to accept data that is older than the current data.

    Returns void

  • Used to set the data.

    This should only be used by Nymph to push the data from storage.

    sdata is used by Nymph to avoid unserializing data that hasn't been requested yet.

    Parameters

    Returns void

  • Refresh the object from storage. (Bypasses Nymph's cache.)

    If the object has been deleted from storage, the database cannot be reached, or a database error occurs, refresh() will return 0.

    Returns Promise<boolean | 0>

    False if the data has not been saved, 0 if it can't be refreshed, true on success.

  • Set whether to use "skipAc" when accessing entity references.

    Parameters

    • useSkipAc: boolean

      True or false, whether to use it.

    Returns void