@trpc/openapi 11.18.1-canary.2 → 11.18.1-canary.30
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/{cli.js → cli.mjs} +78 -109
- package/dist/heyapi/index.cjs +24 -38
- package/dist/heyapi/index.d.cts +9 -12
- package/dist/heyapi/index.d.cts.map +1 -1
- package/dist/heyapi/index.d.mts +9 -12
- package/dist/heyapi/index.d.mts.map +1 -1
- package/dist/heyapi/index.mjs +23 -38
- package/dist/heyapi/index.mjs.map +1 -1
- package/dist/index.cjs +101 -108
- package/dist/index.d.cts +3 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +62 -103
- package/dist/index.mjs.map +1 -1
- package/dist/objectSpread2-C2ceYbQe.cjs +67 -0
- package/dist/objectSpread2-Dh4InpQf.mjs +62 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +7 -7
- package/src/generate.ts +1 -5
- package/src/heyapi/index.ts +1 -2
- package/src/types.ts +9 -16
- package/dist/chunk-CJ2cON1m.mjs +0 -33
- package/dist/objectSpread2-Blgb1OZh.mjs +0 -90
- package/dist/objectSpread2-Blgb1OZh.mjs.map +0 -1
- package/dist/objectSpread2-Cw30I7tb.cjs +0 -131
package/dist/{cli.js → cli.mjs}
RENAMED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import * as fs$1 from "node:fs";
|
|
3
2
|
import * as fs from "node:fs";
|
|
4
|
-
import * as path$1 from "node:path";
|
|
5
3
|
import * as path from "node:path";
|
|
6
4
|
import { parseArgs } from "node:util";
|
|
7
5
|
import * as ts from "typescript";
|
|
8
6
|
import { pathToFileURL } from "node:url";
|
|
9
|
-
|
|
10
7
|
//#region src/schemaExtraction.ts
|
|
11
8
|
/**
|
|
12
9
|
* Zod v4 stores `.describe()` strings in `globalThis.__zod_globalRegistry`,
|
|
@@ -36,7 +33,7 @@ function zodArrayElement(schema) {
|
|
|
36
33
|
return null;
|
|
37
34
|
}
|
|
38
35
|
/** Wrapper def types whose inner schema is accessible via `innerType` or `in`. */
|
|
39
|
-
const wrapperDefTypes = new Set([
|
|
36
|
+
const wrapperDefTypes = /* @__PURE__ */ new Set([
|
|
40
37
|
"optional",
|
|
41
38
|
"nullable",
|
|
42
39
|
"nonoptional",
|
|
@@ -120,13 +117,13 @@ function walkZodShape(schema, prefix, ctx) {
|
|
|
120
117
|
const shape = zodObjectShape(unwrapped);
|
|
121
118
|
if (!shape) return;
|
|
122
119
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
123
|
-
const path
|
|
120
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
124
121
|
const meta = ctx.registry.get(fieldSchema);
|
|
125
122
|
const unwrappedField = unwrapZodSchema(fieldSchema);
|
|
126
123
|
const innerMeta = unwrappedField !== fieldSchema ? ctx.registry.get(unwrappedField) : void 0;
|
|
127
124
|
const description = meta?.description ?? innerMeta?.description;
|
|
128
|
-
if (description) ctx.map.properties.set(path
|
|
129
|
-
walkZodShape(unwrappedField, path
|
|
125
|
+
if (description) ctx.map.properties.set(path, description);
|
|
126
|
+
walkZodShape(unwrappedField, path, ctx);
|
|
130
127
|
}
|
|
131
128
|
}
|
|
132
129
|
/** Check whether a value looks like a tRPC router instance at runtime. */
|
|
@@ -158,8 +155,7 @@ function findRouterExport(mod, exportName) {
|
|
|
158
155
|
*/
|
|
159
156
|
async function tryImportRouter(resolvedPath, exportName) {
|
|
160
157
|
try {
|
|
161
|
-
|
|
162
|
-
return findRouterExport(mod, exportName);
|
|
158
|
+
return findRouterExport(await import(pathToFileURL(resolvedPath).href), exportName);
|
|
163
159
|
} catch {
|
|
164
160
|
return null;
|
|
165
161
|
}
|
|
@@ -241,15 +237,12 @@ function setNestedDescription({ schema, pathParts, description, schemas }) {
|
|
|
241
237
|
const items = getArrayItemsSchema(schema);
|
|
242
238
|
if (!items) return;
|
|
243
239
|
if (rest.length === 0) setLeafDescription(items, description);
|
|
244
|
-
else {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
schemas
|
|
251
|
-
});
|
|
252
|
-
}
|
|
240
|
+
else setNestedDescription({
|
|
241
|
+
schema: resolveSchemaRef(items, schemas) ?? items,
|
|
242
|
+
pathParts: rest,
|
|
243
|
+
description,
|
|
244
|
+
schemas
|
|
245
|
+
});
|
|
253
246
|
return;
|
|
254
247
|
}
|
|
255
248
|
const propSchema = getPropertySchema(schema, head);
|
|
@@ -257,16 +250,14 @@ function setNestedDescription({ schema, pathParts, description, schemas }) {
|
|
|
257
250
|
if (rest.length === 0) setLeafDescription(propSchema, description);
|
|
258
251
|
else {
|
|
259
252
|
const target = getArrayItemsSchema(propSchema) ?? propSchema;
|
|
260
|
-
const resolvedTarget = resolveSchemaRef(target, schemas) ?? target;
|
|
261
253
|
setNestedDescription({
|
|
262
|
-
schema:
|
|
254
|
+
schema: resolveSchemaRef(target, schemas) ?? target,
|
|
263
255
|
pathParts: rest,
|
|
264
256
|
description,
|
|
265
257
|
schemas
|
|
266
258
|
});
|
|
267
259
|
}
|
|
268
260
|
}
|
|
269
|
-
|
|
270
261
|
//#endregion
|
|
271
262
|
//#region src/generate.ts
|
|
272
263
|
const PRIMITIVE_FLAGS = ts.TypeFlags.String | ts.TypeFlags.Number | ts.TypeFlags.Boolean | ts.TypeFlags.StringLiteral | ts.TypeFlags.NumberLiteral | ts.TypeFlags.BooleanLiteral;
|
|
@@ -294,7 +285,7 @@ function unwrapBrand(type) {
|
|
|
294
285
|
if (first && hasObject) return first;
|
|
295
286
|
return type;
|
|
296
287
|
}
|
|
297
|
-
const ANONYMOUS_NAMES = new Set([
|
|
288
|
+
const ANONYMOUS_NAMES = /* @__PURE__ */ new Set([
|
|
298
289
|
"__type",
|
|
299
290
|
"__object",
|
|
300
291
|
"Object",
|
|
@@ -353,8 +344,8 @@ function typeToJsonSchema(type, ctx, depth = 0) {
|
|
|
353
344
|
const storedSchema = ctx.schemas[existingRef];
|
|
354
345
|
if (storedSchema && (isNonEmptySchema(storedSchema) || ctx.visited.has(type))) return schemaRef(existingRef);
|
|
355
346
|
ctx.schemas[existingRef] = storedSchema ?? {};
|
|
356
|
-
const schema
|
|
357
|
-
if (!isSelfSchemaRef(schema
|
|
347
|
+
const schema = convertTypeToSchema(type, ctx, depth);
|
|
348
|
+
if (!isSelfSchemaRef(schema, existingRef)) ctx.schemas[existingRef] = schema;
|
|
358
349
|
return schemaRef(existingRef);
|
|
359
350
|
}
|
|
360
351
|
const schema = convertTypeToSchema(type, ctx, depth);
|
|
@@ -377,8 +368,7 @@ function typeToJsonSchema(type, ctx, depth = 0) {
|
|
|
377
368
|
function handleCyclicRef(type, ctx) {
|
|
378
369
|
let refName = ctx.typeToRef.get(type);
|
|
379
370
|
if (!refName) {
|
|
380
|
-
|
|
381
|
-
refName = ensureUniqueName(name, ctx.schemas);
|
|
371
|
+
refName = ensureUniqueName(getTypeName(type) ?? "RecursiveType", ctx.schemas);
|
|
382
372
|
ctx.typeToRef.set(type, refName);
|
|
383
373
|
ctx.schemas[refName] = {};
|
|
384
374
|
}
|
|
@@ -405,18 +395,14 @@ function convertPrimitiveOrLiteral(type, flags, checker) {
|
|
|
405
395
|
type: "number",
|
|
406
396
|
const: type.value
|
|
407
397
|
};
|
|
408
|
-
if (flags & ts.TypeFlags.BooleanLiteral) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const: isTrue
|
|
413
|
-
};
|
|
414
|
-
}
|
|
398
|
+
if (flags & ts.TypeFlags.BooleanLiteral) return {
|
|
399
|
+
type: "boolean",
|
|
400
|
+
const: checker.typeToString(type) === "true"
|
|
401
|
+
};
|
|
415
402
|
return null;
|
|
416
403
|
}
|
|
417
404
|
function convertUnionType(type, ctx, depth) {
|
|
418
|
-
const
|
|
419
|
-
const defined = members.filter((m) => !hasFlag(m, ts.TypeFlags.Undefined | ts.TypeFlags.Void));
|
|
405
|
+
const defined = type.types.filter((m) => !hasFlag(m, ts.TypeFlags.Undefined | ts.TypeFlags.Void));
|
|
420
406
|
if (defined.length === 0) return {};
|
|
421
407
|
const hasNull = defined.some((m) => hasFlag(m, ts.TypeFlags.Null));
|
|
422
408
|
const nonNull = defined.filter((m) => !hasFlag(m, ts.TypeFlags.Null));
|
|
@@ -450,13 +436,9 @@ function detectDiscriminatorProperty(schemas) {
|
|
|
450
436
|
const first = schemas[0];
|
|
451
437
|
if (!first?.properties) return null;
|
|
452
438
|
const firstProps = Object.keys(first.properties);
|
|
453
|
-
for (const prop of firstProps) {
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
return propSchema !== void 0 && propSchema.const !== void 0 && s.required?.includes(prop);
|
|
457
|
-
});
|
|
458
|
-
if (allHaveConst) return prop;
|
|
459
|
-
}
|
|
439
|
+
for (const prop of firstProps) if (schemas.every((s) => {
|
|
440
|
+
return (s.properties?.[prop])?.const !== void 0 && s.required?.includes(prop);
|
|
441
|
+
})) return prop;
|
|
460
442
|
return null;
|
|
461
443
|
}
|
|
462
444
|
/** A schema that is just `{ type: "somePrimitive" }` with no other keys. */
|
|
@@ -470,14 +452,12 @@ function isSimpleTypeSchema(s) {
|
|
|
470
452
|
*/
|
|
471
453
|
function tryCollapseLiteralUnion(nonNull, hasNull) {
|
|
472
454
|
if (nonNull.length <= 1) return null;
|
|
473
|
-
|
|
474
|
-
if (!allLiterals) return null;
|
|
455
|
+
if (!nonNull.every((m) => hasFlag(m, ts.TypeFlags.StringLiteral | ts.TypeFlags.NumberLiteral))) return null;
|
|
475
456
|
const [first] = nonNull;
|
|
476
457
|
if (!first) return null;
|
|
477
458
|
const isString = hasFlag(first, ts.TypeFlags.StringLiteral);
|
|
478
459
|
const targetFlag = isString ? ts.TypeFlags.StringLiteral : ts.TypeFlags.NumberLiteral;
|
|
479
|
-
|
|
480
|
-
if (!allSameKind) return null;
|
|
460
|
+
if (!nonNull.every((m) => hasFlag(m, targetFlag))) return null;
|
|
481
461
|
const values = nonNull.map((m) => isString ? m.value : m.value);
|
|
482
462
|
const baseType = isString ? "string" : "number";
|
|
483
463
|
return {
|
|
@@ -486,9 +466,7 @@ function tryCollapseLiteralUnion(nonNull, hasNull) {
|
|
|
486
466
|
};
|
|
487
467
|
}
|
|
488
468
|
function convertIntersectionType(type, ctx, depth) {
|
|
489
|
-
const
|
|
490
|
-
const nonBrand = hasPrimitiveMember ? type.types.filter((m) => !isObjectType(m)) : type.types;
|
|
491
|
-
const schemas = nonBrand.map((m) => typeToJsonSchema(m, ctx, depth + 1)).filter(isNonEmptySchema);
|
|
469
|
+
const schemas = (type.types.some(isPrimitive) ? type.types.filter((m) => !isObjectType(m)) : type.types).map((m) => typeToJsonSchema(m, ctx, depth + 1)).filter(isNonEmptySchema);
|
|
492
470
|
if (schemas.length === 0) return {};
|
|
493
471
|
const [onlySchema] = schemas;
|
|
494
472
|
if (schemas.length === 1 && onlySchema !== void 0) return onlySchema;
|
|
@@ -547,10 +525,9 @@ function convertArrayType(type, ctx, depth) {
|
|
|
547
525
|
}
|
|
548
526
|
function convertTupleType(type, ctx, depth) {
|
|
549
527
|
const args = ctx.checker.getTypeArguments(type);
|
|
550
|
-
const schemas = args.map((a) => typeToJsonSchema(a, ctx, depth + 1));
|
|
551
528
|
return {
|
|
552
529
|
type: "array",
|
|
553
|
-
prefixItems:
|
|
530
|
+
prefixItems: args.map((a) => typeToJsonSchema(a, ctx, depth + 1)),
|
|
554
531
|
items: false,
|
|
555
532
|
minItems: args.length,
|
|
556
533
|
maxItems: args.length
|
|
@@ -566,8 +543,7 @@ function convertPlainObject(type, ctx, depth) {
|
|
|
566
543
|
};
|
|
567
544
|
let autoRegName = null;
|
|
568
545
|
const tsName = getTypeName(type);
|
|
569
|
-
|
|
570
|
-
if (isNamedUnregisteredType) {
|
|
546
|
+
if (tsName !== null && typeProps.length > 0 && !ctx.typeToRef.has(type)) {
|
|
571
547
|
autoRegName = ensureUniqueName(tsName, ctx.schemas);
|
|
572
548
|
ctx.typeToRef.set(type, autoRegName);
|
|
573
549
|
ctx.schemas[autoRegName] = {};
|
|
@@ -577,8 +553,7 @@ function convertPlainObject(type, ctx, depth) {
|
|
|
577
553
|
const required = [];
|
|
578
554
|
for (const prop of typeProps) {
|
|
579
555
|
if (shouldSkipPropertySymbol(prop)) continue;
|
|
580
|
-
const
|
|
581
|
-
const propSchema = typeToJsonSchema(propType, ctx, depth + 1);
|
|
556
|
+
const propSchema = typeToJsonSchema(checker.getTypeOfSymbol(prop), ctx, depth + 1);
|
|
582
557
|
const jsDoc = getJsDocComment(prop, checker);
|
|
583
558
|
if (jsDoc && !propSchema.description && !propSchema.$ref) propSchema.description = jsDoc;
|
|
584
559
|
properties[prop.name] = propSchema;
|
|
@@ -607,8 +582,7 @@ function convertObjectType(type, ctx, depth) {
|
|
|
607
582
|
/** Core type-to-schema conversion (no ref handling). */
|
|
608
583
|
function convertTypeToSchema(type, ctx, depth) {
|
|
609
584
|
if (ctx.visited.has(type)) return handleCyclicRef(type, ctx);
|
|
610
|
-
const
|
|
611
|
-
const primitive = convertPrimitiveOrLiteral(type, flags, ctx.checker);
|
|
585
|
+
const primitive = convertPrimitiveOrLiteral(type, type.getFlags(), ctx.checker);
|
|
612
586
|
if (primitive) return primitive;
|
|
613
587
|
if (type.isUnion()) {
|
|
614
588
|
ctx.visited.add(type);
|
|
@@ -639,23 +613,20 @@ function getProcedureTypeName(defType, checker) {
|
|
|
639
613
|
}
|
|
640
614
|
function isVoidLikeInput(inputType) {
|
|
641
615
|
if (!inputType) return true;
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
const isUnionOfVoids = inputType.isUnion() && inputType.types.every((t) => hasFlag(t, ts.TypeFlags.Void | ts.TypeFlags.Undefined));
|
|
645
|
-
return isUnionOfVoids;
|
|
616
|
+
if (hasFlag(inputType, ts.TypeFlags.Void | ts.TypeFlags.Undefined | ts.TypeFlags.Never)) return true;
|
|
617
|
+
return inputType.isUnion() && inputType.types.every((t) => hasFlag(t, ts.TypeFlags.Void | ts.TypeFlags.Undefined));
|
|
646
618
|
}
|
|
647
619
|
function shouldIncludeProcedureInOpenAPI(type) {
|
|
648
620
|
return type !== "subscription";
|
|
649
621
|
}
|
|
650
|
-
function getProcedureInputTypeName(type, path
|
|
622
|
+
function getProcedureInputTypeName(type, path) {
|
|
651
623
|
const directName = getTypeName(type);
|
|
652
624
|
if (directName) return directName;
|
|
653
625
|
for (const sym of [type.aliasSymbol, type.getSymbol()].filter((candidate) => !!candidate)) for (const declaration of sym.declarations ?? []) {
|
|
654
626
|
const declarationName = ts.getNameOfDeclaration(declaration)?.getText();
|
|
655
627
|
if (declarationName && !ANONYMOUS_NAMES.has(declarationName) && !declarationName.startsWith("__")) return declarationName;
|
|
656
628
|
}
|
|
657
|
-
|
|
658
|
-
return `${fallbackName || "Procedure"}Input`;
|
|
629
|
+
return `${path.split(".").filter(Boolean).map((segment) => segment.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")).join("") || "Procedure"}Input`;
|
|
659
630
|
}
|
|
660
631
|
function isUnknownLikeType(type) {
|
|
661
632
|
return hasFlag(type, ts.TypeFlags.Unknown | ts.TypeFlags.Any);
|
|
@@ -685,14 +656,11 @@ function recoverProcedureInputType(def, checker) {
|
|
|
685
656
|
if (callee.name.text !== "input") return;
|
|
686
657
|
const [parserExpr] = expr.arguments;
|
|
687
658
|
if (!parserExpr) return;
|
|
688
|
-
const
|
|
689
|
-
const standardSym = parserType.getProperty("~standard");
|
|
659
|
+
const standardSym = checker.getTypeAtLocation(parserExpr).getProperty("~standard");
|
|
690
660
|
if (!standardSym) return;
|
|
691
|
-
const
|
|
692
|
-
const typesSym = standardType.getProperty("types");
|
|
661
|
+
const typesSym = checker.getTypeOfSymbolAtLocation(standardSym, parserExpr).getProperty("types");
|
|
693
662
|
if (!typesSym) return;
|
|
694
|
-
const
|
|
695
|
-
const outputSym = typesType.getProperty("output");
|
|
663
|
+
const outputSym = checker.getNonNullableType(checker.getTypeOfSymbolAtLocation(typesSym, parserExpr)).getProperty("output");
|
|
696
664
|
if (!outputSym) return;
|
|
697
665
|
const outputType = checker.getTypeOfSymbolAtLocation(outputSym, parserExpr);
|
|
698
666
|
if (!isUnknownLikeType(outputType)) recovered = outputType;
|
|
@@ -746,22 +714,18 @@ function extractProcedure(def, ctx) {
|
|
|
746
714
|
function getJsDocComment(sym, checker) {
|
|
747
715
|
const normalize = (filePath) => filePath.replace(/\\/g, "/");
|
|
748
716
|
const declarations = sym.declarations ?? [];
|
|
749
|
-
|
|
717
|
+
if (declarations.length > 0 && declarations.every((declaration) => {
|
|
750
718
|
const sourceFile = declaration.getSourceFile();
|
|
751
719
|
if (!sourceFile.isDeclarationFile) return false;
|
|
752
|
-
|
|
753
|
-
if (!declarationPath.includes("/node_modules/")) return false;
|
|
720
|
+
if (!normalize(sourceFile.fileName).includes("/node_modules/")) return false;
|
|
754
721
|
try {
|
|
755
|
-
|
|
756
|
-
if (!realPath.includes("/node_modules/")) return false;
|
|
722
|
+
if (!normalize(fs.realpathSync.native(sourceFile.fileName)).includes("/node_modules/")) return false;
|
|
757
723
|
} catch {}
|
|
758
724
|
return true;
|
|
759
|
-
});
|
|
760
|
-
if (isExternalNodeModulesDeclaration) return void 0;
|
|
725
|
+
})) return;
|
|
761
726
|
const parts = sym.getDocumentationComment(checker);
|
|
762
|
-
if (parts.length === 0) return
|
|
763
|
-
|
|
764
|
-
return text || void 0;
|
|
727
|
+
if (parts.length === 0) return;
|
|
728
|
+
return parts.map((p) => p.text).join("") || void 0;
|
|
765
729
|
}
|
|
766
730
|
function walkType(opts) {
|
|
767
731
|
const { type, ctx, currentPath, description, symbol } = opts;
|
|
@@ -791,28 +755,21 @@ function walkType(opts) {
|
|
|
791
755
|
}
|
|
792
756
|
const routerSym = defType.getProperty("router");
|
|
793
757
|
if (!routerSym) return;
|
|
794
|
-
|
|
795
|
-
if (!isRouter) return;
|
|
758
|
+
if (!(checker.typeToString(checker.getTypeOfSymbol(routerSym)) === "true")) return;
|
|
796
759
|
const recordSym = defType.getProperty("record");
|
|
797
760
|
if (!recordSym) return;
|
|
798
761
|
ctx.seen.add(type);
|
|
799
|
-
|
|
800
|
-
walkRecord(recordType, ctx, currentPath);
|
|
762
|
+
walkRecord(checker.getTypeOfSymbol(recordSym), ctx, currentPath);
|
|
801
763
|
ctx.seen.delete(type);
|
|
802
764
|
}
|
|
803
765
|
function walkRecord(recordType, ctx, prefix) {
|
|
804
|
-
for (const prop of recordType.getProperties()) {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
currentPath: fullPath,
|
|
812
|
-
description,
|
|
813
|
-
symbol: prop
|
|
814
|
-
});
|
|
815
|
-
}
|
|
766
|
+
for (const prop of recordType.getProperties()) walkType({
|
|
767
|
+
type: ctx.schemaCtx.checker.getTypeOfSymbol(prop),
|
|
768
|
+
ctx,
|
|
769
|
+
currentPath: prefix ? `${prefix}.${prop.name}` : prop.name,
|
|
770
|
+
description: getJsDocComment(prop, ctx.schemaCtx.checker),
|
|
771
|
+
symbol: prop
|
|
772
|
+
});
|
|
816
773
|
}
|
|
817
774
|
function loadCompilerOptions(startDir) {
|
|
818
775
|
const configPath = ts.findConfigFile(startDir, (f) => ts.sys.fileExists(f), "tsconfig.json");
|
|
@@ -823,9 +780,8 @@ function loadCompilerOptions(startDir) {
|
|
|
823
780
|
noEmit: true
|
|
824
781
|
};
|
|
825
782
|
const configFile = ts.readConfigFile(configPath, (f) => ts.sys.readFile(f));
|
|
826
|
-
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path$1.dirname(configPath));
|
|
827
783
|
const options = {
|
|
828
|
-
...
|
|
784
|
+
...ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath)).options,
|
|
829
785
|
noEmit: true
|
|
830
786
|
};
|
|
831
787
|
if (options.moduleResolution === void 0) {
|
|
@@ -880,14 +836,13 @@ const DEFAULT_ERROR_SCHEMA = {
|
|
|
880
836
|
*/
|
|
881
837
|
function wrapInSuccessEnvelope(outputSchema) {
|
|
882
838
|
const hasOutput = outputSchema !== null && isNonEmptySchema(outputSchema);
|
|
883
|
-
const resultSchema = {
|
|
884
|
-
type: "object",
|
|
885
|
-
properties: { ...hasOutput ? { data: outputSchema } : {} },
|
|
886
|
-
...hasOutput ? { required: ["data"] } : {}
|
|
887
|
-
};
|
|
888
839
|
return {
|
|
889
840
|
type: "object",
|
|
890
|
-
properties: { result:
|
|
841
|
+
properties: { result: {
|
|
842
|
+
type: "object",
|
|
843
|
+
properties: { ...hasOutput ? { data: outputSchema } : {} },
|
|
844
|
+
...hasOutput ? { required: ["data"] } : {}
|
|
845
|
+
} },
|
|
891
846
|
required: ["result"]
|
|
892
847
|
};
|
|
893
848
|
}
|
|
@@ -961,9 +916,9 @@ function buildOpenAPIDocument(procedures, options, meta = { errorSchema: null })
|
|
|
961
916
|
* @param options - Optional generation settings (export name, title, version).
|
|
962
917
|
*/
|
|
963
918
|
async function generateOpenAPIDocument(routerFilePath, options = {}) {
|
|
964
|
-
const resolvedPath = path
|
|
919
|
+
const resolvedPath = path.resolve(routerFilePath);
|
|
965
920
|
const exportName = options.exportName ?? "AppRouter";
|
|
966
|
-
const compilerOptions = loadCompilerOptions(path
|
|
921
|
+
const compilerOptions = loadCompilerOptions(path.dirname(resolvedPath));
|
|
967
922
|
const program = ts.createProgram([resolvedPath], compilerOptions);
|
|
968
923
|
const checker = program.getTypeChecker();
|
|
969
924
|
const sourceFile = program.getSourceFile(resolvedPath);
|
|
@@ -1005,9 +960,23 @@ async function generateOpenAPIDocument(routerFilePath, options = {}) {
|
|
|
1005
960
|
schemas: schemaCtx.schemas
|
|
1006
961
|
});
|
|
1007
962
|
}
|
|
1008
|
-
|
|
1009
963
|
//#endregion
|
|
1010
964
|
//#region src/cli.ts
|
|
965
|
+
/**
|
|
966
|
+
* trpc-openapi – CLI that generates an OpenAPI 3.1 document from a tRPC
|
|
967
|
+
* AppRouter type.
|
|
968
|
+
*
|
|
969
|
+
* Usage:
|
|
970
|
+
* trpc-openapi <router-file> [options]
|
|
971
|
+
*
|
|
972
|
+
* Options:
|
|
973
|
+
* --export, -e Name of the exported router symbol (default: AppRouter)
|
|
974
|
+
* --output, -o Output file path (default: openapi.json)
|
|
975
|
+
* --title OpenAPI info.title (default: tRPC API)
|
|
976
|
+
* --version OpenAPI info.version (default: 0.0.0)
|
|
977
|
+
* --server-url OpenAPI servers[].url (include any tRPC prefix)
|
|
978
|
+
* --help, -h Show this help message
|
|
979
|
+
*/
|
|
1011
980
|
function parseArgs$1(argv) {
|
|
1012
981
|
let parsed;
|
|
1013
982
|
try {
|
|
@@ -1116,5 +1085,5 @@ async function main() {
|
|
|
1116
1085
|
console.log(`OpenAPI document written to: ${outputPath}`);
|
|
1117
1086
|
}
|
|
1118
1087
|
main();
|
|
1119
|
-
|
|
1120
|
-
|
|
1088
|
+
//#endregion
|
|
1089
|
+
export {};
|
package/dist/heyapi/index.cjs
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//#region
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
t[n] = r[n];
|
|
11
|
-
}
|
|
12
|
-
return t;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_objectSpread2 = require("../objectSpread2-C2ceYbQe.cjs");
|
|
3
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/objectWithoutPropertiesLoose.js
|
|
4
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
5
|
+
if (null == r) return {};
|
|
6
|
+
var t = {};
|
|
7
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
8
|
+
if (e.includes(n)) continue;
|
|
9
|
+
t[n] = r[n];
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
11
|
+
return t;
|
|
12
|
+
}
|
|
17
13
|
//#endregion
|
|
18
|
-
//#region
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
var s = Object.getOwnPropertySymbols(e);
|
|
26
|
-
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
27
|
-
}
|
|
28
|
-
return i;
|
|
14
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/objectWithoutProperties.js
|
|
15
|
+
function _objectWithoutProperties(e, t) {
|
|
16
|
+
if (null == e) return {};
|
|
17
|
+
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
18
|
+
if (Object.getOwnPropertySymbols) {
|
|
19
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
20
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
29
21
|
}
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
22
|
+
return i;
|
|
23
|
+
}
|
|
33
24
|
//#endregion
|
|
34
25
|
//#region src/heyapi/index.ts
|
|
35
|
-
var import_objectSpread2 = require_objectSpread2$1.__toESM(require_objectSpread2$1.require_objectSpread2(), 1);
|
|
36
|
-
var import_objectWithoutProperties = require_objectSpread2$1.__toESM(require_objectWithoutProperties(), 1);
|
|
37
26
|
const _excluded = ["transformer"];
|
|
38
27
|
function resolveTransformer(transformer) {
|
|
39
28
|
if ("input" in transformer) return transformer;
|
|
@@ -64,11 +53,9 @@ function createTRPCHeyApiTypeResolvers() {
|
|
|
64
53
|
return {
|
|
65
54
|
string(ctx) {
|
|
66
55
|
if (ctx.schema.format === "date-time" || ctx.schema.format === "date") return ctx.$.type("Date");
|
|
67
|
-
return void 0;
|
|
68
56
|
},
|
|
69
57
|
number(ctx) {
|
|
70
58
|
if (ctx.schema.format === "bigint") return ctx.$.type("bigint");
|
|
71
|
-
return void 0;
|
|
72
59
|
}
|
|
73
60
|
};
|
|
74
61
|
}
|
|
@@ -77,7 +64,7 @@ function createTRPCHeyApiTypeResolvers() {
|
|
|
77
64
|
*/
|
|
78
65
|
function createTRPCHeyApiClientConfig(opts) {
|
|
79
66
|
const transformer = (opts === null || opts === void 0 ? void 0 : opts.transformer) ? resolveTransformer(opts.transformer) : void 0;
|
|
80
|
-
return
|
|
67
|
+
return require_objectSpread2._objectSpread2({ querySerializer: (query) => {
|
|
81
68
|
const params = new URLSearchParams();
|
|
82
69
|
for (const [key, value] of Object.entries(query)) {
|
|
83
70
|
if (value === void 0) continue;
|
|
@@ -128,14 +115,13 @@ function createTRPCErrorInterceptor(transformerOpts) {
|
|
|
128
115
|
* ```
|
|
129
116
|
*/
|
|
130
117
|
function configureTRPCHeyApiClient(client, opts) {
|
|
131
|
-
const { transformer } = opts, heyConfig = (
|
|
118
|
+
const { transformer } = opts, heyConfig = _objectWithoutProperties(opts, _excluded);
|
|
132
119
|
const trpcConfig = createTRPCHeyApiClientConfig({ transformer });
|
|
133
|
-
client.setConfig(
|
|
120
|
+
client.setConfig(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, heyConfig), trpcConfig));
|
|
134
121
|
if (transformer) client.interceptors.error.use(createTRPCErrorInterceptor(transformer));
|
|
135
122
|
}
|
|
136
|
-
|
|
137
123
|
//#endregion
|
|
138
124
|
exports.configureTRPCHeyApiClient = configureTRPCHeyApiClient;
|
|
139
125
|
exports.createTRPCErrorInterceptor = createTRPCErrorInterceptor;
|
|
140
126
|
exports.createTRPCHeyApiClientConfig = createTRPCHeyApiClientConfig;
|
|
141
|
-
exports.createTRPCHeyApiTypeResolvers = createTRPCHeyApiTypeResolvers;
|
|
127
|
+
exports.createTRPCHeyApiTypeResolvers = createTRPCHeyApiTypeResolvers;
|
package/dist/heyapi/index.d.cts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Plugins } from "@hey-api/openapi-ts";
|
|
2
2
|
import { TRPCCombinedDataTransformer, TRPCDataTransformer } from "@trpc/server";
|
|
3
|
-
|
|
4
3
|
//#region src/heyapi/index.d.ts
|
|
5
|
-
type DataTransformerOptions = TRPCDataTransformer | TRPCCombinedDataTransformer;
|
|
6
|
-
interface TRPCHeyApiClientOptions {
|
|
4
|
+
export type DataTransformerOptions = TRPCDataTransformer | TRPCCombinedDataTransformer;
|
|
5
|
+
export interface TRPCHeyApiClientOptions {
|
|
7
6
|
transformer?: DataTransformerOptions;
|
|
8
7
|
}
|
|
9
|
-
type HeyAPIResolvers = Plugins.HeyApiTypeScript.Resolvers;
|
|
10
|
-
type HeyApiConfig = ReturnType<Plugins.HeyApiClientFetch.Client['getConfig']>;
|
|
11
|
-
type TRPCHeyApiClientConfig = Required<Pick<HeyApiConfig, 'querySerializer'>> & Pick<HeyApiConfig, 'bodySerializer' | 'responseTransformer'>;
|
|
8
|
+
export type HeyAPIResolvers = Plugins.HeyApiTypeScript.Resolvers;
|
|
9
|
+
export type HeyApiConfig = ReturnType<Plugins.HeyApiClientFetch.Client['getConfig']>;
|
|
10
|
+
export type TRPCHeyApiClientConfig = Required<Pick<HeyApiConfig, 'querySerializer'>> & Pick<HeyApiConfig, 'bodySerializer' | 'responseTransformer'>;
|
|
12
11
|
/**
|
|
13
12
|
* Returns the `~resolvers` object for the `@hey-api/typescript` plugin.
|
|
14
13
|
*
|
|
@@ -27,11 +26,11 @@ type TRPCHeyApiClientConfig = Required<Pick<HeyApiConfig, 'querySerializer'>> &
|
|
|
27
26
|
* });
|
|
28
27
|
* ```
|
|
29
28
|
*/
|
|
30
|
-
declare function createTRPCHeyApiTypeResolvers(): HeyAPIResolvers;
|
|
29
|
+
export declare function createTRPCHeyApiTypeResolvers(): HeyAPIResolvers;
|
|
31
30
|
/**
|
|
32
31
|
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
33
32
|
*/
|
|
34
|
-
declare function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions): {
|
|
33
|
+
export declare function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions): {
|
|
35
34
|
readonly bodySerializer?: ((body: unknown) => string) | undefined;
|
|
36
35
|
readonly responseTransformer?: ((data: unknown) => Promise<unknown>) | undefined;
|
|
37
36
|
readonly querySerializer: (query: Record<string, unknown>) => string;
|
|
@@ -39,7 +38,7 @@ declare function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions): {
|
|
|
39
38
|
/**
|
|
40
39
|
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
41
40
|
*/
|
|
42
|
-
declare function createTRPCErrorInterceptor(transformerOpts: DataTransformerOptions): (error: unknown) => unknown;
|
|
41
|
+
export declare function createTRPCErrorInterceptor(transformerOpts: DataTransformerOptions): (error: unknown) => unknown;
|
|
43
42
|
/**
|
|
44
43
|
* Configures a hey-api client for use with a tRPC OpenAPI backend.
|
|
45
44
|
*
|
|
@@ -59,8 +58,6 @@ declare function createTRPCErrorInterceptor(transformerOpts: DataTransformerOpti
|
|
|
59
58
|
* });
|
|
60
59
|
* ```
|
|
61
60
|
*/
|
|
62
|
-
declare function configureTRPCHeyApiClient(client: Plugins.HeyApiClientFetch.Client, opts: TRPCHeyApiClientOptions & Omit<HeyApiConfig, keyof TRPCHeyApiClientConfig>): void;
|
|
63
|
-
//# sourceMappingURL=index.d.ts.map
|
|
61
|
+
export declare function configureTRPCHeyApiClient(client: Plugins.HeyApiClientFetch.Client, opts: TRPCHeyApiClientOptions & Omit<HeyApiConfig, keyof TRPCHeyApiClientConfig>): void;
|
|
64
62
|
//#endregion
|
|
65
|
-
export { DataTransformerOptions, HeyAPIResolvers, HeyApiConfig, TRPCHeyApiClientConfig, TRPCHeyApiClientOptions, configureTRPCHeyApiClient, createTRPCErrorInterceptor, createTRPCHeyApiClientConfig, createTRPCHeyApiTypeResolvers };
|
|
66
63
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/heyapi/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/heyapi/index.ts"],"mappings":";;;YAMY,yBACV,sBAAsB;iBACP;EACf,cAAc;;YAGJ,kBAAkB,QAAQ,iBAAiB;YAE3C,eAAe,WACzB,QAAQ,kBAAkB;YAGhB,yBAAyB,SACnC,KAAK,oCAEL,KAAK;;;;;;;;;;;;;;;;;;;wBA6BS,iCAAiC;;;;wBAoBjC,6BAA6B,OAAO;WA4BvB,mBAAA;WAIW,wBAAA,kBAAO;WA1BlB,kBAAA,OAAA;;;;;wBA2Cb,2BACd,iBAAiB,0BAGT;;;;;;;;;;;;;;;;;;;;wBA6BM,0BACd,QAAQ,QAAQ,kBAAkB,QAClC,MAAM,0BACJ,KAAK,oBAAoB"}
|
package/dist/heyapi/index.d.mts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Plugins } from "@hey-api/openapi-ts";
|
|
2
2
|
import { TRPCCombinedDataTransformer, TRPCDataTransformer } from "@trpc/server";
|
|
3
|
-
|
|
4
3
|
//#region src/heyapi/index.d.ts
|
|
5
|
-
type DataTransformerOptions = TRPCDataTransformer | TRPCCombinedDataTransformer;
|
|
6
|
-
interface TRPCHeyApiClientOptions {
|
|
4
|
+
export type DataTransformerOptions = TRPCDataTransformer | TRPCCombinedDataTransformer;
|
|
5
|
+
export interface TRPCHeyApiClientOptions {
|
|
7
6
|
transformer?: DataTransformerOptions;
|
|
8
7
|
}
|
|
9
|
-
type HeyAPIResolvers = Plugins.HeyApiTypeScript.Resolvers;
|
|
10
|
-
type HeyApiConfig = ReturnType<Plugins.HeyApiClientFetch.Client['getConfig']>;
|
|
11
|
-
type TRPCHeyApiClientConfig = Required<Pick<HeyApiConfig, 'querySerializer'>> & Pick<HeyApiConfig, 'bodySerializer' | 'responseTransformer'>;
|
|
8
|
+
export type HeyAPIResolvers = Plugins.HeyApiTypeScript.Resolvers;
|
|
9
|
+
export type HeyApiConfig = ReturnType<Plugins.HeyApiClientFetch.Client['getConfig']>;
|
|
10
|
+
export type TRPCHeyApiClientConfig = Required<Pick<HeyApiConfig, 'querySerializer'>> & Pick<HeyApiConfig, 'bodySerializer' | 'responseTransformer'>;
|
|
12
11
|
/**
|
|
13
12
|
* Returns the `~resolvers` object for the `@hey-api/typescript` plugin.
|
|
14
13
|
*
|
|
@@ -27,11 +26,11 @@ type TRPCHeyApiClientConfig = Required<Pick<HeyApiConfig, 'querySerializer'>> &
|
|
|
27
26
|
* });
|
|
28
27
|
* ```
|
|
29
28
|
*/
|
|
30
|
-
declare function createTRPCHeyApiTypeResolvers(): HeyAPIResolvers;
|
|
29
|
+
export declare function createTRPCHeyApiTypeResolvers(): HeyAPIResolvers;
|
|
31
30
|
/**
|
|
32
31
|
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
33
32
|
*/
|
|
34
|
-
declare function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions): {
|
|
33
|
+
export declare function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions): {
|
|
35
34
|
readonly bodySerializer?: ((body: unknown) => string) | undefined;
|
|
36
35
|
readonly responseTransformer?: ((data: unknown) => Promise<unknown>) | undefined;
|
|
37
36
|
readonly querySerializer: (query: Record<string, unknown>) => string;
|
|
@@ -39,7 +38,7 @@ declare function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions): {
|
|
|
39
38
|
/**
|
|
40
39
|
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
41
40
|
*/
|
|
42
|
-
declare function createTRPCErrorInterceptor(transformerOpts: DataTransformerOptions): (error: unknown) => unknown;
|
|
41
|
+
export declare function createTRPCErrorInterceptor(transformerOpts: DataTransformerOptions): (error: unknown) => unknown;
|
|
43
42
|
/**
|
|
44
43
|
* Configures a hey-api client for use with a tRPC OpenAPI backend.
|
|
45
44
|
*
|
|
@@ -59,8 +58,6 @@ declare function createTRPCErrorInterceptor(transformerOpts: DataTransformerOpti
|
|
|
59
58
|
* });
|
|
60
59
|
* ```
|
|
61
60
|
*/
|
|
62
|
-
declare function configureTRPCHeyApiClient(client: Plugins.HeyApiClientFetch.Client, opts: TRPCHeyApiClientOptions & Omit<HeyApiConfig, keyof TRPCHeyApiClientConfig>): void;
|
|
63
|
-
//# sourceMappingURL=index.d.ts.map
|
|
61
|
+
export declare function configureTRPCHeyApiClient(client: Plugins.HeyApiClientFetch.Client, opts: TRPCHeyApiClientOptions & Omit<HeyApiConfig, keyof TRPCHeyApiClientConfig>): void;
|
|
64
62
|
//#endregion
|
|
65
|
-
export { DataTransformerOptions, HeyAPIResolvers, HeyApiConfig, TRPCHeyApiClientConfig, TRPCHeyApiClientOptions, configureTRPCHeyApiClient, createTRPCErrorInterceptor, createTRPCHeyApiClientConfig, createTRPCHeyApiTypeResolvers };
|
|
66
63
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/heyapi/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/heyapi/index.ts"],"mappings":";;;YAMY,yBACV,sBAAsB;iBACP;EACf,cAAc;;YAGJ,kBAAkB,QAAQ,iBAAiB;YAE3C,eAAe,WACzB,QAAQ,kBAAkB;YAGhB,yBAAyB,SACnC,KAAK,oCAEL,KAAK;;;;;;;;;;;;;;;;;;;wBA6BS,iCAAiC;;;;wBAoBjC,6BAA6B,OAAO;WA4BvB,mBAAA;WAIW,wBAAA,kBAAO;WA1BlB,kBAAA,OAAA;;;;;wBA2Cb,2BACd,iBAAiB,0BAGT;;;;;;;;;;;;;;;;;;;;wBA6BM,0BACd,QAAQ,QAAQ,kBAAkB,QAClC,MAAM,0BACJ,KAAK,oBAAoB"}
|