Class EntityManager

This base class provides an lock interface to execute exclusive operations

Hierarchy

Indexable

[Class: string]: EntityFactory<any> | ManagedFactory<any> | any

Constructors

Properties

An Device factory for user objects. The Device factory can be called to create new instances of devices or can be used to register, push to and check registration status of devices.

File: FileFactory = ...

A File factory for file objects. The file factory can be called to create new instances for files. The created instances implements the File interface

GeoPoint: typeof GeoPoint = GeoPoint

Constructor for a new GeoPoint

List: ArrayConstructor = Array

Constructor for a new List collection

Map: MapConstructor = Map

Constructor for a new Map collection

An Role factory for role objects. The Role factory can be called to create new instances of roles, later on users can be attached to roles to manage the access permissions through this role The created instances implements the Role interface

Set: SetConstructor = Set

Constructor for a new Set collection

An User factory for user objects. The User factory can be called to create new instances of users or can be used to register/login/logout users. The created instances implements the User interface

bloomFilter: null | BloomFilter = null

The bloom filter which contains staleness information of cached objects

bloomFilterLock: Lockable = ...

Bloom filter refresh Promise

bloomFilterRefresh: number = 60

Bloom filter refresh interval in seconds.

cacheBlackList: null | Set<string> = null

Set of object ids that were updated but are not yet included in the bloom filter. This set essentially implements revalidation by side effect which does not work in Chrome.

cacheWhiteList: null | Set<string> = null

Set of object ids that were revalidated after the Bloom filter was loaded.

code: Code
connectData: null | ConnectData = null

the shared connection data if this EntityManager shares the credentials with the EntityManagerFactory

connection: null | Connector = null

The connector used for requests

deviceMe: null | Device = null

The current registered device object

entities: {
    [id: string]: Entity;
} = {}

All managed and cached entity instances

Type declaration

entityManagerFactory: EntityManagerFactory
log: Logger = ...

Log messages can created by calling log directly as function, with a specific log level or with the helper methods, which a members of the log method.

Logs will be filtered by the client logger and the before they persisted. The default log level is 'info' therefore all log messages below the given message aren't persisted.

Examples:

// default log level ist info
db.log('test message %s', 'my string');
// info: test message my string

// pass a explicit log level as the first argument, one of ('trace', 'debug', 'info', 'warn', 'error')
db.log('warn', 'test message %d', 123);
// warn: test message 123

// debug log level will not be persisted by default, since the default logging level is info
db.log('debug', 'test message %j', {number: 123}, {});
// debug: test message {"number":123}
// data = {}

// One additional json object can be provided, which will be persisted together with the log entry
db.log('info', 'test message %s, %s', 'first', 'second', {number: 123});
// info: test message first, second
// data = {number: 123}

//use the log level helper
db.log.info('test message', 'first', 'second', {number: 123});
// info: test message first second
// data = {number: 123}

//change the default log level to trace, i.e. all log levels will be persisted, note that the log level can be
//additionally configured in the baqend
db.log.level = 'trace';

//trace will be persisted now
db.log.trace('test message', 'first', 'second', {number: 123});
// info: test message first second
// data = {number: 123}
me: null | model.User = null

The current logged in user object

metamodel: Metamodel
modules: Modules = ...
tokenStorage: TokenStorage = ...

Returns the tokenStorage which will be used to authorize all requests.

Accessors

  • get isCachingDisabled(): boolean
  • Whether caching is disabled

    Deprecated

    Returns boolean

  • get isDeviceRegistered(): boolean
  • Returns true if the device token is already registered, otherwise false.

    Returns boolean

  • get isOpen(): boolean
  • Determine whether the entity manager is open. true until the entity manager has been closed

    Returns boolean

  • get isReady(): boolean
  • Indicates if there is currently no exclusive operation executed true If no exclusive lock is hold

    Returns boolean

  • get token(): null | string
  • The authentication token if the user is logged in currently

    Returns null | string

  • set token(value: null | string): void
  • The authentication token if the user is logged in currently

    Parameters

    • value: null | string

    Returns void

Methods

  • Parameters

    Returns void

  • Private

    Returns

    Parameters

    Returns void

  • Private

    Save the object state without locking

    Returns

    Type Parameters

    Parameters

    • entity: T
    • options: {
          depth?: number | boolean;
          refresh?: boolean;
      }
      • Optional depth?: number | boolean
      • Optional refresh?: boolean
    • msgFactory: MessageFactory

    Returns Promise<T>

  • Returns void

  • Private

    Returns

    Type Parameters

    Parameters

    • entity: E
    • cb: ((entity: E, abort: (() => void)) => any)

      pre-safe callback

        • (entity: E, abort: (() => void)): any
        • Parameters

          • entity: E
          • abort: (() => void)
              • (): void
              • Returns void

          Returns any

    Returns Promise<E>

  • Private

    Save and lock the object state

    Returns

    Type Parameters

    Parameters

    • entity: T
    • options: {
          depth?: number | boolean;
          refresh?: boolean;
      }
      • Optional depth?: number | boolean
      • Optional refresh?: boolean
    • msgFactory: MessageFactory

    Returns Promise<T>

  • Parameters

    Returns void

  • Parameters

    • obj: JsonMap
    • updateMe: boolean = false

    Returns model.User

  • Adds the given object id to the cacheBlackList if needed.

    Returns

    Parameters

    • objectId: null | string

      The id to add.

    Returns void

  • Adds the given object id to the cacheWhiteList if needed.

    Returns

    Parameters

    • objectId: string

      The id to add.

    Returns void

  • Attach the instance to this database context, if it is not already attached

    Returns

    Parameters

    • entity: Entity

      The entity to attach

    Returns void

  • Parameters

    • username: string
    • newUsername: string
    • password: string

    Returns Promise<Response>

  • Returns Promise<boolean>

  • Clear the persistence context, causing all managed entities to become detached

    Changes made to entities that have not been flushed to the database will not be persisted.

    Returns

    Returns void

  • Close an application-managed entity manager

    After the close method has been invoked, all methods on the EntityManager instance and any Query and TypedQuery objects obtained from it will throw the IllegalStateError except for transaction, and isOpen (which will return false). If this method is called when the entity manager is associated with an active transaction, the persistence context remains managed until the transaction completes.

    Returns

    Returns void

  • Connects this entityManager, used for synchronous and asynchronous initialization

    Parameters

    • Optional useSharedTokenStorage: boolean

      Indicates if the shared credentials should be used

    Returns void

  • Check if the instance is a managed entity instance belonging to the current persistence context

    Returns

    boolean indicating if entity is in persistence context

    Parameters

    • entity: Entity

      entity instance

    Returns boolean

  • Check if an object with the id from the given entity is already attached

    Returns

    boolean indicating if entity with same id is attached

    Parameters

    • entity: Entity

      entity instance

    Returns boolean

  • Creates an instance of Builder for query creation and execution

    The query results are instances of the resultClass argument.

    Returns

    A query builder to create one ore more queries for the specified class

    Type Parameters

    Parameters

    • resultClass: Class<T>

      the type of the query result

    Returns Builder<T>

  • Creates a absolute url for the given relative one

    Returns

    a absolute url which is optionally signed with a resource token which authenticates the currently logged in user

    Parameters

    • relativePath: string

      the relative url

    • Optional authorize: boolean

      indicates if authorization credentials should be generated and be attached to the url

    Returns Promise<string>

  • Delete the entity instance.

    Returns

    Type Parameters

    Parameters

    • entity: T
    • Optional options: {
          depth?: number | boolean;
          force?: boolean;
      }

      The delete options

      • Optional depth?: number | boolean
      • Optional force?: boolean

    Returns Promise<T>

  • Remove the given entity from the persistence context, causing a managed entity to become detached

    Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database. Entities which previously referenced the detached entity will continue to reference it.

    Returns

    Parameters

    • entity: Entity

      The entity instance to detach.

    Returns Promise<Entity>

  • Disables Multi-Factor Authentication for the currently logged in user.

    Throws

    • Thrown when the user is not logged in.

    Returns

    A promise that resolves when Multi-Factor Authentication is successfully disabled.

    Returns Promise<any>

  • Checks the freshness of the bloom filter and does a reload if necessary

    Returns void

  • Returns

    Parameters

    • id: null | string

      To check the bloom filter

    • message: Message

      To attach the headers

    • Optional refresh: boolean

      To force the reload headers

    Returns void

  • Finishes the MFA (Multi-Factor Authentication) initiation process.

    Returns

    A promise that resolves with the user object of the logged-in user.

    Parameters

    • code: number

      The verification code for MFA.

    Returns Promise<model.User>

  • Synchronize the persistence context to the underlying database.

    Returns

    Returns Promise<any>

  • Returns the current MFA status of the user

    Returns

    A promise that resolves to the MFA status of the user. Possible values are 'ENABLED' if MFA is enabled, 'DISABLED' if MFA is disabled, or 'PENDING' if MFA status is pending.

    Returns Promise<"ENABLED" | "DISABLED" | "PENDING">

  • Get an instance whose state may be lazily fetched

    If the requested instance does not exist in the database, the EntityNotFoundError is thrown when the instance state is first accessed. The application should not expect that the instance state will be available upon detachment, unless it was accessed by the application while the entity manager was open.

    Returns

    Type Parameters

    Parameters

    • entityClass: string | Class<T>
    • Optional key: string

    Returns T

  • Returns all referenced sub entities for the given depth and root entity

    Returns

    Parameters

    • entity: Entity
    • Optional depth: number | boolean
    • Optional resolved: Entity[] = []
    • Optional initialEntity: Entity

    Returns Entity[]

  • Returns all referenced one level sub entities for the given path

    Returns

    Parameters

    • entity: Entity
    • path: string[]

    Returns Entity[]

  • Starts the MFA initiate process - note you must be logged in, to start the mfa setup process

    Returns

    A promise that resolves to an object with the following properties:

    • qrCode: A Base64 representation of the QR code for MFA setup.
    • keyUri: The URI for the MFA secret key.

    Example

    const { qrCode, keyUri } = await db.initMFA();
    const code = await setupMFADevice(qrCode, keyUri);
    const user = await db.finishMFA(code);

    Returns Promise<MFAResponse>

  • Returns

    Parameters

    • entity: Entity
    • Optional options: {
          depth?: number | boolean;
          refresh?: boolean;
      }
      • Optional depth?: number | boolean
      • Optional refresh?: boolean

    Returns Promise<Entity>

  • Whether caching is enabled

    Returns this is {
        bloomFilter: BloomFilter;
        cacheBlackList: Set<string>;
        cacheWhiteList: Set<string>;
    }

  • Search for an entity of the specified oid

    If the entity instance is contained in the persistence context, it is returned from there.

    Returns

    the loaded entity or null

    Type Parameters

    Parameters

    • entityClass: string | Class<T>

      entity class

    • Optional oid: string

      Object ID

    • Optional options: {
          local?: boolean;
          refresh?: boolean;
          resolved?: Entity[];
      }

      The load options.

      • Optional local?: boolean
      • Optional refresh?: boolean
      • Optional resolved?: Entity[]

    Returns Promise<null | T>

  • Parameters

    • username: string
    • password: string
    • loginOption: boolean | LoginOption

    Returns Promise<null | model.User>

  • Parameters

    Returns any

  • Returns Promise<void>

  • Checks for a given id, if revalidation is required, the resource is stale or caching was disabled

    Returns

    Indicates if the resource must be revalidated

    Parameters

    • id: string

      The object id to check

    Returns boolean

  • Parameters

    • username: string
    • password: string
    • newPassword: string

    Returns Promise<model.User>

  • Parameters

    • token: string
    • newPassword: string
    • Optional loginOption: boolean | LoginOption

    Returns Promise<null | model.User>

  • Returns

    Type Parameters

    Parameters

    • entity: E
    • cb: ((entity: E, abort: (() => void)) => any)

      pre-safe callback

        • (entity: E, abort: (() => void)): any
        • Parameters

          • entity: E
          • abort: (() => void)
              • (): void
              • Returns void

          Returns any

    Returns Promise<E>

  • Make an instance managed and persistent.

    Returns

    Parameters

    • entity: Entity

      entity instance

    Returns void

  • Waits on the previously requested operation and calls the doneCallback if the operation is fulfilled

    Returns

    A promise which completes successfully, when the previously requested operation completes

    Parameters

    • Optional doneCallback: ((this: EntityManager) => any)

      The callback which will be invoked when the previously operations on this object is completed.

    • Optional failCallback: ((error: Error) => any)

      When the lock can't be released caused by a none recoverable error

        • (error: Error): any
        • Parameters

          • error: Error

          Returns any

    Returns Promise<EntityManager>

  • Refresh the state of the instance from the database, overwriting changes made to the entity, if any.

    Returns

    Type Parameters

    Parameters

    • entity: T

      entity instance

    • options: {
          depth?: number | boolean;
      }

      The refresh options

      • Optional depth?: number | boolean

    Returns Promise<null | T>

  • Returns Promise<null | BloomFilter>

  • Returns

    Parameters

    • deviceType: string

      The OS of the device (IOS/Android)

    • subscription: PushSubscription | {
          token: string;
      }

      WebPush subscription

    • device: null | Device

    Returns Promise<Device>

  • Parameters

    Returns void

  • Requests a perpetual token for the given user

    Only users with the admin role are allowed to request an API token.

    Returns

    Parameters

    Returns Promise<JsonMap>

  • Parameters

    • username: string

    Returns Promise<Response>

  • Resolve the depth by loading the referenced objects of the given entity

    Returns

    Type Parameters

    Parameters

    • entity: T

      entity instance

    • Optional options: {
          depth?: number | boolean;
          local?: boolean;
          refresh?: boolean;
          resolved?: Entity[];
      }

      The load options

      • Optional depth?: number | boolean
      • Optional local?: boolean
      • Optional refresh?: boolean
      • Optional resolved?: Entity[]

    Returns Promise<T>

  • Revoke all created tokens for the given user

    This method will revoke all previously issued tokens and the user must login again.

    Parameters

    Returns Promise<any>

  • Returns

    Type Parameters

    Parameters

    • entity: E
    • Optional options: {
          depth?: number | boolean;
          force?: boolean;
          refresh?: boolean;
      }

      The save options

      • Optional depth?: number | boolean
      • Optional force?: boolean
      • Optional refresh?: boolean
    • withoutLock: boolean = false

      Set true to save the entity without locking

    Returns Promise<E>

  • Parameters

    • message: Message
    • ignoreCredentialError: boolean = true

    Returns Promise<Response>

  • Submit a verification code after a login

    Returns

    The logged-in user object

    Parameters

    • code: number

      A 6 digit verification code

    • token: string

      An MFA token obtained during the login process

    Returns Promise<model.User>

  • Returns

    Parameters

    • entity: Entity
    • Optional options: {
          depth?: number | boolean;
          force?: boolean;
          refresh?: boolean;
      }
      • Optional depth?: number | boolean
      • Optional force?: boolean
      • Optional refresh?: boolean

    Returns Promise<Entity>

  • The given entity will be checked by the validation code of the entity type.

    Returns

    result

    Parameters

    Returns ValidationResult

  • Protected

    Try to aquire an exclusive lock and executes the given callback.

    Returns

    A promise

    Throws

    If the lock can't be aquired

    Type Parameters

    • T

    Parameters

    • callback: (() => Promise<T>)

      The exclusive operation to execute

        • (): Promise<T>
        • Returns Promise<T>

    • Optional critical: boolean = false

      Indicates if the operation is critical. If the operation is critical and the operation fails, then the lock will not be released

    Returns Promise<T>

Generated using TypeDoc