platform-bible-utils
    Preparing search index...

    Class DocumentCombiner

    Base class for any code that wants to compose JSON documents (primarily in the form of JS objects or arrays) together into a single output document.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    baseDocument: JsonDocumentLike
    contributions: Map<string, JsonDocumentLike> = ...
    latestOutput: undefined | JsonDocumentLike
    onDidRebuild: PlatformEvent<undefined> = ...

    Event that emits to announce that the document has been rebuilt and the output has been updated

    Methods

    • Add or update one of the contribution documents for the composition process

      Note: the order in which contribution documents are added can be considered indeterminate as it depends on the order in which Map.forEach iterates over the contributions. However, the order matters when merging two arrays into one. Also, when options.ignoreDuplicateProperties is is true, the order also matters when adding the same property to an object that is already provided previously. Please let us know if you have trouble because of indeterminate contribution ordering.

      Parameters

      • documentName: string

        Name of the contributed document to combine

      • document: JsonDocumentLike

        Content of the contributed document to combine

      Returns undefined | JsonDocumentLike

      Recalculated output document given the new or updated contribution and existing other documents

    • Transform the starting document that is given to the combiner. This transformation occurs after validating the base document and before combining any contributions.

      WARNING: If you do not create the combiner with option copyDocuments: true or clone inside this method, this method will directly modify the baseDocument passed in.

      Parameters

      • baseDocument: JsonDocumentLike

        Initial input document. Already validated via validateBaseDocument

      Returns JsonDocumentLike

      Transformed base document

    • Transform the contributed document associated with documentName. This transformation occurs after validating the contributed document and before combining with other documents.

      WARNING: If you do not create the combiner with option copyDocuments: true or clone inside this method, this method will directly modify the contributed document passed in.

      Parameters

      • documentName: string

        Name of the contributed document to combine

      • document: JsonDocumentLike

        Content of the contributed document to combine. Already validated via validateContribution

      Returns JsonDocumentLike

      Transformed contributed document

    • Transform the document that is the composition of the base document and all contribution documents. This is the last step that will be run prior to validation via validateOutput before this.latestOutput is updated to the new output.

      Parameters

      • finalOutput: JsonDocumentLike

        Final output document that could potentially be returned to callers. "Final" means no further contribution documents will be merged.

      Returns JsonDocumentLike