@orpc/server 0.0.0-next.32cb70c → 0.0.0-next.3826d73

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 (52) hide show
  1. package/dist/chunk-L4ESXQX7.js +32 -0
  2. package/dist/chunk-NXEANHUK.js +351 -0
  3. package/dist/chunk-XI6WGCB3.js +125 -0
  4. package/dist/{chunk-KK4SDLC7.js → chunk-XXBE6CYD.js} +86 -27
  5. package/dist/fetch.js +6 -11
  6. package/dist/hono.js +17 -13
  7. package/dist/index.js +29 -7
  8. package/dist/next.js +5 -10
  9. package/dist/node.js +18 -74
  10. package/dist/plugins.js +11 -0
  11. package/dist/src/adapters/fetch/index.d.ts +1 -4
  12. package/dist/src/adapters/fetch/rpc-handler.d.ts +11 -0
  13. package/dist/src/adapters/fetch/types.d.ts +3 -10
  14. package/dist/src/adapters/hono/middleware.d.ts +5 -5
  15. package/dist/src/adapters/next/serve.d.ts +5 -5
  16. package/dist/src/adapters/node/index.d.ts +1 -3
  17. package/dist/src/adapters/node/rpc-handler.d.ts +11 -0
  18. package/dist/src/adapters/node/types.d.ts +14 -14
  19. package/dist/src/adapters/standard/handler.d.ts +51 -0
  20. package/dist/src/adapters/standard/index.d.ts +7 -0
  21. package/dist/src/adapters/standard/rpc-codec.d.ts +16 -0
  22. package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
  23. package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
  24. package/dist/src/adapters/standard/rpc-serializer.d.ts +22 -0
  25. package/dist/src/adapters/standard/types.d.ts +20 -0
  26. package/dist/src/context.d.ts +0 -1
  27. package/dist/src/implementer-procedure.d.ts +5 -4
  28. package/dist/src/implementer-variants.d.ts +6 -5
  29. package/dist/src/implementer.d.ts +7 -6
  30. package/dist/src/index.d.ts +4 -1
  31. package/dist/src/middleware.d.ts +4 -4
  32. package/dist/src/plugins/base.d.ts +13 -0
  33. package/dist/src/plugins/cors.d.ts +19 -0
  34. package/dist/src/plugins/index.d.ts +4 -0
  35. package/dist/src/plugins/response-headers.d.ts +10 -0
  36. package/dist/src/procedure-client.d.ts +19 -8
  37. package/dist/src/procedure-decorated.d.ts +5 -4
  38. package/dist/src/procedure-utils.d.ts +4 -3
  39. package/dist/src/procedure.d.ts +4 -3
  40. package/dist/src/router-client.d.ts +6 -17
  41. package/dist/src/router.d.ts +1 -0
  42. package/dist/src/utils.d.ts +24 -0
  43. package/dist/standard.js +17 -0
  44. package/package.json +19 -3
  45. package/dist/chunk-ESTRJAOX.js +0 -299
  46. package/dist/chunk-WUOGVGWG.js +0 -1
  47. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  48. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  49. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  50. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  51. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  52. package/dist/src/adapters/node/request-listener.d.ts +0 -28
package/dist/hono.js CHANGED
@@ -1,30 +1,34 @@
1
- import "./chunk-WUOGVGWG.js";
2
1
  import {
3
- ORPCPayloadCodec,
4
- ORPCProcedureMatcher,
5
- RPCHandler,
6
- super_json_exports
7
- } from "./chunk-ESTRJAOX.js";
8
- import "./chunk-KK4SDLC7.js";
2
+ RPCHandler
3
+ } from "./chunk-L4ESXQX7.js";
4
+ import "./chunk-NXEANHUK.js";
5
+ import "./chunk-XXBE6CYD.js";
6
+ import "./chunk-XI6WGCB3.js";
9
7
 
10
8
  // src/adapters/hono/middleware.ts
11
9
  import { value } from "@orpc/shared";
12
10
  function createMiddleware(handler, ...[options]) {
13
11
  return async (c, next) => {
12
+ const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
13
+ const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
14
+ // https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
15
+ get(target, prop) {
16
+ if (bodyProps.has(prop)) {
17
+ return () => c.req[prop]();
18
+ }
19
+ return Reflect.get(target, prop, target);
20
+ }
21
+ });
14
22
  const context = await value(options?.context ?? {}, c);
15
- const { matched, response } = await handler.handle(c.req.raw, { ...options, context });
23
+ const { matched, response } = await handler.handle(request, { ...options, context });
16
24
  if (matched) {
17
- c.res = response;
18
- return;
25
+ return c.newResponse(response.body, response);
19
26
  }
20
27
  await next();
21
28
  };
22
29
  }
23
30
  export {
24
- ORPCPayloadCodec,
25
- ORPCProcedureMatcher,
26
31
  RPCHandler,
27
- super_json_exports as SuperJSON,
28
32
  createMiddleware
29
33
  };
30
34
  //# sourceMappingURL=hono.js.map
package/dist/index.js CHANGED
@@ -3,10 +3,14 @@ import {
3
3
  Procedure,
4
4
  adaptRouter,
5
5
  addMiddleware,
6
+ convertPathToHttpPath,
6
7
  createAccessibleLazyRouter,
8
+ createContractedProcedure,
7
9
  createLazyProcedureFormAnyLazy,
8
10
  createProcedureClient,
9
11
  deepSetLazyRouterPrefix,
12
+ eachAllContractProcedure,
13
+ eachContractProcedure,
10
14
  flatLazy,
11
15
  getLazyRouterPrefix,
12
16
  getRouterChild,
@@ -17,7 +21,7 @@ import {
17
21
  middlewareOutputFn,
18
22
  setRouterContract,
19
23
  unlazy
20
- } from "./chunk-KK4SDLC7.js";
24
+ } from "./chunk-XXBE6CYD.js";
21
25
 
22
26
  // src/builder.ts
23
27
  import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
@@ -46,10 +50,14 @@ function decorateMiddleware(middleware) {
46
50
  decorated.concat = (concatMiddleware, mapInput) => {
47
51
  const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
48
52
  const concatted = decorateMiddleware((options, input, output, ...rest) => {
49
- const next = async (...[nextOptions]) => {
50
- return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
51
- };
52
- const merged = middleware({ ...options, next }, input, output, ...rest);
53
+ const merged = middleware({
54
+ ...options,
55
+ next: (...[nextOptions1]) => mapped({
56
+ ...options,
57
+ context: { ...options.context, ...nextOptions1?.context },
58
+ next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
59
+ }, input, output, ...rest)
60
+ }, input, output, ...rest);
53
61
  return merged;
54
62
  });
55
63
  return concatted;
@@ -353,23 +361,32 @@ function createRouterClient(router, ...rest) {
353
361
  }
354
362
 
355
363
  // src/index.ts
356
- import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
364
+ import { eventIterator, isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
365
+ import { getEventMeta, withEventMeta } from "@orpc/server-standard";
366
+ import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
357
367
  export {
358
368
  Builder,
359
369
  DecoratedProcedure,
360
370
  LAZY_LOADER_SYMBOL,
361
371
  ORPCError,
362
372
  Procedure,
373
+ ValidationError,
363
374
  adaptRouter,
364
375
  call,
376
+ convertPathToHttpPath,
365
377
  createAccessibleLazyRouter,
378
+ createContractedProcedure,
366
379
  createLazyProcedureFormAnyLazy,
367
380
  createProcedureClient,
368
381
  createRouterClient,
369
382
  decorateMiddleware,
370
383
  deepSetLazyRouterPrefix,
384
+ eachAllContractProcedure,
385
+ eachContractProcedure,
386
+ eventIterator,
371
387
  fallbackConfig,
372
388
  flatLazy,
389
+ getEventMeta,
373
390
  getLazyRouterPrefix,
374
391
  getRouterChild,
375
392
  getRouterContract,
@@ -381,10 +398,15 @@ export {
381
398
  lazy,
382
399
  mergeContext,
383
400
  middlewareOutputFn,
401
+ onError,
402
+ onFinish,
403
+ onStart,
404
+ onSuccess,
384
405
  os,
385
406
  safe,
386
407
  setRouterContract,
387
408
  type,
388
- unlazy
409
+ unlazy,
410
+ withEventMeta
389
411
  };
390
412
  //# sourceMappingURL=index.js.map
package/dist/next.js CHANGED
@@ -1,11 +1,9 @@
1
- import "./chunk-WUOGVGWG.js";
2
1
  import {
3
- ORPCPayloadCodec,
4
- ORPCProcedureMatcher,
5
- RPCHandler,
6
- super_json_exports
7
- } from "./chunk-ESTRJAOX.js";
8
- import "./chunk-KK4SDLC7.js";
2
+ RPCHandler
3
+ } from "./chunk-L4ESXQX7.js";
4
+ import "./chunk-NXEANHUK.js";
5
+ import "./chunk-XXBE6CYD.js";
6
+ import "./chunk-XI6WGCB3.js";
9
7
 
10
8
  // src/adapters/next/serve.ts
11
9
  import { value } from "@orpc/shared";
@@ -27,10 +25,7 @@ function serve(handler, ...[options]) {
27
25
  };
28
26
  }
29
27
  export {
30
- ORPCPayloadCodec,
31
- ORPCProcedureMatcher,
32
28
  RPCHandler,
33
- super_json_exports as SuperJSON,
34
29
  serve
35
30
  };
36
31
  //# sourceMappingURL=next.js.map
package/dist/node.js CHANGED
@@ -1,87 +1,31 @@
1
1
  import {
2
- RPCHandler
3
- } from "./chunk-ESTRJAOX.js";
4
- import "./chunk-KK4SDLC7.js";
2
+ RPCCodec,
3
+ RPCMatcher,
4
+ StandardHandler
5
+ } from "./chunk-NXEANHUK.js";
6
+ import "./chunk-XXBE6CYD.js";
7
+ import "./chunk-XI6WGCB3.js";
5
8
 
6
- // src/adapters/node/request-listener.ts
7
- function createRequest(req, res) {
8
- const controller = new AbortController();
9
- res.on("close", () => {
10
- controller.abort();
11
- });
12
- const method = req.method ?? "GET";
13
- const headers = createHeaders(req);
14
- const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
15
- const host = headers.get("Host") ?? "localhost";
16
- const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
17
- const init = { method, headers, signal: controller.signal };
18
- if (method !== "GET" && method !== "HEAD") {
19
- init.body = new ReadableStream({
20
- start(controller2) {
21
- req.on("data", (chunk) => {
22
- controller2.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
23
- });
24
- req.on("end", () => {
25
- controller2.close();
26
- });
27
- }
28
- });
29
- init.duplex = "half";
30
- }
31
- return new Request(url, init);
32
- }
33
- function createHeaders(req) {
34
- const headers = new Headers();
35
- const rawHeaders = req.rawHeaders;
36
- for (let i = 0; i < rawHeaders.length; i += 2) {
37
- headers.append(rawHeaders[i], rawHeaders[i + 1]);
38
- }
39
- return headers;
40
- }
41
- async function sendResponse(res, response) {
42
- const headers = {};
43
- for (const [key, value] of response.headers) {
44
- if (key in headers) {
45
- if (Array.isArray(headers[key])) {
46
- headers[key].push(value);
47
- } else {
48
- headers[key] = [headers[key], value];
49
- }
50
- } else {
51
- headers[key] = value;
52
- }
53
- }
54
- res.writeHead(response.status, headers);
55
- if (response.body != null && res.req.method !== "HEAD") {
56
- for await (const chunk of response.body) {
57
- res.write(chunk);
58
- }
59
- }
60
- res.end();
61
- }
62
-
63
- // src/adapters/node/orpc-handler.ts
64
- var RPCHandler2 = class {
65
- orpcFetchHandler;
9
+ // src/adapters/node/rpc-handler.ts
10
+ import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
11
+ var RPCHandler = class {
12
+ standardHandler;
66
13
  constructor(router, options) {
67
- this.orpcFetchHandler = new RPCHandler(router, options);
14
+ const codec = options?.codec ?? new RPCCodec();
15
+ const matcher = options?.matcher ?? new RPCMatcher();
16
+ this.standardHandler = new StandardHandler(router, matcher, codec, options);
68
17
  }
69
18
  async handle(req, res, ...rest) {
70
- const request = createRequest(req, res);
71
- const result = await this.orpcFetchHandler.handle(request, ...rest);
72
- if (result.matched === false) {
19
+ const standardRequest = toStandardRequest(req, res);
20
+ const result = await this.standardHandler.handle(standardRequest, ...rest);
21
+ if (!result.matched) {
73
22
  return { matched: false };
74
23
  }
75
- const context = rest[0]?.context ?? {};
76
- await rest[0]?.beforeSend?.(result.response, context);
77
- await sendResponse(res, result.response);
24
+ await sendStandardResponse(res, result.response);
78
25
  return { matched: true };
79
26
  }
80
27
  };
81
28
  export {
82
- RPCHandler2 as RPCHandler,
83
- createHeaders,
84
- createRequest,
85
- sendResponse
29
+ RPCHandler
86
30
  };
87
31
  //# sourceMappingURL=node.js.map
@@ -0,0 +1,11 @@
1
+ import {
2
+ CORSPlugin,
3
+ CompositePlugin,
4
+ ResponseHeadersPlugin
5
+ } from "./chunk-XI6WGCB3.js";
6
+ export {
7
+ CORSPlugin,
8
+ CompositePlugin,
9
+ ResponseHeadersPlugin
10
+ };
11
+ //# sourceMappingURL=plugins.js.map
@@ -1,6 +1,3 @@
1
- export * from './orpc-handler';
2
- export * from './orpc-payload-codec';
3
- export * from './orpc-procedure-matcher';
4
- export * as SuperJSON from './super-json';
1
+ export * from './rpc-handler';
5
2
  export * from './types';
6
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { Context } from '../../context';
3
+ import type { Router } from '../../router';
4
+ import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
5
+ import type { FetchHandler, FetchHandleResult } from './types';
6
+ export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
7
+ private readonly standardHandler;
8
+ constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
9
+ handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
10
+ }
11
+ //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,13 +1,6 @@
1
- import type { HTTPPath } from '@orpc/contract';
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
2
  import type { Context } from '../../context';
3
- export type FetchHandleOptions<T extends Context> = {
4
- prefix?: HTTPPath;
5
- } & (Record<never, never> extends T ? {
6
- context?: T;
7
- } : {
8
- context: T;
9
- });
10
- export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
3
+ import type { StandardHandleOptions } from '../standard';
11
4
  export type FetchHandleResult = {
12
5
  matched: true;
13
6
  response: Response;
@@ -16,6 +9,6 @@ export type FetchHandleResult = {
16
9
  response: undefined;
17
10
  };
18
11
  export interface FetchHandler<T extends Context> {
19
- handle(request: Request, ...rest: FetchHandleRest<T>): Promise<FetchHandleResult>;
12
+ handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
20
13
  }
21
14
  //# sourceMappingURL=types.d.ts.map
@@ -1,12 +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
- import type { FetchHandleOptions, FetchHandler } from '../fetch';
4
- import { type Value } from '@orpc/shared';
5
- export type CreateMiddlewareOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
4
+ import type { FetchHandler } from '../fetch';
5
+ import type { StandardHandleOptions } from '../standard';
6
+ export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
7
  context?: Value<T, [HonoContext]>;
7
8
  } : {
8
9
  context: Value<T, [HonoContext]>;
9
10
  });
10
- export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
11
- 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;
12
12
  //# sourceMappingURL=middleware.d.ts.map
@@ -1,13 +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
- import type { FetchHandleOptions, FetchHandler } from '../fetch';
4
- import { type Value } from '@orpc/shared';
5
- export type ServeOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
4
+ import type { FetchHandler } from '../fetch';
5
+ import type { StandardHandleOptions } from '../standard';
6
+ export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
7
  context?: Value<T, [NextRequest]>;
7
8
  } : {
8
9
  context: Value<T, [NextRequest]>;
9
10
  });
10
- export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
11
11
  export interface ServeResult {
12
12
  GET(req: NextRequest): Promise<Response>;
13
13
  POST(req: NextRequest): Promise<Response>;
@@ -15,5 +15,5 @@ export interface ServeResult {
15
15
  PATCH(req: NextRequest): Promise<Response>;
16
16
  DELETE(req: NextRequest): Promise<Response>;
17
17
  }
18
- 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;
19
19
  //# sourceMappingURL=serve.d.ts.map
@@ -1,5 +1,3 @@
1
- export * from './orpc-handler';
2
- export * from './orpc-handler';
3
- export * from './request-listener';
1
+ export * from './rpc-handler';
4
2
  export * from './types';
5
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { Context } from '../../context';
3
+ import type { Router } from '../../router';
4
+ import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
5
+ import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
6
+ export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
7
+ private readonly standardHandler;
8
+ constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
9
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
10
+ }
11
+ //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,22 +1,22 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { Promisable } from '@orpc/shared';
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
3
2
  import type { IncomingMessage, ServerResponse } from 'node:http';
3
+ import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
4
4
  import type { Context } from '../../context';
5
- export type RequestHandleOptions<T extends Context> = {
6
- prefix?: HTTPPath;
7
- beforeSend?(response: Response, context: T): Promisable<void>;
8
- } & (Record<never, never> extends T ? {
9
- context?: T;
10
- } : {
11
- context: T;
12
- });
13
- export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
14
- export type RequestHandleResult = {
5
+ import type { StandardHandleOptions } from '../standard';
6
+ export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
7
+ /**
8
+ * Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
9
+ * This is useful for `express.js` middleware.
10
+ */
11
+ originalUrl?: string;
12
+ };
13
+ export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
14
+ export type NodeHttpHandleResult = {
15
15
  matched: true;
16
16
  } | {
17
17
  matched: false;
18
18
  };
19
- export interface RequestHandler<T extends Context> {
20
- handle(req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
19
+ export interface NodeHttpHandler<T extends Context> {
20
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
21
21
  }
22
22
  //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,51 @@
1
+ import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
+ import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
4
+ import type { Context } from '../../context';
5
+ import type { Plugin } from '../../plugins';
6
+ import type { CreateProcedureClientOptions } from '../../procedure-client';
7
+ import type { Router } from '../../router';
8
+ import type { StandardCodec, StandardMatcher } from './types';
9
+ export type StandardHandleOptions<T extends Context> = {
10
+ prefix?: HTTPPath;
11
+ } & (Record<never, never> extends T ? {
12
+ context?: T;
13
+ } : {
14
+ context: T;
15
+ });
16
+ export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
17
+ context: T;
18
+ };
19
+ export type StandardHandleResult = {
20
+ matched: true;
21
+ response: StandardResponse;
22
+ } | {
23
+ matched: false;
24
+ response: undefined;
25
+ };
26
+ export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
27
+ request: StandardRequest;
28
+ };
29
+ export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, Record<never, never>> & {
30
+ context: TContext;
31
+ };
32
+ export interface StandardHandlerOptions<TContext extends Context> {
33
+ plugins?: Plugin<TContext>[];
34
+ /**
35
+ * Interceptors at the request level, helpful when you want catch errors
36
+ */
37
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
38
+ /**
39
+ * Interceptors at the root level, helpful when you want override the response
40
+ */
41
+ interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
42
+ }
43
+ export declare class StandardHandler<T extends Context> {
44
+ private readonly matcher;
45
+ private readonly codec;
46
+ private readonly options;
47
+ private readonly plugin;
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
+ }
51
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1,7 @@
1
+ export * from './handler';
2
+ export * from './rpc-codec';
3
+ export * from './rpc-handler';
4
+ export * from './rpc-matcher';
5
+ export * from './rpc-serializer';
6
+ export * from './types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ import type { ORPCError } from '@orpc/contract';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
+ import type { AnyProcedure } from '../../procedure';
4
+ import type { StandardCodec, StandardParams } from './types';
5
+ import { RPCSerializer } from './rpc-serializer';
6
+ export interface StandardCodecOptions {
7
+ serializer?: RPCSerializer;
8
+ }
9
+ export declare class RPCCodec implements StandardCodec {
10
+ private readonly serializer;
11
+ constructor(options?: StandardCodecOptions);
12
+ decode(request: StandardRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
13
+ encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
14
+ encodeError(error: ORPCError<any, any>): StandardResponse;
15
+ }
16
+ //# sourceMappingURL=rpc-codec.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { Context } from '../../context';
2
+ import type { StandardHandlerOptions } from './handler';
3
+ import type { StandardCodec, StandardMatcher } from './types';
4
+ export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
5
+ matcher?: StandardMatcher;
6
+ codec?: StandardCodec;
7
+ }
8
+ //# sourceMappingURL=rpc-handler.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { HTTPPath } from '@orpc/contract';
2
+ import type { StandardMatcher, StandardMatchResult } from './types';
3
+ import { type AnyRouter } from '../../router';
4
+ export declare class RPCMatcher implements StandardMatcher {
5
+ private readonly tree;
6
+ private pendingRouters;
7
+ init(router: AnyRouter, path?: string[]): void;
8
+ match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
9
+ }
10
+ //# sourceMappingURL=rpc-matcher.d.ts.map
@@ -0,0 +1,22 @@
1
+ import type { Segment } from '@orpc/shared';
2
+ export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url', Segment[]][];
3
+ export type RPCSerialized = {
4
+ json: unknown;
5
+ meta: RPCSerializedJsonMeta;
6
+ } | FormData | AsyncIteratorObject<{
7
+ json: unknown;
8
+ meta: RPCSerializedJsonMeta;
9
+ }, {
10
+ json: unknown;
11
+ meta: RPCSerializedJsonMeta;
12
+ }, void>;
13
+ export type RPCSerializedFormDataMaps = Segment[][];
14
+ export declare class RPCSerializer {
15
+ serialize(data: unknown): RPCSerialized;
16
+ deserialize(serialized: RPCSerialized): unknown;
17
+ }
18
+ export declare function serializeRPCJson(value: unknown, segments?: Segment[], meta?: RPCSerializedJsonMeta): {
19
+ json: unknown;
20
+ meta: RPCSerializedJsonMeta;
21
+ };
22
+ //# sourceMappingURL=rpc-serializer.d.ts.map
@@ -0,0 +1,20 @@
1
+ import type { HTTPPath, ORPCError } from '@orpc/contract';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
+ import type { AnyProcedure } from '../../procedure';
4
+ import type { AnyRouter } from '../../router';
5
+ export type StandardParams = Record<string, string>;
6
+ export type StandardMatchResult = {
7
+ path: string[];
8
+ procedure: AnyProcedure;
9
+ params?: StandardParams;
10
+ } | undefined;
11
+ export interface StandardMatcher {
12
+ init(router: AnyRouter): void;
13
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
14
+ }
15
+ export interface StandardCodec {
16
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
17
+ encodeError(error: ORPCError<any, any>): StandardResponse;
18
+ decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
19
+ }
20
+ //# sourceMappingURL=types.d.ts.map
@@ -1,6 +1,5 @@
1
1
  import type { IsNever } from '@orpc/shared';
2
2
  export type Context = Record<string, any>;
3
- export type TypeInitialContext<T extends Context> = (type: T) => unknown;
4
3
  export type MergedContext<T extends Context, U extends Context> = T & U;
5
4
  export declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
6
5
  export type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
@@ -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, TOutputSchema, THandlerOutput, 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, TOutputSchema, THandlerOutput, 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,16 +1,17 @@
1
- import type { AnyContractRouter, ContractProcedure, ContractRouter, ContractRouterToErrorMap, ORPCErrorConstructorMap } from '@orpc/contract';
1
+ import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
2
2
  import type { ConflictContextGuard, Context, MergedContext } from './context';
3
3
  import type { ProcedureImplementer } from './implementer-procedure';
4
4
  import type { FlattenLazy } from './lazy-utils';
5
5
  import type { Middleware } from './middleware';
6
6
  import type { AdaptedRouter, Router } from './router';
7
- export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : TContract extends ContractRouter<infer UMeta> ? {
8
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, UMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
7
+ export interface RouterImplementerWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
8
+ use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
9
9
  router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
10
10
  lazy<U extends Router<TInitialContext, TContract>>(loader: () => Promise<{
11
11
  default: U;
12
12
  }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
13
- } & {
13
+ }
14
+ export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
14
15
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
15
- } : never);
16
+ });
16
17
  //# sourceMappingURL=implementer-variants.d.ts.map