@orpc/server 0.0.0-next.ee46dab → 0.0.0-next.ee89076
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 +20 -23
- package/dist/adapters/aws-lambda/index.d.mts +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +42 -0
- package/dist/adapters/bun-ws/index.d.mts +36 -0
- package/dist/adapters/bun-ws/index.d.ts +36 -0
- package/dist/adapters/bun-ws/index.mjs +47 -0
- package/dist/adapters/crossws/index.d.mts +33 -0
- package/dist/adapters/crossws/index.d.ts +33 -0
- package/dist/adapters/crossws/index.mjs +45 -0
- package/dist/adapters/fetch/index.d.mts +81 -11
- package/dist/adapters/fetch/index.d.ts +81 -11
- package/dist/adapters/fetch/index.mjs +179 -8
- package/dist/adapters/message-port/index.d.mts +31 -0
- package/dist/adapters/message-port/index.d.ts +31 -0
- package/dist/adapters/message-port/index.mjs +39 -0
- package/dist/adapters/node/index.d.mts +57 -11
- package/dist/adapters/node/index.d.ts +57 -11
- package/dist/adapters/node/index.mjs +89 -22
- package/dist/adapters/standard/index.d.mts +8 -13
- package/dist/adapters/standard/index.d.ts +8 -13
- package/dist/adapters/standard/index.mjs +5 -3
- package/dist/adapters/standard-peer/index.d.mts +18 -0
- package/dist/adapters/standard-peer/index.d.ts +18 -0
- package/dist/adapters/standard-peer/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +54 -0
- package/dist/adapters/websocket/index.d.ts +54 -0
- package/dist/adapters/websocket/index.mjs +67 -0
- package/dist/adapters/ws/index.d.mts +31 -0
- package/dist/adapters/ws/index.d.ts +31 -0
- package/dist/adapters/ws/index.mjs +37 -0
- package/dist/helpers/index.d.mts +134 -0
- package/dist/helpers/index.d.ts +134 -0
- package/dist/helpers/index.mjs +188 -0
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +564 -52
- package/dist/index.d.ts +564 -52
- package/dist/index.mjs +140 -14
- package/dist/plugins/index.d.mts +148 -9
- package/dist/plugins/index.d.ts +148 -9
- package/dist/plugins/index.mjs +191 -11
- package/dist/shared/{server.DLt5njUb.d.mts → server.B4BGqy3Y.d.mts} +60 -10
- package/dist/shared/{server.DLt5njUb.d.ts → server.B4BGqy3Y.d.ts} +60 -10
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.COL12UTb.d.ts +32 -0
- package/dist/shared/server.CVKCo60T.d.mts +12 -0
- package/dist/shared/{server.e3W6AG3-.mjs → server.CaqDCZX1.mjs} +125 -86
- package/dist/shared/server.Cb6yD7DZ.d.ts +42 -0
- package/dist/shared/server.Ck-gOLzq.d.mts +32 -0
- package/dist/shared/{server.CzxlqYZL.d.mts → server.DBCUJijK.d.mts} +18 -10
- package/dist/shared/server.DNtJ-p60.d.ts +12 -0
- package/dist/shared/{server.BHlRCrf_.d.ts → server.DPIFWpxG.d.ts} +18 -10
- package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
- package/dist/shared/server.DzV1hr3z.d.mts +42 -0
- package/dist/shared/server.UVMTOWrk.mjs +26 -0
- package/dist/shared/server.vzZSq5UM.mjs +219 -0
- package/package.json +71 -20
- package/dist/adapters/hono/index.d.mts +0 -22
- package/dist/adapters/hono/index.d.ts +0 -22
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -29
- package/dist/adapters/next/index.d.ts +0 -29
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.B77ImKAP.d.mts +0 -8
- package/dist/shared/server.Cud5qk0c.d.ts +0 -10
- package/dist/shared/server.DCCkTG29.mjs +0 -162
- package/dist/shared/server.DGnN7q3R.d.mts +0 -10
- package/dist/shared/server.DUF89eb-.d.ts +0 -8
- package/dist/shared/server.Prfzu_zf.mjs +0 -98
@@ -1,162 +0,0 @@
|
|
1
|
-
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
-
import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
|
3
|
-
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.e3W6AG3-.mjs';
|
4
|
-
import { toHttpPath } from '@orpc/client/standard';
|
5
|
-
|
6
|
-
class StandardHandler {
|
7
|
-
constructor(router, matcher, codec, options) {
|
8
|
-
this.matcher = matcher;
|
9
|
-
this.codec = codec;
|
10
|
-
for (const plugin of toArray(options.plugins)) {
|
11
|
-
plugin.init?.(options);
|
12
|
-
}
|
13
|
-
this.interceptors = toArray(options.interceptors);
|
14
|
-
this.clientInterceptors = toArray(options.clientInterceptors);
|
15
|
-
this.rootInterceptors = toArray(options.rootInterceptors);
|
16
|
-
this.matcher.init(router);
|
17
|
-
}
|
18
|
-
interceptors;
|
19
|
-
clientInterceptors;
|
20
|
-
rootInterceptors;
|
21
|
-
async handle(request, options) {
|
22
|
-
const prefix = options.prefix?.replace(/\/$/, "") || void 0;
|
23
|
-
if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
|
24
|
-
return { matched: false, response: void 0 };
|
25
|
-
}
|
26
|
-
return intercept(
|
27
|
-
this.rootInterceptors,
|
28
|
-
{ ...options, request, prefix },
|
29
|
-
async (interceptorOptions) => {
|
30
|
-
let isDecoding = false;
|
31
|
-
try {
|
32
|
-
return await intercept(
|
33
|
-
this.interceptors,
|
34
|
-
interceptorOptions,
|
35
|
-
async ({ request: request2, context, prefix: prefix2 }) => {
|
36
|
-
const method = request2.method;
|
37
|
-
const url = request2.url;
|
38
|
-
const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
|
39
|
-
const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
|
40
|
-
if (!match) {
|
41
|
-
return { matched: false, response: void 0 };
|
42
|
-
}
|
43
|
-
const client = createProcedureClient(match.procedure, {
|
44
|
-
context,
|
45
|
-
path: match.path,
|
46
|
-
interceptors: this.clientInterceptors
|
47
|
-
});
|
48
|
-
isDecoding = true;
|
49
|
-
const input = await this.codec.decode(request2, match.params, match.procedure);
|
50
|
-
isDecoding = false;
|
51
|
-
const lastEventId = Array.isArray(request2.headers["last-event-id"]) ? request2.headers["last-event-id"].at(-1) : request2.headers["last-event-id"];
|
52
|
-
const output = await client(input, { signal: request2.signal, lastEventId });
|
53
|
-
const response = this.codec.encode(output, match.procedure);
|
54
|
-
return {
|
55
|
-
matched: true,
|
56
|
-
response
|
57
|
-
};
|
58
|
-
}
|
59
|
-
);
|
60
|
-
} catch (e) {
|
61
|
-
const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
62
|
-
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
63
|
-
cause: e
|
64
|
-
}) : toORPCError(e);
|
65
|
-
const response = this.codec.encodeError(error);
|
66
|
-
return {
|
67
|
-
matched: true,
|
68
|
-
response
|
69
|
-
};
|
70
|
-
}
|
71
|
-
}
|
72
|
-
);
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
class StandardRPCCodec {
|
77
|
-
constructor(serializer) {
|
78
|
-
this.serializer = serializer;
|
79
|
-
}
|
80
|
-
async decode(request, _params, _procedure) {
|
81
|
-
const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
|
82
|
-
return this.serializer.deserialize(serialized);
|
83
|
-
}
|
84
|
-
encode(output, _procedure) {
|
85
|
-
return {
|
86
|
-
status: 200,
|
87
|
-
headers: {},
|
88
|
-
body: this.serializer.serialize(output)
|
89
|
-
};
|
90
|
-
}
|
91
|
-
encodeError(error) {
|
92
|
-
return {
|
93
|
-
status: error.status,
|
94
|
-
headers: {},
|
95
|
-
body: this.serializer.serialize(error.toJSON())
|
96
|
-
};
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
class StandardRPCMatcher {
|
101
|
-
tree = {};
|
102
|
-
pendingRouters = [];
|
103
|
-
init(router, path = []) {
|
104
|
-
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
105
|
-
const httpPath = toHttpPath(path2);
|
106
|
-
if (isProcedure(contract)) {
|
107
|
-
this.tree[httpPath] = {
|
108
|
-
path: path2,
|
109
|
-
contract,
|
110
|
-
procedure: contract,
|
111
|
-
// this mean dev not used contract-first so we can used contract as procedure directly
|
112
|
-
router
|
113
|
-
};
|
114
|
-
} else {
|
115
|
-
this.tree[httpPath] = {
|
116
|
-
path: path2,
|
117
|
-
contract,
|
118
|
-
procedure: void 0,
|
119
|
-
router
|
120
|
-
};
|
121
|
-
}
|
122
|
-
});
|
123
|
-
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
124
|
-
...option,
|
125
|
-
httpPathPrefix: toHttpPath(option.path)
|
126
|
-
})));
|
127
|
-
}
|
128
|
-
async match(_method, pathname) {
|
129
|
-
if (this.pendingRouters.length) {
|
130
|
-
const newPendingRouters = [];
|
131
|
-
for (const pendingRouter of this.pendingRouters) {
|
132
|
-
if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
133
|
-
const { default: router } = await unlazy(pendingRouter.router);
|
134
|
-
this.init(router, pendingRouter.path);
|
135
|
-
} else {
|
136
|
-
newPendingRouters.push(pendingRouter);
|
137
|
-
}
|
138
|
-
}
|
139
|
-
this.pendingRouters = newPendingRouters;
|
140
|
-
}
|
141
|
-
const match = this.tree[pathname];
|
142
|
-
if (!match) {
|
143
|
-
return void 0;
|
144
|
-
}
|
145
|
-
if (!match.procedure) {
|
146
|
-
const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
|
147
|
-
if (!isProcedure(maybeProcedure)) {
|
148
|
-
throw new Error(`
|
149
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
|
150
|
-
Ensure that the procedure is correctly defined and matches the expected contract.
|
151
|
-
`);
|
152
|
-
}
|
153
|
-
match.procedure = createContractedProcedure(maybeProcedure, match.contract);
|
154
|
-
}
|
155
|
-
return {
|
156
|
-
path: match.path,
|
157
|
-
procedure: match.procedure
|
158
|
-
};
|
159
|
-
}
|
160
|
-
}
|
161
|
-
|
162
|
-
export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { C as Context } from './server.DLt5njUb.mjs';
|
2
|
-
import { S as StandardHandleOptions } from './server.CzxlqYZL.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 };
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
-
import { C as Context } from './server.DLt5njUb.js';
|
3
|
-
import { a as StandardHandlerOptions } from './server.BHlRCrf_.js';
|
4
|
-
|
5
|
-
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
-
}
|
7
|
-
|
8
|
-
export type { StandardRPCHandlerOptions as S };
|
@@ -1,98 +0,0 @@
|
|
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.DCCkTG29.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 };
|