import type { ConfiguredMacro } from "#configuration"; import type { Identity, InexactPartial, Merge, NullishProps } from "#utils"; import type { documents } from "#client/client.d.mts"; import type Document from "#common/abstract/document.d.mts"; import type { DataSchema } from "#common/data/fields.d.mts"; import type BaseMacro from "#common/documents/macro.d.mts"; import type { Token } from "#client/canvas/placeables/_module.d.mts"; import fields = foundry.data.fields; declare namespace Macro { /** * The document's name. */ type Name = "Macro"; /** * The context used to create a `Macro`. */ interface ConstructionContext extends Document.ConstructionContext {} /** * The documents embedded within `Macro`. */ type Hierarchy = Readonly>; /** * The implementation of the `Macro` document instance configured through `CONFIG.Macro.documentClass` in Foundry and * {@linkcode DocumentClassConfig} or {@link ConfiguredMacro | `fvtt-types/configuration/ConfiguredMacro`} in fvtt-types. */ type Implementation = Document.ImplementationFor; /** * The implementation of the `Macro` document configured through `CONFIG.Macro.documentClass` in Foundry and * {@linkcode DocumentClassConfig} in fvtt-types. */ type ImplementationClass = Document.ImplementationClassFor; /** * A document's metadata is special information about the document ranging anywhere from its name, * whether it's indexed, or to the permissions a user has over it. */ interface Metadata extends Merge< Document.Metadata.Default, Readonly<{ name: "Macro"; collection: "macros"; indexed: true; compendiumIndexFields: ["_id", "name", "img", "sort", "folder"]; label: string; labelPlural: string; coreTypes: ["script", "chat"]; // This isn't `CONST.MACRO_TYPES[]` due to the semantics of `Merge`. permissions: Metadata.Permissions; schemaVersion: string; }> > {} namespace Metadata { /** * The permissions for whether a certain user can create, update, or delete this document. */ interface Permissions { create(user: User.Internal.Implementation, doc: Implementation): boolean; update(user: User.Internal.Implementation, doc: Implementation): boolean; delete: "OWNER"; } } /** * The subtypes of `Macro` that Foundry provides. `Macro` does not have `system` and therefore * there is no way for a user to configure custom subtypes. Nevertheless Foundry has a number of * built in subtypes usable for `Macro`. * * `Macro` has two subtypes `"chat"` and `"script"`. A `Macro` with type `"chat"` will create a * `ChatMessage` whereas a `"script"` allows executing arbitrary JavaScript code */ type SubType = foundry.Game.Model.TypeNames; /** * @deprecated `Macro` does not have `system` and therefore there is no way for a user to * configure custom subtypes. * * This type exists only to be informative. */ type ConfiguredSubType = never; /** * @deprecated `Macro` does not have `system` and therefore there is no way for a user to * configure custom subtypes. This means `Known` as a concept does not apply to it. * * This type exists only to be informative. */ type Known = never; /** * `OfType` returns an instance of `Macro` with the corresponding type. This works with both the * builtin `Macro` class or a custom subclass if that is set up in * {@link ConfiguredMacro | `fvtt-types/configuration/ConfiguredMacro`}. * * Note that `Macro` does not have a `system` property and therefore there is no way for a user * to configure custom subtypes. See {@linkcode Macro.SubType} for more information. */ // Note(LukeAbby): The lack of a `system` is why `Document.Internal.DiscriminateSystem` isn't applied. type OfType = _OfType[Type]; /** @internal */ interface _OfType extends Identity<{ [Type in SubType]: Type extends unknown ? ConfiguredMacro extends { document: infer Document } ? Document : // eslint-disable-next-line @typescript-eslint/no-restricted-types Macro : never; }> {} /** * A document's parent is something that can contain it. * For example an `Item` can be contained by an `Actor` which makes `Actor` one of its possible parents. */ type Parent = null; /** * A document's descendants are any child documents, grandchild documents, etc. * This is a union of all instances, or never if the document doesn't have any descendants. */ type Descendant = never; /** * A document's descendants are any child documents, grandchild documents, etc. * This is a union of all classes, or never if the document doesn't have any descendants. */ type DescendantClass = never; /** * Types of `CompendiumCollection` this document might be contained in. * Note that `this.pack` will always return a string; this is the type for `game.packs.get(this.pack)` * * Will be `never` if cannot be contained in a `CompendiumCollection`. */ // Note: Takes any document in the heritage chain (i.e. itself or any parent, transitive or not) that can be contained in a compendium. type Pack = foundry.documents.collections.CompendiumCollection.ForDocument<"Scene">; /** * An embedded document is a document contained in another. * For example an `Item` can be contained by an `Actor` which means `Item` can be embedded in `Actor`. * * If this is `never` it is because there are no embeddable documents (or there's a bug!). */ type Embedded = never; /** * The name of the world or embedded collection this document can find itself in. * For example an `Item` is always going to be inside a collection with a key of `items`. * This is a fixed string per document type and is primarily useful for {@link ClientDocumentMixin | `Descendant Document Events`}. */ type ParentCollectionName = Metadata["collection"]; /** * The world collection that contains `Macro`s. Will be `never` if none exists. */ type CollectionClass = foundry.documents.collections.Macros.ImplementationClass; /** * The world collection that contains `Folder`s. Will be `never` if none exists. */ type Collection = foundry.documents.collections.Macros.Implementation; /** * An instance of `Macro` that comes from the database but failed validation meaning that * its `system` and `_source` could theoretically be anything. */ type Invalid = Document.Internal.Invalid>; /** * An instance of `Macro` that comes from the database. */ type Stored = Document.Internal.Stored>; /** * The data put in {@link Macro._source | `Macro#_source`}. This data is what was * persisted to the database and therefore it must be valid JSON. * * For example a {@link fields.SetField | `SetField`} is persisted to the database as an array * but initialized as a {@linkcode Set}. */ interface Source extends fields.SchemaField.SourceData {} /** * The data necessary to create a document. Used in places like {@linkcode Macro.create} * and {@link Macro | `new Macro(...)`}. * * For example a {@link fields.SetField | `SetField`} can accept any {@linkcode Iterable} * with the right values. This means you can pass a `Set` instance, an array of values, * a generator, or any other iterable. */ interface CreateData extends fields.SchemaField.CreateData {} /** * The data after a {@link foundry.abstract.Document | `Document`} has been initialized, for example * {@link Macro.name | `Macro#name`}. * * This is data transformed from {@linkcode Macro.Source} and turned into more * convenient runtime data structures. For example a {@link fields.SetField | `SetField`} is * persisted to the database as an array of values but at runtime it is a `Set` instance. */ interface InitializedData extends fields.SchemaField.InitializedData {} /** * The data used to update a document, for example {@link Macro.update | `Macro#update`}. * It is a distinct type from {@link Macro.CreateData | `DeepPartial`} because * it has different rules for `null` and `undefined`. */ interface UpdateData extends fields.SchemaField.UpdateData {} /** * The schema for {@linkcode Macro}. This is the source of truth for how an Macro document * must be structured. * * Foundry uses this schema to validate the structure of the {@linkcode Macro}. For example * a {@link fields.StringField | `StringField`} will enforce that the value is a string. More * complex fields like {@link fields.SetField | `SetField`} goes through various conversions * starting as an array in the database, initialized as a set, and allows updates with any * iterable. */ interface Schema extends DataSchema { /** * The _id which uniquely identifies this Macro document * @defaultValue `null` */ _id: fields.DocumentIdField; /** * The name of this Macro * @defaultValue `""` */ name: fields.StringField<{ required: true; blank: false; textSearch: true }>; /** * A Macro subtype from CONST.MACRO_TYPES * @defaultValue `CONST.MACRO_TYPES.CHAT` */ type: fields.DocumentTypeField; /** * The _id of a User document which created this Macro * * @defaultValue `game.user?.id` */ author: fields.DocumentAuthorField; /** * An image file path which provides the thumbnail artwork for this Macro * @defaultValue `BaseMacro.DEFAULT_ICON` */ img: fields.FilePathField<{ categories: ["IMAGE"]; initial: () => typeof BaseMacro.DEFAULT_ICON; }>; /** * The scope of this Macro application from CONST.MACRO_SCOPES * @defaultValue `"global"` * @privateRemarks This field (and `CONST.MACRO_SCOPES`) is entirely vestigial, it's never checked anywhere, * and its `