@temporary-name/server 1.9.3-alpha.16e8a4f82a5b0af6e22263774a4af4e6f9afd8bc → 1.9.3-alpha.1a5ff4923d25c9d83e80d717687ebc859f5312f2

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 (31) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +3 -3
  2. package/dist/adapters/aws-lambda/index.d.ts +3 -3
  3. package/dist/adapters/aws-lambda/index.mjs +4 -6
  4. package/dist/adapters/fetch/index.d.mts +3 -3
  5. package/dist/adapters/fetch/index.d.ts +3 -3
  6. package/dist/adapters/fetch/index.mjs +4 -6
  7. package/dist/adapters/node/index.d.mts +3 -3
  8. package/dist/adapters/node/index.d.ts +3 -3
  9. package/dist/adapters/node/index.mjs +4 -6
  10. package/dist/adapters/standard/index.d.mts +20 -31
  11. package/dist/adapters/standard/index.d.ts +20 -31
  12. package/dist/adapters/standard/index.mjs +4 -6
  13. package/dist/index.d.mts +66 -339
  14. package/dist/index.d.ts +66 -339
  15. package/dist/index.mjs +126 -354
  16. package/dist/openapi/index.d.mts +1 -1
  17. package/dist/openapi/index.d.ts +1 -1
  18. package/dist/openapi/index.mjs +59 -76
  19. package/dist/plugins/index.d.mts +2 -2
  20. package/dist/plugins/index.d.ts +2 -2
  21. package/dist/shared/{server.DLsti1Pv.mjs → server.B--sAUhn.mjs} +55 -94
  22. package/dist/shared/{server.CQyYNJ1H.d.ts → server.BCcLYvdF.d.mts} +1 -2
  23. package/dist/shared/server.CHV9AQHl.mjs +412 -0
  24. package/dist/shared/{server.C1fnTLq0.d.mts → server.CdeqmULw.d.ts} +1 -2
  25. package/dist/shared/{server.BeuTpcmO.d.mts → server.DHezmW6C.d.mts} +2 -2
  26. package/dist/shared/{server.SLLuK6_v.d.ts → server.Da-qLzdU.d.ts} +2 -2
  27. package/dist/shared/{server.BKSOrA6h.d.mts → server.DecvGKtb.d.mts} +125 -75
  28. package/dist/shared/{server.BKSOrA6h.d.ts → server.DecvGKtb.d.ts} +125 -75
  29. package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
  30. package/package.json +10 -9
  31. package/dist/shared/server.BKh8I1Ny.mjs +0 -239
package/dist/index.mjs CHANGED
@@ -1,334 +1,119 @@
1
- import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, getContractRouter } from '@temporary-name/contract';
2
- export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
1
+ import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, prefixRoute, initialSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
2
+ export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
3
3
  import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
4
4
  export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
5
- import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy, u as unlazy, a as gatingContext } from './shared/server.BKh8I1Ny.mjs';
6
- export { L as LAZY_SYMBOL, b as createORPCErrorConstructorMap, m as mergeCurrentContext, d as middlewareOutputFn } from './shared/server.BKh8I1Ny.mjs';
5
+ import { SchemaClass, gatingContext } from '@temporary-name/zod';
6
+ import { P as Procedure, c as createProcedureClient, e as enhanceRouter, a as addMiddleware, s as setHiddenRouterContract, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.CHV9AQHl.mjs';
7
+ export { L as LAZY_SYMBOL, p as createAccessibleLazyRouter, f as createORPCErrorConstructorMap, o as getHiddenRouterContract, k as isStartWithMiddlewares, h as lazy, m as mergeCurrentContext, n as mergeMiddlewares, j as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, q as unlazyRouter } from './shared/server.CHV9AQHl.mjs';
7
8
  export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
8
- import 'node:async_hooks';
9
- import 'zod';
10
- import 'zod/v4/core';
11
9
 
12
- function decorateMiddleware(middleware) {
13
- const decorated = ((...args) => middleware(...args));
14
- decorated.mapInput = (mapInput) => {
15
- const mapped = decorateMiddleware(
16
- (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
17
- );
18
- return mapped;
19
- };
20
- decorated.concat = (concatMiddleware, mapInput) => {
21
- const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
22
- const concatted = decorateMiddleware((options, input, output, ...rest) => {
23
- const merged = middleware(
24
- {
25
- ...options,
26
- next: (...[nextOptions1]) => mapped(
27
- {
28
- ...options,
29
- context: { ...options.context, ...nextOptions1?.context },
30
- next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
31
- },
32
- input,
33
- output,
34
- ...rest
35
- )
36
- },
37
- input,
38
- output,
39
- ...rest
40
- );
41
- return merged;
10
+ class DecoratedProcedure extends Procedure {
11
+ /**
12
+ * Make this procedure callable (works like a function while still being a procedure).
13
+ *
14
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
15
+ */
16
+ callable(...rest) {
17
+ const client = createProcedureClient(this, ...rest);
18
+ return new Proxy(client, {
19
+ get: (target, key) => {
20
+ return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
21
+ },
22
+ has: (target, key) => {
23
+ return Reflect.has(this, key) || Reflect.has(target, key);
24
+ }
42
25
  });
43
- return concatted;
44
- };
45
- return decorated;
46
- }
47
-
48
- function isStartWithMiddlewares(middlewares, compare) {
49
- if (compare.length > middlewares.length) {
50
- return false;
51
- }
52
- for (let i = 0; i < middlewares.length; i++) {
53
- if (compare[i] === void 0) {
54
- return true;
55
- }
56
- if (middlewares[i] !== compare[i]) {
57
- return false;
58
- }
59
26
  }
60
- return true;
61
- }
62
- function mergeMiddlewares(first, second, options) {
63
- if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
64
- return second;
65
- }
66
- return [...first, ...second];
67
- }
68
- function addMiddleware(middlewares, addition) {
69
- return [...middlewares, addition];
70
27
  }
71
28
 
72
- class Procedure {
73
- /**
74
- * This property holds the defined options.
75
- */
76
- "~orpc";
29
+ class ProcedureBuilder extends ContractProcedure {
30
+ z;
77
31
  constructor(def) {
78
- this["~orpc"] = def;
79
- }
80
- }
81
- function isProcedure(item) {
82
- if (item instanceof Procedure) {
83
- return true;
32
+ super(def);
33
+ this.z = new SchemaClass();
84
34
  }
85
- return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
86
- }
87
-
88
- class DecoratedProcedure extends Procedure {
89
35
  /**
90
- * Adds type-safe custom errors.
91
- * The provided errors are spared-merged with any existing errors.
36
+ * Adds type-safe custom errors to the contract.
37
+ * The provided errors are spared-merged with any existing errors in the contract.
92
38
  *
93
39
  * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
94
40
  */
95
41
  errors(errors) {
96
- return new DecoratedProcedure({
42
+ return new ProcedureBuilder({
97
43
  ...this["~orpc"],
98
44
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
99
45
  });
100
46
  }
101
47
  /**
102
- * Sets or updates the metadata.
103
- * The provided metadata is spared-merged with any existing metadata.
48
+ * Sets or updates the metadata for the contract.
49
+ * The provided metadata is spared-merged with any existing metadata in the contract.
104
50
  *
105
51
  * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
106
52
  */
107
53
  meta(meta) {
108
- return new DecoratedProcedure({
54
+ return new ProcedureBuilder({
109
55
  ...this["~orpc"],
110
56
  meta: mergeMeta(this["~orpc"].meta, meta)
111
57
  });
112
58
  }
113
59
  /**
114
- * Sets or updates the route definition.
115
- * The provided route is spared-merged with any existing route.
60
+ * Sets or updates the route definition for the contract.
61
+ * The provided route is spared-merged with any existing route in the contract.
116
62
  * This option is typically relevant when integrating with OpenAPI.
117
63
  *
118
64
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
119
65
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
120
66
  */
121
67
  route(route) {
122
- return new DecoratedProcedure({
68
+ const { prefix } = this["~orpc"];
69
+ return new ProcedureBuilder({
123
70
  ...this["~orpc"],
124
- route: mergeRoute(this["~orpc"].route, route)
71
+ route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
125
72
  });
126
73
  }
127
- use(middleware, mapInput) {
128
- const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
129
- return new DecoratedProcedure({
74
+ path(schema) {
75
+ return new ProcedureBuilder({
130
76
  ...this["~orpc"],
131
- middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
132
- });
133
- }
134
- /**
135
- * Make this procedure callable (works like a function while still being a procedure).
136
- *
137
- * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
138
- */
139
- callable(...rest) {
140
- const client = createProcedureClient(this, ...rest);
141
- return new Proxy(client, {
142
- get: (target, key) => {
143
- return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
77
+ schemas: {
78
+ ...this["~orpc"].schemas,
79
+ pathSchema: schema
144
80
  },
145
- has: (target, key) => {
146
- return Reflect.has(this, key) || Reflect.has(target, key);
147
- }
81
+ inputValidationIndex: this["~orpc"].middlewares.length
148
82
  });
149
83
  }
150
- }
151
-
152
- const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
153
- function setHiddenRouterContract(router, contract) {
154
- return new Proxy(router, {
155
- get(target, key) {
156
- if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
157
- return contract;
158
- }
159
- return Reflect.get(target, key);
160
- }
161
- });
162
- }
163
- function getHiddenRouterContract(router) {
164
- return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
165
- }
166
-
167
- function getRouter(router, path) {
168
- let current = router;
169
- for (let i = 0; i < path.length; i++) {
170
- const segment = path[i];
171
- if (!current) {
172
- return void 0;
173
- }
174
- if (isProcedure(current)) {
175
- return void 0;
176
- }
177
- if (!isLazy(current)) {
178
- current = current[segment];
179
- continue;
180
- }
181
- const lazied = current;
182
- const rest = path.slice(i);
183
- return lazy(async () => {
184
- const unwrapped = await unlazy(lazied);
185
- const next = getRouter(unwrapped.default, rest);
186
- return unlazy(next);
187
- }, getLazyMeta(lazied));
188
- }
189
- return current;
190
- }
191
- function createAccessibleLazyRouter(lazied) {
192
- const recursive = new Proxy(lazied, {
193
- get(target, key) {
194
- if (typeof key !== "string") {
195
- return Reflect.get(target, key);
196
- }
197
- const next = getRouter(lazied, [key]);
198
- return createAccessibleLazyRouter(next);
199
- }
200
- });
201
- return recursive;
202
- }
203
- function enhanceRouter(router, options) {
204
- if (isLazy(router)) {
205
- const laziedMeta = getLazyMeta(router);
206
- const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
207
- const enhanced2 = lazy(
208
- async () => {
209
- const { default: unlaziedRouter } = await unlazy(router);
210
- const enhanced3 = enhanceRouter(unlaziedRouter, options);
211
- return unlazy(enhanced3);
84
+ query(schema) {
85
+ return new ProcedureBuilder({
86
+ ...this["~orpc"],
87
+ schemas: {
88
+ ...this["~orpc"].schemas,
89
+ querySchema: schema
212
90
  },
213
- {
214
- ...laziedMeta,
215
- prefix: enhancedPrefix
216
- }
217
- );
218
- const accessible = createAccessibleLazyRouter(enhanced2);
219
- return accessible;
220
- }
221
- if (isProcedure(router)) {
222
- const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, {
223
- dedupeLeading: options.dedupeLeadingMiddlewares
224
- });
225
- const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
226
- const enhanced2 = new Procedure({
227
- ...router["~orpc"],
228
- route: enhanceRoute(router["~orpc"].route, options),
229
- errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
230
- middlewares: newMiddlewares,
231
- inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
232
- outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
91
+ inputValidationIndex: this["~orpc"].middlewares.length
233
92
  });
234
- return enhanced2;
235
- }
236
- const enhanced = {};
237
- for (const key in router) {
238
- enhanced[key] = enhanceRouter(router[key], options);
239
93
  }
240
- return enhanced;
241
- }
242
- function traverseContractProcedures(options, callback, lazyOptions = []) {
243
- let currentRouter = options.router;
244
- const hiddenContract = getHiddenRouterContract(options.router);
245
- if (hiddenContract !== void 0) {
246
- currentRouter = hiddenContract;
247
- }
248
- if (isLazy(currentRouter)) {
249
- lazyOptions.push({
250
- router: currentRouter,
251
- path: options.path
252
- });
253
- } else if (isContractProcedure(currentRouter)) {
254
- callback({
255
- contract: currentRouter,
256
- path: options.path
94
+ body(schema) {
95
+ return new ProcedureBuilder({
96
+ ...this["~orpc"],
97
+ schemas: {
98
+ ...this["~orpc"].schemas,
99
+ bodySchema: schema
100
+ },
101
+ inputValidationIndex: this["~orpc"].middlewares.length
257
102
  });
258
- } else {
259
- for (const key in currentRouter) {
260
- traverseContractProcedures(
261
- {
262
- router: currentRouter[key],
263
- path: [...options.path, key]
264
- },
265
- callback,
266
- lazyOptions
267
- );
268
- }
269
- }
270
- return lazyOptions;
271
- }
272
- async function resolveContractProcedures(options, callback) {
273
- const pending = [options];
274
- for (const options2 of pending) {
275
- const lazyOptions = traverseContractProcedures(options2, callback);
276
- for (const options3 of lazyOptions) {
277
- const { default: router } = await unlazy(options3.router);
278
- pending.push({
279
- router,
280
- path: options3.path
281
- });
282
- }
283
- }
284
- }
285
- async function unlazyRouter(router) {
286
- if (isProcedure(router)) {
287
- return router;
288
- }
289
- const unlazied = {};
290
- for (const key in router) {
291
- const item = router[key];
292
- const { default: unlaziedRouter } = await unlazy(item);
293
- unlazied[key] = await unlazyRouter(unlaziedRouter);
294
- }
295
- return unlazied;
296
- }
297
-
298
- class Builder {
299
- /**
300
- * This property holds the defined options.
301
- */
302
- "~orpc";
303
- constructor(def) {
304
- this["~orpc"] = def;
305
- }
306
- /**
307
- * Set or override the initial context.
308
- *
309
- * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
310
- */
311
- $context() {
312
- return this;
313
103
  }
314
104
  /**
315
- * Creates a middleware.
316
- *
317
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
318
- */
319
- middleware(middleware) {
320
- return decorateMiddleware(middleware);
321
- }
322
- /**
323
- * Adds type-safe custom errors.
324
- * The provided errors are spared-merged with any existing errors.
105
+ * Defines the output validation schema.
325
106
  *
326
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
107
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
327
108
  */
328
- errors(errors) {
329
- return new Builder({
109
+ output(schema) {
110
+ return new ProcedureBuilder({
330
111
  ...this["~orpc"],
331
- errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
112
+ schemas: {
113
+ ...this["~orpc"].schemas,
114
+ outputSchema: schema
115
+ },
116
+ outputValidationIndex: this["~orpc"].middlewares.length
332
117
  });
333
118
  }
334
119
  /**
@@ -339,7 +124,7 @@ class Builder {
339
124
  * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
340
125
  */
341
126
  use(middleware) {
342
- return new Builder({
127
+ return new this.constructor({
343
128
  ...this["~orpc"],
344
129
  middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
345
130
  });
@@ -352,56 +137,6 @@ class Builder {
352
137
  );
353
138
  });
354
139
  }
355
- /**
356
- * Sets or updates the metadata.
357
- * The provided metadata is spared-merged with any existing metadata.
358
- *
359
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
360
- */
361
- meta(meta) {
362
- return new Builder({
363
- ...this["~orpc"],
364
- meta: mergeMeta(this["~orpc"].meta, meta)
365
- });
366
- }
367
- /**
368
- * Sets or updates the route definition.
369
- * The provided route is spared-merged with any existing route.
370
- * This option is typically relevant when integrating with OpenAPI.
371
- *
372
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
373
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
374
- */
375
- route(route) {
376
- return new Builder({
377
- ...this["~orpc"],
378
- route: mergeRoute(this["~orpc"].route, route)
379
- });
380
- }
381
- /**
382
- * Defines the input validation schema.
383
- *
384
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
385
- */
386
- input(schema) {
387
- return new Builder({
388
- ...this["~orpc"],
389
- inputSchema: schema,
390
- inputValidationIndex: this["~orpc"].middlewares.length
391
- });
392
- }
393
- /**
394
- * Defines the output validation schema.
395
- *
396
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
397
- */
398
- output(schema) {
399
- return new Builder({
400
- ...this["~orpc"],
401
- outputSchema: schema,
402
- outputValidationIndex: this["~orpc"].middlewares.length
403
- });
404
- }
405
140
  /**
406
141
  * Defines the handler of the procedure.
407
142
  *
@@ -413,6 +148,8 @@ class Builder {
413
148
  handler
414
149
  });
415
150
  }
151
+ }
152
+ class BuilderWithMiddlewares extends ProcedureBuilder {
416
153
  /**
417
154
  * Prefixes all procedures in the router.
418
155
  * The provided prefix is post-appended to any existing router prefix.
@@ -422,7 +159,7 @@ class Builder {
422
159
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
423
160
  */
424
161
  prefix(prefix) {
425
- return new Builder({
162
+ return new this.constructor({
426
163
  ...this["~orpc"],
427
164
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
428
165
  });
@@ -434,7 +171,7 @@ class Builder {
434
171
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
435
172
  */
436
173
  tag(...tags) {
437
- return new Builder({
174
+ return new this.constructor({
438
175
  ...this["~orpc"],
439
176
  tags: mergeTags(this["~orpc"].tags, tags)
440
177
  });
@@ -447,33 +184,79 @@ class Builder {
447
184
  router(router) {
448
185
  return enhanceRouter(router, this["~orpc"]);
449
186
  }
187
+ }
188
+
189
+ function decorateMiddleware(middleware) {
190
+ const decorated = ((...args) => middleware(...args));
191
+ decorated.mapInput = (mapInput) => {
192
+ const mapped = decorateMiddleware(
193
+ (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
194
+ );
195
+ return mapped;
196
+ };
197
+ decorated.concat = (concatMiddleware, mapInput) => {
198
+ const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
199
+ const concatted = decorateMiddleware((options, input, output, ...rest) => {
200
+ const merged = middleware(
201
+ {
202
+ ...options,
203
+ next: (...[nextOptions1]) => mapped(
204
+ {
205
+ ...options,
206
+ context: { ...options.context, ...nextOptions1?.context },
207
+ next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
208
+ },
209
+ input,
210
+ output,
211
+ ...rest
212
+ )
213
+ },
214
+ input,
215
+ output,
216
+ ...rest
217
+ );
218
+ return merged;
219
+ });
220
+ return concatted;
221
+ };
222
+ return decorated;
223
+ }
224
+
225
+ class Builder extends BuilderWithMiddlewares {
226
+ /**
227
+ * Set or override the initial context.
228
+ *
229
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
230
+ */
231
+ $context() {
232
+ return this;
233
+ }
450
234
  /**
451
- * Create a lazy router
452
- * And applies all of the previously defined options to the specified router.
235
+ * Creates a middleware.
453
236
  *
454
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
237
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
455
238
  */
456
- lazyRoute(loader) {
457
- return enhanceRouter(lazy(loader), this["~orpc"]);
239
+ middleware(middleware) {
240
+ return decorateMiddleware(middleware);
458
241
  }
459
242
  }
460
243
  function createApiBuilder(opts = {}) {
461
- const base = new Builder({
244
+ return new Builder({
462
245
  route: {},
463
246
  meta: opts.meta ?? {},
464
247
  errorMap: {},
465
248
  inputValidationIndex: 0,
466
249
  outputValidationIndex: 0,
467
250
  middlewares: [
468
- onError((error, options) => {
251
+ onError((error, _options) => {
469
252
  console.dir(error, { depth: null });
470
253
  })
471
254
  ],
255
+ schemas: initialSchemas,
472
256
  // NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
473
257
  // the best solution). For now I've removed the interface to configure it externally.
474
258
  dedupeLeadingMiddlewares: true
475
259
  });
476
- return base;
477
260
  }
478
261
  const os = createApiBuilder();
479
262
 
@@ -511,17 +294,6 @@ function implementerInternal(contract, middlewares) {
511
294
  });
512
295
  return setHiddenRouterContract(adapted, contract);
513
296
  };
514
- } else if (key === "lazyRoute") {
515
- method = (loader) => {
516
- const adapted = enhanceRouter(lazy(loader), {
517
- middlewares,
518
- errorMap: {},
519
- prefix: void 0,
520
- tags: void 0,
521
- dedupeLeadingMiddlewares: true
522
- });
523
- return setHiddenRouterContract(adapted, contract);
524
- };
525
297
  }
526
298
  const next = getContractRouter(target, [key]);
527
299
  if (!next) {
@@ -563,7 +335,7 @@ function implement(contract) {
563
335
  }
564
336
 
565
337
  function createAssertedLazyProcedure(lazied) {
566
- const lazyProcedure = lazy(async () => {
338
+ const lazyProcedure = lazyInternal(async () => {
567
339
  const { default: maybeProcedure } = await unlazy(lazied);
568
340
  if (!isProcedure(maybeProcedure)) {
569
341
  throw new Error(`
@@ -614,4 +386,4 @@ function createRouterClient(router, ...rest) {
614
386
  return recursive;
615
387
  }
616
388
 
617
- export { Builder, DecoratedProcedure, Procedure, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
389
+ export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, lazyInternal, os, setHiddenRouterContract, unlazy };
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
55
55
  minStructureDepthForRef?: number;
56
56
  }
57
57
  interface SchemaConverter {
58
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
58
+ convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
59
59
  }
60
60
  interface ConditionalSchemaConverter extends SchemaConverter {
61
61
  condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
55
55
  minStructureDepthForRef?: number;
56
56
  }
57
57
  interface SchemaConverter {
58
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
58
+ convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
59
59
  }
60
60
  interface ConditionalSchemaConverter extends SchemaConverter {
61
61
  condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;