@orpc/server 0.0.0-next.2568a3f → 0.0.0-next.25bd3b5
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 +28 -8
- package/dist/adapters/fetch/index.d.ts +28 -8
- 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 +28 -8
- package/dist/adapters/node/index.d.ts +28 -8
- 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 +562 -51
- package/dist/index.d.ts +562 -51
- package/dist/index.mjs +137 -11
- package/dist/plugins/index.d.mts +57 -13
- package/dist/plugins/index.d.ts +57 -13
- 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.CaWivVk3.d.ts → server.Bmh5xd4n.d.ts} +11 -11
- package/dist/shared/server.C6Q5sqYw.mjs +20 -0
- package/dist/shared/{server.DFuJLDuo.mjs → server.CIL9uKTN.mjs} +22 -18
- package/dist/shared/{server.BVHsfJ99.d.mts → server.CYNGeoCm.d.mts} +60 -10
- package/dist/shared/{server.BVHsfJ99.d.ts → server.CYNGeoCm.d.ts} +60 -10
- 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.C37gDhSZ.mjs → server.NeumLVdS.mjs} +16 -10
- package/dist/shared/{server.B1oIHH_j.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.BuLPHTX1.d.mts +0 -18
- package/dist/shared/server.DMhSfHk1.d.ts +0 -10
- package/dist/shared/server.D_vpYits.d.ts +0 -18
- package/dist/shared/server.Dwnm6cSk.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>;
|
@@ -28,6 +28,11 @@ interface Lazy<T> {
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
type Lazyable<T> = T | Lazy<T>;
|
31
|
+
/**
|
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.
|
35
|
+
*/
|
31
36
|
declare function lazy<T>(loader: () => Promise<{
|
32
37
|
default: T;
|
33
38
|
}>, meta?: LazyMeta): Lazy<T>;
|
@@ -56,7 +61,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
|
|
56
61
|
outputValidationIndex: number;
|
57
62
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
58
63
|
}
|
64
|
+
/**
|
65
|
+
* This class represents a procedure.
|
66
|
+
*
|
67
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
68
|
+
*/
|
59
69
|
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
70
|
+
/**
|
71
|
+
* This property holds the defined options.
|
72
|
+
*/
|
60
73
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
61
74
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
62
75
|
}
|
@@ -87,6 +100,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
|
|
87
100
|
next: MiddlewareNextFn<TOutput>;
|
88
101
|
errors: TErrorConstructorMap;
|
89
102
|
}
|
103
|
+
/**
|
104
|
+
* A function that represents a middleware.
|
105
|
+
*
|
106
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
107
|
+
*/
|
90
108
|
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
91
109
|
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
92
110
|
}
|
@@ -106,39 +124,71 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TEr
|
|
106
124
|
signal?: AbortSignal;
|
107
125
|
lastEventId: string | undefined;
|
108
126
|
}
|
109
|
-
/**
|
110
|
-
* Options for creating a procedure caller with comprehensive type safety
|
111
|
-
*/
|
112
127
|
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
113
128
|
/**
|
114
129
|
* This is helpful for logging and analytics.
|
115
130
|
*/
|
116
131
|
path?: readonly string[];
|
117
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap
|
132
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
118
133
|
} & (Record<never, never> extends TInitialContext ? {
|
119
|
-
context?: Value<TInitialContext
|
134
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
120
135
|
} : {
|
121
|
-
context: Value<TInitialContext
|
136
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
122
137
|
});
|
123
|
-
|
138
|
+
/**
|
139
|
+
* Create Server-side client from a procedure.
|
140
|
+
*
|
141
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
142
|
+
*/
|
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>;
|
124
144
|
|
145
|
+
/**
|
146
|
+
* Represents a router, which defines a hierarchical structure of procedures.
|
147
|
+
*
|
148
|
+
* @info A procedure is a router too.
|
149
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
150
|
+
*/
|
125
151
|
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
|
126
152
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
127
153
|
};
|
128
154
|
type AnyRouter = Router<any, any>;
|
129
155
|
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
156
|
+
/**
|
157
|
+
* Infer all initial context of the router.
|
158
|
+
*
|
159
|
+
* @info A procedure is a router too.
|
160
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
161
|
+
*/
|
130
162
|
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
131
163
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
132
164
|
};
|
165
|
+
/**
|
166
|
+
* Infer all current context of the router.
|
167
|
+
*
|
168
|
+
* @info A procedure is a router too.
|
169
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
170
|
+
*/
|
133
171
|
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
134
172
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
135
173
|
};
|
174
|
+
/**
|
175
|
+
* Infer all router inputs
|
176
|
+
*
|
177
|
+
* @info A procedure is a router too.
|
178
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
179
|
+
*/
|
136
180
|
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
137
181
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
138
182
|
};
|
183
|
+
/**
|
184
|
+
* Infer all router outputs
|
185
|
+
*
|
186
|
+
* @info A procedure is a router too.
|
187
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
188
|
+
*/
|
139
189
|
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
140
190
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
141
191
|
};
|
142
192
|
|
143
|
-
export { isProcedure as
|
144
|
-
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>;
|
@@ -28,6 +28,11 @@ interface Lazy<T> {
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
type Lazyable<T> = T | Lazy<T>;
|
31
|
+
/**
|
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.
|
35
|
+
*/
|
31
36
|
declare function lazy<T>(loader: () => Promise<{
|
32
37
|
default: T;
|
33
38
|
}>, meta?: LazyMeta): Lazy<T>;
|
@@ -56,7 +61,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
|
|
56
61
|
outputValidationIndex: number;
|
57
62
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
58
63
|
}
|
64
|
+
/**
|
65
|
+
* This class represents a procedure.
|
66
|
+
*
|
67
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
68
|
+
*/
|
59
69
|
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
70
|
+
/**
|
71
|
+
* This property holds the defined options.
|
72
|
+
*/
|
60
73
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
61
74
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
62
75
|
}
|
@@ -87,6 +100,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
|
|
87
100
|
next: MiddlewareNextFn<TOutput>;
|
88
101
|
errors: TErrorConstructorMap;
|
89
102
|
}
|
103
|
+
/**
|
104
|
+
* A function that represents a middleware.
|
105
|
+
*
|
106
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
107
|
+
*/
|
90
108
|
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
91
109
|
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
92
110
|
}
|
@@ -106,39 +124,71 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TEr
|
|
106
124
|
signal?: AbortSignal;
|
107
125
|
lastEventId: string | undefined;
|
108
126
|
}
|
109
|
-
/**
|
110
|
-
* Options for creating a procedure caller with comprehensive type safety
|
111
|
-
*/
|
112
127
|
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
113
128
|
/**
|
114
129
|
* This is helpful for logging and analytics.
|
115
130
|
*/
|
116
131
|
path?: readonly string[];
|
117
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap
|
132
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
118
133
|
} & (Record<never, never> extends TInitialContext ? {
|
119
|
-
context?: Value<TInitialContext
|
134
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
120
135
|
} : {
|
121
|
-
context: Value<TInitialContext
|
136
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
122
137
|
});
|
123
|
-
|
138
|
+
/**
|
139
|
+
* Create Server-side client from a procedure.
|
140
|
+
*
|
141
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
142
|
+
*/
|
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>;
|
124
144
|
|
145
|
+
/**
|
146
|
+
* Represents a router, which defines a hierarchical structure of procedures.
|
147
|
+
*
|
148
|
+
* @info A procedure is a router too.
|
149
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
150
|
+
*/
|
125
151
|
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
|
126
152
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
127
153
|
};
|
128
154
|
type AnyRouter = Router<any, any>;
|
129
155
|
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
156
|
+
/**
|
157
|
+
* Infer all initial context of the router.
|
158
|
+
*
|
159
|
+
* @info A procedure is a router too.
|
160
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
161
|
+
*/
|
130
162
|
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
131
163
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
132
164
|
};
|
165
|
+
/**
|
166
|
+
* Infer all current context of the router.
|
167
|
+
*
|
168
|
+
* @info A procedure is a router too.
|
169
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
170
|
+
*/
|
133
171
|
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
134
172
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
135
173
|
};
|
174
|
+
/**
|
175
|
+
* Infer all router inputs
|
176
|
+
*
|
177
|
+
* @info A procedure is a router too.
|
178
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
179
|
+
*/
|
136
180
|
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
137
181
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
138
182
|
};
|
183
|
+
/**
|
184
|
+
* Infer all router outputs
|
185
|
+
*
|
186
|
+
* @info A procedure is a router too.
|
187
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
188
|
+
*/
|
139
189
|
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
140
190
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
141
191
|
};
|
142
192
|
|
143
|
-
export { isProcedure as
|
144
|
-
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 };
|