FEAT: new PseudoDocumentsField

FIX: BasePseudoDocument 's getEmbeddedDocument
This commit is contained in:
Joaquin Pereyra 2025-06-08 16:13:19 -03:00
parent 70d8f37d3c
commit df23847392
3 changed files with 26 additions and 3 deletions

View file

@ -0,0 +1,22 @@
import { BasePseudoDocument } from "../pseudo-documents/_types";
export default class PseudoDocumentsField extends foundry.data.fields.TypedObjectField {
constructor(model, options = {}, context = {}) {
options.validateKey ||= ((key) => foundry.data.validators.isValidId(key));
if (!(model instanceof BasePseudoDocument)) throw new Error("The model must be a PseudoDocument");
const field = new foundry.data.fields.EmbeddedDataField(model);
super(field, options, context);
}
/** @inheritdoc */
static get _defaults() {
return Object.assign(super._defaults, {
max: Infinity
});
}
/** @override */
_validateType(value, options = {}) {
if (Object.keys(value).length > this.max) throw new Error(`cannot have more than ${this.max} elements`);
return super._validateType(value, options);
}
}