@temporary-name/server 1.9.3-alpha.30822ad82102dcf9276d473ba372416778807e52 → 1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e

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 (34) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +12 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +12 -6
  3. package/dist/adapters/aws-lambda/index.mjs +12 -4
  4. package/dist/adapters/fetch/index.d.mts +12 -6
  5. package/dist/adapters/fetch/index.d.ts +12 -6
  6. package/dist/adapters/fetch/index.mjs +12 -11
  7. package/dist/adapters/node/index.d.mts +12 -6
  8. package/dist/adapters/node/index.d.ts +12 -6
  9. package/dist/adapters/node/index.mjs +12 -11
  10. package/dist/adapters/standard/index.d.mts +28 -13
  11. package/dist/adapters/standard/index.d.ts +28 -13
  12. package/dist/adapters/standard/index.mjs +8 -100
  13. package/dist/index.d.mts +66 -339
  14. package/dist/index.d.ts +66 -339
  15. package/dist/index.mjs +126 -355
  16. package/dist/openapi/index.d.mts +220 -0
  17. package/dist/openapi/index.d.ts +220 -0
  18. package/dist/openapi/index.mjs +759 -0
  19. package/dist/plugins/index.d.mts +2 -2
  20. package/dist/plugins/index.d.ts +2 -2
  21. package/dist/shared/{server.Btxrgkj5.d.ts → server.BRCH88Sb.d.mts} +7 -24
  22. package/dist/shared/server.Bb9Wxubg.d.ts +23 -0
  23. package/dist/shared/server.BbfNcgas.d.mts +23 -0
  24. package/dist/shared/{server.Bo94xDTv.d.mts → server.D24uJlXJ.d.ts} +7 -24
  25. package/dist/shared/server.DlRH_uit.mjs +409 -0
  26. package/dist/shared/server.Kxw442A9.mjs +247 -0
  27. package/dist/shared/{server.C1YnHvvf.d.ts → server.XpnxYU3D.d.mts} +128 -73
  28. package/dist/shared/{server.C1YnHvvf.d.mts → server.XpnxYU3D.d.ts} +128 -73
  29. package/dist/shared/server.u-02Z0mj.mjs +254 -0
  30. package/package.json +17 -10
  31. package/dist/shared/server.BEQrAa3A.mjs +0 -207
  32. package/dist/shared/server.D6K9uoPI.mjs +0 -35
  33. package/dist/shared/server.DZ5BIITo.mjs +0 -9
  34. package/dist/shared/server.X0YaZxSJ.mjs +0 -13
@@ -1,8 +1,8 @@
1
1
  import { Value, Promisable, ORPCError } from '@temporary-name/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
3
3
  import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
4
- import { c as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, d as StandardHandlerOptions } from '../shared/server.Bo94xDTv.mjs';
5
- import { C as Context, P as ProcedureClientInterceptorOptions } from '../shared/server.C1YnHvvf.mjs';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.BRCH88Sb.mjs';
5
+ import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.XpnxYU3D.mjs';
6
6
  import { Meta } from '@temporary-name/contract';
7
7
 
8
8
  interface BatchHandlerOptions<T extends Context> {
@@ -1,8 +1,8 @@
1
1
  import { Value, Promisable, ORPCError } from '@temporary-name/shared';
2
2
  import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
3
3
  import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
4
- import { c as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, d as StandardHandlerOptions } from '../shared/server.Btxrgkj5.js';
5
- import { C as Context, P as ProcedureClientInterceptorOptions } from '../shared/server.C1YnHvvf.js';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.D24uJlXJ.js';
5
+ import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.XpnxYU3D.js';
6
6
  import { Meta } from '@temporary-name/contract';
7
7
 
8
8
  interface BatchHandlerOptions<T extends Context> {
@@ -1,7 +1,7 @@
1
1
  import { Meta } from '@temporary-name/contract';
2
- import { HTTPPath, ORPCError, Interceptor } from '@temporary-name/shared';
3
- import { StandardResponse, StandardLazyRequest } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, A as AnyRouter, a as AnyProcedure, P as ProcedureClientInterceptorOptions } from './server.C1YnHvvf.js';
2
+ import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
+ import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
+ import { C as Context, R as Router, H as ProcedureClientInterceptorOptions } from './server.XpnxYU3D.mjs';
5
5
 
6
6
  interface StandardHandlerPlugin<T extends Context> {
7
7
  order?: number;
@@ -13,22 +13,6 @@ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends
13
13
  init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
14
14
  }
15
15
 
16
- type StandardParams = Record<string, string>;
17
- type StandardMatchResult = {
18
- path: readonly string[];
19
- procedure: AnyProcedure;
20
- params?: StandardParams;
21
- } | undefined;
22
- interface StandardMatcher {
23
- init(router: AnyRouter): void;
24
- match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
25
- }
26
- interface StandardCodec {
27
- encode(output: unknown, procedure: AnyProcedure): StandardResponse;
28
- encodeError(error: ORPCError<any, any>): StandardResponse;
29
- decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
30
- }
31
-
32
16
  interface StandardHandleOptions<T extends Context> {
33
17
  prefix?: HTTPPath;
34
18
  context: T;
@@ -60,14 +44,13 @@ interface StandardHandlerOptions<TContext extends Context> {
60
44
  clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
61
45
  }
62
46
  declare class StandardHandler<T extends Context> {
63
- private readonly matcher;
64
- private readonly codec;
65
47
  private readonly interceptors;
66
48
  private readonly clientInterceptors;
67
49
  private readonly rootInterceptors;
68
- constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
50
+ private readonly matcher;
51
+ constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
69
52
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
70
53
  }
71
54
 
72
- export { CompositeStandardHandlerPlugin as C, StandardHandler as S };
73
- export type { StandardHandlerPlugin as a, StandardHandleOptions as b, StandardHandlerInterceptorOptions as c, StandardHandlerOptions as d, StandardHandleResult as e, StandardParams as f, StandardMatchResult as g, StandardMatcher as h, StandardCodec as i };
55
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as e };
56
+ export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardHandleOptions as c, StandardHandleResult as d };
@@ -0,0 +1,23 @@
1
+ import { HTTPPath } from '@temporary-name/shared';
2
+ import { C as Context } from './server.XpnxYU3D.js';
3
+ import { c as StandardHandleOptions } from './server.D24uJlXJ.js';
4
+
5
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
+ context?: T;
7
+ } : {
8
+ context: T;
9
+ });
10
+ declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
11
+ /**
12
+ * {@link https://github.com/unjs/rou3}
13
+ *
14
+ * @internal
15
+ */
16
+ declare function toRou3Pattern(path: HTTPPath): string;
17
+ /**
18
+ * @internal
19
+ */
20
+ declare function decodeParams(params: Record<string, string>): Record<string, string>;
21
+
22
+ export { decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
23
+ export type { FriendlyStandardHandleOptions as F };
@@ -0,0 +1,23 @@
1
+ import { HTTPPath } from '@temporary-name/shared';
2
+ import { C as Context } from './server.XpnxYU3D.mjs';
3
+ import { c as StandardHandleOptions } from './server.BRCH88Sb.mjs';
4
+
5
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
+ context?: T;
7
+ } : {
8
+ context: T;
9
+ });
10
+ declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
11
+ /**
12
+ * {@link https://github.com/unjs/rou3}
13
+ *
14
+ * @internal
15
+ */
16
+ declare function toRou3Pattern(path: HTTPPath): string;
17
+ /**
18
+ * @internal
19
+ */
20
+ declare function decodeParams(params: Record<string, string>): Record<string, string>;
21
+
22
+ export { decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
23
+ export type { FriendlyStandardHandleOptions as F };
@@ -1,7 +1,7 @@
1
1
  import { Meta } from '@temporary-name/contract';
2
- import { HTTPPath, ORPCError, Interceptor } from '@temporary-name/shared';
3
- import { StandardResponse, StandardLazyRequest } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, A as AnyRouter, a as AnyProcedure, P as ProcedureClientInterceptorOptions } from './server.C1YnHvvf.mjs';
2
+ import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
+ import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
+ import { C as Context, R as Router, H as ProcedureClientInterceptorOptions } from './server.XpnxYU3D.js';
5
5
 
6
6
  interface StandardHandlerPlugin<T extends Context> {
7
7
  order?: number;
@@ -13,22 +13,6 @@ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends
13
13
  init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
14
14
  }
15
15
 
16
- type StandardParams = Record<string, string>;
17
- type StandardMatchResult = {
18
- path: readonly string[];
19
- procedure: AnyProcedure;
20
- params?: StandardParams;
21
- } | undefined;
22
- interface StandardMatcher {
23
- init(router: AnyRouter): void;
24
- match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
25
- }
26
- interface StandardCodec {
27
- encode(output: unknown, procedure: AnyProcedure): StandardResponse;
28
- encodeError(error: ORPCError<any, any>): StandardResponse;
29
- decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
30
- }
31
-
32
16
  interface StandardHandleOptions<T extends Context> {
33
17
  prefix?: HTTPPath;
34
18
  context: T;
@@ -60,14 +44,13 @@ interface StandardHandlerOptions<TContext extends Context> {
60
44
  clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
61
45
  }
62
46
  declare class StandardHandler<T extends Context> {
63
- private readonly matcher;
64
- private readonly codec;
65
47
  private readonly interceptors;
66
48
  private readonly clientInterceptors;
67
49
  private readonly rootInterceptors;
68
- constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
50
+ private readonly matcher;
51
+ constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
69
52
  handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
70
53
  }
71
54
 
72
- export { CompositeStandardHandlerPlugin as C, StandardHandler as S };
73
- export type { StandardHandlerPlugin as a, StandardHandleOptions as b, StandardHandlerInterceptorOptions as c, StandardHandlerOptions as d, StandardHandleResult as e, StandardParams as f, StandardMatchResult as g, StandardMatcher as h, StandardCodec as i };
55
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as e };
56
+ export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardHandleOptions as c, StandardHandleResult as d };
@@ -0,0 +1,409 @@
1
+ import { isContractProcedure, mergePrefix, mergeErrorMap, enhanceRoute, validateORPCError, ValidationError } from '@temporary-name/contract';
2
+ import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
3
+ import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
4
+ import { safeParseAsync } from '@temporary-name/zod';
5
+
6
+ function isStartWithMiddlewares(middlewares, compare) {
7
+ if (compare.length > middlewares.length) {
8
+ return false;
9
+ }
10
+ for (let i = 0; i < middlewares.length; i++) {
11
+ if (compare[i] === void 0) {
12
+ return true;
13
+ }
14
+ if (middlewares[i] !== compare[i]) {
15
+ return false;
16
+ }
17
+ }
18
+ return true;
19
+ }
20
+ function mergeMiddlewares(first, second, options) {
21
+ if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
22
+ return second;
23
+ }
24
+ return [...first, ...second];
25
+ }
26
+ function addMiddleware(middlewares, addition) {
27
+ return [...middlewares, addition];
28
+ }
29
+
30
+ class Procedure {
31
+ /**
32
+ * This property holds the defined options.
33
+ */
34
+ "~orpc";
35
+ constructor(def) {
36
+ this["~orpc"] = def;
37
+ }
38
+ }
39
+ function isProcedure(item) {
40
+ if (item instanceof Procedure) {
41
+ return true;
42
+ }
43
+ return isContractProcedure(item) && "middlewares" in item["~orpc"] && "handler" in item["~orpc"];
44
+ }
45
+
46
+ function mergeCurrentContext(context, other) {
47
+ return { ...context, ...other };
48
+ }
49
+
50
+ function createORPCErrorConstructorMap(errors) {
51
+ const proxy = new Proxy(errors, {
52
+ get(target, code) {
53
+ if (typeof code !== "string") {
54
+ return Reflect.get(target, code);
55
+ }
56
+ const item = (...rest) => {
57
+ const options = resolveMaybeOptionalOptions(rest);
58
+ const config = errors[code];
59
+ return new ORPCError(code, {
60
+ defined: Boolean(config),
61
+ status: config?.status,
62
+ message: options.message ?? config?.message,
63
+ data: options.data,
64
+ cause: options.cause
65
+ });
66
+ };
67
+ return item;
68
+ }
69
+ });
70
+ return proxy;
71
+ }
72
+
73
+ const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
74
+ function setHiddenRouterContract(router, contract) {
75
+ return new Proxy(router, {
76
+ get(target, key) {
77
+ if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
78
+ return contract;
79
+ }
80
+ return Reflect.get(target, key);
81
+ }
82
+ });
83
+ }
84
+ function getHiddenRouterContract(router) {
85
+ return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
86
+ }
87
+
88
+ function getRouter(router, path) {
89
+ let current = router;
90
+ for (let i = 0; i < path.length; i++) {
91
+ const segment = path[i];
92
+ if (!current) {
93
+ return void 0;
94
+ }
95
+ if (isProcedure(current)) {
96
+ return void 0;
97
+ }
98
+ if (!isLazy(current)) {
99
+ current = current[segment];
100
+ continue;
101
+ }
102
+ const lazied = current;
103
+ const rest = path.slice(i);
104
+ return lazyInternal(async () => {
105
+ const unwrapped = await unlazy(lazied);
106
+ const next = getRouter(unwrapped.default, rest);
107
+ return unlazy(next);
108
+ }, getLazyMeta(lazied));
109
+ }
110
+ return current;
111
+ }
112
+ function createAccessibleLazyRouter(lazied) {
113
+ const recursive = new Proxy(lazied, {
114
+ get(target, key) {
115
+ if (typeof key !== "string") {
116
+ return Reflect.get(target, key);
117
+ }
118
+ const next = getRouter(lazied, [key]);
119
+ return createAccessibleLazyRouter(next);
120
+ }
121
+ });
122
+ return recursive;
123
+ }
124
+ function enhanceRouter(router, options) {
125
+ if (isLazy(router)) {
126
+ const laziedMeta = getLazyMeta(router);
127
+ const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
128
+ const enhanced2 = lazyInternal(
129
+ async () => {
130
+ const { default: unlaziedRouter } = await unlazy(router);
131
+ const enhanced3 = enhanceRouter(unlaziedRouter, options);
132
+ return unlazy(enhanced3);
133
+ },
134
+ {
135
+ ...laziedMeta,
136
+ prefix: enhancedPrefix
137
+ }
138
+ );
139
+ const accessible = createAccessibleLazyRouter(enhanced2);
140
+ return accessible;
141
+ }
142
+ if (isProcedure(router)) {
143
+ const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, {
144
+ dedupeLeading: options.dedupeLeadingMiddlewares
145
+ });
146
+ const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
147
+ const enhanced2 = new Procedure({
148
+ ...router["~orpc"],
149
+ route: enhanceRoute(router["~orpc"].route, options),
150
+ errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
151
+ middlewares: newMiddlewares,
152
+ inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
153
+ outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
154
+ });
155
+ return enhanced2;
156
+ }
157
+ const enhanced = {};
158
+ for (const key in router) {
159
+ enhanced[key] = enhanceRouter(router[key], options);
160
+ }
161
+ return enhanced;
162
+ }
163
+ function traverseContractProcedures(options, callback, lazyOptions = []) {
164
+ let currentRouter = options.router;
165
+ const hiddenContract = getHiddenRouterContract(options.router);
166
+ if (hiddenContract !== void 0) {
167
+ currentRouter = hiddenContract;
168
+ }
169
+ if (isLazy(currentRouter)) {
170
+ lazyOptions.push({
171
+ router: currentRouter,
172
+ path: options.path
173
+ });
174
+ } else if (isContractProcedure(currentRouter)) {
175
+ callback({
176
+ contract: currentRouter,
177
+ path: options.path
178
+ });
179
+ } else {
180
+ for (const key in currentRouter) {
181
+ traverseContractProcedures(
182
+ {
183
+ router: currentRouter[key],
184
+ path: [...options.path, key]
185
+ },
186
+ callback,
187
+ lazyOptions
188
+ );
189
+ }
190
+ }
191
+ return lazyOptions;
192
+ }
193
+ async function resolveContractProcedures(options, callback) {
194
+ const pending = [options];
195
+ for (const options2 of pending) {
196
+ const lazyOptions = traverseContractProcedures(options2, callback);
197
+ for (const options3 of lazyOptions) {
198
+ const { default: router } = await unlazy(options3.router);
199
+ pending.push({
200
+ router,
201
+ path: options3.path
202
+ });
203
+ }
204
+ }
205
+ }
206
+ async function unlazyRouter(router) {
207
+ if (isProcedure(router)) {
208
+ return router;
209
+ }
210
+ const unlazied = {};
211
+ for (const key in router) {
212
+ const item = router[key];
213
+ const { default: unlaziedRouter } = await unlazy(item);
214
+ unlazied[key] = await unlazyRouter(unlaziedRouter);
215
+ }
216
+ return unlazied;
217
+ }
218
+
219
+ const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
220
+ function lazyInternal(loader, meta = {}) {
221
+ return {
222
+ [LAZY_SYMBOL]: {
223
+ loader,
224
+ meta
225
+ }
226
+ };
227
+ }
228
+ function lazy(prefix, loader) {
229
+ return enhanceRouter(lazyInternal(loader), {
230
+ middlewares: [],
231
+ errorMap: {},
232
+ dedupeLeadingMiddlewares: true,
233
+ prefix
234
+ });
235
+ }
236
+ function isLazy(item) {
237
+ return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
238
+ }
239
+ function getLazyMeta(lazied) {
240
+ return lazied[LAZY_SYMBOL].meta;
241
+ }
242
+ function unlazy(lazied) {
243
+ return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
244
+ }
245
+
246
+ function middlewareOutputFn(output) {
247
+ return { output, context: {} };
248
+ }
249
+
250
+ function createProcedureClient(lazyableProcedure, ...rest) {
251
+ const options = resolveMaybeOptionalOptions(rest);
252
+ return async (...[input, callerOptions]) => {
253
+ const path = toArray(options.path);
254
+ const { default: procedure } = await unlazy(lazyableProcedure);
255
+ const clientContext = callerOptions?.context ?? {};
256
+ const context = await value(options.context ?? {}, clientContext);
257
+ const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
258
+ const validateError = async (e) => {
259
+ if (e instanceof ORPCError) {
260
+ return await validateORPCError(procedure["~orpc"].errorMap, e);
261
+ }
262
+ return e;
263
+ };
264
+ try {
265
+ const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
266
+ span?.setAttribute("procedure.path", [...path]);
267
+ return intercept(
268
+ toArray(options.interceptors),
269
+ {
270
+ context,
271
+ input,
272
+ errors,
273
+ path,
274
+ procedure,
275
+ signal: callerOptions?.signal,
276
+ lastEventId: callerOptions?.lastEventId
277
+ },
278
+ (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
279
+ );
280
+ });
281
+ if (isAsyncIteratorObject(output)) {
282
+ if (output instanceof HibernationEventIterator) {
283
+ return output;
284
+ }
285
+ return overlayProxy(
286
+ output,
287
+ mapEventIterator(
288
+ asyncIteratorWithSpan(
289
+ { name: "consume_event_iterator_output", signal: callerOptions?.signal },
290
+ output
291
+ ),
292
+ {
293
+ value: (v) => v,
294
+ error: (e) => validateError(e)
295
+ }
296
+ )
297
+ );
298
+ }
299
+ return output;
300
+ } catch (e) {
301
+ throw await validateError(e);
302
+ }
303
+ };
304
+ }
305
+ async function validateInput(procedure, input) {
306
+ const schemas = procedure["~orpc"].schemas;
307
+ return runWithSpan({ name: "validate_input" }, async () => {
308
+ const resultBody = await safeParseAsync(schemas.bodySchema, input.body);
309
+ const resultPath = await safeParseAsync(schemas.pathSchema, input.path);
310
+ const resultQuery = await safeParseAsync(schemas.querySchema, input.query);
311
+ const issues = [];
312
+ if (!resultBody.success) {
313
+ issues.push(...resultBody.error.issues.map((i) => ({ ...i, path: ["body", ...i.path] })));
314
+ }
315
+ if (!resultPath.success) {
316
+ issues.push(...resultPath.error.issues.map((i) => ({ ...i, path: ["path", ...i.path] })));
317
+ }
318
+ if (!resultQuery.success) {
319
+ issues.push(...resultQuery.error.issues.map((i) => ({ ...i, path: ["query", ...i.path] })));
320
+ }
321
+ if (issues.length > 0) {
322
+ throw new ORPCError("BAD_REQUEST", {
323
+ message: "Input validation failed",
324
+ data: {
325
+ issues
326
+ },
327
+ cause: new ValidationError({
328
+ message: "Input validation failed",
329
+ issues,
330
+ data: input
331
+ })
332
+ });
333
+ }
334
+ const results = {
335
+ body: resultBody.data,
336
+ path: resultPath.data,
337
+ query: resultQuery.data
338
+ };
339
+ return results;
340
+ });
341
+ }
342
+ async function validateOutput(procedure, output) {
343
+ const schema = procedure["~orpc"].schemas.outputSchema;
344
+ if (!schema) {
345
+ return output;
346
+ }
347
+ return runWithSpan({ name: "validate_output" }, async () => {
348
+ const result = await safeParseAsync(schema, output);
349
+ if (!result.success) {
350
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
351
+ message: "Output validation failed",
352
+ cause: new ValidationError({
353
+ message: "Output validation failed",
354
+ issues: result.error.issues,
355
+ data: output
356
+ })
357
+ });
358
+ }
359
+ return result.data;
360
+ });
361
+ }
362
+ async function executeProcedureInternal(procedure, options) {
363
+ const middlewares = procedure["~orpc"].middlewares;
364
+ const inputValidationIndex = Math.min(
365
+ Math.max(0, procedure["~orpc"].inputValidationIndex),
366
+ middlewares.length
367
+ );
368
+ const outputValidationIndex = Math.min(
369
+ Math.max(0, procedure["~orpc"].outputValidationIndex),
370
+ middlewares.length
371
+ );
372
+ const next = async (index, context, input) => {
373
+ let currentInput = input;
374
+ if (index === inputValidationIndex) {
375
+ currentInput = await validateInput(procedure, currentInput);
376
+ }
377
+ const mid = middlewares[index];
378
+ const output = mid ? await runWithSpan({ name: `middleware.${mid.name}`, signal: options.signal }, async (span) => {
379
+ span?.setAttribute("middleware.index", index);
380
+ span?.setAttribute("middleware.name", mid.name);
381
+ const result = await mid(
382
+ {
383
+ ...options,
384
+ context,
385
+ next: async (...[nextOptions]) => {
386
+ const nextContext = nextOptions?.context ?? {};
387
+ return {
388
+ output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
389
+ context: nextContext
390
+ };
391
+ }
392
+ },
393
+ currentInput,
394
+ middlewareOutputFn
395
+ );
396
+ return result.output;
397
+ }) : await runWithSpan(
398
+ { name: "handler", signal: options.signal },
399
+ () => procedure["~orpc"].handler({ ...options, context, input: currentInput })
400
+ );
401
+ if (index === outputValidationIndex) {
402
+ return await validateOutput(procedure, output);
403
+ }
404
+ return output;
405
+ };
406
+ return next(0, options.context, options.input);
407
+ }
408
+
409
+ export { LAZY_SYMBOL as L, Procedure as P, addMiddleware as a, isLazy as b, createProcedureClient as c, getRouter as d, enhanceRouter as e, createORPCErrorConstructorMap as f, getLazyMeta as g, lazy as h, isProcedure as i, middlewareOutputFn as j, isStartWithMiddlewares as k, lazyInternal as l, mergeCurrentContext as m, mergeMiddlewares as n, getHiddenRouterContract as o, createAccessibleLazyRouter as p, unlazyRouter as q, resolveContractProcedures as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u };