@orpc/server 0.0.0-next.9d7bfaa → 0.0.0-next.9de128a
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 +6 -7
- 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 +18 -9
- package/dist/adapters/fetch/index.d.ts +18 -9
- package/dist/adapters/fetch/index.mjs +9 -4
- 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 +18 -9
- package/dist/adapters/node/index.d.ts +18 -9
- package/dist/adapters/node/index.mjs +10 -4
- 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 -5
- 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 +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 +23 -49
- package/dist/index.d.ts +23 -49
- package/dist/index.mjs +26 -8
- package/dist/plugins/index.d.mts +28 -15
- package/dist/plugins/index.d.ts +28 -15
- package/dist/plugins/index.mjs +37 -13
- package/dist/shared/server.B7b2w3_i.d.ts +12 -0
- package/dist/shared/server.BEFBl-Cb.d.mts +12 -0
- package/dist/shared/server.BU4WI18A.d.mts +32 -0
- package/dist/shared/{server.D5fBlF9j.d.ts → server.Bmh5xd4n.d.ts} +11 -11
- package/dist/shared/server.C6Q5sqYw.mjs +20 -0
- package/dist/shared/{server.qf03T-Xn.mjs → server.CIL9uKTN.mjs} +22 -18
- package/dist/shared/{server.DPWk5pjW.d.mts → server.CYNGeoCm.d.mts} +10 -8
- package/dist/shared/{server.DPWk5pjW.d.ts → server.CYNGeoCm.d.ts} +10 -8
- package/dist/shared/server.D0H-iaY3.d.ts +32 -0
- package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
- package/dist/shared/server.DhJj-1X9.d.mts +42 -0
- package/dist/shared/{server.DG7Tamti.mjs → server.NeumLVdS.mjs} +13 -10
- package/dist/shared/{server.DY7OKEoj.d.mts → server.gqRxT-yN.d.mts} +11 -11
- package/dist/shared/server.jMTkVNIb.d.ts +42 -0
- package/package.json +72 -8
- package/dist/shared/server.CN0534_m.d.mts +0 -18
- package/dist/shared/server.CjlA3NKP.d.ts +0 -10
- package/dist/shared/server.CuD15qZB.d.ts +0 -18
- package/dist/shared/server.DjgtLwKi.d.mts +0 -10
package/dist/plugins/index.mjs
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
import { value, isAsyncIteratorObject } 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';
|
3
5
|
import { ORPCError } from '@orpc/client';
|
4
6
|
export { S as StrictGetMethodPlugin } from '../shared/server.BW-nUGgA.mjs';
|
5
7
|
import '@orpc/contract';
|
@@ -25,7 +27,8 @@ class BatchHandlerPlugin {
|
|
25
27
|
init(options) {
|
26
28
|
options.rootInterceptors ??= [];
|
27
29
|
options.rootInterceptors.unshift(async (options2) => {
|
28
|
-
|
30
|
+
const xHeader = flattenHeader(options2.request.headers["x-orpc-batch"]);
|
31
|
+
if (xHeader === void 0) {
|
29
32
|
return options2.next();
|
30
33
|
}
|
31
34
|
let isParsing = false;
|
@@ -68,9 +71,10 @@ class BatchHandlerPlugin {
|
|
68
71
|
await Promise.race(responses);
|
69
72
|
const status = await value(this.successStatus, responses, options2);
|
70
73
|
const headers = await value(this.headers, responses, options2);
|
71
|
-
const response = toBatchResponse({
|
74
|
+
const response = await toBatchResponse({
|
72
75
|
status,
|
73
76
|
headers,
|
77
|
+
mode: xHeader === "buffered" ? "buffered" : "streaming",
|
74
78
|
body: async function* () {
|
75
79
|
const promises = [...responses];
|
76
80
|
while (true) {
|
@@ -123,13 +127,11 @@ class CORSPlugin {
|
|
123
127
|
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
124
128
|
}
|
125
129
|
if (this.options.allowMethods?.length) {
|
126
|
-
resHeaders["access-control-allow-methods"] = this.options.allowMethods
|
130
|
+
resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
|
127
131
|
}
|
128
132
|
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
129
|
-
if (
|
130
|
-
resHeaders["access-control-allow-headers"] = allowHeaders
|
131
|
-
} else if (typeof allowHeaders === "string") {
|
132
|
-
resHeaders["access-control-allow-headers"] = allowHeaders;
|
133
|
+
if (typeof allowHeaders === "string" || allowHeaders?.length) {
|
134
|
+
resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
|
133
135
|
}
|
134
136
|
return {
|
135
137
|
matched: true,
|
@@ -147,7 +149,7 @@ class CORSPlugin {
|
|
147
149
|
if (!result.matched) {
|
148
150
|
return result;
|
149
151
|
}
|
150
|
-
const origin =
|
152
|
+
const origin = flattenHeader(interceptorOptions.request.headers.origin) ?? "";
|
151
153
|
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
152
154
|
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
153
155
|
if (allowedOriginArr.includes("*")) {
|
@@ -169,13 +171,29 @@ class CORSPlugin {
|
|
169
171
|
result.response.headers["access-control-allow-credentials"] = "true";
|
170
172
|
}
|
171
173
|
if (this.options.exposeHeaders?.length) {
|
172
|
-
result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders
|
174
|
+
result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
|
173
175
|
}
|
174
176
|
return result;
|
175
177
|
});
|
176
178
|
}
|
177
179
|
}
|
178
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
|
+
|
179
197
|
class ResponseHeadersPlugin {
|
180
198
|
init(options) {
|
181
199
|
options.rootInterceptors ??= [];
|
@@ -191,7 +209,7 @@ class ResponseHeadersPlugin {
|
|
191
209
|
if (!result.matched) {
|
192
210
|
return result;
|
193
211
|
}
|
194
|
-
const responseHeaders = result.response.headers;
|
212
|
+
const responseHeaders = clone(result.response.headers);
|
195
213
|
for (const [key, value] of resHeaders) {
|
196
214
|
if (Array.isArray(responseHeaders[key])) {
|
197
215
|
responseHeaders[key].push(value);
|
@@ -201,7 +219,13 @@ class ResponseHeadersPlugin {
|
|
201
219
|
responseHeaders[key] = value;
|
202
220
|
}
|
203
221
|
}
|
204
|
-
return
|
222
|
+
return {
|
223
|
+
...result,
|
224
|
+
response: {
|
225
|
+
...result.response,
|
226
|
+
headers: responseHeaders
|
227
|
+
}
|
228
|
+
};
|
205
229
|
});
|
206
230
|
}
|
207
231
|
}
|
@@ -249,4 +273,4 @@ class SimpleCsrfProtectionHandlerPlugin {
|
|
249
273
|
}
|
250
274
|
}
|
251
275
|
|
252
|
-
export { BatchHandlerPlugin, CORSPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
|
276
|
+
export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { C as Context } from './server.CYNGeoCm.js';
|
2
|
+
import { b as StandardHandleOptions } from './server.Bmh5xd4n.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.CYNGeoCm.mjs';
|
2
|
+
import { b as StandardHandleOptions } from './server.gqRxT-yN.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,32 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { b as AnyRouter, C as Context, R as Router } from './server.CYNGeoCm.mjs';
|
3
|
+
import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.gqRxT-yN.mjs';
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
5
|
+
import { Value } from '@orpc/shared';
|
6
|
+
import { T as TraverseContractProcedureCallbackOptions } from './server.DhJj-1X9.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,17 +1,17 @@
|
|
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 { C as Context,
|
5
|
+
import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.CYNGeoCm.js';
|
6
6
|
|
7
|
-
interface StandardHandlerPlugin<
|
7
|
+
interface StandardHandlerPlugin<T extends Context> {
|
8
8
|
order?: number;
|
9
|
-
init?(options: StandardHandlerOptions<
|
9
|
+
init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
10
10
|
}
|
11
11
|
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
12
12
|
protected readonly plugins: TPlugin[];
|
13
13
|
constructor(plugins?: readonly TPlugin[]);
|
14
|
-
init(options: StandardHandlerOptions<T>): void;
|
14
|
+
init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
15
15
|
}
|
16
16
|
|
17
17
|
type StandardParams = Record<string, string>;
|
@@ -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,5 +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, StandardHandler as
|
74
|
-
export type {
|
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,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 };
|
@@ -1,18 +1,17 @@
|
|
1
1
|
import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
|
-
import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
|
3
|
-
import '@orpc/standard-server/batch';
|
4
2
|
import { ORPCError, toORPCError } from '@orpc/client';
|
5
|
-
import {
|
6
|
-
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';
|
7
6
|
|
8
7
|
class CompositeStandardHandlerPlugin {
|
9
8
|
plugins;
|
10
9
|
constructor(plugins = []) {
|
11
10
|
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
12
11
|
}
|
13
|
-
init(options) {
|
12
|
+
init(options, router) {
|
14
13
|
for (const plugin of this.plugins) {
|
15
|
-
plugin.init?.(options);
|
14
|
+
plugin.init?.(options, router);
|
16
15
|
}
|
17
16
|
}
|
18
17
|
}
|
@@ -22,7 +21,7 @@ class StandardHandler {
|
|
22
21
|
this.matcher = matcher;
|
23
22
|
this.codec = codec;
|
24
23
|
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
|
25
|
-
plugins.init(options);
|
24
|
+
plugins.init(options, router);
|
26
25
|
this.interceptors = toArray(options.interceptors);
|
27
26
|
this.clientInterceptors = toArray(options.clientInterceptors);
|
28
27
|
this.rootInterceptors = toArray(options.rootInterceptors);
|
@@ -61,8 +60,10 @@ class StandardHandler {
|
|
61
60
|
isDecoding = true;
|
62
61
|
const input = await this.codec.decode(request2, match.params, match.procedure);
|
63
62
|
isDecoding = false;
|
64
|
-
const
|
65
|
-
|
63
|
+
const output = await client(input, {
|
64
|
+
signal: request2.signal,
|
65
|
+
lastEventId: flattenHeader(request2.headers["last-event-id"])
|
66
|
+
});
|
66
67
|
const response = this.codec.encode(output, match.procedure);
|
67
68
|
return {
|
68
69
|
matched: true,
|
@@ -111,10 +112,18 @@ class StandardRPCCodec {
|
|
111
112
|
}
|
112
113
|
|
113
114
|
class StandardRPCMatcher {
|
114
|
-
|
115
|
+
filter;
|
116
|
+
tree = new NullProtoObj();
|
115
117
|
pendingRouters = [];
|
118
|
+
constructor(options = {}) {
|
119
|
+
this.filter = options.filter ?? true;
|
120
|
+
}
|
116
121
|
init(router, path = []) {
|
117
|
-
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;
|
118
127
|
const httpPath = toHttpPath(path2);
|
119
128
|
if (isProcedure(contract)) {
|
120
129
|
this.tree[httpPath] = {
|
@@ -173,15 +182,10 @@ class StandardRPCMatcher {
|
|
173
182
|
}
|
174
183
|
|
175
184
|
class StandardRPCHandler extends StandardHandler {
|
176
|
-
constructor(router, options) {
|
177
|
-
options.plugins ??= [];
|
178
|
-
const strictGetMethodPluginEnabled = options.strictGetMethodPluginEnabled ?? true;
|
179
|
-
if (strictGetMethodPluginEnabled) {
|
180
|
-
options.plugins.push(new StrictGetMethodPlugin());
|
181
|
-
}
|
185
|
+
constructor(router, options = {}) {
|
182
186
|
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
183
187
|
const serializer = new StandardRPCSerializer(jsonSerializer);
|
184
|
-
const matcher = new StandardRPCMatcher();
|
188
|
+
const matcher = new StandardRPCMatcher(options);
|
185
189
|
const codec = new StandardRPCCodec(serializer);
|
186
190
|
super(router, matcher, codec, options);
|
187
191
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
|
2
2
|
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
3
|
-
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, Value } from '@orpc/shared';
|
4
4
|
|
5
5
|
type Context = Record<PropertyKey, any>;
|
6
6
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
@@ -29,7 +29,9 @@ interface Lazy<T> {
|
|
29
29
|
}
|
30
30
|
type Lazyable<T> = T | Lazy<T>;
|
31
31
|
/**
|
32
|
-
*
|
32
|
+
* Creates a lazy-loaded item.
|
33
|
+
*
|
34
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
|
33
35
|
*/
|
34
36
|
declare function lazy<T>(loader: () => Promise<{
|
35
37
|
default: T;
|
@@ -127,18 +129,18 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
|
|
127
129
|
* This is helpful for logging and analytics.
|
128
130
|
*/
|
129
131
|
path?: readonly string[];
|
130
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap
|
132
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
131
133
|
} & (Record<never, never> extends TInitialContext ? {
|
132
|
-
context?: Value<TInitialContext
|
134
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
133
135
|
} : {
|
134
|
-
context: Value<TInitialContext
|
136
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
135
137
|
});
|
136
138
|
/**
|
137
139
|
* Create Server-side client from a procedure.
|
138
140
|
*
|
139
141
|
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
140
142
|
*/
|
141
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...
|
143
|
+
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
142
144
|
|
143
145
|
/**
|
144
146
|
* Represents a router, which defines a hierarchical structure of procedures.
|
@@ -188,5 +190,5 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
188
190
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
189
191
|
};
|
190
192
|
|
191
|
-
export { isProcedure as
|
192
|
-
export type {
|
193
|
+
export { middlewareOutputFn as B, isProcedure as F, createProcedureClient as G, Procedure as P, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, validateORPCError as v };
|
194
|
+
export type { AnyProcedure as A, Context as C, ProcedureHandlerOptions as D, ProcedureDef as E, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, MergedInitialContext as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, AnyMiddleware as a, AnyRouter as b, Lazy as c, ProcedureClientInterceptorOptions as d, Middleware as e, MergedCurrentContext as f, MapInputMiddleware as g, CreateProcedureClientOptions as h, ProcedureClient as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as w, MiddlewareNextFn as x, MiddlewareOutputFn as y, MiddlewareOptions as z };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
|
2
2
|
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
3
|
-
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, Value } from '@orpc/shared';
|
4
4
|
|
5
5
|
type Context = Record<PropertyKey, any>;
|
6
6
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
@@ -29,7 +29,9 @@ interface Lazy<T> {
|
|
29
29
|
}
|
30
30
|
type Lazyable<T> = T | Lazy<T>;
|
31
31
|
/**
|
32
|
-
*
|
32
|
+
* Creates a lazy-loaded item.
|
33
|
+
*
|
34
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
|
33
35
|
*/
|
34
36
|
declare function lazy<T>(loader: () => Promise<{
|
35
37
|
default: T;
|
@@ -127,18 +129,18 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
|
|
127
129
|
* This is helpful for logging and analytics.
|
128
130
|
*/
|
129
131
|
path?: readonly string[];
|
130
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap
|
132
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
131
133
|
} & (Record<never, never> extends TInitialContext ? {
|
132
|
-
context?: Value<TInitialContext
|
134
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
133
135
|
} : {
|
134
|
-
context: Value<TInitialContext
|
136
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
135
137
|
});
|
136
138
|
/**
|
137
139
|
* Create Server-side client from a procedure.
|
138
140
|
*
|
139
141
|
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
140
142
|
*/
|
141
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...
|
143
|
+
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
142
144
|
|
143
145
|
/**
|
144
146
|
* Represents a router, which defines a hierarchical structure of procedures.
|
@@ -188,5 +190,5 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
188
190
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
189
191
|
};
|
190
192
|
|
191
|
-
export { isProcedure as
|
192
|
-
export type {
|
193
|
+
export { middlewareOutputFn as B, isProcedure as F, createProcedureClient as G, Procedure as P, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, validateORPCError as v };
|
194
|
+
export type { AnyProcedure as A, Context as C, ProcedureHandlerOptions as D, ProcedureDef as E, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, MergedInitialContext as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, AnyMiddleware as a, AnyRouter as b, Lazy as c, ProcedureClientInterceptorOptions as d, Middleware as e, MergedCurrentContext as f, MapInputMiddleware as g, CreateProcedureClientOptions as h, ProcedureClient as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as w, MiddlewareNextFn as x, MiddlewareOutputFn as y, MiddlewareOptions as z };
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { b as AnyRouter, C as Context, R as Router } from './server.CYNGeoCm.js';
|
3
|
+
import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.Bmh5xd4n.js';
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
5
|
+
import { Value } from '@orpc/shared';
|
6
|
+
import { T as TraverseContractProcedureCallbackOptions } from './server.jMTkVNIb.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 };
|
@@ -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.CYNGeoCm.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,6 +1,6 @@
|
|
1
1
|
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
|
2
|
+
import { resolveMaybeOptionalOptions, toArray, value, intercept } from '@orpc/shared';
|
2
3
|
import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
|
3
|
-
import { value, intercept } from '@orpc/shared';
|
4
4
|
|
5
5
|
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
6
6
|
function lazy(loader, meta = {}) {
|
@@ -71,14 +71,15 @@ function createORPCErrorConstructorMap(errors) {
|
|
71
71
|
if (typeof code !== "string") {
|
72
72
|
return Reflect.get(target, code);
|
73
73
|
}
|
74
|
-
const item = (...
|
74
|
+
const item = (...rest) => {
|
75
|
+
const options = resolveMaybeOptionalOptions(rest);
|
75
76
|
const config = errors[code];
|
76
77
|
return new ORPCError(code, {
|
77
78
|
defined: Boolean(config),
|
78
79
|
status: config?.status,
|
79
|
-
message: options
|
80
|
-
data: options
|
81
|
-
cause: options
|
80
|
+
message: options.message ?? config?.message,
|
81
|
+
data: options.data,
|
82
|
+
cause: options.cause
|
82
83
|
});
|
83
84
|
};
|
84
85
|
return item;
|
@@ -106,16 +107,17 @@ function middlewareOutputFn(output) {
|
|
106
107
|
return { output, context: {} };
|
107
108
|
}
|
108
109
|
|
109
|
-
function createProcedureClient(lazyableProcedure, ...
|
110
|
+
function createProcedureClient(lazyableProcedure, ...rest) {
|
111
|
+
const options = resolveMaybeOptionalOptions(rest);
|
110
112
|
return async (...[input, callerOptions]) => {
|
111
|
-
const path = options
|
113
|
+
const path = toArray(options.path);
|
112
114
|
const { default: procedure } = await unlazy(lazyableProcedure);
|
113
115
|
const clientContext = callerOptions?.context ?? {};
|
114
|
-
const context = await value(options
|
116
|
+
const context = await value(options.context ?? {}, clientContext);
|
115
117
|
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
|
116
118
|
try {
|
117
119
|
return await intercept(
|
118
|
-
options
|
120
|
+
toArray(options.interceptors),
|
119
121
|
{
|
120
122
|
context,
|
121
123
|
input,
|
@@ -361,7 +363,8 @@ function createContractedProcedure(procedure, contract) {
|
|
361
363
|
});
|
362
364
|
}
|
363
365
|
function call(procedure, input, ...rest) {
|
364
|
-
|
366
|
+
const options = resolveMaybeOptionalOptions(rest);
|
367
|
+
return createProcedureClient(procedure, options)(input, options);
|
365
368
|
}
|
366
369
|
|
367
370
|
export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, resolveContractProcedures as w, unlazyRouter as x };
|