@orpc/server 0.0.0-next.c59d67c → 0.0.0-next.caefe3a

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