@axi-engine/fields 0.2.2 → 0.3.0

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _axi_engine_utils from '@axi-engine/utils';
2
- import { Subscribable, Constructor, Emitter, PathType } from '@axi-engine/utils';
2
+ import { Constructor, Subscribable, Emitter, PathType } from '@axi-engine/utils';
3
3
 
4
4
  interface Policy<T> {
5
5
  readonly id: string;
@@ -75,6 +75,31 @@ declare class Policies<T> {
75
75
  apply(val: T): T;
76
76
  }
77
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
+
78
103
  interface FieldOptions<T> {
79
104
  policies?: Policy<T>[];
80
105
  }
@@ -114,7 +139,7 @@ interface StringField extends Field<string> {
114
139
  * @template T The type of the value this field holds.
115
140
  *
116
141
  */
117
- declare class DefaultField<T> implements Field<T> {
142
+ declare class CoreField<T> implements Field<T> {
118
143
  /** A type keyword of the field */
119
144
  static readonly typeName: string;
120
145
  readonly typeName: string;
@@ -155,21 +180,21 @@ declare class DefaultField<T> implements Field<T> {
155
180
  destroy(): void;
156
181
  }
157
182
 
158
- interface DefaultBooleanFieldOptions extends FieldOptions<boolean> {
183
+ interface CoreBooleanFieldOptions extends FieldOptions<boolean> {
159
184
  }
160
- declare class DefaultBooleanField extends DefaultField<boolean> implements BooleanField {
185
+ declare class CoreBooleanField extends CoreField<boolean> implements BooleanField {
161
186
  static readonly typeName: string;
162
187
  readonly typeName: string;
163
- constructor(name: string, initialVal: boolean, options?: DefaultBooleanFieldOptions);
188
+ constructor(name: string, initialVal: boolean, options?: CoreBooleanFieldOptions);
164
189
  toggle(): boolean;
165
190
  }
166
191
 
167
- interface DefaultStringFieldOptions extends FieldOptions<string> {
192
+ interface CoreStringFieldOptions extends FieldOptions<string> {
168
193
  }
169
- declare class DefaultStringField extends DefaultField<string> implements StringField {
194
+ declare class CoreStringField extends CoreField<string> implements StringField {
170
195
  static readonly typeName: string;
171
196
  readonly typeName: string;
172
- constructor(name: string, initialVal: string, options?: DefaultStringFieldOptions);
197
+ constructor(name: string, initialVal: string, options?: CoreStringFieldOptions);
173
198
  append(str: string | number): this;
174
199
  prepend(str: string | number): this;
175
200
  trim(): this;
@@ -177,16 +202,16 @@ declare class DefaultStringField extends DefaultField<string> implements StringF
177
202
  clear(): void;
178
203
  }
179
204
 
180
- interface DefaultNumericFieldOptions extends FieldOptions<number> {
205
+ interface CoreNumericFieldOptions extends FieldOptions<number> {
181
206
  min?: number;
182
207
  max?: number;
183
208
  }
184
- declare class DefaultNumericField extends DefaultField<number> implements NumericField {
209
+ declare class CoreNumericField extends CoreField<number> implements NumericField {
185
210
  static readonly typeName: string;
186
211
  readonly typeName: string;
187
212
  get min(): number | undefined;
188
213
  get max(): number | undefined;
189
- constructor(name: string, initialVal: number, options?: DefaultNumericFieldOptions);
214
+ constructor(name: string, initialVal: number, options?: CoreNumericFieldOptions);
190
215
  isMin(): boolean;
191
216
  isMax(): boolean;
192
217
  inc(amount?: number): void;
@@ -314,12 +339,12 @@ declare class Fields {
314
339
  upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
315
340
  /**
316
341
  * Retrieves a field by its name.
317
- * @template T - The expected `Field` type to be returned.
342
+ * @template TField - The expected `Field` type to be returned.
318
343
  * @param {string} name - The name of the field to retrieve.
319
- * @returns {T} The `Field` instance.
344
+ * @returns {TField} The `Field` instance.
320
345
  * @throws If the field does not exist.
321
346
  */
322
- get<T extends Field<any>>(name: string): T;
347
+ get<TField extends Field<any>>(name: string): TField;
323
348
  /**
324
349
  * Removes one or more fields from the collection.
325
350
  * This method ensures that the `destroy` method of each removed field is called to clean up its resources.
@@ -333,133 +358,18 @@ declare class Fields {
333
358
  destroy(): void;
334
359
  }
335
360
 
336
- declare const DefaultFields_base: {
337
- new (...args: any[]): {
338
- createBoolean(name: string, initialValue: boolean, options?: DefaultBooleanFieldOptions): DefaultBooleanField;
339
- upsetBoolean(name: string, value: boolean, options?: DefaultBooleanFieldOptions): DefaultBooleanField;
340
- getBoolean(name: string): DefaultBooleanField;
341
- readonly typeName: "fields";
342
- readonly _fields: Map<string, Field<any>>;
343
- readonly _fieldRegistry: FieldRegistry;
344
- onAdd: _axi_engine_utils.Emitter<[event: {
345
- name: string;
346
- field: Field<any>;
347
- }]>;
348
- onRemove: _axi_engine_utils.Emitter<[event: {
349
- names: string[];
350
- }]>;
351
- get fields(): Map<string, Field<any>>;
352
- has(name: string): boolean;
353
- add<T extends Field<any>>(field: Field<any>): T;
354
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
355
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
356
- get<T extends Field<any>>(name: string): T;
357
- remove(names: string | string[]): void;
358
- clear(): void;
359
- destroy(): void;
360
- };
361
- } & {
362
- new (...args: any[]): {
363
- createString(name: string, initialValue: string, options?: DefaultStringFieldOptions): DefaultStringField;
364
- upsetString(name: string, value: string, options?: DefaultStringFieldOptions): DefaultStringField;
365
- getString(name: string): DefaultStringField;
366
- readonly typeName: "fields";
367
- readonly _fields: Map<string, Field<any>>;
368
- readonly _fieldRegistry: FieldRegistry;
369
- onAdd: _axi_engine_utils.Emitter<[event: {
370
- name: string;
371
- field: Field<any>;
372
- }]>;
373
- onRemove: _axi_engine_utils.Emitter<[event: {
374
- names: string[];
375
- }]>;
376
- get fields(): Map<string, Field<any>>;
377
- has(name: string): boolean;
378
- add<T extends Field<any>>(field: Field<any>): T;
379
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
380
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
381
- get<T extends Field<any>>(name: string): T;
382
- remove(names: string | string[]): void;
383
- clear(): void;
384
- destroy(): void;
385
- };
386
- } & {
387
- new (...args: any[]): {
388
- createNumeric(name: string, initialValue: number, options?: DefaultNumericFieldOptions): DefaultNumericField;
389
- upsetNumeric(name: string, value: number, options?: DefaultNumericFieldOptions): DefaultNumericField;
390
- getNumeric(name: string): DefaultNumericField;
391
- readonly typeName: "fields";
392
- readonly _fields: Map<string, Field<any>>;
393
- readonly _fieldRegistry: FieldRegistry;
394
- onAdd: _axi_engine_utils.Emitter<[event: {
395
- name: string;
396
- field: Field<any>;
397
- }]>;
398
- onRemove: _axi_engine_utils.Emitter<[event: {
399
- names: string[];
400
- }]>;
401
- get fields(): Map<string, Field<any>>;
402
- has(name: string): boolean;
403
- add<T extends Field<any>>(field: Field<any>): T;
404
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
405
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
406
- get<T extends Field<any>>(name: string): T;
407
- remove(names: string | string[]): void;
408
- clear(): void;
409
- destroy(): void;
410
- };
411
- } & {
412
- new (...args: any[]): {
413
- createGeneric<T>(name: string, initialValue: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
414
- upsetGeneric<T>(name: string, value: T, options?: FieldOptions<T> | undefined): DefaultField<T>;
415
- getGeneric<T>(name: string): DefaultField<T>;
416
- readonly typeName: "fields";
417
- readonly _fields: Map<string, Field<any>>;
418
- readonly _fieldRegistry: FieldRegistry;
419
- onAdd: _axi_engine_utils.Emitter<[event: {
420
- name: string;
421
- field: Field<any>;
422
- }]>;
423
- onRemove: _axi_engine_utils.Emitter<[event: {
424
- names: string[];
425
- }]>;
426
- get fields(): Map<string, Field<any>>;
427
- has(name: string): boolean;
428
- add<T extends Field<any>>(field: Field<any>): T;
429
- create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
430
- upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
431
- get<T extends Field<any>>(name: string): T;
432
- remove(names: string | string[]): void;
433
- clear(): void;
434
- destroy(): void;
435
- };
436
- } & typeof Fields;
437
- declare class DefaultFields extends DefaultFields_base {
438
- }
439
-
440
361
  interface FieldsFactory<TFields extends Fields> {
441
362
  fields(): TFields;
442
363
  }
443
- declare class DefaultFieldsFactory implements FieldsFactory<DefaultFields> {
444
- private readonly fieldRegistry;
445
- constructor(fieldRegistry: FieldRegistry);
446
- fields(): DefaultFields;
447
- }
364
+
448
365
  /**
449
366
  * Defines the contract for a factory that creates nodes for a FieldTree.
450
367
  * This allows for custom implementations of Fields and FieldTree to be used.
451
368
  */
452
- interface TreeNodeFactory<TFields extends Fields> extends FieldsFactory<TFields> {
369
+ interface FieldTreeFactory<TFields extends Fields> extends FieldsFactory<TFields> {
453
370
  fields(): TFields;
454
371
  tree(): FieldTree<TFields>;
455
372
  }
456
- /**
457
- * The default factory implementation that creates standard DefaultFields and FieldTree instances.
458
- */
459
- declare class DefaultTreeNodeFactory extends DefaultFieldsFactory implements TreeNodeFactory<DefaultFields> {
460
- constructor(fieldRegistry: FieldRegistry);
461
- tree(): FieldTree<DefaultFields>;
462
- }
463
373
 
464
374
  /** A type alias for any container that can be a child node in a FieldTree */
465
375
  type TreeNode<F extends Fields> = FieldTree<F> | F;
@@ -513,9 +423,9 @@ declare class FieldTree<TFields extends Fields> {
513
423
  get nodes(): Map<string, TreeNode<TFields>>;
514
424
  /**
515
425
  * Creates an instance of FieldTree.
516
- * @param {TreeNodeFactory} factory - A factory responsible for creating new nodes within the tree.
426
+ * @param {FieldTreeFactory} factory - A factory responsible for creating new nodes within the tree.
517
427
  */
518
- constructor(factory: TreeNodeFactory<TFields>);
428
+ constructor(factory: FieldTreeFactory<TFields>);
519
429
  /**
520
430
  * Checks if a direct child node with the given name exists.
521
431
  * @param {string} name - The name of the direct child node.
@@ -595,7 +505,14 @@ declare class FieldTree<TFields extends Fields> {
595
505
  * @param {PathType} path - The path to the `Fields` container.
596
506
  * @returns {Fields} The existing or newly created `Fields` instance.
597
507
  */
598
- getOrCreateFields(path: PathType): Fields;
508
+ getOrCreateFields(path: PathType): TFields;
509
+ /**
510
+ * Finds the parent node for a given path.
511
+ * @param path The path to the target node.
512
+ * @returns The parent node (either a FieldTree or Fields).
513
+ * @throws An error if the path is invalid or any intermediate node is not a FieldTree.
514
+ */
515
+ findParentNode(path: PathType): FieldTree<TFields> | TFields;
599
516
  /**
600
517
  * Removes all child nodes from this tree branch.
601
518
  * This method ensures that `destroy()` is called on each child node, allowing for
@@ -622,6 +539,69 @@ declare class FieldTree<TFields extends Fields> {
622
539
  private traversePath;
623
540
  }
624
541
 
542
+ declare const CoreFields_base: _axi_engine_utils.Constructor<{
543
+ createGeneric<T>(name: string, initialValue: T, options?: FieldOptions<T> | undefined): CoreField<T>;
544
+ upsetGeneric<T>(name: string, value: T, options?: FieldOptions<T> | undefined): CoreField<T>;
545
+ getGeneric<T>(name: string): CoreField<T>;
546
+ readonly typeName: "fields";
547
+ readonly _fields: Map<string, Field<any>>;
548
+ readonly _fieldRegistry: FieldRegistry;
549
+ onAdd: _axi_engine_utils.Emitter<[event: {
550
+ name: string;
551
+ field: Field<any>;
552
+ }]>;
553
+ onRemove: _axi_engine_utils.Emitter<[event: {
554
+ names: string[];
555
+ }]>;
556
+ get fields(): Map<string, Field<any>>;
557
+ has(name: string): boolean;
558
+ add<T extends Field<any>>(field: Field<any>): T;
559
+ create<T extends Field<any>>(typeName: string, name: string, initialValue: any, options?: any): T;
560
+ upset<T extends Field<any>>(typeName: string, name: string, value: any, options?: any): T;
561
+ get<TField extends Field<any>>(name: string): TField;
562
+ remove(names: string | string[]): void;
563
+ clear(): void;
564
+ destroy(): void;
565
+ } & Fields & {
566
+ createNumeric: (name: string, initialValue: number, options?: CoreNumericFieldOptions | undefined) => CoreNumericField;
567
+ } & {
568
+ upsetNumeric: (name: string, value: number, options?: CoreNumericFieldOptions | undefined) => CoreNumericField;
569
+ } & {
570
+ getNumeric: (name: string) => CoreNumericField;
571
+ } & {
572
+ createString: (name: string, initialValue: string, options?: CoreStringFieldOptions | undefined) => CoreStringField;
573
+ } & {
574
+ upsetString: (name: string, value: string, options?: CoreStringFieldOptions | undefined) => CoreStringField;
575
+ } & {
576
+ getString: (name: string) => CoreStringField;
577
+ } & {
578
+ createBoolean: (name: string, initialValue: boolean, options?: CoreBooleanFieldOptions | undefined) => CoreBooleanField;
579
+ } & {
580
+ upsetBoolean: (name: string, value: boolean, options?: CoreBooleanFieldOptions | undefined) => CoreBooleanField;
581
+ } & {
582
+ getBoolean: (name: string) => CoreBooleanField;
583
+ }>;
584
+ declare class CoreFields extends CoreFields_base {
585
+ }
586
+
587
+ declare class CoreFieldsFactory implements FieldsFactory<CoreFields> {
588
+ protected readonly _fieldRegistry: FieldRegistry;
589
+ get fieldRegistry(): FieldRegistry;
590
+ constructor(fieldRegistry: FieldRegistry);
591
+ fields(): CoreFields;
592
+ }
593
+
594
+ declare class CoreFieldTree extends FieldTree<CoreFields> {
595
+ }
596
+
597
+ /**
598
+ * The default factory implementation that creates standard DefaultFields and FieldTree instances.
599
+ */
600
+ declare class CoreTreeNodeFactory extends CoreFieldsFactory implements FieldTreeFactory<CoreFields> {
601
+ constructor(fieldRegistry: FieldRegistry);
602
+ tree(): CoreFieldTree;
603
+ }
604
+
625
605
  /**
626
606
  * Defines the contract for a handler that can serialize and deserialize a specific type of Policy.
627
607
  * @template T - The specific Policy class this handler manages.
@@ -825,7 +805,7 @@ interface FieldTreeSnapshot {
825
805
  declare class FieldTreeSerializer<TFields extends Fields> {
826
806
  private readonly fieldTreeNodeFactory;
827
807
  private readonly fieldsSerializer;
828
- constructor(fieldTreeNodeFactory: TreeNodeFactory<TFields>, fieldsSerializer: FieldsSerializer<TFields>);
808
+ constructor(fieldTreeNodeFactory: FieldTreeFactory<TFields>, fieldsSerializer: FieldsSerializer<TFields>);
829
809
  /**
830
810
  * Creates a serializable snapshot of the entire tree and its contained fields.
831
811
  * @returns A plain JavaScript object representing the complete state managed by this tree.
@@ -839,4 +819,218 @@ declare class FieldTreeSerializer<TFields extends Fields> {
839
819
  hydrate(snapshot: FieldTreeSnapshot): FieldTree<TFields>;
840
820
  }
841
821
 
842
- export { type BooleanField, ClampMaxPolicy, ClampMaxPolicySerializerHandler, ClampMinPolicy, ClampMinPolicySerializerHandler, ClampPolicy, ClampPolicySerializerHandler, DefaultBooleanField, type DefaultBooleanFieldOptions, DefaultField, DefaultFields, DefaultFieldsFactory, DefaultNumericField, type DefaultNumericFieldOptions, DefaultStringField, type DefaultStringFieldOptions, DefaultTreeNodeFactory, type Field, type FieldOptions, FieldRegistry, FieldSerializer, type FieldSnapshot, FieldTree, FieldTreeSerializer, type FieldTreeSnapshot, Fields, type FieldsFactory, FieldsSerializer, type FieldsSnapshot, type NumericField, Policies, type Policy, PolicySerializer, type PolicySerializerHandler, type StringField, type TreeNode, type TreeNodeFactory, clampMaxPolicy, clampMinPolicy, clampPolicy };
822
+ interface StoreCreateFieldOptions {
823
+ /** Allows to explicitly specify the field type, overriding the automatic type detection. */
824
+ fieldType?: string;
825
+ }
826
+ /**
827
+ * Defines the primary high-level API for interacting with the state management system.
828
+ * It acts as a facade, simplifying access to the underlying FieldTree and providing
829
+ * both type-safe and dynamic methods for manipulating data.
830
+ */
831
+ interface Store {
832
+ /**
833
+ * Retrieves the raw value of a Field at a specific path.
834
+ * @template T The expected type of the value.
835
+ * @param path The path to the field (e.g., 'player.stats.hp').
836
+ * @returns {T} The raw value stored in the field.
837
+ * @throws An error if the path is invalid or no field exists at the path.
838
+ */
839
+ getValue<T>(path: PathType): T;
840
+ /**
841
+ * Strictly sets the value of an *existing* Field at a specific path.
842
+ * @template T The type of the value being set.
843
+ * @param path The path to the existing field.
844
+ * @param val The new value to set.
845
+ * @returns {T} The value that was set.
846
+ * @throws An error if no field exists at the specified path.
847
+ */
848
+ setValue<T>(path: PathType, val: T): T;
849
+ /**
850
+ * Creates a new Field at a specified path, inferring its type from the provided value.
851
+ * This is a strict operation and will fail if a node already exists at the target path.
852
+ * @template T The type of the initial value.
853
+ * @param path The full path where the new field will be created.
854
+ * @param val The initial value for the field.
855
+ * @param options Optional configuration, including policies and the ability to override field type.
856
+ * @returns {T} value of the newly created Field instance.
857
+ * @throws An error if a node already exists at the path or if the parent path is invalid.
858
+ */
859
+ createValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
860
+ /**
861
+ * Creates new or update a Field at a specified path, inferring its type from the provided value.
862
+ * @template T The type of the initial value.
863
+ * @param path The full path where the new field will be created.
864
+ * @param val The initial value for the field.
865
+ * @param options Optional configuration, including policies and the ability to override field type.
866
+ * @returns {T} value of the newly created Field instance.
867
+ * @throws An error if a node already exists at the path or if the parent path is invalid.
868
+ */
869
+ upsetValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
870
+ /**
871
+ * Creates a new, strongly-typed CoreBooleanField.
872
+ * @throws An error if a node already exists at the path.
873
+ */
874
+ createBoolean(path: PathType, initialValue: boolean, options?: CoreBooleanFieldOptions): CoreBooleanField;
875
+ /**
876
+ * Creates a new, strongly-typed CoreNumericField.
877
+ * @throws An error if a node already exists at the path.
878
+ */
879
+ createNumeric(path: PathType, initialValue: number, options?: CoreNumericFieldOptions): CoreNumericField;
880
+ /**
881
+ * Creates a new, strongly-typed CoreStringField.
882
+ * @throws An error if a node already exists at the path.
883
+ */
884
+ createString(path: PathType, initialValue: string, options?: CoreStringFieldOptions): CoreStringField;
885
+ /**
886
+ * Creates a new, generic CoreField instance for any data type.
887
+ * @throws An error if a node already exists at the path.
888
+ */
889
+ createGeneric<T>(path: PathType, initialValue: T, options?: FieldOptions<T>): CoreField<T>;
890
+ /**
891
+ * Retrieves a strongly-typed CoreBooleanField instance.
892
+ * @throws An error if the path is invalid or the field is not of the expected type.
893
+ */
894
+ getBoolean(path: PathType): CoreBooleanField;
895
+ /**
896
+ * Retrieves a strongly-typed CoreNumericField instance.
897
+ * @throws An error if the path is invalid or the field is not of the expected type.
898
+ */
899
+ getNumeric(path: PathType): CoreNumericField;
900
+ /**
901
+ * Retrieves a strongly-typed CoreStringField instance.
902
+ * @throws An error if the path is invalid or the field is not of the expected type.
903
+ */
904
+ getString(path: PathType): CoreStringField;
905
+ /**
906
+ * Retrieves a generic CoreField instance.
907
+ * @throws An error if the path is invalid.
908
+ */
909
+ getGeneric<T>(path: PathType): CoreField<T>;
910
+ /**
911
+ * A generic method to retrieve a Field instance with a specific asserted type.
912
+ * @template TField The expected Field class or interface.
913
+ * @throws An error if the path is invalid or the field cannot be cast to the specified type.
914
+ */
915
+ getField<TField extends Field<any>>(path: PathType): TField;
916
+ /**
917
+ * Strictly creates a new CoreFields container.
918
+ * Any missing parent nodes in the path will be created automatically.
919
+ * @param path The path where the new Fields container will be created.
920
+ * @returns {CoreFields} The newly created CoreFields instance.
921
+ * @throws An error if a node already exists at the target path.
922
+ */
923
+ createFields(path: PathType): CoreFields;
924
+ /**
925
+ * Strictly creates a new CoreFieldTree node.
926
+ * Any missing parent nodes in the path will be created automatically.
927
+ * @param path The path where the new FieldTree node will be created.
928
+ * @returns {CoreFieldTree} The newly created CoreFieldTree instance.
929
+ * @throws An error if a node already exists at the target path.
930
+ */
931
+ createTree(path: PathType): CoreFieldTree;
932
+ /**
933
+ * Retrieves an existing CoreFields container.
934
+ * @param path The path to the Fields container.
935
+ * @returns {CoreFields} The found CoreFields instance.
936
+ * @throws An error if the path is invalid or the node at the path is not a Fields container.
937
+ */
938
+ getFields(path: PathType): CoreFields;
939
+ /**
940
+ * Retrieves an existing CoreFieldTree node.
941
+ * @param path The path to the FieldTree node.
942
+ * @returns {CoreFieldTree} The found CoreFieldTree instance.
943
+ * @throws An error if the path is invalid or the node at the path is not a FieldTree.
944
+ */
945
+ getTree(path: PathType): CoreFieldTree;
946
+ /**
947
+ * Removes the node (Field, Fields, or FieldTree) at the end of the specified path.
948
+ * This method does not remove parent nodes if they become empty.
949
+ * @param path The path to the node to remove.
950
+ */
951
+ remove(path: PathType): void;
952
+ }
953
+
954
+ interface DataStoreFieldResolver {
955
+ /**
956
+ * The typeName this resolver corresponds to in the FieldRegistry.
957
+ * e.g., 'numeric', 'boolean', 'vector'
958
+ */
959
+ typeName: string;
960
+ /**
961
+ * Checks if this resolver can handle the given value.
962
+ * @param value The value to check.
963
+ * @returns {boolean} True if the value is supported, otherwise false.
964
+ */
965
+ supports(value: unknown): boolean;
966
+ }
967
+
968
+ declare class DataStore implements Store {
969
+ private readonly tree;
970
+ private readonly resolvers;
971
+ private readonly rootFieldsName;
972
+ private _rootFields;
973
+ private get rootFields();
974
+ constructor(tree: CoreFieldTree);
975
+ registerResolver(resolver: DataStoreFieldResolver): void;
976
+ clearResolvers(): void;
977
+ getValue<T>(path: PathType): T;
978
+ setValue<T>(path: PathType, val: T): T;
979
+ createValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
980
+ upsetValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
981
+ createBoolean(path: PathType, initialValue: boolean, options?: CoreBooleanFieldOptions): CoreBooleanField;
982
+ createNumeric(path: PathType, initialValue: number, options?: CoreNumericFieldOptions): CoreNumericField;
983
+ createString(path: PathType, initialValue: string, options?: CoreStringFieldOptions): CoreStringField;
984
+ createGeneric<T>(path: PathType, initialValue: T, options?: FieldOptions<T>): CoreField<T>;
985
+ getBoolean(path: PathType): CoreBooleanField;
986
+ getNumeric(path: PathType): CoreNumericField;
987
+ getString(path: PathType): CoreStringField;
988
+ getGeneric<T>(path: PathType): CoreField<T>;
989
+ getField<TField extends Field<any>>(path: PathType): TField;
990
+ createFields(path: PathType): CoreFields;
991
+ createTree(path: PathType): CoreFieldTree;
992
+ getFields(path: PathType): CoreFields;
993
+ getTree(path: PathType): CoreFieldTree;
994
+ remove(path: PathType): void;
995
+ private isPathToRootFields;
996
+ private getDestinationFields;
997
+ }
998
+
999
+ /**
1000
+ * Creates and configures a FieldRegistry with all the core field types.
1001
+ * @returns {FieldRegistry} A pre-configured FieldRegistry instance.
1002
+ */
1003
+ declare function createCoreFieldRegistry(): FieldRegistry;
1004
+ /**
1005
+ * Creates and configures a PolicySerializer with handlers for core policies.
1006
+ * @returns {PolicySerializer} A pre-configured PolicySerializer instance.
1007
+ */
1008
+ declare function createCorePolicySerializer(): PolicySerializer;
1009
+ /**
1010
+ * Creates a factory for CoreFieldTree and CoreFields nodes.
1011
+ * @param {FieldRegistry} fieldRegistry - The registry to be used by the factory.
1012
+ * @returns {CoreTreeNodeFactory} A new CoreTreeNodeFactory instance.
1013
+ */
1014
+ declare function createCoreTreeNodeFactory(fieldRegistry: FieldRegistry): CoreTreeNodeFactory;
1015
+ /**
1016
+ * Creates a fully configured serializer for a FieldTree.
1017
+ * This function composes all necessary serializers (FieldTree, Fields, Field) for a complete setup.
1018
+ * @param {CoreTreeNodeFactory} fieldTreeNodeFactory - The factory used to create new tree nodes during deserialization.
1019
+ * @param policySerializer
1020
+ * @returns {FieldTreeSerializer<CoreFields>} A top-level serializer for the entire field tree.
1021
+ */
1022
+ declare function createCoreTreeSerializer(fieldTreeNodeFactory: CoreTreeNodeFactory, policySerializer?: PolicySerializer): FieldTreeSerializer<CoreFields>;
1023
+ interface CoreFieldSystemConfig {
1024
+ registry?: FieldRegistry;
1025
+ policySerializer?: PolicySerializer;
1026
+ }
1027
+ /**
1028
+ * Creates a complete core setup for the field system.
1029
+ * @returns {{factory: CoreTreeNodeFactory, serializer: FieldTreeSerializer<CoreFields>}}
1030
+ */
1031
+ declare function createCoreFieldSystem(config?: CoreFieldSystemConfig): {
1032
+ factory: CoreTreeNodeFactory;
1033
+ serializer: FieldTreeSerializer<CoreFields>;
1034
+ };
1035
+
1036
+ 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 };