@orpc/openapi 0.0.0-next.1431467 → 0.0.0-next.16739f4

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.
package/README.md CHANGED
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
23
 
24
- **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
34
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
37
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
38
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
39
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
40
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
41
+ - **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -53,11 +49,16 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
49
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
50
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
51
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
53
  - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
54
  - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
55
+ - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
56
+ - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
58
57
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
58
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
59
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
60
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
61
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
61
62
 
62
63
  ## `@orpc/openapi`
63
64
 
@@ -86,6 +87,14 @@ const server = createServer(async (req, res) => {
86
87
  server.listen(3000, '127.0.0.1', () => console.log('Listening on 127.0.0.1:3000'))
87
88
  ```
88
89
 
90
+ ## Sponsors
91
+
92
+ <p align="center">
93
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
94
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
95
+ </a>
96
+ </p>
97
+
89
98
  ## License
90
99
 
91
100
  Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -1,13 +1,17 @@
1
1
  import { Context, Router } from '@orpc/server';
2
- import { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
3
- import { StandardHandlerOptions, StandardHandleOptions } from '@orpc/server/standard';
4
- import { MaybeOptionalOptions } from '@orpc/shared';
5
- import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
2
+ import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
4
+ import '@orpc/openapi-client/standard';
5
+ import '@orpc/server/standard';
6
6
 
7
- declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
8
- private readonly standardHandler;
9
- constructor(router: Router<T, any>, options?: NoInfer<StandardHandlerOptions<T>>);
10
- handle(request: Request, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
7
+ /**
8
+ * OpenAPI Handler for Fetch Server
9
+ *
10
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
11
+ * @see {@link https://orpc.unnoq.com/docs/integrations/fetch-server Fetch Server Integration Docs}
12
+ */
13
+ declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
14
+ constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
11
15
  }
12
16
 
13
17
  export { OpenAPIHandler };
@@ -1,13 +1,17 @@
1
1
  import { Context, Router } from '@orpc/server';
2
- import { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
3
- import { StandardHandlerOptions, StandardHandleOptions } from '@orpc/server/standard';
4
- import { MaybeOptionalOptions } from '@orpc/shared';
5
- import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
2
+ import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
4
+ import '@orpc/openapi-client/standard';
5
+ import '@orpc/server/standard';
6
6
 
7
- declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
8
- private readonly standardHandler;
9
- constructor(router: Router<T, any>, options?: NoInfer<StandardHandlerOptions<T>>);
10
- handle(request: Request, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
7
+ /**
8
+ * OpenAPI Handler for Fetch Server
9
+ *
10
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
11
+ * @see {@link https://orpc.unnoq.com/docs/integrations/fetch-server Fetch Server Integration Docs}
12
+ */
13
+ declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
14
+ constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
11
15
  }
12
16
 
13
17
  export { OpenAPIHandler };
@@ -1,10 +1,17 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.B6uueFtN.mjs';
2
- import '@orpc/openapi-client/standard';
3
- import '@orpc/server/standard';
4
- import '@orpc/standard-server-fetch';
5
- import '../../shared/openapi.C_biOx82.mjs';
1
+ import { FetchHandler } from '@orpc/server/fetch';
6
2
  import '@orpc/contract';
7
3
  import '@orpc/shared';
4
+ import { a as StandardOpenAPIHandler } from '../../shared/openapi.p5tsmBXx.mjs';
5
+ import '@orpc/client/standard';
8
6
  import '@orpc/server';
9
7
  import 'rou3';
10
- import '../../shared/openapi.BHG_gu5Z.mjs';
8
+ import '@orpc/openapi-client/standard';
9
+ import '@orpc/server/standard';
10
+
11
+ class OpenAPIHandler extends FetchHandler {
12
+ constructor(router, options = {}) {
13
+ super(new StandardOpenAPIHandler(router, options), options);
14
+ }
15
+ }
16
+
17
+ export { OpenAPIHandler };
@@ -1,13 +1,17 @@
1
1
  import { Context, Router } from '@orpc/server';
2
- import { NodeHttpHandler, NodeHttpRequest, NodeHttpResponse, NodeHttpHandleResult } from '@orpc/server/node';
3
- import { StandardHandlerOptions, StandardHandleOptions } from '@orpc/server/standard';
4
- import { MaybeOptionalOptions } from '@orpc/shared';
5
- import { SendStandardResponseOptions } from '@orpc/standard-server-node';
2
+ import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
4
+ import '@orpc/openapi-client/standard';
5
+ import '@orpc/server/standard';
6
6
 
7
- declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
8
- private readonly standardHandler;
9
- constructor(router: Router<T, any>, options?: NoInfer<StandardHandlerOptions<T>>);
10
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
7
+ /**
8
+ * OpenAPI Handler for Node Server
9
+ *
10
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
11
+ * @see {@link https://orpc.unnoq.com/docs/integrations/node Node Integration Docs}
12
+ */
13
+ declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
14
+ constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
11
15
  }
12
16
 
13
17
  export { OpenAPIHandler };
@@ -1,13 +1,17 @@
1
1
  import { Context, Router } from '@orpc/server';
2
- import { NodeHttpHandler, NodeHttpRequest, NodeHttpResponse, NodeHttpHandleResult } from '@orpc/server/node';
3
- import { StandardHandlerOptions, StandardHandleOptions } from '@orpc/server/standard';
4
- import { MaybeOptionalOptions } from '@orpc/shared';
5
- import { SendStandardResponseOptions } from '@orpc/standard-server-node';
2
+ import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
4
+ import '@orpc/openapi-client/standard';
5
+ import '@orpc/server/standard';
6
6
 
7
- declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
8
- private readonly standardHandler;
9
- constructor(router: Router<T, any>, options?: NoInfer<StandardHandlerOptions<T>>);
10
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
7
+ /**
8
+ * OpenAPI Handler for Node Server
9
+ *
10
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
11
+ * @see {@link https://orpc.unnoq.com/docs/integrations/node Node Integration Docs}
12
+ */
13
+ declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
14
+ constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
11
15
  }
12
16
 
13
17
  export { OpenAPIHandler };
@@ -1,31 +1,16 @@
1
- import { OpenAPISerializer } from '@orpc/openapi-client/standard';
2
- import { StandardHandler } from '@orpc/server/standard';
3
- import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
4
- import { a as OpenAPIMatcher, O as OpenAPICodec } from '../../shared/openapi.C_biOx82.mjs';
1
+ import { NodeHttpHandler } from '@orpc/server/node';
5
2
  import '@orpc/contract';
6
3
  import '@orpc/shared';
4
+ import { a as StandardOpenAPIHandler } from '../../shared/openapi.p5tsmBXx.mjs';
5
+ import '@orpc/client/standard';
7
6
  import '@orpc/server';
8
7
  import 'rou3';
9
- import '../../shared/openapi.BHG_gu5Z.mjs';
8
+ import '@orpc/openapi-client/standard';
9
+ import '@orpc/server/standard';
10
10
 
11
- class OpenAPIHandler {
12
- standardHandler;
11
+ class OpenAPIHandler extends NodeHttpHandler {
13
12
  constructor(router, options = {}) {
14
- const serializer = new OpenAPISerializer();
15
- const matcher = new OpenAPIMatcher();
16
- const codec = new OpenAPICodec(serializer);
17
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
18
- }
19
- async handle(req, res, ...[
20
- options = {}
21
- ]) {
22
- const standardRequest = toStandardLazyRequest(req, res);
23
- const result = await this.standardHandler.handle(standardRequest, options);
24
- if (!result.matched) {
25
- return { matched: false };
26
- }
27
- await sendStandardResponse(res, result.response, options);
28
- return { matched: true };
13
+ super(new StandardOpenAPIHandler(router, options), options);
29
14
  }
30
15
  }
31
16
 
@@ -1,23 +1,34 @@
1
- import { ORPCError } from '@orpc/client';
2
- import { OpenAPISerializer } from '@orpc/openapi-client/standard';
1
+ import { ORPCError, HTTPPath } from '@orpc/client';
2
+ import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
3
3
  import { AnyProcedure, AnyRouter } from '@orpc/server';
4
4
  import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
5
5
  import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
6
- import { HTTPPath } from '@orpc/contract';
6
+ export { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
7
7
 
8
- declare class OpenAPICodec implements StandardCodec {
8
+ declare class StandardOpenAPICodec implements StandardCodec {
9
9
  private readonly serializer;
10
- constructor(serializer: OpenAPISerializer);
10
+ constructor(serializer: StandardOpenAPISerializer);
11
11
  decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
12
12
  encode(output: unknown, procedure: AnyProcedure): StandardResponse;
13
13
  encodeError(error: ORPCError<any, any>): StandardResponse;
14
14
  }
15
15
 
16
- declare class OpenAPIMatcher implements StandardMatcher {
16
+ declare class StandardOpenAPIMatcher implements StandardMatcher {
17
17
  private readonly tree;
18
18
  private pendingRouters;
19
- init(router: AnyRouter, path?: string[]): void;
19
+ init(router: AnyRouter, path?: readonly string[]): void;
20
20
  match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
21
21
  }
22
22
 
23
- export { OpenAPICodec, OpenAPIMatcher };
23
+ /**
24
+ * {@link https://github.com/unjs/rou3}
25
+ *
26
+ * @internal
27
+ */
28
+ declare function toRou3Pattern(path: HTTPPath): string;
29
+ /**
30
+ * @internal
31
+ */
32
+ declare function decodeParams(params: Record<string, string>): Record<string, string>;
33
+
34
+ export { StandardOpenAPICodec, StandardOpenAPIMatcher, decodeParams, toRou3Pattern };
@@ -1,23 +1,34 @@
1
- import { ORPCError } from '@orpc/client';
2
- import { OpenAPISerializer } from '@orpc/openapi-client/standard';
1
+ import { ORPCError, HTTPPath } from '@orpc/client';
2
+ import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
3
3
  import { AnyProcedure, AnyRouter } from '@orpc/server';
4
4
  import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
5
5
  import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
6
- import { HTTPPath } from '@orpc/contract';
6
+ export { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
7
7
 
8
- declare class OpenAPICodec implements StandardCodec {
8
+ declare class StandardOpenAPICodec implements StandardCodec {
9
9
  private readonly serializer;
10
- constructor(serializer: OpenAPISerializer);
10
+ constructor(serializer: StandardOpenAPISerializer);
11
11
  decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
12
12
  encode(output: unknown, procedure: AnyProcedure): StandardResponse;
13
13
  encodeError(error: ORPCError<any, any>): StandardResponse;
14
14
  }
15
15
 
16
- declare class OpenAPIMatcher implements StandardMatcher {
16
+ declare class StandardOpenAPIMatcher implements StandardMatcher {
17
17
  private readonly tree;
18
18
  private pendingRouters;
19
- init(router: AnyRouter, path?: string[]): void;
19
+ init(router: AnyRouter, path?: readonly string[]): void;
20
20
  match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
21
21
  }
22
22
 
23
- export { OpenAPICodec, OpenAPIMatcher };
23
+ /**
24
+ * {@link https://github.com/unjs/rou3}
25
+ *
26
+ * @internal
27
+ */
28
+ declare function toRou3Pattern(path: HTTPPath): string;
29
+ /**
30
+ * @internal
31
+ */
32
+ declare function decodeParams(params: Record<string, string>): Record<string, string>;
33
+
34
+ export { StandardOpenAPICodec, StandardOpenAPIMatcher, decodeParams, toRou3Pattern };
@@ -1,6 +1,8 @@
1
- export { O as OpenAPICodec, a as OpenAPIMatcher } from '../../shared/openapi.C_biOx82.mjs';
1
+ export { S as StandardOpenAPICodec, a as StandardOpenAPIHandler, b as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.p5tsmBXx.mjs';
2
+ import '@orpc/openapi-client/standard';
3
+ import '@orpc/server/standard';
2
4
  import '@orpc/contract';
3
5
  import '@orpc/shared';
6
+ import '@orpc/client/standard';
4
7
  import '@orpc/server';
5
8
  import 'rou3';
6
- import '../../shared/openapi.BHG_gu5Z.mjs';
package/dist/index.d.mts CHANGED
@@ -1,167 +1,131 @@
1
- import { AnyContractProcedure, Schema, ContractRouter, HTTPPath } from '@orpc/contract';
2
- import * as OpenAPI from 'openapi3-ts/oas31';
3
- export { OpenAPI };
4
- export { OpenApiBuilder } from 'openapi3-ts/oas31';
5
- import { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
- export { JSONSchema, Format as JSONSchemaFormat, keywords as JSONSchemaKeywords } from 'json-schema-typed/draft-2020-12';
7
- import { OpenAPIJsonSerializer } from '@orpc/openapi-client/standard';
1
+ import { AnyContractProcedure, AnySchema, AnyContractRouter } from '@orpc/contract';
2
+ import { OpenAPIV3_1 } from 'openapi-types';
3
+ export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
4
+ import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
8
5
  import { AnyRouter } from '@orpc/server';
6
+ import { Promisable } from '@orpc/shared';
7
+ import { JSONSchema } from 'json-schema-typed/draft-2020-12';
8
+ export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
9
+ import { HTTPPath, HTTPMethod } from '@orpc/client';
9
10
 
10
- type OverrideOperationValue = OpenAPI.OperationObject | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
11
- declare function setOperationExtender<T extends object>(o: T, extend: OverrideOperationValue): T;
12
- declare function getOperationExtender(o: object): OverrideOperationValue | undefined;
13
- declare function extendOperation(operation: OpenAPI.OperationObject, procedure: AnyContractProcedure): OpenAPI.OperationObject;
11
+ type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
12
+ /**
13
+ * Customize The Operation Object by proxy an error map item or a middleware.
14
+ *
15
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
16
+ */
17
+ declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
18
+ declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
19
+ declare function applyCustomOpenAPIOperation(operation: OpenAPIV3_1.OperationObject, contract: AnyContractProcedure): OpenAPIV3_1.OperationObject;
14
20
 
21
+ /**
22
+ * @internal
23
+ */
15
24
  type ObjectSchema = JSONSchema & {
16
25
  type: 'object';
17
26
  } & object;
27
+ /**
28
+ * @internal
29
+ */
18
30
  type FileSchema = JSONSchema & {
19
31
  type: 'string';
20
32
  contentMediaType: string;
21
33
  } & object;
22
- declare const NON_LOGIC_KEYWORDS: string[];
23
-
24
- declare class SchemaUtils {
25
- isFileSchema(schema: JSONSchema): schema is FileSchema;
26
- isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
27
- isAnySchema(schema: JSONSchema): boolean;
28
- isUndefinableSchema(schema: JSONSchema): boolean;
29
- separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
30
- filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
31
- }
32
- type PublicSchemaUtils = Pick<SchemaUtils, keyof SchemaUtils>;
34
+ /**
35
+ * @internal
36
+ */
37
+ declare const LOGIC_KEYWORDS: string[];
33
38
 
34
- declare class OpenAPIContentBuilder {
35
- private readonly schemaUtils;
36
- constructor(schemaUtils: PublicSchemaUtils);
37
- build(jsonSchema: JSONSchema, options?: Partial<OpenAPI.MediaTypeObject>): OpenAPI.ContentObject;
39
+ interface SchemaConvertOptions {
40
+ strategy: 'input' | 'output';
38
41
  }
39
- type PublicOpenAPIContentBuilder = Pick<OpenAPIContentBuilder, keyof OpenAPIContentBuilder>;
40
-
41
- declare class OpenAPIPathParser {
42
- parseDynamicParams(path: string): {
43
- name: string;
44
- raw: string;
45
- }[];
46
- }
47
- type PublicOpenAPIPathParser = Pick<OpenAPIPathParser, keyof OpenAPIPathParser>;
48
-
49
- type SchemaConvertStrategy = 'input' | 'output';
50
42
  interface SchemaConverter {
51
- convert(schema: Schema, strategy: SchemaConvertStrategy): [required: boolean, jsonSchema: JSONSchema];
43
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
52
44
  }
53
45
  interface ConditionalSchemaConverter extends SchemaConverter {
54
- condition(schema: Schema, strategy: SchemaConvertStrategy): boolean;
46
+ condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
55
47
  }
56
48
  declare class CompositeSchemaConverter implements SchemaConverter {
57
49
  private readonly converters;
58
50
  constructor(converters: ConditionalSchemaConverter[]);
59
- convert(schema: Schema, strategy: SchemaConvertStrategy): [required: boolean, jsonSchema: JSONSchema];
60
- }
61
-
62
- interface OpenAPIInputStructureParseResult {
63
- paramsSchema: ObjectSchema | undefined;
64
- querySchema: ObjectSchema | undefined;
65
- headersSchema: ObjectSchema | undefined;
66
- bodySchema: JSONSchema | undefined;
67
- }
68
- declare class OpenAPIInputStructureParser {
69
- private readonly schemaConverter;
70
- private readonly schemaUtils;
71
- private readonly pathParser;
72
- constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
73
- parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
74
- private parseDetailedSchema;
75
- private parseCompactSchema;
76
- }
77
- type PublicOpenAPIInputStructureParser = Pick<OpenAPIInputStructureParser, keyof OpenAPIInputStructureParser>;
78
-
79
- interface OpenAPIOutputStructureParseResult {
80
- headersSchema: ObjectSchema | undefined;
81
- bodySchema: JSONSchema | undefined;
51
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
82
52
  }
83
- declare class OpenAPIOutputStructureParser {
84
- private readonly schemaConverter;
85
- private readonly schemaUtils;
86
- constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
87
- parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
88
- private parseDetailedSchema;
89
- private parseCompactSchema;
90
- }
91
- type PublicOpenAPIOutputStructureParser = Pick<OpenAPIOutputStructureParser, keyof OpenAPIOutputStructureParser>;
92
-
93
- declare class OpenAPIParametersBuilder {
94
- build(paramIn: OpenAPI.ParameterObject['in'], jsonSchema: JSONSchema & {
95
- type: 'object';
96
- } & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.ParameterObject[];
97
- buildHeadersObject(jsonSchema: JSONSchema & {
98
- type: 'object';
99
- } & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.HeadersObject;
100
- }
101
- type PublicOpenAPIParametersBuilder = Pick<OpenAPIParametersBuilder, keyof OpenAPIParametersBuilder>;
102
53
 
103
- type ErrorHandlerStrategy = 'throw' | 'log' | 'ignore';
104
- interface OpenAPIGeneratorOptions {
105
- contentBuilder?: PublicOpenAPIContentBuilder;
106
- parametersBuilder?: PublicOpenAPIParametersBuilder;
54
+ interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
107
55
  schemaConverters?: ConditionalSchemaConverter[];
108
- schemaUtils?: PublicSchemaUtils;
109
- jsonSerializer?: OpenAPIJsonSerializer;
110
- pathParser?: PublicOpenAPIPathParser;
111
- inputStructureParser?: PublicOpenAPIInputStructureParser;
112
- outputStructureParser?: PublicOpenAPIOutputStructureParser;
113
- /**
114
- * Throw error when you missing define tag definition on OpenAPI root tags
115
- *
116
- * Example: if procedure has tags ['foo', 'bar'], and OpenAPI root tags is ['foo'], then error will be thrown
117
- * Because OpenAPI root tags is missing 'bar' tag
118
- *
119
- * @default false
120
- */
121
- considerMissingTagDefinitionAsError?: boolean;
122
- /**
123
- * Weather ignore procedures that has no path defined.
124
- *
125
- * @default false
126
- */
127
- ignoreUndefinedPathProcedures?: boolean;
128
- /**
129
- * What to do when we found an error with our router
130
- *
131
- * @default 'throw'
132
- */
133
- errorHandlerStrategy?: ErrorHandlerStrategy;
134
- /**
135
- * Strict error response
136
- *
137
- * @default true
138
- */
139
- strictErrorResponses?: boolean;
140
56
  }
57
+ /**
58
+ * The generator that converts oRPC routers/contracts to OpenAPI specifications.
59
+ *
60
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
61
+ */
141
62
  declare class OpenAPIGenerator {
142
- private readonly contentBuilder;
143
- private readonly parametersBuilder;
144
- private readonly schemaConverter;
145
- private readonly schemaUtils;
146
- private readonly jsonSerializer;
147
- private readonly pathParser;
148
- private readonly inputStructureParser;
149
- private readonly outputStructureParser;
150
- private readonly errorHandlerStrategy;
151
- private readonly ignoreUndefinedPathProcedures;
152
- private readonly considerMissingTagDefinitionAsError;
153
- private readonly strictErrorResponses;
63
+ #private;
64
+ private readonly serializer;
65
+ private readonly converter;
154
66
  constructor(options?: OpenAPIGeneratorOptions);
155
- generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
67
+ /**
68
+ * Generates OpenAPI specifications from oRPC routers/contracts.
69
+ *
70
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
71
+ */
72
+ generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
156
73
  }
157
74
 
158
- declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
159
- declare function toOpenAPI31RoutePattern(path: HTTPPath): string;
75
+ /**
76
+ * @internal
77
+ */
78
+ declare function toOpenAPIPath(path: HTTPPath): string;
79
+ /**
80
+ * @internal
81
+ */
82
+ declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
83
+ /**
84
+ * @internal
85
+ */
86
+ declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPIV3_1.MediaTypeObject>;
87
+ /**
88
+ * @internal
89
+ */
90
+ declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPIV3_1.MediaTypeObject>;
91
+ /**
92
+ * @internal
93
+ */
94
+ declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPIV3_1.ParameterObject[];
95
+ /**
96
+ * @internal
97
+ */
98
+ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
99
+ /**
100
+ * @internal
101
+ */
102
+ declare function toOpenAPISchema(schema: JSONSchema): OpenAPIV3_1.SchemaObject & object;
160
103
 
161
- /** unnoq */
104
+ /**
105
+ *@internal
106
+ */
107
+ declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
108
+ /**
109
+ * @internal
110
+ */
111
+ declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
112
+ /**
113
+ * @internal
114
+ */
115
+ declare function isAnySchema(schema: JSONSchema): boolean;
116
+ /**
117
+ * @internal
118
+ */
119
+ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
120
+ /**
121
+ * @internal
122
+ */
123
+ declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
124
+ declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
162
125
 
163
126
  declare const oo: {
164
- spec: typeof setOperationExtender;
127
+ spec: typeof customOpenAPIOperation;
165
128
  };
166
129
 
167
- export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, NON_LOGIC_KEYWORDS, type ObjectSchema, OpenAPIContentBuilder, OpenAPIGenerator, type OpenAPIGeneratorOptions, OpenAPIParametersBuilder, OpenAPIPathParser, type OverrideOperationValue, type PublicOpenAPIContentBuilder, type PublicOpenAPIParametersBuilder, type PublicOpenAPIPathParser, type PublicSchemaUtils, type SchemaConvertStrategy, type SchemaConverter, SchemaUtils, extendOperation, getOperationExtender, oo, setOperationExtender, standardizeHTTPPath, toOpenAPI31RoutePattern };
130
+ export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
131
+ export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter };