@scalar/json-magic 0.8.2 → 0.8.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/bundle/index.d.ts +1 -0
  3. package/dist/bundle/index.d.ts.map +1 -1
  4. package/dist/bundle/index.js.map +1 -1
  5. package/dist/bundle/plugins/browser.js.map +1 -1
  6. package/dist/bundle/plugins/node.d.ts +1 -1
  7. package/dist/bundle/plugins/node.js +1 -1
  8. package/dist/bundle/plugins/node.js.map +1 -1
  9. package/dist/dereference/index.d.ts.map +1 -1
  10. package/dist/dereference/index.js.map +2 -2
  11. package/dist/diff/index.d.ts +1 -1
  12. package/dist/diff/index.d.ts.map +1 -1
  13. package/dist/diff/index.js +1 -1
  14. package/dist/diff/index.js.map +2 -2
  15. package/dist/helpers/escape-json-pointer.d.ts +1 -1
  16. package/dist/helpers/escape-json-pointer.js.map +1 -1
  17. package/dist/magic-proxy/index.d.ts.map +1 -1
  18. package/dist/magic-proxy/index.js.map +2 -2
  19. package/dist/magic-proxy/proxy.d.ts +0 -1
  20. package/dist/magic-proxy/proxy.d.ts.map +1 -1
  21. package/dist/magic-proxy/proxy.js +1 -2
  22. package/dist/magic-proxy/proxy.js.map +2 -2
  23. package/package.json +12 -13
  24. package/.turbo/turbo-build.log +0 -10
  25. package/esbuild.ts +0 -15
  26. package/src/bundle/bundle.test.ts +0 -2917
  27. package/src/bundle/bundle.ts +0 -916
  28. package/src/bundle/create-limiter.test.ts +0 -28
  29. package/src/bundle/create-limiter.ts +0 -52
  30. package/src/bundle/index.ts +0 -3
  31. package/src/bundle/plugins/browser.ts +0 -4
  32. package/src/bundle/plugins/fetch-urls/index.test.ts +0 -141
  33. package/src/bundle/plugins/fetch-urls/index.ts +0 -105
  34. package/src/bundle/plugins/node.ts +0 -5
  35. package/src/bundle/plugins/parse-json/index.test.ts +0 -24
  36. package/src/bundle/plugins/parse-json/index.ts +0 -32
  37. package/src/bundle/plugins/parse-yaml/index.test.ts +0 -26
  38. package/src/bundle/plugins/parse-yaml/index.ts +0 -34
  39. package/src/bundle/plugins/read-files/index.test.ts +0 -36
  40. package/src/bundle/plugins/read-files/index.ts +0 -58
  41. package/src/bundle/value-generator.test.ts +0 -165
  42. package/src/bundle/value-generator.ts +0 -143
  43. package/src/dereference/dereference.test.ts +0 -142
  44. package/src/dereference/dereference.ts +0 -84
  45. package/src/dereference/index.ts +0 -2
  46. package/src/diff/apply.test.ts +0 -262
  47. package/src/diff/apply.ts +0 -83
  48. package/src/diff/diff.test.ts +0 -328
  49. package/src/diff/diff.ts +0 -93
  50. package/src/diff/index.test.ts +0 -150
  51. package/src/diff/index.ts +0 -5
  52. package/src/diff/merge.test.ts +0 -1109
  53. package/src/diff/merge.ts +0 -136
  54. package/src/diff/trie.test.ts +0 -30
  55. package/src/diff/trie.ts +0 -113
  56. package/src/diff/utils.test.ts +0 -169
  57. package/src/diff/utils.ts +0 -111
  58. package/src/helpers/convert-to-local-ref.test.ts +0 -211
  59. package/src/helpers/convert-to-local-ref.ts +0 -43
  60. package/src/helpers/escape-json-pointer.test.ts +0 -13
  61. package/src/helpers/escape-json-pointer.ts +0 -8
  62. package/src/helpers/get-schemas.test.ts +0 -356
  63. package/src/helpers/get-schemas.ts +0 -80
  64. package/src/helpers/get-segments-from-path.test.ts +0 -17
  65. package/src/helpers/get-segments-from-path.ts +0 -17
  66. package/src/helpers/get-value-by-path.test.ts +0 -338
  67. package/src/helpers/get-value-by-path.ts +0 -44
  68. package/src/helpers/is-json-object.ts +0 -31
  69. package/src/helpers/is-object.test.ts +0 -27
  70. package/src/helpers/is-object.ts +0 -4
  71. package/src/helpers/is-yaml.ts +0 -18
  72. package/src/helpers/json-path-utils.test.ts +0 -57
  73. package/src/helpers/json-path-utils.ts +0 -50
  74. package/src/helpers/normalize.test.ts +0 -92
  75. package/src/helpers/normalize.ts +0 -35
  76. package/src/helpers/unescape-json-pointer.test.ts +0 -23
  77. package/src/helpers/unescape-json-pointer.ts +0 -9
  78. package/src/magic-proxy/index.ts +0 -2
  79. package/src/magic-proxy/proxy.test.ts +0 -1987
  80. package/src/magic-proxy/proxy.ts +0 -323
  81. package/src/types.ts +0 -1
  82. package/tsconfig.build.json +0 -12
  83. package/tsconfig.json +0 -16
  84. package/vite.config.ts +0 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @scalar/json-magic
2
2
 
3
+ ## 0.8.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`9ec8adf`](https://github.com/scalar/scalar/commit/9ec8adfea017333dee5bc3949104232f7dc57f4a)]:
8
+ - @scalar/helpers@0.2.0
9
+
10
+ ## 0.8.3
11
+
12
+ ### Patch Changes
13
+
14
+ - [#7417](https://github.com/scalar/scalar/pull/7417) [`e04879c`](https://github.com/scalar/scalar/commit/e04879c65602dfb65393876754f5344751b8953d) Thanks [@marcalexiei](https://github.com/marcalexiei)! - fix(json-margic): remove `helpers/generate-hash` invalid entrypoint
15
+
16
+ - [#7387](https://github.com/scalar/scalar/pull/7387) [`bfd814a`](https://github.com/scalar/scalar/commit/bfd814a4219660face190041cc4845182b56ab03) Thanks [@geoffgscott](https://github.com/geoffgscott)! - hotfix: patch exports from build tooling bug
17
+
18
+ - [#7422](https://github.com/scalar/scalar/pull/7422) [`af54a80`](https://github.com/scalar/scalar/commit/af54a80349269a4269a68f6a372f837177a3537c) Thanks [@inyourtime](https://github.com/inyourtime)! - build(json-magic): prevent src folder from being published
19
+
20
+ - Updated dependencies [[`bfd814a`](https://github.com/scalar/scalar/commit/bfd814a4219660face190041cc4845182b56ab03), [`86f028d`](https://github.com/scalar/scalar/commit/86f028deb0b456f923edd261f5f4b0fa9b616b7d)]:
21
+ - @scalar/helpers@0.1.3
22
+
3
23
  ## 0.8.2
4
24
 
5
25
  ### Patch Changes
@@ -1,3 +1,4 @@
1
+ /** biome-ignore-all lint/performance/noBarrelFile: entrypoint */
1
2
  export type { LifecyclePlugin, LoaderPlugin, Plugin, ResolveResult } from './bundle.js';
2
3
  export { bundle, resolveAndCopyReferences } from './bundle.js';
3
4
  //# 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;AAEpF,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,iEAAiE;AACjE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACpF,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/bundle/index.ts"],
4
- "sourcesContent": ["export type { LifecyclePlugin, LoaderPlugin, Plugin, ResolveResult } from './bundle'\n// biome-ignore lint/performance/noBarrelFile: exporting bundle\nexport { bundle, resolveAndCopyReferences } from './bundle'\n"],
4
+ "sourcesContent": ["/** biome-ignore-all lint/performance/noBarrelFile: entrypoint */\nexport type { LifecyclePlugin, LoaderPlugin, Plugin, ResolveResult } from './bundle'\nexport { bundle, resolveAndCopyReferences } from './bundle'\n"],
5
5
  "mappings": "AAEA,SAAS,QAAQ,gCAAgC;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/bundle/plugins/browser.ts"],
4
- "sourcesContent": ["// biome-ignore lint/performance/noBarrelFile: <explanation>\nexport { fetchUrls } from './fetch-urls'\nexport { parseJson } from './parse-json'\nexport { parseYaml } from './parse-yaml'\n"],
4
+ "sourcesContent": ["// biome-ignore lint/performance/noBarrelFile: entrypoint\nexport { fetchUrls } from './fetch-urls'\nexport { parseJson } from './parse-json'\nexport { parseYaml } from './parse-yaml'\n"],
5
5
  "mappings": "AACA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
1
  export { fetchUrls } from './fetch-urls/index.js';
2
- export { readFiles } from './read-files/index.js';
3
2
  export { parseJson } from './parse-json/index.js';
4
3
  export { parseYaml } from './parse-yaml/index.js';
4
+ export { readFiles } from './read-files/index.js';
5
5
  //# sourceMappingURL=node.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { fetchUrls } from "./fetch-urls/index.js";
2
- import { readFiles } from "./read-files/index.js";
3
2
  import { parseJson } from "./parse-json/index.js";
4
3
  import { parseYaml } from "./parse-yaml/index.js";
4
+ import { readFiles } from "./read-files/index.js";
5
5
  export {
6
6
  fetchUrls,
7
7
  parseJson,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/bundle/plugins/node.ts"],
4
- "sourcesContent": ["// biome-ignore lint/performance/noBarrelFile: <explanation>\nexport { fetchUrls } from './fetch-urls'\nexport { readFiles } from './read-files'\nexport { parseJson } from './parse-json'\nexport { parseYaml } from './parse-yaml'\n"],
4
+ "sourcesContent": ["// biome-ignore lint/performance/noBarrelFile: entrypoint\nexport { fetchUrls } from './fetch-urls'\nexport { parseJson } from './parse-json'\nexport { parseYaml } from './parse-yaml'\nexport { readFiles } from './read-files'\n"],
5
5
  "mappings": "AACA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dereference/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dereference/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dereference/index.ts"],
4
- "sourcesContent": ["// biome-ignore lint/performance/noBarrelFile: <explanation>\nexport { dereference } from './dereference'\n"],
5
- "mappings": "AACA,SAAS,mBAAmB;",
4
+ "sourcesContent": ["export { dereference } from './dereference'\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
- import { diff, type Difference } from '../diff/diff.js';
2
1
  import { apply } from '../diff/apply.js';
2
+ import { type Difference, diff } from '../diff/diff.js';
3
3
  import { merge } from '../diff/merge.js';
4
4
  export { diff, apply, merge, type Difference };
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/diff/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/diff/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,CAAA"}
@@ -1,5 +1,5 @@
1
- import { diff } from "../diff/diff.js";
2
1
  import { apply } from "../diff/apply.js";
2
+ import { diff } from "../diff/diff.js";
3
3
  import { merge } from "../diff/merge.js";
4
4
  export {
5
5
  apply,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/diff/index.ts"],
4
- "sourcesContent": ["import { diff, type Difference } from '@/diff/diff'\nimport { apply } from '@/diff/apply'\nimport { merge } from '@/diff/merge'\n\nexport { diff, apply, merge, type Difference }\n"],
5
- "mappings": "AAAA,SAAS,YAA6B;AACtC,SAAS,aAAa;AACtB,SAAS,aAAa;",
4
+ "sourcesContent": ["import { apply } from '@/diff/apply'\nimport { type Difference, diff } from '@/diff/diff'\nimport { merge } from '@/diff/merge'\n\nexport { diff, apply, merge, type Difference }\n"],
5
+ "mappings": "AAAA,SAAS,aAAa;AACtB,SAA0B,YAAY;AACtC,SAAS,aAAa;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Escapes a JSON pointer string.
3
3
  *
4
- * Example: `/foo/bar~baz` -> `/foo~1bar~0baz`
4
+ * Example: `/foo/bar~baz` -> `'~1foo~1bar~0baz'`
5
5
  */
6
6
  export declare function escapeJsonPointer(str: string): string;
7
7
  //# sourceMappingURL=escape-json-pointer.d.ts.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/helpers/escape-json-pointer.ts"],
4
- "sourcesContent": ["/**\n * Escapes a JSON pointer string.\n *\n * Example: `/foo/bar~baz` -> `/foo~1bar~0baz`\n */\nexport function escapeJsonPointer(str: string) {\n return str.replace(/~/g, '~0').replace(/\\//g, '~1')\n}\n"],
4
+ "sourcesContent": ["/**\n * Escapes a JSON pointer string.\n *\n * Example: `/foo/bar~baz` -> `'~1foo~1bar~0baz'`\n */\nexport function escapeJsonPointer(str: string) {\n return str.replace(/~/g, '~0').replace(/\\//g, '~1')\n}\n"],
5
5
  "mappings": "AAKO,SAAS,kBAAkB,KAAa;AAC7C,SAAO,IAAI,QAAQ,MAAM,IAAI,EAAE,QAAQ,OAAO,IAAI;AACpD;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/magic-proxy/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/magic-proxy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/magic-proxy/index.ts"],
4
- "sourcesContent": ["// biome-ignore lint/performance/noBarrelFile: <explanation>\nexport { createMagicProxy, getRaw } from './proxy'\n"],
5
- "mappings": "AACA,SAAS,kBAAkB,cAAc;",
4
+ "sourcesContent": ["export { createMagicProxy, getRaw } from './proxy'\n"],
5
+ "mappings": "AAAA,SAAS,kBAAkB,cAAc;",
6
6
  "names": []
7
7
  }
@@ -65,7 +65,6 @@ export declare const createMagicProxy: <T extends Record<keyof T & symbol, unkno
65
65
  */
66
66
  currentContext: string;
67
67
  }) => T;
68
- export declare const isMagicProxyObject: (obj: unknown) => boolean;
69
68
  /**
70
69
  * Gets the raw (non-proxied) version of an object created by createMagicProxy.
71
70
  * This is useful when you need to access the original object without the magic proxy wrapper.
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/magic-proxy/proxy.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,OAAO,CAAC,EAA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C3B;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAA;CAOvB,KACA,CAkNF,CAAA;AAMD;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAUnC"}
@@ -187,7 +187,6 @@ function getRaw(obj) {
187
187
  }
188
188
  export {
189
189
  createMagicProxy,
190
- getRaw,
191
- isMagicProxyObject
190
+ getRaw
192
191
  };
193
192
  //# sourceMappingURL=proxy.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/magic-proxy/proxy.ts"],
4
- "sourcesContent": ["import { convertToLocalRef } from '@/helpers/convert-to-local-ref'\nimport { getId, getSchemas } from '@/helpers/get-schemas'\nimport { getValueByPath } from '@/helpers/get-value-by-path'\nimport { isObject } from '@/helpers/is-object'\nimport { createPathFromSegments, parseJsonPointer } from '@/helpers/json-path-utils'\nimport type { UnknownObject } from '@/types'\n\nconst isMagicProxy = Symbol('isMagicProxy')\nconst magicProxyTarget = Symbol('magicProxyTarget')\n\nconst REF_VALUE = '$ref-value'\nconst REF_KEY = '$ref'\n\n/**\n * Creates a \"magic\" proxy for a given object or array, enabling transparent access to\n * JSON Reference ($ref) values as if they were directly present on the object.\n *\n * Features:\n * - If an object contains a `$ref` property, accessing the special `$ref-value` property will resolve and return the referenced value from the root object.\n * - All nested objects and arrays are recursively wrapped in proxies, so reference resolution works at any depth.\n * - Properties starting with `__scalar_` are considered internal and are hidden by default: they return undefined on access, are excluded from enumeration, and `'in'` checks return false. This can be overridden with the `showInternal` option.\n * - Setting, deleting, and enumerating properties works as expected, including for proxied references.\n * - Ensures referential stability by caching proxies for the same target object.\n *\n * @param target - The object or array to wrap in a magic proxy\n * @param options - Optional settings (e.g., showInternal to expose internal properties)\n * @param args - Internal arguments for advanced usage (root object, proxy/cache maps, current context)\n * @returns A proxied version of the input object/array with magic $ref-value support\n *\n * @example\n * const input = {\n * definitions: {\n * foo: { bar: 123 }\n * },\n * refObj: { $ref: '#/definitions/foo' },\n * __scalar_internal: 'hidden property'\n * }\n * const proxy = createMagicProxy(input)\n *\n * // Accessing proxy.refObj['$ref-value'] will resolve to { bar: 123 }\n * console.log(proxy.refObj['$ref-value']) // { bar: 123 }\n *\n * // Properties starting with __scalar_ are hidden\n * console.log(proxy.__scalar_internal) // undefined\n * console.log('__scalar_internal' in proxy) // false\n * console.log(Object.keys(proxy)) // ['definitions', 'refObj'] (no '__scalar_internal')\n *\n * // Setting and deleting properties works as expected\n * proxy.refObj.extra = 'hello'\n * delete proxy.refObj.extra\n */\nexport const createMagicProxy = <T extends Record<keyof T & symbol, unknown>, S extends UnknownObject>(\n target: T,\n options?: Partial<{ showInternal: boolean }>,\n args: {\n /**\n * The root object for resolving local JSON references.\n */\n root: S | T\n /**\n * Cache to store already created proxies for target objects to ensure referential stability.\n *\n * It is helpful when dealing with reactive frameworks like Vue,\n */\n proxyCache: WeakMap<object, T>\n /**\n * Cache to store resolved JSON references.\n */\n cache: Map<string, unknown>\n /**\n * Map of all schemas by their $id or $anchor for cross-document reference resolution.\n */\n schemas: Map<string, string>\n /**\n * The current JSON path context within the root object.\n *\n * Used to resolve $anchor references correctly.\n */\n currentContext: string\n } = {\n root: target,\n proxyCache: new WeakMap(),\n cache: new Map(),\n schemas: getSchemas(target),\n currentContext: '',\n },\n) => {\n if (!isObject(target) && !Array.isArray(target)) {\n return target\n }\n\n // Return existing proxy for the same target to ensure referential stability\n if (args.proxyCache.has(target)) {\n return args.proxyCache.get(target)\n }\n\n const handler: ProxyHandler<T> = {\n /**\n * Proxy \"get\" trap for magic proxy.\n * - If accessing the special isMagicProxy symbol, return true to identify proxy.\n * - If accessing the magicProxyTarget symbol, return the original target object.\n * - Hide properties starting with __scalar_ by returning undefined.\n * - If accessing \"$ref-value\" and the object has a local $ref, resolve and return the referenced value as a new magic proxy.\n * - For all other properties, recursively wrap the returned value in a magic proxy (if applicable).\n */\n get(target, prop, receiver) {\n if (prop === isMagicProxy) {\n // Used to identify if an object is a magic proxy\n return true\n }\n\n if (prop === magicProxyTarget) {\n // Used to retrieve the original target object from the proxy\n return target\n }\n\n // Hide properties starting with __scalar_ - these are considered internal/private properties\n // and should not be accessible through the magic proxy interface\n if (typeof prop === 'string' && prop.startsWith('__scalar_') && !options?.showInternal) {\n return undefined\n }\n\n // Get the $ref value of the current target (if any)\n const ref = Reflect.get(target, REF_KEY, receiver)\n // Get the identifier ($id) of the current target for context tracking\n const id = getId(target)\n\n // If accessing \"$ref-value\" and $ref is a local reference, resolve and return the referenced value\n if (prop === REF_VALUE && typeof ref === 'string') {\n // Check cache first for performance optimization\n if (args.cache.has(ref)) {\n return args.cache.get(ref)\n }\n\n const path = convertToLocalRef(ref, id ?? args.currentContext, args.schemas)\n\n if (path === undefined) {\n return undefined\n }\n\n // Resolve the reference and create a new magic proxy\n const resolvedValue = getValueByPath(args.root, parseJsonPointer(`#/${path}`))\n // Return early if the value is already a magic proxy\n if (isMagicProxyObject(resolvedValue.value)) {\n return resolvedValue.value\n }\n const proxiedValue = createMagicProxy(resolvedValue.value, options, {\n ...args,\n currentContext: resolvedValue.context,\n })\n\n // Store in cache for future lookups\n args.cache.set(ref, proxiedValue)\n return proxiedValue\n }\n\n // For all other properties, recursively wrap the value in a magic proxy\n const value = Reflect.get(target, prop, receiver)\n\n // Return early if the value is already a magic proxy\n if (isMagicProxyObject(value)) {\n return value\n }\n\n return createMagicProxy(value as T, options, { ...args, currentContext: id ?? args.currentContext })\n },\n /**\n * Proxy \"set\" trap for magic proxy.\n * Allows setting properties on the proxied object.\n * This will update the underlying target object.\n *\n * Note: it will not update if the property starts with __scalar_\n * Those will be considered private properties by the proxy\n */\n set(target, prop, newValue, receiver) {\n const ref = Reflect.get(target, REF_KEY, receiver)\n\n if (typeof prop === 'string' && prop.startsWith('__scalar_') && !options?.showInternal) {\n return true\n }\n\n if (prop === REF_VALUE && typeof ref === 'string') {\n const id = getId(target)\n const path = convertToLocalRef(ref, id ?? args.currentContext, args.schemas)\n\n if (path === undefined) {\n return undefined\n }\n\n const segments = parseJsonPointer(`#/${path}`)\n\n if (segments.length === 0) {\n return false // Can not set top level $ref-value\n }\n\n // Get the parent node or create it if it does not exist\n const getParentNode = () => getValueByPath(args.root, segments.slice(0, -1)).value\n\n if (getParentNode() === undefined) {\n createPathFromSegments(args.root, segments.slice(0, -1))\n\n // In this case the ref is pointing to an invalid path, so we warn the user\n console.warn(\n `Trying to set $ref-value for invalid reference: ${ref}\\n\\nPlease fix your input file to fix this issue.`,\n )\n }\n\n // Set the value on the parent node\n getParentNode()[segments.at(-1)] = newValue\n return true\n }\n\n return Reflect.set(target, prop, newValue, receiver)\n },\n /**\n * Proxy \"deleteProperty\" trap for magic proxy.\n * Allows deleting properties from the proxied object.\n * This will update the underlying target object.\n */\n deleteProperty(target, prop) {\n return Reflect.deleteProperty(target, prop)\n },\n /**\n * Proxy \"has\" trap for magic proxy.\n * - Pretend that \"$ref-value\" exists if \"$ref\" exists on the target.\n * This allows expressions like `\"$ref-value\" in obj` to return true for objects with a $ref,\n * even though \"$ref-value\" is a virtual property provided by the proxy.\n * - Hide properties starting with __scalar_ by returning false.\n * - For all other properties, defer to the default Reflect.has behavior.\n */\n has(target, prop) {\n // Hide properties starting with __scalar_\n if (typeof prop === 'string' && prop.startsWith('__scalar_') && !options?.showInternal) {\n return false\n }\n\n // Pretend that \"$ref-value\" exists if \"$ref\" exists\n if (prop === REF_VALUE && REF_KEY in target) {\n return true\n }\n return Reflect.has(target, prop)\n },\n /**\n * Proxy \"ownKeys\" trap for magic proxy.\n * - Returns the list of own property keys for the proxied object.\n * - If the object has a \"$ref\" property, ensures that \"$ref-value\" is also included in the keys,\n * even though \"$ref-value\" is a virtual property provided by the proxy.\n * This allows Object.keys, Reflect.ownKeys, etc. to include \"$ref-value\" for objects with $ref.\n * - Filters out properties starting with __scalar_.\n */\n ownKeys(target) {\n const keys = Reflect.ownKeys(target)\n\n // Filter out properties starting with __scalar_\n const filteredKeys = keys.filter(\n (key) => typeof key !== 'string' || !(key.startsWith('__scalar_') && !options?.showInternal),\n )\n\n if (REF_KEY in target && !filteredKeys.includes(REF_VALUE)) {\n filteredKeys.push(REF_VALUE)\n }\n return filteredKeys\n },\n\n /**\n * Proxy \"getOwnPropertyDescriptor\" trap for magic proxy.\n * - For the virtual \"$ref-value\" property, returns a descriptor that makes it appear as a regular property.\n * - Hide properties starting with __scalar_ by returning undefined.\n * - For all other properties, delegates to the default Reflect.getOwnPropertyDescriptor behavior.\n * - This ensures that Object.getOwnPropertyDescriptor and similar methods work correctly with the virtual property.\n */\n getOwnPropertyDescriptor(target, prop) {\n // Hide properties starting with __scalar_\n if (typeof prop === 'string' && prop.startsWith('__scalar_') && !options?.showInternal) {\n return undefined\n }\n\n const ref = Reflect.get(target, REF_KEY)\n\n if (prop === REF_VALUE && typeof ref === 'string') {\n return {\n configurable: true,\n enumerable: true,\n value: undefined,\n writable: false,\n }\n }\n\n // Otherwise, delegate to the default behavior\n return Reflect.getOwnPropertyDescriptor(target, prop)\n },\n }\n\n const proxied = new Proxy<T>(target, handler)\n args.proxyCache.set(target, proxied)\n return proxied\n}\n\nexport const isMagicProxyObject = (obj: unknown): boolean => {\n return typeof obj === 'object' && obj !== null && (obj as { [isMagicProxy]: boolean })[isMagicProxy] === true\n}\n\n/**\n * Gets the raw (non-proxied) version of an object created by createMagicProxy.\n * This is useful when you need to access the original object without the magic proxy wrapper.\n *\n * @param obj - The magic proxy object to get the raw version of\n * @returns The raw version of the object\n * @example\n * const proxy = createMagicProxy({ foo: { $ref: '#/bar' } })\n * const raw = getRaw(proxy) // { foo: { $ref: '#/bar' } }\n */\nexport function getRaw<T>(obj: T): T {\n if (typeof obj !== 'object' || obj === null) {\n return obj\n }\n\n if ((obj as T & { [isMagicProxy]: boolean | undefined })[isMagicProxy]) {\n return (obj as T & { [magicProxyTarget]: T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Aa,OAAO,QAAQ,UAAU;AACjD,eAAO;AAAA,UACL,cAAc;AAAA,UACd,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,UAAU;AAAA,QACZ;AAAA,MACF;AAGA,aAAO,QAAQ,yBAAyBA,SAAQ,IAAI;AAAA,IACtD;AAAA,EACF;AAEA,QAAM,UAAU,IAAI,MAAS,QAAQ,OAAO;AAC5C,OAAK,WAAW,IAAI,QAAQ,OAAO;AACnC,SAAO;AACT;AAEO,MAAM,qBAAqB,CAAC,QAA0B;AAC3D,SAAO,OAAO,QAAQ,YAAY,QAAQ,QAAS,IAAoC,YAAY,MAAM;AAC3G;AAYO,SAAS,OAAU,KAAW;AACnC,MAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C,WAAO;AAAA,EACT;AAEA,MAAK,IAAoD,YAAY,GAAG;AACtE,WAAQ,IAAsC,gBAAgB;AAAA,EAChE;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import { convertToLocalRef } from '@/helpers/convert-to-local-ref'\nimport { getId, getSchemas } from '@/helpers/get-schemas'\nimport { getValueByPath } from '@/helpers/get-value-by-path'\nimport { isObject } from '@/helpers/is-object'\nimport { createPathFromSegments, parseJsonPointer } from '@/helpers/json-path-utils'\nimport type { UnknownObject } from '@/types'\n\nconst isMagicProxy = Symbol('isMagicProxy')\nconst magicProxyTarget = Symbol('magicProxyTarget')\n\nconst REF_VALUE = '$ref-value'\nconst REF_KEY = '$ref'\n\n/**\n * Creates a \"magic\" proxy for a given object or array, enabling transparent access to\n * JSON Reference ($ref) values as if they were directly present on the object.\n *\n * Features:\n * - If an object contains a `$ref` property, accessing the special `$ref-value` property will resolve and return the referenced value from the root object.\n * - All nested objects and arrays are recursively wrapped in proxies, so reference resolution works at any depth.\n * - Properties starting with `__scalar_` are considered internal and are hidden by default: they return undefined on access, are excluded from enumeration, and `'in'` checks return false. This can be overridden with the `showInternal` option.\n * - Setting, deleting, and enumerating properties works as expected, including for proxied references.\n * - Ensures referential stability by caching proxies for the same target object.\n *\n * @param target - The object or array to wrap in a magic proxy\n * @param options - Optional settings (e.g., showInternal to expose internal properties)\n * @param args - Internal arguments for advanced usage (root object, proxy/cache maps, current context)\n * @returns A proxied version of the input object/array with magic $ref-value support\n *\n * @example\n * const input = {\n * definitions: {\n * foo: { bar: 123 }\n * },\n * refObj: { $ref: '#/definitions/foo' },\n * __scalar_internal: 'hidden property'\n * }\n * const proxy = createMagicProxy(input)\n *\n * // Accessing proxy.refObj['$ref-value'] will resolve to { bar: 123 }\n * console.log(proxy.refObj['$ref-value']) // { bar: 123 }\n *\n * // Properties starting with __scalar_ are hidden\n * console.log(proxy.__scalar_internal) // undefined\n * console.log('__scalar_internal' in proxy) // false\n * console.log(Object.keys(proxy)) // ['definitions', 'refObj'] (no '__scalar_internal')\n *\n * // Setting and deleting properties works as expected\n * proxy.refObj.extra = 'hello'\n * delete proxy.refObj.extra\n */\nexport const createMagicProxy = <T extends Record<keyof T & symbol, unknown>, S extends UnknownObject>(\n target: T,\n options?: Partial<{ showInternal: boolean }>,\n args: {\n /**\n * The root object for resolving local JSON references.\n */\n root: S | T\n /**\n * Cache to store already created proxies for target objects to ensure referential stability.\n *\n * It is helpful when dealing with reactive frameworks like Vue,\n */\n proxyCache: WeakMap<object, T>\n /**\n * Cache to store resolved JSON references.\n */\n cache: Map<string, unknown>\n /**\n * Map of all schemas by their $id or $anchor for cross-document reference resolution.\n */\n schemas: Map<string, string>\n /**\n * The current JSON path context within the root object.\n *\n * Used to resolve $anchor references correctly.\n */\n currentContext: string\n } = {\n root: target,\n proxyCache: new WeakMap(),\n cache: new Map(),\n schemas: getSchemas(target),\n currentContext: '',\n },\n): T => {\n if (!isObject(target) && !Array.isArray(target)) {\n return target\n }\n\n // Return existing proxy for the same target to ensure referential stability\n if (args.proxyCache.has(target)) {\n return args.proxyCache.get(target)\n }\n\n const handler: ProxyHandler<T> = {\n /**\n * Proxy \"get\" trap for magic proxy.\n * - If accessing the special isMagicProxy symbol, return true to identify proxy.\n * - If accessing the magicProxyTarget symbol, return the original target object.\n * - Hide properties starting with __scalar_ by returning undefined.\n * - If accessing \"$ref-value\" and the object has a local $ref, resolve and return the referenced value as a new magic proxy.\n * - For all other properties, recursively wrap the returned value in a magic proxy (if applicable).\n */\n get(target, prop, receiver) {\n if (prop === isMagicProxy) {\n // Used to identify if an object is a magic proxy\n return true\n }\n\n if (prop === magicProxyTarget) {\n // Used to retrieve the original target object from the proxy\n return target\n }\n\n // Hide properties starting with __scalar_ - these are considered internal/private properties\n // and should not be accessible through the magic proxy interface\n if (typeof prop === 'string' && prop.startsWith('__scalar_') && !options?.showInternal) {\n return undefined\n }\n\n // Get the $ref value of the current target (if any)\n const ref = Reflect.get(target, REF_KEY, receiver)\n // Get the identifier ($id) of the current target for context tracking\n const id = getId(target)\n\n // If accessing \"$ref-value\" and $ref is a local reference, resolve and return the referenced value\n if (prop === REF_VALUE && typeof ref === 'string') {\n // Check cache first for performance optimization\n if (args.cache.has(ref)) {\n return args.cache.get(ref)\n }\n\n const path = convertToLocalRef(ref, id ?? args.currentContext, args.schemas)\n\n if (path === undefined) {\n return undefined\n }\n\n // Resolve the reference and create a new magic proxy\n const resolvedValue = getValueByPath(args.root, parseJsonPointer(`#/${path}`))\n // Return early if the value is already a magic proxy\n if (isMagicProxyObject(resolvedValue.value)) {\n return resolvedValue.value\n }\n const proxiedValue = createMagicProxy(resolvedValue.value, options, {\n ...args,\n currentContext: resolvedValue.context,\n })\n\n // Store in cache for future lookups\n args.cache.set(ref, proxiedValue)\n return proxiedValue\n }\n\n // For all other properties, recursively wrap the value in a magic proxy\n const value = Reflect.get(target, prop, receiver)\n\n // Return early if the value is already a magic proxy\n if (isMagicProxyObject(value)) {\n return value\n }\n\n return createMagicProxy(value as T, options, { ...args, currentContext: id ?? args.currentContext })\n },\n /**\n * Proxy \"set\" trap for magic proxy.\n * Allows setting properties on the proxied object.\n * This will update the underlying target object.\n *\n * Note: it will not update if the property starts with __scalar_\n * Those will be considered private properties by the proxy\n */\n set(target, prop, newValue, receiver) {\n const ref = Reflect.get(target, REF_KEY, receiver)\n\n if (typeof prop === 'string' && prop.startsWith('__scalar_') && !options?.showInternal) {\n return true\n }\n\n if (prop === REF_VALUE && typeof ref === 'string') {\n const id = getId(target)\n const path = convertToLocalRef(ref, id ?? args.currentContext, args.schemas)\n\n if (path === undefined) {\n return undefined\n }\n\n const segments = parseJsonPointer(`#/${path}`)\n\n if (segments.length === 0) {\n return false // Can not set top level $ref-value\n }\n\n // Get the parent node or create it if it does not exist\n const getParentNode = () => getValueByPath(args.root, segments.slice(0, -1)).value\n\n if (getParentNode() === undefined) {\n createPathFromSegments(args.root, segments.slice(0, -1))\n\n // In this case the ref is pointing to an invalid path, so we warn the user\n console.warn(\n `Trying to set $ref-value for invalid reference: ${ref}\\n\\nPlease fix your input file to fix this issue.`,\n )\n }\n\n // Set the value on the parent node\n getParentNode()[segments.at(-1)] = newValue\n return true\n }\n\n return Reflect.set(target, prop, newValue, receiver)\n },\n /**\n * Proxy \"deleteProperty\" trap for magic proxy.\n * Allows deleting properties from the proxied object.\n * This will update the underlying target object.\n */\n deleteProperty(target, prop) {\n return Reflect.deleteProperty(target, prop)\n },\n /**\n * Proxy \"has\" trap for magic proxy.\n * - Pretend that \"$ref-value\" exists if \"$ref\" exists on the target.\n * This allows expressions like `\"$ref-value\" in obj` to return true for objects with a $ref,\n * even though \"$ref-value\" is a virtual property provided by the proxy.\n * - Hide properties starting with __scalar_ by returning false.\n * - For all other properties, defer to the default Reflect.has behavior.\n */\n has(target, prop) {\n // Hide properties starting with __scalar_\n if (typeof prop === 'string' && prop.startsWith('__scalar_') && !options?.showInternal) {\n return false\n }\n\n // Pretend that \"$ref-value\" exists if \"$ref\" exists\n if (prop === REF_VALUE && REF_KEY in target) {\n return true\n }\n return Reflect.has(target, prop)\n },\n /**\n * Proxy \"ownKeys\" trap for magic proxy.\n * - Returns the list of own property keys for the proxied object.\n * - If the object has a \"$ref\" property, ensures that \"$ref-value\" is also included in the keys,\n * even though \"$ref-value\" is a virtual property provided by the proxy.\n * This allows Object.keys, Reflect.ownKeys, etc. to include \"$ref-value\" for objects with $ref.\n * - Filters out properties starting with __scalar_.\n */\n ownKeys(target) {\n const keys = Reflect.ownKeys(target)\n\n // Filter out properties starting with __scalar_\n const filteredKeys = keys.filter(\n (key) => typeof key !== 'string' || !(key.startsWith('__scalar_') && !options?.showInternal),\n )\n\n if (REF_KEY in target && !filteredKeys.includes(REF_VALUE)) {\n filteredKeys.push(REF_VALUE)\n }\n return filteredKeys\n },\n\n /**\n * Proxy \"getOwnPropertyDescriptor\" trap for magic proxy.\n * - For the virtual \"$ref-value\" property, returns a descriptor that makes it appear as a regular property.\n * - Hide properties starting with __scalar_ by returning undefined.\n * - For all other properties, delegates to the default Reflect.getOwnPropertyDescriptor behavior.\n * - This ensures that Object.getOwnPropertyDescriptor and similar methods work correctly with the virtual property.\n */\n getOwnPropertyDescriptor(target, prop) {\n // Hide properties starting with __scalar_\n if (typeof prop === 'string' && prop.startsWith('__scalar_') && !options?.showInternal) {\n return undefined\n }\n\n const ref = Reflect.get(target, REF_KEY)\n\n if (prop === REF_VALUE && typeof ref === 'string') {\n return {\n configurable: true,\n enumerable: true,\n value: undefined,\n writable: false,\n }\n }\n\n // Otherwise, delegate to the default behavior\n return Reflect.getOwnPropertyDescriptor(target, prop)\n },\n }\n\n const proxied = new Proxy<T>(target, handler)\n args.proxyCache.set(target, proxied)\n return proxied\n}\n\nconst isMagicProxyObject = (obj: unknown): boolean => {\n return typeof obj === 'object' && obj !== null && (obj as { [isMagicProxy]: boolean })[isMagicProxy] === true\n}\n\n/**\n * Gets the raw (non-proxied) version of an object created by createMagicProxy.\n * This is useful when you need to access the original object without the magic proxy wrapper.\n *\n * @param obj - The magic proxy object to get the raw version of\n * @returns The raw version of the object\n * @example\n * const proxy = createMagicProxy({ foo: { $ref: '#/bar' } })\n * const raw = getRaw(proxy) // { foo: { $ref: '#/bar' } }\n */\nexport function getRaw<T>(obj: T): T {\n if (typeof obj !== 'object' || obj === null) {\n return obj\n }\n\n if ((obj as T & { [isMagicProxy]: boolean | undefined })[isMagicProxy]) {\n return (obj as T & { [magicProxyTarget]: T })[magicProxyTarget]\n }\n\n return obj\n}\n"],
5
+ "mappings": "AAAA,SAAS,yBAAyB;AAClC,SAAS,OAAO,kBAAkB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,wBAAwB,wBAAwB;AAGzD,MAAM,eAAe,OAAO,cAAc;AAC1C,MAAM,mBAAmB,OAAO,kBAAkB;AAElD,MAAM,YAAY;AAClB,MAAM,UAAU;AAwCT,MAAM,mBAAmB,CAC9B,QACA,SACA,OAyBI;AAAA,EACF,MAAM;AAAA,EACN,YAAY,oBAAI,QAAQ;AAAA,EACxB,OAAO,oBAAI,IAAI;AAAA,EACf,SAAS,WAAW,MAAM;AAAA,EAC1B,gBAAgB;AAClB,MACM;AACN,MAAI,CAAC,SAAS,MAAM,KAAK,CAAC,MAAM,QAAQ,MAAM,GAAG;AAC/C,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,WAAW,IAAI,MAAM,GAAG;AAC/B,WAAO,KAAK,WAAW,IAAI,MAAM;AAAA,EACnC;AAEA,QAAM,UAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAS/B,IAAIA,SAAQ,MAAM,UAAU;AAC1B,UAAI,SAAS,cAAc;AAEzB,eAAO;AAAA,MACT;AAEA,UAAI,SAAS,kBAAkB;AAE7B,eAAOA;AAAA,MACT;AAIA,UAAI,OAAO,SAAS,YAAY,KAAK,WAAW,WAAW,KAAK,CAAC,SAAS,cAAc;AACtF,eAAO;AAAA,MACT;AAGA,YAAM,MAAM,QAAQ,IAAIA,SAAQ,SAAS,QAAQ;AAEjD,YAAM,KAAK,MAAMA,OAAM;AAGvB,UAAI,SAAS,aAAa,OAAO,QAAQ,UAAU;AAEjD,YAAI,KAAK,MAAM,IAAI,GAAG,GAAG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,WAAW,KAAK,CAAC,SAAS,cAAc;AACtF,eAAO;AAAA,MACT;AAEA,YAAM,MAAM,QAAQ,IAAIA,SAAQ,OAAO;AAEvC,UAAI,SAAS,aAAa,OAAO,QAAQ,UAAU;AACjD,eAAO;AAAA,UACL,cAAc;AAAA,UACd,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,UAAU;AAAA,QACZ;AAAA,MACF;AAGA,aAAO,QAAQ,yBAAyBA,SAAQ,IAAI;AAAA,IACtD;AAAA,EACF;AAEA,QAAM,UAAU,IAAI,MAAS,QAAQ,OAAO;AAC5C,OAAK,WAAW,IAAI,QAAQ,OAAO;AACnC,SAAO;AACT;AAEA,MAAM,qBAAqB,CAAC,QAA0B;AACpD,SAAO,OAAO,QAAQ,YAAY,QAAQ,QAAS,IAAoC,YAAY,MAAM;AAC3G;AAYO,SAAS,OAAU,KAAW;AACnC,MAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AAC3C,WAAO;AAAA,EACT;AAEA,MAAK,IAAoD,YAAY,GAAG;AACtE,WAAQ,IAAsC,gBAAgB;AAAA,EAChE;AAEA,SAAO;AACT;",
6
6
  "names": ["target"]
7
7
  }
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.8.2",
13
+ "version": "0.8.4",
14
14
  "engines": {
15
15
  "node": ">=20"
16
16
  },
@@ -41,30 +41,29 @@
41
41
  "types": "./dist/diff/index.d.ts",
42
42
  "default": "./dist/diff/index.js"
43
43
  },
44
- "./magic-proxy": {
45
- "import": "./dist/magic-proxy/index.js",
46
- "types": "./dist/magic-proxy/index.d.ts",
47
- "default": "./dist/magic-proxy/index.js"
48
- },
49
44
  "./helpers/escape-json-pointer": {
50
45
  "import": "./dist/helpers/escape-json-pointer.js",
51
- "types": "./dist/helpers/escape-json-pointer.ts",
46
+ "types": "./dist/helpers/escape-json-pointer.d.ts",
52
47
  "default": "./dist/helpers/escape-json-pointer.js"
53
48
  },
54
- "./helpers/generate-hash": {
55
- "import": "./dist/helpers/generate-hash.js",
56
- "types": "./dist/helpers/generate-hash.ts",
57
- "default": "./dist/helpers/generate-hash.js"
49
+ "./magic-proxy": {
50
+ "import": "./dist/magic-proxy/index.js",
51
+ "types": "./dist/magic-proxy/index.d.ts",
52
+ "default": "./dist/magic-proxy/index.js"
58
53
  }
59
54
  },
55
+ "files": [
56
+ "dist",
57
+ "CHANGELOG.md"
58
+ ],
60
59
  "dependencies": {
61
60
  "yaml": "2.8.0",
62
- "@scalar/helpers": "0.1.2"
61
+ "@scalar/helpers": "0.2.0"
63
62
  },
64
63
  "devDependencies": {
65
64
  "fastify": "^5.3.3",
66
65
  "vite": "7.1.11",
67
- "@scalar/build-tooling": "0.3.0"
66
+ "@scalar/build-tooling": "0.3.1"
68
67
  },
69
68
  "scripts": {
70
69
  "build": "scalar-build-esbuild",
@@ -1,10 +0,0 @@
1
-
2
- > @scalar/json-magic@0.8.2 build /home/runner/work/scalar/scalar/packages/json-magic
3
- > scalar-build-esbuild
4
-
5
- @scalar/json-magic: Build completed in 42.51ms
6
-
7
- > @scalar/json-magic@0.8.2 types:build /home/runner/work/scalar/scalar/packages/json-magic
8
- > scalar-types-build
9
-
10
- Types build completed in 2.81s
package/esbuild.ts DELETED
@@ -1,15 +0,0 @@
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
- 'src/helpers/escape-json-pointer.ts',
13
- 'src/helpers/generate-hash.ts',
14
- ],
15
- })