@orpc/server 0.0.0-next.ef3ba82 → 0.0.0-next.f56d2b3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. package/dist/chunk-ESTRJAOX.js +299 -0
  2. package/dist/chunk-KK4SDLC7.js +320 -0
  3. package/dist/chunk-WUOGVGWG.js +1 -0
  4. package/dist/fetch.js +12 -102
  5. package/dist/hono.js +30 -0
  6. package/dist/index.js +320 -322
  7. package/dist/next.js +36 -0
  8. package/dist/node.js +87 -0
  9. package/dist/src/adapters/fetch/index.d.ts +6 -0
  10. package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
  11. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
  12. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
  13. package/dist/src/adapters/fetch/super-json.d.ts +12 -0
  14. package/dist/src/adapters/fetch/types.d.ts +21 -0
  15. package/dist/src/adapters/hono/index.d.ts +3 -0
  16. package/dist/src/adapters/hono/middleware.d.ts +12 -0
  17. package/dist/src/adapters/next/index.d.ts +3 -0
  18. package/dist/src/adapters/next/serve.d.ts +19 -0
  19. package/dist/src/adapters/node/index.d.ts +5 -0
  20. package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
  21. package/dist/src/adapters/node/request-listener.d.ts +28 -0
  22. package/dist/src/adapters/node/types.d.ts +22 -0
  23. package/dist/src/builder-variants.d.ts +74 -0
  24. package/dist/src/builder.d.ts +48 -39
  25. package/dist/src/config.d.ts +6 -0
  26. package/dist/src/context.d.ts +9 -0
  27. package/dist/src/hidden.d.ts +8 -0
  28. package/dist/src/implementer-procedure.d.ts +30 -0
  29. package/dist/src/implementer-variants.d.ts +16 -0
  30. package/dist/src/implementer.d.ts +27 -0
  31. package/dist/src/index.d.ts +17 -10
  32. package/dist/src/lazy-utils.d.ts +6 -0
  33. package/dist/src/lazy.d.ts +22 -0
  34. package/dist/src/middleware-decorated.d.ts +10 -0
  35. package/dist/src/middleware-utils.d.ts +5 -0
  36. package/dist/src/middleware.d.ts +29 -17
  37. package/dist/src/procedure-client.d.ts +20 -0
  38. package/dist/src/procedure-decorated.d.ts +21 -0
  39. package/dist/src/procedure-utils.d.ts +17 -0
  40. package/dist/src/procedure.d.ts +26 -25
  41. package/dist/src/router-accessible-lazy.d.ts +8 -0
  42. package/dist/src/router-client.d.ts +22 -0
  43. package/dist/src/router.d.ts +26 -16
  44. package/package.json +24 -12
  45. package/dist/chunk-CVLK2PBB.js +0 -189
  46. package/dist/src/fetch/handle.d.ts +0 -6
  47. package/dist/src/fetch/handler.d.ts +0 -2
  48. package/dist/src/fetch/index.d.ts +0 -3
  49. package/dist/src/fetch/types.d.ts +0 -34
  50. package/dist/src/procedure-builder.d.ts +0 -30
  51. package/dist/src/procedure-caller.d.ts +0 -18
  52. package/dist/src/procedure-implementer.d.ts +0 -17
  53. package/dist/src/router-builder.d.ts +0 -21
  54. package/dist/src/router-caller.d.ts +0 -21
  55. package/dist/src/router-implementer.d.ts +0 -19
  56. package/dist/src/types.d.ts +0 -7
  57. package/dist/src/utils.d.ts +0 -2
package/dist/index.js CHANGED
@@ -1,393 +1,391 @@
1
1
  import {
2
+ LAZY_LOADER_SYMBOL,
2
3
  Procedure,
3
- createProcedureCaller,
4
- decorateMiddleware,
5
- decorateProcedure,
4
+ adaptRouter,
5
+ addMiddleware,
6
+ createAccessibleLazyRouter,
7
+ createLazyProcedureFormAnyLazy,
8
+ createProcedureClient,
9
+ deepSetLazyRouterPrefix,
10
+ flatLazy,
11
+ getLazyRouterPrefix,
12
+ getRouterChild,
13
+ getRouterContract,
14
+ isLazy,
6
15
  isProcedure,
7
- mergeContext
8
- } from "./chunk-CVLK2PBB.js";
16
+ lazy,
17
+ middlewareOutputFn,
18
+ setRouterContract,
19
+ unlazy
20
+ } from "./chunk-KK4SDLC7.js";
9
21
 
10
22
  // src/builder.ts
11
- import {
12
- ContractProcedure,
13
- isContractProcedure as isContractProcedure2
14
- } from "@orpc/contract";
15
-
16
- // src/procedure-builder.ts
17
- import {
18
- DecoratedContractProcedure
19
- } from "@orpc/contract";
23
+ import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
20
24
 
21
- // src/procedure-implementer.ts
22
- var ProcedureImplementer = class _ProcedureImplementer {
23
- constructor(zz$pi) {
24
- this.zz$pi = zz$pi;
25
- }
26
- use(middleware, mapInput) {
27
- const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
28
- return new _ProcedureImplementer({
29
- ...this.zz$pi,
30
- middlewares: [...this.zz$pi.middlewares ?? [], middleware_]
31
- });
25
+ // src/config.ts
26
+ var DEFAULT_CONFIG = {
27
+ initialInputValidationIndex: 0,
28
+ initialOutputValidationIndex: 0
29
+ };
30
+ function fallbackConfig(key, value) {
31
+ if (value === void 0) {
32
+ return DEFAULT_CONFIG[key];
32
33
  }
33
- func(func) {
34
- return decorateProcedure({
35
- zz$p: {
36
- middlewares: this.zz$pi.middlewares,
37
- contract: this.zz$pi.contract,
38
- func
39
- }
34
+ return value;
35
+ }
36
+
37
+ // src/middleware-decorated.ts
38
+ function decorateMiddleware(middleware) {
39
+ const decorated = middleware;
40
+ decorated.mapInput = (mapInput) => {
41
+ const mapped = decorateMiddleware(
42
+ (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
43
+ );
44
+ return mapped;
45
+ };
46
+ decorated.concat = (concatMiddleware, mapInput) => {
47
+ const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
48
+ const concatted = decorateMiddleware((options, input, output, ...rest) => {
49
+ const next = async (...[nextOptions]) => {
50
+ return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
51
+ };
52
+ const merged = middleware({ ...options, next }, input, output, ...rest);
53
+ return merged;
40
54
  });
41
- }
42
- };
55
+ return concatted;
56
+ };
57
+ return decorated;
58
+ }
43
59
 
44
- // src/procedure-builder.ts
45
- var ProcedureBuilder = class _ProcedureBuilder {
46
- constructor(zz$pb) {
47
- this.zz$pb = zz$pb;
48
- }
49
- /**
50
- * Self chainable
51
- */
52
- route(opts) {
53
- return new _ProcedureBuilder({
54
- ...this.zz$pb,
55
- contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).route(
56
- opts
57
- )
60
+ // src/procedure-decorated.ts
61
+ import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
62
+ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
63
+ errors(errors) {
64
+ return new _DecoratedProcedure({
65
+ ...this["~orpc"],
66
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
58
67
  });
59
68
  }
60
- input(schema, example) {
61
- return new _ProcedureBuilder({
62
- ...this.zz$pb,
63
- contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).input(
64
- schema,
65
- example
66
- )
69
+ meta(meta) {
70
+ return new _DecoratedProcedure({
71
+ ...this["~orpc"],
72
+ meta: mergeMeta(this["~orpc"].meta, meta)
67
73
  });
68
74
  }
69
- output(schema, example) {
70
- return new _ProcedureBuilder({
71
- ...this.zz$pb,
72
- contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).output(
73
- schema,
74
- example
75
- )
75
+ route(route) {
76
+ return new _DecoratedProcedure({
77
+ ...this["~orpc"],
78
+ route: mergeRoute(this["~orpc"].route, route)
76
79
  });
77
80
  }
78
81
  use(middleware, mapInput) {
79
- if (!mapInput) {
80
- return new ProcedureImplementer({
81
- contract: this.zz$pb.contract,
82
- middlewares: this.zz$pb.middlewares
83
- }).use(middleware);
84
- }
85
- return new ProcedureImplementer({
86
- contract: this.zz$pb.contract,
87
- middlewares: this.zz$pb.middlewares
88
- }).use(middleware, mapInput);
82
+ const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
83
+ return new _DecoratedProcedure({
84
+ ...this["~orpc"],
85
+ middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
86
+ });
89
87
  }
90
88
  /**
91
- * Convert to Procedure
89
+ * Make this procedure callable (works like a function while still being a procedure).
92
90
  */
93
- func(func) {
94
- return decorateProcedure({
95
- zz$p: {
96
- middlewares: this.zz$pb.middlewares,
97
- contract: this.zz$pb.contract,
98
- func
99
- }
91
+ callable(...rest) {
92
+ return Object.assign(createProcedureClient(this, ...rest), {
93
+ "~type": "Procedure",
94
+ "~orpc": this["~orpc"]
100
95
  });
101
96
  }
102
- };
103
-
104
- // src/router-builder.ts
105
- import { DecoratedContractProcedure as DecoratedContractProcedure2 } from "@orpc/contract";
106
- var RouterBuilder = class _RouterBuilder {
107
- constructor(zz$rb) {
108
- this.zz$rb = zz$rb;
109
- }
110
- prefix(prefix) {
111
- return new _RouterBuilder({
112
- ...this.zz$rb,
113
- prefix: `${this.zz$rb.prefix ?? ""}${prefix}`
114
- });
115
- }
116
- tags(...tags) {
117
- if (!tags.length)
118
- return this;
119
- return new _RouterBuilder({
120
- ...this.zz$rb,
121
- tags: [...this.zz$rb.tags ?? [], ...tags]
122
- });
123
- }
124
- use(middleware, mapInput) {
125
- const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
126
- return new _RouterBuilder({
127
- ...this.zz$rb,
128
- middlewares: [...this.zz$rb.middlewares || [], middleware_]
129
- });
130
- }
131
- router(router) {
132
- const handled = {};
133
- for (const key in router) {
134
- const item = router[key];
135
- if (isProcedure(item)) {
136
- const builderMiddlewares = this.zz$rb.middlewares ?? [];
137
- const itemMiddlewares = item.zz$p.middlewares ?? [];
138
- const middlewares = [
139
- ...builderMiddlewares,
140
- ...itemMiddlewares.filter(
141
- (item2) => !builderMiddlewares.includes(item2)
142
- )
143
- ];
144
- const contract = DecoratedContractProcedure2.decorate(
145
- item.zz$p.contract
146
- ).addTags(...this.zz$rb.tags ?? []);
147
- handled[key] = decorateProcedure({
148
- zz$p: {
149
- ...item.zz$p,
150
- contract: this.zz$rb.prefix ? contract.prefix(this.zz$rb.prefix) : contract,
151
- middlewares
152
- }
153
- });
154
- } else {
155
- handled[key] = this.router(item);
156
- }
157
- }
158
- return handled;
159
- }
160
- };
161
-
162
- // src/router-implementer.ts
163
- import {
164
- isContractProcedure
165
- } from "@orpc/contract";
166
- var RouterImplementer = class {
167
- constructor(zz$ri) {
168
- this.zz$ri = zz$ri;
169
- }
170
- router(router) {
171
- assertRouterImplementation(this.zz$ri.contract, router);
172
- return router;
97
+ /**
98
+ * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
99
+ */
100
+ actionable(...rest) {
101
+ return this.callable(...rest);
173
102
  }
174
103
  };
175
- function chainRouterImplementer(contract, middlewares) {
176
- const result = {};
177
- for (const key in contract) {
178
- const item = contract[key];
179
- if (isContractProcedure(item)) {
180
- result[key] = new ProcedureImplementer({
181
- contract: item,
182
- middlewares
183
- });
184
- } else {
185
- result[key] = chainRouterImplementer(item, middlewares);
186
- }
187
- }
188
- const implementer = new RouterImplementer({ contract });
189
- return Object.assign(implementer, result);
190
- }
191
- function assertRouterImplementation(contract, router, path = []) {
192
- for (const key in contract) {
193
- const currentPath = [...path, key];
194
- const contractItem = contract[key];
195
- const routerItem = router[key];
196
- if (!routerItem) {
197
- throw new Error(
198
- `Missing implementation for procedure at [${currentPath.join(".")}]`
199
- );
200
- }
201
- if (isContractProcedure(contractItem)) {
202
- if (isProcedure(routerItem)) {
203
- if (routerItem.zz$p.contract !== contractItem) {
204
- throw new Error(
205
- `Mismatch implementation for procedure at [${currentPath.join(".")}]`
206
- );
207
- }
208
- } else {
209
- throw new Error(
210
- `Mismatch implementation for procedure at [${currentPath.join(".")}]`
211
- );
212
- }
213
- } else {
214
- assertRouterImplementation(
215
- contractItem,
216
- routerItem,
217
- currentPath
218
- );
219
- }
220
- }
221
- }
222
104
 
223
105
  // src/builder.ts
224
106
  var Builder = class _Builder {
225
- constructor(zz$b = {}) {
226
- this.zz$b = zz$b;
107
+ "~orpc";
108
+ constructor(def) {
109
+ this["~orpc"] = def;
227
110
  }
228
111
  /**
229
- * Self chainable
112
+ * Reset config
230
113
  */
231
- context() {
232
- return this;
233
- }
234
- use(middleware, mapInput) {
235
- const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
114
+ $config(config) {
115
+ const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
116
+ const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
236
117
  return new _Builder({
237
- ...this.zz$b,
238
- middlewares: [...this.zz$b.middlewares || [], middleware_]
118
+ ...this["~orpc"],
119
+ config,
120
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
121
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
239
122
  });
240
123
  }
241
124
  /**
242
- * Convert to ContractProcedureBuilder
125
+ * Reset initial context
243
126
  */
244
- route(opts) {
245
- return new ProcedureBuilder({
246
- middlewares: this.zz$b.middlewares,
247
- contract: new ContractProcedure({
248
- ...opts,
249
- InputSchema: void 0,
250
- OutputSchema: void 0
251
- })
252
- });
253
- }
254
- input(schema, example) {
255
- return new ProcedureBuilder({
256
- middlewares: this.zz$b.middlewares,
257
- contract: new ContractProcedure({
258
- OutputSchema: void 0,
259
- InputSchema: schema,
260
- inputExample: example
261
- })
262
- });
263
- }
264
- output(schema, example) {
265
- return new ProcedureBuilder({
266
- middlewares: this.zz$b.middlewares,
267
- contract: new ContractProcedure({
268
- InputSchema: void 0,
269
- OutputSchema: schema,
270
- outputExample: example
271
- })
127
+ $context() {
128
+ return new _Builder({
129
+ ...this["~orpc"],
130
+ middlewares: [],
131
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
132
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
272
133
  });
273
134
  }
274
135
  /**
275
- * Convert to Procedure
136
+ * Reset initial meta
276
137
  */
277
- func(func) {
278
- return decorateProcedure({
279
- zz$p: {
280
- middlewares: this.zz$b.middlewares,
281
- contract: new ContractProcedure({
282
- InputSchema: void 0,
283
- OutputSchema: void 0
284
- }),
285
- func
286
- }
138
+ $meta(initialMeta) {
139
+ return new _Builder({
140
+ ...this["~orpc"],
141
+ meta: initialMeta
287
142
  });
288
143
  }
289
144
  /**
290
- * Convert to ProcedureImplementer | RouterBuilder
145
+ * Reset initial route
291
146
  */
292
- contract(contract) {
293
- if (isContractProcedure2(contract)) {
294
- return new ProcedureImplementer({
295
- contract,
296
- middlewares: this.zz$b.middlewares
297
- });
298
- }
299
- return chainRouterImplementer(
300
- contract,
301
- this.zz$b.middlewares
302
- );
147
+ $route(initialRoute) {
148
+ return new _Builder({
149
+ ...this["~orpc"],
150
+ route: initialRoute
151
+ });
303
152
  }
304
- /**
305
- * Create ExtendedMiddleware
306
- */
307
- // TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
308
- // solution (maybe): create new generic for .output() method
309
153
  middleware(middleware) {
310
154
  return decorateMiddleware(middleware);
311
155
  }
156
+ errors(errors) {
157
+ return new _Builder({
158
+ ...this["~orpc"],
159
+ errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
160
+ });
161
+ }
162
+ use(middleware, mapInput) {
163
+ const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
164
+ return new _Builder({
165
+ ...this["~orpc"],
166
+ middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
167
+ });
168
+ }
169
+ meta(meta) {
170
+ return new _Builder({
171
+ ...this["~orpc"],
172
+ meta: mergeMeta2(this["~orpc"].meta, meta)
173
+ });
174
+ }
175
+ route(route) {
176
+ return new _Builder({
177
+ ...this["~orpc"],
178
+ route: mergeRoute2(this["~orpc"].route, route)
179
+ });
180
+ }
181
+ input(schema) {
182
+ return new _Builder({
183
+ ...this["~orpc"],
184
+ inputSchema: schema,
185
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
186
+ });
187
+ }
188
+ output(schema) {
189
+ return new _Builder({
190
+ ...this["~orpc"],
191
+ outputSchema: schema,
192
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
193
+ });
194
+ }
195
+ handler(handler) {
196
+ return new DecoratedProcedure({
197
+ ...this["~orpc"],
198
+ handler
199
+ });
200
+ }
312
201
  prefix(prefix) {
313
- return new RouterBuilder({
314
- ...this.zz$b,
315
- prefix
202
+ return new _Builder({
203
+ ...this["~orpc"],
204
+ prefix: mergePrefix(this["~orpc"].prefix, prefix)
316
205
  });
317
206
  }
318
- tags(...tags) {
319
- return new RouterBuilder({
320
- ...this.zz$b,
321
- tags
207
+ tag(...tags) {
208
+ return new _Builder({
209
+ ...this["~orpc"],
210
+ tags: mergeTags(this["~orpc"].tags, tags)
322
211
  });
323
212
  }
324
- /**
325
- * Create DecoratedRouter
326
- */
327
213
  router(router) {
328
- return new RouterBuilder(this.zz$b).router(router);
214
+ return adaptRouter(router, this["~orpc"]);
215
+ }
216
+ lazy(loader) {
217
+ return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
329
218
  }
330
219
  };
220
+ var os = new Builder({
221
+ config: {},
222
+ route: {},
223
+ meta: {},
224
+ errorMap: {},
225
+ inputSchema: void 0,
226
+ outputSchema: void 0,
227
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
228
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
229
+ middlewares: []
230
+ });
331
231
 
332
- // src/router.ts
333
- import {
334
- isContractProcedure as isContractProcedure3
335
- } from "@orpc/contract";
336
- function toContractRouter(router) {
337
- const contract = {};
338
- for (const key in router) {
339
- const item = router[key];
340
- if (isContractProcedure3(item)) {
341
- contract[key] = item;
342
- } else if (isProcedure(item)) {
343
- contract[key] = item.zz$p.contract;
344
- } else {
345
- contract[key] = toContractRouter(item);
232
+ // src/context.ts
233
+ function mergeContext(context, other) {
234
+ return { ...context, ...other };
235
+ }
236
+
237
+ // src/implementer.ts
238
+ import { isContractProcedure } from "@orpc/contract";
239
+ function implementerInternal(contract, config, middlewares) {
240
+ if (isContractProcedure(contract)) {
241
+ const impl2 = new Builder({
242
+ ...contract["~orpc"],
243
+ config,
244
+ middlewares,
245
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
246
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
247
+ });
248
+ return impl2;
249
+ }
250
+ const impl = new Proxy(contract, {
251
+ get: (target, key) => {
252
+ let method;
253
+ if (key === "middleware") {
254
+ method = (mid) => decorateMiddleware(mid);
255
+ } else if (key === "use") {
256
+ method = (mid) => {
257
+ return implementerInternal(
258
+ contract,
259
+ config,
260
+ addMiddleware(middlewares, mid)
261
+ );
262
+ };
263
+ } else if (key === "router") {
264
+ method = (router) => {
265
+ const adapted = adaptRouter(router, {
266
+ middlewares,
267
+ errorMap: {}
268
+ });
269
+ return setRouterContract(adapted, contract);
270
+ };
271
+ } else if (key === "lazy") {
272
+ method = (loader) => {
273
+ const adapted = adaptRouter(flatLazy(lazy(loader)), {
274
+ middlewares,
275
+ errorMap: {}
276
+ });
277
+ return setRouterContract(adapted, contract);
278
+ };
279
+ }
280
+ const next = Reflect.get(target, key);
281
+ if (!next || typeof next !== "function" && typeof next !== "object") {
282
+ return method ?? next;
283
+ }
284
+ const nextImpl = implementerInternal(next, config, middlewares);
285
+ if (method) {
286
+ return new Proxy(method, {
287
+ get(_, key2) {
288
+ return Reflect.get(nextImpl, key2);
289
+ }
290
+ });
291
+ }
292
+ return nextImpl;
346
293
  }
347
- }
348
- return contract;
294
+ });
295
+ return impl;
296
+ }
297
+ function implement(contract, config = {}) {
298
+ const implInternal = implementerInternal(contract, config, []);
299
+ const impl = new Proxy(implInternal, {
300
+ get: (target, key) => {
301
+ let method;
302
+ if (key === "$context") {
303
+ method = () => impl;
304
+ } else if (key === "$config") {
305
+ method = (config2) => implement(contract, config2);
306
+ }
307
+ const next = Reflect.get(target, key);
308
+ if (!next || typeof next !== "function" && typeof next !== "object") {
309
+ return method ?? next;
310
+ }
311
+ if (method) {
312
+ return new Proxy(method, {
313
+ get(_, key2) {
314
+ return Reflect.get(next, key2);
315
+ }
316
+ });
317
+ }
318
+ return next;
319
+ }
320
+ });
321
+ return impl;
349
322
  }
350
323
 
351
- // src/router-caller.ts
352
- function createRouterCaller(options) {
353
- const caller = {};
354
- for (const key in options.router) {
355
- const path = [...options.basePath ?? [], key];
356
- const item = options.router[key];
357
- if (isProcedure(item)) {
358
- caller[key] = createProcedureCaller({
359
- procedure: item,
360
- context: options.context,
361
- path
362
- });
363
- } else {
364
- caller[key] = createRouterCaller({
365
- router: item,
366
- context: options.context,
367
- basePath: path
324
+ // src/procedure-utils.ts
325
+ function call(procedure, input, ...rest) {
326
+ return createProcedureClient(procedure, ...rest)(input);
327
+ }
328
+
329
+ // src/router-client.ts
330
+ function createRouterClient(router, ...rest) {
331
+ if (isProcedure(router)) {
332
+ const caller = createProcedureClient(router, ...rest);
333
+ return caller;
334
+ }
335
+ const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
336
+ const recursive = new Proxy(procedureCaller, {
337
+ get(target, key) {
338
+ if (typeof key !== "string") {
339
+ return Reflect.get(target, key);
340
+ }
341
+ const next = getRouterChild(router, key);
342
+ if (!next) {
343
+ return Reflect.get(target, key);
344
+ }
345
+ const [options] = rest;
346
+ return createRouterClient(next, {
347
+ ...options,
348
+ path: [...options?.path ?? [], key]
368
349
  });
369
350
  }
370
- }
371
- return caller;
351
+ });
352
+ return recursive;
372
353
  }
373
354
 
374
355
  // src/index.ts
375
- export * from "@orpc/shared/error";
376
- var os = new Builder();
356
+ import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
377
357
  export {
378
358
  Builder,
359
+ DecoratedProcedure,
360
+ LAZY_LOADER_SYMBOL,
361
+ ORPCError,
379
362
  Procedure,
380
- ProcedureBuilder,
381
- ProcedureImplementer,
382
- RouterImplementer,
383
- assertRouterImplementation,
384
- chainRouterImplementer,
385
- createProcedureCaller,
386
- createRouterCaller,
363
+ ValidationError,
364
+ adaptRouter,
365
+ call,
366
+ createAccessibleLazyRouter,
367
+ createLazyProcedureFormAnyLazy,
368
+ createProcedureClient,
369
+ createRouterClient,
387
370
  decorateMiddleware,
388
- decorateProcedure,
371
+ deepSetLazyRouterPrefix,
372
+ fallbackConfig,
373
+ flatLazy,
374
+ getLazyRouterPrefix,
375
+ getRouterChild,
376
+ getRouterContract,
377
+ implement,
378
+ implementerInternal,
379
+ isDefinedError,
380
+ isLazy,
389
381
  isProcedure,
382
+ lazy,
390
383
  mergeContext,
384
+ middlewareOutputFn,
391
385
  os,
392
- toContractRouter
386
+ safe,
387
+ setRouterContract,
388
+ type,
389
+ unlazy
393
390
  };
391
+ //# sourceMappingURL=index.js.map