@vaadin/hilla-lit-form 24.5.0-alpha1 → 24.5.0-alpha10
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.
- package/BinderNode.d.ts.map +1 -1
- package/BinderNode.js +2 -6
- package/BinderNode.js.map +2 -2
- package/Field.d.ts +2 -2
- package/Field.d.ts.map +1 -1
- package/Models.d.ts +46 -3
- package/Models.d.ts.map +1 -1
- package/Models.js +62 -9
- package/Models.js.map +2 -2
- package/Validation.d.ts +1 -1
- package/Validation.d.ts.map +1 -1
- package/Validation.js +5 -4
- package/Validation.js.map +2 -2
- package/Validators.d.ts.map +1 -1
- package/Validators.js +2 -2
- package/Validators.js.map +2 -2
- package/index.js +1 -1
- package/package.json +6 -6
package/BinderNode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BinderNode.d.ts","sourceRoot":"","sources":["src/BinderNode.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAKL,aAAa,EACb,KAAK,cAAc,EAInB,KAAK,KAAK,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,eAAO,MAAM,iBAAiB,eAA6B,CAAC;AAC5D,eAAO,MAAM,OAAO,eAAmB,CAAC;AACxC,eAAO,MAAM,yBAAyB,eAAqC,CAAC;AAC5E,eAAO,MAAM,gBAAgB,eAA4B,CAAC;AAI1D,wBAAgB,aAAa,CAAC,CAAC,SAAS,aAAa,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAS9E;AAkCD,eAAO,MAAM,OAAO,OAAmC,CAAC;AAqBxD;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gB,CAAC,IAAI,OAAO;IAiBvC,SAAS,CAAC,CAAC,yBAAyB,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,GAAG,IAAI;IAiB3E,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI;cAMvB,CAAC,iBAAiB,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAgFpD,eAAe,CAAC,eAAe,UAAQ,GAAG,IAAI;CAyD/C"}
|
package/BinderNode.js
CHANGED
|
@@ -175,13 +175,9 @@ class BinderNode extends EventTarget {
|
|
|
175
175
|
if (!this.parent) {
|
|
176
176
|
return void 0;
|
|
177
177
|
}
|
|
178
|
-
|
|
179
|
-
if (value === void 0) {
|
|
180
|
-
this.parent.initializeValue(true);
|
|
181
|
-
({ value } = this.parent);
|
|
182
|
-
}
|
|
178
|
+
this.initializeValue();
|
|
183
179
|
const key = this.model[_key];
|
|
184
|
-
return value[key];
|
|
180
|
+
return this.parent.value[key];
|
|
185
181
|
}
|
|
186
182
|
set value(value) {
|
|
187
183
|
this.initializeValue();
|
package/BinderNode.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/BinderNode.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */\n/*\n * Copyright 2000-2020 Vaadin Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n// TODO: Fix dependency cycle\n\nimport type { BinderRoot } from './BinderRoot.js';\nimport {\n _createEmptyItemValue,\n _key,\n _parent,\n _validators,\n AbstractModel,\n type ArrayItemModel,\n ArrayModel,\n getObjectModelOwnAndParentGetters,\n ObjectModel,\n type Value,\n} from './Models.js';\nimport type { ClassStaticProperties } from './types.js';\nimport type { Validator, ValueError } from './Validation.js';\nimport { ValidityStateValidator } from './Validators.js';\nimport { _validity } from './Validity.js';\n\nexport const _updateValidation = Symbol('updateValidation');\nexport const _update = Symbol('update');\nexport const _setErrorsWithDescendants = Symbol('setErrorsWithDescendants');\nexport const _clearValidation = Symbol('clearValidation');\n\nconst nodes = new WeakMap<AbstractModel, BinderNode>();\n\nexport function getBinderNode<M extends AbstractModel>(model: M): BinderNode<M> {\n let node = nodes.get(model);\n\n if (!node) {\n node = new BinderNode(model);\n nodes.set(model, node);\n }\n\n return node as BinderNode<M>;\n}\n\nfunction getErrorPropertyName(valueError: ValueError): string {\n return typeof valueError.property === 'string' ? valueError.property : getBinderNode(valueError.property).name;\n}\n\nfunction updateObjectOrArrayKey<M extends AbstractModel>(\n model: M,\n value: Value<M>,\n key: keyof any,\n keyValue: unknown,\n): Value<M> {\n if (model instanceof ObjectModel) {\n // Value contained in object - replace object in parent\n return {\n ...(value as Record<never, never> & Value<M>),\n [key]: keyValue,\n };\n }\n\n if (keyValue === undefined) {\n throw new TypeError('Unexpected undefined value');\n }\n\n if (model instanceof ArrayModel) {\n // Value contained in array - replace array in parent\n const array = (value as unknown[]).slice();\n array[key as number] = keyValue;\n return array as Value<M>;\n }\n\n throw new TypeError(`Unknown model type ${(model as AbstractModel).constructor.name}`);\n}\n\nexport const CHANGED = new Event('binder-node-changed');\n\nclass NotArrayModelError extends Error {\n constructor() {\n super('The model does not represent array');\n }\n}\n\nclass NotArrayItemModelError extends Error {\n constructor() {\n super('The model does not represent array item');\n }\n}\n\ndeclare class ArrayItemBinderNode<M extends AbstractModel> extends BinderNode<M> {\n // @ts-expect-error: re-defining the parent getter.\n declare readonly parent: BinderNode<ArrayModel<M>>;\n}\n\nconst defaultArrayItemCache = new WeakMap<BinderNode, unknown>();\n\n/**\n * The BinderNode\\<M\\> class provides the form binding related APIs\n * with respect to a particular model instance.\n *\n * Structurally, model instances form a tree, in which the object\n * and array models have child nodes of field and array item model\n * instances.\n */\nexport class BinderNode<M extends AbstractModel = AbstractModel> extends EventTarget {\n declare readonly ['constructor']: ClassStaticProperties<typeof BinderNode<M>>;\n readonly model: M;\n /**\n * The validity state read from the bound element, if any. Represents the\n * HTML element internal validation.\n *\n * For elements with `validity.valid === false`, the value in the\n * bound element is considered as invalid.\n */\n [_validity]?: ValidityState;\n #ownErrors?: ReadonlyArray<ValueError<Value<M>>>;\n #validators: ReadonlyArray<Validator<Value<M>>>;\n readonly #validityStateValidator: ValidityStateValidator<Value<M>>;\n #visited = false;\n\n constructor(model: M) {\n super();\n this.model = model;\n nodes.set(model, this);\n this.#validityStateValidator = new ValidityStateValidator<Value<M>>();\n this.#validators = model[_validators];\n\n // Workaround for children initialization with private props\n if (this.constructor === BinderNode) {\n this.initializeValue();\n }\n }\n\n /**\n * The binder for the top-level model.\n */\n get binder(): BinderRoot {\n const binder = this.parent?.binder;\n\n if (!binder) {\n throw new TypeError('BinderNode is detached');\n }\n\n return binder;\n }\n\n /**\n * The default value related to the model\n */\n get defaultValue(): Value<M> | undefined {\n const key = this.model[_key];\n const parentDefaultValue = this.parent!.defaultValue as { readonly [key in typeof key]?: Value<M> };\n\n if (this.#isArrayItem() && !(key in parentDefaultValue)) {\n if (defaultArrayItemCache.has(this.parent)) {\n return defaultArrayItemCache.get(this.parent) as Value<M>;\n }\n\n const value = this.model.constructor.createEmptyValue();\n defaultArrayItemCache.set(this.parent, value);\n return value as Value<M>;\n }\n\n return parentDefaultValue[key];\n }\n\n /**\n * True if the current value is different from the defaultValue.\n */\n get dirty(): boolean {\n return this.value !== this.defaultValue;\n }\n\n /**\n * The combined array of all errors for this node\u2019s model and all its nested\n * models\n */\n get errors(): readonly ValueError[] {\n return [...Array.from(this.#getChildBinderNodes(), (node) => node.errors).flat(), ...this.ownErrors];\n }\n\n /**\n * Indicates if there is any error for the node's model.\n */\n get invalid(): boolean {\n return this.errors.length > 0;\n }\n\n /**\n * The name generated from the model structure, used to set the name\n * attribute on the field components.\n */\n get name(): string {\n let { model }: { model: AbstractModel } = this;\n let name = '';\n\n while (model[_parent] instanceof AbstractModel) {\n name = `${String(model[_key])}${name ? `.${name}` : ''}`;\n model = model[_parent];\n }\n\n return name;\n }\n\n /**\n * The array of validation errors directly related with the model.\n */\n get ownErrors(): ReadonlyArray<ValueError<Value<M>>> {\n return this.#ownErrors ? this.#ownErrors : [];\n }\n\n /**\n * The parent node, if this binder node corresponds to a nested model,\n * otherwise undefined for the top-level binder.\n */\n get parent(): BinderNode | undefined {\n const modelParent = this.model[_parent];\n return modelParent instanceof AbstractModel ? getBinderNode(modelParent) : undefined;\n }\n\n /**\n * True if the value is required to be non-empty.\n */\n get required(): boolean {\n return this.#validators.some((validator) => validator.impliesRequired);\n }\n\n /**\n * The array of validators for the model. The default value is defined in the\n * model.\n */\n get validators(): ReadonlyArray<Validator<Value<M>>> {\n return this.#validators;\n }\n\n set validators(validators: ReadonlyArray<Validator<Value<M>>>) {\n this.#validators = validators;\n this.dispatchEvent(CHANGED);\n }\n\n /**\n * The current value related to the model\n */\n get value(): Value<M> | undefined {\n if (!this.parent) {\n return undefined;\n }\n\n let { value } = this.parent;\n\n if (value === undefined) {\n this.parent.initializeValue(true);\n ({ value } = this.parent);\n }\n\n const key = this.model[_key];\n\n // The value of parent in unknown, so we need to cast it.\n type ParentValue = { readonly [K in typeof key]: Value<M> };\n return (value as ParentValue)[key];\n }\n\n set value(value: Value<M> | undefined) {\n this.initializeValue();\n this.#setValueState(value, undefined);\n }\n\n /**\n * True if the bound field was ever focused and blurred by the user.\n */\n get visited(): boolean {\n return this.#visited;\n }\n\n set visited(v: boolean) {\n if (this.#visited !== v) {\n this.#visited = v;\n this[_updateValidation]().catch(() => {});\n this.dispatchEvent(CHANGED);\n }\n }\n\n /**\n * A helper method to add a validator\n *\n * @param validator - a validator\n */\n addValidator(validator: Validator<Value<M>>): void {\n this.validators = [...this.#validators, validator];\n this.dispatchEvent(CHANGED);\n }\n\n /**\n * Append an item to the array value.\n *\n * Requires the context model to be an array reference.\n *\n * @param item - optional new item value, an empty item is\n * appended if the argument is omitted\n */\n appendItem(item?: Value<ArrayItemModel<M>>): void {\n if (this.#isArray()) {\n const itemValueOrEmptyValue = item ?? this.model[_createEmptyItemValue]();\n const newValue = [...(this.value ?? []), itemValueOrEmptyValue];\n const newDefaultValue = [...(this.defaultValue ?? []), itemValueOrEmptyValue];\n this.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayModelError();\n }\n }\n\n /**\n * Returns a binder node for the nested model instance.\n *\n * @param model - The nested model instance\n */\n for<N extends AbstractModel>(model: N): BinderNode<N> {\n const binderNode = getBinderNode(model);\n if (binderNode.binder !== this.binder) {\n throw new Error('Unknown binder');\n }\n\n return binderNode;\n }\n\n prependItem(item?: Value<ArrayItemModel<M>>): void {\n if (this.#isArray()) {\n const itemValueOrEmptyValue = item ?? this.model[_createEmptyItemValue]();\n const newValue = [itemValueOrEmptyValue, ...(this.value ?? [])];\n const newDefaultValue = [itemValueOrEmptyValue, ...(this.defaultValue ?? [])];\n this.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayModelError();\n }\n }\n\n removeSelf(): void {\n if (this.#isArrayItem()) {\n const newValue = (this.parent.value ?? []).filter((_, i) => i !== this.model[_key]);\n const newDefaultValue = (this.parent.defaultValue ?? []).filter((_, i) => i !== this.model[_key]);\n this.parent.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayItemModelError();\n }\n }\n\n /**\n * Runs all validation callbacks potentially affecting this\n * or any nested model. Returns the combined array of all\n * errors as in the errors property.\n */\n async validate(): Promise<readonly ValueError[]> {\n const errors = await Promise.all([\n ...this.#requestValidationOfDescendants(),\n ...this.#requestValidationWithAncestors(),\n ]).then((arr) => arr.flat());\n this[_setErrorsWithDescendants](errors.length ? errors : undefined);\n this[_update]();\n return errors;\n }\n\n protected [_clearValidation](): boolean {\n if (this.#visited) {\n this.#visited = false;\n this.dispatchEvent(CHANGED);\n }\n let needsUpdate = false;\n if (this.#ownErrors) {\n this.#ownErrors = undefined;\n needsUpdate = true;\n this.dispatchEvent(CHANGED);\n }\n if ([...this.#getChildBinderNodes()].filter((childBinderNode) => childBinderNode[_clearValidation]()).length > 0) {\n needsUpdate = true;\n }\n return needsUpdate;\n }\n\n protected [_setErrorsWithDescendants](errors?: readonly ValueError[]): void {\n const { name } = this;\n const ownErrors = errors\n ? (errors.filter((valueError) => getErrorPropertyName(valueError) === name) as ReadonlyArray<\n ValueError<Value<M>>\n >)\n : undefined;\n const relatedErrors = errors\n ? errors.filter((valueError) => getErrorPropertyName(valueError).startsWith(name))\n : undefined;\n this.#ownErrors = ownErrors;\n for (const childBinderNode of this.#getChildBinderNodes()) {\n childBinderNode[_setErrorsWithDescendants](relatedErrors);\n }\n this.dispatchEvent(CHANGED);\n }\n\n protected [_update](_?: Value<M>): void {\n if (this.parent) {\n this.parent[_update]();\n }\n }\n\n protected async [_updateValidation](): Promise<void> {\n if (this.#visited) {\n await this.validate();\n } else if (this.dirty || this.invalid) {\n await Promise.all(\n [...this.#getChildBinderNodes()].map(async (childBinderNode) => childBinderNode[_updateValidation]()),\n );\n }\n }\n\n *#getChildBinderNodes(): Generator<BinderNode, void, void> {\n if (this.value === undefined || this.defaultValue === undefined) {\n // Undefined value cannot have child properties and items.\n return;\n }\n\n if (this.#isObject()) {\n for (const [, getter] of getObjectModelOwnAndParentGetters(this.model)) {\n const childModel = getter.call(this.model);\n // We need to skip all non-initialised optional fields here in order\n // to prevent infinite recursion for circular references in the model.\n // Here we rely on presence of keys in `defaultValue` to detect all\n // initialised fields. The keys in `defaultValue` are defined for all\n // non-optional fields plus those optional fields whose values were\n // set from initial `binder.read()` or `binder.clear()` or by using a\n // binder node (e.g., form binding) for a nested field.\n if (childModel[_key] in (this.defaultValue as Record<never, never>)) {\n yield getBinderNode(childModel);\n }\n }\n } else if (this.#isArray()) {\n for (const childBinderNode of this.model) {\n yield childBinderNode;\n }\n }\n }\n\n #isArray(): this is BinderNode<ArrayModel> {\n return this.model instanceof ArrayModel;\n }\n\n #isArrayItem(): this is ArrayItemBinderNode<M> {\n return this.model[_parent] instanceof ArrayModel;\n }\n\n #isObject(): this is BinderNode<ObjectModel> {\n return this.model instanceof ObjectModel;\n }\n\n *#requestValidationOfDescendants(): Generator<Promise<readonly ValueError[]>, void, void> {\n for (const node of this.#getChildBinderNodes()) {\n yield* node.#runOwnValidators();\n yield* node.#requestValidationOfDescendants();\n }\n }\n\n *#requestValidationWithAncestors(): Generator<Promise<readonly ValueError[]>, void, void> {\n yield* this.#runOwnValidators();\n\n if (this.parent) {\n yield* this.parent.#requestValidationWithAncestors();\n }\n }\n\n *#runOwnValidators(): Generator<Promise<readonly ValueError[]>, void, void> {\n const hasInvalidState = this[_validity] && !this[_validity].valid;\n const hasBadInput = !!this[_validity]?.badInput;\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n if ((hasInvalidState && !hasBadInput) || !hasInvalidState) {\n for (const validator of this.#validators) {\n yield this.binder.requestValidation(this.model, validator);\n }\n }\n\n if (hasInvalidState) {\n yield this.binder.requestValidation(this.model, this.#validityStateValidator);\n }\n }\n\n initializeValue(forceInitialize = false): void {\n // First, make sure parents have value initialized\n if (\n this.parent &&\n (this.parent.value === undefined || (this.parent.defaultValue as Value<M> | undefined) === undefined)\n ) {\n this.parent.initializeValue(true);\n }\n\n const key = this.model[_key];\n let value: Value<M> | undefined = this.parent\n ? (this.parent.value as { [key in typeof key]: Value<M> })[this.model[_key]]\n : undefined;\n\n const defaultValue: Value<M> | undefined = this.parent\n ? (this.parent.defaultValue as { readonly [key in typeof key]: Value<M> })[this.model[_key]]\n : undefined;\n\n if (value === undefined) {\n // Initialize value if this is the root level node, or it is enforced\n if (forceInitialize || !this.parent) {\n value = this.model.constructor.createEmptyValue() as Value<M>;\n this.#setValueState(value, defaultValue === undefined ? value : defaultValue);\n } else if (\n this.parent.model instanceof ObjectModel &&\n !(key in ((this.parent.value || {}) as { [key in typeof key]?: Value<M> }))\n ) {\n this.#setValueState(undefined, defaultValue === undefined ? value : defaultValue);\n }\n }\n }\n\n #setValueState(value: Value<M> | undefined, defaultValue: Value<M> | undefined): void {\n const { parent } = this;\n if (parent) {\n const key = this.model[_key];\n const parentValue = updateObjectOrArrayKey(parent.model, parent.value, key, value);\n const keepPristine = value === defaultValue && parent.value === parent.defaultValue;\n if (keepPristine) {\n // Keep value and defaultValue equal, so that `dirty` stays false\n parent.#setValueState(parentValue, parentValue);\n } else if (defaultValue !== undefined) {\n // Update value and defaultValue at the same time with different content\n const parentDefaultValue = updateObjectOrArrayKey(parent.model, parent.defaultValue, key, defaultValue);\n parent.#setValueState(parentValue, parentDefaultValue);\n } else {\n parent.#setValueState(parentValue, undefined);\n }\n } else {\n // Root level model - update the binder root\n const binder = this as unknown as BinderRoot<M>;\n if (defaultValue !== undefined) {\n binder.defaultValue = defaultValue;\n }\n binder.value = value!;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAmBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAGP,SAAS,8BAA8B;AACvC,SAAS,iBAAiB;AAEnB,MAAM,oBAAoB,OAAO,kBAAkB;AACnD,MAAM,UAAU,OAAO,QAAQ;AAC/B,MAAM,4BAA4B,OAAO,0BAA0B;AACnE,MAAM,mBAAmB,OAAO,iBAAiB;AAExD,MAAM,QAAQ,oBAAI,QAAmC;AAE9C,SAAS,cAAuC,OAAyB;AAC9E,MAAI,OAAO,MAAM,IAAI,KAAK;AAE1B,MAAI,CAAC,MAAM;AACT,WAAO,IAAI,WAAW,KAAK;AAC3B,UAAM,IAAI,OAAO,IAAI;AAAA,EACvB;AAEA,SAAO;AACT;AAE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AAiC;AACnC,UAAM,cAAc,KAAK,MAAM,OAAO;AACtC,WAAO,uBAAuB,gBAAgB,cAAc,WAAW,IAAI;AAAA,EAC7E;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,WAAoB;AACtB,WAAO,KAAK,YAAY,KAAK,CAAC,cAAc,UAAU,eAAe;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,aAAiD;AACnD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,WAAW,YAAgD;AAC7D,SAAK,cAAc;AACnB,SAAK,cAAc,OAAO;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,QAA8B;AAChC,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAO;AAAA,IACT;AAEA,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */\n/*\n * Copyright 2000-2020 Vaadin Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n// TODO: Fix dependency cycle\n\nimport type { BinderRoot } from './BinderRoot.js';\nimport {\n _createEmptyItemValue,\n _key,\n _parent,\n _validators,\n AbstractModel,\n type ArrayItemModel,\n ArrayModel,\n getObjectModelOwnAndParentGetters,\n ObjectModel,\n type Value,\n} from './Models.js';\nimport type { ClassStaticProperties } from './types.js';\nimport type { Validator, ValueError } from './Validation.js';\nimport { ValidityStateValidator } from './Validators.js';\nimport { _validity } from './Validity.js';\n\nexport const _updateValidation = Symbol('updateValidation');\nexport const _update = Symbol('update');\nexport const _setErrorsWithDescendants = Symbol('setErrorsWithDescendants');\nexport const _clearValidation = Symbol('clearValidation');\n\nconst nodes = new WeakMap<AbstractModel, BinderNode>();\n\nexport function getBinderNode<M extends AbstractModel>(model: M): BinderNode<M> {\n let node = nodes.get(model);\n\n if (!node) {\n node = new BinderNode(model);\n nodes.set(model, node);\n }\n\n return node as BinderNode<M>;\n}\n\nfunction getErrorPropertyName(valueError: ValueError): string {\n return typeof valueError.property === 'string' ? valueError.property : getBinderNode(valueError.property).name;\n}\n\nfunction updateObjectOrArrayKey<M extends AbstractModel>(\n model: M,\n value: Value<M>,\n key: keyof any,\n keyValue: unknown,\n): Value<M> {\n if (model instanceof ObjectModel) {\n // Value contained in object - replace object in parent\n return {\n ...(value as Record<never, never> & Value<M>),\n [key]: keyValue,\n };\n }\n\n if (keyValue === undefined) {\n throw new TypeError('Unexpected undefined value');\n }\n\n if (model instanceof ArrayModel) {\n // Value contained in array - replace array in parent\n const array = (value as unknown[]).slice();\n array[key as number] = keyValue;\n return array as Value<M>;\n }\n\n throw new TypeError(`Unknown model type ${(model as AbstractModel).constructor.name}`);\n}\n\nexport const CHANGED = new Event('binder-node-changed');\n\nclass NotArrayModelError extends Error {\n constructor() {\n super('The model does not represent array');\n }\n}\n\nclass NotArrayItemModelError extends Error {\n constructor() {\n super('The model does not represent array item');\n }\n}\n\ndeclare class ArrayItemBinderNode<M extends AbstractModel> extends BinderNode<M> {\n // @ts-expect-error: re-defining the parent getter.\n declare readonly parent: BinderNode<ArrayModel<M>>;\n}\n\nconst defaultArrayItemCache = new WeakMap<BinderNode, unknown>();\n\n/**\n * The BinderNode\\<M\\> class provides the form binding related APIs\n * with respect to a particular model instance.\n *\n * Structurally, model instances form a tree, in which the object\n * and array models have child nodes of field and array item model\n * instances.\n */\nexport class BinderNode<M extends AbstractModel = AbstractModel> extends EventTarget {\n declare readonly ['constructor']: ClassStaticProperties<typeof BinderNode<M>>;\n readonly model: M;\n /**\n * The validity state read from the bound element, if any. Represents the\n * HTML element internal validation.\n *\n * For elements with `validity.valid === false`, the value in the\n * bound element is considered as invalid.\n */\n [_validity]?: ValidityState;\n #ownErrors?: ReadonlyArray<ValueError<Value<M>>>;\n #validators: ReadonlyArray<Validator<Value<M>>>;\n readonly #validityStateValidator: ValidityStateValidator<Value<M>>;\n #visited = false;\n\n constructor(model: M) {\n super();\n this.model = model;\n nodes.set(model, this);\n this.#validityStateValidator = new ValidityStateValidator<Value<M>>();\n this.#validators = model[_validators];\n\n // Workaround for children initialization with private props\n if (this.constructor === BinderNode) {\n this.initializeValue();\n }\n }\n\n /**\n * The binder for the top-level model.\n */\n get binder(): BinderRoot {\n const binder = this.parent?.binder;\n\n if (!binder) {\n throw new TypeError('BinderNode is detached');\n }\n\n return binder;\n }\n\n /**\n * The default value related to the model\n */\n get defaultValue(): Value<M> | undefined {\n const key = this.model[_key];\n const parentDefaultValue = this.parent!.defaultValue as { readonly [key in typeof key]?: Value<M> };\n\n if (this.#isArrayItem() && !(key in parentDefaultValue)) {\n if (defaultArrayItemCache.has(this.parent)) {\n return defaultArrayItemCache.get(this.parent) as Value<M>;\n }\n\n const value = this.model.constructor.createEmptyValue();\n defaultArrayItemCache.set(this.parent, value);\n return value as Value<M>;\n }\n\n return parentDefaultValue[key];\n }\n\n /**\n * True if the current value is different from the defaultValue.\n */\n get dirty(): boolean {\n return this.value !== this.defaultValue;\n }\n\n /**\n * The combined array of all errors for this node\u2019s model and all its nested\n * models\n */\n get errors(): readonly ValueError[] {\n return [...Array.from(this.#getChildBinderNodes(), (node) => node.errors).flat(), ...this.ownErrors];\n }\n\n /**\n * Indicates if there is any error for the node's model.\n */\n get invalid(): boolean {\n return this.errors.length > 0;\n }\n\n /**\n * The name generated from the model structure, used to set the name\n * attribute on the field components.\n */\n get name(): string {\n let { model }: { model: AbstractModel } = this;\n let name = '';\n\n while (model[_parent] instanceof AbstractModel) {\n name = `${String(model[_key])}${name ? `.${name}` : ''}`;\n model = model[_parent];\n }\n\n return name;\n }\n\n /**\n * The array of validation errors directly related with the model.\n */\n get ownErrors(): ReadonlyArray<ValueError<Value<M>>> {\n return this.#ownErrors ? this.#ownErrors : [];\n }\n\n /**\n * The parent node, if this binder node corresponds to a nested model,\n * otherwise undefined for the top-level binder.\n */\n get parent(): BinderNode | undefined {\n const modelParent = this.model[_parent];\n return modelParent instanceof AbstractModel ? getBinderNode(modelParent) : undefined;\n }\n\n /**\n * True if the value is required to be non-empty.\n */\n get required(): boolean {\n return this.#validators.some((validator) => validator.impliesRequired);\n }\n\n /**\n * The array of validators for the model. The default value is defined in the\n * model.\n */\n get validators(): ReadonlyArray<Validator<Value<M>>> {\n return this.#validators;\n }\n\n set validators(validators: ReadonlyArray<Validator<Value<M>>>) {\n this.#validators = validators;\n this.dispatchEvent(CHANGED);\n }\n\n /**\n * The current value related to the model\n */\n get value(): Value<M> | undefined {\n if (!this.parent) {\n return undefined;\n }\n\n this.initializeValue();\n\n const key = this.model[_key];\n\n // The value of parent in unknown, so we need to cast it.\n type ParentValue = { readonly [K in typeof key]: Value<M> };\n return (this.parent.value as ParentValue)[key];\n }\n\n set value(value: Value<M> | undefined) {\n this.initializeValue();\n this.#setValueState(value, undefined);\n }\n\n /**\n * True if the bound field was ever focused and blurred by the user.\n */\n get visited(): boolean {\n return this.#visited;\n }\n\n set visited(v: boolean) {\n if (this.#visited !== v) {\n this.#visited = v;\n this[_updateValidation]().catch(() => {});\n this.dispatchEvent(CHANGED);\n }\n }\n\n /**\n * A helper method to add a validator\n *\n * @param validator - a validator\n */\n addValidator(validator: Validator<Value<M>>): void {\n this.validators = [...this.#validators, validator];\n this.dispatchEvent(CHANGED);\n }\n\n /**\n * Append an item to the array value.\n *\n * Requires the context model to be an array reference.\n *\n * @param item - optional new item value, an empty item is\n * appended if the argument is omitted\n */\n appendItem(item?: Value<ArrayItemModel<M>>): void {\n if (this.#isArray()) {\n const itemValueOrEmptyValue = item ?? this.model[_createEmptyItemValue]();\n const newValue = [...(this.value ?? []), itemValueOrEmptyValue];\n const newDefaultValue = [...(this.defaultValue ?? []), itemValueOrEmptyValue];\n this.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayModelError();\n }\n }\n\n /**\n * Returns a binder node for the nested model instance.\n *\n * @param model - The nested model instance\n */\n for<N extends AbstractModel>(model: N): BinderNode<N> {\n const binderNode = getBinderNode(model);\n if (binderNode.binder !== this.binder) {\n throw new Error('Unknown binder');\n }\n\n return binderNode;\n }\n\n prependItem(item?: Value<ArrayItemModel<M>>): void {\n if (this.#isArray()) {\n const itemValueOrEmptyValue = item ?? this.model[_createEmptyItemValue]();\n const newValue = [itemValueOrEmptyValue, ...(this.value ?? [])];\n const newDefaultValue = [itemValueOrEmptyValue, ...(this.defaultValue ?? [])];\n this.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayModelError();\n }\n }\n\n removeSelf(): void {\n if (this.#isArrayItem()) {\n const newValue = (this.parent.value ?? []).filter((_, i) => i !== this.model[_key]);\n const newDefaultValue = (this.parent.defaultValue ?? []).filter((_, i) => i !== this.model[_key]);\n this.parent.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayItemModelError();\n }\n }\n\n /**\n * Runs all validation callbacks potentially affecting this\n * or any nested model. Returns the combined array of all\n * errors as in the errors property.\n */\n async validate(): Promise<readonly ValueError[]> {\n const errors = await Promise.all([\n ...this.#requestValidationOfDescendants(),\n ...this.#requestValidationWithAncestors(),\n ]).then((arr) => arr.flat());\n this[_setErrorsWithDescendants](errors.length ? errors : undefined);\n this[_update]();\n return errors;\n }\n\n protected [_clearValidation](): boolean {\n if (this.#visited) {\n this.#visited = false;\n this.dispatchEvent(CHANGED);\n }\n let needsUpdate = false;\n if (this.#ownErrors) {\n this.#ownErrors = undefined;\n needsUpdate = true;\n this.dispatchEvent(CHANGED);\n }\n if ([...this.#getChildBinderNodes()].filter((childBinderNode) => childBinderNode[_clearValidation]()).length > 0) {\n needsUpdate = true;\n }\n return needsUpdate;\n }\n\n protected [_setErrorsWithDescendants](errors?: readonly ValueError[]): void {\n const { name } = this;\n const ownErrors = errors\n ? (errors.filter((valueError) => getErrorPropertyName(valueError) === name) as ReadonlyArray<\n ValueError<Value<M>>\n >)\n : undefined;\n const relatedErrors = errors\n ? errors.filter((valueError) => getErrorPropertyName(valueError).startsWith(name))\n : undefined;\n this.#ownErrors = ownErrors;\n for (const childBinderNode of this.#getChildBinderNodes()) {\n childBinderNode[_setErrorsWithDescendants](relatedErrors);\n }\n this.dispatchEvent(CHANGED);\n }\n\n protected [_update](_?: Value<M>): void {\n if (this.parent) {\n this.parent[_update]();\n }\n }\n\n protected async [_updateValidation](): Promise<void> {\n if (this.#visited) {\n await this.validate();\n } else if (this.dirty || this.invalid) {\n await Promise.all(\n [...this.#getChildBinderNodes()].map(async (childBinderNode) => childBinderNode[_updateValidation]()),\n );\n }\n }\n\n *#getChildBinderNodes(): Generator<BinderNode, void, void> {\n if (this.value === undefined || this.defaultValue === undefined) {\n // Undefined value cannot have child properties and items.\n return;\n }\n\n if (this.#isObject()) {\n for (const [, getter] of getObjectModelOwnAndParentGetters(this.model)) {\n const childModel = getter.call(this.model);\n // We need to skip all non-initialised optional fields here in order\n // to prevent infinite recursion for circular references in the model.\n // Here we rely on presence of keys in `defaultValue` to detect all\n // initialised fields. The keys in `defaultValue` are defined for all\n // non-optional fields plus those optional fields whose values were\n // set from initial `binder.read()` or `binder.clear()` or by using a\n // binder node (e.g., form binding) for a nested field.\n if (childModel[_key] in (this.defaultValue as Record<never, never>)) {\n yield getBinderNode(childModel);\n }\n }\n } else if (this.#isArray()) {\n for (const childBinderNode of this.model) {\n yield childBinderNode;\n }\n }\n }\n\n #isArray(): this is BinderNode<ArrayModel> {\n return this.model instanceof ArrayModel;\n }\n\n #isArrayItem(): this is ArrayItemBinderNode<M> {\n return this.model[_parent] instanceof ArrayModel;\n }\n\n #isObject(): this is BinderNode<ObjectModel> {\n return this.model instanceof ObjectModel;\n }\n\n *#requestValidationOfDescendants(): Generator<Promise<readonly ValueError[]>, void, void> {\n for (const node of this.#getChildBinderNodes()) {\n yield* node.#runOwnValidators();\n yield* node.#requestValidationOfDescendants();\n }\n }\n\n *#requestValidationWithAncestors(): Generator<Promise<readonly ValueError[]>, void, void> {\n yield* this.#runOwnValidators();\n\n if (this.parent) {\n yield* this.parent.#requestValidationWithAncestors();\n }\n }\n\n *#runOwnValidators(): Generator<Promise<readonly ValueError[]>, void, void> {\n const hasInvalidState = this[_validity] && !this[_validity].valid;\n const hasBadInput = !!this[_validity]?.badInput;\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n if ((hasInvalidState && !hasBadInput) || !hasInvalidState) {\n for (const validator of this.#validators) {\n yield this.binder.requestValidation(this.model, validator);\n }\n }\n\n if (hasInvalidState) {\n yield this.binder.requestValidation(this.model, this.#validityStateValidator);\n }\n }\n\n initializeValue(forceInitialize = false): void {\n // First, make sure parents have value initialized\n if (\n this.parent &&\n (this.parent.value === undefined || (this.parent.defaultValue as Value<M> | undefined) === undefined)\n ) {\n this.parent.initializeValue(true);\n }\n\n const key = this.model[_key];\n let value: Value<M> | undefined = this.parent\n ? (this.parent.value as { [key in typeof key]: Value<M> })[this.model[_key]]\n : undefined;\n\n const defaultValue: Value<M> | undefined = this.parent\n ? (this.parent.defaultValue as { readonly [key in typeof key]: Value<M> })[this.model[_key]]\n : undefined;\n\n if (value === undefined) {\n // Initialize value if this is the root level node, or it is enforced\n if (forceInitialize || !this.parent) {\n value = this.model.constructor.createEmptyValue() as Value<M>;\n this.#setValueState(value, defaultValue === undefined ? value : defaultValue);\n } else if (\n this.parent.model instanceof ObjectModel &&\n !(key in ((this.parent.value || {}) as { [key in typeof key]?: Value<M> }))\n ) {\n this.#setValueState(undefined, defaultValue === undefined ? value : defaultValue);\n }\n }\n }\n\n #setValueState(value: Value<M> | undefined, defaultValue: Value<M> | undefined): void {\n const { parent } = this;\n if (parent) {\n const key = this.model[_key];\n const parentValue = updateObjectOrArrayKey(parent.model, parent.value, key, value);\n const keepPristine = value === defaultValue && parent.value === parent.defaultValue;\n if (keepPristine) {\n // Keep value and defaultValue equal, so that `dirty` stays false\n parent.#setValueState(parentValue, parentValue);\n } else if (defaultValue !== undefined) {\n // Update value and defaultValue at the same time with different content\n const parentDefaultValue = updateObjectOrArrayKey(parent.model, parent.defaultValue, key, defaultValue);\n parent.#setValueState(parentValue, parentDefaultValue);\n } else {\n parent.#setValueState(parentValue, undefined);\n }\n } else {\n // Root level model - update the binder root\n const binder = this as unknown as BinderRoot<M>;\n if (defaultValue !== undefined) {\n binder.defaultValue = defaultValue;\n }\n binder.value = value!;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAmBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAGP,SAAS,8BAA8B;AACvC,SAAS,iBAAiB;AAEnB,MAAM,oBAAoB,OAAO,kBAAkB;AACnD,MAAM,UAAU,OAAO,QAAQ;AAC/B,MAAM,4BAA4B,OAAO,0BAA0B;AACnE,MAAM,mBAAmB,OAAO,iBAAiB;AAExD,MAAM,QAAQ,oBAAI,QAAmC;AAE9C,SAAS,cAAuC,OAAyB;AAC9E,MAAI,OAAO,MAAM,IAAI,KAAK;AAE1B,MAAI,CAAC,MAAM;AACT,WAAO,IAAI,WAAW,KAAK;AAC3B,UAAM,IAAI,OAAO,IAAI;AAAA,EACvB;AAEA,SAAO;AACT;AAEA,SAAS,qBAAqB,YAAgC;AAC5D,SAAO,OAAO,WAAW,aAAa,WAAW,WAAW,WAAW,cAAc,WAAW,QAAQ,EAAE;AAC5G;AAEA,SAAS,uBACP,OACA,OACA,KACA,UACU;AACV,MAAI,iBAAiB,aAAa;AAEhC,WAAO;AAAA,MACL,GAAI;AAAA,MACJ,CAAC,GAAG,GAAG;AAAA,IACT;AAAA,EACF;AAEA,MAAI,aAAa,QAAW;AAC1B,UAAM,IAAI,UAAU,4BAA4B;AAAA,EAClD;AAEA,MAAI,iBAAiB,YAAY;AAE/B,UAAM,QAAS,MAAoB,MAAM;AACzC,UAAM,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: FieldElement<T>, model?:
|
|
|
115
115
|
*/
|
|
116
116
|
export declare const field: (_model: AbstractModel<any>, _effect?: ((element: Element) => void) | undefined) => import("lit-html/directive.js").DirectiveResult<{
|
|
117
117
|
new (partInfo: PartInfo): {
|
|
118
|
-
fieldState?: FieldState<any
|
|
119
|
-
render(_model: AbstractModel<any>, _effect?: (
|
|
118
|
+
fieldState?: FieldState<any>;
|
|
119
|
+
render(_model: AbstractModel<any>, _effect?: (element: Element) => void): symbol;
|
|
120
120
|
update(part: ElementPart | PropertyPart, [model, effect]: [_model: AbstractModel<any>, _effect?: ((element: Element) => void) | undefined]): symbol;
|
|
121
121
|
readonly _$isConnected: boolean;
|
|
122
122
|
};
|
package/Field.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["src/Field.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAqB,KAAK,YAAY,EAAE,MAAM,KAAK,CAAC;AAC7E,OAAO,EAAkD,KAAK,QAAQ,EAAY,MAAM,kBAAkB,CAAC;AAE3G,OAAO,EAAe,KAAK,aAAa,EAAwD,MAAM,aAAa,CAAC;AAIpH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,IAAI,OAAO,CAAC;CAC1B,CAAC,CAAC;AAEH,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAIxG,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,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,CAAC,GAAG,EAAE,GAAG,EAE1B;CACF;AAED,KAAK,oBAAoB,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG;IAC/C,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,CAAC,CAAC;CACb,CAAC;AAEF,qBAAa,qBAAqB,CAChC,CAAC,EACD,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAC3D,SAAQ,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC;IAClC,IAAa,KAAK,IAAI,CAAC,CAEtB;IAED,IAAa,KAAK,CAAC,GAAG,EAAE,CAAC,EAExB;CACF;AAMD,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CA0BnH;AAMD;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK,oDAakD,OAAO,KAAK,IAAI;mBAT1D,QAAQ;qBAFjB,UAAU,CAAC,GAAG,CAAC;uBAWJ,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI;qBAI1D,WAAW,GAAG,YAAY,qEAJgB,OAAO,KAAK,IAAI;;;EA4FnF,CAAC"}
|
package/Models.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const _validators: unique symbol;
|
|
|
8
8
|
export declare const _meta: unique symbol;
|
|
9
9
|
export declare const _getPropertyModel: unique symbol;
|
|
10
10
|
export declare const _enum: unique symbol;
|
|
11
|
+
export declare const _items: unique symbol;
|
|
11
12
|
declare const _optional: unique symbol;
|
|
12
13
|
export interface HasFromString<T> {
|
|
13
14
|
[_fromString](value: string): T;
|
|
@@ -44,7 +45,23 @@ export declare abstract class AbstractModel<T = unknown> {
|
|
|
44
45
|
readonly [_optional]: boolean;
|
|
45
46
|
[_key]: keyof any;
|
|
46
47
|
constructor(parent: ModelParent, key: keyof any, optional: boolean, options?: ModelOptions<T>);
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use {@link BinderNode.value} with string conversion instead
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const result = String(binder.for(model).value);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
47
56
|
toString(): string;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use {@link BinderNode.value} instead
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const result = binder.for(model).value;
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
48
65
|
valueOf(): T;
|
|
49
66
|
}
|
|
50
67
|
export declare abstract class PrimitiveModel<T> extends AbstractModel<T> {
|
|
@@ -74,7 +91,7 @@ export declare function makeObjectEmptyValueCreator<M extends ObjectModel>(type:
|
|
|
74
91
|
type ChildModel<T extends Record<never, never>, K extends keyof T> = AbstractModel<NonNullable<T[K]>>;
|
|
75
92
|
export declare class ObjectModel<T extends Record<never, never> = Record<never, never>> extends AbstractModel<T> {
|
|
76
93
|
#private;
|
|
77
|
-
static createEmptyValue: () => Record<never, never
|
|
94
|
+
static createEmptyValue: () => Value<ObjectModel<Record<never, never>>>;
|
|
78
95
|
protected [_getPropertyModel]<K extends keyof T, M extends ChildModel<T, K>>(key: K, init: (parent: this, key: K) => M): M;
|
|
79
96
|
}
|
|
80
97
|
export type ArrayItemModel<M> = M extends ArrayModel<infer MItem> ? MItem : never;
|
|
@@ -82,11 +99,37 @@ export declare class ArrayModel<MItem extends AbstractModel = AbstractModel> ext
|
|
|
82
99
|
#private;
|
|
83
100
|
static createEmptyValue(): [];
|
|
84
101
|
[_createEmptyItemValue]: () => Value<MItem>;
|
|
85
|
-
constructor(parent: ModelParent, key: keyof any, optional: boolean, createItem: (parent:
|
|
102
|
+
constructor(parent: ModelParent, key: keyof any, optional: boolean, createItem: (parent: AbstractModel, key: number) => MItem, options?: ModelOptions<Array<Value<MItem>>>);
|
|
103
|
+
[_items](): Generator<MItem, void, void>;
|
|
86
104
|
/**
|
|
87
|
-
* Iterates the current
|
|
105
|
+
* Iterates over the current model and yields a binder node for every item
|
|
106
|
+
* model.
|
|
107
|
+
*
|
|
108
|
+
* @deprecated Use the {@link m.items} function instead. For example, in React:
|
|
109
|
+
* ```tsx
|
|
110
|
+
* const {model, field} = useForm(GroupModel);
|
|
111
|
+
* return Array.from(m.items(model.people), (personModel) =>
|
|
112
|
+
* <TextField label="Full name" {...field(personModel.fullName)} />
|
|
113
|
+
* );
|
|
114
|
+
* ```
|
|
115
|
+
* In Lit:
|
|
116
|
+
* ```ts
|
|
117
|
+
* return html`${repeat(
|
|
118
|
+
* m.items(this.binder.model.people),
|
|
119
|
+
* (personModel) => html`<vaadin-text-field label="Full name" ${field(personModel.fullName)}></vaadin-text-field>`,
|
|
120
|
+
* )}`;
|
|
121
|
+
* ```
|
|
88
122
|
*/
|
|
89
123
|
[Symbol.iterator](): IterableIterator<BinderNode<MItem>>;
|
|
90
124
|
}
|
|
125
|
+
export declare const m: {
|
|
126
|
+
/**
|
|
127
|
+
* Returns an iterator over item models in the array model.
|
|
128
|
+
*
|
|
129
|
+
* @param model - The array model to iterate over.
|
|
130
|
+
* @returns An iterator over item models.
|
|
131
|
+
*/
|
|
132
|
+
items<M extends ArrayModel>(model: M): Generator<ArrayItemModel<M>, void, void>;
|
|
133
|
+
};
|
|
91
134
|
export {};
|
|
92
135
|
//# sourceMappingURL=Models.d.ts.map
|
package/Models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["src/Models.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,eAAO,MAAM,qBAAqB,
|
|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ItC,CAAC,qBAAqB,CAAC,EAAE,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;gBAQ1C,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,MAAM,GAAG,EACd,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,KAAK,KAAK,EACzD,OAAO,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAO5C,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC;IAmBzC;;;;;;;;;;;;;;;;;;OAkBG;IACF,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CAK1D;AAED,eAAO,MAAM,CAAC;IACZ;;;;;OAKG;UACG,CAAC,SAAS,UAAU,SAAS,CAAC,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;CAGhF,CAAC"}
|
package/Models.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import isNumeric from "validator/es/lib/isNumeric.js";
|
|
2
2
|
import { getBinderNode } from "./BinderNode.js";
|
|
3
3
|
import { IsNumber } from "./Validators.js";
|
|
4
|
-
const _createEmptyItemValue = Symbol("
|
|
4
|
+
const _createEmptyItemValue = Symbol("createEmptyItemValue");
|
|
5
5
|
const _parent = Symbol("parent");
|
|
6
6
|
const _key = Symbol("key");
|
|
7
7
|
const _fromString = Symbol("fromString");
|
|
@@ -9,6 +9,7 @@ const _validators = Symbol("validators");
|
|
|
9
9
|
const _meta = Symbol("meta");
|
|
10
10
|
const _getPropertyModel = Symbol("getPropertyModel");
|
|
11
11
|
const _enum = Symbol("enum");
|
|
12
|
+
const _items = Symbol("items");
|
|
12
13
|
const _optional = Symbol("optional");
|
|
13
14
|
function hasFromString(model) {
|
|
14
15
|
return _fromString in model;
|
|
@@ -33,9 +34,25 @@ class AbstractModel {
|
|
|
33
34
|
this[_validators] = options?.validators ?? [];
|
|
34
35
|
this[_meta] = options?.meta ?? {};
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated Use {@link BinderNode.value} with string conversion instead
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const result = String(binder.for(model).value);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
36
45
|
toString() {
|
|
37
46
|
return String(this.valueOf());
|
|
38
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use {@link BinderNode.value} instead
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const result = binder.for(model).value;
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
39
56
|
valueOf() {
|
|
40
57
|
const { value } = getBinderNode(this);
|
|
41
58
|
if (value === void 0) {
|
|
@@ -116,6 +133,8 @@ class ArrayModel extends AbstractModel {
|
|
|
116
133
|
return [];
|
|
117
134
|
}
|
|
118
135
|
[_createEmptyItemValue];
|
|
136
|
+
// The `parent` parameter is AbstractModel here for purpose; for some reason, setting it to `ArrayModel<MItem>` or
|
|
137
|
+
// `this` breaks the type inference in TS (v5.3.2).
|
|
119
138
|
#createItem;
|
|
120
139
|
#items = [];
|
|
121
140
|
constructor(parent, key, optional, createItem, options) {
|
|
@@ -123,24 +142,56 @@ class ArrayModel extends AbstractModel {
|
|
|
123
142
|
this.#createItem = createItem;
|
|
124
143
|
this[_createEmptyItemValue] = createItem(this, 0).constructor.createEmptyValue;
|
|
125
144
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const array = this.valueOf();
|
|
131
|
-
if (array.length !== this.#items.length) {
|
|
132
|
-
this.#items.length = array.length;
|
|
145
|
+
*[_items]() {
|
|
146
|
+
const values = getBinderNode(this).value ?? [];
|
|
147
|
+
if (values.length !== this.#items.length) {
|
|
148
|
+
this.#items.length = values.length;
|
|
133
149
|
}
|
|
134
|
-
for (let i = 0; i <
|
|
150
|
+
for (let i = 0; i < values.length; i++) {
|
|
135
151
|
let item = this.#items[i];
|
|
136
152
|
if (!item) {
|
|
137
153
|
item = this.#createItem(this, i);
|
|
138
154
|
this.#items[i] = item;
|
|
139
155
|
}
|
|
156
|
+
yield item;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Iterates over the current model and yields a binder node for every item
|
|
161
|
+
* model.
|
|
162
|
+
*
|
|
163
|
+
* @deprecated Use the {@link m.items} function instead. For example, in React:
|
|
164
|
+
* ```tsx
|
|
165
|
+
* const {model, field} = useForm(GroupModel);
|
|
166
|
+
* return Array.from(m.items(model.people), (personModel) =>
|
|
167
|
+
* <TextField label="Full name" {...field(personModel.fullName)} />
|
|
168
|
+
* );
|
|
169
|
+
* ```
|
|
170
|
+
* In Lit:
|
|
171
|
+
* ```ts
|
|
172
|
+
* return html`${repeat(
|
|
173
|
+
* m.items(this.binder.model.people),
|
|
174
|
+
* (personModel) => html`<vaadin-text-field label="Full name" ${field(personModel.fullName)}></vaadin-text-field>`,
|
|
175
|
+
* )}`;
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
*[Symbol.iterator]() {
|
|
179
|
+
for (const item of this[_items]()) {
|
|
140
180
|
yield getBinderNode(item);
|
|
141
181
|
}
|
|
142
182
|
}
|
|
143
183
|
}
|
|
184
|
+
const m = {
|
|
185
|
+
/**
|
|
186
|
+
* Returns an iterator over item models in the array model.
|
|
187
|
+
*
|
|
188
|
+
* @param model - The array model to iterate over.
|
|
189
|
+
* @returns An iterator over item models.
|
|
190
|
+
*/
|
|
191
|
+
items(model) {
|
|
192
|
+
return model[_items]();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
144
195
|
export {
|
|
145
196
|
AbstractModel,
|
|
146
197
|
ArrayModel,
|
|
@@ -154,6 +205,7 @@ export {
|
|
|
154
205
|
_enum,
|
|
155
206
|
_fromString,
|
|
156
207
|
_getPropertyModel,
|
|
208
|
+
_items,
|
|
157
209
|
_key,
|
|
158
210
|
_meta,
|
|
159
211
|
_parent,
|
|
@@ -161,6 +213,7 @@ export {
|
|
|
161
213
|
createDetachedModel,
|
|
162
214
|
getObjectModelOwnAndParentGetters,
|
|
163
215
|
hasFromString,
|
|
216
|
+
m,
|
|
164
217
|
makeEnumEmptyValueCreator,
|
|
165
218
|
makeObjectEmptyValueCreator,
|
|
166
219
|
modelDetachedParent
|
package/Models.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/Models.ts"],
|
|
4
|
-
"sourcesContent": ["import isNumeric from 'validator/es/lib/isNumeric.js';\nimport { type BinderNode, getBinderNode } from './BinderNode.js';\nimport type { Validator } from './Validation.js';\nimport { IsNumber } from './Validators.js';\n\nexport const _createEmptyItemValue = Symbol('
|
|
5
|
-
"mappings": "AAAA,OAAO,eAAe;AACtB,SAA0B,qBAAqB;AAE/C,SAAS,gBAAgB;AAElB,MAAM,wBAAwB,OAAO,
|
|
4
|
+
"sourcesContent": ["import isNumeric from 'validator/es/lib/isNumeric.js';\nimport { type BinderNode, getBinderNode } from './BinderNode.js';\nimport type { Validator } from './Validation.js';\nimport { IsNumber } from './Validators.js';\n\nexport const _createEmptyItemValue = Symbol('createEmptyItemValue');\nexport const _parent = Symbol('parent');\nexport const _key = Symbol('key');\nexport const _fromString = Symbol('fromString');\nexport const _validators = Symbol('validators');\nexport const _meta = Symbol('meta');\nexport const _getPropertyModel = Symbol('getPropertyModel');\nexport const _enum = Symbol('enum');\nexport const _items = Symbol('items');\n\nconst _optional = Symbol('optional');\n\nexport interface HasFromString<T> {\n [_fromString](value: string): T;\n}\n\nexport function hasFromString<T>(model: AbstractModel<T>): model is AbstractModel<T> & HasFromString<T> {\n return _fromString in model;\n}\n\nexport type Value<M> = M extends AbstractModel<infer T> ? T : never;\n\nexport const modelDetachedParent = { $value$: undefined };\n\nexport type ModelParent = AbstractModel | BinderNode | typeof modelDetachedParent;\n\nexport interface Annotation {\n name: string;\n attributes?: Record<string, unknown>;\n}\n\nexport interface ModelMetadata {\n javaType?: string;\n annotations?: Annotation[];\n}\n\nexport interface ModelOptions<T> {\n validators?: ReadonlyArray<Validator<T>>;\n meta?: ModelMetadata;\n}\n\nexport type DetachedModelConstructor<M> = {\n prototype: object;\n new (parent: typeof modelDetachedParent, key: '$value$', optional: boolean): M;\n};\n\nexport function createDetachedModel<M extends AbstractModel>(type: DetachedModelConstructor<M>): M {\n return new type(modelDetachedParent, '$value$', false);\n}\n\nexport abstract class AbstractModel<T = unknown> {\n static createEmptyValue(): unknown {\n return undefined;\n }\n\n declare readonly ['constructor']: typeof AbstractModel<T>;\n\n readonly [_parent]?: ModelParent;\n\n readonly [_validators]: ReadonlyArray<Validator<T>>;\n\n readonly [_meta]: ModelMetadata;\n\n readonly [_optional]: boolean;\n\n [_key]: keyof any;\n\n constructor(parent: ModelParent, key: keyof any, optional: boolean, options?: ModelOptions<T>) {\n this[_parent] = parent;\n this[_key] = key;\n this[_optional] = optional;\n this[_validators] = options?.validators ?? [];\n this[_meta] = options?.meta ?? {};\n }\n\n /**\n * @deprecated Use {@link BinderNode.value} with string conversion instead\n *\n * @example\n * ```ts\n * const result = String(binder.for(model).value);\n * ```\n */\n toString(): string {\n return String(this.valueOf());\n }\n\n /**\n * @deprecated Use {@link BinderNode.value} instead\n *\n * @example\n * ```ts\n * const result = binder.for(model).value;\n * ```\n */\n valueOf(): T {\n const { value } = getBinderNode(this);\n\n if (value === undefined) {\n throw new TypeError('Value is undefined');\n }\n\n return value! as T;\n }\n}\n\nexport abstract class PrimitiveModel<T> extends AbstractModel<T> {}\n\nexport class BooleanModel extends PrimitiveModel<boolean> implements HasFromString<boolean> {\n static override createEmptyValue = Boolean;\n\n [_fromString](str: string): boolean {\n // This implementation matches the values accepted by validator.js and converts all other values to false\n // See https://github.com/validatorjs/validator.js/blob/master/src/lib/isBoolean.js\n return ['true', '1', 'yes'].includes(str.toLowerCase());\n }\n}\n\nexport class NumberModel extends PrimitiveModel<number> implements HasFromString<number | undefined> {\n static override createEmptyValue(): number {\n return NaN;\n }\n\n constructor(parent: ModelParent, key: keyof any, optional: boolean, options?: ModelOptions<number>) {\n // Prepend a built-in validator to indicate NaN input\n const validators = [new IsNumber(optional), ...(options?.validators ?? [])];\n super(parent, key, optional, { ...options, validators });\n }\n\n [_fromString](str: string): number | undefined {\n // Returning undefined is needed to support passing the validation when the value of an optional number field is\n // an empty string\n if (str === '') return undefined;\n return isNumeric(str) ? Number.parseFloat(str) : NaN;\n }\n}\n\nexport class StringModel extends PrimitiveModel<string> implements HasFromString<string> {\n static override createEmptyValue = String;\n [_fromString] = String;\n}\n\ndeclare enum Enum {}\n\nexport function makeEnumEmptyValueCreator<M extends EnumModel>(type: DetachedModelConstructor<M>): () => Value<M> {\n const { [_enum]: enumObject } = createDetachedModel(type);\n const defaultValue = Object.values(enumObject)[0] as Value<M>;\n\n return () => defaultValue;\n}\n\nexport abstract class EnumModel<E extends typeof Enum = typeof Enum>\n extends AbstractModel<E[keyof E]>\n implements HasFromString<E[keyof E] | undefined>\n{\n abstract readonly [_enum]: E;\n\n [_fromString](value: string): E[keyof E] | undefined {\n return value in this[_enum] ? (value as E[keyof E]) : undefined;\n }\n}\n\nexport function* getObjectModelOwnAndParentGetters<M extends ObjectModel>(\n model: M,\n): Generator<readonly [key: keyof Value<M>, getter: () => AbstractModel]> {\n for (\n let proto = Object.getPrototypeOf(model);\n proto !== ObjectModel.prototype;\n proto = Object.getPrototypeOf(proto)\n ) {\n const descriptors = Object.getOwnPropertyDescriptors(proto);\n for (const [name, { get }] of Object.entries(descriptors)) {\n if (get) {\n yield [name as keyof Value<M>, get];\n }\n }\n }\n}\n\nexport function makeObjectEmptyValueCreator<M extends ObjectModel>(type: DetachedModelConstructor<M>): () => Value<M> {\n const model = createDetachedModel(type);\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n const obj: Partial<Value<M>> = {};\n\n // Iterate the model class hierarchy up to the ObjectModel, and extract\n // the property getter names from every prototypes\n for (const [key, getter] of getObjectModelOwnAndParentGetters(model)) {\n const propertyModel = getter.call(model);\n obj[key] = (\n propertyModel[_optional] ? undefined : propertyModel.constructor.createEmptyValue()\n ) as Value<M>[keyof Value<M>];\n }\n\n return obj as Value<M>;\n };\n}\n\ntype ChildModel<T extends Record<never, never>, K extends keyof T> = AbstractModel<NonNullable<T[K]>>;\n\nexport class ObjectModel<T extends Record<never, never> = Record<never, never>> extends AbstractModel<T> {\n static override createEmptyValue = makeObjectEmptyValueCreator(ObjectModel);\n\n #properties: { [K in keyof T]?: ChildModel<T, K> } = {};\n\n protected [_getPropertyModel]<K extends keyof T, M extends ChildModel<T, K>>(\n key: K,\n init: (parent: this, key: K) => M,\n ): M {\n if (!this.#properties[key]) {\n this.#properties[key] = init(this, key);\n }\n\n return this.#properties[key] as M;\n }\n}\n\nexport type ArrayItemModel<M> = M extends ArrayModel<infer MItem> ? MItem : never;\n\nexport class ArrayModel<MItem extends AbstractModel = AbstractModel> extends AbstractModel<Array<Value<MItem>>> {\n static override createEmptyValue(): [] {\n return [];\n }\n\n [_createEmptyItemValue]: () => Value<MItem>;\n\n // The `parent` parameter is AbstractModel here for purpose; for some reason, setting it to `ArrayModel<MItem>` or\n // `this` breaks the type inference in TS (v5.3.2).\n readonly #createItem: (parent: AbstractModel, index: number) => MItem;\n #items: Array<MItem | undefined> = [];\n\n constructor(\n parent: ModelParent,\n key: keyof any,\n optional: boolean,\n createItem: (parent: AbstractModel, key: number) => MItem,\n options?: ModelOptions<Array<Value<MItem>>>,\n ) {\n super(parent, key, optional, options);\n this.#createItem = createItem;\n this[_createEmptyItemValue] = createItem(this, 0).constructor.createEmptyValue as () => Value<MItem>;\n }\n\n *[_items](): Generator<MItem, void, void> {\n const values = getBinderNode(this).value ?? [];\n\n if (values.length !== this.#items.length) {\n this.#items.length = values.length;\n }\n\n for (let i = 0; i < values.length; i++) {\n let item: MItem | undefined = this.#items[i];\n\n if (!item) {\n item = this.#createItem(this, i);\n this.#items[i] = item;\n }\n\n yield item;\n }\n }\n\n /**\n * Iterates over the current model and yields a binder node for every item\n * model.\n *\n * @deprecated Use the {@link m.items} function instead. For example, in React:\n * ```tsx\n * const {model, field} = useForm(GroupModel);\n * return Array.from(m.items(model.people), (personModel) =>\n * <TextField label=\"Full name\" {...field(personModel.fullName)} />\n * );\n * ```\n * In Lit:\n * ```ts\n * return html`${repeat(\n * m.items(this.binder.model.people),\n * (personModel) => html`<vaadin-text-field label=\"Full name\" ${field(personModel.fullName)}></vaadin-text-field>`,\n * )}`;\n * ```\n */\n *[Symbol.iterator](): IterableIterator<BinderNode<MItem>> {\n for (const item of this[_items]()) {\n yield getBinderNode(item);\n }\n }\n}\n\nexport const m = {\n /**\n * Returns an iterator over item models in the array model.\n *\n * @param model - The array model to iterate over.\n * @returns An iterator over item models.\n */\n items<M extends ArrayModel>(model: M): Generator<ArrayItemModel<M>, void, void> {\n return model[_items]() as Generator<ArrayItemModel<M>, void, void>;\n },\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,eAAe;AACtB,SAA0B,qBAAqB;AAE/C,SAAS,gBAAgB;AAElB,MAAM,wBAAwB,OAAO,sBAAsB;AAC3D,MAAM,UAAU,OAAO,QAAQ;AAC/B,MAAM,OAAO,OAAO,KAAK;AACzB,MAAM,cAAc,OAAO,YAAY;AACvC,MAAM,cAAc,OAAO,YAAY;AACvC,MAAM,QAAQ,OAAO,MAAM;AAC3B,MAAM,oBAAoB,OAAO,kBAAkB;AACnD,MAAM,QAAQ,OAAO,MAAM;AAC3B,MAAM,SAAS,OAAO,OAAO;AAEpC,MAAM,YAAY,OAAO,UAAU;AAM5B,SAAS,cAAiB,OAAuE;AACtG,SAAO,eAAe;AACxB;AAIO,MAAM,sBAAsB,EAAE,SAAS,O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;AAAA,EACF;AACF;AAEO,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOf,MAA4B,OAAoD;AAC9E,WAAO,MAAM,MAAM,EAAE;AAAA,EACvB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Validation.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BinderNode } from './BinderNode.js';
|
|
2
2
|
import type { BinderRoot } from './BinderRoot.js';
|
|
3
|
-
import {
|
|
3
|
+
import { AbstractModel, type Value } from './Models.js';
|
|
4
4
|
export interface ValueError<T = unknown> {
|
|
5
5
|
property: AbstractModel | string;
|
|
6
6
|
message: string;
|
package/Validation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validation.d.ts","sourceRoot":"","sources":["src/Validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Validation.d.ts","sourceRoot":"","sources":["src/Validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAe,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAGrE,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACrC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,aA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
|
|
2
|
-
import { NumberModel } from "./Models.js";
|
|
2
|
+
import { AbstractModel, NumberModel } from "./Models.js";
|
|
3
3
|
import { Required } from "./Validators.js";
|
|
4
4
|
class ValidationError extends Error {
|
|
5
5
|
errors;
|
|
@@ -7,9 +7,10 @@ class ValidationError extends Error {
|
|
|
7
7
|
super(
|
|
8
8
|
[
|
|
9
9
|
"There are validation errors in the form.",
|
|
10
|
-
...errors.map(
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
...errors.map((e) => {
|
|
11
|
+
const property = e.property instanceof AbstractModel ? String(getBinderNode(e.property).value) : e.property;
|
|
12
|
+
return `${property} - ${e.validator.constructor.name}${e.message ? `: ${e.message}` : ""}`;
|
|
13
|
+
})
|
|
13
14
|
].join("\n - ")
|
|
14
15
|
);
|
|
15
16
|
this.errors = errors;
|
package/Validation.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/Validation.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BinderNode } from './BinderNode.js';\nimport { getBinderNode } from './BinderNode.js';\nimport type { BinderRoot } from './BinderRoot.js';\nimport {
|
|
5
|
-
"mappings": "AACA,SAAS,qBAAqB;AAE9B,
|
|
4
|
+
"sourcesContent": ["import type { BinderNode } from './BinderNode.js';\nimport { getBinderNode } from './BinderNode.js';\nimport type { BinderRoot } from './BinderRoot.js';\nimport { AbstractModel, NumberModel, type Value } from './Models.js';\nimport { Required } from './Validators.js';\n\nexport interface ValueError<T = unknown> {\n property: AbstractModel | string;\n message: string;\n value: T;\n validator: Validator<T>;\n validatorMessage?: string;\n}\n\nexport interface ValidationResult {\n property: AbstractModel | string;\n message?: string;\n}\n\nexport class ValidationError extends Error {\n errors: readonly ValueError[];\n\n constructor(errors: readonly ValueError[]) {\n super(\n [\n 'There are validation errors in the form.',\n ...errors.map((e) => {\n const property = e.property instanceof AbstractModel ? String(getBinderNode(e.property).value) : e.property;\n return `${property} - ${e.validator.constructor.name}${e.message ? `: ${e.message}` : ''}`;\n }),\n ].join('\\n - '),\n );\n this.errors = errors;\n this.name = this.constructor.name;\n }\n}\n\nexport type InterpolateMessageCallback<M extends AbstractModel> = (\n message: string,\n validator: Validator<Value<M>>,\n binderNode: BinderNode<M>,\n) => string;\n\nexport interface Validator<T = unknown> {\n message: string;\n impliesRequired?: boolean;\n name?: string;\n validate(\n value: T,\n binder: BinderRoot,\n ):\n | Promise<ValidationResult | boolean | readonly ValidationResult[]>\n | ValidationResult\n | boolean\n | readonly ValidationResult[];\n}\n\nexport class ServerValidator implements Validator {\n name = 'ServerValidator';\n message: string;\n\n constructor(message: string) {\n this.message = message;\n }\n\n validate = (): boolean => false;\n}\n\n// The `property` field of `ValidationResult`s is a path relative to the parent.\nfunction setPropertyAbsolutePath(binderNodeName: string, result: ValidationResult): ValidationResult {\n if (typeof result.property === 'string' && binderNodeName.length > 0) {\n result.property = `${binderNodeName}.${result.property}`;\n }\n return result;\n}\n\nexport async function runValidator<M extends AbstractModel>(\n model: M,\n validator: Validator<Value<M>>,\n interpolateMessageCallback?: InterpolateMessageCallback<M>,\n): Promise<ReadonlyArray<ValueError<Value<M>>>> {\n const binderNode = getBinderNode(model);\n const value = binderNode.value as Value<M>;\n\n const interpolateMessage = (message: string) => {\n if (!interpolateMessageCallback) {\n return message;\n }\n return interpolateMessageCallback(message, validator, binderNode);\n };\n\n // If model is not required and value empty, do not run any validator. Except\n // always validate NumberModel, which has a mandatory builtin validator\n // to indicate NaN input.\n if (!binderNode.required && !new Required().validate(value) && !(model instanceof NumberModel)) {\n return [];\n }\n\n try {\n const result = await validator.validate(value, binderNode.binder);\n\n if (result === false) {\n return [\n {\n message: interpolateMessage(validator.message),\n property: binderNode.name,\n validator,\n value,\n },\n ];\n }\n\n if (result === true || (Array.isArray(result) && result.length === 0)) {\n return [];\n }\n\n if (Array.isArray(result)) {\n return result.map((result2) => ({\n message: interpolateMessage(validator.message),\n ...setPropertyAbsolutePath(binderNode.name, result2),\n validator,\n value,\n }));\n }\n\n return [\n {\n message: interpolateMessage(validator.message),\n ...setPropertyAbsolutePath(binderNode.name, result as ValidationResult),\n validator,\n value,\n },\n ];\n } catch (error: unknown) {\n console.error(`${binderNode.name} - Validator ${validator.constructor.name} threw an error:`, error);\n return [{ message: 'Validator threw an error', property: binderNode.name, validator, value }];\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,qBAAqB;AAE9B,SAAS,eAAe,mBAA+B;AACvD,SAAS,gBAAgB;AAelB,MAAM,wBAAwB,MAAM;AAAA,EACzC;AAAA,EAEA,YAAY,QAA+B;AACzC;AAAA,MACE;AAAA,QACE;AAAA,QACA,GAAG,OAAO,IAAI,CAAC,MAAM;AACnB,gBAAM,WAAW,EAAE,oBAAoB,gBAAgB,OAAO,cAAc,EAAE,QAAQ,EAAE,KAAK,IAAI,EAAE;AACnG,iBAAO,GAAG,QAAQ,MAAM,EAAE,UAAU,YAAY,IAAI,GAAG,EAAE,UAAU,KAAK,EAAE,OAAO,KAAK,EAAE;AAAA,QAC1F,CAAC;AAAA,MACH,EAAE,KAAK,OAAO;AAAA,IAChB;AACA,SAAK,SAAS;AACd,SAAK,OAAO,KAAK,YAAY;AAAA,EAC/B;AACF;AAsBO,MAAM,gBAAqC;AAAA,EAChD,OAAO;AAAA,EACP;AAAA,EAEA,YAAY,SAAiB;AAC3B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,WAAW,MAAe;AAC5B;AAGA,SAAS,wBAAwB,gBAAwB,QAA4C;AACnG,MAAI,OAAO,OAAO,aAAa,YAAY,eAAe,SAAS,GAAG;AACpE,WAAO,WAAW,GAAG,cAAc,IAAI,OAAO,QAAQ;AAAA,EACxD;AACA,SAAO;AACT;AAEA,eAAsB,aACpB,OACA,WACA,4BAC8C;AAC9C,QAAM,aAAa,cAAc,KAAK;AACtC,QAAM,QAAQ,WAAW;AAEzB,QAAM,qBAAqB,CAAC,YAAoB;AAC9C,QAAI,CAAC,4BA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ib/isFloat.js";
|
|
7
7
|
import isLength from "validator/es/lib/isLength.js";
|
|
8
|
-
import isNumeric from "validator/es/lib/isNumeric.js";
|
|
9
8
|
import matches from "validator/es/lib/matches.js";
|
|
10
9
|
import toFloat from "validator/es/lib/toFloat.js";
|
|
11
10
|
class AbstractValidator {
|
|
@@ -38,7 +37,8 @@ function _value(attrs) {
|
|
|
38
37
|
}
|
|
39
38
|
class NumberValidator extends AbstractValidator {
|
|
40
39
|
validate(value) {
|
|
41
|
-
|
|
40
|
+
const num = Number(value);
|
|
41
|
+
return !isNaN(num) && isFinite(num);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
class IsNumber extends NumberValidator {
|
package/Validators.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/Validators.ts"],
|
|
4
|
-
"sourcesContent": ["import isAfter from 'validator/es/lib/isAfter.js';\nimport isBefore from 'validator/es/lib/isBefore.js';\nimport isBoolean from 'validator/es/lib/isBoolean.js';\nimport isDecimal from 'validator/es/lib/isDecimal.js';\nimport isEmail from 'validator/es/lib/isEmail.js';\nimport isFloat from 'validator/es/lib/isFloat.js';\nimport isLength from 'validator/es/lib/isLength.js';\nimport isNumeric from 'validator/es/lib/isNumeric.js';\nimport matches from 'validator/es/lib/matches.js';\nimport toFloat from 'validator/es/lib/toFloat.js';\nimport type { Validator } from './Validation.js';\n\ninterface ValidatorAttributes {\n message?: string;\n}\ninterface ValueNumberAttributes extends ValidatorAttributes {\n value: number | string;\n}\ninterface DigitAttributes extends ValidatorAttributes {\n integer: number;\n fraction: number;\n}\ninterface SizeAttributes extends ValidatorAttributes {\n min?: number;\n max?: number;\n}\ninterface PatternAttributes extends ValidatorAttributes {\n regexp: RegExp | string;\n}\ninterface DecimalAttributes extends ValueNumberAttributes {\n inclusive?: boolean;\n}\n\nabstract class AbstractValidator<T> implements Validator<T> {\n message = 'invalid';\n\n impliesRequired = false;\n\n constructor(attrs?: ValidatorAttributes) {\n if (attrs?.message) {\n this.message = attrs.message;\n }\n }\n\n abstract validate(value: T): Promise<boolean> | boolean;\n abstract get name(): string;\n}\n\nexport class Required<T> extends AbstractValidator<T> {\n override impliesRequired = true;\n\n override validate(value: T): boolean {\n if (typeof value === 'string' || Array.isArray(value)) {\n return value.length > 0;\n }\n if (typeof value === 'number') {\n return Number.isFinite(value);\n }\n return value !== undefined;\n }\n\n readonly name: string = 'Required';\n}\n\nfunction _asValidatorAttributes(attrs: PatternAttributes | RegExp | ValueNumberAttributes | number | string) {\n return typeof attrs === 'object' ? attrs : {};\n}\n\nfunction _value(attrs: ValueNumberAttributes | number | string) {\n return typeof attrs === 'object' ? attrs.value : attrs;\n}\n\nabstract class NumberValidator<T> extends AbstractValidator<T> {\n override validate(value: T) {\n return isNumeric(String(value));\n }\n}\n\nexport class IsNumber extends NumberValidator<number | null | undefined> {\n optional: boolean;\n\n constructor(optional: boolean, attrs?: ValidatorAttributes) {\n super({ message: 'must be a number', ...attrs });\n this.optional = optional;\n }\n\n override validate(value: number | null | undefined): boolean {\n return (this.optional && value == null) || super.validate(value);\n }\n\n readonly name = 'IsNumber';\n}\n\nabstract class ValueNumberValidator<T> extends NumberValidator<T> {\n value: number;\n\n protected constructor(attrs: ValueNumberAttributes | number | string) {\n super(_asValidatorAttributes(attrs));\n const val = _value(attrs);\n this.value = typeof val === 'string' ? parseFloat(val) : val;\n }\n}\n\n// JSR380 equivalent (https://beanvalidation.org/2.0/spec/#builtinconstraints)\nexport class Email extends AbstractValidator<string> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be a well-formed email address', ...attrs });\n }\n\n override validate(value: string | null | undefined): boolean {\n return !value || isEmail(value);\n }\n\n readonly name = 'Email';\n}\n\nexport class Null extends AbstractValidator<any> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be null', ...attrs });\n }\n\n override validate(value: any): boolean {\n return value == null;\n }\n\n readonly name = 'Null';\n}\n\nexport class NotNull<T> extends Required<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must not be null', ...attrs });\n }\n\n override validate(value: T): value is NonNullable<T> {\n return !new Null().validate(value);\n }\n\n override readonly name = 'NotNull';\n}\n\nexport class NotEmpty<T> extends Required<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must not be empty', ...attrs });\n }\n\n override validate(value: T): boolean {\n return (\n super.validate(value) && new NotNull<T>().validate(value) && ((value as { length?: number }).length ?? 0) > 0\n );\n }\n\n override readonly name = 'NotEmpty';\n}\n\nexport class NotBlank<T> extends Required<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must not be blank', ...attrs });\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && new NotNull<T>().validate(value) && String(value).trim().length > 0;\n }\n\n override readonly name = 'NotBlank';\n}\n\nexport class AssertTrue<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be true', ...attrs });\n }\n\n override validate(value: T): boolean {\n return isBoolean(String(value)) && String(value) === 'true';\n }\n\n readonly name = 'AssertTrue';\n}\n\nexport class AssertFalse<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be false', ...attrs });\n }\n\n override validate(value: T): boolean {\n return !new AssertTrue<T>().validate(value);\n }\n\n readonly name = 'AssertFalse';\n}\n\nfunction _asValueNumberAttributes(attrs: ValueNumberAttributes | number | string) {\n return typeof attrs === 'object' ? attrs : { value: attrs };\n}\n\nexport class Min<T> extends ValueNumberValidator<T> {\n constructor(attrs: ValueNumberAttributes | number | string) {\n super({\n message: `must be greater than or equal to ${_value(attrs)}`,\n ..._asValueNumberAttributes(attrs),\n });\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && isFloat(String(value), { min: this.value });\n }\n\n readonly name = 'Min';\n}\n\nexport class Max<T> extends ValueNumberValidator<T> {\n constructor(attrs: ValueNumberAttributes | number | string) {\n super({\n message: `must be less than or equal to ${_value(attrs)}`,\n ..._asValueNumberAttributes(attrs),\n });\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && isFloat(String(value), { max: this.value });\n }\n\n readonly name = 'Max';\n}\n\nfunction _inclusive(attrs: DecimalAttributes | number | string) {\n return typeof attrs !== 'object' || attrs.inclusive !== false;\n}\n\nexport class DecimalMin<T> extends ValueNumberValidator<T> {\n inclusive: boolean;\n\n constructor(attrs: DecimalAttributes | number | string) {\n super({\n message: `must be greater than ${_inclusive(attrs) ? 'or equal to ' : ''}${_value(attrs)}`,\n ..._asValueNumberAttributes(attrs),\n });\n this.inclusive = _inclusive(attrs);\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && isFloat(String(value), { [this.inclusive ? 'min' : 'gt']: this.value });\n }\n\n readonly name = 'DecimalMin';\n}\n\nexport class DecimalMax<T> extends ValueNumberValidator<T> {\n inclusive: boolean;\n\n constructor(attrs: DecimalAttributes | number | string) {\n super({\n message: `must be less than ${_inclusive(attrs) ? 'or equal to ' : ''}${_value(attrs)}`,\n ..._asValueNumberAttributes(attrs),\n });\n this.inclusive = _inclusive(attrs);\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && isFloat(String(value), { [this.inclusive ? 'max' : 'lt']: this.value });\n }\n\n readonly name = 'DecimalMax';\n}\n\nexport class Negative<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be less than 0', ...attrs });\n }\n\n override validate(value: T): boolean {\n return toFloat(String(value)) < 0;\n }\n\n readonly name = 'Negative';\n}\n\nexport class NegativeOrZero<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be less than or equal to 0', ...attrs });\n }\n\n override validate(value: T): boolean {\n return toFloat(String(value)) <= 0;\n }\n\n readonly name = 'NegativeOrZero';\n}\n\nexport class Positive<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be greater than 0', ...attrs });\n }\n\n override validate(value: T): boolean {\n return toFloat(String(value)) > 0;\n }\n\n readonly name = 'Positive';\n}\n\nexport class PositiveOrZero<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be greater than or equal to 0', ...attrs });\n }\n\n override validate(value: T): boolean {\n return toFloat(String(value)) >= 0;\n }\n\n readonly name = 'PositiveOrZero';\n}\n\nfunction _min(attrs: SizeAttributes) {\n return attrs.min ?? 0;\n}\n\nfunction _max(attrs: SizeAttributes) {\n return attrs.max ?? Number.MAX_SAFE_INTEGER;\n}\n\nexport class Size extends AbstractValidator<string> {\n min: number;\n max: number;\n\n constructor(attrs: SizeAttributes = {}) {\n super({ message: `size must be between ${_min(attrs)} and ${_max(attrs)}`, ...attrs });\n this.min = _min(attrs);\n this.max = _max(attrs);\n if (this.min > 0) {\n this.impliesRequired = true;\n }\n }\n\n override validate(value: string): boolean {\n if (this.min && this.min > 0 && !new Required().validate(value)) {\n return false;\n }\n // eslint-disable-next-line sort-keys\n return isLength(value, { min: this.min, max: this.max });\n }\n\n readonly name = 'Size';\n}\n\nexport class Digits<T> extends AbstractValidator<T> {\n integer: number;\n fraction: number;\n\n constructor(attrs: DigitAttributes) {\n super({\n message: `numeric value out of bounds (<${attrs.integer} digits>.<${attrs.fraction} digits> expected)`,\n ...attrs,\n });\n this.integer = attrs.integer;\n this.fraction = attrs.fraction;\n }\n\n override validate(value: T): boolean {\n return (\n String(Math.floor(Math.abs(toFloat(String(value))))).length <= this.integer &&\n // eslint-disable-next-line camelcase\n isDecimal(String(value), { decimal_digits: `0,${this.fraction}` })\n );\n }\n\n readonly name = 'Digits';\n}\n\nexport class Past<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be a past date', ...attrs });\n }\n\n override validate(value: T): boolean {\n return isBefore(String(value));\n }\n\n readonly name = 'Past';\n}\n\n/*\n @PastOrPresent has no client-side implementation yet.\n It would consider any input valid and let the server-side to do validation.\n (It's not trivial to ensure the same granularity of _present_ as on the server-side:\n year / month / day / minute).\n*/\n// export class PastOrPresent extends AbstractValidator<any> {\n// constructor(attrs?: ValidatorAttributes) {\n// super({ message: 'must be a date in the past or in the present', ...attrs });\n// }\n// validate() {\n// return true;\n// }\n// }\n\nexport class Future<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be a future date', ...attrs });\n }\n\n override validate(value: T): boolean {\n return isAfter(String(value));\n }\n\n readonly name = 'Future';\n}\n\n/*\n @FutureOrPresent has no client-side implementation yet.\n It would consider any input valid and let the server-side to do validation.\n (It's not trivial to ensure the same granularity of _present_ as on the server-side:\n year / month / day / minute).\n*/\n// export class FutureOrPresent extends AbstractValidator<any> {\n// constructor(attrs?: ValidatorAttributes) {\n// super({ message: 'must be a date in the present or in the future', ...attrs });\n// }\n// validate = () => true;\n// }\n\nfunction _regexp(attrs: PatternAttributes | RegExp | string) {\n if (typeof attrs === 'string') {\n return new RegExp(attrs, 'u');\n }\n\n if (attrs instanceof RegExp) {\n return attrs;\n }\n\n if (typeof attrs.regexp === 'string') {\n return new RegExp(attrs.regexp, 'u');\n }\n\n return attrs.regexp;\n}\n\nexport class Pattern extends AbstractValidator<string> {\n regexp: RegExp;\n\n constructor(attrs: PatternAttributes | RegExp | string) {\n super({\n message: `must match the following regular expression: ${_regexp(attrs).toString()}`,\n ..._asValidatorAttributes(attrs),\n });\n this.regexp = _regexp(attrs);\n }\n\n override validate(value: any): boolean {\n return matches(value, this.regexp);\n }\n\n readonly name = 'Pattern';\n}\n\n/**\n * Validator that reports an error when the bound HTML element validation\n * returns false from `element.checkValidity()` and `element.validity.valid`.\n */\nexport class ValidityStateValidator<T> extends AbstractValidator<T> {\n override message = '';\n\n // eslint-disable-next-line no-useless-constructor,@typescript-eslint/no-useless-constructor\n constructor() {\n super();\n }\n\n override validate(): boolean {\n return false;\n }\n\n readonly name = 'ValidityStateValidator';\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,aAAa;AACpB,OAAO,cAAc;AACrB,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,OAAO,aAAa;AACpB,OAAO,aAAa;AACpB,OAAO,cAAc;AACrB,OAAO,
|
|
4
|
+
"sourcesContent": ["import isAfter from 'validator/es/lib/isAfter.js';\nimport isBefore from 'validator/es/lib/isBefore.js';\nimport isBoolean from 'validator/es/lib/isBoolean.js';\nimport isDecimal from 'validator/es/lib/isDecimal.js';\nimport isEmail from 'validator/es/lib/isEmail.js';\nimport isFloat from 'validator/es/lib/isFloat.js';\nimport isLength from 'validator/es/lib/isLength.js';\nimport matches from 'validator/es/lib/matches.js';\nimport toFloat from 'validator/es/lib/toFloat.js';\nimport type { Validator } from './Validation.js';\n\ninterface ValidatorAttributes {\n message?: string;\n}\ninterface ValueNumberAttributes extends ValidatorAttributes {\n value: number | string;\n}\ninterface DigitAttributes extends ValidatorAttributes {\n integer: number;\n fraction: number;\n}\ninterface SizeAttributes extends ValidatorAttributes {\n min?: number;\n max?: number;\n}\ninterface PatternAttributes extends ValidatorAttributes {\n regexp: RegExp | string;\n}\ninterface DecimalAttributes extends ValueNumberAttributes {\n inclusive?: boolean;\n}\n\nabstract class AbstractValidator<T> implements Validator<T> {\n message = 'invalid';\n\n impliesRequired = false;\n\n constructor(attrs?: ValidatorAttributes) {\n if (attrs?.message) {\n this.message = attrs.message;\n }\n }\n\n abstract validate(value: T): Promise<boolean> | boolean;\n abstract get name(): string;\n}\n\nexport class Required<T> extends AbstractValidator<T> {\n override impliesRequired = true;\n\n override validate(value: T): boolean {\n if (typeof value === 'string' || Array.isArray(value)) {\n return value.length > 0;\n }\n if (typeof value === 'number') {\n return Number.isFinite(value);\n }\n return value !== undefined;\n }\n\n readonly name: string = 'Required';\n}\n\nfunction _asValidatorAttributes(attrs: PatternAttributes | RegExp | ValueNumberAttributes | number | string) {\n return typeof attrs === 'object' ? attrs : {};\n}\n\nfunction _value(attrs: ValueNumberAttributes | number | string) {\n return typeof attrs === 'object' ? attrs.value : attrs;\n}\n\nabstract class NumberValidator<T> extends AbstractValidator<T> {\n override validate(value: T) {\n const num = Number(value);\n return !isNaN(num) && isFinite(num);\n }\n}\n\nexport class IsNumber extends NumberValidator<number | null | undefined> {\n optional: boolean;\n\n constructor(optional: boolean, attrs?: ValidatorAttributes) {\n super({ message: 'must be a number', ...attrs });\n this.optional = optional;\n }\n\n override validate(value: number | null | undefined): boolean {\n return (this.optional && value == null) || super.validate(value);\n }\n\n readonly name = 'IsNumber';\n}\n\nabstract class ValueNumberValidator<T> extends NumberValidator<T> {\n value: number;\n\n protected constructor(attrs: ValueNumberAttributes | number | string) {\n super(_asValidatorAttributes(attrs));\n const val = _value(attrs);\n this.value = typeof val === 'string' ? parseFloat(val) : val;\n }\n}\n\n// JSR380 equivalent (https://beanvalidation.org/2.0/spec/#builtinconstraints)\nexport class Email extends AbstractValidator<string> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be a well-formed email address', ...attrs });\n }\n\n override validate(value: string | null | undefined): boolean {\n return !value || isEmail(value);\n }\n\n readonly name = 'Email';\n}\n\nexport class Null extends AbstractValidator<any> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be null', ...attrs });\n }\n\n override validate(value: any): boolean {\n return value == null;\n }\n\n readonly name = 'Null';\n}\n\nexport class NotNull<T> extends Required<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must not be null', ...attrs });\n }\n\n override validate(value: T): value is NonNullable<T> {\n return !new Null().validate(value);\n }\n\n override readonly name = 'NotNull';\n}\n\nexport class NotEmpty<T> extends Required<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must not be empty', ...attrs });\n }\n\n override validate(value: T): boolean {\n return (\n super.validate(value) && new NotNull<T>().validate(value) && ((value as { length?: number }).length ?? 0) > 0\n );\n }\n\n override readonly name = 'NotEmpty';\n}\n\nexport class NotBlank<T> extends Required<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must not be blank', ...attrs });\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && new NotNull<T>().validate(value) && String(value).trim().length > 0;\n }\n\n override readonly name = 'NotBlank';\n}\n\nexport class AssertTrue<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be true', ...attrs });\n }\n\n override validate(value: T): boolean {\n return isBoolean(String(value)) && String(value) === 'true';\n }\n\n readonly name = 'AssertTrue';\n}\n\nexport class AssertFalse<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be false', ...attrs });\n }\n\n override validate(value: T): boolean {\n return !new AssertTrue<T>().validate(value);\n }\n\n readonly name = 'AssertFalse';\n}\n\nfunction _asValueNumberAttributes(attrs: ValueNumberAttributes | number | string) {\n return typeof attrs === 'object' ? attrs : { value: attrs };\n}\n\nexport class Min<T> extends ValueNumberValidator<T> {\n constructor(attrs: ValueNumberAttributes | number | string) {\n super({\n message: `must be greater than or equal to ${_value(attrs)}`,\n ..._asValueNumberAttributes(attrs),\n });\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && isFloat(String(value), { min: this.value });\n }\n\n readonly name = 'Min';\n}\n\nexport class Max<T> extends ValueNumberValidator<T> {\n constructor(attrs: ValueNumberAttributes | number | string) {\n super({\n message: `must be less than or equal to ${_value(attrs)}`,\n ..._asValueNumberAttributes(attrs),\n });\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && isFloat(String(value), { max: this.value });\n }\n\n readonly name = 'Max';\n}\n\nfunction _inclusive(attrs: DecimalAttributes | number | string) {\n return typeof attrs !== 'object' || attrs.inclusive !== false;\n}\n\nexport class DecimalMin<T> extends ValueNumberValidator<T> {\n inclusive: boolean;\n\n constructor(attrs: DecimalAttributes | number | string) {\n super({\n message: `must be greater than ${_inclusive(attrs) ? 'or equal to ' : ''}${_value(attrs)}`,\n ..._asValueNumberAttributes(attrs),\n });\n this.inclusive = _inclusive(attrs);\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && isFloat(String(value), { [this.inclusive ? 'min' : 'gt']: this.value });\n }\n\n readonly name = 'DecimalMin';\n}\n\nexport class DecimalMax<T> extends ValueNumberValidator<T> {\n inclusive: boolean;\n\n constructor(attrs: DecimalAttributes | number | string) {\n super({\n message: `must be less than ${_inclusive(attrs) ? 'or equal to ' : ''}${_value(attrs)}`,\n ..._asValueNumberAttributes(attrs),\n });\n this.inclusive = _inclusive(attrs);\n }\n\n override validate(value: T): boolean {\n return super.validate(value) && isFloat(String(value), { [this.inclusive ? 'max' : 'lt']: this.value });\n }\n\n readonly name = 'DecimalMax';\n}\n\nexport class Negative<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be less than 0', ...attrs });\n }\n\n override validate(value: T): boolean {\n return toFloat(String(value)) < 0;\n }\n\n readonly name = 'Negative';\n}\n\nexport class NegativeOrZero<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be less than or equal to 0', ...attrs });\n }\n\n override validate(value: T): boolean {\n return toFloat(String(value)) <= 0;\n }\n\n readonly name = 'NegativeOrZero';\n}\n\nexport class Positive<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be greater than 0', ...attrs });\n }\n\n override validate(value: T): boolean {\n return toFloat(String(value)) > 0;\n }\n\n readonly name = 'Positive';\n}\n\nexport class PositiveOrZero<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be greater than or equal to 0', ...attrs });\n }\n\n override validate(value: T): boolean {\n return toFloat(String(value)) >= 0;\n }\n\n readonly name = 'PositiveOrZero';\n}\n\nfunction _min(attrs: SizeAttributes) {\n return attrs.min ?? 0;\n}\n\nfunction _max(attrs: SizeAttributes) {\n return attrs.max ?? Number.MAX_SAFE_INTEGER;\n}\n\nexport class Size extends AbstractValidator<string> {\n min: number;\n max: number;\n\n constructor(attrs: SizeAttributes = {}) {\n super({ message: `size must be between ${_min(attrs)} and ${_max(attrs)}`, ...attrs });\n this.min = _min(attrs);\n this.max = _max(attrs);\n if (this.min > 0) {\n this.impliesRequired = true;\n }\n }\n\n override validate(value: string): boolean {\n if (this.min && this.min > 0 && !new Required().validate(value)) {\n return false;\n }\n // eslint-disable-next-line sort-keys\n return isLength(value, { min: this.min, max: this.max });\n }\n\n readonly name = 'Size';\n}\n\nexport class Digits<T> extends AbstractValidator<T> {\n integer: number;\n fraction: number;\n\n constructor(attrs: DigitAttributes) {\n super({\n message: `numeric value out of bounds (<${attrs.integer} digits>.<${attrs.fraction} digits> expected)`,\n ...attrs,\n });\n this.integer = attrs.integer;\n this.fraction = attrs.fraction;\n }\n\n override validate(value: T): boolean {\n return (\n String(Math.floor(Math.abs(toFloat(String(value))))).length <= this.integer &&\n // eslint-disable-next-line camelcase\n isDecimal(String(value), { decimal_digits: `0,${this.fraction}` })\n );\n }\n\n readonly name = 'Digits';\n}\n\nexport class Past<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be a past date', ...attrs });\n }\n\n override validate(value: T): boolean {\n return isBefore(String(value));\n }\n\n readonly name = 'Past';\n}\n\n/*\n @PastOrPresent has no client-side implementation yet.\n It would consider any input valid and let the server-side to do validation.\n (It's not trivial to ensure the same granularity of _present_ as on the server-side:\n year / month / day / minute).\n*/\n// export class PastOrPresent extends AbstractValidator<any> {\n// constructor(attrs?: ValidatorAttributes) {\n// super({ message: 'must be a date in the past or in the present', ...attrs });\n// }\n// validate() {\n// return true;\n// }\n// }\n\nexport class Future<T> extends AbstractValidator<T> {\n constructor(attrs?: ValidatorAttributes) {\n super({ message: 'must be a future date', ...attrs });\n }\n\n override validate(value: T): boolean {\n return isAfter(String(value));\n }\n\n readonly name = 'Future';\n}\n\n/*\n @FutureOrPresent has no client-side implementation yet.\n It would consider any input valid and let the server-side to do validation.\n (It's not trivial to ensure the same granularity of _present_ as on the server-side:\n year / month / day / minute).\n*/\n// export class FutureOrPresent extends AbstractValidator<any> {\n// constructor(attrs?: ValidatorAttributes) {\n// super({ message: 'must be a date in the present or in the future', ...attrs });\n// }\n// validate = () => true;\n// }\n\nfunction _regexp(attrs: PatternAttributes | RegExp | string) {\n if (typeof attrs === 'string') {\n return new RegExp(attrs, 'u');\n }\n\n if (attrs instanceof RegExp) {\n return attrs;\n }\n\n if (typeof attrs.regexp === 'string') {\n return new RegExp(attrs.regexp, 'u');\n }\n\n return attrs.regexp;\n}\n\nexport class Pattern extends AbstractValidator<string> {\n regexp: RegExp;\n\n constructor(attrs: PatternAttributes | RegExp | string) {\n super({\n message: `must match the following regular expression: ${_regexp(attrs).toString()}`,\n ..._asValidatorAttributes(attrs),\n });\n this.regexp = _regexp(attrs);\n }\n\n override validate(value: any): boolean {\n return matches(value, this.regexp);\n }\n\n readonly name = 'Pattern';\n}\n\n/**\n * Validator that reports an error when the bound HTML element validation\n * returns false from `element.checkValidity()` and `element.validity.valid`.\n */\nexport class ValidityStateValidator<T> extends AbstractValidator<T> {\n override message = '';\n\n // eslint-disable-next-line no-useless-constructor,@typescript-eslint/no-useless-constructor\n constructor() {\n super();\n }\n\n override validate(): boolean {\n return false;\n }\n\n readonly name = 'ValidityStateValidator';\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,aAAa;AACpB,OAAO,cAAc;AACrB,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,OAAO,aAAa;AACpB,OAAO,aAAa;AACpB,OAAO,cAAc;AACrB,OAAO,aAAa;AACpB,OAAO,aAAa;AAwBpB,MAAe,kBAA6C;AAAA,EAC1D,UAAU;AAAA,EAEV,kBAAkB;AAAA,EAElB,YAAY,OAA6B;AACvC,QAAI,OAAO,SAAS;AAClB,WAAK,UAAU,MAAM;AAAA,IACvB;AAAA,EACF;AAIF;AAEO,MAAM,iBAAoB,kBAAqB;AAAA,EAC3C,kBAAkB;AAAA,EAElB,SAAS,OAAmB;AACnC,QAAI,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;AACrD,aAAO,MAAM,SAAS;AAAA,IACxB;AACA,QAAI,OAAO,UAAU,UAAU;AAC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AAO;AAAA,EACT;AAAA,EAES,OAAO;AAClB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@ function __REGISTER__(feature, vaadinObj = window.Vaadin ??= {}) {
|
|
|
2
2
|
vaadinObj.registrations ??= [];
|
|
3
3
|
vaadinObj.registrations.push({
|
|
4
4
|
is: feature ? `${"@vaadin/hilla-lit-form"}/${feature}` : "@vaadin/hilla-lit-form",
|
|
5
|
-
version: "24.5.0-
|
|
5
|
+
version: "24.5.0-alpha10"
|
|
6
6
|
});
|
|
7
7
|
}
|
|
8
8
|
export * from "./Binder.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-lit-form",
|
|
3
|
-
"version": "24.5.0-
|
|
3
|
+
"version": "24.5.0-alpha10",
|
|
4
4
|
"description": "Hilla form utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"build": "concurrently npm:build:*",
|
|
20
20
|
"build:esbuild": "tsx ../../../scripts/build.ts",
|
|
21
21
|
"build:dts": "tsc --isolatedModules -p tsconfig.build.json",
|
|
22
|
-
"lint": "eslint src
|
|
23
|
-
"lint:fix": "
|
|
24
|
-
"test": "karma start ../../../karma.config.cjs --port
|
|
22
|
+
"lint": "eslint src test",
|
|
23
|
+
"lint:fix": "npm run lint -- --fix",
|
|
24
|
+
"test": "karma start ../../../karma.config.cjs --port 9876",
|
|
25
25
|
"test:coverage": "npm run test -- --coverage",
|
|
26
26
|
"test:watch": "npm run test -- --watch",
|
|
27
27
|
"typecheck": "tsc --noEmit"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@vaadin/hilla-frontend": "24.5.0-
|
|
74
|
+
"@vaadin/hilla-frontend": "24.5.0-alpha10",
|
|
75
75
|
"validator": "^13.11.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
@@ -88,6 +88,6 @@
|
|
|
88
88
|
"chai-dom": "^1.11.0",
|
|
89
89
|
"sinon": "^16.0.0",
|
|
90
90
|
"sinon-chai": "^3.7.0",
|
|
91
|
-
"typescript": "5.
|
|
91
|
+
"typescript": "5.5.2"
|
|
92
92
|
}
|
|
93
93
|
}
|