schemastore-to-typescript 0.2.12
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.json +529 -0
- package/CHANGELOG.md +185 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +36 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +173 -0
- package/dist/index.js.map +1 -0
- package/dist/normalize.d.ts +13 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +181 -0
- package/dist/normalize.js.map +1 -0
- package/license +10 -0
- package/package.json +80 -0
- package/readme.md +52 -0
- package/src/cli.ts +43 -0
- package/src/index.ts +256 -0
- package/src/normalize.ts +274 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Change Log - @langri-sha/schemastore-to-typescript
|
|
2
|
+
|
|
3
|
+
<!-- This log was last generated on Mon, 21 Sep 2026 10:53:40 GMT and should not be manually modified. -->
|
|
4
|
+
|
|
5
|
+
<!-- Start content -->
|
|
6
|
+
|
|
7
|
+
## 0.2.12
|
|
8
|
+
|
|
9
|
+
Mon, 21 Sep 2026 10:53:40 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Bump @langri-sha/vitest to v0.2.0
|
|
14
|
+
|
|
15
|
+
## 0.2.11
|
|
16
|
+
|
|
17
|
+
Thu, 10 Sep 2026 07:59:13 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- Compile draft 2020-12 schemas with $defs and a root $ref (filip.dupanovic@gmail.com)
|
|
22
|
+
- Update dependency got to v16
|
|
23
|
+
|
|
24
|
+
## 0.2.10
|
|
25
|
+
|
|
26
|
+
Mon, 31 Aug 2026 21:36:20 GMT
|
|
27
|
+
|
|
28
|
+
### Patches
|
|
29
|
+
|
|
30
|
+
- Update dependency json-schema-to-typescript to v16
|
|
31
|
+
|
|
32
|
+
## 0.2.9
|
|
33
|
+
|
|
34
|
+
Fri, 14 Aug 2026 21:44:42 GMT
|
|
35
|
+
|
|
36
|
+
### Patches
|
|
37
|
+
|
|
38
|
+
- Drop optional members named beside an index signature (filip.dupanovic@gmail.com)
|
|
39
|
+
- Flush the request cache to disk so a response cached during an in-flight write is not silently dropped (filip.dupanovic@gmail.com)
|
|
40
|
+
|
|
41
|
+
## 0.2.8
|
|
42
|
+
|
|
43
|
+
Tue, 04 Aug 2026 04:27:48 GMT
|
|
44
|
+
|
|
45
|
+
### Patches
|
|
46
|
+
|
|
47
|
+
- Upgrade keyv to v5 and got to 14.6.6 (filip.dupanovic@gmail.com)
|
|
48
|
+
- Update dependency got to v15 (email not defined)
|
|
49
|
+
- Bump @langri-sha/vitest to v0.1.9
|
|
50
|
+
|
|
51
|
+
## 0.2.7
|
|
52
|
+
|
|
53
|
+
Mon, 27 Jul 2026 22:24:07 GMT
|
|
54
|
+
|
|
55
|
+
### Patches
|
|
56
|
+
|
|
57
|
+
- Emit generated schema modules as .ts so tsc compiles and publishes them (filip.dupanovic@gmail.com)
|
|
58
|
+
- Bump @langri-sha/vitest to v0.1.8
|
|
59
|
+
|
|
60
|
+
## 0.2.6
|
|
61
|
+
|
|
62
|
+
Mon, 27 Jul 2026 11:38:48 GMT
|
|
63
|
+
|
|
64
|
+
### Patches
|
|
65
|
+
|
|
66
|
+
- Bump @langri-sha/tsconfig to v1.0.1
|
|
67
|
+
- Bump @langri-sha/vitest to v0.1.7
|
|
68
|
+
|
|
69
|
+
## 0.2.5
|
|
70
|
+
|
|
71
|
+
Mon, 27 Jul 2026 11:17:23 GMT
|
|
72
|
+
|
|
73
|
+
### Patches
|
|
74
|
+
|
|
75
|
+
- Bump @langri-sha/tsconfig to v1.0.0
|
|
76
|
+
- Bump @langri-sha/vitest to v0.1.6
|
|
77
|
+
|
|
78
|
+
## 0.2.4
|
|
79
|
+
|
|
80
|
+
Mon, 27 Jul 2026 00:06:02 GMT
|
|
81
|
+
|
|
82
|
+
### Patches
|
|
83
|
+
|
|
84
|
+
- Update the synthesis command in generated file headers (filip.dupanovic@gmail.com)
|
|
85
|
+
- Bump @langri-sha/tsconfig to v0.11.1
|
|
86
|
+
- Bump @langri-sha/vitest to v0.1.5
|
|
87
|
+
|
|
88
|
+
## 0.2.3
|
|
89
|
+
|
|
90
|
+
Sun, 26 Jul 2026 23:32:09 GMT
|
|
91
|
+
|
|
92
|
+
### Patches
|
|
93
|
+
|
|
94
|
+
- fix(deps): update dependency env-paths to v4 (email not defined)
|
|
95
|
+
- fix(deps): update dependency commander to v15 (email not defined)
|
|
96
|
+
- Bump @langri-sha/vitest to v0.1.4
|
|
97
|
+
|
|
98
|
+
## 0.2.2
|
|
99
|
+
|
|
100
|
+
Sat, 25 Jul 2026 15:41:25 GMT
|
|
101
|
+
|
|
102
|
+
### Patches
|
|
103
|
+
|
|
104
|
+
- fix(deps): update dependency keyv-file to v5.3.5 (email not defined)
|
|
105
|
+
- fix(deps): update dependency json-schema-to-typescript to v15.0.4 (email not defined)
|
|
106
|
+
- Bump @langri-sha/tsconfig to v0.11.0
|
|
107
|
+
- Bump @langri-sha/vitest to v0.1.3
|
|
108
|
+
|
|
109
|
+
## 0.2.1
|
|
110
|
+
|
|
111
|
+
Mon, 20 Jul 2026 10:17:52 GMT
|
|
112
|
+
|
|
113
|
+
### Patches
|
|
114
|
+
|
|
115
|
+
- fix(schemastore-to-typescript): remove unused @ts-expect-error directive (TS2578) (email not defined)
|
|
116
|
+
- Force CLI exit so a lingering handle cannot hang the runtime on nested re-runs (filip.dupanovic@gmail.com)
|
|
117
|
+
- fix: attach { cause } to re-thrown errors (ESLint 10 preserve-caught-error) (filip.dupanovic@gmail.com)
|
|
118
|
+
- fix(deps): update dependency es-main to v1.4.0 (email not defined)
|
|
119
|
+
- fix(deps): update dependency keyv-file to v5.3.3 (email not defined)
|
|
120
|
+
- chore: publish from langri-sha/projen, which now owns this package and its history (filip.dupanovic@gmail.com)
|
|
121
|
+
- Drive the CLI through `.then`/`.catch` instead of a top-level await so a stalled cache request can no longer hang `prepare` as an unsettled top-level await (exit code 13) (filip.dupanovic@gmail.com)
|
|
122
|
+
- fix(deps): update dependency debug to v4.4.3 (email not defined)
|
|
123
|
+
- Bump @langri-sha/tsconfig to v0.10.2
|
|
124
|
+
- Bump @langri-sha/vitest to v0.1.2
|
|
125
|
+
|
|
126
|
+
## 0.2.0
|
|
127
|
+
|
|
128
|
+
Sun, 17 May 2026 20:22:40 GMT
|
|
129
|
+
|
|
130
|
+
### Minor changes
|
|
131
|
+
|
|
132
|
+
- Refactor schema fetching to use catalog API and improve tests (bot@langri-sha.com)
|
|
133
|
+
- fix(schemastore-to-typescript): stabilize generated type names by overriding schema title with catalog name (filip.dupanovic@gmail.com)
|
|
134
|
+
|
|
135
|
+
### Patches
|
|
136
|
+
|
|
137
|
+
- fix(deps): update dependency got to v14.4.7 (email not defined)
|
|
138
|
+
|
|
139
|
+
## 0.1.4
|
|
140
|
+
|
|
141
|
+
Tue, 10 Sep 2024 10:39:17 GMT
|
|
142
|
+
|
|
143
|
+
### Patches
|
|
144
|
+
|
|
145
|
+
- fix(schemastore-to-typescript): Supress `keyv-file` type errors (filip.dupanovic@gmail.com)
|
|
146
|
+
- fix(deps): update dependency keyv-file to v5 (email not defined)
|
|
147
|
+
|
|
148
|
+
## 0.1.3
|
|
149
|
+
|
|
150
|
+
Sat, 27 Jul 2024 15:50:17 GMT
|
|
151
|
+
|
|
152
|
+
### Patches
|
|
153
|
+
|
|
154
|
+
- chore(deps): fix(deps): update dependency debug to v4.3.6 (email not defined)
|
|
155
|
+
|
|
156
|
+
## 0.1.2
|
|
157
|
+
|
|
158
|
+
Fri, 26 Jul 2024 21:00:29 GMT
|
|
159
|
+
|
|
160
|
+
### Patches
|
|
161
|
+
|
|
162
|
+
- chore(deps): chore(deps): update dependency projen to v0.84.6 (email not defined)
|
|
163
|
+
- chore(deps): fix(deps): update dependency got to v14.4.2 (email not defined)
|
|
164
|
+
- chore(deps): fix(deps): update dependency json-schema-to-typescript to v15 (email not defined)
|
|
165
|
+
|
|
166
|
+
## 0.1.1
|
|
167
|
+
|
|
168
|
+
Wed, 17 Jul 2024 10:48:16 GMT
|
|
169
|
+
|
|
170
|
+
### Patches
|
|
171
|
+
|
|
172
|
+
- fix(workspace): Use correct GitHub directory (filip.dupanovic@gmail.com)
|
|
173
|
+
|
|
174
|
+
## 0.1.0
|
|
175
|
+
|
|
176
|
+
Mon, 08 Jul 2024 21:43:05 GMT
|
|
177
|
+
|
|
178
|
+
### Minor changes
|
|
179
|
+
|
|
180
|
+
- feat(schema2ts): Compile store schema (filip.dupanovic@gmail.com)
|
|
181
|
+
|
|
182
|
+
### Patches
|
|
183
|
+
|
|
184
|
+
- fix(projen): Use workspace `@langri-sha/tsconfig` (filip.dupanovic@gmail.com)
|
|
185
|
+
- fix(projen): Use correct output directory (filip.dupanovic@gmail.com)
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQnC,eAAO,MAAM,OAAO,EAAE,OAiBlB,CAAA"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import createDebug from 'debug';
|
|
6
|
+
import esMain from 'es-main';
|
|
7
|
+
import { compile } from './index.js';
|
|
8
|
+
const debug = createDebug('schema-store-to-typescript');
|
|
9
|
+
export const program = new Command()
|
|
10
|
+
.name('schemastore-to-typescript')
|
|
11
|
+
.description('Compile a JSON schema store schema to TypeScript definitions')
|
|
12
|
+
.argument('<schema>', 'JSON schema store schema')
|
|
13
|
+
.argument('[output]', 'Path to output the TypeScript definition')
|
|
14
|
+
.option('-n, --no-cache', 'Skip caching requests')
|
|
15
|
+
.showHelpAfterError()
|
|
16
|
+
.action(async (schema, output, { cache }) => {
|
|
17
|
+
output ??= `${schema}.d.ts`;
|
|
18
|
+
const compiled = await compile(schema, cache);
|
|
19
|
+
await fs.writeFile(
|
|
20
|
+
// Using `process.cwd()` as escape hatch for `process.chdir()` not being
|
|
21
|
+
// available in workers. See: https://github.com/vitest-dev/vitest/issues/1436.
|
|
22
|
+
path.resolve(process.cwd(), output), compiled);
|
|
23
|
+
});
|
|
24
|
+
if (esMain(import.meta)) {
|
|
25
|
+
debug('Parsing arguments', process.argv);
|
|
26
|
+
program
|
|
27
|
+
.parseAsync(process.argv)
|
|
28
|
+
.then(() => {
|
|
29
|
+
process.exit(0);
|
|
30
|
+
})
|
|
31
|
+
.catch((error) => {
|
|
32
|
+
console.error(error);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,WAAW,MAAM,OAAO,CAAA;AAC/B,OAAO,MAAM,MAAM,SAAS,CAAA;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,KAAK,GAAG,WAAW,CAAC,4BAA4B,CAAC,CAAA;AAEvD,MAAM,CAAC,MAAM,OAAO,GAAY,IAAI,OAAO,EAAE;KAC1C,IAAI,CAAC,2BAA2B,CAAC;KACjC,WAAW,CAAC,8DAA8D,CAAC;KAC3E,Q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1,173 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import createDebug from 'debug';
|
|
3
|
+
import envPaths from 'env-paths';
|
|
4
|
+
import got, { HTTPError } from 'got';
|
|
5
|
+
import { compile as compileSource, } from 'json-schema-to-typescript';
|
|
6
|
+
import Keyv from 'keyv';
|
|
7
|
+
import { KeyvFile } from 'keyv-file';
|
|
8
|
+
import { normalizeSchema } from './normalize.js';
|
|
9
|
+
const debug = createDebug('schema-store-to-typescript');
|
|
10
|
+
const paths = envPaths('schemastore-to-typescript');
|
|
11
|
+
const store = new KeyvFile({
|
|
12
|
+
filename: path.join(paths.cache, 'requests.json'),
|
|
13
|
+
writeDelay: 0,
|
|
14
|
+
});
|
|
15
|
+
const keyv = new Keyv({ store });
|
|
16
|
+
// Both are declared private in keyv-file's typings, but flushing the cache
|
|
17
|
+
// needs them — see `flushCache`.
|
|
18
|
+
const flushable = store;
|
|
19
|
+
/**
|
|
20
|
+
* `keyv-file@5.3.5` coalesces a `set` onto an in-flight save: `saveToDisk`
|
|
21
|
+
* snapshots the store synchronously at entry, then awaits `mkdir` and
|
|
22
|
+
* `writeFile`, and only clears the in-flight promise afterwards. A `set`
|
|
23
|
+
* landing in that window gets that promise back — it resolves, but the value
|
|
24
|
+
* was never in the snapshot and no further save is scheduled, so it stays in
|
|
25
|
+
* memory for the rest of the process.
|
|
26
|
+
*
|
|
27
|
+
* `compile` writes the catalog and then the schema straight into that window,
|
|
28
|
+
* which loses the schema. `writeDelay` is no help: the window is the write
|
|
29
|
+
* itself, not the timer.
|
|
30
|
+
*
|
|
31
|
+
* So settle whatever is in flight first — its `writeFile` would otherwise race
|
|
32
|
+
* ours and could land last with the older snapshot — and then write the
|
|
33
|
+
* current one unconditionally.
|
|
34
|
+
*/
|
|
35
|
+
const flushCache = async () => {
|
|
36
|
+
await flushable.save();
|
|
37
|
+
await flushable.saveToDisk();
|
|
38
|
+
};
|
|
39
|
+
// Holds literal instance data rather than nested schemas, so it must not be
|
|
40
|
+
// walked as if it were part of the schema shape.
|
|
41
|
+
const nonSchemaKeys = new Set(['default', 'examples', 'const', 'enum']);
|
|
42
|
+
/**
|
|
43
|
+
* Some published schemas (e.g. Renovate's `registryAliases`) combine a
|
|
44
|
+
* `$ref` with a concrete `additionalProperties` schema on the same node — a
|
|
45
|
+
* JSON Schema anti-pattern that `json-schema-to-typescript` compiles into an
|
|
46
|
+
* interface whose own properties conflict with its index signature,
|
|
47
|
+
* producing uncompilable TypeScript (TS2411). `additionalProperties` is the
|
|
48
|
+
* more specific, deliberate declaration, so drop the `$ref` in favor of it.
|
|
49
|
+
*
|
|
50
|
+
* A node declaring `additionalProperties` at all compiles to an interface
|
|
51
|
+
* carrying a string index signature, and an optional member cannot sit beside
|
|
52
|
+
* one: its `undefined` is not assignable to the index type, which is TS2411
|
|
53
|
+
* again (Cargo's `[features]`, `[patch]` and `[lints]`). Where the index type
|
|
54
|
+
* is `unknown` the compiler does allow it, but the named members are then
|
|
55
|
+
* advisory — the same index signature accepts them either way, and following
|
|
56
|
+
* one is how Cargo's `package.metadata` reaches `quikrun`, a mutually
|
|
57
|
+
* recursive schema that overflows the compiler's stack and takes the whole
|
|
58
|
+
* manifest down with it.
|
|
59
|
+
*
|
|
60
|
+
* So optional members are dropped in favour of `additionalProperties`, which
|
|
61
|
+
* is the general contract they were there to narrow. Required ones stay: they
|
|
62
|
+
* are a promise the type has to keep.
|
|
63
|
+
*/
|
|
64
|
+
const sanitizeSchema = (node) => {
|
|
65
|
+
if (Array.isArray(node)) {
|
|
66
|
+
return node.map(sanitizeSchema);
|
|
67
|
+
}
|
|
68
|
+
if (node === null || typeof node !== 'object') {
|
|
69
|
+
return node;
|
|
70
|
+
}
|
|
71
|
+
const sanitized = {};
|
|
72
|
+
for (const [key, value] of Object.entries(node)) {
|
|
73
|
+
sanitized[key] = nonSchemaKeys.has(key) ? value : sanitizeSchema(value);
|
|
74
|
+
}
|
|
75
|
+
if (typeof sanitized.$ref === 'string' &&
|
|
76
|
+
typeof sanitized.additionalProperties === 'object' &&
|
|
77
|
+
sanitized.additionalProperties !== null) {
|
|
78
|
+
delete sanitized.$ref;
|
|
79
|
+
}
|
|
80
|
+
if (sanitized.additionalProperties !== undefined &&
|
|
81
|
+
sanitized.additionalProperties !== false &&
|
|
82
|
+
typeof sanitized.properties === 'object' &&
|
|
83
|
+
sanitized.properties !== null) {
|
|
84
|
+
const required = new Set(Array.isArray(sanitized.required) ? sanitized.required : []);
|
|
85
|
+
const properties = Object.fromEntries(Object.entries(sanitized.properties).filter(([property]) => required.has(property)));
|
|
86
|
+
if (Object.keys(properties).length > 0) {
|
|
87
|
+
sanitized.properties = properties;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
delete sanitized.properties;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return sanitized;
|
|
94
|
+
};
|
|
95
|
+
export const compile = async (name, cache = true) => {
|
|
96
|
+
const catalogUrl = 'https://www.schemastore.org/api/json/catalog.json';
|
|
97
|
+
let catalog;
|
|
98
|
+
let schema;
|
|
99
|
+
const fetchWithRetry = async (url, retryOnCacheError = true) => {
|
|
100
|
+
try {
|
|
101
|
+
return await got(url, {
|
|
102
|
+
cache: cache ? keyv : undefined,
|
|
103
|
+
headers: {
|
|
104
|
+
accept: 'application/json',
|
|
105
|
+
},
|
|
106
|
+
decompress: true,
|
|
107
|
+
}).json();
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
debug(`Error fetching ${url}:`, e);
|
|
111
|
+
if (retryOnCacheError &&
|
|
112
|
+
cache &&
|
|
113
|
+
e instanceof Error &&
|
|
114
|
+
(e.message.includes('Unexpected token') ||
|
|
115
|
+
e.message.includes('is not valid JSON'))) {
|
|
116
|
+
debug(`Clearing cache for ${url} and retrying...`);
|
|
117
|
+
try {
|
|
118
|
+
await keyv.delete(`GET:${url}`);
|
|
119
|
+
}
|
|
120
|
+
catch (clearError) {
|
|
121
|
+
debug(`Failed to clear cache:`, clearError);
|
|
122
|
+
}
|
|
123
|
+
return fetchWithRetry(url, false);
|
|
124
|
+
}
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
try {
|
|
129
|
+
// First, fetch the catalog
|
|
130
|
+
catalog = await fetchWithRetry(catalogUrl);
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
debug(e);
|
|
134
|
+
if (e instanceof HTTPError) {
|
|
135
|
+
throw new Error(`Couldn't retrieve catalog from ${catalogUrl}. [${e.code}]`, { cause: e });
|
|
136
|
+
}
|
|
137
|
+
throw e;
|
|
138
|
+
}
|
|
139
|
+
const schemaMap = new Map();
|
|
140
|
+
for (const schema of catalog.schemas) {
|
|
141
|
+
schemaMap.set(schema.name.toLowerCase(), schema);
|
|
142
|
+
}
|
|
143
|
+
const catalogSchema = schemaMap.get(name.toLowerCase());
|
|
144
|
+
if (!catalogSchema) {
|
|
145
|
+
throw new Error(`Couldn't find schema ${name} in the catalog. Are you sure it exists?`);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
// Fetch the actual schema from the found URL
|
|
149
|
+
debug(`Fetching schema from: ${catalogSchema.url}`);
|
|
150
|
+
schema = await fetchWithRetry(catalogSchema.url);
|
|
151
|
+
if (typeof schema === 'object' && schema !== null) {
|
|
152
|
+
schema.title = catalogSchema.name;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
debug(e);
|
|
157
|
+
if (e instanceof HTTPError) {
|
|
158
|
+
if (e.response.statusCode === 404) {
|
|
159
|
+
throw new Error(`Couldn't find schema ${name} at ${catalogSchema.url}. Are you sure it exists?`, { cause: e });
|
|
160
|
+
}
|
|
161
|
+
throw new Error(`Couldn't retrieve schema from ${catalogSchema.url}. [${e.code}] Status: ${e.response.statusCode}`, { cause: e });
|
|
162
|
+
}
|
|
163
|
+
if (e instanceof Error && e.message.includes('is not valid JSON')) {
|
|
164
|
+
throw new Error(`Failed to parse JSON from ${catalogSchema.url}. The server might be returning invalid or compressed content. Error: ${e.message}`, { cause: e });
|
|
165
|
+
}
|
|
166
|
+
throw e;
|
|
167
|
+
}
|
|
168
|
+
if (cache) {
|
|
169
|
+
await flushCache();
|
|
170
|
+
}
|
|
171
|
+
return compileSource(sanitizeSchema(normalizeSchema(schema)), name);
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,WAAW,MAAM,OAAO,CAAA;AAC/B,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AACpC,OAAO,EAEL,OAAO,IAAI,aAAa,GACzB,MAAM,2BAA2B,CAAA;AAClC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,MAAM,KAAK,GAAG,WAAW,CAAC,4BAA4B,CAAC,CAAA;AACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,2BAA2B,CAAC,CAAA;AAEnD,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC;IACzB,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,eAAe,CAAC;IACjD,UAAU,EAAE,CAAC;CACd,CAAC,CAAA;AAEF,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAEhC,2EAA2E;AAC3E,iCAAiC;AACjC,MAAM,SAAS,GAAG,KAGjB,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;IAC5B,MAAM,SAAS,CAAC,I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O,aAAa,CAAC,cAAc,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;AACrE,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JSONSchema } from 'json-schema-to-typescript';
|
|
2
|
+
/**
|
|
3
|
+
* `json-schema-to-typescript` resolves references against draft-07's
|
|
4
|
+
* vocabulary: it only knows `definitions`, and it expects the root to be a
|
|
5
|
+
* schema rather than a reference to one. Draft 2020-12 documents that spell
|
|
6
|
+
* their definitions `$defs` or that point the root at one therefore fail to
|
|
7
|
+
* resolve, with `Refs should have been resolved by the resolver!`.
|
|
8
|
+
*
|
|
9
|
+
* Restate them in the shape it does resolve, without disturbing documents that
|
|
10
|
+
* are already in it.
|
|
11
|
+
*/
|
|
12
|
+
export declare const normalizeSchema: (schema: JSONSchema) => JSONSchema;
|
|
13
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AA4P3D;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,UAAU,KAAG,UAWpD,CAAA"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2
|
+
// Hold literal instance data rather than nested schemas, so they must not be
|
|
3
|
+
// walked as if they were part of the schema shape.
|
|
4
|
+
const literalKeys = new Set(['const', 'default', 'enum', 'examples']);
|
|
5
|
+
// Keyed by name rather than by keyword: a member of one of these called
|
|
6
|
+
// `$defs` is a subschema that happens to be named `$defs`, not a definition
|
|
7
|
+
// block.
|
|
8
|
+
const namedSchemaKeys = new Set([
|
|
9
|
+
'$defs',
|
|
10
|
+
'definitions',
|
|
11
|
+
'dependencies',
|
|
12
|
+
'dependentSchemas',
|
|
13
|
+
'patternProperties',
|
|
14
|
+
'properties',
|
|
15
|
+
]);
|
|
16
|
+
const escapeToken = (name) => name.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
17
|
+
const unescapeToken = (token) => token.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
18
|
+
const join = (path, token) => path === '' ? token : `${path}/${token}`;
|
|
19
|
+
const resolvePointer = (document, ref) => {
|
|
20
|
+
if (ref === '#') {
|
|
21
|
+
return document;
|
|
22
|
+
}
|
|
23
|
+
if (!ref.startsWith('#/')) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
let node = document;
|
|
27
|
+
for (const token of ref.slice(2).split('/')) {
|
|
28
|
+
if (Array.isArray(node)) {
|
|
29
|
+
node = node[Number(token)];
|
|
30
|
+
}
|
|
31
|
+
else if (isObject(node)) {
|
|
32
|
+
node = node[unescapeToken(token)];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return node;
|
|
39
|
+
};
|
|
40
|
+
const collectRenames = (node, path, inSchema, renames) => {
|
|
41
|
+
if (Array.isArray(node)) {
|
|
42
|
+
for (const [index, item] of node.entries()) {
|
|
43
|
+
collectRenames(item, join(path, String(index)), inSchema, renames);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!isObject(node)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!inSchema) {
|
|
51
|
+
for (const [name, value] of Object.entries(node)) {
|
|
52
|
+
collectRenames(value, join(path, escapeToken(name)), true, renames);
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (isObject(node.$defs)) {
|
|
57
|
+
const taken = new Set(isObject(node.definitions) ? Object.keys(node.definitions) : []);
|
|
58
|
+
const mapping = new Map();
|
|
59
|
+
for (const name of Object.keys(node.$defs)) {
|
|
60
|
+
let target = name;
|
|
61
|
+
for (let suffix = 2; taken.has(target); suffix++) {
|
|
62
|
+
target = `${name}_${suffix}`;
|
|
63
|
+
}
|
|
64
|
+
taken.add(target);
|
|
65
|
+
mapping.set(name, target);
|
|
66
|
+
}
|
|
67
|
+
renames.set(path, mapping);
|
|
68
|
+
}
|
|
69
|
+
for (const [key, value] of Object.entries(node)) {
|
|
70
|
+
if (literalKeys.has(key)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
collectRenames(value, join(path, escapeToken(key)), !namedSchemaKeys.has(key), renames);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const rewriteRef = (ref, renames) => {
|
|
77
|
+
if (!ref.startsWith('#/')) {
|
|
78
|
+
return ref;
|
|
79
|
+
}
|
|
80
|
+
const tokens = ref.slice(2).split('/');
|
|
81
|
+
const rewritten = [];
|
|
82
|
+
let path = '';
|
|
83
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
84
|
+
const token = tokens[index];
|
|
85
|
+
const name = tokens[index + 1];
|
|
86
|
+
const mapping = token === '$defs' ? renames.get(path) : undefined;
|
|
87
|
+
const target = mapping && name !== undefined
|
|
88
|
+
? mapping.get(unescapeToken(name))
|
|
89
|
+
: undefined;
|
|
90
|
+
if (target === undefined) {
|
|
91
|
+
rewritten.push(token);
|
|
92
|
+
path = join(path, token);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
rewritten.push('definitions', escapeToken(target));
|
|
96
|
+
path = join(join(path, token), name);
|
|
97
|
+
index++;
|
|
98
|
+
}
|
|
99
|
+
return `#/${rewritten.join('/')}`;
|
|
100
|
+
};
|
|
101
|
+
const applyRenames = (node, path, inSchema, renames) => {
|
|
102
|
+
if (Array.isArray(node)) {
|
|
103
|
+
return node.map((item, index) => applyRenames(item, join(path, String(index)), inSchema, renames));
|
|
104
|
+
}
|
|
105
|
+
if (!isObject(node)) {
|
|
106
|
+
return node;
|
|
107
|
+
}
|
|
108
|
+
if (!inSchema) {
|
|
109
|
+
return Object.fromEntries(Object.entries(node).map(([name, value]) => [
|
|
110
|
+
name,
|
|
111
|
+
applyRenames(value, join(path, escapeToken(name)), true, renames),
|
|
112
|
+
]));
|
|
113
|
+
}
|
|
114
|
+
const mapping = renames.get(path);
|
|
115
|
+
const renamed = {};
|
|
116
|
+
for (const [key, value] of Object.entries(node)) {
|
|
117
|
+
if (literalKeys.has(key)) {
|
|
118
|
+
renamed[key] = value;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (key === '$ref' && typeof value === 'string') {
|
|
122
|
+
renamed[key] = rewriteRef(value, renames);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (key === '$defs' && mapping) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
renamed[key] = applyRenames(value, join(path, escapeToken(key)), !namedSchemaKeys.has(key), renames);
|
|
129
|
+
}
|
|
130
|
+
if (mapping) {
|
|
131
|
+
const defs = node.$defs;
|
|
132
|
+
const definitions = isObject(renamed.definitions)
|
|
133
|
+
? renamed.definitions
|
|
134
|
+
: {};
|
|
135
|
+
for (const [name, target] of mapping) {
|
|
136
|
+
definitions[target] = applyRenames(defs[name], join(join(path, '$defs'), escapeToken(name)), true, renames);
|
|
137
|
+
}
|
|
138
|
+
renamed.definitions = definitions;
|
|
139
|
+
}
|
|
140
|
+
return renamed;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* A document whose root is `{$ref}` describes the referenced definition, with
|
|
144
|
+
* any sibling keyword layered on top of it — `title` above all, which is what
|
|
145
|
+
* names the exported type. The definition stays where it is, so pointers into
|
|
146
|
+
* it keep resolving; only a copy is hoisted.
|
|
147
|
+
*/
|
|
148
|
+
const inlineRootRef = (document) => {
|
|
149
|
+
let root = document;
|
|
150
|
+
const seen = new Set();
|
|
151
|
+
while (typeof root.$ref === 'string' && !seen.has(root.$ref)) {
|
|
152
|
+
const target = resolvePointer(document, root.$ref);
|
|
153
|
+
if (!isObject(target) || target === root) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
seen.add(root.$ref);
|
|
157
|
+
const siblings = { ...root };
|
|
158
|
+
delete siblings.$ref;
|
|
159
|
+
root = { ...target, ...siblings };
|
|
160
|
+
}
|
|
161
|
+
return root;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* `json-schema-to-typescript` resolves references against draft-07's
|
|
165
|
+
* vocabulary: it only knows `definitions`, and it expects the root to be a
|
|
166
|
+
* schema rather than a reference to one. Draft 2020-12 documents that spell
|
|
167
|
+
* their definitions `$defs` or that point the root at one therefore fail to
|
|
168
|
+
* resolve, with `Refs should have been resolved by the resolver!`.
|
|
169
|
+
*
|
|
170
|
+
* Restate them in the shape it does resolve, without disturbing documents that
|
|
171
|
+
* are already in it.
|
|
172
|
+
*/
|
|
173
|
+
export const normalizeSchema = (schema) => {
|
|
174
|
+
if (!isObject(schema)) {
|
|
175
|
+
return schema;
|
|
176
|
+
}
|
|
177
|
+
const renames = new Map();
|
|
178
|
+
collectRenames(schema, '', true, renames);
|
|
179
|
+
return inlineRootRef(applyRenames(schema, '', true, renames));
|
|
180
|
+
};
|
|
181
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAQA,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAiB,EAAE,CACjD,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAEtE,6EAA6E;AAC7E,mDAAmD;AACnD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;AAErE,wEAAwE;AACxE,4EAA4E;AAC5E,SAAS;AACT,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B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,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAkB,EAAc,EAAE;IAChE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,OAAO,MAAM,CAAA;IACf,CAAC;IAED,MAAM,OAAO,GAAY,IAAI,GAAG,EAAE,CAAA;IAClC,cAAc,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAEzC,OAAO,aAAa,CAClB,YAAY,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAS,CAClC,CAAA;AACjB,CAAC,CAAA"}
|
package/license
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2024 Filip Dupanović <filip.dupanovic@gmail.com> (https://langri-sha.com)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|