Initialize an entity.
Rest
..._rest: any[]Protected
Optional
$allowlistIf 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.
Protected
Optional
$allowlistIf this is defined, then it lists the only tags that will be accepted from incoming JSON. Any other tags will be ignored.
Protected
$clientThe names of methods allowed to be called by the frontend with serverCall.
Protected
$dataThe data proxy object.
Protected
$dataThe data proxy handler.
Protected
$dataThe actual data store.
Protected
$isASleepingWhether this instance is a sleeping reference.
The instance of Nymph to use for queries.
Private
$originalThe AC properties' values when the entity was loaded.
Protected
$privateProperties 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.
Protected
$protectedProperties 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:
You should modify these through client enabled methods or the $save method instead, for safety.
Protected
$protectedTags 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.
Protected
$sdataThe actual sdata store.
Private
$skipWhether to use "skipAc" when accessing entity references.
Protected
$sleepingThe reference to use to wake.
Protected
$wakeA promise that resolved when the entity's data is wake.
The creation date of the entity as a Unix timestamp in milliseconds.
The entity's Globally Unique ID.
This is a 12 byte number represented as a lower case HEX string (24 characters).
The modified date of the entity as a Unix timestamp in milliseconds.
Array of the entity's tags.
Static
ETYPEA unique name for this type of entity used to separate its data from other types of entities in the database.
Static
classThe lookup name for this entity.
This is used for reference arrays (and sleeping references) and client requests.
Static
clientThe names of static methods allowed to be called by the frontend with serverCallStatic.
Static
nymphThe instance of Nymph to use for queries.
Static
pubWhether this entity should publish changes to PubSub servers.
Static
restWhether 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.
Static
searchProperties 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.
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.
The array to search.
Whether to use stronger comparison.
The index if the object is in the array, -1 if it isn't.
Protected
$checkGet the current values of the AC properties.
An object of AC properties.
Get the original values of the AC properties.
An object of AC properties.
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().
The entity's serialized data object.
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.
Resolves to an array of entity's unique constraint strings.
Check whether this object is in an array.
If strict
is false, is()
is used to compare. If strict
is true,
equals()
is used.
The array to search.
Whether to use stronger comparison.
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:
The input data. Please note, this will be modified (destroyed).
Allow to accept data that is older than the current data.
Accept JSON patch from the client.
This function uses the security protection lists:
The patch data. Please note, this will be modified (destroyed).
Allow to accept data that is older than the current data.
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.
The data object.
Optional
sdata: SerializedEntityDataThe serialized data object.
Protected
$referenceSet up a sleeping reference.
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.
False if the data has not been saved, 0 if it can't be refreshed, true on success.
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.
A Nymph Entity Reference array as an unsaved entity.
Static
Optional
alterStatic
factoryCreate or retrieve a new entity instance.
Note that this will always return an entity, even if the GUID is not found.
Static
factoryCreate 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()
.
The Nymph Entity Reference to use to wake.
The new instance.
Static
factoryCreate a new entity instance.
Static
getGet 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
.
Optional
cdate?: numberOptional
guid?: stringOptional
mdate?: numberOptional
sdata?: SerializedEntityDataResolves to an array of entity's unique constraint strings.
Database abstraction object.
Provides a way to access, manipulate, and store data in Nymph.
The GUID is not set until the entity is saved. GUIDs must be unique forever, even after deletion. It's the job of the Nymph DB driver to make sure no two entities ever have the same GUID. This is generally done by using a large randomly generated ID.
Each entity class has an etype that determines which table(s) in the database it belongs to. If two entity classes have the same etype, their data will be stored in the same table(s). This isn't a good idea, however, because references to an entity store a class name, not an etype.
Tags are used to classify entities. Where an etype is used to separate data by tables, tags can be used to separate entities within a table. You can define specific tags to be protected, meaning they cannot be added/removed from the client. It can be useful to allow user defined tags, such as for blog posts.
Simply calling $delete() will not unset the entity. It will still take up memory. Likewise, simply calling unset will not delete the entity from the DB.
Some notes about $equals() and $is(), the replacements for "==":
The == operator will likely not give you the result you want, since two instances of the same entity will fail that check, even though they represent the same data in the database.
$equals() performs a more strict comparison of the entity to another. Use $equals() instead of the == operator when you want to check both the entities they represent, and the data inside them. In order to return true for $equals(), the entity and object must meet the following criteria:
$is() performs a less strict comparison of the entity to another. Use $is() instead of the == operator when the entity's data may have been changed, but you only care if they represent the same entity. In order to return true, the entity and object must meet the following criteria:
Some notes about saving entities in other entity's properties:
Entities use references in the DB to store an entity in their properties. The reference is stored as an array with the values:
Since the referenced entity's class name (meaning the
class
static property, not the name of the class itself) is stored in the reference on the parent entity, if you change the class name in an update, you need to reassign all referenced entities of that class and resave.When an entity is loaded, it does not request its referenced entities from Nymph. Instead, it creates instances without data called sleeping references. When you first access an entity's data, if it is a sleeping reference, it will fill its data from the DB. You can call clearCache() to turn all the entities back into sleeping references.