AbleObject abstract class.

Used in entities which support abilities, such as users and groups.

Type Parameters

  • T extends {
        abilities?: string[];
    }

Hierarchy

Constructors

  • Initialize an entity.

    Type Parameters

    • T extends {
          abilities?: string[];
      }

    Parameters

    • Rest ..._rest: any[]

    Returns AbleObject<T>

Properties

$allowlistData?: string[]

If this is defined, then it lists the only properties that will be accepted from incoming JSON. Any other properties will be ignored.

If you use an allowlist, you don't need to use protectedData, since you can simply leave those entries out of allowlistData.

$allowlistTags?: string[]

If this is defined, then it lists the only tags that will be accepted from incoming JSON. Any other tags will be ignored.

$clientEnabledMethods: string[]

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

$data: T

The data proxy object.

$dataHandler: Object

The data proxy handler.

$dataStore: T

The actual data store.

$isASleepingReference: boolean

Whether this instance is a sleeping reference.

$nymph: Nymph

The instance of Nymph to use for queries.

$privateData: string[]

Properties that will not be serialized into JSON with toJSON(). This can be considered a denylist, because these properties will not be set with incoming JSON.

Clients CAN still determine what is in these properties, unless they are also listed in searchRestrictedData.

$protectedData: string[]

Properties that can only be modified by server side code. They will still be visible on the frontend, unlike $privateData, but any changes to them that come from the frontend will be ignored.

In addition to what's listed here, all of the access control properties will be included when Tilmeld is being used. These are:

  • acUser
  • acGroup
  • acOther
  • acRead
  • acWrite
  • acFull
  • user
  • group

You should modify these through client enabled methods or the $save method instead, for safety.

$protectedTags: string[]

Tags that can only be added/removed by server side code. They will still be visible on the frontend, but any changes to them that come from the frontend will be ignored.

The actual sdata store.

$sleepingReference: null | EntityReference

The reference to use to wake.

$wakePromise: null | Promise<Entity<T>>

A promise that resolved when the entity's data is wake.

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.

ETYPE: string

A unique name for this type of entity used to separate its data from other types of entities in the database.

class: string

The lookup name for this entity.

This is used for reference arrays (and sleeping references) and client requests.

clientEnabledStaticMethods: string[]

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

nymph: Nymph

The instance of Nymph to use for queries.

pubSubEnabled: boolean

Whether this entity should publish changes to PubSub servers.

restEnabled: boolean

Whether this entity should be accessible on the frontend through the REST server.

If this is false, any request from the client that attempts to use this entity will fail.

searchRestrictedData: string[]

Properties that will not be searchable from the frontend. If the frontend includes any of these properties in any of their clauses, they will be filtered out before the search is executed.

Methods

  • Add one or more tags.

    Parameters

    • Rest ...tags: string[]

      List of tags.

    Returns void

  • 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 if this is a sleeping reference.

    Returns boolean

  • Check if this is a sleeping reference and throw an error if so.

    Returns void

  • 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

  • Delete the object from storage.

    Returns Promise<boolean>

    True on success, false on failure.

  • Perform a more strict comparison of this object to another.

    Parameters

    • object: any

      The object to compare.

    Returns boolean

    True or false.

  • Returns null | (null | string)[]

  • Returns null | string

  • Returns null | (null | string)[]

  • Returns null | string

  • Returns null | (null | string)[]

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

    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 any

    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.

  • Perform a less strict comparison of this object to another.

    Parameters

    • object: any

      The object to compare.

    Returns boolean

    True or false.

  • 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

  • Set up a sleeping reference.

    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.

  • Remove one or more tags.

    Parameters

    • Rest ...tags: string[]

      List of tags.

    Returns void

  • Save the object to storage.

    Returns Promise<boolean>

    True on success, false on failure.

  • Return a Nymph Entity Reference for this entity.

    If the entity hasn't been saved yet (and has no GUID), it will be returned instead.

    Returns AbleObject<T> | EntityReference

    A Nymph Entity Reference array as an unsaved entity.

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

    Parameters

    • skipAc: boolean

      True or false, whether to use it.

    Returns void

  • Wake from a sleeping reference.

    Returns Promise<Entity<T>>

  • Parameters

    • Optional level: number

    Returns Promise<Entity<T>>

  • Alter the options for a query for this entity.

    Type Parameters

    Parameters

    • options: T

      The current options.

    Returns T

    The altered options.

  • Create or retrieve a new entity instance.

    Note that this will always return an entity, even if the GUID is not found.

    Type Parameters

    Parameters

    • this: (new () => E)
        • new (): E
        • Returns E

    • Optional guid: string

      An optional GUID to retrieve.

    Returns Promise<E & EntityDataType<E>>

  • Create a new sleeping reference instance.

    Sleeping references won't retrieve their data from the database until they are readied with $wake() or a parent's $wakeAll().

    Type Parameters

    Parameters

    • this: (new () => E)
        • new (): E
        • Returns E

    • reference: EntityReference

      The Nymph Entity Reference to use to wake.

    Returns E & EntityDataType<E>

    The new instance.

  • 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 static method instantiates the entity, assigns all of the given data, then calls $getUniques and returns its output. This can have a performance impact if a lot of extra processing happens during any of these steps. You can override this method to calculate the unique strings faster, but you must return the same strings that would be returned by $getUniques.

    Parameters

    • __namedParameters: {
          cdate?: number;
          data: EntityData;
          guid?: string;
          mdate?: number;
          sdata?: SerializedEntityData;
          tags: string[];
      }

    Returns Promise<string[]>

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

Generated using TypeDoc