@revisium/schema-toolkit 0.16.4 → 0.16.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.
@@ -1,14 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var chunkVGB4YCGF_cjs = require('./chunk-VGB4YCGF.cjs');
3
+ var chunkHLGT7PCU_cjs = require('./chunk-HLGT7PCU.cjs');
4
4
  var nanoid = require('nanoid');
5
5
 
6
6
  var SchemaParser = class {
7
7
  pendingFormulas = [];
8
8
  _parseErrors = [];
9
- parse(schema) {
9
+ _refSchemas = {};
10
+ parse(schema, refSchemas) {
10
11
  this.pendingFormulas = [];
11
12
  this._parseErrors = [];
13
+ this._refSchemas = refSchemas ?? {};
12
14
  return this.parseNode(schema, "root");
13
15
  }
14
16
  parseFormulas(tree) {
@@ -18,7 +20,7 @@ var SchemaParser = class {
18
20
  continue;
19
21
  }
20
22
  try {
21
- const formula = new chunkVGB4YCGF_cjs.ParsedFormula(tree, pending.nodeId, pending.expression);
23
+ const formula = new chunkHLGT7PCU_cjs.ParsedFormula(tree, pending.nodeId, pending.expression);
22
24
  node.setFormula(formula);
23
25
  } catch (error) {
24
26
  this._parseErrors.push({
@@ -32,27 +34,32 @@ var SchemaParser = class {
32
34
  get parseErrors() {
33
35
  return this._parseErrors;
34
36
  }
35
- parseNode(schema, name) {
37
+ parseNode(schema, name, parentRef) {
36
38
  if ("$ref" in schema) {
37
- return chunkVGB4YCGF_cjs.createRefNode(nanoid.nanoid(), name, schema.$ref, this.extractMetadata(schema));
39
+ const refValue = schema.$ref;
40
+ const resolvedSchema = this._refSchemas[refValue];
41
+ if (resolvedSchema) {
42
+ return this.parseNode(resolvedSchema, name, refValue);
43
+ }
44
+ return chunkHLGT7PCU_cjs.createRefNode(nanoid.nanoid(), name, refValue, this.extractMetadata(schema));
38
45
  }
39
46
  const schemaWithType = schema;
40
47
  switch (schemaWithType.type) {
41
48
  case "object" /* Object */:
42
- return this.parseObject(schemaWithType, name);
49
+ return this.parseObject(schemaWithType, name, parentRef);
43
50
  case "array" /* Array */:
44
- return this.parseArray(schemaWithType, name);
51
+ return this.parseArray(schemaWithType, name, parentRef);
45
52
  case "string" /* String */:
46
- return this.parseString(schemaWithType, name);
53
+ return this.parseString(schemaWithType, name, parentRef);
47
54
  case "number" /* Number */:
48
- return this.parseNumber(schemaWithType, name);
55
+ return this.parseNumber(schemaWithType, name, parentRef);
49
56
  case "boolean" /* Boolean */:
50
- return this.parseBoolean(schemaWithType, name);
57
+ return this.parseBoolean(schemaWithType, name, parentRef);
51
58
  default:
52
59
  throw new Error(`Unknown schema type: ${schemaWithType.type}`);
53
60
  }
54
61
  }
55
- parseObject(schema, name) {
62
+ parseObject(schema, name, ref) {
56
63
  const children = [];
57
64
  for (const propName of Object.keys(schema.properties).sort((a, b) => a.localeCompare(b))) {
58
65
  const propSchema = schema.properties[propName];
@@ -60,35 +67,44 @@ var SchemaParser = class {
60
67
  children.push(this.parseNode(propSchema, propName));
61
68
  }
62
69
  }
63
- return chunkVGB4YCGF_cjs.createObjectNode(nanoid.nanoid(), name, children, this.extractMetadata(schema));
70
+ return chunkHLGT7PCU_cjs.createObjectNode(nanoid.nanoid(), name, children, {
71
+ metadata: this.extractMetadata(schema),
72
+ ref
73
+ });
64
74
  }
65
- parseArray(schema, name) {
75
+ parseArray(schema, name, ref) {
66
76
  const items = this.parseNode(schema.items, "items");
67
- return chunkVGB4YCGF_cjs.createArrayNode(nanoid.nanoid(), name, items, this.extractMetadata(schema));
77
+ return chunkHLGT7PCU_cjs.createArrayNode(nanoid.nanoid(), name, items, {
78
+ metadata: this.extractMetadata(schema),
79
+ ref
80
+ });
68
81
  }
69
- parseString(schema, name) {
82
+ parseString(schema, name, ref) {
70
83
  const nodeId = nanoid.nanoid();
71
84
  this.collectFormula(nodeId, schema["x-formula"]);
72
- return chunkVGB4YCGF_cjs.createStringNode(nodeId, name, {
85
+ return chunkHLGT7PCU_cjs.createStringNode(nodeId, name, {
73
86
  defaultValue: schema.default,
74
87
  foreignKey: schema.foreignKey,
75
- metadata: this.extractMetadata(schema)
88
+ metadata: this.extractMetadata(schema),
89
+ ref
76
90
  });
77
91
  }
78
- parseNumber(schema, name) {
92
+ parseNumber(schema, name, ref) {
79
93
  const nodeId = nanoid.nanoid();
80
94
  this.collectFormula(nodeId, schema["x-formula"]);
81
- return chunkVGB4YCGF_cjs.createNumberNode(nodeId, name, {
95
+ return chunkHLGT7PCU_cjs.createNumberNode(nodeId, name, {
82
96
  defaultValue: schema.default,
83
- metadata: this.extractMetadata(schema)
97
+ metadata: this.extractMetadata(schema),
98
+ ref
84
99
  });
85
100
  }
86
- parseBoolean(schema, name) {
101
+ parseBoolean(schema, name, ref) {
87
102
  const nodeId = nanoid.nanoid();
88
103
  this.collectFormula(nodeId, schema["x-formula"]);
89
- return chunkVGB4YCGF_cjs.createBooleanNode(nodeId, name, {
104
+ return chunkHLGT7PCU_cjs.createBooleanNode(nodeId, name, {
90
105
  defaultValue: schema.default,
91
- metadata: this.extractMetadata(schema)
106
+ metadata: this.extractMetadata(schema),
107
+ ref
92
108
  });
93
109
  }
94
110
  extractMetadata(schema) {
@@ -118,13 +134,13 @@ var NodeFactory = class {
118
134
  createNode(name, type) {
119
135
  switch (type) {
120
136
  case "string":
121
- return chunkVGB4YCGF_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
137
+ return chunkHLGT7PCU_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
122
138
  case "number":
123
- return chunkVGB4YCGF_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
139
+ return chunkHLGT7PCU_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
124
140
  case "boolean":
125
- return chunkVGB4YCGF_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
141
+ return chunkHLGT7PCU_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
126
142
  case "object":
127
- return chunkVGB4YCGF_cjs.createObjectNode(nanoid.nanoid(), name, []);
143
+ return chunkHLGT7PCU_cjs.createObjectNode(nanoid.nanoid(), name, []);
128
144
  case "array":
129
145
  return this.createArrayNodeInternal(name);
130
146
  default:
@@ -132,11 +148,11 @@ var NodeFactory = class {
132
148
  }
133
149
  }
134
150
  createArrayNodeInternal(name) {
135
- const items = chunkVGB4YCGF_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
136
- return chunkVGB4YCGF_cjs.createArrayNode(nanoid.nanoid(), name, items);
151
+ const items = chunkHLGT7PCU_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
152
+ return chunkHLGT7PCU_cjs.createArrayNode(nanoid.nanoid(), name, items);
137
153
  }
138
154
  createArrayNodeWithItems(name, items) {
139
- return chunkVGB4YCGF_cjs.createArrayNode(nanoid.nanoid(), name, items);
155
+ return chunkHLGT7PCU_cjs.createArrayNode(nanoid.nanoid(), name, items);
140
156
  }
141
157
  };
142
158
 
@@ -231,22 +247,22 @@ function generateDefaultValue(schema, options = {}) {
231
247
  var SchemaModelImpl = class {
232
248
  _baseTree;
233
249
  _currentTree;
234
- _patchBuilder = new chunkVGB4YCGF_cjs.PatchBuilder();
235
- _serializer = new chunkVGB4YCGF_cjs.SchemaSerializer();
250
+ _patchBuilder = new chunkHLGT7PCU_cjs.PatchBuilder();
251
+ _serializer = new chunkHLGT7PCU_cjs.SchemaSerializer();
236
252
  _nodeFactory = new NodeFactory();
237
- _formulaIndex = new chunkVGB4YCGF_cjs.FormulaDependencyIndex();
253
+ _formulaIndex = new chunkHLGT7PCU_cjs.FormulaDependencyIndex();
238
254
  _formulaParseErrors = [];
239
255
  _refSchemas;
240
256
  constructor(schema, options) {
257
+ this._refSchemas = options?.refSchemas;
241
258
  const parser = new SchemaParser();
242
- const rootNode = parser.parse(schema);
243
- this._currentTree = chunkVGB4YCGF_cjs.createSchemaTree(rootNode);
259
+ const rootNode = parser.parse(schema, this._refSchemas);
260
+ this._currentTree = chunkHLGT7PCU_cjs.createSchemaTree(rootNode);
244
261
  parser.parseFormulas(this._currentTree);
245
262
  this._formulaParseErrors = parser.parseErrors;
246
263
  this._buildFormulaIndex();
247
264
  this._baseTree = this._currentTree.clone();
248
- this._refSchemas = options?.refSchemas;
249
- chunkVGB4YCGF_cjs.makeAutoObservable(this, {
265
+ chunkHLGT7PCU_cjs.makeAutoObservable(this, {
250
266
  _patchBuilder: false,
251
267
  _serializer: false,
252
268
  _nodeFactory: false,
@@ -322,7 +338,7 @@ var SchemaModelImpl = class {
322
338
  this._formulaIndex.unregisterFormula(nodeId);
323
339
  } else {
324
340
  try {
325
- const formula = new chunkVGB4YCGF_cjs.ParsedFormula(this._currentTree, nodeId, expression);
341
+ const formula = new chunkHLGT7PCU_cjs.ParsedFormula(this._currentTree, nodeId, expression);
326
342
  node.setFormula(formula);
327
343
  this._formulaIndex.registerFormula(nodeId, formula);
328
344
  } catch (error) {
@@ -490,7 +506,7 @@ var SchemaModelImpl = class {
490
506
  if (!formula) {
491
507
  return "";
492
508
  }
493
- return chunkVGB4YCGF_cjs.FormulaSerializer.serializeExpression(
509
+ return chunkHLGT7PCU_cjs.FormulaSerializer.serializeExpression(
494
510
  this._currentTree,
495
511
  nodeId,
496
512
  formula,
@@ -498,10 +514,10 @@ var SchemaModelImpl = class {
498
514
  );
499
515
  }
500
516
  get validationErrors() {
501
- return chunkVGB4YCGF_cjs.validateSchema(this._currentTree.root());
517
+ return chunkHLGT7PCU_cjs.validateSchema(this._currentTree.root());
502
518
  }
503
519
  get formulaErrors() {
504
- return [...this._formulaParseErrors, ...chunkVGB4YCGF_cjs.validateFormulas(this._currentTree)];
520
+ return [...this._formulaParseErrors, ...chunkHLGT7PCU_cjs.validateFormulas(this._currentTree)];
505
521
  }
506
522
  get isDirty() {
507
523
  return this.patches.length > 0;
@@ -557,7 +573,7 @@ var RowModelImpl = class {
557
573
  constructor(_rowId, _tree) {
558
574
  this._rowId = _rowId;
559
575
  this._tree = _tree;
560
- chunkVGB4YCGF_cjs.makeAutoObservable(this, {
576
+ chunkHLGT7PCU_cjs.makeAutoObservable(this, {
561
577
  _rowId: false,
562
578
  _tree: false,
563
579
  _tableModel: "observable.ref"
@@ -709,7 +725,7 @@ var ArrayValueNode = class extends BaseValueNode {
709
725
  _nodeFactory = null;
710
726
  constructor(id, name, schema, items) {
711
727
  super(id, name, schema);
712
- this._items = chunkVGB4YCGF_cjs.observable.array();
728
+ this._items = chunkHLGT7PCU_cjs.observable.array();
713
729
  this._baseItems = [];
714
730
  if (items) {
715
731
  for (const item of items) {
@@ -718,7 +734,7 @@ var ArrayValueNode = class extends BaseValueNode {
718
734
  }
719
735
  }
720
736
  this._baseItems = [...this._items];
721
- chunkVGB4YCGF_cjs.makeObservable(this, {
737
+ chunkHLGT7PCU_cjs.makeObservable(this, {
722
738
  _items: "observable",
723
739
  _baseItems: "observable",
724
740
  value: "computed",
@@ -873,7 +889,7 @@ var ArrayValueNode = class extends BaseValueNode {
873
889
  for (const item of this._items) {
874
890
  item.parent = null;
875
891
  }
876
- this._items = chunkVGB4YCGF_cjs.observable.array();
892
+ this._items = chunkHLGT7PCU_cjs.observable.array();
877
893
  for (const baseItem of this._baseItems) {
878
894
  this._items.push(baseItem);
879
895
  }
@@ -916,7 +932,7 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
916
932
  this._baseValue = initialValue;
917
933
  }
918
934
  initObservable() {
919
- chunkVGB4YCGF_cjs.makeObservable(this, {
935
+ chunkHLGT7PCU_cjs.makeObservable(this, {
920
936
  _value: "observable",
921
937
  _baseValue: "observable",
922
938
  _formulaWarning: "observable",
@@ -1264,7 +1280,7 @@ var ObjectValueNode = class extends BaseValueNode {
1264
1280
  _baseChildren;
1265
1281
  constructor(id, name, schema, children) {
1266
1282
  super(id, name, schema);
1267
- this._children = chunkVGB4YCGF_cjs.observable.map();
1283
+ this._children = chunkHLGT7PCU_cjs.observable.map();
1268
1284
  this._baseChildren = /* @__PURE__ */ new Map();
1269
1285
  if (children) {
1270
1286
  for (const child of children) {
@@ -1273,7 +1289,7 @@ var ObjectValueNode = class extends BaseValueNode {
1273
1289
  }
1274
1290
  }
1275
1291
  this._baseChildren = new Map(this._children);
1276
- chunkVGB4YCGF_cjs.makeObservable(this, {
1292
+ chunkHLGT7PCU_cjs.makeObservable(this, {
1277
1293
  _children: "observable",
1278
1294
  _baseChildren: "observable",
1279
1295
  value: "computed",
@@ -1349,7 +1365,7 @@ var ObjectValueNode = class extends BaseValueNode {
1349
1365
  for (const child of this._children.values()) {
1350
1366
  child.parent = null;
1351
1367
  }
1352
- this._children = chunkVGB4YCGF_cjs.observable.map();
1368
+ this._children = chunkHLGT7PCU_cjs.observable.map();
1353
1369
  for (const [key, value] of this._baseChildren) {
1354
1370
  this._children.set(key, value);
1355
1371
  }
@@ -1563,7 +1579,7 @@ var IndexSegment = class {
1563
1579
  };
1564
1580
 
1565
1581
  // src/core/value-path/ValuePath.ts
1566
- var ValuePathImpl = class _ValuePathImpl extends chunkVGB4YCGF_cjs.AbstractBasePath {
1582
+ var ValuePathImpl = class _ValuePathImpl extends chunkHLGT7PCU_cjs.AbstractBasePath {
1567
1583
  asString() {
1568
1584
  const parts = [];
1569
1585
  for (const seg of this.segs) {
@@ -1651,7 +1667,7 @@ function parseValuePath(path) {
1651
1667
  var ValueTree = class {
1652
1668
  constructor(_root) {
1653
1669
  this._root = _root;
1654
- chunkVGB4YCGF_cjs.makeAutoObservable(this, {
1670
+ chunkHLGT7PCU_cjs.makeAutoObservable(this, {
1655
1671
  _root: false
1656
1672
  });
1657
1673
  }
@@ -1741,13 +1757,13 @@ var TableModelImpl = class {
1741
1757
  this._schema = createSchemaModel(options.schema, { refSchemas: options.refSchemas });
1742
1758
  this._fkResolver = options.fkResolver;
1743
1759
  this._refSchemas = options.refSchemas;
1744
- this._rows = chunkVGB4YCGF_cjs.observable.array();
1760
+ this._rows = chunkHLGT7PCU_cjs.observable.array();
1745
1761
  if (options.rows) {
1746
1762
  for (const row of options.rows) {
1747
1763
  this._rows.push(this.createRowModel(row.rowId, row.data));
1748
1764
  }
1749
1765
  }
1750
- chunkVGB4YCGF_cjs.makeAutoObservable(this, {
1766
+ chunkHLGT7PCU_cjs.makeAutoObservable(this, {
1751
1767
  _schema: false,
1752
1768
  _rows: false,
1753
1769
  _jsonSchema: false,
@@ -1868,13 +1884,13 @@ var ForeignKeyResolverImpl = class {
1868
1884
  constructor(options) {
1869
1885
  this.loader = options?.loader;
1870
1886
  this._prefetchEnabled = options?.prefetch ?? false;
1871
- this._schemaCache = chunkVGB4YCGF_cjs.observable.map();
1872
- this._tableCache = chunkVGB4YCGF_cjs.observable.map();
1887
+ this._schemaCache = chunkHLGT7PCU_cjs.observable.map();
1888
+ this._tableCache = chunkHLGT7PCU_cjs.observable.map();
1873
1889
  this._loadingTables = /* @__PURE__ */ new Set();
1874
1890
  this._loadingRows = /* @__PURE__ */ new Map();
1875
1891
  this._pendingTableLoads = /* @__PURE__ */ new Map();
1876
1892
  this._pendingRowLoads = /* @__PURE__ */ new Map();
1877
- chunkVGB4YCGF_cjs.makeAutoObservable(this, {
1893
+ chunkHLGT7PCU_cjs.makeAutoObservable(this, {
1878
1894
  _schemaCache: false,
1879
1895
  _tableCache: false,
1880
1896
  _loadingTables: false,
@@ -1912,7 +1928,7 @@ var ForeignKeyResolverImpl = class {
1912
1928
  if (this._disposed) {
1913
1929
  return;
1914
1930
  }
1915
- chunkVGB4YCGF_cjs.runInAction(() => {
1931
+ chunkHLGT7PCU_cjs.runInAction(() => {
1916
1932
  this._schemaCache.set(tableId, schema);
1917
1933
  });
1918
1934
  }
@@ -1920,12 +1936,12 @@ var ForeignKeyResolverImpl = class {
1920
1936
  if (this._disposed) {
1921
1937
  return;
1922
1938
  }
1923
- const rowMap = chunkVGB4YCGF_cjs.observable.map();
1939
+ const rowMap = chunkHLGT7PCU_cjs.observable.map();
1924
1940
  for (const row of rows) {
1925
1941
  rowMap.set(row.rowId, row);
1926
1942
  }
1927
1943
  const cache = { schema, rows: rowMap };
1928
- chunkVGB4YCGF_cjs.runInAction(() => {
1944
+ chunkHLGT7PCU_cjs.runInAction(() => {
1929
1945
  this._tableCache.set(tableId, cache);
1930
1946
  this._schemaCache.set(tableId, schema);
1931
1947
  });
@@ -1940,7 +1956,7 @@ var ForeignKeyResolverImpl = class {
1940
1956
  const table = this._tableCache.get(tableId);
1941
1957
  if (table) {
1942
1958
  const rowData = { rowId, data };
1943
- chunkVGB4YCGF_cjs.runInAction(() => {
1959
+ chunkHLGT7PCU_cjs.runInAction(() => {
1944
1960
  table.rows.set(rowId, rowData);
1945
1961
  });
1946
1962
  if (this._prefetchEnabled) {
@@ -1954,7 +1970,7 @@ var ForeignKeyResolverImpl = class {
1954
1970
  }
1955
1971
  const schema = this._schemaCache.get(oldTableId);
1956
1972
  const tableCache = this._tableCache.get(oldTableId);
1957
- chunkVGB4YCGF_cjs.runInAction(() => {
1973
+ chunkHLGT7PCU_cjs.runInAction(() => {
1958
1974
  if (schema) {
1959
1975
  this._schemaCache.delete(oldTableId);
1960
1976
  this._schemaCache.set(newTableId, schema);
@@ -2056,9 +2072,9 @@ var ForeignKeyResolverImpl = class {
2056
2072
  }
2057
2073
  ensureTableCache(tableId, schema) {
2058
2074
  if (!this._tableCache.has(tableId)) {
2059
- const rowMap = chunkVGB4YCGF_cjs.observable.map();
2075
+ const rowMap = chunkHLGT7PCU_cjs.observable.map();
2060
2076
  const cache = { schema, rows: rowMap };
2061
- chunkVGB4YCGF_cjs.runInAction(() => {
2077
+ chunkHLGT7PCU_cjs.runInAction(() => {
2062
2078
  this._tableCache.set(tableId, cache);
2063
2079
  });
2064
2080
  }
@@ -2158,7 +2174,7 @@ var DataModelImpl = class {
2158
2174
  _fk;
2159
2175
  _ownsFkResolver;
2160
2176
  constructor(options) {
2161
- this._tables = chunkVGB4YCGF_cjs.observable.map();
2177
+ this._tables = chunkHLGT7PCU_cjs.observable.map();
2162
2178
  if (options?.fkResolver) {
2163
2179
  this._fk = options.fkResolver;
2164
2180
  this._ownsFkResolver = false;
@@ -2166,7 +2182,7 @@ var DataModelImpl = class {
2166
2182
  this._fk = createForeignKeyResolver();
2167
2183
  this._ownsFkResolver = true;
2168
2184
  }
2169
- chunkVGB4YCGF_cjs.makeAutoObservable(this, {
2185
+ chunkHLGT7PCU_cjs.makeAutoObservable(this, {
2170
2186
  _tables: false,
2171
2187
  _fk: false,
2172
2188
  _ownsFkResolver: false
@@ -2276,5 +2292,5 @@ exports.generateDefaultValue = generateDefaultValue;
2276
2292
  exports.generateNodeId = generateNodeId;
2277
2293
  exports.isForeignKeyValueNode = isForeignKeyValueNode;
2278
2294
  exports.resetNodeIdCounter = resetNodeIdCounter;
2279
- //# sourceMappingURL=chunk-MAEGAVK4.cjs.map
2280
- //# sourceMappingURL=chunk-MAEGAVK4.cjs.map
2295
+ //# sourceMappingURL=chunk-I6ZH7HZ7.cjs.map
2296
+ //# sourceMappingURL=chunk-I6ZH7HZ7.cjs.map