Source data for the package
Optional
options: object = {}Options which affect DataModel construction
The source data object for this DataModel instance. Once constructed, the source object is sealed such that no keys may be added nor removed.
An availability code in PACKAGE_AVAILABILITY_CODES which defines whether this package can be used.
A flag which tracks whether this package is a free Exclusive pack
A flag which tracks if this package has files stored in the persistent storage folder
A flag which tracks whether this package is currently locked.
A flag which tracks whether this package is owned, if it is protected.
An immutable reverse-reference to a parent DataModel to which this model belongs.
A set of Tags that indicate what kind of Package this is, provided by the Website
Static
Internal
_schemaThe defined and cached Data Schema for all instances of this DataModel.
Static
LOCALIZATION_Static
Abstract
typeDefine the package type in CONST.PACKAGE_TYPES that this class represents. Each BasePackage subclass must define this attribute.
Is this Package incompatible with the currently installed core Foundry VTT software version?
Is the current state of this DataModel invalid? The model is invalid if there is any unresolved failure.
Define the data schema for this document instance.
The type of this package instance. A value in CONST.PACKAGE_TYPES.
A flag which defines whether this package is unavailable to be used.
An array of validation failure instances which may have occurred when this instance was last validated.
Static
collectionThe named collection to which this package type belongs
Static
schemaThe Data Schema for all instances of this DataModel.
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.
A collection which defines the set of available modules
Are all required dependencies satisfied?
Internal
Test compatibility of a package's supported systems.
A collection which defines the set of available systems.
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.
Clone a model, creating a new data model by combining current data with provided overrides.
Optional
data: object = {}Additional data which overrides current document data at the time of creation
Optional
context: DataModelConstructionContext = {}Context options passed to the data model constructor
The cloned instance
Reset the state of this data instance back to mirror the contained source data, erasing any changes.
Extract the source data for the DataModel into a simple object format that can be serialized.
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.
Optional
source: boolean = trueDraw values from the underlying data source rather than transformed values
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.
New values which should be applied to the data model
Options which determine how the new data is merged
An object containing differential keys and values that were changed
Validate the data contained in the document to check for type and content. If changes are provided, missing types are added to it before cleaning and validation. This mutates the provided changes. This function throws an error if data within the document is not valid.
Options which modify how the model is validated
Whether the data source or proposed change is reported as valid. A boolean is always returned if validation is non-strict.
Protected
_configureProtected
Configure the data model instance before validation and initialization workflows are performed.
Optional
options: object = {}Additional options modifying the configuration
Protected
_initializeProtected
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.
Optional
options: object = {}Options provided to the model constructor
Protected
_initializeProtected
Initialize the source data for a new DataModel instance. One-time migrations and initial cleaning operations are applied to the source data.
The candidate source data from which the model will be constructed
Optional
options: object = {}Options provided to the model constructor
Migrated and cleaned source data which will be stored to the model instance,
which is the same object as the data
argument
Static
_logInternal
A wrapper around the default compatibility warning logger which handles some package-specific interactions.
The package ID being logged
The warning or error being logged
Logging options passed to foundry.utils.logCompatibilityWarning
Optional
installed?: objectIs the package installed?
Static
_migrateInternal
Static
_migrateInternal
Static
cleanClean a data source object to conform to a specific provided schema.
The source data object
Additional options which are passed to field cleaning methods
The cleaned source data, which is the same object as the source
argument
Static
defineDefine the data schema for documents of this type. The schema is populated the first time it is accessed and cached for future reuse.
Static
fromJSONCreate a DataModel instance using a provided serialized JSON string.
Serialized document data in string format
A constructed data model instance
Static
fromRetrieve the latest Package manifest from a provided remote location.
A remote manifest URL to load
Additional options which affect package construction
Optional
strict?: booleanWhether to construct the remote package strictly
A Promise which resolves to a constructed ServerPackage instance
Static
fromCreate a new instance of this DataModel from a source record. The source is presumed to be trustworthy and is not strictly validated.
Initial document data which comes from a trusted source.
Optional
context: Omit<DataModelConstructionContext, "strict"> & DataModelFromSourceOptions = {}Model construction context
Static
isTest if a given availability is incompatible with the core version.
The availability value to test.
Static
migrateMigrate candidate source data for this DataModel which may require initial cleaning or transformations.
The candidate source data from which the model will be constructed
Migrated source data, which is the same object as the source
argument
Static
migrateWrap data migration in a try/catch which attempts it safely
The candidate source data from which the model will be constructed
Migrated source data, which is the same object as the source
argument
Static
shimTake 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.
Data which matches the current schema
Optional
options: { embedded?: boolean } = {}Additional shimming options
Optional
embedded?: booleanApply shims to embedded models?
Data with added backwards-compatible properties, which is the same object as
the data
argument
Static
testCheck the given compatibility data against the current installation state and determine its availability.
The compatibility data to test.
Optional
options: { release?: any } = {}Optional
release?: anyA specific software release for which to test availability. Tests against the current release by default.
Static
testDetermine if a dependency is within the given compatibility range.
The compatibility range declared for the dependency, if any
The known dependency package
Is the dependency compatible with the required range?
Static
validateStatic
validateEvaluate 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.
Candidate data for the model
Static
validateProtected
Static
_initializationProtected
A generator that orders the DataFields in the DataSchema into an expected initialization order.
The data schema used to define a Package manifest. Specific types of packages extend this schema with additional fields.