@orpc/server 0.0.0-next.d5f0415 → 0.0.0-next.d760838

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 (84) hide show
  1. package/README.md +15 -2
  2. package/dist/adapters/fetch/index.d.mts +54 -0
  3. package/dist/adapters/fetch/index.d.ts +54 -0
  4. package/dist/adapters/fetch/index.mjs +9 -0
  5. package/dist/adapters/hono/index.d.mts +22 -0
  6. package/dist/adapters/hono/index.d.ts +22 -0
  7. package/dist/{hono.js → adapters/hono/index.mjs} +11 -13
  8. package/dist/adapters/next/index.d.mts +29 -0
  9. package/dist/adapters/next/index.d.ts +29 -0
  10. package/dist/{next.js → adapters/next/index.mjs} +11 -13
  11. package/dist/adapters/node/index.d.mts +53 -0
  12. package/dist/adapters/node/index.d.ts +53 -0
  13. package/dist/adapters/node/index.mjs +85 -0
  14. package/dist/adapters/standard/index.d.mts +26 -0
  15. package/dist/adapters/standard/index.d.ts +26 -0
  16. package/dist/adapters/standard/index.mjs +6 -0
  17. package/dist/index.d.mts +291 -0
  18. package/dist/index.d.ts +291 -0
  19. package/dist/{index.js → index.mjs} +107 -157
  20. package/dist/plugins/index.d.mts +66 -0
  21. package/dist/plugins/index.d.ts +66 -0
  22. package/dist/plugins/index.mjs +196 -0
  23. package/dist/shared/server.BFt8M4Cr.d.ts +8 -0
  24. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  25. package/dist/shared/server.Bc6jnvPE.d.ts +10 -0
  26. package/dist/shared/server.BlxK0o8R.d.mts +66 -0
  27. package/dist/{chunk-MHVECKBC.js → shared/server.C37gDhSZ.mjs} +167 -224
  28. package/dist/shared/server.CCPFkKqC.mjs +98 -0
  29. package/dist/shared/server.CCgy73tk.d.mts +10 -0
  30. package/dist/{chunk-77FU7QSO.js → shared/server.DJrRF9vD.mjs} +50 -69
  31. package/dist/shared/server.DLt5njUb.d.mts +143 -0
  32. package/dist/shared/server.DLt5njUb.d.ts +143 -0
  33. package/dist/shared/server.DuTpqr2w.d.ts +66 -0
  34. package/dist/shared/server.JgWzFqlo.d.mts +8 -0
  35. package/package.json +30 -35
  36. package/dist/chunk-47YYO5JS.js +0 -32
  37. package/dist/chunk-WQNNSBXW.js +0 -120
  38. package/dist/fetch.js +0 -10
  39. package/dist/node.js +0 -31
  40. package/dist/plugins.js +0 -11
  41. package/dist/src/adapters/fetch/index.d.ts +0 -3
  42. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
  43. package/dist/src/adapters/fetch/types.d.ts +0 -14
  44. package/dist/src/adapters/hono/index.d.ts +0 -3
  45. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  46. package/dist/src/adapters/next/index.d.ts +0 -3
  47. package/dist/src/adapters/next/serve.d.ts +0 -19
  48. package/dist/src/adapters/node/index.d.ts +0 -3
  49. package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
  50. package/dist/src/adapters/node/types.d.ts +0 -22
  51. package/dist/src/adapters/standard/handler.d.ts +0 -53
  52. package/dist/src/adapters/standard/index.d.ts +0 -6
  53. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
  54. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  55. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  56. package/dist/src/adapters/standard/types.d.ts +0 -21
  57. package/dist/src/builder-variants.d.ts +0 -75
  58. package/dist/src/builder.d.ts +0 -58
  59. package/dist/src/config.d.ts +0 -6
  60. package/dist/src/context.d.ts +0 -8
  61. package/dist/src/error.d.ts +0 -12
  62. package/dist/src/hidden.d.ts +0 -8
  63. package/dist/src/implementer-procedure.d.ts +0 -33
  64. package/dist/src/implementer-variants.d.ts +0 -18
  65. package/dist/src/implementer.d.ts +0 -29
  66. package/dist/src/index.d.ts +0 -25
  67. package/dist/src/lazy-utils.d.ts +0 -6
  68. package/dist/src/lazy.d.ts +0 -22
  69. package/dist/src/middleware-decorated.d.ts +0 -11
  70. package/dist/src/middleware-utils.d.ts +0 -5
  71. package/dist/src/middleware.d.ts +0 -38
  72. package/dist/src/plugins/base.d.ts +0 -11
  73. package/dist/src/plugins/cors.d.ts +0 -19
  74. package/dist/src/plugins/index.d.ts +0 -4
  75. package/dist/src/plugins/response-headers.d.ts +0 -10
  76. package/dist/src/procedure-client.d.ts +0 -33
  77. package/dist/src/procedure-decorated.d.ts +0 -24
  78. package/dist/src/procedure-utils.d.ts +0 -19
  79. package/dist/src/procedure.d.ts +0 -31
  80. package/dist/src/router-accessible-lazy.d.ts +0 -8
  81. package/dist/src/router-client.d.ts +0 -12
  82. package/dist/src/router.d.ts +0 -30
  83. package/dist/src/utils.d.ts +0 -24
  84. package/dist/standard.js +0 -13
@@ -1,62 +1,55 @@
1
- import {
2
- convertPathToHttpPath,
3
- createContractedProcedure,
4
- createProcedureClient,
5
- eachContractProcedure,
6
- getRouterChild,
7
- isProcedure,
8
- unlazy
9
- } from "./chunk-MHVECKBC.js";
10
- import {
11
- CompositePlugin
12
- } from "./chunk-WQNNSBXW.js";
1
+ import { ORPCError, toORPCError } from '@orpc/client';
2
+ import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
3
+ import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.C37gDhSZ.mjs';
4
+ import { toHttpPath } from '@orpc/client/standard';
13
5
 
14
- // src/adapters/standard/handler.ts
15
- import { ORPCError, toORPCError } from "@orpc/client";
16
- import { intercept, trim } from "@orpc/shared";
17
- var StandardHandler = class {
18
- constructor(router, matcher, codec, options = {}) {
6
+ class StandardHandler {
7
+ constructor(router, matcher, codec, options) {
19
8
  this.matcher = matcher;
20
9
  this.codec = codec;
21
- this.options = options;
22
- this.plugin = new CompositePlugin(options.plugins);
23
- this.plugin.init(this.options);
10
+ for (const plugin of toArray(options.plugins)) {
11
+ plugin.init?.(options);
12
+ }
13
+ this.interceptors = toArray(options.interceptors);
14
+ this.clientInterceptors = toArray(options.clientInterceptors);
15
+ this.rootInterceptors = toArray(options.rootInterceptors);
24
16
  this.matcher.init(router);
25
17
  }
26
- plugin;
27
- handle(request, ...[options]) {
18
+ interceptors;
19
+ clientInterceptors;
20
+ rootInterceptors;
21
+ async handle(request, options) {
22
+ const prefix = options.prefix?.replace(/\/$/, "") || void 0;
23
+ if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
24
+ return { matched: false, response: void 0 };
25
+ }
28
26
  return intercept(
29
- this.options.rootInterceptors ?? [],
30
- {
31
- request,
32
- ...options,
33
- context: options?.context ?? {}
34
- // context is optional only when all fields are optional so we can safely force it to have a context
35
- },
27
+ this.rootInterceptors,
28
+ { ...options, request, prefix },
36
29
  async (interceptorOptions) => {
37
30
  let isDecoding = false;
38
31
  try {
39
32
  return await intercept(
40
- this.options.interceptors ?? [],
33
+ this.interceptors,
41
34
  interceptorOptions,
42
- async (interceptorOptions2) => {
43
- const method = interceptorOptions2.request.method;
44
- const url = interceptorOptions2.request.url;
45
- const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
46
- const match = await this.matcher.match(method, pathname);
35
+ async ({ request: request2, context, prefix: prefix2 }) => {
36
+ const method = request2.method;
37
+ const url = request2.url;
38
+ const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
39
+ const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
47
40
  if (!match) {
48
41
  return { matched: false, response: void 0 };
49
42
  }
50
43
  const client = createProcedureClient(match.procedure, {
51
- context: interceptorOptions2.context,
44
+ context,
52
45
  path: match.path,
53
- interceptors: this.options.clientInterceptors
46
+ interceptors: this.clientInterceptors
54
47
  });
55
48
  isDecoding = true;
56
- const input = await this.codec.decode(request, match.params, match.procedure);
49
+ const input = await this.codec.decode(request2, match.params, match.procedure);
57
50
  isDecoding = false;
58
- const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
59
- const output = await client(input, { signal: request.signal, lastEventId });
51
+ const lastEventId = Array.isArray(request2.headers["last-event-id"]) ? request2.headers["last-event-id"].at(-1) : request2.headers["last-event-id"];
52
+ const output = await client(input, { signal: request2.signal, lastEventId });
60
53
  const response = this.codec.encode(output, match.procedure);
61
54
  return {
62
55
  matched: true,
@@ -65,7 +58,7 @@ var StandardHandler = class {
65
58
  }
66
59
  );
67
60
  } catch (e) {
68
- const error = isDecoding ? new ORPCError("BAD_REQUEST", {
61
+ const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
69
62
  message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
70
63
  cause: e
71
64
  }) : toORPCError(e);
@@ -78,17 +71,14 @@ var StandardHandler = class {
78
71
  }
79
72
  );
80
73
  }
81
- };
74
+ }
82
75
 
83
- // src/adapters/standard/rpc-codec.ts
84
- import { RPCSerializer } from "@orpc/client/rpc";
85
- var RPCCodec = class {
86
- serializer;
87
- constructor(options = {}) {
88
- this.serializer = options.serializer ?? new RPCSerializer();
76
+ class StandardRPCCodec {
77
+ constructor(serializer) {
78
+ this.serializer = serializer;
89
79
  }
90
80
  async decode(request, _params, _procedure) {
91
- const serialized = request.method === "GET" ? JSON.parse(request.url.searchParams.getAll("data").at(-1)) : await request.body();
81
+ const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
92
82
  return this.serializer.deserialize(serialized);
93
83
  }
94
84
  encode(output, _procedure) {
@@ -105,18 +95,14 @@ var RPCCodec = class {
105
95
  body: this.serializer.serialize(error.toJSON())
106
96
  };
107
97
  }
108
- };
98
+ }
109
99
 
110
- // src/adapters/standard/rpc-matcher.ts
111
- var RPCMatcher = class {
100
+ class StandardRPCMatcher {
112
101
  tree = {};
113
102
  pendingRouters = [];
114
103
  init(router, path = []) {
115
- const laziedOptions = eachContractProcedure({
116
- router,
117
- path
118
- }, ({ path: path2, contract }) => {
119
- const httpPath = convertPathToHttpPath(path2);
104
+ const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
105
+ const httpPath = toHttpPath(path2);
120
106
  if (isProcedure(contract)) {
121
107
  this.tree[httpPath] = {
122
108
  path: path2,
@@ -136,7 +122,7 @@ var RPCMatcher = class {
136
122
  });
137
123
  this.pendingRouters.push(...laziedOptions.map((option) => ({
138
124
  ...option,
139
- httpPathPrefix: convertPathToHttpPath(option.path)
125
+ httpPathPrefix: toHttpPath(option.path)
140
126
  })));
141
127
  }
142
128
  async match(_method, pathname) {
@@ -144,7 +130,7 @@ var RPCMatcher = class {
144
130
  const newPendingRouters = [];
145
131
  for (const pendingRouter of this.pendingRouters) {
146
132
  if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
147
- const { default: router } = await unlazy(pendingRouter.lazied);
133
+ const { default: router } = await unlazy(pendingRouter.router);
148
134
  this.init(router, pendingRouter.path);
149
135
  } else {
150
136
  newPendingRouters.push(pendingRouter);
@@ -157,25 +143,20 @@ var RPCMatcher = class {
157
143
  return void 0;
158
144
  }
159
145
  if (!match.procedure) {
160
- const { default: maybeProcedure } = await unlazy(getRouterChild(match.router, ...match.path));
146
+ const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
161
147
  if (!isProcedure(maybeProcedure)) {
162
148
  throw new Error(`
163
- [Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.path)}.
149
+ [Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
164
150
  Ensure that the procedure is correctly defined and matches the expected contract.
165
151
  `);
166
152
  }
167
- match.procedure = createContractedProcedure(match.contract, maybeProcedure);
153
+ match.procedure = createContractedProcedure(maybeProcedure, match.contract);
168
154
  }
169
155
  return {
170
156
  path: match.path,
171
157
  procedure: match.procedure
172
158
  };
173
159
  }
174
- };
160
+ }
175
161
 
176
- export {
177
- StandardHandler,
178
- RPCCodec,
179
- RPCMatcher
180
- };
181
- //# sourceMappingURL=chunk-77FU7QSO.js.map
162
+ export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
@@ -0,0 +1,143 @@
1
+ import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
+ import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
4
+
5
+ type Context = Record<PropertyKey, any>;
6
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
7
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
8
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
9
+
10
+ type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
11
+ type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
12
+ type ORPCErrorConstructorMap<T extends ErrorMap> = {
13
+ [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
14
+ };
15
+ declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
16
+ declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
17
+
18
+ declare const LAZY_SYMBOL: unique symbol;
19
+ interface LazyMeta {
20
+ prefix?: HTTPPath;
21
+ }
22
+ interface Lazy<T> {
23
+ [LAZY_SYMBOL]: {
24
+ loader: () => Promise<{
25
+ default: T;
26
+ }>;
27
+ meta: LazyMeta;
28
+ };
29
+ }
30
+ type Lazyable<T> = T | Lazy<T>;
31
+ declare function lazy<T>(loader: () => Promise<{
32
+ default: T;
33
+ }>, meta?: LazyMeta): Lazy<T>;
34
+ declare function isLazy(item: unknown): item is Lazy<any>;
35
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
36
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
37
+ default: T extends Lazy<infer U> ? U : T;
38
+ }>;
39
+
40
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
41
+ context: TCurrentContext;
42
+ input: TInput;
43
+ path: readonly string[];
44
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
45
+ signal?: AbortSignal;
46
+ lastEventId: string | undefined;
47
+ errors: TErrorConstructorMap;
48
+ }
49
+ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
50
+ (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
51
+ }
52
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
53
+ __initialContext?: (type: TInitialContext) => unknown;
54
+ middlewares: readonly AnyMiddleware[];
55
+ inputValidationIndex: number;
56
+ outputValidationIndex: number;
57
+ handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
58
+ }
59
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
60
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
62
+ }
63
+ type AnyProcedure = Procedure<any, any, any, any, any, any>;
64
+ declare function isProcedure(item: unknown): item is AnyProcedure;
65
+
66
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
67
+ output: TOutput;
68
+ context: TOutContext;
69
+ }>;
70
+ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
71
+ context?: TOutContext;
72
+ } : {
73
+ context: TOutContext;
74
+ };
75
+ interface MiddlewareNextFn<TOutput> {
76
+ <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
77
+ }
78
+ interface MiddlewareOutputFn<TOutput> {
79
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
80
+ }
81
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
82
+ context: TInContext;
83
+ path: readonly string[];
84
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
85
+ signal?: AbortSignal;
86
+ lastEventId: string | undefined;
87
+ next: MiddlewareNextFn<TOutput>;
88
+ errors: TErrorConstructorMap;
89
+ }
90
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
91
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
92
+ }
93
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
94
+ interface MapInputMiddleware<TInput, TMappedInput> {
95
+ (input: TInput): TMappedInput;
96
+ }
97
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
98
+
99
+ type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
100
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
101
+ context: TInitialContext;
102
+ input: unknown;
103
+ errors: ORPCErrorConstructorMap<TErrorMap>;
104
+ path: readonly string[];
105
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
106
+ signal?: AbortSignal;
107
+ lastEventId: string | undefined;
108
+ }
109
+ /**
110
+ * Options for creating a procedure caller with comprehensive type safety
111
+ */
112
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
+ /**
114
+ * This is helpful for logging and analytics.
115
+ */
116
+ path?: readonly string[];
117
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
118
+ } & (Record<never, never> extends TInitialContext ? {
119
+ context?: Value<TInitialContext, [clientContext: TClientContext]>;
120
+ } : {
121
+ context: Value<TInitialContext, [clientContext: TClientContext]>;
122
+ });
123
+ declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
+
125
+ type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
127
+ };
128
+ type AnyRouter = Router<any, any>;
129
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
130
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
131
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
132
+ };
133
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
134
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
135
+ };
136
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
137
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
138
+ };
139
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
140
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
+ };
142
+
143
+ export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
@@ -0,0 +1,143 @@
1
+ import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
2
+ import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
4
+
5
+ type Context = Record<PropertyKey, any>;
6
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
7
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
8
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
9
+
10
+ type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
11
+ type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
12
+ type ORPCErrorConstructorMap<T extends ErrorMap> = {
13
+ [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
14
+ };
15
+ declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
16
+ declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
17
+
18
+ declare const LAZY_SYMBOL: unique symbol;
19
+ interface LazyMeta {
20
+ prefix?: HTTPPath;
21
+ }
22
+ interface Lazy<T> {
23
+ [LAZY_SYMBOL]: {
24
+ loader: () => Promise<{
25
+ default: T;
26
+ }>;
27
+ meta: LazyMeta;
28
+ };
29
+ }
30
+ type Lazyable<T> = T | Lazy<T>;
31
+ declare function lazy<T>(loader: () => Promise<{
32
+ default: T;
33
+ }>, meta?: LazyMeta): Lazy<T>;
34
+ declare function isLazy(item: unknown): item is Lazy<any>;
35
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
36
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
37
+ default: T extends Lazy<infer U> ? U : T;
38
+ }>;
39
+
40
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
41
+ context: TCurrentContext;
42
+ input: TInput;
43
+ path: readonly string[];
44
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
45
+ signal?: AbortSignal;
46
+ lastEventId: string | undefined;
47
+ errors: TErrorConstructorMap;
48
+ }
49
+ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
50
+ (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
51
+ }
52
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
53
+ __initialContext?: (type: TInitialContext) => unknown;
54
+ middlewares: readonly AnyMiddleware[];
55
+ inputValidationIndex: number;
56
+ outputValidationIndex: number;
57
+ handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
58
+ }
59
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
60
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
62
+ }
63
+ type AnyProcedure = Procedure<any, any, any, any, any, any>;
64
+ declare function isProcedure(item: unknown): item is AnyProcedure;
65
+
66
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
67
+ output: TOutput;
68
+ context: TOutContext;
69
+ }>;
70
+ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
71
+ context?: TOutContext;
72
+ } : {
73
+ context: TOutContext;
74
+ };
75
+ interface MiddlewareNextFn<TOutput> {
76
+ <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
77
+ }
78
+ interface MiddlewareOutputFn<TOutput> {
79
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
80
+ }
81
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
82
+ context: TInContext;
83
+ path: readonly string[];
84
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
85
+ signal?: AbortSignal;
86
+ lastEventId: string | undefined;
87
+ next: MiddlewareNextFn<TOutput>;
88
+ errors: TErrorConstructorMap;
89
+ }
90
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
91
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
92
+ }
93
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
94
+ interface MapInputMiddleware<TInput, TMappedInput> {
95
+ (input: TInput): TMappedInput;
96
+ }
97
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
98
+
99
+ type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
100
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
101
+ context: TInitialContext;
102
+ input: unknown;
103
+ errors: ORPCErrorConstructorMap<TErrorMap>;
104
+ path: readonly string[];
105
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
106
+ signal?: AbortSignal;
107
+ lastEventId: string | undefined;
108
+ }
109
+ /**
110
+ * Options for creating a procedure caller with comprehensive type safety
111
+ */
112
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
+ /**
114
+ * This is helpful for logging and analytics.
115
+ */
116
+ path?: readonly string[];
117
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
118
+ } & (Record<never, never> extends TInitialContext ? {
119
+ context?: Value<TInitialContext, [clientContext: TClientContext]>;
120
+ } : {
121
+ context: Value<TInitialContext, [clientContext: TClientContext]>;
122
+ });
123
+ declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
+
125
+ type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
127
+ };
128
+ type AnyRouter = Router<any, any>;
129
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
130
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
131
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
132
+ };
133
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
134
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
135
+ };
136
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
137
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
138
+ };
139
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
140
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
+ };
142
+
143
+ export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
@@ -0,0 +1,66 @@
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
+ import { Interceptor, ThrowableError } from '@orpc/shared';
4
+ import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.js';
6
+
7
+ type StandardParams = Record<string, string>;
8
+ type StandardMatchResult = {
9
+ path: readonly string[];
10
+ procedure: AnyProcedure;
11
+ params?: StandardParams;
12
+ } | undefined;
13
+ interface StandardMatcher {
14
+ init(router: AnyRouter): void;
15
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
16
+ }
17
+ interface StandardCodec {
18
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
19
+ encodeError(error: ORPCError<any, any>): StandardResponse;
20
+ decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
+ }
22
+
23
+ interface StandardHandleOptions<T extends Context> {
24
+ prefix?: HTTPPath;
25
+ context: T;
26
+ }
27
+ type StandardHandleResult = {
28
+ matched: true;
29
+ response: StandardResponse;
30
+ } | {
31
+ matched: false;
32
+ response: undefined;
33
+ };
34
+ interface StandardHandlerPlugin<TContext extends Context> {
35
+ init?(options: StandardHandlerOptions<TContext>): void;
36
+ }
37
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
38
+ request: StandardLazyRequest;
39
+ }
40
+ interface StandardHandlerOptions<TContext extends Context> {
41
+ plugins?: StandardHandlerPlugin<TContext>[];
42
+ /**
43
+ * Interceptors at the request level, helpful when you want catch errors
44
+ */
45
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
46
+ /**
47
+ * Interceptors at the root level, helpful when you want override the request/response
48
+ */
49
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
50
+ /**
51
+ *
52
+ * Interceptors for procedure client.
53
+ */
54
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
55
+ }
56
+ declare class StandardHandler<T extends Context> {
57
+ private readonly matcher;
58
+ private readonly codec;
59
+ private readonly interceptors;
60
+ private readonly clientInterceptors;
61
+ private readonly rootInterceptors;
62
+ constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
63
+ handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
64
+ }
65
+
66
+ export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardCodec as b, type StandardParams as c, type StandardMatcher as d, type StandardMatchResult as e, type StandardHandleResult as f, type StandardHandlerPlugin as g, type StandardHandlerInterceptorOptions as h, StandardHandler as i };
@@ -0,0 +1,8 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { C as Context } from './server.DLt5njUb.mjs';
3
+ import { a as StandardHandlerOptions } from './server.BlxK0o8R.mjs';
4
+
5
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
+ }
7
+
8
+ export type { StandardRPCHandlerOptions as S };