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