openapi-import 0.0.4 → 0.0.6
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/README.md +3 -0
- package/dist/server.js +82 -29
- package/dist/server.js.map +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ Each schema and operation in the spec becomes a type. Schema types keep the name
|
|
|
70
70
|
- Hover, go to definition and find references jump from each name in the table to its key in the spec.
|
|
71
71
|
- Renaming a schema type renames its key in the spec, and the `$ref`s on a property, an array item or a schema alias that point at it. Update other `$ref`s, such as inside `allOf` or a response, yourself.
|
|
72
72
|
- Spec errors, such as an unresolved `$ref`, show on the key they point at.
|
|
73
|
+
- A `$ref` to another file, such as `./schemas/pet.yaml`, is read from disk. Editing that file updates the types and errors, the same as editing the spec.
|
|
73
74
|
- `tsc --runExternalCode` reports the same errors in CI.
|
|
74
75
|
|
|
75
76
|
## Add Zod schemas and more
|
|
@@ -128,6 +129,8 @@ Leave `input` out of the config to import specs only. With an `input`, the bundl
|
|
|
128
129
|
- Code a plugin writes to a separate file, such as a bundled client runtime, is not included. Point imports like a client's `importPath` at a package.
|
|
129
130
|
- Properties of operation types don't link to the spec, and renaming one doesn't rename its key.
|
|
130
131
|
- Files that `kubb.config.ts` imports are not watched. Restart the TypeScript server after you change them.
|
|
132
|
+
- A `$ref` to a URL is fetched on each rebuild but not watched. Edit the spec or restart the TypeScript server to pick up a change to it.
|
|
133
|
+
- `$ref` files are watched from the start for specs under the `tsconfig.json` folder. For a spec outside it, they are watched from the next time the project reloads, such as after a change to `kubb.config.ts`.
|
|
131
134
|
- A changed spec rebuilds all of its types: about 0.4 s for a 10 KB spec and 2.6 s for a 1.4 MB spec.
|
|
132
135
|
|
|
133
136
|
## Sponsors
|
package/dist/server.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
import { dirname, resolve } from "node:path";
|
|
2
|
-
import { configFileCandidates, findConfigFile, generateModule, loadConfigFile, selectConfig } from "unplugin-kubb";
|
|
3
1
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
2
|
+
import { globSync, readFileSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, resolve } from "node:path";
|
|
5
4
|
import ts from "@typescript/typescript6";
|
|
5
|
+
import { configFileCandidates, findConfigFile, generateModule, loadConfigFile, selectConfig } from "unplugin-kubb";
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
6
7
|
import { Hookable } from "kubb/kit";
|
|
7
8
|
import { pluginTs, pluginTsName, resolverTs } from "@kubb/plugin-ts";
|
|
8
9
|
import * as yaml from "yaml";
|
|
9
|
-
import { parseDocument } from "yaml";
|
|
10
|
-
|
|
10
|
+
import { parse, parseDocument } from "yaml";
|
|
11
|
+
// src/cache.ts
|
|
12
|
+
/**
|
|
13
|
+
* The text of `file`, or `null` when it cannot be read.
|
|
14
|
+
*/
|
|
15
|
+
const readOrNull = (file) => {
|
|
16
|
+
try {
|
|
17
|
+
return readFileSync(file, "utf8");
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
11
22
|
/**
|
|
12
23
|
* Wraps a transform so a repeated request for the same file, content and config returns the
|
|
13
24
|
* previous result. TypeScript asks again for specs it already transformed (another project, a
|
|
14
|
-
* reload), and a Kubb build of a large spec takes seconds. A
|
|
25
|
+
* reload, a changed file next to the spec), and a Kubb build of a large spec takes seconds. A
|
|
26
|
+
* result whose `dependencies` changed on disk, the files its external `$ref`s read, is
|
|
27
|
+
* transformed again. A failed transform is not kept.
|
|
15
28
|
*/
|
|
16
29
|
function cacheTransform(transform) {
|
|
17
30
|
const results = /* @__PURE__ */ new Map();
|
|
18
|
-
|
|
19
|
-
const cached = results.get(params.fileName);
|
|
20
|
-
if (cached && cached.content === params.content && cached.config === config) return cached.result;
|
|
31
|
+
const run = (params, config) => {
|
|
21
32
|
const result = transform(params, config);
|
|
22
33
|
results.set(params.fileName, {
|
|
23
34
|
content: params.content,
|
|
@@ -27,9 +38,14 @@ function cacheTransform(transform) {
|
|
|
27
38
|
result.catch(() => results.delete(params.fileName));
|
|
28
39
|
return result;
|
|
29
40
|
};
|
|
41
|
+
return async (params, config) => {
|
|
42
|
+
const cached = results.get(params.fileName);
|
|
43
|
+
if (!cached || cached.content !== params.content || cached.config !== config) return run(params, config);
|
|
44
|
+
const result = await cached.result;
|
|
45
|
+
return Object.entries(result.dependencies ?? {}).every(([file, text]) => readOrNull(file) === text) ? result : run(params, config);
|
|
46
|
+
};
|
|
30
47
|
}
|
|
31
|
-
|
|
32
|
-
//#region src/config.ts
|
|
48
|
+
// src/config.ts
|
|
33
49
|
/**
|
|
34
50
|
* Finds the Kubb config the way the Kubb CLI does, from `dir` up, and loads it. A config that
|
|
35
51
|
* exports a function is called with no CLI options.
|
|
@@ -65,8 +81,7 @@ async function loadProjectConfig(dir) {
|
|
|
65
81
|
};
|
|
66
82
|
}
|
|
67
83
|
}
|
|
68
|
-
|
|
69
|
-
//#region src/rpc.ts
|
|
84
|
+
// src/rpc.ts
|
|
70
85
|
const separator = "\r\n\r\n";
|
|
71
86
|
/**
|
|
72
87
|
* Frames a message with the LSP base protocol `Content-Length` header the host reads.
|
|
@@ -100,8 +115,7 @@ function createDecoder(onMessage) {
|
|
|
100
115
|
}
|
|
101
116
|
};
|
|
102
117
|
}
|
|
103
|
-
|
|
104
|
-
//#region src/locate.ts
|
|
118
|
+
// src/locate.ts
|
|
105
119
|
const toRange = ([start, end]) => ({
|
|
106
120
|
start,
|
|
107
121
|
end
|
|
@@ -154,8 +168,7 @@ function findRefUsage(document, ref) {
|
|
|
154
168
|
function createLocator(document) {
|
|
155
169
|
return ({ pointer, ref, value }) => findPointer(document, pointer, value) ?? (ref ? findRefUsage(document, ref) : void 0);
|
|
156
170
|
}
|
|
157
|
-
|
|
158
|
-
//#region src/mappings.ts
|
|
171
|
+
// src/mappings.ts
|
|
159
172
|
const kindVerbatim = 0;
|
|
160
173
|
const kindAlias = 2;
|
|
161
174
|
const features = 249;
|
|
@@ -256,8 +269,24 @@ function createMappings(text, content, { locate, locateValue }, pointers) {
|
|
|
256
269
|
}
|
|
257
270
|
return segments;
|
|
258
271
|
}
|
|
259
|
-
|
|
260
|
-
|
|
272
|
+
// src/transform.ts
|
|
273
|
+
const isUrl = (source) => /^https?:\/\//i.test(source);
|
|
274
|
+
const toDependencies = (sources) => Object.fromEntries(sources.filter((source) => !isUrl(source)).map((file) => [file, readOrNull(file)]));
|
|
275
|
+
/**
|
|
276
|
+
* The files that external `$ref`s in the spec at `fileName` read, with the spec as saved on disk.
|
|
277
|
+
*/
|
|
278
|
+
async function readDependencies(fileName) {
|
|
279
|
+
const input = parse(await readFile(fileName, "utf8"));
|
|
280
|
+
const { sources } = await generateModule({
|
|
281
|
+
root: dirname(fileName),
|
|
282
|
+
input,
|
|
283
|
+
config: {
|
|
284
|
+
output: { path: "." },
|
|
285
|
+
plugins: []
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
return sources.filter((source) => !isUrl(source));
|
|
289
|
+
}
|
|
261
290
|
const scanner = ts.createScanner(ts.ScriptTarget.Latest, true);
|
|
262
291
|
function isPlainIdentifier(name) {
|
|
263
292
|
scanner.setText(name);
|
|
@@ -309,7 +338,7 @@ async function transform({ fileName, content }, config) {
|
|
|
309
338
|
hooks.hook("kubb:build:end", ({ files }) => {
|
|
310
339
|
for (const source of files.flatMap((file) => file.sources)) if (source.name && source.pointer) pointers.set(source.name, source.pointer);
|
|
311
340
|
});
|
|
312
|
-
const { text, errors } = await generateModule({
|
|
341
|
+
const { text, errors, sources } = await generateModule({
|
|
313
342
|
root: dirname(fileName),
|
|
314
343
|
input: document.toJS(),
|
|
315
344
|
config: keepSpecCasing(config ?? {
|
|
@@ -319,6 +348,7 @@ async function transform({ fileName, content }, config) {
|
|
|
319
348
|
hooks
|
|
320
349
|
});
|
|
321
350
|
const locate = createLocator(document);
|
|
351
|
+
const dependencies = toDependencies(sources);
|
|
322
352
|
if (errors.length) return {
|
|
323
353
|
text: "export {}",
|
|
324
354
|
extension: ".ts",
|
|
@@ -329,7 +359,8 @@ async function transform({ fileName, content }, config) {
|
|
|
329
359
|
start: range?.start ?? 0,
|
|
330
360
|
length: range ? range.end - range.start : 0
|
|
331
361
|
};
|
|
332
|
-
})
|
|
362
|
+
}),
|
|
363
|
+
dependencies
|
|
333
364
|
};
|
|
334
365
|
if (config && !text) return {
|
|
335
366
|
text: "export {}",
|
|
@@ -338,7 +369,8 @@ async function transform({ fileName, content }, config) {
|
|
|
338
369
|
messageText: "kubb.config.ts generated no code for this spec. Add a plugin such as pluginTs().",
|
|
339
370
|
start: 0,
|
|
340
371
|
length: 0
|
|
341
|
-
}]
|
|
372
|
+
}],
|
|
373
|
+
dependencies
|
|
342
374
|
};
|
|
343
375
|
return {
|
|
344
376
|
text,
|
|
@@ -349,15 +381,32 @@ async function transform({ fileName, content }, config) {
|
|
|
349
381
|
pointer,
|
|
350
382
|
value: true
|
|
351
383
|
})
|
|
352
|
-
}, pointers)
|
|
384
|
+
}, pointers),
|
|
385
|
+
dependencies
|
|
353
386
|
};
|
|
354
387
|
}
|
|
355
|
-
|
|
356
|
-
//#region src/server.ts
|
|
388
|
+
// src/server.ts
|
|
357
389
|
const writeProtocol = process.stdout.write.bind(process.stdout);
|
|
358
390
|
process.stdout.write = process.stderr.write.bind(process.stderr);
|
|
359
391
|
const projects = /* @__PURE__ */ new Map();
|
|
360
392
|
const cachedTransform = cacheTransform(transform);
|
|
393
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
394
|
+
/**
|
|
395
|
+
* The files that external `$ref`s read in the specs under the tsconfig folder, outside
|
|
396
|
+
* `node_modules`, with an extension that `contentMappers` maps to this package. TypeScript only
|
|
397
|
+
* watches what `openProject` returns, so these are found before the first transform.
|
|
398
|
+
*/
|
|
399
|
+
async function findDependencies(configFileName) {
|
|
400
|
+
const { config } = ts.readConfigFile(configFileName, ts.sys.readFile);
|
|
401
|
+
const extensions = (config?.contentMappers ?? []).filter((mapper) => mapper.package === "openapi-import").flatMap((mapper) => mapper.extensions ?? []);
|
|
402
|
+
if (!extensions.length) return [];
|
|
403
|
+
const dir = dirname(configFileName);
|
|
404
|
+
const specs = globSync(extensions.map((extension) => `**/*${extension}`), {
|
|
405
|
+
cwd: dir,
|
|
406
|
+
exclude: (file) => basename(String(file)) === "node_modules"
|
|
407
|
+
});
|
|
408
|
+
return (await Promise.all(specs.map((spec) => readDependencies(resolve(dir, spec)).catch(() => [])))).flat();
|
|
409
|
+
}
|
|
361
410
|
const handlers = {
|
|
362
411
|
initialize: () => ({
|
|
363
412
|
protocolVersion: 1,
|
|
@@ -368,9 +417,12 @@ const handlers = {
|
|
|
368
417
|
const loading = loadProjectConfig(configFileName ? dirname(configFileName) : process.cwd());
|
|
369
418
|
projects.set(projectHandle, loading);
|
|
370
419
|
const project = await loading;
|
|
420
|
+
for (const file of configFileName ? await findDependencies(configFileName) : []) dependencies.add(file);
|
|
421
|
+
const identity = createHash("sha256").update(project.identity);
|
|
422
|
+
for (const file of dependencies) identity.update(`\0${file}\0${readOrNull(file) ?? ""}`);
|
|
371
423
|
return {
|
|
372
|
-
configIdentity: project.identity,
|
|
373
|
-
watchedFiles: project.watchedFiles,
|
|
424
|
+
configIdentity: dependencies.size ? identity.digest("hex") : project.identity,
|
|
425
|
+
watchedFiles: [.../* @__PURE__ */ new Set([...project.watchedFiles, ...dependencies])],
|
|
374
426
|
...options != null && { optionDiagnostics: [{
|
|
375
427
|
path: [],
|
|
376
428
|
messageText: "openapi-import has no options. Set plugin options in kubb.config.ts."
|
|
@@ -392,11 +444,13 @@ const handlers = {
|
|
|
392
444
|
length: 0
|
|
393
445
|
}]
|
|
394
446
|
};
|
|
395
|
-
|
|
447
|
+
const { dependencies: files, ...result } = await cachedTransform(params, project && selectConfig({
|
|
396
448
|
configs: project.configs,
|
|
397
449
|
fileName: params.fileName,
|
|
398
450
|
cwd: project.dir
|
|
399
451
|
}));
|
|
452
|
+
for (const file of Object.keys(files ?? {})) dependencies.add(file);
|
|
453
|
+
return result;
|
|
400
454
|
}
|
|
401
455
|
};
|
|
402
456
|
async function handle({ id, method = "", params }) {
|
|
@@ -429,7 +483,6 @@ async function handle({ id, method = "", params }) {
|
|
|
429
483
|
}
|
|
430
484
|
}
|
|
431
485
|
process.stdin.on("data", createDecoder((message) => void handle(message)));
|
|
432
|
-
//#endregion
|
|
433
486
|
export {};
|
|
434
487
|
|
|
435
488
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":[],"sources":["../src/cache.ts","../src/config.ts","../src/rpc.ts","../src/locate.ts","../src/mappings.ts","../src/transform.ts","../src/server.ts"],"sourcesContent":["import type { UserConfig } from 'kubb'\nimport type { TransformParams } from './transform.ts'\n\n/**\n * Wraps a transform so a repeated request for the same file, content and config returns the\n * previous result. TypeScript asks again for specs it already transformed (another project, a\n * reload), and a Kubb build of a large spec takes seconds. A failed transform is not kept.\n */\nexport function cacheTransform<TResult>(\n transform: (params: TransformParams, config?: UserConfig) => Promise<TResult>,\n): (params: TransformParams, config?: UserConfig) => Promise<TResult> {\n const results = new Map<string, { content: string; config?: UserConfig; result: Promise<TResult> }>()\n\n return (params, config) => {\n const cached = results.get(params.fileName)\n // A reloaded config is a new object, so comparing by reference catches every config change.\n if (cached && cached.content === params.content && cached.config === config) return cached.result\n\n const result = transform(params, config)\n results.set(params.fileName, { content: params.content, config, result })\n result.catch(() => results.delete(params.fileName))\n return result\n }\n}\n","import { createHash } from 'node:crypto'\nimport { readFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport type { UserConfig } from 'kubb'\nimport { configFileCandidates, findConfigFile, loadConfigFile } from 'unplugin-kubb'\n\n/**\n * A Kubb config found for a TypeScript project, with what TypeScript needs to reload it.\n */\nexport type ProjectConfig = {\n /**\n * The project folder.\n */\n dir: string\n /**\n * The configs the file exports, empty when there is no config file.\n */\n configs: Array<UserConfig>\n /**\n * The config file, plus every file the CLI would pick up in `dir`, so adding one reloads too.\n */\n watchedFiles: Array<string>\n /**\n * Changes when the config file changes, so TypeScript transforms its specs again.\n */\n identity: string\n /**\n * Why the config file failed to load. Each transform reports it on the spec.\n */\n error?: string\n}\n\n/**\n * Finds the Kubb config the way the Kubb CLI does, from `dir` up, and loads it. A config that\n * exports a function is called with no CLI options.\n */\nexport async function loadProjectConfig(dir: string): Promise<ProjectConfig> {\n dir = resolve(dir)\n const file = findConfigFile(dir)\n const watchedFiles = [...new Set([...(file ? [file] : []), ...configFileCandidates(dir)])]\n if (!file) return { dir, configs: [], watchedFiles, identity: 'none' }\n\n const identity = createHash('sha256').update(readFileSync(file)).digest('hex')\n try {\n return { dir, configs: await loadConfigFile<UserConfig>({ file, cli: {} }), watchedFiles, identity }\n } catch (error) {\n return { dir, configs: [], watchedFiles, identity, error: `${file} failed to load: ${error instanceof Error ? error.message : String(error)}` }\n }\n}\n","/**\n * A JSON-RPC 2.0 message as the TypeScript content mapper host sends and expects it.\n */\nexport type Message = {\n id?: number | string\n method?: string\n params?: unknown\n result?: unknown\n error?: { code: number; message: string }\n}\n\nconst separator = '\\r\\n\\r\\n'\n\n/**\n * Frames a message with the LSP base protocol `Content-Length` header the host reads.\n */\nexport function encode(message: Message): Buffer {\n const body = Buffer.from(JSON.stringify({ jsonrpc: '2.0', ...message }))\n\n return Buffer.concat([Buffer.from(`Content-Length: ${body.length}${separator}`), body])\n}\n\n/**\n * Returns a stream handler that collects `Content-Length` framed chunks and calls `onMessage`\n * once per complete message, however the chunks split the frames.\n */\nexport function createDecoder(onMessage: (message: Message) => void): (chunk: Buffer) => void {\n let buffer = Buffer.alloc(0)\n\n return (chunk) => {\n buffer = Buffer.concat([buffer, chunk])\n\n while (true) {\n const headerEnd = buffer.indexOf(separator)\n if (headerEnd === -1) return\n\n const header = buffer.subarray(0, headerEnd).toString()\n const length = Number(/content-length:\\s*(\\d+)/i.exec(header)?.[1])\n if (!Number.isInteger(length)) throw new Error(`Missing Content-Length header in \"${header}\"`)\n\n const start = headerEnd + separator.length\n if (buffer.length < start + length) return\n\n const body = buffer.subarray(start, start + length).toString()\n buffer = buffer.subarray(start + length)\n onMessage(JSON.parse(body) as Message)\n }\n }\n}\n","import * as yaml from 'yaml'\n\n/**\n * A range in the spec text, as `[start, end)` offsets.\n */\nexport type Range = { start: number; end: number }\n\nconst toRange = ([start, end]: yaml.Range): Range => ({ start, end })\n\nconst unescapeToken = (token: string) => token.replaceAll('~1', '/').replaceAll('~0', '~')\n\n/**\n * Walks a JSON pointer through maps and sequences; the range is the last key or item it reached,\n * or with `value` the scalar value of that key.\n */\nfunction findPointer(document: yaml.Document, pointer: string, value = false): Range | undefined {\n const tokens = pointer.replace(/^#/, '').split('/').slice(1).map(unescapeToken)\n const reached = tokens.reduce<{ node: unknown; range: Range | undefined } | undefined>(\n (at, token) => {\n if (yaml.isMap(at?.node)) {\n const pair = at.node.items.find((item) => yaml.isScalar(item.key) && String(item.key.value) === token)\n return pair && yaml.isScalar(pair.key) && pair.key.range ? { node: pair.value, range: toRange(pair.key.range) } : undefined\n }\n if (yaml.isSeq(at?.node)) {\n const item = at.node.items[Number(token)]\n return yaml.isNode(item) && item.range ? { node: item, range: toRange(item.range) } : undefined\n }\n return undefined\n },\n { node: document.contents, range: undefined },\n )\n if (!value) return reached?.range\n return yaml.isScalar(reached?.node) && reached.node.range ? toRange(reached.node.range) : undefined\n}\n\n/**\n * The first `$ref` whose value is `ref`.\n */\nfunction findRefUsage(document: yaml.Document, ref: string): Range | undefined {\n let found: Range | undefined\n yaml.visit(document, {\n Pair(_, { key, value }) {\n if (!yaml.isScalar(key) || key.value !== '$ref' || !yaml.isScalar(value) || value.value !== ref || !value.range) return\n found = toRange(value.range)\n return yaml.visit.BREAK\n },\n })\n return found\n}\n\n/**\n * Maps JSON pointers to ranges in an already parsed spec, the same way `@kubb/adapter-oas`'s\n * `locate` does from the spec text. Reusing the document the build parsed saves a second parse of\n * the spec on every transform. An unresolved `$ref` falls back to its first usage.\n */\nexport function createLocator(document: yaml.Document): (location: { pointer: string; ref?: string; value?: boolean }) => Range | undefined {\n return ({ pointer, ref, value }) => findPointer(document, pointer, value) ?? (ref ? findRefUsage(document, ref) : undefined)\n}\n","import ts from '@typescript/typescript6'\n\n/**\n * A span map segment in the tuple form TypeScript reads:\n * `[virtualStart, virtualLength, originalStart, originalLength, kind, features]`.\n */\nexport type Segment = [number, number, number, number, number, number]\n\ntype Locate = (pointer: string) => { start: number; end: number } | undefined\n\n/**\n * Finds a spec key (`locate`) or the scalar value of a key (`locateValue`) from a JSON pointer.\n */\ntype Locators = { locate: Locate; locateValue: Locate }\n\nconst kindVerbatim = 0\nconst kindAlias = 2\n// Hover, Definition, TypeDefinition, Implementation, References, DocumentHighlights.\nconst features = 1 | 8 | 16 | 32 | 64 | 128\n// Only schema names rename into the spec. A stale `$ref` shows as an error, but a stale `required` entry fails silently.\nconst renameFeature = 256\n\nconst refPrefix = '#/components/schemas/'\n\nconst escapeToken = (token: string) => token.replaceAll('~', '~0').replaceAll('/', '~1')\n\n// A schema type's own key: `#/components/schemas/Pet`, not a property or an operation part under it.\nconst isSchemaPointer = (pointer: string | undefined): pointer is string => !!pointer?.startsWith(refPrefix) && !pointer.slice(refPrefix.length).includes('/')\n\n/**\n * A property type without `| null` and one level of `T[]` or `Array<T>`, which the spec writes under `items`.\n */\nfunction unwrap(type: ts.TypeNode | undefined): { type: ts.TypeNode; items: boolean } | undefined {\n const members =\n type && ts.isUnionTypeNode(type)\n ? type.types.filter((member) => !(ts.isLiteralTypeNode(member) && member.literal.kind === ts.SyntaxKind.NullKeyword))\n : [type]\n const [single] = members.length === 1 ? members : []\n if (!single) return undefined\n if (ts.isArrayTypeNode(single)) return { type: single.elementType, items: true }\n if (ts.isTypeReferenceNode(single) && single.typeName.getText() === 'Array' && single.typeArguments?.length === 1)\n return { type: single.typeArguments[0]!, items: true }\n return { type: single, items: false }\n}\n\n/**\n * The members of an interface, or of a type alias for an object literal.\n */\nfunction typeMembers(statement: ts.TypeAliasDeclaration | ts.InterfaceDeclaration): ts.NodeArray<ts.TypeElement> | undefined {\n if (ts.isInterfaceDeclaration(statement)) return statement.members\n return ts.isTypeLiteralNode(statement.type) ? statement.type.members : undefined\n}\n\n/**\n * Links generated names to the spec keys they came from: schemas and their (nested) properties,\n * and operation types to the operation, parameters, request body or response. A schema type named\n * exactly like its key is verbatim, so a rename in TypeScript renames the key. A reference to a\n * schema type maps to the end of the `$ref` that points at that schema, so the rename updates it too.\n * `pointers` maps each emitted declaration name to the JSON pointer it came from.\n */\nexport function createMappings(text: string, content: string, { locate, locateValue }: Locators, pointers: Map<string, string>): Array<Segment> {\n const sourceFile = ts.createSourceFile('index.ts', text, ts.ScriptTarget.Latest, true)\n const segments: Array<Segment> = []\n\n const add = (name: ts.Node, rename: boolean, pointer: string | undefined) => {\n const range = pointer ? locate(pointer) : undefined\n if (!range) return\n const verbatim = rename && content.slice(range.start, range.end) === name.getText(sourceFile)\n segments.push([\n name.getStart(sourceFile),\n name.getWidth(sourceFile),\n range.start,\n range.end - range.start,\n verbatim ? kindVerbatim : kindAlias,\n verbatim ? features | renameFeature : features,\n ])\n }\n\n // Only a reference whose `$ref` ends in the same text renames; anything else would break the spec.\n const addRef = (inner: ReturnType<typeof unwrap>, pointer: string) => {\n if (!inner || !ts.isTypeReferenceNode(inner.type) || !ts.isIdentifier(inner.type.typeName)) return\n const reference = inner.type.typeName\n const name = reference.text\n if (!isSchemaPointer(pointers.get(name))) return\n const range = locateValue(`${pointer}${inner.items ? '/items' : ''}/$ref`)\n if (!range) return\n // The `$ref` value may be quoted, so count the name back from the end of its text.\n const start = range.start + content.slice(range.start, range.end).replace(/['\"]$/, '').length - name.length\n if (content.slice(start - refPrefix.length, start + name.length) !== refPrefix + name) return\n segments.push([reference.getStart(sourceFile), reference.getWidth(sourceFile), start, name.length, kindVerbatim, features | renameFeature])\n }\n\n const addMembers = (members: ts.NodeArray<ts.TypeElement>, pointer: string) => {\n for (const member of members) {\n if (!ts.isPropertySignature(member) || !(ts.isIdentifier(member.name) || ts.isStringLiteral(member.name))) continue\n const propertyPointer = `${pointer}/properties/${escapeToken(member.name.text)}`\n add(member.name, false, propertyPointer)\n const inner = unwrap(member.type)\n addRef(inner, propertyPointer)\n if (inner && ts.isTypeLiteralNode(inner.type)) addMembers(inner.type.members, inner.items ? `${propertyPointer}/items` : propertyPointer)\n }\n }\n\n for (const statement of sourceFile.statements) {\n if (ts.isVariableStatement(statement)) {\n // Enum objects (`export const orderStatusEnum = { ... } as const`) carry their own pointer.\n for (const declaration of statement.declarationList.declarations) {\n if (ts.isIdentifier(declaration.name)) add(declaration.name, false, pointers.get(declaration.name.text))\n }\n continue\n }\n if (!ts.isTypeAliasDeclaration(statement) && !ts.isInterfaceDeclaration(statement)) continue\n const pointer = pointers.get(statement.name.text)\n const isSchema = isSchemaPointer(pointer)\n add(statement.name, isSchema, pointer)\n\n // Property names only resolve under a schema, not under operation parameters or responses.\n if (!isSchema) continue\n const members = typeMembers(statement)\n if (members) addMembers(members, pointer)\n else if (ts.isTypeAliasDeclaration(statement)) addRef(unwrap(statement.type), pointer)\n }\n\n return segments\n}\n","import { dirname } from 'node:path'\nimport ts from '@typescript/typescript6'\nimport type { UserConfig } from 'kubb'\nimport { Hookable, type KubbHooks } from 'kubb/kit'\nimport { pluginTs, pluginTsName, resolverTs } from '@kubb/plugin-ts'\nimport { generateModule } from 'unplugin-kubb'\nimport { parseDocument } from 'yaml'\nimport { createLocator } from './locate.ts'\nimport { createMappings, type Segment } from './mappings.ts'\n\n/**\n * Parameters of the content mapper `transform` request.\n */\nexport type TransformParams = {\n fileName: string\n content: string\n}\n\n/**\n * The module TypeScript checks in place of the spec, and the segments linking it to the spec.\n */\nexport type TransformResult = {\n text: string\n extension: '.ts'\n mappings?: Array<Segment>\n diagnostics?: Array<{ messageText: string; start: number; length: number }>\n}\n\nconst scanner = ts.createScanner(ts.ScriptTarget.Latest, true)\n\n// A keyword such as `string` or `class` scans as a keyword, not an identifier, so it is not kept.\nfunction isPlainIdentifier(name: string): boolean {\n scanner.setText(name)\n return scanner.scan() === ts.SyntaxKind.Identifier && scanner.getTokenEnd() === name.length\n}\n\n/**\n * Keeps a name that is already a valid type name as the spec wrote it (`pet`, `PET_STATUS`), so a\n * schema type matches its key and renames it. Composed names such as `getPetById Status 200` and\n * keys that are not identifiers keep the `@kubb/plugin-ts` PascalCase.\n */\nconst specName = (name: string) => (isPlainIdentifier(name) ? name : resolverTs.name(name))\n\n/**\n * Lets `@kubb/plugin-ts` name schema types after their spec keys, unless the config sets its own `resolver.name`.\n */\nfunction keepSpecCasing(config: UserConfig): UserConfig {\n return {\n ...config,\n plugins: config.plugins?.map((plugin) =>\n plugin.name === pluginTsName\n ? { ...plugin, options: { ...plugin.options, resolver: { name: specName, ...(plugin.options as { resolver?: object })?.resolver } } }\n : plugin,\n ),\n }\n}\n\n/**\n * Generates the module for one spec with `generateModule` from `unplugin-kubb`, the same one a\n * bundler loads. Without a config, only `@kubb/plugin-ts` runs. The spec text comes from the\n * request, so unsaved edits are checked too. It is parsed once and shared by the build, the\n * diagnostics and the mappings.\n */\nexport async function transform({ fileName, content }: TransformParams, config?: UserConfig): Promise<TransformResult> {\n const document = parseDocument(content)\n if (document.errors.length) {\n return {\n text: 'export {}',\n extension: '.ts',\n diagnostics: document.errors.map((error) => ({ messageText: error.message, start: error.pos[0], length: error.pos[1] - error.pos[0] })),\n }\n }\n\n const hooks = new Hookable<KubbHooks>()\n const pointers = new Map<string, string>()\n hooks.hook('kubb:build:end', ({ files }) => {\n for (const source of files.flatMap((file) => file.sources)) {\n if (source.name && source.pointer) pointers.set(source.name, source.pointer)\n }\n })\n\n const { text, errors } = await generateModule({\n root: dirname(fileName),\n input: document.toJS(),\n config: keepSpecCasing(config ?? { output: { path: '.' }, plugins: [pluginTs()] }),\n hooks,\n })\n\n const locate = createLocator(document)\n\n if (errors.length) {\n return {\n text: 'export {}',\n extension: '.ts',\n diagnostics: errors.map((error) => {\n const range = error.location && 'pointer' in error.location ? locate(error.location) : undefined\n return { messageText: error.message, start: range?.start ?? 0, length: range ? range.end - range.start : 0 }\n }),\n }\n }\n\n if (config && !text) {\n return {\n text: 'export {}',\n extension: '.ts',\n diagnostics: [{ messageText: 'kubb.config.ts generated no code for this spec. Add a plugin such as pluginTs().', start: 0, length: 0 }],\n }\n }\n\n return {\n text,\n extension: '.ts',\n mappings: createMappings(text, content, { locate: (pointer) => locate({ pointer }), locateValue: (pointer) => locate({ pointer, value: true }) }, pointers),\n }\n}\n","import { dirname } from 'node:path'\nimport { selectConfig } from 'unplugin-kubb'\nimport { cacheTransform } from './cache.ts'\nimport { loadProjectConfig, type ProjectConfig } from './config.ts'\nimport { createDecoder, encode, type Message } from './rpc.ts'\nimport { transform, type TransformParams } from './transform.ts'\n\n// stdout carries the protocol, so every other stdout write (any console method, direct writes from\n// Kubb or its plugins) goes to stderr.\nconst writeProtocol = process.stdout.write.bind(process.stdout)\nprocess.stdout.write = process.stderr.write.bind(process.stderr) as typeof process.stdout.write\n\n// The load promise is stored right away, so a transform sent before the load finishes waits for it.\nconst projects = new Map<string, Promise<ProjectConfig>>()\n\nconst cachedTransform = cacheTransform(transform)\n\nconst handlers: Record<string, (params: never) => unknown> = {\n initialize: () => ({ protocolVersion: 1, positionEncoding: 'utf-16', diagnosticSource: 'kubb' }),\n // `dynamicConfig` in package.json: TypeScript watches `watchedFiles` and opens the project again\n // when one changes, then transforms its specs again when `configIdentity` differs.\n openProject: async ({ projectHandle, configFileName, options }: { projectHandle: string; configFileName?: string; options?: unknown }) => {\n const loading = loadProjectConfig(configFileName ? dirname(configFileName) : process.cwd())\n projects.set(projectHandle, loading)\n const project = await loading\n\n return {\n configIdentity: project.identity,\n watchedFiles: project.watchedFiles,\n ...(options != null && { optionDiagnostics: [{ path: [], messageText: 'openapi-import has no options. Set plugin options in kubb.config.ts.' }] }),\n }\n },\n closeProject: ({ projectHandle }: { projectHandle: string }) => {\n projects.delete(projectHandle)\n return null\n },\n transform: async (params: TransformParams & { projectHandle: string }) => {\n const project = await projects.get(params.projectHandle)\n if (project?.error) return { text: 'export {}', extension: '.ts', diagnostics: [{ messageText: project.error, start: 0, length: 0 }] }\n\n return cachedTransform(params, project && selectConfig({ configs: project.configs, fileName: params.fileName, cwd: project.dir }))\n },\n}\n\nasync function handle({ id, method = '', params }: Message): Promise<void> {\n const handler = handlers[method]\n if (id === undefined) return\n\n try {\n if (!handler) {\n writeProtocol(encode({ id, error: { code: -32601, message: `Unknown method \"${method}\"` } }))\n return\n }\n const result = await handler(params as never)\n writeProtocol(encode({ id, result: result ?? null }))\n } catch (error) {\n writeProtocol(encode({ id, error: { code: -32603, message: error instanceof Error ? (error.stack ?? error.message) : String(error) } }))\n }\n}\n\nprocess.stdin.on(\n 'data',\n createDecoder((message) => void handle(message)),\n)\n"],"mappings":";;;;;;;;;;;;;;;AAQA,SAAgB,eACd,WACoE;CACpE,MAAM,0BAAU,IAAI,IAAgF;CAEpG,QAAQ,QAAQ,WAAW;EACzB,MAAM,SAAS,QAAQ,IAAI,OAAO,QAAQ;EAE1C,IAAI,UAAU,OAAO,YAAY,OAAO,WAAW,OAAO,WAAW,QAAQ,OAAO,OAAO;EAE3F,MAAM,SAAS,UAAU,QAAQ,MAAM;EACvC,QAAQ,IAAI,OAAO,UAAU;GAAE,SAAS,OAAO;GAAS;GAAQ;EAAO,CAAC;EACxE,OAAO,YAAY,QAAQ,OAAO,OAAO,QAAQ,CAAC;EAClD,OAAO;CACT;AACF;;;;;;;ACaA,eAAsB,kBAAkB,KAAqC;CAC3E,MAAM,QAAQ,GAAG;CACjB,MAAM,OAAO,eAAe,GAAG;CAC/B,MAAM,eAAe,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAI,OAAO,CAAC,IAAI,IAAI,CAAC,GAAI,GAAG,qBAAqB,GAAG,CAAC,CAAC,CAAC;CACzF,IAAI,CAAC,MAAM,OAAO;EAAE;EAAK,SAAS,C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AwD;EACxE,MAAM,UAAU,MAAM,SAAS,IAAI,OAAO,aAAa;EACvD,IAAI,SAAS,OAAO,OAAO;GAAE,MAAM;GAAa,WAAW;GAAO,aAAa,CAAC;IAAE,aAAa,QAAQ;IAAO,OAAO;IAAG,QAAQ;GAAE,CAAC;EAAE;EAErI,OAAO,gBAAgB,QAAQ,WAAW,aAAa;GAAE,SAAS,QAAQ;GAAS,UAAU,OAAO;GAAU,KAAK,QAAQ;EAAI,CAAC,CAAC;CACnI;AACF;AAEA,eAAe,OAAO,EAAE,IAAI,SAAS,IAAI,UAAkC;CACzE,MAAM,UAAU,SAAS;CACzB,IAAI,OAAO,KAAA,GAAW;CAEtB,IAAI;EACF,IAAI,CAAC,SAAS;GACZ,cAAc,OAAO;IAAE;IAAI,OAAO;KAAE,MAAM;KAAQ,SAAS,mBAAmB,OAAO;IAAG;GAAE,CAAC,CAAC;GAC5F;EACF;EACA,MAAM,SAAS,MAAM,QAAQ,MAAe;EAC5C,cAAc,OAAO;GAAE;GAAI,QAAQ,UAAU;EAAK,CAAC,CAAC;CACtD,SAAS,OAAO;EACd,cAAc,OAAO;GAAE;GAAI,OAAO;IAAE,MAAM;IAAQ,SAAS,iBAAiB,QAAS,MAAM,SAAS,MAAM,UAAW,OAAO,KAAK;GAAE;EAAE,CAAC,CAAC;CACzI;AACF;AAEA,QAAQ,MAAM,GACZ,QACA,eAAe,YAAY,KAAK,OAAO,OAAO,CAAC,CACjD"}
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../src/cache.ts","../src/config.ts","../src/rpc.ts","../src/locate.ts","../src/mappings.ts","../src/transform.ts","../src/server.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport type { UserConfig } from 'kubb'\nimport type { TransformParams, TransformResult } from './transform.ts'\n\n/**\n * The text of `file`, or `null` when it cannot be read.\n */\nexport const readOrNull = (file: string): string | null => {\n try {\n return readFileSync(file, 'utf8')\n } catch {\n return null\n }\n}\n\n/**\n * Wraps a transform so a repeated request for the same file, content and config returns the\n * previous result. TypeScript asks again for specs it already transformed (another project, a\n * reload, a changed file next to the spec), and a Kubb build of a large spec takes seconds. A\n * result whose `dependencies` changed on disk, the files its external `$ref`s read, is\n * transformed again. A failed transform is not kept.\n */\nexport function cacheTransform<TResult extends Pick<TransformResult, 'text' | 'dependencies'>>(\n transform: (params: TransformParams, config?: UserConfig) => Promise<TResult>,\n): (params: TransformParams, config?: UserConfig) => Promise<TResult> {\n const results = new Map<string, { content: string; config?: UserConfig; result: Promise<TResult> }>()\n\n const run = (params: TransformParams, config?: UserConfig) => {\n const result = transform(params, config)\n results.set(params.fileName, { content: params.content, config, result })\n result.catch(() => results.delete(params.fileName))\n return result\n }\n\n return async (params, config) => {\n const cached = results.get(params.fileName)\n // A reloaded config is a new object, so comparing by reference catches every config change.\n if (!cached || cached.content !== params.content || cached.config !== config) return run(params, config)\n\n const result = await cached.result\n const fresh = Object.entries(result.dependencies ?? {}).every(([file, text]) => readOrNull(file) === text)\n return fresh ? result : run(params, config)\n }\n}\n","import { createHash } from 'node:crypto'\nimport { readFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport type { UserConfig } from 'kubb'\nimport { configFileCandidates, findConfigFile, loadConfigFile } from 'unplugin-kubb'\n\n/**\n * A Kubb config found for a TypeScript project, with what TypeScript needs to reload it.\n */\nexport type ProjectConfig = {\n /**\n * The project folder.\n */\n dir: string\n /**\n * The configs the file exports, empty when there is no config file.\n */\n configs: Array<UserConfig>\n /**\n * The config file, plus every file the CLI would pick up in `dir`, so adding one reloads too.\n */\n watchedFiles: Array<string>\n /**\n * Changes when the config file changes, so TypeScript transforms its specs again.\n */\n identity: string\n /**\n * Why the config file failed to load. Each transform reports it on the spec.\n */\n error?: string\n}\n\n/**\n * Finds the Kubb config the way the Kubb CLI does, from `dir` up, and loads it. A config that\n * exports a function is called with no CLI options.\n */\nexport async function loadProjectConfig(dir: string): Promise<ProjectConfig> {\n dir = resolve(dir)\n const file = findConfigFile(dir)\n const watchedFiles = [...new Set([...(file ? [file] : []), ...configFileCandidates(dir)])]\n if (!file) return { dir, configs: [], watchedFiles, identity: 'none' }\n\n const identity = createHash('sha256').update(readFileSync(file)).digest('hex')\n try {\n return { dir, configs: await loadConfigFile<UserConfig>({ file, cli: {} }), watchedFiles, identity }\n } catch (error) {\n return { dir, configs: [], watchedFiles, identity, error: `${file} failed to load: ${error instanceof Error ? error.message : String(error)}` }\n }\n}\n","/**\n * A JSON-RPC 2.0 message as the TypeScript content mapper host sends and expects it.\n */\nexport type Message = {\n id?: number | string\n method?: string\n params?: unknown\n result?: unknown\n error?: { code: number; message: string }\n}\n\nconst separator = '\\r\\n\\r\\n'\n\n/**\n * Frames a message with the LSP base protocol `Content-Length` header the host reads.\n */\nexport function encode(message: Message): Buffer {\n const body = Buffer.from(JSON.stringify({ jsonrpc: '2.0', ...message }))\n\n return Buffer.concat([Buffer.from(`Content-Length: ${body.length}${separator}`), body])\n}\n\n/**\n * Returns a stream handler that collects `Content-Length` framed chunks and calls `onMessage`\n * once per complete message, however the chunks split the frames.\n */\nexport function createDecoder(onMessage: (message: Message) => void): (chunk: Buffer) => void {\n let buffer = Buffer.alloc(0)\n\n return (chunk) => {\n buffer = Buffer.concat([buffer, chunk])\n\n while (true) {\n const headerEnd = buffer.indexOf(separator)\n if (headerEnd === -1) return\n\n const header = buffer.subarray(0, headerEnd).toString()\n const length = Number(/content-length:\\s*(\\d+)/i.exec(header)?.[1])\n if (!Number.isInteger(length)) throw new Error(`Missing Content-Length header in \"${header}\"`)\n\n const start = headerEnd + separator.length\n if (buffer.length < start + length) return\n\n const body = buffer.subarray(start, start + length).toString()\n buffer = buffer.subarray(start + length)\n onMessage(JSON.parse(body) as Message)\n }\n }\n}\n","import * as yaml from 'yaml'\n\n/**\n * A range in the spec text, as `[start, end)` offsets.\n */\nexport type Range = { start: number; end: number }\n\nconst toRange = ([start, end]: yaml.Range): Range => ({ start, end })\n\nconst unescapeToken = (token: string) => token.replaceAll('~1', '/').replaceAll('~0', '~')\n\n/**\n * Walks a JSON pointer through maps and sequences; the range is the last key or item it reached,\n * or with `value` the scalar value of that key.\n */\nfunction findPointer(document: yaml.Document, pointer: string, value = false): Range | undefined {\n const tokens = pointer.replace(/^#/, '').split('/').slice(1).map(unescapeToken)\n const reached = tokens.reduce<{ node: unknown; range: Range | undefined } | undefined>(\n (at, token) => {\n if (yaml.isMap(at?.node)) {\n const pair = at.node.items.find((item) => yaml.isScalar(item.key) && String(item.key.value) === token)\n return pair && yaml.isScalar(pair.key) && pair.key.range ? { node: pair.value, range: toRange(pair.key.range) } : undefined\n }\n if (yaml.isSeq(at?.node)) {\n const item = at.node.items[Number(token)]\n return yaml.isNode(item) && item.range ? { node: item, range: toRange(item.range) } : undefined\n }\n return undefined\n },\n { node: document.contents, range: undefined },\n )\n if (!value) return reached?.range\n return yaml.isScalar(reached?.node) && reached.node.range ? toRange(reached.node.range) : undefined\n}\n\n/**\n * The first `$ref` whose value is `ref`.\n */\nfunction findRefUsage(document: yaml.Document, ref: string): Range | undefined {\n let found: Range | undefined\n yaml.visit(document, {\n Pair(_, { key, value }) {\n if (!yaml.isScalar(key) || key.value !== '$ref' || !yaml.isScalar(value) || value.value !== ref || !value.range) return\n found = toRange(value.range)\n return yaml.visit.BREAK\n },\n })\n return found\n}\n\n/**\n * Maps JSON pointers to ranges in an already parsed spec, the same way `@kubb/adapter-oas`'s\n * `locate` does from the spec text. Reusing the document the build parsed saves a second parse of\n * the spec on every transform. An unresolved `$ref` falls back to its first usage.\n */\nexport function createLocator(document: yaml.Document): (location: { pointer: string; ref?: string; value?: boolean }) => Range | undefined {\n return ({ pointer, ref, value }) => findPointer(document, pointer, value) ?? (ref ? findRefUsage(document, ref) : undefined)\n}\n","import ts from '@typescript/typescript6'\n\n/**\n * A span map segment in the tuple form TypeScript reads:\n * `[virtualStart, virtualLength, originalStart, originalLength, kind, features]`.\n */\nexport type Segment = [number, number, number, number, number, number]\n\ntype Locate = (pointer: string) => { start: number; end: number } | undefined\n\n/**\n * Finds a spec key (`locate`) or the scalar value of a key (`locateValue`) from a JSON pointer.\n */\ntype Locators = { locate: Locate; locateValue: Locate }\n\nconst kindVerbatim = 0\nconst kindAlias = 2\n// Hover, Definition, TypeDefinition, Implementation, References, DocumentHighlights.\nconst features = 1 | 8 | 16 | 32 | 64 | 128\n// Only schema names rename into the spec. A stale `$ref` shows as an error, but a stale `required` entry fails silently.\nconst renameFeature = 256\n\nconst refPrefix = '#/components/schemas/'\n\nconst escapeToken = (token: string) => token.replaceAll('~', '~0').replaceAll('/', '~1')\n\n// A schema type's own key: `#/components/schemas/Pet`, not a property or an operation part under it.\nconst isSchemaPointer = (pointer: string | undefined): pointer is string => !!pointer?.startsWith(refPrefix) && !pointer.slice(refPrefix.length).includes('/')\n\n/**\n * A property type without `| null` and one level of `T[]` or `Array<T>`, which the spec writes under `items`.\n */\nfunction unwrap(type: ts.TypeNode | undefined): { type: ts.TypeNode; items: boolean } | undefined {\n const members =\n type && ts.isUnionTypeNode(type)\n ? type.types.filter((member) => !(ts.isLiteralTypeNode(member) && member.literal.kind === ts.SyntaxKind.NullKeyword))\n : [type]\n const [single] = members.length === 1 ? members : []\n if (!single) return undefined\n if (ts.isArrayTypeNode(single)) return { type: single.elementType, items: true }\n if (ts.isTypeReferenceNode(single) && single.typeName.getText() === 'Array' && single.typeArguments?.length === 1)\n return { type: single.typeArguments[0]!, items: true }\n return { type: single, items: false }\n}\n\n/**\n * The members of an interface, or of a type alias for an object literal.\n */\nfunction typeMembers(statement: ts.TypeAliasDeclaration | ts.InterfaceDeclaration): ts.NodeArray<ts.TypeElement> | undefined {\n if (ts.isInterfaceDeclaration(statement)) return statement.members\n return ts.isTypeLiteralNode(statement.type) ? statement.type.members : undefined\n}\n\n/**\n * Links generated names to the spec keys they came from: schemas and their (nested) properties,\n * and operation types to the operation, parameters, request body or response. A schema type named\n * exactly like its key is verbatim, so a rename in TypeScript renames the key. A reference to a\n * schema type maps to the end of the `$ref` that points at that schema, so the rename updates it too.\n * `pointers` maps each emitted declaration name to the JSON pointer it came from.\n */\nexport function createMappings(text: string, content: string, { locate, locateValue }: Locators, pointers: Map<string, string>): Array<Segment> {\n const sourceFile = ts.createSourceFile('index.ts', text, ts.ScriptTarget.Latest, true)\n const segments: Array<Segment> = []\n\n const add = (name: ts.Node, rename: boolean, pointer: string | undefined) => {\n const range = pointer ? locate(pointer) : undefined\n if (!range) return\n const verbatim = rename && content.slice(range.start, range.end) === name.getText(sourceFile)\n segments.push([\n name.getStart(sourceFile),\n name.getWidth(sourceFile),\n range.start,\n range.end - range.start,\n verbatim ? kindVerbatim : kindAlias,\n verbatim ? features | renameFeature : features,\n ])\n }\n\n // Only a reference whose `$ref` ends in the same text renames; anything else would break the spec.\n const addRef = (inner: ReturnType<typeof unwrap>, pointer: string) => {\n if (!inner || !ts.isTypeReferenceNode(inner.type) || !ts.isIdentifier(inner.type.typeName)) return\n const reference = inner.type.typeName\n const name = reference.text\n if (!isSchemaPointer(pointers.get(name))) return\n const range = locateValue(`${pointer}${inner.items ? '/items' : ''}/$ref`)\n if (!range) return\n // The `$ref` value may be quoted, so count the name back from the end of its text.\n const start = range.start + content.slice(range.start, range.end).replace(/['\"]$/, '').length - name.length\n if (content.slice(start - refPrefix.length, start + name.length) !== refPrefix + name) return\n segments.push([reference.getStart(sourceFile), reference.getWidth(sourceFile), start, name.length, kindVerbatim, features | renameFeature])\n }\n\n const addMembers = (members: ts.NodeArray<ts.TypeElement>, pointer: string) => {\n for (const member of members) {\n if (!ts.isPropertySignature(member) || !(ts.isIdentifier(member.name) || ts.isStringLiteral(member.name))) continue\n const propertyPointer = `${pointer}/properties/${escapeToken(member.name.text)}`\n add(member.name, false, propertyPointer)\n const inner = unwrap(member.type)\n addRef(inner, propertyPointer)\n if (inner && ts.isTypeLiteralNode(inner.type)) addMembers(inner.type.members, inner.items ? `${propertyPointer}/items` : propertyPointer)\n }\n }\n\n for (const statement of sourceFile.statements) {\n if (ts.isVariableStatement(statement)) {\n // Enum objects (`export const orderStatusEnum = { ... } as const`) carry their own pointer.\n for (const declaration of statement.declarationList.declarations) {\n if (ts.isIdentifier(declaration.name)) add(declaration.name, false, pointers.get(declaration.name.text))\n }\n continue\n }\n if (!ts.isTypeAliasDeclaration(statement) && !ts.isInterfaceDeclaration(statement)) continue\n const pointer = pointers.get(statement.name.text)\n const isSchema = isSchemaPointer(pointer)\n add(statement.name, isSchema, pointer)\n\n // Property names only resolve under a schema, not under operation parameters or responses.\n if (!isSchema) continue\n const members = typeMembers(statement)\n if (members) addMembers(members, pointer)\n else if (ts.isTypeAliasDeclaration(statement)) addRef(unwrap(statement.type), pointer)\n }\n\n return segments\n}\n","import { readFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\nimport ts from '@typescript/typescript6'\nimport type { UserConfig } from 'kubb'\nimport { Hookable, type KubbHooks } from 'kubb/kit'\nimport { pluginTs, pluginTsName, resolverTs } from '@kubb/plugin-ts'\nimport { generateModule } from 'unplugin-kubb'\nimport { parse, parseDocument } from 'yaml'\nimport { readOrNull } from './cache.ts'\nimport { createLocator } from './locate.ts'\nimport { createMappings, type Segment } from './mappings.ts'\n\n/**\n * Parameters of the content mapper `transform` request.\n */\nexport type TransformParams = {\n fileName: string\n content: string\n}\n\n/**\n * The module TypeScript checks in place of the spec, and the segments linking it to the spec.\n */\nexport type TransformResult = {\n text: string\n extension: '.ts'\n mappings?: Array<Segment>\n diagnostics?: Array<{ messageText: string; start: number; length: number }>\n /**\n * The text of each file an external `$ref` read, by absolute path, or `null` when it is missing.\n * The server watches these files. It is not part of the protocol.\n */\n dependencies?: Record<string, string | null>\n}\n\nconst isUrl = (source: string) => /^https?:\\/\\//i.test(source)\n\n// shortcut: Kubb reads each file before this does, so an edit in between is stored as already built; read through Kubb if that shows up.\nconst toDependencies = (sources: Array<string>) => Object.fromEntries(sources.filter((source) => !isUrl(source)).map((file) => [file, readOrNull(file)]))\n\n/**\n * The files that external `$ref`s in the spec at `fileName` read, with the spec as saved on disk.\n */\nexport async function readDependencies(fileName: string): Promise<Array<string>> {\n const input = parse(await readFile(fileName, 'utf8'))\n const { sources } = await generateModule({ root: dirname(fileName), input, config: { output: { path: '.' }, plugins: [] } })\n return sources.filter((source) => !isUrl(source))\n}\n\nconst scanner = ts.createScanner(ts.ScriptTarget.Latest, true)\n\n// A keyword such as `string` or `class` scans as a keyword, not an identifier, so it is not kept.\nfunction isPlainIdentifier(name: string): boolean {\n scanner.setText(name)\n return scanner.scan() === ts.SyntaxKind.Identifier && scanner.getTokenEnd() === name.length\n}\n\n/**\n * Keeps a name that is already a valid type name as the spec wrote it (`pet`, `PET_STATUS`), so a\n * schema type matches its key and renames it. Composed names such as `getPetById Status 200` and\n * keys that are not identifiers keep the `@kubb/plugin-ts` PascalCase.\n */\nconst specName = (name: string) => (isPlainIdentifier(name) ? name : resolverTs.name(name))\n\n/**\n * Lets `@kubb/plugin-ts` name schema types after their spec keys, unless the config sets its own `resolver.name`.\n */\nfunction keepSpecCasing(config: UserConfig): UserConfig {\n return {\n ...config,\n plugins: config.plugins?.map((plugin) =>\n plugin.name === pluginTsName\n ? { ...plugin, options: { ...plugin.options, resolver: { name: specName, ...(plugin.options as { resolver?: object })?.resolver } } }\n : plugin,\n ),\n }\n}\n\n/**\n * Generates the module for one spec with `generateModule` from `unplugin-kubb`, the same one a\n * bundler loads. Without a config, only `@kubb/plugin-ts` runs. The spec text comes from the\n * request, so unsaved edits are checked too. It is parsed once and shared by the build, the\n * diagnostics and the mappings.\n */\nexport async function transform({ fileName, content }: TransformParams, config?: UserConfig): Promise<TransformResult> {\n const document = parseDocument(content)\n if (document.errors.length) {\n return {\n text: 'export {}',\n extension: '.ts',\n diagnostics: document.errors.map((error) => ({ messageText: error.message, start: error.pos[0], length: error.pos[1] - error.pos[0] })),\n }\n }\n\n const hooks = new Hookable<KubbHooks>()\n const pointers = new Map<string, string>()\n hooks.hook('kubb:build:end', ({ files }) => {\n for (const source of files.flatMap((file) => file.sources)) {\n if (source.name && source.pointer) pointers.set(source.name, source.pointer)\n }\n })\n\n const { text, errors, sources } = await generateModule({\n root: dirname(fileName),\n input: document.toJS(),\n config: keepSpecCasing(config ?? { output: { path: '.' }, plugins: [pluginTs()] }),\n hooks,\n })\n\n const locate = createLocator(document)\n const dependencies = toDependencies(sources)\n\n if (errors.length) {\n return {\n text: 'export {}',\n extension: '.ts',\n diagnostics: errors.map((error) => {\n const range = error.location && 'pointer' in error.location ? locate(error.location) : undefined\n return { messageText: error.message, start: range?.start ?? 0, length: range ? range.end - range.start : 0 }\n }),\n dependencies,\n }\n }\n\n if (config && !text) {\n return {\n text: 'export {}',\n extension: '.ts',\n diagnostics: [{ messageText: 'kubb.config.ts generated no code for this spec. Add a plugin such as pluginTs().', start: 0, length: 0 }],\n dependencies,\n }\n }\n\n return {\n text,\n extension: '.ts',\n mappings: createMappings(text, content, { locate: (pointer) => locate({ pointer }), locateValue: (pointer) => locate({ pointer, value: true }) }, pointers),\n dependencies,\n }\n}\n","import { createHash } from 'node:crypto'\nimport { globSync } from 'node:fs'\nimport { basename, dirname, resolve } from 'node:path'\nimport ts from '@typescript/typescript6'\nimport { selectConfig } from 'unplugin-kubb'\nimport { cacheTransform, readOrNull } from './cache.ts'\nimport { loadProjectConfig, type ProjectConfig } from './config.ts'\nimport { createDecoder, encode, type Message } from './rpc.ts'\nimport { readDependencies, transform, type TransformParams } from './transform.ts'\n\n// stdout carries the protocol, so every other stdout write (any console method, direct writes from\n// Kubb or its plugins) goes to stderr.\nconst writeProtocol = process.stdout.write.bind(process.stdout)\nprocess.stdout.write = process.stderr.write.bind(process.stderr) as typeof process.stdout.write\n\n// The load promise is stored right away, so a transform sent before the load finishes waits for it.\nconst projects = new Map<string, Promise<ProjectConfig>>()\n\nconst cachedTransform = cacheTransform(transform)\n\n// shortcut: one list for every project, and a file stays watched after its `$ref` is gone; split it per project if a stray reload matters.\nconst dependencies = new Set<string>()\n\n/**\n * The files that external `$ref`s read in the specs under the tsconfig folder, outside\n * `node_modules`, with an extension that `contentMappers` maps to this package. TypeScript only\n * watches what `openProject` returns, so these are found before the first transform.\n */\nasync function findDependencies(configFileName: string): Promise<Array<string>> {\n const { config } = ts.readConfigFile(configFileName, ts.sys.readFile)\n const mappers: Array<{ package?: string; extensions?: Array<string> }> = config?.contentMappers ?? []\n // shortcut: a `contentMappers` entry that comes from `extends` is not read, look it up too if someone relies on it.\n const extensions = mappers.filter((mapper) => mapper.package === 'openapi-import').flatMap((mapper) => mapper.extensions ?? [])\n if (!extensions.length) return []\n\n const dir = dirname(configFileName)\n const specs = globSync(\n extensions.map((extension) => `**/*${extension}`),\n { cwd: dir, exclude: (file) => basename(String(file)) === 'node_modules' },\n )\n // A spec that does not parse has nothing to watch yet; its transform reports the error.\n const found = await Promise.all(specs.map((spec) => readDependencies(resolve(dir, spec)).catch(() => [])))\n return found.flat()\n}\n\nconst handlers: Record<string, (params: never) => unknown> = {\n initialize: () => ({ protocolVersion: 1, positionEncoding: 'utf-16', diagnosticSource: 'kubb' }),\n // `dynamicConfig` in package.json: TypeScript watches `watchedFiles` and opens the project again\n // when one changes, then transforms its specs again when `configIdentity` differs. The files that\n // external `$ref`s read are watched too, so a changed schema file updates the spec that points at it.\n openProject: async ({ projectHandle, configFileName, options }: { projectHandle: string; configFileName?: string; options?: unknown }) => {\n const loading = loadProjectConfig(configFileName ? dirname(configFileName) : process.cwd())\n projects.set(projectHandle, loading)\n const project = await loading\n for (const file of configFileName ? await findDependencies(configFileName) : []) dependencies.add(file)\n // TypeScript only transforms again when the identity changes, so it covers the `$ref` files too.\n const identity = createHash('sha256').update(project.identity)\n for (const file of dependencies) identity.update(`\\0${file}\\0${readOrNull(file) ?? ''}`)\n\n return {\n configIdentity: dependencies.size ? identity.digest('hex') : project.identity,\n watchedFiles: [...new Set([...project.watchedFiles, ...dependencies])],\n ...(options != null && { optionDiagnostics: [{ path: [], messageText: 'openapi-import has no options. Set plugin options in kubb.config.ts.' }] }),\n }\n },\n closeProject: ({ projectHandle }: { projectHandle: string }) => {\n projects.delete(projectHandle)\n return null\n },\n transform: async (params: TransformParams & { projectHandle: string }) => {\n const project = await projects.get(params.projectHandle)\n if (project?.error) return { text: 'export {}', extension: '.ts', diagnostics: [{ messageText: project.error, start: 0, length: 0 }] }\n\n const { dependencies: files, ...result } = await cachedTransform(\n params,\n project && selectConfig({ configs: project.configs, fileName: params.fileName, cwd: project.dir }),\n )\n for (const file of Object.keys(files ?? {})) dependencies.add(file)\n return result\n },\n}\n\nasync function handle({ id, method = '', params }: Message): Promise<void> {\n const handler = handlers[method]\n if (id === undefined) return\n\n try {\n if (!handler) {\n writeProtocol(encode({ id, error: { code: -32601, message: `Unknown method \"${method}\"` } }))\n return\n }\n const result = await handler(params as never)\n writeProtocol(encode({ id, result: result ?? null }))\n } catch (error) {\n writeProtocol(encode({ id, error: { code: -32603, message: error instanceof Error ? (error.stack ?? error.message) : String(error) } }))\n }\n}\n\nprocess.stdin.on(\n 'data',\n createDecoder((message) => void handle(message)),\n)\n"],"mappings":";;;;;;;;;;;;;;AAOA,MAAa,cAAc,SAAgC;CACzD,IAAI;EACF,OAAO,aAAa,MAAM,MAAM;CAClC,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;AASA,SAAgB,eACd,WACoE;CACpE,MAAM,0BAAU,IAAI,IAAgF;CAEpG,MAAM,OAAO,QAAyB,WAAwB;EAC5D,MAAM,SAAS,UAAU,QAAQ,MAAM;EACvC,QAAQ,IAAI,OAAO,UAAU;GAAE,SAAS,OAAO;GAAS;GAAQ;EAAO,CAAC;EACxE,OAAO,YAAY,QAAQ,OAAO,OAAO,QAAQ,CAAC;EAClD,OAAO;CACT;CAEA,OAAO,OAAO,QAAQ,WAAW;EAC/B,MAAM,SAAS,QAAQ,IAAI,OAAO,QAAQ;EAE1C,IAAI,CAAC,UAAU,OAAO,YAAY,OAAO,WAAW,OAAO,WAAW,QAAQ,OAAO,IAAI,QAAQ,MAAM;EAEvG,MAAM,SAAS,MAAM,OAAO;EAE5B,OADc,OAAO,QAAQ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AAW;CAEtB,IAAI;EACF,IAAI,CAAC,SAAS;GACZ,cAAc,OAAO;IAAE;IAAI,OAAO;KAAE,MAAM;KAAQ,SAAS,mBAAmB,OAAO;IAAG;GAAE,CAAC,CAAC;GAC5F;EACF;EACA,MAAM,SAAS,MAAM,QAAQ,MAAe;EAC5C,cAAc,OAAO;GAAE;GAAI,QAAQ,UAAU;EAAK,CAAC,CAAC;CACtD,SAAS,OAAO;EACd,cAAc,OAAO;GAAE;GAAI,OAAO;IAAE,MAAM;IAAQ,SAAS,iBAAiB,QAAS,MAAM,SAAS,MAAM,UAAW,OAAO,KAAK;GAAE;EAAE,CAAC,CAAC;CACzI;AACF;AAEA,QAAQ,MAAM,GACZ,QACA,eAAe,YAAY,KAAK,OAAO,OAAO,CAAC,CACjD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-import",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Import OpenAPI specs in TypeScript with types from Kubb, through TypeScript 7.1 content mappers. No generated files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@kubb/plugin-ts": "^5.1.0",
|
|
53
53
|
"@typescript/typescript6": "^6.0.2",
|
|
54
|
-
"unplugin-kubb": "^5.
|
|
54
|
+
"unplugin-kubb": "^5.15.0",
|
|
55
55
|
"yaml": "^2.9.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@kubb/plugin-zod": "^5.4.12",
|
|
61
61
|
"@types/node": "22.20.2",
|
|
62
62
|
"@vitest/coverage-v8": "^5.0.5",
|
|
63
|
-
"kubb": "^5.
|
|
63
|
+
"kubb": "^5.15.0",
|
|
64
64
|
"oxfmt": "^0.72.0",
|
|
65
65
|
"oxlint": "^1.88.0",
|
|
66
66
|
"tsdown": "^0.23.1",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"vitest": "^5.0.5"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"kubb": "^5.
|
|
71
|
+
"kubb": "^5.14.5"
|
|
72
72
|
},
|
|
73
73
|
"typescript": {
|
|
74
74
|
"contentMapper": {
|
|
@@ -80,8 +80,7 @@
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
|
-
"node": ">=22.12"
|
|
84
|
-
"pnpm": ">=11.0.0"
|
|
83
|
+
"node": ">=22.12"
|
|
85
84
|
},
|
|
86
85
|
"scripts": {
|
|
87
86
|
"build": "tsdown",
|