@orpc/openapi 0.41.1 → 0.42.0

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 ADDED
@@ -0,0 +1,91 @@
1
+ <div align="center">
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
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), 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-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
+ - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+
62
+ ## `@orpc/openapi`
63
+
64
+ Generate OpenAPI specs and handle OpenAPI requests. Read the [documentation](https://orpc.unnoq.com/docs/openapi/getting-started) for more information.
65
+
66
+ ```ts
67
+ import { createServer } from 'node:http'
68
+ import { OpenAPIHandler } from '@orpc/openapi/node'
69
+ import { CORSPlugin } from '@orpc/server/plugins'
70
+
71
+ const handler = new OpenAPIHandler(router, {
72
+ plugins: [new CORSPlugin()]
73
+ })
74
+
75
+ const server = createServer(async (req, res) => {
76
+ const result = await handler.handle(req, res, {
77
+ context: { headers: req.headers }
78
+ })
79
+
80
+ if (!result.matched) {
81
+ res.statusCode = 404
82
+ res.end('No procedure matched')
83
+ }
84
+ })
85
+
86
+ server.listen(3000, '127.0.0.1', () => console.log('Listening on 127.0.0.1:3000'))
87
+ ```
88
+
89
+ ## License
90
+
91
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPICodec,
3
3
  OpenAPIMatcher
4
- } from "./chunk-LPBZEW4B.js";
4
+ } from "./chunk-PGCWJMRO.js";
5
5
 
6
6
  // src/adapters/fetch/openapi-handler.ts
7
7
  import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
@@ -9,8 +9,8 @@ import { StandardHandler } from "@orpc/server/standard";
9
9
  var OpenAPIHandler = class {
10
10
  standardHandler;
11
11
  constructor(router, options) {
12
- const matcher = options?.matcher ?? new OpenAPIMatcher(options);
13
- const codec = options?.codec ?? new OpenAPICodec(options);
12
+ const matcher = options?.matcher ?? new OpenAPIMatcher();
13
+ const codec = options?.codec ?? new OpenAPICodec();
14
14
  this.standardHandler = new StandardHandler(router, matcher, codec, options);
15
15
  }
16
16
  async handle(request, ...rest) {
@@ -29,4 +29,4 @@ var OpenAPIHandler = class {
29
29
  export {
30
30
  OpenAPIHandler
31
31
  };
32
- //# sourceMappingURL=chunk-UU2TTVB2.js.map
32
+ //# sourceMappingURL=chunk-ATDLVTJE.js.map
@@ -7,9 +7,8 @@ import { OpenAPISerializer } from "@orpc/client/openapi";
7
7
  import { fallbackContractConfig } from "@orpc/contract";
8
8
  import { isObject } from "@orpc/shared";
9
9
  var OpenAPICodec = class {
10
- serializer;
11
- constructor(options) {
12
- this.serializer = options?.serializer ?? new OpenAPISerializer();
10
+ constructor(serializer = new OpenAPISerializer()) {
11
+ this.serializer = serializer;
13
12
  }
14
13
  async decode(request, params, procedure) {
15
14
  const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
@@ -79,19 +78,12 @@ import { convertPathToHttpPath, createContractedProcedure, eachContractProcedure
79
78
  import { addRoute, createRouter, findRoute } from "rou3";
80
79
  var OpenAPIMatcher = class {
81
80
  tree = createRouter();
82
- ignoreUndefinedMethod;
83
- constructor(options) {
84
- this.ignoreUndefinedMethod = options?.ignoreUndefinedMethod ?? false;
85
- }
86
81
  pendingRouters = [];
87
82
  init(router, path = []) {
88
83
  const laziedOptions = eachContractProcedure({
89
84
  router,
90
85
  path
91
86
  }, ({ path: path2, contract }) => {
92
- if (!contract["~orpc"].route.method && this.ignoreUndefinedMethod) {
93
- return;
94
- }
95
87
  const method = fallbackContractConfig2("defaultMethod", contract["~orpc"].route.method);
96
88
  const httpPath = contract["~orpc"].route.path ? toRou3Pattern(contract["~orpc"].route.path) : convertPathToHttpPath(path2);
97
89
  if (isProcedure(contract)) {
@@ -162,4 +154,4 @@ export {
162
154
  OpenAPICodec,
163
155
  OpenAPIMatcher
164
156
  };
165
- //# sourceMappingURL=chunk-LPBZEW4B.js.map
157
+ //# sourceMappingURL=chunk-PGCWJMRO.js.map
package/dist/fetch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-UU2TTVB2.js";
4
- import "./chunk-LPBZEW4B.js";
3
+ } from "./chunk-ATDLVTJE.js";
4
+ import "./chunk-PGCWJMRO.js";
5
5
  import "./chunk-XGHV4TH3.js";
6
6
  export {
7
7
  OpenAPIHandler
package/dist/hono.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-UU2TTVB2.js";
4
- import "./chunk-LPBZEW4B.js";
3
+ } from "./chunk-ATDLVTJE.js";
4
+ import "./chunk-PGCWJMRO.js";
5
5
  import "./chunk-XGHV4TH3.js";
6
6
  export {
7
7
  OpenAPIHandler
package/dist/index.js CHANGED
@@ -672,7 +672,7 @@ var OpenAPIGenerator = class {
672
672
  }
673
673
  }
674
674
  });
675
- return this.jsonSerializer.serialize(builder.getSpec());
675
+ return this.jsonSerializer.serialize(builder.getSpec())[0];
676
676
  }
677
677
  };
678
678
 
package/dist/next.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-UU2TTVB2.js";
4
- import "./chunk-LPBZEW4B.js";
3
+ } from "./chunk-ATDLVTJE.js";
4
+ import "./chunk-PGCWJMRO.js";
5
5
  import "./chunk-XGHV4TH3.js";
6
6
  export {
7
7
  OpenAPIHandler
package/dist/node.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPICodec,
3
3
  OpenAPIMatcher
4
- } from "./chunk-LPBZEW4B.js";
4
+ } from "./chunk-PGCWJMRO.js";
5
5
  import "./chunk-XGHV4TH3.js";
6
6
 
7
7
  // src/adapters/node/openapi-handler.ts
@@ -10,8 +10,8 @@ import { StandardHandler } from "@orpc/server/standard";
10
10
  var OpenAPIHandler = class {
11
11
  standardHandler;
12
12
  constructor(router, options) {
13
- const matcher = options?.matcher ?? new OpenAPIMatcher(options);
14
- const codec = options?.codec ?? new OpenAPICodec(options);
13
+ const matcher = options?.matcher ?? new OpenAPIMatcher();
14
+ const codec = options?.codec ?? new OpenAPICodec();
15
15
  this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
16
16
  }
17
17
  async handle(req, res, ...rest) {
@@ -3,12 +3,9 @@ import type { AnyProcedure } from '@orpc/server';
3
3
  import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
4
4
  import type { StandardCodec, StandardParams } from '@orpc/server/standard';
5
5
  import { OpenAPISerializer } from '@orpc/client/openapi';
6
- export interface OpenAPICodecOptions {
7
- serializer?: OpenAPISerializer;
8
- }
9
6
  export declare class OpenAPICodec implements StandardCodec {
10
7
  private readonly serializer;
11
- constructor(options?: OpenAPICodecOptions);
8
+ constructor(serializer?: OpenAPISerializer);
12
9
  decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
13
10
  encode(output: unknown, procedure: AnyProcedure): StandardResponse;
14
11
  encodeError(error: ORPCError<any, any>): StandardResponse;
@@ -1,7 +1,5 @@
1
1
  import type { Context } from '@orpc/server';
2
2
  import type { RPCHandlerOptions } from '@orpc/server/standard';
3
- import type { OpenAPICodecOptions } from './openapi-codec';
4
- import type { OpenAPIMatcherOptions } from './openapi-matcher';
5
- export interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T>, OpenAPIMatcherOptions, OpenAPICodecOptions {
3
+ export interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T> {
6
4
  }
7
5
  //# sourceMappingURL=openapi-handler.d.ts.map
@@ -1,18 +1,8 @@
1
1
  import type { AnyRouter } from '@orpc/server';
2
2
  import type { StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
3
3
  import { type HTTPPath } from '@orpc/contract';
4
- export interface OpenAPIMatcherOptions {
5
- /**
6
- * Ignore procedure that does not have a method defined in the contract.
7
- *
8
- * @default false
9
- */
10
- ignoreUndefinedMethod?: boolean;
11
- }
12
4
  export declare class OpenAPIMatcher implements StandardMatcher {
13
5
  private readonly tree;
14
- private readonly ignoreUndefinedMethod;
15
- constructor(options?: OpenAPIMatcherOptions);
16
6
  private pendingRouters;
17
7
  init(router: AnyRouter, path?: string[]): void;
18
8
  match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
@@ -2,7 +2,7 @@ import type { PublicOpenAPIInputStructureParser } from './openapi-input-structur
2
2
  import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
3
3
  import type { PublicOpenAPIPathParser } from './openapi-path-parser';
4
4
  import type { SchemaConverter } from './schema-converter';
5
- import { type PublicOpenAPIJsonSerializer } from '@orpc/client/openapi';
5
+ import { OpenAPIJsonSerializer } from '@orpc/client/openapi';
6
6
  import { type ContractRouter } from '@orpc/contract';
7
7
  import { type AnyRouter } from '@orpc/server';
8
8
  import { type OpenAPI } from './openapi';
@@ -15,7 +15,7 @@ export interface OpenAPIGeneratorOptions {
15
15
  parametersBuilder?: PublicOpenAPIParametersBuilder;
16
16
  schemaConverters?: SchemaConverter[];
17
17
  schemaUtils?: PublicSchemaUtils;
18
- jsonSerializer?: PublicOpenAPIJsonSerializer;
18
+ jsonSerializer?: OpenAPIJsonSerializer;
19
19
  pathParser?: PublicOpenAPIPathParser;
20
20
  inputStructureParser?: PublicOpenAPIInputStructureParser;
21
21
  outputStructureParser?: PublicOpenAPIOutputStructureParser;
package/dist/standard.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPICodec,
3
3
  OpenAPIMatcher
4
- } from "./chunk-LPBZEW4B.js";
4
+ } from "./chunk-PGCWJMRO.js";
5
5
  import "./chunk-XGHV4TH3.js";
6
6
  export {
7
7
  OpenAPICodec,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.41.1",
4
+ "version": "0.42.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -60,10 +60,10 @@
60
60
  "json-schema-typed": "^8.0.1",
61
61
  "openapi3-ts": "^4.4.0",
62
62
  "rou3": "^0.5.1",
63
- "@orpc/client": "0.41.1",
64
- "@orpc/contract": "0.41.1",
65
- "@orpc/server": "0.41.1",
66
- "@orpc/shared": "0.41.1"
63
+ "@orpc/client": "0.42.0",
64
+ "@orpc/contract": "0.42.0",
65
+ "@orpc/shared": "0.42.0",
66
+ "@orpc/server": "0.42.0"
67
67
  },
68
68
  "devDependencies": {
69
69
  "zod": "^3.24.1"