@vaadin/hilla-models 24.7.0-alpha9 → 24.7.0-beta3
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/builders.d.ts +0 -116
- package/builders.js +66 -142
- package/builders.js.map +1 -7
- package/core.d.ts +0 -25
- package/core.js +17 -19
- package/core.js.map +1 -7
- package/index.d.ts +0 -57
- package/index.js +67 -120
- package/index.js.map +1 -7
- package/model.d.ts +0 -87
- package/model.js +47 -63
- package/model.js.map +1 -7
- package/package.json +6 -35
- package/builders.d.ts.map +0 -1
- package/core.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/model.d.ts.map +0 -1
package/builders.d.ts
CHANGED
|
@@ -1,160 +1,44 @@
|
|
|
1
1
|
import type { EmptyObject } from 'type-fest';
|
|
2
2
|
import type { ObjectModel } from './core';
|
|
3
3
|
import { type AnyObject, type DefaultValueProvider, type Model, type ModelMetadata } from './model.js';
|
|
4
|
-
/**
|
|
5
|
-
* The options for creating the model property.
|
|
6
|
-
*/
|
|
7
4
|
export type ModelBuilderPropertyOptions = Readonly<{
|
|
8
5
|
meta?: ModelMetadata;
|
|
9
6
|
}>;
|
|
10
7
|
declare const $model: unique symbol;
|
|
11
|
-
/**
|
|
12
|
-
* The flags for the model constructor that allow to determine specific characteristics of the model.
|
|
13
|
-
*/
|
|
14
8
|
export type Flags = {
|
|
15
|
-
/**
|
|
16
|
-
* Defines if the model is named.
|
|
17
|
-
*/
|
|
18
9
|
named: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* The keys of the self-referencing properties.
|
|
21
|
-
*
|
|
22
|
-
* @remarks
|
|
23
|
-
* The problem of self-reference models is that they cannot have intermediate
|
|
24
|
-
* type because during the property definition, the model itself is in the
|
|
25
|
-
* middle of construction. That's why we define the specific type-only flag
|
|
26
|
-
* that allows us to know which model properties are self-referenced. We can
|
|
27
|
-
* safely set it in the end of building using this flag.
|
|
28
|
-
*/
|
|
29
10
|
selfRefKeys: keyof any;
|
|
30
11
|
};
|
|
31
|
-
/**
|
|
32
|
-
* A builder class for creating all basic models.
|
|
33
|
-
*
|
|
34
|
-
* @typeParam V - The final value type of the model.
|
|
35
|
-
* @typeParam EX - The extra properties of the model.
|
|
36
|
-
* @typeParam F - The flags for the model constructor that allow to determine
|
|
37
|
-
* specific characteristics of the model.
|
|
38
|
-
*/
|
|
39
12
|
export declare class CoreModelBuilder<V, EX extends AnyObject = EmptyObject, F extends Flags = {
|
|
40
13
|
named: false;
|
|
41
14
|
selfRefKeys: never;
|
|
42
15
|
}> {
|
|
43
16
|
protected readonly [$model]: Model<V, EX>;
|
|
44
|
-
/**
|
|
45
|
-
* @param base - The base model to extend.
|
|
46
|
-
* @param defaultValueProvider - The function that provides the default value
|
|
47
|
-
* for the model.
|
|
48
|
-
*/
|
|
49
17
|
constructor(base: Model, defaultValueProvider?: (model: Model<V, EX>) => V);
|
|
50
|
-
/**
|
|
51
|
-
* Appends metadata to the model.
|
|
52
|
-
*
|
|
53
|
-
* @param value - The metadata to append.
|
|
54
|
-
* @returns The current builder instance.
|
|
55
|
-
*/
|
|
56
18
|
meta(value: ModelMetadata): this;
|
|
57
|
-
/**
|
|
58
|
-
* Defines a new property on the model. The property serves the purposes of
|
|
59
|
-
* storing the extra data for specific types of models.
|
|
60
|
-
*
|
|
61
|
-
* @remarks
|
|
62
|
-
* The key of the property should be a symbol to avoid conflicts with
|
|
63
|
-
* properties defined via
|
|
64
|
-
* {@link ObjectModelBuilder}.
|
|
65
|
-
*
|
|
66
|
-
* @param key - The key of the property.
|
|
67
|
-
* @param value - The descriptor of the property.
|
|
68
|
-
* @returns The current builder instance.
|
|
69
|
-
*/
|
|
70
19
|
define<DK extends symbol, DV>(key: DK, value: TypedPropertyDescriptor<DV>): CoreModelBuilder<V, EX & Readonly<Record<DK, DV>>, F>;
|
|
71
|
-
/**
|
|
72
|
-
* Sets the default value provider for the model. This is an alternative way
|
|
73
|
-
* to provide the default value for the model if for some reason using the
|
|
74
|
-
* constructor parameter is undesired.
|
|
75
|
-
*
|
|
76
|
-
* @param defaultValueProvider - The function that provides the default value
|
|
77
|
-
* for the model.
|
|
78
|
-
* @returns The current builder instance.
|
|
79
|
-
*/
|
|
80
20
|
defaultValueProvider(defaultValueProvider: DefaultValueProvider<V, EX>): this;
|
|
81
|
-
/**
|
|
82
|
-
* Sets the name of the model. The name is used for debugging purposes and is
|
|
83
|
-
* displayed in the string representation. Setting the name is required;
|
|
84
|
-
* otherwise, the {@link CoreModelBuilder.build} method won't be available.
|
|
85
|
-
*
|
|
86
|
-
* @param name - The name of the model.
|
|
87
|
-
* @returns The current builder instance.
|
|
88
|
-
*/
|
|
89
21
|
name(name: string): CoreModelBuilder<V, EX, {
|
|
90
22
|
named: true;
|
|
91
23
|
selfRefKeys: F['selfRefKeys'];
|
|
92
24
|
}>;
|
|
93
|
-
/**
|
|
94
|
-
* Builds the model. On the typing level, it checks if all the model parts are
|
|
95
|
-
* set correctly, and raises an error if not.
|
|
96
|
-
*
|
|
97
|
-
* @returns The model.
|
|
98
|
-
*/
|
|
99
25
|
build(this: F['named'] extends true ? this : never): Model<V, EX>;
|
|
100
26
|
}
|
|
101
|
-
/**
|
|
102
|
-
* A builder class for creating object models.
|
|
103
|
-
*
|
|
104
|
-
* @typeParam V - The final value type of the model.
|
|
105
|
-
* @typeParam CV - The current value type of the model. It changes as the model
|
|
106
|
-
* is being built and defines if the
|
|
107
|
-
* {@link ObjectModelBuilder.build} method can be called.
|
|
108
|
-
* @typeParam EX - The extra properties of the model.
|
|
109
|
-
* @typeParam F - The flags for the model constructor that allow to determine
|
|
110
|
-
* specific characteristics of the model.
|
|
111
|
-
*/
|
|
112
27
|
export declare class ObjectModelBuilder<V extends AnyObject, CV extends AnyObject = EmptyObject, EX extends AnyObject = EmptyObject, F extends Flags = {
|
|
113
28
|
named: false;
|
|
114
29
|
selfRefKeys: never;
|
|
115
30
|
}> extends CoreModelBuilder<V, EX, F> {
|
|
116
31
|
constructor(base: Model);
|
|
117
|
-
/**
|
|
118
|
-
* The method that should follow the {@link m.extend} method. It allows to
|
|
119
|
-
* declare the extension for the model and properly name it.
|
|
120
|
-
*
|
|
121
|
-
* @param name - The name of the model.
|
|
122
|
-
*/
|
|
123
32
|
object<NV extends AnyObject>(this: F['named'] extends false ? this : never, name: string): ObjectModelBuilder<NV & V, CV, EX, {
|
|
124
33
|
named: true;
|
|
125
34
|
selfRefKeys: F['selfRefKeys'];
|
|
126
35
|
}>;
|
|
127
|
-
/**
|
|
128
|
-
* {@inheritDoc CoreModelBuilder.define}
|
|
129
|
-
*/
|
|
130
36
|
['define']: <DK extends symbol, DV>(key: DK, value: TypedPropertyDescriptor<DV>) => ObjectModelBuilder<V, CV, EX & Readonly<Record<DK, DV>>, F>;
|
|
131
|
-
/**
|
|
132
|
-
* {@inheritDoc CoreModelBuilder.meta}
|
|
133
|
-
*/
|
|
134
37
|
['meta']: (value: ModelMetadata) => this;
|
|
135
|
-
/**
|
|
136
|
-
* Defines a new model property on the model. Unlike the
|
|
137
|
-
* {@link ObjectModelBuilder.define}, this property is public and allows the
|
|
138
|
-
* user to interact with the model data structure. It also updates the current
|
|
139
|
-
* value type of the model to make it closer to the final value type.
|
|
140
|
-
*
|
|
141
|
-
* @param key - The key of the property.
|
|
142
|
-
* @param model - The model of the property value. You can also provide a
|
|
143
|
-
* function that produces the model based on the current model.
|
|
144
|
-
* @param options - Additional options for the property.
|
|
145
|
-
*
|
|
146
|
-
* @returns The current builder instance updated with the new property type.
|
|
147
|
-
* In case there is a self-referencing property, the {@link Flags.selfRefKeys}
|
|
148
|
-
* flag for the specific property is set.
|
|
149
|
-
*/
|
|
150
38
|
property<PK extends string & keyof V, EXK extends AnyObject = EmptyObject>(key: PK, model: Model<V[PK], EXK> | ((model: Model<V, EX & Readonly<Record<PK, Model<V[PK], EXK>>>>) => Model<V[PK], EXK>), options?: ModelBuilderPropertyOptions): Extract<V[PK], V> extends never ? ObjectModelBuilder<V, CV & Readonly<Record<PK, V[PK]>>, EX & Readonly<Record<PK, Model<V[PK], EXK>>>, F> : ObjectModelBuilder<V, CV & Readonly<Record<PK, V[PK]>>, EX, {
|
|
151
39
|
named: F['named'];
|
|
152
40
|
selfRefKeys: F['selfRefKeys'] | PK;
|
|
153
41
|
}>;
|
|
154
|
-
/**
|
|
155
|
-
* {@inheritDoc CoreModelBuilder.build}
|
|
156
|
-
*/
|
|
157
42
|
build: (this: F['named'] extends true ? (CV extends V ? this : never) : never) => ObjectModel<V, EX, F['selfRefKeys']>;
|
|
158
43
|
}
|
|
159
44
|
export {};
|
|
160
|
-
//# sourceMappingURL=builders.d.ts.map
|
package/builders.js
CHANGED
|
@@ -1,147 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
$defaultValue,
|
|
3
|
-
$key,
|
|
4
|
-
$meta,
|
|
5
|
-
$name,
|
|
6
|
-
$owner
|
|
7
|
-
} from "./model.js";
|
|
1
|
+
import { $defaultValue, $key, $meta, $name, $owner, } from './model.js';
|
|
8
2
|
const { create, defineProperty } = Object;
|
|
9
|
-
const $model = Symbol(
|
|
10
|
-
class CoreModelBuilder {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
const $model = Symbol('model');
|
|
4
|
+
export class CoreModelBuilder {
|
|
5
|
+
[$model];
|
|
6
|
+
constructor(base, defaultValueProvider) {
|
|
7
|
+
this[$model] = create(base);
|
|
8
|
+
if (defaultValueProvider) {
|
|
9
|
+
this.defaultValueProvider(defaultValueProvider);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
meta(value) {
|
|
13
|
+
this.define($meta, { value });
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
define(key, value) {
|
|
17
|
+
defineProperty(this[$model], key, value);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
defaultValueProvider(defaultValueProvider) {
|
|
21
|
+
this.define($defaultValue, {
|
|
22
|
+
get() {
|
|
23
|
+
return defaultValueProvider(this);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
name(name) {
|
|
29
|
+
return this.define($name, { value: name });
|
|
30
|
+
}
|
|
31
|
+
build() {
|
|
32
|
+
return this[$model];
|
|
21
33
|
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Appends metadata to the model.
|
|
25
|
-
*
|
|
26
|
-
* @param value - The metadata to append.
|
|
27
|
-
* @returns The current builder instance.
|
|
28
|
-
*/
|
|
29
|
-
meta(value) {
|
|
30
|
-
this.define($meta, { value });
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Defines a new property on the model. The property serves the purposes of
|
|
35
|
-
* storing the extra data for specific types of models.
|
|
36
|
-
*
|
|
37
|
-
* @remarks
|
|
38
|
-
* The key of the property should be a symbol to avoid conflicts with
|
|
39
|
-
* properties defined via
|
|
40
|
-
* {@link ObjectModelBuilder}.
|
|
41
|
-
*
|
|
42
|
-
* @param key - The key of the property.
|
|
43
|
-
* @param value - The descriptor of the property.
|
|
44
|
-
* @returns The current builder instance.
|
|
45
|
-
*/
|
|
46
|
-
define(key, value) {
|
|
47
|
-
defineProperty(this[$model], key, value);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Sets the default value provider for the model. This is an alternative way
|
|
52
|
-
* to provide the default value for the model if for some reason using the
|
|
53
|
-
* constructor parameter is undesired.
|
|
54
|
-
*
|
|
55
|
-
* @param defaultValueProvider - The function that provides the default value
|
|
56
|
-
* for the model.
|
|
57
|
-
* @returns The current builder instance.
|
|
58
|
-
*/
|
|
59
|
-
defaultValueProvider(defaultValueProvider) {
|
|
60
|
-
this.define($defaultValue, {
|
|
61
|
-
get() {
|
|
62
|
-
return defaultValueProvider(this);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Sets the name of the model. The name is used for debugging purposes and is
|
|
69
|
-
* displayed in the string representation. Setting the name is required;
|
|
70
|
-
* otherwise, the {@link CoreModelBuilder.build} method won't be available.
|
|
71
|
-
*
|
|
72
|
-
* @param name - The name of the model.
|
|
73
|
-
* @returns The current builder instance.
|
|
74
|
-
*/
|
|
75
|
-
name(name) {
|
|
76
|
-
return this.define($name, { value: name });
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Builds the model. On the typing level, it checks if all the model parts are
|
|
80
|
-
* set correctly, and raises an error if not.
|
|
81
|
-
*
|
|
82
|
-
* @returns The model.
|
|
83
|
-
*/
|
|
84
|
-
build() {
|
|
85
|
-
return this[$model];
|
|
86
|
-
}
|
|
87
34
|
}
|
|
88
|
-
const propertyRegistry =
|
|
89
|
-
class ObjectModelBuilder extends CoreModelBuilder {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
35
|
+
const propertyRegistry = new WeakMap();
|
|
36
|
+
export class ObjectModelBuilder extends CoreModelBuilder {
|
|
37
|
+
constructor(base) {
|
|
38
|
+
super(base, (m) => {
|
|
39
|
+
const result = create(null);
|
|
40
|
+
for (const key in m) {
|
|
41
|
+
defineProperty(result, key, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: () => m[key][$defaultValue],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
97
47
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
* @param options - Additional options for the property.
|
|
121
|
-
*
|
|
122
|
-
* @returns The current builder instance updated with the new property type.
|
|
123
|
-
* In case there is a self-referencing property, the {@link Flags.selfRefKeys}
|
|
124
|
-
* flag for the specific property is set.
|
|
125
|
-
*/
|
|
126
|
-
property(key, model, options) {
|
|
127
|
-
defineProperty(this[$model], key, {
|
|
128
|
-
enumerable: true,
|
|
129
|
-
get() {
|
|
130
|
-
if (!propertyRegistry.has(this)) {
|
|
131
|
-
propertyRegistry.set(this, {});
|
|
132
|
-
}
|
|
133
|
-
const props = propertyRegistry.get(this);
|
|
134
|
-
props[key] ??= new CoreModelBuilder(
|
|
135
|
-
typeof model === "function" ? model(this) : model
|
|
136
|
-
).define($key, { value: key }).define($owner, { value: this }).define($meta, { value: options?.meta }).build();
|
|
137
|
-
return props[key];
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
48
|
+
}
|
|
49
|
+
object(name) {
|
|
50
|
+
return this.name(name);
|
|
51
|
+
}
|
|
52
|
+
property(key, model, options) {
|
|
53
|
+
defineProperty(this[$model], key, {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get() {
|
|
56
|
+
if (!propertyRegistry.has(this)) {
|
|
57
|
+
propertyRegistry.set(this, {});
|
|
58
|
+
}
|
|
59
|
+
const props = propertyRegistry.get(this);
|
|
60
|
+
props[key] ??= new CoreModelBuilder(typeof model === 'function' ? model(this) : model)
|
|
61
|
+
.define($key, { value: key })
|
|
62
|
+
.define($owner, { value: this })
|
|
63
|
+
.define($meta, { value: options?.meta })
|
|
64
|
+
.build();
|
|
65
|
+
return props[key];
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
142
70
|
}
|
|
143
|
-
|
|
144
|
-
CoreModelBuilder,
|
|
145
|
-
ObjectModelBuilder
|
|
146
|
-
};
|
|
147
|
-
//# sourceMappingURL=builders.js.map
|
|
71
|
+
//# sourceMappingURL=builders.js.map
|
package/builders.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/builders.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EmptyObject } from 'type-fest';\nimport type { ObjectModel } from './core';\nimport {\n $defaultValue,\n $key,\n $meta,\n $name,\n $owner,\n type AnyObject,\n type DefaultValueProvider,\n type Model,\n type ModelMetadata,\n} from './model.js';\n\nconst { create, defineProperty } = Object;\n\n/**\n * The options for creating the model property.\n */\nexport type ModelBuilderPropertyOptions = Readonly<{\n meta?: ModelMetadata;\n}>;\n\nconst $model = Symbol('model');\n\n/**\n * The flags for the model constructor that allow to determine specific characteristics of the model.\n */\nexport type Flags = {\n /**\n * Defines if the model is named.\n */\n named: boolean;\n\n /**\n * The keys of the self-referencing properties.\n *\n * @remarks\n * The problem of self-reference models is that they cannot have intermediate\n * type because during the property definition, the model itself is in the\n * middle of construction. That's why we define the specific type-only flag\n * that allows us to know which model properties are self-referenced. We can\n * safely set it in the end of building using this flag.\n */\n selfRefKeys: keyof any;\n};\n\n/**\n * A builder class for creating all basic models.\n *\n * @typeParam V - The final value type of the model.\n * @typeParam EX - The extra properties of the model.\n * @typeParam F - The flags for the model constructor that allow to determine\n * specific characteristics of the model.\n */\nexport class CoreModelBuilder<\n V,\n EX extends AnyObject = EmptyObject,\n F extends Flags = { named: false; selfRefKeys: never },\n> {\n protected readonly [$model]: Model<V, EX>;\n\n /**\n * @param base - The base model to extend.\n * @param defaultValueProvider - The function that provides the default value\n * for the model.\n */\n constructor(base: Model, defaultValueProvider?: (model: Model<V, EX>) => V) {\n this[$model] = create(base);\n\n if (defaultValueProvider) {\n this.defaultValueProvider(defaultValueProvider);\n }\n }\n\n /**\n * Appends metadata to the model.\n *\n * @param value - The metadata to append.\n * @returns The current builder instance.\n */\n meta(value: ModelMetadata): this {\n this.define($meta, { value });\n return this;\n }\n\n /**\n * Defines a new property on the model. The property serves the purposes of\n * storing the extra data for specific types of models.\n *\n * @remarks\n * The key of the property should be a symbol to avoid conflicts with\n * properties defined via\n * {@link ObjectModelBuilder}.\n *\n * @param key - The key of the property.\n * @param value - The descriptor of the property.\n * @returns The current builder instance.\n */\n define<DK extends symbol, DV>(\n key: DK,\n value: TypedPropertyDescriptor<DV>,\n ): CoreModelBuilder<V, EX & Readonly<Record<DK, DV>>, F> {\n defineProperty(this[$model], key, value);\n return this as any;\n }\n\n /**\n * Sets the default value provider for the model. This is an alternative way\n * to provide the default value for the model if for some reason using the\n * constructor parameter is undesired.\n *\n * @param defaultValueProvider - The function that provides the default value\n * for the model.\n * @returns The current builder instance.\n */\n defaultValueProvider(defaultValueProvider: DefaultValueProvider<V, EX>): this {\n this.define($defaultValue, {\n get(this: Model<V, EX>) {\n return defaultValueProvider(this);\n },\n });\n return this;\n }\n\n /**\n * Sets the name of the model. The name is used for debugging purposes and is\n * displayed in the string representation. Setting the name is required;\n * otherwise, the {@link CoreModelBuilder.build} method won't be available.\n *\n * @param name - The name of the model.\n * @returns The current builder instance.\n */\n name(name: string): CoreModelBuilder<V, EX, { named: true; selfRefKeys: F['selfRefKeys'] }> {\n return this.define($name, { value: name }) as any;\n }\n\n /**\n * Builds the model. On the typing level, it checks if all the model parts are\n * set correctly, and raises an error if not.\n *\n * @returns The model.\n */\n build(this: F['named'] extends true ? this : never): Model<V, EX> {\n return this[$model];\n }\n}\n\n/**\n * A registry for the property models of the object model. Since the property\n * registration is lazy, we cannot store the property models directly on the\n * object model, so the registry plays a role of a private storage for them.\n *\n * @internal\n */\nconst propertyRegistry = new WeakMap<Model, Record<string, Model>>();\n\n/**\n * A builder class for creating object models.\n *\n * @typeParam V - The final value type of the model.\n * @typeParam CV - The current value type of the model. It changes as the model\n * is being built and defines if the\n * {@link ObjectModelBuilder.build} method can be called.\n * @typeParam EX - The extra properties of the model.\n * @typeParam F - The flags for the model constructor that allow to determine\n * specific characteristics of the model.\n */\nexport class ObjectModelBuilder<\n V extends AnyObject,\n CV extends AnyObject = EmptyObject,\n EX extends AnyObject = EmptyObject,\n F extends Flags = { named: false; selfRefKeys: never },\n> extends CoreModelBuilder<V, EX, F> {\n constructor(base: Model) {\n super(base, (m) => {\n const result = create(null);\n\n // eslint-disable-next-line no-restricted-syntax\n for (const key in m) {\n defineProperty(result, key, {\n enumerable: true,\n get: () => (m[key as keyof Model<V, EX>] as Model)[$defaultValue],\n });\n }\n\n return result;\n });\n }\n\n /**\n * The method that should follow the {@link m.extend} method. It allows to\n * declare the extension for the model and properly name it.\n *\n * @param name - The name of the model.\n */\n object<NV extends AnyObject>(\n this: F['named'] extends false ? this : never,\n name: string,\n ): ObjectModelBuilder<NV & V, CV, EX, { named: true; selfRefKeys: F['selfRefKeys'] }> {\n return this.name(name) as any;\n }\n\n /**\n * {@inheritDoc CoreModelBuilder.define}\n */\n declare ['define']: <DK extends symbol, DV>(\n key: DK,\n value: TypedPropertyDescriptor<DV>,\n ) => ObjectModelBuilder<V, CV, EX & Readonly<Record<DK, DV>>, F>;\n\n /**\n * {@inheritDoc CoreModelBuilder.meta}\n */\n declare ['meta']: (value: ModelMetadata) => this;\n\n /**\n * Defines a new model property on the model. Unlike the\n * {@link ObjectModelBuilder.define}, this property is public and allows the\n * user to interact with the model data structure. It also updates the current\n * value type of the model to make it closer to the final value type.\n *\n * @param key - The key of the property.\n * @param model - The model of the property value. You can also provide a\n * function that produces the model based on the current model.\n * @param options - Additional options for the property.\n *\n * @returns The current builder instance updated with the new property type.\n * In case there is a self-referencing property, the {@link Flags.selfRefKeys}\n * flag for the specific property is set.\n */\n property<PK extends string & keyof V, EXK extends AnyObject = EmptyObject>(\n key: PK,\n model: Model<V[PK], EXK> | ((model: Model<V, EX & Readonly<Record<PK, Model<V[PK], EXK>>>>) => Model<V[PK], EXK>),\n options?: ModelBuilderPropertyOptions,\n ): // It is a workaround for the self-referencing models.\n // If the type of the model property is not the model itself,\n Extract<V[PK], V> extends never\n ? // Then we simply extend the model with the property, and update the\n // current value type of the model.\n ObjectModelBuilder<V, CV & Readonly<Record<PK, V[PK]>>, EX & Readonly<Record<PK, Model<V[PK], EXK>>>, F>\n : // Otherwise, we set a flag of the model that it contains a self-reference\n // property.\n ObjectModelBuilder<\n V,\n CV & Readonly<Record<PK, V[PK]>>,\n EX,\n {\n // Just inheriting the current flag.\n named: F['named'];\n // Adding the property name to all existing self-referencing\n // properties.\n selfRefKeys: F['selfRefKeys'] | PK;\n }\n > {\n defineProperty(this[$model], key, {\n enumerable: true,\n get(this: Model<V, EX & Readonly<Record<PK, Model<V[PK], EXK>>>>) {\n if (!propertyRegistry.has(this)) {\n propertyRegistry.set(this, {});\n }\n\n const props = propertyRegistry.get(this)!;\n\n props[key] ??= new CoreModelBuilder<V[PK], EXK, { named: true; selfRefKeys: never }>(\n typeof model === 'function' ? model(this) : model,\n )\n .define($key, { value: key })\n .define($owner, { value: this })\n .define($meta, { value: options?.meta })\n .build();\n\n return props[key];\n },\n });\n\n return this as any;\n }\n\n /**\n * {@inheritDoc CoreModelBuilder.build}\n */\n declare build: (\n this: F['named'] extends true ? (CV extends V ? this : never) : never,\n ) => ObjectModel<V, EX, F['selfRefKeys']>;\n}\n"],
|
|
5
|
-
"mappings": "AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAEP,MAAM,EAAE,QAAQ,eAAe,IAAI;AASnC,MAAM,SAAS,OAAO,OAAO;AAgCtB,MAAM,iBAIX;AAAA,EACA,CAAoB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO1B,YAAY,MAAa,sBAAmD;AAC1E,SAAK,MAAM,IAAI,OAAO,IAAI;AAE1B,QAAI,sBAAsB;AACxB,WAAK,qBAAqB,oBAAoB;AAAA,IAChD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAK,OAA4B;AAC/B,SAAK,OAAO,OAAO,EAAE,MAAM,CAAC;AAC5B,WAAO;AAAA,E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AAI;YAChB,GAAG;gBACD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBAChC,gBAAgB,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACjC,CAAC;gBAED,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;gBAE1C,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,gBAAgB,CACjC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAClD;qBACE,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;qBAC5B,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;qBAC/B,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qBACvC,KAAK,EAAE,CAAC;gBAEX,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,IAAW,CAAC;IACrB,CAAC;CAQF","sourcesContent":["import type { EmptyObject } from 'type-fest';\nimport type { ObjectModel } from './core';\nimport {\n $defaultValue,\n $key,\n $meta,\n $name,\n $owner,\n type AnyObject,\n type DefaultValueProvider,\n type Model,\n type ModelMetadata,\n} from './model.js';\n\nconst { create, defineProperty } = Object;\n\n/**\n * The options for creating the model property.\n */\nexport type ModelBuilderPropertyOptions = Readonly<{\n meta?: ModelMetadata;\n}>;\n\nconst $model = Symbol('model');\n\n/**\n * The flags for the model constructor that allow to determine specific characteristics of the model.\n */\nexport type Flags = {\n /**\n * Defines if the model is named.\n */\n named: boolean;\n\n /**\n * The keys of the self-referencing properties.\n *\n * @remarks\n * The problem of self-reference models is that they cannot have intermediate\n * type because during the property definition, the model itself is in the\n * middle of construction. That's why we define the specific type-only flag\n * that allows us to know which model properties are self-referenced. We can\n * safely set it in the end of building using this flag.\n */\n selfRefKeys: keyof any;\n};\n\n/**\n * A builder class for creating all basic models.\n *\n * @typeParam V - The final value type of the model.\n * @typeParam EX - The extra properties of the model.\n * @typeParam F - The flags for the model constructor that allow to determine\n * specific characteristics of the model.\n */\nexport class CoreModelBuilder<\n V,\n EX extends AnyObject = EmptyObject,\n F extends Flags = { named: false; selfRefKeys: never },\n> {\n protected readonly [$model]: Model<V, EX>;\n\n /**\n * @param base - The base model to extend.\n * @param defaultValueProvider - The function that provides the default value\n * for the model.\n */\n constructor(base: Model, defaultValueProvider?: (model: Model<V, EX>) => V) {\n this[$model] = create(base);\n\n if (defaultValueProvider) {\n this.defaultValueProvider(defaultValueProvider);\n }\n }\n\n /**\n * Appends metadata to the model.\n *\n * @param value - The metadata to append.\n * @returns The current builder instance.\n */\n meta(value: ModelMetadata): this {\n this.define($meta, { value });\n return this;\n }\n\n /**\n * Defines a new property on the model. The property serves the purposes of\n * storing the extra data for specific types of models.\n *\n * @remarks\n * The key of the property should be a symbol to avoid conflicts with\n * properties defined via\n * {@link ObjectModelBuilder}.\n *\n * @param key - The key of the property.\n * @param value - The descriptor of the property.\n * @returns The current builder instance.\n */\n define<DK extends symbol, DV>(\n key: DK,\n value: TypedPropertyDescriptor<DV>,\n ): CoreModelBuilder<V, EX & Readonly<Record<DK, DV>>, F> {\n defineProperty(this[$model], key, value);\n return this as any;\n }\n\n /**\n * Sets the default value provider for the model. This is an alternative way\n * to provide the default value for the model if for some reason using the\n * constructor parameter is undesired.\n *\n * @param defaultValueProvider - The function that provides the default value\n * for the model.\n * @returns The current builder instance.\n */\n defaultValueProvider(defaultValueProvider: DefaultValueProvider<V, EX>): this {\n this.define($defaultValue, {\n get(this: Model<V, EX>) {\n return defaultValueProvider(this);\n },\n });\n return this;\n }\n\n /**\n * Sets the name of the model. The name is used for debugging purposes and is\n * displayed in the string representation. Setting the name is required;\n * otherwise, the {@link CoreModelBuilder.build} method won't be available.\n *\n * @param name - The name of the model.\n * @returns The current builder instance.\n */\n name(name: string): CoreModelBuilder<V, EX, { named: true; selfRefKeys: F['selfRefKeys'] }> {\n return this.define($name, { value: name }) as any;\n }\n\n /**\n * Builds the model. On the typing level, it checks if all the model parts are\n * set correctly, and raises an error if not.\n *\n * @returns The model.\n */\n build(this: F['named'] extends true ? this : never): Model<V, EX> {\n return this[$model];\n }\n}\n\n/**\n * A registry for the property models of the object model. Since the property\n * registration is lazy, we cannot store the property models directly on the\n * object model, so the registry plays a role of a private storage for them.\n *\n * @internal\n */\nconst propertyRegistry = new WeakMap<Model, Record<string, Model>>();\n\n/**\n * A builder class for creating object models.\n *\n * @typeParam V - The final value type of the model.\n * @typeParam CV - The current value type of the model. It changes as the model\n * is being built and defines if the\n * {@link ObjectModelBuilder.build} method can be called.\n * @typeParam EX - The extra properties of the model.\n * @typeParam F - The flags for the model constructor that allow to determine\n * specific characteristics of the model.\n */\nexport class ObjectModelBuilder<\n V extends AnyObject,\n CV extends AnyObject = EmptyObject,\n EX extends AnyObject = EmptyObject,\n F extends Flags = { named: false; selfRefKeys: never },\n> extends CoreModelBuilder<V, EX, F> {\n constructor(base: Model) {\n super(base, (m) => {\n const result = create(null);\n\n // eslint-disable-next-line no-restricted-syntax\n for (const key in m) {\n defineProperty(result, key, {\n enumerable: true,\n get: () => (m[key as keyof Model<V, EX>] as Model)[$defaultValue],\n });\n }\n\n return result;\n });\n }\n\n /**\n * The method that should follow the {@link m.extend} method. It allows to\n * declare the extension for the model and properly name it.\n *\n * @param name - The name of the model.\n */\n object<NV extends AnyObject>(\n this: F['named'] extends false ? this : never,\n name: string,\n ): ObjectModelBuilder<NV & V, CV, EX, { named: true; selfRefKeys: F['selfRefKeys'] }> {\n return this.name(name) as any;\n }\n\n /**\n * {@inheritDoc CoreModelBuilder.define}\n */\n declare ['define']: <DK extends symbol, DV>(\n key: DK,\n value: TypedPropertyDescriptor<DV>,\n ) => ObjectModelBuilder<V, CV, EX & Readonly<Record<DK, DV>>, F>;\n\n /**\n * {@inheritDoc CoreModelBuilder.meta}\n */\n declare ['meta']: (value: ModelMetadata) => this;\n\n /**\n * Defines a new model property on the model. Unlike the\n * {@link ObjectModelBuilder.define}, this property is public and allows the\n * user to interact with the model data structure. It also updates the current\n * value type of the model to make it closer to the final value type.\n *\n * @param key - The key of the property.\n * @param model - The model of the property value. You can also provide a\n * function that produces the model based on the current model.\n * @param options - Additional options for the property.\n *\n * @returns The current builder instance updated with the new property type.\n * In case there is a self-referencing property, the {@link Flags.selfRefKeys}\n * flag for the specific property is set.\n */\n property<PK extends string & keyof V, EXK extends AnyObject = EmptyObject>(\n key: PK,\n model: Model<V[PK], EXK> | ((model: Model<V, EX & Readonly<Record<PK, Model<V[PK], EXK>>>>) => Model<V[PK], EXK>),\n options?: ModelBuilderPropertyOptions,\n ): // It is a workaround for the self-referencing models.\n // If the type of the model property is not the model itself,\n Extract<V[PK], V> extends never\n ? // Then we simply extend the model with the property, and update the\n // current value type of the model.\n ObjectModelBuilder<V, CV & Readonly<Record<PK, V[PK]>>, EX & Readonly<Record<PK, Model<V[PK], EXK>>>, F>\n : // Otherwise, we set a flag of the model that it contains a self-reference\n // property.\n ObjectModelBuilder<\n V,\n CV & Readonly<Record<PK, V[PK]>>,\n EX,\n {\n // Just inheriting the current flag.\n named: F['named'];\n // Adding the property name to all existing self-referencing\n // properties.\n selfRefKeys: F['selfRefKeys'] | PK;\n }\n > {\n defineProperty(this[$model], key, {\n enumerable: true,\n get(this: Model<V, EX & Readonly<Record<PK, Model<V[PK], EXK>>>>) {\n if (!propertyRegistry.has(this)) {\n propertyRegistry.set(this, {});\n }\n\n const props = propertyRegistry.get(this)!;\n\n props[key] ??= new CoreModelBuilder<V[PK], EXK, { named: true; selfRefKeys: never }>(\n typeof model === 'function' ? model(this) : model,\n )\n .define($key, { value: key })\n .define($owner, { value: this })\n .define($meta, { value: options?.meta })\n .build();\n\n return props[key];\n },\n });\n\n return this as any;\n }\n\n /**\n * {@inheritDoc CoreModelBuilder.build}\n */\n declare build: (\n this: F['named'] extends true ? (CV extends V ? this : never) : never,\n ) => ObjectModel<V, EX, F['selfRefKeys']>;\n}\n"]}
|
package/core.d.ts
CHANGED
|
@@ -1,48 +1,23 @@
|
|
|
1
1
|
import type { EmptyObject } from 'type-fest';
|
|
2
2
|
import { $enum, $itemModel, type $members, type AnyObject, type Enum, Model, type Value } from './model.js';
|
|
3
|
-
/**
|
|
4
|
-
* The model of a primitive value, like `string`, `number` or `boolean`.
|
|
5
|
-
*/
|
|
6
3
|
export type PrimitiveModel<V = unknown> = Model<V>;
|
|
7
4
|
export declare const PrimitiveModel: Model<unknown, EmptyObject>;
|
|
8
|
-
/**
|
|
9
|
-
* The model of a string value.
|
|
10
|
-
*/
|
|
11
5
|
export type StringModel = PrimitiveModel<string>;
|
|
12
6
|
export declare const StringModel: Model<string, EmptyObject>;
|
|
13
|
-
/**
|
|
14
|
-
* The model of a number value.
|
|
15
|
-
*/
|
|
16
7
|
export type NumberModel = PrimitiveModel<number>;
|
|
17
8
|
export declare const NumberModel: Model<number, EmptyObject>;
|
|
18
|
-
/**
|
|
19
|
-
* The model of a boolean value.
|
|
20
|
-
*/
|
|
21
9
|
export type BooleanModel = PrimitiveModel<boolean>;
|
|
22
10
|
export declare const BooleanModel: Model<boolean, EmptyObject>;
|
|
23
|
-
/**
|
|
24
|
-
* The model of an array data.
|
|
25
|
-
*/
|
|
26
11
|
export type ArrayModel<M extends Model = Model> = Model<Array<Value<M>>, Readonly<{
|
|
27
12
|
[$itemModel]: M;
|
|
28
13
|
}>>;
|
|
29
14
|
export declare const ArrayModel: Model<unknown[], EmptyObject & Readonly<Record<typeof $itemModel, Model<unknown, EmptyObject, never>>>>;
|
|
30
|
-
/**
|
|
31
|
-
* The model of an object data.
|
|
32
|
-
*/
|
|
33
15
|
export type ObjectModel<V, EX extends AnyObject = EmptyObject, R extends keyof any = never> = Model<V, EX, R>;
|
|
34
16
|
export declare const ObjectModel: Model<Readonly<Record<never, never>>, EmptyObject>;
|
|
35
|
-
/**
|
|
36
|
-
* The model of an enum data.
|
|
37
|
-
*/
|
|
38
17
|
export type EnumModel<T extends typeof Enum> = Model<T[keyof T], Readonly<{
|
|
39
18
|
[$enum]: T;
|
|
40
19
|
}>>;
|
|
41
20
|
export declare const EnumModel: Model<string, EmptyObject & Readonly<Record<typeof $enum, typeof Enum>>>;
|
|
42
|
-
/**
|
|
43
|
-
* The model of a union data.
|
|
44
|
-
*/
|
|
45
21
|
export type UnionModel<MM extends Model[]> = Model<Value<MM[number]>, Readonly<{
|
|
46
22
|
[$members]: MM;
|
|
47
23
|
}>>;
|
|
48
|
-
//# sourceMappingURL=core.d.ts.map
|
package/core.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { CoreModelBuilder } from
|
|
2
|
-
import { $enum, $itemModel, Model } from
|
|
3
|
-
const PrimitiveModel = new CoreModelBuilder(Model, () =>
|
|
4
|
-
const StringModel = new CoreModelBuilder(PrimitiveModel, () =>
|
|
5
|
-
const NumberModel = new CoreModelBuilder(PrimitiveModel, () => 0).name(
|
|
6
|
-
const BooleanModel = new CoreModelBuilder(PrimitiveModel, () => false).name(
|
|
7
|
-
const ArrayModel = new CoreModelBuilder(Model, () => [])
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=core.js.map
|
|
1
|
+
import { CoreModelBuilder } from './builders.js';
|
|
2
|
+
import { $enum, $itemModel, Model } from './model.js';
|
|
3
|
+
export const PrimitiveModel = new CoreModelBuilder(Model, () => undefined).name('primitive').build();
|
|
4
|
+
export const StringModel = new CoreModelBuilder(PrimitiveModel, () => '').name('string').build();
|
|
5
|
+
export const NumberModel = new CoreModelBuilder(PrimitiveModel, () => 0).name('number').build();
|
|
6
|
+
export const BooleanModel = new CoreModelBuilder(PrimitiveModel, () => false).name('boolean').build();
|
|
7
|
+
export const ArrayModel = new CoreModelBuilder(Model, () => [])
|
|
8
|
+
.name('Array')
|
|
9
|
+
.define($itemModel, { value: Model })
|
|
10
|
+
.build();
|
|
11
|
+
export const ObjectModel = new CoreModelBuilder(Model, () => ({})).name('Object').build();
|
|
12
|
+
export const EnumModel = new CoreModelBuilder(Model)
|
|
13
|
+
.name('Enum')
|
|
14
|
+
.define($enum, { value: {} })
|
|
15
|
+
.defaultValueProvider((self) => Object.values(self[$enum])[0])
|
|
16
|
+
.build();
|
|
17
|
+
//# sourceMappingURL=core.js.map
|
package/core.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/core.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EmptyObject } from 'type-fest';\nimport { CoreModelBuilder } from './builders.js';\nimport { $enum, $itemModel, type $members, type AnyObject, type Enum, Model, type Value } from './model.js';\n\n/**\n * The model of a primitive value, like `string`, `number` or `boolean`.\n */\nexport type PrimitiveModel<V = unknown> = Model<V>;\nexport const PrimitiveModel = new CoreModelBuilder(Model, (): unknown => undefined).name('primitive').build();\n\n/**\n * The model of a string value.\n */\nexport type StringModel = PrimitiveModel<string>;\nexport const StringModel = new CoreModelBuilder(PrimitiveModel, () => '').name('string').build();\n\n/**\n * The model of a number value.\n */\nexport type NumberModel = PrimitiveModel<number>;\nexport const NumberModel = new CoreModelBuilder(PrimitiveModel, () => 0).name('number').build();\n\n/**\n * The model of a boolean value.\n */\nexport type BooleanModel = PrimitiveModel<boolean>;\nexport const BooleanModel = new CoreModelBuilder(PrimitiveModel, () => false).name('boolean').build();\n\n/**\n * The model of an array data.\n */\nexport type ArrayModel<M extends Model = Model> = Model<\n Array<Value<M>>,\n Readonly<{\n [$itemModel]: M;\n }>\n>;\n\nexport const ArrayModel = new CoreModelBuilder(Model, (): unknown[] => [])\n .name('Array')\n .define($itemModel, { value: Model })\n .build();\n\n/**\n * The model of an object data.\n */\nexport type ObjectModel<V, EX extends AnyObject = EmptyObject, R extends keyof any = never> = Model<V, EX, R>;\n\nexport const ObjectModel = new CoreModelBuilder(Model, (): AnyObject => ({})).name('Object').build();\n\n/**\n * The model of an enum data.\n */\nexport type EnumModel<T extends typeof Enum> = Model<\n T[keyof T],\n Readonly<{\n [$enum]: T;\n }>\n>;\n\nexport const EnumModel = new CoreModelBuilder<(typeof Enum)[keyof typeof Enum]>(Model)\n .name('Enum')\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n .define($enum, { value: {} as typeof Enum })\n .defaultValueProvider((self) => Object.values(self[$enum])[0])\n .build();\n\n/**\n * The model of a union data.\n */\nexport type UnionModel<MM extends Model[]> = Model<Value<MM[number]>, Readonly<{ [$members]: MM }>>;\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,wBAAwB;AACjC,SAAS,OAAO,YAAsD,aAAyB;AAMxF,MAAM,iBAAiB,IAAI,iBAAiB,OAAO,MAAe,MAAS,EAAE,KAAK,WAAW,EAAE,MAAM;AAMrG,MAAM,cAAc,IAAI,iBAAiB,gBAAgB,MAAM,EAAE,EAAE,KAAK,QAAQ,EAAE,MAAM;AAMxF,MAAM,cAAc,IAAI,iBAAiB,gBAAgB,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,MAAM;AAMvF,MAAM,eAAe,IAAI,iBAAiB,gBAAgB,MAAM,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM;AAY7F,MAAM,aAAa,IAAI,iBAAiB,OAAO,MAAiB,CAAC,CAAC,EACtE,KAAK,OAAO,EACZ,OAAO,YAAY,EAAE,OAAO,MAAM,CAAC,EACnC,MAAM;AAOF,MAAM,cAAc,IAAI,iBAAiB,OAAO,OAAkB,CAAC,EAAE,EAAE,KAAK,QAAQ,EAAE,MAAM;AAY5F,MAAM,YAAY,IAAI,iBAAmD,KAAK,EAClF,KAAK,MAAM,EAEX,OAAO,OAAO,EAAE,OAAO,CAAC,EAAiB,CAAC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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC;AAYrG,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAmC,KAAK,CAAC;KACnF,IAAI,CAAC,MAAM,CAAC;KAEZ,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAiB,EAAE,CAAC;KAC3C,oBAAoB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7D,KAAK,EAAE,CAAC","sourcesContent":["import type { EmptyObject } from 'type-fest';\nimport { CoreModelBuilder } from './builders.js';\nimport { $enum, $itemModel, type $members, type AnyObject, type Enum, Model, type Value } from './model.js';\n\n/**\n * The model of a primitive value, like `string`, `number` or `boolean`.\n */\nexport type PrimitiveModel<V = unknown> = Model<V>;\nexport const PrimitiveModel = new CoreModelBuilder(Model, (): unknown => undefined).name('primitive').build();\n\n/**\n * The model of a string value.\n */\nexport type StringModel = PrimitiveModel<string>;\nexport const StringModel = new CoreModelBuilder(PrimitiveModel, () => '').name('string').build();\n\n/**\n * The model of a number value.\n */\nexport type NumberModel = PrimitiveModel<number>;\nexport const NumberModel = new CoreModelBuilder(PrimitiveModel, () => 0).name('number').build();\n\n/**\n * The model of a boolean value.\n */\nexport type BooleanModel = PrimitiveModel<boolean>;\nexport const BooleanModel = new CoreModelBuilder(PrimitiveModel, () => false).name('boolean').build();\n\n/**\n * The model of an array data.\n */\nexport type ArrayModel<M extends Model = Model> = Model<\n Array<Value<M>>,\n Readonly<{\n [$itemModel]: M;\n }>\n>;\n\nexport const ArrayModel = new CoreModelBuilder(Model, (): unknown[] => [])\n .name('Array')\n .define($itemModel, { value: Model })\n .build();\n\n/**\n * The model of an object data.\n */\nexport type ObjectModel<V, EX extends AnyObject = EmptyObject, R extends keyof any = never> = Model<V, EX, R>;\n\nexport const ObjectModel = new CoreModelBuilder(Model, (): AnyObject => ({})).name('Object').build();\n\n/**\n * The model of an enum data.\n */\nexport type EnumModel<T extends typeof Enum> = Model<\n T[keyof T],\n Readonly<{\n [$enum]: T;\n }>\n>;\n\nexport const EnumModel = new CoreModelBuilder<(typeof Enum)[keyof typeof Enum]>(Model)\n .name('Enum')\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n .define($enum, { value: {} as typeof Enum })\n .defaultValueProvider((self) => Object.values(self[$enum])[0])\n .build();\n\n/**\n * The model of a union data.\n */\nexport type UnionModel<MM extends Model[]> = Model<Value<MM[number]>, Readonly<{ [$members]: MM }>>;\n"]}
|
package/index.d.ts
CHANGED
|
@@ -5,78 +5,21 @@ import { type AnyObject, type Target, type Enum, type Extensions, Model, type Re
|
|
|
5
5
|
export * from './model.js';
|
|
6
6
|
export * from './core.js';
|
|
7
7
|
export type * from './builders.js';
|
|
8
|
-
/**
|
|
9
|
-
* The utility object that provides methods to create and manipulate models.
|
|
10
|
-
*/
|
|
11
8
|
declare const m: {
|
|
12
|
-
/**
|
|
13
|
-
* Attaches the given model to the target.
|
|
14
|
-
*
|
|
15
|
-
* @param model - The model to attach.
|
|
16
|
-
* @param target - The target to attach the model to. It could be a Binder
|
|
17
|
-
* instance, a Signal, or another object. However, it could never be another
|
|
18
|
-
* model.
|
|
19
|
-
*/
|
|
20
9
|
attach<M extends Model>(model: M, target: Target<Value<M>>): M;
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new model that extends the given base model.
|
|
23
|
-
*
|
|
24
|
-
* @param base - The base model to extend.
|
|
25
|
-
*/
|
|
26
10
|
extend<M extends Model<AnyObject>>(base: M): ObjectModelBuilder<Value<M>, Value<M>, Extensions<M>, {
|
|
27
11
|
named: false;
|
|
28
12
|
selfRefKeys: References<M>;
|
|
29
13
|
}>;
|
|
30
|
-
/**
|
|
31
|
-
* Creates a new model that represents an optional value.
|
|
32
|
-
*
|
|
33
|
-
* @param base - The base model to extend.
|
|
34
|
-
*/
|
|
35
14
|
optional<M extends Model>(base: M): M;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a new model that represents an array of items.
|
|
38
|
-
*
|
|
39
|
-
* @param itemModel - The model of the items in the array.
|
|
40
|
-
*/
|
|
41
15
|
array<M extends Model>(itemModel: M): ArrayModel<M>;
|
|
42
|
-
/**
|
|
43
|
-
* Creates a new model that represents an object.
|
|
44
|
-
*
|
|
45
|
-
* @param name - The name of the object.
|
|
46
|
-
*/
|
|
47
16
|
object<T extends AnyObject>(name: string): ObjectModelBuilder<T, EmptyObject, EmptyObject, {
|
|
48
17
|
named: true;
|
|
49
18
|
selfRefKeys: never;
|
|
50
19
|
}>;
|
|
51
|
-
/**
|
|
52
|
-
* Creates a new model that represents an enum.
|
|
53
|
-
*
|
|
54
|
-
* @param obj - The enum object to represent.
|
|
55
|
-
* @param name - The name of the model.
|
|
56
|
-
*/
|
|
57
20
|
enum<T extends typeof Enum>(obj: T, name: string): EnumModel<T>;
|
|
58
|
-
/**
|
|
59
|
-
* Creates a new model that represents a union of the values of the given
|
|
60
|
-
* models.
|
|
61
|
-
*
|
|
62
|
-
* @param members - The models to create the union from.
|
|
63
|
-
*/
|
|
64
21
|
union<MM extends Model[]>(...members: MM): UnionModel<MM>;
|
|
65
|
-
/**
|
|
66
|
-
* Iterates over the given array model yielding an item model for each item
|
|
67
|
-
* the model value has.
|
|
68
|
-
*
|
|
69
|
-
* @param model - The array model to iterate over.
|
|
70
|
-
*/
|
|
71
22
|
items<V extends Model>(model: ArrayModel<V>): Generator<V, undefined, void>;
|
|
72
|
-
/**
|
|
73
|
-
* Provides the value the given model represents. For attached models it will
|
|
74
|
-
* be the owner value or its part, for detached models it will be the default
|
|
75
|
-
* value of the model.
|
|
76
|
-
*
|
|
77
|
-
* @param model - The model to get the value from.
|
|
78
|
-
*/
|
|
79
23
|
value<T>(model: Model<T>): T;
|
|
80
24
|
};
|
|
81
25
|
export default m;
|
|
82
|
-
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,125 +1,72 @@
|
|
|
1
|
-
import { CoreModelBuilder, ObjectModelBuilder } from
|
|
2
|
-
import { ArrayModel, EnumModel, ObjectModel } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
$itemModel,
|
|
7
|
-
$key,
|
|
8
|
-
$members,
|
|
9
|
-
$name,
|
|
10
|
-
$optional,
|
|
11
|
-
$owner,
|
|
12
|
-
Model,
|
|
13
|
-
nothing
|
|
14
|
-
} from "./model.js";
|
|
15
|
-
export * from "./model.js";
|
|
16
|
-
export * from "./core.js";
|
|
1
|
+
import { CoreModelBuilder, ObjectModelBuilder } from './builders.js';
|
|
2
|
+
import { ArrayModel, EnumModel, ObjectModel } from './core.js';
|
|
3
|
+
import { $defaultValue, $enum, $itemModel, $key, $members, $name, $optional, $owner, Model, nothing, } from './model.js';
|
|
4
|
+
export * from './model.js';
|
|
5
|
+
export * from './core.js';
|
|
17
6
|
const { defineProperty } = Object;
|
|
18
|
-
const arrayItemModels =
|
|
7
|
+
const arrayItemModels = new WeakMap();
|
|
19
8
|
function getRawValue(model) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
if (model[$owner] instanceof Model) {
|
|
10
|
+
const parentValue = getRawValue(model[$owner]);
|
|
11
|
+
return parentValue === nothing ? nothing : parentValue[model[$key]];
|
|
12
|
+
}
|
|
13
|
+
return model[$owner].value;
|
|
25
14
|
}
|
|
26
15
|
const m = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* Creates a new model that represents a union of the values of the given
|
|
84
|
-
* models.
|
|
85
|
-
*
|
|
86
|
-
* @param members - The models to create the union from.
|
|
87
|
-
*/
|
|
88
|
-
union(...members) {
|
|
89
|
-
return new CoreModelBuilder(Model, () => members[0][$defaultValue]).name(members.map((model) => model[$name]).join(" | ")).define($members, { value: members }).build();
|
|
90
|
-
},
|
|
91
|
-
/**
|
|
92
|
-
* Iterates over the given array model yielding an item model for each item
|
|
93
|
-
* the model value has.
|
|
94
|
-
*
|
|
95
|
-
* @param model - The array model to iterate over.
|
|
96
|
-
*/
|
|
97
|
-
*items(model) {
|
|
98
|
-
const list = arrayItemModels.get(model) ?? [];
|
|
99
|
-
arrayItemModels.set(model, list);
|
|
100
|
-
const value = m.value(model);
|
|
101
|
-
list.length = value.length;
|
|
102
|
-
for (let i = 0; i < value.length; i++) {
|
|
103
|
-
if (!list[i]) {
|
|
104
|
-
list[i] = new CoreModelBuilder(model[$itemModel], () => value[i]).name(`${model[$itemModel][$name]}[${i}]`).define($key, { value: i }).define($owner, { value: model }).build();
|
|
105
|
-
}
|
|
106
|
-
yield list[i];
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
/**
|
|
110
|
-
* Provides the value the given model represents. For attached models it will
|
|
111
|
-
* be the owner value or its part, for detached models it will be the default
|
|
112
|
-
* value of the model.
|
|
113
|
-
*
|
|
114
|
-
* @param model - The model to get the value from.
|
|
115
|
-
*/
|
|
116
|
-
value(model) {
|
|
117
|
-
const value = getRawValue(model);
|
|
118
|
-
return value === nothing ? model[$defaultValue] : value;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
var index_default = m;
|
|
122
|
-
export {
|
|
123
|
-
index_default as default
|
|
16
|
+
attach(model, target) {
|
|
17
|
+
const _model = new CoreModelBuilder(model)
|
|
18
|
+
.name(`@${model[$name]}`)
|
|
19
|
+
.build();
|
|
20
|
+
defineProperty(_model, $owner, { value: target });
|
|
21
|
+
defineProperty(target, 'model', { enumerable: true, configurable: true, value: model });
|
|
22
|
+
return _model;
|
|
23
|
+
},
|
|
24
|
+
extend(base) {
|
|
25
|
+
return new ObjectModelBuilder(base);
|
|
26
|
+
},
|
|
27
|
+
optional(base) {
|
|
28
|
+
return new CoreModelBuilder(base)
|
|
29
|
+
.define($optional, { value: true })
|
|
30
|
+
.build();
|
|
31
|
+
},
|
|
32
|
+
array(itemModel) {
|
|
33
|
+
return new CoreModelBuilder(ArrayModel)
|
|
34
|
+
.name(`Array<${itemModel[$name]}>`)
|
|
35
|
+
.define($itemModel, { value: itemModel })
|
|
36
|
+
.build();
|
|
37
|
+
},
|
|
38
|
+
object(name) {
|
|
39
|
+
return new ObjectModelBuilder(ObjectModel).name(name);
|
|
40
|
+
},
|
|
41
|
+
enum(obj, name) {
|
|
42
|
+
return new CoreModelBuilder(EnumModel).define($enum, { value: obj }).name(name).build();
|
|
43
|
+
},
|
|
44
|
+
union(...members) {
|
|
45
|
+
return new CoreModelBuilder(Model, () => members[0][$defaultValue])
|
|
46
|
+
.name(members.map((model) => model[$name]).join(' | '))
|
|
47
|
+
.define($members, { value: members })
|
|
48
|
+
.build();
|
|
49
|
+
},
|
|
50
|
+
*items(model) {
|
|
51
|
+
const list = arrayItemModels.get(model) ?? [];
|
|
52
|
+
arrayItemModels.set(model, list);
|
|
53
|
+
const value = m.value(model);
|
|
54
|
+
list.length = value.length;
|
|
55
|
+
for (let i = 0; i < value.length; i++) {
|
|
56
|
+
if (!list[i]) {
|
|
57
|
+
list[i] = new CoreModelBuilder(model[$itemModel], () => value[i])
|
|
58
|
+
.name(`${model[$itemModel][$name]}[${i}]`)
|
|
59
|
+
.define($key, { value: i })
|
|
60
|
+
.define($owner, { value: model })
|
|
61
|
+
.build();
|
|
62
|
+
}
|
|
63
|
+
yield list[i];
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
value(model) {
|
|
67
|
+
const value = getRawValue(model);
|
|
68
|
+
return value === nothing ? model[$defaultValue] : value;
|
|
69
|
+
},
|
|
124
70
|
};
|
|
125
|
-
|
|
71
|
+
export default m;
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EmptyObject } from 'type-fest';\nimport { CoreModelBuilder, ObjectModelBuilder } from './builders.js';\nimport { ArrayModel, EnumModel, ObjectModel, type UnionModel } from './core.js';\nimport {\n $defaultValue,\n $enum,\n $itemModel,\n $key,\n $members,\n $name,\n $optional,\n $owner,\n type AnyObject,\n type Target,\n type Enum,\n type Extensions,\n Model,\n nothing,\n type References,\n type Value,\n} from './model.js';\n\nexport * from './model.js';\nexport * from './core.js';\nexport type * from './builders.js';\n\nconst { defineProperty } = Object;\n\nconst arrayItemModels = new WeakMap<ArrayModel, Model[]>();\n\nfunction getRawValue<T>(model: Model<T>): T | typeof nothing {\n if (model[$owner] instanceof Model) {\n // If the current model is a property of another model, the owner is\n // definitely an object. So we just return the part of the value of\n // the owner.\n const parentValue = getRawValue(model[$owner] as Model<Record<keyof any, T>>);\n return parentValue === nothing ? nothing : parentValue[model[$key]];\n }\n\n // Otherwise, the owner is a Target, so we can return the full value.\n return (model[$owner] as Target<T>).value;\n}\n\n/**\n * The utility object that provides methods to create and manipulate models.\n */\nconst m = {\n /**\n * Attaches the given model to the target.\n *\n * @param model - The model to attach.\n * @param target - The target to attach the model to. It could be a Binder\n * instance, a Signal, or another object. However, it could never be another\n * model.\n */\n attach<M extends Model>(model: M, target: Target<Value<M>>): M {\n const _model = new CoreModelBuilder<Value<M>, Extensions<M>, { named: false; selfRefKeys: References<M> }>(model)\n .name(`@${model[$name]}`)\n .build();\n defineProperty(_model, $owner, { value: target });\n defineProperty(target, 'model', { enumerable: true, configurable: true, value: model });\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return _model as any;\n },\n\n /**\n * Creates a new model that extends the given base model.\n *\n * @param base - The base model to extend.\n */\n extend<M extends Model<AnyObject>>(\n base: M,\n ): ObjectModelBuilder<Value<M>, Value<M>, Extensions<M>, { named: false; selfRefKeys: References<M> }> {\n return new ObjectModelBuilder(base);\n },\n\n /**\n * Creates a new model that represents an optional value.\n *\n * @param base - The base model to extend.\n */\n optional<M extends Model>(base: M): M {\n return new CoreModelBuilder<Value<M>, Extensions<M>, { named: true; selfRefKeys: References<M> }>(base)\n .define($optional, { value: true })\n .build() as M;\n },\n\n /**\n * Creates a new model that represents an array of items.\n *\n * @param itemModel - The model of the items in the array.\n */\n array<M extends Model>(itemModel: M): ArrayModel<M> {\n return new CoreModelBuilder<Array<Value<M>>>(ArrayModel)\n .name(`Array<${itemModel[$name]}>`)\n .define($itemModel, { value: itemModel })\n .build();\n },\n\n /**\n * Creates a new model that represents an object.\n *\n * @param name - The name of the object.\n */\n object<T extends AnyObject>(\n name: string,\n ): ObjectModelBuilder<T, EmptyObject, EmptyObject, { named: true; selfRefKeys: never }> {\n return new ObjectModelBuilder(ObjectModel).name(name) as any;\n },\n\n /**\n * Creates a new model that represents an enum.\n *\n * @param obj - The enum object to represent.\n * @param name - The name of the model.\n */\n enum<T extends typeof Enum>(obj: T, name: string): EnumModel<T> {\n return new CoreModelBuilder<T[keyof T]>(EnumModel).define($enum, { value: obj }).name(name).build();\n },\n\n /**\n * Creates a new model that represents a union of the values of the given\n * models.\n *\n * @param members - The models to create the union from.\n */\n union<MM extends Model[]>(...members: MM): UnionModel<MM> {\n return new CoreModelBuilder(Model, () => members[0][$defaultValue] as Value<MM[number]>)\n .name(members.map((model) => model[$name]).join(' | '))\n .define($members, { value: members })\n .build();\n },\n\n /**\n * Iterates over the given array model yielding an item model for each item\n * the model value has.\n *\n * @param model - The array model to iterate over.\n */\n *items<V extends Model>(model: ArrayModel<V>): Generator<V, undefined, void> {\n const list = arrayItemModels.get(model) ?? [];\n arrayItemModels.set(model, list);\n const value = m.value(model);\n\n list.length = value.length;\n\n for (let i = 0; i < value.length; i++) {\n if (!list[i]) {\n list[i] = new CoreModelBuilder(model[$itemModel], () => value[i])\n .name(`${model[$itemModel][$name]}[${i}]`)\n .define($key, { value: i })\n .define($owner, { value: model })\n .build();\n }\n\n yield list[i] as V;\n }\n },\n\n /**\n * Provides the value the given model represents. For attached models it will\n * be the owner value or its part, for detached models it will be the default\n * value of the model.\n *\n * @param model - The model to get the value from.\n */\n value<T>(model: Model<T>): T {\n const value = getRawValue(model);\n\n // If the value is `nothing`, we return the default value of the model.\n return value === nothing ? model[$defaultValue] : value;\n },\n};\n\nexport default m;\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,kBAAkB,0BAA0B;AACrD,SAAS,YAAY,WAAW,mBAAoC;AACpE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAKA;AAAA,EACA;AAAA,OAGK;AAEP,cAAc;AACd,cAAc;AAGd,MAAM,EAAE,eAAe,IAAI;AAE3B,MAAM,kBAAkB,oBAAI,QAA6B;AAEzD,SAAS,YAAe,OAAqC;AAC3D,MAAI,MAAM,MAAM,aAAa,OAAO;AAIlC,UAAM,cAAc,YAAY,MAAM,MAAM,CAAgC;AAC5E,WAAO,gBAAgB,UAAU,UAAU,YAAY,MAAM,IAAI,CA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C,KAAK,EAAE,IAAI,CAAC,CAAC;QACjC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAE7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAE3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBACb,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;qBAC9D,IAAI,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;qBACzC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;qBAC1B,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;qBAChC,KAAK,EAAE,CAAC;YACb,CAAC;YAED,MAAM,IAAI,CAAC,CAAC,CAAM,CAAC;QACrB,CAAC;IACH,CAAC;IASD,KAAK,CAAI,KAAe;QACtB,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAGjC,OAAO,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1D,CAAC;CACF,CAAC;AAEF,eAAe,CAAC,CAAC","sourcesContent":["import type { EmptyObject } from 'type-fest';\nimport { CoreModelBuilder, ObjectModelBuilder } from './builders.js';\nimport { ArrayModel, EnumModel, ObjectModel, type UnionModel } from './core.js';\nimport {\n $defaultValue,\n $enum,\n $itemModel,\n $key,\n $members,\n $name,\n $optional,\n $owner,\n type AnyObject,\n type Target,\n type Enum,\n type Extensions,\n Model,\n nothing,\n type References,\n type Value,\n} from './model.js';\n\nexport * from './model.js';\nexport * from './core.js';\nexport type * from './builders.js';\n\nconst { defineProperty } = Object;\n\nconst arrayItemModels = new WeakMap<ArrayModel, Model[]>();\n\nfunction getRawValue<T>(model: Model<T>): T | typeof nothing {\n if (model[$owner] instanceof Model) {\n // If the current model is a property of another model, the owner is\n // definitely an object. So we just return the part of the value of\n // the owner.\n const parentValue = getRawValue(model[$owner] as Model<Record<keyof any, T>>);\n return parentValue === nothing ? nothing : parentValue[model[$key]];\n }\n\n // Otherwise, the owner is a Target, so we can return the full value.\n return (model[$owner] as Target<T>).value;\n}\n\n/**\n * The utility object that provides methods to create and manipulate models.\n */\nconst m = {\n /**\n * Attaches the given model to the target.\n *\n * @param model - The model to attach.\n * @param target - The target to attach the model to. It could be a Binder\n * instance, a Signal, or another object. However, it could never be another\n * model.\n */\n attach<M extends Model>(model: M, target: Target<Value<M>>): M {\n const _model = new CoreModelBuilder<Value<M>, Extensions<M>, { named: false; selfRefKeys: References<M> }>(model)\n .name(`@${model[$name]}`)\n .build();\n defineProperty(_model, $owner, { value: target });\n defineProperty(target, 'model', { enumerable: true, configurable: true, value: model });\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return _model as any;\n },\n\n /**\n * Creates a new model that extends the given base model.\n *\n * @param base - The base model to extend.\n */\n extend<M extends Model<AnyObject>>(\n base: M,\n ): ObjectModelBuilder<Value<M>, Value<M>, Extensions<M>, { named: false; selfRefKeys: References<M> }> {\n return new ObjectModelBuilder(base);\n },\n\n /**\n * Creates a new model that represents an optional value.\n *\n * @param base - The base model to extend.\n */\n optional<M extends Model>(base: M): M {\n return new CoreModelBuilder<Value<M>, Extensions<M>, { named: true; selfRefKeys: References<M> }>(base)\n .define($optional, { value: true })\n .build() as M;\n },\n\n /**\n * Creates a new model that represents an array of items.\n *\n * @param itemModel - The model of the items in the array.\n */\n array<M extends Model>(itemModel: M): ArrayModel<M> {\n return new CoreModelBuilder<Array<Value<M>>>(ArrayModel)\n .name(`Array<${itemModel[$name]}>`)\n .define($itemModel, { value: itemModel })\n .build();\n },\n\n /**\n * Creates a new model that represents an object.\n *\n * @param name - The name of the object.\n */\n object<T extends AnyObject>(\n name: string,\n ): ObjectModelBuilder<T, EmptyObject, EmptyObject, { named: true; selfRefKeys: never }> {\n return new ObjectModelBuilder(ObjectModel).name(name) as any;\n },\n\n /**\n * Creates a new model that represents an enum.\n *\n * @param obj - The enum object to represent.\n * @param name - The name of the model.\n */\n enum<T extends typeof Enum>(obj: T, name: string): EnumModel<T> {\n return new CoreModelBuilder<T[keyof T]>(EnumModel).define($enum, { value: obj }).name(name).build();\n },\n\n /**\n * Creates a new model that represents a union of the values of the given\n * models.\n *\n * @param members - The models to create the union from.\n */\n union<MM extends Model[]>(...members: MM): UnionModel<MM> {\n return new CoreModelBuilder(Model, () => members[0][$defaultValue] as Value<MM[number]>)\n .name(members.map((model) => model[$name]).join(' | '))\n .define($members, { value: members })\n .build();\n },\n\n /**\n * Iterates over the given array model yielding an item model for each item\n * the model value has.\n *\n * @param model - The array model to iterate over.\n */\n *items<V extends Model>(model: ArrayModel<V>): Generator<V, undefined, void> {\n const list = arrayItemModels.get(model) ?? [];\n arrayItemModels.set(model, list);\n const value = m.value(model);\n\n list.length = value.length;\n\n for (let i = 0; i < value.length; i++) {\n if (!list[i]) {\n list[i] = new CoreModelBuilder(model[$itemModel], () => value[i])\n .name(`${model[$itemModel][$name]}[${i}]`)\n .define($key, { value: i })\n .define($owner, { value: model })\n .build();\n }\n\n yield list[i] as V;\n }\n },\n\n /**\n * Provides the value the given model represents. For attached models it will\n * be the owner value or its part, for detached models it will be the default\n * value of the model.\n *\n * @param model - The model to get the value from.\n */\n value<T>(model: Model<T>): T {\n const value = getRawValue(model);\n\n // If the value is `nothing`, we return the default value of the model.\n return value === nothing ? model[$defaultValue] : value;\n },\n};\n\nexport default m;\n"]}
|
package/model.d.ts
CHANGED
|
@@ -8,17 +8,10 @@ export interface Annotation {
|
|
|
8
8
|
jvmType: string;
|
|
9
9
|
arguments: Record<string, AnnotationValue>;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
* The metadata of a model.
|
|
13
|
-
*/
|
|
14
11
|
export interface ModelMetadata {
|
|
15
12
|
jvmType?: string;
|
|
16
13
|
annotations?: Annotation[];
|
|
17
14
|
}
|
|
18
|
-
/**
|
|
19
|
-
* The target to which a model is attached. It could be a Binder instance, a
|
|
20
|
-
* Signal or another object. However, it could never be another model.
|
|
21
|
-
*/
|
|
22
15
|
export type Target<T = unknown> = Readonly<{
|
|
23
16
|
model?: Model<T>;
|
|
24
17
|
value: T;
|
|
@@ -27,110 +20,30 @@ export declare const nothing: unique symbol;
|
|
|
27
20
|
export declare enum Enum {
|
|
28
21
|
}
|
|
29
22
|
export type AnyObject = Readonly<Record<never, never>>;
|
|
30
|
-
/**
|
|
31
|
-
* The symbol that represents the {@link Model[$key]} property.
|
|
32
|
-
*/
|
|
33
23
|
export declare const $key: unique symbol;
|
|
34
|
-
/**
|
|
35
|
-
* The symbol that represents the {@link Model[$name]} property.
|
|
36
|
-
*/
|
|
37
24
|
export declare const $name: unique symbol;
|
|
38
|
-
/**
|
|
39
|
-
* The symbol that represents the {@link Model[$owner]} property.
|
|
40
|
-
*/
|
|
41
25
|
export declare const $owner: unique symbol;
|
|
42
|
-
/**
|
|
43
|
-
* The symbol that represents the {@link Model[$meta]} property.
|
|
44
|
-
*/
|
|
45
26
|
export declare const $meta: unique symbol;
|
|
46
|
-
/**
|
|
47
|
-
* The symbol that represents the {@link Model[$optional]} property.
|
|
48
|
-
*/
|
|
49
27
|
export declare const $optional: unique symbol;
|
|
50
|
-
/**
|
|
51
|
-
* The symbol that represents the {@link Model[$value]} property.
|
|
52
|
-
*/
|
|
53
28
|
export declare const $defaultValue: unique symbol;
|
|
54
|
-
/**
|
|
55
|
-
* The symbol that represents the {@link EnumModel[$enumerate]} property.
|
|
56
|
-
*/
|
|
57
29
|
export declare const $enum: unique symbol;
|
|
58
|
-
/**
|
|
59
|
-
* The symbol that represents the {@link UnionModel[$members]} property.
|
|
60
|
-
*/
|
|
61
30
|
export declare const $members: unique symbol;
|
|
62
|
-
/**
|
|
63
|
-
* The symbol that represents the {@link ArrayModel[$itemModel]} property.
|
|
64
|
-
*/
|
|
65
31
|
export declare const $itemModel: unique symbol;
|
|
66
|
-
/**
|
|
67
|
-
* Extracts the value type the model represents.
|
|
68
|
-
*/
|
|
69
32
|
export type Value<M extends Model> = M extends Model<infer T> ? T : never;
|
|
70
|
-
/**
|
|
71
|
-
* Extracts the list of extra properties of the model.
|
|
72
|
-
*/
|
|
73
33
|
export type Extensions<M extends Model> = M extends Model<unknown, infer EX> ? EX : EmptyObject;
|
|
74
|
-
/**
|
|
75
|
-
* Extracts the list of self-referencing properties of the model.
|
|
76
|
-
*/
|
|
77
34
|
export type References<M extends Model> = M extends Model<unknown, AnyObject, infer R> ? R : never;
|
|
78
|
-
/**
|
|
79
|
-
* A model that represents a specific type of data.
|
|
80
|
-
*
|
|
81
|
-
* @typeParam V - The type of the data described by the model.
|
|
82
|
-
* @typeParam EX - The extra properties of the model. It could be either a model
|
|
83
|
-
* that represents a property of the object the current model describe, or a
|
|
84
|
-
* model-specific metadata. It's recommended to use a symbol as a key for the
|
|
85
|
-
* metadata property to avoid the potential naming conflicts with the described
|
|
86
|
-
* object properties.
|
|
87
|
-
* @typeParam R - The keys of the self-referencing properties of the model.
|
|
88
|
-
*
|
|
89
|
-
* @remarks
|
|
90
|
-
* Since we know the full model definition only on this step, the `R` type
|
|
91
|
-
* parameter is essential to describe a model with self-reference properties.
|
|
92
|
-
*/
|
|
93
35
|
export type Model<V = unknown, EX extends AnyObject = EmptyObject, R extends keyof any = never> = EX & Readonly<{
|
|
94
36
|
[P in R]: Model<V, EX, R>;
|
|
95
37
|
}> & Readonly<{
|
|
96
|
-
/**
|
|
97
|
-
* The key of the model in the owner model.
|
|
98
|
-
*/
|
|
99
38
|
[$key]: keyof any;
|
|
100
|
-
/**
|
|
101
|
-
* The name of the model. For attached models, the name will be prefixed
|
|
102
|
-
* with the `@` symbol.
|
|
103
|
-
*/
|
|
104
39
|
[$name]: string;
|
|
105
|
-
/**
|
|
106
|
-
* The owner model of the model. For detached models, the owner will always
|
|
107
|
-
* be a specific global object `detachedTarget`.
|
|
108
|
-
*/
|
|
109
40
|
[$owner]: Model | Target;
|
|
110
|
-
/**
|
|
111
|
-
* The metadata of the model.
|
|
112
|
-
*/
|
|
113
41
|
[$meta]?: ModelMetadata;
|
|
114
|
-
/**
|
|
115
|
-
* Whether the model is optional. It describes if the data described by
|
|
116
|
-
* this model is nullable.
|
|
117
|
-
*/
|
|
118
42
|
[$optional]: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* The default value of the model.
|
|
121
|
-
*/
|
|
122
43
|
[$defaultValue]: V;
|
|
123
44
|
[Symbol.toStringTag]: string;
|
|
124
45
|
[Symbol.hasInstance](value: any): value is Model<V, EX, R>;
|
|
125
46
|
toString(): string;
|
|
126
47
|
}>;
|
|
127
|
-
/**
|
|
128
|
-
* A function that provides a default value for a model.
|
|
129
|
-
*
|
|
130
|
-
* @typeParam V - The type of the data described by the model.
|
|
131
|
-
* @typeParam EX - The extra properties of the model.
|
|
132
|
-
* @typeParam R - The keys of the self-referencing properties of the model.
|
|
133
|
-
*/
|
|
134
48
|
export type DefaultValueProvider<V, EX extends AnyObject = EmptyObject, R extends keyof any = never> = (model: Model<V, EX, R>) => V;
|
|
135
49
|
export declare const Model: Model;
|
|
136
|
-
//# sourceMappingURL=model.d.ts.map
|
package/model.js
CHANGED
|
@@ -1,64 +1,48 @@
|
|
|
1
|
-
const nothing = Symbol(
|
|
2
|
-
const detachedTarget = Object.create(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
model: { value: void 0 },
|
|
8
|
-
value: { value: nothing }
|
|
9
|
-
}
|
|
10
|
-
);
|
|
11
|
-
const $key = Symbol("key");
|
|
12
|
-
const $name = Symbol("name");
|
|
13
|
-
const $owner = Symbol("owner");
|
|
14
|
-
const $meta = Symbol("meta");
|
|
15
|
-
const $optional = Symbol("optional");
|
|
16
|
-
const $defaultValue = Symbol("value");
|
|
17
|
-
const $enum = Symbol("enumerate");
|
|
18
|
-
const $members = Symbol("members");
|
|
19
|
-
const $itemModel = Symbol("itemModel");
|
|
20
|
-
const Model = Object.create(null, {
|
|
21
|
-
[$key]: {
|
|
22
|
-
value: "model"
|
|
23
|
-
},
|
|
24
|
-
[$name]: {
|
|
25
|
-
value: "Model"
|
|
26
|
-
},
|
|
27
|
-
[$owner]: {
|
|
28
|
-
value: detachedTarget
|
|
29
|
-
},
|
|
30
|
-
[$meta]: {},
|
|
31
|
-
[$optional]: {
|
|
32
|
-
value: false
|
|
33
|
-
},
|
|
34
|
-
[$defaultValue]: {},
|
|
35
|
-
[Symbol.toStringTag]: {
|
|
36
|
-
get() {
|
|
37
|
-
return this[$name];
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
[Symbol.hasInstance]: {
|
|
41
|
-
value(o) {
|
|
42
|
-
return typeof o === "object" && o != null && (this === o || Object.prototype.isPrototypeOf.call(this, o));
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
toString: {
|
|
46
|
-
value() {
|
|
47
|
-
return `[${String(this[$owner])} / ${String(this[$key])}${this[$optional] ? "?" : ""}] ${this[$name]}`;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
export const nothing = Symbol('nothing');
|
|
2
|
+
const detachedTarget = Object.create({
|
|
3
|
+
toString: () => ':detached:',
|
|
4
|
+
}, {
|
|
5
|
+
model: { value: undefined },
|
|
6
|
+
value: { value: nothing },
|
|
50
7
|
});
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
8
|
+
export const $key = Symbol('key');
|
|
9
|
+
export const $name = Symbol('name');
|
|
10
|
+
export const $owner = Symbol('owner');
|
|
11
|
+
export const $meta = Symbol('meta');
|
|
12
|
+
export const $optional = Symbol('optional');
|
|
13
|
+
export const $defaultValue = Symbol('value');
|
|
14
|
+
export const $enum = Symbol('enumerate');
|
|
15
|
+
export const $members = Symbol('members');
|
|
16
|
+
export const $itemModel = Symbol('itemModel');
|
|
17
|
+
export const Model = Object.create(null, {
|
|
18
|
+
[$key]: {
|
|
19
|
+
value: 'model',
|
|
20
|
+
},
|
|
21
|
+
[$name]: {
|
|
22
|
+
value: 'Model',
|
|
23
|
+
},
|
|
24
|
+
[$owner]: {
|
|
25
|
+
value: detachedTarget,
|
|
26
|
+
},
|
|
27
|
+
[$meta]: {},
|
|
28
|
+
[$optional]: {
|
|
29
|
+
value: false,
|
|
30
|
+
},
|
|
31
|
+
[$defaultValue]: {},
|
|
32
|
+
[Symbol.toStringTag]: {
|
|
33
|
+
get() {
|
|
34
|
+
return this[$name];
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
[Symbol.hasInstance]: {
|
|
38
|
+
value(o) {
|
|
39
|
+
return typeof o === 'object' && o != null && (this === o || Object.prototype.isPrototypeOf.call(this, o));
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
toString: {
|
|
43
|
+
value() {
|
|
44
|
+
return `[${String(this[$owner])} / ${String(this[$key])}${this[$optional] ? '?' : ''}] ${this[$name]}`;
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=model.js.map
|
package/model.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/model.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EmptyObject } from 'type-fest';\n\nexport interface JvmTypeRef {\n jvmType: string;\n genericArguments?: JvmTypeRef[];\n}\n\nexport type AnnotationValue = AnnotationValue[] | JvmTypeRef | boolean | number | string | undefined;\n\nexport interface Annotation {\n jvmType: string;\n arguments: Record<string, AnnotationValue>;\n}\n\n/**\n * The metadata of a model.\n */\nexport interface ModelMetadata {\n jvmType?: string;\n annotations?: Annotation[];\n}\n\n/**\n * The target to which a model is attached. It could be a Binder instance, a\n * Signal or another object. However, it could never be another model.\n */\nexport type Target<T = unknown> = Readonly<{\n model?: Model<T>;\n value: T;\n}>;\n\nexport const nothing = Symbol('nothing');\n\nconst detachedTarget: Target = Object.create(\n {\n toString: () => ':detached:',\n },\n {\n model: { value: undefined },\n value: { value: nothing },\n },\n);\n\nexport declare enum Enum {}\n\nexport type AnyObject = Readonly<Record<never, never>>; // {}\n\n/* eslint-disable tsdoc/syntax */\n/**\n * The symbol that represents the {@link Model[$key]} property.\n */\nexport const $key = Symbol('key');\n\n/**\n * The symbol that represents the {@link Model[$name]} property.\n */\nexport const $name = Symbol('name');\n\n/**\n * The symbol that represents the {@link Model[$owner]} property.\n */\nexport const $owner = Symbol('owner');\n\n/**\n * The symbol that represents the {@link Model[$meta]} property.\n */\nexport const $meta = Symbol('meta');\n\n/**\n * The symbol that represents the {@link Model[$optional]} property.\n */\nexport const $optional = Symbol('optional');\n\n/**\n * The symbol that represents the {@link Model[$value]} property.\n */\nexport const $defaultValue = Symbol('value');\n\n/**\n * The symbol that represents the {@link EnumModel[$enumerate]} property.\n */\nexport const $enum = Symbol('enumerate');\n\n/**\n * The symbol that represents the {@link UnionModel[$members]} property.\n */\nexport const $members = Symbol('members');\n\n/**\n * The symbol that represents the {@link ArrayModel[$itemModel]} property.\n */\nexport const $itemModel = Symbol('itemModel');\n\n/* eslint-enable tsdoc/syntax */\n\n/**\n * Extracts the value type the model represents.\n */\nexport type Value<M extends Model> = M extends Model<infer T> ? T : never;\n\n/**\n * Extracts the list of extra properties of the model.\n */\nexport type Extensions<M extends Model> = M extends Model<unknown, infer EX> ? EX : EmptyObject;\n\n/**\n * Extracts the list of self-referencing properties of the model.\n */\nexport type References<M extends Model> = M extends Model<unknown, AnyObject, infer R> ? R : never;\n\n/**\n * A model that represents a specific type of data.\n *\n * @typeParam V - The type of the data described by the model.\n * @typeParam EX - The extra properties of the model. It could be either a model\n * that represents a property of the object the current model describe, or a\n * model-specific metadata. It's recommended to use a symbol as a key for the\n * metadata property to avoid the potential naming conflicts with the described\n * object properties.\n * @typeParam R - The keys of the self-referencing properties of the model.\n *\n * @remarks\n * Since we know the full model definition only on this step, the `R` type\n * parameter is essential to describe a model with self-reference properties.\n */\nexport type Model<V = unknown, EX extends AnyObject = EmptyObject, R extends keyof any = never> = EX &\n Readonly<{\n [P in R]: Model<V, EX, R>;\n }> &\n Readonly<{\n /**\n * The key of the model in the owner model.\n */\n [$key]: keyof any;\n\n /**\n * The name of the model. For attached models, the name will be prefixed\n * with the `@` symbol.\n */\n [$name]: string;\n\n /**\n * The owner model of the model. For detached models, the owner will always\n * be a specific global object `detachedTarget`.\n */\n [$owner]: Model | Target;\n\n /**\n * The metadata of the model.\n */\n [$meta]?: ModelMetadata;\n\n /**\n * Whether the model is optional. It describes if the data described by\n * this model is nullable.\n */\n [$optional]: boolean;\n\n /**\n * The default value of the model.\n */\n [$defaultValue]: V;\n [Symbol.toStringTag]: string;\n [Symbol.hasInstance](value: any): value is Model<V, EX, R>;\n toString(): string;\n }>;\n\n/**\n * A function that provides a default value for a model.\n *\n * @typeParam V - The type of the data described by the model.\n * @typeParam EX - The extra properties of the model.\n * @typeParam R - The keys of the self-referencing properties of the model.\n */\nexport type DefaultValueProvider<V, EX extends AnyObject = EmptyObject, R extends keyof any = never> = (\n model: Model<V, EX, R>,\n) => V;\n\nexport const Model: Model = Object.create(null, {\n [$key]: {\n value: 'model',\n },\n [$name]: {\n value: 'Model',\n },\n [$owner]: {\n value: detachedTarget,\n },\n [$meta]: {},\n [$optional]: {\n value: false,\n },\n [$defaultValue]: {},\n [Symbol.toStringTag]: {\n get(this: Model) {\n return this[$name];\n },\n },\n [Symbol.hasInstance]: {\n value(this: Model, o: unknown) {\n return typeof o === 'object' && o != null && (this === o || Object.prototype.isPrototypeOf.call(this, o));\n },\n },\n toString: {\n value(this: Model) {\n return `[${String(this[$owner])} / ${String(this[$key])}${this[$optional] ? '?' : ''}] ${this[$name]}`;\n },\n },\n});\n"],
|
|
5
|
-
"mappings": "AA+BO,MAAM,UAAU,OAAO,SAAS;AAEvC,MAAM,iBAAyB,OAAO;AAAA,EACpC;AAAA,IACE,UAAU,MAAM;AAAA,EAClB;AAAA,EACA;AAAA,IACE,OAAO,EAAE,OAAO,OAAU;AAAA,IAC1B,OAAO,EAAE,OAAO,QAAQ;AAAA,EAC1B;AACF;AAUO,MAAM,OAAO,OAAO,KAAK;AAKzB,MAAM,QAAQ,OAAO,MAAM;AAK3B,MAAM,SAAS,OAAO,OAAO;AAK7B,MAAM,QAAQ,OAAO,MAAM;AAK3B,MAAM,YAAY,OAAO,UAAU;AAKnC,MAAM,gBAAgB,OAAO,OAAO;AAKpC,MAAM,QAAQ,OAAO,WAAW;AAKhC,MAAM,WAAW,OAAO,SAAS;AAKjC,MAAM,aAAa,OAAO,WAAW;AAuFrC,MAAM,QAAe,OAAO,OAAO,MAAM;AAAA,EAC9C,CAAC,IAAI,GAAG;AAAA,IACN,OAAO;AAAA,EACT;AAAA,EACA,CAAC,KAAK,GAAG;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA,CAAC,MAAM,GAAG;AAAA,IACR,OAAO;AAAA,EACT;AAAA,EACA,CAAC,KAAK,GAAG,CAAC;AAAA,EACV,CAAC,SAAS,GAAG;AAAA,IACX,OAAO;AAAA,EACT;AAAA,EACA,CAAC,aAAa,GAAG,CAAC;AAAA,EAClB,CAAC,OAAO,WAAW,GAAG;AAAA,IACpB,MAAiB;AACf,aAAO,KAAK,KAAK;AAAA,IACnB;AAAA,EACF;AAAA,EACA,CAAC,OAAO,WAAW,GAAG;AAAA,IACpB,MAAmB,GAAY;AAC7B,aAAO,OAAO,MAAM,YAAY,KAAK,SAAS,SAA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,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAuF9C,MAAM,CAAC,MAAM,KAAK,GAAU,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;IAC9C,CAAC,IAAI,CAAC,EAAE;QACN,KAAK,EAAE,OAAO;KACf;IACD,CAAC,KAAK,CAAC,EAAE;QACP,KAAK,EAAE,OAAO;KACf;IACD,CAAC,MAAM,CAAC,EAAE;QACR,KAAK,EAAE,cAAc;KACtB;IACD,CAAC,KAAK,CAAC,EAAE,EAAE;IACX,CAAC,SAAS,CAAC,EAAE;QACX,KAAK,EAAE,KAAK;KACb;IACD,CAAC,aAAa,CAAC,EAAE,EAAE;IACnB,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;QACpB,GAAG;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;KACF;IACD,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;QACpB,KAAK,CAAc,CAAU;YAC3B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5G,CAAC;KACF;IACD,QAAQ,EAAE;QACR,KAAK;YAEH,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACzG,CAAC;KACF;CACF,CAAC,CAAC","sourcesContent":["import type { EmptyObject } from 'type-fest';\n\nexport interface JvmTypeRef {\n jvmType: string;\n genericArguments?: JvmTypeRef[];\n}\n\nexport type AnnotationValue = AnnotationValue[] | JvmTypeRef | boolean | number | string | undefined;\n\nexport interface Annotation {\n jvmType: string;\n arguments: Record<string, AnnotationValue>;\n}\n\n/**\n * The metadata of a model.\n */\nexport interface ModelMetadata {\n jvmType?: string;\n annotations?: Annotation[];\n}\n\n/**\n * The target to which a model is attached. It could be a Binder instance, a\n * Signal or another object. However, it could never be another model.\n */\nexport type Target<T = unknown> = Readonly<{\n model?: Model<T>;\n value: T;\n}>;\n\nexport const nothing = Symbol('nothing');\n\nconst detachedTarget: Target = Object.create(\n {\n toString: () => ':detached:',\n },\n {\n model: { value: undefined },\n value: { value: nothing },\n },\n);\n\nexport declare enum Enum {}\n\nexport type AnyObject = Readonly<Record<never, never>>; // {}\n\n/* eslint-disable tsdoc/syntax */\n/**\n * The symbol that represents the {@link Model[$key]} property.\n */\nexport const $key = Symbol('key');\n\n/**\n * The symbol that represents the {@link Model[$name]} property.\n */\nexport const $name = Symbol('name');\n\n/**\n * The symbol that represents the {@link Model[$owner]} property.\n */\nexport const $owner = Symbol('owner');\n\n/**\n * The symbol that represents the {@link Model[$meta]} property.\n */\nexport const $meta = Symbol('meta');\n\n/**\n * The symbol that represents the {@link Model[$optional]} property.\n */\nexport const $optional = Symbol('optional');\n\n/**\n * The symbol that represents the {@link Model[$value]} property.\n */\nexport const $defaultValue = Symbol('value');\n\n/**\n * The symbol that represents the {@link EnumModel[$enumerate]} property.\n */\nexport const $enum = Symbol('enumerate');\n\n/**\n * The symbol that represents the {@link UnionModel[$members]} property.\n */\nexport const $members = Symbol('members');\n\n/**\n * The symbol that represents the {@link ArrayModel[$itemModel]} property.\n */\nexport const $itemModel = Symbol('itemModel');\n\n/* eslint-enable tsdoc/syntax */\n\n/**\n * Extracts the value type the model represents.\n */\nexport type Value<M extends Model> = M extends Model<infer T> ? T : never;\n\n/**\n * Extracts the list of extra properties of the model.\n */\nexport type Extensions<M extends Model> = M extends Model<unknown, infer EX> ? EX : EmptyObject;\n\n/**\n * Extracts the list of self-referencing properties of the model.\n */\nexport type References<M extends Model> = M extends Model<unknown, AnyObject, infer R> ? R : never;\n\n/**\n * A model that represents a specific type of data.\n *\n * @typeParam V - The type of the data described by the model.\n * @typeParam EX - The extra properties of the model. It could be either a model\n * that represents a property of the object the current model describe, or a\n * model-specific metadata. It's recommended to use a symbol as a key for the\n * metadata property to avoid the potential naming conflicts with the described\n * object properties.\n * @typeParam R - The keys of the self-referencing properties of the model.\n *\n * @remarks\n * Since we know the full model definition only on this step, the `R` type\n * parameter is essential to describe a model with self-reference properties.\n */\nexport type Model<V = unknown, EX extends AnyObject = EmptyObject, R extends keyof any = never> = EX &\n Readonly<{\n [P in R]: Model<V, EX, R>;\n }> &\n Readonly<{\n /**\n * The key of the model in the owner model.\n */\n [$key]: keyof any;\n\n /**\n * The name of the model. For attached models, the name will be prefixed\n * with the `@` symbol.\n */\n [$name]: string;\n\n /**\n * The owner model of the model. For detached models, the owner will always\n * be a specific global object `detachedTarget`.\n */\n [$owner]: Model | Target;\n\n /**\n * The metadata of the model.\n */\n [$meta]?: ModelMetadata;\n\n /**\n * Whether the model is optional. It describes if the data described by\n * this model is nullable.\n */\n [$optional]: boolean;\n\n /**\n * The default value of the model.\n */\n [$defaultValue]: V;\n [Symbol.toStringTag]: string;\n [Symbol.hasInstance](value: any): value is Model<V, EX, R>;\n toString(): string;\n }>;\n\n/**\n * A function that provides a default value for a model.\n *\n * @typeParam V - The type of the data described by the model.\n * @typeParam EX - The extra properties of the model.\n * @typeParam R - The keys of the self-referencing properties of the model.\n */\nexport type DefaultValueProvider<V, EX extends AnyObject = EmptyObject, R extends keyof any = never> = (\n model: Model<V, EX, R>,\n) => V;\n\nexport const Model: Model = Object.create(null, {\n [$key]: {\n value: 'model',\n },\n [$name]: {\n value: 'Model',\n },\n [$owner]: {\n value: detachedTarget,\n },\n [$meta]: {},\n [$optional]: {\n value: false,\n },\n [$defaultValue]: {},\n [Symbol.toStringTag]: {\n get(this: Model) {\n return this[$name];\n },\n },\n [Symbol.hasInstance]: {\n value(this: Model, o: unknown) {\n return typeof o === 'object' && o != null && (this === o || Object.prototype.isPrototypeOf.call(this, o));\n },\n },\n toString: {\n value(this: Model) {\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n return `[${String(this[$owner])} / ${String(this[$key])}${this[$optional] ? '?' : ''}] ${this[$name]}`;\n },\n },\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-models",
|
|
3
|
-
"version": "24.7.0-
|
|
3
|
+
"version": "24.7.0-beta3",
|
|
4
4
|
"description": "Generative form models for Hilla",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -17,15 +17,12 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"clean:build": "git clean -fx . -e .vite -e node_modules",
|
|
20
|
-
"build": "
|
|
21
|
-
"build:esbuild": "tsx ../../../scripts/build.ts",
|
|
22
|
-
"build:dts": "tsc --isolatedModules -p tsconfig.build.json",
|
|
23
|
-
"build:copy": "cd src && copyfiles **/*.d.ts ..",
|
|
20
|
+
"build": "tsx ../../../scripts/build.ts",
|
|
24
21
|
"lint": "eslint src test",
|
|
25
22
|
"lint:fix": "eslint src test --fix",
|
|
26
|
-
"test": "
|
|
27
|
-
"test:coverage": "
|
|
28
|
-
"test:watch": "
|
|
23
|
+
"test": "vitest --run",
|
|
24
|
+
"test:coverage": "vitest --run --coverage",
|
|
25
|
+
"test:watch": "vitest",
|
|
29
26
|
"typecheck": "tsc --noEmit"
|
|
30
27
|
},
|
|
31
28
|
"exports": {
|
|
@@ -46,36 +43,10 @@
|
|
|
46
43
|
"access": "public"
|
|
47
44
|
},
|
|
48
45
|
"dependencies": {
|
|
49
|
-
"@vaadin/hilla-lit-form": "24.7.0-
|
|
46
|
+
"@vaadin/hilla-lit-form": "24.7.0-beta3"
|
|
50
47
|
},
|
|
51
48
|
"peerDependencies": {
|
|
52
49
|
"react": "18 || 19",
|
|
53
50
|
"react-dom": "18 || 19"
|
|
54
|
-
},
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"@testing-library/react": "^16.1.0",
|
|
57
|
-
"@testing-library/user-event": "^14.5.2",
|
|
58
|
-
"@types/chai": "^4.3.20",
|
|
59
|
-
"@types/chai-as-promised": "^7.1.8",
|
|
60
|
-
"@types/chai-dom": "^1.11.3",
|
|
61
|
-
"@types/chai-like": "^1.1.3",
|
|
62
|
-
"@types/mocha": "^10.0.10",
|
|
63
|
-
"@types/node": "^20.17.12",
|
|
64
|
-
"@types/react": "^18.3.18",
|
|
65
|
-
"@types/react-dom": "^18",
|
|
66
|
-
"@types/sinon": "^10.0.20",
|
|
67
|
-
"@types/sinon-chai": "^3.2.12",
|
|
68
|
-
"@types/validator": "^13.12.2",
|
|
69
|
-
"c8": "^10.1.3",
|
|
70
|
-
"chai": "^5.1.2",
|
|
71
|
-
"chai-as-promised": "^7.1.2",
|
|
72
|
-
"chai-dom": "^1.12.0",
|
|
73
|
-
"chai-like": "^1.1.3",
|
|
74
|
-
"glob": "^11.0.1",
|
|
75
|
-
"mocha": "^11.1.0",
|
|
76
|
-
"monocart-coverage-reports": "^2.11.5",
|
|
77
|
-
"sinon": "^16.1.3",
|
|
78
|
-
"sinon-chai": "^3.7.0",
|
|
79
|
-
"typescript": "5.7.3"
|
|
80
51
|
}
|
|
81
52
|
}
|
package/builders.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["src/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAML,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,KAAK,EACV,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AAIpB;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,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