Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EntityManager

Hierarchy

Indexable

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

Index

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 model.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 model.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: {} = {}

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
  • set token(value: null | string): void
  • The authentication token if the user is logged in currently

    Returns null | string

  • The authentication token if the user is logged in currently

    Parameters

    • value: null | string

    Returns void

Methods

  • Parameters

    Returns void

  • _createObjectFactory(types: {}): void
  • Parameters

    Returns void

    • @private
  • _locklessSave<T>(entity: T, options: { depth?: number | boolean; refresh?: boolean }, msgFactory: MessageFactory): Promise<T>
  • Save the object state without locking

    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 Promise<null | model.User>

  • _logout(): void
  • Returns void

  • _optimisticSave<E>(entity: E, cb: (entity: E, abort: () => void) => any): Promise<E>
  • 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>

  • _save<T>(entity: T, options: { depth?: number | boolean; refresh?: boolean }, msgFactory: MessageFactory): Promise<T>
  • Save and lock the object state

    Type parameters

    Parameters

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

    Returns Promise<T>

  • _updateBloomFilter(bloomFilter: JsonMap): void
  • Parameters

    Returns void

  • Parameters

    Returns Entity

  • Parameters

    • obj: JsonMap
    • updateMe: boolean = false

    Returns model.User

  • Parameters

    Returns Promise<null | model.User>

  • addToBlackList(objectId: null | string): void
  • Adds the given object id to the cacheBlackList if needed.

    Parameters

    • objectId: null | string

      The id to add.

    Returns void

  • addToWhiteList(objectId: string): void
  • Adds the given object id to the cacheWhiteList if needed.

    Parameters

    • objectId: string

      The id to add.

    Returns void

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

    Parameters

    • entity: Entity

      The entity to attach

    Returns void

  • changeUsername(username: string, newUsername: string, password: string): Promise<Response>
  • Parameters

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

    Returns Promise<Response>

  • checkDeviceRegistration(): Promise<boolean>
  • Returns Promise<boolean>

  • clear(): void
  • 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 void

  • close(): 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 void

  • connected(useSharedTokenStorage?: boolean): void
  • Connects this entityManager, used for synchronous and asynchronous initialization

    Parameters

    • Optional useSharedTokenStorage: boolean

      Indicates if the shared credentials should be used

    Returns void

  • contains(entity: Entity): boolean
  • Check if the instance is a managed entity instance belonging to the current persistence context

    Parameters

    • entity: Entity

      entity instance

    Returns boolean

    boolean indicating if entity is in persistence context

  • containsById(entity: Entity): boolean
  • Check if an object with the id from the given entity is already attached

    Parameters

    • entity: Entity

      entity instance

    Returns boolean

    boolean indicating if entity with same id is attached

  • Creates an instance of {@link Builder} for query creation and execution

    The query results are instances of the resultClass argument.

    Type parameters

    Parameters

    • resultClass: Class<T>

      the type of the query result

    Returns Builder<T>

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

  • createURL(relativePath: string, authorize?: boolean): Promise<string>
  • Creates a absolute url for the given relative one

    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>

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

  • delete<T>(entity: T, options?: { depth?: number | boolean; force?: boolean }): Promise<T>
  • Delete the entity instance.

    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.

    Parameters

    • entity: Entity

      The entity instance to detach.

    Returns Promise<Entity>

  • ensureBloomFilterFreshness(): void
  • Checks the freshness of the bloom filter and does a reload if necessary

    Returns void

  • ensureCacheHeader(id: null | string, message: Message, refresh?: boolean): void
  • 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

  • flush(): Promise<any>
  • Synchronize the persistence context to the underlying database.

    Returns Promise<any>

  • getReference<T>(entityClass: string | Class<T>, key?: string): T
  • 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.

    Type parameters

    Parameters

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

    Returns T

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

    Parameters

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

    Returns Entity[]

  • getSubEntitiesByPath(entity: Entity, path: string[]): Entity[]
  • Returns all referenced one level sub entities for the given path

    Parameters

    Returns Entity[]

  • insert(entity: Entity, options?: { depth?: number | boolean; refresh?: boolean }): Promise<Entity>
  • Parameters

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

    Returns Promise<Entity>

  • isCachingEnabled(): this is { bloomFilter: BloomFilter; cacheBlackList: Set<string>; cacheWhiteList: Set<string> }
  • Whether caching is enabled

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

  • load<T>(entityClass: string | Class<T>, oid?: string, options?: { local?: boolean; refresh?: boolean; resolved?: Entity[] }): Promise<null | T>
  • Search for an entity of the specified oid

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

    Type parameters

    Parameters

    • entityClass: string | Class<T>

      entity class

    • Optional oid: string

      Object ID

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

    Returns Promise<null | T>

    the loaded entity or null

  • login(username: string, password: string, loginOption: boolean | LoginOption): Promise<null | model.User>
  • Parameters

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

    Returns Promise<null | model.User>

  • loginWithOAuth(provider: string, options: OAuthOptions): any
  • Parameters

    Returns any

  • logout(): Promise<void>
  • Returns Promise<void>

  • mustRevalidate(id: string): boolean
  • Checks for a given id, if revalidation is required, the resource is stale or caching was disabled

    Parameters

    • id: string

      The object id to check

    Returns boolean

    Indicates if the resource must be revalidated

  • newPassword(username: string, password: string, newPassword: string): Promise<model.User>
  • Parameters

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

    Returns Promise<model.User>

  • newPasswordWithToken(token: string, newPassword: string, loginOption?: boolean | LoginOption): Promise<null | model.User>
  • Parameters

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

    Returns Promise<null | model.User>

  • optimisticSave<E>(entity: E, cb: (entity: E, abort: () => void) => any): Promise<E>
  • 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.

    Parameters

    • entity: Entity

      entity instance

    Returns void

  • Parameters

    Returns Promise<Response>

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

    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>

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

  • refresh<T>(entity: T, options: { depth?: number | boolean }): Promise<null | T>
  • Refresh the state of the instance from the database, overwriting changes made to the entity, if any.

    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>

  • Parameters

    Returns Promise<null | model.User>

  • registerDevice(deviceType: string, subscription: PushSubscription | { token: string }, device: null | Device): Promise<Device>
  • Parameters

    • deviceType: string

      The OS of the device (IOS/Android)

    • subscription: PushSubscription | { token: string }

      WebPush subscription

    • device: null | Device

    Returns Promise<Device>

  • removeReference(entity: Entity): void
  • Parameters

    Returns void

  • Parameters

    Returns Promise<null | model.User>

  • Requests a perpetual token for the given user

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

    Parameters

    Returns Promise<JsonMap>

  • resetPassword(username: string): Promise<Response>
  • Parameters

    • username: string

    Returns Promise<Response>

  • resolveDepth<T>(entity: T, options?: { depth?: number | boolean; local?: boolean; refresh?: boolean; resolved?: Entity[] }): Promise<T>
  • Resolve the depth by loading the referenced objects of the given entity

    Type parameters

    Parameters

    • entity: T

      entity instance

    • Optional options: { depth?: number | boolean; local?: boolean; refresh?: boolean; resolved?: Entity[] }
      • 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>

  • save<E>(entity: E, options?: { depth?: number | boolean; force?: boolean; refresh?: boolean }, withoutLock?: boolean): Promise<E>
  • 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>

  • update(entity: Entity, options?: { depth?: number | boolean; force?: boolean; refresh?: boolean }): Promise<Entity>
  • 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.

    Parameters

    Returns ValidationResult

    result

  • withLock<T>(callback: () => Promise<T>, critical?: boolean): Promise<T>
  • Try to aquire an exclusive lock and executes the given callback.

    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>

    • critical: boolean = false

    Returns Promise<T>

    A promise

Generated using TypeDoc