Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    The data schema used to define Module manifest files. Extends the basic PackageData schema with some additional module-specific fields.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    The source data object for this DataModel instance. Once constructed, the source object is sealed such that no keys may be added nor removed.

    _unknownKeys: string[] = ...

    An array of top-level manifest keys that were provided which are not supported by the schema.

    availability: number

    An availability code in PACKAGE_AVAILABILITY_CODES which defines whether this package can be used.

    exclusive: boolean

    A flag which tracks whether this package is a free Exclusive pack

    hasStorage: boolean

    A flag which tracks if this package has files stored in the persistent storage folder

    locked: boolean

    A flag which tracks whether this package is currently locked.

    owned: boolean | null

    A flag which tracks whether this package is owned, if it is protected.

    parent: DataModel<object, DataModelConstructionContext> | null

    An immutable reverse-reference to a parent DataModel to which this model belongs.

    tags: string[]

    A set of Tags that indicate what kind of Package this is, provided by the Website

    The defined and cached Data Schema for all instances of this DataModel.

    icon: string = "fa-plug"

    The default icon used for this type of Package.

    LOCALIZATION_PREFIXES: string[] = ...
    type: string = "module"

    Accessors

    • get incompatibleWithCoreVersion(): boolean

      Is this Package incompatible with the currently installed core Foundry VTT software version?

      Returns boolean

    • get invalid(): boolean

      Is the current state of this DataModel invalid? The model is invalid if there is any unresolved failure.

      Returns boolean

    • get type(): string

      The type of this package instance. A value in CONST.PACKAGE_TYPES.

      Returns string

    • get unavailable(): boolean

      A flag which defines whether this package is unavailable to be used.

      Returns boolean

    • get collection(): string

      The named collection to which this package type belongs

      Returns string

    Methods

    • Parameters

      • data: any
      • __namedParameters: { installed?: boolean } = {}

      Returns object

    • Internal

      Test that the dependencies of a package are satisfied as compatible. This method assumes that all packages in modulesCollection have already had their own availability tested.

      Parameters

      • modulesCollection: Collection<string, Module>

        A collection which defines the set of available modules

      Returns Promise<boolean>

      Are all required dependencies satisfied?

    • Internal

      Test compatibility of a package's supported systems.

      Parameters

      • systemCollection: Collection<string, System>

        A collection which defines the set of available systems.

      Returns Promise<boolean>

      True if all supported systems which are currently installed are compatible or if the package has no supported systems. Returns false otherwise, or if no supported systems are installed.

    • Traverse the data model instance, obtaining the DataField definition for a field of a particular property.

      Parameters

      • key: string | string[]

        A property key like ["abilities", "strength"] or "abilities.strength"

      Returns DataField | undefined

      The corresponding DataField definition for that field, or undefined

    • Reset the state of this data instance back to mirror the contained source data, erasing any changes.

      Returns void

    • Extract the source data for the DataModel into a simple object format that can be serialized.

      Returns object

      The document source data expressed as a plain object

    • Copy and transform the DataModel into a plain object. Draw the values of the extracted object from the data source (by default) otherwise from its transformed values.

      Parameters

      • Optionalsource: boolean = true

        Draw values from the underlying data source rather than transformed values

      Returns object

      The extracted primitive object

    • Update the DataModel locally by applying an object of changes to its source data. The provided changes are expanded, cleaned, validated, and stored to the source data object for this model. The provided changes argument is mutated in this process. The source data is then re-initialized to apply those changes to the prepared data. The method returns an object of differential changes which modified the original data.

      Parameters

      • changes: object = {}

        New values which should be applied to the data model

      • options: DataModelUpdateOptions = {}

        Options which determine how the new data is merged

      Returns object

      An object containing differential keys and values that were changed

      An error if the requested data model changes were invalid

    • Validate the data contained in the document to check for type and content. This method is intended to validate complete model records, verifying both individual field validation as well as joint model validity.

      For validating sets of partial model changes, it is preferred to call DataModel#updateSource as a dryRun. This method provides a convenience alias for such a workflow if changes are provided.

      Warning: if fallback handling is allowed, this process will mutate provided changes or model source data.

      Parameters

      Returns boolean

      Whether the data source or proposed change is reported as valid. A boolean is always returned if validation is non-strict.

      An error thrown if validation is strict and a failure occurs.

    • Protected

      Configure the data model instance before validation and initialization workflows are performed.

      Parameters

      • Optionaloptions: object = {}

        Additional options modifying the configuration

      Returns void

    • Protected

      A generator that orders the DataFields in the DataSchema into an expected initialization order.

      Returns Generator<[string, DataField], any, any>

    • Protected

      Initialize the instance by copying data from the source object to instance attributes. This mirrors the workflow of SchemaField#initialize but with some added functionality.

      Parameters

      • Optionaloptions: object = {}

        Options provided to the model constructor

      Returns void

    • Protected

      Perform the second step of the DataModel#_updateSource workflow which applies the prepared diff to the model.

      Parameters

      • copy: object

        The prepared copy of source data with changes applied

      • diff: object

        The differential changes that were applied to source

      • options: DataModelUpdateOptions

        Options which determine how the new data is merged

      • _state: data.types.DataModelUpdateState

        Data cleaning state which might include instructions for final commit

      Returns void

    • Protected

      Perform the first step of the DataModel#_updateSource workflow which applies changes to a copy of model source data and records the resulting diff.

      Parameters

      • copy: object

        A mutable copy of model source data

      • changes: object

        New values which should be applied to the data model

      • options: DataModelUpdateOptions

        Options which determine how the new data is merged

      • _state: data.types.DataModelUpdateState

        Data cleaning state

      Returns object

      The resulting difference applied to source data

      A failure if the proposed change is invalid

    • Parameters

      • data: any
      • _options: any
      • _state: any

      Returns void

    • Internal

      A wrapper around the default compatibility warning logger which handles some package-specific interactions.

      Parameters

      • packageId: string

        The package ID being logged

      • message: string

        The warning or error being logged

      • options: { installed?: object } = {}

        Logging options passed to foundry.utils.logCompatibilityWarning

        • Optionalinstalled?: object

          Is the package installed?

      Returns void

    • Retrieve the latest Package manifest from a provided remote location.

      Parameters

      • manifestUrl: string

        A remote manifest URL to load

      • options: { strict?: boolean } = {}

        Additional options which affect package construction

        • Optionalstrict?: boolean

          Whether to construct the remote package strictly

      Returns Promise<ServerPackage>

      A Promise which resolves to a constructed ServerPackage instance

      An error if the retrieved manifest data is invalid

    • Test if a given availability is incompatible with the core version.

      Parameters

      • availability: number

        The availability value to test.

      Returns boolean

    • Migrate candidate source data for this DataModel which may require initial cleaning or transformations.

      Parameters

      • data: any

        Candidate source data for the module, before further cleaning

      • __namedParameters: {} = {}

        Additional options for how the field is cleaned

      Returns object

      Migrated source data, ready for further cleaning

    • Wrap data migration in a try/catch which attempts it safely.

      Parameters

      • source: object

        Candidate source data for the module, before further cleaning

      • Optionaloptions: Readonly<DataModelCleaningOptions> = {}

        Additional options for how the field is cleaned

      Returns object

      Migrated source data, ready for further cleaning

    • Take data which conforms to the current data schema and add backwards-compatible accessors to it in order to support older code which uses this data.

      Parameters

      • data: object

        Data which matches the current schema

      • Optionaloptions: { embedded?: boolean } = {}

        Additional shimming options

        • Optionalembedded?: boolean

          Apply shims to embedded models?

      Returns object

      Data with added backwards-compatible properties, which is the same object as the data argument

    • Check the given compatibility data against the current installation state and determine its availability.

      Parameters

      • data: Partial<PackageManifestData>

        The compatibility data to test.

      • Optionaloptions: { release?: any } = {}
        • Optionalrelease?: any

          A specific software release for which to test availability. Tests against the current release by default.

      Returns number

    • Validate that a Package ID is allowed.

      Parameters

      • id: string

        The candidate ID

      Returns void

      An error if the candidate ID is invalid

    • Evaluate joint validation rules which apply validation conditions across multiple fields of the model. Field-specific validation rules should be defined as part of the DataSchema for the model. This method allows for testing aggregate rules which impose requirements on the overall model.

      Parameters

      • data: object

        Candidate data for the model

      Returns void

      An error if a validation failure is detected

    • Validate that a version is allowed.

      Parameters

      • version: string

        The candidate version

      Returns void

      An error if the version is invalid

    • Protected

      Apply preliminary model-specific cleaning rules or alter cleaning options or initial state. Subclass models may implement this function to configure the cleaning workflow. Any mutations to data, options, or _state parameters are performed inplace.

      Parameters

      Returns void