@temporary-name/server 1.9.3-alpha.37dfe6603933b8e445661fe453c4fbdb30ccb524 → 1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d
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/adapters/aws-lambda/index.d.mts +3 -3
- package/dist/adapters/aws-lambda/index.d.ts +3 -3
- package/dist/adapters/aws-lambda/index.mjs +3 -5
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +3 -5
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +3 -5
- package/dist/adapters/standard/index.d.mts +3 -3
- package/dist/adapters/standard/index.d.ts +3 -3
- package/dist/adapters/standard/index.mjs +3 -5
- package/dist/index.d.mts +41 -222
- package/dist/index.d.ts +41 -222
- package/dist/index.mjs +93 -92
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.DLsti1Pv.mjs → server.B9VxPdeK.mjs} +1 -1
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.B9i6p26R.d.ts} +1 -1
- package/dist/shared/{server.BKSOrA6h.d.mts → server.Bzrdopnd.d.mts} +1 -1
- package/dist/shared/{server.BKSOrA6h.d.ts → server.Bzrdopnd.d.ts} +1 -1
- package/dist/shared/{server.C1fnTLq0.d.mts → server.C-j2WKJz.d.mts} +1 -1
- package/dist/shared/{server.SLLuK6_v.d.ts → server.CYRDznXq.d.ts} +2 -2
- package/dist/shared/{server.BeuTpcmO.d.mts → server.Cp__uvkw.d.mts} +2 -2
- package/dist/shared/{server.BKh8I1Ny.mjs → server.DcfsPloY.mjs} +17 -54
- package/package.json +10 -9
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
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 {
|
|
6
|
-
export {
|
|
3
|
+
import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, ContractProcedure, 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
|
11
|
+
if (compare.length > middlewares.length) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
15
|
+
if (compare[i] === void 0) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (middlewares[i] !== compare[i]) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function mergeMiddlewares(first, second, options) {
|
|
25
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
26
|
+
return second;
|
|
27
|
+
}
|
|
28
|
+
return [...first, ...second];
|
|
29
|
+
}
|
|
30
|
+
function addMiddleware(middlewares, addition) {
|
|
31
|
+
return [...middlewares, addition];
|
|
32
|
+
}
|
|
11
33
|
|
|
12
34
|
function decorateMiddleware(middleware) {
|
|
13
35
|
const decorated = ((...args) => middleware(...args));
|
|
@@ -45,30 +67,6 @@ function decorateMiddleware(middleware) {
|
|
|
45
67
|
return decorated;
|
|
46
68
|
}
|
|
47
69
|
|
|
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
70
|
class Procedure {
|
|
73
71
|
/**
|
|
74
72
|
* This property holds the defined options.
|
|
@@ -295,87 +293,49 @@ async function unlazyRouter(router) {
|
|
|
295
293
|
return unlazied;
|
|
296
294
|
}
|
|
297
295
|
|
|
298
|
-
class
|
|
299
|
-
|
|
300
|
-
* This property holds the defined options.
|
|
301
|
-
*/
|
|
302
|
-
"~orpc";
|
|
296
|
+
class ProcedureBuilder extends ContractProcedure {
|
|
297
|
+
z;
|
|
303
298
|
constructor(def) {
|
|
304
|
-
|
|
299
|
+
super(def);
|
|
300
|
+
this.z = new SchemaClass();
|
|
305
301
|
}
|
|
306
302
|
/**
|
|
307
|
-
*
|
|
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.
|
|
303
|
+
* Adds type-safe custom errors to the contract.
|
|
304
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
325
305
|
*
|
|
326
306
|
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
327
307
|
*/
|
|
328
308
|
errors(errors) {
|
|
329
|
-
return new
|
|
309
|
+
return new ProcedureBuilder({
|
|
330
310
|
...this["~orpc"],
|
|
331
311
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
332
312
|
});
|
|
333
313
|
}
|
|
334
314
|
/**
|
|
335
|
-
*
|
|
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.
|
|
315
|
+
* Sets or updates the metadata for the contract.
|
|
316
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
358
317
|
*
|
|
359
318
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
360
319
|
*/
|
|
361
320
|
meta(meta) {
|
|
362
|
-
return new
|
|
321
|
+
return new ProcedureBuilder({
|
|
363
322
|
...this["~orpc"],
|
|
364
323
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
365
324
|
});
|
|
366
325
|
}
|
|
367
326
|
/**
|
|
368
|
-
* Sets or updates the route definition.
|
|
369
|
-
* The provided route is spared-merged with any existing route.
|
|
327
|
+
* Sets or updates the route definition for the contract.
|
|
328
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
370
329
|
* This option is typically relevant when integrating with OpenAPI.
|
|
371
330
|
*
|
|
372
331
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
373
332
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
374
333
|
*/
|
|
375
334
|
route(route) {
|
|
376
|
-
|
|
335
|
+
const { prefix } = this["~orpc"];
|
|
336
|
+
return new ProcedureBuilder({
|
|
377
337
|
...this["~orpc"],
|
|
378
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
338
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
379
339
|
});
|
|
380
340
|
}
|
|
381
341
|
/**
|
|
@@ -384,7 +344,7 @@ class Builder {
|
|
|
384
344
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
385
345
|
*/
|
|
386
346
|
input(schema) {
|
|
387
|
-
return new
|
|
347
|
+
return new ProcedureBuilder({
|
|
388
348
|
...this["~orpc"],
|
|
389
349
|
inputSchema: schema,
|
|
390
350
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
@@ -396,12 +356,33 @@ class Builder {
|
|
|
396
356
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
397
357
|
*/
|
|
398
358
|
output(schema) {
|
|
399
|
-
return new
|
|
359
|
+
return new ProcedureBuilder({
|
|
400
360
|
...this["~orpc"],
|
|
401
361
|
outputSchema: schema,
|
|
402
362
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
403
363
|
});
|
|
404
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
367
|
+
*
|
|
368
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
369
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
370
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
371
|
+
*/
|
|
372
|
+
use(middleware) {
|
|
373
|
+
return new this.constructor({
|
|
374
|
+
...this["~orpc"],
|
|
375
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
useGating(gates, isGateEnabled) {
|
|
379
|
+
return this.use(({ next, context }) => {
|
|
380
|
+
return gatingContext.run(
|
|
381
|
+
(gate) => isGateEnabled(gate, context),
|
|
382
|
+
() => next({ context: { isGateEnabled } })
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
405
386
|
/**
|
|
406
387
|
* Defines the handler of the procedure.
|
|
407
388
|
*
|
|
@@ -413,6 +394,8 @@ class Builder {
|
|
|
413
394
|
handler
|
|
414
395
|
});
|
|
415
396
|
}
|
|
397
|
+
}
|
|
398
|
+
class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
416
399
|
/**
|
|
417
400
|
* Prefixes all procedures in the router.
|
|
418
401
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -422,7 +405,7 @@ class Builder {
|
|
|
422
405
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
423
406
|
*/
|
|
424
407
|
prefix(prefix) {
|
|
425
|
-
return new
|
|
408
|
+
return new this.constructor({
|
|
426
409
|
...this["~orpc"],
|
|
427
410
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
428
411
|
});
|
|
@@ -434,7 +417,7 @@ class Builder {
|
|
|
434
417
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
435
418
|
*/
|
|
436
419
|
tag(...tags) {
|
|
437
|
-
return new
|
|
420
|
+
return new this.constructor({
|
|
438
421
|
...this["~orpc"],
|
|
439
422
|
tags: mergeTags(this["~orpc"].tags, tags)
|
|
440
423
|
});
|
|
@@ -457,15 +440,34 @@ class Builder {
|
|
|
457
440
|
return enhanceRouter(lazy(loader), this["~orpc"]);
|
|
458
441
|
}
|
|
459
442
|
}
|
|
443
|
+
|
|
444
|
+
class Builder extends BuilderWithMiddlewares {
|
|
445
|
+
/**
|
|
446
|
+
* Set or override the initial context.
|
|
447
|
+
*
|
|
448
|
+
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
449
|
+
*/
|
|
450
|
+
$context() {
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Creates a middleware.
|
|
455
|
+
*
|
|
456
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
457
|
+
*/
|
|
458
|
+
middleware(middleware) {
|
|
459
|
+
return decorateMiddleware(middleware);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
460
462
|
function createApiBuilder(opts = {}) {
|
|
461
|
-
|
|
463
|
+
return new Builder({
|
|
462
464
|
route: {},
|
|
463
465
|
meta: opts.meta ?? {},
|
|
464
466
|
errorMap: {},
|
|
465
467
|
inputValidationIndex: 0,
|
|
466
468
|
outputValidationIndex: 0,
|
|
467
469
|
middlewares: [
|
|
468
|
-
onError((error,
|
|
470
|
+
onError((error, _options) => {
|
|
469
471
|
console.dir(error, { depth: null });
|
|
470
472
|
})
|
|
471
473
|
],
|
|
@@ -473,7 +475,6 @@ function createApiBuilder(opts = {}) {
|
|
|
473
475
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
474
476
|
dedupeLeadingMiddlewares: true
|
|
475
477
|
});
|
|
476
|
-
return base;
|
|
477
478
|
}
|
|
478
479
|
const os = createApiBuilder();
|
|
479
480
|
|
|
@@ -614,4 +615,4 @@ function createRouterClient(router, ...rest) {
|
|
|
614
615
|
return recursive;
|
|
615
616
|
}
|
|
616
617
|
|
|
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 };
|
|
618
|
+
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 };
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -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.
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.
|
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.C-j2WKJz.mjs';
|
|
5
|
+
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.Bzrdopnd.mjs';
|
|
6
6
|
import { Meta } from '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface BatchHandlerOptions<T extends Context> {
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -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.
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.
|
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.B9i6p26R.js';
|
|
5
|
+
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.Bzrdopnd.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 { 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.
|
|
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';
|
|
@@ -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.
|
|
4
|
+
import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.Bzrdopnd.js';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|
|
@@ -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,
|
|
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<{
|
|
@@ -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,
|
|
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<{
|
|
@@ -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.
|
|
4
|
+
import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.Bzrdopnd.mjs';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTTPPath } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context } from './server.
|
|
3
|
-
import { c as StandardHandleOptions } from './server.
|
|
2
|
+
import { C as Context } from './server.Bzrdopnd.js';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.B9i6p26R.js';
|
|
4
4
|
|
|
5
5
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
6
|
context?: T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTTPPath } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context } from './server.
|
|
3
|
-
import { c as StandardHandleOptions } from './server.
|
|
2
|
+
import { C as Context } from './server.Bzrdopnd.mjs';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.C-j2WKJz.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 {
|
|
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
|
|
151
|
-
if (result.
|
|
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.
|
|
132
|
+
return result.data;
|
|
165
133
|
});
|
|
166
134
|
}
|
|
167
|
-
async function validateOutput(
|
|
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
|
|
170
|
-
if (result.
|
|
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.
|
|
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
|
-
|
|
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,
|
|
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 };
|
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.
|
|
4
|
+
"version": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
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/contract": "1.9.3-alpha.
|
|
78
|
-
"@temporary-name/interop": "1.9.3-alpha.
|
|
79
|
-
"@temporary-name/shared": "1.9.3-alpha.
|
|
80
|
-
"@temporary-name/standard-server": "1.9.3-alpha.
|
|
81
|
-
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.
|
|
82
|
-
"@temporary-name/standard-server-
|
|
83
|
-
"@temporary-name/standard-server-
|
|
76
|
+
"@temporary-name/contract": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
77
|
+
"@temporary-name/interop": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
78
|
+
"@temporary-name/shared": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
79
|
+
"@temporary-name/standard-server": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
80
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
81
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
82
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
83
|
+
"@temporary-name/json-schema": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d",
|
|
84
|
+
"@temporary-name/zod": "1.9.3-alpha.5537ef74244620c125352bc9356d8c0ae804f10d"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
87
|
"@types/supertest": "^6.0.3",
|