@scalar/json-magic 0.8.2 → 0.8.3

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 +13 -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
@@ -1,92 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
-
3
- import { normalize } from '@/helpers/normalize'
4
-
5
- describe('normalize', () => {
6
- it('returns undefined if the document is null', () => {
7
- expect(normalize(null)).toEqual(undefined)
8
- })
9
-
10
- it('should parse JSON string specifications', () => {
11
- const jsonString = '{"foo": "bar"}'
12
- expect(normalize(jsonString)).toEqual({ foo: 'bar' })
13
- })
14
-
15
- it('should parse YAML string specifications', () => {
16
- const yamlString = 'foo: bar\nbar: foo'
17
- expect(normalize(yamlString)).toEqual({ foo: 'bar', bar: 'foo' })
18
- })
19
-
20
- it('should handle invalid YAML with custom maxAliasCount', () => {
21
- const yamlString = `
22
- aliases: &ref
23
- - item1
24
- - item2
25
- items: *ref
26
- `
27
- expect(() => normalize(yamlString)).not.toThrow()
28
- })
29
-
30
- it('should return the same object if specification is already an object', () => {
31
- const obj = { foo: 'bar' }
32
- expect(normalize(obj)).toBe(obj)
33
- })
34
-
35
- it("doesn't freak out on invalid JSON strings ", () => {
36
- // Missing quotes around property name
37
- const malformedJson = '{ foo: "bar" }'
38
- expect(normalize(malformedJson)).toEqual(undefined)
39
- })
40
-
41
- it('should handle empty string input', () => {
42
- expect(normalize('')).toEqual(undefined)
43
- })
44
-
45
- it('should handle whitespace-only string input', () => {
46
- expect(normalize(' ')).toEqual(undefined)
47
- })
48
-
49
- it('should handle complex nested structures', () => {
50
- const complex = {
51
- nested: {
52
- array: [1, 2, 3],
53
- object: {
54
- foo: 'bar',
55
- },
56
- },
57
- }
58
- expect(normalize(complex)).toEqual(complex)
59
- })
60
-
61
- it('should handle invalid JSON and YAML strings gracefully', () => {
62
- const invalidString = 'not a valid json or yaml'
63
- expect(() => normalize(invalidString)).not.toThrow()
64
- })
65
-
66
- it('should handle non-string, non-object inputs', () => {
67
- expect(normalize(42)).toEqual(42)
68
- expect(normalize(true)).toEqual(true)
69
- expect(normalize([1, 2, 3])).toEqual([1, 2, 3])
70
- })
71
-
72
- it('should handle deeply nested structures', () => {
73
- const nested = { a: { b: { c: { d: { e: 'deep' } } } } }
74
- expect(normalize(nested)).toEqual(nested)
75
- })
76
-
77
- it('should handle large input strings', () => {
78
- const largeJson = JSON.stringify({ foo: 'bar'.repeat(10000) })
79
- expect(normalize(largeJson)).toEqual({ foo: 'bar'.repeat(10000) })
80
- })
81
-
82
- it('should handle circular references', () => {
83
- const circularObj: any = {}
84
- circularObj.self = circularObj
85
- expect(() => normalize(circularObj)).not.toThrow()
86
- })
87
-
88
- it('should handle special characters in strings', () => {
89
- const specialCharJson = '{"foo": "bar\\n"}'
90
- expect(normalize(specialCharJson)).toEqual({ foo: 'bar\n' })
91
- })
92
- })
@@ -1,35 +0,0 @@
1
- import { parse } from 'yaml'
2
-
3
- /**
4
- * Normalize a string (YAML, JSON, object) to a JavaScript datatype.
5
- */
6
- export function normalize(content: any) {
7
- if (content === null) {
8
- return undefined
9
- }
10
-
11
- if (typeof content === 'string') {
12
- if (content.trim() === '') {
13
- return undefined
14
- }
15
-
16
- try {
17
- return JSON.parse(content)
18
- } catch (_error) {
19
- // Does it look like YAML?
20
- const hasColon = /^[^:]+:/.test(content)
21
- const isJson = content.slice(0, 50).trimStart().startsWith('{')
22
-
23
- if (!hasColon || isJson) {
24
- return undefined
25
- }
26
-
27
- return parse(content, {
28
- maxAliasCount: 10000,
29
- merge: true,
30
- })
31
- }
32
- }
33
-
34
- return content
35
- }
@@ -1,23 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
-
3
- import { unescapeJsonPointer } from './unescape-json-pointer'
4
-
5
- describe('unescapeJsonPointer', () => {
6
- it('unescapes a slash', () => {
7
- expect(unescapeJsonPointer('/foo~1bar~1baz')).toBe('/foo/bar/baz')
8
- })
9
-
10
- it('unescapes multiple slashes', () => {
11
- expect(unescapeJsonPointer('#/paths/~1upload/post/responses/401/content/application~1problem+json/schema')).toBe(
12
- '#/paths//upload/post/responses/401/content/application/problem+json/schema',
13
- )
14
- })
15
-
16
- it('unescapes a tilde', () => {
17
- expect(unescapeJsonPointer('/foo~0bar~0baz')).toBe('/foo~bar~baz')
18
- })
19
-
20
- it('unescapes a space', () => {
21
- expect(unescapeJsonPointer('foo%20bar')).toBe('foo bar')
22
- })
23
- })
@@ -1,9 +0,0 @@
1
- /**
2
- * Unescape JSON pointer
3
- *
4
- * Examples:
5
- * /foo~1bar~0baz -> /foo/bar~baz
6
- */
7
- export function unescapeJsonPointer(uri: string) {
8
- return decodeURI(uri.replace(/~1/g, '/').replace(/~0/g, '~'))
9
- }
@@ -1,2 +0,0 @@
1
- // biome-ignore lint/performance/noBarrelFile: <explanation>
2
- export { createMagicProxy, getRaw } from './proxy'