@scalar/json-magic 0.12.20 → 0.13.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @scalar/json-magic
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#9897](https://github.com/scalar/scalar/pull/9897): Export the `get-value-by-path`, `set-value-at-path`, `is-yaml`, and `is-json-object` helpers, and expose `isLocalRef`, `prefixInternalRef`, and `prefixInternalRefRecursive` from the bundle entry point.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#9898](https://github.com/scalar/scalar/pull/9898): Treat array/object container mismatches as a single update in diff instead of descending into per-index adds. Before, `diff({ tags: {} }, { tags: ['x', 'y'] })` walked the array's indices as object keys and emitted per-index `add` differences, so `apply` wrote numeric string properties onto the existing object and produced the corrupted hybrid `{ tags: { '0': 'x', '1': 'y' } }`. A container type change (either direction) is now one `update` difference carrying the full new value, and applying it replaces the container correctly.
12
+
3
13
  ## 0.12.20
4
14
 
5
15
  ## 0.12.19
@@ -1,3 +1,3 @@
1
1
  export type { LifecyclePlugin, LoaderPlugin, Plugin, ResolveResult } from './bundle.js';
2
- export { bundle, resolveAndCopyReferences } from './bundle.js';
2
+ export { bundle, isLocalRef, prefixInternalRef, prefixInternalRefRecursive, resolveAndCopyReferences } from './bundle.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundle/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACpF,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundle/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACpF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA"}
@@ -1 +1 @@
1
- export { bundle, resolveAndCopyReferences } from './bundle.js';
1
+ export { bundle, isLocalRef, prefixInternalRef, prefixInternalRefRecursive, resolveAndCopyReferences } from './bundle.js';
@@ -1 +1 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff/diff.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,KAAK,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE7C;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,EAAE,IAAI;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAA;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,oBAyC7F,CAAA"}
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff/diff.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,KAAK,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE7C;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,EAAE,IAAI;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAA;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,oBAiD7F,CAAA"}
package/dist/diff/diff.js CHANGED
@@ -52,6 +52,13 @@ export const diff = (doc1, doc2) => {
52
52
  // We now can assume that el1 and el2 are of the same type
53
53
  // For nested objects, we need to recursively check the properties
54
54
  if (typeof el1 === 'object' && typeof el2 === 'object' && el1 !== null && el2 !== null) {
55
+ // A container type change (array to plain object or vice versa) is a single update.
56
+ // Recursing would treat array indices as object keys and produce per-key
57
+ // differences that corrupt the container when applied.
58
+ if (Array.isArray(el1) !== Array.isArray(el2)) {
59
+ diff.push({ path: prefix, changes: el2, type: 'update' });
60
+ return;
61
+ }
55
62
  const keys = new Set([...Object.keys(el1), ...Object.keys(el2)]);
56
63
  for (const key of keys) {
57
64
  bfs(el1[key], el2[key], [...prefix, key]);
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "url": "git+https://github.com/scalar/scalar.git",
11
11
  "directory": "packages/json-magic"
12
12
  },
13
- "version": "0.12.20",
13
+ "version": "0.13.0",
14
14
  "engines": {
15
15
  "node": ">=22"
16
16
  },
@@ -56,6 +56,11 @@
56
56
  "types": "./dist/helpers/get-segments-from-path.d.ts",
57
57
  "default": "./dist/helpers/get-segments-from-path.js"
58
58
  },
59
+ "./helpers/get-value-by-path": {
60
+ "import": "./dist/helpers/get-value-by-path.js",
61
+ "types": "./dist/helpers/get-value-by-path.d.ts",
62
+ "default": "./dist/helpers/get-value-by-path.js"
63
+ },
59
64
  "./helpers/is-file-path": {
60
65
  "import": "./dist/helpers/is-file-path.js",
61
66
  "types": "./dist/helpers/is-file-path.d.ts",
@@ -66,11 +71,26 @@
66
71
  "types": "./dist/helpers/is-http-url.d.ts",
67
72
  "default": "./dist/helpers/is-http-url.js"
68
73
  },
74
+ "./helpers/is-json-object": {
75
+ "import": "./dist/helpers/is-json-object.js",
76
+ "types": "./dist/helpers/is-json-object.d.ts",
77
+ "default": "./dist/helpers/is-json-object.js"
78
+ },
79
+ "./helpers/is-yaml": {
80
+ "import": "./dist/helpers/is-yaml.js",
81
+ "types": "./dist/helpers/is-yaml.d.ts",
82
+ "default": "./dist/helpers/is-yaml.js"
83
+ },
69
84
  "./helpers/normalize": {
70
85
  "import": "./dist/helpers/normalize.js",
71
86
  "types": "./dist/helpers/normalize.d.ts",
72
87
  "default": "./dist/helpers/normalize.js"
73
88
  },
89
+ "./helpers/set-value-at-path": {
90
+ "import": "./dist/helpers/set-value-at-path.js",
91
+ "types": "./dist/helpers/set-value-at-path.d.ts",
92
+ "default": "./dist/helpers/set-value-at-path.js"
93
+ },
74
94
  "./helpers/unescape-json-pointer": {
75
95
  "import": "./dist/helpers/unescape-json-pointer.js",
76
96
  "types": "./dist/helpers/unescape-json-pointer.d.ts",