An extension of the Collection. Used for the specific task of containing embedded Document instances within a parent Document.

Hierarchy (view full)

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 EmbeddedCollection

Properties

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

_initialized: boolean = false

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

_source: any[]

The source data array from which the embedded collection is created

Accessors

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

    Returns V[]

Methods

  • Instantiate a Document for inclusion in the Collection.

    Parameters

    • data: any

      The Document data.

    • Optional context: DocumentConstructionContext = {}

      Document creation context.

    Returns Document

  • Initialize the EmbeddedCollection object by constructing its contained Document instances

    Parameters

    • Optional options: DocumentConstructionContext = {}

      Initialization options.

    Returns void

  • Get an element from the EmbeddedCollection by its ID.

    Parameters

    • id: string

      The ID of the Embedded Document to retrieve.

    • Optional options: {
          strict: boolean;
          invalid: boolean;
      } = {}

      Additional options to configure retrieval.

      • strict: boolean

        Throw an Error if the requested Embedded Document does not exist.

      • invalid: boolean

        Allow retrieving an invalid Embedded Document.

    Returns Document

    Throws

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

  • Add an item to the collection.

    Parameters

    • key: string

      The embedded Document ID.

    • value: Document

      The embedded Document instance.

    • Optional options: {
          modifySource: boolean;
      } = {}

      Additional options to the set operation.

      • modifySource: boolean

        Whether to modify the collection's source as part of the operation.

    Returns EmbeddedCollection

  • Parameters

    • key: string

      The embedded Document ID.

    • Optional options: {
          modifySource: boolean;
      } = {}

      Additional options to the delete operation.

      • modifySource: boolean

        Whether to modify the collection's source as part of the operation.

    Returns boolean

  • Update an EmbeddedCollection using an array of provided document data.

    Parameters

    • changes: DataModel[]

      An array of provided Document data

    • Optional options: any = {}

      Additional options which modify how the collection is updated

    Returns void

  • Obtain a temporary Document instance for a document id which currently has invalid source data.

    Parameters

    • id: string

      A document ID with invalid source data.

    • Optional options: {
          strict: boolean;
      } = {}

      Additional options to configure retrieval.

      • strict: boolean

        Throw an Error if the requested ID is not in the set of invalid IDs for this collection.

    Returns Document

    An in-memory instance for the invalid Document

    Throws

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

  • Convert the EmbeddedCollection to an array of simple objects.

    Parameters

    • Optional source: boolean = true

      Draw data for contained Documents from the underlying data source?

    Returns any[]

    The extracted array of primitive objects

  • Internal

    Follow-up actions to take when a database operation modifies Documents in this EmbeddedCollection.

    Parameters

    • action: DatabaseAction

      The database action performed

    • documents: Document[]

      The array of modified Documents

    • result: any[]

      The result of the database operation

    • operation: DatabaseOperation

      Database operation details

    • user: BaseUser

      The User who performed the operation

    Returns void

  • Find an entry in the Map using a functional condition.

    Parameters

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

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

        • (arg0, arg1, arg2): boolean
        • Parameters

          Returns boolean

    Returns any

    The value, if found, otherwise undefined

    See

    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
  • Filter the Collection, returning an Array of entries which match a functional condition.

    Parameters

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

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

        • (arg0, arg1, arg2): boolean
        • Parameters

          Returns boolean

    Returns any[]

    An Array of matched values

    See

    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");
  • Apply a function to each element of the collection

    Parameters

    • fn: ((arg0) => void)

      A function to apply to each element

        • (arg0): void
        • Parameters

          • arg0: any

          Returns void

    Returns void

    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);
  • Get an entry from the Collection by name. Use of this method assumes that the objects stored in the collection have a "name" attribute.

    Parameters

    • name: string

      The name of the entry to retrieve

    • Optional options: {
          strict: boolean;
      } = {}

      Additional options that affect how entries are retrieved

      • strict: boolean

        Throw an Error if the requested name does not exist. Default false.

    Returns any

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

    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
  • Transform each element of the Collection into a new form, returning an Array of transformed values

    Parameters

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

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

        • (arg0, arg1, arg2): any
        • Parameters

          Returns any

    Returns any[]

    An Array of transformed values

  • Reduce the Collection by applying an evaluator function and accumulating entries

    Parameters

    • reducer: ((arg0, arg1, arg2, arg3) => 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, arg1, arg2, arg3): any
        • Parameters

          • arg0: any
          • arg1: any
          • arg2: number
          • arg3: Collection<any, any>

          Returns any

    • initial: any

      An initial value which accumulates with each iteration

    Returns any

    The accumulated result

    See

    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"
  • Test whether a condition is met by some entry in the Collection.

    Parameters

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

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

        • (arg0, arg1, arg2): boolean
        • Parameters

          Returns boolean

    Returns boolean

    Was the test condition passed by at least one entry?

    See

  • Convert the Collection to a primitive array of its contents.

    Returns any[]

    An array of contained values

  • Then iterating over a Collection, we should iterate over its values instead of over its entries

    Returns IterableIterator<any>

  • Protected

    Initialize an embedded document and store it in the collection.

    Parameters

    • data: any

      The Document data.

    • Optional context: DocumentConstructionContext

      Context to configure Document initialization.

    Returns void

  • Protected

    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.

    • Optional options: {
          strict: boolean;
      } = {}

      Options to configure invalid Document handling.

      • strict: boolean

        Whether to throw an error or only log a warning.

    Returns void

  • Protected

    Modify the underlying source array to include the Document.

    Parameters

    • key: string

      The Document ID key.

    • value: Document

      The Document.

    Returns void

  • Protected

    Remove the value from the underlying source array.

    Parameters

    • key: string

      The Document ID key.

    • Optional options: any = {}

      Additional options to configure deletion behavior.

    Returns void

  • Protected

    Create or update an embedded Document in this collection.

    Parameters

    • data: DataModel

      The update delta.

    • Optional options: any

      Additional options which modify how the collection is updated.

    Returns void