@revisium/schema-toolkit 0.20.2 → 0.21.1

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 (140) hide show
  1. package/README.md +216 -0
  2. package/dist/FormulaPathBuilder-BUJRR0Am.d.cts +48 -0
  3. package/dist/FormulaPathBuilder-QR0htn-e.d.ts +48 -0
  4. package/dist/{chunk-VGADCIBG.cjs → chunk-2PIMJSWJ.cjs} +12 -8
  5. package/dist/chunk-3MJP73IJ.js +1 -0
  6. package/dist/{chunk-LLHQWDAR.js → chunk-4U2RZHMX.js} +19 -21
  7. package/dist/{chunk-Q2UOTIMG.js → chunk-5DUMJHCA.js} +0 -2
  8. package/dist/{chunk-V6JTSET2.cjs → chunk-7JWCZZPJ.cjs} +49 -51
  9. package/dist/{chunk-YFWOURZL.js → chunk-7PEC6ZYY.js} +0 -2
  10. package/dist/chunk-AV5EZUMZ.cjs +2 -0
  11. package/dist/{chunk-3JZKQWQH.js → chunk-AWFMSOHM.js} +5 -7
  12. package/dist/{chunk-X2VRR7V7.cjs → chunk-ERW5XVED.cjs} +0 -2
  13. package/dist/{chunk-XNFSFT7T.cjs → chunk-EVD5ZI55.cjs} +0 -2
  14. package/dist/{chunk-ZRNFSUOV.cjs → chunk-FL6PWPVJ.cjs} +0 -2
  15. package/dist/{chunk-55AMH44G.js → chunk-FTBRJODD.js} +28 -30
  16. package/dist/{chunk-R3MS2N4A.js → chunk-GJM63Q4K.js} +0 -2
  17. package/dist/{chunk-U5YDA3LA.js → chunk-HFMZITNE.js} +238 -31
  18. package/dist/{chunk-EGC32GPY.cjs → chunk-ITYABUR5.cjs} +19 -21
  19. package/dist/{chunk-R4CFU33U.js → chunk-IZMBM36H.js} +10 -9
  20. package/dist/chunk-J4RVO37K.cjs +2 -0
  21. package/dist/{chunk-QEV4Q4TR.js → chunk-JLXX3SGF.js} +30 -32
  22. package/dist/{chunk-MPF6VCB5.js → chunk-NO655UI5.js} +0 -2
  23. package/dist/chunk-OAUVP6CU.js +1 -0
  24. package/dist/{chunk-B3T6YB2D.cjs → chunk-ONW2OVNQ.cjs} +28 -30
  25. package/dist/{chunk-32FZHFIO.cjs → chunk-QKA7DJDN.cjs} +0 -2
  26. package/dist/{chunk-46ME2TAU.cjs → chunk-RCCBUOGY.cjs} +5 -7
  27. package/dist/{chunk-IPL2CGVA.cjs → chunk-RQBW7ATZ.cjs} +0 -2
  28. package/dist/{chunk-FZ2MS4Q5.cjs → chunk-S5SRXND6.cjs} +307 -97
  29. package/dist/{chunk-WSPFHUHU.cjs → chunk-T3QQSHAC.cjs} +0 -2
  30. package/dist/{chunk-J6SCHJKG.cjs → chunk-VMELKZXD.cjs} +0 -2
  31. package/dist/{chunk-5VDDLW7U.js → chunk-WE4OLW5U.js} +0 -2
  32. package/dist/{chunk-JUOGJFTL.js → chunk-XKWWCXGB.js} +0 -2
  33. package/dist/{chunk-ZBPUTF3Q.js → chunk-ZPRBA4AQ.js} +0 -2
  34. package/dist/consts/index.cjs +4 -6
  35. package/dist/consts/index.js +2 -4
  36. package/dist/core/index.cjs +65 -69
  37. package/dist/core/index.d.cts +6 -4
  38. package/dist/core/index.d.ts +6 -4
  39. package/dist/core/index.js +4 -8
  40. package/dist/formula/index.cjs +7 -9
  41. package/dist/formula/index.d.cts +1 -1
  42. package/dist/formula/index.d.ts +1 -1
  43. package/dist/formula/index.js +1 -3
  44. package/dist/index.cjs +269 -248
  45. package/dist/index.d.cts +8 -7
  46. package/dist/index.d.ts +8 -7
  47. package/dist/index.js +15 -18
  48. package/dist/{json-patch.types-DY7k9hxy.d.ts → json-patch.types-BpVnp08Z.d.ts} +1 -1
  49. package/dist/{json-patch.types-Cu0Medki.d.cts → json-patch.types-eM6pYC2P.d.cts} +1 -1
  50. package/dist/{json-string.store-C58zbl31.d.ts → json-string.store-DfdLcgnM.d.ts} +11 -11
  51. package/dist/{json-string.store-DuI--IL2.d.cts → json-string.store-cAOADo23.d.cts} +11 -11
  52. package/dist/lib/index.cjs +51 -54
  53. package/dist/lib/index.d.cts +3 -3
  54. package/dist/lib/index.d.ts +3 -3
  55. package/dist/lib/index.js +7 -10
  56. package/dist/mocks/index.cjs +30 -21
  57. package/dist/mocks/index.d.cts +22 -8
  58. package/dist/mocks/index.d.ts +22 -8
  59. package/dist/mocks/index.js +2 -5
  60. package/dist/model/index.cjs +85 -78
  61. package/dist/model/index.d.cts +171 -346
  62. package/dist/model/index.d.ts +171 -346
  63. package/dist/model/index.js +4 -9
  64. package/dist/plugins/index.cjs +20 -23
  65. package/dist/plugins/index.d.cts +10 -10
  66. package/dist/plugins/index.d.ts +10 -10
  67. package/dist/plugins/index.js +2 -5
  68. package/dist/{schema.types-B5OgKLpV.d.cts → schema.types-On_VGw2m.d.cts} +7 -6
  69. package/dist/{schema.types-B5OgKLpV.d.ts → schema.types-On_VGw2m.d.ts} +7 -6
  70. package/dist/typed-BRZhUqGG.d.ts +502 -0
  71. package/dist/typed-Cri0IYAn.d.cts +502 -0
  72. package/dist/types/index.cjs +6 -9
  73. package/dist/types/index.d.cts +7 -5
  74. package/dist/types/index.d.ts +7 -5
  75. package/dist/types/index.js +2 -5
  76. package/dist/{FormulaPathBuilder-DwlKOvVB.d.ts → types-BIvIURgy.d.cts} +37 -82
  77. package/dist/{FormulaPathBuilder-D9LkBcSv.d.cts → types-C_pTFtSY.d.ts} +37 -82
  78. package/dist/validation-schemas/index.cjs +18 -20
  79. package/dist/validation-schemas/index.js +1 -3
  80. package/package.json +1 -1
  81. package/dist/chunk-32FZHFIO.cjs.map +0 -1
  82. package/dist/chunk-3FJZMVWA.js +0 -3
  83. package/dist/chunk-3FJZMVWA.js.map +0 -1
  84. package/dist/chunk-3IKI64T2.js +0 -3
  85. package/dist/chunk-3IKI64T2.js.map +0 -1
  86. package/dist/chunk-3JZKQWQH.js.map +0 -1
  87. package/dist/chunk-46ME2TAU.cjs.map +0 -1
  88. package/dist/chunk-55AMH44G.js.map +0 -1
  89. package/dist/chunk-5VDDLW7U.js.map +0 -1
  90. package/dist/chunk-B3T6YB2D.cjs.map +0 -1
  91. package/dist/chunk-EGC32GPY.cjs.map +0 -1
  92. package/dist/chunk-FZ2MS4Q5.cjs.map +0 -1
  93. package/dist/chunk-G6ZKEVVU.cjs +0 -4
  94. package/dist/chunk-G6ZKEVVU.cjs.map +0 -1
  95. package/dist/chunk-IPL2CGVA.cjs.map +0 -1
  96. package/dist/chunk-J6SCHJKG.cjs.map +0 -1
  97. package/dist/chunk-JUOGJFTL.js.map +0 -1
  98. package/dist/chunk-L6HE7QPU.cjs +0 -4
  99. package/dist/chunk-L6HE7QPU.cjs.map +0 -1
  100. package/dist/chunk-LLHQWDAR.js.map +0 -1
  101. package/dist/chunk-MPF6VCB5.js.map +0 -1
  102. package/dist/chunk-NY3H6C7K.js +0 -3
  103. package/dist/chunk-NY3H6C7K.js.map +0 -1
  104. package/dist/chunk-Q2UOTIMG.js.map +0 -1
  105. package/dist/chunk-QEV4Q4TR.js.map +0 -1
  106. package/dist/chunk-R3MS2N4A.js.map +0 -1
  107. package/dist/chunk-R4CFU33U.js.map +0 -1
  108. package/dist/chunk-TBFTADML.cjs +0 -4
  109. package/dist/chunk-TBFTADML.cjs.map +0 -1
  110. package/dist/chunk-U5YDA3LA.js.map +0 -1
  111. package/dist/chunk-V6JTSET2.cjs.map +0 -1
  112. package/dist/chunk-VGADCIBG.cjs.map +0 -1
  113. package/dist/chunk-WSPFHUHU.cjs.map +0 -1
  114. package/dist/chunk-X2VRR7V7.cjs.map +0 -1
  115. package/dist/chunk-XNFSFT7T.cjs.map +0 -1
  116. package/dist/chunk-YFWOURZL.js.map +0 -1
  117. package/dist/chunk-ZBPUTF3Q.js.map +0 -1
  118. package/dist/chunk-ZRNFSUOV.cjs.map +0 -1
  119. package/dist/consts/index.cjs.map +0 -1
  120. package/dist/consts/index.js.map +0 -1
  121. package/dist/core/index.cjs.map +0 -1
  122. package/dist/core/index.js.map +0 -1
  123. package/dist/formula/index.cjs.map +0 -1
  124. package/dist/formula/index.js.map +0 -1
  125. package/dist/index.cjs.map +0 -1
  126. package/dist/index.js.map +0 -1
  127. package/dist/json-value-patch.types-CgiEpchp.d.ts +0 -24
  128. package/dist/json-value-patch.types-LEJxcIWR.d.cts +0 -24
  129. package/dist/lib/index.cjs.map +0 -1
  130. package/dist/lib/index.js.map +0 -1
  131. package/dist/mocks/index.cjs.map +0 -1
  132. package/dist/mocks/index.js.map +0 -1
  133. package/dist/model/index.cjs.map +0 -1
  134. package/dist/model/index.js.map +0 -1
  135. package/dist/plugins/index.cjs.map +0 -1
  136. package/dist/plugins/index.js.map +0 -1
  137. package/dist/types/index.cjs.map +0 -1
  138. package/dist/types/index.js.map +0 -1
  139. package/dist/validation-schemas/index.cjs.map +0 -1
  140. package/dist/validation-schemas/index.js.map +0 -1
@@ -1,61 +1,19 @@
1
- import { h as JsonSchemaStore } from '../json-string.store-DuI--IL2.cjs';
2
- export { A as AddedPropertyEvent, C as ChangeNameEvent, f as JsonArrayStore, m as JsonArrayValueStore, b as JsonBooleanStore, k as JsonBooleanValueStore, a as JsonNumberStore, j as JsonNumberValueStore, c as JsonObjectStore, l as JsonObjectValueStore, g as JsonSchemaStorePrimitives, J as JsonStringStore, i as JsonStringValueStore, p as JsonValueStore, o as JsonValueStoreParent, n as JsonValueStorePrimitives, d as MigrateItemsEvent, M as MigratePropertyEvent, R as RemovedPropertyEvent, e as ReplaceItemsEvent } from '../json-string.store-DuI--IL2.cjs';
3
- import { l as SchemaNode, P as Path, j as NodeMetadata, h as SchemaValidationError, T as TreeFormulaValidationError, n as SchemaPatch, m as SchemaTree, D as Diagnostic, B as BasePath, r as BasePathSegment, s as Formula, F as FormulaDependency } from '../FormulaPathBuilder-D9LkBcSv.cjs';
4
- export { b as FormulaPathBuilder, a as FormulaSerializer, R as ResolvedDependency } from '../FormulaPathBuilder-D9LkBcSv.cjs';
5
- import { h as JsonPatch } from '../json-patch.types-Cu0Medki.cjs';
6
- import { f as JsonObjectSchema, i as JsonSchema } from '../schema.types-B5OgKLpV.cjs';
7
- import { d as JsonValuePatch } from '../json-value-patch.types-LEJxcIWR.cjs';
1
+ import { h as JsonSchemaStore } from '../json-string.store-cAOADo23.cjs';
2
+ export { A as AddedPropertyEvent, C as ChangeNameEvent, f as JsonArrayStore, m as JsonArrayValueStore, b as JsonBooleanStore, k as JsonBooleanValueStore, a as JsonNumberStore, j as JsonNumberValueStore, c as JsonObjectStore, l as JsonObjectValueStore, g as JsonSchemaStorePrimitives, J as JsonStringStore, i as JsonStringValueStore, p as JsonValueStore, o as JsonValueStoreParent, n as JsonValueStorePrimitives, d as MigrateItemsEvent, M as MigratePropertyEvent, R as RemovedPropertyEvent, e as ReplaceItemsEvent } from '../json-string.store-cAOADo23.cjs';
3
+ import { a3 as RefSchemas, Y as TypeTransformer, E as FieldTypeSpec, _ as TransformResult, Z as TransformContext, M as RowData, H as SchemaModelOptions, B as SchemaModel, C as FieldType, Q as RowModel, S as SchemaPaths, N as NodeAtPath, V as ValueAtPath, I as InferValue, U as RowModelOptions, z as ValueTreeLike, W as TableModelLike, q as ValueNode, d as JsonValuePatch, L as TableModelOptions, K as TableModel, X as ForeignKeyResolver, R as RefSchemas$1, l as ValueType, a4 as NodeChangeListener, a5 as NodeChangeEvent, O as ObjectValueNode$1, A as ArrayValueNode$1, P as PrimitiveValueNode, r as FormulaWarning, F as FormulaDefinition, y as NodeFactory$1, a6 as ValuePath, a7 as Change, x as NodeFactoryOptions, g as InferNode } from '../typed-Cri0IYAn.cjs';
4
+ export { v as ArrayNodeOptions, a2 as CompositeTypeName, D as DirtyTrackable, $ as FieldSchemaSpec, w as NodeFactoryFn, n as NodeFactoryRegistry, u as ObjectNodeOptions, t as PrimitiveNodeOptions, a1 as PrimitiveTypeName, G as ReplaceResult, a0 as SimpleFieldType, s as ValueNodeOptions, p as createDefaultRegistry, o as createNodeFactory, m as extractFormulaDefinition } from '../typed-Cri0IYAn.cjs';
5
+ import { g as JsonObjectSchema, j as JsonSchema } from '../schema.types-On_VGw2m.cjs';
6
+ import { j as SchemaNode, T as TreeFormulaValidationError, D as Diagnostic, o as Formula, F as FormulaDependency, P as Path } from '../types-BIvIURgy.cjs';
7
+ export { R as ResolvedDependency } from '../types-BIvIURgy.cjs';
8
+ import { S as SchemaTree } from '../FormulaPathBuilder-BUJRR0Am.cjs';
9
+ export { a as FormulaPathBuilder, F as FormulaSerializer } from '../FormulaPathBuilder-BUJRR0Am.cjs';
8
10
  import { ASTNode } from '@revisium/formula';
9
11
  import 'eventemitter3';
10
12
  import '../json.types-PrMmLhba.cjs';
11
-
12
- declare const equal: (value: unknown) => unknown;
13
- declare const fromNumberToString: (value: number, defaultValue?: string) => string;
14
- declare const fromBooleanToString: (value: boolean, defaultValue?: string) => string;
15
- declare const fromStringToBoolean: (value: string, defaultValue?: boolean) => boolean;
16
- declare const fromStringToNumber: (value: string, defaultValue?: number) => number;
17
- declare const fromBooleanToNumber: (value: boolean) => number;
18
- declare const fromNumberToBoolean: (value: number) => boolean;
19
- declare const toArrayTransformation: (transformation: Transformation) => (value: unknown) => unknown[];
20
- declare const fromArrayTransformation: (transformation: Transformation) => (value: unknown) => unknown;
21
- declare const fromObjectToPrimitive: (_value: unknown, defaultValue: unknown) => unknown;
22
- declare const fromPrimitiveToObject: (_value: unknown, defaultValue: unknown) => unknown;
23
- declare const fromObjectToArray: (_value: unknown, defaultValue: unknown) => unknown;
24
- declare const fromArrayToObject: (_value: unknown, defaultValue: unknown) => unknown;
25
- declare const getTransformation: (from: JsonSchemaStore, to: JsonSchemaStore) => Transformation | undefined;
26
- type Transformation = (value: unknown, defaultValue?: unknown) => unknown;
27
-
28
- type PrimitiveTypeName = 'string' | 'number' | 'boolean';
29
- type CompositeTypeName = 'object' | 'array';
30
- type SimpleFieldType = PrimitiveTypeName | CompositeTypeName;
31
- interface FieldSchemaSpec {
32
- type?: SimpleFieldType;
33
- $ref?: string;
34
- default?: unknown;
35
- title?: string;
36
- description?: string;
37
- deprecated?: boolean;
38
- foreignKey?: string;
39
- 'x-formula'?: {
40
- expression: string;
41
- };
42
- }
43
- type FieldTypeSpec = SimpleFieldType | FieldSchemaSpec;
44
- interface TransformContext {
45
- sourceNode: SchemaNode;
46
- targetSpec: FieldSchemaSpec;
47
- refSchemas?: RefSchemas$1;
48
- }
49
- interface TransformResult {
50
- node: SchemaNode;
51
- }
52
- interface TypeTransformer {
53
- canTransform(ctx: TransformContext): boolean;
54
- transform(ctx: TransformContext): TransformResult;
55
- }
13
+ import '../json-patch.types-eM6pYC2P.cjs';
56
14
 
57
15
  interface TypeTransformChainOptions {
58
- refSchemas?: RefSchemas$1;
16
+ refSchemas?: RefSchemas;
59
17
  customTransformers?: TypeTransformer[];
60
18
  }
61
19
  declare class TypeTransformChain {
@@ -97,62 +55,43 @@ declare class DefaultTransformer implements TypeTransformer {
97
55
  private extractMetadata;
98
56
  }
99
57
 
100
- type RefSchemas$1 = Record<string, JsonSchema>;
101
- interface SchemaModelOptions {
102
- refSchemas?: RefSchemas$1;
103
- customTransformers?: TypeTransformer[];
58
+ interface ForeignKeyRowLoaderResult {
59
+ schema: JsonObjectSchema;
60
+ row: RowData;
104
61
  }
105
- type FieldType = 'string' | 'number' | 'boolean' | 'object' | 'array';
106
-
107
- interface ReplaceResult {
108
- replacedNodeId: string;
109
- newNodeId: string;
110
- }
111
- interface SchemaModel {
112
- readonly root: SchemaNode;
113
- nodeById(id: string): SchemaNode;
114
- pathOf(id: string): Path;
115
- addField(parentId: string, name: string, type: FieldType): SchemaNode;
116
- insertFieldAt(parentId: string, index: number, name: string, type: FieldType): SchemaNode;
117
- removeField(nodeId: string): boolean;
118
- renameField(nodeId: string, newName: string): void;
119
- changeFieldType(nodeId: string, newType: FieldTypeSpec): SchemaNode;
120
- updateMetadata(nodeId: string, meta: Partial<NodeMetadata>): void;
121
- updateFormula(nodeId: string, expression: string | undefined): void;
122
- updateForeignKey(nodeId: string, foreignKey: string | undefined): void;
123
- updateDefaultValue(nodeId: string, value: unknown): void;
124
- wrapInArray(nodeId: string): ReplaceResult | null;
125
- wrapRootInArray(): ReplaceResult | null;
126
- replaceRoot(newType: FieldType): ReplaceResult | null;
127
- canMoveNode(nodeId: string, targetParentId: string): boolean;
128
- hasValidDropTarget(nodeId: string): boolean;
129
- moveNode(nodeId: string, targetParentId: string): void;
130
- getFormulaDependents(nodeId: string): readonly string[];
131
- hasFormulaDependents(nodeId: string): boolean;
132
- serializeFormula(nodeId: string): string;
133
- readonly validationErrors: SchemaValidationError[];
134
- readonly formulaErrors: TreeFormulaValidationError[];
135
- readonly isDirty: boolean;
136
- readonly isValid: boolean;
137
- readonly patches: SchemaPatch[];
138
- readonly jsonPatches: JsonPatch[];
139
- markAsSaved(): void;
140
- revert(): void;
141
- readonly plainSchema: JsonObjectSchema;
142
- readonly nodeCount: number;
143
- readonly refSchemas: RefSchemas$1 | undefined;
144
- generateDefaultValue(options?: {
145
- arrayItemCount?: number;
146
- }): unknown;
62
+ interface ForeignKeyLoader {
63
+ loadSchema(tableId: string): Promise<JsonObjectSchema>;
64
+ loadRow(tableId: string, rowId: string): Promise<ForeignKeyRowLoaderResult>;
65
+ }
66
+ interface ForeignKeyResolverOptions {
67
+ loader?: ForeignKeyLoader;
68
+ prefetch?: boolean;
69
+ prefetchDepth?: 1;
147
70
  }
148
71
 
72
+ declare const equal: (value: unknown) => unknown;
73
+ declare const fromNumberToString: (value: number, defaultValue?: string) => string;
74
+ declare const fromBooleanToString: (value: boolean, defaultValue?: string) => string;
75
+ declare const fromStringToBoolean: (value: string, defaultValue?: boolean) => boolean;
76
+ declare const fromStringToNumber: (value: string, defaultValue?: number) => number;
77
+ declare const fromBooleanToNumber: (value: boolean) => number;
78
+ declare const fromNumberToBoolean: (value: number) => boolean;
79
+ declare const toArrayTransformation: (transformation: Transformation) => (value: unknown) => unknown[];
80
+ declare const fromArrayTransformation: (transformation: Transformation) => (value: unknown) => unknown;
81
+ declare const fromObjectToPrimitive: (_value: unknown, defaultValue: unknown) => unknown;
82
+ declare const fromPrimitiveToObject: (_value: unknown, defaultValue: unknown) => unknown;
83
+ declare const fromObjectToArray: (_value: unknown, defaultValue: unknown) => unknown;
84
+ declare const fromArrayToObject: (_value: unknown, defaultValue: unknown) => unknown;
85
+ declare const getTransformation: (from: JsonSchemaStore, to: JsonSchemaStore) => Transformation | undefined;
86
+ type Transformation = (value: unknown, defaultValue?: unknown) => unknown;
87
+
149
88
  declare function createSchemaModel(schema: JsonObjectSchema, options?: SchemaModelOptions): SchemaModel;
150
89
 
151
90
  declare class SchemaParser {
152
91
  private pendingFormulas;
153
92
  private _parseErrors;
154
93
  private _refSchemas;
155
- parse(schema: JsonObjectSchema, refSchemas?: RefSchemas$1): SchemaNode;
94
+ parse(schema: JsonObjectSchema, refSchemas?: RefSchemas): SchemaNode;
156
95
  parseFormulas(tree: SchemaTree): void;
157
96
  get parseErrors(): TreeFormulaValidationError[];
158
97
  private parseNode;
@@ -165,255 +104,21 @@ declare class SchemaParser {
165
104
  private collectFormula;
166
105
  }
167
106
 
168
- declare class NodeFactory$1 {
107
+ declare class NodeFactory {
169
108
  createNode(name: string, type: FieldType): SchemaNode;
170
109
  private createArrayNodeInternal;
171
110
  createArrayNodeWithItems(name: string, items: SchemaNode): SchemaNode;
172
111
  }
173
112
 
174
- declare enum ValueType {
175
- String = "string",
176
- Number = "number",
177
- Boolean = "boolean",
178
- Object = "object",
179
- Array = "array"
113
+ interface TypedRowModel<S> extends RowModel {
114
+ get<P extends SchemaPaths<S>>(path: P): NodeAtPath<S, P>;
115
+ getValue<P extends SchemaPaths<S>>(path: P): ValueAtPath<S, P>;
116
+ setValue<P extends SchemaPaths<S>>(path: P, value: ValueAtPath<S, P>): void;
117
+ getPlainValue(): InferValue<S>;
180
118
  }
181
- interface FormulaDefinition {
182
- readonly expression: string;
183
- readonly version: number;
184
- }
185
- interface FormulaWarning {
186
- readonly type: 'nan' | 'infinity' | 'type-coercion' | 'division-by-zero' | 'null-reference' | 'runtime-error';
187
- readonly message: string;
188
- readonly expression: string;
189
- readonly computedValue: unknown;
190
- }
191
- interface ValueNode {
192
- readonly id: string;
193
- readonly type: ValueType;
194
- readonly schema: JsonSchema;
195
- parent: ValueNode | null;
196
- readonly name: string;
197
- readonly value: unknown;
198
- getPlainValue(): unknown;
199
- isObject(): this is ObjectValueNode$1;
200
- isArray(): this is ArrayValueNode$1;
201
- isPrimitive(): this is PrimitiveValueNode;
202
- readonly errors: readonly Diagnostic[];
203
- readonly warnings: readonly Diagnostic[];
204
- readonly isValid: boolean;
205
- readonly hasWarnings: boolean;
206
- }
207
- interface DirtyTrackable {
208
- readonly isDirty: boolean;
209
- commit(): void;
210
- revert(): void;
211
- }
212
- interface PrimitiveValueNode extends ValueNode, DirtyTrackable {
213
- value: string | number | boolean;
214
- readonly baseValue: string | number | boolean;
215
- readonly defaultValue: unknown;
216
- readonly formula: FormulaDefinition | undefined;
217
- readonly formulaWarning: FormulaWarning | null;
218
- readonly isReadOnly: boolean;
219
- setValue(value: unknown, options?: {
220
- internal?: boolean;
221
- }): void;
222
- setFormulaWarning(warning: FormulaWarning | null): void;
223
- }
224
- interface ObjectValueNode$1 extends ValueNode, DirtyTrackable {
225
- readonly value: Record<string, ValueNode>;
226
- readonly children: readonly ValueNode[];
227
- child(name: string): ValueNode | undefined;
228
- addChild(node: ValueNode): void;
229
- removeChild(name: string): void;
230
- hasChild(name: string): boolean;
231
- }
232
- interface ArrayValueNode$1 extends ValueNode, DirtyTrackable {
233
- readonly value: readonly ValueNode[];
234
- readonly length: number;
235
- at(index: number): ValueNode | undefined;
236
- push(node: ValueNode): void;
237
- insertAt(index: number, node: ValueNode): void;
238
- removeAt(index: number): void;
239
- move(fromIndex: number, toIndex: number): void;
240
- replaceAt(index: number, node: ValueNode): void;
241
- clear(): void;
242
- setNodeFactory(factory: NodeFactory): void;
243
- pushValue(value?: unknown): void;
244
- insertValueAt(index: number, value?: unknown): void;
245
- }
246
- interface ValueNodeOptions {
247
- readonly id?: string;
248
- readonly name: string;
249
- readonly schema: JsonSchema;
250
- readonly parent?: ValueNode | null;
251
- }
252
- interface PrimitiveNodeOptions extends ValueNodeOptions {
253
- readonly value?: unknown;
254
- }
255
- interface ObjectNodeOptions extends ValueNodeOptions {
256
- readonly children?: ValueNode[];
257
- }
258
- interface ArrayNodeOptions extends ValueNodeOptions {
259
- readonly items?: ValueNode[];
260
- }
261
- declare function extractFormulaDefinition(schema: JsonSchema): FormulaDefinition | undefined;
262
-
263
- type NodeFactoryFn = (name: string, schema: JsonSchema, value: unknown, id?: string) => ValueNode;
264
- declare class NodeFactoryRegistry {
265
- private readonly factories;
266
- register(schemaType: string, factory: NodeFactoryFn): this;
267
- get(schemaType: string): NodeFactoryFn | undefined;
268
- has(schemaType: string): boolean;
269
- }
270
- type RefSchemas = Record<string, JsonSchema>;
271
- interface NodeFactoryOptions {
272
- refSchemas?: RefSchemas;
273
- fkResolver?: ForeignKeyResolver;
274
- }
275
- declare class NodeFactory {
276
- private readonly registry;
277
- private readonly refSchemas;
278
- constructor(registry: NodeFactoryRegistry, options?: NodeFactoryOptions);
279
- create(name: string, schema: JsonSchema, value: unknown, id?: string): ValueNode;
280
- createTree(schema: JsonSchema, value: unknown): ValueNode;
281
- private getSchemaType;
282
- private resolveSchema;
283
- }
284
- declare function createDefaultRegistry(fkResolver?: ForeignKeyResolver): NodeFactoryRegistry;
285
- declare function createNodeFactory(options?: NodeFactoryOptions): NodeFactory;
286
-
287
- interface RowData {
288
- rowId: string;
289
- data: unknown;
290
- }
291
- interface TableModelOptions {
292
- tableId: string;
293
- schema: JsonObjectSchema;
294
- rows?: RowData[];
295
- fkResolver?: ForeignKeyResolver;
296
- refSchemas?: RefSchemas;
297
- }
298
- interface TableModel {
299
- readonly fk: ForeignKeyResolver | undefined;
300
- readonly refSchemas: RefSchemas | undefined;
301
- readonly tableId: string;
302
- readonly baseTableId: string;
303
- readonly isRenamed: boolean;
304
- rename(newTableId: string): void;
305
- readonly schema: SchemaModel;
306
- readonly rows: readonly RowModel[];
307
- readonly rowCount: number;
308
- addRow(rowId: string, data?: unknown): RowModel;
309
- removeRow(rowId: string): void;
310
- getRow(rowId: string): RowModel | undefined;
311
- getRowIndex(rowId: string): number;
312
- getRowAt(index: number): RowModel | undefined;
313
- readonly isDirty: boolean;
314
- commit(): void;
315
- revert(): void;
316
- dispose(): void;
317
- }
318
-
319
- interface ForeignKeyLoaderResult {
320
- schema: JsonObjectSchema;
321
- rows: RowData[];
322
- }
323
- interface ForeignKeyRowLoaderResult {
324
- schema: JsonObjectSchema;
325
- row: RowData;
326
- }
327
- interface ForeignKeyLoader {
328
- loadSchema(tableId: string): Promise<JsonObjectSchema>;
329
- loadTable(tableId: string): Promise<ForeignKeyLoaderResult>;
330
- loadRow(tableId: string, rowId: string): Promise<ForeignKeyRowLoaderResult>;
331
- }
332
- interface ForeignKeyResolverOptions {
333
- loader?: ForeignKeyLoader;
334
- prefetch?: boolean;
335
- prefetchDepth?: 1;
336
- }
337
-
338
- interface ForeignKeyResolver {
339
- addSchema(tableId: string, schema: JsonObjectSchema): void;
340
- addTable(tableId: string, schema: JsonObjectSchema, rows: RowData[]): void;
341
- addRow(tableId: string, rowId: string, data: unknown): void;
342
- renameTable(oldTableId: string, newTableId: string): void;
343
- getSchema(tableId: string): Promise<JsonObjectSchema>;
344
- getRowData(tableId: string, rowId: string): Promise<RowData>;
345
- isLoading(tableId: string): boolean;
346
- isLoadingRow(tableId: string, rowId: string): boolean;
347
- hasSchema(tableId: string): boolean;
348
- hasTable(tableId: string): boolean;
349
- hasRow(tableId: string, rowId: string): boolean;
350
- setPrefetch(enabled: boolean): void;
351
- readonly isPrefetchEnabled: boolean;
352
- dispose(): void;
353
- }
354
-
355
- interface ValuePathSegment extends BasePathSegment {
356
- isProperty(): boolean;
357
- isIndex(): boolean;
358
- propertyName(): string;
359
- indexValue(): number;
360
- equals(other: ValuePathSegment): boolean;
361
- }
362
- interface ValuePath extends BasePath<ValuePathSegment, ValuePath> {
363
- asString(): string;
364
- asJsonPointer(): string;
365
- child(name: string): ValuePath;
366
- childIndex(index: number): ValuePath;
367
- }
368
-
369
- interface ValueTreeLike {
370
- readonly root: ValueNode;
371
- get(path: string): ValueNode | undefined;
372
- getValue(path: string): unknown;
373
- setValue(path: string, value: unknown): void;
374
- getPlainValue(): unknown;
375
- readonly isDirty: boolean;
376
- readonly isValid: boolean;
377
- readonly errors: readonly Diagnostic[];
378
- getPatches(): readonly JsonValuePatch[];
379
- commit(): void;
380
- revert(): void;
381
- nodeById(id: string): ValueNode | undefined;
382
- pathOf(nodeOrId: ValueNode | string): ValuePath;
383
- dispose(): void;
384
- }
385
-
386
- interface RowModelOptions {
387
- rowId: string;
388
- schema: JsonSchema;
389
- data?: unknown;
390
- fkResolver?: ForeignKeyResolver;
391
- refSchemas?: RefSchemas;
392
- }
393
- interface TableModelLike {
394
- getRowIndex(rowId: string): number;
395
- getRowAt(index: number): RowModel | undefined;
396
- readonly rowCount: number;
397
- }
398
- interface RowModel {
399
- readonly rowId: string;
400
- readonly tableModel: TableModelLike | null;
401
- readonly tree: ValueTreeLike;
402
- readonly index: number;
403
- readonly prev: RowModel | null;
404
- readonly next: RowModel | null;
405
- get(path: string): ValueNode | undefined;
406
- getValue(path: string): unknown;
407
- setValue(path: string, value: unknown): void;
408
- getPlainValue(): unknown;
409
- nodeById(id: string): ValueNode | undefined;
410
- readonly isDirty: boolean;
411
- readonly isValid: boolean;
412
- readonly errors: readonly Diagnostic[];
413
- getPatches(): readonly JsonValuePatch[];
414
- commit(): void;
415
- revert(): void;
416
- dispose(): void;
119
+ interface TypedRowModelOptions<S extends JsonSchema> extends Omit<RowModelOptions, 'schema' | 'data'> {
120
+ schema: S;
121
+ data?: InferValue<S>;
417
122
  }
418
123
 
419
124
  declare class RowModelImpl implements RowModel {
@@ -441,8 +146,24 @@ declare class RowModelImpl implements RowModel {
441
146
  dispose(): void;
442
147
  setTableModel(tableModel: TableModelLike | null): void;
443
148
  }
149
+ declare function createRowModel<const S extends JsonSchema>(options: TypedRowModelOptions<S>): TypedRowModel<S>;
444
150
  declare function createRowModel(options: RowModelOptions): RowModel;
445
151
 
152
+ interface TypedRowData<S> {
153
+ rowId: string;
154
+ data: InferValue<S>;
155
+ }
156
+ interface TypedTableModel<S> extends TableModel {
157
+ readonly rows: readonly TypedRowModel<S>[];
158
+ addRow(rowId: string, data?: InferValue<S>): TypedRowModel<S>;
159
+ getRow(rowId: string): TypedRowModel<S> | undefined;
160
+ getRowAt(index: number): TypedRowModel<S> | undefined;
161
+ }
162
+ interface TypedTableModelOptions<S extends JsonObjectSchema> extends Omit<TableModelOptions, 'schema' | 'rows'> {
163
+ schema: S;
164
+ rows?: TypedRowData<S>[];
165
+ }
166
+
446
167
  declare class TableModelImpl implements TableModel {
447
168
  private _tableId;
448
169
  private _baseTableId;
@@ -456,7 +177,7 @@ declare class TableModelImpl implements TableModel {
456
177
  get baseTableId(): string;
457
178
  get isRenamed(): boolean;
458
179
  get fk(): ForeignKeyResolver | undefined;
459
- get refSchemas(): RefSchemas | undefined;
180
+ get refSchemas(): RefSchemas$1 | undefined;
460
181
  get schema(): SchemaModel;
461
182
  get rows(): readonly RowModel[];
462
183
  get rowCount(): number;
@@ -472,6 +193,7 @@ declare class TableModelImpl implements TableModel {
472
193
  dispose(): void;
473
194
  private createRow;
474
195
  }
196
+ declare function createTableModel<const S extends JsonObjectSchema>(options: TypedTableModelOptions<S>): TypedTableModel<S>;
475
197
  declare function createTableModel(options: TableModelOptions): TableModel;
476
198
 
477
199
  interface GenerateDefaultValueOptions {
@@ -634,7 +356,11 @@ declare abstract class BaseValueNode implements ValueNode {
634
356
  readonly schema: JsonSchema;
635
357
  private _parent;
636
358
  private readonly _name;
359
+ private readonly _emitter;
637
360
  constructor(id: string | undefined, name: string, schema: JsonSchema);
361
+ on(event: 'change', listener: NodeChangeListener): void;
362
+ off(event: 'change', listener: NodeChangeListener): void;
363
+ protected emit(changeEvent: NodeChangeEvent): void;
638
364
  get parent(): ValueNode | null;
639
365
  set parent(value: ValueNode | null);
640
366
  get name(): string;
@@ -718,6 +444,9 @@ declare class ObjectValueNode extends BaseValueNode implements ObjectValueNode$1
718
444
  hasChild(name: string): boolean;
719
445
  addChild(node: ValueNode): void;
720
446
  removeChild(name: string): void;
447
+ setValue(value: Record<string, unknown>, options?: {
448
+ internal?: boolean;
449
+ }): void;
721
450
  get isDirty(): boolean;
722
451
  commit(): void;
723
452
  revert(): void;
@@ -742,9 +471,12 @@ declare class ArrayValueNode extends BaseValueNode implements ArrayValueNode$1 {
742
471
  move(fromIndex: number, toIndex: number): void;
743
472
  replaceAt(index: number, node: ValueNode): void;
744
473
  clear(): void;
745
- setNodeFactory(factory: NodeFactory): void;
474
+ setNodeFactory(factory: NodeFactory$1): void;
746
475
  pushValue(value?: unknown): void;
747
476
  insertValueAt(index: number, value?: unknown): void;
477
+ setValue(value: unknown[], options?: {
478
+ internal?: boolean;
479
+ }): void;
748
480
  private createItemNode;
749
481
  private propagateFactory;
750
482
  get isDirty(): boolean;
@@ -773,4 +505,97 @@ declare class ForeignKeyValueNodeImpl extends StringValueNode implements Foreign
773
505
  getSchema(): Promise<JsonObjectSchema>;
774
506
  }
775
507
 
776
- export { type ArrayNodeOptions, ArrayToItemsTypeTransformer, ArrayValueNode, type ArrayValueNode$1 as ArrayValueNodeInterface, BasePrimitiveValueNode, BaseValueNode, BooleanValueNode, type CompositeTypeName, type DataModel, DataModelImpl, type DataModelOptions, DefaultTransformer, type DirtyTrackable, type FieldSchemaSpec, type FieldType, type FieldTypeSpec, type ForeignKeyLoader, type ForeignKeyLoaderResult, ForeignKeyNotFoundError, type ForeignKeyResolver, ForeignKeyResolverImpl, ForeignKeyResolverNotConfiguredError, type ForeignKeyResolverOptions, type ForeignKeyRowLoaderResult, type ForeignKeyValueNode, ForeignKeyValueNodeImpl, FormulaChangeDetector, type FormulaDefinition, FormulaDependency, FormulaDependencyIndex, FormulaPath, type FormulaWarning, type GenerateDefaultValueOptions, type IndirectFormulaChange, JsonSchemaStore, NodeFactory$1 as NodeFactory, type NodeFactoryFn, type NodeFactoryOptions, NodeFactoryRegistry, NumberValueNode, type ObjectNodeOptions, ObjectToArrayTransformer, ObjectValueNode, type ObjectValueNode$1 as ObjectValueNodeInterface, ParsedFormula, type PrimitiveNodeOptions, PrimitiveToArrayTransformer, type PrimitiveTypeName, type PrimitiveValueNode, type RefSchemas, RefTransformer, type ReplaceResult, type RowData, type RowModel, RowModelImpl, type RowModelOptions, type SchemaModel, type SchemaModelOptions, SchemaParser, type SimpleFieldType, StringValueNode, type TableModel, TableModelImpl, type TableModelLike, type TableModelOptions, type TransformContext, type TransformResult, TypeTransformChain, type TypeTransformChainOptions, type TypeTransformer, type ValueNode, NodeFactory as ValueNodeFactory, type ValueNodeOptions, type ValueTreeLike, ValueType, createDataModel, createDefaultRegistry, createForeignKeyResolver, createNodeFactory, createRowModel, createSchemaModel, createTableModel, createTypeTransformChain, equal, extractFormulaDefinition, fromArrayToObject, fromArrayTransformation, fromBooleanToNumber, fromBooleanToString, fromNumberToBoolean, fromNumberToString, fromObjectToArray, fromObjectToPrimitive, fromPrimitiveToObject, fromStringToBoolean, fromStringToNumber, generateDefaultValue, generateNodeId, getTransformation, isForeignKeyValueNode, resetNodeIdCounter, toArrayTransformation };
508
+ interface FormulaArrayLevel {
509
+ readonly array: ArrayValueNode$1;
510
+ readonly index: number;
511
+ }
512
+ interface FormulaField {
513
+ readonly node: PrimitiveValueNode;
514
+ readonly expression: string;
515
+ readonly parent: ObjectValueNode$1 | null;
516
+ readonly dependencyNodes: readonly PrimitiveValueNode[];
517
+ readonly arrayLevels: readonly FormulaArrayLevel[];
518
+ }
519
+ interface FormulaEngineOptions {
520
+ onError?: (node: PrimitiveValueNode, error: Error) => void;
521
+ onWarning?: (node: PrimitiveValueNode, type: string, message: string) => void;
522
+ }
523
+ interface ValueTreeRoot {
524
+ readonly root: ValueNode;
525
+ getPlainValue(): unknown;
526
+ }
527
+
528
+ declare class FormulaEngine {
529
+ private readonly tree;
530
+ private readonly collector;
531
+ private readonly graph;
532
+ private readonly evaluator;
533
+ private formulas;
534
+ private dependencyMap;
535
+ private evaluationOrder;
536
+ private disposers;
537
+ constructor(tree: ValueTreeRoot, options?: FormulaEngineOptions);
538
+ reinitialize(): void;
539
+ dispose(): void;
540
+ getFormulas(): readonly FormulaField[];
541
+ getEvaluationOrder(): readonly FormulaField[];
542
+ private initialize;
543
+ private evaluateAll;
544
+ private setupReactions;
545
+ private setupArrayReactions;
546
+ private handleDependencyChange;
547
+ private handleStructureChange;
548
+ private disposeReactions;
549
+ }
550
+
551
+ declare class ValueTree implements ValueTreeLike {
552
+ private readonly _root;
553
+ private readonly index;
554
+ private readonly changeTracker;
555
+ private readonly _nodeChangeListener;
556
+ private _formulaEngine;
557
+ private _suppressEvents;
558
+ constructor(_root: ValueNode);
559
+ get root(): ValueNode;
560
+ nodeById(id: string): ValueNode | undefined;
561
+ pathOf(nodeOrId: ValueNode | string): ValuePath;
562
+ get(path: string): ValueNode | undefined;
563
+ getValue(path: string): unknown;
564
+ setValue(path: string, value: unknown, options?: {
565
+ internal?: boolean;
566
+ }): void;
567
+ getPlainValue(): unknown;
568
+ get isDirty(): boolean;
569
+ get isValid(): boolean;
570
+ get errors(): readonly Diagnostic[];
571
+ getPatches(): readonly JsonValuePatch[];
572
+ trackChange(change: Change): void;
573
+ commit(): void;
574
+ revert(): void;
575
+ rebuildIndex(): void;
576
+ registerNode(node: ValueNode): void;
577
+ invalidatePathsUnder(node: ValueNode): void;
578
+ setFormulaEngine(engine: FormulaEngine): void;
579
+ get formulaEngine(): FormulaEngine | null;
580
+ dispose(): void;
581
+ private handleNodeChange;
582
+ private toArrayItemChange;
583
+ private toArrayStructureChange;
584
+ private adoptNode;
585
+ private walkTree;
586
+ private subscribe;
587
+ private unsubscribe;
588
+ }
589
+
590
+ interface TypedValueTree<S> extends ValueTreeLike {
591
+ readonly root: InferNode<S>;
592
+ get<P extends SchemaPaths<S>>(path: P): NodeAtPath<S, P>;
593
+ getValue<P extends SchemaPaths<S>>(path: P): ValueAtPath<S, P>;
594
+ setValue<P extends SchemaPaths<S>>(path: P, value: ValueAtPath<S, P>, options?: {
595
+ internal?: boolean;
596
+ }): void;
597
+ }
598
+ declare function typedNode<S extends JsonSchema>(node: ValueNode): InferNode<S>;
599
+ declare function createTypedTree<const S extends JsonSchema>(schema: S, data: InferValue<S>, options?: NodeFactoryOptions): TypedValueTree<S>;
600
+
601
+ export { ArrayToItemsTypeTransformer, ArrayValueNode, ArrayValueNode$1 as ArrayValueNodeInterface, BasePrimitiveValueNode, BaseValueNode, BooleanValueNode, type DataModel, DataModelImpl, type DataModelOptions, DefaultTransformer, FieldType, FieldTypeSpec, type ForeignKeyLoader, ForeignKeyNotFoundError, ForeignKeyResolver, ForeignKeyResolverImpl, ForeignKeyResolverNotConfiguredError, type ForeignKeyResolverOptions, type ForeignKeyRowLoaderResult, type ForeignKeyValueNode, ForeignKeyValueNodeImpl, FormulaChangeDetector, FormulaDefinition, FormulaDependency, FormulaDependencyIndex, FormulaPath, FormulaWarning, type GenerateDefaultValueOptions, type IndirectFormulaChange, JsonSchemaStore, NodeFactory, NodeFactoryOptions, NumberValueNode, ObjectToArrayTransformer, ObjectValueNode, ObjectValueNode$1 as ObjectValueNodeInterface, ParsedFormula, PrimitiveToArrayTransformer, PrimitiveValueNode, RefSchemas$1 as RefSchemas, RefTransformer, RowData, RowModel, RowModelImpl, RowModelOptions, SchemaModel, SchemaModelOptions, SchemaParser, StringValueNode, TableModel, TableModelImpl, TableModelLike, TableModelOptions, TransformContext, TransformResult, TypeTransformChain, type TypeTransformChainOptions, TypeTransformer, type TypedRowData, type TypedRowModel, type TypedRowModelOptions, type TypedTableModel, type TypedTableModelOptions, type TypedValueTree, ValueNode, NodeFactory$1 as ValueNodeFactory, ValueTree, ValueTreeLike, ValueType, createDataModel, createForeignKeyResolver, createRowModel, createSchemaModel, createTableModel, createTypeTransformChain, createTypedTree, equal, fromArrayToObject, fromArrayTransformation, fromBooleanToNumber, fromBooleanToString, fromNumberToBoolean, fromNumberToString, fromObjectToArray, fromObjectToPrimitive, fromPrimitiveToObject, fromStringToBoolean, fromStringToNumber, generateDefaultValue, generateNodeId, getTransformation, isForeignKeyValueNode, resetNodeIdCounter, toArrayTransformation, typedNode };