@orpc/openapi 2.0.0-beta.3 → 2.0.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +71 -101
  2. package/dist/adapters/aws-lambda/index.d.mts +26 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +26 -0
  4. package/dist/adapters/aws-lambda/index.mjs +21 -0
  5. package/dist/adapters/fastify/index.d.mts +23 -0
  6. package/dist/adapters/fastify/index.d.ts +23 -0
  7. package/dist/adapters/fastify/index.mjs +21 -0
  8. package/dist/adapters/fetch/index.d.mts +12 -2
  9. package/dist/adapters/fetch/index.d.ts +12 -2
  10. package/dist/adapters/fetch/index.mjs +4 -4
  11. package/dist/adapters/node/index.d.mts +7 -2
  12. package/dist/adapters/node/index.d.ts +7 -2
  13. package/dist/adapters/node/index.mjs +3 -3
  14. package/dist/adapters/standard/index.d.mts +10 -46
  15. package/dist/adapters/standard/index.d.ts +10 -46
  16. package/dist/adapters/standard/index.mjs +4 -4
  17. package/dist/extensions/route.d.mts +2 -2
  18. package/dist/extensions/route.d.ts +2 -2
  19. package/dist/helpers/index.d.mts +9 -1
  20. package/dist/helpers/index.d.ts +9 -1
  21. package/dist/helpers/index.mjs +1 -1
  22. package/dist/index.d.mts +70 -36
  23. package/dist/index.d.ts +70 -36
  24. package/dist/index.mjs +701 -738
  25. package/dist/plugins/index.d.mts +10 -1
  26. package/dist/plugins/index.d.ts +10 -1
  27. package/dist/shared/{openapi.DmAa7YPO.mjs → openapi.0yE-t1W-.mjs} +120 -42
  28. package/dist/shared/{openapi.DuDd2iQz.d.mts → openapi.9smDzQwj.d.mts} +10 -7
  29. package/dist/shared/{openapi.B3H7yHQa.mjs → openapi.BaqI61Xi.mjs} +91 -42
  30. package/dist/shared/openapi.Bd9icEUa.d.mts +45 -0
  31. package/dist/shared/{openapi.B2SK0ZAr.mjs → openapi.BlHXe8vI.mjs} +21 -29
  32. package/dist/shared/openapi.D1CqEIRy.d.ts +45 -0
  33. package/dist/shared/{openapi.BQzzr4-4.d.ts → openapi.DTYZZ6Ph.d.ts} +36 -10
  34. package/dist/shared/{openapi.CYgMBSUF.d.mts → openapi.DfTTLtn5.d.mts} +19 -5
  35. package/dist/shared/{openapi.CYgMBSUF.d.ts → openapi.DfTTLtn5.d.ts} +19 -5
  36. package/dist/shared/{openapi.BcEtAxQj.d.mts → openapi.Drcd0PuL.d.mts} +36 -10
  37. package/dist/shared/{openapi.C7m7NAmH.d.mts → openapi.Dz-JaXHo.d.mts} +13 -2
  38. package/dist/shared/{openapi.C7m7NAmH.d.ts → openapi.Dz-JaXHo.d.ts} +13 -2
  39. package/dist/shared/{openapi.DBYxUpK8.d.ts → openapi.YCiBHaJ-.d.ts} +10 -7
  40. package/dist/shared/{openapi.Bt87OzTt.mjs → openapi.s_p5sN-P.mjs} +20 -15
  41. package/package.json +54 -14
@@ -1,15 +1,20 @@
1
1
  import { Context, Router } from '@orpc/server';
2
2
  import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
3
3
  import { StandardHandlerOptions } from '@orpc/server/standard';
4
- import { O as OpenAPIHandlerCodecOptions } from '../../shared/openapi.DBYxUpK8.js';
4
+ import { OpenAPIHandlerCodecOptions } from '../standard/index.js';
5
5
  import '@orpc/client';
6
6
  import '@orpc/shared';
7
7
  import '@standardserver/core';
8
8
  import '@orpc/contract';
9
- import '../../shared/openapi.C7m7NAmH.js';
9
+ import '../../shared/openapi.Dz-JaXHo.js';
10
10
 
11
11
  interface OpenAPIHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, OpenAPIHandlerCodecOptions<T> {
12
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
+ */
13
18
  declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
14
19
  constructor(router: Router<T>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
15
20
  }
@@ -1,12 +1,12 @@
1
1
  import { NodeHttpHandler } from '@orpc/server/node';
2
2
  import { StandardHandler } from '@orpc/server/standard';
3
- import { O as OpenAPIHandlerCodec } from '../../shared/openapi.B3H7yHQa.mjs';
3
+ import { O as OpenAPIHandlerCodec } from '../../shared/openapi.BaqI61Xi.mjs';
4
4
  import '@orpc/client';
5
5
  import '@orpc/server';
6
6
  import '@orpc/shared';
7
7
  import '@standardserver/core';
8
- import '../../shared/openapi.DmAa7YPO.mjs';
9
- import '../../shared/openapi.Bt87OzTt.mjs';
8
+ import '../../shared/openapi.0yE-t1W-.mjs';
9
+ import '../../shared/openapi.s_p5sN-P.mjs';
10
10
  import '../../shared/openapi.B9PQzqBn.mjs';
11
11
  import 'rou3';
12
12
 
@@ -1,50 +1,14 @@
1
- export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.DuDd2iQz.mjs';
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 } from '@orpc/shared';
6
- import { StandardUrl, StandardHeaders, StandardLazyResponse, StandardRequest } from '@standardserver/core';
7
- import { O as OpenAPISerializer } from '../../shared/openapi.C7m7NAmH.mjs';
1
+ export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.9smDzQwj.mjs';
2
+ export { a as OpenAPILinkCodec, O as OpenAPILinkCodecOptions } from '../../shared/openapi.Bd9icEUa.mjs';
3
+ import { StandardHeaders } from '@standardserver/core';
4
+ import { OpenAPISerializer } from '../../index.mjs';
5
+ import '@orpc/client';
8
6
  import '@orpc/server';
9
7
  import '@orpc/server/standard';
8
+ import '@orpc/shared';
9
+ import '@orpc/contract';
10
+ import '@orpc/client/standard';
10
11
 
11
- declare class OpenAPILinkCodecError extends TypeError {
12
- }
13
- interface OpenAPILinkCodecOptions<T extends ClientContext> {
14
- /**
15
- * Base URL for all requests, without origin. Should match the OpenAPI handler mount path.
16
- *
17
- * @example '/api'
18
- * @default '/'
19
- */
20
- url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
21
- /**
22
- * Inject headers into the request.
23
- */
24
- headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
25
- /**
26
- * Override the default OpenAPI serializer.
27
- */
28
- serializer?: Pick<OpenAPISerializer, keyof OpenAPISerializer>;
29
- /**
30
- * Customize how an error response body is converted into an ORPC error.
31
- * Return `null` or `undefined` to fall back to the default decoding behavior.
32
- */
33
- customErrorResponseBodyDecoder?: (deserializedBody: unknown, response: StandardLazyResponse) => AnyORPCError | null | undefined;
34
- }
35
- declare class OpenAPILinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
36
- private readonly router;
37
- private readonly baseUrl;
38
- private readonly headers;
39
- private readonly serializer;
40
- private readonly customErrorResponseBodyDecoder;
41
- constructor(router: RouterContract, options?: OpenAPILinkCodecOptions<T>);
42
- encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
43
- private encodePathParam;
44
- private serializeQueryString;
45
- decodeResponse(response: StandardLazyResponse, path: string[], _options: ClientOptions<T>): Promise<StandardLinkCodecDecodedResponse>;
46
- private resolveProcedure;
47
- }
12
+ declare function serializeHeaders(headers: object, serializer: Pick<OpenAPISerializer, 'serialize'>): StandardHeaders;
48
13
 
49
- export { OpenAPILinkCodec, OpenAPILinkCodecError };
50
- export type { OpenAPILinkCodecOptions };
14
+ export { serializeHeaders };
@@ -1,50 +1,14 @@
1
- export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.DBYxUpK8.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 } from '@orpc/shared';
6
- import { StandardUrl, StandardHeaders, StandardLazyResponse, StandardRequest } from '@standardserver/core';
7
- import { O as OpenAPISerializer } from '../../shared/openapi.C7m7NAmH.js';
1
+ export { a as OpenAPIHandlerCodec, b as OpenAPIHandlerCodecCore, c as OpenAPIHandlerCodecCoreOptions, O as OpenAPIHandlerCodecOptions, d as OpenAPIMatcher, e as OpenAPIMatcherOptions } from '../../shared/openapi.YCiBHaJ-.js';
2
+ export { a as OpenAPILinkCodec, O as OpenAPILinkCodecOptions } from '../../shared/openapi.D1CqEIRy.js';
3
+ import { StandardHeaders } from '@standardserver/core';
4
+ import { OpenAPISerializer } from '../../index.js';
5
+ import '@orpc/client';
8
6
  import '@orpc/server';
9
7
  import '@orpc/server/standard';
8
+ import '@orpc/shared';
9
+ import '@orpc/contract';
10
+ import '@orpc/client/standard';
10
11
 
11
- declare class OpenAPILinkCodecError extends TypeError {
12
- }
13
- interface OpenAPILinkCodecOptions<T extends ClientContext> {
14
- /**
15
- * Base URL for all requests, without origin. Should match the OpenAPI handler mount path.
16
- *
17
- * @example '/api'
18
- * @default '/'
19
- */
20
- url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
21
- /**
22
- * Inject headers into the request.
23
- */
24
- headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
25
- /**
26
- * Override the default OpenAPI serializer.
27
- */
28
- serializer?: Pick<OpenAPISerializer, keyof OpenAPISerializer>;
29
- /**
30
- * Customize how an error response body is converted into an ORPC error.
31
- * Return `null` or `undefined` to fall back to the default decoding behavior.
32
- */
33
- customErrorResponseBodyDecoder?: (deserializedBody: unknown, response: StandardLazyResponse) => AnyORPCError | null | undefined;
34
- }
35
- declare class OpenAPILinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
36
- private readonly router;
37
- private readonly baseUrl;
38
- private readonly headers;
39
- private readonly serializer;
40
- private readonly customErrorResponseBodyDecoder;
41
- constructor(router: RouterContract, options?: OpenAPILinkCodecOptions<T>);
42
- encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
43
- private encodePathParam;
44
- private serializeQueryString;
45
- decodeResponse(response: StandardLazyResponse, path: string[], _options: ClientOptions<T>): Promise<StandardLinkCodecDecodedResponse>;
46
- private resolveProcedure;
47
- }
12
+ declare function serializeHeaders(headers: object, serializer: Pick<OpenAPISerializer, 'serialize'>): StandardHeaders;
48
13
 
49
- export { OpenAPILinkCodec, OpenAPILinkCodecError };
50
- export type { OpenAPILinkCodecOptions };
14
+ export { serializeHeaders };
@@ -1,11 +1,11 @@
1
- export { O as OpenAPIHandlerCodec, a as OpenAPIHandlerCodecCore, b as OpenAPIMatcher } from '../../shared/openapi.B3H7yHQa.mjs';
2
- export { O as OpenAPILinkCodec, a as OpenAPILinkCodecError } from '../../shared/openapi.B2SK0ZAr.mjs';
1
+ export { O as OpenAPIHandlerCodec, a as OpenAPIHandlerCodecCore, b as OpenAPIMatcher, s as serializeHeaders } from '../../shared/openapi.BaqI61Xi.mjs';
2
+ export { O as OpenAPILinkCodec } from '../../shared/openapi.BlHXe8vI.mjs';
3
3
  import '@orpc/client';
4
4
  import '@orpc/server';
5
5
  import '@orpc/shared';
6
6
  import '@standardserver/core';
7
- import '../../shared/openapi.DmAa7YPO.mjs';
8
- import '../../shared/openapi.Bt87OzTt.mjs';
7
+ import '../../shared/openapi.0yE-t1W-.mjs';
8
+ import '../../shared/openapi.s_p5sN-P.mjs';
9
9
  import '../../shared/openapi.B9PQzqBn.mjs';
10
10
  import 'rou3';
11
11
  import '@orpc/contract';
@@ -1,10 +1,10 @@
1
1
  import { AnyORPCError } from '@orpc/client';
2
2
  import { ErrorMap, AnySchema } from '@orpc/contract';
3
3
  import { Context } from '@orpc/server';
4
- import { O as OpenAPIMeta } from '../shared/openapi.BcEtAxQj.mjs';
4
+ import { OpenAPIMeta } from '../index.mjs';
5
5
  import '@orpc/shared';
6
6
  import '@standardserver/core';
7
- import '../shared/openapi.CYgMBSUF.mjs';
7
+ import '../shared/openapi.DfTTLtn5.mjs';
8
8
  import '@hey-api/spec-types';
9
9
 
10
10
  declare module '@orpc/contract' {
@@ -1,10 +1,10 @@
1
1
  import { AnyORPCError } from '@orpc/client';
2
2
  import { ErrorMap, AnySchema } from '@orpc/contract';
3
3
  import { Context } from '@orpc/server';
4
- import { O as OpenAPIMeta } from '../shared/openapi.BQzzr4-4.js';
4
+ import { OpenAPIMeta } from '../index.js';
5
5
  import '@orpc/shared';
6
6
  import '@standardserver/core';
7
- import '../shared/openapi.CYgMBSUF.js';
7
+ import '../shared/openapi.DfTTLtn5.js';
8
8
  import '@hey-api/spec-types';
9
9
 
10
10
  declare module '@orpc/contract' {
@@ -23,10 +23,15 @@
23
23
  * // thumb: form.get('thumb'),
24
24
  * // }
25
25
  * ```
26
+ *
27
+ * @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
26
28
  */
27
29
  declare function parseFormData(form: FormData): any;
28
30
  /**
29
- * Get the issue message from the error.
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.
30
35
  *
31
36
  * @example
32
37
  * ```tsx
@@ -42,9 +47,12 @@ declare function parseFormData(form: FormData): any;
42
47
  * <input name="images[]" type="file" />
43
48
  * <p>{getIssueMessage(error, 'images[]')}</p>
44
49
  * </form>
50
+ * ```
45
51
  *
46
52
  * @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
47
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}
48
56
  */
49
57
  declare function getIssueMessage(error: unknown, path: string): string | undefined;
50
58
 
@@ -23,10 +23,15 @@
23
23
  * // thumb: form.get('thumb'),
24
24
  * // }
25
25
  * ```
26
+ *
27
+ * @see {@link https://orpc.dev/docs/helpers/form-data#parseformdata | Form Data Helpers - parseFormData}
26
28
  */
27
29
  declare function parseFormData(form: FormData): any;
28
30
  /**
29
- * Get the issue message from the error.
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.
30
35
  *
31
36
  * @example
32
37
  * ```tsx
@@ -42,9 +47,12 @@ declare function parseFormData(form: FormData): any;
42
47
  * <input name="images[]" type="file" />
43
48
  * <p>{getIssueMessage(error, 'images[]')}</p>
44
49
  * </form>
50
+ * ```
45
51
  *
46
52
  * @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
47
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}
48
56
  */
49
57
  declare function getIssueMessage(error: unknown, path: string): string | undefined;
50
58
 
@@ -1,6 +1,6 @@
1
1
  import { isSchemaIssue } from '@orpc/contract';
2
2
  import { isTypescriptObject } from '@orpc/shared';
3
- import { B as BracketNotationSerializer } from '../shared/openapi.Bt87OzTt.mjs';
3
+ import { B as BracketNotationSerializer } from '../shared/openapi.s_p5sN-P.mjs';
4
4
 
5
5
  function parseFormData(form) {
6
6
  const serializer = new BracketNotationSerializer();
package/dist/index.d.mts CHANGED
@@ -1,37 +1,59 @@
1
- import { O as OpenAPISerializer } from './shared/openapi.C7m7NAmH.mjs';
2
- export { B as BracketNotationSerializeResult, a as BracketNotationSerializer, b as BracketNotationSerializerOptions, c as OpenAPIJsonSerialization, d as OpenAPIJsonSerializer, e as OpenAPIJsonSerializerHandler, f as OpenAPIJsonSerializerOptions, g as OpenAPISerializerOptions, h as OpenAPISerializerSerializeOptions } from './shared/openapi.C7m7NAmH.mjs';
3
- import { ClientContext, ClientRest, ThrowableError, ORPCClientOptions, ClientLink } from '@orpc/client';
1
+ import { O as OpenAPISerializer } from './shared/openapi.Dz-JaXHo.mjs';
2
+ export { B as BracketNotationSerializeResult, a as BracketNotationSerializer, b as BracketNotationSerializerOptions, c as OpenAPIJsonSerialization, d as OpenAPIJsonSerializer, e as OpenAPIJsonSerializerHandler, f as OpenAPIJsonSerializerOptions, g as OpenAPISerializerOptions, h as OpenAPISerializerSerializeOptions } from './shared/openapi.Dz-JaXHo.mjs';
3
+ import { ClientContext, ORPCClientOptions, ClientLink } from '@orpc/client';
4
4
  export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
5
- import { AnySchema, ErrorMap, ProcedureContract, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap, RouterContractClient, RouterContract, AnyProcedureContract } from '@orpc/contract';
6
- import { PromiseWithError, Value } from '@orpc/shared';
7
- import { J as JsonifiedValue, b as JsonifiedClientError, c as JsonifiedClient, a as OpenAPIDocument } from './shared/openapi.CYgMBSUF.mjs';
8
- export { d as JsonifiedArray, O as OpenAPIOperationObject } from './shared/openapi.CYgMBSUF.mjs';
9
- 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.BcEtAxQj.mjs';
10
- import { JsonSchemaConverter, JsonSchema } from '@orpc/json-schema';
5
+ import { RouterContract, RouterContractClient, AnyProcedureContract, ProcedureContract } from '@orpc/contract';
6
+ import { J as JsonifiedClient, O as OpenAPIDocument } from './shared/openapi.DfTTLtn5.mjs';
7
+ export { a as JsonifiedArray, b as JsonifiedClientError, c as JsonifiedValue, d as OpenAPIOperationObject } from './shared/openapi.DfTTLtn5.mjs';
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.Drcd0PuL.mjs';
9
+ import { JsonSchema, JsonSchemaConverter } from '@orpc/json-schema';
11
10
  import { AnyRouter, AnyProcedure } from '@orpc/server';
11
+ import { Value } from '@orpc/shared';
12
12
  export { StandardBodyHint } from '@standardserver/core';
13
13
  import '@hey-api/spec-types';
14
14
 
15
- interface ContractJsonifiedCaller<TClientContext extends ClientContext> {
16
- <TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(procedure: ProcedureContract<TInputSchema, TOutputSchema, TErrorMap>, ...rest: ClientRest<TClientContext, InferSchemaInput<TInputSchema>>): PromiseWithError<JsonifiedValue<InferSchemaOutput<TOutputSchema>>, JsonifiedClientError<ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
15
+ interface ContractJsonifiedClientFactory<TClientContext extends ClientContext> {
16
+ <T extends RouterContract>(contract: T): JsonifiedClient<RouterContractClient<T, TClientContext>>;
17
17
  }
18
- interface ContractJsonifiedCallerOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
18
+ interface ContractJsonifiedClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
19
19
  /**
20
20
  * An optional reference to the root router-contract.
21
- * When provided, the caller will automatically register the called procedure-contract
21
+ * When provided, the client factory will automatically register the passed contract
22
22
  * into the router at the path defined by `meta.path`.
23
23
  */
24
24
  contractRef?: undefined | RouterContract;
25
25
  }
26
- declare function createContractJsonifiedCaller<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedCallerOptions<TClientContext>): ContractJsonifiedCaller<TClientContext>;
26
+ declare function createContractJsonifiedClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedClientFactoryOptions<TClientContext>): ContractJsonifiedClientFactory<TClientContext>;
27
27
 
28
28
  declare const DEFAULT_OPENAPI_METHOD = "POST";
29
29
  declare const DEFAULT_OPENAPI_SUCCESS_DESCRIPTION = "OK";
30
30
  declare const DEFAULT_OPENAPI_INPUT_STRUCTURE = "compact";
31
31
  declare const DEFAULT_OPENAPI_OUTPUT_STRUCTURE = "compact";
32
32
 
33
+ /**
34
+ * GET and HEAD requests cannot carry a request body,
35
+ * so their compact input maps to query parameters instead.
36
+ */
37
+ declare function isBodylessMethod(method: string): boolean;
38
+ /**
39
+ * Dynamic parameters are always returned in path order.
40
+ */
41
+ declare function getDynamicPathParams(path: `/${string}`): {
42
+ segment: string;
43
+ startIndex: number;
44
+ parameterName: string;
45
+ allowsSlash: boolean;
46
+ }[] | undefined;
47
+
33
48
  declare class OpenAPIGeneratorError extends TypeError {
34
49
  }
50
+ interface OpenAPIErrorBodyDefinition {
51
+ code: string;
52
+ defaultMessage: string | undefined;
53
+ dataOptional: boolean;
54
+ dataJsonSchema: JsonSchema;
55
+ }
56
+
35
57
  interface OpenAPIGeneratorOptions {
36
58
  converters?: JsonSchemaConverter[] | undefined;
37
59
  /**
@@ -42,11 +64,16 @@ interface OpenAPIGeneratorOptions {
42
64
  interface OpenAPIGeneratorGenerateOptions {
43
65
  base?: Partial<OpenAPIDocument> | undefined;
44
66
  /**
45
- * Controls whether a generated json schema `$defs` at root-level should be moved into `components.schemas`.
67
+ * Root-level `$defs` are always moved into `components.schemas`.
68
+ * Use this to customize the component name of a hoisted def.
46
69
  *
47
- * @default true
70
+ * @remarks
71
+ * - The returned name is a preference, conflicting names are still postfixed (`Planet`, `PlanetInput`, `Planet2`, ...).
72
+ * - Return `undefined` to keep the original def name.
73
+ *
74
+ * @default defName => defName
48
75
  */
49
- shouldHoistDef?: Value<boolean, [defName: string, defSchema: JsonSchema]>;
76
+ customComponentName?: (defName: string, defSchema: JsonSchema) => string | undefined;
50
77
  /**
51
78
  * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
52
79
  *
@@ -62,21 +89,22 @@ interface OpenAPIGeneratorGenerateOptions {
62
89
  * - Return `null | undefined` to use the default error response body shaper.
63
90
  */
64
91
  customErrorResponseBodySchema?: Value<JsonSchema | undefined | null, [
65
- definedErrors: {
66
- code: string;
67
- defaultMessage: string | undefined;
68
- dataOptional: boolean;
69
- dataJsonSchema: JsonSchema;
70
- }[],
92
+ definedErrors: OpenAPIErrorBodyDefinition[],
71
93
  status: number
72
94
  ]>;
73
95
  /**
74
96
  * Mapping ORPCError Code -> HTTP Status Code
75
97
  *
76
- * @default COMMON_ERROR_STATUS_MAP, DEFAULT_ERROR_STATUS
98
+ * @default COMMON_ERROR_STATUS_MAP
77
99
  */
78
100
  errorStatusMap?: Record<string, number> | undefined;
79
101
  }
102
+ /**
103
+ * Generates an OpenAPI document from a contract or router.
104
+ * Relies on JSON schema converters to translate input, output, and error schemas into JSON Schemas.
105
+ *
106
+ * @see {@link https://orpc.dev/docs/openapi/specification#openapi-generator | OpenAPI Specification - OpenAPI Generator}
107
+ */
80
108
  declare class OpenAPIGenerator {
81
109
  private readonly serializer;
82
110
  private readonly converter;
@@ -84,20 +112,26 @@ declare class OpenAPIGenerator {
84
112
  generate(router: RouterContract | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPIDocument>;
85
113
  private convertSchema;
86
114
  private convertSchemas;
87
- private request;
88
- private successResponse;
89
- private errorResponse;
90
115
  }
91
116
 
117
+ type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : {
118
+ [K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never;
119
+ };
120
+ interface PopulateRouterContractOpenAPIPathsOptions {
121
+ /**
122
+ * Base path segments.
123
+ */
124
+ path?: undefined | string[];
125
+ }
92
126
  /**
93
- * Dynamic parameters are always returned in path order.
127
+ * Automatically populates missing openapi.path using router structure.
128
+ *
129
+ * Builds paths by joining router keys with `/`.
130
+ * Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
131
+ *
132
+ * @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
94
133
  */
95
- declare function getDynamicPathParams(path: `/${string}`): {
96
- segment: string;
97
- startIndex: number;
98
- parameterName: string;
99
- allowsSlash: boolean;
100
- }[] | undefined;
134
+ declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
101
135
 
102
- export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams };
103
- export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions };
136
+ export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedClientFactory, getDynamicPathParams, isBodylessMethod, populateRouterContractOpenAPIPaths };
137
+ export type { ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, OpenAPIErrorBodyDefinition, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths };
package/dist/index.d.ts CHANGED
@@ -1,37 +1,59 @@
1
- import { O as OpenAPISerializer } from './shared/openapi.C7m7NAmH.js';
2
- export { B as BracketNotationSerializeResult, a as BracketNotationSerializer, b as BracketNotationSerializerOptions, c as OpenAPIJsonSerialization, d as OpenAPIJsonSerializer, e as OpenAPIJsonSerializerHandler, f as OpenAPIJsonSerializerOptions, g as OpenAPISerializerOptions, h as OpenAPISerializerSerializeOptions } from './shared/openapi.C7m7NAmH.js';
3
- import { ClientContext, ClientRest, ThrowableError, ORPCClientOptions, ClientLink } from '@orpc/client';
1
+ import { O as OpenAPISerializer } from './shared/openapi.Dz-JaXHo.js';
2
+ export { B as BracketNotationSerializeResult, a as BracketNotationSerializer, b as BracketNotationSerializerOptions, c as OpenAPIJsonSerialization, d as OpenAPIJsonSerializer, e as OpenAPIJsonSerializerHandler, f as OpenAPIJsonSerializerOptions, g as OpenAPISerializerOptions, h as OpenAPISerializerSerializeOptions } from './shared/openapi.Dz-JaXHo.js';
3
+ import { ClientContext, ORPCClientOptions, ClientLink } from '@orpc/client';
4
4
  export { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
5
- import { AnySchema, ErrorMap, ProcedureContract, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap, RouterContractClient, RouterContract, AnyProcedureContract } from '@orpc/contract';
6
- import { PromiseWithError, Value } from '@orpc/shared';
7
- import { J as JsonifiedValue, b as JsonifiedClientError, c as JsonifiedClient, a as OpenAPIDocument } from './shared/openapi.CYgMBSUF.js';
8
- export { d as JsonifiedArray, O as OpenAPIOperationObject } from './shared/openapi.CYgMBSUF.js';
9
- 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.BQzzr4-4.js';
10
- import { JsonSchemaConverter, JsonSchema } from '@orpc/json-schema';
5
+ import { RouterContract, RouterContractClient, AnyProcedureContract, ProcedureContract } from '@orpc/contract';
6
+ import { J as JsonifiedClient, O as OpenAPIDocument } from './shared/openapi.DfTTLtn5.js';
7
+ export { a as JsonifiedArray, b as JsonifiedClientError, c as JsonifiedValue, d as OpenAPIOperationObject } from './shared/openapi.DfTTLtn5.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.DTYZZ6Ph.js';
9
+ import { JsonSchema, JsonSchemaConverter } from '@orpc/json-schema';
11
10
  import { AnyRouter, AnyProcedure } from '@orpc/server';
11
+ import { Value } from '@orpc/shared';
12
12
  export { StandardBodyHint } from '@standardserver/core';
13
13
  import '@hey-api/spec-types';
14
14
 
15
- interface ContractJsonifiedCaller<TClientContext extends ClientContext> {
16
- <TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(procedure: ProcedureContract<TInputSchema, TOutputSchema, TErrorMap>, ...rest: ClientRest<TClientContext, InferSchemaInput<TInputSchema>>): PromiseWithError<JsonifiedValue<InferSchemaOutput<TOutputSchema>>, JsonifiedClientError<ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
15
+ interface ContractJsonifiedClientFactory<TClientContext extends ClientContext> {
16
+ <T extends RouterContract>(contract: T): JsonifiedClient<RouterContractClient<T, TClientContext>>;
17
17
  }
18
- interface ContractJsonifiedCallerOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
18
+ interface ContractJsonifiedClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'interceptors' | 'scoped'> {
19
19
  /**
20
20
  * An optional reference to the root router-contract.
21
- * When provided, the caller will automatically register the called procedure-contract
21
+ * When provided, the client factory will automatically register the passed contract
22
22
  * into the router at the path defined by `meta.path`.
23
23
  */
24
24
  contractRef?: undefined | RouterContract;
25
25
  }
26
- declare function createContractJsonifiedCaller<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedCallerOptions<TClientContext>): ContractJsonifiedCaller<TClientContext>;
26
+ declare function createContractJsonifiedClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractJsonifiedClientFactoryOptions<TClientContext>): ContractJsonifiedClientFactory<TClientContext>;
27
27
 
28
28
  declare const DEFAULT_OPENAPI_METHOD = "POST";
29
29
  declare const DEFAULT_OPENAPI_SUCCESS_DESCRIPTION = "OK";
30
30
  declare const DEFAULT_OPENAPI_INPUT_STRUCTURE = "compact";
31
31
  declare const DEFAULT_OPENAPI_OUTPUT_STRUCTURE = "compact";
32
32
 
33
+ /**
34
+ * GET and HEAD requests cannot carry a request body,
35
+ * so their compact input maps to query parameters instead.
36
+ */
37
+ declare function isBodylessMethod(method: string): boolean;
38
+ /**
39
+ * Dynamic parameters are always returned in path order.
40
+ */
41
+ declare function getDynamicPathParams(path: `/${string}`): {
42
+ segment: string;
43
+ startIndex: number;
44
+ parameterName: string;
45
+ allowsSlash: boolean;
46
+ }[] | undefined;
47
+
33
48
  declare class OpenAPIGeneratorError extends TypeError {
34
49
  }
50
+ interface OpenAPIErrorBodyDefinition {
51
+ code: string;
52
+ defaultMessage: string | undefined;
53
+ dataOptional: boolean;
54
+ dataJsonSchema: JsonSchema;
55
+ }
56
+
35
57
  interface OpenAPIGeneratorOptions {
36
58
  converters?: JsonSchemaConverter[] | undefined;
37
59
  /**
@@ -42,11 +64,16 @@ interface OpenAPIGeneratorOptions {
42
64
  interface OpenAPIGeneratorGenerateOptions {
43
65
  base?: Partial<OpenAPIDocument> | undefined;
44
66
  /**
45
- * Controls whether a generated json schema `$defs` at root-level should be moved into `components.schemas`.
67
+ * Root-level `$defs` are always moved into `components.schemas`.
68
+ * Use this to customize the component name of a hoisted def.
46
69
  *
47
- * @default true
70
+ * @remarks
71
+ * - The returned name is a preference, conflicting names are still postfixed (`Planet`, `PlanetInput`, `Planet2`, ...).
72
+ * - Return `undefined` to keep the original def name.
73
+ *
74
+ * @default defName => defName
48
75
  */
49
- shouldHoistDef?: Value<boolean, [defName: string, defSchema: JsonSchema]>;
76
+ customComponentName?: (defName: string, defSchema: JsonSchema) => string | undefined;
50
77
  /**
51
78
  * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
52
79
  *
@@ -62,21 +89,22 @@ interface OpenAPIGeneratorGenerateOptions {
62
89
  * - Return `null | undefined` to use the default error response body shaper.
63
90
  */
64
91
  customErrorResponseBodySchema?: Value<JsonSchema | undefined | null, [
65
- definedErrors: {
66
- code: string;
67
- defaultMessage: string | undefined;
68
- dataOptional: boolean;
69
- dataJsonSchema: JsonSchema;
70
- }[],
92
+ definedErrors: OpenAPIErrorBodyDefinition[],
71
93
  status: number
72
94
  ]>;
73
95
  /**
74
96
  * Mapping ORPCError Code -> HTTP Status Code
75
97
  *
76
- * @default COMMON_ERROR_STATUS_MAP, DEFAULT_ERROR_STATUS
98
+ * @default COMMON_ERROR_STATUS_MAP
77
99
  */
78
100
  errorStatusMap?: Record<string, number> | undefined;
79
101
  }
102
+ /**
103
+ * Generates an OpenAPI document from a contract or router.
104
+ * Relies on JSON schema converters to translate input, output, and error schemas into JSON Schemas.
105
+ *
106
+ * @see {@link https://orpc.dev/docs/openapi/specification#openapi-generator | OpenAPI Specification - OpenAPI Generator}
107
+ */
80
108
  declare class OpenAPIGenerator {
81
109
  private readonly serializer;
82
110
  private readonly converter;
@@ -84,20 +112,26 @@ declare class OpenAPIGenerator {
84
112
  generate(router: RouterContract | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPIDocument>;
85
113
  private convertSchema;
86
114
  private convertSchemas;
87
- private request;
88
- private successResponse;
89
- private errorResponse;
90
115
  }
91
116
 
117
+ type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : {
118
+ [K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never;
119
+ };
120
+ interface PopulateRouterContractOpenAPIPathsOptions {
121
+ /**
122
+ * Base path segments.
123
+ */
124
+ path?: undefined | string[];
125
+ }
92
126
  /**
93
- * Dynamic parameters are always returned in path order.
127
+ * Automatically populates missing openapi.path using router structure.
128
+ *
129
+ * Builds paths by joining router keys with `/`.
130
+ * Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
131
+ *
132
+ * @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
94
133
  */
95
- declare function getDynamicPathParams(path: `/${string}`): {
96
- segment: string;
97
- startIndex: number;
98
- parameterName: string;
99
- allowsSlash: boolean;
100
- }[] | undefined;
134
+ declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
101
135
 
102
- export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, JsonifiedClientError, JsonifiedValue, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedCaller, getDynamicPathParams };
103
- export type { ContractJsonifiedCaller, ContractJsonifiedCallerOptions, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions };
136
+ export { DEFAULT_OPENAPI_INPUT_STRUCTURE, DEFAULT_OPENAPI_METHOD, DEFAULT_OPENAPI_OUTPUT_STRUCTURE, DEFAULT_OPENAPI_SUCCESS_DESCRIPTION, JsonifiedClient, OpenAPIDocument, OpenAPIGenerator, OpenAPIGeneratorError, OpenAPISerializer, createContractJsonifiedClientFactory, getDynamicPathParams, isBodylessMethod, populateRouterContractOpenAPIPaths };
137
+ export type { ContractJsonifiedClientFactory, ContractJsonifiedClientFactoryOptions, OpenAPIErrorBodyDefinition, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, PopulateRouterContractOpenAPIPathsOptions, PopulatedContractRouterOpenAPIPaths };