@orpc/server 0.0.0-next.350a165 → 0.0.0-next.3636544
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 +18 -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 +47 -0
- package/dist/adapters/fetch/index.d.mts +29 -8
- package/dist/adapters/fetch/index.d.ts +29 -8
- package/dist/adapters/fetch/index.mjs +109 -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 +41 -0
- package/dist/adapters/node/index.d.mts +29 -8
- package/dist/adapters/node/index.d.ts +29 -8
- package/dist/adapters/node/index.mjs +13 -9
- 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 +14 -0
- package/dist/adapters/standard-peer/index.d.ts +14 -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 +69 -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 +39 -0
- package/dist/helpers/index.d.mts +130 -0
- package/dist/helpers/index.d.ts +130 -0
- package/dist/helpers/index.mjs +182 -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 +563 -51
- package/dist/index.d.ts +563 -51
- package/dist/index.mjs +138 -12
- package/dist/plugins/index.d.mts +112 -11
- package/dist/plugins/index.d.ts +112 -11
- package/dist/plugins/index.mjs +91 -13
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.C6Q5sqYw.mjs +20 -0
- package/dist/shared/server.CC8z0B3U.d.mts +32 -0
- package/dist/shared/{server.C78d5yfh.mjs → server.CIL9uKTN.mjs} +32 -11
- package/dist/shared/server.CNZgPgce.d.ts +12 -0
- package/dist/shared/server.Cu-7se50.d.mts +12 -0
- package/dist/shared/server.Cwq7K86l.d.mts +42 -0
- package/dist/shared/{server.DfyOFejj.d.ts → server.DHgXKx3q.d.mts} +18 -17
- package/dist/shared/server.DOwaI1le.d.ts +32 -0
- package/dist/shared/{server.Dm5DEJl5.d.mts → server.DVBSOxWU.d.ts} +18 -17
- package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
- package/dist/shared/{server.C37gDhSZ.mjs → server.NeumLVdS.mjs} +16 -10
- package/dist/shared/server.a_VzWVCm.d.ts +42 -0
- package/dist/shared/{server.DLt5njUb.d.mts → server.wMv480px.d.mts} +58 -9
- package/dist/shared/{server.DLt5njUb.d.ts → server.wMv480px.d.ts} +58 -9
- package/package.json +70 -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.C56IpPNj.d.mts +0 -10
- package/dist/shared/server.CSIDw0mq.mjs +0 -106
- package/dist/shared/server.CyrwhzzU.d.ts +0 -8
- package/dist/shared/server.DgrNIRDf.d.mts +0 -8
- package/dist/shared/server.DnuwaDJo.d.ts +0 -10
package/dist/plugins/index.mjs
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
import { value } from '@orpc/shared';
|
1
|
+
import { value, isAsyncIteratorObject, clone } from '@orpc/shared';
|
2
|
+
import { flattenHeader } from '@orpc/standard-server';
|
2
3
|
import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
|
4
|
+
import { toFetchHeaders } from '@orpc/standard-server-fetch';
|
5
|
+
import { ORPCError } from '@orpc/client';
|
6
|
+
export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
|
7
|
+
import '@orpc/contract';
|
3
8
|
|
4
9
|
class BatchHandlerPlugin {
|
5
10
|
maxSize;
|
@@ -22,7 +27,8 @@ class BatchHandlerPlugin {
|
|
22
27
|
init(options) {
|
23
28
|
options.rootInterceptors ??= [];
|
24
29
|
options.rootInterceptors.unshift(async (options2) => {
|
25
|
-
|
30
|
+
const xHeader = flattenHeader(options2.request.headers["x-orpc-batch"]);
|
31
|
+
if (xHeader === void 0) {
|
26
32
|
return options2.next();
|
27
33
|
}
|
28
34
|
let isParsing = false;
|
@@ -46,6 +52,14 @@ class BatchHandlerPlugin {
|
|
46
52
|
const mapped = this.mapRequestItem(request, options2);
|
47
53
|
return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
|
48
54
|
if (matched) {
|
55
|
+
if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
|
56
|
+
return {
|
57
|
+
index,
|
58
|
+
status: 500,
|
59
|
+
headers: {},
|
60
|
+
body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
|
61
|
+
};
|
62
|
+
}
|
49
63
|
return { ...response2, index };
|
50
64
|
}
|
51
65
|
return { index, status: 404, headers: {}, body: "No procedure matched" };
|
@@ -57,9 +71,10 @@ class BatchHandlerPlugin {
|
|
57
71
|
await Promise.race(responses);
|
58
72
|
const status = await value(this.successStatus, responses, options2);
|
59
73
|
const headers = await value(this.headers, responses, options2);
|
60
|
-
const response = toBatchResponse({
|
74
|
+
const response = await toBatchResponse({
|
61
75
|
status,
|
62
76
|
headers,
|
77
|
+
mode: xHeader === "buffered" ? "buffered" : "streaming",
|
63
78
|
body: async function* () {
|
64
79
|
const promises = [...responses];
|
65
80
|
while (true) {
|
@@ -112,13 +127,11 @@ class CORSPlugin {
|
|
112
127
|
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
113
128
|
}
|
114
129
|
if (this.options.allowMethods?.length) {
|
115
|
-
resHeaders["access-control-allow-methods"] = this.options.allowMethods
|
130
|
+
resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
|
116
131
|
}
|
117
132
|
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
118
|
-
if (
|
119
|
-
resHeaders["access-control-allow-headers"] = allowHeaders
|
120
|
-
} else if (typeof allowHeaders === "string") {
|
121
|
-
resHeaders["access-control-allow-headers"] = allowHeaders;
|
133
|
+
if (typeof allowHeaders === "string" || allowHeaders?.length) {
|
134
|
+
resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
|
122
135
|
}
|
123
136
|
return {
|
124
137
|
matched: true,
|
@@ -136,7 +149,7 @@ class CORSPlugin {
|
|
136
149
|
if (!result.matched) {
|
137
150
|
return result;
|
138
151
|
}
|
139
|
-
const origin =
|
152
|
+
const origin = flattenHeader(interceptorOptions.request.headers.origin) ?? "";
|
140
153
|
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
141
154
|
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
142
155
|
if (allowedOriginArr.includes("*")) {
|
@@ -158,13 +171,29 @@ class CORSPlugin {
|
|
158
171
|
result.response.headers["access-control-allow-credentials"] = "true";
|
159
172
|
}
|
160
173
|
if (this.options.exposeHeaders?.length) {
|
161
|
-
result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders
|
174
|
+
result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
|
162
175
|
}
|
163
176
|
return result;
|
164
177
|
});
|
165
178
|
}
|
166
179
|
}
|
167
180
|
|
181
|
+
class RequestHeadersPlugin {
|
182
|
+
init(options) {
|
183
|
+
options.rootInterceptors ??= [];
|
184
|
+
options.rootInterceptors.push((interceptorOptions) => {
|
185
|
+
const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
|
186
|
+
return interceptorOptions.next({
|
187
|
+
...interceptorOptions,
|
188
|
+
context: {
|
189
|
+
...interceptorOptions.context,
|
190
|
+
reqHeaders
|
191
|
+
}
|
192
|
+
});
|
193
|
+
});
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
168
197
|
class ResponseHeadersPlugin {
|
169
198
|
init(options) {
|
170
199
|
options.rootInterceptors ??= [];
|
@@ -180,7 +209,7 @@ class ResponseHeadersPlugin {
|
|
180
209
|
if (!result.matched) {
|
181
210
|
return result;
|
182
211
|
}
|
183
|
-
const responseHeaders = result.response.headers;
|
212
|
+
const responseHeaders = clone(result.response.headers);
|
184
213
|
for (const [key, value] of resHeaders) {
|
185
214
|
if (Array.isArray(responseHeaders[key])) {
|
186
215
|
responseHeaders[key].push(value);
|
@@ -190,9 +219,58 @@ class ResponseHeadersPlugin {
|
|
190
219
|
responseHeaders[key] = value;
|
191
220
|
}
|
192
221
|
}
|
193
|
-
return
|
222
|
+
return {
|
223
|
+
...result,
|
224
|
+
response: {
|
225
|
+
...result.response,
|
226
|
+
headers: responseHeaders
|
227
|
+
}
|
228
|
+
};
|
229
|
+
});
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
|
234
|
+
class SimpleCsrfProtectionHandlerPlugin {
|
235
|
+
headerName;
|
236
|
+
headerValue;
|
237
|
+
exclude;
|
238
|
+
error;
|
239
|
+
constructor(options = {}) {
|
240
|
+
this.headerName = options.headerName ?? "x-csrf-token";
|
241
|
+
this.headerValue = options.headerValue ?? "orpc";
|
242
|
+
this.exclude = options.exclude ?? false;
|
243
|
+
this.error = options.error ?? new ORPCError("CSRF_TOKEN_MISMATCH", {
|
244
|
+
status: 403,
|
245
|
+
message: "Invalid CSRF token"
|
246
|
+
});
|
247
|
+
}
|
248
|
+
order = 8e6;
|
249
|
+
init(options) {
|
250
|
+
options.rootInterceptors ??= [];
|
251
|
+
options.clientInterceptors ??= [];
|
252
|
+
options.rootInterceptors.unshift(async (options2) => {
|
253
|
+
const headerName = await value(this.headerName, options2);
|
254
|
+
const headerValue = await value(this.headerValue, options2);
|
255
|
+
return options2.next({
|
256
|
+
...options2,
|
257
|
+
context: {
|
258
|
+
...options2.context,
|
259
|
+
[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
|
260
|
+
}
|
261
|
+
});
|
262
|
+
});
|
263
|
+
options.clientInterceptors.unshift(async (options2) => {
|
264
|
+
if (typeof options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL] !== "boolean") {
|
265
|
+
throw new TypeError("[SimpleCsrfProtectionHandlerPlugin] CSRF protection context has been corrupted or modified by another plugin or interceptor");
|
266
|
+
}
|
267
|
+
const excluded = await value(this.exclude, options2);
|
268
|
+
if (!excluded && !options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]) {
|
269
|
+
throw this.error;
|
270
|
+
}
|
271
|
+
return options2.next();
|
194
272
|
});
|
195
273
|
}
|
196
274
|
}
|
197
275
|
|
198
|
-
export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin };
|
276
|
+
export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { ORPCError, fallbackContractConfig } from '@orpc/contract';
|
2
|
+
|
3
|
+
const STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL = Symbol("STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT");
|
4
|
+
class StrictGetMethodPlugin {
|
5
|
+
error;
|
6
|
+
order = 7e6;
|
7
|
+
constructor(options = {}) {
|
8
|
+
this.error = options.error ?? new ORPCError("METHOD_NOT_SUPPORTED");
|
9
|
+
}
|
10
|
+
init(options) {
|
11
|
+
options.rootInterceptors ??= [];
|
12
|
+
options.clientInterceptors ??= [];
|
13
|
+
options.rootInterceptors.unshift((options2) => {
|
14
|
+
const isGetMethod = options2.request.method === "GET";
|
15
|
+
return options2.next({
|
16
|
+
...options2,
|
17
|
+
context: {
|
18
|
+
...options2.context,
|
19
|
+
[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL]: isGetMethod
|
20
|
+
}
|
21
|
+
});
|
22
|
+
});
|
23
|
+
options.clientInterceptors.unshift((options2) => {
|
24
|
+
if (typeof options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] !== "boolean") {
|
25
|
+
throw new TypeError("[StrictGetMethodPlugin] strict GET method context has been corrupted or modified by another plugin or interceptor");
|
26
|
+
}
|
27
|
+
const procedureMethod = fallbackContractConfig("defaultMethod", options2.procedure["~orpc"].route.method);
|
28
|
+
if (options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] && procedureMethod !== "GET") {
|
29
|
+
throw this.error;
|
30
|
+
}
|
31
|
+
return options2.next();
|
32
|
+
});
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
export { StrictGetMethodPlugin as S };
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import '@orpc/client';
|
2
|
+
import '@orpc/shared';
|
3
|
+
import '@orpc/standard-server';
|
4
|
+
import '@orpc/contract';
|
5
|
+
import '@orpc/client/standard';
|
6
|
+
import { r as resolveFriendlyStandardHandleOptions } from './server.DZ5BIITo.mjs';
|
7
|
+
|
8
|
+
async function handleStandardServerPeerMessage(handler, peer, message, options) {
|
9
|
+
const [id, request] = await peer.message(message);
|
10
|
+
if (!request) {
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
const { response } = await handler.handle(
|
14
|
+
{ ...request, body: () => Promise.resolve(request.body) },
|
15
|
+
resolveFriendlyStandardHandleOptions(options)
|
16
|
+
);
|
17
|
+
await peer.response(id, response ?? { status: 404, headers: {}, body: "No procedure matched" });
|
18
|
+
}
|
19
|
+
|
20
|
+
export { handleStandardServerPeerMessage as h };
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { b as AnyRouter, C as Context, R as Router } from './server.wMv480px.mjs';
|
3
|
+
import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.DHgXKx3q.mjs';
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
5
|
+
import { Value } from '@orpc/shared';
|
6
|
+
import { T as TraverseContractProcedureCallbackOptions } from './server.Cwq7K86l.mjs';
|
7
|
+
|
8
|
+
interface StandardRPCMatcherOptions {
|
9
|
+
/**
|
10
|
+
* Filter procedures. Return `false` to exclude a procedure from matching.
|
11
|
+
*
|
12
|
+
* @default true
|
13
|
+
*/
|
14
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
15
|
+
}
|
16
|
+
declare class StandardRPCMatcher implements StandardMatcher {
|
17
|
+
private readonly filter;
|
18
|
+
private readonly tree;
|
19
|
+
private pendingRouters;
|
20
|
+
constructor(options?: StandardRPCMatcherOptions);
|
21
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
22
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
23
|
+
}
|
24
|
+
|
25
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions, StandardRPCMatcherOptions {
|
26
|
+
}
|
27
|
+
declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
|
28
|
+
constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
|
29
|
+
}
|
30
|
+
|
31
|
+
export { StandardRPCHandler as a, StandardRPCMatcher as c };
|
32
|
+
export type { StandardRPCHandlerOptions as S, StandardRPCMatcherOptions as b };
|
@@ -1,16 +1,17 @@
|
|
1
|
+
import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
1
2
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
-
import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
|
3
|
-
import {
|
4
|
-
import {
|
3
|
+
import { toArray, intercept, parseEmptyableJSON, NullProtoObj, value } from '@orpc/shared';
|
4
|
+
import { flattenHeader } from '@orpc/standard-server';
|
5
|
+
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.NeumLVdS.mjs';
|
5
6
|
|
6
7
|
class CompositeStandardHandlerPlugin {
|
7
8
|
plugins;
|
8
9
|
constructor(plugins = []) {
|
9
10
|
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
10
11
|
}
|
11
|
-
init(options) {
|
12
|
+
init(options, router) {
|
12
13
|
for (const plugin of this.plugins) {
|
13
|
-
plugin.init?.(options);
|
14
|
+
plugin.init?.(options, router);
|
14
15
|
}
|
15
16
|
}
|
16
17
|
}
|
@@ -20,7 +21,7 @@ class StandardHandler {
|
|
20
21
|
this.matcher = matcher;
|
21
22
|
this.codec = codec;
|
22
23
|
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
|
23
|
-
plugins.init(options);
|
24
|
+
plugins.init(options, router);
|
24
25
|
this.interceptors = toArray(options.interceptors);
|
25
26
|
this.clientInterceptors = toArray(options.clientInterceptors);
|
26
27
|
this.rootInterceptors = toArray(options.rootInterceptors);
|
@@ -59,8 +60,10 @@ class StandardHandler {
|
|
59
60
|
isDecoding = true;
|
60
61
|
const input = await this.codec.decode(request2, match.params, match.procedure);
|
61
62
|
isDecoding = false;
|
62
|
-
const
|
63
|
-
|
63
|
+
const output = await client(input, {
|
64
|
+
signal: request2.signal,
|
65
|
+
lastEventId: flattenHeader(request2.headers["last-event-id"])
|
66
|
+
});
|
64
67
|
const response = this.codec.encode(output, match.procedure);
|
65
68
|
return {
|
66
69
|
matched: true,
|
@@ -109,10 +112,18 @@ class StandardRPCCodec {
|
|
109
112
|
}
|
110
113
|
|
111
114
|
class StandardRPCMatcher {
|
112
|
-
|
115
|
+
filter;
|
116
|
+
tree = new NullProtoObj();
|
113
117
|
pendingRouters = [];
|
118
|
+
constructor(options = {}) {
|
119
|
+
this.filter = options.filter ?? true;
|
120
|
+
}
|
114
121
|
init(router, path = []) {
|
115
|
-
const laziedOptions = traverseContractProcedures({ router, path }, (
|
122
|
+
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
123
|
+
if (!value(this.filter, traverseOptions)) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
const { path: path2, contract } = traverseOptions;
|
116
127
|
const httpPath = toHttpPath(path2);
|
117
128
|
if (isProcedure(contract)) {
|
118
129
|
this.tree[httpPath] = {
|
@@ -170,4 +181,14 @@ class StandardRPCMatcher {
|
|
170
181
|
}
|
171
182
|
}
|
172
183
|
|
173
|
-
|
184
|
+
class StandardRPCHandler extends StandardHandler {
|
185
|
+
constructor(router, options = {}) {
|
186
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
187
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
188
|
+
const matcher = new StandardRPCMatcher(options);
|
189
|
+
const codec = new StandardRPCCodec(serializer);
|
190
|
+
super(router, matcher, codec, options);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardRPCCodec as a, StandardRPCHandler as b, StandardRPCMatcher as c };
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { C as Context } from './server.wMv480px.js';
|
2
|
+
import { b as StandardHandleOptions } from './server.DVBSOxWU.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
|
+
declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
|
10
|
+
|
11
|
+
export { resolveFriendlyStandardHandleOptions as r };
|
12
|
+
export type { FriendlyStandardHandleOptions as F };
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { C as Context } from './server.wMv480px.mjs';
|
2
|
+
import { b as StandardHandleOptions } from './server.DHgXKx3q.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
|
+
declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
|
10
|
+
|
11
|
+
export { resolveFriendlyStandardHandleOptions as r };
|
12
|
+
export type { FriendlyStandardHandleOptions as F };
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { ErrorMap, EnhanceRouteOptions, MergedErrorMap, AnyContractRouter, AnyContractProcedure } from '@orpc/contract';
|
2
|
+
import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.wMv480px.mjs';
|
3
|
+
|
4
|
+
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
5
|
+
type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
|
6
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
7
|
+
};
|
8
|
+
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
9
|
+
type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends Procedure<infer UInitialContext, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
10
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
11
|
+
};
|
12
|
+
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
13
|
+
middlewares: readonly AnyMiddleware[];
|
14
|
+
errorMap: TErrorMap;
|
15
|
+
dedupeLeadingMiddlewares: boolean;
|
16
|
+
}
|
17
|
+
declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap>(router: T, options: EnhanceRouterOptions<TErrorMap>): EnhancedRouter<T, TInitialContext, TCurrentContext, TErrorMap>;
|
18
|
+
interface TraverseContractProceduresOptions {
|
19
|
+
router: AnyContractRouter | AnyRouter;
|
20
|
+
path: readonly string[];
|
21
|
+
}
|
22
|
+
interface TraverseContractProcedureCallbackOptions {
|
23
|
+
contract: AnyContractProcedure | AnyProcedure;
|
24
|
+
path: readonly string[];
|
25
|
+
}
|
26
|
+
/**
|
27
|
+
* @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
|
28
|
+
*/
|
29
|
+
type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
|
30
|
+
interface LazyTraverseContractProceduresOptions {
|
31
|
+
router: Lazy<AnyRouter>;
|
32
|
+
path: readonly string[];
|
33
|
+
}
|
34
|
+
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
35
|
+
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
|
36
|
+
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
37
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
38
|
+
};
|
39
|
+
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
40
|
+
|
41
|
+
export { createAccessibleLazyRouter as c, enhanceRouter as e, getRouter as g, resolveContractProcedures as r, traverseContractProcedures as t, unlazyRouter as u };
|
42
|
+
export type { AccessibleLazyRouter as A, ContractProcedureCallbackOptions as C, EnhanceRouterOptions as E, LazyTraverseContractProceduresOptions as L, TraverseContractProcedureCallbackOptions as T, UnlaziedRouter as U, EnhancedRouter as a, TraverseContractProceduresOptions as b };
|
@@ -1,8 +1,18 @@
|
|
1
1
|
import { HTTPPath, ORPCError } from '@orpc/client';
|
2
|
-
import { Meta
|
3
|
-
import { Interceptor
|
2
|
+
import { Meta } from '@orpc/contract';
|
3
|
+
import { Interceptor } from '@orpc/shared';
|
4
4
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
5
|
-
import {
|
5
|
+
import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.wMv480px.mjs';
|
6
|
+
|
7
|
+
interface StandardHandlerPlugin<T extends Context> {
|
8
|
+
order?: number;
|
9
|
+
init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
10
|
+
}
|
11
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
12
|
+
protected readonly plugins: TPlugin[];
|
13
|
+
constructor(plugins?: readonly TPlugin[]);
|
14
|
+
init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
15
|
+
}
|
6
16
|
|
7
17
|
type StandardParams = Record<string, string>;
|
8
18
|
type StandardMatchResult = {
|
@@ -20,16 +30,6 @@ interface StandardCodec {
|
|
20
30
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
31
|
}
|
22
32
|
|
23
|
-
interface StandardHandlerPlugin<TContext extends Context> {
|
24
|
-
order?: number;
|
25
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
26
|
-
}
|
27
|
-
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
28
|
-
protected readonly plugins: TPlugin[];
|
29
|
-
constructor(plugins?: readonly TPlugin[]);
|
30
|
-
init(options: StandardHandlerOptions<T>): void;
|
31
|
-
}
|
32
|
-
|
33
33
|
interface StandardHandleOptions<T extends Context> {
|
34
34
|
prefix?: HTTPPath;
|
35
35
|
context: T;
|
@@ -49,16 +49,16 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
49
49
|
/**
|
50
50
|
* Interceptors at the request level, helpful when you want catch errors
|
51
51
|
*/
|
52
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult
|
52
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
|
53
53
|
/**
|
54
54
|
* Interceptors at the root level, helpful when you want override the request/response
|
55
55
|
*/
|
56
|
-
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
|
57
57
|
/**
|
58
58
|
*
|
59
59
|
* Interceptors for procedure client.
|
60
60
|
*/
|
61
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>,
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
|
62
62
|
}
|
63
63
|
declare class StandardHandler<T extends Context> {
|
64
64
|
private readonly matcher;
|
@@ -70,4 +70,5 @@ declare class StandardHandler<T extends Context> {
|
|
70
70
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
71
71
|
}
|
72
72
|
|
73
|
-
export { CompositeStandardHandlerPlugin as C,
|
73
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as f };
|
74
|
+
export type { StandardCodec as S, StandardParams as a, StandardHandleOptions as b, StandardHandleResult as c, StandardHandlerInterceptorOptions as d, StandardHandlerOptions as e, StandardHandlerPlugin as g, StandardMatchResult as h, StandardMatcher as i };
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { b as AnyRouter, C as Context, R as Router } from './server.wMv480px.js';
|
3
|
+
import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.DVBSOxWU.js';
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
5
|
+
import { Value } from '@orpc/shared';
|
6
|
+
import { T as TraverseContractProcedureCallbackOptions } from './server.a_VzWVCm.js';
|
7
|
+
|
8
|
+
interface StandardRPCMatcherOptions {
|
9
|
+
/**
|
10
|
+
* Filter procedures. Return `false` to exclude a procedure from matching.
|
11
|
+
*
|
12
|
+
* @default true
|
13
|
+
*/
|
14
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
15
|
+
}
|
16
|
+
declare class StandardRPCMatcher implements StandardMatcher {
|
17
|
+
private readonly filter;
|
18
|
+
private readonly tree;
|
19
|
+
private pendingRouters;
|
20
|
+
constructor(options?: StandardRPCMatcherOptions);
|
21
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
22
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
23
|
+
}
|
24
|
+
|
25
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions, StandardRPCMatcherOptions {
|
26
|
+
}
|
27
|
+
declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
|
28
|
+
constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
|
29
|
+
}
|
30
|
+
|
31
|
+
export { StandardRPCHandler as a, StandardRPCMatcher as c };
|
32
|
+
export type { StandardRPCHandlerOptions as S, StandardRPCMatcherOptions as b };
|
@@ -1,8 +1,18 @@
|
|
1
1
|
import { HTTPPath, ORPCError } from '@orpc/client';
|
2
|
-
import { Meta
|
3
|
-
import { Interceptor
|
2
|
+
import { Meta } from '@orpc/contract';
|
3
|
+
import { Interceptor } from '@orpc/shared';
|
4
4
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
5
|
-
import {
|
5
|
+
import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.wMv480px.js';
|
6
|
+
|
7
|
+
interface StandardHandlerPlugin<T extends Context> {
|
8
|
+
order?: number;
|
9
|
+
init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
10
|
+
}
|
11
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
12
|
+
protected readonly plugins: TPlugin[];
|
13
|
+
constructor(plugins?: readonly TPlugin[]);
|
14
|
+
init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
15
|
+
}
|
6
16
|
|
7
17
|
type StandardParams = Record<string, string>;
|
8
18
|
type StandardMatchResult = {
|
@@ -20,16 +30,6 @@ interface StandardCodec {
|
|
20
30
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
31
|
}
|
22
32
|
|
23
|
-
interface StandardHandlerPlugin<TContext extends Context> {
|
24
|
-
order?: number;
|
25
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
26
|
-
}
|
27
|
-
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
28
|
-
protected readonly plugins: TPlugin[];
|
29
|
-
constructor(plugins?: readonly TPlugin[]);
|
30
|
-
init(options: StandardHandlerOptions<T>): void;
|
31
|
-
}
|
32
|
-
|
33
33
|
interface StandardHandleOptions<T extends Context> {
|
34
34
|
prefix?: HTTPPath;
|
35
35
|
context: T;
|
@@ -49,16 +49,16 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
49
49
|
/**
|
50
50
|
* Interceptors at the request level, helpful when you want catch errors
|
51
51
|
*/
|
52
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult
|
52
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
|
53
53
|
/**
|
54
54
|
* Interceptors at the root level, helpful when you want override the request/response
|
55
55
|
*/
|
56
|
-
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
|
57
57
|
/**
|
58
58
|
*
|
59
59
|
* Interceptors for procedure client.
|
60
60
|
*/
|
61
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>,
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
|
62
62
|
}
|
63
63
|
declare class StandardHandler<T extends Context> {
|
64
64
|
private readonly matcher;
|
@@ -70,4 +70,5 @@ declare class StandardHandler<T extends Context> {
|
|
70
70
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
71
71
|
}
|
72
72
|
|
73
|
-
export { CompositeStandardHandlerPlugin as C,
|
73
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as f };
|
74
|
+
export type { StandardCodec as S, StandardParams as a, StandardHandleOptions as b, StandardHandleResult as c, StandardHandlerInterceptorOptions as d, StandardHandlerOptions as e, StandardHandlerPlugin as g, StandardMatchResult as h, StandardMatcher as i };
|