Skip to content

Commit

Permalink
Merge pull request #2925 from League-of-Foundry-Developers/document-s…
Browse files Browse the repository at this point in the history
…chema-updates

Document schema updates
  • Loading branch information
LukeAbby authored Nov 11, 2024
2 parents 8b7e625 + 71d6ae5 commit 4cdb450
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/foundry/common/abstract/data.d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EmptyObject } from "../../../types/utils.d.mts";
import type { AnyObject, EmptyObject } from "../../../types/utils.d.mts";
import type { DataField, SchemaField } from "../data/fields.d.mts";
import type { fields } from "../data/module.d.mts";
import type { DataModelValidationFailure } from "../data/validation-failure.d.mts";
Expand Down Expand Up @@ -350,14 +350,14 @@ declare abstract class DataModel<
* @param source - The candidate source data from which the model will be constructed
* @returns Migrated source data, if necessary
*/
static migrateData(source: object): object;
static migrateData(source: AnyObject): AnyObject;

/**
* Wrap data migration in a try/catch which attempts it safely
* @param source - The candidate source data from which the model will be constructed
* @returns Migrated source data, if necessary
*/
static migrateDataSafe(source: object): object;
static migrateDataSafe(source: AnyObject): AnyObject;

/**
* Take data which conforms to the current data schema and add backwards-compatible accessors to it in order to
Expand Down
3 changes: 2 additions & 1 deletion src/foundry/common/abstract/document.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ declare abstract class Document<
temporary?: Temporary;
},
): Promise<Document.ToStoredIf<T, Temporary> | undefined>;

/**
* Update this Document using incremental data, saving it to the database.
* @see {@link Document.updateDocuments}
Expand All @@ -443,7 +444,7 @@ declare abstract class Document<
*
* @remarks If no document has actually been updated, the returned {@link Promise} resolves to `undefined`.
*/
override update(
update(
// TODO: Determine if this is Partial, DeepPartial, or InexactPartial.
data?: Partial<Document.ConstructorDataForSchema<Schema>>,
operation?: InexactPartial<Omit<DatabaseOperationsFor<ConcreteMetadata["name"], "update">, "updates">>,
Expand Down
4 changes: 3 additions & 1 deletion src/foundry/common/documents/actor-delta.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { fields } from "../data/module.d.mts";
import type { CONST, documents } from "../../client-esm/client.d.mts";

/**
* The Document definition for an ActorDelta.
* The ActorDelta Document.
* Defines the DataSchema and common behaviors for an ActorDelta which are shared between both client and server.
* ActorDeltas store a delta that can be applied to a particular Actor in order to produce a new Actor.
*/
Expand Down Expand Up @@ -49,6 +49,8 @@ declare class BaseActorDelta extends Document<BaseActorDelta.Schema, BaseActorDe
context: unknown,
): Document.ConfiguredClassForName<"Actor"> | null;

static migrateData(source: AnyObject): AnyObject;

//TODO: Figure out if this override still applies
toObject(source: true): this["_source"];
toObject(source?: boolean): ReturnType<this["schema"]["toObject"]>;
Expand Down
23 changes: 3 additions & 20 deletions src/foundry/common/documents/adventure.d.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { AnyObject, Merge } from "../../../types/utils.mts";
import type { DataModel } from "../abstract/data.mts";
import type { Merge } from "../../../types/utils.mts";
import type Document from "../abstract/document.mts";
import type * as fields from "../data/fields.d.mts";

/**
* The Document definition for an Adventure.
* The Adventure Document.
* Defines the DataSchema and common behaviors for an Adventure which are shared between both client and server.
*/
// Note(LukeAbby): You may wonder why documents don't simply pass the `Parent` generic parameter.
Expand Down Expand Up @@ -33,22 +32,6 @@ declare class BaseAdventure extends Document<BaseAdventure.Schema, BaseAdventure
* Provide a thumbnail image path used to represent the Adventure document.
*/
get thumbnail(): string;

static override fromSource<Schema extends DataSchema>(
source: fields.SchemaField.InnerAssignmentType<Schema>,
{
strict,
...context
}?: DataModel.ConstructorOptions<null> & {
/**
* Models created from trusted source data are validated non-strictly
* @defaultValue `false`
*/
strict?: boolean;
},
): foundry.abstract.DataModel<Schema, DataModel.Any | null>;

static override migrateData(source: AnyObject): AnyObject;
}

export default BaseAdventure;
Expand Down Expand Up @@ -203,7 +186,7 @@ declare namespace BaseAdventure {
? Key
: never]: BaseAdventure.Schema[Key] extends fields.SetField<infer ElementType, any, any, any, any, any, any, any>
? ElementType extends fields.EmbeddedDataField<infer ModelType, any, any, any, any>
? ModelType extends typeof Document // TODO: This doesn't seem to quite work to ensure it's the configured class
? ModelType extends Document.AnyConstructor // TODO: This doesn't seem to quite work to ensure it's the configured class
? ModelType["implementation"]
: ModelType
: never
Expand Down
4 changes: 3 additions & 1 deletion src/foundry/common/documents/fog-exploration.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type * as fields from "../data/fields.d.mts";
import type * as documents from "./_module.mts";

/**
* The Document definition for FogExploration.
* The FogExploration Document.
* Defines the DataSchema and common behaviors for FogExploration which are shared between both client and server.
*/
// Note(LukeAbby): You may wonder why documents don't simply pass the `Parent` generic parameter.
Expand Down Expand Up @@ -106,5 +106,7 @@ declare namespace BaseFogExploration {
* @defaultValue `{}`
*/
flags: fields.ObjectField.FlagsField<"FogExploration">;

_stats: fields.DocumentStatsField;
}
}
11 changes: 9 additions & 2 deletions src/foundry/common/documents/playlist-sound.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type Document from "../abstract/document.mts";
import type * as fields from "../data/fields.d.mts";

/**
* The Document definition for a PlaylistSound.
* The PlaylistSound Document.
* Defines the DataSchema and common behaviors for a PlaylistSound which are shared between both client and server.
*/
// Note(LukeAbby): You may wonder why documents don't simply pass the `Parent` generic parameter.
Expand Down Expand Up @@ -52,6 +52,7 @@ declare namespace BasePlaylistSound {
indexed: true;
label: string;
labelPlural: string;
compendiumIndexFields: ["name", "sort"];
schemaVersion: string;
}
>;
Expand All @@ -72,7 +73,7 @@ declare namespace BasePlaylistSound {
/**
* The name of this sound
*/
name: fields.StringField<{ required: true; blank: false }>;
name: fields.StringField<{ required: true; blank: false; textSearch: true }>;

/**
* The description of this sound
Expand All @@ -86,6 +87,12 @@ declare namespace BasePlaylistSound {
*/
path: fields.FilePathField<{ categories: ["AUDIO"] }>;

/**
* A channel in CONST.AUDIO_CHANNELS where this sound is are played
* @defaultValue `"music"`
*/
channel: fields.StringField<{ choices: typeof foundry.CONST.AUDIO_CHANNELS; initial: string; blank: false }>;

/**
* Is this sound currently playing?
* @defaultValue `false`
Expand Down
11 changes: 10 additions & 1 deletion src/foundry/common/documents/playlist.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type * as fields from "../data/fields.d.mts";
import type * as documents from "./_module.mts";

/**
* The Document definition for a Playlist.
* The Playlist Document.
* Defines the DataSchema and common behaviors for a Playlist which are shared between both client and server.
*/
// Note(LukeAbby): You may wonder why documents don't simply pass the `Parent` generic parameter.
Expand Down Expand Up @@ -53,6 +53,9 @@ declare namespace BasePlaylist {
embedded: { PlaylistSound: "sounds" };
label: string;
labelPlural: string;
permissions: {
create: "PLAYLIST_CREATE";
};
schemaVersion: string;
}
>;
Expand Down Expand Up @@ -87,6 +90,12 @@ declare namespace BasePlaylist {
*/
sounds: fields.EmbeddedCollectionField<typeof documents.BasePlaylistSound, Playlist.ConfiguredInstance>;

/**
* A channel in CONST.AUDIO_CHANNELS where all sounds in this playlist are played
* @defaultValue `"music"`
*/
channel: fields.StringField<{ choices: typeof foundry.CONST.AUDIO_CHANNELS; initial: string; blank: false }>;

/**
* The playback mode for sounds in this playlist
* @defaultValue `CONST.PLAYLIST_MODES.SEQUENTIAL`
Expand Down
14 changes: 9 additions & 5 deletions src/foundry/common/documents/setting.d.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Merge } from "../../../types/utils.mts";
import type { AnyObject, Merge } from "../../../types/utils.mts";
import type Document from "../abstract/document.mts";
import type * as fields from "../data/fields.d.mts";
import type BaseUser from "./user.d.mts";

/**
* The Document definition for a Setting.
* The Setting Document.
* Defines the DataSchema and common behaviors for a Setting which are shared between both client and server.
*/
// Note(LukeAbby): You may wonder why documents don't simply pass the `Parent` generic parameter.
Expand All @@ -22,6 +23,8 @@ declare class BaseSetting extends Document<BaseSetting.Schema, BaseSetting.Metad
static override metadata: Readonly<BaseSetting.Metadata>;

static override defineSchema(): BaseSetting.Schema;

static canUserCreate(user: BaseUser): boolean;
}

export default BaseSetting;
Expand All @@ -37,9 +40,9 @@ declare namespace BaseSetting {
label: string;
labelPlural: string;
permissions: {
create: "SETTINGS_MODIFY";
update: "SETTINGS_MODIFY";
delete: "SETTINGS_MODIFY";
create: (user: BaseUser, doc: Document.Any, data: AnyObject) => boolean;
update: (user: BaseUser, doc: Document.Any, data: AnyObject) => boolean;
delete: (user: BaseUser, doc: Document.Any, data: AnyObject) => boolean;
};
schemaVersion: string;
}
Expand Down Expand Up @@ -77,6 +80,7 @@ declare namespace BaseSetting {
value: fields.JSONField<{
required: true;
nullable: true;
initial: null;
}>;

/**
Expand Down
7 changes: 6 additions & 1 deletion src/foundry/common/documents/user.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type * as fields from "../data/fields.d.mts";
import type BaseActor from "./actor.mts";

/**
* The Document definition for a User.
* The User Document.
* Defines the DataSchema and common behaviors for a User which are shared between both client and server.
*/
// Note(LukeAbby): You may wonder why documents don't simply pass the `Parent` generic parameter.
Expand Down Expand Up @@ -39,6 +39,11 @@ declare class BaseUser extends Document<BaseUser.Schema, BaseUser.Metadata, any>
*/
static #validatePermissions(perms: AnyObject): boolean;

/**
* A convenience test for whether this User has the NONE role.
*/
get isBanned(): boolean;

/**
* Test whether the User has a GAMEMASTER or ASSISTANT role in this World?
*/
Expand Down

0 comments on commit 4cdb450

Please sign in to comment.