@temporary-name/server 1.9.3-alpha.37dfe6603933b8e445661fe453c4fbdb30ccb524 → 1.9.3-alpha.4225889dbc4c4adc76cdbabb804a30cd075c9d7a

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 (29) 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 +14 -30
  11. package/dist/adapters/standard/index.d.ts +14 -30
  12. package/dist/adapters/standard/index.mjs +4 -6
  13. package/dist/index.d.mts +41 -319
  14. package/dist/index.d.ts +41 -319
  15. package/dist/index.mjs +102 -352
  16. package/dist/openapi/index.mjs +27 -61
  17. package/dist/plugins/index.d.mts +2 -2
  18. package/dist/plugins/index.d.ts +2 -2
  19. package/dist/shared/{server.BeuTpcmO.d.mts → server.BYnDyuDL.d.mts} +2 -2
  20. package/dist/shared/{server.CQyYNJ1H.d.ts → server.BlJrjUA9.d.mts} +1 -2
  21. package/dist/shared/{server.C1fnTLq0.d.mts → server.C-tNYmY_.d.ts} +1 -2
  22. package/dist/shared/server.CjkiSCui.mjs +396 -0
  23. package/dist/shared/{server.DLsti1Pv.mjs → server.DdHBdcen.mjs} +58 -89
  24. package/dist/shared/{server.SLLuK6_v.d.ts → server.JI4dqTgD.d.ts} +2 -2
  25. package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
  26. package/dist/shared/{server.BKSOrA6h.d.mts → server.WsFQIubj.d.mts} +103 -60
  27. package/dist/shared/{server.BKSOrA6h.d.ts → server.WsFQIubj.d.ts} +103 -60
  28. package/package.json +10 -9
  29. package/dist/shared/server.BKh8I1Ny.mjs +0 -239
package/dist/index.mjs CHANGED
@@ -1,136 +1,13 @@
1
- import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, getContractRouter } from '@temporary-name/contract';
2
- export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
3
1
  import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
4
2
  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';
3
+ import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, prefixRoute, isContractProcedure, getContractRouter } from '@temporary-name/contract';
4
+ export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
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.CjkiSCui.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.CjkiSCui.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
-
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;
42
- });
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
- }
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
- }
71
-
72
- class Procedure {
73
- /**
74
- * This property holds the defined options.
75
- */
76
- "~orpc";
77
- constructor(def) {
78
- this["~orpc"] = def;
79
- }
80
- }
81
- function isProcedure(item) {
82
- if (item instanceof Procedure) {
83
- return true;
84
- }
85
- return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
86
- }
87
9
 
88
10
  class DecoratedProcedure extends Procedure {
89
- /**
90
- * Adds type-safe custom errors.
91
- * The provided errors are spared-merged with any existing errors.
92
- *
93
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
94
- */
95
- errors(errors) {
96
- return new DecoratedProcedure({
97
- ...this["~orpc"],
98
- errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
99
- });
100
- }
101
- /**
102
- * Sets or updates the metadata.
103
- * The provided metadata is spared-merged with any existing metadata.
104
- *
105
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
106
- */
107
- meta(meta) {
108
- return new DecoratedProcedure({
109
- ...this["~orpc"],
110
- meta: mergeMeta(this["~orpc"].meta, meta)
111
- });
112
- }
113
- /**
114
- * Sets or updates the route definition.
115
- * The provided route is spared-merged with any existing route.
116
- * This option is typically relevant when integrating with OpenAPI.
117
- *
118
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
119
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
120
- */
121
- route(route) {
122
- return new DecoratedProcedure({
123
- ...this["~orpc"],
124
- route: mergeRoute(this["~orpc"].route, route)
125
- });
126
- }
127
- use(middleware, mapInput) {
128
- const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
129
- return new DecoratedProcedure({
130
- ...this["~orpc"],
131
- middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
132
- });
133
- }
134
11
  /**
135
12
  * Make this procedure callable (works like a function while still being a procedure).
136
13
  *
@@ -149,233 +26,49 @@ class DecoratedProcedure extends Procedure {
149
26
  }
150
27
  }
151
28
 
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);
212
- },
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
233
- });
234
- return enhanced2;
235
- }
236
- const enhanced = {};
237
- for (const key in router) {
238
- enhanced[key] = enhanceRouter(router[key], options);
239
- }
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
257
- });
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";
29
+ class ProcedureBuilder extends ContractProcedure {
30
+ z;
303
31
  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
- }
314
- /**
315
- * Creates a middleware.
316
- *
317
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
318
- */
319
- middleware(middleware) {
320
- return decorateMiddleware(middleware);
32
+ super(def);
33
+ this.z = new SchemaClass();
321
34
  }
322
35
  /**
323
- * Adds type-safe custom errors.
324
- * 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.
325
38
  *
326
39
  * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
327
40
  */
328
41
  errors(errors) {
329
- return new Builder({
42
+ return new ProcedureBuilder({
330
43
  ...this["~orpc"],
331
44
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
332
45
  });
333
46
  }
334
47
  /**
335
- * Uses a middleware to modify the context or improve the pipeline.
336
- *
337
- * @info Supports both normal middleware and inline middleware implementations.
338
- * @note The current context must be satisfy middleware dependent-context
339
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
340
- */
341
- use(middleware) {
342
- return new Builder({
343
- ...this["~orpc"],
344
- middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
345
- });
346
- }
347
- useGating(gates, isGateEnabled) {
348
- return this.use(({ next, context }) => {
349
- return gatingContext.run(
350
- (gate) => isGateEnabled(gate, context),
351
- () => next({ context: { isGateEnabled } })
352
- );
353
- });
354
- }
355
- /**
356
- * Sets or updates the metadata.
357
- * 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.
358
50
  *
359
51
  * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
360
52
  */
361
53
  meta(meta) {
362
- return new Builder({
54
+ return new ProcedureBuilder({
363
55
  ...this["~orpc"],
364
56
  meta: mergeMeta(this["~orpc"].meta, meta)
365
57
  });
366
58
  }
367
59
  /**
368
- * Sets or updates the route definition.
369
- * 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.
370
62
  * This option is typically relevant when integrating with OpenAPI.
371
63
  *
372
64
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
373
65
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
374
66
  */
375
67
  route(route) {
376
- return new Builder({
68
+ const { prefix } = this["~orpc"];
69
+ return new ProcedureBuilder({
377
70
  ...this["~orpc"],
378
- route: mergeRoute(this["~orpc"].route, route)
71
+ route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
379
72
  });
380
73
  }
381
74
  /**
@@ -384,7 +77,7 @@ class Builder {
384
77
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
385
78
  */
386
79
  input(schema) {
387
- return new Builder({
80
+ return new ProcedureBuilder({
388
81
  ...this["~orpc"],
389
82
  inputSchema: schema,
390
83
  inputValidationIndex: this["~orpc"].middlewares.length
@@ -396,12 +89,33 @@ class Builder {
396
89
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
397
90
  */
398
91
  output(schema) {
399
- return new Builder({
92
+ return new ProcedureBuilder({
400
93
  ...this["~orpc"],
401
94
  outputSchema: schema,
402
95
  outputValidationIndex: this["~orpc"].middlewares.length
403
96
  });
404
97
  }
98
+ /**
99
+ * Uses a middleware to modify the context or improve the pipeline.
100
+ *
101
+ * @info Supports both normal middleware and inline middleware implementations.
102
+ * @note The current context must be satisfy middleware dependent-context
103
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
104
+ */
105
+ use(middleware) {
106
+ return new this.constructor({
107
+ ...this["~orpc"],
108
+ middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
109
+ });
110
+ }
111
+ useGating(gates, isGateEnabled) {
112
+ return this.use(({ next, context }) => {
113
+ return gatingContext.run(
114
+ (gate) => isGateEnabled(gate, context),
115
+ () => next({ context: { isGateEnabled } })
116
+ );
117
+ });
118
+ }
405
119
  /**
406
120
  * Defines the handler of the procedure.
407
121
  *
@@ -413,6 +127,8 @@ class Builder {
413
127
  handler
414
128
  });
415
129
  }
130
+ }
131
+ class BuilderWithMiddlewares extends ProcedureBuilder {
416
132
  /**
417
133
  * Prefixes all procedures in the router.
418
134
  * The provided prefix is post-appended to any existing router prefix.
@@ -422,7 +138,7 @@ class Builder {
422
138
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
423
139
  */
424
140
  prefix(prefix) {
425
- return new Builder({
141
+ return new this.constructor({
426
142
  ...this["~orpc"],
427
143
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
428
144
  });
@@ -434,7 +150,7 @@ class Builder {
434
150
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
435
151
  */
436
152
  tag(...tags) {
437
- return new Builder({
153
+ return new this.constructor({
438
154
  ...this["~orpc"],
439
155
  tags: mergeTags(this["~orpc"].tags, tags)
440
156
  });
@@ -447,25 +163,71 @@ class Builder {
447
163
  router(router) {
448
164
  return enhanceRouter(router, this["~orpc"]);
449
165
  }
166
+ }
167
+
168
+ function decorateMiddleware(middleware) {
169
+ const decorated = ((...args) => middleware(...args));
170
+ decorated.mapInput = (mapInput) => {
171
+ const mapped = decorateMiddleware(
172
+ (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
173
+ );
174
+ return mapped;
175
+ };
176
+ decorated.concat = (concatMiddleware, mapInput) => {
177
+ const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
178
+ const concatted = decorateMiddleware((options, input, output, ...rest) => {
179
+ const merged = middleware(
180
+ {
181
+ ...options,
182
+ next: (...[nextOptions1]) => mapped(
183
+ {
184
+ ...options,
185
+ context: { ...options.context, ...nextOptions1?.context },
186
+ next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
187
+ },
188
+ input,
189
+ output,
190
+ ...rest
191
+ )
192
+ },
193
+ input,
194
+ output,
195
+ ...rest
196
+ );
197
+ return merged;
198
+ });
199
+ return concatted;
200
+ };
201
+ return decorated;
202
+ }
203
+
204
+ class Builder extends BuilderWithMiddlewares {
450
205
  /**
451
- * Create a lazy router
452
- * And applies all of the previously defined options to the specified router.
206
+ * Set or override the initial context.
453
207
  *
454
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
208
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
455
209
  */
456
- lazyRoute(loader) {
457
- return enhanceRouter(lazy(loader), this["~orpc"]);
210
+ $context() {
211
+ return this;
212
+ }
213
+ /**
214
+ * Creates a middleware.
215
+ *
216
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
217
+ */
218
+ middleware(middleware) {
219
+ return decorateMiddleware(middleware);
458
220
  }
459
221
  }
460
222
  function createApiBuilder(opts = {}) {
461
- const base = new Builder({
223
+ return new Builder({
462
224
  route: {},
463
225
  meta: opts.meta ?? {},
464
226
  errorMap: {},
465
227
  inputValidationIndex: 0,
466
228
  outputValidationIndex: 0,
467
229
  middlewares: [
468
- onError((error, options) => {
230
+ onError((error, _options) => {
469
231
  console.dir(error, { depth: null });
470
232
  })
471
233
  ],
@@ -473,7 +235,6 @@ function createApiBuilder(opts = {}) {
473
235
  // the best solution). For now I've removed the interface to configure it externally.
474
236
  dedupeLeadingMiddlewares: true
475
237
  });
476
- return base;
477
238
  }
478
239
  const os = createApiBuilder();
479
240
 
@@ -511,17 +272,6 @@ function implementerInternal(contract, middlewares) {
511
272
  });
512
273
  return setHiddenRouterContract(adapted, contract);
513
274
  };
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
275
  }
526
276
  const next = getContractRouter(target, [key]);
527
277
  if (!next) {
@@ -563,7 +313,7 @@ function implement(contract) {
563
313
  }
564
314
 
565
315
  function createAssertedLazyProcedure(lazied) {
566
- const lazyProcedure = lazy(async () => {
316
+ const lazyProcedure = lazyInternal(async () => {
567
317
  const { default: maybeProcedure } = await unlazy(lazied);
568
318
  if (!isProcedure(maybeProcedure)) {
569
319
  throw new Error(`
@@ -614,4 +364,4 @@ function createRouterClient(router, ...rest) {
614
364
  return recursive;
615
365
  }
616
366
 
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 };
367
+ 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 };
@@ -1,7 +1,7 @@
1
1
  import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
2
2
  import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@temporary-name/contract';
3
3
  import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
4
- import { a as standardizeHTTPPath, j as jsonSerialize, g as getDynamicParams, d as deserialize, s as serialize } from '../shared/server.BEHw7Eyx.mjs';
4
+ import { a as standardizeHTTPPath, j as jsonSerialize, g as getDynamicParams, d as deserialize, s as serialize } from '../shared/server.Kxw442A9.mjs';
5
5
  import '@temporary-name/standard-server';
6
6
  import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
7
7
  export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
@@ -542,77 +542,43 @@ ${errors.join("\n\n")}`
542
542
  return;
543
543
  }
544
544
  const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
545
- const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
546
545
  let [required, schema] = await this.converter.convert(def.inputSchema, {
547
546
  ...baseSchemaConvertOptions,
548
547
  strategy: "input",
549
- minStructureDepthForRef: dynamicParams?.length || inputStructure === "detailed" ? 1 : 0
548
+ minStructureDepthForRef: dynamicParams?.length ? 1 : 0
550
549
  });
551
550
  if (isAnySchema(schema) && !dynamicParams?.length) {
552
551
  return;
553
552
  }
554
- if (inputStructure === "compact") {
555
- if (dynamicParams?.length) {
556
- const error2 = new OpenAPIGeneratorError(
557
- 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
558
- );
559
- if (!isObjectSchema(schema)) {
560
- throw error2;
561
- }
562
- const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
563
- schema = rest;
564
- required = rest.required ? rest.required.length !== 0 : false;
565
- if (!checkParamsSchema(paramsSchema, dynamicParams)) {
566
- throw error2;
567
- }
568
- ref.parameters ??= [];
569
- ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
553
+ if (dynamicParams?.length) {
554
+ const error = new OpenAPIGeneratorError(
555
+ 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
556
+ );
557
+ if (!isObjectSchema(schema)) {
558
+ throw error;
570
559
  }
571
- if (method === "GET") {
572
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, schema);
573
- if (!isObjectSchema(resolvedSchema)) {
574
- throw new OpenAPIGeneratorError(
575
- 'When method is "GET", input schema must satisfy: object | any | unknown'
576
- );
577
- }
578
- ref.parameters ??= [];
579
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
580
- } else {
581
- ref.requestBody = {
582
- required,
583
- content: toOpenAPIContent(schema)
584
- };
560
+ const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
561
+ schema = rest;
562
+ required = rest.required ? rest.required.length !== 0 : false;
563
+ if (!checkParamsSchema(paramsSchema, dynamicParams)) {
564
+ throw error;
585
565
  }
586
- return;
587
- }
588
- const error = new OpenAPIGeneratorError(
589
- 'When input structure is "detailed", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }'
590
- );
591
- if (!isObjectSchema(schema)) {
592
- throw error;
593
- }
594
- const resolvedParamSchema = schema.properties?.params !== void 0 ? resolveOpenAPIJsonSchemaRef(doc, schema.properties.params) : void 0;
595
- if (dynamicParams?.length && (resolvedParamSchema === void 0 || !isObjectSchema(resolvedParamSchema) || !checkParamsSchema(resolvedParamSchema, dynamicParams))) {
596
- throw new OpenAPIGeneratorError(
597
- 'When input structure is "detailed" and path has dynamic params, the "params" schema must be an object with all dynamic params as required.'
598
- );
599
- }
600
- for (const from of ["params", "query", "headers"]) {
601
- const fromSchema = schema.properties?.[from];
602
- if (fromSchema !== void 0) {
603
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, fromSchema);
604
- if (!isObjectSchema(resolvedSchema)) {
605
- throw error;
606
- }
607
- const parameterIn = from === "params" ? "path" : from === "headers" ? "header" : "query";
608
- ref.parameters ??= [];
609
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, parameterIn));
566
+ ref.parameters ??= [];
567
+ ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
568
+ }
569
+ if (method === "GET") {
570
+ const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, schema);
571
+ if (!isObjectSchema(resolvedSchema)) {
572
+ throw new OpenAPIGeneratorError(
573
+ 'When method is "GET", input schema must satisfy: object | any | unknown'
574
+ );
610
575
  }
611
- }
612
- if (schema.properties?.body !== void 0) {
576
+ ref.parameters ??= [];
577
+ ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
578
+ } else {
613
579
  ref.requestBody = {
614
- required: schema.required?.includes("body"),
615
- content: toOpenAPIContent(schema.properties.body)
580
+ required,
581
+ content: toOpenAPIContent(schema)
616
582
  };
617
583
  }
618
584
  }