@orpc/openapi 0.0.0-next.331b26b → 0.0.0-next.3826d73

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.
Files changed (41) hide show
  1. package/dist/chunk-EIQG2BFG.js +56 -0
  2. package/dist/chunk-OLJZJSQL.js +453 -0
  3. package/dist/chunk-V6Y6IZ2S.js +32 -0
  4. package/dist/fetch.js +5 -30
  5. package/dist/hono.js +5 -30
  6. package/dist/index.js +254 -49
  7. package/dist/next.js +5 -30
  8. package/dist/node.js +18 -34
  9. package/dist/src/adapters/fetch/index.d.ts +0 -8
  10. package/dist/src/adapters/fetch/openapi-handler.d.ts +8 -29
  11. package/dist/src/adapters/node/index.d.ts +0 -3
  12. package/dist/src/adapters/node/openapi-handler.d.ts +8 -8
  13. package/dist/src/adapters/standard/index.d.ts +6 -0
  14. package/dist/src/adapters/standard/openapi-codec.d.ts +16 -0
  15. package/dist/src/adapters/standard/openapi-handler.d.ts +7 -0
  16. package/dist/src/adapters/standard/openapi-matcher.d.ts +20 -0
  17. package/dist/src/adapters/standard/openapi-serializer.d.ts +11 -0
  18. package/dist/src/index.d.ts +5 -0
  19. package/dist/src/openapi-generator.d.ts +9 -2
  20. package/dist/src/openapi-input-structure-parser.d.ts +2 -2
  21. package/dist/src/openapi-operation-extender.d.ts +7 -0
  22. package/dist/src/openapi-output-structure-parser.d.ts +2 -2
  23. package/dist/src/schema-converter.d.ts +2 -2
  24. package/dist/src/schema.d.ts +1 -1
  25. package/dist/src/utils.d.ts +2 -16
  26. package/dist/standard.js +14 -0
  27. package/package.json +13 -11
  28. package/dist/chunk-KNYXLM77.js +0 -107
  29. package/dist/chunk-XYIZDXKB.js +0 -652
  30. package/dist/chunk-YOKECDND.js +0 -25
  31. package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
  32. package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
  33. package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
  34. package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
  35. package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
  36. package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
  37. package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
  38. package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
  39. package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
  40. package/dist/src/adapters/node/types.d.ts +0 -2
  41. /package/dist/src/adapters/{fetch → standard}/bracket-notation.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,9 +1,54 @@
1
1
  import {
2
2
  JSONSerializer,
3
- forEachAllContractProcedure,
4
- forEachContractProcedure,
5
- standardizeHTTPPath
6
- } from "./chunk-KNYXLM77.js";
3
+ standardizeHTTPPath,
4
+ toOpenAPI31RoutePattern
5
+ } from "./chunk-EIQG2BFG.js";
6
+
7
+ // src/openapi-operation-extender.ts
8
+ import { isProcedure } from "@orpc/server";
9
+ var OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
10
+ function setOperationExtender(o, extend) {
11
+ return new Proxy(o, {
12
+ get(target, prop, receiver) {
13
+ if (prop === OPERATION_EXTENDER_SYMBOL) {
14
+ return extend;
15
+ }
16
+ return Reflect.get(target, prop, receiver);
17
+ }
18
+ });
19
+ }
20
+ function getOperationExtender(o) {
21
+ return o[OPERATION_EXTENDER_SYMBOL];
22
+ }
23
+ function extendOperation(operation, procedure) {
24
+ const operationExtenders = [];
25
+ for (const errorItem of Object.values(procedure["~orpc"].errorMap)) {
26
+ const maybeExtender = getOperationExtender(errorItem);
27
+ if (maybeExtender) {
28
+ operationExtenders.push(maybeExtender);
29
+ }
30
+ }
31
+ if (isProcedure(procedure)) {
32
+ for (const middleware of procedure["~orpc"].middlewares) {
33
+ const maybeExtender = getOperationExtender(middleware);
34
+ if (maybeExtender) {
35
+ operationExtenders.push(maybeExtender);
36
+ }
37
+ }
38
+ }
39
+ let currentOperation = operation;
40
+ for (const extender of operationExtenders) {
41
+ if (typeof extender === "function") {
42
+ currentOperation = extender(currentOperation, procedure);
43
+ } else {
44
+ currentOperation = {
45
+ ...currentOperation,
46
+ ...extender
47
+ };
48
+ }
49
+ }
50
+ return currentOperation;
51
+ }
7
52
 
8
53
  // src/openapi.ts
9
54
  import { OpenApiBuilder } from "openapi3-ts/oas31";
@@ -36,14 +81,16 @@ var OpenAPIContentBuilder = class {
36
81
  };
37
82
 
38
83
  // src/openapi-generator.ts
39
- import { fallbackToGlobalConfig as fallbackToGlobalConfig2 } from "@orpc/contract";
84
+ import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus, getEventIteratorSchemaDetails } from "@orpc/contract";
85
+ import { eachAllContractProcedure } from "@orpc/server";
86
+ import { group } from "@orpc/shared";
40
87
 
41
88
  // src/openapi-error.ts
42
89
  var OpenAPIError = class extends Error {
43
90
  };
44
91
 
45
92
  // src/openapi-input-structure-parser.ts
46
- import { fallbackToGlobalConfig } from "@orpc/contract";
93
+ import { fallbackContractConfig } from "@orpc/contract";
47
94
  var OpenAPIInputStructureParser = class {
48
95
  constructor(schemaConverter, schemaUtils, pathParser) {
49
96
  this.schemaConverter = schemaConverter;
@@ -51,8 +98,8 @@ var OpenAPIInputStructureParser = class {
51
98
  this.pathParser = pathParser;
52
99
  }
53
100
  parse(contract, structure) {
54
- const inputSchema = this.schemaConverter.convert(contract["~orpc"].InputSchema, { strategy: "input" });
55
- const method = fallbackToGlobalConfig("defaultMethod", contract["~orpc"].route?.method);
101
+ const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
102
+ const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
56
103
  const httpPath = contract["~orpc"].route?.path;
57
104
  if (this.schemaUtils.isAnySchema(inputSchema)) {
58
105
  return {
@@ -144,7 +191,7 @@ var OpenAPIOutputStructureParser = class {
144
191
  this.schemaUtils = schemaUtils;
145
192
  }
146
193
  parse(contract, structure) {
147
- const outputSchema = this.schemaConverter.convert(contract["~orpc"].OutputSchema, { strategy: "output" });
194
+ const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
148
195
  if (this.schemaUtils.isAnySchema(outputSchema)) {
149
196
  return {
150
197
  headersSchema: void 0,
@@ -183,14 +230,14 @@ var OpenAPIOutputStructureParser = class {
183
230
  };
184
231
 
185
232
  // src/openapi-parameters-builder.ts
186
- import { get, isPlainObject, omit } from "@orpc/shared";
233
+ import { get, isObject, omit } from "@orpc/shared";
187
234
  var OpenAPIParametersBuilder = class {
188
235
  build(paramIn, jsonSchema, options) {
189
236
  const parameters = [];
190
237
  for (const name in jsonSchema.properties) {
191
238
  const schema = jsonSchema.properties[name];
192
239
  const paramExamples = jsonSchema.examples?.filter((example) => {
193
- return isPlainObject(example) && name in example;
240
+ return isObject(example) && name in example;
194
241
  }).map((example) => {
195
242
  return example[name];
196
243
  });
@@ -251,7 +298,7 @@ var CompositeSchemaConverter = class {
251
298
  };
252
299
 
253
300
  // src/schema-utils.ts
254
- import { isPlainObject as isPlainObject2 } from "@orpc/shared";
301
+ import { isObject as isObject2 } from "@orpc/shared";
255
302
 
256
303
  // src/schema.ts
257
304
  import * as JSONSchema from "json-schema-typed/draft-2020-12";
@@ -293,14 +340,14 @@ var SchemaUtils = class {
293
340
  return typeof schema === "object" && schema.type === "object";
294
341
  }
295
342
  isAnySchema(schema) {
296
- return schema === true || Object.keys(schema).length === 0;
343
+ return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
297
344
  }
298
345
  isUndefinableSchema(schema) {
299
346
  const [matches] = this.filterSchemaBranches(schema, (schema2) => {
300
347
  if (typeof schema2 === "boolean") {
301
348
  return schema2;
302
349
  }
303
- return Object.keys(schema2).length === 0;
350
+ return Object.keys(schema2).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
304
351
  });
305
352
  return matches.length > 0;
306
353
  }
@@ -313,7 +360,7 @@ var SchemaUtils = class {
313
360
  }, {});
314
361
  matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
315
362
  matched.examples = schema.examples?.map((example) => {
316
- if (!isPlainObject2(example)) {
363
+ if (!isObject2(example)) {
317
364
  return example;
318
365
  }
319
366
  return Object.entries(example).reduce((acc, [key, value]) => {
@@ -329,7 +376,7 @@ var SchemaUtils = class {
329
376
  }, {});
330
377
  rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
331
378
  rest.examples = schema.examples?.map((example) => {
332
- if (!isPlainObject2(example)) {
379
+ if (!isObject2(example)) {
333
380
  return example;
334
381
  }
335
382
  return Object.entries(example).reduce((acc, [key, value]) => {
@@ -384,6 +431,7 @@ var OpenAPIGenerator = class {
384
431
  errorHandlerStrategy;
385
432
  ignoreUndefinedPathProcedures;
386
433
  considerMissingTagDefinitionAsError;
434
+ strictErrorResponses;
387
435
  constructor(options) {
388
436
  this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
389
437
  this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
@@ -396,6 +444,7 @@ var OpenAPIGenerator = class {
396
444
  this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
397
445
  this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
398
446
  this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
447
+ this.strictErrorResponses = options?.strictErrorResponses ?? true;
399
448
  }
400
449
  async generate(router, doc) {
401
450
  const builder = new OpenApiBuilder({
@@ -403,37 +452,186 @@ var OpenAPIGenerator = class {
403
452
  openapi: "3.1.1"
404
453
  });
405
454
  const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
406
- await forEachAllContractProcedure(router, ({ contract, path }) => {
455
+ await eachAllContractProcedure({
456
+ path: [],
457
+ router
458
+ }, ({ contract, path }) => {
407
459
  try {
408
460
  const def = contract["~orpc"];
409
461
  if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
410
462
  return;
411
463
  }
412
- const method = fallbackToGlobalConfig2("defaultMethod", def.route?.method);
413
- const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
414
- const inputStructure = fallbackToGlobalConfig2("defaultInputStructure", def.route?.inputStructure);
415
- const outputStructure = fallbackToGlobalConfig2("defaultOutputStructure", def.route?.outputStructure);
416
- const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
417
- const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
418
- const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
419
- required: true
420
- }) : [];
421
- const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
422
- const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
423
- const parameters = [...params, ...query, ...headers];
424
- const requestBody = bodySchema !== void 0 ? {
425
- required: this.schemaUtils.isUndefinableSchema(bodySchema),
426
- content: this.contentBuilder.build(bodySchema)
427
- } : void 0;
428
- const successResponse = {
429
- description: fallbackToGlobalConfig2("defaultSuccessDescription", def.route?.successDescription),
430
- content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema, {
431
- example: def.outputExample
432
- }) : void 0,
433
- headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema, {
434
- example: def.outputExample
435
- }) : void 0
436
- };
464
+ const method = fallbackContractConfig2("defaultMethod", def.route?.method);
465
+ const httpPath = def.route?.path ? toOpenAPI31RoutePattern(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
466
+ const { parameters, requestBody } = (() => {
467
+ const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.inputSchema);
468
+ if (eventIteratorSchemaDetails) {
469
+ const requestBody3 = {
470
+ required: true,
471
+ content: {
472
+ "text/event-stream": {
473
+ schema: {
474
+ oneOf: [
475
+ {
476
+ type: "object",
477
+ properties: {
478
+ event: { type: "string", const: "message" },
479
+ data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
480
+ id: { type: "string" },
481
+ retry: { type: "number" }
482
+ },
483
+ required: ["event", "data"]
484
+ },
485
+ {
486
+ type: "object",
487
+ properties: {
488
+ event: { type: "string", const: "done" },
489
+ data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
490
+ id: { type: "string" },
491
+ retry: { type: "number" }
492
+ },
493
+ required: ["event", "data"]
494
+ },
495
+ {
496
+ type: "object",
497
+ properties: {
498
+ event: { type: "string", const: "error" },
499
+ data: {},
500
+ id: { type: "string" },
501
+ retry: { type: "number" }
502
+ },
503
+ required: ["event", "data"]
504
+ }
505
+ ]
506
+ }
507
+ }
508
+ }
509
+ };
510
+ return { requestBody: requestBody3, parameters: [] };
511
+ }
512
+ const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
513
+ const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
514
+ const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
515
+ required: true
516
+ }) : [];
517
+ const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
518
+ const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
519
+ const parameters2 = [...params, ...query, ...headers];
520
+ const requestBody2 = bodySchema !== void 0 ? {
521
+ required: this.schemaUtils.isUndefinableSchema(bodySchema),
522
+ content: this.contentBuilder.build(bodySchema)
523
+ } : void 0;
524
+ return { parameters: parameters2, requestBody: requestBody2 };
525
+ })();
526
+ const { responses } = (() => {
527
+ const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.outputSchema);
528
+ if (eventIteratorSchemaDetails) {
529
+ const responses3 = {};
530
+ responses3[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
531
+ description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
532
+ content: {
533
+ "text/event-stream": {
534
+ schema: {
535
+ oneOf: [
536
+ {
537
+ type: "object",
538
+ properties: {
539
+ event: { type: "string", const: "message" },
540
+ data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
541
+ id: { type: "string" },
542
+ retry: { type: "number" }
543
+ },
544
+ required: ["event", "data"]
545
+ },
546
+ {
547
+ type: "object",
548
+ properties: {
549
+ event: { type: "string", const: "done" },
550
+ data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
551
+ id: { type: "string" },
552
+ retry: { type: "number" }
553
+ },
554
+ required: ["event", "data"]
555
+ },
556
+ {
557
+ type: "object",
558
+ properties: {
559
+ event: { type: "string", const: "error" },
560
+ data: {},
561
+ id: { type: "string" },
562
+ retry: { type: "number" }
563
+ },
564
+ required: ["event", "data"]
565
+ }
566
+ ]
567
+ }
568
+ }
569
+ }
570
+ };
571
+ return { responses: responses3 };
572
+ }
573
+ const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
574
+ const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
575
+ const responses2 = {};
576
+ responses2[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
577
+ description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
578
+ content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
579
+ headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
580
+ };
581
+ return { responses: responses2 };
582
+ })();
583
+ const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
584
+ ...config,
585
+ code,
586
+ status: fallbackORPCErrorStatus(code, config?.status)
587
+ })), (error) => error.status);
588
+ for (const status in errors) {
589
+ const configs = errors[status];
590
+ if (!configs || configs.length === 0) {
591
+ continue;
592
+ }
593
+ const schemas = configs.map(({ data, code, message }) => {
594
+ const json = {
595
+ type: "object",
596
+ properties: {
597
+ defined: { const: true },
598
+ code: { const: code },
599
+ status: { const: Number(status) },
600
+ message: { type: "string", default: message },
601
+ data: {}
602
+ },
603
+ required: ["defined", "code", "status", "message"]
604
+ };
605
+ if (data) {
606
+ const dataJson = this.schemaConverter.convert(data, { strategy: "output" });
607
+ json.properties.data = dataJson;
608
+ if (!this.schemaUtils.isUndefinableSchema(dataJson)) {
609
+ json.required.push("data");
610
+ }
611
+ }
612
+ return json;
613
+ });
614
+ if (this.strictErrorResponses) {
615
+ schemas.push({
616
+ type: "object",
617
+ properties: {
618
+ defined: { const: false },
619
+ code: { type: "string" },
620
+ status: { type: "number" },
621
+ message: { type: "string" },
622
+ data: {}
623
+ },
624
+ required: ["defined", "code", "status", "message"]
625
+ });
626
+ }
627
+ const contentSchema = schemas.length === 1 ? schemas[0] : {
628
+ oneOf: schemas
629
+ };
630
+ responses[status] = {
631
+ description: status,
632
+ content: this.contentBuilder.build(contentSchema)
633
+ };
634
+ }
437
635
  if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
438
636
  const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
439
637
  if (missingTag !== void 0) {
@@ -450,12 +648,11 @@ var OpenAPIGenerator = class {
450
648
  operationId: path.join("."),
451
649
  parameters: parameters.length ? parameters : void 0,
452
650
  requestBody,
453
- responses: {
454
- [fallbackToGlobalConfig2("defaultSuccessStatus", def.route?.successStatus)]: successResponse
455
- }
651
+ responses
456
652
  };
653
+ const extendedOperation = extendOperation(operation, contract);
457
654
  builder.addPath(httpPath, {
458
- [method.toLocaleLowerCase()]: operation
655
+ [method.toLocaleLowerCase()]: extendedOperation
459
656
  });
460
657
  } catch (e) {
461
658
  if (e instanceof OpenAPIError) {
@@ -477,6 +674,11 @@ var OpenAPIGenerator = class {
477
674
  return this.jsonSerializer.serialize(builder.getSpec());
478
675
  }
479
676
  };
677
+
678
+ // src/index.ts
679
+ var oo = {
680
+ spec: setOperationExtender
681
+ };
480
682
  export {
481
683
  CompositeSchemaConverter,
482
684
  JSONSchema,
@@ -489,8 +691,11 @@ export {
489
691
  OpenAPIPathParser,
490
692
  OpenApiBuilder,
491
693
  SchemaUtils,
492
- forEachAllContractProcedure,
493
- forEachContractProcedure,
494
- standardizeHTTPPath
694
+ extendOperation,
695
+ getOperationExtender,
696
+ oo,
697
+ setOperationExtender,
698
+ standardizeHTTPPath,
699
+ toOpenAPI31RoutePattern
495
700
  };
496
701
  //# sourceMappingURL=index.js.map
package/dist/next.js CHANGED
@@ -1,34 +1,9 @@
1
1
  import {
2
- OpenAPIServerHandler,
3
- OpenAPIServerlessHandler
4
- } from "./chunk-YOKECDND.js";
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-XYIZDXKB.js";
18
- import "./chunk-KNYXLM77.js";
2
+ OpenAPIHandler
3
+ } from "./chunk-V6Y6IZ2S.js";
4
+ import "./chunk-OLJZJSQL.js";
5
+ import "./chunk-EIQG2BFG.js";
19
6
  export {
20
- CompositeSchemaCoercer,
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
- OpenAPIHandler
3
- } from "./chunk-XYIZDXKB.js";
4
- import "./chunk-KNYXLM77.js";
2
+ OpenAPICodec,
3
+ OpenAPIMatcher
4
+ } from "./chunk-OLJZJSQL.js";
5
+ import "./chunk-EIQG2BFG.js";
5
6
 
6
7
  // src/adapters/node/openapi-handler.ts
7
- import { createRequest, sendResponse } from "@orpc/server/node";
8
- var OpenAPIHandler2 = class {
9
- openapiFetchHandler;
10
- constructor(hono, router, options) {
11
- this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
8
+ import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
9
+ import { StandardHandler } from "@orpc/server/standard";
10
+ var OpenAPIHandler = class {
11
+ standardHandler;
12
+ constructor(router, options) {
13
+ const matcher = options?.matcher ?? new OpenAPIMatcher(options);
14
+ const codec = options?.codec ?? new OpenAPICodec(options);
15
+ this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
12
16
  }
13
- async handle(req, res, ...[options]) {
14
- const request = createRequest(req, res);
15
- const castedOptions = options ?? {};
16
- const result = await this.openapiFetchHandler.handle(request, castedOptions);
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 options?.beforeSend?.(result.response, castedOptions.context);
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
- OpenAPIHandler2 as OpenAPIHandler,
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, WithSignal } from '@orpc/server';
2
- import type { FetchHandler, FetchHandleRest, FetchHandleResult } from '@orpc/server/fetch';
3
- import type { PublicInputStructureCompact } from './input-structure-compact';
4
- import { type Hooks } from '@orpc/shared';
5
- import { type PublicJSONSerializer } from '../../json-serializer';
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 options?;
20
- private readonly procedureMatcher;
21
- private readonly payloadCodec;
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,5 +1,2 @@
1
1
  export * from './openapi-handler';
2
- export * from './openapi-handler-server';
3
- export * from './openapi-handler-serverless';
4
- export * from './types';
5
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,11 +1,11 @@
1
1
  import type { Context, Router } from '@orpc/server';
2
- import type { IncomingMessage, ServerResponse } from 'node:http';
3
- import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
4
- import type { Hono } from '../fetch/openapi-procedure-matcher';
5
- import { type RequestHandler, type RequestHandleRest, type RequestHandleResult } from '@orpc/server/node';
6
- export declare class OpenAPIHandler<T extends Context> implements RequestHandler<T> {
7
- private readonly openapiFetchHandler;
8
- constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
9
- handle(req: IncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
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,6 @@
1
+ export * as BracketNotation from './bracket-notation';
2
+ export * from './openapi-codec';
3
+ export * from './openapi-handler';
4
+ export * from './openapi-matcher';
5
+ export * from './openapi-serializer';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ import type { AnyProcedure } from '@orpc/server';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
+ import type { StandardCodec, StandardParams } from '@orpc/server/standard';
4
+ import { type ORPCError } from '@orpc/contract';
5
+ import { OpenAPISerializer } from './openapi-serializer';
6
+ export interface OpenAPICodecOptions {
7
+ serializer?: OpenAPISerializer;
8
+ }
9
+ export declare class OpenAPICodec implements StandardCodec {
10
+ private readonly serializer;
11
+ constructor(options?: OpenAPICodecOptions);
12
+ decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
13
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
14
+ encodeError(error: ORPCError<any, any>): StandardResponse;
15
+ }
16
+ //# sourceMappingURL=openapi-codec.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { Context } from '@orpc/server';
2
+ import type { RPCHandlerOptions } from '@orpc/server/standard';
3
+ import type { OpenAPICodecOptions } from './openapi-codec';
4
+ import type { OpenAPIMatcherOptions } from './openapi-matcher';
5
+ export interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T>, OpenAPIMatcherOptions, OpenAPICodecOptions {
6
+ }
7
+ //# sourceMappingURL=openapi-handler.d.ts.map