Options
All
  • Public
  • Public/Protected
  • All
Menu

An embedded collection delta contains delta source objects that can be compared against other objects inside a base embedded collection, and generate new embedded Documents by combining them.

Hierarchy

Index

Constructors

  • Parameters

    • name: string

      The name of this collection in the parent Document.

    • parent: DataModel

      The parent DataModel instance to which this collection belongs.

    • sourceArray: any[]

      The source data array for the collection in the parent Document data.

    Returns EmbeddedCollectionDelta

Accessors

  • A convenience getter to return the corresponding base collection.

    Returns EmbeddedCollection

  • A convenience getter to return the corresponding synthetic collection.

    Returns EmbeddedCollection

  • get contents(): any[]
  • Return an Array of all the entry values in the Collection

    Returns any[]

Methods

  • createDocument(data: any, context?: {}): Document
  • initialize(__namedParameters?: { strict: boolean; full: boolean }): void
  • override

    Parameters

    • __namedParameters: { strict: boolean; full: boolean } = {}
      • strict: boolean
      • full: boolean

    Returns void

  • _initializeDocument(data: any, __namedParameters: Object): void
  • _createOrUpdate(data: any, options: any): void
  • manages(key: string): boolean
  • Determine whether a given ID is managed directly by this collection delta or inherited from the base collection.

    Parameters

    • key: string

      The Document ID.

    Returns boolean

  • isTombstone(key: string): boolean
  • Determine whether a given ID exists as a tombstone Document in the collection delta.

    Parameters

    • key: string

      The Document ID.

    Returns boolean

  • restoreDocument(id: string): Promise<Document>
  • Restore a Document so that it is no longer managed by the collection delta and instead inherits from the base Document.

    Parameters

    • id: string

      The Document ID.

    Returns Promise<Document>

    The restored Document.

  • restoreDocuments(ids: string[]): Promise<Document[]>
  • Restore the given Documents so that they are no longer managed by the collection delta and instead inherit directly from their counterparts in the base Actor.

    Parameters

    • ids: string[]

      The IDs of the Documents to restore.

    Returns Promise<Document[]>

    An array of updated Document instances.

  • set(key: any, value: any, options?: {}): void
  • Add an item to the collection.

    Parameters

    • key: any

      The embedded Document ID.

    • value: any

      The embedded Document instance.

    • options: {} = {}

      Additional options to the set operation.

      Returns void

    • _set(key: any, value: any, __namedParameters?: { restoreDelta: boolean }): void
    • override

      Parameters

      • key: any
      • value: any
      • __namedParameters: { restoreDelta: boolean } = {}
        • restoreDelta: boolean

      Returns void

    • delete(key: any, options?: {}): void
    • Parameters

      • key: any

        The embedded Document ID.

      • options: {} = {}

        Additional options to the delete operation.

        Returns void

      • _delete(key: any, __namedParameters?: { restoreDelta: boolean }): void
      • override

        Parameters

        • key: any
        • __namedParameters: { restoreDelta: boolean } = {}
          • restoreDelta: boolean

        Returns void

      • get(id: string, [options]?: { strict: boolean; invalid: boolean }): Document
      • Get an element from the EmbeddedCollection by its ID.

        throws

        If strict is true and the Embedded Document cannot be found.

        Parameters

        • id: string

          The ID of the Embedded Document to retrieve.

        • [options]: { strict: boolean; invalid: boolean } = {}

          Additional options to configure retrieval.

          • strict: boolean
          • invalid: boolean

        Returns Document

      • update(changes: DataModel[], options?: any): void
      • Update an EmbeddedCollection using an array of provided document data.

        Parameters

        • changes: DataModel[]

          An array of provided Document data

        • options: any = {}

        Returns void

      • getInvalid(id: string, [options]?: { strict: boolean }): Document
      • Obtain a temporary Document instance for a document id which currently has invalid source data.

        throws

        If strict is true and the requested ID is not in the set of invalid IDs for this collection.

        Parameters

        • id: string

          A document ID with invalid source data.

        • [options]: { strict: boolean } = {}

          Additional options to configure retrieval.

          • strict: boolean

        Returns Document

        An in-memory instance for the invalid Document

      • toObject(source?: boolean): any[]
      • Convert the EmbeddedCollection to an array of simple objects.

        Parameters

        • source: boolean = true

        Returns any[]

        The extracted array of primitive objects

      • find(condition: ((arg0: any, arg1: number, arg2: Collection) => boolean)): any
      • Find an entry in the Map using a functional condition.

        see

        {Array#find}

        example

        Create a new Collection and reference its contents

        let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
        c.get("a") === c.find(entry => entry === "A"); // true

        Parameters

        • condition: ((arg0: any, arg1: number, arg2: Collection) => boolean)

          The functional condition to test. Positional arguments are the value, the index of iteration, and the collection being searched.

            • (arg0: any, arg1: number, arg2: Collection): boolean
            • Parameters

              Returns boolean

        Returns any

        The value, if found, otherwise undefined

      • filter(condition: ((arg0: any, arg1: number, arg2: Collection) => boolean)): any[]
      • Filter the Collection, returning an Array of entries which match a functional condition.

        see

        {Array#filter}

        example

        Filter the Collection for specific entries

        let c = new Collection([["a", "AA"], ["b", "AB"], ["c", "CC"]]);
        let hasA = c.filters(entry => entry.slice(0) === "A");

        Parameters

        • condition: ((arg0: any, arg1: number, arg2: Collection) => boolean)

          The functional condition to test. Positional arguments are the value, the index of iteration, and the collection being filtered.

            • (arg0: any, arg1: number, arg2: Collection): boolean
            • Parameters

              Returns boolean

        Returns any[]

        An Array of matched values

      • forEach(fn: ((arg0: any) => void)): void
      • Apply a function to each element of the collection

        see

        Array#forEach

        example

        Apply a function to each value in the collection

        let c = new Collection([["a", {active: false}], ["b", {active: false}], ["c", {active: false}]]);
        c.forEach(e => e.active = true);

        Parameters

        • fn: ((arg0: any) => void)

          A function to apply to each element

            • (arg0: any): void
            • Parameters

              • arg0: any

              Returns void

        Returns void

      • getName(name: string, [options]?: { strict: boolean }): any
      • Get an entry from the Collection by name. Use of this method assumes that the objects stored in the collection have a "name" attribute.

        example

        Get an element from the Collection by name (if applicable)

        let c = new Collection([["a", "Alfred"], ["b", "Bob"], ["c", "Cynthia"]]);
        c.getName("Alfred"); // "Alfred"
        c.getName("D"); // undefined
        c.getName("D", {strict: true}); // throws Error

        Parameters

        • name: string

          The name of the entry to retrieve

        • [options]: { strict: boolean } = {}

          Additional options that affect how entries are retrieved

          • strict: boolean

        Returns any

        The retrieved entry value, if one was found, otherwise undefined

      • map(transformer: ((arg0: any, arg1: number, arg2: Collection) => any)): any[]
      • Transform each element of the Collection into a new form, returning an Array of transformed values

        Parameters

        • transformer: ((arg0: any, arg1: number, arg2: Collection) => any)

          A transformation function applied to each entry value. Positional arguments are the value, the index of iteration, and the collection being mapped.

            • Parameters

              Returns any

        Returns any[]

        An Array of transformed values

      • reduce(reducer: ((arg0: any, arg1: any, arg2: number, arg3: Collection) => any), initial: any): any
      • Reduce the Collection by applying an evaluator function and accumulating entries

        see

        {Array#reduce}

        example

        Reduce a collection to an array of transformed values

        let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
        let letters = c.reduce((s, l) => {
        return s + l;
        }, ""); // "ABC"

        Parameters

        • reducer: ((arg0: any, arg1: any, arg2: number, arg3: Collection) => any)

          A reducer function applied to each entry value. Positional arguments are the accumulator, the value, the index of iteration, and the collection being reduced.

            • (arg0: any, arg1: any, arg2: number, arg3: Collection): any
            • Parameters

              Returns any

        • initial: any

          An initial value which accumulates with each iteration

        Returns any

        The accumulated result

      • some(condition: ((arg0: any, arg1: number, arg2: Collection) => boolean)): boolean
      • Test whether a condition is met by some entry in the Collection.

        see

        {Array#some}

        Parameters

        • condition: ((arg0: any, arg1: number, arg2: Collection) => boolean)

          The functional condition to test. Positional arguments are the value, the index of iteration, and the collection being tested.

            • (arg0: any, arg1: number, arg2: Collection): boolean
            • Parameters

              Returns boolean

        Returns boolean

        Was the test condition passed by at least one entry?

      • toJSON(): any[]
      • Convert the Collection to a primitive array of its contents.

        Returns any[]

        An array of contained values

      • [iterator](): IterableIterator<any>
      • When iterating over a Collection, we should iterate over its values instead of over its entries

        Returns IterableIterator<any>

      • _handleInvalidDocument(id: string, err: Error, [options]?: { strict: boolean }): void
      • Log warnings or errors when a Document is found to be invalid.

        Parameters

        • id: string

          The invalid Document's ID.

        • err: Error

          The validation error.

        • [options]: { strict: boolean } = {}

          Options to configure invalid Document handling.

          • strict: boolean

        Returns void

      Properties

      _initialized: boolean

      Has this embedded collection been initialized as a one-time workflow?

      documentClass: typeof Document

      The Document implementation used to construct instances within this collection.

      name: string

      The name of this collection in the parent Document.

      model: DataModel

      The parent DataModel to which this EmbeddedCollection instance belongs.

      invalidDocumentIds: Set<string> = ...

      Record the set of document ids where the Document was not initialized because of invalid source data

      #managedIds: Set<string> = ...

      Maintain a list of IDs that are managed by this collection delta to distinguish from those IDs that are inherited from the base collection.

      #tombstones: Set<string> = ...

      Maintain a list of IDs that are tombstone Documents.