@revisium/schema-toolkit 0.18.0 → 0.19.0

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.
@@ -2240,7 +2240,9 @@ var PatchEnricher = class {
2240
2240
  constructor(currentTree, baseTree) {
2241
2241
  this.currentTree = currentTree;
2242
2242
  this.baseTree = baseTree;
2243
+ this.extractors = this.buildExtractors();
2243
2244
  }
2245
+ extractors;
2244
2246
  enrich(patch) {
2245
2247
  const fieldName = this.getFieldNameFromPath(patch.path);
2246
2248
  if (patch.op === "add") {
@@ -2257,18 +2259,13 @@ var PatchEnricher = class {
2257
2259
  enrichAddPatch(patch, fieldName) {
2258
2260
  const currentNode = this.getNodeAtPath(this.currentTree, patch.path);
2259
2261
  if (!currentNode) {
2260
- return { patch, fieldName, metadataChanges: [] };
2262
+ return { patch, fieldName, propertyChanges: [] };
2261
2263
  }
2262
- const metadata = this.computeAddMetadata(currentNode);
2263
- return {
2264
- patch,
2265
- fieldName,
2266
- metadataChanges: this.computeMetadataChanges(metadata),
2267
- ...metadata
2268
- };
2264
+ const propertyChanges = this.computeAddPropertyChanges(currentNode);
2265
+ return { patch, fieldName, propertyChanges };
2269
2266
  }
2270
2267
  enrichRemovePatch(patch, fieldName) {
2271
- return { patch, fieldName, metadataChanges: [] };
2268
+ return { patch, fieldName, propertyChanges: [] };
2272
2269
  }
2273
2270
  enrichMovePatch(patch, fieldName) {
2274
2271
  const fromPath = patch.from;
@@ -2276,98 +2273,98 @@ var PatchEnricher = class {
2276
2273
  const movesIntoArray = this.movesIntoArrayBoundary(fromPath, patch.path);
2277
2274
  const baseNode = this.getNodeAtPath(this.baseTree, fromPath);
2278
2275
  const currentNode = this.getNodeAtPath(this.currentTree, patch.path);
2279
- const formulaChange = this.computeFormulaChange(baseNode, currentNode);
2280
- const metadataChanges = [];
2281
- if (formulaChange) {
2282
- metadataChanges.push("formula");
2283
- }
2276
+ const propertyChanges = this.computePropertyChanges(baseNode, currentNode);
2284
2277
  return {
2285
2278
  patch,
2286
2279
  fieldName,
2287
- metadataChanges,
2280
+ propertyChanges,
2288
2281
  isRename: isRename || void 0,
2289
- movesIntoArray: movesIntoArray || void 0,
2290
- formulaChange
2282
+ movesIntoArray: movesIntoArray || void 0
2291
2283
  };
2292
2284
  }
2293
2285
  enrichReplacePatch(patch, fieldName) {
2294
2286
  const baseNode = this.getNodeAtPath(this.baseTree, patch.path);
2295
2287
  const currentNode = this.getNodeAtPath(this.currentTree, patch.path);
2296
2288
  const isArrayMetadataPatch = baseNode?.isArray() && currentNode?.isArray();
2297
- const formulaChange = this.computeFormulaChange(baseNode, currentNode);
2298
- const defaultChange = isArrayMetadataPatch ? void 0 : this.computeDefaultChange(baseNode, currentNode);
2299
- const descriptionChange = this.computeDescriptionChange(baseNode, currentNode);
2300
- const deprecatedChange = this.computeDeprecatedChange(baseNode, currentNode);
2301
- const foreignKeyChange = this.computeForeignKeyChange(baseNode, currentNode);
2302
- const contentMediaTypeChange = this.computeContentMediaTypeChange(baseNode, currentNode);
2303
- const metadataChanges = this.computeMetadataChanges({
2304
- formulaChange,
2305
- defaultChange,
2306
- descriptionChange,
2307
- deprecatedChange,
2308
- foreignKeyChange,
2309
- contentMediaTypeChange
2310
- });
2289
+ const skipProperties = isArrayMetadataPatch ? ["default"] : [];
2290
+ const propertyChanges = this.computePropertyChanges(
2291
+ baseNode,
2292
+ currentNode,
2293
+ { skipProperties }
2294
+ );
2311
2295
  return {
2312
2296
  patch,
2313
2297
  fieldName,
2314
- metadataChanges,
2315
- typeChange: this.computeTypeChange(baseNode, currentNode, isArrayMetadataPatch),
2316
- formulaChange,
2317
- defaultChange,
2318
- descriptionChange,
2319
- deprecatedChange,
2320
- foreignKeyChange,
2321
- contentMediaTypeChange
2298
+ propertyChanges,
2299
+ typeChange: this.computeTypeChange(baseNode, currentNode, isArrayMetadataPatch)
2322
2300
  };
2323
2301
  }
2324
- computeAddMetadata(node) {
2325
- const result = {};
2326
- const formula = node.formula();
2327
- if (formula) {
2328
- result.formulaChange = {
2329
- fromFormula: void 0,
2330
- toFormula: this.getFormulaExpression(formula, this.currentTree, node.id()),
2331
- fromVersion: void 0,
2332
- toVersion: formula.version()
2333
- };
2334
- }
2335
- const defaultValue = node.defaultValue();
2336
- if (defaultValue !== void 0 && isPrimitiveDefault(defaultValue)) {
2337
- result.defaultChange = {
2338
- fromDefault: void 0,
2339
- toDefault: defaultValue
2340
- };
2341
- }
2342
- const meta = node.metadata();
2343
- if (meta.description) {
2344
- result.descriptionChange = {
2345
- fromDescription: void 0,
2346
- toDescription: meta.description
2347
- };
2348
- }
2349
- if (meta.deprecated) {
2350
- result.deprecatedChange = {
2351
- fromDeprecated: void 0,
2352
- toDeprecated: meta.deprecated
2353
- };
2354
- }
2355
- const foreignKey = node.foreignKey();
2356
- if (foreignKey) {
2357
- result.foreignKeyChange = {
2358
- fromForeignKey: void 0,
2359
- toForeignKey: foreignKey
2360
- };
2361
- }
2362
- const contentMediaType = node.contentMediaType();
2363
- if (contentMediaType) {
2364
- result.contentMediaTypeChange = {
2365
- fromContentMediaType: void 0,
2366
- toContentMediaType: contentMediaType
2367
- };
2302
+ buildExtractors() {
2303
+ return [
2304
+ {
2305
+ property: "formula",
2306
+ extract: (node, tree) => {
2307
+ const formula = node?.formula();
2308
+ if (!formula || !node) {
2309
+ return void 0;
2310
+ }
2311
+ return FormulaSerializer.serializeExpression(tree, node.id(), formula, { strict: false });
2312
+ },
2313
+ compare: (from, to) => from === to
2314
+ },
2315
+ {
2316
+ property: "default",
2317
+ extract: (node) => {
2318
+ const value = node?.defaultValue();
2319
+ return isPrimitiveDefault(value) ? value : void 0;
2320
+ }
2321
+ },
2322
+ {
2323
+ property: "description",
2324
+ extract: (node) => node?.metadata().description
2325
+ },
2326
+ {
2327
+ property: "deprecated",
2328
+ extract: (node) => node?.metadata().deprecated
2329
+ },
2330
+ {
2331
+ property: "foreignKey",
2332
+ extract: (node) => node?.foreignKey()
2333
+ },
2334
+ {
2335
+ property: "contentMediaType",
2336
+ extract: (node) => node?.contentMediaType()
2337
+ },
2338
+ {
2339
+ property: "ref",
2340
+ extract: (node) => node?.ref()
2341
+ },
2342
+ {
2343
+ property: "title",
2344
+ extract: (node) => node?.metadata().title
2345
+ }
2346
+ ];
2347
+ }
2348
+ computePropertyChanges(baseNode, currentNode, options) {
2349
+ const skipSet = options?.skipProperties;
2350
+ const result = [];
2351
+ for (const extractor of this.extractors) {
2352
+ if (skipSet?.includes(extractor.property)) {
2353
+ continue;
2354
+ }
2355
+ const from = extractor.extract(baseNode, this.baseTree);
2356
+ const to = extractor.extract(currentNode, this.currentTree);
2357
+ const areEqual = extractor.compare ? extractor.compare(from, to) : from === to;
2358
+ if (!areEqual) {
2359
+ result.push({ property: extractor.property, from, to });
2360
+ }
2368
2361
  }
2369
2362
  return result;
2370
2363
  }
2364
+ computeAddPropertyChanges(node) {
2365
+ const allChanges = this.computePropertyChanges(null, node);
2366
+ return allChanges.filter((change) => change.to !== void 0);
2367
+ }
2371
2368
  computeTypeChange(baseNode, currentNode, ignoreItems) {
2372
2369
  if (!baseNode || !currentNode) {
2373
2370
  return void 0;
@@ -2386,98 +2383,6 @@ var PatchEnricher = class {
2386
2383
  }
2387
2384
  return void 0;
2388
2385
  }
2389
- computeFormulaChange(baseNode, currentNode) {
2390
- const baseFormula = baseNode?.formula();
2391
- const currentFormula = currentNode?.formula();
2392
- const baseExpr = baseFormula && baseNode ? this.getFormulaExpression(baseFormula, this.baseTree, baseNode.id()) : void 0;
2393
- const currentExpr = currentFormula && currentNode ? this.getFormulaExpression(currentFormula, this.currentTree, currentNode.id()) : void 0;
2394
- const baseVersion = baseFormula?.version();
2395
- const currentVersion = currentFormula?.version();
2396
- if (baseExpr !== currentExpr || baseVersion !== currentVersion) {
2397
- return {
2398
- fromFormula: baseExpr,
2399
- toFormula: currentExpr,
2400
- fromVersion: baseVersion,
2401
- toVersion: currentVersion
2402
- };
2403
- }
2404
- return void 0;
2405
- }
2406
- getFormulaExpression(formula, tree, nodeId) {
2407
- return FormulaSerializer.serializeExpression(tree, nodeId, formula, { strict: false });
2408
- }
2409
- computeDefaultChange(baseNode, currentNode) {
2410
- const baseDefault = baseNode?.defaultValue();
2411
- const currentDefault = currentNode?.defaultValue();
2412
- const safeBaseDefault = isPrimitiveDefault(baseDefault) ? baseDefault : void 0;
2413
- const safeCurrentDefault = isPrimitiveDefault(
2414
- currentDefault
2415
- ) ? currentDefault : void 0;
2416
- if (safeBaseDefault !== safeCurrentDefault) {
2417
- return {
2418
- fromDefault: safeBaseDefault,
2419
- toDefault: safeCurrentDefault
2420
- };
2421
- }
2422
- return void 0;
2423
- }
2424
- computeDescriptionChange(baseNode, currentNode) {
2425
- const baseDesc = baseNode?.metadata().description;
2426
- const currentDesc = currentNode?.metadata().description;
2427
- if (baseDesc !== currentDesc) {
2428
- return { fromDescription: baseDesc, toDescription: currentDesc };
2429
- }
2430
- return void 0;
2431
- }
2432
- computeDeprecatedChange(baseNode, currentNode) {
2433
- const baseDeprecated = baseNode?.metadata().deprecated;
2434
- const currentDeprecated = currentNode?.metadata().deprecated;
2435
- if (baseDeprecated !== currentDeprecated) {
2436
- return { fromDeprecated: baseDeprecated, toDeprecated: currentDeprecated };
2437
- }
2438
- return void 0;
2439
- }
2440
- computeForeignKeyChange(baseNode, currentNode) {
2441
- const baseFk = baseNode?.foreignKey();
2442
- const currentFk = currentNode?.foreignKey();
2443
- if (baseFk !== currentFk) {
2444
- return { fromForeignKey: baseFk, toForeignKey: currentFk };
2445
- }
2446
- return void 0;
2447
- }
2448
- computeContentMediaTypeChange(baseNode, currentNode) {
2449
- const baseMediaType = baseNode?.contentMediaType();
2450
- const currentMediaType = currentNode?.contentMediaType();
2451
- if (baseMediaType !== currentMediaType) {
2452
- return {
2453
- fromContentMediaType: baseMediaType,
2454
- toContentMediaType: currentMediaType
2455
- };
2456
- }
2457
- return void 0;
2458
- }
2459
- computeMetadataChanges(changes) {
2460
- const result = [];
2461
- if (changes.formulaChange) {
2462
- result.push("formula");
2463
- }
2464
- if (changes.defaultChange) {
2465
- result.push("default");
2466
- }
2467
- if (changes.descriptionChange) {
2468
- result.push("description");
2469
- }
2470
- if (changes.deprecatedChange) {
2471
- result.push("deprecated");
2472
- }
2473
- if (changes.foreignKeyChange) {
2474
- result.push("foreignKey");
2475
- }
2476
- if (changes.contentMediaTypeChange) {
2477
- result.push("contentMediaType");
2478
- }
2479
- return result;
2480
- }
2481
2386
  getNodeType(node) {
2482
2387
  if (node.isArray()) {
2483
2388
  const items = node.items();
@@ -2955,5 +2860,5 @@ function buildArrayItemsPath(parentPath) {
2955
2860
  }
2956
2861
 
2957
2862
  export { AbstractBasePath, ChangeCoalescer, ChangeCollector, CompositeRule, EMPTY_METADATA, EMPTY_PATH, EnumValidator, FIELD_NAME_ERROR_MESSAGE, ForeignKeyValidator, FormulaChangeDetector, FormulaDependencyIndex, FormulaPath, FormulaPathBuilder, FormulaSerializer, ItemsSegment, MaxLengthValidator, MaximumValidator, MinLengthValidator, MinimumValidator, NULL_NODE, NodePathIndex, ParsedFormula, PatchBuilder, PatchEnricher, PatchGenerator, PatternValidator, PropertySegment, RequiredValidator, ResolvedDependency, SchemaDiff, SchemaPropertyRule, SchemaSerializer, SchemaTruthyRule, ValidationEngine, ValidatorRegistry, ValidatorResolver, areNodesContentEqual, areNodesEqual, coalesceChanges, collectChanges, createArrayNode, createBooleanNode, createDefaultValidatorRegistry, createMobxProvider, createNumberNode, createObjectNode, createPath, createRefNode, createSchemaTree, createStringNode, createValidationEngine, isValidFieldName, jsonPointerToPath, jsonPointerToSegments, jsonPointerToSimplePath, makeAutoObservable, makeObservable, observable, reaction, resetReactivityProvider, runInAction, setReactivityProvider, validateFormulas, validateSchema };
2958
- //# sourceMappingURL=chunk-5FFJ2R3L.js.map
2959
- //# sourceMappingURL=chunk-5FFJ2R3L.js.map
2863
+ //# sourceMappingURL=chunk-EPFW6FVB.js.map
2864
+ //# sourceMappingURL=chunk-EPFW6FVB.js.map