@vaadin/hilla-lit-form 24.4.0-alpha1
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/.lintstagedrc.js +6 -0
- package/Binder.d.ts +28 -0
- package/Binder.d.ts.map +1 -0
- package/Binder.js +29 -0
- package/Binder.js.map +7 -0
- package/BinderNode.d.ts +123 -0
- package/BinderNode.d.ts.map +1 -0
- package/BinderNode.js +414 -0
- package/BinderNode.js.map +7 -0
- package/BinderRoot.d.ts +98 -0
- package/BinderRoot.d.ts.map +1 -0
- package/BinderRoot.js +242 -0
- package/BinderRoot.js.map +7 -0
- package/Field.d.ts +125 -0
- package/Field.d.ts.map +1 -0
- package/Field.js +293 -0
- package/Field.js.map +7 -0
- package/LICENSE +201 -0
- package/Models.d.ts +92 -0
- package/Models.d.ts.map +1 -0
- package/Models.js +166 -0
- package/Models.js.map +7 -0
- package/README.md +26 -0
- package/Validation.d.ts +33 -0
- package/Validation.d.ts.map +1 -0
- package/Validation.js +86 -0
- package/Validation.js.map +7 -0
- package/Validators.d.ts +165 -0
- package/Validators.d.ts.map +1 -0
- package/Validators.js +342 -0
- package/Validators.js.map +7 -0
- package/Validity.d.ts +9 -0
- package/Validity.d.ts.map +1 -0
- package/Validity.js +19 -0
- package/Validity.js.map +7 -0
- package/index.d.ts +9 -0
- package/index.d.ts.map +1 -0
- package/index.js +18 -0
- package/index.js.map +7 -0
- package/package.json +93 -0
- package/types.d.js +1 -0
- package/types.d.js.map +7 -0
package/Models.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import isNumeric from "validator/es/lib/isNumeric.js";
|
|
2
|
+
import { getBinderNode } from "./BinderNode.js";
|
|
3
|
+
import { IsNumber } from "./Validators.js";
|
|
4
|
+
const _createEmptyItemValue = Symbol("itemModel");
|
|
5
|
+
const _parent = Symbol("parent");
|
|
6
|
+
const _key = Symbol("key");
|
|
7
|
+
const _fromString = Symbol("fromString");
|
|
8
|
+
const _validators = Symbol("validators");
|
|
9
|
+
const _meta = Symbol("meta");
|
|
10
|
+
const _getPropertyModel = Symbol("getPropertyModel");
|
|
11
|
+
const _enum = Symbol("enum");
|
|
12
|
+
const _optional = Symbol("optional");
|
|
13
|
+
function hasFromString(model) {
|
|
14
|
+
return _fromString in model;
|
|
15
|
+
}
|
|
16
|
+
const modelDetachedParent = { $value$: void 0 };
|
|
17
|
+
function createDetachedModel(type) {
|
|
18
|
+
return new type(modelDetachedParent, "$value$", false);
|
|
19
|
+
}
|
|
20
|
+
class AbstractModel {
|
|
21
|
+
static createEmptyValue() {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
[_parent];
|
|
25
|
+
[_validators];
|
|
26
|
+
[_meta];
|
|
27
|
+
[_optional];
|
|
28
|
+
[_key];
|
|
29
|
+
constructor(parent, key, optional, options) {
|
|
30
|
+
this[_parent] = parent;
|
|
31
|
+
this[_key] = key;
|
|
32
|
+
this[_optional] = optional;
|
|
33
|
+
this[_validators] = options?.validators ?? [];
|
|
34
|
+
this[_meta] = options?.meta ?? {};
|
|
35
|
+
}
|
|
36
|
+
toString() {
|
|
37
|
+
return String(this.valueOf());
|
|
38
|
+
}
|
|
39
|
+
valueOf() {
|
|
40
|
+
const { value } = getBinderNode(this);
|
|
41
|
+
if (value === void 0) {
|
|
42
|
+
throw new TypeError("Value is undefined");
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class PrimitiveModel extends AbstractModel {
|
|
48
|
+
}
|
|
49
|
+
class BooleanModel extends PrimitiveModel {
|
|
50
|
+
static createEmptyValue = Boolean;
|
|
51
|
+
[_fromString](str) {
|
|
52
|
+
return ["true", "1", "yes"].includes(str.toLowerCase());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
class NumberModel extends PrimitiveModel {
|
|
56
|
+
static createEmptyValue = Number;
|
|
57
|
+
constructor(parent, key, optional, options) {
|
|
58
|
+
const validators = [new IsNumber(optional), ...options?.validators ?? []];
|
|
59
|
+
super(parent, key, optional, { ...options, validators });
|
|
60
|
+
}
|
|
61
|
+
[_fromString](str) {
|
|
62
|
+
if (str === "")
|
|
63
|
+
return void 0;
|
|
64
|
+
return isNumeric(str) ? Number.parseFloat(str) : NaN;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class StringModel extends PrimitiveModel {
|
|
68
|
+
static createEmptyValue = String;
|
|
69
|
+
[_fromString] = String;
|
|
70
|
+
}
|
|
71
|
+
function makeEnumEmptyValueCreator(type) {
|
|
72
|
+
const { [_enum]: enumObject } = createDetachedModel(type);
|
|
73
|
+
const defaultValue = Object.values(enumObject)[0];
|
|
74
|
+
return () => defaultValue;
|
|
75
|
+
}
|
|
76
|
+
class EnumModel extends AbstractModel {
|
|
77
|
+
[_fromString](value) {
|
|
78
|
+
return value in this[_enum] ? value : void 0;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function* getObjectModelOwnAndParentGetters(model) {
|
|
82
|
+
for (let proto = Object.getPrototypeOf(model); proto !== ObjectModel.prototype; proto = Object.getPrototypeOf(proto)) {
|
|
83
|
+
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
84
|
+
for (const [name, { get }] of Object.entries(descriptors)) {
|
|
85
|
+
if (get) {
|
|
86
|
+
yield [name, get];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function makeObjectEmptyValueCreator(type) {
|
|
92
|
+
const model = createDetachedModel(type);
|
|
93
|
+
return () => {
|
|
94
|
+
const obj = {};
|
|
95
|
+
for (const [key, getter] of getObjectModelOwnAndParentGetters(model)) {
|
|
96
|
+
const propertyModel = getter.call(model);
|
|
97
|
+
obj[key] = propertyModel[_optional] ? void 0 : propertyModel.constructor.createEmptyValue();
|
|
98
|
+
}
|
|
99
|
+
return obj;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
class ObjectModel extends AbstractModel {
|
|
103
|
+
static createEmptyValue = makeObjectEmptyValueCreator(ObjectModel);
|
|
104
|
+
#properties = {};
|
|
105
|
+
[_getPropertyModel](key, init) {
|
|
106
|
+
if (!this.#properties[key]) {
|
|
107
|
+
this.#properties[key] = init(this, key);
|
|
108
|
+
}
|
|
109
|
+
return this.#properties[key];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class ArrayModel extends AbstractModel {
|
|
113
|
+
static createEmptyValue() {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
[_createEmptyItemValue];
|
|
117
|
+
#createItem;
|
|
118
|
+
#items = [];
|
|
119
|
+
constructor(parent, key, optional, createItem, options) {
|
|
120
|
+
super(parent, key, optional, options);
|
|
121
|
+
this.#createItem = createItem;
|
|
122
|
+
this[_createEmptyItemValue] = createItem(this, 0).constructor.createEmptyValue;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Iterates the current array value and yields a binder node for every item.
|
|
126
|
+
*/
|
|
127
|
+
*[Symbol.iterator]() {
|
|
128
|
+
const array = this.valueOf();
|
|
129
|
+
if (array.length !== this.#items.length) {
|
|
130
|
+
this.#items.length = array.length;
|
|
131
|
+
}
|
|
132
|
+
for (let i = 0; i < array.length; i++) {
|
|
133
|
+
let item = this.#items[i];
|
|
134
|
+
if (!item) {
|
|
135
|
+
item = this.#createItem(this, i);
|
|
136
|
+
this.#items[i] = item;
|
|
137
|
+
}
|
|
138
|
+
yield getBinderNode(item);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
AbstractModel,
|
|
144
|
+
ArrayModel,
|
|
145
|
+
BooleanModel,
|
|
146
|
+
EnumModel,
|
|
147
|
+
NumberModel,
|
|
148
|
+
ObjectModel,
|
|
149
|
+
PrimitiveModel,
|
|
150
|
+
StringModel,
|
|
151
|
+
_createEmptyItemValue,
|
|
152
|
+
_enum,
|
|
153
|
+
_fromString,
|
|
154
|
+
_getPropertyModel,
|
|
155
|
+
_key,
|
|
156
|
+
_meta,
|
|
157
|
+
_parent,
|
|
158
|
+
_validators,
|
|
159
|
+
createDetachedModel,
|
|
160
|
+
getObjectModelOwnAndParentGetters,
|
|
161
|
+
hasFromString,
|
|
162
|
+
makeEnumEmptyValueCreator,
|
|
163
|
+
makeObjectEmptyValueCreator,
|
|
164
|
+
modelDetachedParent
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=Models.js.map
|
package/Models.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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('itemModel');\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');\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 toString(): string {\n return String(this.valueOf());\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\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 readonly #createItem: (parent: this, index: number) => MItem;\n #items: Array<MItem | undefined> = [];\n\n constructor(\n parent: ModelParent,\n key: keyof any,\n optional: boolean,\n createItem: (parent: ArrayModel<MItem>, 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 /**\n * Iterates the current array value and yields a binder node for every item.\n */\n *[Symbol.iterator](): IterableIterator<BinderNode<MItem>> {\n const array = this.valueOf();\n\n if (array.length !== this.#items.length) {\n this.#items.length = array.length;\n }\n\n for (let i = 0; i < array.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 getBinderNode(item);\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,eAAe;AACtB,SAA0B,qBAAqB;AAE/C,SAAS,gBAAgB;AAElB,MAAM,wBAAwB,OAAO,WAAW;AAChD,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;AAElC,MAAM,YAAY,OAAO,UAAU;AAM5B,SAAS,cAAiB,OAAuE;AACtG,SAAO,eAAe;AACx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CAAC;AAAA,EAEtD,CAAW,iBAAiB,EAC1B,KACA,MACG;AACH,QAAI,CAAC,KAAK,YAAY,GAAG,GAAG;AAC1B,WAAK,YAAY,GAAG,IAAI,KAAK,MAAM,GAAG;AAAA,IACxC;AAEA,WAAO,KAAK,YAAY,GAAG;AAAA,EAC7B;AACF;AAIO,MAAM,mBAAgE,cAAmC;AAAA,EAC9G,OAAgB,mBAAuB;AACrC,WAAO,CAAC;AAAA,EACV;AAAA,EAEA,CAAC,qBAAqB;AAAA,EAEb;AAAA,EACT,SAAmC,CAAC;AAAA,EAEpC,YACE,QACA,KACA,UACA,YACA,SACA;AACA,UAAM,QAAQ,KAAK,UAAU,OAAO;AACpC,SAAK,cAAc;AACnB,SAAK,qBAAqB,IAAI,WAAW,MAAM,CAAC,EAAE,YAAY;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA,EAKA,EAAE,OAAO,QAAQ,IAAyC;AACxD,UAAM,QAAQ,KAAK,QAAQ;AAE3B,QAAI,MAAM,WAAW,KAAK,OAAO,QAAQ;AACvC,WAAK,OAAO,SAAS,MAAM;AAAA,IAC7B;AAEA,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,UAAI,OAA0B,KAAK,OAAO,CAAC;AAE3C,UAAI,CAAC,MAAM;AACT,eAAO,KAAK,YAAY,MAAM,CAAC;AAC/B,aAAK,OAAO,CAAC,IAAI;AAAA,MACnB;AAEA,YAAM,cAAc,IAAI;AAAA,IAC1B;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Hilla Lit Form
|
|
2
|
+
|
|
3
|
+
[API documentation ↗](https://hilla.dev/docs/data-binding/reference)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@vaadin/hilla-lit-form)
|
|
6
|
+
|
|
7
|
+
A set of utilities for building forms with TypeScript and [Lit](https://lit.dev/), including data binding, validation, code generation, backend integration, Lit directives, and more.
|
|
8
|
+
|
|
9
|
+
A part of the Hilla project.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
$ npm install @vaadin/hilla-lit-form
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Contribution
|
|
18
|
+
|
|
19
|
+
Read the [contributing guide](https://vaadin.com/docs/latest/contributing-docs/overview) to learn about our development process, how to propose bugfixes and improvements, and how to test your changes to Vaadin components.
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
Apache License 2.0
|
|
24
|
+
|
|
25
|
+
Vaadin collects development time usage statistics to improve this product.
|
|
26
|
+
For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
|
package/Validation.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BinderNode } from './BinderNode.js';
|
|
2
|
+
import type { BinderRoot } from './BinderRoot.js';
|
|
3
|
+
import { type AbstractModel, type Value } from './Models.js';
|
|
4
|
+
export interface ValueError<T = unknown> {
|
|
5
|
+
property: AbstractModel | string;
|
|
6
|
+
message: string;
|
|
7
|
+
value: T;
|
|
8
|
+
validator: Validator<T>;
|
|
9
|
+
validatorMessage?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ValidationResult {
|
|
12
|
+
property: AbstractModel | string;
|
|
13
|
+
message?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class ValidationError extends Error {
|
|
16
|
+
errors: readonly ValueError[];
|
|
17
|
+
constructor(errors: readonly ValueError[]);
|
|
18
|
+
}
|
|
19
|
+
export type InterpolateMessageCallback<M extends AbstractModel> = (message: string, validator: Validator<Value<M>>, binderNode: BinderNode<M>) => string;
|
|
20
|
+
export interface Validator<T = unknown> {
|
|
21
|
+
message: string;
|
|
22
|
+
impliesRequired?: boolean;
|
|
23
|
+
name?: string;
|
|
24
|
+
validate(value: T, binder: BinderRoot): Promise<ValidationResult | boolean | readonly ValidationResult[]> | ValidationResult | boolean | readonly ValidationResult[];
|
|
25
|
+
}
|
|
26
|
+
export declare class ServerValidator implements Validator {
|
|
27
|
+
name: string;
|
|
28
|
+
message: string;
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
validate: () => boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function runValidator<M extends AbstractModel>(model: M, validator: Validator<Value<M>>, interpolateMessageCallback?: InterpolateMessageCallback<M>): Promise<ReadonlyArray<ValueError<Value<M>>>>;
|
|
33
|
+
//# sourceMappingURL=Validation.d.ts.map
|
|
@@ -0,0 +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,KAAK,aAAa,EAAe,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAG1E,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,aAAa,GAAG,MAAM,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;gBAElB,MAAM,EAAE,SAAS,UAAU,EAAE;CAY1C;AAED,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,aAAa,IAAI,CAChE,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC9B,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,KACtB,MAAM,CAAC;AAEZ,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CACN,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,UAAU,GAEhB,OAAO,CAAC,gBAAgB,GAAG,OAAO,GAAG,SAAS,gBAAgB,EAAE,CAAC,GACjE,gBAAgB,GAChB,OAAO,GACP,SAAS,gBAAgB,EAAE,CAAC;CACjC;AAED,qBAAa,eAAgB,YAAW,SAAS;IAC/C,IAAI,SAAqB;IACzB,OAAO,EAAE,MAAM,CAAC;gBAEJ,OAAO,EAAE,MAAM;IAI3B,QAAQ,QAAO,OAAO,CAAU;CACjC;AAUD,wBAAsB,YAAY,CAAC,CAAC,SAAS,aAAa,EACxD,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC9B,0BAA0B,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAyD9C"}
|
package/Validation.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { getBinderNode } from "./BinderNode.js";
|
|
2
|
+
import { NumberModel } from "./Models.js";
|
|
3
|
+
import { Required } from "./Validators.js";
|
|
4
|
+
class ValidationError extends Error {
|
|
5
|
+
errors;
|
|
6
|
+
constructor(errors) {
|
|
7
|
+
super(
|
|
8
|
+
[
|
|
9
|
+
"There are validation errors in the form.",
|
|
10
|
+
...errors.map(
|
|
11
|
+
(e) => `${e.property.toString()} - ${e.validator.constructor.name}${e.message ? `: ${e.message}` : ""}`
|
|
12
|
+
)
|
|
13
|
+
].join("\n - ")
|
|
14
|
+
);
|
|
15
|
+
this.errors = errors;
|
|
16
|
+
this.name = this.constructor.name;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class ServerValidator {
|
|
20
|
+
name = "ServerValidator";
|
|
21
|
+
message;
|
|
22
|
+
constructor(message) {
|
|
23
|
+
this.message = message;
|
|
24
|
+
}
|
|
25
|
+
validate = () => false;
|
|
26
|
+
}
|
|
27
|
+
function setPropertyAbsolutePath(binderNodeName, result) {
|
|
28
|
+
if (typeof result.property === "string" && binderNodeName.length > 0) {
|
|
29
|
+
result.property = `${binderNodeName}.${result.property}`;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async function runValidator(model, validator, interpolateMessageCallback) {
|
|
34
|
+
const binderNode = getBinderNode(model);
|
|
35
|
+
const value = binderNode.value;
|
|
36
|
+
const interpolateMessage = (message) => {
|
|
37
|
+
if (!interpolateMessageCallback) {
|
|
38
|
+
return message;
|
|
39
|
+
}
|
|
40
|
+
return interpolateMessageCallback(message, validator, binderNode);
|
|
41
|
+
};
|
|
42
|
+
if (!binderNode.required && !new Required().validate(value) && !(model instanceof NumberModel)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const result = await validator.validate(value, binderNode.binder);
|
|
47
|
+
if (result === false) {
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
message: interpolateMessage(validator.message),
|
|
51
|
+
property: binderNode.name,
|
|
52
|
+
validator,
|
|
53
|
+
value
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
if (result === true || Array.isArray(result) && result.length === 0) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(result)) {
|
|
61
|
+
return result.map((result2) => ({
|
|
62
|
+
message: interpolateMessage(validator.message),
|
|
63
|
+
...setPropertyAbsolutePath(binderNode.name, result2),
|
|
64
|
+
validator,
|
|
65
|
+
value
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
return [
|
|
69
|
+
{
|
|
70
|
+
message: interpolateMessage(validator.message),
|
|
71
|
+
...setPropertyAbsolutePath(binderNode.name, result),
|
|
72
|
+
validator,
|
|
73
|
+
value
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(`${binderNode.name} - Validator ${validator.constructor.name} threw an error:`, error);
|
|
78
|
+
return [{ message: "Validator threw an error", property: binderNode.name, validator, value }];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
ServerValidator,
|
|
83
|
+
ValidationError,
|
|
84
|
+
runValidator
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=Validation.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 { type 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(\n (e) => `${e.property.toString()} - ${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,qBA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,UAAU,WAAW;AAAA,UACrB;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,WAAW,QAAS,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,GAAI;AACrE,aAAO,CAAC;AAAA,IACV;AAEA,QAAI,MAAM,QAAQ,MAAM,GAAG;AACzB,aAAO,OAAO,IAAI,CAAC,aAAa;AAAA,QAC9B,SAAS,mBAAmB,UAAU,OAAO;AAAA,QAC7C,GAAG,wBAAwB,WAAW,MAAM,OAAO;AAAA,QACnD;AAAA,QACA;AAAA,MACF,EAAE;AAAA,IACJ;AAEA,WAAO;AAAA,MACL;AAAA,QACE,SAAS,mBAAmB,UAAU,OAAO;AAAA,QAC7C,GAAG,wBAAwB,WAAW,MAAM,MAA0B;AAAA,QACtE;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF,SAAS,OAAgB;AACvB,YAAQ,MAAM,GAAG,WAAW,IAAI,gBAAgB,UAAU,YAAY,IAAI,oBAAoB,KAAK;AACnG,WAAO,CAAC,EAAE,SAAS,4BAA4B,UAAU,WAAW,MAAM,WAAW,MAAM,CAAC;AAAA,EAC9F;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/Validators.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { Validator } from './Validation.js';
|
|
2
|
+
interface ValidatorAttributes {
|
|
3
|
+
message?: string;
|
|
4
|
+
}
|
|
5
|
+
interface ValueNumberAttributes extends ValidatorAttributes {
|
|
6
|
+
value: number | string;
|
|
7
|
+
}
|
|
8
|
+
interface DigitAttributes extends ValidatorAttributes {
|
|
9
|
+
integer: number;
|
|
10
|
+
fraction: number;
|
|
11
|
+
}
|
|
12
|
+
interface SizeAttributes extends ValidatorAttributes {
|
|
13
|
+
min?: number;
|
|
14
|
+
max?: number;
|
|
15
|
+
}
|
|
16
|
+
interface PatternAttributes extends ValidatorAttributes {
|
|
17
|
+
regexp: RegExp | string;
|
|
18
|
+
}
|
|
19
|
+
interface DecimalAttributes extends ValueNumberAttributes {
|
|
20
|
+
inclusive?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare abstract class AbstractValidator<T> implements Validator<T> {
|
|
23
|
+
message: string;
|
|
24
|
+
impliesRequired: boolean;
|
|
25
|
+
constructor(attrs?: ValidatorAttributes);
|
|
26
|
+
abstract validate(value: T): Promise<boolean> | boolean;
|
|
27
|
+
abstract get name(): string;
|
|
28
|
+
}
|
|
29
|
+
export declare class Required<T> extends AbstractValidator<T> {
|
|
30
|
+
impliesRequired: boolean;
|
|
31
|
+
validate(value: T): boolean;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
}
|
|
34
|
+
declare abstract class NumberValidator<T> extends AbstractValidator<T> {
|
|
35
|
+
validate(value: T): boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare class IsNumber extends NumberValidator<number | null | undefined> {
|
|
38
|
+
optional: boolean;
|
|
39
|
+
constructor(optional: boolean, attrs?: ValidatorAttributes);
|
|
40
|
+
validate(value: number | null | undefined): boolean;
|
|
41
|
+
readonly name = "IsNumber";
|
|
42
|
+
}
|
|
43
|
+
declare abstract class ValueNumberValidator<T> extends NumberValidator<T> {
|
|
44
|
+
value: number;
|
|
45
|
+
protected constructor(attrs: ValueNumberAttributes | number | string);
|
|
46
|
+
}
|
|
47
|
+
export declare class Email extends AbstractValidator<string> {
|
|
48
|
+
constructor(attrs?: ValidatorAttributes);
|
|
49
|
+
validate(value: string | null | undefined): boolean;
|
|
50
|
+
readonly name = "Email";
|
|
51
|
+
}
|
|
52
|
+
export declare class Null extends AbstractValidator<any> {
|
|
53
|
+
constructor(attrs?: ValidatorAttributes);
|
|
54
|
+
validate(value: any): boolean;
|
|
55
|
+
readonly name = "Null";
|
|
56
|
+
}
|
|
57
|
+
export declare class NotNull<T> extends Required<T> {
|
|
58
|
+
constructor(attrs?: ValidatorAttributes);
|
|
59
|
+
validate(value: T): value is NonNullable<T>;
|
|
60
|
+
readonly name = "NotNull";
|
|
61
|
+
}
|
|
62
|
+
export declare class NotEmpty<T> extends Required<T> {
|
|
63
|
+
constructor(attrs?: ValidatorAttributes);
|
|
64
|
+
validate(value: T): boolean;
|
|
65
|
+
readonly name = "NotEmpty";
|
|
66
|
+
}
|
|
67
|
+
export declare class NotBlank<T> extends Required<T> {
|
|
68
|
+
constructor(attrs?: ValidatorAttributes);
|
|
69
|
+
validate(value: T): boolean;
|
|
70
|
+
readonly name = "NotBlank";
|
|
71
|
+
}
|
|
72
|
+
export declare class AssertTrue<T> extends AbstractValidator<T> {
|
|
73
|
+
constructor(attrs?: ValidatorAttributes);
|
|
74
|
+
validate(value: T): boolean;
|
|
75
|
+
readonly name = "AssertTrue";
|
|
76
|
+
}
|
|
77
|
+
export declare class AssertFalse<T> extends AbstractValidator<T> {
|
|
78
|
+
constructor(attrs?: ValidatorAttributes);
|
|
79
|
+
validate(value: T): boolean;
|
|
80
|
+
readonly name = "AssertFalse";
|
|
81
|
+
}
|
|
82
|
+
export declare class Min<T> extends ValueNumberValidator<T> {
|
|
83
|
+
constructor(attrs: ValueNumberAttributes | number | string);
|
|
84
|
+
validate(value: T): boolean;
|
|
85
|
+
readonly name = "Min";
|
|
86
|
+
}
|
|
87
|
+
export declare class Max<T> extends ValueNumberValidator<T> {
|
|
88
|
+
constructor(attrs: ValueNumberAttributes | number | string);
|
|
89
|
+
validate(value: T): boolean;
|
|
90
|
+
readonly name = "Max";
|
|
91
|
+
}
|
|
92
|
+
export declare class DecimalMin<T> extends ValueNumberValidator<T> {
|
|
93
|
+
inclusive: boolean;
|
|
94
|
+
constructor(attrs: DecimalAttributes | number | string);
|
|
95
|
+
validate(value: T): boolean;
|
|
96
|
+
readonly name = "DecimalMin";
|
|
97
|
+
}
|
|
98
|
+
export declare class DecimalMax<T> extends ValueNumberValidator<T> {
|
|
99
|
+
inclusive: boolean;
|
|
100
|
+
constructor(attrs: DecimalAttributes | number | string);
|
|
101
|
+
validate(value: T): boolean;
|
|
102
|
+
readonly name = "DecimalMax";
|
|
103
|
+
}
|
|
104
|
+
export declare class Negative<T> extends AbstractValidator<T> {
|
|
105
|
+
constructor(attrs?: ValidatorAttributes);
|
|
106
|
+
validate(value: T): boolean;
|
|
107
|
+
readonly name = "Negative";
|
|
108
|
+
}
|
|
109
|
+
export declare class NegativeOrZero<T> extends AbstractValidator<T> {
|
|
110
|
+
constructor(attrs?: ValidatorAttributes);
|
|
111
|
+
validate(value: T): boolean;
|
|
112
|
+
readonly name = "NegativeOrZero";
|
|
113
|
+
}
|
|
114
|
+
export declare class Positive<T> extends AbstractValidator<T> {
|
|
115
|
+
constructor(attrs?: ValidatorAttributes);
|
|
116
|
+
validate(value: T): boolean;
|
|
117
|
+
readonly name = "Positive";
|
|
118
|
+
}
|
|
119
|
+
export declare class PositiveOrZero<T> extends AbstractValidator<T> {
|
|
120
|
+
constructor(attrs?: ValidatorAttributes);
|
|
121
|
+
validate(value: T): boolean;
|
|
122
|
+
readonly name = "PositiveOrZero";
|
|
123
|
+
}
|
|
124
|
+
export declare class Size extends AbstractValidator<string> {
|
|
125
|
+
min: number;
|
|
126
|
+
max: number;
|
|
127
|
+
constructor(attrs?: SizeAttributes);
|
|
128
|
+
validate(value: string): boolean;
|
|
129
|
+
readonly name = "Size";
|
|
130
|
+
}
|
|
131
|
+
export declare class Digits<T> extends AbstractValidator<T> {
|
|
132
|
+
integer: number;
|
|
133
|
+
fraction: number;
|
|
134
|
+
constructor(attrs: DigitAttributes);
|
|
135
|
+
validate(value: T): boolean;
|
|
136
|
+
readonly name = "Digits";
|
|
137
|
+
}
|
|
138
|
+
export declare class Past<T> extends AbstractValidator<T> {
|
|
139
|
+
constructor(attrs?: ValidatorAttributes);
|
|
140
|
+
validate(value: T): boolean;
|
|
141
|
+
readonly name = "Past";
|
|
142
|
+
}
|
|
143
|
+
export declare class Future<T> extends AbstractValidator<T> {
|
|
144
|
+
constructor(attrs?: ValidatorAttributes);
|
|
145
|
+
validate(value: T): boolean;
|
|
146
|
+
readonly name = "Future";
|
|
147
|
+
}
|
|
148
|
+
export declare class Pattern extends AbstractValidator<string> {
|
|
149
|
+
regexp: RegExp;
|
|
150
|
+
constructor(attrs: PatternAttributes | RegExp | string);
|
|
151
|
+
validate(value: any): boolean;
|
|
152
|
+
readonly name = "Pattern";
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Validator that reports an error when the bound HTML element validation
|
|
156
|
+
* returns false from `element.checkValidity()` and `element.validity.valid`.
|
|
157
|
+
*/
|
|
158
|
+
export declare class ValidityStateValidator<T> extends AbstractValidator<T> {
|
|
159
|
+
message: string;
|
|
160
|
+
constructor();
|
|
161
|
+
validate(): boolean;
|
|
162
|
+
readonly name = "ValidityStateValidator";
|
|
163
|
+
}
|
|
164
|
+
export {};
|
|
165
|
+
//# sourceMappingURL=Validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validators.d.ts","sourceRoot":"","sources":["src/Validators.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,UAAU,qBAAsB,SAAQ,mBAAmB;IACzD,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AACD,UAAU,eAAgB,SAAQ,mBAAmB;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AACD,UAAU,cAAe,SAAQ,mBAAmB;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AACD,UAAU,iBAAkB,SAAQ,mBAAmB;IACrD,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AACD,UAAU,iBAAkB,SAAQ,qBAAqB;IACvD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,uBAAe,iBAAiB,CAAC,CAAC,CAAE,YAAW,S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