@orpc/openapi 0.39.0 → 0.40.0
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/{chunk-SE4JDETS.js → chunk-5QMOOQSF.js} +2 -2
- package/dist/{chunk-MEP42INL.js → chunk-TOZPXKQC.js} +31 -1
- package/dist/fetch.js +2 -2
- package/dist/hono.js +2 -2
- package/dist/index.js +118 -21
- package/dist/next.js +2 -2
- package/dist/node.js +1 -1
- package/dist/standard.js +1 -1
- package/package.json +7 -10
@@ -1,7 +1,7 @@
|
|
1
1
|
import {
|
2
2
|
OpenAPICodec,
|
3
3
|
OpenAPIMatcher
|
4
|
-
} from "./chunk-
|
4
|
+
} from "./chunk-TOZPXKQC.js";
|
5
5
|
|
6
6
|
// src/adapters/fetch/openapi-handler.ts
|
7
7
|
import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
|
@@ -29,4 +29,4 @@ var OpenAPIHandler = class {
|
|
29
29
|
export {
|
30
30
|
OpenAPIHandler
|
31
31
|
};
|
32
|
-
//# sourceMappingURL=chunk-
|
32
|
+
//# sourceMappingURL=chunk-5QMOOQSF.js.map
|
@@ -226,6 +226,8 @@ import { fallbackContractConfig } from "@orpc/contract";
|
|
226
226
|
import { isObject as isObject2 } from "@orpc/shared";
|
227
227
|
|
228
228
|
// src/adapters/standard/openapi-serializer.ts
|
229
|
+
import { mapEventIterator, ORPCError, toORPCError } from "@orpc/contract";
|
230
|
+
import { ErrorEvent, isAsyncIteratorObject } from "@orpc/server-standard";
|
229
231
|
import { findDeepMatches } from "@orpc/shared";
|
230
232
|
var OpenAPISerializer = class {
|
231
233
|
jsonSerializer;
|
@@ -236,6 +238,23 @@ var OpenAPISerializer = class {
|
|
236
238
|
if (data instanceof Blob || data === void 0) {
|
237
239
|
return data;
|
238
240
|
}
|
241
|
+
if (isAsyncIteratorObject(data)) {
|
242
|
+
return mapEventIterator(data, {
|
243
|
+
value: async (value) => this.jsonSerializer.serialize(value),
|
244
|
+
error: async (e) => {
|
245
|
+
if (e instanceof ErrorEvent) {
|
246
|
+
return new ErrorEvent({
|
247
|
+
data: this.jsonSerializer.serialize(e.data),
|
248
|
+
cause: e
|
249
|
+
});
|
250
|
+
}
|
251
|
+
return new ErrorEvent({
|
252
|
+
data: this.jsonSerializer.serialize(toORPCError(e).toJSON()),
|
253
|
+
cause: e
|
254
|
+
});
|
255
|
+
}
|
256
|
+
});
|
257
|
+
}
|
239
258
|
const serializedJSON = this.jsonSerializer.serialize(data);
|
240
259
|
const { values: blobs } = findDeepMatches((v) => v instanceof Blob, serializedJSON);
|
241
260
|
if (blobs.length === 0) {
|
@@ -257,6 +276,17 @@ var OpenAPISerializer = class {
|
|
257
276
|
if (serialized instanceof URLSearchParams || serialized instanceof FormData) {
|
258
277
|
return deserialize([...serialized.entries()]);
|
259
278
|
}
|
279
|
+
if (isAsyncIteratorObject(serialized)) {
|
280
|
+
return mapEventIterator(serialized, {
|
281
|
+
value: async (value) => value,
|
282
|
+
error: async (e) => {
|
283
|
+
if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
|
284
|
+
return ORPCError.fromJSON(e.data, { cause: e });
|
285
|
+
}
|
286
|
+
return e;
|
287
|
+
}
|
288
|
+
});
|
289
|
+
}
|
260
290
|
return serialized;
|
261
291
|
}
|
262
292
|
};
|
@@ -417,4 +447,4 @@ export {
|
|
417
447
|
OpenAPICodec,
|
418
448
|
OpenAPIMatcher
|
419
449
|
};
|
420
|
-
//# sourceMappingURL=chunk-
|
450
|
+
//# sourceMappingURL=chunk-TOZPXKQC.js.map
|
package/dist/fetch.js
CHANGED
package/dist/hono.js
CHANGED
package/dist/index.js
CHANGED
@@ -80,7 +80,7 @@ var OpenAPIContentBuilder = class {
|
|
80
80
|
};
|
81
81
|
|
82
82
|
// src/openapi-generator.ts
|
83
|
-
import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus } from "@orpc/contract";
|
83
|
+
import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus, getEventIteratorSchemaDetails } from "@orpc/contract";
|
84
84
|
import { eachAllContractProcedure } from "@orpc/server";
|
85
85
|
import { group } from "@orpc/shared";
|
86
86
|
|
@@ -462,26 +462,123 @@ var OpenAPIGenerator = class {
|
|
462
462
|
}
|
463
463
|
const method = fallbackContractConfig2("defaultMethod", def.route?.method);
|
464
464
|
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
465
|
-
const
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
465
|
+
const { parameters, requestBody } = (() => {
|
466
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.inputSchema);
|
467
|
+
if (eventIteratorSchemaDetails) {
|
468
|
+
const requestBody3 = {
|
469
|
+
required: true,
|
470
|
+
content: {
|
471
|
+
"text/event-stream": {
|
472
|
+
schema: {
|
473
|
+
oneOf: [
|
474
|
+
{
|
475
|
+
type: "object",
|
476
|
+
properties: {
|
477
|
+
event: { type: "string", const: "message" },
|
478
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
|
479
|
+
id: { type: "string" },
|
480
|
+
retry: { type: "number" }
|
481
|
+
},
|
482
|
+
required: ["event", "data"]
|
483
|
+
},
|
484
|
+
{
|
485
|
+
type: "object",
|
486
|
+
properties: {
|
487
|
+
event: { type: "string", const: "done" },
|
488
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
|
489
|
+
id: { type: "string" },
|
490
|
+
retry: { type: "number" }
|
491
|
+
},
|
492
|
+
required: ["event", "data"]
|
493
|
+
},
|
494
|
+
{
|
495
|
+
type: "object",
|
496
|
+
properties: {
|
497
|
+
event: { type: "string", const: "error" },
|
498
|
+
data: {},
|
499
|
+
id: { type: "string" },
|
500
|
+
retry: { type: "number" }
|
501
|
+
},
|
502
|
+
required: ["event", "data"]
|
503
|
+
}
|
504
|
+
]
|
505
|
+
}
|
506
|
+
}
|
507
|
+
}
|
508
|
+
};
|
509
|
+
return { requestBody: requestBody3, parameters: [] };
|
510
|
+
}
|
511
|
+
const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
|
512
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
513
|
+
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
514
|
+
required: true
|
515
|
+
}) : [];
|
516
|
+
const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
|
517
|
+
const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
|
518
|
+
const parameters2 = [...params, ...query, ...headers];
|
519
|
+
const requestBody2 = bodySchema !== void 0 ? {
|
520
|
+
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
521
|
+
content: this.contentBuilder.build(bodySchema)
|
522
|
+
} : void 0;
|
523
|
+
return { parameters: parameters2, requestBody: requestBody2 };
|
524
|
+
})();
|
525
|
+
const { responses } = (() => {
|
526
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.outputSchema);
|
527
|
+
if (eventIteratorSchemaDetails) {
|
528
|
+
const responses3 = {};
|
529
|
+
responses3[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
530
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
531
|
+
content: {
|
532
|
+
"text/event-stream": {
|
533
|
+
schema: {
|
534
|
+
oneOf: [
|
535
|
+
{
|
536
|
+
type: "object",
|
537
|
+
properties: {
|
538
|
+
event: { type: "string", const: "message" },
|
539
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
|
540
|
+
id: { type: "string" },
|
541
|
+
retry: { type: "number" }
|
542
|
+
},
|
543
|
+
required: ["event", "data"]
|
544
|
+
},
|
545
|
+
{
|
546
|
+
type: "object",
|
547
|
+
properties: {
|
548
|
+
event: { type: "string", const: "done" },
|
549
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
|
550
|
+
id: { type: "string" },
|
551
|
+
retry: { type: "number" }
|
552
|
+
},
|
553
|
+
required: ["event", "data"]
|
554
|
+
},
|
555
|
+
{
|
556
|
+
type: "object",
|
557
|
+
properties: {
|
558
|
+
event: { type: "string", const: "error" },
|
559
|
+
data: {},
|
560
|
+
id: { type: "string" },
|
561
|
+
retry: { type: "number" }
|
562
|
+
},
|
563
|
+
required: ["event", "data"]
|
564
|
+
}
|
565
|
+
]
|
566
|
+
}
|
567
|
+
}
|
568
|
+
}
|
569
|
+
};
|
570
|
+
return { responses: responses3 };
|
571
|
+
}
|
572
|
+
const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
|
573
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
574
|
+
const responses2 = {};
|
575
|
+
responses2[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
576
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
577
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
|
578
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
|
579
|
+
};
|
580
|
+
return { responses: responses2 };
|
581
|
+
})();
|
485
582
|
const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
|
486
583
|
...config,
|
487
584
|
code,
|
package/dist/next.js
CHANGED
package/dist/node.js
CHANGED
package/dist/standard.js
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/openapi",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.40.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -54,18 +54,15 @@
|
|
54
54
|
"dist"
|
55
55
|
],
|
56
56
|
"dependencies": {
|
57
|
-
"@orpc/server-standard": "^0.
|
58
|
-
"@orpc/server-standard-fetch": "^0.
|
59
|
-
"@orpc/server-standard-node": "^0.
|
60
|
-
"escape-string-regexp": "^5.0.0",
|
61
|
-
"fast-content-type-parse": "^2.0.0",
|
57
|
+
"@orpc/server-standard": "^0.4.0",
|
58
|
+
"@orpc/server-standard-fetch": "^0.4.0",
|
59
|
+
"@orpc/server-standard-node": "^0.4.0",
|
62
60
|
"json-schema-typed": "^8.0.1",
|
63
61
|
"openapi3-ts": "^4.4.0",
|
64
62
|
"rou3": "^0.5.1",
|
65
|
-
"
|
66
|
-
"@orpc/server": "0.
|
67
|
-
"@orpc/
|
68
|
-
"@orpc/shared": "0.39.0"
|
63
|
+
"@orpc/contract": "0.40.0",
|
64
|
+
"@orpc/server": "0.40.0",
|
65
|
+
"@orpc/shared": "0.40.0"
|
69
66
|
},
|
70
67
|
"devDependencies": {
|
71
68
|
"@readme/openapi-parser": "^2.6.0",
|