@revisium/schema-toolkit 0.21.2 → 0.21.4

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,4 +1,4 @@
1
- import { AbstractBasePath, EMPTY_PATH, FormulaError, ResolvedDependency, FormulaSerializer, createRefNode, createObjectNode, createArrayNode, createStringNode, createNumberNode, createBooleanNode, observable, makeObservable, makeAutoObservable, runInAction, PatchBuilder, SchemaSerializer, createSchemaTree, NULL_NODE, validateSchema, validateFormulas, reaction } from './chunk-AWFMSOHM.js';
1
+ import { AbstractBasePath, EMPTY_PATH, FormulaError, ResolvedDependency, FormulaSerializer, createRefNode, createObjectNode, createArrayNode, createStringNode, createNumberNode, createBooleanNode, observable, makeObservable, makeAutoObservable, runInAction, PatchBuilder, SchemaSerializer, createSchemaTree, NULL_NODE, validateSchema, validateFormulas, reaction } from './chunk-MXEQ5CBK.js';
2
2
  import { obj, ref } from './chunk-IZMBM36H.js';
3
3
  import { nanoid } from 'nanoid';
4
4
  import { parseFormula, parseExpression, evaluateWithContext } from '@revisium/formula';
@@ -306,10 +306,17 @@ var SchemaParser = class {
306
306
  pendingFormulas = [];
307
307
  _parseErrors = [];
308
308
  _refSchemas = {};
309
+ _resolvingRefs = /* @__PURE__ */ new Set();
309
310
  parse(schema, refSchemas) {
310
311
  this.pendingFormulas = [];
311
312
  this._parseErrors = [];
312
313
  this._refSchemas = refSchemas ?? {};
314
+ this._resolvingRefs = /* @__PURE__ */ new Set();
315
+ for (const [refKey, refSchema] of Object.entries(this._refSchemas)) {
316
+ if (refSchema === schema) {
317
+ this._resolvingRefs.add(refKey);
318
+ }
319
+ }
313
320
  return this.parseNode(schema, "root");
314
321
  }
315
322
  parseFormulas(tree) {
@@ -338,7 +345,13 @@ var SchemaParser = class {
338
345
  const refValue = schema.$ref;
339
346
  const resolvedSchema = this._refSchemas[refValue];
340
347
  if (resolvedSchema) {
341
- return this.parseNode(resolvedSchema, name, refValue);
348
+ if (this._resolvingRefs.has(refValue)) {
349
+ return createRefNode(nanoid(), name, refValue, this.extractMetadata(schema));
350
+ }
351
+ this._resolvingRefs.add(refValue);
352
+ const node = this.parseNode(resolvedSchema, name, refValue);
353
+ this._resolvingRefs.delete(refValue);
354
+ return node;
342
355
  }
343
356
  return createRefNode(nanoid(), name, refValue, this.extractMetadata(schema));
344
357
  }
@@ -1972,8 +1985,12 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
1972
1985
  if (this.isReadOnly && !options?.internal) {
1973
1986
  throw new Error(`Cannot set value on read-only field: ${this.name}`);
1974
1987
  }
1988
+ const coercedValue = this.coerceValue(value);
1989
+ if (coercedValue === this._value) {
1990
+ return;
1991
+ }
1975
1992
  const oldValue = this._value;
1976
- this._value = this.coerceValue(value);
1993
+ this._value = coercedValue;
1977
1994
  if (!options?.internal) {
1978
1995
  this.emit({ type: "setValue", node: this, value: this._value, oldValue });
1979
1996
  }
@@ -1159,28 +1159,10 @@ var FormulaSerializer = class _FormulaSerializer {
1159
1159
 
1160
1160
  // src/core/schema-diff/SchemaComparator.ts
1161
1161
  function areNodesEqual(current, base, context) {
1162
- if (current.nodeType() !== base.nodeType()) {
1163
- return false;
1164
- }
1165
1162
  if (current.name() !== base.name()) {
1166
1163
  return false;
1167
1164
  }
1168
- if (!areMetadataEqual(current, base)) {
1169
- return false;
1170
- }
1171
- if (current.isPrimitive()) {
1172
- return arePrimitivesEqual(current, base, context);
1173
- }
1174
- if (current.isObject()) {
1175
- return areObjectsEqual(current, base, context);
1176
- }
1177
- if (current.isArray()) {
1178
- return areArraysEqual(current, base, context);
1179
- }
1180
- if (current.isRef()) {
1181
- return current.ref() === base.ref();
1182
- }
1183
- return current.isNull() && base.isNull();
1165
+ return areNodesContentEqual(current, base, context);
1184
1166
  }
1185
1167
  function areNodesContentEqual(current, base, context) {
1186
1168
  if (current.nodeType() !== base.nodeType()) {
@@ -1192,15 +1174,15 @@ function areNodesContentEqual(current, base, context) {
1192
1174
  if (current.isPrimitive()) {
1193
1175
  return arePrimitivesEqual(current, base, context);
1194
1176
  }
1177
+ if (current.isRef()) {
1178
+ return current.ref() === base.ref();
1179
+ }
1195
1180
  if (current.isObject()) {
1196
1181
  return areObjectsEqual(current, base, context);
1197
1182
  }
1198
1183
  if (current.isArray()) {
1199
1184
  return areArraysEqual(current, base, context);
1200
1185
  }
1201
- if (current.isRef()) {
1202
- return current.ref() === base.ref();
1203
- }
1204
1186
  return current.isNull() && base.isNull();
1205
1187
  }
1206
1188
  function areMetadataEqual(current, base) {
@@ -1161,28 +1161,10 @@ var FormulaSerializer = class _FormulaSerializer {
1161
1161
 
1162
1162
  // src/core/schema-diff/SchemaComparator.ts
1163
1163
  function areNodesEqual(current, base, context) {
1164
- if (current.nodeType() !== base.nodeType()) {
1165
- return false;
1166
- }
1167
1164
  if (current.name() !== base.name()) {
1168
1165
  return false;
1169
1166
  }
1170
- if (!areMetadataEqual(current, base)) {
1171
- return false;
1172
- }
1173
- if (current.isPrimitive()) {
1174
- return arePrimitivesEqual(current, base, context);
1175
- }
1176
- if (current.isObject()) {
1177
- return areObjectsEqual(current, base, context);
1178
- }
1179
- if (current.isArray()) {
1180
- return areArraysEqual(current, base, context);
1181
- }
1182
- if (current.isRef()) {
1183
- return current.ref() === base.ref();
1184
- }
1185
- return current.isNull() && base.isNull();
1167
+ return areNodesContentEqual(current, base, context);
1186
1168
  }
1187
1169
  function areNodesContentEqual(current, base, context) {
1188
1170
  if (current.nodeType() !== base.nodeType()) {
@@ -1194,15 +1176,15 @@ function areNodesContentEqual(current, base, context) {
1194
1176
  if (current.isPrimitive()) {
1195
1177
  return arePrimitivesEqual(current, base, context);
1196
1178
  }
1179
+ if (current.isRef()) {
1180
+ return current.ref() === base.ref();
1181
+ }
1197
1182
  if (current.isObject()) {
1198
1183
  return areObjectsEqual(current, base, context);
1199
1184
  }
1200
1185
  if (current.isArray()) {
1201
1186
  return areArraysEqual(current, base, context);
1202
1187
  }
1203
- if (current.isRef()) {
1204
- return current.ref() === base.ref();
1205
- }
1206
1188
  return current.isNull() && base.isNull();
1207
1189
  }
1208
1190
  function areMetadataEqual(current, base) {