@orpc/openapi 0.0.0-next.3f6c426 → 0.0.0-next.435356b

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-DRV7KYES.js +420 -0
  2. package/dist/chunk-HC5PVG4R.js +52 -0
  3. package/dist/chunk-NHYWV7BW.js +32 -0
  4. package/dist/fetch.js +5 -42
  5. package/dist/hono.js +9 -0
  6. package/dist/index.js +139 -33
  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 +15 -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 +9 -2
  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 +21 -10
  30. package/dist/chunk-KNYXLM77.js +0 -107
  31. package/dist/chunk-WNX6GP4X.js +0 -652
  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";
@@ -36,14 +80,16 @@ var OpenAPIContentBuilder = class {
36
80
  };
37
81
 
38
82
  // src/openapi-generator.ts
39
- import { fallbackToGlobalConfig as fallbackToGlobalConfig2 } from "@orpc/contract";
83
+ import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus } from "@orpc/contract";
84
+ import { eachAllContractProcedure } from "@orpc/server";
85
+ import { group } from "@orpc/shared";
40
86
 
41
87
  // src/openapi-error.ts
42
88
  var OpenAPIError = class extends Error {
43
89
  };
44
90
 
45
91
  // src/openapi-input-structure-parser.ts
46
- import { fallbackToGlobalConfig } from "@orpc/contract";
92
+ import { fallbackContractConfig } from "@orpc/contract";
47
93
  var OpenAPIInputStructureParser = class {
48
94
  constructor(schemaConverter, schemaUtils, pathParser) {
49
95
  this.schemaConverter = schemaConverter;
@@ -51,8 +97,8 @@ var OpenAPIInputStructureParser = class {
51
97
  this.pathParser = pathParser;
52
98
  }
53
99
  parse(contract, structure) {
54
- const inputSchema = this.schemaConverter.convert(contract["~orpc"].InputSchema, { strategy: "input" });
55
- const method = fallbackToGlobalConfig("defaultMethod", contract["~orpc"].route?.method);
100
+ const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
101
+ const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
56
102
  const httpPath = contract["~orpc"].route?.path;
57
103
  if (this.schemaUtils.isAnySchema(inputSchema)) {
58
104
  return {
@@ -144,7 +190,7 @@ var OpenAPIOutputStructureParser = class {
144
190
  this.schemaUtils = schemaUtils;
145
191
  }
146
192
  parse(contract, structure) {
147
- const outputSchema = this.schemaConverter.convert(contract["~orpc"].OutputSchema, { strategy: "output" });
193
+ const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
148
194
  if (this.schemaUtils.isAnySchema(outputSchema)) {
149
195
  return {
150
196
  headersSchema: void 0,
@@ -183,14 +229,14 @@ var OpenAPIOutputStructureParser = class {
183
229
  };
184
230
 
185
231
  // src/openapi-parameters-builder.ts
186
- import { get, isPlainObject, omit } from "@orpc/shared";
232
+ import { get, isObject, omit } from "@orpc/shared";
187
233
  var OpenAPIParametersBuilder = class {
188
234
  build(paramIn, jsonSchema, options) {
189
235
  const parameters = [];
190
236
  for (const name in jsonSchema.properties) {
191
237
  const schema = jsonSchema.properties[name];
192
238
  const paramExamples = jsonSchema.examples?.filter((example) => {
193
- return isPlainObject(example) && name in example;
239
+ return isObject(example) && name in example;
194
240
  }).map((example) => {
195
241
  return example[name];
196
242
  });
@@ -251,7 +297,7 @@ var CompositeSchemaConverter = class {
251
297
  };
252
298
 
253
299
  // src/schema-utils.ts
254
- import { isPlainObject as isPlainObject2 } from "@orpc/shared";
300
+ import { isObject as isObject2 } from "@orpc/shared";
255
301
 
256
302
  // src/schema.ts
257
303
  import * as JSONSchema from "json-schema-typed/draft-2020-12";
@@ -293,14 +339,14 @@ var SchemaUtils = class {
293
339
  return typeof schema === "object" && schema.type === "object";
294
340
  }
295
341
  isAnySchema(schema) {
296
- return schema === true || Object.keys(schema).length === 0;
342
+ return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
297
343
  }
298
344
  isUndefinableSchema(schema) {
299
345
  const [matches] = this.filterSchemaBranches(schema, (schema2) => {
300
346
  if (typeof schema2 === "boolean") {
301
347
  return schema2;
302
348
  }
303
- return Object.keys(schema2).length === 0;
349
+ return Object.keys(schema2).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
304
350
  });
305
351
  return matches.length > 0;
306
352
  }
@@ -313,7 +359,7 @@ var SchemaUtils = class {
313
359
  }, {});
314
360
  matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
315
361
  matched.examples = schema.examples?.map((example) => {
316
- if (!isPlainObject2(example)) {
362
+ if (!isObject2(example)) {
317
363
  return example;
318
364
  }
319
365
  return Object.entries(example).reduce((acc, [key, value]) => {
@@ -329,7 +375,7 @@ var SchemaUtils = class {
329
375
  }, {});
330
376
  rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
331
377
  rest.examples = schema.examples?.map((example) => {
332
- if (!isPlainObject2(example)) {
378
+ if (!isObject2(example)) {
333
379
  return example;
334
380
  }
335
381
  return Object.entries(example).reduce((acc, [key, value]) => {
@@ -384,6 +430,7 @@ var OpenAPIGenerator = class {
384
430
  errorHandlerStrategy;
385
431
  ignoreUndefinedPathProcedures;
386
432
  considerMissingTagDefinitionAsError;
433
+ strictErrorResponses;
387
434
  constructor(options) {
388
435
  this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
389
436
  this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
@@ -396,6 +443,7 @@ var OpenAPIGenerator = class {
396
443
  this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
397
444
  this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
398
445
  this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
446
+ this.strictErrorResponses = options?.strictErrorResponses ?? true;
399
447
  }
400
448
  async generate(router, doc) {
401
449
  const builder = new OpenApiBuilder({
@@ -403,16 +451,19 @@ var OpenAPIGenerator = class {
403
451
  openapi: "3.1.1"
404
452
  });
405
453
  const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
406
- await forEachAllContractProcedure(router, ({ contract, path }) => {
454
+ await eachAllContractProcedure({
455
+ path: [],
456
+ router
457
+ }, ({ contract, path }) => {
407
458
  try {
408
459
  const def = contract["~orpc"];
409
460
  if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
410
461
  return;
411
462
  }
412
- const method = fallbackToGlobalConfig2("defaultMethod", def.route?.method);
463
+ const method = fallbackContractConfig2("defaultMethod", def.route?.method);
413
464
  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);
465
+ const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
466
+ const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
416
467
  const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
417
468
  const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
418
469
  const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
@@ -425,15 +476,64 @@ var OpenAPIGenerator = class {
425
476
  required: this.schemaUtils.isUndefinableSchema(bodySchema),
426
477
  content: this.contentBuilder.build(bodySchema)
427
478
  } : void 0;
428
- const successResponse = {
429
- description: "OK",
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
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
436
484
  };
485
+ const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
486
+ ...config,
487
+ code,
488
+ status: fallbackORPCErrorStatus(code, config?.status)
489
+ })), (error) => error.status);
490
+ for (const status in errors) {
491
+ const configs = errors[status];
492
+ if (!configs || configs.length === 0) {
493
+ continue;
494
+ }
495
+ const schemas = configs.map(({ data, code, message }) => {
496
+ const json = {
497
+ type: "object",
498
+ properties: {
499
+ defined: { const: true },
500
+ code: { const: code },
501
+ status: { const: Number(status) },
502
+ message: { type: "string", default: message },
503
+ data: {}
504
+ },
505
+ required: ["defined", "code", "status", "message"]
506
+ };
507
+ if (data) {
508
+ const dataJson = this.schemaConverter.convert(data, { strategy: "output" });
509
+ json.properties.data = dataJson;
510
+ if (!this.schemaUtils.isUndefinableSchema(dataJson)) {
511
+ json.required.push("data");
512
+ }
513
+ }
514
+ return json;
515
+ });
516
+ if (this.strictErrorResponses) {
517
+ schemas.push({
518
+ type: "object",
519
+ properties: {
520
+ defined: { const: false },
521
+ code: { type: "string" },
522
+ status: { type: "number" },
523
+ message: { type: "string" },
524
+ data: {}
525
+ },
526
+ required: ["defined", "code", "status", "message"]
527
+ });
528
+ }
529
+ const contentSchema = schemas.length === 1 ? schemas[0] : {
530
+ oneOf: schemas
531
+ };
532
+ responses[status] = {
533
+ description: status,
534
+ content: this.contentBuilder.build(contentSchema)
535
+ };
536
+ }
437
537
  if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
438
538
  const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
439
539
  if (missingTag !== void 0) {
@@ -450,12 +550,11 @@ var OpenAPIGenerator = class {
450
550
  operationId: path.join("."),
451
551
  parameters: parameters.length ? parameters : void 0,
452
552
  requestBody,
453
- responses: {
454
- [fallbackToGlobalConfig2("defaultSuccessStatus", def.route?.successStatus)]: successResponse
455
- }
553
+ responses
456
554
  };
555
+ const extendedOperation = extendOperation(operation, contract);
457
556
  builder.addPath(httpPath, {
458
- [method.toLocaleLowerCase()]: operation
557
+ [method.toLocaleLowerCase()]: extendedOperation
459
558
  });
460
559
  } catch (e) {
461
560
  if (e instanceof OpenAPIError) {
@@ -477,6 +576,11 @@ var OpenAPIGenerator = class {
477
576
  return this.jsonSerializer.serialize(builder.getSpec());
478
577
  }
479
578
  };
579
+
580
+ // src/index.ts
581
+ var oo = {
582
+ spec: setOperationExtender
583
+ };
480
584
  export {
481
585
  CompositeSchemaConverter,
482
586
  JSONSchema,
@@ -489,8 +593,10 @@ export {
489
593
  OpenAPIPathParser,
490
594
  OpenApiBuilder,
491
595
  SchemaUtils,
492
- forEachAllContractProcedure,
493
- forEachContractProcedure,
596
+ extendOperation,
597
+ getOperationExtender,
598
+ oo,
599
+ setOperationExtender,
494
600
  standardizeHTTPPath
495
601
  };
496
602
  //# sourceMappingURL=index.js.map
package/dist/next.js ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ OpenAPIHandler
3
+ } from "./chunk-NHYWV7BW.js";
4
+ import "./chunk-DRV7KYES.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-WNX6GP4X.js";
4
- import "./chunk-KNYXLM77.js";
2
+ OpenAPICodec,
3
+ OpenAPIMatcher
4
+ } from "./chunk-DRV7KYES.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 { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/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 = nodeHttpToStandardRequest(req, res);
19
+ const result = await this.standardHandler.handle(standardRequest, ...rest);
20
+ if (!result.matched) {
21
+ return { matched: false };
22
+ }
23
+ await nodeHttpResponseSendStandardResponse(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,15 @@
1
+ import type { AnyProcedure } from '@orpc/server';
2
+ import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from '@orpc/server/standard';
3
+ import { type ORPCError } from '@orpc/contract';
4
+ import { OpenAPISerializer } from './openapi-serializer';
5
+ export interface OpenAPICodecOptions {
6
+ serializer?: OpenAPISerializer;
7
+ }
8
+ export declare class OpenAPICodec implements StandardCodec {
9
+ private readonly serializer;
10
+ constructor(options?: OpenAPICodecOptions);
11
+ decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
12
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
13
+ encodeError(error: ORPCError<any, any>): StandardResponse;
14
+ }
15
+ //# 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
@@ -1,12 +1,17 @@
1
1
  /** unnoq */
2
+ import { setOperationExtender } from './openapi-operation-extender';
2
3
  export * from './json-serializer';
3
4
  export * from './openapi';
4
5
  export * from './openapi-content-builder';
5
6
  export * from './openapi-generator';
7
+ export * from './openapi-operation-extender';
6
8
  export * from './openapi-parameters-builder';
7
9
  export * from './openapi-path-parser';
8
10
  export * from './schema';
9
11
  export * from './schema-converter';
10
12
  export * from './schema-utils';
11
13
  export * from './utils';
14
+ export declare const oo: {
15
+ spec: typeof setOperationExtender;
16
+ };
12
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,9 @@
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';
6
5
  import { type ContractRouter } from '@orpc/contract';
6
+ import { type AnyRouter } from '@orpc/server';
7
7
  import { type PublicJSONSerializer } from './json-serializer';
8
8
  import { type OpenAPI } from './openapi';
9
9
  import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
@@ -40,6 +40,12 @@ export interface OpenAPIGeneratorOptions {
40
40
  * @default 'throw'
41
41
  */
42
42
  errorHandlerStrategy?: ErrorHandlerStrategy;
43
+ /**
44
+ * Strict error response
45
+ *
46
+ * @default true
47
+ */
48
+ strictErrorResponses?: boolean;
43
49
  }
44
50
  export declare class OpenAPIGenerator {
45
51
  private readonly contentBuilder;
@@ -53,8 +59,9 @@ export declare class OpenAPIGenerator {
53
59
  private readonly errorHandlerStrategy;
54
60
  private readonly ignoreUndefinedPathProcedures;
55
61
  private readonly considerMissingTagDefinitionAsError;
62
+ private readonly strictErrorResponses;
56
63
  constructor(options?: OpenAPIGeneratorOptions);
57
- generate(router: ContractRouter | ANY_ROUTER, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
64
+ generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
58
65
  }
59
66
  export {};
60
67
  //# sourceMappingURL=openapi-generator.d.ts.map
@@ -1,8 +1,8 @@
1
+ import type { AnyContractProcedure } from '@orpc/contract';
1
2
  import type { PublicOpenAPIPathParser } from './openapi-path-parser';
2
3
  import type { JSONSchema, ObjectSchema } from './schema';
3
4
  import type { SchemaConverter } from './schema-converter';
4
5
  import type { PublicSchemaUtils } from './schema-utils';
5
- import { type ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
6
6
  export interface OpenAPIInputStructureParseResult {
7
7
  paramsSchema: ObjectSchema | undefined;
8
8
  querySchema: ObjectSchema | undefined;
@@ -14,7 +14,7 @@ export declare class OpenAPIInputStructureParser {
14
14
  private readonly schemaUtils;
15
15
  private readonly pathParser;
16
16
  constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
17
- parse(contract: ANY_CONTRACT_PROCEDURE, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
17
+ parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
18
18
  private parseDetailedSchema;
19
19
  private parseCompactSchema;
20
20
  }
@@ -0,0 +1,7 @@
1
+ import type { AnyContractProcedure } from '@orpc/contract';
2
+ import type { OpenAPI } from './openapi';
3
+ export type OverrideOperationValue = OpenAPI.OperationObject | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
4
+ export declare function setOperationExtender<T extends object>(o: T, extend: OverrideOperationValue): T;
5
+ export declare function getOperationExtender(o: object): OverrideOperationValue | undefined;
6
+ export declare function extendOperation(operation: OpenAPI.OperationObject, procedure: AnyContractProcedure): OpenAPI.OperationObject;
7
+ //# sourceMappingURL=openapi-operation-extender.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
1
+ import type { AnyContractProcedure } from '@orpc/contract';
2
2
  import type { JSONSchema, ObjectSchema } from './schema';
3
3
  import type { SchemaConverter } from './schema-converter';
4
4
  import type { PublicSchemaUtils } from './schema-utils';
@@ -10,7 +10,7 @@ export declare class OpenAPIOutputStructureParser {
10
10
  private readonly schemaConverter;
11
11
  private readonly schemaUtils;
12
12
  constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
13
- parse(contract: ANY_CONTRACT_PROCEDURE, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
13
+ parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
14
14
  private parseDetailedSchema;
15
15
  private parseCompactSchema;
16
16
  }
@@ -4,8 +4,8 @@ export interface SchemaConvertOptions {
4
4
  strategy: 'input' | 'output';
5
5
  }
6
6
  export interface SchemaConverter {
7
- condition: (schema: Schema, options: SchemaConvertOptions) => boolean;
8
- convert: (schema: Schema, options: SchemaConvertOptions) => JSONSchema.JSONSchema;
7
+ condition(schema: Schema, options: SchemaConvertOptions): boolean;
8
+ convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
9
9
  }
10
10
  export declare class CompositeSchemaConverter implements SchemaConverter {
11
11
  private readonly converters;