Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ModelHandlers<TDocument, TInstance>

Provides a number of methods which are used to handle events that occur within the Iridium workflow - such as what happens when a document is received from the database, or how to handle the creation of new documents and saving of instances.

Mostly this is for cache support, wrapping and hook triggering.

internal

Type parameters

  • TDocument: object

  • TInstance

Hierarchy

  • ModelHandlers

Index

Constructors

constructor

Properties

model

model: Model<TDocument, TInstance>

Methods

creatingDocuments

  • Called by methods which will create a new document in the DB. Responsible for dispatching hooks, performing data validation and processing any necessary transforms.

    Parameters

    • documents: InsertionDocument<TDocument>[]

      The list of documents which will be inserted. For single inserts an array of one document may be provided.

    • Default value transformOptions: TransformOptions = {}

      Options which can be used to control how the transforms are applied when representing the document

    Returns Promise<any[]>

documentReceived

  • documentReceived<TResult>(conditions: any, result: TDocument, wrapper: function, options?: QueryOptions): Promise<TResult>
  • Called by methods which retrieve a document from the database. This method is responsible for performing any necessary transforms on the data, setting the cache entry and wrapping the returned object in the relevant wrapper type (usually an Instance). This method will also trigger the onRetrieved and onReady hooks on the model at the correct times.

    Type parameters

    • TResult

    Parameters

    • conditions: any

      The conditions which were used to request the document from the DB

    • result: TDocument

      The resulting document which was returned by the DB

    • wrapper: function

      The method which will be used to wrap the document, usually an Instance

        • (document: TDocument, isNew?: undefined | true | false, isPartial?: undefined | true | false): TResult
        • Parameters

          • document: TDocument
          • Optional isNew: undefined | true | false
          • Optional isPartial: undefined | true | false

          Returns TResult

    • Default value options: QueryOptions = {}

      Options which may be provided to override the behaviour of this method

    Returns Promise<TResult>

savingDocument

  • savingDocument(instance: TInstance, changes: any): Promise<TInstance>
  • Called by Instance methods before an Instance is saved to the databse. Will only be called if there are changes to be saved and will ensure that the onSaving hook is called if it is set.

    Parameters

    • instance: TInstance

      The instance which is being saved to the database

    • changes: any

      The list of changes that have been made to this instance since it was retrieved from the DB

    Returns Promise<TInstance>

Generated using TypeDoc