@kubb/ast 5.0.0-beta.62 → 5.0.0-beta.63
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/dist/{defineMacro-Vw-xQvq7.d.ts → defineMacro-BATi7xoC.d.ts} +4 -5
- package/dist/{defineMacro-BryDiuQl.cjs → defineMacro-CEZHaCXE.cjs} +5 -5
- package/dist/defineMacro-CEZHaCXE.cjs.map +1 -0
- package/dist/{defineMacro-CNkUpxia.js → defineMacro-Shz8f6SG.js} +3 -3
- package/dist/defineMacro-Shz8f6SG.js.map +1 -0
- package/dist/factory.cjs +56 -56
- package/dist/factory.cjs.map +1 -1
- package/dist/factory.d.ts +5 -5
- package/dist/factory.js +5 -5
- package/dist/factory.js.map +1 -1
- package/dist/{index-CTaN_ee_.d.ts → index-B9cc8MBS.d.ts} +46 -113
- package/dist/index.cjs +142 -271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.js +108 -236
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +12 -12
- package/dist/macros.cjs.map +1 -1
- package/dist/macros.d.ts +2 -2
- package/dist/macros.js +4 -4
- package/dist/macros.js.map +1 -1
- package/dist/{operationParams-B44p6EQy.d.ts → operationParams-k5CKwSWZ.d.ts} +9 -2
- package/dist/{visitor-DepQEKyp.js → refs-BjNDuCBD.js} +115 -120
- package/dist/refs-BjNDuCBD.js.map +1 -0
- package/dist/{visitor-B7Zlnp4c.cjs → refs-u5SDdyV7.cjs} +139 -144
- package/dist/refs-u5SDdyV7.cjs.map +1 -0
- package/dist/{response-BeG6hq2D.cjs → schema-BkvrrOAr.cjs} +171 -153
- package/dist/schema-BkvrrOAr.cjs.map +1 -0
- package/dist/{response-Rd1uisM1.js → schema-Cbnxmz4b.js} +166 -154
- package/dist/schema-Cbnxmz4b.js.map +1 -0
- package/dist/{types-DQTgVSwE.d.ts → types-BB_xgRJ3.d.ts} +55 -79
- package/dist/types.d.ts +5 -5
- package/dist/{utils-BDI3kXlb.cjs → utils-CEepwqmb.cjs} +74 -67
- package/dist/utils-CEepwqmb.cjs.map +1 -0
- package/dist/{utils-DW9rnfsD.js → utils-DaXkewb1.js} +56 -49
- package/dist/utils-DaXkewb1.js.map +1 -0
- package/dist/utils.cjs +11 -11
- package/dist/utils.d.ts +44 -29
- package/dist/utils.js +3 -3
- package/package.json +1 -1
- package/src/constants.ts +3 -6
- package/src/defineMacro.ts +1 -1
- package/src/defineNode.ts +6 -9
- package/src/definePrinter.ts +5 -3
- package/src/dialect.ts +23 -13
- package/src/factory.ts +4 -4
- package/src/index.ts +1 -1
- package/src/infer.ts +1 -1
- package/src/macros/macroEnumName.ts +1 -1
- package/src/nodes/code.ts +8 -5
- package/src/nodes/file.ts +5 -4
- package/src/nodes/operation.ts +3 -0
- package/src/nodes/parameter.ts +5 -5
- package/src/nodes/property.ts +5 -5
- package/src/nodes/schema.ts +4 -4
- package/src/optionality.ts +15 -0
- package/src/types.ts +1 -2
- package/src/utils/codegen.ts +6 -7
- package/src/utils/fileMerge.ts +7 -8
- package/src/utils/operationParams.ts +8 -8
- package/src/utils/refs.ts +14 -18
- package/src/utils/schemaGraph.ts +41 -33
- package/src/utils/schemaMerge.ts +2 -2
- package/src/visitor.ts +1 -1
- package/dist/defineMacro-BryDiuQl.cjs.map +0 -1
- package/dist/defineMacro-CNkUpxia.js.map +0 -1
- package/dist/response-BeG6hq2D.cjs.map +0 -1
- package/dist/response-Rd1uisM1.js.map +0 -1
- package/dist/utils-BDI3kXlb.cjs.map +0 -1
- package/dist/utils-DW9rnfsD.js.map +0 -1
- package/dist/visitor-B7Zlnp4c.cjs.map +0 -1
- package/dist/visitor-DepQEKyp.js.map +0 -1
- package/src/dedupe.ts +0 -231
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,113 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
require("./utils-
|
|
5
|
-
const require_defineMacro = require("./defineMacro-
|
|
2
|
+
const require_schema = require("./schema-BkvrrOAr.cjs");
|
|
3
|
+
const require_refs = require("./refs-u5SDdyV7.cjs");
|
|
4
|
+
require("./utils-CEepwqmb.cjs");
|
|
5
|
+
const require_defineMacro = require("./defineMacro-CEZHaCXE.cjs");
|
|
6
6
|
const require_factory = require("./factory.cjs");
|
|
7
7
|
let node_crypto = require("node:crypto");
|
|
8
|
+
//#region src/dialect.ts
|
|
9
|
+
/**
|
|
10
|
+
* Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
|
|
11
|
+
* dialect's type for inference.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* export const oasDialect = defineDialect({
|
|
16
|
+
* name: 'oas',
|
|
17
|
+
* schema: {
|
|
18
|
+
* isNullable,
|
|
19
|
+
* isReference,
|
|
20
|
+
* isDiscriminator,
|
|
21
|
+
* isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',
|
|
22
|
+
* resolveRef,
|
|
23
|
+
* },
|
|
24
|
+
* dedupe: { plan },
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function defineDialect(dialect) {
|
|
29
|
+
return dialect;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/definePrinter.ts
|
|
33
|
+
/**
|
|
34
|
+
* Defines a schema printer: a function that takes a `SchemaNode` and emits
|
|
35
|
+
* code in your target language. Each plugin that produces code from schemas
|
|
36
|
+
* (TypeScript types, Zod schemas, Faker factories) ships a printer built
|
|
37
|
+
* with this helper.
|
|
38
|
+
*
|
|
39
|
+
* The builder receives resolved options and returns:
|
|
40
|
+
*
|
|
41
|
+
* - `name` unique identifier for the printer.
|
|
42
|
+
* - `options` stored on the returned printer instance.
|
|
43
|
+
* - `nodes` map of `SchemaType` → handler. Handlers return the rendered
|
|
44
|
+
* output (a string, a TypeScript AST node, ...) for that schema type.
|
|
45
|
+
* - `print` (optional), top-level override exposed as `printer.print`.
|
|
46
|
+
* Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
|
|
47
|
+
*
|
|
48
|
+
* Without a `print` override, `printer.print` falls back to `printer.transform`
|
|
49
|
+
* (the node-level dispatcher).
|
|
50
|
+
*
|
|
51
|
+
* @example Tiny Zod printer
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'
|
|
54
|
+
*
|
|
55
|
+
* type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
|
|
56
|
+
*
|
|
57
|
+
* export const zodPrinter = definePrinter<PrinterZod>((options) => ({
|
|
58
|
+
* name: 'zod',
|
|
59
|
+
* options: { strict: options.strict ?? true },
|
|
60
|
+
* nodes: {
|
|
61
|
+
* string: () => 'z.string()',
|
|
62
|
+
* object(node) {
|
|
63
|
+
* const props = node.properties
|
|
64
|
+
* .map((p) => `${p.name}: ${this.transform(p.schema)}`)
|
|
65
|
+
* .join(', ')
|
|
66
|
+
* return `z.object({ ${props} })`
|
|
67
|
+
* },
|
|
68
|
+
* },
|
|
69
|
+
* }))
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function definePrinter(build) {
|
|
73
|
+
return createPrinterFactory((node) => node.type)(build);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Generic printer factory behind `definePrinter`. Pass a `getKey` function that maps a node to its
|
|
77
|
+
* handler key, and it returns a `definePrinter`-style helper for that node and key type. `definePrinter`
|
|
78
|
+
* itself is this factory keyed by `node.type`.
|
|
79
|
+
*
|
|
80
|
+
* @example Key a printer by `node.kind` instead of `node.type`
|
|
81
|
+
* ```ts
|
|
82
|
+
* const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(
|
|
83
|
+
* (node) => node.kind,
|
|
84
|
+
* )
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
function createPrinterFactory(getKey) {
|
|
88
|
+
return function(build) {
|
|
89
|
+
return (options) => {
|
|
90
|
+
const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? {});
|
|
91
|
+
const context = {
|
|
92
|
+
options: resolvedOptions,
|
|
93
|
+
transform: (node) => {
|
|
94
|
+
const key = getKey(node);
|
|
95
|
+
if (key === null) return null;
|
|
96
|
+
const handler = nodes[key];
|
|
97
|
+
if (!handler) return null;
|
|
98
|
+
return handler.call(context, node);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
name,
|
|
103
|
+
options: resolvedOptions,
|
|
104
|
+
transform: context.transform,
|
|
105
|
+
print: printOverride ? printOverride.bind(context) : context.transform
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
8
111
|
//#region src/signature.ts
|
|
9
112
|
/**
|
|
10
113
|
* The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.
|
|
@@ -13,7 +116,7 @@ function flagsDescriptor(node) {
|
|
|
13
116
|
return `${node.primitive ?? ""};${node.format ?? ""};${node.nullable ? 1 : 0}`;
|
|
14
117
|
}
|
|
15
118
|
function refTargetName(node) {
|
|
16
|
-
if (node.ref) return
|
|
119
|
+
if (node.ref) return require_refs.extractRefName(node.ref);
|
|
17
120
|
return node.name ?? "";
|
|
18
121
|
}
|
|
19
122
|
const arrayTupleFields = [
|
|
@@ -257,284 +360,52 @@ function signatureOf(node) {
|
|
|
257
360
|
return signature;
|
|
258
361
|
}
|
|
259
362
|
//#endregion
|
|
260
|
-
//#region src/dedupe.ts
|
|
261
|
-
/**
|
|
262
|
-
* Builds the shared `ref` replacement for a duplicate occurrence, carrying the
|
|
263
|
-
* usage-slot and documentation fields that are not part of the canonical type.
|
|
264
|
-
*/
|
|
265
|
-
function createRefNode(node, canonical) {
|
|
266
|
-
return require_response.createSchema({
|
|
267
|
-
type: "ref",
|
|
268
|
-
name: canonical.name,
|
|
269
|
-
ref: canonical.ref,
|
|
270
|
-
optional: node.optional,
|
|
271
|
-
nullish: node.nullish,
|
|
272
|
-
readOnly: node.readOnly,
|
|
273
|
-
writeOnly: node.writeOnly,
|
|
274
|
-
deprecated: node.deprecated,
|
|
275
|
-
description: node.description,
|
|
276
|
-
default: node.default,
|
|
277
|
-
example: node.example
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
function applyDedupe(node, plan, skipRootMatch = false) {
|
|
281
|
-
const { canonicalBySignature, aliasNames } = plan;
|
|
282
|
-
if (canonicalBySignature.size === 0 && aliasNames.size === 0) return node;
|
|
283
|
-
const root = node;
|
|
284
|
-
return require_visitor.transform(node, { schema(schemaNode) {
|
|
285
|
-
if (schemaNode.type === "ref") {
|
|
286
|
-
const target = schemaNode.ref ? require_visitor.extractRefName(schemaNode.ref) : schemaNode.name;
|
|
287
|
-
const canonical = target ? aliasNames.get(target) : void 0;
|
|
288
|
-
return canonical ? {
|
|
289
|
-
...schemaNode,
|
|
290
|
-
name: canonical.name,
|
|
291
|
-
ref: canonical.ref
|
|
292
|
-
} : void 0;
|
|
293
|
-
}
|
|
294
|
-
const signature = signatureOf(schemaNode);
|
|
295
|
-
if (skipRootMatch && schemaNode === root) return void 0;
|
|
296
|
-
const canonical = canonicalBySignature.get(signature);
|
|
297
|
-
if (!canonical) return void 0;
|
|
298
|
-
return createRefNode(schemaNode, canonical);
|
|
299
|
-
} });
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Strips usage-slot flags from a hoisted definition and applies its canonical name.
|
|
303
|
-
* A standalone definition is never optional, so `optional`/`nullish` are cleared.
|
|
304
|
-
*/
|
|
305
|
-
function cleanDefinition(node, name) {
|
|
306
|
-
return {
|
|
307
|
-
...node,
|
|
308
|
-
name,
|
|
309
|
-
optional: void 0,
|
|
310
|
-
nullish: void 0
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.
|
|
315
|
-
*
|
|
316
|
-
* A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence
|
|
317
|
-
* is a named top-level schema, the first one becomes the canonical (so other top-level
|
|
318
|
-
* duplicates and inline copies turn into references to it). Every other top-level name with
|
|
319
|
-
* the same content is recorded in `aliasNames`, so refs to it can be repointed at the
|
|
320
|
-
* canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied
|
|
321
|
-
* per node with {@link applyDedupe}.
|
|
322
|
-
*
|
|
323
|
-
* @example
|
|
324
|
-
* ```ts
|
|
325
|
-
* const plan = buildDedupePlan([...schemaNodes, ...operationNodes], {
|
|
326
|
-
* isCandidate: (node) => node.type === 'enum' || node.type === 'object',
|
|
327
|
-
* nameFor: (node) => node.name ?? null,
|
|
328
|
-
* refFor: (name) => `#/components/schemas/${name}`,
|
|
329
|
-
* })
|
|
330
|
-
* ```
|
|
331
|
-
*/
|
|
332
|
-
function buildDedupePlan(roots, options) {
|
|
333
|
-
const { isCandidate, nameFor, refFor, minOccurrences = 2 } = options;
|
|
334
|
-
const topLevelNodes = /* @__PURE__ */ new Set();
|
|
335
|
-
const groups = /* @__PURE__ */ new Map();
|
|
336
|
-
function record(schemaNode) {
|
|
337
|
-
if (!isCandidate(schemaNode)) return;
|
|
338
|
-
const signature = signatureOf(schemaNode);
|
|
339
|
-
const isTopLevel = topLevelNodes.has(schemaNode) && !!schemaNode.name;
|
|
340
|
-
const group = groups.get(signature);
|
|
341
|
-
if (group) {
|
|
342
|
-
group.count++;
|
|
343
|
-
if (isTopLevel) group.topLevelNames.push(schemaNode.name);
|
|
344
|
-
} else groups.set(signature, {
|
|
345
|
-
count: 1,
|
|
346
|
-
representative: schemaNode,
|
|
347
|
-
topLevelNames: isTopLevel ? [schemaNode.name] : []
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
for (const root of roots) {
|
|
351
|
-
if (root.kind === "Schema") topLevelNodes.add(root);
|
|
352
|
-
for (const schemaNode of require_visitor.collectLazy(root, { schema: (node) => node })) record(schemaNode);
|
|
353
|
-
}
|
|
354
|
-
const canonicalBySignature = /* @__PURE__ */ new Map();
|
|
355
|
-
const aliasNames = /* @__PURE__ */ new Map();
|
|
356
|
-
const pendingHoists = [];
|
|
357
|
-
for (const [signature, group] of groups) {
|
|
358
|
-
if (group.count < minOccurrences) continue;
|
|
359
|
-
const [firstName, ...duplicateNames] = group.topLevelNames;
|
|
360
|
-
if (firstName) {
|
|
361
|
-
const canonical = {
|
|
362
|
-
name: firstName,
|
|
363
|
-
ref: refFor(firstName)
|
|
364
|
-
};
|
|
365
|
-
canonicalBySignature.set(signature, canonical);
|
|
366
|
-
for (const duplicate of duplicateNames) aliasNames.set(duplicate, canonical);
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
const name = nameFor(group.representative, signature);
|
|
370
|
-
if (!name) continue;
|
|
371
|
-
canonicalBySignature.set(signature, {
|
|
372
|
-
name,
|
|
373
|
-
ref: refFor(name)
|
|
374
|
-
});
|
|
375
|
-
pendingHoists.push({
|
|
376
|
-
name,
|
|
377
|
-
representative: group.representative
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
canonicalBySignature,
|
|
382
|
-
aliasNames,
|
|
383
|
-
hoisted: pendingHoists.map(({ name, representative }) => cleanDefinition(applyDedupe(representative, {
|
|
384
|
-
canonicalBySignature,
|
|
385
|
-
aliasNames
|
|
386
|
-
}, true), name))
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
//#endregion
|
|
390
|
-
//#region src/dialect.ts
|
|
391
|
-
/**
|
|
392
|
-
* Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
|
|
393
|
-
* dialect's type for inference.
|
|
394
|
-
*
|
|
395
|
-
* @example
|
|
396
|
-
* ```ts
|
|
397
|
-
* export const oasDialect = defineDialect({
|
|
398
|
-
* name: 'oas',
|
|
399
|
-
* schema: {
|
|
400
|
-
* isNullable,
|
|
401
|
-
* isReference,
|
|
402
|
-
* isDiscriminator,
|
|
403
|
-
* isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',
|
|
404
|
-
* resolveRef,
|
|
405
|
-
* optionality,
|
|
406
|
-
* },
|
|
407
|
-
* })
|
|
408
|
-
* ```
|
|
409
|
-
*/
|
|
410
|
-
function defineDialect(dialect) {
|
|
411
|
-
return dialect;
|
|
412
|
-
}
|
|
413
|
-
//#endregion
|
|
414
|
-
//#region src/definePrinter.ts
|
|
415
|
-
/**
|
|
416
|
-
* Defines a schema printer: a function that takes a `SchemaNode` and emits
|
|
417
|
-
* code in your target language. Each plugin that produces code from schemas
|
|
418
|
-
* (TypeScript types, Zod schemas, Faker factories) ships a printer built
|
|
419
|
-
* with this helper.
|
|
420
|
-
*
|
|
421
|
-
* The builder receives resolved options and returns:
|
|
422
|
-
*
|
|
423
|
-
* - `name` unique identifier for the printer.
|
|
424
|
-
* - `options` stored on the returned printer instance.
|
|
425
|
-
* - `nodes` map of `SchemaType` → handler. Handlers return the rendered
|
|
426
|
-
* output (a string, a TypeScript AST node, ...) for that schema type.
|
|
427
|
-
* - `print` (optional), top-level override exposed as `printer.print`.
|
|
428
|
-
* Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
|
|
429
|
-
*
|
|
430
|
-
* Without a `print` override, `printer.print` falls back to `printer.transform`
|
|
431
|
-
* (the node-level dispatcher).
|
|
432
|
-
*
|
|
433
|
-
* @example Tiny Zod printer
|
|
434
|
-
* ```ts
|
|
435
|
-
* import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'
|
|
436
|
-
*
|
|
437
|
-
* type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
|
|
438
|
-
*
|
|
439
|
-
* export const zodPrinter = definePrinter<PrinterZod>((options) => ({
|
|
440
|
-
* name: 'zod',
|
|
441
|
-
* options: { strict: options.strict ?? true },
|
|
442
|
-
* nodes: {
|
|
443
|
-
* string: () => 'z.string()',
|
|
444
|
-
* object(node) {
|
|
445
|
-
* const props = node.properties
|
|
446
|
-
* .map((p) => `${p.name}: ${this.transform(p.schema)}`)
|
|
447
|
-
* .join(', ')
|
|
448
|
-
* return `z.object({ ${props} })`
|
|
449
|
-
* },
|
|
450
|
-
* },
|
|
451
|
-
* }))
|
|
452
|
-
* ```
|
|
453
|
-
*/
|
|
454
|
-
function definePrinter(build) {
|
|
455
|
-
return createPrinterFactory((node) => node.type)(build);
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.
|
|
459
|
-
*
|
|
460
|
-
* @example
|
|
461
|
-
* ```ts
|
|
462
|
-
* export const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(
|
|
463
|
-
* (node) => node.kind,
|
|
464
|
-
* )
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
function createPrinterFactory(getKey) {
|
|
468
|
-
return function(build) {
|
|
469
|
-
return (options) => {
|
|
470
|
-
const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? {});
|
|
471
|
-
const context = {
|
|
472
|
-
options: resolvedOptions,
|
|
473
|
-
transform: (node) => {
|
|
474
|
-
const key = getKey(node);
|
|
475
|
-
if (key === null) return null;
|
|
476
|
-
const handler = nodes[key];
|
|
477
|
-
if (!handler) return null;
|
|
478
|
-
return handler.call(context, node);
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
return {
|
|
482
|
-
name,
|
|
483
|
-
options: resolvedOptions,
|
|
484
|
-
transform: context.transform,
|
|
485
|
-
print: printOverride ? printOverride.bind(context) : context.transform
|
|
486
|
-
};
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
//#endregion
|
|
491
|
-
exports.applyDedupe = applyDedupe;
|
|
492
363
|
exports.applyMacros = require_defineMacro.applyMacros;
|
|
493
|
-
exports.arrowFunctionDef =
|
|
494
|
-
exports.breakDef =
|
|
495
|
-
exports.
|
|
496
|
-
exports.collect = require_visitor.collect;
|
|
364
|
+
exports.arrowFunctionDef = require_schema.arrowFunctionDef;
|
|
365
|
+
exports.breakDef = require_schema.breakDef;
|
|
366
|
+
exports.collect = require_refs.collect;
|
|
497
367
|
exports.composeMacros = require_defineMacro.composeMacros;
|
|
498
|
-
exports.constDef =
|
|
499
|
-
exports.contentDef =
|
|
368
|
+
exports.constDef = require_schema.constDef;
|
|
369
|
+
exports.contentDef = require_schema.contentDef;
|
|
500
370
|
exports.createPrinterFactory = createPrinterFactory;
|
|
501
371
|
exports.defineDialect = defineDialect;
|
|
502
372
|
exports.defineMacro = require_defineMacro.defineMacro;
|
|
503
|
-
exports.defineNode =
|
|
373
|
+
exports.defineNode = require_schema.defineNode;
|
|
504
374
|
exports.definePrinter = definePrinter;
|
|
505
|
-
exports.exportDef =
|
|
375
|
+
exports.exportDef = require_schema.exportDef;
|
|
506
376
|
Object.defineProperty(exports, "factory", {
|
|
507
377
|
enumerable: true,
|
|
508
378
|
get: function() {
|
|
509
379
|
return require_factory.factory_exports;
|
|
510
380
|
}
|
|
511
381
|
});
|
|
512
|
-
exports.fileDef =
|
|
513
|
-
exports.functionDef =
|
|
514
|
-
exports.functionParameterDef =
|
|
515
|
-
exports.functionParametersDef =
|
|
516
|
-
exports.importDef =
|
|
517
|
-
exports.indexedAccessTypeDef =
|
|
518
|
-
exports.inputDef =
|
|
519
|
-
exports.isHttpOperationNode =
|
|
520
|
-
exports.jsxDef =
|
|
521
|
-
exports.narrowSchema =
|
|
522
|
-
exports.nodeDefs =
|
|
523
|
-
exports.objectBindingPatternDef =
|
|
524
|
-
exports.operationDef =
|
|
525
|
-
exports.
|
|
526
|
-
exports.
|
|
527
|
-
exports.
|
|
528
|
-
exports.
|
|
529
|
-
exports.
|
|
530
|
-
exports.
|
|
531
|
-
exports.
|
|
382
|
+
exports.fileDef = require_schema.fileDef;
|
|
383
|
+
exports.functionDef = require_schema.functionDef;
|
|
384
|
+
exports.functionParameterDef = require_schema.functionParameterDef;
|
|
385
|
+
exports.functionParametersDef = require_schema.functionParametersDef;
|
|
386
|
+
exports.importDef = require_schema.importDef;
|
|
387
|
+
exports.indexedAccessTypeDef = require_schema.indexedAccessTypeDef;
|
|
388
|
+
exports.inputDef = require_schema.inputDef;
|
|
389
|
+
exports.isHttpOperationNode = require_refs.isHttpOperationNode;
|
|
390
|
+
exports.jsxDef = require_schema.jsxDef;
|
|
391
|
+
exports.narrowSchema = require_refs.narrowSchema;
|
|
392
|
+
exports.nodeDefs = require_refs.nodeDefs;
|
|
393
|
+
exports.objectBindingPatternDef = require_schema.objectBindingPatternDef;
|
|
394
|
+
exports.operationDef = require_schema.operationDef;
|
|
395
|
+
exports.optionality = require_schema.optionality;
|
|
396
|
+
exports.outputDef = require_schema.outputDef;
|
|
397
|
+
exports.parameterDef = require_schema.parameterDef;
|
|
398
|
+
exports.propertyDef = require_schema.propertyDef;
|
|
399
|
+
exports.requestBodyDef = require_schema.requestBodyDef;
|
|
400
|
+
exports.responseDef = require_schema.responseDef;
|
|
401
|
+
exports.schemaDef = require_schema.schemaDef;
|
|
402
|
+
exports.schemaTypes = require_refs.schemaTypes;
|
|
532
403
|
exports.signatureOf = signatureOf;
|
|
533
|
-
exports.sourceDef =
|
|
534
|
-
exports.textDef =
|
|
535
|
-
exports.transform =
|
|
536
|
-
exports.typeDef =
|
|
537
|
-
exports.typeLiteralDef =
|
|
538
|
-
exports.walk =
|
|
404
|
+
exports.sourceDef = require_schema.sourceDef;
|
|
405
|
+
exports.textDef = require_schema.textDef;
|
|
406
|
+
exports.transform = require_refs.transform;
|
|
407
|
+
exports.typeDef = require_schema.typeDef;
|
|
408
|
+
exports.typeLiteralDef = require_schema.typeLiteralDef;
|
|
409
|
+
exports.walk = require_refs.walk;
|
|
539
410
|
|
|
540
411
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["extractRefName","obj","createSchema","transform","extractRefName","collectLazy"],"sources":["../src/signature.ts","../src/dedupe.ts","../src/dialect.ts","../src/definePrinter.ts"],"sourcesContent":["import { hash } from 'node:crypto'\nimport type { SchemaNode } from './nodes/index.ts'\nimport { extractRefName } from './utils/index.ts'\n\n/**\n * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.\n */\nfunction flagsDescriptor(node: SchemaNode): string {\n return `${node.primitive ?? ''};${node.format ?? ''};${node.nullable ? 1 : 0}`\n}\n\nfunction refTargetName(node: Extract<SchemaNode, { type: 'ref' }>): string {\n if (node.ref) return extractRefName(node.ref)\n return node.name ?? ''\n}\n\ntype ScalarField = { kind: 'scalar'; key: string; prefix: string }\ntype BoolField = { kind: 'bool'; key: string; prefix: string }\ntype ChildField = { kind: 'child'; key: string; prefix: string }\ntype ChildrenField = { kind: 'children'; key: string; prefix: string }\ntype ObjectPropsField = { kind: 'objectProps' }\ntype AdditionalPropsField = { kind: 'additionalProps' }\ntype PatternPropsField = { kind: 'patternProps' }\ntype EnumValuesField = { kind: 'enumValues' }\ntype RefTargetField = { kind: 'refTarget' }\n\ntype ShapeField =\n | ScalarField\n | BoolField\n | ChildField\n | ChildrenField\n | ObjectPropsField\n | AdditionalPropsField\n | PatternPropsField\n | EnumValuesField\n | RefTargetField\n\nconst arrayTupleFields: ReadonlyArray<ShapeField> = [\n { kind: 'children', key: 'items', prefix: 'i' },\n { kind: 'child', key: 'rest', prefix: 'r' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'bool', key: 'unique', prefix: 'u' },\n]\n\nconst numericFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'exclusiveMinimum', prefix: 'emn' },\n { kind: 'scalar', key: 'exclusiveMaximum', prefix: 'emx' },\n { kind: 'scalar', key: 'multipleOf', prefix: 'mo' },\n]\n\nconst rangeFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n]\n\n/**\n * Maps each node `type` to its ordered shape-contributing fields. Types absent from the map\n * (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.\n */\nconst SHAPE_KEYS: Partial<Record<SchemaNode['type'], ReadonlyArray<ShapeField>>> = {\n object: [\n { kind: 'objectProps' },\n { kind: 'additionalProps' },\n { kind: 'patternProps' },\n { kind: 'scalar', key: 'minProperties', prefix: 'mn' },\n { kind: 'scalar', key: 'maxProperties', prefix: 'mx' },\n ],\n array: arrayTupleFields,\n tuple: arrayTupleFields,\n union: [\n { kind: 'scalar', key: 'strategy', prefix: 's' },\n { kind: 'scalar', key: 'discriminatorPropertyName', prefix: 'd' },\n { kind: 'children', key: 'members', prefix: 'm' },\n ],\n intersection: [{ kind: 'children', key: 'members', prefix: 'm' }],\n enum: [{ kind: 'enumValues' }],\n ref: [{ kind: 'refTarget' }],\n string: [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'pattern', prefix: 'pt' },\n ],\n number: numericFields,\n integer: numericFields,\n bigint: numericFields,\n url: [\n { kind: 'scalar', key: 'path', prefix: 'path' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n ],\n uuid: rangeFields,\n email: rangeFields,\n datetime: [\n { kind: 'bool', key: 'offset', prefix: 'o' },\n { kind: 'bool', key: 'local', prefix: 'l' },\n ],\n date: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n time: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n}\n\nfunction serializeShapeField(field: ShapeField, node: SchemaNode, record: Record<string, unknown>): string {\n switch (field.kind) {\n case 'scalar':\n return `${field.prefix}:${record[field.key] ?? ''}`\n case 'bool':\n return `${field.prefix}:${record[field.key] ? 1 : 0}`\n case 'child': {\n const child = record[field.key] as SchemaNode | undefined\n return `${field.prefix}:${child ? signatureOf(child) : ''}`\n }\n case 'children': {\n const children = (record[field.key] as Array<SchemaNode> | undefined) ?? []\n return `${field.prefix}[${children.map((c) => signatureOf(c)).join(',')}]`\n }\n case 'objectProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const props = (obj.properties ?? []).map((prop) => `${prop.name}${prop.required ? '!' : '?'}${signatureOf(prop.schema)}`).join(',')\n return `p[${props}]`\n }\n case 'additionalProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n if (typeof obj.additionalProperties === 'boolean') return `ab:${obj.additionalProperties}`\n if (obj.additionalProperties) return `as:${signatureOf(obj.additionalProperties)}`\n return ''\n }\n case 'patternProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const pattern = obj.patternProperties\n ? Object.keys(obj.patternProperties)\n .sort()\n .map((key) => `${key}=${signatureOf(obj.patternProperties![key]!)}`)\n .join(',')\n : ''\n return `pp[${pattern}]`\n }\n case 'enumValues': {\n const en = node as Extract<SchemaNode, { type: 'enum' }>\n let values = ''\n if (en.namedEnumValues?.length) {\n values = en.namedEnumValues.map((entry) => `${entry.name}=${entry.primitive}:${String(entry.value)}`).join(',')\n } else if (en.enumValues?.length) {\n values = en.enumValues.map((value) => `${value === null ? 'null' : typeof value}:${String(value)}`).join(',')\n }\n return `v[${values}]`\n }\n case 'refTarget': {\n return `->${refTargetName(node as Extract<SchemaNode, { type: 'ref' }>)}`\n }\n }\n}\n\n/**\n * Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,\n * constraints, and its children's signatures.\n */\nfunction describeShape(node: SchemaNode): string {\n const flags = flagsDescriptor(node)\n const fields = SHAPE_KEYS[node.type]\n if (!fields) return `${node.type}|${flags}`\n\n const record = node as unknown as Record<string, unknown>\n const parts: Array<string> = [`${node.type}|${flags}`]\n for (const field of fields) {\n parts.push(serializeShapeField(field, node, record))\n }\n return parts.join('|')\n}\n\n/**\n * Caches the digest per node, keyed by identity. A `WeakMap` so entries die with the node, and so\n * a tree hashed during dedupe planning is not walked again when it is rewritten during streaming.\n * Reuse is safe because a signature depends only on content, and nodes are immutable once created.\n */\nconst signatureCache = new WeakMap<SchemaNode, string>()\n\n/**\n * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas\n * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,\n * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,\n * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`\n * nodes compare by target name, which also terminates on circular shapes.\n *\n * @example Two enums with different descriptions share a signature\n * ```ts\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))\n * ```\n */\nexport function signatureOf(node: SchemaNode): string {\n const cached = signatureCache.get(node)\n if (cached !== undefined) return cached\n const signature = hash('sha256', describeShape(node), 'hex')\n signatureCache.set(node, signature)\n\n return signature\n}\n\n/**\n * Returns `true` when two schema nodes are structurally identical under shape-only equality,\n * meaning they produce the same TypeScript type.\n */\nexport function isSchemaEqual(a: SchemaNode, b: SchemaNode): boolean {\n return signatureOf(a) === signatureOf(b)\n}\n","import type { Node, OperationNode, SchemaNode } from './nodes/index.ts'\nimport { createSchema } from './nodes/schema.ts'\nimport { signatureOf } from './signature.ts'\nimport { extractRefName } from './utils/index.ts'\nimport { collectLazy, transform } from './visitor.ts'\n\n/**\n * A canonical destination for a deduplicated shape: the shared schema name and\n * the synthetic `$ref` path that points at it.\n */\nexport type DedupeCanonical = {\n /**\n * Canonical schema name every duplicate occurrence refers to.\n */\n name: string\n /**\n * `$ref` path stored on the generated `ref` nodes (for example `#/components/schemas/Status`).\n */\n ref: string\n}\n\n/**\n * The result of {@link buildDedupePlan}: a lookup from structural signature to its\n * canonical target, plus the freshly hoisted definitions that must be added to\n * the schema list.\n */\nexport type DedupePlan = {\n /**\n * Maps a structural signature to the canonical schema that represents it.\n */\n canonicalBySignature: Map<string, DedupeCanonical>\n /**\n * Maps the name of a top-level schema that duplicates a canonical one to that canonical, so\n * references to the duplicate can be repointed at the first schema with the same content.\n */\n aliasNames: Map<string, DedupeCanonical>\n /**\n * New top-level schema definitions created for inline shapes that had no existing\n * named component. Nested duplicates inside each definition are already collapsed.\n */\n hoisted: Array<SchemaNode>\n}\n\n/**\n * The lookups {@link applyDedupe} needs from a {@link DedupePlan}.\n */\nexport type DedupeLookups = Pick<DedupePlan, 'canonicalBySignature' | 'aliasNames'>\n\n/**\n * Options that inject the naming and candidate policy into {@link buildDedupePlan}.\n * The mechanics (grouping, counting, rewriting) live here. The policy lives in the caller.\n */\nexport type BuildDedupePlanOptions = {\n /**\n * Returns `true` when a node should be deduplicated. This is the only gate, so it must\n * reject both ineligible kinds (return `false` for anything other than, say, enums and\n * objects) and unsafe shapes (e.g. nodes that reference a circular schema).\n */\n isCandidate: (node: SchemaNode) => boolean\n /**\n * Produces the canonical name for an inline shape with no existing named component.\n * Return `null` to leave the shape inline (for example when no contextual name exists).\n */\n nameFor: (node: SchemaNode, signature: string) => string | null\n /**\n * Builds the `$ref` path for a canonical name.\n */\n refFor: (name: string) => string\n /**\n * Minimum number of occurrences before a shape is deduplicated.\n *\n * @default 2\n */\n minOccurrences?: number\n}\n\n/**\n * Builds the shared `ref` replacement for a duplicate occurrence, carrying the\n * usage-slot and documentation fields that are not part of the canonical type.\n */\nfunction createRefNode(node: SchemaNode, canonical: DedupeCanonical): SchemaNode {\n return createSchema({\n type: 'ref',\n name: canonical.name,\n ref: canonical.ref,\n optional: node.optional,\n nullish: node.nullish,\n readOnly: node.readOnly,\n writeOnly: node.writeOnly,\n deprecated: node.deprecated,\n description: node.description,\n default: node.default,\n example: node.example,\n })\n}\n\n/**\n * Rewrites a node, replacing every candidate sub-schema whose signature has a canonical\n * target with a `ref` to that target. Replacing a node with a `ref` prunes its subtree,\n * so nested duplicates inside a replaced shape are not visited again. A `ref` that points\n * at a duplicate top-level schema (see `aliasNames`) is repointed at the first schema with\n * the same content.\n *\n * Pass `skipRootMatch` when rewriting a canonical definition so its own root is not\n * turned into a reference to itself. Nested duplicates are still collapsed.\n *\n * @example\n * ```ts\n * const next = applyDedupe(operationNode, plan)\n * ```\n */\nexport function applyDedupe(node: SchemaNode, plan: DedupeLookups, skipRootMatch?: boolean): SchemaNode\nexport function applyDedupe(node: OperationNode, plan: DedupeLookups, skipRootMatch?: boolean): OperationNode\nexport function applyDedupe(node: Node, plan: DedupeLookups, skipRootMatch = false): Node {\n const { canonicalBySignature, aliasNames } = plan\n if (canonicalBySignature.size === 0 && aliasNames.size === 0) return node\n\n const root = node\n\n return transform(node, {\n schema(schemaNode) {\n if (schemaNode.type === 'ref') {\n const target = schemaNode.ref ? extractRefName(schemaNode.ref) : schemaNode.name\n const canonical = target ? aliasNames.get(target) : undefined\n\n return canonical ? { ...schemaNode, name: canonical.name, ref: canonical.ref } : undefined\n }\n\n const signature = signatureOf(schemaNode)\n if (skipRootMatch && schemaNode === root) return undefined\n\n const canonical = canonicalBySignature.get(signature)\n if (!canonical) return undefined\n\n return createRefNode(schemaNode, canonical)\n },\n })\n}\n\n/**\n * Strips usage-slot flags from a hoisted definition and applies its canonical name.\n * A standalone definition is never optional, so `optional`/`nullish` are cleared.\n */\nfunction cleanDefinition(node: SchemaNode, name: string): SchemaNode {\n return { ...node, name, optional: undefined, nullish: undefined }\n}\n\n/**\n * Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.\n *\n * A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence\n * is a named top-level schema, the first one becomes the canonical (so other top-level\n * duplicates and inline copies turn into references to it). Every other top-level name with\n * the same content is recorded in `aliasNames`, so refs to it can be repointed at the\n * canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied\n * per node with {@link applyDedupe}.\n *\n * @example\n * ```ts\n * const plan = buildDedupePlan([...schemaNodes, ...operationNodes], {\n * isCandidate: (node) => node.type === 'enum' || node.type === 'object',\n * nameFor: (node) => node.name ?? null,\n * refFor: (name) => `#/components/schemas/${name}`,\n * })\n * ```\n */\nexport function buildDedupePlan(roots: ReadonlyArray<Node>, options: BuildDedupePlanOptions): DedupePlan {\n const { isCandidate, nameFor, refFor, minOccurrences = 2 } = options\n\n const topLevelNodes = new Set<SchemaNode>()\n\n type Group = {\n count: number\n representative: SchemaNode\n topLevelNames: Array<string>\n }\n const groups = new Map<string, Group>()\n\n function record(schemaNode: SchemaNode): void {\n if (!isCandidate(schemaNode)) return\n const signature = signatureOf(schemaNode)\n\n const isTopLevel = topLevelNodes.has(schemaNode) && !!schemaNode.name\n const group = groups.get(signature)\n if (group) {\n group.count++\n if (isTopLevel) group.topLevelNames.push(schemaNode.name!)\n } else {\n groups.set(signature, { count: 1, representative: schemaNode, topLevelNames: isTopLevel ? [schemaNode.name!] : [] })\n }\n }\n\n for (const root of roots) {\n if (root.kind === 'Schema') topLevelNodes.add(root)\n for (const schemaNode of collectLazy<SchemaNode>(root, { schema: (node) => node })) {\n record(schemaNode)\n }\n }\n\n const canonicalBySignature = new Map<string, DedupeCanonical>()\n const aliasNames = new Map<string, DedupeCanonical>()\n const pendingHoists: Array<{ name: string; representative: SchemaNode }> = []\n\n for (const [signature, group] of groups) {\n if (group.count < minOccurrences) continue\n\n const [firstName, ...duplicateNames] = group.topLevelNames\n if (firstName) {\n const canonical: DedupeCanonical = { name: firstName, ref: refFor(firstName) }\n canonicalBySignature.set(signature, canonical)\n for (const duplicate of duplicateNames) {\n aliasNames.set(duplicate, canonical)\n }\n continue\n }\n\n const name = nameFor(group.representative, signature)\n if (!name) continue\n\n canonicalBySignature.set(signature, { name, ref: refFor(name) })\n pendingHoists.push({ name, representative: group.representative })\n }\n\n // Build hoisted definitions only after every canonical name is known, so nested\n // duplicates inside a definition also resolve to refs.\n const hoisted = pendingHoists.map(({ name, representative }) =>\n cleanDefinition(applyDedupe(representative, { canonicalBySignature, aliasNames }, true), name),\n )\n\n return { canonicalBySignature, aliasNames, hoisted }\n}\n","import type { SchemaNode } from './nodes/index.ts'\n\n/**\n * The spec-specific questions a schema parser answers while turning a source document into Kubb\n * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where\n * OpenAPI, AsyncAPI, and plain JSON Schema differ.\n */\nexport type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Whether the schema is nullable.\n */\n isNullable(schema?: TSchema): boolean\n /**\n * Whether the value is a `$ref` pointer.\n */\n isReference(value?: unknown): value is TRef\n /**\n * Whether the schema carries a discriminator for polymorphism.\n */\n isDiscriminator(value?: unknown): value is TDiscriminated\n /**\n * Whether the schema is binary data, converted to a `blob` node.\n */\n isBinary(schema: TSchema): boolean\n /**\n * Resolves a local `$ref` against the document, or nullish when it cannot.\n */\n resolveRef<TResolved>(document: TDocument, ref: string): TResolved | null | undefined\n /**\n * Derives a schema's `optional`/`nullish` flags from a parent's `required` value and the\n * schema's own `nullable`. How \"required\" and \"nullable\" combine is spec-specific, so the\n * dialect owns it. Method syntax keeps a concrete dialect assignable to the base\n * `SchemaDialect` (bivariant parameters).\n */\n optionality(schema: SchemaNode, required: boolean): SchemaNode\n}\n\n/**\n * A spec adapter's dialect. `name` identifies it in logs and diagnostics; `schema` holds the\n * spec-specific schema questions the parser answers.\n */\nexport type Dialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Identifies the dialect in logs and diagnostics.\n */\n name: string\n /**\n * The spec-specific schema behavior. See {@link SchemaDialect}.\n */\n schema: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>\n}\n\n/**\n * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the\n * dialect's type for inference.\n *\n * @example\n * ```ts\n * export const oasDialect = defineDialect({\n * name: 'oas',\n * schema: {\n * isNullable,\n * isReference,\n * isDiscriminator,\n * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',\n * resolveRef,\n * optionality,\n * },\n * })\n * ```\n */\nexport function defineDialect<TSchema, TRef, TDiscriminated, TDocument>(\n dialect: Dialect<TSchema, TRef, TDiscriminated, TDocument>,\n): Dialect<TSchema, TRef, TDiscriminated, TDocument> {\n return dialect\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * }\n * ```\n */\ntype PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n */\n transform: (node: SchemaNode) => TOutput | null\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\ntype PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\ntype PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n/**\n * Defines a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'\n *\n * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return createPrinterFactory<SchemaNode, SchemaType, SchemaNodeByType>((node) => node.type)(build) as (options?: T['options']) => Printer<T>\n}\n\n/**\n * Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.\n *\n * @example\n * ```ts\n * export const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(\n * (node) => node.kind,\n * )\n * ```\n */\nexport function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | null) {\n return function <T extends PrinterFactoryOptions>(\n build: (options: T['options']) => {\n name: T['name']\n options: T['options']\n nodes: Partial<{\n [K in TKey]: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNodeByKey[K],\n ) => T['output'] | null\n }>\n print?: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNode,\n ) => T['printOutput'] | null\n },\n ): (options?: T['options']) => {\n name: T['name']\n options: T['options']\n transform: (node: TNode) => T['output'] | null\n print: (node: TNode) => T['printOutput'] | null\n } {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: TNode): T['output'] | null => {\n const key = getKey(node)\n if (key === null) return null\n\n const handler = nodes[key]\n\n if (!handler) return null\n\n return (handler as (this: typeof context, node: TNode) => T['output'] | null).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: TNode) => T['printOutput'] | null,\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAOA,SAAS,gBAAgB,MAA0B;CACjD,OAAO,GAAG,KAAK,aAAa,GAAG,GAAG,KAAK,UAAU,GAAG,GAAG,KAAK,WAAW,IAAI;AAC7E;AAEA,SAAS,cAAc,MAAoD;CACzE,IAAI,KAAK,KAAK,OAAOA,gBAAAA,eAAe,KAAK,GAAG;CAC5C,OAAO,KAAK,QAAQ;AACtB;AAuBA,MAAM,mBAA8C;CAClD;EAAE,MAAM;EAAY,KAAK;EAAS,QAAQ;CAAI;CAC9C;EAAE,MAAM;EAAS,KAAK;EAAQ,QAAQ;CAAI;CAC1C;EAAE,MAAM;EAAU,KAAK;EAAO,QAAQ;CAAK;CAC3C;EAAE,MAAM;EAAU,KAAK;EAAO,QAAQ;CAAK;CAC3C;EAAE,MAAM;EAAQ,KAAK;EAAU,QAAQ;CAAI;AAC7C;AAEA,MAAM,gBAA2C;C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AK,EAAE,MAAM,qBACzC,gBAAgB,YAAY,gBAAgB;GAAE;GAAsB;EAAW,GAAG,IAAI,GAAG,IAAI,CAG9C;CAAE;AACrD;;;;;;;;;;;;;;;;;;;;;;AC/JA,SAAgB,cACd,SACmD;CACnD,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACiHA,SAAgB,cAAuE,OAAkE;CACvJ,OAAO,sBAAgE,SAAS,KAAK,IAAI,CAAC,CAAC,KAAK;AAClG;;;;;;;;;;;AAYA,SAAgB,qBAAkG,QAAsC;CACtJ,OAAO,SACL,OAyBA;EACA,QAAQ,YAAY;GAClB,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,OAAO,kBAAkB,MAAM,WAAY,CAAC,CAAkB;GAE7G,MAAM,UAAU;IACd,SAAS;IACT,YAAY,SAAoC;KAC9C,MAAM,MAAM,OAAO,IAAI;KACvB,IAAI,QAAQ,MAAM,OAAO;KAEzB,MAAM,UAAU,MAAM;KAEtB,IAAI,CAAC,SAAS,OAAO;KAErB,OAAQ,QAAsE,KAAK,SAAS,IAAI;IAClG;GACF;GAEA,OAAO;IACL;IACA,SAAS;IACT,WAAW,QAAQ;IACnB,OAAQ,gBAAgB,cAAc,KAAK,OAAO,IAAI,QAAQ;GAChE;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["extractRefName","obj"],"sources":["../src/dialect.ts","../src/definePrinter.ts","../src/signature.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\n\n/**\n * The spec-specific questions a schema parser answers while turning a source document into Kubb\n * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where\n * OpenAPI, AsyncAPI, and plain JSON Schema differ.\n */\nexport type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Whether the schema is nullable.\n */\n isNullable(schema?: TSchema): boolean\n /**\n * Whether the value is a `$ref` pointer.\n */\n isReference(value?: unknown): value is TRef\n /**\n * Whether the schema carries a discriminator for polymorphism.\n */\n isDiscriminator(value?: unknown): value is TDiscriminated\n /**\n * Whether the schema is binary data, converted to a `blob` node.\n */\n isBinary(schema: TSchema): boolean\n /**\n * Resolves a local `$ref` against the document, or nullish when it cannot.\n */\n resolveRef<TResolved>(document: TDocument, ref: string): TResolved | null | undefined\n}\n\n/**\n * How a dialect collapses structurally identical schemas into shared definitions. The contract is\n * generic over the plan and context types, which the adapter supplies. The mechanics live in the\n * adapter, not here, so `@kubb/ast` carries no dedupe logic. The returned plan owns the rewriting\n * behavior, so callers interact with one object.\n */\nexport type Dedupe<TPlan = unknown, TContext = unknown> = {\n /**\n * Scans a forest of nodes and produces a plan describing which shapes to share.\n */\n plan(roots: ReadonlyArray<Node>, context: TContext): TPlan\n}\n\n/**\n * A spec adapter's dialect. `name` identifies it in logs and diagnostics, `schema` holds the\n * spec-specific schema questions the parser answers, and `dedupe` is the schema-sharing seam.\n */\nexport type Dialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown, TDedupe extends Dedupe = Dedupe> = {\n /**\n * Identifies the dialect in logs and diagnostics.\n */\n name: string\n /**\n * The spec-specific schema behavior. See {@link SchemaDialect}.\n */\n schema: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>\n /**\n * The schema-sharing behavior. See {@link Dedupe}.\n */\n dedupe: TDedupe\n}\n\n/**\n * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the\n * dialect's type for inference.\n *\n * @example\n * ```ts\n * export const oasDialect = defineDialect({\n * name: 'oas',\n * schema: {\n * isNullable,\n * isReference,\n * isDiscriminator,\n * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',\n * resolveRef,\n * },\n * dedupe: { plan },\n * })\n * ```\n */\nexport function defineDialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe extends Dedupe>(\n dialect: Dialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe>,\n): Dialect<TSchema, TRef, TDiscriminated, TDocument, TDedupe> {\n return dialect\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * }\n * ```\n */\ntype PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n */\n transform: (node: SchemaNode) => TOutput | null\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\ntype PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\ntype PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n/**\n * Defines a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'\n *\n * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return createPrinterFactory<SchemaNode, SchemaType, SchemaNodeByType>((node) => node.type)(build) as (options?: T['options']) => Printer<T>\n}\n\n/**\n * Generic printer factory behind `definePrinter`. Pass a `getKey` function that maps a node to its\n * handler key, and it returns a `definePrinter`-style helper for that node and key type. `definePrinter`\n * itself is this factory keyed by `node.type`.\n *\n * @example Key a printer by `node.kind` instead of `node.type`\n * ```ts\n * const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(\n * (node) => node.kind,\n * )\n * ```\n */\nexport function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | null) {\n return function <T extends PrinterFactoryOptions>(\n build: (options: T['options']) => {\n name: T['name']\n options: T['options']\n nodes: Partial<{\n [K in TKey]: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNodeByKey[K],\n ) => T['output'] | null\n }>\n print?: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNode,\n ) => T['printOutput'] | null\n },\n ): (options?: T['options']) => {\n name: T['name']\n options: T['options']\n transform: (node: TNode) => T['output'] | null\n print: (node: TNode) => T['printOutput'] | null\n } {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: TNode): T['output'] | null => {\n const key = getKey(node)\n if (key === null) return null\n\n const handler = nodes[key]\n\n if (!handler) return null\n\n return (handler as (this: typeof context, node: TNode) => T['output'] | null).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: TNode) => T['printOutput'] | null,\n }\n }\n }\n}\n","import { hash } from 'node:crypto'\nimport type { SchemaNode } from './nodes/index.ts'\nimport { extractRefName } from './utils/index.ts'\n\n/**\n * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.\n */\nfunction flagsDescriptor(node: SchemaNode): string {\n return `${node.primitive ?? ''};${node.format ?? ''};${node.nullable ? 1 : 0}`\n}\n\nfunction refTargetName(node: Extract<SchemaNode, { type: 'ref' }>): string {\n if (node.ref) return extractRefName(node.ref)\n return node.name ?? ''\n}\n\ntype ScalarField = { kind: 'scalar'; key: string; prefix: string }\ntype BoolField = { kind: 'bool'; key: string; prefix: string }\ntype ChildField = { kind: 'child'; key: string; prefix: string }\ntype ChildrenField = { kind: 'children'; key: string; prefix: string }\ntype ObjectPropsField = { kind: 'objectProps' }\ntype AdditionalPropsField = { kind: 'additionalProps' }\ntype PatternPropsField = { kind: 'patternProps' }\ntype EnumValuesField = { kind: 'enumValues' }\ntype RefTargetField = { kind: 'refTarget' }\n\ntype ShapeField =\n | ScalarField\n | BoolField\n | ChildField\n | ChildrenField\n | ObjectPropsField\n | AdditionalPropsField\n | PatternPropsField\n | EnumValuesField\n | RefTargetField\n\nconst arrayTupleFields: ReadonlyArray<ShapeField> = [\n { kind: 'children', key: 'items', prefix: 'i' },\n { kind: 'child', key: 'rest', prefix: 'r' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'bool', key: 'unique', prefix: 'u' },\n]\n\nconst numericFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'exclusiveMinimum', prefix: 'emn' },\n { kind: 'scalar', key: 'exclusiveMaximum', prefix: 'emx' },\n { kind: 'scalar', key: 'multipleOf', prefix: 'mo' },\n]\n\nconst rangeFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n]\n\n/**\n * Maps each node `type` to its ordered shape-contributing fields. Types absent from the map\n * (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.\n */\nconst SHAPE_KEYS: Partial<Record<SchemaNode['type'], ReadonlyArray<ShapeField>>> = {\n object: [\n { kind: 'objectProps' },\n { kind: 'additionalProps' },\n { kind: 'patternProps' },\n { kind: 'scalar', key: 'minProperties', prefix: 'mn' },\n { kind: 'scalar', key: 'maxProperties', prefix: 'mx' },\n ],\n array: arrayTupleFields,\n tuple: arrayTupleFields,\n union: [\n { kind: 'scalar', key: 'strategy', prefix: 's' },\n { kind: 'scalar', key: 'discriminatorPropertyName', prefix: 'd' },\n { kind: 'children', key: 'members', prefix: 'm' },\n ],\n intersection: [{ kind: 'children', key: 'members', prefix: 'm' }],\n enum: [{ kind: 'enumValues' }],\n ref: [{ kind: 'refTarget' }],\n string: [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'pattern', prefix: 'pt' },\n ],\n number: numericFields,\n integer: numericFields,\n bigint: numericFields,\n url: [\n { kind: 'scalar', key: 'path', prefix: 'path' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n ],\n uuid: rangeFields,\n email: rangeFields,\n datetime: [\n { kind: 'bool', key: 'offset', prefix: 'o' },\n { kind: 'bool', key: 'local', prefix: 'l' },\n ],\n date: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n time: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n}\n\nfunction serializeShapeField(field: ShapeField, node: SchemaNode, record: Record<string, unknown>): string {\n switch (field.kind) {\n case 'scalar':\n return `${field.prefix}:${record[field.key] ?? ''}`\n case 'bool':\n return `${field.prefix}:${record[field.key] ? 1 : 0}`\n case 'child': {\n const child = record[field.key] as SchemaNode | undefined\n return `${field.prefix}:${child ? signatureOf(child) : ''}`\n }\n case 'children': {\n const children = (record[field.key] as Array<SchemaNode> | undefined) ?? []\n return `${field.prefix}[${children.map((c) => signatureOf(c)).join(',')}]`\n }\n case 'objectProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const props = (obj.properties ?? []).map((prop) => `${prop.name}${prop.required ? '!' : '?'}${signatureOf(prop.schema)}`).join(',')\n return `p[${props}]`\n }\n case 'additionalProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n if (typeof obj.additionalProperties === 'boolean') return `ab:${obj.additionalProperties}`\n if (obj.additionalProperties) return `as:${signatureOf(obj.additionalProperties)}`\n return ''\n }\n case 'patternProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const pattern = obj.patternProperties\n ? Object.keys(obj.patternProperties)\n .sort()\n .map((key) => `${key}=${signatureOf(obj.patternProperties![key]!)}`)\n .join(',')\n : ''\n return `pp[${pattern}]`\n }\n case 'enumValues': {\n const en = node as Extract<SchemaNode, { type: 'enum' }>\n let values = ''\n if (en.namedEnumValues?.length) {\n values = en.namedEnumValues.map((entry) => `${entry.name}=${entry.primitive}:${String(entry.value)}`).join(',')\n } else if (en.enumValues?.length) {\n values = en.enumValues.map((value) => `${value === null ? 'null' : typeof value}:${String(value)}`).join(',')\n }\n return `v[${values}]`\n }\n case 'refTarget': {\n return `->${refTargetName(node as Extract<SchemaNode, { type: 'ref' }>)}`\n }\n }\n}\n\n/**\n * Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,\n * constraints, and its children's signatures.\n */\nfunction describeShape(node: SchemaNode): string {\n const flags = flagsDescriptor(node)\n const fields = SHAPE_KEYS[node.type]\n if (!fields) return `${node.type}|${flags}`\n\n const record = node as unknown as Record<string, unknown>\n const parts: Array<string> = [`${node.type}|${flags}`]\n for (const field of fields) {\n parts.push(serializeShapeField(field, node, record))\n }\n return parts.join('|')\n}\n\n/**\n * Caches the digest per node, keyed by identity. A `WeakMap` so entries die with the node, and so\n * a tree hashed during dedupe planning is not walked again when it is rewritten during streaming.\n * Reuse is safe because a signature depends only on content, and nodes are immutable once created.\n */\nconst signatureCache = new WeakMap<SchemaNode, string>()\n\n/**\n * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas\n * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,\n * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,\n * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`\n * nodes compare by target name, which also terminates on circular shapes.\n *\n * @example Two enums with different descriptions share a signature\n * ```ts\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))\n * ```\n */\nexport function signatureOf(node: SchemaNode): string {\n const cached = signatureCache.get(node)\n if (cached !== undefined) return cached\n const signature = hash('sha256', describeShape(node), 'hex')\n signatureCache.set(node, signature)\n\n return signature\n}\n\n/**\n * Returns `true` when two schema nodes are structurally identical under shape-only equality,\n * meaning they produce the same TypeScript type.\n */\nexport function isSchemaEqual(a: Sch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,aAAA,GAAA,YAAA,KAAA,CAAiB,UAAU,cAAc,IAAI,GAAG,KAAK;CAC3D,eAAe,IAAI,MAAM,SAAS;CAElC,OAAO;AACT"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { n as __name } from "./chunk-CNktS9qV.js";
|
|
2
|
-
import { $ as exportDef, $t as textDef, A as IndexedAccessTypeNode, At as InferSchemaNode, B as functionParametersDef, Bt as TypeNode, C as ParameterNode, Ct as UrlSchemaNode, D as FunctionParamNode, Dt as UserPropertyNode, E as FunctionParamKind, Et as PropertyNode, Ft as ConstNode, G as FileNode, H as objectBindingPatternDef, Ht as breakDef, It as FunctionNode, J as UserFileNode, K as ImportNode, Lt as JSDocNode, M as TypeExpression, Mt as ArrowFunctionNode, N as TypeLiteralNode, Nt as BreakNode, O as FunctionParameterNode, Pt as CodeNode, Qt as jsxDef, Rt as JsxNode, S as ParameterLocation, St as UnionSchemaNode, T as parameterDef, Tt as schemaDef, U as typeLiteralDef, Ut as constDef, V as indexedAccessTypeDef, Vt as arrowFunctionDef, W as ExportNode, Zt as functionDef, _t as SchemaNode, a as InputMeta, an as NodeKind, bt as StringSchemaNode, c as inputDef,
|
|
2
|
+
import { $ as exportDef, $t as textDef, A as IndexedAccessTypeNode, At as InferSchemaNode, B as functionParametersDef, Bt as TypeNode, C as ParameterNode, Ct as UrlSchemaNode, D as FunctionParamNode, Dt as UserPropertyNode, E as FunctionParamKind, Et as PropertyNode, Ft as ConstNode, G as FileNode, H as objectBindingPatternDef, Ht as breakDef, It as FunctionNode, J as UserFileNode, K as ImportNode, Lt as JSDocNode, M as TypeExpression, Mt as ArrowFunctionNode, N as TypeLiteralNode, Nt as BreakNode, O as FunctionParameterNode, Pt as CodeNode, Qt as jsxDef, Rt as JsxNode, S as ParameterLocation, St as UnionSchemaNode, T as parameterDef, Tt as schemaDef, U as typeLiteralDef, Ut as constDef, V as indexedAccessTypeDef, Vt as arrowFunctionDef, W as ExportNode, Zt as functionDef, _t as SchemaNode, a as InputMeta, an as NodeKind, bt as StringSchemaNode, c as inputDef, ct as DatetimeSchemaNode, d as HttpOperationNode, dt as NumberSchemaNode, en as typeDef, et as fileDef, f as OperationNode, ft as ObjectSchemaNode, g as StatusCode, gt as ScalarSchemaType, h as ResponseNode, ht as ScalarSchemaNode, i as outputDef, in as BaseNode, it as contentDef, j as ObjectBindingPatternNode, jt as ParserOptions, k as FunctionParametersNode, kt as propertyDef, l as GenericOperationNode, lt as EnumSchemaNode, m as operationDef, mt as RefSchemaNode, n as OutputNode, nn as NodeDef, nt as sourceDef, o as InputNode, ot as ArraySchemaNode, pt as PrimitiveSchemaType, q as SourceNode, rn as defineNode, rt as ContentNode, st as DateSchemaNode, t as Node, tn as DistributiveOmit, tt as importDef, u as HttpMethod, ut as IntersectionSchemaNode, v as responseDef, vt as SchemaNodeByType, x as requestBodyDef, xt as TimeSchemaNode, y as RequestBodyNode, yt as SchemaType, z as functionParameterDef, zt as TextNode } from "./index-B9cc8MBS.js";
|
|
3
3
|
import { t as factory_d_exports } from "./factory.js";
|
|
4
|
-
import { a as defineMacro, c as VisitorContext, d as walk, f as schemaTypes, i as composeMacros, l as collect, n as Macro, o as ParentOf, r as applyMacros, s as Visitor, t as Enforce, u as transform } from "./defineMacro-
|
|
5
|
-
import { a as definePrinter, c as
|
|
6
|
-
import { n as OperationParamsResolver } from "./operationParams-
|
|
4
|
+
import { a as defineMacro, c as VisitorContext, d as walk, f as schemaTypes, i as composeMacros, l as collect, n as Macro, o as ParentOf, r as applyMacros, s as Visitor, t as Enforce, u as transform } from "./defineMacro-BATi7xoC.js";
|
|
5
|
+
import { a as definePrinter, c as SchemaDialect, i as createPrinterFactory, l as defineDialect, n as PrinterFactoryOptions, o as Dedupe, r as PrinterPartial, s as Dialect, t as Printer } from "./types-BB_xgRJ3.js";
|
|
6
|
+
import { n as OperationParamsResolver } from "./operationParams-k5CKwSWZ.js";
|
|
7
7
|
|
|
8
8
|
//#region src/guards.d.ts
|
|
9
9
|
/**
|
|
@@ -28,6 +28,13 @@ declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | u
|
|
|
28
28
|
*/
|
|
29
29
|
declare function isHttpOperationNode(node: OperationNode): node is HttpOperationNode;
|
|
30
30
|
//#endregion
|
|
31
|
+
//#region src/optionality.d.ts
|
|
32
|
+
/**
|
|
33
|
+
* Generic JSON Schema optionality: a non-required field is optional, and a
|
|
34
|
+
* non-required nullable field is nullish.
|
|
35
|
+
*/
|
|
36
|
+
declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
|
|
37
|
+
//#endregion
|
|
31
38
|
//#region src/signature.d.ts
|
|
32
39
|
/**
|
|
33
40
|
* Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas
|
|
@@ -132,5 +139,5 @@ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<Input
|
|
|
132
139
|
default?: string;
|
|
133
140
|
}> | NodeDef<FunctionParametersNode, Partial<Omit<FunctionParametersNode, "kind">>> | NodeDef<IndexedAccessTypeNode, Omit<IndexedAccessTypeNode, "kind">> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
|
|
134
141
|
//#endregion
|
|
135
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type
|
|
142
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type Dedupe, type Dialect, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type FunctionParamKind, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type IndexedAccessTypeNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectBindingPatternNode, type ObjectSchemaNode, type OperationNode, type OperationParamsResolver, type OutputNode, type ParameterLocation, type ParameterNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaDialect, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeExpression, type TypeLiteralNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, composeMacros, constDef, contentDef, createPrinterFactory, defineDialect, defineMacro, defineNode, definePrinter, exportDef, factory_d_exports as factory, fileDef, functionDef, functionParameterDef, functionParametersDef, importDef, indexedAccessTypeDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, objectBindingPatternDef, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, signatureOf, sourceDef, textDef, transform, typeDef, typeLiteralDef, walk };
|
|
136
143
|
//# sourceMappingURL=index.d.ts.map
|