@orpc/openapi 0.0.0-next.cba521d → 0.0.0-next.cc4cb21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -0
- package/dist/chunk-LTTK3H5J.js +157 -0
- package/dist/chunk-PW7RAFQQ.js +32 -0
- package/dist/chunk-XGHV4TH3.js +13 -0
- package/dist/fetch.js +5 -30
- package/dist/hono.js +5 -30
- package/dist/index.js +202 -51
- package/dist/next.js +5 -30
- package/dist/node.js +18 -34
- package/dist/src/adapters/fetch/index.d.ts +0 -8
- package/dist/src/adapters/fetch/openapi-handler.d.ts +8 -29
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/openapi-handler.d.ts +8 -8
- package/dist/src/adapters/standard/index.d.ts +4 -0
- package/dist/src/adapters/standard/openapi-codec.d.ts +13 -0
- package/dist/src/adapters/standard/openapi-handler.d.ts +5 -0
- package/dist/src/adapters/standard/openapi-matcher.d.ts +10 -0
- package/dist/src/index.d.ts +5 -1
- package/dist/src/openapi-generator.d.ts +4 -4
- package/dist/src/openapi-input-structure-parser.d.ts +2 -2
- package/dist/src/openapi-operation-extender.d.ts +7 -0
- package/dist/src/openapi-output-structure-parser.d.ts +2 -2
- package/dist/src/schema-converter.d.ts +2 -2
- package/dist/src/utils.d.ts +2 -16
- package/dist/standard.js +10 -0
- package/package.json +14 -12
- package/dist/chunk-EVWWILO6.js +0 -25
- package/dist/chunk-KNYXLM77.js +0 -107
- package/dist/chunk-X2HG5K4J.js +0 -651
- package/dist/src/adapters/fetch/bracket-notation.d.ts +0 -84
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
- package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
- package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
- package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/node/types.d.ts +0 -2
- package/dist/src/json-serializer.d.ts +0 -5
package/dist/index.js
CHANGED
|
@@ -1,9 +1,53 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
standardizeHTTPPath,
|
|
3
|
+
toOpenAPI31RoutePattern
|
|
4
|
+
} from "./chunk-XGHV4TH3.js";
|
|
5
|
+
|
|
6
|
+
// src/openapi-operation-extender.ts
|
|
7
|
+
import { isProcedure } from "@orpc/server";
|
|
8
|
+
var OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
9
|
+
function setOperationExtender(o, extend) {
|
|
10
|
+
return new Proxy(o, {
|
|
11
|
+
get(target, prop, receiver) {
|
|
12
|
+
if (prop === OPERATION_EXTENDER_SYMBOL) {
|
|
13
|
+
return extend;
|
|
14
|
+
}
|
|
15
|
+
return Reflect.get(target, prop, receiver);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function getOperationExtender(o) {
|
|
20
|
+
return o[OPERATION_EXTENDER_SYMBOL];
|
|
21
|
+
}
|
|
22
|
+
function extendOperation(operation, procedure) {
|
|
23
|
+
const operationExtenders = [];
|
|
24
|
+
for (const errorItem of Object.values(procedure["~orpc"].errorMap)) {
|
|
25
|
+
const maybeExtender = getOperationExtender(errorItem);
|
|
26
|
+
if (maybeExtender) {
|
|
27
|
+
operationExtenders.push(maybeExtender);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (isProcedure(procedure)) {
|
|
31
|
+
for (const middleware of procedure["~orpc"].middlewares) {
|
|
32
|
+
const maybeExtender = getOperationExtender(middleware);
|
|
33
|
+
if (maybeExtender) {
|
|
34
|
+
operationExtenders.push(maybeExtender);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
let currentOperation = operation;
|
|
39
|
+
for (const extender of operationExtenders) {
|
|
40
|
+
if (typeof extender === "function") {
|
|
41
|
+
currentOperation = extender(currentOperation, procedure);
|
|
42
|
+
} else {
|
|
43
|
+
currentOperation = {
|
|
44
|
+
...currentOperation,
|
|
45
|
+
...extender
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return currentOperation;
|
|
50
|
+
}
|
|
7
51
|
|
|
8
52
|
// src/openapi.ts
|
|
9
53
|
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
|
@@ -36,7 +80,10 @@ var OpenAPIContentBuilder = class {
|
|
|
36
80
|
};
|
|
37
81
|
|
|
38
82
|
// src/openapi-generator.ts
|
|
39
|
-
import { fallbackORPCErrorStatus
|
|
83
|
+
import { fallbackORPCErrorStatus } from "@orpc/client";
|
|
84
|
+
import { OpenAPIJsonSerializer } from "@orpc/client/openapi";
|
|
85
|
+
import { fallbackContractConfig as fallbackContractConfig2, getEventIteratorSchemaDetails } from "@orpc/contract";
|
|
86
|
+
import { eachAllContractProcedure } from "@orpc/server";
|
|
40
87
|
import { group } from "@orpc/shared";
|
|
41
88
|
|
|
42
89
|
// src/openapi-error.ts
|
|
@@ -44,7 +91,7 @@ var OpenAPIError = class extends Error {
|
|
|
44
91
|
};
|
|
45
92
|
|
|
46
93
|
// src/openapi-input-structure-parser.ts
|
|
47
|
-
import {
|
|
94
|
+
import { fallbackContractConfig } from "@orpc/contract";
|
|
48
95
|
var OpenAPIInputStructureParser = class {
|
|
49
96
|
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
50
97
|
this.schemaConverter = schemaConverter;
|
|
@@ -52,8 +99,8 @@ var OpenAPIInputStructureParser = class {
|
|
|
52
99
|
this.pathParser = pathParser;
|
|
53
100
|
}
|
|
54
101
|
parse(contract, structure) {
|
|
55
|
-
const inputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
56
|
-
const method =
|
|
102
|
+
const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
|
|
103
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
57
104
|
const httpPath = contract["~orpc"].route?.path;
|
|
58
105
|
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
59
106
|
return {
|
|
@@ -145,7 +192,7 @@ var OpenAPIOutputStructureParser = class {
|
|
|
145
192
|
this.schemaUtils = schemaUtils;
|
|
146
193
|
}
|
|
147
194
|
parse(contract, structure) {
|
|
148
|
-
const outputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
195
|
+
const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
|
|
149
196
|
if (this.schemaUtils.isAnySchema(outputSchema)) {
|
|
150
197
|
return {
|
|
151
198
|
headersSchema: void 0,
|
|
@@ -184,14 +231,14 @@ var OpenAPIOutputStructureParser = class {
|
|
|
184
231
|
};
|
|
185
232
|
|
|
186
233
|
// src/openapi-parameters-builder.ts
|
|
187
|
-
import { get,
|
|
234
|
+
import { get, isObject, omit } from "@orpc/shared";
|
|
188
235
|
var OpenAPIParametersBuilder = class {
|
|
189
236
|
build(paramIn, jsonSchema, options) {
|
|
190
237
|
const parameters = [];
|
|
191
238
|
for (const name in jsonSchema.properties) {
|
|
192
239
|
const schema = jsonSchema.properties[name];
|
|
193
240
|
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
194
|
-
return
|
|
241
|
+
return isObject(example) && name in example;
|
|
195
242
|
}).map((example) => {
|
|
196
243
|
return example[name];
|
|
197
244
|
});
|
|
@@ -252,7 +299,7 @@ var CompositeSchemaConverter = class {
|
|
|
252
299
|
};
|
|
253
300
|
|
|
254
301
|
// src/schema-utils.ts
|
|
255
|
-
import {
|
|
302
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
|
256
303
|
|
|
257
304
|
// src/schema.ts
|
|
258
305
|
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
@@ -288,10 +335,10 @@ var NON_LOGIC_KEYWORDS = [
|
|
|
288
335
|
// src/schema-utils.ts
|
|
289
336
|
var SchemaUtils = class {
|
|
290
337
|
isFileSchema(schema) {
|
|
291
|
-
return
|
|
338
|
+
return isObject2(schema) && schema.type === "string" && typeof schema.contentMediaType === "string";
|
|
292
339
|
}
|
|
293
340
|
isObjectSchema(schema) {
|
|
294
|
-
return
|
|
341
|
+
return isObject2(schema) && schema.type === "object";
|
|
295
342
|
}
|
|
296
343
|
isAnySchema(schema) {
|
|
297
344
|
return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
|
|
@@ -314,7 +361,7 @@ var SchemaUtils = class {
|
|
|
314
361
|
}, {});
|
|
315
362
|
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
316
363
|
matched.examples = schema.examples?.map((example) => {
|
|
317
|
-
if (!
|
|
364
|
+
if (!isObject2(example)) {
|
|
318
365
|
return example;
|
|
319
366
|
}
|
|
320
367
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -330,7 +377,7 @@ var SchemaUtils = class {
|
|
|
330
377
|
}, {});
|
|
331
378
|
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
332
379
|
rest.examples = schema.examples?.map((example) => {
|
|
333
|
-
if (!
|
|
380
|
+
if (!isObject2(example)) {
|
|
334
381
|
return example;
|
|
335
382
|
}
|
|
336
383
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -390,7 +437,7 @@ var OpenAPIGenerator = class {
|
|
|
390
437
|
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
391
438
|
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
392
439
|
this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
|
|
393
|
-
this.jsonSerializer = options?.jsonSerializer ?? new
|
|
440
|
+
this.jsonSerializer = options?.jsonSerializer ?? new OpenAPIJsonSerializer();
|
|
394
441
|
this.contentBuilder = options?.contentBuilder ?? new OpenAPIContentBuilder(this.schemaUtils);
|
|
395
442
|
this.pathParser = new OpenAPIPathParser();
|
|
396
443
|
this.inputStructureParser = options?.inputStructureParser ?? new OpenAPIInputStructureParser(this.schemaConverter, this.schemaUtils, this.pathParser);
|
|
@@ -406,38 +453,134 @@ var OpenAPIGenerator = class {
|
|
|
406
453
|
openapi: "3.1.1"
|
|
407
454
|
});
|
|
408
455
|
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
409
|
-
await
|
|
456
|
+
await eachAllContractProcedure({
|
|
457
|
+
path: [],
|
|
458
|
+
router
|
|
459
|
+
}, ({ contract, path }) => {
|
|
410
460
|
try {
|
|
411
461
|
const def = contract["~orpc"];
|
|
412
462
|
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
413
463
|
return;
|
|
414
464
|
}
|
|
415
|
-
const method =
|
|
416
|
-
const httpPath = def.route?.path ?
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
465
|
+
const method = fallbackContractConfig2("defaultMethod", def.route?.method);
|
|
466
|
+
const httpPath = def.route?.path ? toOpenAPI31RoutePattern(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
467
|
+
const { parameters, requestBody } = (() => {
|
|
468
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.inputSchema);
|
|
469
|
+
if (eventIteratorSchemaDetails) {
|
|
470
|
+
const requestBody3 = {
|
|
471
|
+
required: true,
|
|
472
|
+
content: {
|
|
473
|
+
"text/event-stream": {
|
|
474
|
+
schema: {
|
|
475
|
+
oneOf: [
|
|
476
|
+
{
|
|
477
|
+
type: "object",
|
|
478
|
+
properties: {
|
|
479
|
+
event: { type: "string", const: "message" },
|
|
480
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
|
|
481
|
+
id: { type: "string" },
|
|
482
|
+
retry: { type: "number" }
|
|
483
|
+
},
|
|
484
|
+
required: ["event", "data"]
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
type: "object",
|
|
488
|
+
properties: {
|
|
489
|
+
event: { type: "string", const: "done" },
|
|
490
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
|
|
491
|
+
id: { type: "string" },
|
|
492
|
+
retry: { type: "number" }
|
|
493
|
+
},
|
|
494
|
+
required: ["event", "data"]
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
type: "object",
|
|
498
|
+
properties: {
|
|
499
|
+
event: { type: "string", const: "error" },
|
|
500
|
+
data: {},
|
|
501
|
+
id: { type: "string" },
|
|
502
|
+
retry: { type: "number" }
|
|
503
|
+
},
|
|
504
|
+
required: ["event", "data"]
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
return { requestBody: requestBody3, parameters: [] };
|
|
512
|
+
}
|
|
513
|
+
const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
|
|
514
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
515
|
+
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
516
|
+
required: true
|
|
517
|
+
}) : [];
|
|
518
|
+
const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
|
|
519
|
+
const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
|
|
520
|
+
const parameters2 = [...params, ...query, ...headers];
|
|
521
|
+
const requestBody2 = bodySchema !== void 0 ? {
|
|
522
|
+
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
|
523
|
+
content: this.contentBuilder.build(bodySchema)
|
|
524
|
+
} : void 0;
|
|
525
|
+
return { parameters: parameters2, requestBody: requestBody2 };
|
|
526
|
+
})();
|
|
527
|
+
const { responses } = (() => {
|
|
528
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.outputSchema);
|
|
529
|
+
if (eventIteratorSchemaDetails) {
|
|
530
|
+
const responses3 = {};
|
|
531
|
+
responses3[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
532
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
533
|
+
content: {
|
|
534
|
+
"text/event-stream": {
|
|
535
|
+
schema: {
|
|
536
|
+
oneOf: [
|
|
537
|
+
{
|
|
538
|
+
type: "object",
|
|
539
|
+
properties: {
|
|
540
|
+
event: { type: "string", const: "message" },
|
|
541
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
|
|
542
|
+
id: { type: "string" },
|
|
543
|
+
retry: { type: "number" }
|
|
544
|
+
},
|
|
545
|
+
required: ["event", "data"]
|
|
546
|
+
},
|
|
547
|
+
{
|
|
548
|
+
type: "object",
|
|
549
|
+
properties: {
|
|
550
|
+
event: { type: "string", const: "done" },
|
|
551
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
|
|
552
|
+
id: { type: "string" },
|
|
553
|
+
retry: { type: "number" }
|
|
554
|
+
},
|
|
555
|
+
required: ["event", "data"]
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
type: "object",
|
|
559
|
+
properties: {
|
|
560
|
+
event: { type: "string", const: "error" },
|
|
561
|
+
data: {},
|
|
562
|
+
id: { type: "string" },
|
|
563
|
+
retry: { type: "number" }
|
|
564
|
+
},
|
|
565
|
+
required: ["event", "data"]
|
|
566
|
+
}
|
|
567
|
+
]
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
return { responses: responses3 };
|
|
573
|
+
}
|
|
574
|
+
const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
|
|
575
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
576
|
+
const responses2 = {};
|
|
577
|
+
responses2[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
578
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
579
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
|
|
580
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
|
|
581
|
+
};
|
|
582
|
+
return { responses: responses2 };
|
|
583
|
+
})();
|
|
441
584
|
const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
|
|
442
585
|
...config,
|
|
443
586
|
code,
|
|
@@ -508,8 +651,9 @@ var OpenAPIGenerator = class {
|
|
|
508
651
|
requestBody,
|
|
509
652
|
responses
|
|
510
653
|
};
|
|
654
|
+
const extendedOperation = extendOperation(operation, contract);
|
|
511
655
|
builder.addPath(httpPath, {
|
|
512
|
-
[method.toLocaleLowerCase()]:
|
|
656
|
+
[method.toLocaleLowerCase()]: extendedOperation
|
|
513
657
|
});
|
|
514
658
|
} catch (e) {
|
|
515
659
|
if (e instanceof OpenAPIError) {
|
|
@@ -528,14 +672,18 @@ var OpenAPIGenerator = class {
|
|
|
528
672
|
}
|
|
529
673
|
}
|
|
530
674
|
});
|
|
531
|
-
return this.jsonSerializer.serialize(builder.getSpec());
|
|
675
|
+
return this.jsonSerializer.serialize(builder.getSpec())[0];
|
|
532
676
|
}
|
|
533
677
|
};
|
|
678
|
+
|
|
679
|
+
// src/index.ts
|
|
680
|
+
var oo = {
|
|
681
|
+
spec: setOperationExtender
|
|
682
|
+
};
|
|
534
683
|
export {
|
|
535
684
|
CompositeSchemaConverter,
|
|
536
685
|
JSONSchema,
|
|
537
686
|
Format as JSONSchemaFormat,
|
|
538
|
-
JSONSerializer,
|
|
539
687
|
NON_LOGIC_KEYWORDS,
|
|
540
688
|
OpenAPIContentBuilder,
|
|
541
689
|
OpenAPIGenerator,
|
|
@@ -543,8 +691,11 @@ export {
|
|
|
543
691
|
OpenAPIPathParser,
|
|
544
692
|
OpenApiBuilder,
|
|
545
693
|
SchemaUtils,
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
694
|
+
extendOperation,
|
|
695
|
+
getOperationExtender,
|
|
696
|
+
oo,
|
|
697
|
+
setOperationExtender,
|
|
698
|
+
standardizeHTTPPath,
|
|
699
|
+
toOpenAPI31RoutePattern
|
|
549
700
|
};
|
|
550
701
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
CompositeSchemaCoercer,
|
|
7
|
-
InputStructureCompact,
|
|
8
|
-
InputStructureDetailed,
|
|
9
|
-
OpenAPIHandler,
|
|
10
|
-
OpenAPIPayloadCodec,
|
|
11
|
-
OpenAPIProcedureMatcher,
|
|
12
|
-
deserialize,
|
|
13
|
-
escapeSegment,
|
|
14
|
-
parsePath,
|
|
15
|
-
serialize,
|
|
16
|
-
stringifyPath
|
|
17
|
-
} from "./chunk-X2HG5K4J.js";
|
|
18
|
-
import "./chunk-KNYXLM77.js";
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-PW7RAFQQ.js";
|
|
4
|
+
import "./chunk-LTTK3H5J.js";
|
|
5
|
+
import "./chunk-XGHV4TH3.js";
|
|
19
6
|
export {
|
|
20
|
-
|
|
21
|
-
InputStructureCompact,
|
|
22
|
-
InputStructureDetailed,
|
|
23
|
-
OpenAPIHandler,
|
|
24
|
-
OpenAPIPayloadCodec,
|
|
25
|
-
OpenAPIProcedureMatcher,
|
|
26
|
-
OpenAPIServerHandler,
|
|
27
|
-
OpenAPIServerlessHandler,
|
|
28
|
-
deserialize,
|
|
29
|
-
escapeSegment,
|
|
30
|
-
parsePath,
|
|
31
|
-
serialize,
|
|
32
|
-
stringifyPath
|
|
7
|
+
OpenAPIHandler
|
|
33
8
|
};
|
|
34
9
|
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
|
@@ -1,46 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
OpenAPICodec,
|
|
3
|
+
OpenAPIMatcher
|
|
4
|
+
} from "./chunk-LTTK3H5J.js";
|
|
5
|
+
import "./chunk-XGHV4TH3.js";
|
|
5
6
|
|
|
6
7
|
// src/adapters/node/openapi-handler.ts
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import { StandardHandler } from "@orpc/server/standard";
|
|
9
|
+
import { sendStandardResponse, toStandardRequest } from "@orpc/standard-server-node";
|
|
10
|
+
var OpenAPIHandler = class {
|
|
11
|
+
standardHandler;
|
|
12
|
+
constructor(router, options) {
|
|
13
|
+
const matcher = options?.matcher ?? new OpenAPIMatcher();
|
|
14
|
+
const codec = options?.codec ?? new OpenAPICodec();
|
|
15
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
|
|
12
16
|
}
|
|
13
|
-
async handle(req, res, ...
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
if (result.matched === false) {
|
|
17
|
+
async handle(req, res, ...rest) {
|
|
18
|
+
const standardRequest = toStandardRequest(req, res);
|
|
19
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
20
|
+
if (!result.matched) {
|
|
18
21
|
return { matched: false };
|
|
19
22
|
}
|
|
20
|
-
await
|
|
21
|
-
await sendResponse(res, result.response);
|
|
23
|
+
await sendStandardResponse(res, result.response);
|
|
22
24
|
return { matched: true };
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
|
-
|
|
26
|
-
// src/adapters/node/openapi-handler-server.ts
|
|
27
|
-
import { TrieRouter } from "hono/router/trie-router";
|
|
28
|
-
var OpenAPIServerHandler = class extends OpenAPIHandler2 {
|
|
29
|
-
constructor(router, options) {
|
|
30
|
-
super(new TrieRouter(), router, options);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/adapters/node/openapi-handler-serverless.ts
|
|
35
|
-
import { LinearRouter } from "hono/router/linear-router";
|
|
36
|
-
var OpenAPIServerlessHandler = class extends OpenAPIHandler2 {
|
|
37
|
-
constructor(router, options) {
|
|
38
|
-
super(new LinearRouter(), router, options);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
27
|
export {
|
|
42
|
-
|
|
43
|
-
OpenAPIServerHandler,
|
|
44
|
-
OpenAPIServerlessHandler
|
|
28
|
+
OpenAPIHandler
|
|
45
29
|
};
|
|
46
30
|
//# sourceMappingURL=node.js.map
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
export * from './bracket-notation';
|
|
2
|
-
export * from './input-structure-compact';
|
|
3
|
-
export * from './input-structure-detailed';
|
|
4
1
|
export * from './openapi-handler';
|
|
5
|
-
export * from './openapi-handler-server';
|
|
6
|
-
export * from './openapi-handler-serverless';
|
|
7
|
-
export * from './openapi-payload-codec';
|
|
8
|
-
export * from './openapi-procedure-matcher';
|
|
9
|
-
export * from './schema-coercer';
|
|
10
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,32 +1,11 @@
|
|
|
1
|
-
import type { Context, Router
|
|
2
|
-
import type { FetchHandler,
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { type PublicInputStructureDetailed } from './input-structure-detailed';
|
|
7
|
-
import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
|
|
8
|
-
import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
|
|
9
|
-
import { type SchemaCoercer } from './schema-coercer';
|
|
10
|
-
export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, WithSignal> & {
|
|
11
|
-
jsonSerializer?: PublicJSONSerializer;
|
|
12
|
-
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
|
13
|
-
payloadCodec?: PublicOpenAPIPayloadCodec;
|
|
14
|
-
inputBuilderSimple?: PublicInputStructureCompact;
|
|
15
|
-
inputBuilderFull?: PublicInputStructureDetailed;
|
|
16
|
-
schemaCoercers?: SchemaCoercer[];
|
|
17
|
-
};
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
|
3
|
+
import type { StandardHandleOptions } from '@orpc/server/standard';
|
|
4
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
|
5
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
|
18
6
|
export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
|
19
|
-
private readonly
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
private readonly inputStructureCompact;
|
|
23
|
-
private readonly inputStructureDetailed;
|
|
24
|
-
private readonly compositeSchemaCoercer;
|
|
25
|
-
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>> | undefined);
|
|
26
|
-
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
|
27
|
-
private decodeInput;
|
|
28
|
-
private encodeOutput;
|
|
29
|
-
private assertDetailedOutput;
|
|
30
|
-
private convertToORPCError;
|
|
7
|
+
private readonly standardHandler;
|
|
8
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
9
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
|
31
10
|
}
|
|
32
11
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Context, Router } from '@orpc/server';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
export declare class OpenAPIHandler<T extends Context> implements
|
|
7
|
-
private readonly
|
|
8
|
-
constructor(
|
|
9
|
-
handle(req:
|
|
2
|
+
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from '@orpc/server/node';
|
|
3
|
+
import type { StandardHandleOptions } from '@orpc/server/standard';
|
|
4
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
|
5
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
|
6
|
+
export declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
|
7
|
+
private readonly standardHandler;
|
|
8
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
9
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ORPCError } from '@orpc/client';
|
|
2
|
+
import type { AnyProcedure } from '@orpc/server';
|
|
3
|
+
import type { StandardCodec, StandardParams } from '@orpc/server/standard';
|
|
4
|
+
import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
|
|
5
|
+
import { OpenAPISerializer } from '@orpc/client/openapi';
|
|
6
|
+
export declare class OpenAPICodec implements StandardCodec {
|
|
7
|
+
private readonly serializer;
|
|
8
|
+
constructor(serializer?: OpenAPISerializer);
|
|
9
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
10
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
11
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=openapi-codec.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AnyRouter } from '@orpc/server';
|
|
2
|
+
import type { StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
|
3
|
+
import { type HTTPPath } from '@orpc/contract';
|
|
4
|
+
export declare class OpenAPIMatcher implements StandardMatcher {
|
|
5
|
+
private readonly tree;
|
|
6
|
+
private pendingRouters;
|
|
7
|
+
init(router: AnyRouter, path?: string[]): void;
|
|
8
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=openapi-matcher.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
|
-
|
|
2
|
+
import { setOperationExtender } from './openapi-operation-extender';
|
|
3
3
|
export * from './openapi';
|
|
4
4
|
export * from './openapi-content-builder';
|
|
5
5
|
export * from './openapi-generator';
|
|
6
|
+
export * from './openapi-operation-extender';
|
|
6
7
|
export * from './openapi-parameters-builder';
|
|
7
8
|
export * from './openapi-path-parser';
|
|
8
9
|
export * from './schema';
|
|
9
10
|
export * from './schema-converter';
|
|
10
11
|
export * from './schema-utils';
|
|
11
12
|
export * from './utils';
|
|
13
|
+
export declare const oo: {
|
|
14
|
+
spec: typeof setOperationExtender;
|
|
15
|
+
};
|
|
12
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ANY_ROUTER } from '@orpc/server';
|
|
2
1
|
import type { PublicOpenAPIInputStructureParser } from './openapi-input-structure-parser';
|
|
3
2
|
import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
|
|
4
3
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
5
4
|
import type { SchemaConverter } from './schema-converter';
|
|
5
|
+
import { OpenAPIJsonSerializer } from '@orpc/client/openapi';
|
|
6
6
|
import { type ContractRouter } from '@orpc/contract';
|
|
7
|
-
import { type
|
|
7
|
+
import { type AnyRouter } from '@orpc/server';
|
|
8
8
|
import { type OpenAPI } from './openapi';
|
|
9
9
|
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
10
10
|
import { type PublicOpenAPIParametersBuilder } from './openapi-parameters-builder';
|
|
@@ -15,7 +15,7 @@ export interface OpenAPIGeneratorOptions {
|
|
|
15
15
|
parametersBuilder?: PublicOpenAPIParametersBuilder;
|
|
16
16
|
schemaConverters?: SchemaConverter[];
|
|
17
17
|
schemaUtils?: PublicSchemaUtils;
|
|
18
|
-
jsonSerializer?:
|
|
18
|
+
jsonSerializer?: OpenAPIJsonSerializer;
|
|
19
19
|
pathParser?: PublicOpenAPIPathParser;
|
|
20
20
|
inputStructureParser?: PublicOpenAPIInputStructureParser;
|
|
21
21
|
outputStructureParser?: PublicOpenAPIOutputStructureParser;
|
|
@@ -61,7 +61,7 @@ export declare class OpenAPIGenerator {
|
|
|
61
61
|
private readonly considerMissingTagDefinitionAsError;
|
|
62
62
|
private readonly strictErrorResponses;
|
|
63
63
|
constructor(options?: OpenAPIGeneratorOptions);
|
|
64
|
-
generate(router: ContractRouter |
|
|
64
|
+
generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
|
65
65
|
}
|
|
66
66
|
export {};
|
|
67
67
|
//# sourceMappingURL=openapi-generator.d.ts.map
|