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

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

    Returns string

  • get maxFolderDepth(): number
  • override

    Returns number

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

    Returns any

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

    Returns boolean

  • get ownership(): number
  • The visibility configuration of this compendium pack. A value in CONST.USER_ROLES

    Returns number

  • 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(): 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

  • setFolder(folder: string | Folder): Promise<void>
  • 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

  • _getVisibleTreeContents(): any
  • override

    Returns any

  • get(key: any, options: any): Document
  • 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

  • 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

  • getUserLevel(user?: User): number
  • 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

  • testUserPermission(user: BaseUser, permission: string | number, options?: { exact: boolean }): boolean
  • 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

    Returns boolean

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

  • 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

  • importFolder(folder: Folder, [options]?: { importParents: boolean }): Promise<void>
  • Import a Folder into this Compendium Collection.

    Parameters

    • folder: Folder

      The existing Folder you wish to import

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

      Additional options which modify how the data is imported.

      • importParents: boolean

    Returns Promise<void>

  • importFolders(folders: Folder[], [options]?: { importParents: boolean }): Promise<void>
  • Import an array of Folders into this Compendium Collection.

    Parameters

    • folders: Folder[]

      The existing Folders you wish to import

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

      Additional options which modify how the data is imported.

      • importParents: boolean

    Returns Promise<void>

  • 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

  • configureOwnershipDialog(): Promise<any>
  • Prompt the gamemaster with a dialog to configure ownership of this Compendium pack.

    Returns Promise<any>

    The configured ownership for the pack

  • getUuid(id: string): string
  • 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..."

  • configure(configuration?: any): Promise<any>
  • 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>

  • 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

    • _onDeleteFolder(parentFolder: any, deleteFolderId: any, deleteContents: any): any[]
    • Handle shifting documents in a deleted folder to a new parent folder.

      Parameters

      • parentFolder: any

        The parent folder to which documents should be shifted

      • deleteFolderId: any

        The ID of the folder being deleted

      • deleteContents: any

        Whether to delete the contents of the folder

      Returns any[]

      An array of document IDs to deleted

    • createDocument(data: any, context?: any): Document
    • Instantiate a Document for inclusion in the Collection.

      Parameters

      • data: any

        The Document data.

      • context: any = {}

      Returns Document

    • 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

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

      Parameters

      • force: any
      • options: any

      Returns void

    • search(search: { query: string; filters: FieldFilter[]; exclude: string[] }): string[]
    • 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

      Returns string[]

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

      internal

      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.

      internal

      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.

      internal

      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

    • #assertUserCanManage(__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

    • _sortStandard(a: any, b: any): number
    • override

      Parameters

      • a: any
      • b: any

      Returns number

    • _activateSocketListeners(socket: Socket): void
    • Activate the Socket event listeners used to receive responses to compendium management events.

      internal

      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>

    • getSearchableFields(documentName: string, documentSubtype?: string, isEmbedded?: boolean): Set<string>
    • Get the searchable fields for a given document or index, based on its data model

      Parameters

      • documentName: string

        The document type name

      • documentSubtype: string = ""
      • isEmbedded: boolean = false

      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