@vaadin/hilla-models 25.2.4 → 25.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"modelBuilders.js","sourceRoot":"","sources":["src/modelBuilders.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,IAAI,EACJ,KAAK,EACL,KAAK,EACL,SAAS,EACT,MAAM,GAOP,MAAM,YAAY,CAAC;AAGpB,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;AAE1C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAqB/B,MAAM,OAAO,gBAAgB;IACR,CAAC,MAAM,CAAC,CAAe;IAO1C,YAAY,IAAW,EAAE,oBAAiD;QACxE,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAE5B,IAAI,oBAAoB,EAAE,CAAC;YACzB,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAQD,IAAI,CAAC,KAAoB;QACvB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAeD,MAAM,CACJ,GAAO,EACP,KAAkC;QAQlC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO,IAAW,CAAC;IACrB,CAAC;IAWD,oBAAoB,CAAC,oBAAiD;QACpE,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;YACzB,GAAG;gBACD,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;YACpC,CAAC;SACF,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAUD,IAAI,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,E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ClD;qBACE,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;qBAC5B,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;qBAC/B,KAAK,EAAE,CAAC;gBAEX,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CAMF","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-indexed-object-style */\nimport {\n $defaultValue,\n $key,\n $meta,\n $name,\n $optional,\n $owner,\n type AnyObject,\n type DefaultValueProvider,\n type TargetModel,\n type Model,\n type ModelConverter,\n type ModelMetadata,\n} from './Model.js';\nimport type { ObjectModel } from './models.js';\n\nconst { create, defineProperty } = Object;\n\nconst $model = Symbol('model');\n\n/**\n * The flags for the model constructor that allow to determine specific characteristics of the model.\n */\nexport type Flags = {\n /**\n * Defines if the model is named.\n */\n named: boolean;\n};\n\n/**\n * A builder class for creating all basic models.\n * @internal low-level API for internal use only.\n *\n * @typeParam V - The final value type of the model.\n * @typeParam EX - The extra properties of the model.\n * @typeParam F - The flags for the model constructor that allow to determine\n * specific characteristics of the model.\n */\nexport class CoreModelBuilder<V, EX extends AnyObject = AnyObject, F extends Flags = { named: false }> {\n protected readonly [$model]: Model<V, EX>;\n\n /**\n * @param base - The base model to extend.\n * @param defaultValueProvider - The function that provides the default value\n * for the model.\n */\n constructor(base: Model, defaultValueProvider?: (model: Model<V, EX>) => V) {\n this[$model] = create(base);\n\n if (defaultValueProvider) {\n this.defaultValueProvider(defaultValueProvider);\n }\n }\n\n /**\n * Appends metadata to the model.\n *\n * @param value - The metadata to append.\n * @returns The current builder instance.\n */\n meta(value: ModelMetadata): this {\n this.define($meta, { value });\n return this;\n }\n\n /**\n * Defines a new property on the model. The property serves the purposes of\n * storing the extra data for specific types of models.\n *\n * @remarks\n * The key of the property should be a symbol to avoid conflicts with\n * properties defined via\n * {@link ObjectModelBuilder}.\n *\n * @param key - The key of the property.\n * @param value - The descriptor of the property.\n * @returns The current builder instance.\n */\n define<const DK extends symbol, const DV>(\n key: DK,\n value: TypedPropertyDescriptor<DV>,\n ): CoreModelBuilder<\n V,\n {\n readonly [key in keyof EX | DK]: key extends DK ? DV : key extends keyof EX ? EX[key] : never;\n },\n F\n > {\n defineProperty(this[$model], key, value);\n return this as any;\n }\n\n /**\n * Sets the default value provider for the model. This is an alternative way\n * to provide the default value for the model if for some reason using the\n * constructor parameter is undesired.\n *\n * @param defaultValueProvider - The function that provides the default value\n * for the model.\n * @returns The current builder instance.\n */\n defaultValueProvider(defaultValueProvider: DefaultValueProvider<V, EX>): this {\n this.define($defaultValue, {\n get(this: Model<V, EX>) {\n return defaultValueProvider(this);\n },\n });\n return this;\n }\n\n /**\n * Sets the name of the model. The name is used for debugging purposes and is\n * displayed in the string representation. Setting the name is required;\n * otherwise, the {@link CoreModelBuilder.build} method won't be available.\n *\n * @param name - The name of the model.\n * @returns The current builder instance.\n */\n name(name: string): CoreModelBuilder<V, EX, { named: true }> {\n return this.define($name, { value: name }) as any;\n }\n\n /**\n * Builds the model. On the typing level, it checks if all the model parts are\n * set correctly and raises an error if not.\n *\n * @returns The model.\n */\n build(this: F['named'] extends true ? this : never): AnyObject extends EX ? Model<V> : Model<V, EX> {\n return this[$model];\n }\n}\n\n/**\n * A registry for the property models of the object model. Since the property\n * registration is lazy, we cannot store the property models directly on the\n * object model, so the registry plays a role of a private storage for them.\n *\n * @internal\n */\nconst propertyRegistry = new WeakMap<Model, Record<string, Model>>();\n\n/**\n * A builder class for creating object models.\n * @internal low-level API for internal use only.\n *\n * @typeParam V - The final value type of the model.\n * @typeParam CV - The current value type of the model. It changes as the model\n * is being built and defines if the\n * {@link ObjectModelBuilder.build} method can be called.\n * @typeParam EX - The extra properties of the model.\n * @typeParam F - The flags for the model constructor that allow to determine\n * specific characteristics of the model.\n */\nexport class ObjectModelBuilder<\n V extends AnyObject,\n CV extends AnyObject = AnyObject,\n EX extends AnyObject = AnyObject,\n F extends Flags = { named: false },\n> extends CoreModelBuilder<\n V,\n {\n readonly [K in keyof EX]: EX[K] extends ModelConverter ? TargetModel<EX[K], ObjectModel<V, EX>> : EX[K];\n },\n F\n> {\n constructor(base: Model) {\n super(base, (m) => {\n const result: Record<string, unknown> = {};\n\n // eslint-disable-next-line no-restricted-syntax\n for (const key in m) {\n const keyModel = m[key as keyof Model<V, EX>] as Model;\n result[key] = keyModel[$optional] ? undefined : keyModel[$defaultValue];\n // defineProperty(result, key, {\n // enumerable: true,\n // value: keyModel[$optional] ? undefined : keyModel[$defaultValue],\n // });\n }\n\n return result as V;\n });\n }\n\n /**\n * The method that should follow the {@link m.extend} method. It allows to\n * declare the extension for the model and properly name it.\n *\n * @param name - The name of the model.\n */\n object<NV extends V>(\n this: F['named'] extends false ? this : never,\n name: string,\n ): ObjectModelBuilder<NV, CV, EX, { named: true }> {\n return this.name(name) as any;\n }\n\n /**\n * {@inheritDoc CoreModelBuilder.define}\n */\n // @ts-ignore: TypeScript has difficulties with the override type here\n declare ['define']: <const DK extends symbol, DV>(\n key: DK,\n value: TypedPropertyDescriptor<DV>,\n ) => ObjectModelBuilder<\n V,\n CV,\n {\n readonly [key in keyof EX | DK]: key extends DK ? DV : key extends keyof EX ? EX[key] : never;\n },\n F\n >;\n\n /**\n * {@inheritDoc CoreModelBuilder.meta}\n */\n declare ['meta']: (value: ModelMetadata) => this;\n\n /**\n * Defines a new model property on the model. Unlike the\n * {@link ObjectModelBuilder.define}, this property is public and allows the\n * user to interact with the model data structure. It also updates the current\n * value type of the model to make it closer to the final value type.\n *\n * @param key - The key of the property.\n * @param model - The model of the property value. You can also provide a\n * function that produces the model based on the current model.\n *\n * @returns The current builder instance updated with the new property type.\n */\n property<const PK extends string & keyof V, const M extends Model<V[PK]>>(\n key: PK,\n model: M,\n ): ObjectModelBuilder<\n V,\n {\n readonly [key in keyof CV | PK]: key extends PK ? V[PK] : key extends keyof CV ? CV[key] : never;\n },\n {\n readonly [key in keyof EX | PK]: key extends PK ? M : key extends keyof EX ? EX[key] : never;\n },\n F\n >;\n property<const PK extends string & keyof V, const MC extends ModelConverter>(\n key: PK,\n model: MC,\n ): ObjectModelBuilder<\n V,\n {\n readonly [key in keyof CV | PK]: key extends PK ? V[PK] : key extends keyof CV ? CV[key] : never;\n },\n {\n readonly [key in keyof EX | PK]: key extends PK ? MC : key extends keyof EX ? EX[key] : never;\n },\n F\n >;\n property<PK extends string & keyof V, M extends Model<V[PK]>>(\n key: PK,\n model: M | ((model: Model<V, EX>) => M),\n ): unknown {\n defineProperty(this[$model], key, {\n enumerable: true,\n get(this: Model<V, EX & { readonly [key in PK]: M }>) {\n if (!propertyRegistry.has(this)) {\n propertyRegistry.set(this, {});\n }\n\n const props = propertyRegistry.get(this)!;\n\n props[key] ??= new CoreModelBuilder<V[PK], object, { named: true }>(\n typeof model === 'function' ? model(this) : model,\n )\n .define($key, { value: key })\n .define($owner, { value: this })\n .build();\n\n return props[key];\n },\n });\n\n return this;\n }\n\n /**\n * {@inheritDoc CoreModelBuilder.build}\n */\n declare build: (this: F['named'] extends true ? (CV extends V ? this : never) : never) => ObjectModel<V, EX>;\n}\n"]}
1
+ {"version":3,"file":"modelBuilders.js","sourceRoot":"","sources":["src/modelBuilders.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,IAAI,EACJ,KAAK,EACL,KAAK,EACL,SAAS,EACT,MAAM,GAOP,MAAM,YAAY,CAAC;AAGpB,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;AAE1C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAqB/B,MAAM,OAAO,gBAAgB;IACR,CAAC,MAAM,CAAC,CAAe;IAO1C,YAAY,IAAW,EAAE,oBAAiD;QACxE,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAE5B,IAAI,oBAAoB,EAAE,CAAC;YAC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AAC,CAAC,CAAC;IACL,CAAC;IAQD,MAAM,CAEJ,IAAY;QAEZ,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAQ,CAAC;IAChC,CAAC;IA6DD,QAAQ,CACN,GAAO,EACP,KAAuC;QAEvC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE;YAChC,UAAU,EAAE,IAAI;YAChB,GAAG;gBACD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBAChC,gBAAgB,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACjC,CAAC;gBAED,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;gBAE1C,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,gBAAgB,CACjC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAClD;qBACE,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;qBAC5B,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;qBAC/B,KAAK,EAAE,CAAC;gBAEX,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CAMF","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-indexed-object-style */\nimport {\n $defaultValue,\n $key,\n $meta,\n $name,\n $optional,\n $owner,\n type AnyObject,\n type DefaultValueProvider,\n type TargetModel,\n type Model,\n type ModelConverter,\n type ModelMetadata,\n} from './Model.js';\nimport type { ObjectModel } from './models.js';\n\nconst { create, defineProperty } = Object;\n\nconst $model = Symbol('model');\n\n/**\n * The flags for the model constructor that allow to determine specific characteristics of the model.\n */\nexport type Flags = {\n /**\n * Defines if the model is named.\n */\n named: boolean;\n};\n\n/**\n * A builder class for creating all basic models.\n * @internal low-level API for internal use only.\n *\n * @typeParam V - The final value type of the model.\n * @typeParam EX - The extra properties of the model.\n * @typeParam F - The flags for the model constructor that allow to determine\n * specific characteristics of the model.\n */\nexport class CoreModelBuilder<V, EX extends AnyObject = AnyObject, F extends Flags = { named: false }> {\n protected readonly [$model]: Model<V, EX>;\n\n /**\n * @param base - The base model to extend.\n * @param defaultValueProvider - The function that provides the default value\n * for the model.\n */\n constructor(base: Model, defaultValueProvider?: (model: Model<V, EX>) => V) {\n this[$model] = create(base);\n\n if (defaultValueProvider) {\n this.defaultValueProvider(defaultValueProvider);\n }\n }\n\n /**\n * Appends metadata to the model.\n *\n * @param value - The metadata to append.\n * @returns The current builder instance.\n */\n meta(value: ModelMetadata): this {\n this.define($meta, { value });\n return this;\n }\n\n /**\n * Defines a new property on the model. The property serves the purposes of\n * storing the extra data for specific types of models.\n *\n * @remarks\n * The key of the property should be a symbol to avoid conflicts with\n * properties defined via\n * {@link ObjectModelBuilder}.\n *\n * @param key - The key of the property.\n * @param value - The descriptor of the property.\n * @returns The current builder instance.\n */\n define<const DK extends symbol, const DV>(\n key: DK,\n value: TypedPropertyDescriptor<DV>,\n ): CoreModelBuilder<\n V,\n {\n readonly [key in keyof EX | DK]: key extends DK ? DV : key extends keyof EX ? EX[key] : never;\n },\n F\n > {\n defineProperty(this[$model], key, value);\n return this as any;\n }\n\n /**\n * Sets the default value provider for the model. This is an alternative way\n * to provide the default value for the model if for some reason using the\n * constructor parameter is undesired.\n *\n * @param defaultValueProvider - The function that provides the default value\n * for the model.\n * @returns The current builder instance.\n */\n defaultValueProvider(defaultValueProvider: DefaultValueProvider<V, EX>): this {\n this.define($defaultValue, {\n get(this: Model<V, EX>) {\n return defaultValueProvider(this);\n },\n });\n return this;\n }\n\n /**\n * Sets the name of the model. The name is used for debugging purposes and is\n * displayed in the string representation. Setting the name is required;\n * otherwise, the {@link CoreModelBuilder.build} method won't be available.\n *\n * @param name - The name of the model.\n * @returns The current builder instance.\n */\n name(name: string): CoreModelBuilder<V, EX, { named: true }> {\n return this.define($name, { value: name }) as any;\n }\n\n /**\n * Builds the model. On the typing level, it checks if all the model parts are\n * set correctly and raises an error if not.\n *\n * @returns The model.\n */\n build(this: F['named'] extends true ? this : never): AnyObject extends EX ? Model<V> : Model<V, EX> {\n return this[$model];\n }\n}\n\n/**\n * A registry for the property models of the object model. Since the property\n * registration is lazy, we cannot store the property models directly on the\n * object model, so the registry plays a role of a private storage for them.\n *\n * @internal\n */\nconst propertyRegistry = new WeakMap<Model, Record<string, Model>>();\n\n/**\n * A builder class for creating object models.\n * @internal low-level API for internal use only.\n *\n * @typeParam V - The final value type of the model.\n * @typeParam CV - The current value type of the model. It changes as the model\n * is being built and defines if the\n * {@link ObjectModelBuilder.build} method can be called.\n * @typeParam EX - The extra properties of the model.\n * @typeParam F - The flags for the model constructor that allow to determine\n * specific characteristics of the model.\n */\nexport class ObjectModelBuilder<\n V extends AnyObject,\n CV extends AnyObject = AnyObject,\n EX extends AnyObject = AnyObject,\n F extends Flags = { named: false },\n> extends CoreModelBuilder<\n V,\n {\n readonly [K in keyof EX]: EX[K] extends ModelConverter ? TargetModel<EX[K], ObjectModel<V, EX>> : EX[K];\n },\n F\n> {\n constructor(base: Model) {\n super(base, (m) => {\n const result: Record<string, unknown> = {};\n\n // eslint-disable-next-line no-restricted-syntax\n for (const key in m) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const keyModel = m[key as keyof Model<V, EX>] as Model;\n result[key] = keyModel[$optional] ? undefined : keyModel[$defaultValue];\n // defineProperty(result, key, {\n // enumerable: true,\n // value: keyModel[$optional] ? undefined : keyModel[$defaultValue],\n // });\n }\n\n return result as V;\n });\n }\n\n /**\n * The method that should follow the {@link m.extend} method. It allows to\n * declare the extension for the model and properly name it.\n *\n * @param name - The name of the model.\n */\n object<NV extends V>(\n this: F['named'] extends false ? this : never,\n name: string,\n ): ObjectModelBuilder<NV, CV, EX, { named: true }> {\n return this.name(name) as any;\n }\n\n /**\n * {@inheritDoc CoreModelBuilder.define}\n */\n // @ts-ignore: TypeScript has difficulties with the override type here\n declare ['define']: <const DK extends symbol, DV>(\n key: DK,\n value: TypedPropertyDescriptor<DV>,\n ) => ObjectModelBuilder<\n V,\n CV,\n {\n readonly [key in keyof EX | DK]: key extends DK ? DV : key extends keyof EX ? EX[key] : never;\n },\n F\n >;\n\n /**\n * {@inheritDoc CoreModelBuilder.meta}\n */\n declare ['meta']: (value: ModelMetadata) => this;\n\n /**\n * Defines a new model property on the model. Unlike the\n * {@link ObjectModelBuilder.define}, this property is public and allows the\n * user to interact with the model data structure. It also updates the current\n * value type of the model to make it closer to the final value type.\n *\n * @param key - The key of the property.\n * @param model - The model of the property value. You can also provide a\n * function that produces the model based on the current model.\n *\n * @returns The current builder instance updated with the new property type.\n */\n property<const PK extends string & keyof V, const M extends Model<V[PK]>>(\n key: PK,\n model: M,\n ): ObjectModelBuilder<\n V,\n {\n readonly [key in keyof CV | PK]: key extends PK ? V[PK] : key extends keyof CV ? CV[key] : never;\n },\n {\n readonly [key in keyof EX | PK]: key extends PK ? M : key extends keyof EX ? EX[key] : never;\n },\n F\n >;\n property<const PK extends string & keyof V, const MC extends ModelConverter>(\n key: PK,\n model: MC,\n ): ObjectModelBuilder<\n V,\n {\n readonly [key in keyof CV | PK]: key extends PK ? V[PK] : key extends keyof CV ? CV[key] : never;\n },\n {\n readonly [key in keyof EX | PK]: key extends PK ? MC : key extends keyof EX ? EX[key] : never;\n },\n F\n >;\n property<PK extends string & keyof V, M extends Model<V[PK]>>(\n key: PK,\n model: M | ((model: Model<V, EX>) => M),\n ): unknown {\n defineProperty(this[$model], key, {\n enumerable: true,\n get(this: Model<V, EX & { readonly [key in PK]: M }>) {\n if (!propertyRegistry.has(this)) {\n propertyRegistry.set(this, {});\n }\n\n const props = propertyRegistry.get(this)!;\n\n props[key] ??= new CoreModelBuilder<V[PK], object, { named: true }>(\n typeof model === 'function' ? model(this) : model,\n )\n .define($key, { value: key })\n .define($owner, { value: this })\n .build();\n\n return props[key];\n },\n });\n\n return this;\n }\n\n /**\n * {@inheritDoc CoreModelBuilder.build}\n */\n declare build: (this: F['named'] extends true ? (CV extends V ? this : never) : never) => ObjectModel<V, EX>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/hilla-models",
3
- "version": "25.2.4",
3
+ "version": "25.2.5",
4
4
  "description": "Generative form models for Hilla",
5
5
  "main": "index.js",
6
6
  "module": "index.js",