@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.
- package/CHANGELOG.md +13 -0
- package/dist/bundle/index.d.ts +1 -0
- package/dist/bundle/index.d.ts.map +1 -1
- package/dist/bundle/index.js.map +1 -1
- package/dist/bundle/plugins/browser.js.map +1 -1
- package/dist/bundle/plugins/node.d.ts +1 -1
- package/dist/bundle/plugins/node.js +1 -1
- package/dist/bundle/plugins/node.js.map +1 -1
- package/dist/dereference/index.d.ts.map +1 -1
- package/dist/dereference/index.js.map +2 -2
- package/dist/diff/index.d.ts +1 -1
- package/dist/diff/index.d.ts.map +1 -1
- package/dist/diff/index.js +1 -1
- package/dist/diff/index.js.map +2 -2
- package/dist/helpers/escape-json-pointer.d.ts +1 -1
- package/dist/helpers/escape-json-pointer.js.map +1 -1
- package/dist/magic-proxy/index.d.ts.map +1 -1
- package/dist/magic-proxy/index.js.map +2 -2
- package/dist/magic-proxy/proxy.d.ts +0 -1
- package/dist/magic-proxy/proxy.d.ts.map +1 -1
- package/dist/magic-proxy/proxy.js +1 -2
- package/dist/magic-proxy/proxy.js.map +2 -2
- package/package.json +12 -13
- package/.turbo/turbo-build.log +0 -10
- package/esbuild.ts +0 -15
- package/src/bundle/bundle.test.ts +0 -2917
- package/src/bundle/bundle.ts +0 -916
- package/src/bundle/create-limiter.test.ts +0 -28
- package/src/bundle/create-limiter.ts +0 -52
- package/src/bundle/index.ts +0 -3
- package/src/bundle/plugins/browser.ts +0 -4
- package/src/bundle/plugins/fetch-urls/index.test.ts +0 -141
- package/src/bundle/plugins/fetch-urls/index.ts +0 -105
- package/src/bundle/plugins/node.ts +0 -5
- package/src/bundle/plugins/parse-json/index.test.ts +0 -24
- package/src/bundle/plugins/parse-json/index.ts +0 -32
- package/src/bundle/plugins/parse-yaml/index.test.ts +0 -26
- package/src/bundle/plugins/parse-yaml/index.ts +0 -34
- package/src/bundle/plugins/read-files/index.test.ts +0 -36
- package/src/bundle/plugins/read-files/index.ts +0 -58
- package/src/bundle/value-generator.test.ts +0 -165
- package/src/bundle/value-generator.ts +0 -143
- package/src/dereference/dereference.test.ts +0 -142
- package/src/dereference/dereference.ts +0 -84
- package/src/dereference/index.ts +0 -2
- package/src/diff/apply.test.ts +0 -262
- package/src/diff/apply.ts +0 -83
- package/src/diff/diff.test.ts +0 -328
- package/src/diff/diff.ts +0 -93
- package/src/diff/index.test.ts +0 -150
- package/src/diff/index.ts +0 -5
- package/src/diff/merge.test.ts +0 -1109
- package/src/diff/merge.ts +0 -136
- package/src/diff/trie.test.ts +0 -30
- package/src/diff/trie.ts +0 -113
- package/src/diff/utils.test.ts +0 -169
- package/src/diff/utils.ts +0 -111
- package/src/helpers/convert-to-local-ref.test.ts +0 -211
- package/src/helpers/convert-to-local-ref.ts +0 -43
- package/src/helpers/escape-json-pointer.test.ts +0 -13
- package/src/helpers/escape-json-pointer.ts +0 -8
- package/src/helpers/get-schemas.test.ts +0 -356
- package/src/helpers/get-schemas.ts +0 -80
- package/src/helpers/get-segments-from-path.test.ts +0 -17
- package/src/helpers/get-segments-from-path.ts +0 -17
- package/src/helpers/get-value-by-path.test.ts +0 -338
- package/src/helpers/get-value-by-path.ts +0 -44
- package/src/helpers/is-json-object.ts +0 -31
- package/src/helpers/is-object.test.ts +0 -27
- package/src/helpers/is-object.ts +0 -4
- package/src/helpers/is-yaml.ts +0 -18
- package/src/helpers/json-path-utils.test.ts +0 -57
- package/src/helpers/json-path-utils.ts +0 -50
- package/src/helpers/normalize.test.ts +0 -92
- package/src/helpers/normalize.ts +0 -35
- package/src/helpers/unescape-json-pointer.test.ts +0 -23
- package/src/helpers/unescape-json-pointer.ts +0 -9
- package/src/magic-proxy/index.ts +0 -2
- package/src/magic-proxy/proxy.test.ts +0 -1987
- package/src/magic-proxy/proxy.ts +0 -323
- package/src/types.ts +0 -1
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -16
- 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
|
-
})
|
package/src/helpers/normalize.ts
DELETED
|
@@ -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
|
-
})
|
package/src/magic-proxy/index.ts
DELETED