Entity interface.

interface EntityInterface {
    $nymph: Nymph;
    cdate: null | number;
    guid: null | string;
    mdate: null | number;
    tags: string[];
    $addTag(...tags): void;
    $arraySearch(array, strict?): number;
    $delete(): Promise<boolean>;
    $equals(object): boolean;
    $getPatch(): EntityPatch;
    $hasTag(...tags): boolean;
    $inArray(array, strict?): boolean;
    $init(entityJson): EntityInterface;
    $is(object): boolean;
    $patch(): Promise<boolean>;
    $refresh(): Promise<boolean | 0>;
    $removeTag(...tags): void;
    $save(): Promise<boolean>;
    $serverCall(method, params, stateless): Promise<any>;
    $toReference(): EntityReference | EntityInterface;
    $wake(): Promise<EntityInterface>;
    $wakeAll(level?): Promise<EntityInterface>;
}

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.

  • 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.

  • 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.

  • Call an instance method on the server version of this entity.

    The entity's data will be sent up to the server as well, so the server's state can match the client's state. It won't be propagated into the DB, though.

    Parameters

    • method: string

      The name of the method.

    • params: Iterable<any>

      The parameters to call the method with.

    • stateless: boolean

      Whether the server should return, and the client update, the data in the entity after the method has run.

    Returns Promise<any>

    The value that the method on the server returned.

  • Ready this entity's data, and the data of entity's within this one's.

    Parameters

    • Optional level: number

      The number of levels deep to wake. If undefined, it will keep going until there are no more entities. (Careful of infinite loops.)

    Returns Promise<EntityInterface>

    The entity.