@axi-engine/fields 0.3.3 → 0.3.5

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 (164) hide show
  1. package/dist/core-field-tree-factory.d.ts +13 -0
  2. package/dist/core-field-tree-factory.d.ts.map +1 -0
  3. package/dist/core-field-tree-factory.js +14 -0
  4. package/dist/core-field-tree-factory.js.map +1 -0
  5. package/dist/core-field-tree.d.ts +5 -0
  6. package/dist/core-field-tree.d.ts.map +1 -0
  7. package/dist/core-field-tree.js +4 -0
  8. package/dist/core-field-tree.js.map +1 -0
  9. package/dist/core-fields-factory.d.ts +10 -0
  10. package/dist/core-fields-factory.d.ts.map +1 -0
  11. package/dist/core-fields-factory.js +14 -0
  12. package/dist/core-fields-factory.js.map +1 -0
  13. package/dist/core-fields.d.ts +47 -0
  14. package/dist/core-fields.d.ts.map +1 -0
  15. package/dist/core-fields.js +8 -0
  16. package/dist/core-fields.js.map +1 -0
  17. package/dist/data-store-field-resolver.d.ts +26 -0
  18. package/dist/data-store-field-resolver.d.ts.map +1 -0
  19. package/dist/data-store-field-resolver.js +21 -0
  20. package/dist/data-store-field-resolver.js.map +1 -0
  21. package/dist/data-store.d.ts +38 -0
  22. package/dist/data-store.d.ts.map +1 -0
  23. package/dist/data-store.js +141 -0
  24. package/dist/data-store.js.map +1 -0
  25. package/dist/field-definitions/core-boolean-field.d.ts +11 -0
  26. package/dist/field-definitions/core-boolean-field.d.ts.map +1 -0
  27. package/dist/field-definitions/core-boolean-field.js +13 -0
  28. package/dist/field-definitions/core-boolean-field.js.map +1 -0
  29. package/dist/field-definitions/core-field.d.ts +51 -0
  30. package/dist/field-definitions/core-field.d.ts.map +1 -0
  31. package/dist/field-definitions/core-field.js +74 -0
  32. package/dist/field-definitions/core-field.js.map +1 -0
  33. package/dist/field-definitions/core-numeric-field.d.ts +18 -0
  34. package/dist/field-definitions/core-numeric-field.d.ts.map +1 -0
  35. package/dist/field-definitions/core-numeric-field.js +45 -0
  36. package/dist/field-definitions/core-numeric-field.js.map +1 -0
  37. package/dist/field-definitions/core-string-field.d.ts +15 -0
  38. package/dist/field-definitions/core-string-field.d.ts.map +1 -0
  39. package/dist/field-definitions/core-string-field.js +27 -0
  40. package/dist/field-definitions/core-string-field.js.map +1 -0
  41. package/dist/field-definitions/index.d.ts +5 -0
  42. package/dist/field-definitions/index.d.ts.map +1 -0
  43. package/dist/field-definitions/index.js +5 -0
  44. package/dist/field-definitions/index.js.map +1 -0
  45. package/dist/field-registry.d.ts +5 -0
  46. package/dist/field-registry.d.ts.map +1 -0
  47. package/dist/field-registry.js +4 -0
  48. package/dist/field-registry.js.map +1 -0
  49. package/dist/field-tree-factory.d.ts +12 -0
  50. package/dist/field-tree-factory.d.ts.map +1 -0
  51. package/dist/field-tree-factory.js +2 -0
  52. package/dist/field-tree-factory.js.map +1 -0
  53. package/dist/field-tree.d.ts +171 -0
  54. package/dist/field-tree.d.ts.map +1 -0
  55. package/dist/field-tree.js +248 -0
  56. package/dist/field-tree.js.map +1 -0
  57. package/dist/field.d.ts +34 -0
  58. package/dist/field.d.ts.map +1 -0
  59. package/dist/field.js +2 -0
  60. package/dist/field.js.map +1 -0
  61. package/dist/fields-factory.d.ts +5 -0
  62. package/dist/fields-factory.d.ts.map +1 -0
  63. package/dist/fields-factory.js +2 -0
  64. package/dist/fields-factory.js.map +1 -0
  65. package/dist/fields.d.ts +101 -0
  66. package/dist/fields.d.ts.map +1 -0
  67. package/dist/fields.js +143 -0
  68. package/dist/fields.js.map +1 -0
  69. package/dist/index.d.mts +794 -815
  70. package/dist/index.d.ts +18 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +18 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/index.mjs +1084 -1116
  75. package/dist/mixins/mixin-factory.d.ts +29 -0
  76. package/dist/mixins/mixin-factory.d.ts.map +1 -0
  77. package/dist/mixins/mixin-factory.js +32 -0
  78. package/dist/mixins/mixin-factory.js.map +1 -0
  79. package/dist/mixins/with-boolean-fields.mixin.d.ts +9 -0
  80. package/dist/mixins/with-boolean-fields.mixin.d.ts.map +1 -0
  81. package/dist/mixins/with-boolean-fields.mixin.js +4 -0
  82. package/dist/mixins/with-boolean-fields.mixin.js.map +1 -0
  83. package/dist/mixins/with-default-generic-fields.mixin.d.ts +31 -0
  84. package/dist/mixins/with-default-generic-fields.mixin.d.ts.map +1 -0
  85. package/dist/mixins/with-default-generic-fields.mixin.js +15 -0
  86. package/dist/mixins/with-default-generic-fields.mixin.js.map +1 -0
  87. package/dist/mixins/with-numeric-fields.mixin.d.ts +9 -0
  88. package/dist/mixins/with-numeric-fields.mixin.d.ts.map +1 -0
  89. package/dist/mixins/with-numeric-fields.mixin.js +4 -0
  90. package/dist/mixins/with-numeric-fields.mixin.js.map +1 -0
  91. package/dist/mixins/with-string-fields.mixin.d.ts +9 -0
  92. package/dist/mixins/with-string-fields.mixin.d.ts.map +1 -0
  93. package/dist/mixins/with-string-fields.mixin.js +4 -0
  94. package/dist/mixins/with-string-fields.mixin.js.map +1 -0
  95. package/dist/policies/clamp-max-policy.d.ts +11 -0
  96. package/dist/policies/clamp-max-policy.d.ts.map +1 -0
  97. package/dist/policies/clamp-max-policy.js +18 -0
  98. package/dist/policies/clamp-max-policy.js.map +1 -0
  99. package/dist/policies/clamp-min-policy.d.ts +11 -0
  100. package/dist/policies/clamp-min-policy.d.ts.map +1 -0
  101. package/dist/policies/clamp-min-policy.js +18 -0
  102. package/dist/policies/clamp-min-policy.js.map +1 -0
  103. package/dist/policies/clamp-policy.d.ts +12 -0
  104. package/dist/policies/clamp-policy.d.ts.map +1 -0
  105. package/dist/policies/clamp-policy.js +21 -0
  106. package/dist/policies/clamp-policy.js.map +1 -0
  107. package/dist/policies/index.d.ts +6 -0
  108. package/dist/policies/index.d.ts.map +1 -0
  109. package/dist/policies/index.js +6 -0
  110. package/dist/policies/index.js.map +1 -0
  111. package/dist/policies/policies.d.ts +38 -0
  112. package/dist/policies/policies.d.ts.map +1 -0
  113. package/dist/policies/policies.js +62 -0
  114. package/dist/policies/policies.js.map +1 -0
  115. package/dist/policies/policy.d.ts +6 -0
  116. package/dist/policies/policy.d.ts.map +1 -0
  117. package/dist/policies/policy.js +2 -0
  118. package/dist/policies/policy.js.map +1 -0
  119. package/dist/serializer/field-serializer.d.ts +52 -0
  120. package/dist/serializer/field-serializer.d.ts.map +1 -0
  121. package/dist/serializer/field-serializer.js +66 -0
  122. package/dist/serializer/field-serializer.js.map +1 -0
  123. package/dist/serializer/field-tree-serializer.d.ts +50 -0
  124. package/dist/serializer/field-tree-serializer.d.ts.map +1 -0
  125. package/dist/serializer/field-tree-serializer.js +68 -0
  126. package/dist/serializer/field-tree-serializer.js.map +1 -0
  127. package/dist/serializer/fields-serializer.d.ts +49 -0
  128. package/dist/serializer/fields-serializer.d.ts.map +1 -0
  129. package/dist/serializer/fields-serializer.js +57 -0
  130. package/dist/serializer/fields-serializer.js.map +1 -0
  131. package/dist/serializer/index.d.ts +8 -0
  132. package/dist/serializer/index.d.ts.map +1 -0
  133. package/dist/serializer/index.js +8 -0
  134. package/dist/serializer/index.js.map +1 -0
  135. package/dist/serializer/policies/clamp-max-policy-serializer-handler.d.ts +13 -0
  136. package/dist/serializer/policies/clamp-max-policy-serializer-handler.d.ts.map +1 -0
  137. package/dist/serializer/policies/clamp-max-policy-serializer-handler.js +10 -0
  138. package/dist/serializer/policies/clamp-max-policy-serializer-handler.js.map +1 -0
  139. package/dist/serializer/policies/clamp-min-policy-serializer-handler.d.ts +13 -0
  140. package/dist/serializer/policies/clamp-min-policy-serializer-handler.d.ts.map +1 -0
  141. package/dist/serializer/policies/clamp-min-policy-serializer-handler.js +10 -0
  142. package/dist/serializer/policies/clamp-min-policy-serializer-handler.js.map +1 -0
  143. package/dist/serializer/policies/clamp-policy-serializer-handler.d.ts +16 -0
  144. package/dist/serializer/policies/clamp-policy-serializer-handler.d.ts.map +1 -0
  145. package/dist/serializer/policies/clamp-policy-serializer-handler.js +10 -0
  146. package/dist/serializer/policies/clamp-policy-serializer-handler.js.map +1 -0
  147. package/dist/serializer/policy-serializer.d.ts +41 -0
  148. package/dist/serializer/policy-serializer.d.ts.map +1 -0
  149. package/dist/serializer/policy-serializer.js +43 -0
  150. package/dist/serializer/policy-serializer.js.map +1 -0
  151. package/dist/setup.d.ts +41 -0
  152. package/dist/setup.d.ts.map +1 -0
  153. package/dist/setup.js +57 -0
  154. package/dist/setup.js.map +1 -0
  155. package/dist/store.d.ts +137 -0
  156. package/dist/store.d.ts.map +1 -0
  157. package/dist/store.js +2 -0
  158. package/dist/store.js.map +1 -0
  159. package/package.json +44 -44
  160. package/dist/index.cjs +0 -1232
  161. package/dist/index.d.cts +0 -1018
  162. package/dist/index.d.cts.map +0 -1
  163. package/dist/index.d.mts.map +0 -1
  164. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,45 @@
1
+ import { clampPolicy, clampMaxPolicy, clampMinPolicy, ClampPolicy, ClampMinPolicy, ClampMaxPolicy } from '../policies';
2
+ import { CoreField } from './core-field';
3
+ import { isNullOrUndefined } from '@axi-engine/utils';
4
+ export class CoreNumericField extends CoreField {
5
+ static typeName = 'numeric';
6
+ typeName = CoreNumericField.typeName;
7
+ get min() {
8
+ const policy = this.policies.get(ClampPolicy.id) ??
9
+ this.policies.get(ClampMinPolicy.id);
10
+ return policy?.min;
11
+ }
12
+ get max() {
13
+ const policy = this.policies.get(ClampPolicy.id) ??
14
+ this.policies.get(ClampMaxPolicy.id);
15
+ return policy?.max;
16
+ }
17
+ constructor(name, initialVal, options) {
18
+ const policies = options?.policies ?? [];
19
+ if (!isNullOrUndefined(options?.min) && !isNullOrUndefined(options?.max)) {
20
+ policies.unshift(clampPolicy(options.min, options.max));
21
+ }
22
+ else if (!isNullOrUndefined(options?.min)) {
23
+ policies.unshift(clampMinPolicy(options.min));
24
+ }
25
+ else if (!isNullOrUndefined(options?.max)) {
26
+ policies.unshift(clampMaxPolicy(options.max));
27
+ }
28
+ super(name, initialVal, { policies });
29
+ }
30
+ isMin() {
31
+ const min = this.min;
32
+ return isNullOrUndefined(min) ? false : this.value <= min;
33
+ }
34
+ isMax() {
35
+ const max = this.max;
36
+ return isNullOrUndefined(max) ? false : this.value >= max;
37
+ }
38
+ inc(amount = 1) {
39
+ this.value = this.value + amount;
40
+ }
41
+ dec(amount = 1) {
42
+ this.value = this.value - amount;
43
+ }
44
+ }
45
+ //# sourceMappingURL=core-numeric-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-numeric-field.js","sourceRoot":"","sources":["../../src/field-definitions/core-numeric-field.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,cAAc,EACd,WAAW,EACX,cAAc,EACd,cAAc,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AASpD,MAAM,OAAO,gBAAiB,SAAQ,SAAiB;IACrD,MAAM,CAAU,QAAQ,GAAW,SAAS,CAAC;IACpC,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC;IAE9C,IAAI,GAAG;QACL,MAAM,MAAM,GACV,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAc,WAAW,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAiB,cAAc,CAAC,EAAE,CAAC,CAAC;QACvD,OAAO,MAAM,EAAE,GAAG,CAAC;IACrB,CAAC;IAED,IAAI,GAAG;QACL,MAAM,MAAM,GACV,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAc,WAAW,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAiB,cAAc,CAAC,EAAE,CAAC,CAAC;QACvD,OAAO,MAAM,EAAE,GAAG,CAAC;IACrB,CAAC;IAED,YAAY,IAAY,EAAE,UAAkB,EAAE,OAAiC;QAC7E,MAAM,QAAQ,G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AAK,GAAG,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;IACnC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { CoreField } from './core-field';
2
+ import { FieldOptions, StringField } from '../field';
3
+ export interface CoreStringFieldOptions extends FieldOptions<string> {
4
+ }
5
+ export declare class CoreStringField extends CoreField<string> implements StringField {
6
+ static readonly typeName: string;
7
+ readonly typeName: string;
8
+ constructor(name: string, initialVal: string, options?: CoreStringFieldOptions);
9
+ append(str: string | number): this;
10
+ prepend(str: string | number): this;
11
+ trim(): this;
12
+ isEmpty(): boolean;
13
+ clear(): void;
14
+ }
15
+ //# sourceMappingURL=core-string-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-string-field.d.ts","sourceRoot":"","sources":["../../src/field-definitions/core-string-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,YAAY,EAAE,WAAW,EAAC,MAAM,UAAU,CAAC;AAEnD,MAAM,WAAW,sBAAuB,SAAQ,YAAY,CAAC,MAAM,CAAC;CAAI;AAExE,qBAAa,eAAgB,SAAQ,SAAS,CAAC,MAAM,CAAE,YAAW,WAAW;IAC3E,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAY;IAC5C,QAAQ,CAAC,QAAQ,SAA4B;gBAEjC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAI9E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAI3B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAI5B,IAAI;IAIJ,OAAO;IAIP,KAAK;CAGN"}
@@ -0,0 +1,27 @@
1
+ import { CoreField } from './core-field';
2
+ export class CoreStringField extends CoreField {
3
+ static typeName = 'string';
4
+ typeName = CoreStringField.typeName;
5
+ constructor(name, initialVal, options) {
6
+ super(name, initialVal, options);
7
+ }
8
+ append(str) {
9
+ this.value = this.value + str;
10
+ return this;
11
+ }
12
+ prepend(str) {
13
+ this.value = str + this.value;
14
+ return this;
15
+ }
16
+ trim() {
17
+ this.value = this.value.trim();
18
+ return this;
19
+ }
20
+ isEmpty() {
21
+ return this.value.length === 0;
22
+ }
23
+ clear() {
24
+ this.value = '';
25
+ }
26
+ }
27
+ //# sourceMappingURL=core-string-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-string-field.js","sourceRoot":"","sources":["../../src/field-definitions/core-string-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAKvC,MAAM,OAAO,eAAgB,SAAQ,SAAiB;IACpD,MAAM,CAAU,QAAQ,GAAW,QAAQ,CAAC;IACnC,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;IAE7C,YAAY,IAAY,EAAE,UAAkB,EAAE,OAAgC;QAC5E,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,GAAoB;QACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,GAAoB;QAC1B,IAAI,CAAC,KAAK,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI;QACF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './core-field';
2
+ export * from './core-boolean-field';
3
+ export * from './core-string-field';
4
+ export * from './core-numeric-field';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/field-definitions/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './core-field';
2
+ export * from './core-boolean-field';
3
+ export * from './core-string-field';
4
+ export * from './core-numeric-field';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/field-definitions/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ConstructorRegistry } from '@axi-engine/utils';
2
+ import { Field } from './field';
3
+ export declare class FieldRegistry extends ConstructorRegistry<Field<any>> {
4
+ }
5
+ //# sourceMappingURL=field-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-registry.d.ts","sourceRoot":"","sources":["../src/field-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAG9B,qBAAa,aAAc,SAAQ,mBAAmB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CAAI"}
@@ -0,0 +1,4 @@
1
+ import { ConstructorRegistry } from '@axi-engine/utils';
2
+ export class FieldRegistry extends ConstructorRegistry {
3
+ }
4
+ //# sourceMappingURL=field-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-registry.js","sourceRoot":"","sources":["../src/field-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAItD,MAAM,OAAO,aAAc,SAAQ,mBAA+B;CAAI"}
@@ -0,0 +1,12 @@
1
+ import { Fields } from './fields';
2
+ import { FieldTree } from './field-tree';
3
+ import { FieldsFactory } from './fields-factory';
4
+ /**
5
+ * Defines the contract for a factory that creates nodes for a FieldTree.
6
+ * This allows for custom implementations of Fields and FieldTree to be used.
7
+ */
8
+ export interface FieldTreeFactory<TFields extends Fields> extends FieldsFactory<TFields> {
9
+ fields(): TFields;
10
+ tree(): FieldTree<TFields>;
11
+ }
12
+ //# sourceMappingURL=field-tree-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-tree-factory.d.ts","sourceRoot":"","sources":["../src/field-tree-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAG/C;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,OAAO,SAAS,MAAM,CAAE,SAAQ,aAAa,CAAC,OAAO,CAAC;IACtF,MAAM,IAAI,OAAO,CAAC;IAClB,IAAI,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;CAC3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=field-tree-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-tree-factory.js","sourceRoot":"","sources":["../src/field-tree-factory.ts"],"names":[],"mappings":""}
@@ -0,0 +1,171 @@
1
+ import { Emitter, PathType } from '@axi-engine/utils';
2
+ import { Fields } from './fields';
3
+ import { FieldTreeFactory } from './field-tree-factory';
4
+ /** A type alias for any container that can be a child node in a FieldTree */
5
+ export type TreeNode<F extends Fields> = FieldTree<F> | F;
6
+ /**
7
+ * Represents a hierarchical data structure for managing the global state of the system.
8
+ *
9
+ * This class acts as the single source of truth for long-term data that exists
10
+ * across different scenes and scripts, such as player stats, inventory,
11
+ * and overall game progress. It uses a path-based system for accessing and
12
+ * manipulating nested data, similar to a file system.
13
+ *
14
+ */
15
+ export declare class FieldTree<TFields extends Fields> {
16
+ static readonly typeName = "fieldTree";
17
+ readonly typeName = "fieldTree";
18
+ /** @private The internal map storing child nodes (branches or leaves). */
19
+ private readonly _nodes;
20
+ /** @private The factory used to create new child nodes. */
21
+ private readonly _factory;
22
+ /**
23
+ * An event emitter that fires immediately after a new node is added to this tree branch.
24
+ * @event
25
+ * @param {object} event - The event payload.
26
+ * @param {string} event.name - The name (key) of the added node.
27
+ * @param event.node - The node instance that was added.
28
+ * @example
29
+ * myTree.onAdd.subscribe(({ name, node }) => {
30
+ * console.log(`Node '${name}' was added.`, node);
31
+ * });
32
+ */
33
+ onAdd: Emitter<[event: {
34
+ name: string;
35
+ node: TreeNode<TFields>;
36
+ }]>;
37
+ /**
38
+ * An event emitter that fires once after one or more nodes have been successfully removed.
39
+ * @event
40
+ * @param {object} event - The event payload.
41
+ * @param {string[]} event.names - An array of names of the nodes that were removed.
42
+ * @example
43
+ * myTree.onRemove.subscribe(({ names }) => {
44
+ * console.log(`Nodes removed: ${names.join(', ')}`);
45
+ * });
46
+ */
47
+ onRemove: Emitter<[event: {
48
+ names: string[];
49
+ }]>;
50
+ /**
51
+ * Gets the collection of direct child nodes of this tree branch.
52
+ */
53
+ get nodes(): Map<string, TreeNode<TFields>>;
54
+ /**
55
+ * Creates an instance of FieldTree.
56
+ * @param {FieldTreeFactory} factory - A factory responsible for creating new nodes within the tree.
57
+ */
58
+ constructor(factory: FieldTreeFactory<TFields>);
59
+ /**
60
+ * Checks if a direct child node with the given name exists.
61
+ * @param {string} name - The name of the direct child node.
62
+ * @returns {boolean} `true` if the node exists, otherwise `false`.
63
+ */
64
+ has(name: string): boolean;
65
+ /**
66
+ * Checks if a node exists at a given path, traversing the tree.
67
+ * @param {PathType} path - The path to check (e.g., 'player/stats' or ['player', 'stats']).
68
+ * @returns {boolean} `true` if the entire path resolves to a node, otherwise `false`.
69
+ */
70
+ hasPath(path: PathType): boolean;
71
+ /**
72
+ * Adds a pre-existing node as a direct child of this tree branch.
73
+ * @param {string} name - The name to assign to the new child node.
74
+ * @param {TreeNode} node - The node instance to add.
75
+ * @returns {TreeNode} The added node.
76
+ * @throws If a node with the same name already exists.
77
+ */
78
+ addNode(name: string, node: TreeNode<TFields>): TreeNode<TFields>;
79
+ /**
80
+ * Retrieves a direct child node by its name.
81
+ * @param {string} name - The name of the child node.
82
+ * @returns {TreeNode} The retrieved node.
83
+ * @throws If a node with the given name cannot be found.
84
+ */
85
+ getNode(name: string): TreeNode<TFields>;
86
+ /**
87
+ * Removes one or more nodes from this tree branch.
88
+ *
89
+ * This method first validates that all specified nodes exist. If validation passes,
90
+ * it recursively calls `destroy()` on each node to ensure proper cleanup of the entire subtree.
91
+ * Finally, it emits a single `onRemove` event with the names of all successfully removed nodes.
92
+ *
93
+ * @param {string | string[]} names - A single name or an array of names of the nodes to remove.
94
+ * @throws If any of the specified names do not correspond to an existing node.
95
+ */
96
+ removeNode(names: string | string[]): void;
97
+ /**
98
+ * Creates a new `FieldTree` (branch) node at the specified path.
99
+ * @param {PathType} path - The path where the new `FieldTree` should be created.
100
+ * @param {boolean} [createPath=false] - If `true`, any missing parent branches in the path will be created automatically.
101
+ * @returns {FieldTree} The newly created `FieldTree` instance.
102
+ * @throws If the path is invalid or a node already exists at the target location.
103
+ */
104
+ createFieldTree<T extends FieldTree<TFields>>(path: PathType, createPath?: boolean): T;
105
+ /**
106
+ * Creates a new `Fields` (leaf) container at the specified path.
107
+ * @param {PathType} path - The path where the new `Fields` container should be created.
108
+ * @param {boolean} [createPath=false] - If `true`, any missing parent branches in the path will be created automatically.
109
+ * @returns {Fields} The newly created `Fields` instance.
110
+ * @throws If the path is invalid or a node already exists at the target location.
111
+ */
112
+ createFields(path: PathType, createPath?: boolean): TFields;
113
+ /**
114
+ * Retrieves a `FieldTree` (branch) node from a specified path.
115
+ * @param {PathType} path - The path to the `FieldTree` node.
116
+ * @returns {FieldTree} The `FieldTree` instance at the specified path.
117
+ * @throws If the path is invalid or the node at the path is not a `FieldTree`.
118
+ */
119
+ getFieldTree(path: PathType): FieldTree<TFields>;
120
+ /**
121
+ * Retrieves a `Fields` (leaf) container from a specified path.
122
+ * @param {PathType} path - The path to the `Fields` container.
123
+ * @returns {Fields} The `Fields` instance at the specified path.
124
+ * @throws If the path is invalid or the node at the path is not a `Fields` container.
125
+ */
126
+ getFields(path: PathType): TFields;
127
+ /**
128
+ * Retrieves a `FieldTree` at the specified path. If it or any part of the path doesn't exist, it will be created.
129
+ * @param {PathType} path - The path to the `FieldTree` node.
130
+ * @returns {FieldTree} The existing or newly created `FieldTree` instance.
131
+ */
132
+ getOrCreateFieldTree(path: PathType): FieldTree<TFields>;
133
+ /**
134
+ * Retrieves a `Fields` container at the specified path. If it or any part of the path doesn't exist, it will be created.
135
+ * @param {PathType} path - The path to the `Fields` container.
136
+ * @returns {Fields} The existing or newly created `Fields` instance.
137
+ */
138
+ getOrCreateFields(path: PathType): TFields;
139
+ /**
140
+ * Finds the parent node for a given path.
141
+ * @param path The path to the target node.
142
+ * @returns The parent node (either a FieldTree or Fields).
143
+ * @throws An error if the path is invalid or any intermediate node is not a FieldTree.
144
+ */
145
+ findParentNode(path: PathType): FieldTree<TFields> | TFields;
146
+ /**
147
+ * Removes all child nodes from this tree branch.
148
+ * This method ensures that `destroy()` is called on each child node, allowing for
149
+ * a full, recursive cleanup of the entire subtree.
150
+ */
151
+ clear(): void;
152
+ /**
153
+ * Performs a complete cleanup of this node and its entire subtree.
154
+ *
155
+ * It recursively destroys all child nodes by calling `clear()` and then
156
+ * unsubscribes all listeners from its own event emitters.
157
+ * This method should be called when a node is no longer needed.
158
+ */
159
+ destroy(): void;
160
+ /**
161
+ * @private
162
+ * Navigates the tree to the parent of a target node.
163
+ * This is the core traversal logic for all path-based operations.
164
+ * @param {PathType} path - The full path to the target node.
165
+ * @param {boolean} [createPath=false] - If `true`, creates missing `FieldTree` branches along the path.
166
+ * @returns {{branch: FieldTree, leafName: string}} An object containing the final branch (parent node) and the name of the leaf (target node).
167
+ * @throws If the path is empty, invalid, or contains a `Fields` container as an intermediate segment.
168
+ */
169
+ private traversePath;
170
+ }
171
+ //# sourceMappingURL=field-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-tree.d.ts","sourceRoot":"","sources":["../src/field-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAqC,QAAQ,EAAwB,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAEtD,6EAA6E;AAC7E,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAE1D;;;;;;;;GAQG;AACH,qBAAa,SAAS,CAAC,OAAO,SAAS,MAAM;IAC3C,MAAM,CAAC,QAAQ,CAAC,QAAQ,eAAe;IACvC,QAAQ,CAAC,QAAQ,eAAsB;IAEvC,0EAA0E;IAC1E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6C;IAEpE,2DAA2D;IAC3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IAErD;;;;;;;;;;OAUG;IACH,KAAK;cACG,MAAM;cACN,QAAQ,CAAC,OAAO,CAAC;QACnB;IAEN;;;;;;;;;OASG;IACH,QAAQ;eACC,MAAM,EAAE;QACX;IAEN;;OAEG;IACH,IAAI,KAAK,mCAER;IAED;;;OAGG;gBACS,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC;IAI9C;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO;IAKhC;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC;IAOjE;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC;IAMxC;;;;;;;;;OASG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAcnC;;;;;;OAMG;IACH,eAAe,CAAC,CAAC,SAAS,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,CAAC;IAKtF;;;;;;OAMG;IACH,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO;IAK3D;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;IAUhD;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO;IAUlC;;;;OAIG;IACH,oBAAoB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;IAOxD;;;;OAIG;IACH,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO;IAO1C;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,OAAO;IAK5D;;;;OAIG;IACH,KAAK;IAIL;;;;;;OAMG;IACH,OAAO;IAMP;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;CAyBrB"}
@@ -0,0 +1,248 @@
1
+ import { Emitter, ensurePathArray, ensurePathString, throwIf, throwIfEmpty } from '@axi-engine/utils';
2
+ import { Fields } from './fields';
3
+ /**
4
+ * Represents a hierarchical data structure for managing the global state of the system.
5
+ *
6
+ * This class acts as the single source of truth for long-term data that exists
7
+ * across different scenes and scripts, such as player stats, inventory,
8
+ * and overall game progress. It uses a path-based system for accessing and
9
+ * manipulating nested data, similar to a file system.
10
+ *
11
+ */
12
+ export class FieldTree {
13
+ static typeName = 'fieldTree';
14
+ typeName = FieldTree.typeName;
15
+ /** @private The internal map storing child nodes (branches or leaves). */
16
+ _nodes = new Map();
17
+ /** @private The factory used to create new child nodes. */
18
+ _factory;
19
+ /**
20
+ * An event emitter that fires immediately after a new node is added to this tree branch.
21
+ * @event
22
+ * @param {object} event - The event payload.
23
+ * @param {string} event.name - The name (key) of the added node.
24
+ * @param event.node - The node instance that was added.
25
+ * @example
26
+ * myTree.onAdd.subscribe(({ name, node }) => {
27
+ * console.log(`Node '${name}' was added.`, node);
28
+ * });
29
+ */
30
+ onAdd = new Emitter();
31
+ /**
32
+ * An event emitter that fires once after one or more nodes have been successfully removed.
33
+ * @event
34
+ * @param {object} event - The event payload.
35
+ * @param {string[]} event.names - An array of names of the nodes that were removed.
36
+ * @example
37
+ * myTree.onRemove.subscribe(({ names }) => {
38
+ * console.log(`Nodes removed: ${names.join(', ')}`);
39
+ * });
40
+ */
41
+ onRemove = new Emitter();
42
+ /**
43
+ * Gets the collection of direct child nodes of this tree branch.
44
+ */
45
+ get nodes() {
46
+ return this._nodes;
47
+ }
48
+ /**
49
+ * Creates an instance of FieldTree.
50
+ * @param {FieldTreeFactory} factory - A factory responsible for creating new nodes within the tree.
51
+ */
52
+ constructor(factory) {
53
+ this._factory = factory;
54
+ }
55
+ /**
56
+ * Checks if a direct child node with the given name exists.
57
+ * @param {string} name - The name of the direct child node.
58
+ * @returns {boolean} `true` if the node exists, otherwise `false`.
59
+ */
60
+ has(name) {
61
+ return this._nodes.has(name);
62
+ }
63
+ /**
64
+ * Checks if a node exists at a given path, traversing the tree.
65
+ * @param {PathType} path - The path to check (e.g., 'player/stats' or ['player', 'stats']).
66
+ * @returns {boolean} `true` if the entire path resolves to a node, otherwise `false`.
67
+ */
68
+ hasPath(path) {
69
+ const traversedPath = this.traversePath(path);
70
+ return traversedPath.branch.has(traversedPath.leafName);
71
+ }
72
+ /**
73
+ * Adds a pre-existing node as a direct child of this tree branch.
74
+ * @param {string} name - The name to assign to the new child node.
75
+ * @param {TreeNode} node - The node instance to add.
76
+ * @returns {TreeNode} The added node.
77
+ * @throws If a node with the same name already exists.
78
+ */
79
+ addNode(name, node) {
80
+ throwIf(this.has(name), `Can't add node with name: '${name}', node already exists`);
81
+ this._nodes.set(name, node);
82
+ this.onAdd.emit({ name, node });
83
+ return node;
84
+ }
85
+ /**
86
+ * Retrieves a direct child node by its name.
87
+ * @param {string} name - The name of the child node.
88
+ * @returns {TreeNode} The retrieved node.
89
+ * @throws If a node with the given name cannot be found.
90
+ */
91
+ getNode(name) {
92
+ const node = this._nodes.get(name);
93
+ throwIfEmpty(node, `Can't find node with name '${name}'`);
94
+ return node;
95
+ }
96
+ /**
97
+ * Removes one or more nodes from this tree branch.
98
+ *
99
+ * This method first validates that all specified nodes exist. If validation passes,
100
+ * it recursively calls `destroy()` on each node to ensure proper cleanup of the entire subtree.
101
+ * Finally, it emits a single `onRemove` event with the names of all successfully removed nodes.
102
+ *
103
+ * @param {string | string[]} names - A single name or an array of names of the nodes to remove.
104
+ * @throws If any of the specified names do not correspond to an existing node.
105
+ */
106
+ removeNode(names) {
107
+ const toRemoveNames = Array.isArray(names) ? names : [names];
108
+ toRemoveNames.forEach(name => {
109
+ throwIf(!this.has(name), `Can't remove node with name: '${name}', node doesn't exists`);
110
+ });
111
+ toRemoveNames.forEach(name => {
112
+ this._nodes.get(name).destroy();
113
+ this._nodes.delete(name);
114
+ });
115
+ if (toRemoveNames.length) {
116
+ this.onRemove.emit({ names: toRemoveNames });
117
+ }
118
+ }
119
+ /**
120
+ * Creates a new `FieldTree` (branch) node at the specified path.
121
+ * @param {PathType} path - The path where the new `FieldTree` should be created.
122
+ * @param {boolean} [createPath=false] - If `true`, any missing parent branches in the path will be created automatically.
123
+ * @returns {FieldTree} The newly created `FieldTree` instance.
124
+ * @throws If the path is invalid or a node already exists at the target location.
125
+ */
126
+ createFieldTree(path, createPath) {
127
+ const traversedPath = this.traversePath(path, createPath);
128
+ return traversedPath.branch.addNode(traversedPath.leafName, this._factory.tree());
129
+ }
130
+ /**
131
+ * Creates a new `Fields` (leaf) container at the specified path.
132
+ * @param {PathType} path - The path where the new `Fields` container should be created.
133
+ * @param {boolean} [createPath=false] - If `true`, any missing parent branches in the path will be created automatically.
134
+ * @returns {Fields} The newly created `Fields` instance.
135
+ * @throws If the path is invalid or a node already exists at the target location.
136
+ */
137
+ createFields(path, createPath) {
138
+ const traversedPath = this.traversePath(path, createPath);
139
+ return traversedPath.branch.addNode(traversedPath.leafName, this._factory.fields());
140
+ }
141
+ /**
142
+ * Retrieves a `FieldTree` (branch) node from a specified path.
143
+ * @param {PathType} path - The path to the `FieldTree` node.
144
+ * @returns {FieldTree} The `FieldTree` instance at the specified path.
145
+ * @throws If the path is invalid or the node at the path is not a `FieldTree`.
146
+ */
147
+ getFieldTree(path) {
148
+ const traversedPath = this.traversePath(path);
149
+ const node = traversedPath.branch.getNode(traversedPath.leafName);
150
+ throwIf(!(node instanceof FieldTree), `Node with name: ${traversedPath.leafName} by path: '${ensurePathString(path)}' should be instance of FieldTree`);
151
+ return node;
152
+ }
153
+ /**
154
+ * Retrieves a `Fields` (leaf) container from a specified path.
155
+ * @param {PathType} path - The path to the `Fields` container.
156
+ * @returns {Fields} The `Fields` instance at the specified path.
157
+ * @throws If the path is invalid or the node at the path is not a `Fields` container.
158
+ */
159
+ getFields(path) {
160
+ const traversedPath = this.traversePath(path);
161
+ const node = traversedPath.branch.getNode(traversedPath.leafName);
162
+ throwIf(!(node instanceof Fields), `Node with name: ${traversedPath.leafName} by path: '${ensurePathString(path)}' should be instance of Fields`);
163
+ return node;
164
+ }
165
+ /**
166
+ * Retrieves a `FieldTree` at the specified path. If it or any part of the path doesn't exist, it will be created.
167
+ * @param {PathType} path - The path to the `FieldTree` node.
168
+ * @returns {FieldTree} The existing or newly created `FieldTree` instance.
169
+ */
170
+ getOrCreateFieldTree(path) {
171
+ const traversedPath = this.traversePath(path, true);
172
+ return traversedPath.branch.has(traversedPath.leafName) ?
173
+ traversedPath.branch.getFieldTree(traversedPath.leafName) :
174
+ traversedPath.branch.createFieldTree(traversedPath.leafName);
175
+ }
176
+ /**
177
+ * Retrieves a `Fields` container at the specified path. If it or any part of the path doesn't exist, it will be created.
178
+ * @param {PathType} path - The path to the `Fields` container.
179
+ * @returns {Fields} The existing or newly created `Fields` instance.
180
+ */
181
+ getOrCreateFields(path) {
182
+ const traversedPath = this.traversePath(path, true);
183
+ return traversedPath.branch.has(traversedPath.leafName) ?
184
+ traversedPath.branch.getFields(traversedPath.leafName) :
185
+ traversedPath.branch.createFields(traversedPath.leafName);
186
+ }
187
+ /**
188
+ * Finds the parent node for a given path.
189
+ * @param path The path to the target node.
190
+ * @returns The parent node (either a FieldTree or Fields).
191
+ * @throws An error if the path is invalid or any intermediate node is not a FieldTree.
192
+ */
193
+ findParentNode(path) {
194
+ const info = this.traversePath(path);
195
+ return info.branch;
196
+ }
197
+ /**
198
+ * Removes all child nodes from this tree branch.
199
+ * This method ensures that `destroy()` is called on each child node, allowing for
200
+ * a full, recursive cleanup of the entire subtree.
201
+ */
202
+ clear() {
203
+ this.removeNode(Array.from(this._nodes.keys()));
204
+ }
205
+ /**
206
+ * Performs a complete cleanup of this node and its entire subtree.
207
+ *
208
+ * It recursively destroys all child nodes by calling `clear()` and then
209
+ * unsubscribes all listeners from its own event emitters.
210
+ * This method should be called when a node is no longer needed.
211
+ */
212
+ destroy() {
213
+ this.clear();
214
+ this.onAdd.clear();
215
+ this.onRemove.clear();
216
+ }
217
+ /**
218
+ * @private
219
+ * Navigates the tree to the parent of a target node.
220
+ * This is the core traversal logic for all path-based operations.
221
+ * @param {PathType} path - The full path to the target node.
222
+ * @param {boolean} [createPath=false] - If `true`, creates missing `FieldTree` branches along the path.
223
+ * @returns {{branch: FieldTree, leafName: string}} An object containing the final branch (parent node) and the name of the leaf (target node).
224
+ * @throws If the path is empty, invalid, or contains a `Fields` container as an intermediate segment.
225
+ */
226
+ traversePath(path, createPath) {
227
+ const pathArr = ensurePathArray(path);
228
+ throwIfEmpty(pathArr, 'The path is empty');
229
+ const leafName = pathArr.pop();
230
+ let currentNode = this;
231
+ for (const pathPart of pathArr) {
232
+ let node;
233
+ if (currentNode.has(pathPart)) {
234
+ node = currentNode.getNode(pathPart);
235
+ }
236
+ else {
237
+ if (createPath) {
238
+ node = currentNode.createFieldTree(pathPart);
239
+ }
240
+ }
241
+ throwIfEmpty(node, `Can't find node with name ${pathPart} by path parsing: ${ensurePathString(path)}`);
242
+ throwIf(node instanceof Fields, `Node with name ${pathPart} should be instance of FieldTree`);
243
+ currentNode = node;
244
+ }
245
+ return { branch: currentNode, leafName: leafName };
246
+ }
247
+ }
248
+ //# sourceMappingURL=field-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-tree.js","sourceRoot":"","sources":["../src/field-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAY,OAAO,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAMhC;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAS;IACpB,MAAM,CAAU,QAAQ,GAAG,WAAW,CAAC;IAC9B,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;IAEvC,0EAA0E;IACzD,MAAM,GAAmC,IAAI,GAAG,EAAE,CAAC;IAEpE,2DAA2D;IAC1C,QAAQ,CAA4B;IAErD;;;;;;;;;;OAUG;IACH,KAAK,GAAG,IAAI,OAAO,EAGd,CAAC;IAEN;;;;;;;;;OASG;IACH,QAAQ,GAAG,IAAI,OAAO,EAEjB,CAAC;IAEN;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,YAAY,OAAkC;QAC5C,IAAI,CAAC,QAAQ,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AAO,EAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAC,CAAC;IACnD,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Subscribable } from '@axi-engine/utils';
2
+ import { Policies, Policy } from './policies';
3
+ export interface FieldOptions<T> {
4
+ policies?: Policy<T>[];
5
+ }
6
+ export interface Field<T> {
7
+ readonly typeName: string;
8
+ readonly name: string;
9
+ value: T;
10
+ policies: Policies<T>;
11
+ setValueSilently(val: T): void;
12
+ batchUpdate(updateFn: (currentValue: T) => T): void;
13
+ onChange: Subscribable<[newValue: T, oldValue: T]>;
14
+ destroy(): void;
15
+ }
16
+ export interface NumericField extends Field<number> {
17
+ readonly min: number | undefined;
18
+ readonly max: number | undefined;
19
+ isMin(): boolean;
20
+ isMax(): boolean;
21
+ inc(val: number): void;
22
+ dec(val: number): void;
23
+ }
24
+ export interface BooleanField extends Field<boolean> {
25
+ toggle(): boolean;
26
+ }
27
+ export interface StringField extends Field<string> {
28
+ append(str: string | number): this;
29
+ prepend(str: string | number): this;
30
+ trim(): this;
31
+ isEmpty(): boolean;
32
+ clear(): void;
33
+ }
34
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAE5C,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;CACvB;AAED,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAA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