@orpc/openapi 0.38.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.
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  OpenAPICodec,
3
3
  OpenAPIMatcher
4
- } from "./chunk-DRV7KYES.js";
4
+ } from "./chunk-TOZPXKQC.js";
5
5
 
6
6
  // src/adapters/fetch/openapi-handler.ts
7
- import { fetchRequestToStandardRequest, standardResponseToFetchResponse } from "@orpc/server/fetch";
7
+ import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
8
8
  import { StandardHandler } from "@orpc/server/standard";
9
9
  var OpenAPIHandler = class {
10
10
  standardHandler;
@@ -14,14 +14,14 @@ var OpenAPIHandler = class {
14
14
  this.standardHandler = new StandardHandler(router, matcher, codec, options);
15
15
  }
16
16
  async handle(request, ...rest) {
17
- const standardRequest = fetchRequestToStandardRequest(request);
17
+ const standardRequest = toStandardRequest(request);
18
18
  const result = await this.standardHandler.handle(standardRequest, ...rest);
19
19
  if (!result.matched) {
20
20
  return result;
21
21
  }
22
22
  return {
23
23
  matched: true,
24
- response: standardResponseToFetchResponse(result.response)
24
+ response: toFetchResponse(result.response)
25
25
  };
26
26
  }
27
27
  };
@@ -29,4 +29,4 @@ var OpenAPIHandler = class {
29
29
  export {
30
30
  OpenAPIHandler
31
31
  };
32
- //# sourceMappingURL=chunk-NHYWV7BW.js.map
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-DRV7KYES.js.map
450
+ //# sourceMappingURL=chunk-TOZPXKQC.js.map
package/dist/fetch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-NHYWV7BW.js";
4
- import "./chunk-DRV7KYES.js";
3
+ } from "./chunk-5QMOOQSF.js";
4
+ import "./chunk-TOZPXKQC.js";
5
5
  import "./chunk-HC5PVG4R.js";
6
6
  export {
7
7
  OpenAPIHandler
package/dist/hono.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-NHYWV7BW.js";
4
- import "./chunk-DRV7KYES.js";
3
+ } from "./chunk-5QMOOQSF.js";
4
+ import "./chunk-TOZPXKQC.js";
5
5
  import "./chunk-HC5PVG4R.js";
6
6
  export {
7
7
  OpenAPIHandler
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 inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
466
- const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
467
- const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
468
- const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
469
- const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
470
- required: true
471
- }) : [];
472
- const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
473
- const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
474
- const parameters = [...params, ...query, ...headers];
475
- const requestBody = bodySchema !== void 0 ? {
476
- required: this.schemaUtils.isUndefinableSchema(bodySchema),
477
- content: this.contentBuilder.build(bodySchema)
478
- } : void 0;
479
- const responses = {};
480
- responses[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
481
- description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
482
- content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
483
- headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
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
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-NHYWV7BW.js";
4
- import "./chunk-DRV7KYES.js";
3
+ } from "./chunk-5QMOOQSF.js";
4
+ import "./chunk-TOZPXKQC.js";
5
5
  import "./chunk-HC5PVG4R.js";
6
6
  export {
7
7
  OpenAPIHandler
package/dist/node.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  OpenAPICodec,
3
3
  OpenAPIMatcher
4
- } from "./chunk-DRV7KYES.js";
4
+ } from "./chunk-TOZPXKQC.js";
5
5
  import "./chunk-HC5PVG4R.js";
6
6
 
7
7
  // src/adapters/node/openapi-handler.ts
8
- import { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/node";
8
+ import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
9
9
  import { StandardHandler } from "@orpc/server/standard";
10
10
  var OpenAPIHandler = class {
11
11
  standardHandler;
@@ -15,12 +15,12 @@ var OpenAPIHandler = class {
15
15
  this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
16
16
  }
17
17
  async handle(req, res, ...rest) {
18
- const standardRequest = nodeHttpToStandardRequest(req, res);
18
+ const standardRequest = toStandardRequest(req, res);
19
19
  const result = await this.standardHandler.handle(standardRequest, ...rest);
20
20
  if (!result.matched) {
21
21
  return { matched: false };
22
22
  }
23
- await nodeHttpResponseSendStandardResponse(res, result.response);
23
+ await sendStandardResponse(res, result.response);
24
24
  return { matched: true };
25
25
  }
26
26
  };
@@ -1,5 +1,6 @@
1
1
  import type { AnyProcedure } from '@orpc/server';
2
- import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from '@orpc/server/standard';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
+ import type { StandardCodec, StandardParams } from '@orpc/server/standard';
3
4
  import { type ORPCError } from '@orpc/contract';
4
5
  import { OpenAPISerializer } from './openapi-serializer';
5
6
  export interface OpenAPICodecOptions {
package/dist/standard.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  OpenAPIMatcher,
4
4
  OpenAPISerializer,
5
5
  bracket_notation_exports
6
- } from "./chunk-DRV7KYES.js";
6
+ } from "./chunk-TOZPXKQC.js";
7
7
  import "./chunk-HC5PVG4R.js";
8
8
  export {
9
9
  bracket_notation_exports as BracketNotation,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.38.0",
4
+ "version": "0.40.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -54,15 +54,15 @@
54
54
  "dist"
55
55
  ],
56
56
  "dependencies": {
57
- "escape-string-regexp": "^5.0.0",
58
- "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",
59
60
  "json-schema-typed": "^8.0.1",
60
61
  "openapi3-ts": "^4.4.0",
61
62
  "rou3": "^0.5.1",
62
- "wildcard-match": "^5.1.3",
63
- "@orpc/contract": "0.38.0",
64
- "@orpc/server": "0.38.0",
65
- "@orpc/shared": "0.38.0"
63
+ "@orpc/contract": "0.40.0",
64
+ "@orpc/server": "0.40.0",
65
+ "@orpc/shared": "0.40.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@readme/openapi-parser": "^2.6.0",