@orpc/openapi 0.0.0-next.f22c7ec → 0.0.0-next.f47352c

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 (63) hide show
  1. package/README.md +104 -0
  2. package/dist/adapters/fetch/index.d.mts +11 -0
  3. package/dist/adapters/fetch/index.d.ts +11 -0
  4. package/dist/adapters/fetch/index.mjs +10 -0
  5. package/dist/adapters/hono/index.d.mts +6 -0
  6. package/dist/adapters/hono/index.d.ts +6 -0
  7. package/dist/adapters/hono/index.mjs +10 -0
  8. package/dist/adapters/next/index.d.mts +6 -0
  9. package/dist/adapters/next/index.d.ts +6 -0
  10. package/dist/adapters/next/index.mjs +10 -0
  11. package/dist/adapters/node/index.d.mts +11 -0
  12. package/dist/adapters/node/index.d.ts +11 -0
  13. package/dist/adapters/node/index.mjs +22 -0
  14. package/dist/adapters/standard/index.d.mts +34 -0
  15. package/dist/adapters/standard/index.d.ts +34 -0
  16. package/dist/adapters/standard/index.mjs +7 -0
  17. package/dist/index.d.mts +114 -0
  18. package/dist/index.d.ts +114 -0
  19. package/dist/index.mjs +536 -0
  20. package/dist/shared/openapi.CGZ7t-VN.mjs +17 -0
  21. package/dist/shared/openapi.IfmmOyba.d.mts +8 -0
  22. package/dist/shared/openapi.IfmmOyba.d.ts +8 -0
  23. package/dist/shared/openapi.sdeu0I7N.mjs +146 -0
  24. package/package.json +31 -35
  25. package/dist/chunk-N7JLIFHD.js +0 -25
  26. package/dist/chunk-TW72MGM2.js +0 -651
  27. package/dist/chunk-V4HFPIEN.js +0 -107
  28. package/dist/fetch.js +0 -34
  29. package/dist/hono.js +0 -34
  30. package/dist/index.js +0 -550
  31. package/dist/next.js +0 -34
  32. package/dist/node.js +0 -46
  33. package/dist/src/adapters/fetch/bracket-notation.d.ts +0 -84
  34. package/dist/src/adapters/fetch/index.d.ts +0 -10
  35. package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
  36. package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
  37. package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
  38. package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
  39. package/dist/src/adapters/fetch/openapi-handler.d.ts +0 -32
  40. package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
  41. package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
  42. package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
  43. package/dist/src/adapters/hono/index.d.ts +0 -2
  44. package/dist/src/adapters/next/index.d.ts +0 -2
  45. package/dist/src/adapters/node/index.d.ts +0 -5
  46. package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
  47. package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
  48. package/dist/src/adapters/node/openapi-handler.d.ts +0 -11
  49. package/dist/src/adapters/node/types.d.ts +0 -2
  50. package/dist/src/index.d.ts +0 -12
  51. package/dist/src/json-serializer.d.ts +0 -5
  52. package/dist/src/openapi-content-builder.d.ts +0 -10
  53. package/dist/src/openapi-error.d.ts +0 -3
  54. package/dist/src/openapi-generator.d.ts +0 -67
  55. package/dist/src/openapi-input-structure-parser.d.ts +0 -22
  56. package/dist/src/openapi-output-structure-parser.d.ts +0 -18
  57. package/dist/src/openapi-parameters-builder.d.ts +0 -12
  58. package/dist/src/openapi-path-parser.d.ts +0 -8
  59. package/dist/src/openapi.d.ts +0 -3
  60. package/dist/src/schema-converter.d.ts +0 -16
  61. package/dist/src/schema-utils.d.ts +0 -11
  62. package/dist/src/schema.d.ts +0 -12
  63. package/dist/src/utils.d.ts +0 -18
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ <div align="center">
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
+ </div>
4
+
5
+ <h1></h1>
6
+
7
+ <div align="center">
8
+ <a href="https://codecov.io/gh/unnoq/orpc">
9
+ <img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@orpc/openapi">
12
+ <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fopenapi?logo=npm" />
13
+ </a>
14
+ <a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
15
+ <img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
16
+ </a>
17
+ <a href="https://discord.gg/TXEbwRBvQn">
18
+ <img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
19
+ </a>
20
+ </div>
21
+
22
+ <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
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.
25
+
26
+ ---
27
+
28
+ ## Highlights
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, Solid, Svelte), 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.
46
+
47
+ ## Documentation
48
+
49
+ You can find the full documentation [here](https://orpc.unnoq.com).
50
+
51
+ ## Packages
52
+
53
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
57
+ - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
58
+ - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
59
+ - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
60
+ - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
61
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
62
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
63
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
64
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
65
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
66
+
67
+ ## `@orpc/openapi`
68
+
69
+ Generate OpenAPI specs and handle OpenAPI requests. Read the [documentation](https://orpc.unnoq.com/docs/openapi/getting-started) for more information.
70
+
71
+ ```ts
72
+ import { createServer } from 'node:http'
73
+ import { OpenAPIHandler } from '@orpc/openapi/node'
74
+ import { CORSPlugin } from '@orpc/server/plugins'
75
+
76
+ const handler = new OpenAPIHandler(router, {
77
+ plugins: [new CORSPlugin()]
78
+ })
79
+
80
+ const server = createServer(async (req, res) => {
81
+ const result = await handler.handle(req, res, {
82
+ context: { headers: req.headers }
83
+ })
84
+
85
+ if (!result.matched) {
86
+ res.statusCode = 404
87
+ res.end('No procedure matched')
88
+ }
89
+ })
90
+
91
+ server.listen(3000, '127.0.0.1', () => console.log('Listening on 127.0.0.1:3000'))
92
+ ```
93
+
94
+ ## Sponsors
95
+
96
+ <p align="center">
97
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
98
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
99
+ </a>
100
+ </p>
101
+
102
+ ## License
103
+
104
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -0,0 +1,11 @@
1
+ import { Context, Router } from '@orpc/server';
2
+ import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
4
+ import '@orpc/openapi-client/standard';
5
+ import '@orpc/server/standard';
6
+
7
+ declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
8
+ constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
9
+ }
10
+
11
+ export { OpenAPIHandler };
@@ -0,0 +1,11 @@
1
+ import { Context, Router } from '@orpc/server';
2
+ import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
4
+ import '@orpc/openapi-client/standard';
5
+ import '@orpc/server/standard';
6
+
7
+ declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
8
+ constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
9
+ }
10
+
11
+ export { OpenAPIHandler };
@@ -0,0 +1,10 @@
1
+ export { O as OpenAPIHandler } from '../../shared/openapi.CGZ7t-VN.mjs';
2
+ import '@orpc/openapi-client/standard';
3
+ import '@orpc/server/fetch';
4
+ import '@orpc/server/standard';
5
+ import '../../shared/openapi.sdeu0I7N.mjs';
6
+ import '@orpc/contract';
7
+ import '@orpc/shared';
8
+ import '@orpc/client/standard';
9
+ import '@orpc/server';
10
+ import 'rou3';
@@ -0,0 +1,6 @@
1
+ export { OpenAPIHandler } from '../fetch/index.mjs';
2
+ import '@orpc/server';
3
+ import '@orpc/server/fetch';
4
+ import '../../shared/openapi.IfmmOyba.mjs';
5
+ import '@orpc/openapi-client/standard';
6
+ import '@orpc/server/standard';
@@ -0,0 +1,6 @@
1
+ export { OpenAPIHandler } from '../fetch/index.js';
2
+ import '@orpc/server';
3
+ import '@orpc/server/fetch';
4
+ import '../../shared/openapi.IfmmOyba.js';
5
+ import '@orpc/openapi-client/standard';
6
+ import '@orpc/server/standard';
@@ -0,0 +1,10 @@
1
+ export { O as OpenAPIHandler } from '../../shared/openapi.CGZ7t-VN.mjs';
2
+ import '@orpc/openapi-client/standard';
3
+ import '@orpc/server/fetch';
4
+ import '@orpc/server/standard';
5
+ import '../../shared/openapi.sdeu0I7N.mjs';
6
+ import '@orpc/contract';
7
+ import '@orpc/shared';
8
+ import '@orpc/client/standard';
9
+ import '@orpc/server';
10
+ import 'rou3';
@@ -0,0 +1,6 @@
1
+ export { OpenAPIHandler } from '../fetch/index.mjs';
2
+ import '@orpc/server';
3
+ import '@orpc/server/fetch';
4
+ import '../../shared/openapi.IfmmOyba.mjs';
5
+ import '@orpc/openapi-client/standard';
6
+ import '@orpc/server/standard';
@@ -0,0 +1,6 @@
1
+ export { OpenAPIHandler } from '../fetch/index.js';
2
+ import '@orpc/server';
3
+ import '@orpc/server/fetch';
4
+ import '../../shared/openapi.IfmmOyba.js';
5
+ import '@orpc/openapi-client/standard';
6
+ import '@orpc/server/standard';
@@ -0,0 +1,10 @@
1
+ export { O as OpenAPIHandler } from '../../shared/openapi.CGZ7t-VN.mjs';
2
+ import '@orpc/openapi-client/standard';
3
+ import '@orpc/server/fetch';
4
+ import '@orpc/server/standard';
5
+ import '../../shared/openapi.sdeu0I7N.mjs';
6
+ import '@orpc/contract';
7
+ import '@orpc/shared';
8
+ import '@orpc/client/standard';
9
+ import '@orpc/server';
10
+ import 'rou3';
@@ -0,0 +1,11 @@
1
+ import { Context, Router } from '@orpc/server';
2
+ import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
4
+ import '@orpc/openapi-client/standard';
5
+ import '@orpc/server/standard';
6
+
7
+ declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
8
+ constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
9
+ }
10
+
11
+ export { OpenAPIHandler };
@@ -0,0 +1,11 @@
1
+ import { Context, Router } from '@orpc/server';
2
+ import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
4
+ import '@orpc/openapi-client/standard';
5
+ import '@orpc/server/standard';
6
+
7
+ declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
8
+ constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
9
+ }
10
+
11
+ export { OpenAPIHandler };
@@ -0,0 +1,22 @@
1
+ import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
2
+ import { NodeHttpHandler } from '@orpc/server/node';
3
+ import { StandardHandler } from '@orpc/server/standard';
4
+ import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from '../../shared/openapi.sdeu0I7N.mjs';
5
+ import '@orpc/contract';
6
+ import '@orpc/shared';
7
+ import '@orpc/client/standard';
8
+ import '@orpc/server';
9
+ import 'rou3';
10
+
11
+ class OpenAPIHandler extends NodeHttpHandler {
12
+ constructor(router, options = {}) {
13
+ const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
14
+ const bracketNotationSerializer = new StandardBracketNotationSerializer();
15
+ const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
16
+ const matcher = new StandardOpenAPIMatcher();
17
+ const codec = new StandardOpenAPICodec(serializer);
18
+ super(new StandardHandler(router, matcher, codec, options), options);
19
+ }
20
+ }
21
+
22
+ export { OpenAPIHandler };
@@ -0,0 +1,34 @@
1
+ import { ORPCError, HTTPPath } from '@orpc/client';
2
+ import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
3
+ import { AnyProcedure, AnyRouter } from '@orpc/server';
4
+ import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
5
+ import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
6
+ export { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
7
+
8
+ declare class StandardOpenAPICodec implements StandardCodec {
9
+ private readonly serializer;
10
+ constructor(serializer: StandardOpenAPISerializer);
11
+ decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
12
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
13
+ encodeError(error: ORPCError<any, any>): StandardResponse;
14
+ }
15
+
16
+ declare class StandardOpenAPIMatcher implements StandardMatcher {
17
+ private readonly tree;
18
+ private pendingRouters;
19
+ init(router: AnyRouter, path?: readonly string[]): void;
20
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
21
+ }
22
+
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 };
@@ -0,0 +1,34 @@
1
+ import { ORPCError, HTTPPath } from '@orpc/client';
2
+ import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
3
+ import { AnyProcedure, AnyRouter } from '@orpc/server';
4
+ import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
5
+ import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
6
+ export { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
7
+
8
+ declare class StandardOpenAPICodec implements StandardCodec {
9
+ private readonly serializer;
10
+ constructor(serializer: StandardOpenAPISerializer);
11
+ decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
12
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
13
+ encodeError(error: ORPCError<any, any>): StandardResponse;
14
+ }
15
+
16
+ declare class StandardOpenAPIMatcher implements StandardMatcher {
17
+ private readonly tree;
18
+ private pendingRouters;
19
+ init(router: AnyRouter, path?: readonly string[]): void;
20
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
21
+ }
22
+
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 };
@@ -0,0 +1,7 @@
1
+ export { S as StandardOpenAPICodec, a as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.sdeu0I7N.mjs';
2
+ import '@orpc/contract';
3
+ import '@orpc/shared';
4
+ import '@orpc/client/standard';
5
+ import '@orpc/server';
6
+ import 'rou3';
7
+ import '@orpc/openapi-client/standard';
@@ -0,0 +1,114 @@
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';
5
+ import { AnyRouter } from '@orpc/server';
6
+ import { JSONSchema } from 'json-schema-typed/draft-2020-12';
7
+ export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
8
+ import { HTTPPath, HTTPMethod } from '@orpc/client';
9
+
10
+ type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
11
+ declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
12
+ declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
13
+ declare function applyCustomOpenAPIOperation(operation: OpenAPIV3_1.OperationObject, contract: AnyContractProcedure): OpenAPIV3_1.OperationObject;
14
+
15
+ /**
16
+ * @internal
17
+ */
18
+ type ObjectSchema = JSONSchema & {
19
+ type: 'object';
20
+ } & object;
21
+ /**
22
+ * @internal
23
+ */
24
+ type FileSchema = JSONSchema & {
25
+ type: 'string';
26
+ contentMediaType: string;
27
+ } & object;
28
+ /**
29
+ * @internal
30
+ */
31
+ declare const LOGIC_KEYWORDS: string[];
32
+
33
+ interface SchemaConvertOptions {
34
+ strategy: 'input' | 'output';
35
+ }
36
+ interface SchemaConverter {
37
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
38
+ }
39
+ interface ConditionalSchemaConverter extends SchemaConverter {
40
+ condition(schema: AnySchema | undefined, options: SchemaConvertOptions): boolean;
41
+ }
42
+ declare class CompositeSchemaConverter implements SchemaConverter {
43
+ private readonly converters;
44
+ constructor(converters: ConditionalSchemaConverter[]);
45
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
46
+ }
47
+
48
+ interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
49
+ schemaConverters?: ConditionalSchemaConverter[];
50
+ }
51
+ declare class OpenAPIGenerator {
52
+ #private;
53
+ private readonly serializer;
54
+ private readonly converter;
55
+ constructor(options?: OpenAPIGeneratorOptions);
56
+ generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
57
+ }
58
+
59
+ /**
60
+ * @internal
61
+ */
62
+ declare function toOpenAPIPath(path: HTTPPath): string;
63
+ /**
64
+ * @internal
65
+ */
66
+ declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
67
+ /**
68
+ * @internal
69
+ */
70
+ declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPIV3_1.MediaTypeObject>;
71
+ /**
72
+ * @internal
73
+ */
74
+ declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPIV3_1.MediaTypeObject>;
75
+ /**
76
+ * @internal
77
+ */
78
+ declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPIV3_1.ParameterObject[];
79
+ /**
80
+ * @internal
81
+ */
82
+ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
83
+ /**
84
+ * @internal
85
+ */
86
+ declare function toOpenAPISchema(schema: JSONSchema): OpenAPIV3_1.SchemaObject & object;
87
+
88
+ /**
89
+ *@internal
90
+ */
91
+ declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
92
+ /**
93
+ * @internal
94
+ */
95
+ declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
96
+ /**
97
+ * @internal
98
+ */
99
+ declare function isAnySchema(schema: JSONSchema): boolean;
100
+ /**
101
+ * @internal
102
+ */
103
+ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
104
+ /**
105
+ * @internal
106
+ */
107
+ declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
108
+ declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
109
+
110
+ declare const oo: {
111
+ spec: typeof customOpenAPIOperation;
112
+ };
113
+
114
+ export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, LOGIC_KEYWORDS, type ObjectSchema, OpenAPIGenerator, type OpenAPIGeneratorOptions, type OverrideOperationValue, type SchemaConvertOptions, type SchemaConverter, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
@@ -0,0 +1,114 @@
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';
5
+ import { AnyRouter } from '@orpc/server';
6
+ import { JSONSchema } from 'json-schema-typed/draft-2020-12';
7
+ export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
8
+ import { HTTPPath, HTTPMethod } from '@orpc/client';
9
+
10
+ type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
11
+ declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
12
+ declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
13
+ declare function applyCustomOpenAPIOperation(operation: OpenAPIV3_1.OperationObject, contract: AnyContractProcedure): OpenAPIV3_1.OperationObject;
14
+
15
+ /**
16
+ * @internal
17
+ */
18
+ type ObjectSchema = JSONSchema & {
19
+ type: 'object';
20
+ } & object;
21
+ /**
22
+ * @internal
23
+ */
24
+ type FileSchema = JSONSchema & {
25
+ type: 'string';
26
+ contentMediaType: string;
27
+ } & object;
28
+ /**
29
+ * @internal
30
+ */
31
+ declare const LOGIC_KEYWORDS: string[];
32
+
33
+ interface SchemaConvertOptions {
34
+ strategy: 'input' | 'output';
35
+ }
36
+ interface SchemaConverter {
37
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
38
+ }
39
+ interface ConditionalSchemaConverter extends SchemaConverter {
40
+ condition(schema: AnySchema | undefined, options: SchemaConvertOptions): boolean;
41
+ }
42
+ declare class CompositeSchemaConverter implements SchemaConverter {
43
+ private readonly converters;
44
+ constructor(converters: ConditionalSchemaConverter[]);
45
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
46
+ }
47
+
48
+ interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
49
+ schemaConverters?: ConditionalSchemaConverter[];
50
+ }
51
+ declare class OpenAPIGenerator {
52
+ #private;
53
+ private readonly serializer;
54
+ private readonly converter;
55
+ constructor(options?: OpenAPIGeneratorOptions);
56
+ generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
57
+ }
58
+
59
+ /**
60
+ * @internal
61
+ */
62
+ declare function toOpenAPIPath(path: HTTPPath): string;
63
+ /**
64
+ * @internal
65
+ */
66
+ declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
67
+ /**
68
+ * @internal
69
+ */
70
+ declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPIV3_1.MediaTypeObject>;
71
+ /**
72
+ * @internal
73
+ */
74
+ declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPIV3_1.MediaTypeObject>;
75
+ /**
76
+ * @internal
77
+ */
78
+ declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPIV3_1.ParameterObject[];
79
+ /**
80
+ * @internal
81
+ */
82
+ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
83
+ /**
84
+ * @internal
85
+ */
86
+ declare function toOpenAPISchema(schema: JSONSchema): OpenAPIV3_1.SchemaObject & object;
87
+
88
+ /**
89
+ *@internal
90
+ */
91
+ declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
92
+ /**
93
+ * @internal
94
+ */
95
+ declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
96
+ /**
97
+ * @internal
98
+ */
99
+ declare function isAnySchema(schema: JSONSchema): boolean;
100
+ /**
101
+ * @internal
102
+ */
103
+ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
104
+ /**
105
+ * @internal
106
+ */
107
+ declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
108
+ declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
109
+
110
+ declare const oo: {
111
+ spec: typeof customOpenAPIOperation;
112
+ };
113
+
114
+ export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, LOGIC_KEYWORDS, type ObjectSchema, OpenAPIGenerator, type OpenAPIGeneratorOptions, type OverrideOperationValue, type SchemaConvertOptions, type SchemaConverter, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };