@orpc/openapi 2.0.0-beta.46 → 2.0.0-beta.48

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 (88) hide show
  1. package/README.md +6 -4
  2. package/dist/adapters/aws-lambda/index.d.mts +14 -26
  3. package/dist/adapters/aws-lambda/index.mjs +1 -21
  4. package/dist/adapters/aws-lambda/openapi-handler.d.mts +17 -0
  5. package/dist/adapters/aws-lambda/openapi-handler.mjs +11 -0
  6. package/dist/adapters/fastify/index.d.mts +1 -23
  7. package/dist/adapters/fastify/index.mjs +1 -21
  8. package/dist/adapters/fastify/openapi-handler.d.mts +14 -0
  9. package/dist/adapters/fastify/openapi-handler.mjs +11 -0
  10. package/dist/adapters/fetch/index.d.mts +2 -37
  11. package/dist/adapters/fetch/index.mjs +2 -34
  12. package/dist/adapters/fetch/openapi-handler.d.mts +14 -0
  13. package/dist/adapters/fetch/openapi-handler.mjs +11 -0
  14. package/dist/adapters/fetch/openapi-link.d.mts +15 -0
  15. package/dist/adapters/fetch/openapi-link.mjs +11 -0
  16. package/dist/adapters/node/index.d.mts +1 -23
  17. package/dist/adapters/node/index.mjs +1 -21
  18. package/dist/adapters/node/openapi-handler.d.mts +14 -0
  19. package/dist/adapters/node/openapi-handler.mjs +11 -0
  20. package/dist/adapters/standard/index.d.mts +3 -48
  21. package/dist/adapters/standard/index.mjs +3 -12
  22. package/dist/adapters/standard/openapi-handler-codec.d.mts +61 -0
  23. package/dist/adapters/standard/openapi-handler-codec.mjs +203 -0
  24. package/dist/adapters/standard/openapi-link-codec.d.mts +53 -0
  25. package/dist/adapters/standard/openapi-link-codec.mjs +356 -0
  26. package/dist/adapters/standard/openapi-matcher.d.mts +29 -0
  27. package/dist/adapters/standard/openapi-matcher.mjs +105 -0
  28. package/dist/adapters/standard/utils.d.mts +4 -0
  29. package/dist/adapters/standard/utils.mjs +36 -0
  30. package/dist/bracket-notation.d.mts +26 -0
  31. package/dist/bracket-notation.mjs +156 -0
  32. package/dist/client-factory.d.mts +24 -0
  33. package/dist/client-factory.mjs +5 -0
  34. package/dist/constants.d.mts +4 -0
  35. package/dist/constants.mjs +4 -0
  36. package/dist/extensions/route.d.mts +74 -39
  37. package/dist/extensions/route.mjs +8 -10
  38. package/dist/helpers/form-data.d.mts +57 -0
  39. package/dist/helpers/form-data.mjs +36 -0
  40. package/dist/helpers/index.d.mts +1 -59
  41. package/dist/helpers/index.mjs +1 -39
  42. package/dist/index.d.mts +13 -159
  43. package/dist/index.mjs +11 -778
  44. package/dist/meta.d.mts +345 -0
  45. package/dist/meta.mjs +56 -0
  46. package/dist/openapi-generator-components.d.mts +24 -0
  47. package/dist/openapi-generator-components.mjs +227 -0
  48. package/dist/openapi-generator-operation.d.mts +29 -0
  49. package/dist/openapi-generator-operation.mjs +447 -0
  50. package/dist/openapi-generator.d.mts +87 -0
  51. package/dist/openapi-generator.mjs +115 -0
  52. package/dist/openapi-json-serializer.d.mts +86 -0
  53. package/dist/openapi-json-serializer.mjs +229 -0
  54. package/dist/openapi-serializer.d.mts +43 -0
  55. package/dist/openapi-serializer.mjs +87 -0
  56. package/dist/plugins/index.d.mts +1 -121
  57. package/dist/plugins/index.mjs +1 -167
  58. package/dist/plugins/openapi-reference.d.mts +118 -0
  59. package/dist/plugins/openapi-reference.mjs +157 -0
  60. package/dist/router-utils.d.mts +18 -0
  61. package/dist/router-utils.mjs +29 -0
  62. package/dist/types.d.mts +27 -0
  63. package/dist/types.mjs +1 -0
  64. package/dist/utils.d.mts +14 -0
  65. package/dist/utils.mjs +40 -0
  66. package/package.json +15 -15
  67. package/dist/adapters/aws-lambda/index.d.ts +0 -27
  68. package/dist/adapters/fastify/index.d.ts +0 -23
  69. package/dist/adapters/fetch/index.d.ts +0 -37
  70. package/dist/adapters/node/index.d.ts +0 -23
  71. package/dist/adapters/standard/index.d.ts +0 -48
  72. package/dist/extensions/route.d.ts +0 -41
  73. package/dist/helpers/index.d.ts +0 -59
  74. package/dist/index.d.ts +0 -159
  75. package/dist/plugins/index.d.ts +0 -121
  76. package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
  77. package/dist/shared/openapi.BCrrWRbv.d.mts +0 -87
  78. package/dist/shared/openapi.BNe1y1cD.mjs +0 -360
  79. package/dist/shared/openapi.B_SoJfYz.d.mts +0 -328
  80. package/dist/shared/openapi.B_SoJfYz.d.ts +0 -328
  81. package/dist/shared/openapi.BkjX_6hE.d.ts +0 -87
  82. package/dist/shared/openapi.Covi8zVE.d.mts +0 -33
  83. package/dist/shared/openapi.Covi8zVE.d.ts +0 -33
  84. package/dist/shared/openapi.DXqJL3gB.mjs +0 -408
  85. package/dist/shared/openapi.DtEVcxuW.mjs +0 -149
  86. package/dist/shared/openapi.E3ZBiweM.mjs +0 -353
  87. package/dist/shared/openapi.YMRD3b4R.d.mts +0 -157
  88. package/dist/shared/openapi.YMRD3b4R.d.ts +0 -157
@@ -1,23 +0,0 @@
1
- import { Context, Router } from '@orpc/server';
2
- import { FastifyHandler, FastifyHandlerOptions } from '@orpc/server/fastify';
3
- import { StandardHandlerOptions } from '@orpc/server/standard';
4
- import { OpenAPIHandlerCodecOptions } from '../standard/index.js';
5
- import '@orpc/client';
6
- import '@orpc/shared';
7
- import '@standard-server/core';
8
- import '@orpc/contract';
9
- import '../../shared/openapi.YMRD3b4R.js';
10
-
11
- interface OpenAPIHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, StandardHandlerOptions<T>, OpenAPIHandlerCodecOptions<T> {
12
- }
13
- /**
14
- * Serves oRPC procedures over the OpenAPI (RESTful) protocol as part of a Fastify server.
15
- *
16
- * @see {@link https://orpc.dev/docs/adapters/fastify | Fastify Adapter}
17
- */
18
- declare class OpenAPIHandler<T extends Context> extends FastifyHandler<T> {
19
- constructor(router: Router<T>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
20
- }
21
-
22
- export { OpenAPIHandler };
23
- export type { OpenAPIHandlerOptions };
@@ -1,37 +0,0 @@
1
- import { Context, Router } from '@orpc/server';
2
- import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
3
- import { StandardHandlerOptions } from '@orpc/server/standard';
4
- import { OpenAPIHandlerCodecOptions } from '../standard/index.js';
5
- import { ClientContext } from '@orpc/client';
6
- import { FetchLinkTransportOptions } from '@orpc/client/fetch';
7
- import { StandardLink, StandardLinkOptions } from '@orpc/client/standard';
8
- import { RouterContract } from '@orpc/contract';
9
- import { OpenAPILinkCodecOptions } from '../standard/index.js';
10
- import '@orpc/shared';
11
- import '@standard-server/core';
12
- import '../../shared/openapi.YMRD3b4R.js';
13
-
14
- interface OpenAPIHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, StandardHandlerOptions<T>, OpenAPIHandlerCodecOptions<T> {
15
- }
16
- /**
17
- * Serves oRPC procedures over the OpenAPI (RESTful) protocol using the Fetch API `Request`/`Response`.
18
- *
19
- * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
20
- */
21
- declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
22
- constructor(router: Router<T>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
23
- }
24
-
25
- interface OpenAPILinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, FetchLinkTransportOptions<T>, OpenAPILinkCodecOptions<T> {
26
- }
27
- /**
28
- * Client link that calls an OpenAPI (RESTful) oRPC server over HTTP using the Fetch API.
29
- *
30
- * @see {@link https://orpc.dev/docs/openapi/link | OpenAPI Link}
31
- */
32
- declare class OpenAPILink<T extends ClientContext> extends StandardLink<T> {
33
- constructor(router: RouterContract, options?: OpenAPILinkOptions<T>);
34
- }
35
-
36
- export { OpenAPIHandler, OpenAPILink };
37
- export type { OpenAPIHandlerOptions, OpenAPILinkOptions };
@@ -1,23 +0,0 @@
1
- import { Context, Router } from '@orpc/server';
2
- import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
3
- import { StandardHandlerOptions } from '@orpc/server/standard';
4
- import { OpenAPIHandlerCodecOptions } from '../standard/index.js';
5
- import '@orpc/client';
6
- import '@orpc/shared';
7
- import '@standard-server/core';
8
- import '@orpc/contract';
9
- import '../../shared/openapi.YMRD3b4R.js';
10
-
11
- interface OpenAPIHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, StandardHandlerOptions<T>, OpenAPIHandlerCodecOptions<T> {
12
- }
13
- /**
14
- * Serves oRPC procedures over the OpenAPI (RESTful) protocol using Node.js built-in HTTP request/response.
15
- *
16
- * @see {@link https://orpc.dev/docs/adapters/node-http | Node HTTP Adapter}
17
- */
18
- declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
19
- constructor(router: Router<T>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
20
- }
21
-
22
- export { OpenAPIHandler };
23
- export type { OpenAPIHandlerOptions };
@@ -1,48 +0,0 @@
1
- export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.BkjX_6hE.js';
2
- import { ClientContext, ClientOptions, AnyORPCError } from '@orpc/client';
3
- import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from '@orpc/client/standard';
4
- import { RouterContract } from '@orpc/contract';
5
- import { Value, Promisable, Public } from '@orpc/shared';
6
- import { StandardUrl, StandardHeaders, StandardLazyResponse, StandardRequest } from '@standard-server/core';
7
- import { OpenAPISerializer } from '../../index.js';
8
- import '@orpc/server';
9
- import '@orpc/server/standard';
10
-
11
- interface OpenAPILinkCodecOptions<T extends ClientContext> {
12
- /**
13
- * Base URL for all requests, without origin. Should match the OpenAPI handler mount path.
14
- *
15
- * @example '/api'
16
- * @default '/'
17
- */
18
- url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
19
- /**
20
- * Inject headers into the request.
21
- */
22
- headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
23
- /**
24
- * Override the default OpenAPI serializer.
25
- */
26
- serializer?: Public<OpenAPISerializer> | undefined;
27
- /**
28
- * Customize how an error response body is converted into an ORPC error.
29
- * Return `null` or `undefined` to fall back to the default decoding behavior.
30
- */
31
- customErrorResponseBodyDecoder?: ((deserializedBody: unknown, response: StandardLazyResponse) => AnyORPCError | null | undefined) | undefined;
32
- }
33
- declare class OpenAPILinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
34
- private readonly router;
35
- private readonly baseUrl;
36
- private readonly headers;
37
- private readonly serializer;
38
- private readonly customErrorResponseBodyDecoder;
39
- constructor(router: RouterContract, options?: OpenAPILinkCodecOptions<T>);
40
- encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
41
- private encodePathParam;
42
- private serializeQueryString;
43
- decodeResponse(response: StandardLazyResponse, path: string[], _options: ClientOptions<T>): Promise<StandardLinkCodecDecodedResponse>;
44
- private resolveProcedure;
45
- }
46
-
47
- export { OpenAPILinkCodec };
48
- export type { OpenAPILinkCodecOptions };
@@ -1,41 +0,0 @@
1
- import { ErrorMap, AnySchema } from '@orpc/contract';
2
- import { Context } from '@orpc/server';
3
- import { OpenAPIMeta } from '../index.js';
4
- import '@orpc/shared';
5
- import '@standard-server/core';
6
- import '@openapi-spec/types/v3.2';
7
-
8
- declare module '@orpc/contract' {
9
- interface ContractBuilder<TErrorMap extends ErrorMap> {
10
- route(meta: OpenAPIMeta): ContractBuilder<TErrorMap>;
11
- }
12
- interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
13
- route(meta: OpenAPIMeta): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
14
- }
15
- interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
16
- route(meta: OpenAPIMeta): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
17
- }
18
- interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
19
- route(meta: OpenAPIMeta): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
20
- }
21
- }
22
- declare module '@orpc/server' {
23
- interface Builder<TInitialContext extends Context, TErrorMap extends ErrorMap> {
24
- route(meta: OpenAPIMeta): Builder<TInitialContext, TErrorMap>;
25
- }
26
- interface BuilderWithMiddlewares<TInitialContext extends Context, TInjectedContext extends Context, TErrorMap extends ErrorMap> {
27
- route(meta: OpenAPIMeta): BuilderWithMiddlewares<TInitialContext, TInjectedContext, TErrorMap>;
28
- }
29
- interface BuilderWithInput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap> {
30
- route(meta: OpenAPIMeta): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, TErrorMap>;
31
- }
32
- interface BuilderWithOutput<TInitialContext extends Context, TInjectedContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
33
- route(meta: OpenAPIMeta): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, TErrorMap>;
34
- }
35
- interface BuilderWithInputOutput<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
36
- route(meta: OpenAPIMeta): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
37
- }
38
- interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
39
- route(meta: OpenAPIMeta): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
40
- }
41
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * Parse a form data with [bracket notation](https://orpc.dev/docs/openapi/bracket-notation) syntax
3
- *
4
- * @example
5
- * ```ts
6
- * const form = new FormData()
7
- * form.append('a', '1')
8
- * form.append('user[name]', 'John')
9
- * form.append('user[age]', '20')
10
- * form.append('user[friends][]', 'Bob')
11
- * form.append('user[friends][]', 'Alice')
12
- * form.append('user[friends][]', 'Charlie')
13
- * form.append('thumb', new Blob(['hello']), 'thumb.png')
14
- *
15
- * parseFormData(form)
16
- * // {
17
- * // a: '1',
18
- * // user: {
19
- * // name: 'John',
20
- * // age: '20',
21
- * // friends: ['Bob', 'Alice', 'Charlie'],
22
- * // },
23
- * // thumb: form.get('thumb'),
24
- * // }
25
- * ```
26
- *
27
- * @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
28
- */
29
- declare function parseFormData(form: FormData): any;
30
- /**
31
- * Gets the issue message from the error for a given field path.
32
- *
33
- * @remarks
34
- * **Note**: Requires validation errors to follow the standard schema issue format, stored under `data.issues` — customized validation errors may not be found.
35
- *
36
- * @example
37
- * ```tsx
38
- * const { error, data, execute } = useServerAction(someAction)
39
- *
40
- * return <form action={(form) => execute(parseFormData(form))}>
41
- * <input name="user[name]" type="text" />
42
- * <p>{getIssueMessage(error, 'user[name]')}</p>
43
- *
44
- * <input name="user[age]" type="number" />
45
- * <p>{getIssueMessage(error, 'user[age]')}</p>
46
- *
47
- * <input name="images[]" type="file" />
48
- * <p>{getIssueMessage(error, 'images[]')}</p>
49
- * </form>
50
- * ```
51
- *
52
- * @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
53
- * @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
54
- *
55
- * @see {@link https://orpc.dev/docs/helpers/form-data#getissuemessage | Form Data Helpers - getIssueMessage}
56
- */
57
- declare function getIssueMessage(error: unknown, path: string): string | undefined;
58
-
59
- export { getIssueMessage, parseFormData };
package/dist/index.d.ts DELETED
@@ -1,159 +0,0 @@
1
- import { a as OpenAPIJsonSerializer } from './shared/openapi.YMRD3b4R.js';
2
- export { B as BracketNotationSerializeResult, b as BracketNotationSerializer, c as BracketNotationSerializerOptions, d as OpenAPIJsonSerialization, e as OpenAPIJsonSerializerHandler, f as OpenAPIJsonSerializerOptions, O as OpenAPISerializer, g as OpenAPISerializerOptions, h as OpenAPISerializerSerializeOptions } from './shared/openapi.YMRD3b4R.js';
3
- import { ClientContext, ORPCClientOptions, ClientLink } from '@orpc/client';
4
- export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
5
- import { RouterContract, RouterContractClient, AnyProcedureContract, ProcedureContract } from '@orpc/contract';
6
- import { J as JsonifiedClient, a as OpenAPIVersion, O as OpenAPIDocument } from './shared/openapi.Covi8zVE.js';
7
- export { b as JsonifiedArray, c as JsonifiedClientError, d as JsonifiedValue } from './shared/openapi.Covi8zVE.js';
8
- export { a as OpenAPIFunction, O as OpenAPIMeta, b as OpenAPIMetaPlugin, c as OpenAPIMethodMetaPlugin, d as OpenAPIPathMetaPlugin, e as OpenAPIPrefixMetaPlugin, f as OpenAPISpecMetaPlugin, g as getOpenAPIMeta, o as openapi } from './shared/openapi.B_SoJfYz.js';
9
- import { JsonSchema, JsonSchemaConverter } from '@orpc/json-schema';
10
- export { JsonSchema } from '@orpc/json-schema';
11
- import { AnyRouter, AnyProcedure } from '@orpc/server';
12
- import { Public, Value } from '@orpc/shared';
13
- import * as OpenAPIV3_2 from '@openapi-spec/types/v3.2';
14
- export { OpenAPIV3_2 };
15
- export { StandardBodyHint } from '@standard-server/core';
16
- import * as OpenAPIV3_0 from '@openapi-spec/types/v3.0';
17
- export { OpenAPIV3_0 };
18
- import * as OpenAPIV3_1 from '@openapi-spec/types/v3.1';
19
- export { OpenAPIV3_1 };
20
-
21
- interface ContractJsonifiedClientFactory<TClientContext extends ClientContext> {
22
- <T extends RouterContract>(contract: T): JsonifiedClient<RouterContractClient<T, TClientContext>>;
23
- }
24
- interface ContractJsonifiedClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
25
- /**
26
- * An optional reference to the root router-contract.
27
- * When provided, the client factory will automatically register the passed contract
28
- * into the router at the path defined by `meta.path`.
29
- */
30
- contractRef?: RouterContract | undefined;
31
- }
32
- /**
33
- * Like `createContractClientFactory`, but the clients it builds are typed as `JsonifiedClient`,
34
- * for links that require it, such as OpenAPI Link.
35
- *
36
- * @remarks
37
- * **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
38
- *
39
- * @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
40
- */
41
- declare function createContractJsonifiedClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedClientFactoryOptions<TClientContext>): ContractJsonifiedClientFactory<TClientContext>;
42
-
43
- declare const DEFAULT_OPENAPI_METHOD = "POST";
44
-
45
- /**
46
- * Dynamic parameters are always returned in path order.
47
- */
48
- declare function getDynamicPathParams(path: `/${string}`): {
49
- segment: string;
50
- startIndex: number;
51
- parameterName: string;
52
- allowsSlash: boolean;
53
- }[] | undefined;
54
-
55
- declare class OpenAPIGeneratorError extends TypeError {
56
- }
57
- interface OpenAPIErrorBodyDefinition {
58
- code: string;
59
- defaultMessage: string | undefined;
60
- dataOptional: boolean;
61
- dataJsonSchema: JsonSchema;
62
- }
63
-
64
- interface OpenAPIGeneratorOptions {
65
- converters?: JsonSchemaConverter[] | undefined;
66
- /**
67
- * The serializer used to serialize the generated OpenAPI documentation
68
- */
69
- serializer?: Public<OpenAPIJsonSerializer> | undefined;
70
- }
71
- interface OpenAPIGeneratorGenerateOptions<TVersion extends OpenAPIVersion> {
72
- /**
73
- * The OpenAPI version of the generated document.
74
- * The document is generated as OpenAPI 3.2 and downgraded when an older version is requested.
75
- * The minor version selects the conversion, the document carries the exact value, such as `3.1.0`.
76
- *
77
- * @default '3.2.0'
78
- */
79
- version?: TVersion | undefined;
80
- /**
81
- * OpenAPI 3.2 document fields to start from, such as `info`, `servers`, or `components`.
82
- * They are downgraded with the rest of the document when an older `version` is requested.
83
- * The `openapi` field is derived from `version`.
84
- */
85
- base?: Partial<Omit<OpenAPIV3_2.OpenAPIObject, 'openapi'>> | undefined;
86
- /**
87
- * Root-level `$defs` are always moved into `components.schemas`.
88
- * Use this to customize the component name of a hoisted def.
89
- *
90
- * @remarks
91
- * - The returned name is a preference, conflicting names are still postfixed (`Planet`, `PlanetInput`, `Planet2`, ...).
92
- * - Return `undefined` to keep the original def name.
93
- *
94
- * @default defName => defName
95
- */
96
- customComponentName?: ((defName: string, defSchema: JsonSchema) => string | undefined) | undefined;
97
- /**
98
- * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
99
- *
100
- * @default true
101
- */
102
- filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
103
- /**
104
- * Define a custom JSON schema for the error response body when using
105
- * type-safe errors. Helps align ORPC error formatting with existing API
106
- * response standards or conventions.
107
- *
108
- * @remarks
109
- * - Return `null | undefined` to use the default error response body shaper.
110
- * - The schema is an OpenAPI 3.2 Schema Object, it is downgraded with the rest of the document when an older `version` is requested.
111
- */
112
- customErrorResponseBodySchema?: Value<JsonSchema | undefined | null, [
113
- definedErrors: OpenAPIErrorBodyDefinition[],
114
- status: number
115
- ]> | undefined;
116
- /**
117
- * Mapping ORPCError Code -> HTTP Status Code
118
- * Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
119
- *
120
- * @default COMMON_ERROR_STATUS_MAP
121
- */
122
- errorStatusMap?: Record<string, number> | undefined;
123
- }
124
- /**
125
- * Generates an OpenAPI document from a contract or router.
126
- * Relies on JSON schema converters to translate input, output, and error schemas into JSON Schemas.
127
- *
128
- * @see {@link https://orpc.dev/docs/openapi/specification#openapi-generator | OpenAPI Specification - OpenAPI Generator}
129
- */
130
- declare class OpenAPIGenerator {
131
- private readonly serializer;
132
- private readonly converter;
133
- constructor(options?: OpenAPIGeneratorOptions);
134
- generate<TVersion extends OpenAPIVersion = '3.2.0'>(router: RouterContract | AnyRouter, options?: OpenAPIGeneratorGenerateOptions<TVersion>): Promise<OpenAPIDocument<TVersion>>;
135
- private convertSchema;
136
- private convertSchemas;
137
- }
138
-
139
- type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : {
140
- [K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never;
141
- };
142
- interface PopulateRouterContractOpenAPIPathsOptions {
143
- /**
144
- * Base path segments.
145
- */
146
- path?: string[] | undefined;
147
- }
148
- /**
149
- * Automatically populates missing openapi.path using router structure.
150
- *
151
- * Builds paths by joining router keys with `/`.
152
- * Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
153
- *
154
- * @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
155
- */
156
- declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
157
-
158
- export { DEFAULT_OPENAPI_METHOD, JsonifiedClient, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPIJsonSerializer, OpenAPIVersion, createContractJsonifiedClientFactory, getDynamicPathParams, populateRouterContractOpenAPIPaths };
159
- export type { ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, OpenAPIErrorBodyDefinition, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths };
@@ -1,121 +0,0 @@
1
- import { Context } from '@orpc/server';
2
- import { StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions, StandardHandlerOptions } from '@orpc/server/standard';
3
- import { Value, Promisable } from '@orpc/shared';
4
- import { ApiReferenceConfiguration } from '@scalar/api-reference';
5
- import { StandardUrl } from '@standard-server/core';
6
- import { SwaggerUIOptions } from 'swagger-ui';
7
- import { OpenAPIDocument, OpenAPIVersion } from '../index.js';
8
- import '@openapi-spec/types/v3.0';
9
- import '@openapi-spec/types/v3.1';
10
- import '@openapi-spec/types/v3.2';
11
- import '@orpc/client';
12
-
13
- type OpenAPIReferenceHandlerPluginProvider = 'scalar' | 'swagger';
14
- interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ApiReferenceConfiguration> {
15
- }
16
- interface OpenAPIReferenceHandlerPluginSwaggerConfig extends Partial<Omit<SwaggerUIOptions, 'dom_id' | 'presets' | 'plugins'>> {
17
- dom_id?: undefined;
18
- /**
19
- * Paths to global variables holding the presets, resolved in the browser,
20
- * e.g. `'SwaggerUIBundle.presets.apis'`. Load custom presets through `docsHead`.
21
- *
22
- * @default ['SwaggerUIBundle.presets.apis']
23
- */
24
- presets?: string[] | undefined;
25
- /**
26
- * Paths to global variables holding the plugins, resolved in the browser,
27
- * e.g. `'SwaggerUIBundle.plugins.DownloadUrl'`. Load custom plugins through `docsHead`.
28
- *
29
- * @default ['SwaggerUIBundle.plugins.DownloadUrl']
30
- */
31
- plugins?: string[] | undefined;
32
- }
33
- interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> {
34
- /**
35
- * A static or dynamic OpenAPI document to serve.
36
- * Receives routing interceptor options when provided as a function.
37
- */
38
- spec: Value<Promisable<OpenAPIDocument<OpenAPIVersion>>, [StandardHandlerRoutingInterceptorOptions<T>]>;
39
- /**
40
- * Determines whether the docs UI and OpenAPI JSON are allowed to be served for a request.
41
- * When it resolves to `false`, the request falls through as unmatched,
42
- * as if the plugin were not installed. Useful for restricting access
43
- * to authenticated users.
44
- */
45
- allow?: Value<Promisable<boolean>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
46
- /**
47
- * The URL path at which to serve the OpenAPI JSON.
48
- *
49
- * @default '/spec.json'
50
- */
51
- specPath?: StandardUrl | undefined;
52
- /**
53
- * The UI provider to use for rendering the API reference.
54
- *
55
- * @default 'scalar'
56
- */
57
- provider?: TProvider | undefined;
58
- /**
59
- * Provider-specific configuration passed directly to the chosen UI library.
60
- * Options differ depending on `provider`.
61
- */
62
- providerConfig?: (TProvider extends 'swagger' ? OpenAPIReferenceHandlerPluginSwaggerConfig : OpenAPIReferenceHandlerPluginScalarConfig) | undefined;
63
- /**
64
- * URL for the provider's main script bundle.
65
- *
66
- * @default 'https://cdn.jsdelivr.net/npm/@scalar/api-reference' | 'https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js'
67
- */
68
- providerScriptUrl?: string | undefined;
69
- /**
70
- * URL for the provider's stylesheet.
71
- *
72
- * @default undefined | 'https://unpkg.com/swagger-ui-dist/swagger-ui.css'
73
- */
74
- providerCssUrl?: string | undefined;
75
- /**
76
- * The URL path at which to serve the API reference UI.
77
- *
78
- * @default '/'
79
- */
80
- docsPath?: StandardUrl | undefined;
81
- /**
82
- * The document title for the API reference UI.
83
- *
84
- * @default spec.info.title
85
- */
86
- docsTitle?: Value<Promisable<string>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
87
- /**
88
- * Raw HTML to inject into the `<head>` of the API reference page.
89
- * Useful for custom stylesheets, meta tags, or scripts.
90
- *
91
- * @default ''
92
- */
93
- docsHead?: Value<Promisable<string>, [StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
94
- }
95
- /**
96
- * Serves API reference documentation powered by Scalar or Swagger UI,
97
- * and exposes the OpenAPI specification as JSON.
98
- *
99
- * @remarks
100
- * **Note**: By default, the API reference UI is served from `/` and the OpenAPI specification from `/spec.json`.
101
- *
102
- * @see {@link https://orpc.dev/docs/plugins/openapi-reference | OpenAPI Reference Plugin (Swagger/Scalar)}
103
- */
104
- declare class OpenAPIReferenceHandlerPlugin<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> implements StandardHandlerPlugin<T> {
105
- name: string;
106
- private readonly spec;
107
- private readonly allow;
108
- private readonly specPath;
109
- private readonly provider;
110
- private readonly providerConfig;
111
- private readonly providerScriptUrl;
112
- private readonly providerCssUrl;
113
- private readonly docsPath;
114
- private readonly docsTitle;
115
- private readonly docsHead;
116
- constructor(options: OpenAPIReferenceHandlerPluginOptions<T, TProvider>);
117
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
118
- }
119
-
120
- export { OpenAPIReferenceHandlerPlugin };
121
- export type { OpenAPIReferenceHandlerPluginOptions, OpenAPIReferenceHandlerPluginProvider, OpenAPIReferenceHandlerPluginScalarConfig, OpenAPIReferenceHandlerPluginSwaggerConfig };
@@ -1,49 +0,0 @@
1
- import { mergeHttpPath } from '@orpc/shared';
2
-
3
- const openapi = (incoming) => ({
4
- name: "~openapi",
5
- init(meta) {
6
- const existing = meta["~openapi"];
7
- const tags = existing?.tags && incoming.tags ? [...existing.tags, ...incoming.tags] : "tags" in incoming ? incoming.tags : existing?.tags;
8
- const queryStyles = existing?.queryStyles && incoming.queryStyles ? { ...existing.queryStyles, ...incoming.queryStyles } : "queryStyles" in incoming ? incoming.queryStyles : existing?.queryStyles;
9
- const paramsStyles = existing?.paramsStyles && incoming.paramsStyles ? { ...existing.paramsStyles, ...incoming.paramsStyles } : "paramsStyles" in incoming ? incoming.paramsStyles : existing?.paramsStyles;
10
- const existingSpec = existing?.spec;
11
- const incomingSpec = incoming.spec;
12
- const spec = typeof existingSpec === "function" && typeof incomingSpec === "function" ? (current) => incomingSpec(existingSpec(current)) : typeof existingSpec === "function" && typeof incomingSpec === "object" ? existingSpec(incomingSpec) : typeof existingSpec === "object" && typeof incomingSpec === "function" ? incomingSpec(existingSpec) : "spec" in incoming ? incomingSpec : existingSpec;
13
- const prefix = existing?.prefix && incoming.prefix ? mergeHttpPath(existing.prefix, incoming.prefix) : "prefix" in incoming ? incoming.prefix : existing?.prefix;
14
- const merged = {
15
- ...existing,
16
- ...incoming,
17
- tags,
18
- queryStyles,
19
- paramsStyles,
20
- spec,
21
- prefix
22
- };
23
- return {
24
- ...meta,
25
- "~openapi": merged
26
- };
27
- }
28
- });
29
- openapi.method = (method) => ({
30
- ...openapi({ method }),
31
- name: "~openapi/method"
32
- });
33
- openapi.path = (path) => ({
34
- ...openapi({ path }),
35
- name: "~openapi/path"
36
- });
37
- openapi.spec = (spec) => ({
38
- ...openapi({ spec }),
39
- name: "~openapi/spec"
40
- });
41
- openapi.prefix = (prefix) => ({
42
- ...openapi({ prefix }),
43
- name: "~openapi/prefix"
44
- });
45
- function getOpenAPIMeta(procedureOrLazy) {
46
- return procedureOrLazy["~orpc"].meta["~openapi"];
47
- }
48
-
49
- export { getOpenAPIMeta as g, openapi as o };
@@ -1,87 +0,0 @@
1
- import { AnyORPCError } from '@orpc/client';
2
- import { AnyProcedure, AnyRouter, Context } from '@orpc/server';
3
- import { StandardHandlerCodec, ResolvedStandardHandlerHandleOptions, StandardHandlerCodecResolvedProcedure } from '@orpc/server/standard';
4
- import { Value, Public, Promisable } from '@orpc/shared';
5
- import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
6
- import { AnyProcedureContract } from '@orpc/contract';
7
- import { O as OpenAPISerializer } from './openapi.YMRD3b4R.mjs';
8
-
9
- interface OpenAPIMatcherOptions {
10
- /**
11
- * Filter which procedures are exposed for matching. Return `false` to exclude.
12
- *
13
- * @default true
14
- */
15
- filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
16
- }
17
- declare class OpenAPIMatcher {
18
- private readonly filter;
19
- private readonly rootRouter;
20
- private readonly tree;
21
- private readonly pendingLazyRouters;
22
- constructor(router: AnyRouter, options?: OpenAPIMatcherOptions);
23
- private index;
24
- match(method: string, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
25
- path: string[];
26
- procedure: AnyProcedure;
27
- params?: Record<string, string> | undefined;
28
- } | undefined>;
29
- private findMatch;
30
- private resolvePendingLazyRouters;
31
- private loadPendingLazyRouters;
32
- private loadPendingLazyRouter;
33
- private indexPendingLazyRouter;
34
- private resolveProcedure;
35
- }
36
-
37
- interface OpenAPIHandlerCodecCoreOptions<_T extends Context> {
38
- /**
39
- * Override the default OpenAPI serializer.
40
- */
41
- serializer?: Public<OpenAPISerializer> | undefined;
42
- /**
43
- * Mapping ORPCError Code -> HTTP Status Code
44
- * The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
45
- * Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
46
- *
47
- * @default COMMON_ERROR_STATUS_MAP
48
- */
49
- errorStatusMap?: Record<string, number> | undefined;
50
- /**
51
- * Customize how an ORPC error is serialized into a response body.
52
- * Use this if your API needs a different error output structure.
53
- *
54
- * @remarks
55
- * - Return `null | undefined` to fallback to default behavior
56
- *
57
- * @default ((e) => e.toJSON())
58
- */
59
- customErrorResponseBodyEncoder?: ((error: AnyORPCError) => unknown) | undefined;
60
- }
61
- declare class OpenAPIHandlerCodecCore<T extends Context> {
62
- private readonly serializer;
63
- private readonly errorStatusMap;
64
- private readonly customErrorResponseBodySerializer;
65
- constructor(options?: OpenAPIHandlerCodecCoreOptions<T>);
66
- decodeInput(matched: {
67
- procedure: AnyProcedure;
68
- params?: Record<string, string> | undefined;
69
- }, request: StandardLazyRequest): Promise<unknown>;
70
- /**
71
- * @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
72
- */
73
- encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]): Promisable<StandardResponse>;
74
- encodeError(error: AnyORPCError): Promisable<StandardResponse>;
75
- private deserializeQuery;
76
- private deserializeParams;
77
- }
78
- interface OpenAPIHandlerCodecOptions<T extends Context> extends OpenAPIHandlerCodecCoreOptions<T>, OpenAPIMatcherOptions {
79
- }
80
- declare class OpenAPIHandlerCodec<T extends Context> extends OpenAPIHandlerCodecCore<T> implements StandardHandlerCodec<T> {
81
- private readonly matcher;
82
- constructor(router: AnyRouter, options?: OpenAPIHandlerCodecOptions<T>);
83
- resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
84
- }
85
-
86
- export { OpenAPIHandlerCodec as a, OpenAPIHandlerCodecCore as b, OpenAPIMatcher as d };
87
- export type { OpenAPIHandlerCodecOptions as O, OpenAPIHandlerCodecCoreOptions as c, OpenAPIMatcherOptions as e };