@scalar/json-magic 0.8.1 → 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 (94) hide show
  1. package/CHANGELOG.md +22 -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/bundle/value-generator.d.ts +2 -2
  10. package/dist/bundle/value-generator.d.ts.map +1 -1
  11. package/dist/bundle/value-generator.js +3 -3
  12. package/dist/bundle/value-generator.js.map +2 -2
  13. package/dist/dereference/index.d.ts.map +1 -1
  14. package/dist/dereference/index.js.map +2 -2
  15. package/dist/diff/index.d.ts +1 -1
  16. package/dist/diff/index.d.ts.map +1 -1
  17. package/dist/diff/index.js +1 -1
  18. package/dist/diff/index.js.map +2 -2
  19. package/dist/helpers/escape-json-pointer.d.ts +1 -1
  20. package/dist/helpers/escape-json-pointer.js.map +1 -1
  21. package/dist/magic-proxy/index.d.ts.map +1 -1
  22. package/dist/magic-proxy/index.js.map +2 -2
  23. package/dist/magic-proxy/proxy.d.ts +0 -1
  24. package/dist/magic-proxy/proxy.d.ts.map +1 -1
  25. package/dist/magic-proxy/proxy.js +1 -2
  26. package/dist/magic-proxy/proxy.js.map +2 -2
  27. package/package.json +12 -14
  28. package/.turbo/turbo-build.log +0 -10
  29. package/dist/helpers/generate-hash.d.ts +0 -11
  30. package/dist/helpers/generate-hash.d.ts.map +0 -1
  31. package/dist/helpers/generate-hash.js +0 -16
  32. package/dist/helpers/generate-hash.js.map +0 -7
  33. package/esbuild.ts +0 -15
  34. package/src/bundle/bundle.test.ts +0 -2921
  35. package/src/bundle/bundle.ts +0 -916
  36. package/src/bundle/create-limiter.test.ts +0 -28
  37. package/src/bundle/create-limiter.ts +0 -52
  38. package/src/bundle/index.ts +0 -3
  39. package/src/bundle/plugins/browser.ts +0 -4
  40. package/src/bundle/plugins/fetch-urls/index.test.ts +0 -144
  41. package/src/bundle/plugins/fetch-urls/index.ts +0 -105
  42. package/src/bundle/plugins/node.ts +0 -5
  43. package/src/bundle/plugins/parse-json/index.test.ts +0 -24
  44. package/src/bundle/plugins/parse-json/index.ts +0 -32
  45. package/src/bundle/plugins/parse-yaml/index.test.ts +0 -26
  46. package/src/bundle/plugins/parse-yaml/index.ts +0 -34
  47. package/src/bundle/plugins/read-files/index.test.ts +0 -36
  48. package/src/bundle/plugins/read-files/index.ts +0 -58
  49. package/src/bundle/value-generator.test.ts +0 -165
  50. package/src/bundle/value-generator.ts +0 -143
  51. package/src/dereference/dereference.test.ts +0 -145
  52. package/src/dereference/dereference.ts +0 -84
  53. package/src/dereference/index.ts +0 -2
  54. package/src/diff/apply.test.ts +0 -262
  55. package/src/diff/apply.ts +0 -83
  56. package/src/diff/diff.test.ts +0 -328
  57. package/src/diff/diff.ts +0 -93
  58. package/src/diff/index.test.ts +0 -150
  59. package/src/diff/index.ts +0 -5
  60. package/src/diff/merge.test.ts +0 -1109
  61. package/src/diff/merge.ts +0 -136
  62. package/src/diff/trie.test.ts +0 -30
  63. package/src/diff/trie.ts +0 -113
  64. package/src/diff/utils.test.ts +0 -169
  65. package/src/diff/utils.ts +0 -111
  66. package/src/helpers/convert-to-local-ref.test.ts +0 -211
  67. package/src/helpers/convert-to-local-ref.ts +0 -43
  68. package/src/helpers/escape-json-pointer.test.ts +0 -13
  69. package/src/helpers/escape-json-pointer.ts +0 -8
  70. package/src/helpers/generate-hash.test.ts +0 -74
  71. package/src/helpers/generate-hash.ts +0 -29
  72. package/src/helpers/get-schemas.test.ts +0 -356
  73. package/src/helpers/get-schemas.ts +0 -80
  74. package/src/helpers/get-segments-from-path.test.ts +0 -17
  75. package/src/helpers/get-segments-from-path.ts +0 -17
  76. package/src/helpers/get-value-by-path.test.ts +0 -338
  77. package/src/helpers/get-value-by-path.ts +0 -44
  78. package/src/helpers/is-json-object.ts +0 -31
  79. package/src/helpers/is-object.test.ts +0 -27
  80. package/src/helpers/is-object.ts +0 -4
  81. package/src/helpers/is-yaml.ts +0 -18
  82. package/src/helpers/json-path-utils.test.ts +0 -57
  83. package/src/helpers/json-path-utils.ts +0 -50
  84. package/src/helpers/normalize.test.ts +0 -92
  85. package/src/helpers/normalize.ts +0 -35
  86. package/src/helpers/unescape-json-pointer.test.ts +0 -23
  87. package/src/helpers/unescape-json-pointer.ts +0 -9
  88. package/src/magic-proxy/index.ts +0 -2
  89. package/src/magic-proxy/proxy.test.ts +0 -1987
  90. package/src/magic-proxy/proxy.ts +0 -323
  91. package/src/types.ts +0 -1
  92. package/tsconfig.build.json +0 -12
  93. package/tsconfig.json +0 -16
  94. package/vite.config.ts +0 -8
package/src/diff/diff.ts DELETED
@@ -1,93 +0,0 @@
1
- /**
2
- * Represents the possible types of changes that can be made to a document.
3
- * - 'add': A new property is added
4
- * - 'update': An existing property's value is changed
5
- * - 'delete': A property is removed
6
- */
7
- type ChangeType = 'add' | 'update' | 'delete'
8
-
9
- /**
10
- * Represents a single difference between two documents.
11
- * @property path - Array of strings representing the path to the changed property
12
- * @property changes - The new value for the property (for add/update) or the old value (for delete)
13
- * @property type - The type of change that occurred
14
- */
15
- export type Difference<_T> = { path: string[]; changes: any; type: ChangeType }
16
-
17
- /**
18
- * Get the difference between two objects.
19
- *
20
- * This function performs a breadth-first comparison between two objects and returns
21
- * a list of operations needed to transform the first object into the second.
22
- *
23
- * @param doc1 - The source object to compare from
24
- * @param doc2 - The target object to compare to
25
- * @returns A list of operations (add/update/delete) with their paths and changes
26
- *
27
- * @example
28
- * // Compare two simple objects
29
- * const original = { name: 'John', age: 30 }
30
- * const updated = { name: 'John', age: 31, city: 'New York' }
31
- * const differences = diff(original, updated)
32
- * // Returns:
33
- * // [
34
- * // { path: ['age'], changes: 31, type: 'update' },
35
- * // { path: ['city'], changes: 'New York', type: 'add' }
36
- * // ]
37
- *
38
- * @example
39
- * // Compare nested objects
40
- * const original = {
41
- * user: { name: 'John', settings: { theme: 'light' } }
42
- * }
43
- * const updated = {
44
- * user: { name: 'John', settings: { theme: 'dark' } }
45
- * }
46
- * const differences = diff(original, updated)
47
- * // Returns:
48
- * // [
49
- * // { path: ['user', 'settings', 'theme'], changes: 'dark', type: 'update' }
50
- * // ]
51
- */
52
- export const diff = <T extends Record<string, unknown>>(doc1: Record<string, unknown>, doc2: T) => {
53
- const diff: Difference<T>[] = []
54
-
55
- const bfs = (el1: unknown, el2: unknown, prefix = []) => {
56
- // If the types are different, we know that the property has been added, deleted or updated
57
- if (typeof el1 !== typeof el2) {
58
- if (typeof el1 === 'undefined') {
59
- diff.push({ path: prefix, changes: el2, type: 'add' })
60
- return
61
- }
62
-
63
- if (typeof el2 === 'undefined') {
64
- diff.push({ path: prefix, changes: el1, type: 'delete' })
65
- return
66
- }
67
-
68
- diff.push({ path: prefix, changes: el2, type: 'update' })
69
- return
70
- }
71
-
72
- // We now can assume that el1 and el2 are of the same type
73
-
74
- // For nested objects, we need to recursively check the properties
75
- if (typeof el1 === 'object' && typeof el2 === 'object' && el1 !== null && el2 !== null) {
76
- const keys = new Set([...Object.keys(el1), ...Object.keys(el2)])
77
-
78
- for (const key of keys) {
79
- bfs(el1[key], el2[key], [...prefix, key])
80
- }
81
- return
82
- }
83
-
84
- // For primitives, we can just compare the values
85
- if (el1 !== el2) {
86
- diff.push({ path: prefix, changes: el2, type: 'update' })
87
- }
88
- }
89
-
90
- // Run breadth-first search
91
- bfs(doc1, doc2)
92
- return diff
93
- }
@@ -1,150 +0,0 @@
1
- import { apply } from '@/diff/apply'
2
- import { diff } from '@/diff/diff'
3
- import { describe, expect, test } from 'vitest'
4
-
5
- describe('if we get list of operations we need to perform A -> B, when we apply them on A it should give us B', () => {
6
- test.each([
7
- [
8
- { name: 'John', age: 25 },
9
- { name: 'Jeremy', age: 25 },
10
- ],
11
- [
12
- {
13
- name: 'John',
14
- age: 25,
15
- interest: {
16
- cars: { classics: ['Ferrari 250 GTO', 'Chevrolet Camaro'] },
17
- music: { pop: ['Bruno Mars', 'Justin Bieber'] },
18
- },
19
- },
20
- {
21
- name: 'John',
22
- age: 25,
23
- interest: {
24
- cars: { classics: ['Ferrari 250 GTO'] },
25
- music: { rock: ['Eagles', 'AC/DC'] },
26
- },
27
- },
28
- ],
29
- [{ version: '1.1.0', name: '@scalar/json-diff' }, {}],
30
- [
31
- {
32
- openapi: '3.0.0',
33
- info: {
34
- title: 'Simple API',
35
- description: 'A small OpenAPI specification example',
36
- version: '1.0.0',
37
- },
38
- paths: {
39
- '/users': {
40
- get: {
41
- summary: 'Get a list of users',
42
- operationId: 'getUsers',
43
- responses: {
44
- '200': {
45
- description: 'A list of users',
46
- content: {
47
- 'application/json': {
48
- schema: {
49
- type: 'array',
50
- items: {
51
- type: 'object',
52
- properties: {
53
- id: { type: 'integer' },
54
- name: { type: 'string' },
55
- },
56
- },
57
- },
58
- },
59
- },
60
- },
61
- },
62
- },
63
- },
64
- '/users/{id}': {
65
- get: {
66
- summary: 'Get a user by ID',
67
- operationId: 'getUserById',
68
- parameters: [
69
- {
70
- name: 'id',
71
- in: 'path',
72
- required: true,
73
- schema: { type: 'integer' },
74
- },
75
- ],
76
- responses: {
77
- '200': {
78
- description: 'User details',
79
- content: {
80
- 'application/json': {
81
- schema: {
82
- type: 'object',
83
- properties: {
84
- id: { type: 'integer' },
85
- name: { type: 'string' },
86
- },
87
- },
88
- },
89
- },
90
- },
91
- '404': {
92
- description: 'User not found',
93
- },
94
- },
95
- },
96
- },
97
- },
98
- },
99
- {
100
- openapi: '3.0.0',
101
- info: {
102
- title: 'Simple API',
103
- description: 'A big OpenAPI specification example',
104
- version: '1.0.0',
105
- },
106
- paths: {
107
- '/users': {
108
- get: {
109
- summary: 'Get a list of users',
110
- operationId: 'getUsers',
111
- responses: {
112
- '200': {
113
- description: 'A list of users',
114
- content: {
115
- 'application/json': {
116
- schema: {
117
- type: 'array',
118
- items: {
119
- type: 'object',
120
- properties: {
121
- id: { type: 'integer' },
122
- name: { type: 'string' },
123
- },
124
- },
125
- },
126
- },
127
- },
128
- },
129
- },
130
- },
131
- },
132
- },
133
- },
134
- ],
135
- [{}, {}],
136
- [
137
- {},
138
- {
139
- openapi: '3.0.0',
140
- info: {
141
- title: 'Simple API',
142
- description: 'A big OpenAPI specification example',
143
- version: '1.0.0',
144
- },
145
- },
146
- ],
147
- ])('apply(a, diff(a, b)) === b', (a, b) => {
148
- expect(apply(a, diff(a, b))).toEqual(b)
149
- })
150
- })
package/src/diff/index.ts DELETED
@@ -1,5 +0,0 @@
1
- import { diff, type Difference } from '@/diff/diff'
2
- import { apply } from '@/diff/apply'
3
- import { merge } from '@/diff/merge'
4
-
5
- export { diff, apply, merge, type Difference }