A user group data model.

Written by Hunter Perrin for SciActive.

Hunter Perrin [email protected]

Hierarchy (view full)

Constructors

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: GroupData

The data proxy object.

$dataHandler: Object

The data proxy handler.

$dataStore: GroupData

The actual data store.

$isASleepingReference: boolean

Whether this instance is a sleeping reference.

$nymph: Nymph

The instance of Nymph to use for queries.

$originalGroupname?: string

Used to save the current groupname for domain admin permissions.

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

$tags: never[] = []
$wakePromise: null | Promise<Entity<GroupData>>

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.

class: string = 'Group'

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.

ETYPE: string = 'tilmeld_group'

The instance of Tilmeld to use for queries.

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.

    • Optionalstrict: 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

  • Check that an email is unique.

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Check that a groupname is valid.

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • 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

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

  • Returns null | (null | string)[]

  • Returns any

  • 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

    • OptionalincludeSData: boolean

      Whether to include the serialized data as well.

    • OptionalreferenceOnlyExisting: boolean

      Whether to only turn existing entities into references.

    Returns any

    The entity's data object.

  • Get a GUID for the entity.

    If the entity has already been saved, this will just return the GUID.

    If the entity has not yet been saved, this will return a new GUID that gets held by the entity. The guid property will remain null, but this method will then always return the same GUID. When the entity is eventually saved into the database, this GUID will be used.

    Returns string

  • Get the number of parents the group has.

    If the group is a top level group, this will return 0. If it is a child of a top level group, this will return 1. If it is a grandchild of a top level group, this will return 2, and so on.

    Levels will max out at 1024 to avoid recursive loops.

    Returns Promise<number>

    The level of the group.

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

  • Gets an array of users in the group.

    Parameters

    • descendants: boolean = false

      Include users in all descendant groups too.

    • Optionallimit: number

      The limit for the query.

    • Optionaloffset: number

      The offset for the query.

    Returns Promise<(User & UserData)[]>

    An array of users.

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

    • Optionalstrict: 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).

    • allowConflict: boolean = false

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

    • allowConflict: boolean = false

      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 or the client.

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

    If source is set to "server", the data is coming from the DB or the cache. If not, assume the data is coming from the client and can't be trusted.

    Parameters

    • data: EntityData

      The data object.

    • Optionalsdata: SerializedEntityData

      The serialized data object.

    • Optionalsource: "server"

      If this is set to "server", the data is coming from the DB.

    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

  • Return a Nymph Entity Reference for this entity.

    If the entity hasn't been saved yet (and has no GUID), it will use the guaranteed GUID from $getGuaranteedGUID, unless existingOnly is true, then it will return the entity.

    Parameters

    • OptionalexistingOnly: boolean

      Whether to only turn existing entities into references.

    Returns Group | EntityReference

    A Nymph Entity Reference array.

  • Update the data protection arrays for a user.

    Parameters

    • OptionalgivenUser: User & UserData

      User to update protection for. If undefined, will use the currently logged in user.

    Returns void

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

    Parameters

    • skipAc: boolean

      True or false, whether to use it.

    Returns void

  • 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

    • Optionalguid: 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 a string for full text search for one of an entity's properties.

    The result will be tokenized and stored as the full text search index for use with "search" clauses.

    Return null to not include any tokens in the full text search storage.

    You shouldn't use any other entity data to transform the text, as it won't always be available. This function is meant for things like stripping HTML tags.

    Parameters

    • _name: string
    • value: any

    Returns null | string

    By default, returns the value if it is a string.

  • Get all the groups that can be assigned as primary groups.

    Parameters

    • Optionaloptions: Options

      The options for an optional search query.

    • Optionalselectors: Selector[]

      The selectors for an optional search query.

    Returns Promise<(Group & GroupData)[]>

    An array of the assignable primary groups.

  • Get all the groups that can be assigned as secondary groups.

    Parameters

    • Optionaloptions: Options

      The options for an optional search query.

    • Optionalselectors: Selector[]

      The selectors for an optional search query.

    Returns Promise<(Group & GroupData)[]>

    An array of the assignable secondary groups.

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