@orpc/server 0.16.0 → 0.17.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.
package/dist/index.js CHANGED
@@ -1,308 +1,396 @@
1
1
  import {
2
2
  LAZY_LOADER_SYMBOL,
3
3
  Procedure,
4
- createFlattenLazy,
5
- createLazy,
6
- createProcedureCaller,
7
- decorateLazy,
8
- decorateMiddleware,
9
- decorateProcedure,
4
+ createProcedureClient,
5
+ flatLazy,
6
+ getRouterChild,
10
7
  isLazy,
11
8
  isProcedure,
12
- loadLazy,
13
- loadProcedure,
14
- mergeContext
15
- } from "./chunk-Z2PQ6UAM.js";
9
+ lazy,
10
+ mergeContext,
11
+ unlazy
12
+ } from "./chunk-FN62GL22.js";
16
13
 
17
14
  // src/builder.ts
18
- import {
19
- ContractProcedure,
20
- isContractProcedure as isContractProcedure2
21
- } from "@orpc/contract";
15
+ import { ContractProcedure } from "@orpc/contract";
22
16
 
23
- // src/procedure-builder.ts
24
- import {
25
- DecoratedContractProcedure as DecoratedContractProcedure2
26
- } from "@orpc/contract";
17
+ // src/implementer-chainable.ts
18
+ import { isContractProcedure } from "@orpc/contract";
19
+ import { createCallableObject } from "@orpc/shared";
27
20
 
28
- // src/router-builder.ts
29
- import { DecoratedContractProcedure, prefixHTTPPath } from "@orpc/contract";
21
+ // src/middleware-decorated.ts
22
+ function decorateMiddleware(middleware) {
23
+ const decorated = middleware;
24
+ decorated.mapInput = (mapInput) => {
25
+ const mapped = decorateMiddleware(
26
+ (input, ...rest) => middleware(mapInput(input), ...rest)
27
+ );
28
+ return mapped;
29
+ };
30
+ decorated.concat = (concatMiddleware, mapInput) => {
31
+ const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
32
+ const concatted = decorateMiddleware((input, context, meta, ...rest) => {
33
+ const next = async (options) => {
34
+ return mapped(input, mergeContext(context, options.context), meta, ...rest);
35
+ };
36
+ const merged = middleware(input, context, { ...meta, next }, ...rest);
37
+ return merged;
38
+ });
39
+ return concatted;
40
+ };
41
+ return decorated;
42
+ }
43
+
44
+ // src/procedure-decorated.ts
45
+ import { DecoratedContractProcedure } from "@orpc/contract";
46
+ function decorateProcedure(procedure) {
47
+ const caller = createProcedureClient({
48
+ procedure,
49
+ context: void 0
50
+ });
51
+ const decorated = caller;
52
+ decorated["~type"] = procedure["~type"];
53
+ decorated["~orpc"] = procedure["~orpc"];
54
+ decorated.prefix = (prefix) => {
55
+ return decorateProcedure(new Procedure({
56
+ ...procedure["~orpc"],
57
+ contract: DecoratedContractProcedure.decorate(procedure["~orpc"].contract).prefix(prefix)
58
+ }));
59
+ };
60
+ decorated.route = (route) => {
61
+ return decorateProcedure(new Procedure({
62
+ ...procedure["~orpc"],
63
+ contract: DecoratedContractProcedure.decorate(procedure["~orpc"].contract).route(route)
64
+ }));
65
+ };
66
+ decorated.use = (middleware, mapInput) => {
67
+ const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
68
+ return decorateProcedure(new Procedure({
69
+ ...procedure["~orpc"],
70
+ middlewares: [...procedure["~orpc"].middlewares ?? [], middleware_]
71
+ }));
72
+ };
73
+ decorated.unshiftTag = (...tags) => {
74
+ return decorateProcedure(new Procedure({
75
+ ...procedure["~orpc"],
76
+ contract: DecoratedContractProcedure.decorate(procedure["~orpc"].contract).unshiftTag(...tags)
77
+ }));
78
+ };
79
+ decorated.unshiftMiddleware = (...middlewares) => {
80
+ if (procedure["~orpc"].middlewares?.length) {
81
+ let min = 0;
82
+ for (let i = 0; i < procedure["~orpc"].middlewares.length; i++) {
83
+ const index = middlewares.indexOf(procedure["~orpc"].middlewares[i], min);
84
+ if (index === -1) {
85
+ middlewares.push(...procedure["~orpc"].middlewares.slice(i));
86
+ break;
87
+ }
88
+ min = index + 1;
89
+ }
90
+ }
91
+ return decorateProcedure(new Procedure({
92
+ ...procedure["~orpc"],
93
+ middlewares
94
+ }));
95
+ };
96
+ return decorated;
97
+ }
98
+
99
+ // src/procedure-implementer.ts
100
+ var ProcedureImplementer = class _ProcedureImplementer {
101
+ "~type" = "ProcedureImplementer";
102
+ "~orpc";
103
+ constructor(def) {
104
+ this["~orpc"] = def;
105
+ }
106
+ use(middleware, mapInput) {
107
+ const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
108
+ return new _ProcedureImplementer({
109
+ ...this["~orpc"],
110
+ middlewares: [...this["~orpc"].middlewares ?? [], mappedMiddleware]
111
+ });
112
+ }
113
+ func(func) {
114
+ return decorateProcedure(new Procedure({
115
+ middlewares: this["~orpc"].middlewares,
116
+ contract: this["~orpc"].contract,
117
+ func
118
+ }));
119
+ }
120
+ };
121
+
122
+ // src/hidden.ts
123
+ var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
124
+ function setRouterContract(obj, contract) {
125
+ return new Proxy(obj, {
126
+ get(target, key) {
127
+ if (key === ROUTER_CONTRACT_SYMBOL) {
128
+ return contract;
129
+ }
130
+ return Reflect.get(target, key);
131
+ }
132
+ });
133
+ }
134
+ function getRouterContract(obj) {
135
+ return obj[ROUTER_CONTRACT_SYMBOL];
136
+ }
30
137
  var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
138
+ function deepSetLazyRouterPrefix(router, prefix) {
139
+ return new Proxy(router, {
140
+ get(target, key) {
141
+ if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
142
+ const val = Reflect.get(target, key);
143
+ if (val && (typeof val === "object" || typeof val === "function")) {
144
+ return deepSetLazyRouterPrefix(val, prefix);
145
+ }
146
+ return val;
147
+ }
148
+ return prefix;
149
+ }
150
+ });
151
+ }
152
+ function getLazyRouterPrefix(obj) {
153
+ return obj[LAZY_ROUTER_PREFIX_SYMBOL];
154
+ }
155
+
156
+ // src/lazy-utils.ts
157
+ function createLazyProcedureFormAnyLazy(lazied) {
158
+ const lazyProcedure = lazy(async () => {
159
+ const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
160
+ if (!isProcedure(maybeProcedure)) {
161
+ throw new Error(`
162
+ Expected a lazy<procedure> but got lazy<unknown>.
163
+ This should be caught by TypeScript compilation.
164
+ Please report this issue if this makes you feel uncomfortable.
165
+ `);
166
+ }
167
+ return { default: maybeProcedure };
168
+ });
169
+ return lazyProcedure;
170
+ }
171
+
172
+ // src/lazy-decorated.ts
173
+ function decorateLazy(lazied) {
174
+ const flattenLazy = flatLazy(lazied);
175
+ const procedureProcedureClient = createProcedureClient({
176
+ procedure: createLazyProcedureFormAnyLazy(flattenLazy),
177
+ context: void 0
178
+ });
179
+ Object.assign(procedureProcedureClient, flattenLazy);
180
+ const recursive = new Proxy(procedureProcedureClient, {
181
+ get(target, key) {
182
+ if (typeof key !== "string") {
183
+ return Reflect.get(target, key);
184
+ }
185
+ const next = getRouterChild(flattenLazy, key);
186
+ return decorateLazy(next);
187
+ }
188
+ });
189
+ return recursive;
190
+ }
191
+
192
+ // src/router-builder.ts
31
193
  var RouterBuilder = class _RouterBuilder {
32
- constructor(zz$rb) {
33
- this.zz$rb = zz$rb;
34
- if (zz$rb.prefix && zz$rb.prefix.includes("{")) {
35
- throw new Error('Prefix cannot contain "{" for dynamic routing');
194
+ "~type" = "RouterBuilder";
195
+ "~orpc";
196
+ constructor(def) {
197
+ this["~orpc"] = def;
198
+ if (def.prefix && def.prefix.includes("{")) {
199
+ throw new Error(`
200
+ Dynamic routing in prefix not supported yet.
201
+ Please remove "{" from "${def.prefix}".
202
+ `);
36
203
  }
37
204
  }
38
205
  prefix(prefix) {
39
206
  return new _RouterBuilder({
40
- ...this.zz$rb,
41
- prefix: `${this.zz$rb.prefix ?? ""}${prefix}`
207
+ ...this["~orpc"],
208
+ prefix: `${this["~orpc"].prefix ?? ""}${prefix}`
42
209
  });
43
210
  }
44
- tags(...tags) {
45
- if (!tags.length)
46
- return this;
211
+ tag(...tags) {
47
212
  return new _RouterBuilder({
48
- ...this.zz$rb,
49
- tags: [...this.zz$rb.tags ?? [], ...tags]
213
+ ...this["~orpc"],
214
+ tags: [...this["~orpc"].tags ?? [], ...tags]
50
215
  });
51
216
  }
52
- use(middleware, mapInput) {
53
- const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
217
+ use(middleware) {
54
218
  return new _RouterBuilder({
55
- ...this.zz$rb,
56
- middlewares: [...this.zz$rb.middlewares || [], middleware_]
219
+ ...this["~orpc"],
220
+ middlewares: [...this["~orpc"].middlewares ?? [], middleware]
57
221
  });
58
222
  }
59
223
  router(router) {
60
- const handled = adaptRouter({
61
- routerOrChild: router,
62
- middlewares: this.zz$rb.middlewares,
63
- tags: this.zz$rb.tags,
64
- prefix: this.zz$rb.prefix
65
- });
66
- return handled;
224
+ const adapted = adapt(router, this["~orpc"]);
225
+ return adapted;
67
226
  }
68
227
  lazy(loader) {
69
- const lazy = adaptLazyRouter({
70
- current: createLazy(loader),
71
- middlewares: this.zz$rb.middlewares,
72
- tags: this.zz$rb.tags,
73
- prefix: this.zz$rb.prefix
74
- });
75
- return lazy;
228
+ const adapted = adapt(flatLazy(lazy(loader)), this["~orpc"]);
229
+ return adapted;
76
230
  }
77
231
  };
78
- function adaptRouter(options) {
79
- if (isProcedure(options.routerOrChild)) {
80
- return adaptProcedure({
81
- ...options,
82
- procedure: options.routerOrChild
83
- });
84
- }
85
- if (isLazy(options.routerOrChild)) {
86
- return adaptLazyRouter({
87
- ...options,
88
- current: options.routerOrChild
89
- });
90
- }
91
- const handled = {};
92
- for (const key in options.routerOrChild) {
93
- handled[key] = adaptRouter({
94
- ...options,
95
- routerOrChild: options.routerOrChild[key]
96
- });
97
- }
98
- return handled;
99
- }
100
- function adaptLazyRouter(options) {
101
- const loader = async () => {
102
- const current = (await loadLazy(options.current)).default;
103
- return {
104
- default: adaptRouter({
105
- ...options,
106
- routerOrChild: current
107
- })
108
- };
109
- };
110
- let lazyRouterPrefix = options.prefix;
111
- if (LAZY_ROUTER_PREFIX_SYMBOL in options.current && typeof options.current[LAZY_ROUTER_PREFIX_SYMBOL] === "string") {
112
- lazyRouterPrefix = lazyRouterPrefix ? prefixHTTPPath(options.current[LAZY_ROUTER_PREFIX_SYMBOL], lazyRouterPrefix) : options.current[LAZY_ROUTER_PREFIX_SYMBOL];
232
+ function adapt(item, options) {
233
+ if (isLazy(item)) {
234
+ const adaptedLazy = decorateLazy(lazy(async () => {
235
+ const routerOrProcedure = (await unlazy(item)).default;
236
+ const adapted2 = adapt(routerOrProcedure, options);
237
+ return { default: adapted2 };
238
+ }));
239
+ const lazyPrefix = getLazyRouterPrefix(item);
240
+ if (options.prefix || lazyPrefix) {
241
+ const prefixed = deepSetLazyRouterPrefix(adaptedLazy, `${options.prefix ?? ""}${lazyPrefix ?? ""}`);
242
+ return prefixed;
243
+ }
244
+ return adaptedLazy;
113
245
  }
114
- const decoratedLazy = Object.assign(decorateLazy(createLazy(loader)), {
115
- [LAZY_ROUTER_PREFIX_SYMBOL]: lazyRouterPrefix
116
- });
117
- const recursive = new Proxy(decoratedLazy, {
118
- get(target, key) {
119
- if (typeof key !== "string") {
120
- return Reflect.get(target, key);
121
- }
122
- return adaptLazyRouter({
123
- ...options,
124
- current: createLazy(async () => {
125
- const current = (await loadLazy(options.current)).default;
126
- return { default: current[key] };
127
- })
128
- });
246
+ if (isProcedure(item)) {
247
+ let decorated = decorateProcedure(item);
248
+ if (options.tags?.length) {
249
+ decorated = decorated.unshiftTag(...options.tags);
129
250
  }
130
- });
131
- return recursive;
132
- }
133
- function adaptProcedure(options) {
134
- const builderMiddlewares = options.middlewares ?? [];
135
- const procedureMiddlewares = options.procedure.zz$p.middlewares ?? [];
136
- const middlewares = [
137
- ...builderMiddlewares,
138
- ...procedureMiddlewares.filter(
139
- (item) => !builderMiddlewares.includes(item)
140
- )
141
- ];
142
- let contract = DecoratedContractProcedure.decorate(
143
- options.procedure.zz$p.contract
144
- ).addTags(...options.tags ?? []);
145
- if (options.prefix) {
146
- contract = contract.prefix(options.prefix);
147
- }
148
- return decorateProcedure({
149
- zz$p: {
150
- ...options.procedure.zz$p,
151
- contract,
152
- middlewares
251
+ if (options.prefix) {
252
+ decorated = decorated.prefix(options.prefix);
153
253
  }
154
- });
254
+ if (options.middlewares?.length) {
255
+ decorated = decorated.unshiftMiddleware(...options.middlewares);
256
+ }
257
+ return decorated;
258
+ }
259
+ const adapted = {};
260
+ for (const key in item) {
261
+ adapted[key] = adapt(item[key], options);
262
+ }
263
+ return adapted;
155
264
  }
156
265
 
157
- // src/procedure-implementer.ts
158
- var ProcedureImplementer = class _ProcedureImplementer {
159
- constructor(zz$pi) {
160
- this.zz$pi = zz$pi;
161
- }
162
- use(middleware, mapInput) {
163
- const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
164
- return new _ProcedureImplementer({
165
- ...this.zz$pi,
166
- middlewares: [...this.zz$pi.middlewares ?? [], middleware_]
266
+ // src/router-implementer.ts
267
+ var RouterImplementer = class _RouterImplementer {
268
+ "~type" = "RouterImplementer";
269
+ "~orpc";
270
+ constructor(def) {
271
+ this["~orpc"] = def;
272
+ }
273
+ use(middleware) {
274
+ return new _RouterImplementer({
275
+ ...this["~orpc"],
276
+ middlewares: [...this["~orpc"].middlewares ?? [], middleware]
167
277
  });
168
278
  }
169
- func(func) {
170
- return decorateProcedure({
171
- zz$p: {
172
- middlewares: this.zz$pi.middlewares,
173
- contract: this.zz$pi.contract,
174
- func
175
- }
176
- });
279
+ router(router) {
280
+ const adapted = new RouterBuilder(this["~orpc"]).router(router);
281
+ const contracted = setRouterContract(adapted, this["~orpc"].contract);
282
+ return contracted;
177
283
  }
178
284
  lazy(loader) {
179
- return new RouterBuilder(this.zz$pi).lazy(loader);
285
+ const adapted = new RouterBuilder(this["~orpc"]).lazy(loader);
286
+ const contracted = setRouterContract(adapted, this["~orpc"].contract);
287
+ return contracted;
180
288
  }
181
289
  };
182
290
 
291
+ // src/implementer-chainable.ts
292
+ function createChainableImplementer(contract, middlewares) {
293
+ if (isContractProcedure(contract)) {
294
+ const implementer = new ProcedureImplementer({
295
+ contract,
296
+ middlewares
297
+ });
298
+ return implementer;
299
+ }
300
+ const chainable = {};
301
+ for (const key in contract) {
302
+ chainable[key] = createChainableImplementer(contract[key], middlewares);
303
+ }
304
+ const routerImplementer = new RouterImplementer({ contract, middlewares });
305
+ const merged = new Proxy(chainable, {
306
+ get(target, key) {
307
+ const next = Reflect.get(target, key);
308
+ const method = Reflect.get(routerImplementer, key);
309
+ if (typeof key !== "string" || typeof method !== "function") {
310
+ return next;
311
+ }
312
+ if (!next) {
313
+ return method.bind(routerImplementer);
314
+ }
315
+ return createCallableObject(next, method.bind(routerImplementer));
316
+ }
317
+ });
318
+ return merged;
319
+ }
320
+
183
321
  // src/procedure-builder.ts
322
+ import {
323
+ DecoratedContractProcedure as DecoratedContractProcedure2
324
+ } from "@orpc/contract";
184
325
  var ProcedureBuilder = class _ProcedureBuilder {
185
- constructor(zz$pb) {
186
- this.zz$pb = zz$pb;
326
+ "~type" = "ProcedureBuilder";
327
+ "~orpc";
328
+ constructor(def) {
329
+ this["~orpc"] = def;
187
330
  }
188
- /**
189
- * Self chainable
190
- */
191
- route(opts) {
331
+ route(route) {
192
332
  return new _ProcedureBuilder({
193
- ...this.zz$pb,
194
- contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).route(
195
- opts
196
- )
333
+ ...this["~orpc"],
334
+ contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).route(route)
197
335
  });
198
336
  }
199
337
  input(schema, example) {
200
338
  return new _ProcedureBuilder({
201
- ...this.zz$pb,
202
- contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).input(
203
- schema,
204
- example
205
- )
339
+ ...this["~orpc"],
340
+ contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).input(schema, example)
206
341
  });
207
342
  }
208
343
  output(schema, example) {
209
344
  return new _ProcedureBuilder({
210
- ...this.zz$pb,
211
- contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).output(
212
- schema,
213
- example
214
- )
345
+ ...this["~orpc"],
346
+ contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
215
347
  });
216
348
  }
217
349
  use(middleware, mapInput) {
218
350
  if (!mapInput) {
219
351
  return new ProcedureImplementer({
220
- contract: this.zz$pb.contract,
221
- middlewares: this.zz$pb.middlewares
352
+ contract: this["~orpc"].contract,
353
+ middlewares: this["~orpc"].middlewares
222
354
  }).use(middleware);
223
355
  }
224
356
  return new ProcedureImplementer({
225
- contract: this.zz$pb.contract,
226
- middlewares: this.zz$pb.middlewares
357
+ contract: this["~orpc"].contract,
358
+ middlewares: this["~orpc"].middlewares
227
359
  }).use(middleware, mapInput);
228
360
  }
229
- /**
230
- * Convert to Procedure
231
- */
232
361
  func(func) {
233
- return decorateProcedure({
234
- zz$p: {
235
- middlewares: this.zz$pb.middlewares,
236
- contract: this.zz$pb.contract,
237
- func
238
- }
239
- });
362
+ return decorateProcedure(new Procedure({
363
+ middlewares: this["~orpc"].middlewares,
364
+ contract: this["~orpc"].contract,
365
+ func
366
+ }));
240
367
  }
241
368
  };
242
369
 
243
- // src/router-implementer.ts
244
- import { isContractProcedure } from "@orpc/contract";
245
- var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
246
- var RouterImplementer = class {
247
- constructor(zz$ri) {
248
- this.zz$ri = zz$ri;
249
- }
250
- router(router) {
251
- return Object.assign(new RouterBuilder({}).router(router), {
252
- [ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
253
- });
254
- }
255
- lazy(loader) {
256
- const lazy = createLazy(loader);
257
- const decorated = decorateLazy(lazy);
258
- return Object.assign(decorated, {
259
- [ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
260
- });
261
- }
262
- };
263
- function chainRouterImplementer(contract, middlewares) {
264
- const result = {};
265
- for (const key in contract) {
266
- const item = contract[key];
267
- if (isContractProcedure(item)) {
268
- result[key] = new ProcedureImplementer({
269
- contract: item,
270
- middlewares
271
- });
272
- } else {
273
- result[key] = chainRouterImplementer(item, middlewares);
274
- }
275
- }
276
- const implementer = new RouterImplementer({ contract });
277
- return Object.assign(implementer, result);
278
- }
279
-
280
370
  // src/builder.ts
281
371
  var Builder = class _Builder {
282
- constructor(zz$b = {}) {
283
- this.zz$b = zz$b;
372
+ "~type" = "Builder";
373
+ "~orpc";
374
+ constructor(def) {
375
+ this["~orpc"] = def;
284
376
  }
285
- /**
286
- * Self chainable
287
- */
288
377
  context() {
289
- return this;
378
+ return new _Builder({});
290
379
  }
291
- use(middleware, mapInput) {
292
- const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
380
+ use(middleware) {
293
381
  return new _Builder({
294
- ...this.zz$b,
295
- middlewares: [...this.zz$b.middlewares || [], middleware_]
382
+ ...this["~orpc"],
383
+ middlewares: [...this["~orpc"].middlewares ?? [], middleware]
296
384
  });
297
385
  }
298
- /**
299
- * Convert to ContractProcedureBuilder
300
- */
301
- route(opts) {
386
+ middleware(middleware) {
387
+ return decorateMiddleware(middleware);
388
+ }
389
+ route(route) {
302
390
  return new ProcedureBuilder({
303
- middlewares: this.zz$b.middlewares,
391
+ middlewares: this["~orpc"].middlewares,
304
392
  contract: new ContractProcedure({
305
- ...opts,
393
+ route,
306
394
  InputSchema: void 0,
307
395
  OutputSchema: void 0
308
396
  })
@@ -310,7 +398,7 @@ var Builder = class _Builder {
310
398
  }
311
399
  input(schema, example) {
312
400
  return new ProcedureBuilder({
313
- middlewares: this.zz$b.middlewares,
401
+ middlewares: this["~orpc"].middlewares,
314
402
  contract: new ContractProcedure({
315
403
  OutputSchema: void 0,
316
404
  InputSchema: schema,
@@ -320,7 +408,7 @@ var Builder = class _Builder {
320
408
  }
321
409
  output(schema, example) {
322
410
  return new ProcedureBuilder({
323
- middlewares: this.zz$b.middlewares,
411
+ middlewares: this["~orpc"].middlewares,
324
412
  contract: new ContractProcedure({
325
413
  InputSchema: void 0,
326
414
  OutputSchema: schema,
@@ -328,107 +416,69 @@ var Builder = class _Builder {
328
416
  })
329
417
  });
330
418
  }
331
- /**
332
- * Convert to Procedure
333
- */
334
419
  func(func) {
335
- return decorateProcedure({
336
- zz$p: {
337
- middlewares: this.zz$b.middlewares,
338
- contract: new ContractProcedure({
339
- InputSchema: void 0,
340
- OutputSchema: void 0
341
- }),
342
- func
343
- }
344
- });
345
- }
346
- /**
347
- * Convert to ProcedureImplementer | RouterBuilder
348
- */
349
- contract(contract) {
350
- if (isContractProcedure2(contract)) {
351
- return new ProcedureImplementer({
352
- contract,
353
- middlewares: this.zz$b.middlewares
354
- });
355
- }
356
- return chainRouterImplementer(
357
- contract,
358
- this.zz$b.middlewares
359
- );
360
- }
361
- /**
362
- * Create ExtendedMiddleware
363
- */
364
- // TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
365
- // solution (maybe): create new generic for .output() method
366
- middleware(middleware) {
367
- return decorateMiddleware(middleware);
420
+ return decorateProcedure(new Procedure({
421
+ middlewares: this["~orpc"].middlewares,
422
+ contract: new ContractProcedure({
423
+ InputSchema: void 0,
424
+ OutputSchema: void 0
425
+ }),
426
+ func
427
+ }));
368
428
  }
369
429
  prefix(prefix) {
370
430
  return new RouterBuilder({
371
- ...this.zz$b,
431
+ middlewares: this["~orpc"].middlewares,
372
432
  prefix
373
433
  });
374
434
  }
375
- tags(...tags) {
435
+ tag(...tags) {
376
436
  return new RouterBuilder({
377
- ...this.zz$b,
437
+ middlewares: this["~orpc"].middlewares,
378
438
  tags
379
439
  });
380
440
  }
381
- /**
382
- * Create DecoratedRouter
383
- */
384
441
  router(router) {
385
- return new RouterBuilder(this.zz$b).router(router);
442
+ return new RouterBuilder(this["~orpc"]).router(router);
386
443
  }
387
444
  lazy(loader) {
388
- return new RouterBuilder(this.zz$b).lazy(loader);
445
+ return new RouterBuilder(this["~orpc"]).lazy(loader);
446
+ }
447
+ contract(contract) {
448
+ return createChainableImplementer(contract, this["~orpc"].middlewares);
389
449
  }
390
450
  };
391
451
 
392
- // src/router.ts
393
- import {
394
- isContractProcedure as isContractProcedure3
395
- } from "@orpc/contract";
396
- function toContractRouter(router) {
397
- const contract = {};
398
- for (const key in router) {
399
- const item = router[key];
400
- if (isContractProcedure3(item)) {
401
- contract[key] = item;
402
- } else if (isProcedure(item)) {
403
- contract[key] = item.zz$p.contract;
404
- } else {
405
- contract[key] = toContractRouter(item);
406
- }
452
+ // src/router-client.ts
453
+ function createRouterClient(options) {
454
+ if (isProcedure(options.router)) {
455
+ const caller = createProcedureClient({
456
+ ...options,
457
+ procedure: options.router,
458
+ context: options.context,
459
+ path: options.path
460
+ });
461
+ return caller;
407
462
  }
408
- return contract;
409
- }
410
-
411
- // src/router-caller.ts
412
- function createRouterCaller(options) {
413
- return createRouterCallerInternal(options);
414
- }
415
- function createRouterCallerInternal(options) {
416
- const procedureCaller = isLazy(options.router) || isProcedure(options.router) ? createProcedureCaller({
463
+ const procedureCaller = isLazy(options.router) ? createProcedureClient({
417
464
  ...options,
418
- procedure: options.router,
465
+ procedure: createLazyProcedureFormAnyLazy(options.router),
419
466
  context: options.context,
420
- path: options.basePath
467
+ path: options.path
421
468
  }) : {};
422
469
  const recursive = new Proxy(procedureCaller, {
423
470
  get(target, key) {
424
471
  if (typeof key !== "string") {
425
472
  return Reflect.get(target, key);
426
473
  }
427
- const next = options.router[key];
428
- return createRouterCallerInternal({
474
+ const next = getRouterChild(options.router, key);
475
+ if (!next) {
476
+ return Reflect.get(target, key);
477
+ }
478
+ return createRouterClient({
429
479
  ...options,
430
480
  router: next,
431
- basePath: [...options.basePath ?? [], key]
481
+ path: [...options.path ?? [], key]
432
482
  });
433
483
  }
434
484
  });
@@ -437,31 +487,32 @@ function createRouterCallerInternal(options) {
437
487
 
438
488
  // src/index.ts
439
489
  export * from "@orpc/shared/error";
440
- var os = new Builder();
490
+ var os = new Builder({});
441
491
  export {
442
492
  Builder,
443
493
  LAZY_LOADER_SYMBOL,
444
- LAZY_ROUTER_PREFIX_SYMBOL,
445
494
  Procedure,
446
495
  ProcedureBuilder,
447
496
  ProcedureImplementer,
448
- ROUTER_CONTRACT_SYMBOL,
449
497
  RouterBuilder,
450
498
  RouterImplementer,
451
- chainRouterImplementer,
452
- createFlattenLazy,
453
- createLazy,
454
- createProcedureCaller,
455
- createRouterCaller,
499
+ createChainableImplementer,
500
+ createProcedureClient,
501
+ createRouterClient,
456
502
  decorateLazy,
457
503
  decorateMiddleware,
458
504
  decorateProcedure,
505
+ deepSetLazyRouterPrefix,
506
+ flatLazy,
507
+ getLazyRouterPrefix,
508
+ getRouterChild,
509
+ getRouterContract,
459
510
  isLazy,
460
511
  isProcedure,
461
- loadLazy,
462
- loadProcedure,
512
+ lazy,
463
513
  mergeContext,
464
514
  os,
465
- toContractRouter
515
+ setRouterContract,
516
+ unlazy
466
517
  };
467
518
  //# sourceMappingURL=index.js.map