@orpc/server 0.0.0-next.15d9202 → 0.0.0-next.173b319
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 +10 -0
- package/dist/adapters/fetch/index.d.mts +38 -10
- package/dist/adapters/fetch/index.d.ts +38 -10
- package/dist/adapters/fetch/index.mjs +6 -6
- package/dist/adapters/hono/index.d.mts +6 -3
- package/dist/adapters/hono/index.d.ts +6 -3
- package/dist/adapters/hono/index.mjs +6 -6
- package/dist/adapters/next/index.d.mts +6 -3
- package/dist/adapters/next/index.d.ts +6 -3
- package/dist/adapters/next/index.mjs +6 -6
- package/dist/adapters/node/index.d.mts +40 -21
- package/dist/adapters/node/index.d.ts +40 -21
- package/dist/adapters/node/index.mjs +77 -23
- package/dist/adapters/standard/index.d.mts +9 -8
- package/dist/adapters/standard/index.d.ts +9 -8
- package/dist/adapters/standard/index.mjs +2 -3
- package/dist/index.d.mts +29 -30
- package/dist/index.d.ts +29 -30
- package/dist/index.mjs +3 -7
- package/dist/plugins/index.d.mts +11 -12
- package/dist/plugins/index.d.ts +11 -12
- package/dist/plugins/index.mjs +9 -5
- package/dist/shared/{server.hqPWnakL.d.ts → server.23VRZIfj.d.ts} +15 -24
- package/dist/shared/server.B4eSvRkD.mjs +98 -0
- package/dist/shared/server.BG5ftPWa.d.ts +10 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/{server.B_5ZADvP.mjs → server.BtxZnWJ9.mjs} +16 -5
- package/dist/shared/server.C-CCcROC.d.mts +10 -0
- package/dist/shared/server.CIbpOMZX.d.mts +8 -0
- package/dist/shared/server.DCcCuA52.d.ts +8 -0
- package/dist/shared/{server.CL84X8p4.d.mts → server.DJqfB27m.d.mts} +15 -24
- package/dist/shared/{server.3mOimouH.mjs → server.DnR6v9pj.mjs} +32 -30
- package/dist/shared/{server.DnmJuN02.d.mts → server.MZvbGc3n.d.mts} +1 -2
- package/dist/shared/{server.DnmJuN02.d.ts → server.MZvbGc3n.d.ts} +1 -2
- package/package.json +8 -8
- package/dist/shared/server.BgDZnmUZ.mjs +0 -28
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
package/dist/plugins/index.mjs
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
|
2
1
|
import { value } from '@orpc/shared';
|
3
2
|
|
4
3
|
class CORSPlugin {
|
@@ -79,14 +78,19 @@ class ResponseHeadersPlugin {
|
|
79
78
|
init(options) {
|
80
79
|
options.rootInterceptors ??= [];
|
81
80
|
options.rootInterceptors.push(async (interceptorOptions) => {
|
82
|
-
const
|
83
|
-
|
84
|
-
|
81
|
+
const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
|
82
|
+
const result = await interceptorOptions.next({
|
83
|
+
...interceptorOptions,
|
84
|
+
context: {
|
85
|
+
...interceptorOptions.context,
|
86
|
+
resHeaders
|
87
|
+
}
|
88
|
+
});
|
85
89
|
if (!result.matched) {
|
86
90
|
return result;
|
87
91
|
}
|
88
92
|
const responseHeaders = result.response.headers;
|
89
|
-
for (const [key, value] of
|
93
|
+
for (const [key, value] of resHeaders) {
|
90
94
|
if (Array.isArray(responseHeaders[key])) {
|
91
95
|
responseHeaders[key].push(value);
|
92
96
|
} else if (responseHeaders[key] !== void 0) {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
-
import { Interceptor
|
2
|
+
import { Interceptor } 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.MZvbGc3n.js';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
@@ -20,13 +20,10 @@ interface StandardCodec {
|
|
20
20
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
21
|
}
|
22
22
|
|
23
|
-
|
23
|
+
interface StandardHandleOptions<T extends Context> {
|
24
24
|
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
25
|
context: T;
|
29
|
-
}
|
26
|
+
}
|
30
27
|
type StandardHandleResult = {
|
31
28
|
matched: true;
|
32
29
|
response: StandardResponse;
|
@@ -34,12 +31,14 @@ type StandardHandleResult = {
|
|
34
31
|
matched: false;
|
35
32
|
response: undefined;
|
36
33
|
};
|
37
|
-
|
38
|
-
|
34
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
35
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
36
|
+
}
|
37
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
39
38
|
request: StandardLazyRequest;
|
40
|
-
}
|
39
|
+
}
|
41
40
|
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
-
plugins?:
|
41
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
43
42
|
/**
|
44
43
|
* Interceptors at the request level, helpful when you want catch errors
|
45
44
|
*/
|
@@ -57,19 +56,11 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
57
56
|
declare class StandardHandler<T extends Context> {
|
58
57
|
private readonly matcher;
|
59
58
|
private readonly codec;
|
60
|
-
private readonly
|
61
|
-
private readonly
|
59
|
+
private readonly interceptors;
|
60
|
+
private readonly clientInterceptors;
|
61
|
+
private readonly rootInterceptors;
|
62
62
|
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
-
handle(request: StandardLazyRequest,
|
64
|
-
}
|
65
|
-
|
66
|
-
interface HandlerPlugin<TContext extends Context> {
|
67
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
-
}
|
69
|
-
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
-
private readonly plugins;
|
71
|
-
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
63
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
73
64
|
}
|
74
65
|
|
75
|
-
export {
|
66
|
+
export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
3
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.DnR6v9pj.mjs';
|
4
|
+
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
6
|
+
import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
|
7
|
+
|
8
|
+
class BodyLimitPlugin {
|
9
|
+
maxBodySize;
|
10
|
+
constructor(options) {
|
11
|
+
this.maxBodySize = options.maxBodySize;
|
12
|
+
}
|
13
|
+
initRuntimeAdapter(options) {
|
14
|
+
options.adapterInterceptors ??= [];
|
15
|
+
options.adapterInterceptors.push(async (options2) => {
|
16
|
+
if (!options2.request.body) {
|
17
|
+
return options2.next();
|
18
|
+
}
|
19
|
+
let currentBodySize = 0;
|
20
|
+
const rawReader = options2.request.body.getReader();
|
21
|
+
const reader = new ReadableStream({
|
22
|
+
start: async (controller) => {
|
23
|
+
try {
|
24
|
+
if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
|
25
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
while (true) {
|
29
|
+
const { done, value } = await rawReader.read();
|
30
|
+
if (done) {
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
currentBodySize += value.length;
|
34
|
+
if (currentBodySize > this.maxBodySize) {
|
35
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
controller.enqueue(value);
|
39
|
+
}
|
40
|
+
} finally {
|
41
|
+
controller.close();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
});
|
45
|
+
const requestInit = { body: reader, duplex: "half" };
|
46
|
+
return options2.next({
|
47
|
+
...options2,
|
48
|
+
request: new Request(options2.request, requestInit)
|
49
|
+
});
|
50
|
+
});
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
class FetchHandler {
|
55
|
+
constructor(standardHandler, options = {}) {
|
56
|
+
this.standardHandler = standardHandler;
|
57
|
+
for (const plugin of toArray(options.plugins)) {
|
58
|
+
plugin.initRuntimeAdapter?.(options);
|
59
|
+
}
|
60
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
61
|
+
this.toFetchResponseOptions = options;
|
62
|
+
}
|
63
|
+
toFetchResponseOptions;
|
64
|
+
adapterInterceptors;
|
65
|
+
async handle(request, ...rest) {
|
66
|
+
return intercept(
|
67
|
+
this.adapterInterceptors,
|
68
|
+
{
|
69
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
70
|
+
request,
|
71
|
+
toFetchResponseOptions: this.toFetchResponseOptions
|
72
|
+
},
|
73
|
+
async ({ request: request2, toFetchResponseOptions, ...options }) => {
|
74
|
+
const standardRequest = toStandardLazyRequest(request2);
|
75
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
76
|
+
if (!result.matched) {
|
77
|
+
return result;
|
78
|
+
}
|
79
|
+
return {
|
80
|
+
matched: true,
|
81
|
+
response: toFetchResponse(result.response, toFetchResponseOptions)
|
82
|
+
};
|
83
|
+
}
|
84
|
+
);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
class RPCHandler extends FetchHandler {
|
89
|
+
constructor(router, options = {}) {
|
90
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
91
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
92
|
+
const matcher = new StandardRPCMatcher();
|
93
|
+
const codec = new StandardRPCCodec(serializer);
|
94
|
+
super(new StandardHandler(router, matcher, codec, options), options);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
export { BodyLimitPlugin as B, FetchHandler as F, RPCHandler as R };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { C as Context } from './server.MZvbGc3n.js';
|
2
|
+
import { S as StandardHandleOptions } from './server.23VRZIfj.js';
|
3
|
+
|
4
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
5
|
+
context?: T;
|
6
|
+
} : {
|
7
|
+
context: T;
|
8
|
+
});
|
9
|
+
|
10
|
+
export type { FriendlyStandardHandleOptions as F };
|
@@ -58,6 +58,10 @@ function isProcedure(item) {
|
|
58
58
|
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
59
59
|
}
|
60
60
|
|
61
|
+
function mergeCurrentContext(context, other) {
|
62
|
+
return { ...context, ...other };
|
63
|
+
}
|
64
|
+
|
61
65
|
function createORPCErrorConstructorMap(errors) {
|
62
66
|
const proxy = new Proxy(errors, {
|
63
67
|
get(target, code) {
|
@@ -170,23 +174,30 @@ async function executeProcedureInternal(procedure, options) {
|
|
170
174
|
let currentInput = options.input;
|
171
175
|
const next = async (...[nextOptions]) => {
|
172
176
|
const index = currentIndex;
|
177
|
+
const midContext = nextOptions?.context ?? {};
|
173
178
|
currentIndex += 1;
|
174
|
-
currentContext =
|
179
|
+
currentContext = mergeCurrentContext(currentContext, midContext);
|
175
180
|
if (index === inputValidationIndex) {
|
176
181
|
currentInput = await validateInput(procedure, currentInput);
|
177
182
|
}
|
178
183
|
const mid = middlewares[index];
|
179
|
-
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
|
+
};
|
180
191
|
if (index === outputValidationIndex) {
|
181
192
|
const validatedOutput = await validateOutput(procedure, result.output);
|
182
193
|
return {
|
183
|
-
|
194
|
+
context: result.context,
|
184
195
|
output: validatedOutput
|
185
196
|
};
|
186
197
|
}
|
187
198
|
return result;
|
188
199
|
};
|
189
|
-
return (await next(
|
200
|
+
return (await next()).output;
|
190
201
|
}
|
191
202
|
|
192
203
|
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
@@ -360,4 +371,4 @@ function toHttpPath(path) {
|
|
360
371
|
return `/${path.map(encodeURIComponent).join("/")}`;
|
361
372
|
}
|
362
373
|
|
363
|
-
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,
|
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 };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { C as Context } from './server.MZvbGc3n.mjs';
|
2
|
+
import { S as StandardHandleOptions } from './server.DJqfB27m.mjs';
|
3
|
+
|
4
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
5
|
+
context?: T;
|
6
|
+
} : {
|
7
|
+
context: T;
|
8
|
+
});
|
9
|
+
|
10
|
+
export type { FriendlyStandardHandleOptions as F };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.MZvbGc3n.mjs';
|
3
|
+
import { a as StandardHandlerOptions } from './server.DJqfB27m.mjs';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.MZvbGc3n.js';
|
3
|
+
import { a as StandardHandlerOptions } from './server.23VRZIfj.js';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
-
import { Interceptor
|
2
|
+
import { Interceptor } 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.MZvbGc3n.mjs';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
@@ -20,13 +20,10 @@ interface StandardCodec {
|
|
20
20
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
21
|
}
|
22
22
|
|
23
|
-
|
23
|
+
interface StandardHandleOptions<T extends Context> {
|
24
24
|
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
25
|
context: T;
|
29
|
-
}
|
26
|
+
}
|
30
27
|
type StandardHandleResult = {
|
31
28
|
matched: true;
|
32
29
|
response: StandardResponse;
|
@@ -34,12 +31,14 @@ type StandardHandleResult = {
|
|
34
31
|
matched: false;
|
35
32
|
response: undefined;
|
36
33
|
};
|
37
|
-
|
38
|
-
|
34
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
35
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
36
|
+
}
|
37
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
39
38
|
request: StandardLazyRequest;
|
40
|
-
}
|
39
|
+
}
|
41
40
|
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
-
plugins?:
|
41
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
43
42
|
/**
|
44
43
|
* Interceptors at the request level, helpful when you want catch errors
|
45
44
|
*/
|
@@ -57,19 +56,11 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
57
56
|
declare class StandardHandler<T extends Context> {
|
58
57
|
private readonly matcher;
|
59
58
|
private readonly codec;
|
60
|
-
private readonly
|
61
|
-
private readonly
|
59
|
+
private readonly interceptors;
|
60
|
+
private readonly clientInterceptors;
|
61
|
+
private readonly rootInterceptors;
|
62
62
|
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
-
handle(request: StandardLazyRequest,
|
64
|
-
}
|
65
|
-
|
66
|
-
interface HandlerPlugin<TContext extends Context> {
|
67
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
-
}
|
69
|
-
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
-
private readonly plugins;
|
71
|
-
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
63
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
73
64
|
}
|
74
65
|
|
75
|
-
export {
|
66
|
+
export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };
|
@@ -1,51 +1,53 @@
|
|
1
1
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.B_5ZADvP.mjs';
|
2
|
+
import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
|
3
|
+
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BtxZnWJ9.mjs';
|
5
4
|
|
6
5
|
class StandardHandler {
|
7
6
|
constructor(router, matcher, codec, options) {
|
8
7
|
this.matcher = matcher;
|
9
8
|
this.codec = codec;
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
for (const plugin of toArray(options.plugins)) {
|
10
|
+
plugin.init?.(options);
|
11
|
+
}
|
12
|
+
this.interceptors = toArray(options.interceptors);
|
13
|
+
this.clientInterceptors = toArray(options.clientInterceptors);
|
14
|
+
this.rootInterceptors = toArray(options.rootInterceptors);
|
13
15
|
this.matcher.init(router);
|
14
16
|
}
|
15
|
-
|
16
|
-
|
17
|
+
interceptors;
|
18
|
+
clientInterceptors;
|
19
|
+
rootInterceptors;
|
20
|
+
handle(request, options) {
|
17
21
|
return intercept(
|
18
|
-
this.
|
19
|
-
{
|
20
|
-
request,
|
21
|
-
...options,
|
22
|
-
context: options?.context ?? {}
|
23
|
-
// context is optional only when all fields are optional so we can safely force it to have a context
|
24
|
-
},
|
22
|
+
this.rootInterceptors,
|
23
|
+
{ ...options, request },
|
25
24
|
async (interceptorOptions) => {
|
26
25
|
let isDecoding = false;
|
27
26
|
try {
|
28
27
|
return await intercept(
|
29
|
-
this.
|
28
|
+
this.interceptors,
|
30
29
|
interceptorOptions,
|
31
|
-
async (
|
32
|
-
const method =
|
33
|
-
const url =
|
34
|
-
|
35
|
-
|
30
|
+
async ({ request: request2, context, prefix }) => {
|
31
|
+
const method = request2.method;
|
32
|
+
const url = request2.url;
|
33
|
+
if (prefix && !url.pathname.startsWith(prefix)) {
|
34
|
+
return { matched: false, response: void 0 };
|
35
|
+
}
|
36
|
+
const pathname = prefix ? url.pathname.replace(prefix, "") : url.pathname;
|
37
|
+
const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
|
36
38
|
if (!match) {
|
37
39
|
return { matched: false, response: void 0 };
|
38
40
|
}
|
39
41
|
const client = createProcedureClient(match.procedure, {
|
40
|
-
context
|
42
|
+
context,
|
41
43
|
path: match.path,
|
42
|
-
interceptors: this.
|
44
|
+
interceptors: this.clientInterceptors
|
43
45
|
});
|
44
46
|
isDecoding = true;
|
45
|
-
const input = await this.codec.decode(
|
47
|
+
const input = await this.codec.decode(request2, match.params, match.procedure);
|
46
48
|
isDecoding = false;
|
47
|
-
const lastEventId = Array.isArray(
|
48
|
-
const output = await client(input, { signal:
|
49
|
+
const lastEventId = Array.isArray(request2.headers["last-event-id"]) ? request2.headers["last-event-id"].at(-1) : request2.headers["last-event-id"];
|
50
|
+
const output = await client(input, { signal: request2.signal, lastEventId });
|
49
51
|
const response = this.codec.encode(output, match.procedure);
|
50
52
|
return {
|
51
53
|
matched: true,
|
@@ -54,7 +56,7 @@ class StandardHandler {
|
|
54
56
|
}
|
55
57
|
);
|
56
58
|
} catch (e) {
|
57
|
-
const error = isDecoding ? new ORPCError("BAD_REQUEST", {
|
59
|
+
const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
58
60
|
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
59
61
|
cause: e
|
60
62
|
}) : toORPCError(e);
|
@@ -69,7 +71,7 @@ class StandardHandler {
|
|
69
71
|
}
|
70
72
|
}
|
71
73
|
|
72
|
-
class
|
74
|
+
class StandardRPCCodec {
|
73
75
|
constructor(serializer) {
|
74
76
|
this.serializer = serializer;
|
75
77
|
}
|
@@ -93,7 +95,7 @@ class RPCCodec {
|
|
93
95
|
}
|
94
96
|
}
|
95
97
|
|
96
|
-
class
|
98
|
+
class StandardRPCMatcher {
|
97
99
|
tree = {};
|
98
100
|
pendingRouters = [];
|
99
101
|
init(router, path = []) {
|
@@ -155,4 +157,4 @@ class RPCMatcher {
|
|
155
157
|
}
|
156
158
|
}
|
157
159
|
|
158
|
-
export {
|
160
|
+
export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
|
@@ -6,7 +6,6 @@ type Context = Record<string, any>;
|
|
6
6
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
7
7
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
8
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 T & U ? unknown : never;
|
10
9
|
|
11
10
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
11
|
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
@@ -141,4 +140,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
141
140
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
141
|
};
|
143
142
|
|
144
|
-
export { type AnyProcedure as A,
|
143
|
+
export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
|
@@ -6,7 +6,6 @@ type Context = Record<string, any>;
|
|
6
6
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
7
7
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
8
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 T & U ? unknown : never;
|
10
9
|
|
11
10
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
11
|
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
@@ -141,4 +140,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
141
140
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
141
|
};
|
143
142
|
|
144
|
-
export { type AnyProcedure as A,
|
143
|
+
export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
|
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.173b319",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -58,15 +58,15 @@
|
|
58
58
|
"next": ">=14.0.0"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@orpc/
|
62
|
-
"@orpc/standard-server": "0.0.0-next.
|
63
|
-
"@orpc/
|
64
|
-
"@orpc/
|
65
|
-
"@orpc/shared": "0.0.0-next.
|
66
|
-
"@orpc/standard-server-node": "0.0.0-next.
|
61
|
+
"@orpc/client": "0.0.0-next.173b319",
|
62
|
+
"@orpc/standard-server": "0.0.0-next.173b319",
|
63
|
+
"@orpc/standard-server-fetch": "0.0.0-next.173b319",
|
64
|
+
"@orpc/contract": "0.0.0-next.173b319",
|
65
|
+
"@orpc/shared": "0.0.0-next.173b319",
|
66
|
+
"@orpc/standard-server-node": "0.0.0-next.173b319"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
|
-
"
|
69
|
+
"supertest": "^7.0.0"
|
70
70
|
},
|
71
71
|
"scripts": {
|
72
72
|
"build": "unbuild",
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { RPCSerializer } from '@orpc/client/standard';
|
2
|
-
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
-
import { S as StandardHandler, a as RPCMatcher, R as RPCCodec } from './server.3mOimouH.mjs';
|
4
|
-
|
5
|
-
class RPCHandler {
|
6
|
-
standardHandler;
|
7
|
-
constructor(router, options = {}) {
|
8
|
-
const serializer = new RPCSerializer();
|
9
|
-
const matcher = new RPCMatcher();
|
10
|
-
const codec = new RPCCodec(serializer);
|
11
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
12
|
-
}
|
13
|
-
async handle(request, ...[
|
14
|
-
options = {}
|
15
|
-
]) {
|
16
|
-
const standardRequest = toStandardLazyRequest(request);
|
17
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
18
|
-
if (!result.matched) {
|
19
|
-
return result;
|
20
|
-
}
|
21
|
-
return {
|
22
|
-
matched: true,
|
23
|
-
response: toFetchResponse(result.response, options)
|
24
|
-
};
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
export { RPCHandler as R };
|