@axi-engine/fields 0.3.2 → 0.3.4
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/README.md +6 -2
- package/dist/core-field-tree-factory.d.ts +13 -0
- package/dist/core-field-tree-factory.d.ts.map +1 -0
- package/dist/core-field-tree-factory.js +14 -0
- package/dist/core-field-tree-factory.js.map +1 -0
- package/dist/core-field-tree.d.ts +5 -0
- package/dist/core-field-tree.d.ts.map +1 -0
- package/dist/core-field-tree.js +4 -0
- package/dist/core-field-tree.js.map +1 -0
- package/dist/core-fields-factory.d.ts +10 -0
- package/dist/core-fields-factory.d.ts.map +1 -0
- package/dist/core-fields-factory.js +14 -0
- package/dist/core-fields-factory.js.map +1 -0
- package/dist/core-fields.d.ts +47 -0
- package/dist/core-fields.d.ts.map +1 -0
- package/dist/core-fields.js +8 -0
- package/dist/core-fields.js.map +1 -0
- package/dist/data-store-field-resolver.d.ts +26 -0
- package/dist/data-store-field-resolver.d.ts.map +1 -0
- package/dist/data-store-field-resolver.js +21 -0
- package/dist/data-store-field-resolver.js.map +1 -0
- package/dist/data-store.d.ts +38 -0
- package/dist/data-store.d.ts.map +1 -0
- package/dist/data-store.js +141 -0
- package/dist/data-store.js.map +1 -0
- package/dist/field-definitions/core-boolean-field.d.ts +11 -0
- package/dist/field-definitions/core-boolean-field.d.ts.map +1 -0
- package/dist/field-definitions/core-boolean-field.js +13 -0
- package/dist/field-definitions/core-boolean-field.js.map +1 -0
- package/dist/field-definitions/core-field.d.ts +51 -0
- package/dist/field-definitions/core-field.d.ts.map +1 -0
- package/dist/field-definitions/core-field.js +74 -0
- package/dist/field-definitions/core-field.js.map +1 -0
- package/dist/field-definitions/core-numeric-field.d.ts +18 -0
- package/dist/field-definitions/core-numeric-field.d.ts.map +1 -0
- package/dist/field-definitions/core-numeric-field.js +45 -0
- package/dist/field-definitions/core-numeric-field.js.map +1 -0
- package/dist/field-definitions/core-string-field.d.ts +15 -0
- package/dist/field-definitions/core-string-field.d.ts.map +1 -0
- package/dist/field-definitions/core-string-field.js +27 -0
- package/dist/field-definitions/core-string-field.js.map +1 -0
- package/dist/field-definitions/index.d.ts +5 -0
- package/dist/field-definitions/index.d.ts.map +1 -0
- package/dist/field-definitions/index.js +5 -0
- package/dist/field-definitions/index.js.map +1 -0
- package/dist/field-registry.d.ts +5 -0
- package/dist/field-registry.d.ts.map +1 -0
- package/dist/field-registry.js +4 -0
- package/dist/field-registry.js.map +1 -0
- package/dist/field-tree-factory.d.ts +12 -0
- package/dist/field-tree-factory.d.ts.map +1 -0
- package/dist/field-tree-factory.js +2 -0
- package/dist/field-tree-factory.js.map +1 -0
- package/dist/field-tree.d.ts +171 -0
- package/dist/field-tree.d.ts.map +1 -0
- package/dist/field-tree.js +248 -0
- package/dist/field-tree.js.map +1 -0
- package/dist/field.d.ts +34 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +2 -0
- package/dist/field.js.map +1 -0
- package/dist/fields-factory.d.ts +5 -0
- package/dist/fields-factory.d.ts.map +1 -0
- package/dist/fields-factory.js +2 -0
- package/dist/fields-factory.js.map +1 -0
- package/dist/fields.d.ts +101 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +143 -0
- package/dist/fields.js.map +1 -0
- package/dist/index.d.mts +112 -112
- package/dist/index.d.ts +18 -997
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -1228
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -2
- package/dist/mixins/mixin-factory.d.ts +29 -0
- package/dist/mixins/mixin-factory.d.ts.map +1 -0
- package/dist/mixins/mixin-factory.js +32 -0
- package/dist/mixins/mixin-factory.js.map +1 -0
- package/dist/mixins/with-boolean-fields.mixin.d.ts +9 -0
- package/dist/mixins/with-boolean-fields.mixin.d.ts.map +1 -0
- package/dist/mixins/with-boolean-fields.mixin.js +4 -0
- package/dist/mixins/with-boolean-fields.mixin.js.map +1 -0
- package/dist/mixins/with-default-generic-fields.mixin.d.ts +31 -0
- package/dist/mixins/with-default-generic-fields.mixin.d.ts.map +1 -0
- package/dist/mixins/with-default-generic-fields.mixin.js +15 -0
- package/dist/mixins/with-default-generic-fields.mixin.js.map +1 -0
- package/dist/mixins/with-numeric-fields.mixin.d.ts +9 -0
- package/dist/mixins/with-numeric-fields.mixin.d.ts.map +1 -0
- package/dist/mixins/with-numeric-fields.mixin.js +4 -0
- package/dist/mixins/with-numeric-fields.mixin.js.map +1 -0
- package/dist/mixins/with-string-fields.mixin.d.ts +9 -0
- package/dist/mixins/with-string-fields.mixin.d.ts.map +1 -0
- package/dist/mixins/with-string-fields.mixin.js +4 -0
- package/dist/mixins/with-string-fields.mixin.js.map +1 -0
- package/dist/policies/clamp-max-policy.d.ts +11 -0
- package/dist/policies/clamp-max-policy.d.ts.map +1 -0
- package/dist/policies/clamp-max-policy.js +18 -0
- package/dist/policies/clamp-max-policy.js.map +1 -0
- package/dist/policies/clamp-min-policy.d.ts +11 -0
- package/dist/policies/clamp-min-policy.d.ts.map +1 -0
- package/dist/policies/clamp-min-policy.js +18 -0
- package/dist/policies/clamp-min-policy.js.map +1 -0
- package/dist/policies/clamp-policy.d.ts +12 -0
- package/dist/policies/clamp-policy.d.ts.map +1 -0
- package/dist/policies/clamp-policy.js +21 -0
- package/dist/policies/clamp-policy.js.map +1 -0
- package/dist/policies/index.d.ts +6 -0
- package/dist/policies/index.d.ts.map +1 -0
- package/dist/policies/index.js +6 -0
- package/dist/policies/index.js.map +1 -0
- package/dist/policies/policies.d.ts +38 -0
- package/dist/policies/policies.d.ts.map +1 -0
- package/dist/policies/policies.js +62 -0
- package/dist/policies/policies.js.map +1 -0
- package/dist/policies/policy.d.ts +6 -0
- package/dist/policies/policy.d.ts.map +1 -0
- package/dist/policies/policy.js +2 -0
- package/dist/policies/policy.js.map +1 -0
- package/dist/serializer/field-serializer.d.ts +52 -0
- package/dist/serializer/field-serializer.d.ts.map +1 -0
- package/dist/serializer/field-serializer.js +66 -0
- package/dist/serializer/field-serializer.js.map +1 -0
- package/dist/serializer/field-tree-serializer.d.ts +50 -0
- package/dist/serializer/field-tree-serializer.d.ts.map +1 -0
- package/dist/serializer/field-tree-serializer.js +68 -0
- package/dist/serializer/field-tree-serializer.js.map +1 -0
- package/dist/serializer/fields-serializer.d.ts +49 -0
- package/dist/serializer/fields-serializer.d.ts.map +1 -0
- package/dist/serializer/fields-serializer.js +57 -0
- package/dist/serializer/fields-serializer.js.map +1 -0
- package/dist/serializer/index.d.ts +8 -0
- package/dist/serializer/index.d.ts.map +1 -0
- package/dist/serializer/index.js +8 -0
- package/dist/serializer/index.js.map +1 -0
- package/dist/serializer/policies/clamp-max-policy-serializer-handler.d.ts +13 -0
- package/dist/serializer/policies/clamp-max-policy-serializer-handler.d.ts.map +1 -0
- package/dist/serializer/policies/clamp-max-policy-serializer-handler.js +10 -0
- package/dist/serializer/policies/clamp-max-policy-serializer-handler.js.map +1 -0
- package/dist/serializer/policies/clamp-min-policy-serializer-handler.d.ts +13 -0
- package/dist/serializer/policies/clamp-min-policy-serializer-handler.d.ts.map +1 -0
- package/dist/serializer/policies/clamp-min-policy-serializer-handler.js +10 -0
- package/dist/serializer/policies/clamp-min-policy-serializer-handler.js.map +1 -0
- package/dist/serializer/policies/clamp-policy-serializer-handler.d.ts +16 -0
- package/dist/serializer/policies/clamp-policy-serializer-handler.d.ts.map +1 -0
- package/dist/serializer/policies/clamp-policy-serializer-handler.js +10 -0
- package/dist/serializer/policies/clamp-policy-serializer-handler.js.map +1 -0
- package/dist/serializer/policy-serializer.d.ts +41 -0
- package/dist/serializer/policy-serializer.d.ts.map +1 -0
- package/dist/serializer/policy-serializer.js +43 -0
- package/dist/serializer/policy-serializer.js.map +1 -0
- package/dist/setup.d.ts +41 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +57 -0
- package/dist/setup.js.map +1 -0
- package/dist/store.d.ts +137 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +2 -0
- package/dist/store.js.map +1 -0
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -1,1228 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
ClampMaxPolicy: () => ClampMaxPolicy,
|
|
24
|
-
ClampMaxPolicySerializerHandler: () => ClampMaxPolicySerializerHandler,
|
|
25
|
-
ClampMinPolicy: () => ClampMinPolicy,
|
|
26
|
-
ClampMinPolicySerializerHandler: () => ClampMinPolicySerializerHandler,
|
|
27
|
-
ClampPolicy: () => ClampPolicy,
|
|
28
|
-
ClampPolicySerializerHandler: () => ClampPolicySerializerHandler,
|
|
29
|
-
CoreBooleanField: () => CoreBooleanField,
|
|
30
|
-
CoreField: () => CoreField,
|
|
31
|
-
CoreFieldTree: () => CoreFieldTree,
|
|
32
|
-
CoreFields: () => CoreFields,
|
|
33
|
-
CoreFieldsFactory: () => CoreFieldsFactory,
|
|
34
|
-
CoreNumericField: () => CoreNumericField,
|
|
35
|
-
CoreStringField: () => CoreStringField,
|
|
36
|
-
CoreTreeNodeFactory: () => CoreTreeNodeFactory,
|
|
37
|
-
DataStore: () => DataStore,
|
|
38
|
-
FieldRegistry: () => FieldRegistry,
|
|
39
|
-
FieldSerializer: () => FieldSerializer,
|
|
40
|
-
FieldTree: () => FieldTree,
|
|
41
|
-
FieldTreeSerializer: () => FieldTreeSerializer,
|
|
42
|
-
Fields: () => Fields,
|
|
43
|
-
FieldsSerializer: () => FieldsSerializer,
|
|
44
|
-
Policies: () => Policies,
|
|
45
|
-
PolicySerializer: () => PolicySerializer,
|
|
46
|
-
clampMaxPolicy: () => clampMaxPolicy,
|
|
47
|
-
clampMinPolicy: () => clampMinPolicy,
|
|
48
|
-
clampPolicy: () => clampPolicy,
|
|
49
|
-
createCoreFieldRegistry: () => createCoreFieldRegistry,
|
|
50
|
-
createCoreFieldSystem: () => createCoreFieldSystem,
|
|
51
|
-
createCorePolicySerializer: () => createCorePolicySerializer,
|
|
52
|
-
createCoreTreeNodeFactory: () => createCoreTreeNodeFactory,
|
|
53
|
-
createCoreTreeSerializer: () => createCoreTreeSerializer,
|
|
54
|
-
createTypedMethodsMixin: () => createTypedMethodsMixin
|
|
55
|
-
});
|
|
56
|
-
module.exports = __toCommonJS(index_exports);
|
|
57
|
-
|
|
58
|
-
// src/policies/clamp-policy.ts
|
|
59
|
-
var ClampPolicy = class _ClampPolicy {
|
|
60
|
-
constructor(min, max) {
|
|
61
|
-
this.min = min;
|
|
62
|
-
this.max = max;
|
|
63
|
-
}
|
|
64
|
-
static id = "clamp";
|
|
65
|
-
id = _ClampPolicy.id;
|
|
66
|
-
apply(val) {
|
|
67
|
-
return Math.max(this.min, Math.min(this.max, val));
|
|
68
|
-
}
|
|
69
|
-
updateBounds(min, max) {
|
|
70
|
-
this.min = min;
|
|
71
|
-
this.max = max;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
function clampPolicy(min, max) {
|
|
75
|
-
return new ClampPolicy(min, max);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// src/policies/clamp-max-policy.ts
|
|
79
|
-
var ClampMaxPolicy = class _ClampMaxPolicy {
|
|
80
|
-
constructor(max) {
|
|
81
|
-
this.max = max;
|
|
82
|
-
}
|
|
83
|
-
static id = "clampMax";
|
|
84
|
-
id = _ClampMaxPolicy.id;
|
|
85
|
-
apply(val) {
|
|
86
|
-
return Math.min(this.max, val);
|
|
87
|
-
}
|
|
88
|
-
updateBounds(max) {
|
|
89
|
-
this.max = max;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
function clampMaxPolicy(max) {
|
|
93
|
-
return new ClampMaxPolicy(max);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// src/policies/clamp-min-policy.ts
|
|
97
|
-
var ClampMinPolicy = class _ClampMinPolicy {
|
|
98
|
-
constructor(min) {
|
|
99
|
-
this.min = min;
|
|
100
|
-
}
|
|
101
|
-
static id = "clampMin";
|
|
102
|
-
id = _ClampMinPolicy.id;
|
|
103
|
-
apply(val) {
|
|
104
|
-
return Math.max(this.min, val);
|
|
105
|
-
}
|
|
106
|
-
updateBounds(min) {
|
|
107
|
-
this.min = min;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
function clampMinPolicy(min) {
|
|
111
|
-
return new ClampMinPolicy(min);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/policies/policies.ts
|
|
115
|
-
var Policies = class {
|
|
116
|
-
policies = /* @__PURE__ */ new Map();
|
|
117
|
-
get items() {
|
|
118
|
-
return this.policies;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Retrieves a specific policy instance by its ID.
|
|
122
|
-
* Useful for accessing a policy's internal state or methods.
|
|
123
|
-
* @template P The expected type of the policy.
|
|
124
|
-
* @param id The unique ID of the policy to retrieve.
|
|
125
|
-
* @returns The policy instance, or `undefined` if not found.
|
|
126
|
-
*/
|
|
127
|
-
get(id) {
|
|
128
|
-
return this.policies.get(id);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Adds a new policy to the field or replaces an existing one with the same ID.
|
|
132
|
-
* The new policy will be applied on the next `set()` operation.
|
|
133
|
-
* If a policy with the same ID already exists, its `destroy` method will be called before it is replaced.
|
|
134
|
-
* @param policy The policy instance to add.
|
|
135
|
-
*/
|
|
136
|
-
add(policy) {
|
|
137
|
-
const existed = this.policies.get(policy.id);
|
|
138
|
-
existed?.destroy?.();
|
|
139
|
-
this.policies.set(policy.id, policy);
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Removes a policy from the field by its ID and call `destroy` method.
|
|
144
|
-
* @param policyId The unique ID of the policy to remove.
|
|
145
|
-
* @returns `true` if the policy was found and removed, otherwise `false`.
|
|
146
|
-
*/
|
|
147
|
-
remove(policyId) {
|
|
148
|
-
const policyToRemove = this.policies.get(policyId);
|
|
149
|
-
if (!policyToRemove) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
policyToRemove.destroy?.();
|
|
153
|
-
return this.policies.delete(policyId);
|
|
154
|
-
}
|
|
155
|
-
isEmpty() {
|
|
156
|
-
return this.policies.size === 0;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Removes all policies from the field.
|
|
160
|
-
* After this, `set()` will no longer apply any transformations to the value until new policies are added.
|
|
161
|
-
*/
|
|
162
|
-
clear() {
|
|
163
|
-
this.policies.forEach((policy) => policy.destroy?.());
|
|
164
|
-
this.policies.clear();
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Forces the current value to be re-processed by all policies.
|
|
168
|
-
* Useful if a policy's logic has changed and you need to re-evaluate the current state.
|
|
169
|
-
*/
|
|
170
|
-
apply(val) {
|
|
171
|
-
let finalVal = val;
|
|
172
|
-
this.policies.forEach((policy) => finalVal = policy.apply(finalVal));
|
|
173
|
-
return finalVal;
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// src/mixins/mixin-factory.ts
|
|
178
|
-
function createTypedMethodsMixin(typeName, baseMethodName) {
|
|
179
|
-
const methodNames = {
|
|
180
|
-
create: `create${baseMethodName}`,
|
|
181
|
-
upset: `upset${baseMethodName}`,
|
|
182
|
-
get: `get${baseMethodName}`
|
|
183
|
-
};
|
|
184
|
-
return function(Base) {
|
|
185
|
-
return class FieldsWith extends Base {
|
|
186
|
-
// createBoolean, createMySignal, etc.
|
|
187
|
-
[methodNames.create](name, initialValue, options) {
|
|
188
|
-
return this.create(typeName, name, initialValue, options);
|
|
189
|
-
}
|
|
190
|
-
// upsetBoolean, upsetMySignal, etc.
|
|
191
|
-
[methodNames.upset](name, value, options) {
|
|
192
|
-
return this.upset(typeName, name, value, options);
|
|
193
|
-
}
|
|
194
|
-
// getBoolean, getMySignal, etc.
|
|
195
|
-
[methodNames.get](name) {
|
|
196
|
-
return this.get(name);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// src/field-definitions/core-field.ts
|
|
203
|
-
var import_utils = require("@axi-engine/utils");
|
|
204
|
-
var import_dequal = require("dequal");
|
|
205
|
-
var CoreField = class _CoreField {
|
|
206
|
-
/** A type keyword of the field */
|
|
207
|
-
static typeName = "default";
|
|
208
|
-
typeName = _CoreField.typeName;
|
|
209
|
-
/** A unique identifier for the field. */
|
|
210
|
-
_name;
|
|
211
|
-
_value;
|
|
212
|
-
_onChange = new import_utils.Emitter();
|
|
213
|
-
onChange;
|
|
214
|
-
policies = new Policies();
|
|
215
|
-
get name() {
|
|
216
|
-
return this._name;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Gets the current raw value of the field.
|
|
220
|
-
* For reactive updates, it's recommended to use the `.signal` property instead.
|
|
221
|
-
*/
|
|
222
|
-
get value() {
|
|
223
|
-
return this._value;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Sets a new value for the field.
|
|
227
|
-
* The provided value will be processed by all registered policies before the underlying signal is updated.
|
|
228
|
-
* @param val The new value to set.
|
|
229
|
-
*/
|
|
230
|
-
set value(val) {
|
|
231
|
-
const oldVal = this._value;
|
|
232
|
-
const finalVal = this.policies.apply(val);
|
|
233
|
-
if (!(0, import_dequal.dequal)(this._value, finalVal)) {
|
|
234
|
-
this._value = finalVal;
|
|
235
|
-
this._onChange.emit(this._value, oldVal);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Creates an instance of a Field.
|
|
240
|
-
* @param name A unique identifier for the field.
|
|
241
|
-
* @param initialVal The initial value of the field.
|
|
242
|
-
* @param options Optional configuration for the field.
|
|
243
|
-
* @param options.policies An array of policies to apply to the field's value on every `set` operation.
|
|
244
|
-
* @param options.isEqual An function for compare old and new value, by default uses the strictEquals from `utils`
|
|
245
|
-
*
|
|
246
|
-
*/
|
|
247
|
-
constructor(name, initialVal, options) {
|
|
248
|
-
this.onChange = this._onChange;
|
|
249
|
-
this._name = name;
|
|
250
|
-
options?.policies?.forEach((policy) => this.policies.add(policy));
|
|
251
|
-
this.value = initialVal;
|
|
252
|
-
}
|
|
253
|
-
setValueSilently(val) {
|
|
254
|
-
this._value = this.policies.apply(val);
|
|
255
|
-
}
|
|
256
|
-
batchUpdate(updateFn) {
|
|
257
|
-
this.value = updateFn(this.value);
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Cleans up resources used by the field and its policies.
|
|
261
|
-
* This should be called when the field is no longer needed to prevent memory leaks from reactive policies.
|
|
262
|
-
*/
|
|
263
|
-
destroy() {
|
|
264
|
-
this.policies.clear();
|
|
265
|
-
this._onChange.clear();
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
// src/field-definitions/core-boolean-field.ts
|
|
270
|
-
var CoreBooleanField = class _CoreBooleanField extends CoreField {
|
|
271
|
-
static typeName = "boolean";
|
|
272
|
-
typeName = _CoreBooleanField.typeName;
|
|
273
|
-
constructor(name, initialVal, options) {
|
|
274
|
-
super(name, initialVal, options);
|
|
275
|
-
}
|
|
276
|
-
toggle() {
|
|
277
|
-
this.value = !this.value;
|
|
278
|
-
return this.value;
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
// src/field-definitions/core-string-field.ts
|
|
283
|
-
var CoreStringField = class _CoreStringField extends CoreField {
|
|
284
|
-
static typeName = "string";
|
|
285
|
-
typeName = _CoreStringField.typeName;
|
|
286
|
-
constructor(name, initialVal, options) {
|
|
287
|
-
super(name, initialVal, options);
|
|
288
|
-
}
|
|
289
|
-
append(str) {
|
|
290
|
-
this.value = this.value + str;
|
|
291
|
-
return this;
|
|
292
|
-
}
|
|
293
|
-
prepend(str) {
|
|
294
|
-
this.value = str + this.value;
|
|
295
|
-
return this;
|
|
296
|
-
}
|
|
297
|
-
trim() {
|
|
298
|
-
this.value = this.value.trim();
|
|
299
|
-
return this;
|
|
300
|
-
}
|
|
301
|
-
isEmpty() {
|
|
302
|
-
return this.value.length === 0;
|
|
303
|
-
}
|
|
304
|
-
clear() {
|
|
305
|
-
this.value = "";
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
// src/field-definitions/core-numeric-field.ts
|
|
310
|
-
var import_utils2 = require("@axi-engine/utils");
|
|
311
|
-
var CoreNumericField = class _CoreNumericField extends CoreField {
|
|
312
|
-
static typeName = "numeric";
|
|
313
|
-
typeName = _CoreNumericField.typeName;
|
|
314
|
-
get min() {
|
|
315
|
-
const policy = this.policies.get(ClampPolicy.id) ?? this.policies.get(ClampMinPolicy.id);
|
|
316
|
-
return policy?.min;
|
|
317
|
-
}
|
|
318
|
-
get max() {
|
|
319
|
-
const policy = this.policies.get(ClampPolicy.id) ?? this.policies.get(ClampMaxPolicy.id);
|
|
320
|
-
return policy?.max;
|
|
321
|
-
}
|
|
322
|
-
constructor(name, initialVal, options) {
|
|
323
|
-
const policies = options?.policies ?? [];
|
|
324
|
-
if (!(0, import_utils2.isNullOrUndefined)(options?.min) && !(0, import_utils2.isNullOrUndefined)(options?.max)) {
|
|
325
|
-
policies.unshift(clampPolicy(options.min, options.max));
|
|
326
|
-
} else if (!(0, import_utils2.isNullOrUndefined)(options?.min)) {
|
|
327
|
-
policies.unshift(clampMinPolicy(options.min));
|
|
328
|
-
} else if (!(0, import_utils2.isNullOrUndefined)(options?.max)) {
|
|
329
|
-
policies.unshift(clampMaxPolicy(options.max));
|
|
330
|
-
}
|
|
331
|
-
super(name, initialVal, { policies });
|
|
332
|
-
}
|
|
333
|
-
isMin() {
|
|
334
|
-
const min = this.min;
|
|
335
|
-
return (0, import_utils2.isNullOrUndefined)(min) ? false : this.value <= min;
|
|
336
|
-
}
|
|
337
|
-
isMax() {
|
|
338
|
-
const max = this.max;
|
|
339
|
-
return (0, import_utils2.isNullOrUndefined)(max) ? false : this.value >= max;
|
|
340
|
-
}
|
|
341
|
-
inc(amount = 1) {
|
|
342
|
-
this.value = this.value + amount;
|
|
343
|
-
}
|
|
344
|
-
dec(amount = 1) {
|
|
345
|
-
this.value = this.value - amount;
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
// src/field-registry.ts
|
|
350
|
-
var import_utils3 = require("@axi-engine/utils");
|
|
351
|
-
var FieldRegistry = class extends import_utils3.ConstructorRegistry {
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
// src/fields.ts
|
|
355
|
-
var import_utils4 = require("@axi-engine/utils");
|
|
356
|
-
var Fields = class _Fields {
|
|
357
|
-
static typeName = "fields";
|
|
358
|
-
typeName = _Fields.typeName;
|
|
359
|
-
_fields = /* @__PURE__ */ new Map();
|
|
360
|
-
_fieldRegistry;
|
|
361
|
-
/**
|
|
362
|
-
* An event emitter that fires when a new field is added to the collection.
|
|
363
|
-
* @event
|
|
364
|
-
* @param {object} event - The event payload.
|
|
365
|
-
* @param {string} event.name - The name of the added field.
|
|
366
|
-
* @param {Field<any>} event.field - The `Field` instance that was added.
|
|
367
|
-
*/
|
|
368
|
-
onAdd = new import_utils4.Emitter();
|
|
369
|
-
/**
|
|
370
|
-
* An event emitter that fires after one or more fields have been removed.
|
|
371
|
-
* @event
|
|
372
|
-
* @param {object} event - The event payload.
|
|
373
|
-
* @param {string[]} event.names - An array of names of the fields that were successfully removed.
|
|
374
|
-
*/
|
|
375
|
-
onRemove = new import_utils4.Emitter();
|
|
376
|
-
/**
|
|
377
|
-
* Gets the read-only map of all `Field` instances in this container.
|
|
378
|
-
* @returns {Map<string, Field<any>>} The collection of fields.
|
|
379
|
-
*/
|
|
380
|
-
get fields() {
|
|
381
|
-
return this._fields;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Creates an instance of Fields.
|
|
385
|
-
* @param {FieldRegistry} fieldRegistry - The registry used to create new `Field` instances.
|
|
386
|
-
*/
|
|
387
|
-
constructor(fieldRegistry) {
|
|
388
|
-
this._fieldRegistry = fieldRegistry;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Checks if a field with the given name exists in the collection.
|
|
392
|
-
* @param {string} name The name of the field to check.
|
|
393
|
-
* @returns {boolean} `true` if the field exists, otherwise `false`.
|
|
394
|
-
*/
|
|
395
|
-
has(name) {
|
|
396
|
-
return this._fields.has(name);
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Adds a pre-existing `Field` instance to the collection and fires the `onAdd` event.
|
|
400
|
-
* @template T - The specific `Field` type being added.
|
|
401
|
-
* @param {Field<any>} field - The `Field` instance to add.
|
|
402
|
-
* @returns {T} The added `Field` instance, cast to type `T`.
|
|
403
|
-
* @throws If a field with the same name already exists.
|
|
404
|
-
*/
|
|
405
|
-
add(field) {
|
|
406
|
-
(0, import_utils4.throwIf)(this.has(field.name), `Field with name '${field.name}' already exists`);
|
|
407
|
-
this._fields.set(field.name, field);
|
|
408
|
-
this.onAdd.emit({
|
|
409
|
-
name: field.name,
|
|
410
|
-
field
|
|
411
|
-
});
|
|
412
|
-
return field;
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Creates a new `Field` instance of a specified type, adds it to the collection, and returns it.
|
|
416
|
-
* This is the primary factory method for creating fields within this container.
|
|
417
|
-
* @template T - The expected `Field` type to be returned.
|
|
418
|
-
* @param {string} typeName - The registered type name of the field to create (e.g., 'numeric', 'boolean').
|
|
419
|
-
* @param {string} name - The unique name for the new field.
|
|
420
|
-
* @param {*} initialValue - The initial value for the new field.
|
|
421
|
-
* @param {*} [options] - Optional configuration passed to the field's constructor.
|
|
422
|
-
* @returns {T} The newly created `Field` instance.
|
|
423
|
-
*/
|
|
424
|
-
create(typeName, name, initialValue, options) {
|
|
425
|
-
const Ctor = this._fieldRegistry.get(typeName);
|
|
426
|
-
const field = new Ctor(name, initialValue, options);
|
|
427
|
-
this.add(field);
|
|
428
|
-
return field;
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Updates an existing field's value or creates a new one if it doesn't exist.
|
|
432
|
-
* @template T - The expected `Field` type.
|
|
433
|
-
* @param {string} typeName - The type name to use if a new field needs to be created.
|
|
434
|
-
* @param {string} name - The name of the field to update or create.
|
|
435
|
-
* @param {*} value - The new value to set.
|
|
436
|
-
* @param {*} [options] - Optional configuration, used only if a new field is created.
|
|
437
|
-
* @returns {T} The existing or newly created `Field` instance.
|
|
438
|
-
*/
|
|
439
|
-
upset(typeName, name, value, options) {
|
|
440
|
-
if (this.has(name)) {
|
|
441
|
-
const field = this.get(name);
|
|
442
|
-
field.value = value;
|
|
443
|
-
return field;
|
|
444
|
-
}
|
|
445
|
-
return this.create(typeName, name, value, options);
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Retrieves a field by its name.
|
|
449
|
-
* @template TField - The expected `Field` type to be returned.
|
|
450
|
-
* @param {string} name - The name of the field to retrieve.
|
|
451
|
-
* @returns {TField} The `Field` instance.
|
|
452
|
-
* @throws If the field does not exist.
|
|
453
|
-
*/
|
|
454
|
-
get(name) {
|
|
455
|
-
(0, import_utils4.throwIf)(!this._fields.has(name), `Field with name '${name}' not exists`);
|
|
456
|
-
return this._fields.get(name);
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Removes one or more fields from the collection.
|
|
460
|
-
* This method ensures that the `destroy` method of each removed field is called to clean up its resources.
|
|
461
|
-
* @param {string| string[]} names A single name or an array of names to remove.
|
|
462
|
-
*/
|
|
463
|
-
remove(names) {
|
|
464
|
-
const namesToRemove = Array.isArray(names) ? names : [names];
|
|
465
|
-
const reallyRemoved = namesToRemove.filter((name) => {
|
|
466
|
-
const field = this._fields.get(name);
|
|
467
|
-
if (!field) {
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
|
-
field.destroy();
|
|
471
|
-
return this._fields.delete(name);
|
|
472
|
-
});
|
|
473
|
-
if (!reallyRemoved.length) {
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
this.onRemove.emit({ names: reallyRemoved });
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Removes all fields from the collection, ensuring each is properly destroyed.
|
|
480
|
-
*/
|
|
481
|
-
clear() {
|
|
482
|
-
this.remove(Array.from(this._fields.keys()));
|
|
483
|
-
}
|
|
484
|
-
destroy() {
|
|
485
|
-
this.clear();
|
|
486
|
-
this.onAdd.clear();
|
|
487
|
-
this.onRemove.clear();
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
// src/field-tree.ts
|
|
492
|
-
var import_utils5 = require("@axi-engine/utils");
|
|
493
|
-
var FieldTree = class _FieldTree {
|
|
494
|
-
static typeName = "fieldTree";
|
|
495
|
-
typeName = _FieldTree.typeName;
|
|
496
|
-
/** @private The internal map storing child nodes (branches or leaves). */
|
|
497
|
-
_nodes = /* @__PURE__ */ new Map();
|
|
498
|
-
/** @private The factory used to create new child nodes. */
|
|
499
|
-
_factory;
|
|
500
|
-
/**
|
|
501
|
-
* An event emitter that fires immediately after a new node is added to this tree branch.
|
|
502
|
-
* @event
|
|
503
|
-
* @param {object} event - The event payload.
|
|
504
|
-
* @param {string} event.name - The name (key) of the added node.
|
|
505
|
-
* @param event.node - The node instance that was added.
|
|
506
|
-
* @example
|
|
507
|
-
* myTree.onAdd.subscribe(({ name, node }) => {
|
|
508
|
-
* console.log(`Node '${name}' was added.`, node);
|
|
509
|
-
* });
|
|
510
|
-
*/
|
|
511
|
-
onAdd = new import_utils5.Emitter();
|
|
512
|
-
/**
|
|
513
|
-
* An event emitter that fires once after one or more nodes have been successfully removed.
|
|
514
|
-
* @event
|
|
515
|
-
* @param {object} event - The event payload.
|
|
516
|
-
* @param {string[]} event.names - An array of names of the nodes that were removed.
|
|
517
|
-
* @example
|
|
518
|
-
* myTree.onRemove.subscribe(({ names }) => {
|
|
519
|
-
* console.log(`Nodes removed: ${names.join(', ')}`);
|
|
520
|
-
* });
|
|
521
|
-
*/
|
|
522
|
-
onRemove = new import_utils5.Emitter();
|
|
523
|
-
/**
|
|
524
|
-
* Gets the collection of direct child nodes of this tree branch.
|
|
525
|
-
*/
|
|
526
|
-
get nodes() {
|
|
527
|
-
return this._nodes;
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* Creates an instance of FieldTree.
|
|
531
|
-
* @param {FieldTreeFactory} factory - A factory responsible for creating new nodes within the tree.
|
|
532
|
-
*/
|
|
533
|
-
constructor(factory) {
|
|
534
|
-
this._factory = factory;
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* Checks if a direct child node with the given name exists.
|
|
538
|
-
* @param {string} name - The name of the direct child node.
|
|
539
|
-
* @returns {boolean} `true` if the node exists, otherwise `false`.
|
|
540
|
-
*/
|
|
541
|
-
has(name) {
|
|
542
|
-
return this._nodes.has(name);
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Checks if a node exists at a given path, traversing the tree.
|
|
546
|
-
* @param {PathType} path - The path to check (e.g., 'player/stats' or ['player', 'stats']).
|
|
547
|
-
* @returns {boolean} `true` if the entire path resolves to a node, otherwise `false`.
|
|
548
|
-
*/
|
|
549
|
-
hasPath(path) {
|
|
550
|
-
const traversedPath = this.traversePath(path);
|
|
551
|
-
return traversedPath.branch.has(traversedPath.leafName);
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Adds a pre-existing node as a direct child of this tree branch.
|
|
555
|
-
* @param {string} name - The name to assign to the new child node.
|
|
556
|
-
* @param {TreeNode} node - The node instance to add.
|
|
557
|
-
* @returns {TreeNode} The added node.
|
|
558
|
-
* @throws If a node with the same name already exists.
|
|
559
|
-
*/
|
|
560
|
-
addNode(name, node) {
|
|
561
|
-
(0, import_utils5.throwIf)(this.has(name), `Can't add node with name: '${name}', node already exists`);
|
|
562
|
-
this._nodes.set(name, node);
|
|
563
|
-
this.onAdd.emit({ name, node });
|
|
564
|
-
return node;
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Retrieves a direct child node by its name.
|
|
568
|
-
* @param {string} name - The name of the child node.
|
|
569
|
-
* @returns {TreeNode} The retrieved node.
|
|
570
|
-
* @throws If a node with the given name cannot be found.
|
|
571
|
-
*/
|
|
572
|
-
getNode(name) {
|
|
573
|
-
const node = this._nodes.get(name);
|
|
574
|
-
(0, import_utils5.throwIfEmpty)(node, `Can't find node with name '${name}'`);
|
|
575
|
-
return node;
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* Removes one or more nodes from this tree branch.
|
|
579
|
-
*
|
|
580
|
-
* This method first validates that all specified nodes exist. If validation passes,
|
|
581
|
-
* it recursively calls `destroy()` on each node to ensure proper cleanup of the entire subtree.
|
|
582
|
-
* Finally, it emits a single `onRemove` event with the names of all successfully removed nodes.
|
|
583
|
-
*
|
|
584
|
-
* @param {string | string[]} names - A single name or an array of names of the nodes to remove.
|
|
585
|
-
* @throws If any of the specified names do not correspond to an existing node.
|
|
586
|
-
*/
|
|
587
|
-
removeNode(names) {
|
|
588
|
-
const toRemoveNames = Array.isArray(names) ? names : [names];
|
|
589
|
-
toRemoveNames.forEach((name) => {
|
|
590
|
-
(0, import_utils5.throwIf)(!this.has(name), `Can't remove node with name: '${name}', node doesn't exists`);
|
|
591
|
-
});
|
|
592
|
-
toRemoveNames.forEach((name) => {
|
|
593
|
-
this._nodes.get(name).destroy();
|
|
594
|
-
this._nodes.delete(name);
|
|
595
|
-
});
|
|
596
|
-
if (toRemoveNames.length) {
|
|
597
|
-
this.onRemove.emit({ names: toRemoveNames });
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* Creates a new `FieldTree` (branch) node at the specified path.
|
|
602
|
-
* @param {PathType} path - The path where the new `FieldTree` should be created.
|
|
603
|
-
* @param {boolean} [createPath=false] - If `true`, any missing parent branches in the path will be created automatically.
|
|
604
|
-
* @returns {FieldTree} The newly created `FieldTree` instance.
|
|
605
|
-
* @throws If the path is invalid or a node already exists at the target location.
|
|
606
|
-
*/
|
|
607
|
-
createFieldTree(path, createPath) {
|
|
608
|
-
const traversedPath = this.traversePath(path, createPath);
|
|
609
|
-
return traversedPath.branch.addNode(traversedPath.leafName, this._factory.tree());
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* Creates a new `Fields` (leaf) container at the specified path.
|
|
613
|
-
* @param {PathType} path - The path where the new `Fields` container should be created.
|
|
614
|
-
* @param {boolean} [createPath=false] - If `true`, any missing parent branches in the path will be created automatically.
|
|
615
|
-
* @returns {Fields} The newly created `Fields` instance.
|
|
616
|
-
* @throws If the path is invalid or a node already exists at the target location.
|
|
617
|
-
*/
|
|
618
|
-
createFields(path, createPath) {
|
|
619
|
-
const traversedPath = this.traversePath(path, createPath);
|
|
620
|
-
return traversedPath.branch.addNode(traversedPath.leafName, this._factory.fields());
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Retrieves a `FieldTree` (branch) node from a specified path.
|
|
624
|
-
* @param {PathType} path - The path to the `FieldTree` node.
|
|
625
|
-
* @returns {FieldTree} The `FieldTree` instance at the specified path.
|
|
626
|
-
* @throws If the path is invalid or the node at the path is not a `FieldTree`.
|
|
627
|
-
*/
|
|
628
|
-
getFieldTree(path) {
|
|
629
|
-
const traversedPath = this.traversePath(path);
|
|
630
|
-
const node = traversedPath.branch.getNode(traversedPath.leafName);
|
|
631
|
-
(0, import_utils5.throwIf)(
|
|
632
|
-
!(node instanceof _FieldTree),
|
|
633
|
-
`Node with name: ${traversedPath.leafName} by path: '${(0, import_utils5.ensurePathString)(path)}' should be instance of FieldTree`
|
|
634
|
-
);
|
|
635
|
-
return node;
|
|
636
|
-
}
|
|
637
|
-
/**
|
|
638
|
-
* Retrieves a `Fields` (leaf) container from a specified path.
|
|
639
|
-
* @param {PathType} path - The path to the `Fields` container.
|
|
640
|
-
* @returns {Fields} The `Fields` instance at the specified path.
|
|
641
|
-
* @throws If the path is invalid or the node at the path is not a `Fields` container.
|
|
642
|
-
*/
|
|
643
|
-
getFields(path) {
|
|
644
|
-
const traversedPath = this.traversePath(path);
|
|
645
|
-
const node = traversedPath.branch.getNode(traversedPath.leafName);
|
|
646
|
-
(0, import_utils5.throwIf)(
|
|
647
|
-
!(node instanceof Fields),
|
|
648
|
-
`Node with name: ${traversedPath.leafName} by path: '${(0, import_utils5.ensurePathString)(path)}' should be instance of Fields`
|
|
649
|
-
);
|
|
650
|
-
return node;
|
|
651
|
-
}
|
|
652
|
-
/**
|
|
653
|
-
* Retrieves a `FieldTree` at the specified path. If it or any part of the path doesn't exist, it will be created.
|
|
654
|
-
* @param {PathType} path - The path to the `FieldTree` node.
|
|
655
|
-
* @returns {FieldTree} The existing or newly created `FieldTree` instance.
|
|
656
|
-
*/
|
|
657
|
-
getOrCreateFieldTree(path) {
|
|
658
|
-
const traversedPath = this.traversePath(path, true);
|
|
659
|
-
return traversedPath.branch.has(traversedPath.leafName) ? traversedPath.branch.getFieldTree(traversedPath.leafName) : traversedPath.branch.createFieldTree(traversedPath.leafName);
|
|
660
|
-
}
|
|
661
|
-
/**
|
|
662
|
-
* Retrieves a `Fields` container at the specified path. If it or any part of the path doesn't exist, it will be created.
|
|
663
|
-
* @param {PathType} path - The path to the `Fields` container.
|
|
664
|
-
* @returns {Fields} The existing or newly created `Fields` instance.
|
|
665
|
-
*/
|
|
666
|
-
getOrCreateFields(path) {
|
|
667
|
-
const traversedPath = this.traversePath(path, true);
|
|
668
|
-
return traversedPath.branch.has(traversedPath.leafName) ? traversedPath.branch.getFields(traversedPath.leafName) : traversedPath.branch.createFields(traversedPath.leafName);
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Finds the parent node for a given path.
|
|
672
|
-
* @param path The path to the target node.
|
|
673
|
-
* @returns The parent node (either a FieldTree or Fields).
|
|
674
|
-
* @throws An error if the path is invalid or any intermediate node is not a FieldTree.
|
|
675
|
-
*/
|
|
676
|
-
findParentNode(path) {
|
|
677
|
-
const info = this.traversePath(path);
|
|
678
|
-
return info.branch;
|
|
679
|
-
}
|
|
680
|
-
/**
|
|
681
|
-
* Removes all child nodes from this tree branch.
|
|
682
|
-
* This method ensures that `destroy()` is called on each child node, allowing for
|
|
683
|
-
* a full, recursive cleanup of the entire subtree.
|
|
684
|
-
*/
|
|
685
|
-
clear() {
|
|
686
|
-
this.removeNode(Array.from(this._nodes.keys()));
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* Performs a complete cleanup of this node and its entire subtree.
|
|
690
|
-
*
|
|
691
|
-
* It recursively destroys all child nodes by calling `clear()` and then
|
|
692
|
-
* unsubscribes all listeners from its own event emitters.
|
|
693
|
-
* This method should be called when a node is no longer needed.
|
|
694
|
-
*/
|
|
695
|
-
destroy() {
|
|
696
|
-
this.clear();
|
|
697
|
-
this.onAdd.clear();
|
|
698
|
-
this.onRemove.clear();
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* @private
|
|
702
|
-
* Navigates the tree to the parent of a target node.
|
|
703
|
-
* This is the core traversal logic for all path-based operations.
|
|
704
|
-
* @param {PathType} path - The full path to the target node.
|
|
705
|
-
* @param {boolean} [createPath=false] - If `true`, creates missing `FieldTree` branches along the path.
|
|
706
|
-
* @returns {{branch: FieldTree, leafName: string}} An object containing the final branch (parent node) and the name of the leaf (target node).
|
|
707
|
-
* @throws If the path is empty, invalid, or contains a `Fields` container as an intermediate segment.
|
|
708
|
-
*/
|
|
709
|
-
traversePath(path, createPath) {
|
|
710
|
-
const pathArr = (0, import_utils5.ensurePathArray)(path);
|
|
711
|
-
(0, import_utils5.throwIfEmpty)(pathArr, "The path is empty");
|
|
712
|
-
const leafName = pathArr.pop();
|
|
713
|
-
let currentNode = this;
|
|
714
|
-
for (const pathPart of pathArr) {
|
|
715
|
-
let node;
|
|
716
|
-
if (currentNode.has(pathPart)) {
|
|
717
|
-
node = currentNode.getNode(pathPart);
|
|
718
|
-
} else {
|
|
719
|
-
if (createPath) {
|
|
720
|
-
node = currentNode.createFieldTree(pathPart);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
(0, import_utils5.throwIfEmpty)(node, `Can't find node with name ${pathPart} by path parsing: ${(0, import_utils5.ensurePathString)(path)}`);
|
|
724
|
-
(0, import_utils5.throwIf)(node instanceof Fields, `Node with name ${pathPart} should be instance of FieldTree`);
|
|
725
|
-
currentNode = node;
|
|
726
|
-
}
|
|
727
|
-
return { branch: currentNode, leafName };
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
|
|
731
|
-
// src/mixins/with-boolean-fields.mixin.ts
|
|
732
|
-
var WithBooleanFields = createTypedMethodsMixin(CoreBooleanField.typeName, "Boolean");
|
|
733
|
-
|
|
734
|
-
// src/mixins/with-string-fields.mixin.ts
|
|
735
|
-
var WithStringFields = createTypedMethodsMixin(CoreBooleanField.typeName, "String");
|
|
736
|
-
|
|
737
|
-
// src/mixins/with-numeric-fields.mixin.ts
|
|
738
|
-
var WithNumericFields = createTypedMethodsMixin(CoreBooleanField.typeName, "Numeric");
|
|
739
|
-
|
|
740
|
-
// src/mixins/with-default-generic-fields.mixin.ts
|
|
741
|
-
function WithDefaultGenericFields(Base) {
|
|
742
|
-
return class FieldsWithDefaultGeneric extends Base {
|
|
743
|
-
createGeneric(name, initialValue, options) {
|
|
744
|
-
return this.create(CoreField.typeName, name, initialValue, options);
|
|
745
|
-
}
|
|
746
|
-
upsetGeneric(name, value, options) {
|
|
747
|
-
return this.upset(CoreField.typeName, name, value, options);
|
|
748
|
-
}
|
|
749
|
-
getGeneric(name) {
|
|
750
|
-
return this.get(name);
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
// src/core-fields.ts
|
|
756
|
-
var CoreFields = class extends WithBooleanFields(WithStringFields(WithNumericFields(WithDefaultGenericFields(Fields)))) {
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
// src/core-fields-factory.ts
|
|
760
|
-
var CoreFieldsFactory = class {
|
|
761
|
-
_fieldRegistry;
|
|
762
|
-
get fieldRegistry() {
|
|
763
|
-
return this._fieldRegistry;
|
|
764
|
-
}
|
|
765
|
-
constructor(fieldRegistry) {
|
|
766
|
-
this._fieldRegistry = fieldRegistry;
|
|
767
|
-
}
|
|
768
|
-
fields() {
|
|
769
|
-
return new CoreFields(this._fieldRegistry);
|
|
770
|
-
}
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
// src/core-field-tree.ts
|
|
774
|
-
var CoreFieldTree = class extends FieldTree {
|
|
775
|
-
};
|
|
776
|
-
|
|
777
|
-
// src/core-field-tree-factory.ts
|
|
778
|
-
var CoreTreeNodeFactory = class extends CoreFieldsFactory {
|
|
779
|
-
constructor(fieldRegistry) {
|
|
780
|
-
super(fieldRegistry);
|
|
781
|
-
}
|
|
782
|
-
tree() {
|
|
783
|
-
return new CoreFieldTree(this);
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
|
|
787
|
-
// src/serializer/policies/clamp-policy-serializer-handler.ts
|
|
788
|
-
var ClampPolicySerializerHandler = class {
|
|
789
|
-
snapshot(policy) {
|
|
790
|
-
return { min: policy.min, max: policy.max };
|
|
791
|
-
}
|
|
792
|
-
hydrate(data) {
|
|
793
|
-
return new ClampPolicy(data.min, data.max);
|
|
794
|
-
}
|
|
795
|
-
};
|
|
796
|
-
|
|
797
|
-
// src/serializer/policies/clamp-max-policy-serializer-handler.ts
|
|
798
|
-
var ClampMaxPolicySerializerHandler = class {
|
|
799
|
-
snapshot(policy) {
|
|
800
|
-
return { max: policy.max };
|
|
801
|
-
}
|
|
802
|
-
hydrate(data) {
|
|
803
|
-
return new ClampMaxPolicy(data.max);
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
|
|
807
|
-
// src/serializer/policies/clamp-min-policy-serializer-handler.ts
|
|
808
|
-
var ClampMinPolicySerializerHandler = class {
|
|
809
|
-
snapshot(policy) {
|
|
810
|
-
return { min: policy.min };
|
|
811
|
-
}
|
|
812
|
-
hydrate(data) {
|
|
813
|
-
return new ClampMinPolicy(data.min);
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
// src/serializer/policy-serializer.ts
|
|
818
|
-
var import_utils6 = require("@axi-engine/utils");
|
|
819
|
-
var PolicySerializer = class {
|
|
820
|
-
handlers = /* @__PURE__ */ new Map();
|
|
821
|
-
register(policyId, handler) {
|
|
822
|
-
(0, import_utils6.throwIf)(this.handlers.has(policyId), `A handler for policy ID '${policyId}' is already registered.`);
|
|
823
|
-
this.handlers.set(policyId, handler);
|
|
824
|
-
return this;
|
|
825
|
-
}
|
|
826
|
-
clearHandlers() {
|
|
827
|
-
this.handlers.clear();
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* Creates a serializable snapshot of a policy instance.
|
|
831
|
-
* The snapshot includes the policy's state and a `__type` identifier.
|
|
832
|
-
* @param policy The policy instance to snapshot.
|
|
833
|
-
* @returns A plain object ready for JSON serialization.
|
|
834
|
-
* @throws If no handler is registered for the policy's ID.
|
|
835
|
-
*/
|
|
836
|
-
snapshot(policy) {
|
|
837
|
-
const handler = this.handlers.get(policy.id);
|
|
838
|
-
(0, import_utils6.throwIfEmpty)(handler, `No serializer handler registered for policy ID: '${policy.id}'`);
|
|
839
|
-
const data = handler.snapshot(policy);
|
|
840
|
-
return {
|
|
841
|
-
__type: policy.id,
|
|
842
|
-
...data
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Restores a policy instance from its snapshot representation.
|
|
847
|
-
* @param snapshot The plain object snapshot, which must contain a `__type` property.
|
|
848
|
-
* @returns A new, fully functional policy instance.
|
|
849
|
-
* @throws If the snapshot is invalid or no handler is registered for its `__type`.
|
|
850
|
-
*/
|
|
851
|
-
hydrate(snapshot) {
|
|
852
|
-
const typeId = snapshot?.__type;
|
|
853
|
-
(0, import_utils6.throwIfEmpty)(typeId, 'Invalid policy snapshot: missing "__type" identifier.');
|
|
854
|
-
const handler = this.handlers.get(typeId);
|
|
855
|
-
(0, import_utils6.throwIfEmpty)(handler, `No serializer handler registered for policy ID: '${typeId}'`);
|
|
856
|
-
const { __type, ...data } = snapshot;
|
|
857
|
-
return handler.hydrate(data);
|
|
858
|
-
}
|
|
859
|
-
};
|
|
860
|
-
|
|
861
|
-
// src/serializer/field-serializer.ts
|
|
862
|
-
var import_utils7 = require("@axi-engine/utils");
|
|
863
|
-
var FieldSerializer = class {
|
|
864
|
-
/**
|
|
865
|
-
* Creates an instance of FieldSerializer.
|
|
866
|
-
* @param {FieldRegistry} fieldRegistry - A registry that maps string type names to Field constructors.
|
|
867
|
-
* @param {PolicySerializer} policySerializer - A serializer dedicated to handling Policy instances.
|
|
868
|
-
*/
|
|
869
|
-
constructor(fieldRegistry, policySerializer) {
|
|
870
|
-
this.fieldRegistry = fieldRegistry;
|
|
871
|
-
this.policySerializer = policySerializer;
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* Creates a serializable snapshot of a Field instance.
|
|
875
|
-
* The snapshot includes the field's type, name, current value, and the state of all its policies.
|
|
876
|
-
* @param {Field<any>} field - The Field instance to serialize.
|
|
877
|
-
* @returns {FieldSnapshot} A plain object ready for JSON serialization.
|
|
878
|
-
*/
|
|
879
|
-
snapshot(field) {
|
|
880
|
-
let snapshot = {
|
|
881
|
-
__type: field.typeName,
|
|
882
|
-
name: field.name,
|
|
883
|
-
value: field.value
|
|
884
|
-
};
|
|
885
|
-
if (!field.policies.isEmpty()) {
|
|
886
|
-
const serializedPolicies = [];
|
|
887
|
-
field.policies.items.forEach((policy) => serializedPolicies.push(this.policySerializer.snapshot(policy)));
|
|
888
|
-
snapshot.policies = serializedPolicies;
|
|
889
|
-
}
|
|
890
|
-
return snapshot;
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* Restores a Field instance from its snapshot representation.
|
|
894
|
-
* It uses the `__type` property to find the correct constructor and hydrates
|
|
895
|
-
* the field with its value and all its policies.
|
|
896
|
-
* @param {FieldSnapshot} snapshot - The plain object snapshot to deserialize.
|
|
897
|
-
* @returns {Field<any>} A new, fully functional Field instance.
|
|
898
|
-
* @throws If the snapshot is invalid, missing a `__type`, or if the type is not registered.
|
|
899
|
-
*/
|
|
900
|
-
hydrate(snapshot) {
|
|
901
|
-
const fieldType = snapshot.__type;
|
|
902
|
-
(0, import_utils7.throwIfEmpty)(fieldType, 'Invalid field snapshot: missing "__type" identifier.');
|
|
903
|
-
const Ctor = this.fieldRegistry.get(fieldType);
|
|
904
|
-
let policies;
|
|
905
|
-
if (!(0, import_utils7.isNullOrUndefined)(snapshot.policies)) {
|
|
906
|
-
policies = [];
|
|
907
|
-
snapshot.policies.forEach((p) => policies.push(this.policySerializer.hydrate(p)));
|
|
908
|
-
}
|
|
909
|
-
return new Ctor(snapshot.name, snapshot.value, { policies });
|
|
910
|
-
}
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
// src/serializer/fields-serializer.ts
|
|
914
|
-
var FieldsSerializer = class {
|
|
915
|
-
/**
|
|
916
|
-
* Creates an instance of FieldsSerializer.
|
|
917
|
-
* @param {FieldsFactory} fieldsFactory - A registry that maps string type names to Field constructors.
|
|
918
|
-
* @param {FieldSerializer} fieldSerializer - A serializer of field instances.
|
|
919
|
-
*/
|
|
920
|
-
constructor(fieldsFactory, fieldSerializer) {
|
|
921
|
-
this.fieldsFactory = fieldsFactory;
|
|
922
|
-
this.fieldSerializer = fieldSerializer;
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* Creates a serializable snapshot of a `Fields` container.
|
|
926
|
-
*
|
|
927
|
-
* The snapshot includes a `__type` identifier (currently hardcoded) and an array of snapshots
|
|
928
|
-
* for each `Field` within the container.
|
|
929
|
-
* @param {Fields} fields - The `Fields` instance to serialize.
|
|
930
|
-
* @returns {FieldsSnapshot} A plain object ready for JSON serialization.
|
|
931
|
-
*/
|
|
932
|
-
snapshot(fields) {
|
|
933
|
-
const res = {
|
|
934
|
-
__type: fields.typeName
|
|
935
|
-
};
|
|
936
|
-
fields.fields.forEach((field) => res[field.name] = this.fieldSerializer.snapshot(field));
|
|
937
|
-
return res;
|
|
938
|
-
}
|
|
939
|
-
/**
|
|
940
|
-
* Restores a `Fields` container instance from its snapshot representation.
|
|
941
|
-
*
|
|
942
|
-
* It iterates through the field snapshots and hydrates them individually, adding them to the new container.
|
|
943
|
-
* @param {FieldsSnapshot} snapshot - The plain object snapshot to deserialize.
|
|
944
|
-
* @returns {Fields} A new `DefaultFields` instance populated with the restored fields.
|
|
945
|
-
*/
|
|
946
|
-
hydrate(snapshot) {
|
|
947
|
-
const { __type, ...fieldsData } = snapshot;
|
|
948
|
-
const fields = this.fieldsFactory.fields();
|
|
949
|
-
for (const fieldName in fieldsData) {
|
|
950
|
-
const fieldSnapshot = fieldsData[fieldName];
|
|
951
|
-
const restoredField = this.fieldSerializer.hydrate(fieldSnapshot);
|
|
952
|
-
fields.add(restoredField);
|
|
953
|
-
}
|
|
954
|
-
return fields;
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
// src/serializer/field-tree-serializer.ts
|
|
959
|
-
var import_utils8 = require("@axi-engine/utils");
|
|
960
|
-
var FieldTreeSerializer = class {
|
|
961
|
-
constructor(fieldTreeNodeFactory, fieldsSerializer) {
|
|
962
|
-
this.fieldTreeNodeFactory = fieldTreeNodeFactory;
|
|
963
|
-
this.fieldsSerializer = fieldsSerializer;
|
|
964
|
-
}
|
|
965
|
-
/**
|
|
966
|
-
* Creates a serializable snapshot of the entire tree and its contained fields.
|
|
967
|
-
* @returns A plain JavaScript object representing the complete state managed by this tree.
|
|
968
|
-
*/
|
|
969
|
-
snapshot(tree) {
|
|
970
|
-
const res = {
|
|
971
|
-
__type: tree.typeName
|
|
972
|
-
};
|
|
973
|
-
tree.nodes.forEach((node, key) => {
|
|
974
|
-
if (node.typeName === tree.typeName) {
|
|
975
|
-
res[key] = this.snapshot(node);
|
|
976
|
-
} else if (node.typeName === Fields.typeName) {
|
|
977
|
-
res[key] = this.fieldsSerializer.snapshot(node);
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
return res;
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Restores the state of the tree from a snapshot.
|
|
984
|
-
* It intelligently creates missing nodes based on `__type` metadata and delegates hydration to child nodes.
|
|
985
|
-
* @param snapshot The snapshot object to load.
|
|
986
|
-
*/
|
|
987
|
-
hydrate(snapshot) {
|
|
988
|
-
const { __type, ...nodes } = snapshot;
|
|
989
|
-
const tree = this.fieldTreeNodeFactory.tree();
|
|
990
|
-
for (const key in nodes) {
|
|
991
|
-
const nodeData = nodes[key];
|
|
992
|
-
if ((0, import_utils8.isString)(nodeData)) {
|
|
993
|
-
continue;
|
|
994
|
-
}
|
|
995
|
-
if (nodeData.__type === FieldTree.typeName) {
|
|
996
|
-
tree.addNode(key, this.hydrate(nodeData));
|
|
997
|
-
} else if (nodeData.__type === Fields.typeName) {
|
|
998
|
-
tree.addNode(key, this.fieldsSerializer.hydrate(nodeData));
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
return tree;
|
|
1002
|
-
}
|
|
1003
|
-
};
|
|
1004
|
-
|
|
1005
|
-
// src/data-store-field-resolver.ts
|
|
1006
|
-
var import_utils9 = require("@axi-engine/utils");
|
|
1007
|
-
var NumericFieldResolver = class {
|
|
1008
|
-
typeName = CoreNumericField.typeName;
|
|
1009
|
-
supports(value) {
|
|
1010
|
-
return (0, import_utils9.isNumber)(value);
|
|
1011
|
-
}
|
|
1012
|
-
};
|
|
1013
|
-
var BooleanFieldResolver = class {
|
|
1014
|
-
typeName = CoreBooleanField.typeName;
|
|
1015
|
-
supports(value) {
|
|
1016
|
-
return (0, import_utils9.isBoolean)(value);
|
|
1017
|
-
}
|
|
1018
|
-
};
|
|
1019
|
-
var StringFieldResolver = class {
|
|
1020
|
-
typeName = CoreStringField.typeName;
|
|
1021
|
-
supports(value) {
|
|
1022
|
-
return (0, import_utils9.isString)(value);
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
|
|
1026
|
-
// src/data-store.ts
|
|
1027
|
-
var import_utils10 = require("@axi-engine/utils");
|
|
1028
|
-
var DataStore = class {
|
|
1029
|
-
constructor(tree) {
|
|
1030
|
-
this.tree = tree;
|
|
1031
|
-
this.registerResolver(new NumericFieldResolver());
|
|
1032
|
-
this.registerResolver(new BooleanFieldResolver());
|
|
1033
|
-
this.registerResolver(new StringFieldResolver());
|
|
1034
|
-
}
|
|
1035
|
-
resolvers = [];
|
|
1036
|
-
rootFieldsName = "__root_fields";
|
|
1037
|
-
_rootFields;
|
|
1038
|
-
get rootFields() {
|
|
1039
|
-
if (!this._rootFields) {
|
|
1040
|
-
this._rootFields = this.tree.getOrCreateFields(this.rootFieldsName);
|
|
1041
|
-
}
|
|
1042
|
-
return this._rootFields;
|
|
1043
|
-
}
|
|
1044
|
-
registerResolver(resolver) {
|
|
1045
|
-
this.resolvers.unshift(resolver);
|
|
1046
|
-
}
|
|
1047
|
-
clearResolvers() {
|
|
1048
|
-
this.resolvers.length = 0;
|
|
1049
|
-
}
|
|
1050
|
-
getValue(path) {
|
|
1051
|
-
return this.getField(path).value;
|
|
1052
|
-
}
|
|
1053
|
-
setValue(path, val) {
|
|
1054
|
-
const field = this.getField(path);
|
|
1055
|
-
field.value = val;
|
|
1056
|
-
return field.value;
|
|
1057
|
-
}
|
|
1058
|
-
createValue(path, val, options) {
|
|
1059
|
-
const dest = this.getDestinationFields(path);
|
|
1060
|
-
if (options?.fieldType) {
|
|
1061
|
-
return dest.fields.create(options.fieldType, dest.leafName, val, options).value;
|
|
1062
|
-
}
|
|
1063
|
-
for (let resolver of this.resolvers) {
|
|
1064
|
-
if (resolver.supports(val)) {
|
|
1065
|
-
return dest.fields.create(resolver.typeName, dest.leafName, val, options).value;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
return dest.fields.createGeneric(dest.leafName, val, options).value;
|
|
1069
|
-
}
|
|
1070
|
-
upsetValue(path, val, options) {
|
|
1071
|
-
const dest = this.getDestinationFields(path);
|
|
1072
|
-
if (options?.fieldType) {
|
|
1073
|
-
return dest.fields.upset(options.fieldType, dest.leafName, val, options).value;
|
|
1074
|
-
}
|
|
1075
|
-
for (let resolver of this.resolvers) {
|
|
1076
|
-
if (resolver.supports(val)) {
|
|
1077
|
-
return dest.fields.upset(resolver.typeName, dest.leafName, val, options).value;
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
return dest.fields.upsetGeneric(dest.leafName, val, options).value;
|
|
1081
|
-
}
|
|
1082
|
-
createBoolean(path, initialValue, options) {
|
|
1083
|
-
const dest = this.getDestinationFields(path);
|
|
1084
|
-
return dest.fields.createBoolean(dest.leafName, initialValue, options);
|
|
1085
|
-
}
|
|
1086
|
-
createNumeric(path, initialValue, options) {
|
|
1087
|
-
const dest = this.getDestinationFields(path);
|
|
1088
|
-
return dest.fields.createNumeric(dest.leafName, initialValue, options);
|
|
1089
|
-
}
|
|
1090
|
-
createString(path, initialValue, options) {
|
|
1091
|
-
const dest = this.getDestinationFields(path);
|
|
1092
|
-
return dest.fields.createString(dest.leafName, initialValue, options);
|
|
1093
|
-
}
|
|
1094
|
-
createGeneric(path, initialValue, options) {
|
|
1095
|
-
const dest = this.getDestinationFields(path);
|
|
1096
|
-
return dest.fields.createGeneric(dest.leafName, initialValue, options);
|
|
1097
|
-
}
|
|
1098
|
-
getBoolean(path) {
|
|
1099
|
-
return this.getField(path);
|
|
1100
|
-
}
|
|
1101
|
-
getNumeric(path) {
|
|
1102
|
-
return this.getField(path);
|
|
1103
|
-
}
|
|
1104
|
-
getString(path) {
|
|
1105
|
-
return this.getField(path);
|
|
1106
|
-
}
|
|
1107
|
-
getGeneric(path) {
|
|
1108
|
-
return this.getField(path);
|
|
1109
|
-
}
|
|
1110
|
-
getField(path) {
|
|
1111
|
-
const pathArr = (0, import_utils10.ensurePathArray)(path);
|
|
1112
|
-
(0, import_utils10.throwIfEmpty)(pathArr, `Wrong path or path is empty: ${(0, import_utils10.ensurePathString)(path)}, should contain at least one path segment`);
|
|
1113
|
-
if (this.isPathToRootFields(pathArr)) {
|
|
1114
|
-
return this.rootFields.get(pathArr[0]);
|
|
1115
|
-
}
|
|
1116
|
-
const fieldName = pathArr.pop();
|
|
1117
|
-
const fields = this.tree.getFields(pathArr);
|
|
1118
|
-
return fields.get(fieldName);
|
|
1119
|
-
}
|
|
1120
|
-
createFields(path) {
|
|
1121
|
-
return this.tree.createFields(path, true);
|
|
1122
|
-
}
|
|
1123
|
-
createTree(path) {
|
|
1124
|
-
return this.tree.createFieldTree(path, true);
|
|
1125
|
-
}
|
|
1126
|
-
getFields(path) {
|
|
1127
|
-
return this.tree.getFields(path);
|
|
1128
|
-
}
|
|
1129
|
-
getTree(path) {
|
|
1130
|
-
return this.tree.getFieldTree(path);
|
|
1131
|
-
}
|
|
1132
|
-
remove(path) {
|
|
1133
|
-
const pathArr = (0, import_utils10.ensurePathArray)(path);
|
|
1134
|
-
(0, import_utils10.throwIfEmpty)(pathArr, `Wrong path or path is empty: ${(0, import_utils10.ensurePathString)(path)}, should contain at least one path segment`);
|
|
1135
|
-
if (this.isPathToRootFields(pathArr)) {
|
|
1136
|
-
this.rootFields.remove(pathArr);
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
const node = this.tree.findParentNode(pathArr);
|
|
1140
|
-
const leafName = pathArr[pathArr.length - 1];
|
|
1141
|
-
if (node instanceof CoreFields) {
|
|
1142
|
-
node.remove(leafName);
|
|
1143
|
-
} else if (node instanceof CoreFieldTree) {
|
|
1144
|
-
node.removeNode(leafName);
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
isPathToRootFields(path) {
|
|
1148
|
-
return (0, import_utils10.ensurePathArray)(path).length === 1;
|
|
1149
|
-
}
|
|
1150
|
-
getDestinationFields(path) {
|
|
1151
|
-
const pathArr = (0, import_utils10.ensurePathArray)(path);
|
|
1152
|
-
if (this.isPathToRootFields(pathArr)) {
|
|
1153
|
-
return { fields: this.rootFields, leafName: pathArr[0] };
|
|
1154
|
-
}
|
|
1155
|
-
const leafName = pathArr.pop();
|
|
1156
|
-
return { fields: this.tree.getOrCreateFields(path), leafName };
|
|
1157
|
-
}
|
|
1158
|
-
};
|
|
1159
|
-
|
|
1160
|
-
// src/setup.ts
|
|
1161
|
-
function createCoreFieldRegistry() {
|
|
1162
|
-
const fieldRegistry = new FieldRegistry();
|
|
1163
|
-
fieldRegistry.register(CoreField.typeName, CoreField);
|
|
1164
|
-
fieldRegistry.register(CoreNumericField.typeName, CoreNumericField);
|
|
1165
|
-
fieldRegistry.register(CoreStringField.typeName, CoreStringField);
|
|
1166
|
-
fieldRegistry.register(CoreBooleanField.typeName, CoreBooleanField);
|
|
1167
|
-
return fieldRegistry;
|
|
1168
|
-
}
|
|
1169
|
-
function createCorePolicySerializer() {
|
|
1170
|
-
const policySerializer = new PolicySerializer();
|
|
1171
|
-
policySerializer.register(ClampPolicy.id, new ClampPolicySerializerHandler());
|
|
1172
|
-
policySerializer.register(ClampMinPolicy.id, new ClampMinPolicySerializerHandler());
|
|
1173
|
-
policySerializer.register(ClampMaxPolicy.id, new ClampMaxPolicySerializerHandler());
|
|
1174
|
-
return policySerializer;
|
|
1175
|
-
}
|
|
1176
|
-
function createCoreTreeNodeFactory(fieldRegistry) {
|
|
1177
|
-
return new CoreTreeNodeFactory(fieldRegistry);
|
|
1178
|
-
}
|
|
1179
|
-
function createCoreTreeSerializer(fieldTreeNodeFactory, policySerializer) {
|
|
1180
|
-
return new FieldTreeSerializer(
|
|
1181
|
-
fieldTreeNodeFactory,
|
|
1182
|
-
new FieldsSerializer(
|
|
1183
|
-
fieldTreeNodeFactory,
|
|
1184
|
-
new FieldSerializer(fieldTreeNodeFactory.fieldRegistry, policySerializer ?? createCorePolicySerializer())
|
|
1185
|
-
)
|
|
1186
|
-
);
|
|
1187
|
-
}
|
|
1188
|
-
function createCoreFieldSystem(config) {
|
|
1189
|
-
const registry = config?.registry ?? createCoreFieldRegistry();
|
|
1190
|
-
const factory = createCoreTreeNodeFactory(registry);
|
|
1191
|
-
const serializer = createCoreTreeSerializer(factory, config?.policySerializer);
|
|
1192
|
-
return { factory, serializer };
|
|
1193
|
-
}
|
|
1194
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1195
|
-
0 && (module.exports = {
|
|
1196
|
-
ClampMaxPolicy,
|
|
1197
|
-
ClampMaxPolicySerializerHandler,
|
|
1198
|
-
ClampMinPolicy,
|
|
1199
|
-
ClampMinPolicySerializerHandler,
|
|
1200
|
-
ClampPolicy,
|
|
1201
|
-
ClampPolicySerializerHandler,
|
|
1202
|
-
CoreBooleanField,
|
|
1203
|
-
CoreField,
|
|
1204
|
-
CoreFieldTree,
|
|
1205
|
-
CoreFields,
|
|
1206
|
-
CoreFieldsFactory,
|
|
1207
|
-
CoreNumericField,
|
|
1208
|
-
CoreStringField,
|
|
1209
|
-
CoreTreeNodeFactory,
|
|
1210
|
-
DataStore,
|
|
1211
|
-
FieldRegistry,
|
|
1212
|
-
FieldSerializer,
|
|
1213
|
-
FieldTree,
|
|
1214
|
-
FieldTreeSerializer,
|
|
1215
|
-
Fields,
|
|
1216
|
-
FieldsSerializer,
|
|
1217
|
-
Policies,
|
|
1218
|
-
PolicySerializer,
|
|
1219
|
-
clampMaxPolicy,
|
|
1220
|
-
clampMinPolicy,
|
|
1221
|
-
clampPolicy,
|
|
1222
|
-
createCoreFieldRegistry,
|
|
1223
|
-
createCoreFieldSystem,
|
|
1224
|
-
createCorePolicySerializer,
|
|
1225
|
-
createCoreTreeNodeFactory,
|
|
1226
|
-
createCoreTreeSerializer,
|
|
1227
|
-
createTypedMethodsMixin
|
|
1228
|
-
});
|
|
1
|
+
export * from './policies/index';
|
|
2
|
+
export * from './mixins/mixin-factory';
|
|
3
|
+
export * from './field';
|
|
4
|
+
export * from './field-definitions';
|
|
5
|
+
export * from './field-registry';
|
|
6
|
+
export * from './fields';
|
|
7
|
+
export * from './field-tree';
|
|
8
|
+
export * from './fields-factory';
|
|
9
|
+
export * from './field-tree-factory';
|
|
10
|
+
export * from './core-fields';
|
|
11
|
+
export * from './core-fields-factory';
|
|
12
|
+
export * from './core-field-tree';
|
|
13
|
+
export * from './core-field-tree-factory';
|
|
14
|
+
export * from './serializer/index';
|
|
15
|
+
export * from './store';
|
|
16
|
+
export * from './data-store';
|
|
17
|
+
export * from './setup';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|