@orpc/server 0.0.0-next.c0088c7 → 0.0.0-next.c0afbea

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 (32) hide show
  1. package/README.md +3 -1
  2. package/dist/adapters/fetch/index.d.mts +3 -3
  3. package/dist/adapters/fetch/index.d.ts +3 -3
  4. package/dist/adapters/fetch/index.mjs +3 -3
  5. package/dist/adapters/hono/index.d.mts +2 -2
  6. package/dist/adapters/hono/index.d.ts +2 -2
  7. package/dist/adapters/hono/index.mjs +3 -3
  8. package/dist/adapters/next/index.d.mts +2 -2
  9. package/dist/adapters/next/index.d.ts +2 -2
  10. package/dist/adapters/next/index.mjs +3 -3
  11. package/dist/adapters/node/index.d.mts +3 -3
  12. package/dist/adapters/node/index.d.ts +3 -3
  13. package/dist/adapters/node/index.mjs +2 -2
  14. package/dist/adapters/standard/index.d.mts +4 -4
  15. package/dist/adapters/standard/index.d.ts +4 -4
  16. package/dist/adapters/standard/index.mjs +2 -2
  17. package/dist/index.d.mts +120 -106
  18. package/dist/index.d.ts +120 -106
  19. package/dist/index.mjs +39 -29
  20. package/dist/plugins/index.d.mts +12 -12
  21. package/dist/plugins/index.d.ts +12 -12
  22. package/dist/plugins/index.mjs +1 -1
  23. package/dist/shared/{server.Drm1Lma3.d.ts → server.CM3tWr3C.d.mts} +12 -14
  24. package/dist/shared/{server.V6zT5iYQ.mjs → server.CMrS28Go.mjs} +124 -157
  25. package/dist/shared/server.CPteJIPP.d.mts +143 -0
  26. package/dist/shared/server.CPteJIPP.d.ts +143 -0
  27. package/dist/shared/{server.DKrKGnk2.mjs → server.CSZRzcSW.mjs} +8 -11
  28. package/dist/shared/{server.BHIDiY4a.mjs → server.Cq3B6PoL.mjs} +1 -1
  29. package/dist/shared/{server.CtBp-i4f.d.mts → server.DmW25ynm.d.ts} +12 -14
  30. package/package.json +7 -7
  31. package/dist/shared/server.ptXwNGQr.d.mts +0 -158
  32. package/dist/shared/server.ptXwNGQr.d.ts +0 -158
@@ -1,31 +1,31 @@
1
- import { a as StandardHandlerInterceptorOptions, P as Plugin, b as StandardHandlerOptions } from '../shared/server.CtBp-i4f.mjs';
2
- export { C as CompositePlugin } from '../shared/server.CtBp-i4f.mjs';
1
+ import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CM3tWr3C.mjs';
2
+ export { C as CompositePlugin } from '../shared/server.CM3tWr3C.mjs';
3
3
  import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.ptXwNGQr.mjs';
4
+ import { C as Context } from '../shared/server.CPteJIPP.mjs';
5
5
  import '@orpc/contract';
6
6
  import '@orpc/standard-server';
7
7
  import '@orpc/client';
8
8
 
9
9
  interface CORSOptions<TContext extends Context> {
10
- origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
- timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
- allowMethods?: string[];
13
- allowHeaders?: string[];
10
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
+ allowMethods?: readonly string[];
13
+ allowHeaders?: readonly string[];
14
14
  maxAge?: number;
15
15
  credentials?: boolean;
16
- exposeHeaders?: string[];
16
+ exposeHeaders?: readonly string[];
17
17
  }
18
- declare class CORSPlugin<TContext extends Context> implements Plugin<TContext> {
18
+ declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
19
19
  private readonly options;
20
- constructor(options?: Partial<CORSOptions<TContext>>);
20
+ constructor(options?: CORSOptions<TContext>);
21
21
  init(options: StandardHandlerOptions<TContext>): void;
22
22
  }
23
23
 
24
24
  interface ResponseHeadersPluginContext {
25
25
  resHeaders?: Headers;
26
26
  }
27
- declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements Plugin<TContext> {
27
+ declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
28
  init(options: StandardHandlerOptions<TContext>): void;
29
29
  }
30
30
 
31
- export { type CORSOptions, CORSPlugin, Plugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
31
+ export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
@@ -1,31 +1,31 @@
1
- import { a as StandardHandlerInterceptorOptions, P as Plugin, b as StandardHandlerOptions } from '../shared/server.Drm1Lma3.js';
2
- export { C as CompositePlugin } from '../shared/server.Drm1Lma3.js';
1
+ import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DmW25ynm.js';
2
+ export { C as CompositePlugin } from '../shared/server.DmW25ynm.js';
3
3
  import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.ptXwNGQr.js';
4
+ import { C as Context } from '../shared/server.CPteJIPP.js';
5
5
  import '@orpc/contract';
6
6
  import '@orpc/standard-server';
7
7
  import '@orpc/client';
8
8
 
9
9
  interface CORSOptions<TContext extends Context> {
10
- origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
- timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
- allowMethods?: string[];
13
- allowHeaders?: string[];
10
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
+ allowMethods?: readonly string[];
13
+ allowHeaders?: readonly string[];
14
14
  maxAge?: number;
15
15
  credentials?: boolean;
16
- exposeHeaders?: string[];
16
+ exposeHeaders?: readonly string[];
17
17
  }
18
- declare class CORSPlugin<TContext extends Context> implements Plugin<TContext> {
18
+ declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
19
19
  private readonly options;
20
- constructor(options?: Partial<CORSOptions<TContext>>);
20
+ constructor(options?: CORSOptions<TContext>);
21
21
  init(options: StandardHandlerOptions<TContext>): void;
22
22
  }
23
23
 
24
24
  interface ResponseHeadersPluginContext {
25
25
  resHeaders?: Headers;
26
26
  }
27
- declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements Plugin<TContext> {
27
+ declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
28
  init(options: StandardHandlerOptions<TContext>): void;
29
29
  }
30
30
 
31
- export { type CORSOptions, CORSPlugin, Plugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
31
+ export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
@@ -3,7 +3,7 @@ import { value } from '@orpc/shared';
3
3
 
4
4
  class CORSPlugin {
5
5
  options;
6
- constructor(options) {
6
+ constructor(options = {}) {
7
7
  const defaults = {
8
8
  origin: (origin) => origin,
9
9
  allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
@@ -1,12 +1,12 @@
1
- import { HTTPPath, Schema, Meta, SchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
1
+ import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
2
  import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
3
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.ptXwNGQr.js';
4
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.CPteJIPP.mjs';
5
5
  import { ORPCError } from '@orpc/client';
6
6
 
7
7
  type StandardParams = Record<string, string>;
8
8
  type StandardMatchResult = {
9
- path: string[];
9
+ path: readonly string[];
10
10
  procedure: AnyProcedure;
11
11
  params?: StandardParams;
12
12
  } | undefined;
@@ -27,9 +27,6 @@ type StandardHandleOptions<T extends Context> = {
27
27
  } : {
28
28
  context: T;
29
29
  });
30
- type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
31
- context: T;
32
- };
33
30
  type StandardHandleResult = {
34
31
  matched: true;
35
32
  response: StandardResponse;
@@ -37,11 +34,12 @@ type StandardHandleResult = {
37
34
  matched: false;
38
35
  response: undefined;
39
36
  };
40
- type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
37
+ type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
38
+ context: T;
41
39
  request: StandardLazyRequest;
42
40
  };
43
41
  interface StandardHandlerOptions<TContext extends Context> {
44
- plugins?: Plugin<TContext>[];
42
+ plugins?: HandlerPlugin<TContext>[];
45
43
  /**
46
44
  * Interceptors at the request level, helpful when you want catch errors
47
45
  */
@@ -54,24 +52,24 @@ interface StandardHandlerOptions<TContext extends Context> {
54
52
  *
55
53
  * Interceptors for procedure client.
56
54
  */
57
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Schema, Record<never, never>, Meta>, SchemaOutput<Schema, unknown>, ErrorFromErrorMap<Record<never, never>>>[];
55
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
58
56
  }
59
57
  declare class StandardHandler<T extends Context> {
60
58
  private readonly matcher;
61
59
  private readonly codec;
62
60
  private readonly options;
63
61
  private readonly plugin;
64
- constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
62
+ constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
65
63
  handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
66
64
  }
67
65
 
68
- interface Plugin<TContext extends Context> {
66
+ interface HandlerPlugin<TContext extends Context> {
69
67
  init?(options: StandardHandlerOptions<TContext>): void;
70
68
  }
71
- declare class CompositePlugin<TContext extends Context> implements Plugin<TContext> {
69
+ declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
72
70
  private readonly plugins;
73
- constructor(plugins?: Plugin<TContext>[]);
71
+ constructor(plugins?: HandlerPlugin<TContext>[]);
74
72
  init(options: StandardHandlerOptions<TContext>): void;
75
73
  }
76
74
 
77
- export { CompositePlugin as C, type Plugin as P, type StandardHandleOptions as S, type WellStandardHandleOptions as W, type StandardHandlerInterceptorOptions as a, type StandardHandlerOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
75
+ export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerInterceptorOptions as a, type StandardHandlerOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
@@ -1,18 +1,31 @@
1
+ import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
1
2
  import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
2
- import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, adaptRoute } from '@orpc/contract';
3
3
  import { value, intercept, toError } from '@orpc/shared';
4
4
 
5
- const LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
6
- function lazy(loader) {
5
+ const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
6
+ function lazy(loader, meta = {}) {
7
7
  return {
8
- [LAZY_LOADER_SYMBOL]: loader
8
+ [LAZY_SYMBOL]: {
9
+ loader,
10
+ meta
11
+ }
9
12
  };
10
13
  }
11
14
  function isLazy(item) {
12
- return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
15
+ return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
16
+ }
17
+ function getLazyMeta(lazied) {
18
+ return lazied[LAZY_SYMBOL].meta;
13
19
  }
14
20
  function unlazy(lazied) {
15
- return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
21
+ return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
22
+ }
23
+
24
+ function mergeMiddlewares(first, second) {
25
+ return [...first, ...second];
26
+ }
27
+ function addMiddleware(middlewares, addition) {
28
+ return [...middlewares, addition];
16
29
  }
17
30
 
18
31
  class Procedure {
@@ -28,52 +41,6 @@ function isProcedure(item) {
28
41
  return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
29
42
  }
30
43
 
31
- function flatLazy(lazied) {
32
- const flattenLoader = async () => {
33
- let current = await unlazy(lazied);
34
- while (true) {
35
- if (!isLazy(current.default)) {
36
- break;
37
- }
38
- current = await unlazy(current.default);
39
- }
40
- return current;
41
- };
42
- return lazy(flattenLoader);
43
- }
44
- function createLazyProcedureFormAnyLazy(lazied) {
45
- const lazyProcedure = lazy(async () => {
46
- const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
47
- if (!isProcedure(maybeProcedure)) {
48
- throw new Error(`
49
- Expected a lazy<procedure> but got lazy<unknown>.
50
- This should be caught by TypeScript compilation.
51
- Please report this issue if this makes you feel uncomfortable.
52
- `);
53
- }
54
- return { default: maybeProcedure };
55
- });
56
- return lazyProcedure;
57
- }
58
-
59
- function dedupeMiddlewares(compare, middlewares) {
60
- let min = 0;
61
- for (let i = 0; i < middlewares.length; i++) {
62
- const index = compare.indexOf(middlewares[i], min);
63
- if (index === -1) {
64
- return middlewares.slice(i);
65
- }
66
- min = index + 1;
67
- }
68
- return [];
69
- }
70
- function mergeMiddlewares(first, second) {
71
- return [...first, ...dedupeMiddlewares(first, second)];
72
- }
73
- function addMiddleware(middlewares, addition) {
74
- return [...middlewares, addition];
75
- }
76
-
77
44
  function createORPCErrorConstructorMap(errors) {
78
45
  const proxy = new Proxy(errors, {
79
46
  get(target, code) {
@@ -205,169 +172,162 @@ async function executeProcedureInternal(procedure, options) {
205
172
  return (await next({})).output;
206
173
  }
207
174
 
208
- const ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
209
- function setRouterContract(obj, contract) {
210
- return new Proxy(obj, {
175
+ const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
176
+ function setHiddenRouterContract(router, contract) {
177
+ return new Proxy(router, {
211
178
  get(target, key) {
212
- if (key === ROUTER_CONTRACT_SYMBOL) {
179
+ if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
213
180
  return contract;
214
181
  }
215
182
  return Reflect.get(target, key);
216
183
  }
217
184
  });
218
185
  }
219
- function getRouterContract(obj) {
220
- return obj[ROUTER_CONTRACT_SYMBOL];
186
+ function getHiddenRouterContract(router) {
187
+ return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
221
188
  }
222
- const LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
223
- function deepSetLazyRouterPrefix(router, prefix) {
224
- return new Proxy(router, {
225
- get(target, key) {
226
- if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
227
- const val = Reflect.get(target, key);
228
- if (isLazy(val)) {
229
- return deepSetLazyRouterPrefix(val, prefix);
230
- }
231
- return val;
232
- }
233
- return prefix;
189
+
190
+ function getRouter(router, path) {
191
+ let current = router;
192
+ for (let i = 0; i < path.length; i++) {
193
+ const segment = path[i];
194
+ if (!current) {
195
+ return void 0;
234
196
  }
235
- });
236
- }
237
- function getLazyRouterPrefix(obj) {
238
- return obj[LAZY_ROUTER_PREFIX_SYMBOL];
197
+ if (isProcedure(current)) {
198
+ return void 0;
199
+ }
200
+ if (!isLazy(current)) {
201
+ current = current[segment];
202
+ continue;
203
+ }
204
+ const lazied = current;
205
+ const rest = path.slice(i);
206
+ return lazy(async () => {
207
+ const unwrapped = await unlazy(lazied);
208
+ const next = getRouter(unwrapped.default, rest);
209
+ return unlazy(next);
210
+ }, getLazyMeta(lazied));
211
+ }
212
+ return current;
239
213
  }
240
-
241
214
  function createAccessibleLazyRouter(lazied) {
242
- const flattenLazy = flatLazy(lazied);
243
- const recursive = new Proxy(flattenLazy, {
215
+ const recursive = new Proxy(lazied, {
244
216
  get(target, key) {
245
217
  if (typeof key !== "string") {
246
218
  return Reflect.get(target, key);
247
219
  }
248
- const next = getRouterChild(flattenLazy, key);
220
+ const next = getRouter(lazied, [key]);
249
221
  return createAccessibleLazyRouter(next);
250
222
  }
251
223
  });
252
224
  return recursive;
253
225
  }
254
-
255
- function adaptRouter(router, options) {
226
+ function enhanceRouter(router, options) {
256
227
  if (isLazy(router)) {
257
- const adapted2 = lazy(async () => {
258
- const unlaziedRouter = (await unlazy(router)).default;
259
- const adapted3 = adaptRouter(unlaziedRouter, options);
260
- return { default: adapted3 };
228
+ const laziedMeta = getLazyMeta(router);
229
+ const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
230
+ const enhanced2 = lazy(async () => {
231
+ const { default: unlaziedRouter } = await unlazy(router);
232
+ const enhanced3 = enhanceRouter(unlaziedRouter, options);
233
+ return unlazy(enhanced3);
234
+ }, {
235
+ ...laziedMeta,
236
+ prefix: enhancedPrefix
261
237
  });
262
- const accessible = createAccessibleLazyRouter(adapted2);
263
- const currentPrefix = getLazyRouterPrefix(router);
264
- const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
265
- if (prefix) {
266
- return deepSetLazyRouterPrefix(accessible, prefix);
267
- }
238
+ const accessible = createAccessibleLazyRouter(enhanced2);
268
239
  return accessible;
269
240
  }
270
241
  if (isProcedure(router)) {
271
242
  const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
272
243
  const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
273
- const adapted2 = new Procedure({
244
+ const enhanced2 = new Procedure({
274
245
  ...router["~orpc"],
275
- route: adaptRoute(router["~orpc"].route, options),
246
+ route: enhanceRoute(router["~orpc"].route, options),
276
247
  errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
277
248
  middlewares: newMiddlewares,
278
249
  inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
279
250
  outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
280
251
  });
281
- return adapted2;
252
+ return enhanced2;
282
253
  }
283
- const adapted = {};
254
+ const enhanced = {};
284
255
  for (const key in router) {
285
- adapted[key] = adaptRouter(router[key], options);
286
- }
287
- return adapted;
288
- }
289
- function getRouterChild(router, ...path) {
290
- let current = router;
291
- for (let i = 0; i < path.length; i++) {
292
- const segment = path[i];
293
- if (!current) {
294
- return void 0;
295
- }
296
- if (isProcedure(current)) {
297
- return void 0;
298
- }
299
- if (!isLazy(current)) {
300
- current = current[segment];
301
- continue;
302
- }
303
- const lazied = current;
304
- const rest = path.slice(i);
305
- const newLazy = lazy(async () => {
306
- const unwrapped = await unlazy(lazied);
307
- if (!unwrapped.default) {
308
- return unwrapped;
309
- }
310
- const next = getRouterChild(unwrapped.default, ...rest);
311
- return { default: next };
312
- });
313
- return flatLazy(newLazy);
256
+ enhanced[key] = enhanceRouter(router[key], options);
314
257
  }
315
- return current;
258
+ return enhanced;
316
259
  }
317
-
318
- function eachContractProcedure(options, callback, laziedOptions = []) {
319
- const hiddenContract = getRouterContract(options.router);
320
- if (hiddenContract) {
321
- return eachContractProcedure(
322
- {
323
- router: hiddenContract,
324
- path: options.path
325
- },
326
- callback,
327
- laziedOptions
328
- );
260
+ function traverseContractProcedures(options, callback, lazyOptions = []) {
261
+ let currentRouter = options.router;
262
+ const hiddenContract = getHiddenRouterContract(options.router);
263
+ if (hiddenContract !== void 0) {
264
+ currentRouter = hiddenContract;
329
265
  }
330
- if (isLazy(options.router)) {
331
- laziedOptions.push({
332
- lazied: options.router,
266
+ if (isLazy(currentRouter)) {
267
+ lazyOptions.push({
268
+ router: currentRouter,
333
269
  path: options.path
334
270
  });
335
- } else if (isContractProcedure(options.router)) {
271
+ } else if (isContractProcedure(currentRouter)) {
336
272
  callback({
337
- contract: options.router,
273
+ contract: currentRouter,
338
274
  path: options.path
339
275
  });
340
276
  } else {
341
- for (const key in options.router) {
342
- eachContractProcedure(
277
+ for (const key in currentRouter) {
278
+ traverseContractProcedures(
343
279
  {
344
- router: options.router[key],
280
+ router: currentRouter[key],
345
281
  path: [...options.path, key]
346
282
  },
347
283
  callback,
348
- laziedOptions
284
+ lazyOptions
349
285
  );
350
286
  }
351
287
  }
352
- return laziedOptions;
288
+ return lazyOptions;
353
289
  }
354
- async function eachAllContractProcedure(options, callback) {
290
+ async function resolveContractProcedures(options, callback) {
355
291
  const pending = [options];
356
- for (const item of pending) {
357
- const lazies = eachContractProcedure(item, callback);
358
- for (const lazy of lazies) {
359
- const { default: router } = await unlazy(lazy.lazied);
292
+ for (const options2 of pending) {
293
+ const lazyOptions = traverseContractProcedures(options2, callback);
294
+ for (const options3 of lazyOptions) {
295
+ const { default: router } = await unlazy(options3.router);
360
296
  pending.push({
361
- path: lazy.path,
362
- router
297
+ router,
298
+ path: options3.path
363
299
  });
364
300
  }
365
301
  }
366
302
  }
367
- function convertPathToHttpPath(path) {
368
- return `/${path.map(encodeURIComponent).join("/")}`;
303
+ async function unlazyRouter(router) {
304
+ if (isProcedure(router)) {
305
+ return router;
306
+ }
307
+ const unlazied = {};
308
+ for (const key in router) {
309
+ const item = router[key];
310
+ const { default: unlaziedRouter } = await unlazy(item);
311
+ unlazied[key] = await unlazyRouter(unlaziedRouter);
312
+ }
313
+ return unlazied;
314
+ }
315
+
316
+ function createAssertedLazyProcedure(lazied) {
317
+ const lazyProcedure = lazy(async () => {
318
+ const { default: maybeProcedure } = await unlazy(lazied);
319
+ if (!isProcedure(maybeProcedure)) {
320
+ throw new Error(`
321
+ Expected a lazy<procedure> but got lazy<unknown>.
322
+ This should be caught by TypeScript compilation.
323
+ Please report this issue if this makes you feel uncomfortable.
324
+ `);
325
+ }
326
+ return { default: maybeProcedure };
327
+ }, getLazyMeta(lazied));
328
+ return lazyProcedure;
369
329
  }
370
- function createContractedProcedure(contract, procedure) {
330
+ function createContractedProcedure(procedure, contract) {
371
331
  return new Procedure({
372
332
  ...procedure["~orpc"],
373
333
  errorMap: contract["~orpc"].errorMap,
@@ -375,5 +335,12 @@ function createContractedProcedure(contract, procedure) {
375
335
  meta: contract["~orpc"].meta
376
336
  });
377
337
  }
338
+ function call(procedure, input, ...rest) {
339
+ return createProcedureClient(procedure, ...rest)(input);
340
+ }
341
+
342
+ function toHttpPath(path) {
343
+ return `/${path.map(encodeURIComponent).join("/")}`;
344
+ }
378
345
 
379
- export { LAZY_LOADER_SYMBOL as L, Procedure as P, convertPathToHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, eachContractProcedure as e, adaptRouter as f, getRouterChild as g, flatLazy as h, isProcedure as i, isLazy as j, createLazyProcedureFormAnyLazy as k, lazy as l, getRouterContract as m, deepSetLazyRouterPrefix as n, getLazyRouterPrefix as o, middlewareOutputFn as p, createAccessibleLazyRouter as q, eachAllContractProcedure as r, setRouterContract as s, unlazy as u };
346
+ export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i, getLazyMeta as j, call as k, lazy as l, middlewareOutputFn as m, getHiddenRouterContract as n, createAccessibleLazyRouter as o, unlazyRouter as p, resolveContractProcedures as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u };