Options
All
  • Public
  • Public/Protected
  • All
Menu

A collection of Document objects contained within a specific compendium pack. Each Compendium pack has its own associated instance of the CompendiumCollection class which contains its contents.

abstract
see

{Game#packs}

param metadata

The compendium metadata, an object provided by game.data

Hierarchy

Index

Constructors

Properties

metadata: any

The compendium metadata which defines the compendium content and location

index: Collection<string, any>

A subsidiary collection which contains the more minimal index of the pack

apps: Application[]

An Array of application references which will be automatically updated when the collection content changes

invalidDocumentIds: Set<string> = ...

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

#indexedFields: Set<string>

Track which document fields have been indexed for this compendium pack

CACHE_LIFETIME_SECONDS: number = 300

The amount of time that Document instances within this CompendiumCollection are held in memory. Accessing the contents of the Compendium pack extends the duration of this lifetime.

CONFIG_SETTING: string = "compendiumConfiguration"

The named game setting which contains Compendium configurations.

documentName: string

The base Document type which is contained within this DocumentCollection

Accessors

  • get collection(): string
  • The canonical Compendium name - comprised of the originating package and the pack name

    Returns string

  • get config(): any
  • Access the compendium configuration data for this pack

    Returns any

  • get documentName(): any
  • inheritdoc

    Returns any

  • get locked(): boolean
  • Track whether the Compendium Collection is locked for editing

    Returns boolean

  • get private(): boolean
  • Track whether the Compendium Collection is private

    Returns boolean

  • get title(): string
  • A convenience reference to the label which should be used as the title for the Compendium pack.

    Returns string

  • get indexFields(): Set<string>
  • The index fields which should be loaded for this compendium pack

    Returns Set<string>

  • get indexed(): boolean
  • Has this compendium pack been fully indexed?

    Returns boolean

  • get documentClass(): Function
  • A reference to the Document class definition which is contained within this DocumentCollection.

    Returns Function

  • get name(): string
  • The Collection class name

    Returns string

Methods

  • get(key: any, options: any): any
  • inheritdoc

    Parameters

    • key: any
    • options: any

    Returns any

  • set(id: any, document: any): void
  • delete(id: any): void
  • getIndex([options]?: { fields: string[] }): Promise<Collection>
  • Load the Compendium index and cache it as the keys and values of the Collection.

    Parameters

    • [options]: { fields: string[] } = {}

      Options which customize how the index is created

      • fields: string[]

    Returns Promise<Collection>

  • getDocument(id: string): Promise<Document>
  • Get a single Document from this Compendium by ID. The document may already be locally cached, otherwise it is retrieved from the server.

    Parameters

    • id: string

      The requested Document id

    Returns Promise<Document>

    The retrieved Document instance

  • getDocuments(query?: any): Promise<Document[]>
  • Load multiple documents from the Compendium pack using a provided query object.

    Parameters

    • query: any = {}

      A database query used to retrieve documents from the underlying database

    Returns Promise<Document[]>

    The retrieved Document instances

  • importDocument(document: Document, options?: any): Promise<Document>
  • Import a Document into this Compendium Collection.

    Parameters

    • document: Document

      The existing Document you wish to import

    • options: any = {}

    Returns Promise<Document>

    The imported Document instance

  • importAll([options={}]?: { folderId: string; folderName: string }): Promise<Document[]>
  • Fully import the contents of a Compendium pack into a World folder.

    Parameters

    • [options={}]: { folderId: string; folderName: string } = {}

      Options which modify the import operation. Additional options are forwarded to {@link WorldCollection#fromCompendium} and Document.createDocuments

      • folderId: string
      • folderName: string

    Returns Promise<Document[]>

    The imported Documents, now existing within the World

  • importDialog(options?: any): Promise<boolean | Document[]>
  • Provide a dialog form that prompts the user to import the full contents of a Compendium pack into the World.

    Parameters

    • options: any = {}

    Returns Promise<boolean | Document[]>

    A promise which resolves in the following ways: an array of imported Documents if the "yes" button was pressed, false if the "no" button was pressed, or null if the dialog was closed without making a choice.

  • indexDocument(document: Document): void
  • Add a Document to the index, capturing its relevant index attributes

    Parameters

    • document: Document

      The document to index

    Returns void

  • configure(settings?: any): Promise<any>
  • Assign configuration metadata settings to the compendium pack

    Parameters

    • settings: any = {}

      The object of compendium settings to define

    Returns Promise<any>

    A Promise which resolves once the setting is updated

  • Delete an existing world-level Compendium Collection. This action may only be performed for world-level packs by a Gamemaster User.

    Returns Promise<CompendiumCollection>

  • Duplicate a compendium pack to the current World.

    Parameters

    • label: string = {}

      A new Compendium label

    Returns Promise<CompendiumCollection>

  • Migrate a compendium pack. This operation re-saves all documents within the compendium pack to disk, applying the current data model. If the document type has system data, the latest system data template will also be applied to all documents.

    Returns Promise<CompendiumCollection>

  • updateAll(transformation: any, condition?: any, options?: {}): Promise<Document[]>
  • Update all objects in this DocumentCollection with a provided transformation. Conditionally filter to only apply to Entities which match a certain condition.

    Parameters

    • transformation: any

      An object of data or function to apply to all matched objects

    • condition: any = null

      A function which tests whether to target each object

    • options: {} = {}

      Returns Promise<Document[]>

      An array of updated data once the operation is complete

    • _onCreateDocuments(documents: any, result: any, options: any, userId: any): void
    • Follow-up actions taken after a set of Documents in this Collection are created.

      Parameters

      • documents: any

        An Array of created Documents

      • result: any

        An Array of created data objects

      • options: any

        Options which modified the creation operation

      • userId: any

        The ID of the User who triggered the operation

      Returns void

    • _onUpdateDocuments(documents: any, result: any, options: any, userId: any): void
    • Follow-up actions taken after a set of Documents in this Collection are updated.

      Parameters

      • documents: any

        An Array of updated Documents

      • result: any

        An Array of incremental data objects

      • options: any

        Options which modified the update operation

      • userId: any

        The ID of the User who triggered the operation

      Returns void

    • _onDeleteDocuments(documents: any, result: any, options: any, userId: any): void
    • Follow-up actions taken after a set of Documents in this Collection are deleted.

      Parameters

      • documents: any

        An Array of deleted Documents

      • result: any

        An Array of document IDs being deleted

      • options: any

        Options which modified the deletion operation

      • userId: any

        The ID of the User who triggered the operation

      Returns void

    • getInvalid(id: string): Document
    • 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.

      Returns Document

      An in-memory instance for the invalid Document

    • render(force: any, options: any): void
    • Render any Applications associated with this DocumentCollection.

      Parameters

      • force: any
      • options: any

      Returns void

    • _preCreateDocuments(result: any[], options: any, userId: string): void
    • Preliminary actions taken before a set of Documents in this Collection are created.

      Parameters

      • result: any[]

        An Array of created data objects

      • options: any

        Options which modified the creation operation

      • userId: string

        The ID of the User who triggered the operation

      Returns void

    • _preUpdateDocuments(result: any[], options: any, userId: string): void
    • Preliminary actions taken before a set of Documents in this Collection are updated.

      Parameters

      • result: any[]

        An Array of incremental data objects

      • options: any

        Options which modified the update operation

      • userId: string

        The ID of the User who triggered the operation

      Returns void

    • _preDeleteDocuments(result: string[], options: any, userId: string): void
    • Preliminary actions taken before a set of Documents in this Collection are deleted.

      Parameters

      • result: string[]

        An Array of document IDs being deleted

      • options: any

        Options which modified the deletion operation

      • userId: string

        The ID of the User who triggered the operation

      Returns void

    • _assertUserCanModify(__namedParameters?: { requireUnlocked: boolean }): boolean
    • Validate that the current user is able to modify content of this Compendium pack

      Parameters

      • __namedParameters: { requireUnlocked: boolean } = {}
        • requireUnlocked: boolean

      Returns boolean

    • _onModifyContents(documents: any, options: any, userId: any): void
    • Follow-up actions taken when Documents within this Compendium pack are modified

      Parameters

      • documents: any
      • options: any
      • userId: any

      Returns void

    • Create a new Compendium Collection using provided metadata.

      Parameters

      • metadata: any

        The compendium metadata used to create the new pack

      • options: any = {}

        Additional options which modify the Compendium creation request

      Returns Promise<CompendiumCollection>