@orpc/server 0.28.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import {
4
4
  getRouterChild,
5
5
  isProcedure,
6
6
  unlazy
7
- } from "./chunk-DNG2IB3R.js";
7
+ } from "./chunk-XDC42C3C.js";
8
8
 
9
9
  // src/adapters/fetch/super-json.ts
10
10
  var super_json_exports = {};
@@ -238,7 +238,7 @@ var ORPCProcedureMatcher = class {
238
238
  // src/adapters/fetch/orpc-handler.ts
239
239
  import { ORPCError as ORPCError2 } from "@orpc/contract";
240
240
  import { executeWithHooks, trim as trim2 } from "@orpc/shared";
241
- var ORPCHandler = class {
241
+ var RPCHandler = class {
242
242
  constructor(router, options) {
243
243
  this.options = options;
244
244
  this.procedureMatcher = options?.procedureMatcher ?? new ORPCProcedureMatcher(router);
@@ -256,9 +256,8 @@ var ORPCHandler = class {
256
256
  return { matched: false, response: void 0 };
257
257
  }
258
258
  const input = await this.payloadCodec.decode(request);
259
- const client = createProcedureClient({
259
+ const client = createProcedureClient(match.procedure, {
260
260
  context,
261
- procedure: match.procedure,
262
261
  path: match.path
263
262
  });
264
263
  const output = await client(input, { signal: request.signal });
@@ -297,6 +296,6 @@ export {
297
296
  super_json_exports,
298
297
  ORPCPayloadCodec,
299
298
  ORPCProcedureMatcher,
300
- ORPCHandler
299
+ RPCHandler
301
300
  };
302
- //# sourceMappingURL=chunk-V3I7RIRY.js.map
301
+ //# sourceMappingURL=chunk-VY6NXNQT.js.map
@@ -89,11 +89,11 @@ function flatLazy(lazied) {
89
89
  // src/procedure-client.ts
90
90
  import { ORPCError as ORPCError2, validateORPCError, ValidationError } from "@orpc/contract";
91
91
  import { executeWithHooks, toError, value } from "@orpc/shared";
92
- function createProcedureClient(options) {
92
+ function createProcedureClient(lazyableProcedure, ...[options]) {
93
93
  return async (...[input, callerOptions]) => {
94
- const path = options.path ?? [];
95
- const { default: procedure } = await unlazy(options.procedure);
96
- const context = await value(options.context);
94
+ const path = options?.path ?? [];
95
+ const { default: procedure } = await unlazy(lazyableProcedure);
96
+ const context = await value(options?.context, callerOptions?.context);
97
97
  const meta = {
98
98
  path,
99
99
  procedure,
@@ -224,4 +224,4 @@ export {
224
224
  createProcedureClient,
225
225
  getRouterChild
226
226
  };
227
- //# sourceMappingURL=chunk-DNG2IB3R.js.map
227
+ //# sourceMappingURL=chunk-XDC42C3C.js.map
package/dist/fetch.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import "./chunk-WUOGVGWG.js";
2
2
  import {
3
- ORPCHandler,
4
3
  ORPCPayloadCodec,
5
4
  ORPCProcedureMatcher,
5
+ RPCHandler,
6
6
  super_json_exports
7
- } from "./chunk-V3I7RIRY.js";
8
- import "./chunk-DNG2IB3R.js";
7
+ } from "./chunk-VY6NXNQT.js";
8
+ import "./chunk-XDC42C3C.js";
9
9
  export {
10
- ORPCHandler,
11
10
  ORPCPayloadCodec,
12
11
  ORPCProcedureMatcher,
12
+ RPCHandler,
13
13
  super_json_exports as SuperJSON
14
14
  };
15
15
  //# sourceMappingURL=fetch.js.map
package/dist/hono.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import "./chunk-WUOGVGWG.js";
2
2
  import {
3
- ORPCHandler,
4
3
  ORPCPayloadCodec,
5
4
  ORPCProcedureMatcher,
5
+ RPCHandler,
6
6
  super_json_exports
7
- } from "./chunk-V3I7RIRY.js";
8
- import "./chunk-DNG2IB3R.js";
7
+ } from "./chunk-VY6NXNQT.js";
8
+ import "./chunk-XDC42C3C.js";
9
9
 
10
10
  // src/adapters/hono/middleware.ts
11
11
  import { value } from "@orpc/shared";
@@ -21,9 +21,9 @@ function createMiddleware(handler, ...[options]) {
21
21
  };
22
22
  }
23
23
  export {
24
- ORPCHandler,
25
24
  ORPCPayloadCodec,
26
25
  ORPCProcedureMatcher,
26
+ RPCHandler,
27
27
  super_json_exports as SuperJSON,
28
28
  createMiddleware
29
29
  };
package/dist/index.js CHANGED
@@ -10,14 +10,14 @@ import {
10
10
  lazy,
11
11
  mergeContext,
12
12
  unlazy
13
- } from "./chunk-DNG2IB3R.js";
13
+ } from "./chunk-XDC42C3C.js";
14
14
 
15
15
  // src/builder.ts
16
16
  import { ContractProcedure } from "@orpc/contract";
17
17
 
18
18
  // src/implementer-chainable.ts
19
19
  import { isContractProcedure } from "@orpc/contract";
20
- import { createCallableObject } from "@orpc/shared";
20
+ import { createCallableObject as createCallableObject2 } from "@orpc/shared";
21
21
 
22
22
  // src/middleware-decorated.ts
23
23
  function decorateMiddleware(middleware) {
@@ -44,58 +44,72 @@ function decorateMiddleware(middleware) {
44
44
 
45
45
  // src/procedure-decorated.ts
46
46
  import { DecoratedContractProcedure } from "@orpc/contract";
47
- function decorateProcedure(procedure) {
48
- const caller = createProcedureClient({
49
- procedure,
50
- context: void 0
51
- });
52
- const decorated = caller;
53
- decorated["~type"] = procedure["~type"];
54
- decorated["~orpc"] = procedure["~orpc"];
55
- decorated.prefix = (prefix) => {
56
- return decorateProcedure(new Procedure({
57
- ...procedure["~orpc"],
58
- contract: DecoratedContractProcedure.decorate(procedure["~orpc"].contract).prefix(prefix)
59
- }));
60
- };
61
- decorated.route = (route) => {
62
- return decorateProcedure(new Procedure({
63
- ...procedure["~orpc"],
64
- contract: DecoratedContractProcedure.decorate(procedure["~orpc"].contract).route(route)
65
- }));
66
- };
67
- decorated.use = (middleware, mapInput) => {
47
+ import { createCallableObject } from "@orpc/shared";
48
+ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
49
+ static decorate(procedure) {
50
+ if (procedure instanceof _DecoratedProcedure) {
51
+ return procedure;
52
+ }
53
+ return new _DecoratedProcedure(procedure["~orpc"]);
54
+ }
55
+ prefix(prefix) {
56
+ return new _DecoratedProcedure({
57
+ ...this["~orpc"],
58
+ contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).prefix(prefix)
59
+ });
60
+ }
61
+ route(route) {
62
+ return new _DecoratedProcedure({
63
+ ...this["~orpc"],
64
+ contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).route(route)
65
+ });
66
+ }
67
+ use(middleware, mapInput) {
68
68
  const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
69
- return decorateProcedure(new Procedure({
70
- ...procedure["~orpc"],
71
- middlewares: [...procedure["~orpc"].middlewares ?? [], middleware_]
72
- }));
73
- };
74
- decorated.unshiftTag = (...tags) => {
75
- return decorateProcedure(new Procedure({
76
- ...procedure["~orpc"],
77
- contract: DecoratedContractProcedure.decorate(procedure["~orpc"].contract).unshiftTag(...tags)
78
- }));
79
- };
80
- decorated.unshiftMiddleware = (...middlewares) => {
81
- if (procedure["~orpc"].middlewares?.length) {
69
+ return new _DecoratedProcedure({
70
+ ...this["~orpc"],
71
+ middlewares: [...this["~orpc"].middlewares ?? [], middleware_]
72
+ });
73
+ }
74
+ unshiftTag(...tags) {
75
+ return new _DecoratedProcedure({
76
+ ...this["~orpc"],
77
+ contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).unshiftTag(...tags)
78
+ });
79
+ }
80
+ unshiftMiddleware(...middlewares) {
81
+ const castedMiddlewares = middlewares;
82
+ if (this["~orpc"].middlewares?.length) {
82
83
  let min = 0;
83
- for (let i = 0; i < procedure["~orpc"].middlewares.length; i++) {
84
- const index = middlewares.indexOf(procedure["~orpc"].middlewares[i], min);
84
+ for (let i = 0; i < this["~orpc"].middlewares.length; i++) {
85
+ const index = castedMiddlewares.indexOf(this["~orpc"].middlewares[i], min);
85
86
  if (index === -1) {
86
- middlewares.push(...procedure["~orpc"].middlewares.slice(i));
87
+ castedMiddlewares.push(...this["~orpc"].middlewares.slice(i));
87
88
  break;
88
89
  }
89
90
  min = index + 1;
90
91
  }
91
92
  }
92
- return decorateProcedure(new Procedure({
93
- ...procedure["~orpc"],
94
- middlewares
95
- }));
96
- };
97
- return decorated;
98
- }
93
+ return new _DecoratedProcedure({
94
+ ...this["~orpc"],
95
+ middlewares: castedMiddlewares
96
+ });
97
+ }
98
+ /**
99
+ * Make this procedure callable (works like a function while still being a procedure).
100
+ * **Note**: this only takes effect when this method is called at the end of the chain.
101
+ */
102
+ callable(...rest) {
103
+ return createCallableObject(this, createProcedureClient(this, ...rest));
104
+ }
105
+ /**
106
+ * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
107
+ * **Note**: this only takes effect when this method is called at the end of the chain.
108
+ */
109
+ actionable(...rest) {
110
+ return this.callable(...rest);
111
+ }
112
+ };
99
113
 
100
114
  // src/procedure-implementer.ts
101
115
  var ProcedureImplementer = class _ProcedureImplementer {
@@ -112,11 +126,11 @@ var ProcedureImplementer = class _ProcedureImplementer {
112
126
  });
113
127
  }
114
128
  handler(handler) {
115
- return decorateProcedure(new Procedure({
129
+ return new DecoratedProcedure({
116
130
  middlewares: this["~orpc"].middlewares,
117
131
  contract: this["~orpc"].contract,
118
132
  handler
119
- }));
133
+ });
120
134
  }
121
135
  };
122
136
 
@@ -154,31 +168,10 @@ function getLazyRouterPrefix(obj) {
154
168
  return obj[LAZY_ROUTER_PREFIX_SYMBOL];
155
169
  }
156
170
 
157
- // src/lazy-utils.ts
158
- function createLazyProcedureFormAnyLazy(lazied) {
159
- const lazyProcedure = lazy(async () => {
160
- const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
161
- if (!isProcedure(maybeProcedure)) {
162
- throw new Error(`
163
- Expected a lazy<procedure> but got lazy<unknown>.
164
- This should be caught by TypeScript compilation.
165
- Please report this issue if this makes you feel uncomfortable.
166
- `);
167
- }
168
- return { default: maybeProcedure };
169
- });
170
- return lazyProcedure;
171
- }
172
-
173
171
  // src/lazy-decorated.ts
174
172
  function decorateLazy(lazied) {
175
173
  const flattenLazy = flatLazy(lazied);
176
- const procedureProcedureClient = createProcedureClient({
177
- procedure: createLazyProcedureFormAnyLazy(flattenLazy),
178
- context: void 0
179
- });
180
- Object.assign(procedureProcedureClient, flattenLazy);
181
- const recursive = new Proxy(procedureProcedureClient, {
174
+ const recursive = new Proxy(flattenLazy, {
182
175
  get(target, key) {
183
176
  if (typeof key !== "string") {
184
177
  return Reflect.get(target, key);
@@ -245,7 +238,7 @@ function adapt(item, options) {
245
238
  return adaptedLazy;
246
239
  }
247
240
  if (isProcedure(item)) {
248
- let decorated = decorateProcedure(item);
241
+ let decorated = DecoratedProcedure.decorate(item);
249
242
  if (options.tags?.length) {
250
243
  decorated = decorated.unshiftTag(...options.tags);
251
244
  }
@@ -313,7 +306,7 @@ function createChainableImplementer(contract, middlewares) {
313
306
  if (!next) {
314
307
  return method.bind(routerImplementer);
315
308
  }
316
- return createCallableObject(next, method.bind(routerImplementer));
309
+ return createCallableObject2(next, method.bind(routerImplementer));
317
310
  }
318
311
  });
319
312
  return merged;
@@ -366,11 +359,11 @@ var ProcedureBuilder = class _ProcedureBuilder {
366
359
  }).use(middleware, mapInput);
367
360
  }
368
361
  handler(handler) {
369
- return decorateProcedure(new Procedure({
362
+ return new DecoratedProcedure({
370
363
  middlewares: this["~orpc"].middlewares,
371
364
  contract: this["~orpc"].contract,
372
365
  handler
373
- }));
366
+ });
374
367
  }
375
368
  };
376
369
 
@@ -437,7 +430,7 @@ var Builder = class _Builder {
437
430
  });
438
431
  }
439
432
  handler(handler) {
440
- return decorateProcedure(new Procedure({
433
+ return new DecoratedProcedure({
441
434
  middlewares: this["~orpc"].middlewares,
442
435
  contract: new ContractProcedure({
443
436
  InputSchema: void 0,
@@ -445,7 +438,7 @@ var Builder = class _Builder {
445
438
  errorMap: void 0
446
439
  }),
447
440
  handler
448
- }));
441
+ });
449
442
  }
450
443
  prefix(prefix) {
451
444
  return new RouterBuilder({
@@ -470,36 +463,47 @@ var Builder = class _Builder {
470
463
  }
471
464
  };
472
465
 
466
+ // src/procedure-utils.ts
467
+ function call(procedure, input, ...rest) {
468
+ return createProcedureClient(procedure, ...rest)(input);
469
+ }
470
+
471
+ // src/lazy-utils.ts
472
+ function createLazyProcedureFormAnyLazy(lazied) {
473
+ const lazyProcedure = lazy(async () => {
474
+ const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
475
+ if (!isProcedure(maybeProcedure)) {
476
+ throw new Error(`
477
+ Expected a lazy<procedure> but got lazy<unknown>.
478
+ This should be caught by TypeScript compilation.
479
+ Please report this issue if this makes you feel uncomfortable.
480
+ `);
481
+ }
482
+ return { default: maybeProcedure };
483
+ });
484
+ return lazyProcedure;
485
+ }
486
+
473
487
  // src/router-client.ts
474
- function createRouterClient(options) {
475
- if (isProcedure(options.router)) {
476
- const caller = createProcedureClient({
477
- ...options,
478
- procedure: options.router,
479
- context: options.context,
480
- path: options.path
481
- });
488
+ function createRouterClient(router, ...rest) {
489
+ if (isProcedure(router)) {
490
+ const caller = createProcedureClient(router, ...rest);
482
491
  return caller;
483
492
  }
484
- const procedureCaller = isLazy(options.router) ? createProcedureClient({
485
- ...options,
486
- procedure: createLazyProcedureFormAnyLazy(options.router),
487
- context: options.context,
488
- path: options.path
489
- }) : {};
493
+ const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
490
494
  const recursive = new Proxy(procedureCaller, {
491
495
  get(target, key) {
492
496
  if (typeof key !== "string") {
493
497
  return Reflect.get(target, key);
494
498
  }
495
- const next = getRouterChild(options.router, key);
499
+ const next = getRouterChild(router, key);
496
500
  if (!next) {
497
501
  return Reflect.get(target, key);
498
502
  }
499
- return createRouterClient({
503
+ const [options] = rest;
504
+ return createRouterClient(next, {
500
505
  ...options,
501
- router: next,
502
- path: [...options.path ?? [], key]
506
+ path: [...options?.path ?? [], key]
503
507
  });
504
508
  }
505
509
  });
@@ -511,6 +515,7 @@ import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe }
511
515
  var os = new Builder({});
512
516
  export {
513
517
  Builder,
518
+ DecoratedProcedure,
514
519
  LAZY_LOADER_SYMBOL,
515
520
  ORPCError,
516
521
  Procedure,
@@ -518,6 +523,7 @@ export {
518
523
  ProcedureImplementer,
519
524
  RouterBuilder,
520
525
  RouterImplementer,
526
+ call,
521
527
  configGlobal,
522
528
  createChainableImplementer,
523
529
  createORPCErrorConstructorMap,
@@ -525,7 +531,6 @@ export {
525
531
  createRouterClient,
526
532
  decorateLazy,
527
533
  decorateMiddleware,
528
- decorateProcedure,
529
534
  deepSetLazyRouterPrefix,
530
535
  fallbackToGlobalConfig,
531
536
  flatLazy,
package/dist/next.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import "./chunk-WUOGVGWG.js";
2
2
  import {
3
- ORPCHandler,
4
3
  ORPCPayloadCodec,
5
4
  ORPCProcedureMatcher,
5
+ RPCHandler,
6
6
  super_json_exports
7
- } from "./chunk-V3I7RIRY.js";
8
- import "./chunk-DNG2IB3R.js";
7
+ } from "./chunk-VY6NXNQT.js";
8
+ import "./chunk-XDC42C3C.js";
9
9
 
10
10
  // src/adapters/next/serve.ts
11
11
  import { value } from "@orpc/shared";
@@ -27,9 +27,9 @@ function serve(handler, ...[options]) {
27
27
  };
28
28
  }
29
29
  export {
30
- ORPCHandler,
31
30
  ORPCPayloadCodec,
32
31
  ORPCProcedureMatcher,
32
+ RPCHandler,
33
33
  super_json_exports as SuperJSON,
34
34
  serve
35
35
  };
package/dist/node.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
- ORPCHandler
3
- } from "./chunk-V3I7RIRY.js";
4
- import "./chunk-DNG2IB3R.js";
2
+ RPCHandler
3
+ } from "./chunk-VY6NXNQT.js";
4
+ import "./chunk-XDC42C3C.js";
5
5
 
6
6
  // src/adapters/node/request-listener.ts
7
7
  function createRequest(req, res) {
@@ -61,10 +61,10 @@ async function sendResponse(res, response) {
61
61
  }
62
62
 
63
63
  // src/adapters/node/orpc-handler.ts
64
- var ORPCHandler2 = class {
64
+ var RPCHandler2 = class {
65
65
  orpcFetchHandler;
66
66
  constructor(router, options) {
67
- this.orpcFetchHandler = new ORPCHandler(router, options);
67
+ this.orpcFetchHandler = new RPCHandler(router, options);
68
68
  }
69
69
  async handle(req, res, ...[options]) {
70
70
  const request = createRequest(req, res);
@@ -79,7 +79,7 @@ var ORPCHandler2 = class {
79
79
  }
80
80
  };
81
81
  export {
82
- ORPCHandler2 as ORPCHandler,
82
+ RPCHandler2 as RPCHandler,
83
83
  createHeaders,
84
84
  createRequest,
85
85
  sendResponse
@@ -4,17 +4,17 @@ import type { Context } from '../../types';
4
4
  import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
5
5
  import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
6
6
  import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
7
- export type ORPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
7
+ export type RPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
8
8
  signal?: AbortSignal;
9
9
  }> & {
10
10
  procedureMatcher?: PublicORPCProcedureMatcher;
11
11
  payloadCodec?: PublicORPCPayloadCodec;
12
12
  };
13
- export declare class ORPCHandler<T extends Context> implements FetchHandler<T> {
13
+ export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
14
14
  private readonly options?;
15
15
  private readonly procedureMatcher;
16
16
  private readonly payloadCodec;
17
- constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<T>> | undefined);
17
+ constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>> | undefined);
18
18
  handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
19
19
  }
20
20
  //# sourceMappingURL=orpc-handler.d.ts.map
@@ -1,12 +1,12 @@
1
1
  import type { ServerResponse } from 'node:http';
2
2
  import type { Router } from '../../router';
3
3
  import type { Context } from '../../types';
4
- import type { ORPCHandlerOptions } from '../fetch/orpc-handler';
4
+ import type { RPCHandlerOptions } from '../fetch/orpc-handler';
5
5
  import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
6
6
  import { type ExpressableIncomingMessage } from './request-listener';
7
- export declare class ORPCHandler<T extends Context> implements RequestHandler<T> {
7
+ export declare class RPCHandler<T extends Context> implements RequestHandler<T> {
8
8
  private readonly orpcFetchHandler;
9
- constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<T>>);
9
+ constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
10
10
  handle(req: ExpressableIncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
11
11
  }
12
12
  //# sourceMappingURL=orpc-handler.d.ts.map
@@ -2,13 +2,13 @@ import type { ANY_CONTRACT_PROCEDURE, ContractRouter, ErrorMap, HTTPPath, RouteO
2
2
  import type { FlattenLazy } from './lazy';
3
3
  import type { Middleware } from './middleware';
4
4
  import type { DecoratedMiddleware } from './middleware-decorated';
5
+ import type { ProcedureHandler } from './procedure';
5
6
  import type { Router } from './router';
6
7
  import type { AdaptedRouter } from './router-builder';
7
8
  import type { Context, MergeContext, WELL_CONTEXT } from './types';
8
9
  import { type ChainableImplementer } from './implementer-chainable';
9
- import { type ProcedureHandler } from './procedure';
10
10
  import { ProcedureBuilder } from './procedure-builder';
11
- import { type DecoratedProcedure } from './procedure-decorated';
11
+ import { DecoratedProcedure } from './procedure-decorated';
12
12
  import { RouterBuilder } from './router-builder';
13
13
  export interface BuilderDef<TContext extends Context, TExtraContext extends Context> {
14
14
  middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
@@ -13,6 +13,7 @@ export * from './procedure-builder';
13
13
  export * from './procedure-client';
14
14
  export * from './procedure-decorated';
15
15
  export * from './procedure-implementer';
16
+ export * from './procedure-utils';
16
17
  export * from './router';
17
18
  export * from './router-builder';
18
19
  export * from './router-client';
@@ -1,10 +1,7 @@
1
- import type { ErrorFromErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
2
1
  import type { Lazy } from './lazy';
3
- import type { Procedure } from './procedure';
4
- import type { ProcedureClient } from './procedure-client';
5
2
  import { type ANY_ROUTER } from './router';
6
- export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends Procedure<infer UContext, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? undefined extends UContext ? ProcedureClient<unknown, SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>, ErrorFromErrorMap<UErrorMap>> : unknown : {
7
- [K in keyof T]: T[K] extends object ? DecoratedLazy<T[K]> : never;
8
- });
3
+ export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends ANY_ROUTER ? {
4
+ [K in keyof T]: DecoratedLazy<T[K]>;
5
+ } : unknown);
9
6
  export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
10
7
  //# sourceMappingURL=lazy-decorated.d.ts.map
@@ -1,9 +1,9 @@
1
1
  import type { ContractProcedure, ErrorMap, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { ORPCErrorConstructorMap } from './error';
3
3
  import type { MapInputMiddleware, Middleware } from './middleware';
4
- import type { DecoratedProcedure } from './procedure-decorated';
4
+ import type { ProcedureHandler } from './procedure';
5
5
  import type { Context, MergeContext } from './types';
6
- import { type ProcedureHandler } from './procedure';
6
+ import { DecoratedProcedure } from './procedure-decorated';
7
7
  import { ProcedureImplementer } from './procedure-implementer';
8
8
  export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
9
9
  contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
@@ -2,33 +2,21 @@ import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOu
2
2
  import type { Hooks, Value } from '@orpc/shared';
3
3
  import type { Lazyable } from './lazy';
4
4
  import type { Procedure } from './procedure';
5
- import type { AbortSignal, Context, Meta } from './types';
6
- export type ProcedureClientOptions<TClientContext> = {
7
- signal?: AbortSignal;
8
- } & (undefined extends TClientContext ? {
9
- context?: TClientContext;
10
- } : {
11
- context: TClientContext;
12
- });
13
- export type ProcedureClient<TClientContext, TInput, TOutput, TError extends Error> = Client<TClientContext, TInput, TOutput, TError>;
5
+ import type { Context, Meta } from './types';
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>>;
14
7
  /**
15
8
  * Options for creating a procedure caller with comprehensive type safety
16
9
  */
17
- export type CreateProcedureClientOptions<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = {
18
- procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>;
10
+ export type CreateProcedureClientOptions<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = {
19
11
  /**
20
12
  * This is helpful for logging and analytics.
21
- *
22
- * @internal
23
13
  */
24
14
  path?: string[];
25
15
  } & ({
26
- /**
27
- * The context used when calling the procedure.
28
- */
29
- context: Value<TContext>;
16
+ context: Value<TContext, [clientContext: TClientContext]>;
30
17
  } | (undefined extends TContext ? {
31
- context?: undefined;
18
+ context?: Value<TContext, [clientContext: TClientContext]>;
32
19
  } : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
33
- export declare function createProcedureClient<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(options: CreateProcedureClientOptions<TContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>): ProcedureClient<unknown, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
20
+ export type CreateProcedureClientRest<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TContext, TOutputSchema, THandlerOutput, TClientContext>] | (undefined extends TContext ? [] : never);
21
+ export declare function createProcedureClient<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, ...[options]: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
34
22
  //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,15 +1,26 @@
1
- import type { ErrorFromErrorMap, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ClientRest, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { ORPCErrorConstructorMap } from './error';
3
3
  import type { MapInputMiddleware, Middleware } from './middleware';
4
- import type { ProcedureClient } from './procedure-client';
4
+ import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
5
5
  import type { Context, MergeContext } from './types';
6
6
  import { Procedure } from './procedure';
7
- export type DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & {
8
- prefix: (prefix: HTTPPath) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
9
- route: (route: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
10
- use: (<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>) & (<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
11
- unshiftTag: (...tags: string[]) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
12
- unshiftMiddleware: <U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(...middlewares: Middleware<TContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
13
- } & (undefined extends TContext ? ProcedureClient<unknown, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>> : unknown);
14
- export declare function decorateProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
7
+ export declare class DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> extends Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> {
8
+ static decorate<UContext extends Context, UExtraContext extends Context, UInputSchema extends Schema, UOutputSchema extends Schema, UHandlerOutput extends SchemaInput<UOutputSchema>, UErrorMap extends ErrorMap>(procedure: Procedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>): DecoratedProcedure<any, any, any, any, any, any> | DecoratedProcedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>;
9
+ prefix(prefix: HTTPPath): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
10
+ route(route: RouteOptions): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
11
+ use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
12
+ use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
13
+ unshiftTag(...tags: string[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
14
+ unshiftMiddleware<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(...middlewares: Middleware<TContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
15
+ /**
16
+ * Make this procedure callable (works like a function while still being a procedure).
17
+ * **Note**: this only takes effect when this method is called at the end of the chain.
18
+ */
19
+ callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
20
+ /**
21
+ * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
22
+ * **Note**: this only takes effect when this method is called at the end of the chain.
23
+ */
24
+ actionable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
25
+ }
15
26
  //# sourceMappingURL=procedure-decorated.d.ts.map
@@ -2,8 +2,8 @@ import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } f
2
2
  import type { ORPCErrorConstructorMap } from './error';
3
3
  import type { MapInputMiddleware, Middleware } from './middleware';
4
4
  import type { ProcedureHandler } from './procedure';
5
- import type { DecoratedProcedure } from './procedure-decorated';
6
5
  import type { Context, MergeContext } from './types';
6
+ import { DecoratedProcedure } from './procedure-decorated';
7
7
  export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
8
8
  contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
9
9
  middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>[];
@@ -0,0 +1,17 @@
1
+ import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { Lazyable } from './lazy';
3
+ import type { Procedure } from './procedure';
4
+ import type { Context } from './types';
5
+ import { type CreateProcedureClientRest } from './procedure-client';
6
+ /**
7
+ * Directly call a procedure without creating a client.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const output = await call(getting, 'input')
12
+ * const output = await call(getting, 'input', { context: { db: 'postgres' } })
13
+ * ```
14
+ *
15
+ */
16
+ export declare function call<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
17
+ //# sourceMappingURL=procedure-utils.d.ts.map
@@ -5,7 +5,7 @@ import type { Procedure } from './procedure';
5
5
  import type { ANY_ROUTER, Router } from './router';
6
6
  import type { Context, MergeContext } from './types';
7
7
  import { type DecoratedLazy } from './lazy-decorated';
8
- import { type DecoratedProcedure } from './procedure-decorated';
8
+ import { DecoratedProcedure } from './procedure-decorated';
9
9
  export type AdaptedRouter<TContext extends Context, TRouter extends ANY_ROUTER> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TContext, U>> : TRouter extends Procedure<any, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
10
10
  [K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TContext, TRouter[K]> : never;
11
11
  };
@@ -1,15 +1,16 @@
1
- import type { ContractProcedure, ContractRouter, ErrorFromErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
2
1
  import type { Hooks, Value } from '@orpc/shared';
3
2
  import type { Lazy } from './lazy';
4
3
  import type { Procedure } from './procedure';
5
- import type { ProcedureClient } from './procedure-client';
4
+ import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
6
5
  import type { Meta } from './types';
7
6
  import { type ANY_ROUTER, type Router } from './router';
8
- export type RouterClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER | ContractRouter> ? RouterClient<U, TClientContext> : TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> | Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? ProcedureClient<TClientContext, SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>, ErrorFromErrorMap<UErrorMap>> : {
9
- [K in keyof TRouter]: TRouter[K] extends ANY_ROUTER | ContractRouter ? RouterClient<TRouter[K], TClientContext> : never;
7
+ /**
8
+ * FIXME: separate RouterClient and ContractRouterClient, don't mix them
9
+ */
10
+ export type RouterClient<TRouter extends ANY_ROUTER, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
11
+ [K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? RouterClient<TRouter[K], TClientContext> : never;
10
12
  };
11
13
  export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
12
- router: TRouter | Lazy<undefined>;
13
14
  /**
14
15
  * This is helpful for logging and analytics.
15
16
  *
@@ -21,5 +22,5 @@ export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
21
22
  } : {
22
23
  context: Value<UContext>;
23
24
  } : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
24
- export declare function createRouterClient<TRouter extends ANY_ROUTER>(options: CreateRouterClientOptions<TRouter>): RouterClient<TRouter, unknown>;
25
+ export declare function createRouterClient<TRouter extends ANY_ROUTER, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
25
26
  //# sourceMappingURL=router-client.d.ts.map
@@ -12,5 +12,5 @@ export type InferRouterInputs<T extends ANY_ROUTER> = T extends Lazy<infer U ext
12
12
  export type InferRouterOutputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
13
13
  [K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterOutputs<T[K]> : never;
14
14
  };
15
- export declare function getRouterChild<T extends ANY_ROUTER | Lazy<undefined>>(router: T, ...path: string[]): T extends ANY_LAZY ? Lazy<ANY_PROCEDURE | Record<string, ANY_ROUTER> | undefined> : ANY_ROUTER | Lazy<undefined> | undefined;
15
+ export declare function getRouterChild<T extends ANY_ROUTER | Lazy<undefined>>(router: T, ...path: string[]): T extends ANY_LAZY ? Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER>> | Lazy<undefined> : ANY_ROUTER | Lazy<undefined> | undefined;
16
16
  //# sourceMappingURL=router.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.28.0",
4
+ "version": "0.29.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -53,8 +53,8 @@
53
53
  "next": ">=14.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@orpc/contract": "0.28.0",
57
- "@orpc/shared": "0.28.0"
56
+ "@orpc/contract": "0.29.0",
57
+ "@orpc/shared": "0.29.0"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsup --onSuccess='tsc -b --noCheck'",