@orpc/server 0.0.0-next.9723092 → 0.0.0-next.989a435

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 (35) hide show
  1. package/dist/{chunk-F75AQ6KO.js → chunk-DAUWED3D.js} +11 -5
  2. package/dist/chunk-N2FJGXSJ.js +32 -0
  3. package/dist/{chunk-XFBAK67J.js → chunk-XI6WGCB3.js} +2 -5
  4. package/dist/{chunk-SV6DBVXJ.js → chunk-XP6YRLY2.js} +3 -2
  5. package/dist/fetch.js +6 -14
  6. package/dist/hono.js +7 -15
  7. package/dist/index.js +1 -1
  8. package/dist/next.js +6 -14
  9. package/dist/node.js +7 -151
  10. package/dist/plugins.js +1 -1
  11. package/dist/src/adapters/fetch/index.d.ts +0 -1
  12. package/dist/src/adapters/fetch/rpc-handler.d.ts +3 -2
  13. package/dist/src/adapters/fetch/types.d.ts +3 -2
  14. package/dist/src/adapters/hono/middleware.d.ts +2 -3
  15. package/dist/src/adapters/next/serve.d.ts +2 -3
  16. package/dist/src/adapters/node/index.d.ts +0 -1
  17. package/dist/src/adapters/node/rpc-handler.d.ts +3 -2
  18. package/dist/src/adapters/node/types.d.ts +3 -2
  19. package/dist/src/adapters/standard/handler.d.ts +7 -7
  20. package/dist/src/adapters/standard/rpc-codec.d.ts +2 -1
  21. package/dist/src/adapters/standard/rpc-serializer.d.ts +1 -1
  22. package/dist/src/adapters/standard/types.d.ts +2 -26
  23. package/dist/src/implementer-procedure.d.ts +5 -4
  24. package/dist/src/middleware.d.ts +3 -4
  25. package/dist/src/procedure-client.d.ts +5 -6
  26. package/dist/src/procedure-decorated.d.ts +5 -4
  27. package/dist/src/procedure-utils.d.ts +3 -2
  28. package/dist/src/procedure.d.ts +1 -1
  29. package/dist/src/router-client.d.ts +6 -6
  30. package/dist/src/router.d.ts +1 -0
  31. package/dist/standard.js +3 -3
  32. package/package.json +6 -4
  33. package/dist/chunk-LBBHJSG5.js +0 -136
  34. package/dist/src/adapters/fetch/utils.d.ts +0 -6
  35. package/dist/src/adapters/node/utils.d.ts +0 -5
@@ -6,10 +6,10 @@ import {
6
6
  getRouterChild,
7
7
  isProcedure,
8
8
  unlazy
9
- } from "./chunk-SV6DBVXJ.js";
9
+ } from "./chunk-XP6YRLY2.js";
10
10
  import {
11
11
  CompositePlugin
12
- } from "./chunk-XFBAK67J.js";
12
+ } from "./chunk-XI6WGCB3.js";
13
13
 
14
14
  // src/adapters/standard/handler.ts
15
15
  import { toORPCError } from "@orpc/contract";
@@ -75,9 +75,12 @@ var StandardHandler = class {
75
75
  };
76
76
 
77
77
  // src/adapters/standard/rpc-serializer.ts
78
- import { findDeepMatches, isPlainObject, set } from "@orpc/shared";
78
+ import { findDeepMatches, isObject, set } from "@orpc/shared";
79
79
  var RPCSerializer = class {
80
80
  serialize(data) {
81
+ if (data === void 0) {
82
+ return void 0;
83
+ }
81
84
  if (data instanceof Blob) {
82
85
  return data;
83
86
  }
@@ -95,6 +98,9 @@ var RPCSerializer = class {
95
98
  return form;
96
99
  }
97
100
  deserialize(serialized) {
101
+ if (serialized === void 0) {
102
+ return void 0;
103
+ }
98
104
  if (serialized instanceof Blob) {
99
105
  return serialized;
100
106
  }
@@ -131,7 +137,7 @@ function serializeRPCJson(value, segments = [], meta = []) {
131
137
  meta.push(["url", segments]);
132
138
  return { json: value.toString(), meta };
133
139
  }
134
- if (isPlainObject(value)) {
140
+ if (isObject(value)) {
135
141
  const json = {};
136
142
  for (const k in value) {
137
143
  json[k] = serializeRPCJson(value[k], [...segments, k], meta).json;
@@ -310,4 +316,4 @@ export {
310
316
  RPCCodec,
311
317
  RPCMatcher
312
318
  };
313
- //# sourceMappingURL=chunk-F75AQ6KO.js.map
319
+ //# sourceMappingURL=chunk-DAUWED3D.js.map
@@ -0,0 +1,32 @@
1
+ import {
2
+ RPCCodec,
3
+ RPCMatcher,
4
+ StandardHandler
5
+ } from "./chunk-DAUWED3D.js";
6
+
7
+ // src/adapters/fetch/rpc-handler.ts
8
+ import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
9
+ var RPCHandler = class {
10
+ standardHandler;
11
+ constructor(router, options) {
12
+ const matcher = options?.matcher ?? new RPCMatcher();
13
+ const codec = options?.codec ?? new RPCCodec();
14
+ this.standardHandler = new StandardHandler(router, matcher, codec, options);
15
+ }
16
+ async handle(request, ...rest) {
17
+ const standardRequest = toStandardRequest(request);
18
+ const result = await this.standardHandler.handle(standardRequest, ...rest);
19
+ if (!result.matched) {
20
+ return result;
21
+ }
22
+ return {
23
+ matched: true,
24
+ response: toFetchResponse(result.response)
25
+ };
26
+ }
27
+ };
28
+
29
+ export {
30
+ RPCHandler
31
+ };
32
+ //# sourceMappingURL=chunk-N2FJGXSJ.js.map
@@ -21,12 +21,9 @@ var CORSPlugin = class {
21
21
  options;
22
22
  constructor(options) {
23
23
  const defaults = {
24
- origin: "*",
24
+ origin: (origin) => origin,
25
25
  allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
26
26
  };
27
- if (options?.credentials) {
28
- defaults.origin = (origin) => origin;
29
- }
30
27
  this.options = {
31
28
  ...defaults,
32
29
  ...options
@@ -125,4 +122,4 @@ export {
125
122
  CORSPlugin,
126
123
  ResponseHeadersPlugin
127
124
  };
128
- //# sourceMappingURL=chunk-XFBAK67J.js.map
125
+ //# sourceMappingURL=chunk-XI6WGCB3.js.map
@@ -68,7 +68,8 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
68
68
  return async (...[input, callerOptions]) => {
69
69
  const path = options?.path ?? [];
70
70
  const { default: procedure } = await unlazy(lazyableProcedure);
71
- const context = await value(options?.context ?? {}, callerOptions?.context);
71
+ const clientContext = callerOptions?.context ?? {};
72
+ const context = await value(options?.context ?? {}, clientContext);
72
73
  const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
73
74
  try {
74
75
  return await intercept(
@@ -374,4 +375,4 @@ export {
374
375
  convertPathToHttpPath,
375
376
  createContractedProcedure
376
377
  };
377
- //# sourceMappingURL=chunk-SV6DBVXJ.js.map
378
+ //# sourceMappingURL=chunk-XP6YRLY2.js.map
package/dist/fetch.js CHANGED
@@ -1,18 +1,10 @@
1
1
  import {
2
- RPCHandler,
3
- fetchReToStandardBody,
4
- fetchRequestToStandardRequest,
5
- standardBodyToFetchBody,
6
- standardResponseToFetchResponse
7
- } from "./chunk-LBBHJSG5.js";
8
- import "./chunk-F75AQ6KO.js";
9
- import "./chunk-SV6DBVXJ.js";
10
- import "./chunk-XFBAK67J.js";
2
+ RPCHandler
3
+ } from "./chunk-N2FJGXSJ.js";
4
+ import "./chunk-DAUWED3D.js";
5
+ import "./chunk-XP6YRLY2.js";
6
+ import "./chunk-XI6WGCB3.js";
11
7
  export {
12
- RPCHandler,
13
- fetchReToStandardBody,
14
- fetchRequestToStandardRequest,
15
- standardBodyToFetchBody,
16
- standardResponseToFetchResponse
8
+ RPCHandler
17
9
  };
18
10
  //# sourceMappingURL=fetch.js.map
package/dist/hono.js CHANGED
@@ -1,13 +1,9 @@
1
1
  import {
2
- RPCHandler,
3
- fetchReToStandardBody,
4
- fetchRequestToStandardRequest,
5
- standardBodyToFetchBody,
6
- standardResponseToFetchResponse
7
- } from "./chunk-LBBHJSG5.js";
8
- import "./chunk-F75AQ6KO.js";
9
- import "./chunk-SV6DBVXJ.js";
10
- import "./chunk-XFBAK67J.js";
2
+ RPCHandler
3
+ } from "./chunk-N2FJGXSJ.js";
4
+ import "./chunk-DAUWED3D.js";
5
+ import "./chunk-XP6YRLY2.js";
6
+ import "./chunk-XI6WGCB3.js";
11
7
 
12
8
  // src/adapters/hono/middleware.ts
13
9
  import { value } from "@orpc/shared";
@@ -26,17 +22,13 @@ function createMiddleware(handler, ...[options]) {
26
22
  const context = await value(options?.context ?? {}, c);
27
23
  const { matched, response } = await handler.handle(request, { ...options, context });
28
24
  if (matched) {
29
- return c.body(response.body, response);
25
+ return c.newResponse(response.body, response);
30
26
  }
31
27
  await next();
32
28
  };
33
29
  }
34
30
  export {
35
31
  RPCHandler,
36
- createMiddleware,
37
- fetchReToStandardBody,
38
- fetchRequestToStandardRequest,
39
- standardBodyToFetchBody,
40
- standardResponseToFetchResponse
32
+ createMiddleware
41
33
  };
42
34
  //# sourceMappingURL=hono.js.map
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  middlewareOutputFn,
22
22
  setRouterContract,
23
23
  unlazy
24
- } from "./chunk-SV6DBVXJ.js";
24
+ } from "./chunk-XP6YRLY2.js";
25
25
 
26
26
  // src/builder.ts
27
27
  import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
package/dist/next.js CHANGED
@@ -1,13 +1,9 @@
1
1
  import {
2
- RPCHandler,
3
- fetchReToStandardBody,
4
- fetchRequestToStandardRequest,
5
- standardBodyToFetchBody,
6
- standardResponseToFetchResponse
7
- } from "./chunk-LBBHJSG5.js";
8
- import "./chunk-F75AQ6KO.js";
9
- import "./chunk-SV6DBVXJ.js";
10
- import "./chunk-XFBAK67J.js";
2
+ RPCHandler
3
+ } from "./chunk-N2FJGXSJ.js";
4
+ import "./chunk-DAUWED3D.js";
5
+ import "./chunk-XP6YRLY2.js";
6
+ import "./chunk-XI6WGCB3.js";
11
7
 
12
8
  // src/adapters/next/serve.ts
13
9
  import { value } from "@orpc/shared";
@@ -30,10 +26,6 @@ function serve(handler, ...[options]) {
30
26
  }
31
27
  export {
32
28
  RPCHandler,
33
- fetchReToStandardBody,
34
- fetchRequestToStandardRequest,
35
- serve,
36
- standardBodyToFetchBody,
37
- standardResponseToFetchResponse
29
+ serve
38
30
  };
39
31
  //# sourceMappingURL=next.js.map
package/dist/node.js CHANGED
@@ -2,154 +2,12 @@ import {
2
2
  RPCCodec,
3
3
  RPCMatcher,
4
4
  StandardHandler
5
- } from "./chunk-F75AQ6KO.js";
6
- import "./chunk-SV6DBVXJ.js";
7
- import "./chunk-XFBAK67J.js";
8
-
9
- // src/adapters/node/utils.ts
10
- import { Buffer, File } from "node:buffer";
11
- import { Readable } from "node:stream";
12
- import { once } from "@orpc/shared";
13
- import cd from "content-disposition";
14
- function nodeHttpToStandardRequest(req, res) {
15
- const method = req.method ?? "GET";
16
- const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
17
- const host = req.headers.host ?? "localhost";
18
- const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
19
- return {
20
- raw: { request: req, response: res },
21
- method,
22
- url,
23
- headers: req.headers,
24
- body: once(() => {
25
- return nodeHttpRequestToStandardBody(req);
26
- }),
27
- get signal() {
28
- const signal = nodeHttpResponseToAbortSignal(res);
29
- Object.defineProperty(this, "signal", { value: signal, writable: true });
30
- return signal;
31
- },
32
- set signal(value) {
33
- Object.defineProperty(this, "signal", { value, writable: true });
34
- }
35
- };
36
- }
37
- function nodeHttpResponseSendStandardResponse(res, standardResponse) {
38
- return new Promise((resolve, reject) => {
39
- res.on("error", reject);
40
- res.on("finish", resolve);
41
- if (standardResponse.body === void 0) {
42
- res.writeHead(standardResponse.status, standardResponse.headers);
43
- res.end();
44
- return;
45
- }
46
- if (standardResponse.body instanceof Blob) {
47
- const resHeaders = {
48
- ...standardResponse.headers,
49
- "content-type": standardResponse.body.type,
50
- "content-length": standardResponse.body.size.toString()
51
- };
52
- if (!standardResponse.headers["content-disposition"] && standardResponse.body instanceof Blob) {
53
- resHeaders["content-disposition"] = cd(standardResponse.body instanceof File ? standardResponse.body.name : "blob");
54
- }
55
- res.writeHead(standardResponse.status, resHeaders);
56
- Readable.fromWeb(
57
- standardResponse.body.stream()
58
- // Conflict between types=node and lib=dom so we need to cast it
59
- ).pipe(res);
60
- return;
61
- }
62
- if (standardResponse.body instanceof FormData) {
63
- const response = new Response(standardResponse.body);
64
- res.writeHead(standardResponse.status, {
65
- ...standardResponse.headers,
66
- "content-type": response.headers.get("content-type")
67
- });
68
- Readable.fromWeb(
69
- response.body
70
- // Conflict between types=node and lib=dom so we need to cast it
71
- ).pipe(res);
72
- return;
73
- }
74
- if (standardResponse.body instanceof URLSearchParams) {
75
- res.writeHead(standardResponse.status, {
76
- ...standardResponse.headers,
77
- "content-type": "application/x-www-form-urlencoded"
78
- });
79
- const string2 = standardResponse.body.toString();
80
- res.end(string2);
81
- return;
82
- }
83
- res.writeHead(standardResponse.status, {
84
- ...standardResponse.headers,
85
- "content-type": "application/json"
86
- });
87
- const string = JSON.stringify(standardResponse.body);
88
- res.end(string);
89
- });
90
- }
91
- async function nodeHttpRequestToStandardBody(req) {
92
- const method = req.method ?? "GET";
93
- if (method === "GET" || method === "HEAD") {
94
- return void 0;
95
- }
96
- const contentDisposition = req.headers["content-disposition"];
97
- const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
98
- const contentType = req.headers["content-type"];
99
- if (fileName) {
100
- return await streamToFile(req, fileName, contentType || "application/octet-stream");
101
- }
102
- if (!contentType || contentType.startsWith("application/json")) {
103
- const text = await streamToString(req);
104
- if (!text) {
105
- return void 0;
106
- }
107
- return JSON.parse(text);
108
- }
109
- if (contentType.startsWith("multipart/form-data")) {
110
- return await streamToFormData(req, contentType);
111
- }
112
- if (contentType.startsWith("application/x-www-form-urlencoded")) {
113
- const text = await streamToString(req);
114
- return new URLSearchParams(text);
115
- }
116
- if (contentType.startsWith("text/")) {
117
- return await streamToString(req);
118
- }
119
- return streamToFile(req, "blob", contentType);
120
- }
121
- function streamToFormData(stream, contentType) {
122
- const response = new Response(stream, {
123
- // Conflict between types=node and lib=dom so we need to cast it
124
- headers: {
125
- "content-type": contentType
126
- }
127
- });
128
- return response.formData();
129
- }
130
- async function streamToString(stream) {
131
- let string = "";
132
- for await (const chunk of stream) {
133
- string += chunk.toString();
134
- }
135
- return string;
136
- }
137
- async function streamToFile(stream, fileName, contentType) {
138
- const chunks = [];
139
- for await (const chunk of stream) {
140
- chunks.push(chunk);
141
- }
142
- return new File([Buffer.concat(chunks)], fileName, { type: contentType });
143
- }
144
- function nodeHttpResponseToAbortSignal(res) {
145
- const controller = new AbortController();
146
- res.on("close", () => {
147
- controller.abort();
148
- });
149
- return controller.signal;
150
- }
5
+ } from "./chunk-DAUWED3D.js";
6
+ import "./chunk-XP6YRLY2.js";
7
+ import "./chunk-XI6WGCB3.js";
151
8
 
152
9
  // src/adapters/node/rpc-handler.ts
10
+ import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
153
11
  var RPCHandler = class {
154
12
  standardHandler;
155
13
  constructor(router, options) {
@@ -158,18 +16,16 @@ var RPCHandler = class {
158
16
  this.standardHandler = new StandardHandler(router, matcher, codec, options);
159
17
  }
160
18
  async handle(req, res, ...rest) {
161
- const standardRequest = nodeHttpToStandardRequest(req, res);
19
+ const standardRequest = toStandardRequest(req, res);
162
20
  const result = await this.standardHandler.handle(standardRequest, ...rest);
163
21
  if (!result.matched) {
164
22
  return { matched: false };
165
23
  }
166
- await nodeHttpResponseSendStandardResponse(res, result.response);
24
+ await sendStandardResponse(res, result.response);
167
25
  return { matched: true };
168
26
  }
169
27
  };
170
28
  export {
171
- RPCHandler,
172
- nodeHttpResponseSendStandardResponse,
173
- nodeHttpToStandardRequest
29
+ RPCHandler
174
30
  };
175
31
  //# sourceMappingURL=node.js.map
package/dist/plugins.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  CORSPlugin,
3
3
  CompositePlugin,
4
4
  ResponseHeadersPlugin
5
- } from "./chunk-XFBAK67J.js";
5
+ } from "./chunk-XI6WGCB3.js";
6
6
  export {
7
7
  CORSPlugin,
8
8
  CompositePlugin,
@@ -1,4 +1,3 @@
1
1
  export * from './rpc-handler';
2
2
  export * from './types';
3
- export * from './utils';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,10 +1,11 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
1
2
  import type { Context } from '../../context';
2
3
  import type { Router } from '../../router';
3
- import type { RPCHandlerOptions, StandardHandleRest } from '../standard';
4
+ import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
4
5
  import type { FetchHandler, FetchHandleResult } from './types';
5
6
  export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
6
7
  private readonly standardHandler;
7
8
  constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
8
- handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
9
+ handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
9
10
  }
10
11
  //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,5 +1,6 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
1
2
  import type { Context } from '../../context';
2
- import type { StandardHandleRest } from '../standard';
3
+ import type { StandardHandleOptions } from '../standard';
3
4
  export type FetchHandleResult = {
4
5
  matched: true;
5
6
  response: Response;
@@ -8,6 +9,6 @@ export type FetchHandleResult = {
8
9
  response: undefined;
9
10
  };
10
11
  export interface FetchHandler<T extends Context> {
11
- handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
12
+ handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
12
13
  }
13
14
  //# sourceMappingURL=types.d.ts.map
@@ -1,13 +1,12 @@
1
+ import type { MaybeOptionalOptions, Value } from '@orpc/shared';
1
2
  import type { Context as HonoContext, MiddlewareHandler } from 'hono';
2
3
  import type { Context } from '../../context';
3
4
  import type { FetchHandler } from '../fetch';
4
5
  import type { StandardHandleOptions } from '../standard';
5
- import { type Value } from '@orpc/shared';
6
6
  export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
7
7
  context?: Value<T, [HonoContext]>;
8
8
  } : {
9
9
  context: Value<T, [HonoContext]>;
10
10
  });
11
- export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
12
- export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
11
+ export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
13
12
  //# sourceMappingURL=middleware.d.ts.map
@@ -1,14 +1,13 @@
1
+ import type { MaybeOptionalOptions, Value } from '@orpc/shared';
1
2
  import type { NextRequest } from 'next/server';
2
3
  import type { Context } from '../../context';
3
4
  import type { FetchHandler } from '../fetch';
4
5
  import type { StandardHandleOptions } from '../standard';
5
- import { type Value } from '@orpc/shared';
6
6
  export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
7
7
  context?: Value<T, [NextRequest]>;
8
8
  } : {
9
9
  context: Value<T, [NextRequest]>;
10
10
  });
11
- export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
12
11
  export interface ServeResult {
13
12
  GET(req: NextRequest): Promise<Response>;
14
13
  POST(req: NextRequest): Promise<Response>;
@@ -16,5 +15,5 @@ export interface ServeResult {
16
15
  PATCH(req: NextRequest): Promise<Response>;
17
16
  DELETE(req: NextRequest): Promise<Response>;
18
17
  }
19
- export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
18
+ export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
20
19
  //# sourceMappingURL=serve.d.ts.map
@@ -1,4 +1,3 @@
1
1
  export * from './rpc-handler';
2
2
  export * from './types';
3
- export * from './utils';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,10 +1,11 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
1
2
  import type { Context } from '../../context';
2
3
  import type { Router } from '../../router';
3
- import type { RPCHandlerOptions, StandardHandleRest } from '../standard';
4
+ import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
4
5
  import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
5
6
  export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
6
7
  private readonly standardHandler;
7
8
  constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
8
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
9
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
9
10
  }
10
11
  //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,7 +1,8 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
1
2
  import type { IncomingMessage, ServerResponse } from 'node:http';
2
3
  import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
3
4
  import type { Context } from '../../context';
4
- import type { StandardHandleRest } from '../standard';
5
+ import type { StandardHandleOptions } from '../standard';
5
6
  export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
6
7
  /**
7
8
  * Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
@@ -16,6 +17,6 @@ export type NodeHttpHandleResult = {
16
17
  matched: false;
17
18
  };
18
19
  export interface NodeHttpHandler<T extends Context> {
19
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
20
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
20
21
  }
21
22
  //# sourceMappingURL=types.d.ts.map
@@ -1,10 +1,11 @@
1
1
  import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
2
- import type { Interceptor } from '@orpc/shared';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
+ import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
4
  import type { Context } from '../../context';
4
5
  import type { Plugin } from '../../plugins';
5
6
  import type { CreateProcedureClientOptions } from '../../procedure-client';
6
7
  import type { Router } from '../../router';
7
- import type { StandardCodec, StandardMatcher, StandardRequest, StandardResponse } from './types';
8
+ import type { StandardCodec, StandardMatcher } from './types';
8
9
  export type StandardHandleOptions<T extends Context> = {
9
10
  prefix?: HTTPPath;
10
11
  } & (Record<never, never> extends T ? {
@@ -15,7 +16,6 @@ export type StandardHandleOptions<T extends Context> = {
15
16
  export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
16
17
  context: T;
17
18
  };
18
- export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
19
19
  export type StandardHandleResult = {
20
20
  matched: true;
21
21
  response: StandardResponse;
@@ -26,7 +26,7 @@ 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, unknown> & {
29
+ export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, Record<never, never>> & {
30
30
  context: TContext;
31
31
  };
32
32
  export interface StandardHandlerOptions<TContext extends Context> {
@@ -40,12 +40,12 @@ export interface StandardHandlerOptions<TContext extends Context> {
40
40
  */
41
41
  interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
42
42
  }
43
- export declare class StandardHandler<TContext extends Context> {
43
+ export declare class StandardHandler<T extends Context> {
44
44
  private readonly matcher;
45
45
  private readonly codec;
46
46
  private readonly options;
47
47
  private readonly plugin;
48
- constructor(router: Router<TContext, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<TContext>>);
49
- handle(request: StandardRequest, ...[options]: StandardHandleRest<TContext>): Promise<StandardHandleResult>;
48
+ constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
49
+ handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
50
50
  }
51
51
  //# sourceMappingURL=handler.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import type { ORPCError } from '@orpc/contract';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
2
3
  import type { AnyProcedure } from '../../procedure';
3
- import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from './types';
4
+ import type { StandardCodec, StandardParams } from './types';
4
5
  import { RPCSerializer } from './rpc-serializer';
5
6
  export interface StandardCodecOptions {
6
7
  serializer?: RPCSerializer;
@@ -3,7 +3,7 @@ export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | '
3
3
  export type RPCSerialized = {
4
4
  json: unknown;
5
5
  meta: RPCSerializedJsonMeta;
6
- } | FormData | Blob;
6
+ } | FormData | Blob | undefined;
7
7
  export type RPCSerializedFormDataMaps = Segment[][];
8
8
  export declare class RPCSerializer {
9
9
  serialize(data: unknown): RPCSerialized;
@@ -1,31 +1,7 @@
1
- import type { AbortSignal, HTTPPath, ORPCError } from '@orpc/contract';
2
- import type { JsonValue } from '@orpc/shared';
1
+ import type { HTTPPath, ORPCError } from '@orpc/contract';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
3
  import type { AnyProcedure } from '../../procedure';
4
4
  import type { AnyRouter } from '../../router';
5
- export interface StandardHeaders {
6
- [key: string]: string | string[] | undefined;
7
- }
8
- export type StandardBody = undefined | JsonValue | Blob | URLSearchParams | FormData;
9
- export interface StandardRequest {
10
- /**
11
- * Can be { request: Request } or { request: IncomingMessage, response: ServerResponse } based on the adapter.
12
- */
13
- raw: Record<string, unknown>;
14
- method: string;
15
- url: URL;
16
- headers: StandardHeaders;
17
- /**
18
- * The body has been parsed base on the content-type header.
19
- * This method can safely call multiple times (cached).
20
- */
21
- body(): Promise<StandardBody>;
22
- signal?: AbortSignal;
23
- }
24
- export interface StandardResponse {
25
- status: number;
26
- headers: StandardHeaders;
27
- body: StandardBody;
28
- }
29
5
  export type StandardParams = Record<string, string>;
30
6
  export type StandardMatchResult = {
31
7
  path: string[];
@@ -1,9 +1,10 @@
1
- import type { ClientRest, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ClientContext, ClientRest, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
3
  import type { BuilderDef } from './builder';
3
4
  import type { ConflictContextGuard, Context, MergedContext } from './context';
4
5
  import type { MapInputMiddleware, Middleware } from './middleware';
5
6
  import type { Procedure, ProcedureHandler } from './procedure';
6
- import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
7
+ import type { CreateProcedureClientOptions, ProcedureClient } from './procedure-client';
7
8
  import type { DecoratedProcedure } from './procedure-decorated';
8
9
  /**
9
10
  * Like `DecoratedProcedure`, but removed all method that can change the contract.
@@ -13,11 +14,11 @@ export interface ImplementedProcedure<TInitialContext extends Context, TCurrentC
13
14
  /**
14
15
  * Make this procedure callable (works like a function while still being a procedure).
15
16
  */
16
- callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
17
+ callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
17
18
  /**
18
19
  * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
19
20
  */
20
- actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
21
+ actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
21
22
  }
22
23
  /**
23
24
  * Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
@@ -1,5 +1,5 @@
1
- import type { AbortSignal, ErrorMap, Meta, ORPCErrorConstructorMap, Schema } from '@orpc/contract';
2
- import type { Promisable } from '@orpc/shared';
1
+ import type { ErrorMap, Meta, ORPCErrorConstructorMap, Schema } from '@orpc/contract';
2
+ import type { MaybeOptionalOptions, Promisable } from '@orpc/shared';
3
3
  import type { Context } from './context';
4
4
  import type { Procedure } from './procedure';
5
5
  export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
@@ -11,9 +11,8 @@ export type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never,
11
11
  } : {
12
12
  context: TOutContext;
13
13
  };
14
- export type MiddlewareNextFnRest<TOutContext extends Context> = [options: MiddlewareNextFnOptions<TOutContext>] | (Record<never, never> extends TOutContext ? [] : never);
15
14
  export interface MiddlewareNextFn<TInContext extends Context, TOutput> {
16
- <U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MiddlewareNextFnRest<U>): MiddlewareResult<U, TOutput>;
15
+ <U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
17
16
  }
18
17
  export interface MiddlewareOutputFn<TOutput> {
19
18
  (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
@@ -1,9 +1,9 @@
1
- import type { Client, ErrorFromErrorMap, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { Interceptor, Value } from '@orpc/shared';
1
+ import type { Client, ClientContext, ErrorFromErrorMap, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { Interceptor, MaybeOptionalOptions, Value } from '@orpc/shared';
3
3
  import type { Context } from './context';
4
4
  import type { Lazyable } from './lazy';
5
5
  import type { Procedure } from './procedure';
6
- export type ProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
6
+ export type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
7
7
  export interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
8
8
  context: TInitialContext;
9
9
  input: SchemaInput<TInputSchema>;
@@ -15,7 +15,7 @@ export interface ProcedureClientInterceptorOptions<TInitialContext extends Conte
15
15
  /**
16
16
  * Options for creating a procedure caller with comprehensive type safety
17
17
  */
18
- export type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext> = {
18
+ export type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
19
19
  /**
20
20
  * This is helpful for logging and analytics.
21
21
  */
@@ -26,6 +26,5 @@ export type CreateProcedureClientOptions<TInitialContext extends Context, TInput
26
26
  } : {
27
27
  context: Value<TInitialContext, [clientContext: TClientContext]>;
28
28
  });
29
- export type CreateProcedureClientRest<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext> = [options: CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>] | (Record<never, never> extends TInitialContext ? [] : never);
30
- export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
29
+ export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
31
30
  //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,7 +1,8 @@
1
- import type { ClientRest, ErrorMap, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ClientContext, ClientRest, ErrorMap, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
3
  import type { ConflictContextGuard, Context, MergedContext } from './context';
3
4
  import type { MapInputMiddleware, Middleware } from './middleware';
4
- import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
5
+ import type { CreateProcedureClientOptions, ProcedureClient } from './procedure-client';
5
6
  import { Procedure } from './procedure';
6
7
  export declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> {
7
8
  errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, MergedErrorMap<TErrorMap, U>, TMeta>;
@@ -12,10 +13,10 @@ export declare class DecoratedProcedure<TInitialContext extends Context, TCurren
12
13
  /**
13
14
  * Make this procedure callable (works like a function while still being a procedure).
14
15
  */
15
- callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
16
+ callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
16
17
  /**
17
18
  * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
18
19
  */
19
- actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
20
+ actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
20
21
  }
21
22
  //# sourceMappingURL=procedure-decorated.d.ts.map
@@ -1,8 +1,9 @@
1
1
  import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Meta, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
3
  import type { Context } from './context';
3
4
  import type { Lazyable } from './lazy';
4
5
  import type { Procedure } from './procedure';
5
- import { type CreateProcedureClientRest } from './procedure-client';
6
+ import type { CreateProcedureClientOptions } from './procedure-client';
6
7
  /**
7
8
  * Directly call a procedure without creating a client.
8
9
  *
@@ -13,5 +14,5 @@ import { type CreateProcedureClientRest } from './procedure-client';
13
14
  * ```
14
15
  *
15
16
  */
16
- export declare function call<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
17
+ export declare function call<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, input: SchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, Record<never, never>>>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
17
18
  //# sourceMappingURL=procedure-utils.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { AbortSignal, ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { Promisable } from '@orpc/shared';
3
3
  import type { Context, TypeInitialContext } from './context';
4
4
  import type { AnyMiddleware } from './middleware';
@@ -1,11 +1,11 @@
1
- import type { ErrorMap, Meta } from '@orpc/contract';
1
+ import type { ClientContext, ErrorMap, Meta } from '@orpc/contract';
2
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
3
  import type { Lazy } from './lazy';
3
4
  import type { Procedure } from './procedure';
4
- import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
5
- import type { AnyRouter, Router } from './router';
6
- export type RouterClient<TRouter extends AnyRouter, TClientContext> = TRouter extends Lazy<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
5
+ import type { CreateProcedureClientOptions, ProcedureClient } from './procedure-client';
6
+ import type { AnyRouter, InferRouterInitialContext } from './router';
7
+ export type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext> = TRouter extends Lazy<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
7
8
  [K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
8
9
  };
9
- export type CreateRouterClientRest<TRouter extends AnyRouter, TClientContext> = CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, undefined, unknown, ErrorMap, Meta, TClientContext>;
10
- export declare function createRouterClient<TRouter extends AnyRouter, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateRouterClientRest<TRouter, TClientContext>): RouterClient<TRouter, TClientContext>;
10
+ export declare function createRouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext>(router: TRouter | Lazy<undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<TRouter>, undefined, undefined, unknown, ErrorMap, Meta, TClientContext>>): RouterClient<TRouter, TClientContext>;
11
11
  //# sourceMappingURL=router-client.d.ts.map
@@ -9,6 +9,7 @@ export type Router<TInitialContext extends Context, TContract extends AnyContrac
9
9
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
10
10
  }>;
11
11
  export type AnyRouter = Router<any, any>;
12
+ export type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext, any> ? UInitialContext : never;
12
13
  export type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
13
14
  [K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
14
15
  };
package/dist/standard.js CHANGED
@@ -4,9 +4,9 @@ import {
4
4
  RPCSerializer,
5
5
  StandardHandler,
6
6
  serializeRPCJson
7
- } from "./chunk-F75AQ6KO.js";
8
- import "./chunk-SV6DBVXJ.js";
9
- import "./chunk-XFBAK67J.js";
7
+ } from "./chunk-DAUWED3D.js";
8
+ import "./chunk-XP6YRLY2.js";
9
+ import "./chunk-XI6WGCB3.js";
10
10
  export {
11
11
  RPCCodec,
12
12
  RPCMatcher,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.9723092",
4
+ "version": "0.0.0-next.989a435",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -63,9 +63,11 @@
63
63
  "next": ">=14.0.0"
64
64
  },
65
65
  "dependencies": {
66
- "content-disposition": "^0.5.4",
67
- "@orpc/contract": "0.0.0-next.9723092",
68
- "@orpc/shared": "0.0.0-next.9723092"
66
+ "@orpc/server-standard": "^0.0.0",
67
+ "@orpc/server-standard-fetch": "^0.0.0",
68
+ "@orpc/server-standard-node": "^0.0.0",
69
+ "@orpc/contract": "0.0.0-next.989a435",
70
+ "@orpc/shared": "0.0.0-next.989a435"
69
71
  },
70
72
  "devDependencies": {
71
73
  "light-my-request": "^6.5.1"
@@ -1,136 +0,0 @@
1
- import {
2
- RPCCodec,
3
- RPCMatcher,
4
- StandardHandler
5
- } from "./chunk-F75AQ6KO.js";
6
-
7
- // src/adapters/fetch/utils.ts
8
- import { once } from "@orpc/shared";
9
- import cd from "content-disposition";
10
- function fetchHeadersToStandardHeaders(headers) {
11
- const standardHeaders = {};
12
- for (const [key, value] of headers) {
13
- if (Array.isArray(standardHeaders[key])) {
14
- standardHeaders[key].push(value);
15
- } else if (standardHeaders[key] !== void 0) {
16
- standardHeaders[key] = [standardHeaders[key], value];
17
- } else {
18
- standardHeaders[key] = value;
19
- }
20
- }
21
- return standardHeaders;
22
- }
23
- async function fetchReToStandardBody(re) {
24
- if (!re.body) {
25
- return void 0;
26
- }
27
- const contentDisposition = re.headers.get("content-disposition");
28
- const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
29
- if (fileName) {
30
- const blob2 = await re.blob();
31
- return new File([blob2], fileName, {
32
- type: blob2.type
33
- });
34
- }
35
- const contentType = re.headers.get("content-type");
36
- if (!contentType || contentType.startsWith("application/json")) {
37
- const text = await re.text();
38
- if (!text) {
39
- return void 0;
40
- }
41
- return JSON.parse(text);
42
- }
43
- if (contentType.startsWith("multipart/form-data")) {
44
- return await re.formData();
45
- }
46
- if (contentType.startsWith("application/x-www-form-urlencoded")) {
47
- return new URLSearchParams(await re.text());
48
- }
49
- if (contentType.startsWith("text/")) {
50
- return await re.text();
51
- }
52
- const blob = await re.blob();
53
- return new File([blob], "blob", {
54
- type: blob.type
55
- });
56
- }
57
- function fetchRequestToStandardRequest(request) {
58
- const url = new URL(request.url);
59
- return {
60
- raw: { request },
61
- url,
62
- signal: request.signal,
63
- method: request.method,
64
- body: once(() => {
65
- return fetchReToStandardBody(request);
66
- }),
67
- get headers() {
68
- const headers = fetchHeadersToStandardHeaders(request.headers);
69
- Object.defineProperty(this, "headers", { value: headers, writable: true });
70
- return headers;
71
- },
72
- set headers(value) {
73
- Object.defineProperty(this, "headers", { value, writable: true });
74
- }
75
- };
76
- }
77
- function standardResponseToFetchHeaders(response) {
78
- const fetchHeaders = new Headers();
79
- for (const [key, value] of Object.entries(response.headers)) {
80
- if (Array.isArray(value)) {
81
- for (const v of value) {
82
- fetchHeaders.append(key, v);
83
- }
84
- } else if (value !== void 0) {
85
- fetchHeaders.append(key, value);
86
- }
87
- }
88
- if (response.body instanceof Blob && !fetchHeaders.has("content-disposition")) {
89
- fetchHeaders.set("content-disposition", cd(response.body instanceof File ? response.body.name : "blob"));
90
- } else if (!(response.body instanceof Blob) && !(response.body instanceof URLSearchParams) && !(response.body instanceof FormData) && response.body !== void 0 && !fetchHeaders.has("content-type")) {
91
- fetchHeaders.set("content-type", "application/json");
92
- }
93
- return fetchHeaders;
94
- }
95
- function standardBodyToFetchBody(body) {
96
- if (body instanceof Blob || body instanceof FormData || body instanceof URLSearchParams) {
97
- return body;
98
- }
99
- return JSON.stringify(body);
100
- }
101
- function standardResponseToFetchResponse(response) {
102
- return new Response(standardBodyToFetchBody(response.body), {
103
- headers: standardResponseToFetchHeaders(response),
104
- status: response.status
105
- });
106
- }
107
-
108
- // src/adapters/fetch/rpc-handler.ts
109
- var RPCHandler = class {
110
- standardHandler;
111
- constructor(router, options) {
112
- const matcher = options?.matcher ?? new RPCMatcher();
113
- const codec = options?.codec ?? new RPCCodec();
114
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
115
- }
116
- async handle(request, ...rest) {
117
- const standardRequest = fetchRequestToStandardRequest(request);
118
- const result = await this.standardHandler.handle(standardRequest, ...rest);
119
- if (!result.matched) {
120
- return result;
121
- }
122
- return {
123
- matched: true,
124
- response: standardResponseToFetchResponse(result.response)
125
- };
126
- }
127
- };
128
-
129
- export {
130
- fetchReToStandardBody,
131
- fetchRequestToStandardRequest,
132
- standardBodyToFetchBody,
133
- standardResponseToFetchResponse,
134
- RPCHandler
135
- };
136
- //# sourceMappingURL=chunk-LBBHJSG5.js.map
@@ -1,6 +0,0 @@
1
- import type { StandardBody, StandardRequest, StandardResponse } from '../standard';
2
- export declare function fetchReToStandardBody(re: Request | Response): Promise<StandardBody>;
3
- export declare function fetchRequestToStandardRequest(request: Request): StandardRequest;
4
- export declare function standardBodyToFetchBody(body: StandardBody): Blob | FormData | URLSearchParams | string | undefined;
5
- export declare function standardResponseToFetchResponse(response: StandardResponse): Response;
6
- //# sourceMappingURL=utils.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { StandardRequest, StandardResponse } from '../standard';
2
- import type { NodeHttpRequest, NodeHttpResponse } from './types';
3
- export declare function nodeHttpToStandardRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardRequest;
4
- export declare function nodeHttpResponseSendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse): Promise<void>;
5
- //# sourceMappingURL=utils.d.ts.map