@orpc/server 0.0.0-next.8e347ae → 0.0.0-next.8f622a0
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/README.md +2 -0
- package/dist/adapters/fetch/index.d.mts +5 -3
- package/dist/adapters/fetch/index.d.ts +5 -3
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/hono/index.d.mts +4 -2
- package/dist/adapters/hono/index.d.ts +4 -2
- package/dist/adapters/hono/index.mjs +4 -4
- package/dist/adapters/next/index.d.mts +4 -2
- package/dist/adapters/next/index.d.ts +4 -2
- package/dist/adapters/next/index.mjs +4 -4
- package/dist/adapters/node/index.d.mts +5 -3
- package/dist/adapters/node/index.d.ts +5 -3
- package/dist/adapters/node/index.mjs +8 -7
- package/dist/adapters/standard/index.d.mts +9 -8
- package/dist/adapters/standard/index.d.ts +9 -8
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +53 -44
- package/dist/index.d.ts +53 -44
- package/dist/index.mjs +21 -22
- package/dist/plugins/index.d.mts +3 -3
- package/dist/plugins/index.d.ts +3 -3
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/server.B52eKaNe.d.mts +8 -0
- package/dist/shared/server.BA-onDGB.d.ts +8 -0
- package/dist/shared/{server.CSZRzcSW.mjs → server.BY9sDlwl.mjs} +6 -6
- package/dist/shared/{server.CPteJIPP.d.mts → server.BYTulgUc.d.mts} +12 -11
- package/dist/shared/{server.CPteJIPP.d.ts → server.BYTulgUc.d.ts} +12 -11
- package/dist/shared/{server.CMrS28Go.mjs → server.BtxZnWJ9.mjs} +35 -7
- package/dist/shared/{server.DmW25ynm.d.ts → server.CDzXh8DM.d.mts} +3 -3
- package/dist/shared/{server.CM3tWr3C.d.mts → server.CkGvC2T0.d.ts} +3 -3
- package/dist/shared/{server.Q6ZmnTgO.mjs → server.Dba3Iiyp.mjs} +2 -2
- package/dist/shared/{server.Cq3B6PoL.mjs → server.Del5OmaY.mjs} +6 -5
- package/package.json +7 -7
@@ -1,19 +1,20 @@
|
|
1
1
|
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
-
import {
|
2
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
3
|
import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
4
4
|
|
5
5
|
type Context = Record<string, any>;
|
6
|
-
type
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}[keyof T] ? never : unknown;
|
6
|
+
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
7
|
+
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
8
|
+
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
9
|
+
type ContextExtendsGuard<T extends Context, U extends Context> = T extends U ? unknown : never;
|
11
10
|
|
12
11
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
13
12
|
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
14
13
|
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
15
14
|
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
16
15
|
};
|
16
|
+
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
17
|
+
declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
17
18
|
|
18
19
|
declare const LAZY_SYMBOL: unique symbol;
|
19
20
|
interface LazyMeta {
|
@@ -51,7 +52,7 @@ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutp
|
|
51
52
|
}
|
52
53
|
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
53
54
|
__initialContext?: (type: TInitialContext) => unknown;
|
54
|
-
middlewares: AnyMiddleware[];
|
55
|
+
middlewares: readonly AnyMiddleware[];
|
55
56
|
inputValidationIndex: number;
|
56
57
|
outputValidationIndex: number;
|
57
58
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
@@ -72,8 +73,8 @@ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never>
|
|
72
73
|
} : {
|
73
74
|
context: TOutContext;
|
74
75
|
};
|
75
|
-
interface MiddlewareNextFn<
|
76
|
-
<U extends Context
|
76
|
+
interface MiddlewareNextFn<TOutput> {
|
77
|
+
<U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
77
78
|
}
|
78
79
|
interface MiddlewareOutputFn<TOutput> {
|
79
80
|
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
@@ -84,7 +85,7 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
|
|
84
85
|
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
85
86
|
signal?: AbortSignal;
|
86
87
|
lastEventId: string | undefined;
|
87
|
-
next: MiddlewareNextFn<
|
88
|
+
next: MiddlewareNextFn<TOutput>;
|
88
89
|
errors: TErrorConstructorMap;
|
89
90
|
}
|
90
91
|
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
@@ -140,4 +141,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
140
141
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
141
142
|
};
|
142
143
|
|
143
|
-
export { type AnyProcedure as A,
|
144
|
+
export { type AnyProcedure as A, type MiddlewareOptions as B, type Context as C, middlewareOutputFn as D, type ProcedureHandlerOptions as E, type ProcedureDef as F, isProcedure as G, createProcedureClient as H, type InferRouterInitialContext as I, type InferRouterInitialContexts as J, type InferRouterCurrentContexts as K, type Lazyable as L, type Middleware as M, type InferRouterInputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type InferRouterOutputs as Q, type Router as R, type AnyRouter as a, Procedure as b, type ContextExtendsGuard as c, type MergedCurrentContext as d, type MergedInitialContext as e, type MapInputMiddleware as f, type CreateProcedureClientOptions as g, type ProcedureClient as h, type AnyMiddleware as i, type Lazy as j, type ProcedureHandler as k, type ORPCErrorConstructorMapItemOptions as l, mergeCurrentContext as m, type ORPCErrorConstructorMapItem as n, createORPCErrorConstructorMap as o, LAZY_SYMBOL as p, type LazyMeta as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u, validateORPCError as v, type MiddlewareResult as w, type MiddlewareNextFnOptions as x, type MiddlewareNextFn as y, type MiddlewareOutputFn as z };
|
@@ -21,7 +21,24 @@ function unlazy(lazied) {
|
|
21
21
|
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
|
22
22
|
}
|
23
23
|
|
24
|
-
function
|
24
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
25
|
+
if (compare.length > middlewares.length) {
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
for (let i = 0; i < middlewares.length; i++) {
|
29
|
+
if (compare[i] === void 0) {
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
if (middlewares[i] !== compare[i]) {
|
33
|
+
return false;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
function mergeMiddlewares(first, second, options) {
|
39
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
40
|
+
return second;
|
41
|
+
}
|
25
42
|
return [...first, ...second];
|
26
43
|
}
|
27
44
|
function addMiddleware(middlewares, addition) {
|
@@ -41,6 +58,10 @@ function isProcedure(item) {
|
|
41
58
|
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
42
59
|
}
|
43
60
|
|
61
|
+
function mergeCurrentContext(context, other) {
|
62
|
+
return { ...context, ...other };
|
63
|
+
}
|
64
|
+
|
44
65
|
function createORPCErrorConstructorMap(errors) {
|
45
66
|
const proxy = new Proxy(errors, {
|
46
67
|
get(target, code) {
|
@@ -153,23 +174,30 @@ async function executeProcedureInternal(procedure, options) {
|
|
153
174
|
let currentInput = options.input;
|
154
175
|
const next = async (...[nextOptions]) => {
|
155
176
|
const index = currentIndex;
|
177
|
+
const midContext = nextOptions?.context ?? {};
|
156
178
|
currentIndex += 1;
|
157
|
-
currentContext =
|
179
|
+
currentContext = mergeCurrentContext(currentContext, midContext);
|
158
180
|
if (index === inputValidationIndex) {
|
159
181
|
currentInput = await validateInput(procedure, currentInput);
|
160
182
|
}
|
161
183
|
const mid = middlewares[index];
|
162
|
-
const result = mid ?
|
184
|
+
const result = mid ? {
|
185
|
+
context: midContext,
|
186
|
+
output: (await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn)).output
|
187
|
+
} : {
|
188
|
+
context: midContext,
|
189
|
+
output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput })
|
190
|
+
};
|
163
191
|
if (index === outputValidationIndex) {
|
164
192
|
const validatedOutput = await validateOutput(procedure, result.output);
|
165
193
|
return {
|
166
|
-
|
194
|
+
context: result.context,
|
167
195
|
output: validatedOutput
|
168
196
|
};
|
169
197
|
}
|
170
198
|
return result;
|
171
199
|
};
|
172
|
-
return (await next(
|
200
|
+
return (await next()).output;
|
173
201
|
}
|
174
202
|
|
175
203
|
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
@@ -239,7 +267,7 @@ function enhanceRouter(router, options) {
|
|
239
267
|
return accessible;
|
240
268
|
}
|
241
269
|
if (isProcedure(router)) {
|
242
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
|
270
|
+
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
|
243
271
|
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
244
272
|
const enhanced2 = new Procedure({
|
245
273
|
...router["~orpc"],
|
@@ -343,4 +371,4 @@ function toHttpPath(path) {
|
|
343
371
|
return `/${path.map(encodeURIComponent).join("/")}`;
|
344
372
|
}
|
345
373
|
|
346
|
-
export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i,
|
374
|
+
export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i, createORPCErrorConstructorMap as j, getLazyMeta as k, lazy as l, mergeCurrentContext as m, middlewareOutputFn as n, isStartWithMiddlewares as o, mergeMiddlewares as p, call as q, getHiddenRouterContract as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, createAccessibleLazyRouter as w, resolveContractProcedures as x, unlazyRouter as y };
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
-
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.mjs';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
@@ -66,10 +66,10 @@ declare class StandardHandler<T extends Context> {
|
|
66
66
|
interface HandlerPlugin<TContext extends Context> {
|
67
67
|
init?(options: StandardHandlerOptions<TContext>): void;
|
68
68
|
}
|
69
|
-
declare class
|
69
|
+
declare class CompositeHandlerPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
70
|
private readonly plugins;
|
71
71
|
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
72
|
init(options: StandardHandlerOptions<TContext>): void;
|
73
73
|
}
|
74
74
|
|
75
|
-
export {
|
75
|
+
export { CompositeHandlerPlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
-
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.js';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
@@ -66,10 +66,10 @@ declare class StandardHandler<T extends Context> {
|
|
66
66
|
interface HandlerPlugin<TContext extends Context> {
|
67
67
|
init?(options: StandardHandlerOptions<TContext>): void;
|
68
68
|
}
|
69
|
-
declare class
|
69
|
+
declare class CompositeHandlerPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
70
|
private readonly plugins;
|
71
71
|
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
72
|
init(options: StandardHandlerOptions<TContext>): void;
|
73
73
|
}
|
74
74
|
|
75
|
-
export {
|
75
|
+
export { CompositeHandlerPlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|
@@ -1,13 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
2
|
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
-
import { S as StandardHandler,
|
3
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.BY9sDlwl.mjs';
|
4
4
|
|
5
5
|
class RPCHandler {
|
6
6
|
standardHandler;
|
7
7
|
constructor(router, options = {}) {
|
8
|
-
const
|
9
|
-
const
|
10
|
-
const
|
8
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
9
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
10
|
+
const matcher = new StandardRPCMatcher();
|
11
|
+
const codec = new StandardRPCCodec(serializer);
|
11
12
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
12
13
|
}
|
13
14
|
async handle(request, ...[
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.8f622a0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -58,12 +58,12 @@
|
|
58
58
|
"next": ">=14.0.0"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@orpc/contract": "0.0.0-next.
|
62
|
-
"@orpc/shared": "0.0.0-next.
|
63
|
-
"@orpc/
|
64
|
-
"@orpc/standard-server": "0.0.0-next.
|
65
|
-
"@orpc/standard-server-node": "0.0.0-next.
|
66
|
-
"@orpc/
|
61
|
+
"@orpc/contract": "0.0.0-next.8f622a0",
|
62
|
+
"@orpc/shared": "0.0.0-next.8f622a0",
|
63
|
+
"@orpc/standard-server-fetch": "0.0.0-next.8f622a0",
|
64
|
+
"@orpc/standard-server": "0.0.0-next.8f622a0",
|
65
|
+
"@orpc/standard-server-node": "0.0.0-next.8f622a0",
|
66
|
+
"@orpc/client": "0.0.0-next.8f622a0"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
69
|
"light-my-request": "^6.5.1"
|