@orpc/openapi 0.0.0-next.3b1cf14 → 0.0.0-next.3f40711

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 (42) hide show
  1. package/dist/chunk-5QMOOQSF.js +32 -0
  2. package/dist/chunk-HC5PVG4R.js +52 -0
  3. package/dist/chunk-TOZPXKQC.js +450 -0
  4. package/dist/fetch.js +5 -42
  5. package/dist/hono.js +9 -0
  6. package/dist/index.js +251 -42
  7. package/dist/next.js +9 -0
  8. package/dist/node.js +20 -36
  9. package/dist/src/adapters/fetch/index.d.ts +0 -8
  10. package/dist/src/adapters/fetch/openapi-handler.d.ts +9 -31
  11. package/dist/src/adapters/hono/index.d.ts +2 -0
  12. package/dist/src/adapters/next/index.d.ts +2 -0
  13. package/dist/src/adapters/node/index.d.ts +0 -3
  14. package/dist/src/adapters/node/openapi-handler.d.ts +8 -9
  15. package/dist/src/adapters/standard/index.d.ts +6 -0
  16. package/dist/src/adapters/standard/openapi-codec.d.ts +16 -0
  17. package/dist/src/adapters/standard/openapi-handler.d.ts +7 -0
  18. package/dist/src/adapters/standard/openapi-matcher.d.ts +20 -0
  19. package/dist/src/adapters/standard/openapi-serializer.d.ts +11 -0
  20. package/dist/src/index.d.ts +5 -0
  21. package/dist/src/openapi-generator.d.ts +10 -3
  22. package/dist/src/openapi-input-structure-parser.d.ts +2 -2
  23. package/dist/src/openapi-operation-extender.d.ts +7 -0
  24. package/dist/src/openapi-output-structure-parser.d.ts +2 -2
  25. package/dist/src/schema-converter.d.ts +2 -2
  26. package/dist/src/schema.d.ts +1 -1
  27. package/dist/src/utils.d.ts +1 -16
  28. package/dist/standard.js +14 -0
  29. package/package.json +24 -13
  30. package/dist/chunk-KNYXLM77.js +0 -107
  31. package/dist/chunk-YXHH6XHB.js +0 -642
  32. package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
  33. package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
  34. package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
  35. package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
  36. package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
  37. package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
  38. package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
  39. package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
  40. package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
  41. package/dist/src/adapters/node/types.d.ts +0 -2
  42. /package/dist/src/adapters/{fetch → standard}/bracket-notation.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,9 +1,53 @@
1
1
  import {
2
2
  JSONSerializer,
3
- forEachAllContractProcedure,
4
- forEachContractProcedure,
5
3
  standardizeHTTPPath
6
- } from "./chunk-KNYXLM77.js";
4
+ } from "./chunk-HC5PVG4R.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";
@@ -35,11 +79,17 @@ var OpenAPIContentBuilder = class {
35
79
  }
36
80
  };
37
81
 
82
+ // src/openapi-generator.ts
83
+ import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus, getEventIteratorSchemaDetails } from "@orpc/contract";
84
+ import { eachAllContractProcedure } from "@orpc/server";
85
+ import { group } from "@orpc/shared";
86
+
38
87
  // src/openapi-error.ts
39
88
  var OpenAPIError = class extends Error {
40
89
  };
41
90
 
42
91
  // src/openapi-input-structure-parser.ts
92
+ import { fallbackContractConfig } from "@orpc/contract";
43
93
  var OpenAPIInputStructureParser = class {
44
94
  constructor(schemaConverter, schemaUtils, pathParser) {
45
95
  this.schemaConverter = schemaConverter;
@@ -47,8 +97,8 @@ var OpenAPIInputStructureParser = class {
47
97
  this.pathParser = pathParser;
48
98
  }
49
99
  parse(contract, structure) {
50
- const inputSchema = this.schemaConverter.convert(contract["~orpc"].InputSchema, { strategy: "input" });
51
- const method = contract["~orpc"].route?.method ?? "POST";
100
+ const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
101
+ const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
52
102
  const httpPath = contract["~orpc"].route?.path;
53
103
  if (this.schemaUtils.isAnySchema(inputSchema)) {
54
104
  return {
@@ -140,7 +190,7 @@ var OpenAPIOutputStructureParser = class {
140
190
  this.schemaUtils = schemaUtils;
141
191
  }
142
192
  parse(contract, structure) {
143
- const outputSchema = this.schemaConverter.convert(contract["~orpc"].OutputSchema, { strategy: "output" });
193
+ const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
144
194
  if (this.schemaUtils.isAnySchema(outputSchema)) {
145
195
  return {
146
196
  headersSchema: void 0,
@@ -179,14 +229,14 @@ var OpenAPIOutputStructureParser = class {
179
229
  };
180
230
 
181
231
  // src/openapi-parameters-builder.ts
182
- import { get, isPlainObject, omit } from "@orpc/shared";
232
+ import { get, isObject, omit } from "@orpc/shared";
183
233
  var OpenAPIParametersBuilder = class {
184
234
  build(paramIn, jsonSchema, options) {
185
235
  const parameters = [];
186
236
  for (const name in jsonSchema.properties) {
187
237
  const schema = jsonSchema.properties[name];
188
238
  const paramExamples = jsonSchema.examples?.filter((example) => {
189
- return isPlainObject(example) && name in example;
239
+ return isObject(example) && name in example;
190
240
  }).map((example) => {
191
241
  return example[name];
192
242
  });
@@ -247,7 +297,7 @@ var CompositeSchemaConverter = class {
247
297
  };
248
298
 
249
299
  // src/schema-utils.ts
250
- import { isPlainObject as isPlainObject2 } from "@orpc/shared";
300
+ import { isObject as isObject2 } from "@orpc/shared";
251
301
 
252
302
  // src/schema.ts
253
303
  import * as JSONSchema from "json-schema-typed/draft-2020-12";
@@ -289,14 +339,14 @@ var SchemaUtils = class {
289
339
  return typeof schema === "object" && schema.type === "object";
290
340
  }
291
341
  isAnySchema(schema) {
292
- return schema === true || Object.keys(schema).length === 0;
342
+ return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
293
343
  }
294
344
  isUndefinableSchema(schema) {
295
345
  const [matches] = this.filterSchemaBranches(schema, (schema2) => {
296
346
  if (typeof schema2 === "boolean") {
297
347
  return schema2;
298
348
  }
299
- return Object.keys(schema2).length === 0;
349
+ return Object.keys(schema2).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
300
350
  });
301
351
  return matches.length > 0;
302
352
  }
@@ -309,7 +359,7 @@ var SchemaUtils = class {
309
359
  }, {});
310
360
  matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
311
361
  matched.examples = schema.examples?.map((example) => {
312
- if (!isPlainObject2(example)) {
362
+ if (!isObject2(example)) {
313
363
  return example;
314
364
  }
315
365
  return Object.entries(example).reduce((acc, [key, value]) => {
@@ -325,7 +375,7 @@ var SchemaUtils = class {
325
375
  }, {});
326
376
  rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
327
377
  rest.examples = schema.examples?.map((example) => {
328
- if (!isPlainObject2(example)) {
378
+ if (!isObject2(example)) {
329
379
  return example;
330
380
  }
331
381
  return Object.entries(example).reduce((acc, [key, value]) => {
@@ -380,6 +430,7 @@ var OpenAPIGenerator = class {
380
430
  errorHandlerStrategy;
381
431
  ignoreUndefinedPathProcedures;
382
432
  considerMissingTagDefinitionAsError;
433
+ strictErrorResponses;
383
434
  constructor(options) {
384
435
  this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
385
436
  this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
@@ -392,6 +443,7 @@ var OpenAPIGenerator = class {
392
443
  this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
393
444
  this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
394
445
  this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
446
+ this.strictErrorResponses = options?.strictErrorResponses ?? true;
395
447
  }
396
448
  async generate(router, doc) {
397
449
  const builder = new OpenApiBuilder({
@@ -399,35 +451,186 @@ var OpenAPIGenerator = class {
399
451
  openapi: "3.1.1"
400
452
  });
401
453
  const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
402
- await forEachAllContractProcedure(router, ({ contract, path }) => {
454
+ await eachAllContractProcedure({
455
+ path: [],
456
+ router
457
+ }, ({ contract, path }) => {
403
458
  try {
404
459
  const def = contract["~orpc"];
405
460
  if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
406
461
  return;
407
462
  }
408
- const method = def.route?.method ?? "POST";
463
+ const method = fallbackContractConfig2("defaultMethod", def.route?.method);
409
464
  const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
410
- const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, def.route?.inputStructure ?? "compact");
411
- const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, def.route?.outputStructure ?? "compact");
412
- const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
413
- required: true
414
- }) : [];
415
- const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
416
- const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
417
- const parameters = [...params, ...query, ...headers];
418
- const requestBody = bodySchema !== void 0 ? {
419
- required: this.schemaUtils.isUndefinableSchema(bodySchema),
420
- content: this.contentBuilder.build(bodySchema)
421
- } : void 0;
422
- const successResponse = {
423
- description: "OK",
424
- content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema, {
425
- example: def.outputExample
426
- }) : void 0,
427
- headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema, {
428
- example: def.outputExample
429
- }) : void 0
430
- };
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
+ })();
582
+ const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
583
+ ...config,
584
+ code,
585
+ status: fallbackORPCErrorStatus(code, config?.status)
586
+ })), (error) => error.status);
587
+ for (const status in errors) {
588
+ const configs = errors[status];
589
+ if (!configs || configs.length === 0) {
590
+ continue;
591
+ }
592
+ const schemas = configs.map(({ data, code, message }) => {
593
+ const json = {
594
+ type: "object",
595
+ properties: {
596
+ defined: { const: true },
597
+ code: { const: code },
598
+ status: { const: Number(status) },
599
+ message: { type: "string", default: message },
600
+ data: {}
601
+ },
602
+ required: ["defined", "code", "status", "message"]
603
+ };
604
+ if (data) {
605
+ const dataJson = this.schemaConverter.convert(data, { strategy: "output" });
606
+ json.properties.data = dataJson;
607
+ if (!this.schemaUtils.isUndefinableSchema(dataJson)) {
608
+ json.required.push("data");
609
+ }
610
+ }
611
+ return json;
612
+ });
613
+ if (this.strictErrorResponses) {
614
+ schemas.push({
615
+ type: "object",
616
+ properties: {
617
+ defined: { const: false },
618
+ code: { type: "string" },
619
+ status: { type: "number" },
620
+ message: { type: "string" },
621
+ data: {}
622
+ },
623
+ required: ["defined", "code", "status", "message"]
624
+ });
625
+ }
626
+ const contentSchema = schemas.length === 1 ? schemas[0] : {
627
+ oneOf: schemas
628
+ };
629
+ responses[status] = {
630
+ description: status,
631
+ content: this.contentBuilder.build(contentSchema)
632
+ };
633
+ }
431
634
  if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
432
635
  const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
433
636
  if (missingTag !== void 0) {
@@ -444,12 +647,11 @@ var OpenAPIGenerator = class {
444
647
  operationId: path.join("."),
445
648
  parameters: parameters.length ? parameters : void 0,
446
649
  requestBody,
447
- responses: {
448
- [def.route?.successStatus ?? 200]: successResponse
449
- }
650
+ responses
450
651
  };
652
+ const extendedOperation = extendOperation(operation, contract);
451
653
  builder.addPath(httpPath, {
452
- [method.toLocaleLowerCase()]: operation
654
+ [method.toLocaleLowerCase()]: extendedOperation
453
655
  });
454
656
  } catch (e) {
455
657
  if (e instanceof OpenAPIError) {
@@ -471,6 +673,11 @@ var OpenAPIGenerator = class {
471
673
  return this.jsonSerializer.serialize(builder.getSpec());
472
674
  }
473
675
  };
676
+
677
+ // src/index.ts
678
+ var oo = {
679
+ spec: setOperationExtender
680
+ };
474
681
  export {
475
682
  CompositeSchemaConverter,
476
683
  JSONSchema,
@@ -483,8 +690,10 @@ export {
483
690
  OpenAPIPathParser,
484
691
  OpenApiBuilder,
485
692
  SchemaUtils,
486
- forEachAllContractProcedure,
487
- forEachContractProcedure,
693
+ extendOperation,
694
+ getOperationExtender,
695
+ oo,
696
+ setOperationExtender,
488
697
  standardizeHTTPPath
489
698
  };
490
699
  //# sourceMappingURL=index.js.map
package/dist/next.js ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ OpenAPIHandler
3
+ } from "./chunk-5QMOOQSF.js";
4
+ import "./chunk-TOZPXKQC.js";
5
+ import "./chunk-HC5PVG4R.js";
6
+ export {
7
+ OpenAPIHandler
8
+ };
9
+ //# sourceMappingURL=next.js.map
package/dist/node.js CHANGED
@@ -1,46 +1,30 @@
1
1
  import {
2
- OpenAPIHandler
3
- } from "./chunk-YXHH6XHB.js";
4
- import "./chunk-KNYXLM77.js";
2
+ OpenAPICodec,
3
+ OpenAPIMatcher
4
+ } from "./chunk-TOZPXKQC.js";
5
+ import "./chunk-HC5PVG4R.js";
5
6
 
6
7
  // src/adapters/node/openapi-handler.ts
7
- import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
8
- import { ORPC_HANDLER_HEADER } from "@orpc/shared";
9
- var OpenAPIHandler2 = class {
10
- openapiFetchHandler;
11
- constructor(hono, router, options) {
12
- this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
13
- }
14
- condition(request) {
15
- return request.headers[ORPC_HANDLER_HEADER] === void 0;
16
- }
17
- async handle(req, res, ...[options]) {
18
- const request = createRequest(req, res, options);
19
- const castedOptions = options ?? {};
20
- const response = await this.openapiFetchHandler.fetch(request, castedOptions);
21
- await options?.beforeSend?.(response, castedOptions.context);
22
- return await sendResponse(res, response);
23
- }
24
- };
25
-
26
- // src/adapters/node/openapi-handler-server.ts
27
- import { TrieRouter } from "hono/router/trie-router";
28
- var OpenAPIServerHandler = class extends OpenAPIHandler2 {
8
+ import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
9
+ import { StandardHandler } from "@orpc/server/standard";
10
+ var OpenAPIHandler = class {
11
+ standardHandler;
29
12
  constructor(router, options) {
30
- super(new TrieRouter(), 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 });
31
16
  }
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);
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) {
21
+ return { matched: false };
22
+ }
23
+ await sendStandardResponse(res, result.response);
24
+ return { matched: true };
39
25
  }
40
26
  };
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,33 +1,11 @@
1
- import type { Context, Router, WithSignal } from '@orpc/server';
2
- import type { ConditionalFetchHandler, FetchOptions } 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, Response, T, WithSignal> & {
11
- jsonSerializer?: PublicJSONSerializer;
12
- procedureMatcher?: PublicOpenAPIProcedureMatcher;
13
- payloadCodec?: PublicOpenAPIPayloadCodec;
14
- inputBuilderSimple?: PublicInputStructureCompact;
15
- inputBuilderFull?: PublicInputStructureDetailed;
16
- schemaCoercers?: SchemaCoercer[];
17
- };
18
- export declare class OpenAPIHandler<T extends Context> implements ConditionalFetchHandler<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
- condition(request: Request): boolean;
27
- fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
28
- private decodeInput;
29
- private encodeOutput;
30
- private assertDetailedOutput;
31
- private convertToORPCError;
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';
6
+ export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
7
+ private readonly standardHandler;
8
+ constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
9
+ handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
32
10
  }
33
11
  //# sourceMappingURL=openapi-handler.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from '../fetch';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from '../fetch';
2
+ //# sourceMappingURL=index.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,12 +1,11 @@
1
1
  import type { Context, Router } from '@orpc/server';
2
- import type { ConditionalRequestHandler, RequestOptions } from '@orpc/server/node';
3
- import type { IncomingMessage, ServerResponse } from 'node:http';
4
- import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
5
- import type { Hono } from '../fetch/openapi-procedure-matcher';
6
- export declare class OpenAPIHandler<T extends Context> implements ConditionalRequestHandler<T> {
7
- private readonly openapiFetchHandler;
8
- constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
9
- condition(request: IncomingMessage): boolean;
10
- handle(req: IncomingMessage, res: ServerResponse, ...[options]: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
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>;
11
10
  }
12
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
@@ -0,0 +1,20 @@
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 interface OpenAPIMatcherOptions {
5
+ /**
6
+ * Ignore procedure that does not have a method defined in the contract.
7
+ *
8
+ * @default false
9
+ */
10
+ ignoreUndefinedMethod?: boolean;
11
+ }
12
+ export declare class OpenAPIMatcher implements StandardMatcher {
13
+ private readonly tree;
14
+ private readonly ignoreUndefinedMethod;
15
+ constructor(options?: OpenAPIMatcherOptions);
16
+ private pendingRouters;
17
+ init(router: AnyRouter, path?: string[]): void;
18
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
19
+ }
20
+ //# sourceMappingURL=openapi-matcher.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { PublicJSONSerializer } from '../../json-serializer';
2
+ export interface OpenAPISerializerOptions {
3
+ jsonSerializer?: PublicJSONSerializer;
4
+ }
5
+ export declare class OpenAPISerializer {
6
+ private readonly jsonSerializer;
7
+ constructor(options?: OpenAPISerializerOptions);
8
+ serialize(data: unknown): unknown;
9
+ deserialize(serialized: unknown): unknown;
10
+ }
11
+ //# sourceMappingURL=openapi-serializer.d.ts.map