@temporary-name/server 1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307 → 1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3

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.mjs CHANGED
@@ -1,49 +1,11 @@
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 { isContractProcedure, mergePrefix, mergeErrorMap, enhanceRoute, mergeTags, ContractProcedure, mergeMeta, mergeRoute, prefixRoute, getContractRouter } from '@temporary-name/contract';
4
+ export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
5
+ import { SchemaClass, gatingContext } from '@temporary-name/zod';
6
+ import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy, u as unlazy } from './shared/server.DcfsPloY.mjs';
7
+ export { L as LAZY_SYMBOL, a as createORPCErrorConstructorMap, m as mergeCurrentContext, b as middlewareOutputFn } from './shared/server.DcfsPloY.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
9
 
48
10
  function isStartWithMiddlewares(middlewares, compare) {
49
11
  if (compare.length > middlewares.length) {
@@ -82,55 +44,10 @@ function isProcedure(item) {
82
44
  if (item instanceof Procedure) {
83
45
  return true;
84
46
  }
85
- return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
47
+ return isContractProcedure(item) && "middlewares" in item["~orpc"] && "handler" in item["~orpc"];
86
48
  }
87
49
 
88
50
  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
51
  /**
135
52
  * Make this procedure callable (works like a function while still being a procedure).
136
53
  *
@@ -295,87 +212,49 @@ async function unlazyRouter(router) {
295
212
  return unlazied;
296
213
  }
297
214
 
298
- class Builder {
299
- /**
300
- * This property holds the defined options.
301
- */
302
- "~orpc";
215
+ class ProcedureBuilder extends ContractProcedure {
216
+ z;
303
217
  constructor(def) {
304
- this["~orpc"] = def;
218
+ super(def);
219
+ this.z = new SchemaClass();
305
220
  }
306
221
  /**
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);
321
- }
322
- /**
323
- * Adds type-safe custom errors.
324
- * The provided errors are spared-merged with any existing errors.
222
+ * Adds type-safe custom errors to the contract.
223
+ * The provided errors are spared-merged with any existing errors in the contract.
325
224
  *
326
225
  * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
327
226
  */
328
227
  errors(errors) {
329
- return new Builder({
228
+ return new ProcedureBuilder({
330
229
  ...this["~orpc"],
331
230
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
332
231
  });
333
232
  }
334
233
  /**
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.
234
+ * Sets or updates the metadata for the contract.
235
+ * The provided metadata is spared-merged with any existing metadata in the contract.
358
236
  *
359
237
  * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
360
238
  */
361
239
  meta(meta) {
362
- return new Builder({
240
+ return new ProcedureBuilder({
363
241
  ...this["~orpc"],
364
242
  meta: mergeMeta(this["~orpc"].meta, meta)
365
243
  });
366
244
  }
367
245
  /**
368
- * Sets or updates the route definition.
369
- * The provided route is spared-merged with any existing route.
246
+ * Sets or updates the route definition for the contract.
247
+ * The provided route is spared-merged with any existing route in the contract.
370
248
  * This option is typically relevant when integrating with OpenAPI.
371
249
  *
372
250
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
373
251
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
374
252
  */
375
253
  route(route) {
376
- return new Builder({
254
+ const { prefix } = this["~orpc"];
255
+ return new ProcedureBuilder({
377
256
  ...this["~orpc"],
378
- route: mergeRoute(this["~orpc"].route, route)
257
+ route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
379
258
  });
380
259
  }
381
260
  /**
@@ -384,7 +263,7 @@ class Builder {
384
263
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
385
264
  */
386
265
  input(schema) {
387
- return new Builder({
266
+ return new ProcedureBuilder({
388
267
  ...this["~orpc"],
389
268
  inputSchema: schema,
390
269
  inputValidationIndex: this["~orpc"].middlewares.length
@@ -396,12 +275,33 @@ class Builder {
396
275
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
397
276
  */
398
277
  output(schema) {
399
- return new Builder({
278
+ return new ProcedureBuilder({
400
279
  ...this["~orpc"],
401
280
  outputSchema: schema,
402
281
  outputValidationIndex: this["~orpc"].middlewares.length
403
282
  });
404
283
  }
284
+ /**
285
+ * Uses a middleware to modify the context or improve the pipeline.
286
+ *
287
+ * @info Supports both normal middleware and inline middleware implementations.
288
+ * @note The current context must be satisfy middleware dependent-context
289
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
290
+ */
291
+ use(middleware) {
292
+ return new this.constructor({
293
+ ...this["~orpc"],
294
+ middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
295
+ });
296
+ }
297
+ useGating(gates, isGateEnabled) {
298
+ return this.use(({ next, context }) => {
299
+ return gatingContext.run(
300
+ (gate) => isGateEnabled(gate, context),
301
+ () => next({ context: { isGateEnabled } })
302
+ );
303
+ });
304
+ }
405
305
  /**
406
306
  * Defines the handler of the procedure.
407
307
  *
@@ -413,6 +313,8 @@ class Builder {
413
313
  handler
414
314
  });
415
315
  }
316
+ }
317
+ class BuilderWithMiddlewares extends ProcedureBuilder {
416
318
  /**
417
319
  * Prefixes all procedures in the router.
418
320
  * The provided prefix is post-appended to any existing router prefix.
@@ -422,7 +324,7 @@ class Builder {
422
324
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
423
325
  */
424
326
  prefix(prefix) {
425
- return new Builder({
327
+ return new this.constructor({
426
328
  ...this["~orpc"],
427
329
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
428
330
  });
@@ -434,7 +336,7 @@ class Builder {
434
336
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
435
337
  */
436
338
  tag(...tags) {
437
- return new Builder({
339
+ return new this.constructor({
438
340
  ...this["~orpc"],
439
341
  tags: mergeTags(this["~orpc"].tags, tags)
440
342
  });
@@ -454,18 +356,74 @@ class Builder {
454
356
  * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
455
357
  */
456
358
  lazyRoute(loader) {
457
- return enhanceRouter(lazy(loader), this["~orpc"]);
359
+ const lazied = lazy(loader);
360
+ return enhanceRouter(lazied, this["~orpc"]);
361
+ }
362
+ }
363
+
364
+ function decorateMiddleware(middleware) {
365
+ const decorated = ((...args) => middleware(...args));
366
+ decorated.mapInput = (mapInput) => {
367
+ const mapped = decorateMiddleware(
368
+ (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
369
+ );
370
+ return mapped;
371
+ };
372
+ decorated.concat = (concatMiddleware, mapInput) => {
373
+ const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
374
+ const concatted = decorateMiddleware((options, input, output, ...rest) => {
375
+ const merged = middleware(
376
+ {
377
+ ...options,
378
+ next: (...[nextOptions1]) => mapped(
379
+ {
380
+ ...options,
381
+ context: { ...options.context, ...nextOptions1?.context },
382
+ next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
383
+ },
384
+ input,
385
+ output,
386
+ ...rest
387
+ )
388
+ },
389
+ input,
390
+ output,
391
+ ...rest
392
+ );
393
+ return merged;
394
+ });
395
+ return concatted;
396
+ };
397
+ return decorated;
398
+ }
399
+
400
+ class Builder extends BuilderWithMiddlewares {
401
+ /**
402
+ * Set or override the initial context.
403
+ *
404
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
405
+ */
406
+ $context() {
407
+ return this;
408
+ }
409
+ /**
410
+ * Creates a middleware.
411
+ *
412
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
413
+ */
414
+ middleware(middleware) {
415
+ return decorateMiddleware(middleware);
458
416
  }
459
417
  }
460
418
  function createApiBuilder(opts = {}) {
461
- const base = new Builder({
419
+ return new Builder({
462
420
  route: {},
463
421
  meta: opts.meta ?? {},
464
422
  errorMap: {},
465
423
  inputValidationIndex: 0,
466
424
  outputValidationIndex: 0,
467
425
  middlewares: [
468
- onError((error, options) => {
426
+ onError((error, _options) => {
469
427
  console.dir(error, { depth: null });
470
428
  })
471
429
  ],
@@ -473,7 +431,6 @@ function createApiBuilder(opts = {}) {
473
431
  // the best solution). For now I've removed the interface to configure it externally.
474
432
  dedupeLeadingMiddlewares: true
475
433
  });
476
- return base;
477
434
  }
478
435
  const os = createApiBuilder();
479
436
 
@@ -614,4 +571,4 @@ function createRouterClient(router, ...rest) {
614
571
  return recursive;
615
572
  }
616
573
 
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 };
574
+ export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, 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 };
@@ -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 { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.C1fnTLq0.mjs';
5
- import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.mjs';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.YXplw8TW.mjs';
5
+ import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.CZNLCQBm.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 { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CQyYNJ1H.js';
5
- import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.js';
4
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.B15EEOr0.js';
5
+ import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.CZNLCQBm.js';
6
6
  import { Meta } from '@temporary-name/contract';
7
7
 
8
8
  interface BatchHandlerOptions<T extends Context> {
@@ -1,6 +1,6 @@
1
1
  import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.BKSOrA6h.js';
3
- import { c as StandardHandleOptions } from './server.CQyYNJ1H.js';
2
+ import { C as Context } from './server.CZNLCQBm.js';
3
+ import { c as StandardHandleOptions } from './server.B15EEOr0.js';
4
4
 
5
5
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
6
  context?: T;
@@ -1,7 +1,7 @@
1
1
  import { Meta } from '@temporary-name/contract';
2
2
  import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.BKSOrA6h.js';
4
+ import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.CZNLCQBm.js';
5
5
 
6
6
  interface StandardHandlerPlugin<T extends Context> {
7
7
  order?: number;
@@ -1,6 +1,6 @@
1
1
  import { isObject, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent, value, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
2
2
  import { flattenHeader } from '@temporary-name/standard-server';
3
- import { c as createProcedureClient } from './server.BKh8I1Ny.mjs';
3
+ import { c as createProcedureClient } from './server.DcfsPloY.mjs';
4
4
  import { fallbackContractConfig } from '@temporary-name/contract';
5
5
  import { d as deserialize, s as serialize, a as standardizeHTTPPath } from './server.BEHw7Eyx.mjs';
6
6
  import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
@@ -71,7 +71,7 @@ declare class Procedure<TInitialContext extends Context, TCurrentContext extends
71
71
  '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
72
72
  constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
73
73
  }
74
- type AnyProcedure = Procedure<any, any, any, any, any, any>;
74
+ type AnyProcedure = Procedure<any, any, AnySchema, AnySchema, any, any>;
75
75
  declare function isProcedure(item: unknown): item is AnyProcedure;
76
76
 
77
77
  type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
@@ -189,4 +189,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
189
189
  };
190
190
 
191
191
  export { isProcedure as D, createProcedureClient as F, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, middlewareOutputFn as y };
192
- export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, Middleware as M, ORPCErrorConstructorMap as O, Router as R, MergedInitialContext as a, MergedCurrentContext as b, MapInputMiddleware as c, CreateProcedureClientOptions as d, ProcedureClient as e, AnyRouter as f, Lazy as g, AnyProcedure as h, ProcedureHandler as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };
192
+ export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, CreateProcedureClientOptions as a, ProcedureClient as b, AnyRouter as c, Lazy as d, AnyProcedure as e, Middleware as f, MergedCurrentContext as g, ProcedureHandler as h, MapInputMiddleware as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };
@@ -71,7 +71,7 @@ declare class Procedure<TInitialContext extends Context, TCurrentContext extends
71
71
  '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
72
72
  constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
73
73
  }
74
- type AnyProcedure = Procedure<any, any, any, any, any, any>;
74
+ type AnyProcedure = Procedure<any, any, AnySchema, AnySchema, any, any>;
75
75
  declare function isProcedure(item: unknown): item is AnyProcedure;
76
76
 
77
77
  type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
@@ -189,4 +189,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
189
189
  };
190
190
 
191
191
  export { isProcedure as D, createProcedureClient as F, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, middlewareOutputFn as y };
192
- export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, Middleware as M, ORPCErrorConstructorMap as O, Router as R, MergedInitialContext as a, MergedCurrentContext as b, MapInputMiddleware as c, CreateProcedureClientOptions as d, ProcedureClient as e, AnyRouter as f, Lazy as g, AnyProcedure as h, ProcedureHandler as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };
192
+ export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, CreateProcedureClientOptions as a, ProcedureClient as b, AnyRouter as c, Lazy as d, AnyProcedure as e, Middleware as f, MergedCurrentContext as g, ProcedureHandler as h, MapInputMiddleware as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };
@@ -1,6 +1,6 @@
1
1
  import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.BKSOrA6h.mjs';
3
- import { c as StandardHandleOptions } from './server.C1fnTLq0.mjs';
2
+ import { C as Context } from './server.CZNLCQBm.mjs';
3
+ import { c as StandardHandleOptions } from './server.YXplw8TW.mjs';
4
4
 
5
5
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
6
  context?: T;
@@ -1,39 +1,7 @@
1
1
  import { validateORPCError, ValidationError } from '@temporary-name/contract';
2
2
  import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
3
3
  import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
4
- import { AsyncLocalStorage } from 'node:async_hooks';
5
- import 'zod';
6
- import * as z4 from 'zod/v4/core';
7
-
8
- const gatingContext = new AsyncLocalStorage();
9
- function withoutGatedFields(data, schema, isGateEnabled) {
10
- const filtered = { ...data };
11
- const gatedFields = getGatedFields(schema);
12
- for (const [fieldName, gate] of gatedFields) {
13
- if (!isGateEnabled(gate)) {
14
- delete filtered[fieldName];
15
- }
16
- }
17
- return filtered;
18
- }
19
- function getGatedFields(schema) {
20
- if (!schema || schema["~standard"].vendor !== "zod") {
21
- return [];
22
- }
23
- const gatedFields = [];
24
- const zodDef = schema._zod.def;
25
- if (zodDef.type === "object") {
26
- const shape = zodDef.shape;
27
- for (const fieldName in shape) {
28
- const fieldSchema = shape[fieldName];
29
- const gate = z4.globalRegistry.get(fieldSchema)?.gate;
30
- if (gate) {
31
- gatedFields.push([fieldName, gate]);
32
- }
33
- }
34
- }
35
- return gatedFields;
36
- }
4
+ import { safeParseAsync } from '@temporary-name/zod';
37
5
 
38
6
  const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
39
7
  function lazy(loader, meta = {}) {
@@ -147,37 +115,41 @@ async function validateInput(procedure, input) {
147
115
  return input;
148
116
  }
149
117
  return runWithSpan({ name: "validate_input" }, async () => {
150
- const result = await schema["~standard"].validate(input);
151
- if (result.issues) {
118
+ const result = await safeParseAsync(schema, input);
119
+ if (!result.success) {
152
120
  throw new ORPCError("BAD_REQUEST", {
153
121
  message: "Input validation failed",
154
122
  data: {
155
- issues: result.issues
123
+ issues: result.error.issues
156
124
  },
157
125
  cause: new ValidationError({
158
126
  message: "Input validation failed",
159
- issues: result.issues,
127
+ issues: result.error.issues,
160
128
  data: input
161
129
  })
162
130
  });
163
131
  }
164
- return result.value;
132
+ return result.data;
165
133
  });
166
134
  }
167
- async function validateOutput(schema, output) {
135
+ async function validateOutput(procedure, output) {
136
+ const schema = procedure["~orpc"].outputSchema;
137
+ if (!schema) {
138
+ return output;
139
+ }
168
140
  return runWithSpan({ name: "validate_output" }, async () => {
169
- const result = await schema["~standard"].validate(output);
170
- if (result.issues) {
141
+ const result = await safeParseAsync(schema, output);
142
+ if (!result.success) {
171
143
  throw new ORPCError("INTERNAL_SERVER_ERROR", {
172
144
  message: "Output validation failed",
173
145
  cause: new ValidationError({
174
146
  message: "Output validation failed",
175
- issues: result.issues,
147
+ issues: result.error.issues,
176
148
  data: output
177
149
  })
178
150
  });
179
151
  }
180
- return result.value;
152
+ return result.data;
181
153
  });
182
154
  }
183
155
  async function executeProcedureInternal(procedure, options) {
@@ -220,20 +192,11 @@ async function executeProcedureInternal(procedure, options) {
220
192
  () => procedure["~orpc"].handler({ ...options, context, input: currentInput })
221
193
  );
222
194
  if (index === outputValidationIndex) {
223
- const schema = procedure["~orpc"].outputSchema;
224
- if (!schema) {
225
- return output;
226
- }
227
- const validated = await validateOutput(schema, output);
228
- const isGateEnabled = gatingContext.getStore();
229
- if (!validated || !isGateEnabled) {
230
- return validated;
231
- }
232
- return withoutGatedFields(validated, schema, isGateEnabled);
195
+ return await validateOutput(procedure, output);
233
196
  }
234
197
  return output;
235
198
  };
236
199
  return next(0, options.context, options.input);
237
200
  }
238
201
 
239
- export { LAZY_SYMBOL as L, gatingContext as a, createORPCErrorConstructorMap as b, createProcedureClient as c, middlewareOutputFn as d, getLazyMeta as g, isLazy as i, lazy as l, mergeCurrentContext as m, unlazy as u };
202
+ export { LAZY_SYMBOL as L, createORPCErrorConstructorMap as a, middlewareOutputFn as b, createProcedureClient as c, getLazyMeta as g, isLazy as i, lazy as l, mergeCurrentContext as m, unlazy as u };
@@ -1,7 +1,7 @@
1
1
  import { Meta } from '@temporary-name/contract';
2
2
  import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.BKSOrA6h.mjs';
4
+ import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.CZNLCQBm.mjs';
5
5
 
6
6
  interface StandardHandlerPlugin<T extends Context> {
7
7
  order?: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@temporary-name/server",
3
3
  "type": "module",
4
- "version": "1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307",
4
+ "version": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.stainless.com/",
7
7
  "repository": {
@@ -71,16 +71,17 @@
71
71
  },
72
72
  "dependencies": {
73
73
  "cookie": "^1.0.2",
74
- "@standard-schema/spec": "^1.0.0",
75
74
  "rou3": "^0.7.7",
76
75
  "zod": "^4.1.12",
77
- "@temporary-name/interop": "1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307",
78
- "@temporary-name/shared": "1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307",
79
- "@temporary-name/contract": "1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307",
80
- "@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307",
81
- "@temporary-name/standard-server": "1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307",
82
- "@temporary-name/standard-server-fetch": "1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307",
83
- "@temporary-name/standard-server-node": "1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307"
76
+ "@temporary-name/contract": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
77
+ "@temporary-name/interop": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
78
+ "@temporary-name/json-schema": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
79
+ "@temporary-name/shared": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
80
+ "@temporary-name/standard-server-fetch": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
81
+ "@temporary-name/standard-server-node": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
82
+ "@temporary-name/zod": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
83
+ "@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3",
84
+ "@temporary-name/standard-server": "1.9.3-alpha.76a5d8c6a7525b4b17df3f9565304645f0922ab3"
84
85
  },
85
86
  "devDependencies": {
86
87
  "@types/supertest": "^6.0.3",