@revisium/schema-toolkit-ui 0.1.0 → 0.1.2

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.
package/dist/index.cjs CHANGED
@@ -2662,6 +2662,12 @@ var PatchGenerator = class {
2662
2662
  if (this.isChildOfAny(currentPath, replacedPaths)) continue;
2663
2663
  if (this.hasChildIn(currentPath, childChangePathObjects)) continue;
2664
2664
  if (!this.isActuallyModified(change)) continue;
2665
+ if (change.currentNode.isArray()) {
2666
+ const arrayPatches = this.generateArrayReplacePatches(change.currentNode, change.baseNode, currentPath);
2667
+ patches.push(...arrayPatches);
2668
+ replacedPaths.push(currentPath);
2669
+ continue;
2670
+ }
2665
2671
  const schema = this.serializer.serializeWithTree(change.currentNode, this.currentTree);
2666
2672
  patches.push({
2667
2673
  op: "replace",
@@ -2672,6 +2678,49 @@ var PatchGenerator = class {
2672
2678
  }
2673
2679
  return patches;
2674
2680
  }
2681
+ generateArrayReplacePatches(currentNode, baseNode, currentPath) {
2682
+ if (!baseNode.isArray()) {
2683
+ const schema = this.serializer.serializeWithTree(currentNode, this.currentTree);
2684
+ return [{
2685
+ op: "replace",
2686
+ path: currentPath.asJsonPointer(),
2687
+ value: schema
2688
+ }];
2689
+ }
2690
+ const patches = [];
2691
+ const metadataChanged = this.hasMetadataChanged(currentNode, baseNode);
2692
+ const itemsChanged = this.hasItemsChanged(currentNode, baseNode);
2693
+ if (metadataChanged) {
2694
+ const schema = this.serializer.serializeWithTree(currentNode, this.currentTree);
2695
+ patches.push({
2696
+ op: "replace",
2697
+ path: currentPath.asJsonPointer(),
2698
+ value: schema
2699
+ });
2700
+ }
2701
+ if (itemsChanged) {
2702
+ const items = currentNode.items();
2703
+ if (!items.isNull()) {
2704
+ const itemsPath = currentPath.childItems();
2705
+ const itemsSchema = this.serializer.serializeWithTree(items, this.currentTree);
2706
+ patches.push({
2707
+ op: "replace",
2708
+ path: itemsPath.asJsonPointer(),
2709
+ value: itemsSchema
2710
+ });
2711
+ }
2712
+ }
2713
+ return patches;
2714
+ }
2715
+ hasItemsChanged(currentNode, baseNode) {
2716
+ const items = currentNode.items();
2717
+ const baseItems = baseNode.items();
2718
+ if (items.isNull() && baseItems.isNull()) return false;
2719
+ if (items.isNull() || baseItems.isNull()) return true;
2720
+ const currentItemsSchema = this.serializer.serializeWithTree(items, this.currentTree);
2721
+ const baseItemsSchema = this.serializer.serializeWithTree(baseItems, this.baseTree);
2722
+ return !this.comparator.areEqual(currentItemsSchema, baseItemsSchema);
2723
+ }
2675
2724
  isChildOfAny(path, parents) {
2676
2725
  return parents.some((parent) => path.isChildOf(parent));
2677
2726
  }
@@ -2862,6 +2911,15 @@ var NodeMetadataExtractor = class {
2862
2911
  hasTypeChanged(baseNode, currentNode) {
2863
2912
  return this.getNodeType(baseNode) !== this.getNodeType(currentNode);
2864
2913
  }
2914
+ hasTypeChangedIgnoringItems(baseNode, currentNode) {
2915
+ return this.getBaseNodeType(baseNode) !== this.getBaseNodeType(currentNode);
2916
+ }
2917
+ getBaseNodeType(node) {
2918
+ if (!node || node.isNull()) return "unknown";
2919
+ if (node.isRef()) return node.ref();
2920
+ if (node.isArray()) return "array";
2921
+ return node.nodeType();
2922
+ }
2865
2923
  };
2866
2924
 
2867
2925
  //#endregion
@@ -2923,22 +2981,26 @@ var PatchEnricher = class {
2923
2981
  const baseNode = this.getNodeAtPath(this.baseTree, patch.path);
2924
2982
  const currentNode = this.getNodeAtPath(this.currentTree, patch.path);
2925
2983
  const { metadataChanges, formulaChange, defaultChange, descriptionChange, deprecatedChange, foreignKeyChange, contentMediaTypeChange } = this.metadataExtractor.computeMetadataChanges(this.baseTree, baseNode, this.currentTree, currentNode);
2984
+ const isArrayMetadataPatch = this.isArrayMetadataOnlyPatch(baseNode, currentNode);
2926
2985
  return {
2927
2986
  patch,
2928
2987
  fieldName,
2929
2988
  metadataChanges,
2930
- typeChange: this.metadataExtractor.hasTypeChanged(baseNode, currentNode) ? {
2989
+ typeChange: (isArrayMetadataPatch ? this.metadataExtractor.hasTypeChangedIgnoringItems(baseNode, currentNode) : this.metadataExtractor.hasTypeChanged(baseNode, currentNode)) ? {
2931
2990
  fromType: this.metadataExtractor.getNodeType(baseNode),
2932
2991
  toType: this.metadataExtractor.getNodeType(currentNode)
2933
2992
  } : void 0,
2934
2993
  formulaChange,
2935
- defaultChange,
2994
+ defaultChange: isArrayMetadataPatch ? void 0 : defaultChange,
2936
2995
  descriptionChange,
2937
2996
  deprecatedChange,
2938
2997
  foreignKeyChange,
2939
2998
  contentMediaTypeChange
2940
2999
  };
2941
3000
  }
3001
+ isArrayMetadataOnlyPatch(baseNode, currentNode) {
3002
+ return Boolean(baseNode?.isArray() && currentNode?.isArray());
3003
+ }
2942
3004
  getFieldNameFromPath(jsonPointer) {
2943
3005
  try {
2944
3006
  return jsonPointerToPath(jsonPointer).asSimple();