@vaadin/hilla-models 25.1.2 → 25.1.3

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":"ConstraintBuilder.js","sourceRoot":"","sources":["src/ConstraintBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EAIrB,aAAa,EACb,KAAK,EAEL,KAAK,GAEN,MAAM,YAAY,CAAC;AAepB,MAAM,OAAO,iBAAiB;IAC5B,eAAe,CAAW;IAChB,CAAC,KAAK,CAAC,CAAgB;IACxB,kBAAkB,CAAc;IAEzC;QACE,IAAI,CAAC,eAAe,GAAG,KAA4B,CAAC;QACpD,IAAI,CAAC,kBAAkB,GAAG,EAA4B,CAAC;IACzD,CAAC;IAOD,KAAK,CAA2B,cAAiB;QAC/C,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,OAAO,IAAW,CAAC;IACrB,CAAC;IAQD,IAAI,CAAqB,IAAQ;QAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;QACnB,OAAO,IAAW,CAAC;IACrB,CAAC;IASD,SAAS,CACP,IAAQ,EACR,KAAgB;QAMf,IAAI,CAAC,kBAA8C,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;QAClF,OAAO,IAAW,CAAC;IACrB,CAAC;IAQD,KAAK;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,MAAM,iBAAiB,GAAG,IAAI,CAAC,kBAAkB,CAAC;QAClD,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC;QAE5C,SAAS,oBAAoB,CAAC,KAAe;YAC3C,IAAI,CAAC,CAAC,KAAK,YAAY,cAAc,CAAC,EAAE,CAAC;gBACvC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,qCAAqC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChG,CAAC;QACH,CAAC;QAED,IAAI,uBAAuB,GAAG,CAAC,CAAC,iBAA2B,EAAE,EAAE;YAC7D,MAAM,UAAU,GAAgB;gBAC9B,GAAG,iBAAiB;gBACpB,GAAG,CAAC,OAAO,iBAAiB,KAAK,QAAQ,IAAI,iBAAiB,KAAK,IAAI;oBACrE,CAAC,CAAC,iBAAiB;oBACnB,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;aAClC,CAAC;YAEF,OAAO,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,EAAE;gBACrE,UAAU,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE;aAClC,CAAoC,CAAC;QACxC,CAAC,CAA8C,CAAC;QAEhD,uBAAuB,GAAG,MAAM,CAAC,gBAAgB,CAAC,uBAAuB,EAAE;YACzE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;YACrB,CAAC,qBAAqB,CAAC,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE;SACzD,CAAiD,CAAC;QAEnD,OAAO,uBAAuE,CAAC;IACjF,CAAC;CACF","sourcesContent":["import type { EmptyObject } from 'type-fest';\nimport {\n $assertSupportedModel,\n type Constraint,\n type ConstraintFn,\n type NonAttributedConstraint,\n $defaultValue,\n $name,\n type AnyObject,\n Model,\n type Value,\n} from './Model.js';\n\n/**\n * A builder class for declaring constraints.\n * @internal low-level API for internal use only.\n *\n * @typeParam V - The value type of the constraint.\n * @typeParam N - The name of the constraint.\n * @typeParam A - The attributes for the constraint function, object with string\n * keys and arbitrary values. Attributes are required or optional settings for\n * a particular constraint, for example, the 'min' and 'max' settings for the\n * `Size({min, max})` constraint. When the `value` attribute is the only one,\n * the value can be given directly as the first argument of the constraint\n * function; otherwise the attribute object should be provided.\n */\nexport class ConstraintBuilder<V = unknown, const N extends string = string, A extends AnyObject = EmptyObject> {\n #supportedModel: Model<V>;\n protected [$name]: N | undefined;\n readonly #attributeDefaults: Required<A>;\n\n constructor() {\n this.#supportedModel = Model as unknown as Model<V>;\n this.#attributeDefaults = {} as unknown as Required<A>;\n }\n\n /**\n * Sets the model that the constraint is applicable to.\n *\n * @param supportedModel - The model that the constraint is applicable to.\n */\n model<const M extends Model<V>>(supportedModel: M): ConstraintBuilder<Value<M>, N, A> {\n this.#supportedModel = supportedModel;\n return this as any;\n }\n\n /**\n * Sets the name of the constraint.\n *\n * @param name - the name of the constraint.\n * @returns The current builder instance updated with the new name.\n */\n name<const NN extends N>(name: NN): ConstraintBuilder<V, N & NN, A> {\n this[$name] = name;\n return this as any;\n }\n\n /**\n * Defines a new attribute for the constraint.\n *\n * @param name - the name of the attribute.\n * @param model - the model of the attribute value.\n * @returns The current builder instance updated with the new attribute.\n */\n attribute<AN extends string, AV>(\n name: AN,\n model: Model<AV>,\n ): ConstraintBuilder<\n V,\n N,\n (A extends EmptyObject ? AnyObject : A) & Readonly<undefined extends AV ? Partial<Record<AN, AV>> : Record<AN, AV>>\n > {\n (this.#attributeDefaults as Record<string, unknown>)[name] = model[$defaultValue];\n return this as any;\n }\n\n /**\n * Builds the constraint declaration. On the typing level, it checks if all the\n * constraint parts are set correctly and raises an error if not.\n *\n * @returns The constraint declaration.\n */\n build(this: string extends N ? never : this): NonAttributedConstraint<V | undefined, N, A> {\n const name = this[$name];\n const attributeDefaults = this.#attributeDefaults;\n const supportedModel = this.#supportedModel;\n\n function assertSupportedModel(model: Model<V>): void {\n if (!(model instanceof supportedModel)) {\n throw new Error(`The constraint \"${name}\" is not applicable to the model \"${model[$name]}\".`);\n }\n }\n\n let NonAttributedConstraint = ((valueOrAttributes?: unknown) => {\n const attributes: Required<A> = {\n ...attributeDefaults,\n ...(typeof valueOrAttributes === 'object' && valueOrAttributes !== null\n ? valueOrAttributes\n : { value: valueOrAttributes }),\n };\n\n return Object.defineProperties(Object.create(NonAttributedConstraint), {\n attributes: { value: attributes },\n }) as Constraint<V | undefined, N, A>;\n }) as unknown as ConstraintFn<V | undefined, A>;\n\n NonAttributedConstraint = Object.defineProperties(NonAttributedConstraint, {\n name: { value: name },\n [$assertSupportedModel]: { value: assertSupportedModel },\n }) as NonAttributedConstraint<V | undefined, N, A>;\n\n return NonAttributedConstraint as NonAttributedConstraint<V | undefined, N, A>;\n }\n}\n"]}
1
+ {"version":3,"file":"ConstraintBuilder.js","sourceRoot":"","sources":["src/ConstraintBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EAIrB,aAAa,EACb,KAAK,EAEL,KAAK,GAEN,MAAM,YAAY,CAAC;AAepB,MAAM,OAAO,iBAAiB;IAC5B,eAAe,CAAW;IAChB,CAAC,KAAK,CAAC,CAAgB;IACxB,kBAAkB,CAAc;IAEzC;QACE,IAAI,CAAC,eAAe,GAAG,KAA4B,CAAC;QACpD,IAAI,CAAC,kBAAkB,GAAG,EAA4B,CAAC;IACzD,CAAC;IAOD,KAAK,CAA2B,cAAiB;QAC/C,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,OAAO,IAAW,CAAC;IACrB,CAAC;IAQD,IAAI,CAAqB,IAAQ;QAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;QACnB,OAAO,IAAW,CAAC;IACrB,CAAC;IASD,SAAS,CACP,IAAQ,EACR,KAAgB;QAMf,IAAI,CAAC,kBAA8C,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;QAClF,OAAO,IAAW,CAAC;IACrB,CAAC;IAQD,KAAK;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,MAAM,iBAAiB,GAAG,IAAI,CAAC,kBAAkB,CAAC;QAClD,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC;QAE5C,SAAS,oBAAoB,CAAC,KAAe;YAC3C,IAAI,CAAC,CAAC,KAAK,YAAY,cAAc,CAAC,EAAE,CAAC;gBACvC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,qCAAqC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChG,CAAC;QACH,CAAC;QAED,IAAI,uBAAuB,GAAG,CAAC,CAAC,iBAA2B,EAAE,EAAE;YAC7D,MAAM,UAAU,GAAgB;gBAC9B,GAAG,iBAAiB;gBACpB,GAAG,CAAC,OAAO,iBAAiB,KAAK,QAAQ,IAAI,iBAAiB,KAAK,IAAI;oBACrE,CAAC,CAAC,iBAAiB;oBACnB,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;aAClC,CAAC;YAEF,OAAO,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,EAAE;gBACrE,UAAU,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE;aAClC,CAAoC,CAAC;QACxC,CAAC,CAA8C,CAAC;QAEhD,uBAAuB,GAAG,MAAM,CAAC,gBAAgB,CAAC,uBAAuB,EAAE;YACzE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;YACrB,CAAC,qBAAqB,CAAC,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE;SACzD,CAAC,CAAC;QAEH,OAAO,uBAAuE,CAAC;IACjF,CAAC;CACF","sourcesContent":["import type { EmptyObject } from 'type-fest';\nimport {\n $assertSupportedModel,\n type Constraint,\n type ConstraintFn,\n type NonAttributedConstraint,\n $defaultValue,\n $name,\n type AnyObject,\n Model,\n type Value,\n} from './Model.js';\n\n/**\n * A builder class for declaring constraints.\n * @internal low-level API for internal use only.\n *\n * @typeParam V - The value type of the constraint.\n * @typeParam N - The name of the constraint.\n * @typeParam A - The attributes for the constraint function, object with string\n * keys and arbitrary values. Attributes are required or optional settings for\n * a particular constraint, for example, the 'min' and 'max' settings for the\n * `Size({min, max})` constraint. When the `value` attribute is the only one,\n * the value can be given directly as the first argument of the constraint\n * function; otherwise the attribute object should be provided.\n */\nexport class ConstraintBuilder<V = unknown, const N extends string = string, A extends AnyObject = EmptyObject> {\n #supportedModel: Model<V>;\n protected [$name]: N | undefined;\n readonly #attributeDefaults: Required<A>;\n\n constructor() {\n this.#supportedModel = Model as unknown as Model<V>;\n this.#attributeDefaults = {} as unknown as Required<A>;\n }\n\n /**\n * Sets the model that the constraint is applicable to.\n *\n * @param supportedModel - The model that the constraint is applicable to.\n */\n model<const M extends Model<V>>(supportedModel: M): ConstraintBuilder<Value<M>, N, A> {\n this.#supportedModel = supportedModel;\n return this as any;\n }\n\n /**\n * Sets the name of the constraint.\n *\n * @param name - the name of the constraint.\n * @returns The current builder instance updated with the new name.\n */\n name<const NN extends N>(name: NN): ConstraintBuilder<V, N & NN, A> {\n this[$name] = name;\n return this as any;\n }\n\n /**\n * Defines a new attribute for the constraint.\n *\n * @param name - the name of the attribute.\n * @param model - the model of the attribute value.\n * @returns The current builder instance updated with the new attribute.\n */\n attribute<AN extends string, AV>(\n name: AN,\n model: Model<AV>,\n ): ConstraintBuilder<\n V,\n N,\n (A extends EmptyObject ? AnyObject : A) & Readonly<undefined extends AV ? Partial<Record<AN, AV>> : Record<AN, AV>>\n > {\n (this.#attributeDefaults as Record<string, unknown>)[name] = model[$defaultValue];\n return this as any;\n }\n\n /**\n * Builds the constraint declaration. On the typing level, it checks if all the\n * constraint parts are set correctly and raises an error if not.\n *\n * @returns The constraint declaration.\n */\n build(this: string extends N ? never : this): NonAttributedConstraint<V | undefined, N, A> {\n const name = this[$name];\n const attributeDefaults = this.#attributeDefaults;\n const supportedModel = this.#supportedModel;\n\n function assertSupportedModel(model: Model<V>): void {\n if (!(model instanceof supportedModel)) {\n throw new Error(`The constraint \"${name}\" is not applicable to the model \"${model[$name]}\".`);\n }\n }\n\n let NonAttributedConstraint = ((valueOrAttributes?: unknown) => {\n const attributes: Required<A> = {\n ...attributeDefaults,\n ...(typeof valueOrAttributes === 'object' && valueOrAttributes !== null\n ? valueOrAttributes\n : { value: valueOrAttributes }),\n };\n\n return Object.defineProperties(Object.create(NonAttributedConstraint), {\n attributes: { value: attributes },\n }) as Constraint<V | undefined, N, A>;\n }) as unknown as ConstraintFn<V | undefined, A>;\n\n NonAttributedConstraint = Object.defineProperties(NonAttributedConstraint, {\n name: { value: name },\n [$assertSupportedModel]: { value: assertSupportedModel },\n });\n\n return NonAttributedConstraint as NonAttributedConstraint<V | undefined, N, A>;\n }\n}\n"]}
package/converters.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"converters.js","sourceRoot":"","sources":["src/converters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,KAAK,EACL,SAAS,GAUV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAsB,MAAM,aAAa,CAAC;AAmCzE,SAAS,oBAAoB,CAI3B,gBAAmB;IACnB,OAAO,CAAC,CAAC,gBAA0C,EAAE,GAAG,SAAyB,EAAE,EAAE;QACnF,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAAE,CAAC;YAC3C,OAAO,CAAC,KAAY,EAAE,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;QACnF,CAAC;QAED,OAAO,gBAAgB,CAAC,gBAAgB,EAAE,GAAG,SAAS,CAAC,CAAC;IAC1D,CAAC,CAAQ,CAAC;AACZ,CAAC;AASD,SAAS,QAAQ,CAAwB,KAAQ;IAC/C,OAAO,KAAK,CAAC;AACf,CAAC;AAQD,MAAM,KAAK,GAAG,QAAqB,CAAC;AACpC,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;AASzB,SAAS,YAAY,CAAwB,KAAQ;IACnD,OAAO,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,EA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K,EAAO,CAAC;AACpF,CAAC;AAQD,MAAM,CAAC,MAAM,IAAI,GAAG,oBAAoB,CAA8B,QAAQ,CAAC,CAAC","sourcesContent":["import {\n $assertSupportedModel,\n $constraints,\n $name,\n $optional,\n type $targetModel,\n type Constraint,\n type CompositeOf,\n type SourceModel,\n type TargetModel,\n type Model,\n type ModelConverter,\n type ModelMetadata,\n type Value,\n} from './Model.js';\nimport { CoreModelBuilder } from './modelBuilders.js';\nimport { $itemModel, ArrayModel, type OptionalModel } from './models.js';\n\n/**\n * Function that converts the given model.\n *\n * @param model - the model to convert\n * @returns derived model\n */\nexport type ModelConverterFn<SM extends Model = Model, TM extends Model = Model> = (\n model: SM,\n ...extraArgs: readonly any[]\n) => TM;\n\n/**\n * Universal converter function type for models and model converter functions.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport type ModelConverterCallable<\n MC extends ModelConverter,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n F extends ModelConverterFn<SourceModel<MC>, TargetModel<MC, SourceModel<MC>>>,\n> = F extends (model: Model, ...extraArgs: infer E) => Model\n ? <const IMC extends ModelConverter>(modelConverter: IMC, ...extraArgs: E) => CompositeOf<MC, IMC>\n : never;\n\n/**\n * Applies HKT signature and adds model converter callback support for the given\n * simple model converter function implementation. These additions provide\n * support for self-referencing properties in object model, i. g.,\n * `.property(m.optional(m.self))`.\n *\n * @param modelConverterFn - model function implementation\n * @returns model converter that also supports other converters as arguments,\n * for which it returns a composite model converter.\n */\nfunction createModelConverter<\n const MC extends ModelConverter,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n const F extends ModelConverterFn<SourceModel<MC>, TargetModel<MC, SourceModel<MC>>>,\n>(modelConverterFn: F): MC & F & ModelConverterCallable<MC, F> {\n return ((modelOrConverter: Model | ModelConverterFn, ...extraArgs: readonly any[]) => {\n if (typeof modelOrConverter === 'function') {\n return (model: Model) => modelConverterFn(modelOrConverter(model), ...extraArgs);\n }\n\n return modelConverterFn(modelOrConverter, ...extraArgs);\n }) as any;\n}\n\n/**\n * HKT signature for model converters that return models of the same data type\n * as the given model.\n */\nexport interface IdentityOf extends ModelConverter {\n readonly [$targetModel]: SourceModel<this>;\n}\nfunction selfImpl<const M extends Model>(model: M): M {\n return model;\n}\nexport type ModelSelf = IdentityOf & typeof selfImpl;\n\n/**\n * The model converter identity function that returns the given model.\n *\n * @param model - The model to return.\n */\nconst _self = selfImpl as ModelSelf;\nexport { _self as self };\n\n/**\n * HKT signature for optional model converter, which returns optional model\n * of the given one.\n */\nexport interface OptionalOf extends ModelConverter {\n readonly [$targetModel]: OptionalModel<SourceModel<this>>;\n}\nfunction optionalImpl<const M extends Model>(model: M) {\n return new CoreModelBuilder(model).name(model[$name]).define($optional, { value: true }).build() as OptionalModel<M>;\n}\n\n/**\n * Creates a new model that represents an optional value.\n *\n * @param base - The base model to extend.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport const optional = createModelConverter<OptionalOf, typeof optionalImpl>(optionalImpl);\n\n/**\n * HKT signature for array model converte, which returns array model with\n * items of the given model.\n */\nexport interface ArrayOf extends ModelConverter {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n readonly [$targetModel]: ArrayModel<SourceModel<this>>;\n}\nfunction arrayImpl<const M extends Model>(model: M) {\n return new CoreModelBuilder<Array<Value<M>>>(ArrayModel, (): Array<Value<M>> => [])\n .name(`Array<${model[$name]}>`)\n .define($itemModel, { value: model })\n .build() as ArrayModel<M>;\n}\n/**\n * Creates a new model that represents an array of items.\n *\n * @param itemModel - The model of the items in the array.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport const array = createModelConverter<ArrayOf, typeof arrayImpl>(arrayImpl);\n\nfunction constrainedImpl<const M extends Model>(\n this: void,\n model: M,\n constraint: Constraint<Value<M>>,\n ...moreConstraints: ReadonlyArray<Constraint<Value<M>>>\n): M {\n const previousConstraints = model[$constraints];\n const newConstraints = [constraint, ...moreConstraints];\n for (const newConstraint of newConstraints) {\n newConstraint[$assertSupportedModel](model as Model<Value<M>>);\n }\n return new CoreModelBuilder(model)\n .name(model[$name])\n .define($constraints, { value: [...previousConstraints, ...newConstraints] })\n .build() as any;\n}\n/**\n * Applies the constraints to the given model.\n *\n * @param model - The model to apply the constraints to.\n * @param constraint - The constraint to apply.\n * @param moreConstraints - Additional constraints to apply.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport const constrained = createModelConverter<IdentityOf, typeof constrainedImpl>(constrainedImpl);\n\nfunction metaImpl<const M extends Model>(this: void, model: M, metadata: ModelMetadata): M {\n return new CoreModelBuilder(model).name(model[$name]).meta(metadata).build() as M;\n}\n/**\n * Defines the metadata for the given model.\n *\n * @param model - The model to define metadata for.\n * @param metadata - The metadata to define.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport const meta = createModelConverter<IdentityOf, typeof metaImpl>(metaImpl);\n"]}
1
+ {"version":3,"file":"converters.js","sourceRoot":"","sources":["src/converters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,KAAK,EACL,SAAS,GAUV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAsB,MAAM,aAAa,CAAC;AAmCzE,SAAS,oBAAoB,CAI3B,gBAAmB;IACnB,OAAO,CAAC,CAAC,gBAA0C,EAAE,GAAG,SAAyB,EAAE,EAAE;QACnF,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAAE,CAAC;YAC3C,OAAO,CAAC,KAAY,EAAE,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;QACnF,CAAC;QAED,OAAO,gBAAgB,CAAC,gBAAgB,EAAE,GAAG,SAAS,CAAC,CAAC;IAC1D,CA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B,MAAM,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,mBAAmB,EAAE,GAAG,cAAc,CAAC,EAAE,CAAC;SAC5E,KAAK,EAAS,CAAC;AACpB,CAAC;AASD,MAAM,CAAC,MAAM,WAAW,GAAG,oBAAoB,CAAqC,eAAe,CAAC,CAAC;AAErG,SAAS,QAAQ,CAAoC,KAAQ,EAAE,QAAuB;IACpF,OAAO,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAO,CAAC;AACpF,CAAC;AAQD,MAAM,CAAC,MAAM,IAAI,GAAG,oBAAoB,CAA8B,QAAQ,CAAC,CAAC","sourcesContent":["import {\n $assertSupportedModel,\n $constraints,\n $name,\n $optional,\n type $targetModel,\n type Constraint,\n type CompositeOf,\n type SourceModel,\n type TargetModel,\n type Model,\n type ModelConverter,\n type ModelMetadata,\n type Value,\n} from './Model.js';\nimport { CoreModelBuilder } from './modelBuilders.js';\nimport { $itemModel, ArrayModel, type OptionalModel } from './models.js';\n\n/**\n * Function that converts the given model.\n *\n * @param model - the model to convert\n * @returns derived model\n */\nexport type ModelConverterFn<SM extends Model = Model, TM extends Model = Model> = (\n model: SM,\n ...extraArgs: readonly any[]\n) => TM;\n\n/**\n * Universal converter function type for models and model converter functions.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport type ModelConverterCallable<\n MC extends ModelConverter,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n F extends ModelConverterFn<SourceModel<MC>, TargetModel<MC, SourceModel<MC>>>,\n> = F extends (model: Model, ...extraArgs: infer E) => Model\n ? <const IMC extends ModelConverter>(modelConverter: IMC, ...extraArgs: E) => CompositeOf<MC, IMC>\n : never;\n\n/**\n * Applies HKT signature and adds model converter callback support for the given\n * simple model converter function implementation. These additions provide\n * support for self-referencing properties in object model, i. g.,\n * `.property(m.optional(m.self))`.\n *\n * @param modelConverterFn - model function implementation\n * @returns model converter that also supports other converters as arguments,\n * for which it returns a composite model converter.\n */\nfunction createModelConverter<\n const MC extends ModelConverter,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n const F extends ModelConverterFn<SourceModel<MC>, TargetModel<MC, SourceModel<MC>>>,\n>(modelConverterFn: F): MC & F & ModelConverterCallable<MC, F> {\n return ((modelOrConverter: Model | ModelConverterFn, ...extraArgs: readonly any[]) => {\n if (typeof modelOrConverter === 'function') {\n return (model: Model) => modelConverterFn(modelOrConverter(model), ...extraArgs);\n }\n\n return modelConverterFn(modelOrConverter, ...extraArgs);\n }) as any;\n}\n\n/**\n * HKT signature for model converters that return models of the same data type\n * as the given model.\n */\nexport interface IdentityOf extends ModelConverter {\n readonly [$targetModel]: SourceModel<this>;\n}\nfunction selfImpl<const M extends Model>(model: M): M {\n return model;\n}\nexport type ModelSelf = IdentityOf & typeof selfImpl;\n\n/**\n * The model converter identity function that returns the given model.\n *\n * @param model - The model to return.\n */\nconst _self = selfImpl as ModelSelf;\nexport { _self as self };\n\n/**\n * HKT signature for optional model converter, which returns optional model\n * of the given one.\n */\nexport interface OptionalOf extends ModelConverter {\n readonly [$targetModel]: OptionalModel<SourceModel<this>>;\n}\nfunction optionalImpl<const M extends Model>(model: M) {\n return new CoreModelBuilder(model).name(model[$name]).define($optional, { value: true }).build() as OptionalModel<M>;\n}\n\n/**\n * Creates a new model that represents an optional value.\n *\n * @param base - The base model to extend.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport const optional = createModelConverter<OptionalOf, typeof optionalImpl>(optionalImpl);\n\n/**\n * HKT signature for array model converte, which returns array model with\n * items of the given model.\n */\nexport interface ArrayOf extends ModelConverter {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n readonly [$targetModel]: ArrayModel<SourceModel<this>>;\n}\nfunction arrayImpl<const M extends Model>(model: M): ArrayModel<M> {\n return new CoreModelBuilder<Array<Value<M>>>(ArrayModel, (): Array<Value<M>> => [])\n .name(`Array<${model[$name]}>`)\n .define<typeof $itemModel, M>($itemModel, { value: model })\n .build();\n}\n/**\n * Creates a new model that represents an array of items.\n *\n * @param itemModel - The model of the items in the array.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport const array = createModelConverter<ArrayOf, typeof arrayImpl>(arrayImpl);\n\nfunction constrainedImpl<const M extends Model>(\n this: void,\n model: M,\n constraint: Constraint<Value<M>>,\n ...moreConstraints: ReadonlyArray<Constraint<Value<M>>>\n): M {\n const previousConstraints = model[$constraints];\n const newConstraints = [constraint, ...moreConstraints];\n for (const newConstraint of newConstraints) {\n newConstraint[$assertSupportedModel](model as Model<Value<M>>);\n }\n return new CoreModelBuilder(model)\n .name(model[$name])\n .define($constraints, { value: [...previousConstraints, ...newConstraints] })\n .build() as any;\n}\n/**\n * Applies the constraints to the given model.\n *\n * @param model - The model to apply the constraints to.\n * @param constraint - The constraint to apply.\n * @param moreConstraints - Additional constraints to apply.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport const constrained = createModelConverter<IdentityOf, typeof constrainedImpl>(constrainedImpl);\n\nfunction metaImpl<const M extends Model>(this: void, model: M, metadata: ModelMetadata): M {\n return new CoreModelBuilder(model).name(model[$name]).meta(metadata).build() as M;\n}\n/**\n * Defines the metadata for the given model.\n *\n * @param model - The model to define metadata for.\n * @param metadata - The metadata to define.\n */\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\nexport const meta = createModelConverter<IdentityOf, typeof metaImpl>(metaImpl);\n"]}
package/models.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,GAGN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAMtD,MAAM,CAAC,MAAM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,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAYzC,MAAM,CAAC,MAAM,SAAS,GAA2B,IAAI,gBAAgB,CAAmC,KAAK,CAAC;KAC3G,IAAI,CAAC,MAAM,CAAC;KAEZ,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAiB,EAAE,CAAC;KAC3C,oBAAoB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7D,KAAK,EAAE,CAAC","sourcesContent":["import {\n type $defaultValue,\n type $members,\n type AnyObject,\n type Enum,\n type Extensions,\n type TargetModel,\n Model,\n type ModelConverter,\n type Value,\n} from './Model.js';\nimport { CoreModelBuilder } from './modelBuilders.js';\n\n/**\n * The model of a primitive value, like `string`, `number` or `boolean`.\n */\nexport type PrimitiveModel<V = unknown> = Model<V>;\nexport const PrimitiveModel = new CoreModelBuilder(Model, (): unknown => undefined).name('primitive').build();\n\n/**\n * The model of a string value.\n */\nexport type StringModel = PrimitiveModel<string>;\nexport const StringModel = new CoreModelBuilder(PrimitiveModel, () => '').name('string').build();\n\n/**\n * The model of a number value.\n */\nexport type NumberModel = PrimitiveModel<number>;\nexport const NumberModel = new CoreModelBuilder(PrimitiveModel, () => NaN).name('number').build();\n\n/**\n * The model of a boolean value.\n */\nexport type BooleanModel = PrimitiveModel<boolean>;\nexport const BooleanModel = new CoreModelBuilder(PrimitiveModel, () => false).name('boolean').build();\n\n/**\n * The symbol that represents the ArrayModel item property.\n */\nexport const $itemModel = Symbol('itemModel');\n\n/**\n * The model of array data.\n */\nexport type ArrayModel<M extends Model = Model> = Model<\n Array<Value<M>>,\n {\n readonly [$itemModel]: M;\n }\n>;\nexport const ArrayModel: ArrayModel = new CoreModelBuilder(Model, (): unknown[] => [])\n .name('Array')\n .define($itemModel, { value: Model })\n .build();\n\n/**\n * The model of object data.\n */\nexport type ObjectModel<V, EX extends AnyObject = AnyObject> = Model<\n V,\n {\n readonly [K in keyof EX]: EX[K] extends ModelConverter ? TargetModel<EX[K], ObjectModel<V, EX>> : EX[K];\n }\n>;\nexport const ObjectModel = new CoreModelBuilder(Model, (): AnyObject => ({})).name('Object').build();\n\n/**\n * The model of a `Record<string, V>` data, which is a special case\n * of `ObjectModel<Record<string, V>>` that is used to represent an arbitrary\n * object with string keys, such as a Java `Map<String, Object>`.\n */\nexport type RecordModel<K extends string, V> = Model<Record<K, V>>;\nexport const RecordModel = new CoreModelBuilder(ObjectModel, (): Record<string, unknown> => ({}))\n .name('Record')\n .build();\n\n/**\n * The symbol that represents the `EnumModel[$enumerate]` property.\n */\nexport const $enum = Symbol('enumerate');\n\n/**\n * The model of enum data.\n */\nexport type EnumModel<T extends typeof Enum> = Model<\n T[keyof T],\n {\n readonly [$enum]: T;\n }\n>;\n\nexport const EnumModel: EnumModel<typeof Enum> = new CoreModelBuilder<(typeof Enum)[keyof typeof Enum]>(Model)\n .name('Enum')\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n .define($enum, { value: {} as typeof Enum })\n .defaultValueProvider((self) => Object.values(self[$enum])[0])\n .build();\n\n/**\n * The model of a union data.\n */\nexport type UnionModel<MM extends Model[]> = Model<Value<MM[number]>, { readonly [$members]: MM }>;\n\n/**\n * The model of an optional type.\n */\nexport type OptionalModel<M extends Model> = Model<\n M[typeof $defaultValue] | undefined,\n Extensions<M> & {\n readonly $optional: true;\n }\n>;\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,GAGN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAMtD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,gBAAgB,CAAC,KAAK,EAAE,GAAY,EAAE,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAA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CAAC;KAC3G,IAAI,CAAC,MAAM,CAAC;KACZ,MAAM,CAA4B,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;KACvD,oBAAoB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7D,KAAK,EAAE,CAAC","sourcesContent":["import {\n type $defaultValue,\n type $members,\n type AnyObject,\n type Enum,\n type Extensions,\n type TargetModel,\n Model,\n type ModelConverter,\n type Value,\n} from './Model.js';\nimport { CoreModelBuilder } from './modelBuilders.js';\n\n/**\n * The model of a primitive value, like `string`, `number` or `boolean`.\n */\nexport type PrimitiveModel<V = unknown> = Model<V>;\nexport const PrimitiveModel = new CoreModelBuilder(Model, (): unknown => undefined).name('primitive').build();\n\n/**\n * The model of a string value.\n */\nexport type StringModel = PrimitiveModel<string>;\nexport const StringModel = new CoreModelBuilder(PrimitiveModel, () => '').name('string').build();\n\n/**\n * The model of a number value.\n */\nexport type NumberModel = PrimitiveModel<number>;\nexport const NumberModel = new CoreModelBuilder(PrimitiveModel, () => NaN).name('number').build();\n\n/**\n * The model of a boolean value.\n */\nexport type BooleanModel = PrimitiveModel<boolean>;\nexport const BooleanModel = new CoreModelBuilder(PrimitiveModel, () => false).name('boolean').build();\n\n/**\n * The symbol that represents the ArrayModel item property.\n */\nexport const $itemModel = Symbol('itemModel');\n\n/**\n * The model of array data.\n */\nexport type ArrayModel<M extends Model = Model> = Model<\n Array<Value<M>>,\n {\n readonly [$itemModel]: M;\n }\n>;\nexport const ArrayModel: ArrayModel = new CoreModelBuilder(Model, (): unknown[] => [])\n .name('Array')\n .define($itemModel, { value: Model })\n .build();\n\n/**\n * The model of object data.\n */\nexport type ObjectModel<V, EX extends AnyObject = AnyObject> = Model<\n V,\n {\n readonly [K in keyof EX]: EX[K] extends ModelConverter ? TargetModel<EX[K], ObjectModel<V, EX>> : EX[K];\n }\n>;\nexport const ObjectModel = new CoreModelBuilder(Model, (): AnyObject => ({})).name('Object').build();\n\n/**\n * The model of a `Record<string, V>` data, which is a special case\n * of `ObjectModel<Record<string, V>>` that is used to represent an arbitrary\n * object with string keys, such as a Java `Map<String, Object>`.\n */\nexport type RecordModel<K extends string, V> = Model<Record<K, V>>;\nexport const RecordModel = new CoreModelBuilder(ObjectModel, (): Record<string, unknown> => ({}))\n .name('Record')\n .build();\n\n/**\n * The symbol that represents the `EnumModel[$enumerate]` property.\n */\nexport const $enum = Symbol('enumerate');\n\n/**\n * The model of enum data.\n */\nexport type EnumModel<T extends typeof Enum> = Model<\n T[keyof T],\n {\n readonly [$enum]: T;\n }\n>;\n\nexport const EnumModel: EnumModel<typeof Enum> = new CoreModelBuilder<(typeof Enum)[keyof typeof Enum]>(Model)\n .name('Enum')\n .define<typeof $enum, typeof Enum>($enum, { value: {} })\n .defaultValueProvider((self) => Object.values(self[$enum])[0])\n .build();\n\n/**\n * The model of a union data.\n */\nexport type UnionModel<MM extends Model[]> = Model<Value<MM[number]>, { readonly [$members]: MM }>;\n\n/**\n * The model of an optional type.\n */\nexport type OptionalModel<M extends Model> = Model<\n M[typeof $defaultValue] | undefined,\n Extensions<M> & {\n readonly $optional: true;\n }\n>;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/hilla-models",
3
- "version": "25.1.2",
3
+ "version": "25.1.3",
4
4
  "description": "Generative form models for Hilla",
5
5
  "main": "index.js",
6
6
  "module": "index.js",