@axi-engine/fields 0.3.4 → 0.3.6

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 (157) hide show
  1. package/dist/index.d.ts +997 -18
  2. package/dist/index.js +1228 -18
  3. package/package.json +3 -3
  4. package/dist/core-field-tree-factory.d.ts +0 -13
  5. package/dist/core-field-tree-factory.d.ts.map +0 -1
  6. package/dist/core-field-tree-factory.js +0 -14
  7. package/dist/core-field-tree-factory.js.map +0 -1
  8. package/dist/core-field-tree.d.ts +0 -5
  9. package/dist/core-field-tree.d.ts.map +0 -1
  10. package/dist/core-field-tree.js +0 -4
  11. package/dist/core-field-tree.js.map +0 -1
  12. package/dist/core-fields-factory.d.ts +0 -10
  13. package/dist/core-fields-factory.d.ts.map +0 -1
  14. package/dist/core-fields-factory.js +0 -14
  15. package/dist/core-fields-factory.js.map +0 -1
  16. package/dist/core-fields.d.ts +0 -47
  17. package/dist/core-fields.d.ts.map +0 -1
  18. package/dist/core-fields.js +0 -8
  19. package/dist/core-fields.js.map +0 -1
  20. package/dist/data-store-field-resolver.d.ts +0 -26
  21. package/dist/data-store-field-resolver.d.ts.map +0 -1
  22. package/dist/data-store-field-resolver.js +0 -21
  23. package/dist/data-store-field-resolver.js.map +0 -1
  24. package/dist/data-store.d.ts +0 -38
  25. package/dist/data-store.d.ts.map +0 -1
  26. package/dist/data-store.js +0 -141
  27. package/dist/data-store.js.map +0 -1
  28. package/dist/field-definitions/core-boolean-field.d.ts +0 -11
  29. package/dist/field-definitions/core-boolean-field.d.ts.map +0 -1
  30. package/dist/field-definitions/core-boolean-field.js +0 -13
  31. package/dist/field-definitions/core-boolean-field.js.map +0 -1
  32. package/dist/field-definitions/core-field.d.ts +0 -51
  33. package/dist/field-definitions/core-field.d.ts.map +0 -1
  34. package/dist/field-definitions/core-field.js +0 -74
  35. package/dist/field-definitions/core-field.js.map +0 -1
  36. package/dist/field-definitions/core-numeric-field.d.ts +0 -18
  37. package/dist/field-definitions/core-numeric-field.d.ts.map +0 -1
  38. package/dist/field-definitions/core-numeric-field.js +0 -45
  39. package/dist/field-definitions/core-numeric-field.js.map +0 -1
  40. package/dist/field-definitions/core-string-field.d.ts +0 -15
  41. package/dist/field-definitions/core-string-field.d.ts.map +0 -1
  42. package/dist/field-definitions/core-string-field.js +0 -27
  43. package/dist/field-definitions/core-string-field.js.map +0 -1
  44. package/dist/field-definitions/index.d.ts +0 -5
  45. package/dist/field-definitions/index.d.ts.map +0 -1
  46. package/dist/field-definitions/index.js +0 -5
  47. package/dist/field-definitions/index.js.map +0 -1
  48. package/dist/field-registry.d.ts +0 -5
  49. package/dist/field-registry.d.ts.map +0 -1
  50. package/dist/field-registry.js +0 -4
  51. package/dist/field-registry.js.map +0 -1
  52. package/dist/field-tree-factory.d.ts +0 -12
  53. package/dist/field-tree-factory.d.ts.map +0 -1
  54. package/dist/field-tree-factory.js +0 -2
  55. package/dist/field-tree-factory.js.map +0 -1
  56. package/dist/field-tree.d.ts +0 -171
  57. package/dist/field-tree.d.ts.map +0 -1
  58. package/dist/field-tree.js +0 -248
  59. package/dist/field-tree.js.map +0 -1
  60. package/dist/field.d.ts +0 -34
  61. package/dist/field.d.ts.map +0 -1
  62. package/dist/field.js +0 -2
  63. package/dist/field.js.map +0 -1
  64. package/dist/fields-factory.d.ts +0 -5
  65. package/dist/fields-factory.d.ts.map +0 -1
  66. package/dist/fields-factory.js +0 -2
  67. package/dist/fields-factory.js.map +0 -1
  68. package/dist/fields.d.ts +0 -101
  69. package/dist/fields.d.ts.map +0 -1
  70. package/dist/fields.js +0 -143
  71. package/dist/fields.js.map +0 -1
  72. package/dist/index.d.ts.map +0 -1
  73. package/dist/index.js.map +0 -1
  74. package/dist/mixins/mixin-factory.d.ts +0 -29
  75. package/dist/mixins/mixin-factory.d.ts.map +0 -1
  76. package/dist/mixins/mixin-factory.js +0 -32
  77. package/dist/mixins/mixin-factory.js.map +0 -1
  78. package/dist/mixins/with-boolean-fields.mixin.d.ts +0 -9
  79. package/dist/mixins/with-boolean-fields.mixin.d.ts.map +0 -1
  80. package/dist/mixins/with-boolean-fields.mixin.js +0 -4
  81. package/dist/mixins/with-boolean-fields.mixin.js.map +0 -1
  82. package/dist/mixins/with-default-generic-fields.mixin.d.ts +0 -31
  83. package/dist/mixins/with-default-generic-fields.mixin.d.ts.map +0 -1
  84. package/dist/mixins/with-default-generic-fields.mixin.js +0 -15
  85. package/dist/mixins/with-default-generic-fields.mixin.js.map +0 -1
  86. package/dist/mixins/with-numeric-fields.mixin.d.ts +0 -9
  87. package/dist/mixins/with-numeric-fields.mixin.d.ts.map +0 -1
  88. package/dist/mixins/with-numeric-fields.mixin.js +0 -4
  89. package/dist/mixins/with-numeric-fields.mixin.js.map +0 -1
  90. package/dist/mixins/with-string-fields.mixin.d.ts +0 -9
  91. package/dist/mixins/with-string-fields.mixin.d.ts.map +0 -1
  92. package/dist/mixins/with-string-fields.mixin.js +0 -4
  93. package/dist/mixins/with-string-fields.mixin.js.map +0 -1
  94. package/dist/policies/clamp-max-policy.d.ts +0 -11
  95. package/dist/policies/clamp-max-policy.d.ts.map +0 -1
  96. package/dist/policies/clamp-max-policy.js +0 -18
  97. package/dist/policies/clamp-max-policy.js.map +0 -1
  98. package/dist/policies/clamp-min-policy.d.ts +0 -11
  99. package/dist/policies/clamp-min-policy.d.ts.map +0 -1
  100. package/dist/policies/clamp-min-policy.js +0 -18
  101. package/dist/policies/clamp-min-policy.js.map +0 -1
  102. package/dist/policies/clamp-policy.d.ts +0 -12
  103. package/dist/policies/clamp-policy.d.ts.map +0 -1
  104. package/dist/policies/clamp-policy.js +0 -21
  105. package/dist/policies/clamp-policy.js.map +0 -1
  106. package/dist/policies/index.d.ts +0 -6
  107. package/dist/policies/index.d.ts.map +0 -1
  108. package/dist/policies/index.js +0 -6
  109. package/dist/policies/index.js.map +0 -1
  110. package/dist/policies/policies.d.ts +0 -38
  111. package/dist/policies/policies.d.ts.map +0 -1
  112. package/dist/policies/policies.js +0 -62
  113. package/dist/policies/policies.js.map +0 -1
  114. package/dist/policies/policy.d.ts +0 -6
  115. package/dist/policies/policy.d.ts.map +0 -1
  116. package/dist/policies/policy.js +0 -2
  117. package/dist/policies/policy.js.map +0 -1
  118. package/dist/serializer/field-serializer.d.ts +0 -52
  119. package/dist/serializer/field-serializer.d.ts.map +0 -1
  120. package/dist/serializer/field-serializer.js +0 -66
  121. package/dist/serializer/field-serializer.js.map +0 -1
  122. package/dist/serializer/field-tree-serializer.d.ts +0 -50
  123. package/dist/serializer/field-tree-serializer.d.ts.map +0 -1
  124. package/dist/serializer/field-tree-serializer.js +0 -68
  125. package/dist/serializer/field-tree-serializer.js.map +0 -1
  126. package/dist/serializer/fields-serializer.d.ts +0 -49
  127. package/dist/serializer/fields-serializer.d.ts.map +0 -1
  128. package/dist/serializer/fields-serializer.js +0 -57
  129. package/dist/serializer/fields-serializer.js.map +0 -1
  130. package/dist/serializer/index.d.ts +0 -8
  131. package/dist/serializer/index.d.ts.map +0 -1
  132. package/dist/serializer/index.js +0 -8
  133. package/dist/serializer/index.js.map +0 -1
  134. package/dist/serializer/policies/clamp-max-policy-serializer-handler.d.ts +0 -13
  135. package/dist/serializer/policies/clamp-max-policy-serializer-handler.d.ts.map +0 -1
  136. package/dist/serializer/policies/clamp-max-policy-serializer-handler.js +0 -10
  137. package/dist/serializer/policies/clamp-max-policy-serializer-handler.js.map +0 -1
  138. package/dist/serializer/policies/clamp-min-policy-serializer-handler.d.ts +0 -13
  139. package/dist/serializer/policies/clamp-min-policy-serializer-handler.d.ts.map +0 -1
  140. package/dist/serializer/policies/clamp-min-policy-serializer-handler.js +0 -10
  141. package/dist/serializer/policies/clamp-min-policy-serializer-handler.js.map +0 -1
  142. package/dist/serializer/policies/clamp-policy-serializer-handler.d.ts +0 -16
  143. package/dist/serializer/policies/clamp-policy-serializer-handler.d.ts.map +0 -1
  144. package/dist/serializer/policies/clamp-policy-serializer-handler.js +0 -10
  145. package/dist/serializer/policies/clamp-policy-serializer-handler.js.map +0 -1
  146. package/dist/serializer/policy-serializer.d.ts +0 -41
  147. package/dist/serializer/policy-serializer.d.ts.map +0 -1
  148. package/dist/serializer/policy-serializer.js +0 -43
  149. package/dist/serializer/policy-serializer.js.map +0 -1
  150. package/dist/setup.d.ts +0 -41
  151. package/dist/setup.d.ts.map +0 -1
  152. package/dist/setup.js +0 -57
  153. package/dist/setup.js.map +0 -1
  154. package/dist/store.d.ts +0 -137
  155. package/dist/store.d.ts.map +0 -1
  156. package/dist/store.js +0 -2
  157. package/dist/store.js.map +0 -1
@@ -1,10 +0,0 @@
1
- import { ClampPolicy } from '../../policies';
2
- export class ClampPolicySerializerHandler {
3
- snapshot(policy) {
4
- return { min: policy.min, max: policy.max };
5
- }
6
- hydrate(data) {
7
- return new ClampPolicy(data.min, data.max);
8
- }
9
- }
10
- //# sourceMappingURL=clamp-policy-serializer-handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clamp-policy-serializer-handler.js","sourceRoot":"","sources":["../../../src/serializer/policies/clamp-policy-serializer-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAG3C,MAAM,OAAO,4BAA4B;IACvC,QAAQ,CAAC,MAAmB;QAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;IAC9C,CAAC;IAED,OAAO,CAAC,IAAkC;QACxC,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;CACF"}
@@ -1,41 +0,0 @@
1
- import { Policy } from '../policies';
2
- /**
3
- * Defines the contract for a handler that can serialize and deserialize a specific type of Policy.
4
- * @template T - The specific Policy class this handler manages.
5
- * @template S - The shape of the plain object this handler produces/consumes.
6
- */
7
- export interface PolicySerializerHandler<T extends Policy<any>, S extends object> {
8
- /**
9
- * Converts a Policy instance into a serializable plain object.
10
- * @param policy The Policy instance to serialize.
11
- * @returns A plain object representing the policy's state.
12
- */
13
- snapshot(policy: T): S;
14
- /**
15
- * Creates a new Policy instance from a plain object.
16
- * @param snapshotData The plain object containing the policy's state.
17
- * @returns A new instance of the Policy.
18
- */
19
- hydrate(snapshotData: S): T;
20
- }
21
- export declare class PolicySerializer {
22
- private readonly handlers;
23
- register(policyId: string, handler: PolicySerializerHandler<any, any>): this;
24
- clearHandlers(): void;
25
- /**
26
- * Creates a serializable snapshot of a policy instance.
27
- * The snapshot includes the policy's state and a `__type` identifier.
28
- * @param policy The policy instance to snapshot.
29
- * @returns A plain object ready for JSON serialization.
30
- * @throws If no handler is registered for the policy's ID.
31
- */
32
- snapshot(policy: Policy<any>): object;
33
- /**
34
- * Restores a policy instance from its snapshot representation.
35
- * @param snapshot The plain object snapshot, which must contain a `__type` property.
36
- * @returns A new, fully functional policy instance.
37
- * @throws If the snapshot is invalid or no handler is registered for its `__type`.
38
- */
39
- hydrate(snapshot: any): Policy<any>;
40
- }
41
- //# sourceMappingURL=policy-serializer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"policy-serializer.d.ts","sourceRoot":"","sources":["../../src/serializer/policy-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAGnC;;;;GAIG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,MAAM;IAC9E;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IAEvB;;;;OAIG;IACH,OAAO,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC;CAC7B;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwD;IAEjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,CAAC;IAMrE,aAAa;IAIb;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM;IAWrC;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,EAAE,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;CASpC"}
@@ -1,43 +0,0 @@
1
- import { throwIf, throwIfEmpty } from '@axi-engine/utils';
2
- export class PolicySerializer {
3
- handlers = new Map();
4
- register(policyId, handler) {
5
- throwIf(this.handlers.has(policyId), `A handler for policy ID '${policyId}' is already registered.`);
6
- this.handlers.set(policyId, handler);
7
- return this;
8
- }
9
- clearHandlers() {
10
- this.handlers.clear();
11
- }
12
- /**
13
- * Creates a serializable snapshot of a policy instance.
14
- * The snapshot includes the policy's state and a `__type` identifier.
15
- * @param policy The policy instance to snapshot.
16
- * @returns A plain object ready for JSON serialization.
17
- * @throws If no handler is registered for the policy's ID.
18
- */
19
- snapshot(policy) {
20
- const handler = this.handlers.get(policy.id);
21
- throwIfEmpty(handler, `No serializer handler registered for policy ID: '${policy.id}'`);
22
- const data = handler.snapshot(policy);
23
- return {
24
- __type: policy.id,
25
- ...data
26
- };
27
- }
28
- /**
29
- * Restores a policy instance from its snapshot representation.
30
- * @param snapshot The plain object snapshot, which must contain a `__type` property.
31
- * @returns A new, fully functional policy instance.
32
- * @throws If the snapshot is invalid or no handler is registered for its `__type`.
33
- */
34
- hydrate(snapshot) {
35
- const typeId = snapshot?.__type;
36
- throwIfEmpty(typeId, 'Invalid policy snapshot: missing "__type" identifier.');
37
- const handler = this.handlers.get(typeId);
38
- throwIfEmpty(handler, `No serializer handler registered for policy ID: '${typeId}'`);
39
- const { __type, ...data } = snapshot;
40
- return handler.hydrate(data);
41
- }
42
- }
43
- //# sourceMappingURL=policy-serializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"policy-serializer.js","sourceRoot":"","sources":["../../src/serializer/policy-serializer.ts"],"names":[],"mappings":"AACA,OAAO,E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CAAC;CACF"}
package/dist/setup.d.ts DELETED
@@ -1,41 +0,0 @@
1
- import { FieldRegistry } from './field-registry';
2
- import { FieldTreeSerializer, PolicySerializer } from './serializer';
3
- import { CoreFields } from './core-fields';
4
- import { CoreTreeNodeFactory } from './core-field-tree-factory';
5
- /**
6
- * Creates and configures a FieldRegistry with all the core field types.
7
- * @returns {FieldRegistry} A pre-configured FieldRegistry instance.
8
- */
9
- export declare function createCoreFieldRegistry(): FieldRegistry;
10
- /**
11
- * Creates and configures a PolicySerializer with handlers for core policies.
12
- * @returns {PolicySerializer} A pre-configured PolicySerializer instance.
13
- */
14
- export declare function createCorePolicySerializer(): PolicySerializer;
15
- /**
16
- * Creates a factory for CoreFieldTree and CoreFields nodes.
17
- * @param {FieldRegistry} fieldRegistry - The registry to be used by the factory.
18
- * @returns {CoreTreeNodeFactory} A new CoreTreeNodeFactory instance.
19
- */
20
- export declare function createCoreTreeNodeFactory(fieldRegistry: FieldRegistry): CoreTreeNodeFactory;
21
- /**
22
- * Creates a fully configured serializer for a FieldTree.
23
- * This function composes all necessary serializers (FieldTree, Fields, Field) for a complete setup.
24
- * @param {CoreTreeNodeFactory} fieldTreeNodeFactory - The factory used to create new tree nodes during deserialization.
25
- * @param policySerializer
26
- * @returns {FieldTreeSerializer<CoreFields>} A top-level serializer for the entire field tree.
27
- */
28
- export declare function createCoreTreeSerializer(fieldTreeNodeFactory: CoreTreeNodeFactory, policySerializer?: PolicySerializer): FieldTreeSerializer<CoreFields>;
29
- export interface CoreFieldSystemConfig {
30
- registry?: FieldRegistry;
31
- policySerializer?: PolicySerializer;
32
- }
33
- /**
34
- * Creates a complete core setup for the field system.
35
- * @returns {{factory: CoreTreeNodeFactory, serializer: FieldTreeSerializer<CoreFields>}}
36
- */
37
- export declare function createCoreFieldSystem(config?: CoreFieldSystemConfig): {
38
- factory: CoreTreeNodeFactory;
39
- serializer: FieldTreeSerializer<CoreFields>;
40
- };
41
- //# sourceMappingURL=setup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAG4D,mBAAmB,EACpF,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAG9D;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,aAAa,CAOvD;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,gBAAgB,CAM7D;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,aAAa,GAAG,mBAAmB,CAE3F;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,oBAAoB,EAAE,mBAAmB,EACzC,gBAAgB,CAAC,EAAE,gBAAgB,GAClC,mBAAmB,CAAC,UAAU,CAAC,CAQjC;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAClE;IAAE,OAAO,EAAE,mBAAmB,CAAC;IAAC,UAAU,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAA;CAAE,CAM9E"}
package/dist/setup.js DELETED
@@ -1,57 +0,0 @@
1
- import { FieldRegistry } from './field-registry';
2
- import { ClampMaxPolicySerializerHandler, ClampMinPolicySerializerHandler, ClampPolicySerializerHandler, FieldSerializer, FieldsSerializer, FieldTreeSerializer, PolicySerializer } from './serializer';
3
- import { ClampMaxPolicy, ClampMinPolicy, ClampPolicy } from './policies';
4
- import { CoreBooleanField, CoreField, CoreNumericField, CoreStringField } from './field-definitions';
5
- import { CoreTreeNodeFactory } from './core-field-tree-factory';
6
- /**
7
- * Creates and configures a FieldRegistry with all the core field types.
8
- * @returns {FieldRegistry} A pre-configured FieldRegistry instance.
9
- */
10
- export function createCoreFieldRegistry() {
11
- const fieldRegistry = new FieldRegistry();
12
- fieldRegistry.register(CoreField.typeName, CoreField);
13
- fieldRegistry.register(CoreNumericField.typeName, CoreNumericField);
14
- fieldRegistry.register(CoreStringField.typeName, CoreStringField);
15
- fieldRegistry.register(CoreBooleanField.typeName, CoreBooleanField);
16
- return fieldRegistry;
17
- }
18
- /**
19
- * Creates and configures a PolicySerializer with handlers for core policies.
20
- * @returns {PolicySerializer} A pre-configured PolicySerializer instance.
21
- */
22
- export function createCorePolicySerializer() {
23
- const policySerializer = new PolicySerializer();
24
- policySerializer.register(ClampPolicy.id, new ClampPolicySerializerHandler());
25
- policySerializer.register(ClampMinPolicy.id, new ClampMinPolicySerializerHandler());
26
- policySerializer.register(ClampMaxPolicy.id, new ClampMaxPolicySerializerHandler());
27
- return policySerializer;
28
- }
29
- /**
30
- * Creates a factory for CoreFieldTree and CoreFields nodes.
31
- * @param {FieldRegistry} fieldRegistry - The registry to be used by the factory.
32
- * @returns {CoreTreeNodeFactory} A new CoreTreeNodeFactory instance.
33
- */
34
- export function createCoreTreeNodeFactory(fieldRegistry) {
35
- return new CoreTreeNodeFactory(fieldRegistry);
36
- }
37
- /**
38
- * Creates a fully configured serializer for a FieldTree.
39
- * This function composes all necessary serializers (FieldTree, Fields, Field) for a complete setup.
40
- * @param {CoreTreeNodeFactory} fieldTreeNodeFactory - The factory used to create new tree nodes during deserialization.
41
- * @param policySerializer
42
- * @returns {FieldTreeSerializer<CoreFields>} A top-level serializer for the entire field tree.
43
- */
44
- export function createCoreTreeSerializer(fieldTreeNodeFactory, policySerializer) {
45
- return new FieldTreeSerializer(fieldTreeNodeFactory, new FieldsSerializer(fieldTreeNodeFactory, new FieldSerializer(fieldTreeNodeFactory.fieldRegistry, policySerializer ?? createCorePolicySerializer())));
46
- }
47
- /**
48
- * Creates a complete core setup for the field system.
49
- * @returns {{factory: CoreTreeNodeFactory, serializer: FieldTreeSerializer<CoreFields>}}
50
- */
51
- export function createCoreFieldSystem(config) {
52
- const registry = config?.registry ?? createCoreFieldRegistry();
53
- const factory = createCoreTreeNodeFactory(registry);
54
- const serializer = createCoreTreeSerializer(factory, config?.policySerializer);
55
- return { factory, serializer };
56
- }
57
- //# sourceMappingURL=setup.js.map
package/dist/setup.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,+BAA+B,EAC/B,+BAA+B,EAC/B,4BAA4B,EAAE,eAAe,EAAE,gBAAgB,EAAE,mBAAmB,EACpF,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,cAAc,EAAE,cAAc,EAAE,WAAW,EAAC,MAAM,YAAY,CAAC;AACvE,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAEnG,OAAO,EAAC,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAG9D;;;GAGG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;IAC1C,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACtD,aAAa,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IACpE,aAAa,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAClE,aAAa,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IACpE,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAChD,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,4BAA4B,EAAE,CAAC,CAAC;IAC9E,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,EAAE,IAAI,+BAA+B,EAAE,CAAC,CAAC;IACpF,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,EAAE,IAAI,+BAA+B,EAAE,CAAC,CAAC;IACpF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,aAA4B;IACpE,OAAO,IAAI,mBAAmB,CAAC,aAAa,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,oBAAyC,EACzC,gBAAmC;IAEnC,OAAO,IAAI,mBAAmB,CAC5B,oBAAoB,EACpB,IAAI,gBAAgB,CAClB,oBAAoB,EACpB,IAAI,eAAe,CAAC,oBAAoB,CAAC,aAAa,EAAE,gBAAgB,IAAI,0BAA0B,EAAE,CAAC,CAC1G,CACF,CAAC;AACJ,CAAC;AAOD;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA8B;IAGlE,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,uBAAuB,EAAE,CAAC;IAC/D,MAAM,OAAO,GAAG,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC/E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACjC,CAAC"}
package/dist/store.d.ts DELETED
@@ -1,137 +0,0 @@
1
- import { PathType } from '@axi-engine/utils';
2
- import { Field, FieldOptions } from './field';
3
- import { CoreBooleanField, CoreBooleanFieldOptions, CoreField, CoreNumericField, CoreNumericFieldOptions, CoreStringField, CoreStringFieldOptions } from './field-definitions';
4
- import { CoreFields } from './core-fields';
5
- import { CoreFieldTree } from './core-field-tree';
6
- export interface StoreCreateFieldOptions {
7
- /** Allows to explicitly specify the field type, overriding the automatic type detection. */
8
- fieldType?: string;
9
- }
10
- /**
11
- * Defines the primary high-level API for interacting with the state management system.
12
- * It acts as a facade, simplifying access to the underlying FieldTree and providing
13
- * both type-safe and dynamic methods for manipulating data.
14
- */
15
- export interface Store {
16
- /**
17
- * Retrieves the raw value of a Field at a specific path.
18
- * @template T The expected type of the value.
19
- * @param path The path to the field (e.g., 'player.stats.hp').
20
- * @returns {T} The raw value stored in the field.
21
- * @throws An error if the path is invalid or no field exists at the path.
22
- */
23
- getValue<T>(path: PathType): T;
24
- /**
25
- * Strictly sets the value of an *existing* Field at a specific path.
26
- * @template T The type of the value being set.
27
- * @param path The path to the existing field.
28
- * @param val The new value to set.
29
- * @returns {T} The value that was set.
30
- * @throws An error if no field exists at the specified path.
31
- */
32
- setValue<T>(path: PathType, val: T): T;
33
- /**
34
- * Creates a new Field at a specified path, inferring its type from the provided value.
35
- * This is a strict operation and will fail if a node already exists at the target path.
36
- * @template T The type of the initial value.
37
- * @param path The full path where the new field will be created.
38
- * @param val The initial value for the field.
39
- * @param options Optional configuration, including policies and the ability to override field type.
40
- * @returns {T} value of the newly created Field instance.
41
- * @throws An error if a node already exists at the path or if the parent path is invalid.
42
- */
43
- createValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
44
- /**
45
- * Creates new or update a Field at a specified path, inferring its type from the provided value.
46
- * @template T The type of the initial value.
47
- * @param path The full path where the new field will be created.
48
- * @param val The initial value for the field.
49
- * @param options Optional configuration, including policies and the ability to override field type.
50
- * @returns {T} value of the newly created Field instance.
51
- * @throws An error if a node already exists at the path or if the parent path is invalid.
52
- */
53
- upsetValue<T>(path: PathType, val: T, options?: FieldOptions<T> & StoreCreateFieldOptions): T;
54
- /**
55
- * Creates a new, strongly-typed CoreBooleanField.
56
- * @throws An error if a node already exists at the path.
57
- */
58
- createBoolean(path: PathType, initialValue: boolean, options?: CoreBooleanFieldOptions): CoreBooleanField;
59
- /**
60
- * Creates a new, strongly-typed CoreNumericField.
61
- * @throws An error if a node already exists at the path.
62
- */
63
- createNumeric(path: PathType, initialValue: number, options?: CoreNumericFieldOptions): CoreNumericField;
64
- /**
65
- * Creates a new, strongly-typed CoreStringField.
66
- * @throws An error if a node already exists at the path.
67
- */
68
- createString(path: PathType, initialValue: string, options?: CoreStringFieldOptions): CoreStringField;
69
- /**
70
- * Creates a new, generic CoreField instance for any data type.
71
- * @throws An error if a node already exists at the path.
72
- */
73
- createGeneric<T>(path: PathType, initialValue: T, options?: FieldOptions<T>): CoreField<T>;
74
- /**
75
- * Retrieves a strongly-typed CoreBooleanField instance.
76
- * @throws An error if the path is invalid or the field is not of the expected type.
77
- */
78
- getBoolean(path: PathType): CoreBooleanField;
79
- /**
80
- * Retrieves a strongly-typed CoreNumericField instance.
81
- * @throws An error if the path is invalid or the field is not of the expected type.
82
- */
83
- getNumeric(path: PathType): CoreNumericField;
84
- /**
85
- * Retrieves a strongly-typed CoreStringField instance.
86
- * @throws An error if the path is invalid or the field is not of the expected type.
87
- */
88
- getString(path: PathType): CoreStringField;
89
- /**
90
- * Retrieves a generic CoreField instance.
91
- * @throws An error if the path is invalid.
92
- */
93
- getGeneric<T>(path: PathType): CoreField<T>;
94
- /**
95
- * A generic method to retrieve a Field instance with a specific asserted type.
96
- * @template TField The expected Field class or interface.
97
- * @throws An error if the path is invalid or the field cannot be cast to the specified type.
98
- */
99
- getField<TField extends Field<any>>(path: PathType): TField;
100
- /**
101
- * Strictly creates a new CoreFields container.
102
- * Any missing parent nodes in the path will be created automatically.
103
- * @param path The path where the new Fields container will be created.
104
- * @returns {CoreFields} The newly created CoreFields instance.
105
- * @throws An error if a node already exists at the target path.
106
- */
107
- createFields(path: PathType): CoreFields;
108
- /**
109
- * Strictly creates a new CoreFieldTree node.
110
- * Any missing parent nodes in the path will be created automatically.
111
- * @param path The path where the new FieldTree node will be created.
112
- * @returns {CoreFieldTree} The newly created CoreFieldTree instance.
113
- * @throws An error if a node already exists at the target path.
114
- */
115
- createTree(path: PathType): CoreFieldTree;
116
- /**
117
- * Retrieves an existing CoreFields container.
118
- * @param path The path to the Fields container.
119
- * @returns {CoreFields} The found CoreFields instance.
120
- * @throws An error if the path is invalid or the node at the path is not a Fields container.
121
- */
122
- getFields(path: PathType): CoreFields;
123
- /**
124
- * Retrieves an existing CoreFieldTree node.
125
- * @param path The path to the FieldTree node.
126
- * @returns {CoreFieldTree} The found CoreFieldTree instance.
127
- * @throws An error if the path is invalid or the node at the path is not a FieldTree.
128
- */
129
- getTree(path: PathType): CoreFieldTree;
130
- /**
131
- * Removes the node (Field, Fields, or FieldTree) at the end of the specified path.
132
- * This method does not remove parent nodes if they become empty.
133
- * @param path The path to the node to remove.
134
- */
135
- remove(path: PathType): void;
136
- }
137
- //# sourceMappingURL=store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAC,KAAK,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EAAE,SAAS,EAAE,gBAAgB,EACpD,uBAAuB,EAAE,eAAe,EACxC,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,uBAAuB;IACtC,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,KAAK;IAEpB;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,GAAG,CA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AAA;IAE1C;;;OAGG;IACH,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;IAE3C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAA;IAE3D;;;;;;OAMG;IACH,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAA;IAExC;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,aAAa,CAAA;IAEzC;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAA;IAErC;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,aAAa,CAAA;IAEtC;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC7B"}
package/dist/store.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=store.js.map
package/dist/store.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":""}