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

Param: metadata

The compendium metadata, an object provided by game.data

Hierarchy (view full)

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

applicationClass: typeof Application = Compendium

A reference to the Application class which provides an interface to interact with this compendium content.

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

The set of Compendium Folders

#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 banner(): string | void
  • The banner image for this Compendium pack, or the default image for the pack type if no image is set.

    Returns string | void

  • get maxFolderDepth(): number
  • Returns number

  • get folder(): Folder
  • Get the Folder that this Compendium is displayed within

    Returns Folder

  • get sort(): number
  • Get the sort order for this Compendium

    Returns number

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

    Returns any

  • get documentName(): any
  • Returns any

    Inherit Doc

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

    Returns boolean

  • get ownership(): Record<USER_ROLES, DOCUMENT_OWNERSHIP_LEVELS>
  • The visibility configuration of this compendium pack.

    Returns Record<USER_ROLES, DOCUMENT_OWNERSHIP_LEVELS>

  • get visible(): boolean
  • Is this Compendium pack visible to the current game User?

    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(): typeof Document
  • A reference to the Document class definition which is contained within this DocumentCollection.

    Returns typeof Document

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

    Returns string

Methods

  • Assign this CompendiumCollection to be organized within a specific Folder.

    Parameters

    • folder: string | Folder

      The desired Folder within the World or null to clear the folder

    Returns Promise<void>

    A promise which resolves once the transaction is complete

  • Returns any

  • Get an element from the DocumentCollection by its ID.

    Parameters

    • key: any

      The ID of the Document to retrieve.

    • options: any

      Additional options to configure retrieval.

    Returns Document

    Throws

    If strict is true and the Document cannot be found.

  • Parameters

    • id: any
    • document: any

    Returns void

    Inherit Doc

  • Returns void

    Inherit Doc

  • Load the Compendium index and cache it as the keys and values of the Collection.

    Parameters

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

      Options which customize how the index is created

      • fields: string[]

        An array of fields to return as part of the index

    Returns Promise<Collection>

  • 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

  • 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

    Example: Get Documents that match the given value only.

    await pack.getDocuments({ type: "weapon" });
    

    Example: Get several Documents by their IDs.

    await pack.getDocuments({ _id__in: arrayOfIds });
    

    Example: Get Documents by their sub-types.

    await pack.getDocuments({ type__in: ["weapon", "armor"] });
    
  • Get the ownership level that a User has for this Compendium pack.

    Parameters

    • user: User = game.user

      The user being tested

    Returns number

    The ownership level in CONST.DOCUMENT_OWNERSHIP_LEVELS

  • Test whether a certain User has a requested permission level (or greater) over the Compendium pack

    Parameters

    • user: BaseUser

      The User being tested

    • permission: string | number

      The permission level from DOCUMENT_OWNERSHIP_LEVELS to test

    • options: {
          exact: boolean;
      } = {}

      Additional options involved in the permission test

      • exact: boolean

        Require the exact permission level requested?

    Returns boolean

    Does the user have this permission level over the Compendium pack?

  • Import a Document into this Compendium Collection.

    Parameters

    • document: Document

      The existing Document you wish to import

    • Optional options: any = {}

      Additional options which modify how the data is imported. See ClientDocumentMixin#toCompendium

    Returns Promise<Document>

    The imported Document instance

  • Import a Folder into this Compendium Collection.

    Parameters

    • folder: Folder

      The existing Folder you wish to import

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

      Additional options which modify how the data is imported.

      • importParents: boolean

        Import any parent folders which are not already present in the Compendium

    Returns Promise<void>

  • Import an array of Folders into this Compendium Collection.

    Parameters

    • folders: Folder[]

      The existing Folders you wish to import

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

      Additional options which modify how the data is imported.

      • importParents: boolean

        Import any parent folders which are not already present in the Compendium

    Returns Promise<void>

  • Fully import the contents of a Compendium pack into a World folder.

    Parameters

    • Optional options: {
          folderId: string;
          folderName: string;
      } = {}

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

      • folderId: string

        An existing Folder _id to use.

      • folderName: string

        A new Folder name to create.

    Returns Promise<Document[]>

    The imported Documents, now existing within the World

  • Provide a dialog form that prompts the user to import the full contents of a Compendium pack into the World.

    Parameters

    • Optional options: any = {}

      Additional options passed to the Dialog.confirm method

    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.

  • Add a Document to the index, capturing its relevant index attributes

    Parameters

    • document: Document

      The document to index

    Returns void

  • Prompt the gamemaster with a dialog to configure ownership of this Compendium pack.

    Returns Promise<Record<string, string>>

    The configured ownership for the pack

  • Generate a UUID for a given primary document ID within this Compendium pack

    Parameters

    • id: string

      The document ID to generate a UUID for

    Returns string

    The generated UUID, in the form of "Compendium..."

  • Assign configuration metadata settings to the compendium pack

    Parameters

    • configuration: 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>

  • 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>

  • 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: {} = {}

      Additional options passed to Document.updateDocuments

      Returns Promise<Document[]>

      An array of updated data once the operation is complete

    • Internal

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

      Parameters

      • action: any

        The database action performed

      • documents: any

        The array of modified Documents

      • result: any

        The result of the database operation

      • operation: any

        Database operation details

      • user: any

        The User who performed the operation

      Returns void

    • Instantiate a Document for inclusion in the Collection.

      Parameters

      • data: any

        The Document data.

      • Optional context: any = {}

        Document creation context.

      Returns 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.

      • 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.

    • Render any Applications associated with this DocumentCollection.

      Parameters

      • force: any
      • options: any

      Returns void

    • Find all Documents which match a given search term using a full-text search against their indexed HTML fields and their name. If filters are provided, results are filtered to only those that match the provided values.

      Parameters

      • search: {
            query: string;
            filters: FieldFilter[];
            exclude: string[];
        }

        An object configuring the search

        • query: string

          A case-insensitive search string

        • filters: FieldFilter[]

          An array of filters to apply

        • exclude: string[]

          An array of document IDs to exclude from search results

      Returns string[]

    • Private

      Validate that the current user is able to modify content of this Compendium pack

      Parameters

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

      Returns boolean

    • Parameters

      • a: any
      • b: any

      Returns number

    • Internal

      Activate the Socket event listeners used to receive responses to compendium management events.

      Parameters

      • socket: Socket

        The active game socket.

      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>

    • Get the searchable fields for a given document or index, based on its data model

      Parameters

      • documentName: string

        The document type name

      • Optional documentSubtype: string = ""

        The document subtype name

      • Optional isEmbedded: boolean = false

        Whether the document is an embedded object

      Returns Set<string>

      The dot-delimited property paths of searchable fields

    • Handle a response from the server where a compendium was created.

      Parameters

      • response: SocketResponse

        The server response.

      Returns CompendiumCollection

    • Handle a response from the server where a compendium was deleted.

      Parameters

      • response: SocketResponse

        The server response.

      Returns CompendiumCollection