@orpc/server 0.41.1 → 0.41.2

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,118 @@
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/server">
12
+ <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fserver?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/server`
63
+
64
+ Build your API or implement API contract. Read the [documentation](https://orpc.unnoq.com/docs/getting-started) for more information.
65
+
66
+ ```ts
67
+ import type { IncomingHttpHeaders } from 'node:http'
68
+ import { ORPCError, os } from '@orpc/server'
69
+ import { z } from 'zod'
70
+
71
+ const PlanetSchema = z.object({
72
+ id: z.number().int().min(1),
73
+ name: z.string(),
74
+ description: z.string().optional(),
75
+ })
76
+
77
+ export const listPlanet = os
78
+ .input(
79
+ z.object({
80
+ limit: z.number().int().min(1).max(100).optional(),
81
+ cursor: z.number().int().min(0).default(0),
82
+ }),
83
+ )
84
+ .handler(async ({ input }) => {
85
+ // your list code here
86
+ return [{ id: 1, name: 'name' }]
87
+ })
88
+
89
+ export const findPlanet = os
90
+ .input(PlanetSchema.pick({ id: true }))
91
+ .handler(async ({ input }) => {
92
+ // your find code here
93
+ return { id: 1, name: 'name' }
94
+ })
95
+
96
+ export const createPlanet = os
97
+ .$context<{ headers: IncomingHttpHeaders }>()
98
+ .use(({ context, next }) => {
99
+ const user = parseJWT(context.headers.authorization?.split(' ')[1])
100
+
101
+ if (user) {
102
+ return next({ context: { user } })
103
+ }
104
+
105
+ throw new ORPCError('UNAUTHORIZED')
106
+ })
107
+ .input(PlanetSchema.omit({ id: true }))
108
+ .handler(async ({ input, context }) => {
109
+ // your create code here
110
+ return { id: 1, name: 'name' }
111
+ })
112
+
113
+ export const router = { planet: { list: listPlanet, find: findPlanet, create: createPlanet } }
114
+ ```
115
+
116
+ ## License
117
+
118
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -2,7 +2,7 @@ import {
2
2
  RPCCodec,
3
3
  RPCMatcher,
4
4
  StandardHandler
5
- } from "./chunk-LXOL226G.js";
5
+ } from "./chunk-77FU7QSO.js";
6
6
 
7
7
  // src/adapters/fetch/rpc-handler.ts
8
8
  import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
@@ -29,4 +29,4 @@ var RPCHandler = class {
29
29
  export {
30
30
  RPCHandler
31
31
  };
32
- //# sourceMappingURL=chunk-KPT6FDBK.js.map
32
+ //# sourceMappingURL=chunk-47YYO5JS.js.map
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-MHVECKBC.js";
10
10
  import {
11
11
  CompositePlugin
12
- } from "./chunk-XI6WGCB3.js";
12
+ } from "./chunk-WQNNSBXW.js";
13
13
 
14
14
  // src/adapters/standard/handler.ts
15
15
  import { ORPCError, toORPCError } from "@orpc/client";
@@ -19,14 +19,14 @@ var StandardHandler = class {
19
19
  this.matcher = matcher;
20
20
  this.codec = codec;
21
21
  this.options = options;
22
- this.plugin = new CompositePlugin(options?.plugins);
22
+ this.plugin = new CompositePlugin(options.plugins);
23
23
  this.plugin.init(this.options);
24
24
  this.matcher.init(router);
25
25
  }
26
26
  plugin;
27
27
  handle(request, ...[options]) {
28
28
  return intercept(
29
- this.options.interceptorsRoot ?? [],
29
+ this.options.rootInterceptors ?? [],
30
30
  {
31
31
  request,
32
32
  ...options,
@@ -47,12 +47,11 @@ var StandardHandler = class {
47
47
  if (!match) {
48
48
  return { matched: false, response: void 0 };
49
49
  }
50
- const clientOptions = {
50
+ const client = createProcedureClient(match.procedure, {
51
51
  context: interceptorOptions2.context,
52
- path: match.path
53
- };
54
- this.plugin.beforeCreateProcedureClient(clientOptions, interceptorOptions2);
55
- const client = createProcedureClient(match.procedure, clientOptions);
52
+ path: match.path,
53
+ interceptors: this.options.clientInterceptors
54
+ });
56
55
  isDecoding = true;
57
56
  const input = await this.codec.decode(request, match.params, match.procedure);
58
57
  isDecoding = false;
@@ -179,4 +178,4 @@ export {
179
178
  RPCCodec,
180
179
  RPCMatcher
181
180
  };
182
- //# sourceMappingURL=chunk-LXOL226G.js.map
181
+ //# sourceMappingURL=chunk-77FU7QSO.js.map
@@ -8,11 +8,6 @@ var CompositePlugin = class {
8
8
  plugin.init?.(options);
9
9
  }
10
10
  }
11
- beforeCreateProcedureClient(clientOptions, interceptorOptions) {
12
- for (const plugin of this.plugins) {
13
- plugin.beforeCreateProcedureClient?.(clientOptions, interceptorOptions);
14
- }
15
- }
16
11
  };
17
12
 
18
13
  // src/plugins/cors.ts
@@ -30,8 +25,8 @@ var CORSPlugin = class {
30
25
  };
31
26
  }
32
27
  init(options) {
33
- options.interceptorsRoot ??= [];
34
- options.interceptorsRoot.unshift(async (interceptorOptions) => {
28
+ options.rootInterceptors ??= [];
29
+ options.rootInterceptors.unshift(async (interceptorOptions) => {
35
30
  if (interceptorOptions.request.method === "OPTIONS") {
36
31
  const resHeaders = {};
37
32
  if (this.options.maxAge !== void 0) {
@@ -57,7 +52,7 @@ var CORSPlugin = class {
57
52
  }
58
53
  return interceptorOptions.next();
59
54
  });
60
- options.interceptorsRoot.unshift(async (interceptorOptions) => {
55
+ options.rootInterceptors.unshift(async (interceptorOptions) => {
61
56
  const result = await interceptorOptions.next();
62
57
  if (!result.matched) {
63
58
  return result;
@@ -94,8 +89,8 @@ var CORSPlugin = class {
94
89
  // src/plugins/response-headers.ts
95
90
  var ResponseHeadersPlugin = class {
96
91
  init(options) {
97
- options.interceptorsRoot ??= [];
98
- options.interceptorsRoot.push(async (interceptorOptions) => {
92
+ options.rootInterceptors ??= [];
93
+ options.rootInterceptors.push(async (interceptorOptions) => {
99
94
  const headers = new Headers();
100
95
  interceptorOptions.context.resHeaders = headers;
101
96
  const result = await interceptorOptions.next();
@@ -122,4 +117,4 @@ export {
122
117
  CORSPlugin,
123
118
  ResponseHeadersPlugin
124
119
  };
125
- //# sourceMappingURL=chunk-XI6WGCB3.js.map
120
+ //# sourceMappingURL=chunk-WQNNSBXW.js.map
package/dist/fetch.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  RPCHandler
3
- } from "./chunk-KPT6FDBK.js";
4
- import "./chunk-LXOL226G.js";
3
+ } from "./chunk-47YYO5JS.js";
4
+ import "./chunk-77FU7QSO.js";
5
5
  import "./chunk-MHVECKBC.js";
6
- import "./chunk-XI6WGCB3.js";
6
+ import "./chunk-WQNNSBXW.js";
7
7
  export {
8
8
  RPCHandler
9
9
  };
package/dist/hono.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  RPCHandler
3
- } from "./chunk-KPT6FDBK.js";
4
- import "./chunk-LXOL226G.js";
3
+ } from "./chunk-47YYO5JS.js";
4
+ import "./chunk-77FU7QSO.js";
5
5
  import "./chunk-MHVECKBC.js";
6
- import "./chunk-XI6WGCB3.js";
6
+ import "./chunk-WQNNSBXW.js";
7
7
 
8
8
  // src/adapters/hono/middleware.ts
9
9
  import { value } from "@orpc/shared";
package/dist/next.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  RPCHandler
3
- } from "./chunk-KPT6FDBK.js";
4
- import "./chunk-LXOL226G.js";
3
+ } from "./chunk-47YYO5JS.js";
4
+ import "./chunk-77FU7QSO.js";
5
5
  import "./chunk-MHVECKBC.js";
6
- import "./chunk-XI6WGCB3.js";
6
+ import "./chunk-WQNNSBXW.js";
7
7
 
8
8
  // src/adapters/next/serve.ts
9
9
  import { value } from "@orpc/shared";
package/dist/node.js CHANGED
@@ -2,9 +2,9 @@ import {
2
2
  RPCCodec,
3
3
  RPCMatcher,
4
4
  StandardHandler
5
- } from "./chunk-LXOL226G.js";
5
+ } from "./chunk-77FU7QSO.js";
6
6
  import "./chunk-MHVECKBC.js";
7
- import "./chunk-XI6WGCB3.js";
7
+ import "./chunk-WQNNSBXW.js";
8
8
 
9
9
  // src/adapters/node/rpc-handler.ts
10
10
  import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
package/dist/plugins.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  CORSPlugin,
3
3
  CompositePlugin,
4
4
  ResponseHeadersPlugin
5
- } from "./chunk-XI6WGCB3.js";
5
+ } from "./chunk-WQNNSBXW.js";
6
6
  export {
7
7
  CORSPlugin,
8
8
  CompositePlugin,
@@ -1,9 +1,9 @@
1
- import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
1
+ import type { ErrorFromErrorMap, HTTPPath, Meta, Schema, SchemaOutput } from '@orpc/contract';
2
2
  import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
3
  import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
4
4
  import type { Context } from '../../context';
5
5
  import type { Plugin } from '../../plugins';
6
- import type { CreateProcedureClientOptions } from '../../procedure-client';
6
+ import type { ProcedureClientInterceptorOptions } from '../../procedure-client';
7
7
  import type { Router } from '../../router';
8
8
  import type { StandardCodec, StandardMatcher } from './types';
9
9
  export type StandardHandleOptions<T extends Context> = {
@@ -26,9 +26,6 @@ export type StandardHandleResult = {
26
26
  export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
27
27
  request: StandardRequest;
28
28
  };
29
- export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, Record<never, never>> & {
30
- context: TContext;
31
- };
32
29
  export interface StandardHandlerOptions<TContext extends Context> {
33
30
  plugins?: Plugin<TContext>[];
34
31
  /**
@@ -36,9 +33,14 @@ export interface StandardHandlerOptions<TContext extends Context> {
36
33
  */
37
34
  interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
38
35
  /**
39
- * Interceptors at the root level, helpful when you want override the response
36
+ * Interceptors at the root level, helpful when you want override the request/response
37
+ */
38
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
39
+ /**
40
+ *
41
+ * Interceptors for procedure client.
40
42
  */
41
- interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
43
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Schema, Record<never, never>, Meta>, SchemaOutput<Schema, unknown>, ErrorFromErrorMap<Record<never, never>>>[];
42
44
  }
43
45
  export declare class StandardHandler<T extends Context> {
44
46
  private readonly matcher;
@@ -1,13 +1,11 @@
1
- import type { StandardHandlerInterceptorOptions, StandardHandlerOptions, WellCreateProcedureClientOptions } from '../adapters/standard';
1
+ import type { StandardHandlerOptions } from '../adapters/standard';
2
2
  import type { Context } from '../context';
3
3
  export interface Plugin<TContext extends Context> {
4
4
  init?(options: StandardHandlerOptions<TContext>): void;
5
- beforeCreateProcedureClient?(clientOptions: WellCreateProcedureClientOptions<TContext>, interceptorOptions: StandardHandlerInterceptorOptions<TContext>): void;
6
5
  }
7
6
  export declare class CompositePlugin<TContext extends Context> implements Plugin<TContext> {
8
7
  private readonly plugins;
9
8
  constructor(plugins?: Plugin<TContext>[]);
10
9
  init(options: StandardHandlerOptions<TContext>): void;
11
- beforeCreateProcedureClient(clientOptions: WellCreateProcedureClientOptions<TContext>, interceptorOptions: StandardHandlerInterceptorOptions<TContext>): void;
12
10
  }
13
11
  //# sourceMappingURL=base.d.ts.map
package/dist/standard.js CHANGED
@@ -2,9 +2,9 @@ import {
2
2
  RPCCodec,
3
3
  RPCMatcher,
4
4
  StandardHandler
5
- } from "./chunk-LXOL226G.js";
5
+ } from "./chunk-77FU7QSO.js";
6
6
  import "./chunk-MHVECKBC.js";
7
- import "./chunk-XI6WGCB3.js";
7
+ import "./chunk-WQNNSBXW.js";
8
8
  export {
9
9
  RPCCodec,
10
10
  RPCMatcher,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.41.1",
4
+ "version": "0.41.2",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -66,9 +66,9 @@
66
66
  "@orpc/server-standard": "^0.4.0",
67
67
  "@orpc/server-standard-fetch": "^0.4.0",
68
68
  "@orpc/server-standard-node": "^0.4.0",
69
- "@orpc/client": "0.41.1",
70
- "@orpc/shared": "0.41.1",
71
- "@orpc/contract": "0.41.1"
69
+ "@orpc/contract": "0.41.2",
70
+ "@orpc/client": "0.41.2",
71
+ "@orpc/shared": "0.41.2"
72
72
  },
73
73
  "devDependencies": {
74
74
  "light-my-request": "^6.5.1"