@orpc/server 0.0.0-next.d16a1b6 → 0.0.0-next.d3b4900
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 +13 -1
- package/dist/adapters/fetch/index.d.mts +38 -11
- package/dist/adapters/fetch/index.d.ts +38 -11
- package/dist/adapters/fetch/index.mjs +6 -6
- package/dist/adapters/hono/index.d.mts +6 -4
- package/dist/adapters/hono/index.d.ts +6 -4
- package/dist/adapters/hono/index.mjs +6 -6
- package/dist/adapters/next/index.d.mts +6 -4
- package/dist/adapters/next/index.d.ts +6 -4
- package/dist/adapters/next/index.mjs +6 -6
- package/dist/adapters/node/index.d.mts +40 -22
- package/dist/adapters/node/index.d.ts +40 -22
- package/dist/adapters/node/index.mjs +77 -20
- package/dist/adapters/standard/index.d.mts +10 -13
- package/dist/adapters/standard/index.d.ts +10 -13
- package/dist/adapters/standard/index.mjs +2 -4
- package/dist/index.d.mts +140 -118
- package/dist/index.d.ts +140 -118
- package/dist/index.mjs +55 -46
- package/dist/plugins/index.d.mts +14 -15
- package/dist/plugins/index.d.ts +14 -15
- package/dist/plugins/index.mjs +10 -6
- package/dist/shared/{server.B-ewprcf.d.ts → server.23VRZIfj.d.ts} +19 -30
- package/dist/shared/server.B4eSvRkD.mjs +98 -0
- package/dist/shared/server.BG5ftPWa.d.ts +10 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/{server.V6zT5iYQ.mjs → server.BtxZnWJ9.mjs} +155 -160
- package/dist/shared/server.C-CCcROC.d.mts +10 -0
- package/dist/shared/server.CIbpOMZX.d.mts +8 -0
- package/dist/shared/server.DCcCuA52.d.ts +8 -0
- package/dist/shared/{server.DJrh0Ceu.d.mts → server.DJqfB27m.d.mts} +19 -30
- package/dist/shared/{server.BBGuTxHE.mjs → server.DnR6v9pj.mjs} +42 -45
- package/dist/shared/server.MZvbGc3n.d.mts +143 -0
- package/dist/shared/server.MZvbGc3n.d.ts +143 -0
- package/package.json +8 -8
- package/dist/shared/server.CA-o8cUY.d.mts +0 -9
- package/dist/shared/server.Cn9ybJtE.d.mts +0 -152
- package/dist/shared/server.Cn9ybJtE.d.ts +0 -152
- package/dist/shared/server.DPQt9YYq.d.ts +0 -9
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
- package/dist/shared/server.pW-fRQNZ.mjs +0 -24
package/dist/index.mjs
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure } from '@orpc/contract';
|
1
|
+
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
2
2
|
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { P as Procedure, d as addMiddleware, c as createProcedureClient,
|
4
|
-
export { L as
|
3
|
+
import { P as Procedure, d as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, f as isLazy, h as createAssertedLazyProcedure, g as getRouter } from './shared/server.BtxZnWJ9.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, q as call, w as createAccessibleLazyRouter, b as createContractedProcedure, j as createORPCErrorConstructorMap, r as getHiddenRouterContract, k as getLazyMeta, o as isStartWithMiddlewares, m as mergeCurrentContext, p as mergeMiddlewares, n as middlewareOutputFn, x as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, y as unlazyRouter, v as validateORPCError } from './shared/server.BtxZnWJ9.mjs';
|
5
5
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
6
6
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
7
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
8
8
|
|
9
9
|
const DEFAULT_CONFIG = {
|
10
10
|
initialInputValidationIndex: 0,
|
11
|
-
initialOutputValidationIndex: 0
|
11
|
+
initialOutputValidationIndex: 0,
|
12
|
+
dedupeLeadingMiddlewares: true
|
12
13
|
};
|
13
14
|
function fallbackConfig(key, value) {
|
14
15
|
if (value === void 0) {
|
@@ -18,7 +19,7 @@ function fallbackConfig(key, value) {
|
|
18
19
|
}
|
19
20
|
|
20
21
|
function decorateMiddleware(middleware) {
|
21
|
-
const decorated = middleware;
|
22
|
+
const decorated = (...args) => middleware(...args);
|
22
23
|
decorated.mapInput = (mapInput) => {
|
23
24
|
const mapped = decorateMiddleware(
|
24
25
|
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
@@ -73,9 +74,13 @@ class DecoratedProcedure extends Procedure {
|
|
73
74
|
* Make this procedure callable (works like a function while still being a procedure).
|
74
75
|
*/
|
75
76
|
callable(...rest) {
|
76
|
-
return
|
77
|
-
|
78
|
-
|
77
|
+
return new Proxy(createProcedureClient(this, ...rest), {
|
78
|
+
get: (target, key) => {
|
79
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
80
|
+
},
|
81
|
+
has: (target, key) => {
|
82
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
83
|
+
}
|
79
84
|
});
|
80
85
|
}
|
81
86
|
/**
|
@@ -100,6 +105,7 @@ class Builder {
|
|
100
105
|
return new Builder({
|
101
106
|
...this["~orpc"],
|
102
107
|
config,
|
108
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
|
103
109
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
104
110
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
105
111
|
});
|
@@ -133,6 +139,12 @@ class Builder {
|
|
133
139
|
route: initialRoute
|
134
140
|
});
|
135
141
|
}
|
142
|
+
$input(initialInputSchema) {
|
143
|
+
return new Builder({
|
144
|
+
...this["~orpc"],
|
145
|
+
inputSchema: initialInputSchema
|
146
|
+
});
|
147
|
+
}
|
136
148
|
middleware(middleware) {
|
137
149
|
return decorateMiddleware(middleware);
|
138
150
|
}
|
@@ -194,10 +206,10 @@ class Builder {
|
|
194
206
|
});
|
195
207
|
}
|
196
208
|
router(router) {
|
197
|
-
return
|
209
|
+
return enhanceRouter(router, this["~orpc"]);
|
198
210
|
}
|
199
211
|
lazy(loader) {
|
200
|
-
return
|
212
|
+
return enhanceRouter(lazy(loader), this["~orpc"]);
|
201
213
|
}
|
202
214
|
}
|
203
215
|
const os = new Builder({
|
@@ -205,17 +217,12 @@ const os = new Builder({
|
|
205
217
|
route: {},
|
206
218
|
meta: {},
|
207
219
|
errorMap: {},
|
208
|
-
inputSchema: void 0,
|
209
|
-
outputSchema: void 0,
|
210
220
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
211
221
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
212
|
-
middlewares: []
|
222
|
+
middlewares: [],
|
223
|
+
dedupeLeadingMiddlewares: true
|
213
224
|
});
|
214
225
|
|
215
|
-
function mergeContext(context, other) {
|
216
|
-
return { ...context, ...other };
|
217
|
-
}
|
218
|
-
|
219
226
|
function implementerInternal(contract, config, middlewares) {
|
220
227
|
if (isContractProcedure(contract)) {
|
221
228
|
const impl2 = new Builder({
|
@@ -223,12 +230,16 @@ function implementerInternal(contract, config, middlewares) {
|
|
223
230
|
config,
|
224
231
|
middlewares,
|
225
232
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
226
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
233
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
|
234
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
227
235
|
});
|
228
236
|
return impl2;
|
229
237
|
}
|
230
238
|
const impl = new Proxy(contract, {
|
231
239
|
get: (target, key) => {
|
240
|
+
if (typeof key !== "string") {
|
241
|
+
return Reflect.get(target, key);
|
242
|
+
}
|
232
243
|
let method;
|
233
244
|
if (key === "middleware") {
|
234
245
|
method = (mid) => decorateMiddleware(mid);
|
@@ -242,23 +253,29 @@ function implementerInternal(contract, config, middlewares) {
|
|
242
253
|
};
|
243
254
|
} else if (key === "router") {
|
244
255
|
method = (router) => {
|
245
|
-
const adapted =
|
256
|
+
const adapted = enhanceRouter(router, {
|
246
257
|
middlewares,
|
247
|
-
errorMap: {}
|
258
|
+
errorMap: {},
|
259
|
+
prefix: void 0,
|
260
|
+
tags: void 0,
|
261
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
248
262
|
});
|
249
|
-
return
|
263
|
+
return setHiddenRouterContract(adapted, contract);
|
250
264
|
};
|
251
265
|
} else if (key === "lazy") {
|
252
266
|
method = (loader) => {
|
253
|
-
const adapted =
|
267
|
+
const adapted = enhanceRouter(lazy(loader), {
|
254
268
|
middlewares,
|
255
|
-
errorMap: {}
|
269
|
+
errorMap: {},
|
270
|
+
prefix: void 0,
|
271
|
+
tags: void 0,
|
272
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
256
273
|
});
|
257
|
-
return
|
274
|
+
return setHiddenRouterContract(adapted, contract);
|
258
275
|
};
|
259
276
|
}
|
260
|
-
const next =
|
261
|
-
if (!next
|
277
|
+
const next = getContractRouter(target, [key]);
|
278
|
+
if (!next) {
|
262
279
|
return method ?? next;
|
263
280
|
}
|
264
281
|
const nextImpl = implementerInternal(next, config, middlewares);
|
@@ -285,42 +302,34 @@ function implement(contract, config = {}) {
|
|
285
302
|
method = (config2) => implement(contract, config2);
|
286
303
|
}
|
287
304
|
const next = Reflect.get(target, key);
|
288
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
289
|
-
return method
|
305
|
+
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
306
|
+
return method || next;
|
290
307
|
}
|
291
|
-
|
292
|
-
|
293
|
-
get(
|
294
|
-
|
295
|
-
|
296
|
-
});
|
297
|
-
}
|
298
|
-
return next;
|
308
|
+
return new Proxy(method, {
|
309
|
+
get(_, key2) {
|
310
|
+
return Reflect.get(next, key2);
|
311
|
+
}
|
312
|
+
});
|
299
313
|
}
|
300
314
|
});
|
301
315
|
return impl;
|
302
316
|
}
|
303
317
|
|
304
|
-
function
|
305
|
-
return createProcedureClient(procedure, ...rest)(input);
|
306
|
-
}
|
307
|
-
|
308
|
-
function createRouterClient(router, ...rest) {
|
318
|
+
function createRouterClient(router, ...[options]) {
|
309
319
|
if (isProcedure(router)) {
|
310
|
-
const caller = createProcedureClient(router,
|
320
|
+
const caller = createProcedureClient(router, options);
|
311
321
|
return caller;
|
312
322
|
}
|
313
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(
|
323
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
314
324
|
const recursive = new Proxy(procedureCaller, {
|
315
325
|
get(target, key) {
|
316
326
|
if (typeof key !== "string") {
|
317
327
|
return Reflect.get(target, key);
|
318
328
|
}
|
319
|
-
const next =
|
329
|
+
const next = getRouter(router, [key]);
|
320
330
|
if (!next) {
|
321
331
|
return Reflect.get(target, key);
|
322
332
|
}
|
323
|
-
const [options] = rest;
|
324
333
|
return createRouterClient(next, {
|
325
334
|
...options,
|
326
335
|
path: [...options?.path ?? [], key]
|
@@ -330,4 +339,4 @@ function createRouterClient(router, ...rest) {
|
|
330
339
|
return recursive;
|
331
340
|
}
|
332
341
|
|
333
|
-
export { Builder, DecoratedProcedure, Procedure,
|
342
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,31 +1,30 @@
|
|
1
|
-
import {
|
2
|
-
export { C as CompositePlugin } from '../shared/server.DJrh0Ceu.mjs';
|
1
|
+
import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DJqfB27m.mjs';
|
3
2
|
import { Value } from '@orpc/shared';
|
4
|
-
import { C as Context } from '../shared/server.
|
3
|
+
import { C as Context } from '../shared/server.MZvbGc3n.mjs';
|
5
4
|
import '@orpc/contract';
|
6
5
|
import '@orpc/standard-server';
|
7
6
|
import '@orpc/client';
|
8
7
|
|
9
|
-
interface CORSOptions<
|
10
|
-
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<
|
11
|
-
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<
|
12
|
-
allowMethods?: string[];
|
13
|
-
allowHeaders?: string[];
|
8
|
+
interface CORSOptions<T extends Context> {
|
9
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
10
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
11
|
+
allowMethods?: readonly string[];
|
12
|
+
allowHeaders?: readonly string[];
|
14
13
|
maxAge?: number;
|
15
14
|
credentials?: boolean;
|
16
|
-
exposeHeaders?: string[];
|
15
|
+
exposeHeaders?: readonly string[];
|
17
16
|
}
|
18
|
-
declare class CORSPlugin<
|
17
|
+
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
19
18
|
private readonly options;
|
20
|
-
constructor(options?:
|
21
|
-
init(options: StandardHandlerOptions<
|
19
|
+
constructor(options?: CORSOptions<T>);
|
20
|
+
init(options: StandardHandlerOptions<T>): void;
|
22
21
|
}
|
23
22
|
|
24
23
|
interface ResponseHeadersPluginContext {
|
25
24
|
resHeaders?: Headers;
|
26
25
|
}
|
27
|
-
declare class ResponseHeadersPlugin<
|
28
|
-
init(options: StandardHandlerOptions<
|
26
|
+
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
27
|
+
init(options: StandardHandlerOptions<T>): void;
|
29
28
|
}
|
30
29
|
|
31
|
-
export { type CORSOptions, CORSPlugin,
|
30
|
+
export { type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,31 +1,30 @@
|
|
1
|
-
import {
|
2
|
-
export { C as CompositePlugin } from '../shared/server.B-ewprcf.js';
|
1
|
+
import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.23VRZIfj.js';
|
3
2
|
import { Value } from '@orpc/shared';
|
4
|
-
import { C as Context } from '../shared/server.
|
3
|
+
import { C as Context } from '../shared/server.MZvbGc3n.js';
|
5
4
|
import '@orpc/contract';
|
6
5
|
import '@orpc/standard-server';
|
7
6
|
import '@orpc/client';
|
8
7
|
|
9
|
-
interface CORSOptions<
|
10
|
-
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<
|
11
|
-
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<
|
12
|
-
allowMethods?: string[];
|
13
|
-
allowHeaders?: string[];
|
8
|
+
interface CORSOptions<T extends Context> {
|
9
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
10
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
11
|
+
allowMethods?: readonly string[];
|
12
|
+
allowHeaders?: readonly string[];
|
14
13
|
maxAge?: number;
|
15
14
|
credentials?: boolean;
|
16
|
-
exposeHeaders?: string[];
|
15
|
+
exposeHeaders?: readonly string[];
|
17
16
|
}
|
18
|
-
declare class CORSPlugin<
|
17
|
+
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
19
18
|
private readonly options;
|
20
|
-
constructor(options?:
|
21
|
-
init(options: StandardHandlerOptions<
|
19
|
+
constructor(options?: CORSOptions<T>);
|
20
|
+
init(options: StandardHandlerOptions<T>): void;
|
22
21
|
}
|
23
22
|
|
24
23
|
interface ResponseHeadersPluginContext {
|
25
24
|
resHeaders?: Headers;
|
26
25
|
}
|
27
|
-
declare class ResponseHeadersPlugin<
|
28
|
-
init(options: StandardHandlerOptions<
|
26
|
+
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
27
|
+
init(options: StandardHandlerOptions<T>): void;
|
29
28
|
}
|
30
29
|
|
31
|
-
export { type CORSOptions, CORSPlugin,
|
30
|
+
export { type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
package/dist/plugins/index.mjs
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
|
2
1
|
import { value } from '@orpc/shared';
|
3
2
|
|
4
3
|
class CORSPlugin {
|
5
4
|
options;
|
6
|
-
constructor(options) {
|
5
|
+
constructor(options = {}) {
|
7
6
|
const defaults = {
|
8
7
|
origin: (origin) => origin,
|
9
8
|
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
@@ -79,14 +78,19 @@ class ResponseHeadersPlugin {
|
|
79
78
|
init(options) {
|
80
79
|
options.rootInterceptors ??= [];
|
81
80
|
options.rootInterceptors.push(async (interceptorOptions) => {
|
82
|
-
const
|
83
|
-
|
84
|
-
|
81
|
+
const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
|
82
|
+
const result = await interceptorOptions.next({
|
83
|
+
...interceptorOptions,
|
84
|
+
context: {
|
85
|
+
...interceptorOptions.context,
|
86
|
+
resHeaders
|
87
|
+
}
|
88
|
+
});
|
85
89
|
if (!result.matched) {
|
86
90
|
return result;
|
87
91
|
}
|
88
92
|
const responseHeaders = result.response.headers;
|
89
|
-
for (const [key, value] of
|
93
|
+
for (const [key, value] of resHeaders) {
|
90
94
|
if (Array.isArray(responseHeaders[key])) {
|
91
95
|
responseHeaders[key].push(value);
|
92
96
|
} else if (responseHeaders[key] !== void 0) {
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import { HTTPPath,
|
2
|
-
import { Interceptor
|
1
|
+
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
+
import { Interceptor } from '@orpc/shared';
|
3
3
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
-
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.MZvbGc3n.js';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
8
8
|
type StandardMatchResult = {
|
9
|
-
path: string[];
|
9
|
+
path: readonly string[];
|
10
10
|
procedure: AnyProcedure;
|
11
11
|
params?: StandardParams;
|
12
12
|
} | undefined;
|
@@ -20,16 +20,10 @@ interface StandardCodec {
|
|
20
20
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
21
|
}
|
22
22
|
|
23
|
-
|
23
|
+
interface StandardHandleOptions<T extends Context> {
|
24
24
|
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
25
|
context: T;
|
29
|
-
}
|
30
|
-
type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
31
|
-
context: T;
|
32
|
-
};
|
26
|
+
}
|
33
27
|
type StandardHandleResult = {
|
34
28
|
matched: true;
|
35
29
|
response: StandardResponse;
|
@@ -37,11 +31,14 @@ type StandardHandleResult = {
|
|
37
31
|
matched: false;
|
38
32
|
response: undefined;
|
39
33
|
};
|
40
|
-
|
34
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
35
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
36
|
+
}
|
37
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
41
38
|
request: StandardLazyRequest;
|
42
|
-
}
|
39
|
+
}
|
43
40
|
interface StandardHandlerOptions<TContext extends Context> {
|
44
|
-
plugins?:
|
41
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
45
42
|
/**
|
46
43
|
* Interceptors at the request level, helpful when you want catch errors
|
47
44
|
*/
|
@@ -54,24 +51,16 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
54
51
|
*
|
55
52
|
* Interceptors for procedure client.
|
56
53
|
*/
|
57
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext,
|
54
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
58
55
|
}
|
59
56
|
declare class StandardHandler<T extends Context> {
|
60
57
|
private readonly matcher;
|
61
58
|
private readonly codec;
|
62
|
-
private readonly
|
63
|
-
private readonly
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
interface Plugin<TContext extends Context> {
|
69
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
70
|
-
}
|
71
|
-
declare class CompositePlugin<TContext extends Context> implements Plugin<TContext> {
|
72
|
-
private readonly plugins;
|
73
|
-
constructor(plugins?: Plugin<TContext>[]);
|
74
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
59
|
+
private readonly interceptors;
|
60
|
+
private readonly clientInterceptors;
|
61
|
+
private readonly rootInterceptors;
|
62
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
75
64
|
}
|
76
65
|
|
77
|
-
export {
|
66
|
+
export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
3
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.DnR6v9pj.mjs';
|
4
|
+
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
6
|
+
import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
|
7
|
+
|
8
|
+
class BodyLimitPlugin {
|
9
|
+
maxBodySize;
|
10
|
+
constructor(options) {
|
11
|
+
this.maxBodySize = options.maxBodySize;
|
12
|
+
}
|
13
|
+
initRuntimeAdapter(options) {
|
14
|
+
options.adapterInterceptors ??= [];
|
15
|
+
options.adapterInterceptors.push(async (options2) => {
|
16
|
+
if (!options2.request.body) {
|
17
|
+
return options2.next();
|
18
|
+
}
|
19
|
+
let currentBodySize = 0;
|
20
|
+
const rawReader = options2.request.body.getReader();
|
21
|
+
const reader = new ReadableStream({
|
22
|
+
start: async (controller) => {
|
23
|
+
try {
|
24
|
+
if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
|
25
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
while (true) {
|
29
|
+
const { done, value } = await rawReader.read();
|
30
|
+
if (done) {
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
currentBodySize += value.length;
|
34
|
+
if (currentBodySize > this.maxBodySize) {
|
35
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
controller.enqueue(value);
|
39
|
+
}
|
40
|
+
} finally {
|
41
|
+
controller.close();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
});
|
45
|
+
const requestInit = { body: reader, duplex: "half" };
|
46
|
+
return options2.next({
|
47
|
+
...options2,
|
48
|
+
request: new Request(options2.request, requestInit)
|
49
|
+
});
|
50
|
+
});
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
class FetchHandler {
|
55
|
+
constructor(standardHandler, options = {}) {
|
56
|
+
this.standardHandler = standardHandler;
|
57
|
+
for (const plugin of toArray(options.plugins)) {
|
58
|
+
plugin.initRuntimeAdapter?.(options);
|
59
|
+
}
|
60
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
61
|
+
this.toFetchResponseOptions = options;
|
62
|
+
}
|
63
|
+
toFetchResponseOptions;
|
64
|
+
adapterInterceptors;
|
65
|
+
async handle(request, ...rest) {
|
66
|
+
return intercept(
|
67
|
+
this.adapterInterceptors,
|
68
|
+
{
|
69
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
70
|
+
request,
|
71
|
+
toFetchResponseOptions: this.toFetchResponseOptions
|
72
|
+
},
|
73
|
+
async ({ request: request2, toFetchResponseOptions, ...options }) => {
|
74
|
+
const standardRequest = toStandardLazyRequest(request2);
|
75
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
76
|
+
if (!result.matched) {
|
77
|
+
return result;
|
78
|
+
}
|
79
|
+
return {
|
80
|
+
matched: true,
|
81
|
+
response: toFetchResponse(result.response, toFetchResponseOptions)
|
82
|
+
};
|
83
|
+
}
|
84
|
+
);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
class RPCHandler extends FetchHandler {
|
89
|
+
constructor(router, options = {}) {
|
90
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
91
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
92
|
+
const matcher = new StandardRPCMatcher();
|
93
|
+
const codec = new StandardRPCCodec(serializer);
|
94
|
+
super(new StandardHandler(router, matcher, codec, options), options);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
export { BodyLimitPlugin as B, FetchHandler as F, RPCHandler as R };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { C as Context } from './server.MZvbGc3n.js';
|
2
|
+
import { S as StandardHandleOptions } from './server.23VRZIfj.js';
|
3
|
+
|
4
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
5
|
+
context?: T;
|
6
|
+
} : {
|
7
|
+
context: T;
|
8
|
+
});
|
9
|
+
|
10
|
+
export type { FriendlyStandardHandleOptions as F };
|