@scalar/json-magic 0.5.1 → 0.6.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.
@@ -1,10 +1,10 @@
1
1
 
2
- > @scalar/json-magic@0.5.1 build /home/runner/work/scalar/scalar/packages/json-magic
2
+ > @scalar/json-magic@0.6.0 build /home/runner/work/scalar/scalar/packages/json-magic
3
3
  > scalar-build-esbuild
4
4
 
5
- @scalar/json-magic: Build completed in 29.83ms
5
+ @scalar/json-magic: Build completed in 61.22ms
6
6
 
7
- > @scalar/json-magic@0.5.1 types:build /home/runner/work/scalar/scalar/packages/json-magic
7
+ > @scalar/json-magic@0.6.0 types:build /home/runner/work/scalar/scalar/packages/json-magic
8
8
  > scalar-types-build
9
9
 
10
- Types build completed in 1.46s
10
+ Types build completed in 1.77s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @scalar/json-magic
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4951456: feat: merge yaml aliases for in-mem representation
8
+
9
+ ## 0.5.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 6462733: fix: comment out flaky test for now
14
+
3
15
  ## 0.5.1
4
16
 
5
17
  ### Patch Changes
@@ -8,7 +8,7 @@ function parseYaml() {
8
8
  try {
9
9
  return {
10
10
  ok: true,
11
- data: YAML.parse(value)
11
+ data: YAML.parse(value, { merge: true, maxAliasCount: 1e4 })
12
12
  };
13
13
  } catch {
14
14
  return {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/bundle/plugins/parse-yaml/index.ts"],
4
- "sourcesContent": ["import YAML from 'yaml'\n\nimport type { LoaderPlugin, ResolveResult } from '@/bundle'\nimport { isYaml } from '@/helpers/is-yaml'\n\n/**\n * Creates a plugin that parses YAML strings into JavaScript objects.\n * @returns A plugin object with validate and exec functions\n * @example\n * ```ts\n * const yamlPlugin = parseYaml()\n * const result = yamlPlugin.exec('name: John\\nage: 30')\n * // result = { name: 'John', age: 30 }\n * ```\n */\nexport function parseYaml(): LoaderPlugin {\n return {\n type: 'loader',\n validate: isYaml,\n exec: async (value): Promise<ResolveResult> => {\n try {\n return {\n ok: true,\n data: YAML.parse(value),\n }\n } catch {\n return {\n ok: false,\n }\n }\n },\n }\n}\n"],
5
- "mappings": "AAAA,OAAO,UAAU;AAGjB,SAAS,cAAc;AAYhB,SAAS,YAA0B;AACxC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,MAAM,OAAO,UAAkC;AAC7C,UAAI;AACF,eAAO;AAAA,UACL,IAAI;AAAA,UACJ,MAAM,KAAK,MAAM,KAAK;AAAA,QACxB;AAAA,MACF,QAAQ;AACN,eAAO;AAAA,UACL,IAAI;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import YAML from 'yaml'\n\nimport type { LoaderPlugin, ResolveResult } from '@/bundle'\nimport { isYaml } from '@/helpers/is-yaml'\n\n/**\n * Creates a plugin that parses YAML strings into JavaScript objects.\n * @returns A plugin object with validate and exec functions\n * @example\n * ```ts\n * const yamlPlugin = parseYaml()\n * const result = yamlPlugin.exec('name: John\\nage: 30')\n * // result = { name: 'John', age: 30 }\n * ```\n */\nexport function parseYaml(): LoaderPlugin {\n return {\n type: 'loader',\n validate: isYaml,\n exec: async (value): Promise<ResolveResult> => {\n try {\n return {\n ok: true,\n data: YAML.parse(value, { merge: true, maxAliasCount: 10000 }),\n }\n } catch {\n return {\n ok: false,\n }\n }\n },\n }\n}\n"],
5
+ "mappings": "AAAA,OAAO,UAAU;AAGjB,SAAS,cAAc;AAYhB,SAAS,YAA0B;AACxC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,IACV,MAAM,OAAO,UAAkC;AAC7C,UAAI;AACF,eAAO;AAAA,UACL,IAAI;AAAA,UACJ,MAAM,KAAK,MAAM,OAAO,EAAE,OAAO,MAAM,eAAe,IAAM,CAAC;AAAA,QAC/D;AAAA,MACF,QAAQ;AACN,eAAO;AAAA,UACL,IAAI;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/helpers/normalize.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,GAAG,OA4BrC"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/helpers/normalize.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,GAAG,OA6BrC"}
@@ -16,7 +16,8 @@ function normalize(content) {
16
16
  return void 0;
17
17
  }
18
18
  return parse(content, {
19
- maxAliasCount: 1e4
19
+ maxAliasCount: 1e4,
20
+ merge: true
20
21
  });
21
22
  }
22
23
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/helpers/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;",
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 merge: true,\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,QACf,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;",
6
6
  "names": []
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.5.1",
13
+ "version": "0.6.0",
14
14
  "engines": {
15
15
  "node": ">=20"
16
16
  },
@@ -53,7 +53,6 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
- "vue": "^3.5.17",
57
56
  "yaml": "2.8.0",
58
57
  "@scalar/helpers": "0.0.11"
59
58
  },
@@ -1409,7 +1409,7 @@ describe('bundle', () => {
1409
1409
  content: {
1410
1410
  'application/json': {
1411
1411
  schema: {
1412
- $ref: 'https://example.com/root/schema#user-schema',
1412
+ $ref: 'https://example.com/root#user-schema',
1413
1413
  },
1414
1414
  },
1415
1415
  },
@@ -1421,13 +1421,20 @@ describe('bundle', () => {
1421
1421
  }
1422
1422
 
1423
1423
  await bundle(input, {
1424
- plugins: [fetchUrls(), readFiles()],
1424
+ plugins: [
1425
+ fetchUrls({
1426
+ fetch: async () => {
1427
+ return Response.json({ message: 'should not be called' })
1428
+ },
1429
+ }),
1430
+ readFiles(),
1431
+ ],
1425
1432
  treeShake: false,
1426
1433
  })
1427
1434
 
1428
1435
  // The $ref should remain unchanged because the schema is already defined locally with $anchor
1429
1436
  expect(input.paths['/users'].get.responses['200'].content['application/json'].schema.$ref).toBe(
1430
- 'https://example.com/root/schema#user-schema',
1437
+ 'https://example.com/root#user-schema',
1431
1438
  )
1432
1439
 
1433
1440
  // The external schema should not be bundled into x-ext
@@ -2056,7 +2063,7 @@ describe('bundle', () => {
2056
2063
 
2057
2064
  describe('bundle with a certain depth', () => {
2058
2065
  let server: FastifyInstance
2059
- const PORT = 7299
2066
+ const PORT = 7298
2060
2067
  const url = `http://localhost:${PORT}`
2061
2068
 
2062
2069
  beforeEach(() => {
@@ -21,7 +21,7 @@ export function parseYaml(): LoaderPlugin {
21
21
  try {
22
22
  return {
23
23
  ok: true,
24
- data: YAML.parse(value),
24
+ data: YAML.parse(value, { merge: true, maxAliasCount: 10000 }),
25
25
  }
26
26
  } catch {
27
27
  return {
@@ -26,6 +26,7 @@ export function normalize(content: any) {
26
26
 
27
27
  return parse(content, {
28
28
  maxAliasCount: 10000,
29
+ merge: true,
29
30
  })
30
31
  }
31
32
  }