@axi-engine/fields 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/index.cjs +1232 -0
- package/dist/index.d.cts +1018 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +798 -816
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1116 -1128
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -39
- package/dist/index.d.ts +0 -1036
- package/dist/index.js +0 -1272
package/dist/index.d.mts
CHANGED
|
@@ -1,80 +1,86 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Constructor,
|
|
1
|
+
import * as _axi_engine_utils0 from "@axi-engine/utils";
|
|
2
|
+
import { Constructor, ConstructorRegistry, Emitter, PathType, Subscribable } from "@axi-engine/utils";
|
|
3
3
|
|
|
4
|
+
//#region src/policies/policy.d.ts
|
|
4
5
|
interface Policy<T> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
readonly id: string;
|
|
7
|
+
apply: (val: T) => T;
|
|
8
|
+
destroy?: () => void;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/policies/clamp-policy.d.ts
|
|
10
12
|
declare class ClampPolicy implements Policy<number> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
static readonly id = "clamp";
|
|
16
|
+
readonly id = "clamp";
|
|
17
|
+
constructor(min: number, max: number);
|
|
18
|
+
apply(val: number): number;
|
|
19
|
+
updateBounds(min: number, max: number): void;
|
|
18
20
|
}
|
|
19
21
|
declare function clampPolicy(min: number, max: number): ClampPolicy;
|
|
20
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/policies/clamp-max-policy.d.ts
|
|
21
24
|
declare class ClampMaxPolicy implements Policy<number> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
max: number;
|
|
26
|
+
static readonly id = "clampMax";
|
|
27
|
+
readonly id = "clampMax";
|
|
28
|
+
constructor(max: number);
|
|
29
|
+
apply(val: number): number;
|
|
30
|
+
updateBounds(max: number): void;
|
|
28
31
|
}
|
|
29
32
|
declare function clampMaxPolicy(max: number): ClampMaxPolicy;
|
|
30
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/policies/clamp-min-policy.d.ts
|
|
31
35
|
declare class ClampMinPolicy implements Policy<number> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
min: number;
|
|
37
|
+
static readonly id = "clampMin";
|
|
38
|
+
readonly id = "clampMin";
|
|
39
|
+
constructor(min: number);
|
|
40
|
+
apply(val: number): number;
|
|
41
|
+
updateBounds(min: number): void;
|
|
38
42
|
}
|
|
39
43
|
declare function clampMinPolicy(min: number): ClampMinPolicy;
|
|
40
|
-
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/policies/policies.d.ts
|
|
41
46
|
declare class Policies<T> {
|
|
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
|
-
|
|
47
|
+
private readonly policies;
|
|
48
|
+
get items(): Map<string, Policy<T>>;
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves a specific policy instance by its ID.
|
|
51
|
+
* Useful for accessing a policy's internal state or methods.
|
|
52
|
+
* @template P The expected type of the policy.
|
|
53
|
+
* @param id The unique ID of the policy to retrieve.
|
|
54
|
+
* @returns The policy instance, or `undefined` if not found.
|
|
55
|
+
*/
|
|
56
|
+
get<P extends Policy<T>>(id: string): P | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Adds a new policy to the field or replaces an existing one with the same ID.
|
|
59
|
+
* The new policy will be applied on the next `set()` operation.
|
|
60
|
+
* If a policy with the same ID already exists, its `destroy` method will be called before it is replaced.
|
|
61
|
+
* @param policy The policy instance to add.
|
|
62
|
+
*/
|
|
63
|
+
add(policy: Policy<T>): this;
|
|
64
|
+
/**
|
|
65
|
+
* Removes a policy from the field by its ID and call `destroy` method.
|
|
66
|
+
* @param policyId The unique ID of the policy to remove.
|
|
67
|
+
* @returns `true` if the policy was found and removed, otherwise `false`.
|
|
68
|
+
*/
|
|
69
|
+
remove(policyId: string): boolean;
|
|
70
|
+
isEmpty(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Removes all policies from the field.
|
|
73
|
+
* After this, `set()` will no longer apply any transformations to the value until new policies are added.
|
|
74
|
+
*/
|
|
75
|
+
clear(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Forces the current value to be re-processed by all policies.
|
|
78
|
+
* Useful if a policy's logic has changed and you need to re-evaluate the current state.
|
|
79
|
+
*/
|
|
80
|
+
apply(val: T): T;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/mixins/mixin-factory.d.ts
|
|
78
84
|
/**
|
|
79
85
|
* extract field type
|
|
80
86
|
*/
|
|
@@ -83,13 +89,7 @@ type GetValueType<TField extends Field<any>> = TField extends Field<infer U> ? U
|
|
|
83
89
|
* A mapped type that creates the method signatures for a typed mixin.
|
|
84
90
|
* e.g., createBoolean, upsetBoolean, getBoolean
|
|
85
91
|
*/
|
|
86
|
-
type TypedMethods<TCtor extends Constructor<Field<any>>, TBaseName extends string> = {
|
|
87
|
-
[K in `create${TBaseName}`]: (name: string, initialValue: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor>;
|
|
88
|
-
} & {
|
|
89
|
-
[K in `upset${TBaseName}`]: (name: string, value: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor>;
|
|
90
|
-
} & {
|
|
91
|
-
[K in `get${TBaseName}`]: (name: string) => InstanceType<TCtor>;
|
|
92
|
-
};
|
|
92
|
+
type TypedMethods<TCtor extends Constructor<Field<any>>, TBaseName extends string> = { [K in `create${TBaseName}`]: (name: string, initialValue: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor> } & { [K in `upset${TBaseName}`]: (name: string, value: GetValueType<InstanceType<TCtor>>, options?: ConstructorParameters<TCtor>[2]) => InstanceType<TCtor> } & { [K in `get${TBaseName}`]: (name: string) => InstanceType<TCtor> };
|
|
93
93
|
/**
|
|
94
94
|
* A higher-order function that generates a mixin for a specific Field type.
|
|
95
95
|
* This factory removes the need to write boilerplate mixin code for every new field type.
|
|
@@ -99,39 +99,41 @@ type TypedMethods<TCtor extends Constructor<Field<any>>, TBaseName extends strin
|
|
|
99
99
|
* @returns A fully functional, typed mixin.
|
|
100
100
|
*/
|
|
101
101
|
declare function createTypedMethodsMixin<TCtor extends Constructor<Field<any>>, TBaseName extends string>(typeName: string, baseMethodName: TBaseName): <TBase extends Constructor<Fields>>(Base: TBase) => Constructor<InstanceType<TBase> & TypedMethods<TCtor, TBaseName>>;
|
|
102
|
-
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/field.d.ts
|
|
103
104
|
interface FieldOptions<T> {
|
|
104
|
-
|
|
105
|
+
policies?: Policy<T>[];
|
|
105
106
|
}
|
|
106
107
|
interface Field<T> {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
readonly typeName: string;
|
|
109
|
+
readonly name: string;
|
|
110
|
+
value: T;
|
|
111
|
+
policies: Policies<T>;
|
|
112
|
+
setValueSilently(val: T): void;
|
|
113
|
+
batchUpdate(updateFn: (currentValue: T) => T): void;
|
|
114
|
+
onChange: Subscribable<[newValue: T, oldValue: T]>;
|
|
115
|
+
destroy(): void;
|
|
115
116
|
}
|
|
116
117
|
interface NumericField extends Field<number> {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
readonly min: number | undefined;
|
|
119
|
+
readonly max: number | undefined;
|
|
120
|
+
isMin(): boolean;
|
|
121
|
+
isMax(): boolean;
|
|
122
|
+
inc(val: number): void;
|
|
123
|
+
dec(val: number): void;
|
|
123
124
|
}
|
|
124
125
|
interface BooleanField extends Field<boolean> {
|
|
125
|
-
|
|
126
|
+
toggle(): boolean;
|
|
126
127
|
}
|
|
127
128
|
interface StringField extends Field<string> {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
129
|
+
append(str: string | number): this;
|
|
130
|
+
prepend(str: string | number): this;
|
|
131
|
+
trim(): this;
|
|
132
|
+
isEmpty(): boolean;
|
|
133
|
+
clear(): void;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/field-definitions/core-field.d.ts
|
|
135
137
|
/**
|
|
136
138
|
* A state container that wraps a value.
|
|
137
139
|
* It allows applying a pipeline of transformation or validation "policies" before any new value is set.
|
|
@@ -140,126 +142,89 @@ interface StringField extends Field<string> {
|
|
|
140
142
|
*
|
|
141
143
|
*/
|
|
142
144
|
declare class CoreField<T> implements Field<T> {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
145
|
+
/** A type keyword of the field */
|
|
146
|
+
static readonly typeName: string;
|
|
147
|
+
readonly typeName: string;
|
|
148
|
+
/** A unique identifier for the field. */
|
|
149
|
+
private readonly _name;
|
|
150
|
+
private _value;
|
|
151
|
+
private readonly _onChange;
|
|
152
|
+
readonly onChange: Subscribable<[newValue: T, oldvalue: T]>;
|
|
153
|
+
readonly policies: Policies<T>;
|
|
154
|
+
get name(): string;
|
|
155
|
+
/**
|
|
156
|
+
* Gets the current raw value of the field.
|
|
157
|
+
* For reactive updates, it's recommended to use the `.signal` property instead.
|
|
158
|
+
*/
|
|
159
|
+
get value(): T;
|
|
160
|
+
/**
|
|
161
|
+
* Sets a new value for the field.
|
|
162
|
+
* The provided value will be processed by all registered policies before the underlying signal is updated.
|
|
163
|
+
* @param val The new value to set.
|
|
164
|
+
*/
|
|
165
|
+
set value(val: T);
|
|
166
|
+
/**
|
|
167
|
+
* Creates an instance of a Field.
|
|
168
|
+
* @param name A unique identifier for the field.
|
|
169
|
+
* @param initialVal The initial value of the field.
|
|
170
|
+
* @param options Optional configuration for the field.
|
|
171
|
+
* @param options.policies An array of policies to apply to the field's value on every `set` operation.
|
|
172
|
+
* @param options.isEqual An function for compare old and new value, by default uses the strictEquals from `utils`
|
|
173
|
+
*
|
|
174
|
+
*/
|
|
175
|
+
constructor(name: string, initialVal: T, options?: FieldOptions<T>);
|
|
176
|
+
setValueSilently(val: T): void;
|
|
177
|
+
batchUpdate(updateFn: (currentValue: T) => T): void;
|
|
178
|
+
/**
|
|
179
|
+
* Cleans up resources used by the field and its policies.
|
|
180
|
+
* This should be called when the field is no longer needed to prevent memory leaks from reactive policies.
|
|
181
|
+
*/
|
|
182
|
+
destroy(): void;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/field-definitions/core-boolean-field.d.ts
|
|
186
|
+
interface CoreBooleanFieldOptions extends FieldOptions<boolean> {}
|
|
185
187
|
declare class CoreBooleanField extends CoreField<boolean> implements BooleanField {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
188
|
+
static readonly typeName: string;
|
|
189
|
+
readonly typeName: string;
|
|
190
|
+
constructor(name: string, initialVal: boolean, options?: CoreBooleanFieldOptions);
|
|
191
|
+
toggle(): boolean;
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/field-definitions/core-string-field.d.ts
|
|
195
|
+
interface CoreStringFieldOptions extends FieldOptions<string> {}
|
|
194
196
|
declare class CoreStringField extends CoreField<string> implements StringField {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
197
|
+
static readonly typeName: string;
|
|
198
|
+
readonly typeName: string;
|
|
199
|
+
constructor(name: string, initialVal: string, options?: CoreStringFieldOptions);
|
|
200
|
+
append(str: string | number): this;
|
|
201
|
+
prepend(str: string | number): this;
|
|
202
|
+
trim(): this;
|
|
203
|
+
isEmpty(): boolean;
|
|
204
|
+
clear(): void;
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/field-definitions/core-numeric-field.d.ts
|
|
205
208
|
interface CoreNumericFieldOptions extends FieldOptions<number> {
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
min?: number;
|
|
210
|
+
max?: number;
|
|
208
211
|
}
|
|
209
212
|
declare class CoreNumericField extends CoreField<number> implements NumericField {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
* factories, and serialization engines where types need to be dynamically resolved.
|
|
226
|
-
*
|
|
227
|
-
* @template T - A base type that all registered constructors must produce an instance of.
|
|
228
|
-
*/
|
|
229
|
-
declare class ConstructorRegistry<T> {
|
|
230
|
-
private readonly items;
|
|
231
|
-
/**
|
|
232
|
-
* Registers a constructor with a unique string identifier.
|
|
233
|
-
*
|
|
234
|
-
* @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
|
|
235
|
-
* @param ctor - The class constructor to register.
|
|
236
|
-
* @returns The registry instance for chainable calls.
|
|
237
|
-
* @throws If a constructor with the same `typeId` is already registered.
|
|
238
|
-
*/
|
|
239
|
-
register(typeId: string, ctor: Constructor<T>): this;
|
|
240
|
-
/**
|
|
241
|
-
* Retrieves a constructor by its identifier.
|
|
242
|
-
*
|
|
243
|
-
* @param typeId - The identifier of the constructor to retrieve.
|
|
244
|
-
* @returns The found class constructor.
|
|
245
|
-
* @throws If no constructor is found for the given `typeId`.
|
|
246
|
-
*/
|
|
247
|
-
get(typeId: string): Constructor<T>;
|
|
248
|
-
/**
|
|
249
|
-
* Checks if a constructor for a given identifier is registered.
|
|
250
|
-
* @param typeId - The identifier to check.
|
|
251
|
-
* @returns `true` if a constructor is registered, otherwise `false`.
|
|
252
|
-
*/
|
|
253
|
-
has(typeId: string): boolean;
|
|
254
|
-
/**
|
|
255
|
-
* Clears all registered constructors from the registry.
|
|
256
|
-
*/
|
|
257
|
-
clear(): void;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
declare class FieldRegistry extends ConstructorRegistry<Field<any>> {
|
|
261
|
-
}
|
|
262
|
-
|
|
213
|
+
static readonly typeName: string;
|
|
214
|
+
readonly typeName: string;
|
|
215
|
+
get min(): number | undefined;
|
|
216
|
+
get max(): number | undefined;
|
|
217
|
+
constructor(name: string, initialVal: number, options?: CoreNumericFieldOptions);
|
|
218
|
+
isMin(): boolean;
|
|
219
|
+
isMax(): boolean;
|
|
220
|
+
inc(amount?: number): void;
|
|
221
|
+
dec(amount?: number): void;
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/field-registry.d.ts
|
|
225
|
+
declare class FieldRegistry extends ConstructorRegistry<Field<any>> {}
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/fields.d.ts
|
|
263
228
|
/**
|
|
264
229
|
* A container for a collection of named `Field` instances.
|
|
265
230
|
*
|
|
@@ -268,109 +233,112 @@ declare class FieldRegistry extends ConstructorRegistry<Field<any>> {
|
|
|
268
233
|
* create `Field` instances of different types.
|
|
269
234
|
*/
|
|
270
235
|
declare class Fields {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
236
|
+
static readonly typeName = "fields";
|
|
237
|
+
readonly typeName = "fields";
|
|
238
|
+
readonly _fields: Map<string, Field<any>>;
|
|
239
|
+
readonly _fieldRegistry: FieldRegistry;
|
|
240
|
+
/**
|
|
241
|
+
* An event emitter that fires when a new field is added to the collection.
|
|
242
|
+
* @event
|
|
243
|
+
* @param {object} event - The event payload.
|
|
244
|
+
* @param {string} event.name - The name of the added field.
|
|
245
|
+
* @param {Field<any>} event.field - The `Field` instance that was added.
|
|
246
|
+
*/
|
|
247
|
+
onAdd: Emitter<[event: {
|
|
248
|
+
name: string;
|
|
249
|
+
field: Field<any>;
|
|
250
|
+
}]>;
|
|
251
|
+
/**
|
|
252
|
+
* An event emitter that fires after one or more fields have been removed.
|
|
253
|
+
* @event
|
|
254
|
+
* @param {object} event - The event payload.
|
|
255
|
+
* @param {string[]} event.names - An array of names of the fields that were successfully removed.
|
|
256
|
+
*/
|
|
257
|
+
onRemove: Emitter<[event: {
|
|
258
|
+
names: string[];
|
|
259
|
+
}]>;
|
|
260
|
+
/**
|
|
261
|
+
* Gets the read-only map of all `Field` instances in this container.
|
|
262
|
+
* @returns {Map<string, Field<any>>} The collection of fields.
|
|
263
|
+
*/
|
|
264
|
+
get fields(): Map<string, Field<any>>;
|
|
265
|
+
/**
|
|
266
|
+
* Creates an instance of Fields.
|
|
267
|
+
* @param {FieldRegistry} fieldRegistry - The registry used to create new `Field` instances.
|
|
268
|
+
*/
|
|
269
|
+
constructor(fieldRegistry: FieldRegistry);
|
|
270
|
+
/**
|
|
271
|
+
* Checks if a field with the given name exists in the collection.
|
|
272
|
+
* @param {string} name The name of the field to check.
|
|
273
|
+
* @returns {boolean} `true` if the field exists, otherwise `false`.
|
|
274
|
+
*/
|
|
275
|
+
has(name: string): boolean;
|
|
276
|
+
/**
|
|
277
|
+
* Adds a pre-existing `Field` instance to the collection and fires the `onAdd` event.
|
|
278
|
+
* @template T - The specific `Field` type being added.
|
|
279
|
+
* @param {Field<any>} field - The `Field` instance to add.
|
|
280
|
+
* @returns {T} The added `Field` instance, cast to type `T`.
|
|
281
|
+
* @throws If a field with the same name already exists.
|
|
282
|
+
*/
|
|
283
|
+
add<T extends Field<any>>(field: Field<any>): T;
|
|
284
|
+
/**
|
|
285
|
+
* Creates a new `Field` instance of a specified type, adds it to the collection, and returns it.
|
|
286
|
+
* This is the primary factory method for creating fields within this container.
|
|
287
|
+
* @template T - The expected `Field` type to be returned.
|
|
288
|
+
* @param {string} typeName - The registered type name of the field to create (e.g., 'numeric', 'boolean').
|
|
289
|
+
* @param {string} name - The unique name for the new field.
|
|
290
|
+
* @param {*} initialValue - The initial value for the new field.
|
|
291
|
+
* @param {*} [options] - Optional configuration passed to the field's constructor.
|
|
292
|
+
* @returns {T} The newly created `Field` instance.
|
|
293
|
+
*/
|
|
294
|
+
create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
|
|
295
|
+
/**
|
|
296
|
+
* Updates an existing field's value or creates a new one if it doesn't exist.
|
|
297
|
+
* @template T - The expected `Field` type.
|
|
298
|
+
* @param {string} typeName - The type name to use if a new field needs to be created.
|
|
299
|
+
* @param {string} name - The name of the field to update or create.
|
|
300
|
+
* @param {*} value - The new value to set.
|
|
301
|
+
* @param {*} [options] - Optional configuration, used only if a new field is created.
|
|
302
|
+
* @returns {T} The existing or newly created `Field` instance.
|
|
303
|
+
*/
|
|
304
|
+
upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
|
|
305
|
+
/**
|
|
306
|
+
* Retrieves a field by its name.
|
|
307
|
+
* @template TField - The expected `Field` type to be returned.
|
|
308
|
+
* @param {string} name - The name of the field to retrieve.
|
|
309
|
+
* @returns {TField} The `Field` instance.
|
|
310
|
+
* @throws If the field does not exist.
|
|
311
|
+
*/
|
|
312
|
+
get<TField extends Field<any>>(name: string): TField;
|
|
313
|
+
/**
|
|
314
|
+
* Removes one or more fields from the collection.
|
|
315
|
+
* This method ensures that the `destroy` method of each removed field is called to clean up its resources.
|
|
316
|
+
* @param {string| string[]} names A single name or an array of names to remove.
|
|
317
|
+
*/
|
|
318
|
+
remove(names: string | string[]): void;
|
|
319
|
+
/**
|
|
320
|
+
* Removes all fields from the collection, ensuring each is properly destroyed.
|
|
321
|
+
*/
|
|
322
|
+
clear(): void;
|
|
323
|
+
destroy(): void;
|
|
324
|
+
}
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/fields-factory.d.ts
|
|
361
327
|
interface FieldsFactory<TFields extends Fields> {
|
|
362
|
-
|
|
328
|
+
fields(): TFields;
|
|
363
329
|
}
|
|
364
|
-
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/field-tree-factory.d.ts
|
|
365
332
|
/**
|
|
366
333
|
* Defines the contract for a factory that creates nodes for a FieldTree.
|
|
367
334
|
* This allows for custom implementations of Fields and FieldTree to be used.
|
|
368
335
|
*/
|
|
369
336
|
interface FieldTreeFactory<TFields extends Fields> extends FieldsFactory<TFields> {
|
|
370
|
-
|
|
371
|
-
|
|
337
|
+
fields(): TFields;
|
|
338
|
+
tree(): FieldTree<TFields>;
|
|
372
339
|
}
|
|
373
|
-
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/field-tree.d.ts
|
|
374
342
|
/** A type alias for any container that can be a child node in a FieldTree */
|
|
375
343
|
type TreeNode<F extends Fields> = FieldTree<F> | F;
|
|
376
344
|
/**
|
|
@@ -383,309 +351,316 @@ type TreeNode<F extends Fields> = FieldTree<F> | F;
|
|
|
383
351
|
*
|
|
384
352
|
*/
|
|
385
353
|
declare class FieldTree<TFields extends Fields> {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
354
|
+
static readonly typeName = "fieldTree";
|
|
355
|
+
readonly typeName = "fieldTree";
|
|
356
|
+
/** @private The internal map storing child nodes (branches or leaves). */
|
|
357
|
+
private readonly _nodes;
|
|
358
|
+
/** @private The factory used to create new child nodes. */
|
|
359
|
+
private readonly _factory;
|
|
360
|
+
/**
|
|
361
|
+
* An event emitter that fires immediately after a new node is added to this tree branch.
|
|
362
|
+
* @event
|
|
363
|
+
* @param {object} event - The event payload.
|
|
364
|
+
* @param {string} event.name - The name (key) of the added node.
|
|
365
|
+
* @param event.node - The node instance that was added.
|
|
366
|
+
* @example
|
|
367
|
+
* myTree.onAdd.subscribe(({ name, node }) => {
|
|
368
|
+
* console.log(`Node '${name}' was added.`, node);
|
|
369
|
+
* });
|
|
370
|
+
*/
|
|
371
|
+
onAdd: Emitter<[event: {
|
|
372
|
+
name: string;
|
|
373
|
+
node: TreeNode<TFields>;
|
|
374
|
+
}]>;
|
|
375
|
+
/**
|
|
376
|
+
* An event emitter that fires once after one or more nodes have been successfully removed.
|
|
377
|
+
* @event
|
|
378
|
+
* @param {object} event - The event payload.
|
|
379
|
+
* @param {string[]} event.names - An array of names of the nodes that were removed.
|
|
380
|
+
* @example
|
|
381
|
+
* myTree.onRemove.subscribe(({ names }) => {
|
|
382
|
+
* console.log(`Nodes removed: ${names.join(', ')}`);
|
|
383
|
+
* });
|
|
384
|
+
*/
|
|
385
|
+
onRemove: Emitter<[event: {
|
|
386
|
+
names: string[];
|
|
387
|
+
}]>;
|
|
388
|
+
/**
|
|
389
|
+
* Gets the collection of direct child nodes of this tree branch.
|
|
390
|
+
*/
|
|
391
|
+
get nodes(): Map<string, TreeNode<TFields>>;
|
|
392
|
+
/**
|
|
393
|
+
* Creates an instance of FieldTree.
|
|
394
|
+
* @param {FieldTreeFactory} factory - A factory responsible for creating new nodes within the tree.
|
|
395
|
+
*/
|
|
396
|
+
constructor(factory: FieldTreeFactory<TFields>);
|
|
397
|
+
/**
|
|
398
|
+
* Checks if a direct child node with the given name exists.
|
|
399
|
+
* @param {string} name - The name of the direct child node.
|
|
400
|
+
* @returns {boolean} `true` if the node exists, otherwise `false`.
|
|
401
|
+
*/
|
|
402
|
+
has(name: string): boolean;
|
|
403
|
+
/**
|
|
404
|
+
* Checks if a node exists at a given path, traversing the tree.
|
|
405
|
+
* @param {PathType} path - The path to check (e.g., 'player/stats' or ['player', 'stats']).
|
|
406
|
+
* @returns {boolean} `true` if the entire path resolves to a node, otherwise `false`.
|
|
407
|
+
*/
|
|
408
|
+
hasPath(path: PathType): boolean;
|
|
409
|
+
/**
|
|
410
|
+
* Adds a pre-existing node as a direct child of this tree branch.
|
|
411
|
+
* @param {string} name - The name to assign to the new child node.
|
|
412
|
+
* @param {TreeNode} node - The node instance to add.
|
|
413
|
+
* @returns {TreeNode} The added node.
|
|
414
|
+
* @throws If a node with the same name already exists.
|
|
415
|
+
*/
|
|
416
|
+
addNode(name: string, node: TreeNode<TFields>): TreeNode<TFields>;
|
|
417
|
+
/**
|
|
418
|
+
* Retrieves a direct child node by its name.
|
|
419
|
+
* @param {string} name - The name of the child node.
|
|
420
|
+
* @returns {TreeNode} The retrieved node.
|
|
421
|
+
* @throws If a node with the given name cannot be found.
|
|
422
|
+
*/
|
|
423
|
+
getNode(name: string): TreeNode<TFields>;
|
|
424
|
+
/**
|
|
425
|
+
* Removes one or more nodes from this tree branch.
|
|
426
|
+
*
|
|
427
|
+
* This method first validates that all specified nodes exist. If validation passes,
|
|
428
|
+
* it recursively calls `destroy()` on each node to ensure proper cleanup of the entire subtree.
|
|
429
|
+
* Finally, it emits a single `onRemove` event with the names of all successfully removed nodes.
|
|
430
|
+
*
|
|
431
|
+
* @param {string | string[]} names - A single name or an array of names of the nodes to remove.
|
|
432
|
+
* @throws If any of the specified names do not correspond to an existing node.
|
|
433
|
+
*/
|
|
434
|
+
removeNode(names: string | string[]): void;
|
|
435
|
+
/**
|
|
436
|
+
* Creates a new `FieldTree` (branch) node at the specified path.
|
|
437
|
+
* @param {PathType} path - The path where the new `FieldTree` should be created.
|
|
438
|
+
* @param {boolean} [createPath=false] - If `true`, any missing parent branches in the path will be created automatically.
|
|
439
|
+
* @returns {FieldTree} The newly created `FieldTree` instance.
|
|
440
|
+
* @throws If the path is invalid or a node already exists at the target location.
|
|
441
|
+
*/
|
|
442
|
+
createFieldTree<T extends FieldTree<TFields>>(path: PathType, createPath?: boolean): T;
|
|
443
|
+
/**
|
|
444
|
+
* Creates a new `Fields` (leaf) container at the specified path.
|
|
445
|
+
* @param {PathType} path - The path where the new `Fields` container should be created.
|
|
446
|
+
* @param {boolean} [createPath=false] - If `true`, any missing parent branches in the path will be created automatically.
|
|
447
|
+
* @returns {Fields} The newly created `Fields` instance.
|
|
448
|
+
* @throws If the path is invalid or a node already exists at the target location.
|
|
449
|
+
*/
|
|
450
|
+
createFields(path: PathType, createPath?: boolean): TFields;
|
|
451
|
+
/**
|
|
452
|
+
* Retrieves a `FieldTree` (branch) node from a specified path.
|
|
453
|
+
* @param {PathType} path - The path to the `FieldTree` node.
|
|
454
|
+
* @returns {FieldTree} The `FieldTree` instance at the specified path.
|
|
455
|
+
* @throws If the path is invalid or the node at the path is not a `FieldTree`.
|
|
456
|
+
*/
|
|
457
|
+
getFieldTree(path: PathType): FieldTree<TFields>;
|
|
458
|
+
/**
|
|
459
|
+
* Retrieves a `Fields` (leaf) container from a specified path.
|
|
460
|
+
* @param {PathType} path - The path to the `Fields` container.
|
|
461
|
+
* @returns {Fields} The `Fields` instance at the specified path.
|
|
462
|
+
* @throws If the path is invalid or the node at the path is not a `Fields` container.
|
|
463
|
+
*/
|
|
464
|
+
getFields(path: PathType): TFields;
|
|
465
|
+
/**
|
|
466
|
+
* Retrieves a `FieldTree` at the specified path. If it or any part of the path doesn't exist, it will be created.
|
|
467
|
+
* @param {PathType} path - The path to the `FieldTree` node.
|
|
468
|
+
* @returns {FieldTree} The existing or newly created `FieldTree` instance.
|
|
469
|
+
*/
|
|
470
|
+
getOrCreateFieldTree(path: PathType): FieldTree<TFields>;
|
|
471
|
+
/**
|
|
472
|
+
* Retrieves a `Fields` container at the specified path. If it or any part of the path doesn't exist, it will be created.
|
|
473
|
+
* @param {PathType} path - The path to the `Fields` container.
|
|
474
|
+
* @returns {Fields} The existing or newly created `Fields` instance.
|
|
475
|
+
*/
|
|
476
|
+
getOrCreateFields(path: PathType): TFields;
|
|
477
|
+
/**
|
|
478
|
+
* Finds the parent node for a given path.
|
|
479
|
+
* @param path The path to the target node.
|
|
480
|
+
* @returns The parent node (either a FieldTree or Fields).
|
|
481
|
+
* @throws An error if the path is invalid or any intermediate node is not a FieldTree.
|
|
482
|
+
*/
|
|
483
|
+
findParentNode(path: PathType): FieldTree<TFields> | TFields;
|
|
484
|
+
/**
|
|
485
|
+
* Removes all child nodes from this tree branch.
|
|
486
|
+
* This method ensures that `destroy()` is called on each child node, allowing for
|
|
487
|
+
* a full, recursive cleanup of the entire subtree.
|
|
488
|
+
*/
|
|
489
|
+
clear(): void;
|
|
490
|
+
/**
|
|
491
|
+
* Performs a complete cleanup of this node and its entire subtree.
|
|
492
|
+
*
|
|
493
|
+
* It recursively destroys all child nodes by calling `clear()` and then
|
|
494
|
+
* unsubscribes all listeners from its own event emitters.
|
|
495
|
+
* This method should be called when a node is no longer needed.
|
|
496
|
+
*/
|
|
497
|
+
destroy(): void;
|
|
498
|
+
/**
|
|
499
|
+
* @private
|
|
500
|
+
* Navigates the tree to the parent of a target node.
|
|
501
|
+
* This is the core traversal logic for all path-based operations.
|
|
502
|
+
* @param {PathType} path - The full path to the target node.
|
|
503
|
+
* @param {boolean} [createPath=false] - If `true`, creates missing `FieldTree` branches along the path.
|
|
504
|
+
* @returns {{branch: FieldTree, leafName: string}} An object containing the final branch (parent node) and the name of the leaf (target node).
|
|
505
|
+
* @throws If the path is empty, invalid, or contains a `Fields` container as an intermediate segment.
|
|
506
|
+
*/
|
|
507
|
+
private traversePath;
|
|
508
|
+
}
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/core-fields.d.ts
|
|
511
|
+
declare const CoreFields_base: _axi_engine_utils0.Constructor<{
|
|
512
|
+
createGeneric<T>(name: string, initialValue: T, options?: FieldOptions<T> | undefined): CoreField<T>;
|
|
513
|
+
upsetGeneric<T>(name: string, value: T, options?: FieldOptions<T> | undefined): CoreField<T>;
|
|
514
|
+
getGeneric<T>(name: string): CoreField<T>;
|
|
515
|
+
readonly typeName: "fields";
|
|
516
|
+
readonly _fields: Map<string, Field<any>>;
|
|
517
|
+
readonly _fieldRegistry: FieldRegistry;
|
|
518
|
+
onAdd: _axi_engine_utils0.Emitter<[event: {
|
|
519
|
+
name: string;
|
|
520
|
+
field: Field<any>;
|
|
521
|
+
}]>;
|
|
522
|
+
onRemove: _axi_engine_utils0.Emitter<[event: {
|
|
523
|
+
names: string[];
|
|
524
|
+
}]>;
|
|
525
|
+
get fields(): Map<string, Field<any>>;
|
|
526
|
+
has(name: string): boolean;
|
|
527
|
+
add<T extends Field<any>>(field: Field<any>): T;
|
|
528
|
+
create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
|
|
529
|
+
upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
|
|
530
|
+
get<TField extends Field<any>>(name: string): TField;
|
|
531
|
+
remove(names: string | string[]): void;
|
|
532
|
+
clear(): void;
|
|
533
|
+
destroy(): void;
|
|
565
534
|
} & Fields & {
|
|
566
|
-
|
|
535
|
+
createNumeric: (name: string, initialValue: number, options?: CoreNumericFieldOptions | undefined) => CoreNumericField;
|
|
567
536
|
} & {
|
|
568
|
-
|
|
537
|
+
upsetNumeric: (name: string, value: number, options?: CoreNumericFieldOptions | undefined) => CoreNumericField;
|
|
569
538
|
} & {
|
|
570
|
-
|
|
539
|
+
getNumeric: (name: string) => CoreNumericField;
|
|
571
540
|
} & {
|
|
572
|
-
|
|
541
|
+
createString: (name: string, initialValue: string, options?: CoreStringFieldOptions | undefined) => CoreStringField;
|
|
573
542
|
} & {
|
|
574
|
-
|
|
543
|
+
upsetString: (name: string, value: string, options?: CoreStringFieldOptions | undefined) => CoreStringField;
|
|
575
544
|
} & {
|
|
576
|
-
|
|
545
|
+
getString: (name: string) => CoreStringField;
|
|
577
546
|
} & {
|
|
578
|
-
|
|
547
|
+
createBoolean: (name: string, initialValue: boolean, options?: CoreBooleanFieldOptions | undefined) => CoreBooleanField;
|
|
579
548
|
} & {
|
|
580
|
-
|
|
549
|
+
upsetBoolean: (name: string, value: boolean, options?: CoreBooleanFieldOptions | undefined) => CoreBooleanField;
|
|
581
550
|
} & {
|
|
582
|
-
|
|
551
|
+
getBoolean: (name: string) => CoreBooleanField;
|
|
583
552
|
}>;
|
|
584
|
-
declare class CoreFields extends CoreFields_base {
|
|
585
|
-
|
|
586
|
-
|
|
553
|
+
declare class CoreFields extends CoreFields_base {}
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/core-fields-factory.d.ts
|
|
587
556
|
declare class CoreFieldsFactory implements FieldsFactory<CoreFields> {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
|
|
557
|
+
protected readonly _fieldRegistry: FieldRegistry;
|
|
558
|
+
get fieldRegistry(): FieldRegistry;
|
|
559
|
+
constructor(fieldRegistry: FieldRegistry);
|
|
560
|
+
fields(): CoreFields;
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region src/core-field-tree.d.ts
|
|
564
|
+
declare class CoreFieldTree extends FieldTree<CoreFields> {}
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/core-field-tree-factory.d.ts
|
|
597
567
|
/**
|
|
598
568
|
* The default factory implementation that creates standard DefaultFields and FieldTree instances.
|
|
599
569
|
*/
|
|
600
570
|
declare class CoreTreeNodeFactory extends CoreFieldsFactory implements FieldTreeFactory<CoreFields> {
|
|
601
|
-
|
|
602
|
-
|
|
571
|
+
constructor(fieldRegistry: FieldRegistry);
|
|
572
|
+
tree(): CoreFieldTree;
|
|
603
573
|
}
|
|
604
|
-
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/serializer/policy-serializer.d.ts
|
|
605
576
|
/**
|
|
606
577
|
* Defines the contract for a handler that can serialize and deserialize a specific type of Policy.
|
|
607
578
|
* @template T - The specific Policy class this handler manages.
|
|
608
579
|
* @template S - The shape of the plain object this handler produces/consumes.
|
|
609
580
|
*/
|
|
610
581
|
interface PolicySerializerHandler<T extends Policy<any>, S extends object> {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
582
|
+
/**
|
|
583
|
+
* Converts a Policy instance into a serializable plain object.
|
|
584
|
+
* @param policy The Policy instance to serialize.
|
|
585
|
+
* @returns A plain object representing the policy's state.
|
|
586
|
+
*/
|
|
587
|
+
snapshot(policy: T): S;
|
|
588
|
+
/**
|
|
589
|
+
* Creates a new Policy instance from a plain object.
|
|
590
|
+
* @param snapshotData The plain object containing the policy's state.
|
|
591
|
+
* @returns A new instance of the Policy.
|
|
592
|
+
*/
|
|
593
|
+
hydrate(snapshotData: S): T;
|
|
623
594
|
}
|
|
624
595
|
declare class PolicySerializer {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
|
|
596
|
+
private readonly handlers;
|
|
597
|
+
register(policyId: string, handler: PolicySerializerHandler<any, any>): this;
|
|
598
|
+
clearHandlers(): void;
|
|
599
|
+
/**
|
|
600
|
+
* Creates a serializable snapshot of a policy instance.
|
|
601
|
+
* The snapshot includes the policy's state and a `__type` identifier.
|
|
602
|
+
* @param policy The policy instance to snapshot.
|
|
603
|
+
* @returns A plain object ready for JSON serialization.
|
|
604
|
+
* @throws If no handler is registered for the policy's ID.
|
|
605
|
+
*/
|
|
606
|
+
snapshot(policy: Policy<any>): object;
|
|
607
|
+
/**
|
|
608
|
+
* Restores a policy instance from its snapshot representation.
|
|
609
|
+
* @param snapshot The plain object snapshot, which must contain a `__type` property.
|
|
610
|
+
* @returns A new, fully functional policy instance.
|
|
611
|
+
* @throws If the snapshot is invalid or no handler is registered for its `__type`.
|
|
612
|
+
*/
|
|
613
|
+
hydrate(snapshot: any): Policy<any>;
|
|
614
|
+
}
|
|
615
|
+
//#endregion
|
|
616
|
+
//#region src/serializer/policies/clamp-policy-serializer-handler.d.ts
|
|
645
617
|
declare class ClampPolicySerializerHandler implements PolicySerializerHandler<ClampPolicy, {
|
|
618
|
+
min: number;
|
|
619
|
+
max: number;
|
|
620
|
+
}> {
|
|
621
|
+
snapshot(policy: ClampPolicy): {
|
|
646
622
|
min: number;
|
|
647
623
|
max: number;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
hydrate(data: {
|
|
654
|
-
min: number;
|
|
655
|
-
max: number;
|
|
656
|
-
}): ClampPolicy;
|
|
624
|
+
};
|
|
625
|
+
hydrate(data: {
|
|
626
|
+
min: number;
|
|
627
|
+
max: number;
|
|
628
|
+
}): ClampPolicy;
|
|
657
629
|
}
|
|
658
|
-
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region src/serializer/policies/clamp-max-policy-serializer-handler.d.ts
|
|
659
632
|
declare class ClampMaxPolicySerializerHandler implements PolicySerializerHandler<ClampMaxPolicy, {
|
|
660
|
-
|
|
633
|
+
max: number;
|
|
661
634
|
}> {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
635
|
+
snapshot(policy: ClampMaxPolicy): {
|
|
636
|
+
max: number;
|
|
637
|
+
};
|
|
638
|
+
hydrate(data: {
|
|
639
|
+
max: number;
|
|
640
|
+
}): ClampMaxPolicy;
|
|
668
641
|
}
|
|
669
|
-
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/serializer/policies/clamp-min-policy-serializer-handler.d.ts
|
|
670
644
|
declare class ClampMinPolicySerializerHandler implements PolicySerializerHandler<ClampMinPolicy, {
|
|
671
|
-
|
|
645
|
+
min: number;
|
|
672
646
|
}> {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
647
|
+
snapshot(policy: ClampMinPolicy): {
|
|
648
|
+
min: number;
|
|
649
|
+
};
|
|
650
|
+
hydrate(data: {
|
|
651
|
+
min: number;
|
|
652
|
+
}): ClampMinPolicy;
|
|
679
653
|
}
|
|
680
|
-
|
|
654
|
+
//#endregion
|
|
655
|
+
//#region src/serializer/field-serializer.d.ts
|
|
681
656
|
/**
|
|
682
657
|
* A plain object representation of a Field's state for serialization.
|
|
683
658
|
*/
|
|
684
659
|
interface FieldSnapshot {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
660
|
+
__type: string;
|
|
661
|
+
name: string;
|
|
662
|
+
value: any;
|
|
663
|
+
policies?: object[];
|
|
689
664
|
}
|
|
690
665
|
/**
|
|
691
666
|
* Orchestrates the serialization and deserialization of Field instances.
|
|
@@ -701,38 +676,39 @@ interface FieldSnapshot {
|
|
|
701
676
|
* without breaking external references to it.
|
|
702
677
|
*/
|
|
703
678
|
declare class FieldSerializer {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
|
|
679
|
+
private readonly fieldRegistry;
|
|
680
|
+
private readonly policySerializer;
|
|
681
|
+
/**
|
|
682
|
+
* Creates an instance of FieldSerializer.
|
|
683
|
+
* @param {FieldRegistry} fieldRegistry - A registry that maps string type names to Field constructors.
|
|
684
|
+
* @param {PolicySerializer} policySerializer - A serializer dedicated to handling Policy instances.
|
|
685
|
+
*/
|
|
686
|
+
constructor(fieldRegistry: FieldRegistry, policySerializer: PolicySerializer);
|
|
687
|
+
/**
|
|
688
|
+
* Creates a serializable snapshot of a Field instance.
|
|
689
|
+
* The snapshot includes the field's type, name, current value, and the state of all its policies.
|
|
690
|
+
* @param {Field<any>} field - The Field instance to serialize.
|
|
691
|
+
* @returns {FieldSnapshot} A plain object ready for JSON serialization.
|
|
692
|
+
*/
|
|
693
|
+
snapshot(field: Field<any>): FieldSnapshot;
|
|
694
|
+
/**
|
|
695
|
+
* Restores a Field instance from its snapshot representation.
|
|
696
|
+
* It uses the `__type` property to find the correct constructor and hydrates
|
|
697
|
+
* the field with its value and all its policies.
|
|
698
|
+
* @param {FieldSnapshot} snapshot - The plain object snapshot to deserialize.
|
|
699
|
+
* @returns {Field<any>} A new, fully functional Field instance.
|
|
700
|
+
* @throws If the snapshot is invalid, missing a `__type`, or if the type is not registered.
|
|
701
|
+
*/
|
|
702
|
+
hydrate(snapshot: FieldSnapshot): Field<any>;
|
|
703
|
+
}
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region src/serializer/fields-serializer.d.ts
|
|
730
706
|
/**
|
|
731
707
|
* A plain object representation of a Fields container's state for serialization.
|
|
732
708
|
*/
|
|
733
709
|
interface FieldsSnapshot {
|
|
734
|
-
|
|
735
|
-
|
|
710
|
+
__type: string;
|
|
711
|
+
[fieldName: string]: FieldSnapshot | string;
|
|
736
712
|
}
|
|
737
713
|
/**
|
|
738
714
|
* Orchestrates the serialization and deserialization of `Fields` container instances.
|
|
@@ -746,33 +722,34 @@ interface FieldsSnapshot {
|
|
|
746
722
|
* in place, preserving the container instance itself.
|
|
747
723
|
*/
|
|
748
724
|
declare class FieldsSerializer<TFields extends Fields> {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
}
|
|
775
|
-
|
|
725
|
+
private readonly fieldsFactory;
|
|
726
|
+
private readonly fieldSerializer;
|
|
727
|
+
/**
|
|
728
|
+
* Creates an instance of FieldsSerializer.
|
|
729
|
+
* @param {FieldsFactory} fieldsFactory - A registry that maps string type names to Field constructors.
|
|
730
|
+
* @param {FieldSerializer} fieldSerializer - A serializer of field instances.
|
|
731
|
+
*/
|
|
732
|
+
constructor(fieldsFactory: FieldsFactory<TFields>, fieldSerializer: FieldSerializer);
|
|
733
|
+
/**
|
|
734
|
+
* Creates a serializable snapshot of a `Fields` container.
|
|
735
|
+
*
|
|
736
|
+
* The snapshot includes a `__type` identifier (currently hardcoded) and an array of snapshots
|
|
737
|
+
* for each `Field` within the container.
|
|
738
|
+
* @param {Fields} fields - The `Fields` instance to serialize.
|
|
739
|
+
* @returns {FieldsSnapshot} A plain object ready for JSON serialization.
|
|
740
|
+
*/
|
|
741
|
+
snapshot(fields: Fields): FieldsSnapshot;
|
|
742
|
+
/**
|
|
743
|
+
* Restores a `Fields` container instance from its snapshot representation.
|
|
744
|
+
*
|
|
745
|
+
* It iterates through the field snapshots and hydrates them individually, adding them to the new container.
|
|
746
|
+
* @param {FieldsSnapshot} snapshot - The plain object snapshot to deserialize.
|
|
747
|
+
* @returns {Fields} A new `DefaultFields` instance populated with the restored fields.
|
|
748
|
+
*/
|
|
749
|
+
hydrate(snapshot: FieldsSnapshot): TFields;
|
|
750
|
+
}
|
|
751
|
+
//#endregion
|
|
752
|
+
//#region src/serializer/field-tree-serializer.d.ts
|
|
776
753
|
/**
|
|
777
754
|
* Represents the serializable state of a `FieldTree` container.
|
|
778
755
|
*
|
|
@@ -783,8 +760,8 @@ declare class FieldsSerializer<TFields extends Fields> {
|
|
|
783
760
|
* The `| string` is included to ensure compatibility with the `__type` property.
|
|
784
761
|
*/
|
|
785
762
|
interface FieldTreeSnapshot {
|
|
786
|
-
|
|
787
|
-
|
|
763
|
+
__type: string;
|
|
764
|
+
[fieldName: string]: FieldsSnapshot | FieldTreeSnapshot | string;
|
|
788
765
|
}
|
|
789
766
|
/**
|
|
790
767
|
* Orchestrates the recursive serialization and deserialization of `FieldTree` instances.
|
|
@@ -803,25 +780,26 @@ interface FieldTreeSnapshot {
|
|
|
803
780
|
* patching nodes in place to maintain object references.
|
|
804
781
|
*/
|
|
805
782
|
declare class FieldTreeSerializer<TFields extends Fields> {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
}
|
|
821
|
-
|
|
783
|
+
private readonly fieldTreeNodeFactory;
|
|
784
|
+
private readonly fieldsSerializer;
|
|
785
|
+
constructor(fieldTreeNodeFactory: FieldTreeFactory<TFields>, fieldsSerializer: FieldsSerializer<TFields>);
|
|
786
|
+
/**
|
|
787
|
+
* Creates a serializable snapshot of the entire tree and its contained fields.
|
|
788
|
+
* @returns A plain JavaScript object representing the complete state managed by this tree.
|
|
789
|
+
*/
|
|
790
|
+
snapshot(tree: FieldTree<TFields>): FieldTreeSnapshot;
|
|
791
|
+
/**
|
|
792
|
+
* Restores the state of the tree from a snapshot.
|
|
793
|
+
* It intelligently creates missing nodes based on `__type` metadata and delegates hydration to child nodes.
|
|
794
|
+
* @param snapshot The snapshot object to load.
|
|
795
|
+
*/
|
|
796
|
+
hydrate(snapshot: FieldTreeSnapshot): FieldTree<TFields>;
|
|
797
|
+
}
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region src/store.d.ts
|
|
822
800
|
interface StoreCreateFieldOptions {
|
|
823
|
-
|
|
824
|
-
|
|
801
|
+
/** Allows to explicitly specify the field type, overriding the automatic type detection. */
|
|
802
|
+
fieldType?: string;
|
|
825
803
|
}
|
|
826
804
|
/**
|
|
827
805
|
* Defines the primary high-level API for interacting with the state management system.
|
|
@@ -829,173 +807,176 @@ interface StoreCreateFieldOptions {
|
|
|
829
807
|
* both type-safe and dynamic methods for manipulating data.
|
|
830
808
|
*/
|
|
831
809
|
interface Store {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
}
|
|
953
|
-
|
|
810
|
+
/**
|
|
811
|
+
* Retrieves the raw value of a Field at a specific path.
|
|
812
|
+
* @template T The expected type of the value.
|
|
813
|
+
* @param path The path to the field (e.g., 'player.stats.hp').
|
|
814
|
+
* @returns {T} The raw value stored in the field.
|
|
815
|
+
* @throws An error if the path is invalid or no field exists at the path.
|
|
816
|
+
*/
|
|
817
|
+
getValue<T>(path: PathType): T;
|
|
818
|
+
/**
|
|
819
|
+
* Strictly sets the value of an *existing* Field at a specific path.
|
|
820
|
+
* @template T The type of the value being set.
|
|
821
|
+
* @param path The path to the existing field.
|
|
822
|
+
* @param val The new value to set.
|
|
823
|
+
* @returns {T} The value that was set.
|
|
824
|
+
* @throws An error if no field exists at the specified path.
|
|
825
|
+
*/
|
|
826
|
+
setValue<T>(path: PathType, val: T): T;
|
|
827
|
+
/**
|
|
828
|
+
* Creates a new Field at a specified path, inferring its type from the provided value.
|
|
829
|
+
* This is a strict operation and will fail if a node already exists at the target path.
|
|
830
|
+
* @template T The type of the initial value.
|
|
831
|
+
* @param path The full path where the new field will be created.
|
|
832
|
+
* @param val The initial value for the field.
|
|
833
|
+
* @param options Optional configuration, including policies and the ability to override field type.
|
|
834
|
+
* @returns {T} value of the newly created Field instance.
|
|
835
|
+
* @throws An error if a node already exists at the path or if the parent path is invalid.
|
|
836
|
+
*/
|
|
837
|
+
createValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
|
|
838
|
+
/**
|
|
839
|
+
* Creates new or update a Field at a specified path, inferring its type from the provided value.
|
|
840
|
+
* @template T The type of the initial value.
|
|
841
|
+
* @param path The full path where the new field will be created.
|
|
842
|
+
* @param val The initial value for the field.
|
|
843
|
+
* @param options Optional configuration, including policies and the ability to override field type.
|
|
844
|
+
* @returns {T} value of the newly created Field instance.
|
|
845
|
+
* @throws An error if a node already exists at the path or if the parent path is invalid.
|
|
846
|
+
*/
|
|
847
|
+
upsetValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
|
|
848
|
+
/**
|
|
849
|
+
* Creates a new, strongly-typed CoreBooleanField.
|
|
850
|
+
* @throws An error if a node already exists at the path.
|
|
851
|
+
*/
|
|
852
|
+
createBoolean(path: PathType, initialValue: boolean, options?: CoreBooleanFieldOptions): CoreBooleanField;
|
|
853
|
+
/**
|
|
854
|
+
* Creates a new, strongly-typed CoreNumericField.
|
|
855
|
+
* @throws An error if a node already exists at the path.
|
|
856
|
+
*/
|
|
857
|
+
createNumeric(path: PathType, initialValue: number, options?: CoreNumericFieldOptions): CoreNumericField;
|
|
858
|
+
/**
|
|
859
|
+
* Creates a new, strongly-typed CoreStringField.
|
|
860
|
+
* @throws An error if a node already exists at the path.
|
|
861
|
+
*/
|
|
862
|
+
createString(path: PathType, initialValue: string, options?: CoreStringFieldOptions): CoreStringField;
|
|
863
|
+
/**
|
|
864
|
+
* Creates a new, generic CoreField instance for any data type.
|
|
865
|
+
* @throws An error if a node already exists at the path.
|
|
866
|
+
*/
|
|
867
|
+
createGeneric<T>(path: PathType, initialValue: T, options?: FieldOptions<T>): CoreField<T>;
|
|
868
|
+
/**
|
|
869
|
+
* Retrieves a strongly-typed CoreBooleanField instance.
|
|
870
|
+
* @throws An error if the path is invalid or the field is not of the expected type.
|
|
871
|
+
*/
|
|
872
|
+
getBoolean(path: PathType): CoreBooleanField;
|
|
873
|
+
/**
|
|
874
|
+
* Retrieves a strongly-typed CoreNumericField instance.
|
|
875
|
+
* @throws An error if the path is invalid or the field is not of the expected type.
|
|
876
|
+
*/
|
|
877
|
+
getNumeric(path: PathType): CoreNumericField;
|
|
878
|
+
/**
|
|
879
|
+
* Retrieves a strongly-typed CoreStringField instance.
|
|
880
|
+
* @throws An error if the path is invalid or the field is not of the expected type.
|
|
881
|
+
*/
|
|
882
|
+
getString(path: PathType): CoreStringField;
|
|
883
|
+
/**
|
|
884
|
+
* Retrieves a generic CoreField instance.
|
|
885
|
+
* @throws An error if the path is invalid.
|
|
886
|
+
*/
|
|
887
|
+
getGeneric<T>(path: PathType): CoreField<T>;
|
|
888
|
+
/**
|
|
889
|
+
* A generic method to retrieve a Field instance with a specific asserted type.
|
|
890
|
+
* @template TField The expected Field class or interface.
|
|
891
|
+
* @throws An error if the path is invalid or the field cannot be cast to the specified type.
|
|
892
|
+
*/
|
|
893
|
+
getField<TField extends Field<any>>(path: PathType): TField;
|
|
894
|
+
/**
|
|
895
|
+
* Strictly creates a new CoreFields container.
|
|
896
|
+
* Any missing parent nodes in the path will be created automatically.
|
|
897
|
+
* @param path The path where the new Fields container will be created.
|
|
898
|
+
* @returns {CoreFields} The newly created CoreFields instance.
|
|
899
|
+
* @throws An error if a node already exists at the target path.
|
|
900
|
+
*/
|
|
901
|
+
createFields(path: PathType): CoreFields;
|
|
902
|
+
/**
|
|
903
|
+
* Strictly creates a new CoreFieldTree node.
|
|
904
|
+
* Any missing parent nodes in the path will be created automatically.
|
|
905
|
+
* @param path The path where the new FieldTree node will be created.
|
|
906
|
+
* @returns {CoreFieldTree} The newly created CoreFieldTree instance.
|
|
907
|
+
* @throws An error if a node already exists at the target path.
|
|
908
|
+
*/
|
|
909
|
+
createTree(path: PathType): CoreFieldTree;
|
|
910
|
+
/**
|
|
911
|
+
* Retrieves an existing CoreFields container.
|
|
912
|
+
* @param path The path to the Fields container.
|
|
913
|
+
* @returns {CoreFields} The found CoreFields instance.
|
|
914
|
+
* @throws An error if the path is invalid or the node at the path is not a Fields container.
|
|
915
|
+
*/
|
|
916
|
+
getFields(path: PathType): CoreFields;
|
|
917
|
+
/**
|
|
918
|
+
* Retrieves an existing CoreFieldTree node.
|
|
919
|
+
* @param path The path to the FieldTree node.
|
|
920
|
+
* @returns {CoreFieldTree} The found CoreFieldTree instance.
|
|
921
|
+
* @throws An error if the path is invalid or the node at the path is not a FieldTree.
|
|
922
|
+
*/
|
|
923
|
+
getTree(path: PathType): CoreFieldTree;
|
|
924
|
+
/**
|
|
925
|
+
* Removes the node (Field, Fields, or FieldTree) at the end of the specified path.
|
|
926
|
+
* This method does not remove parent nodes if they become empty.
|
|
927
|
+
* @param path The path to the node to remove.
|
|
928
|
+
*/
|
|
929
|
+
remove(path: PathType): void;
|
|
930
|
+
}
|
|
931
|
+
//#endregion
|
|
932
|
+
//#region src/data-store-field-resolver.d.ts
|
|
954
933
|
interface DataStoreFieldResolver {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
}
|
|
967
|
-
|
|
934
|
+
/**
|
|
935
|
+
* The typeName this resolver corresponds to in the FieldRegistry.
|
|
936
|
+
* e.g., 'numeric', 'boolean', 'vector'
|
|
937
|
+
*/
|
|
938
|
+
typeName: string;
|
|
939
|
+
/**
|
|
940
|
+
* Checks if this resolver can handle the given value.
|
|
941
|
+
* @param value The value to check.
|
|
942
|
+
* @returns {boolean} True if the value is supported, otherwise false.
|
|
943
|
+
*/
|
|
944
|
+
supports(value: unknown): boolean;
|
|
945
|
+
}
|
|
946
|
+
//#endregion
|
|
947
|
+
//#region src/data-store.d.ts
|
|
968
948
|
declare class DataStore implements Store {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
|
|
949
|
+
private readonly tree;
|
|
950
|
+
private readonly resolvers;
|
|
951
|
+
private readonly rootFieldsName;
|
|
952
|
+
private _rootFields;
|
|
953
|
+
private get rootFields();
|
|
954
|
+
constructor(tree: CoreFieldTree);
|
|
955
|
+
registerResolver(resolver: DataStoreFieldResolver): void;
|
|
956
|
+
clearResolvers(): void;
|
|
957
|
+
getValue<T>(path: PathType): T;
|
|
958
|
+
setValue<T>(path: PathType, val: T): T;
|
|
959
|
+
createValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
|
|
960
|
+
upsetValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
|
|
961
|
+
createBoolean(path: PathType, initialValue: boolean, options?: CoreBooleanFieldOptions): CoreBooleanField;
|
|
962
|
+
createNumeric(path: PathType, initialValue: number, options?: CoreNumericFieldOptions): CoreNumericField;
|
|
963
|
+
createString(path: PathType, initialValue: string, options?: CoreStringFieldOptions): CoreStringField;
|
|
964
|
+
createGeneric<T>(path: PathType, initialValue: T, options?: FieldOptions<T>): CoreField<T>;
|
|
965
|
+
getBoolean(path: PathType): CoreBooleanField;
|
|
966
|
+
getNumeric(path: PathType): CoreNumericField;
|
|
967
|
+
getString(path: PathType): CoreStringField;
|
|
968
|
+
getGeneric<T>(path: PathType): CoreField<T>;
|
|
969
|
+
getField<TField extends Field<any>>(path: PathType): TField;
|
|
970
|
+
createFields(path: PathType): CoreFields;
|
|
971
|
+
createTree(path: PathType): CoreFieldTree;
|
|
972
|
+
getFields(path: PathType): CoreFields;
|
|
973
|
+
getTree(path: PathType): CoreFieldTree;
|
|
974
|
+
remove(path: PathType): void;
|
|
975
|
+
private isPathToRootFields;
|
|
976
|
+
private getDestinationFields;
|
|
977
|
+
}
|
|
978
|
+
//#endregion
|
|
979
|
+
//#region src/setup.d.ts
|
|
999
980
|
/**
|
|
1000
981
|
* Creates and configures a FieldRegistry with all the core field types.
|
|
1001
982
|
* @returns {FieldRegistry} A pre-configured FieldRegistry instance.
|
|
@@ -1021,16 +1002,17 @@ declare function createCoreTreeNodeFactory(fieldRegistry: FieldRegistry): CoreTr
|
|
|
1021
1002
|
*/
|
|
1022
1003
|
declare function createCoreTreeSerializer(fieldTreeNodeFactory: CoreTreeNodeFactory, policySerializer?: PolicySerializer): FieldTreeSerializer<CoreFields>;
|
|
1023
1004
|
interface CoreFieldSystemConfig {
|
|
1024
|
-
|
|
1025
|
-
|
|
1005
|
+
registry?: FieldRegistry;
|
|
1006
|
+
policySerializer?: PolicySerializer;
|
|
1026
1007
|
}
|
|
1027
1008
|
/**
|
|
1028
1009
|
* Creates a complete core setup for the field system.
|
|
1029
1010
|
* @returns {{factory: CoreTreeNodeFactory, serializer: FieldTreeSerializer<CoreFields>}}
|
|
1030
1011
|
*/
|
|
1031
1012
|
declare function createCoreFieldSystem(config?: CoreFieldSystemConfig): {
|
|
1032
|
-
|
|
1033
|
-
|
|
1013
|
+
factory: CoreTreeNodeFactory;
|
|
1014
|
+
serializer: FieldTreeSerializer<CoreFields>;
|
|
1034
1015
|
};
|
|
1035
|
-
|
|
1036
|
-
export {
|
|
1016
|
+
//#endregion
|
|
1017
|
+
export { BooleanField, ClampMaxPolicy, ClampMaxPolicySerializerHandler, ClampMinPolicy, ClampMinPolicySerializerHandler, ClampPolicy, ClampPolicySerializerHandler, CoreBooleanField, CoreBooleanFieldOptions, CoreField, CoreFieldSystemConfig, CoreFieldTree, CoreFields, CoreFieldsFactory, CoreNumericField, CoreNumericFieldOptions, CoreStringField, CoreStringFieldOptions, CoreTreeNodeFactory, DataStore, Field, FieldOptions, FieldRegistry, FieldSerializer, FieldSnapshot, FieldTree, FieldTreeFactory, FieldTreeSerializer, FieldTreeSnapshot, Fields, FieldsFactory, FieldsSerializer, FieldsSnapshot, NumericField, Policies, Policy, PolicySerializer, PolicySerializerHandler, Store, StoreCreateFieldOptions, StringField, TreeNode, clampMaxPolicy, clampMinPolicy, clampPolicy, createCoreFieldRegistry, createCoreFieldSystem, createCorePolicySerializer, createCoreTreeNodeFactory, createCoreTreeSerializer, createTypedMethodsMixin };
|
|
1018
|
+
//# sourceMappingURL=index.d.mts.map
|