@scalar/json-magic 0.1.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/.turbo/turbo-build.log +9 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +356 -0
- package/dist/bundle/bundle.d.ts +292 -0
- package/dist/bundle/bundle.d.ts.map +1 -0
- package/dist/bundle/bundle.js +259 -0
- package/dist/bundle/bundle.js.map +7 -0
- package/dist/bundle/create-limiter.d.ts +21 -0
- package/dist/bundle/create-limiter.d.ts.map +1 -0
- package/dist/bundle/create-limiter.js +31 -0
- package/dist/bundle/create-limiter.js.map +7 -0
- package/dist/bundle/index.d.ts +2 -0
- package/dist/bundle/index.d.ts.map +1 -0
- package/dist/bundle/index.js +5 -0
- package/dist/bundle/index.js.map +7 -0
- package/dist/bundle/plugins/browser.d.ts +4 -0
- package/dist/bundle/plugins/browser.d.ts.map +1 -0
- package/dist/bundle/plugins/browser.js +9 -0
- package/dist/bundle/plugins/browser.js.map +7 -0
- package/dist/bundle/plugins/fetch-urls/index.d.ts +39 -0
- package/dist/bundle/plugins/fetch-urls/index.d.ts.map +1 -0
- package/dist/bundle/plugins/fetch-urls/index.js +48 -0
- package/dist/bundle/plugins/fetch-urls/index.js.map +7 -0
- package/dist/bundle/plugins/node.d.ts +5 -0
- package/dist/bundle/plugins/node.d.ts.map +1 -0
- package/dist/bundle/plugins/node.js +11 -0
- package/dist/bundle/plugins/node.js.map +7 -0
- package/dist/bundle/plugins/parse-json/index.d.ts +13 -0
- package/dist/bundle/plugins/parse-json/index.d.ts.map +1 -0
- package/dist/bundle/plugins/parse-json/index.js +22 -0
- package/dist/bundle/plugins/parse-json/index.js.map +7 -0
- package/dist/bundle/plugins/parse-yaml/index.d.ts +13 -0
- package/dist/bundle/plugins/parse-yaml/index.d.ts.map +1 -0
- package/dist/bundle/plugins/parse-yaml/index.js +23 -0
- package/dist/bundle/plugins/parse-yaml/index.js.map +7 -0
- package/dist/bundle/plugins/read-files/index.d.ts +29 -0
- package/dist/bundle/plugins/read-files/index.d.ts.map +1 -0
- package/dist/bundle/plugins/read-files/index.js +30 -0
- package/dist/bundle/plugins/read-files/index.js.map +7 -0
- package/dist/bundle/value-generator.d.ts +79 -0
- package/dist/bundle/value-generator.d.ts.map +1 -0
- package/dist/bundle/value-generator.js +55 -0
- package/dist/bundle/value-generator.js.map +7 -0
- package/dist/dereference/dereference.d.ts +45 -0
- package/dist/dereference/dereference.d.ts.map +1 -0
- package/dist/dereference/dereference.js +37 -0
- package/dist/dereference/dereference.js.map +7 -0
- package/dist/dereference/index.d.ts +2 -0
- package/dist/dereference/index.d.ts.map +1 -0
- package/dist/dereference/index.js +5 -0
- package/dist/dereference/index.js.map +7 -0
- package/dist/diff/apply.d.ts +35 -0
- package/dist/diff/apply.d.ts.map +1 -0
- package/dist/diff/apply.js +40 -0
- package/dist/diff/apply.js.map +7 -0
- package/dist/diff/diff.d.ts +56 -0
- package/dist/diff/diff.d.ts.map +1 -0
- package/dist/diff/diff.js +33 -0
- package/dist/diff/diff.js.map +7 -0
- package/dist/diff/index.d.ts +5 -0
- package/dist/diff/index.d.ts.map +1 -0
- package/dist/diff/index.js +9 -0
- package/dist/diff/index.js.map +7 -0
- package/dist/diff/merge.d.ts +43 -0
- package/dist/diff/merge.d.ts.map +1 -0
- package/dist/diff/merge.js +61 -0
- package/dist/diff/merge.js.map +7 -0
- package/dist/diff/trie.d.ts +64 -0
- package/dist/diff/trie.d.ts.map +1 -0
- package/dist/diff/trie.js +82 -0
- package/dist/diff/trie.js.map +7 -0
- package/dist/diff/utils.d.ts +63 -0
- package/dist/diff/utils.d.ts.map +1 -0
- package/dist/diff/utils.js +48 -0
- package/dist/diff/utils.js.map +7 -0
- package/dist/magic-proxy/index.d.ts +2 -0
- package/dist/magic-proxy/index.d.ts.map +1 -0
- package/dist/magic-proxy/index.js +6 -0
- package/dist/magic-proxy/index.js.map +7 -0
- package/dist/magic-proxy/proxy.d.ts +63 -0
- package/dist/magic-proxy/proxy.d.ts.map +1 -0
- package/dist/magic-proxy/proxy.js +108 -0
- package/dist/magic-proxy/proxy.js.map +7 -0
- package/dist/polyfills/index.d.ts +2 -0
- package/dist/polyfills/index.d.ts.map +1 -0
- package/dist/polyfills/index.js +25 -0
- package/dist/polyfills/index.js.map +7 -0
- package/dist/polyfills/path.d.ts +24 -0
- package/dist/polyfills/path.d.ts.map +1 -0
- package/dist/polyfills/path.js +174 -0
- package/dist/polyfills/path.js.map +7 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +7 -0
- package/dist/utils/escape-json-pointer.d.ts +7 -0
- package/dist/utils/escape-json-pointer.d.ts.map +1 -0
- package/dist/utils/escape-json-pointer.js +7 -0
- package/dist/utils/escape-json-pointer.js.map +7 -0
- package/dist/utils/get-segments-from-path.d.ts +5 -0
- package/dist/utils/get-segments-from-path.d.ts.map +1 -0
- package/dist/utils/get-segments-from-path.js +11 -0
- package/dist/utils/get-segments-from-path.js.map +7 -0
- package/dist/utils/is-json-object.d.ts +18 -0
- package/dist/utils/is-json-object.d.ts.map +1 -0
- package/dist/utils/is-json-object.js +16 -0
- package/dist/utils/is-json-object.js.map +7 -0
- package/dist/utils/is-object.d.ts +5 -0
- package/dist/utils/is-object.d.ts.map +1 -0
- package/dist/utils/is-object.js +5 -0
- package/dist/utils/is-object.js.map +7 -0
- package/dist/utils/is-yaml.d.ts +17 -0
- package/dist/utils/is-yaml.d.ts.map +1 -0
- package/dist/utils/is-yaml.js +7 -0
- package/dist/utils/is-yaml.js.map +7 -0
- package/dist/utils/json-path-utils.d.ts +23 -0
- package/dist/utils/json-path-utils.d.ts.map +1 -0
- package/dist/utils/json-path-utils.js +16 -0
- package/dist/utils/json-path-utils.js.map +7 -0
- package/dist/utils/normalize.d.ts +5 -0
- package/dist/utils/normalize.d.ts.map +1 -0
- package/dist/utils/normalize.js +28 -0
- package/dist/utils/normalize.js.map +7 -0
- package/dist/utils/unescape-json-pointer.d.ts +8 -0
- package/dist/utils/unescape-json-pointer.d.ts.map +1 -0
- package/dist/utils/unescape-json-pointer.js +7 -0
- package/dist/utils/unescape-json-pointer.js.map +7 -0
- package/esbuild.ts +13 -0
- package/package.json +65 -0
- package/src/bundle/bundle.test.ts +1843 -0
- package/src/bundle/bundle.ts +758 -0
- package/src/bundle/create-limiter.test.ts +28 -0
- package/src/bundle/create-limiter.ts +52 -0
- package/src/bundle/index.ts +2 -0
- package/src/bundle/plugins/browser.ts +4 -0
- package/src/bundle/plugins/fetch-urls/index.test.ts +147 -0
- package/src/bundle/plugins/fetch-urls/index.ts +94 -0
- package/src/bundle/plugins/node.ts +5 -0
- package/src/bundle/plugins/parse-json/index.test.ts +22 -0
- package/src/bundle/plugins/parse-json/index.ts +30 -0
- package/src/bundle/plugins/parse-yaml/index.test.ts +24 -0
- package/src/bundle/plugins/parse-yaml/index.ts +31 -0
- package/src/bundle/plugins/read-files/index.test.ts +35 -0
- package/src/bundle/plugins/read-files/index.ts +55 -0
- package/src/bundle/value-generator.test.ts +166 -0
- package/src/bundle/value-generator.ts +147 -0
- package/src/dereference/dereference.test.ts +137 -0
- package/src/dereference/dereference.ts +84 -0
- package/src/dereference/index.ts +2 -0
- package/src/diff/apply.test.ts +262 -0
- package/src/diff/apply.ts +78 -0
- package/src/diff/diff.test.ts +328 -0
- package/src/diff/diff.ts +94 -0
- package/src/diff/index.test.ts +150 -0
- package/src/diff/index.ts +5 -0
- package/src/diff/merge.test.ts +1109 -0
- package/src/diff/merge.ts +136 -0
- package/src/diff/trie.test.ts +30 -0
- package/src/diff/trie.ts +113 -0
- package/src/diff/utils.test.ts +169 -0
- package/src/diff/utils.ts +113 -0
- package/src/magic-proxy/index.ts +2 -0
- package/src/magic-proxy/proxy.test.ts +145 -0
- package/src/magic-proxy/proxy.ts +225 -0
- package/src/polyfills/index.ts +12 -0
- package/src/polyfills/path.ts +248 -0
- package/src/types.ts +1 -0
- package/src/utils/escape-json-pointer.test.ts +13 -0
- package/src/utils/escape-json-pointer.ts +8 -0
- package/src/utils/get-segments-from-path.test.ts +17 -0
- package/src/utils/get-segments-from-path.ts +17 -0
- package/src/utils/is-json-object.ts +31 -0
- package/src/utils/is-object.test.ts +27 -0
- package/src/utils/is-object.ts +4 -0
- package/src/utils/is-yaml.ts +18 -0
- package/src/utils/json-path-utils.test.ts +13 -0
- package/src/utils/json-path-utils.ts +38 -0
- package/src/utils/normalize.test.ts +91 -0
- package/src/utils/normalize.ts +34 -0
- package/src/utils/unescape-json-pointer.test.ts +23 -0
- package/src/utils/unescape-json-pointer.ts +9 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +16 -0
- package/vite.config.ts +8 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function parseJsonPointer(pointer) {
|
|
2
|
+
return pointer.split("/").filter((segment, index) => (index !== 0 || segment !== "#") && segment);
|
|
3
|
+
}
|
|
4
|
+
function getValueByPath(obj, pointer) {
|
|
5
|
+
return pointer.reduce((acc, part) => {
|
|
6
|
+
if (acc === void 0 || acc === null) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
return acc[part];
|
|
10
|
+
}, obj);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
getValueByPath,
|
|
14
|
+
parseJsonPointer
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=json-path-utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/json-path-utils.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Parses a JSON Pointer string into an array of path segments\n *\n * @example\n * ```ts\n * parseJsonPointer('#/components/schemas/User')\n *\n * ['components', 'schemas', 'User']\n * ```\n */\nexport function parseJsonPointer(pointer: string): string[] {\n return (\n pointer\n // Split on '/'\n .split('/')\n // Remove the leading '#' if present\n .filter((segment, index) => (index !== 0 || segment !== '#') && segment)\n )\n}\n\n/**\n * Retrieves a nested value from the source document using a path array\n *\n * @example\n * ```ts\n * getValueByPath(document, ['components', 'schemas', 'User'])\n *\n * { id: '123', name: 'John Doe' }\n * ```\n */\nexport function getValueByPath<R = unknown>(obj: any, pointer: string[]): R {\n return pointer.reduce((acc, part) => {\n if (acc === undefined || acc === null) {\n return undefined\n }\n return acc[part]\n }, obj)\n}\n"],
|
|
5
|
+
"mappings": "AAUO,SAAS,iBAAiB,SAA2B;AAC1D,SACE,QAEG,MAAM,GAAG,EAET,OAAO,CAAC,SAAS,WAAW,UAAU,KAAK,YAAY,QAAQ,OAAO;AAE7E;AAYO,SAAS,eAA4B,KAAU,SAAsB;AAC1E,SAAO,QAAQ,OAAO,CAAC,KAAK,SAAS;AACnC,QAAI,QAAQ,UAAa,QAAQ,MAAM;AACrC,aAAO;AAAA,IACT;AACA,WAAO,IAAI,IAAI;AAAA,EACjB,GAAG,GAAG;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,GAAG,OA4BrC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { parse } from "yaml";
|
|
2
|
+
function normalize(content) {
|
|
3
|
+
if (content === null) {
|
|
4
|
+
return void 0;
|
|
5
|
+
}
|
|
6
|
+
if (typeof content === "string") {
|
|
7
|
+
if (content.trim() === "") {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(content);
|
|
12
|
+
} catch (_error) {
|
|
13
|
+
const hasColon = /^[^:]+:/.test(content);
|
|
14
|
+
const isJson = content.slice(0, 50).trimStart().startsWith("{");
|
|
15
|
+
if (!hasColon || isJson) {
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
return parse(content, {
|
|
19
|
+
maxAliasCount: 1e4
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return content;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
normalize
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/normalize.ts"],
|
|
4
|
+
"sourcesContent": ["import { parse } from 'yaml'\n\n/**\n * Normalize a string (YAML, JSON, object) to a JavaScript datatype.\n */\nexport function normalize(content: any) {\n if (content === null) {\n return undefined\n }\n\n if (typeof content === 'string') {\n if (content.trim() === '') {\n return undefined\n }\n\n try {\n return JSON.parse(content)\n } catch (_error) {\n // Does it look like YAML?\n const hasColon = /^[^:]+:/.test(content)\n const isJson = content.slice(0, 50).trimStart().startsWith('{')\n\n if (!hasColon || isJson) {\n return undefined\n }\n\n return parse(content, {\n maxAliasCount: 10000,\n })\n }\n }\n\n return content\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AAKf,SAAS,UAAU,SAAc;AACtC,MAAI,YAAY,MAAM;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,QAAI,QAAQ,KAAK,MAAM,IAAI;AACzB,aAAO;AAAA,IACT;AAEA,QAAI;AACF,aAAO,KAAK,MAAM,OAAO;AAAA,IAC3B,SAAS,QAAQ;AAEf,YAAM,WAAW,UAAU,KAAK,OAAO;AACvC,YAAM,SAAS,QAAQ,MAAM,GAAG,EAAE,EAAE,UAAU,EAAE,WAAW,GAAG;AAE9D,UAAI,CAAC,YAAY,QAAQ;AACvB,eAAO;AAAA,MACT;AAEA,aAAO,MAAM,SAAS;AAAA,QACpB,eAAe;AAAA,MACjB,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unescape-json-pointer.d.ts","sourceRoot":"","sources":["../../src/utils/unescape-json-pointer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,UAE9C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/unescape-json-pointer.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Unescape JSON pointer\n *\n * Examples:\n * /foo~1bar~0baz -> /foo/bar~baz\n */\nexport function unescapeJsonPointer(uri: string) {\n return decodeURI(uri.replace(/~1/g, '/').replace(/~0/g, '~'))\n}\n"],
|
|
5
|
+
"mappings": "AAMO,SAAS,oBAAoB,KAAa;AAC/C,SAAO,UAAU,IAAI,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,CAAC;AAC9D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esbuild.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { build } from '@scalar/build-tooling/esbuild'
|
|
2
|
+
|
|
3
|
+
await build({
|
|
4
|
+
platform: 'shared',
|
|
5
|
+
entries: [
|
|
6
|
+
'src/bundle/index.ts',
|
|
7
|
+
'src/magic-proxy/index.ts',
|
|
8
|
+
'src/diff/index.ts',
|
|
9
|
+
'src/dereference/index.ts',
|
|
10
|
+
'src/bundle/plugins/node.ts',
|
|
11
|
+
'src/bundle/plugins/browser.ts',
|
|
12
|
+
],
|
|
13
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scalar/json-magic",
|
|
3
|
+
"description": "A collection of utilities for working with JSON objects, including diffing, conflict resolution, bundling and more.",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Scalar (https://github.com/scalar)",
|
|
6
|
+
"homepage": "https://github.com/scalar/scalar",
|
|
7
|
+
"bugs": "https://github.com/scalar/scalar/issues/new/choose",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/scalar/scalar.git",
|
|
11
|
+
"directory": "packages/json-magic"
|
|
12
|
+
},
|
|
13
|
+
"version": "0.1.0",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"yaml": "2.8.0",
|
|
20
|
+
"vue": "^3.5.17"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"vite": "6.1.6",
|
|
24
|
+
"fastify": "^5.3.3",
|
|
25
|
+
"@scalar/build-tooling": "0.2.4"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
"./bundle": {
|
|
29
|
+
"import": "./dist/bundle/index.js",
|
|
30
|
+
"types": "./dist/bundle/index.d.ts",
|
|
31
|
+
"default": "./dist/bundle/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./bundle/plugins/browser": {
|
|
34
|
+
"import": "./dist/bundle/plugins/browser.js",
|
|
35
|
+
"types": "./dist/bundle/plugins/browser.d.ts",
|
|
36
|
+
"default": "./dist/bundle/plugins/browser.js"
|
|
37
|
+
},
|
|
38
|
+
"./bundle/plugins/node": {
|
|
39
|
+
"import": "./dist/bundle/plugins/node.js",
|
|
40
|
+
"types": "./dist/bundle/plugins/node.d.ts",
|
|
41
|
+
"default": "./dist/bundle/plugins/node.js"
|
|
42
|
+
},
|
|
43
|
+
"./dereference": {
|
|
44
|
+
"import": "./dist/dereference/index.js",
|
|
45
|
+
"types": "./dist/dereference/index.d.ts",
|
|
46
|
+
"default": "./dist/dereference/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./diff": {
|
|
49
|
+
"import": "./dist/diff/index.js",
|
|
50
|
+
"types": "./dist/diff/index.d.ts",
|
|
51
|
+
"default": "./dist/diff/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./magic-proxy": {
|
|
54
|
+
"import": "./dist/magic-proxy/index.js",
|
|
55
|
+
"types": "./dist/magic-proxy/index.d.ts",
|
|
56
|
+
"default": "./dist/magic-proxy/index.js"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "scalar-build-esbuild",
|
|
61
|
+
"test": "vitest test",
|
|
62
|
+
"types:build": "scalar-types-build",
|
|
63
|
+
"types:check": "scalar-types-check"
|
|
64
|
+
}
|
|
65
|
+
}
|