@orpc/server 0.0.0-next.6d75718 → 0.0.0-next.6f0af5e
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 +1 -0
- package/dist/adapters/fetch/index.d.mts +27 -10
- package/dist/adapters/fetch/index.d.ts +27 -10
- package/dist/adapters/fetch/index.mjs +104 -8
- package/dist/adapters/node/index.d.mts +31 -14
- package/dist/adapters/node/index.d.ts +31 -14
- package/dist/adapters/node/index.mjs +53 -16
- package/dist/adapters/standard/index.d.mts +6 -6
- package/dist/adapters/standard/index.d.ts +6 -6
- package/dist/adapters/standard/index.mjs +6 -3
- package/dist/index.d.mts +51 -36
- package/dist/index.d.ts +51 -36
- package/dist/index.mjs +32 -11
- package/dist/plugins/index.d.mts +101 -6
- package/dist/plugins/index.d.ts +101 -6
- package/dist/plugins/index.mjs +147 -2
- package/dist/shared/{server.DJqfB27m.d.mts → server.B1oIHH_j.d.mts} +19 -11
- package/dist/shared/{server.MZvbGc3n.d.mts → server.BVHsfJ99.d.mts} +10 -9
- package/dist/shared/{server.MZvbGc3n.d.ts → server.BVHsfJ99.d.ts} +10 -9
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.BuLPHTX1.d.mts +18 -0
- package/dist/shared/{server.BtxZnWJ9.mjs → server.C37gDhSZ.mjs} +19 -29
- package/dist/shared/{server.23VRZIfj.d.ts → server.CaWivVk3.d.ts} +19 -11
- package/dist/shared/{server.CVNC_Jz8.mjs → server.DFuJLDuo.mjs} +44 -11
- package/dist/shared/{server.BG5ftPWa.d.ts → server.DMhSfHk1.d.ts} +2 -2
- package/dist/shared/server.D_vpYits.d.ts +18 -0
- package/dist/shared/{server.C-CCcROC.d.mts → server.Dwnm6cSk.d.mts} +2 -2
- package/package.json +8 -22
- package/dist/adapters/hono/index.d.mts +0 -22
- package/dist/adapters/hono/index.d.ts +0 -22
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -29
- package/dist/adapters/next/index.d.ts +0 -29
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.CIbpOMZX.d.mts +0 -8
- package/dist/shared/server.CTt4UYhI.mjs +0 -51
- package/dist/shared/server.DCcCuA52.d.ts +0 -8
@@ -1,6 +1,6 @@
|
|
1
1
|
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
|
2
2
|
import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
|
3
|
-
import { value, intercept
|
3
|
+
import { value, intercept } from '@orpc/shared';
|
4
4
|
|
5
5
|
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
6
6
|
function lazy(loader, meta = {}) {
|
@@ -127,7 +127,7 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
127
127
|
);
|
128
128
|
} catch (e) {
|
129
129
|
if (!(e instanceof ORPCError)) {
|
130
|
-
throw
|
130
|
+
throw e;
|
131
131
|
}
|
132
132
|
const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
|
133
133
|
throw validated;
|
@@ -169,35 +169,29 @@ async function executeProcedureInternal(procedure, options) {
|
|
169
169
|
const middlewares = procedure["~orpc"].middlewares;
|
170
170
|
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
171
171
|
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
172
|
-
|
173
|
-
|
174
|
-
let currentInput = options.input;
|
175
|
-
const next = async (...[nextOptions]) => {
|
176
|
-
const index = currentIndex;
|
177
|
-
const midContext = nextOptions?.context ?? {};
|
178
|
-
currentIndex += 1;
|
179
|
-
currentContext = mergeCurrentContext(currentContext, midContext);
|
172
|
+
const next = async (index, context, input) => {
|
173
|
+
let currentInput = input;
|
180
174
|
if (index === inputValidationIndex) {
|
181
175
|
currentInput = await validateInput(procedure, currentInput);
|
182
176
|
}
|
183
177
|
const mid = middlewares[index];
|
184
|
-
const
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
178
|
+
const output = mid ? (await mid({
|
179
|
+
...options,
|
180
|
+
context,
|
181
|
+
next: async (...[nextOptions]) => {
|
182
|
+
const nextContext = nextOptions?.context ?? {};
|
183
|
+
return {
|
184
|
+
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
|
185
|
+
context: nextContext
|
186
|
+
};
|
187
|
+
}
|
188
|
+
}, currentInput, middlewareOutputFn)).output : await procedure["~orpc"].handler({ ...options, context, input: currentInput });
|
191
189
|
if (index === outputValidationIndex) {
|
192
|
-
|
193
|
-
return {
|
194
|
-
context: result.context,
|
195
|
-
output: validatedOutput
|
196
|
-
};
|
190
|
+
return await validateOutput(procedure, output);
|
197
191
|
}
|
198
|
-
return
|
192
|
+
return output;
|
199
193
|
};
|
200
|
-
return (
|
194
|
+
return next(0, options.context, options.input);
|
201
195
|
}
|
202
196
|
|
203
197
|
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
@@ -367,8 +361,4 @@ function call(procedure, input, ...rest) {
|
|
367
361
|
return createProcedureClient(procedure, ...rest)(input);
|
368
362
|
}
|
369
363
|
|
370
|
-
|
371
|
-
return `/${path.map(encodeURIComponent).join("/")}`;
|
372
|
-
}
|
373
|
-
|
374
|
-
export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i, createORPCErrorConstructorMap as j, getLazyMeta as k, lazy as l, mergeCurrentContext as m, middlewareOutputFn as n, isStartWithMiddlewares as o, mergeMiddlewares as p, call as q, getHiddenRouterContract as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, createAccessibleLazyRouter as w, resolveContractProcedures as x, unlazyRouter as y };
|
364
|
+
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 };
|
@@ -1,8 +1,18 @@
|
|
1
|
-
import { HTTPPath,
|
2
|
-
import {
|
1
|
+
import { HTTPPath, ORPCError } from '@orpc/client';
|
2
|
+
import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
|
3
|
+
import { Interceptor, ThrowableError } from '@orpc/shared';
|
3
4
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
-
import {
|
5
|
-
|
5
|
+
import { C as Context, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions, R as Router } from './server.BVHsfJ99.js';
|
6
|
+
|
7
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
8
|
+
order?: number;
|
9
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
10
|
+
}
|
11
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
12
|
+
protected readonly plugins: TPlugin[];
|
13
|
+
constructor(plugins?: readonly TPlugin[]);
|
14
|
+
init(options: StandardHandlerOptions<T>): void;
|
15
|
+
}
|
6
16
|
|
7
17
|
type StandardParams = Record<string, string>;
|
8
18
|
type StandardMatchResult = {
|
@@ -31,9 +41,6 @@ type StandardHandleResult = {
|
|
31
41
|
matched: false;
|
32
42
|
response: undefined;
|
33
43
|
};
|
34
|
-
interface StandardHandlerPlugin<TContext extends Context> {
|
35
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
36
|
-
}
|
37
44
|
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
38
45
|
request: StandardLazyRequest;
|
39
46
|
}
|
@@ -42,16 +49,16 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
42
49
|
/**
|
43
50
|
* Interceptors at the request level, helpful when you want catch errors
|
44
51
|
*/
|
45
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult,
|
52
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
46
53
|
/**
|
47
54
|
* Interceptors at the root level, helpful when you want override the request/response
|
48
55
|
*/
|
49
|
-
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult,
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
50
57
|
/**
|
51
58
|
*
|
52
59
|
* Interceptors for procedure client.
|
53
60
|
*/
|
54
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext,
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
55
62
|
}
|
56
63
|
declare class StandardHandler<T extends Context> {
|
57
64
|
private readonly matcher;
|
@@ -63,4 +70,5 @@ declare class StandardHandler<T extends Context> {
|
|
63
70
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
64
71
|
}
|
65
72
|
|
66
|
-
export {
|
73
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as i };
|
74
|
+
export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardCodec as c, StandardParams as d, StandardMatcher as e, StandardMatchResult as f, StandardHandleOptions as g, StandardHandleResult as h };
|
@@ -1,14 +1,28 @@
|
|
1
|
+
import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
|
+
import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
|
3
|
+
import '@orpc/standard-server/batch';
|
1
4
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
import { c as createProcedureClient, t as traverseContractProcedures,
|
5
|
+
import { S as StrictGetMethodPlugin } from './server.BW-nUGgA.mjs';
|
6
|
+
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.C37gDhSZ.mjs';
|
7
|
+
|
8
|
+
class CompositeStandardHandlerPlugin {
|
9
|
+
plugins;
|
10
|
+
constructor(plugins = []) {
|
11
|
+
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
12
|
+
}
|
13
|
+
init(options) {
|
14
|
+
for (const plugin of this.plugins) {
|
15
|
+
plugin.init?.(options);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
4
19
|
|
5
20
|
class StandardHandler {
|
6
21
|
constructor(router, matcher, codec, options) {
|
7
22
|
this.matcher = matcher;
|
8
23
|
this.codec = codec;
|
9
|
-
|
10
|
-
|
11
|
-
}
|
24
|
+
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
|
25
|
+
plugins.init(options);
|
12
26
|
this.interceptors = toArray(options.interceptors);
|
13
27
|
this.clientInterceptors = toArray(options.clientInterceptors);
|
14
28
|
this.rootInterceptors = toArray(options.rootInterceptors);
|
@@ -17,21 +31,25 @@ class StandardHandler {
|
|
17
31
|
interceptors;
|
18
32
|
clientInterceptors;
|
19
33
|
rootInterceptors;
|
20
|
-
handle(request, options) {
|
34
|
+
async handle(request, options) {
|
35
|
+
const prefix = options.prefix?.replace(/\/$/, "") || void 0;
|
36
|
+
if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
|
37
|
+
return { matched: false, response: void 0 };
|
38
|
+
}
|
21
39
|
return intercept(
|
22
40
|
this.rootInterceptors,
|
23
|
-
{ ...options, request },
|
41
|
+
{ ...options, request, prefix },
|
24
42
|
async (interceptorOptions) => {
|
25
43
|
let isDecoding = false;
|
26
44
|
try {
|
27
45
|
return await intercept(
|
28
46
|
this.interceptors,
|
29
47
|
interceptorOptions,
|
30
|
-
async ({ request: request2, context, prefix }) => {
|
48
|
+
async ({ request: request2, context, prefix: prefix2 }) => {
|
31
49
|
const method = request2.method;
|
32
50
|
const url = request2.url;
|
33
|
-
const pathname =
|
34
|
-
const match = await this.matcher.match(method, pathname);
|
51
|
+
const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
|
52
|
+
const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
|
35
53
|
if (!match) {
|
36
54
|
return { matched: false, response: void 0 };
|
37
55
|
}
|
@@ -154,4 +172,19 @@ class StandardRPCMatcher {
|
|
154
172
|
}
|
155
173
|
}
|
156
174
|
|
157
|
-
|
175
|
+
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
|
+
}
|
182
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
183
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
184
|
+
const matcher = new StandardRPCMatcher();
|
185
|
+
const codec = new StandardRPCCodec(serializer);
|
186
|
+
super(router, matcher, codec, options);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardRPCCodec as a, StandardRPCHandler as b, StandardRPCMatcher as c };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { C as Context } from './server.
|
2
|
-
import {
|
1
|
+
import { C as Context } from './server.BVHsfJ99.js';
|
2
|
+
import { g as StandardHandleOptions } from './server.CaWivVk3.js';
|
3
3
|
|
4
4
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
5
5
|
context?: T;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context, R as Router } from './server.BVHsfJ99.js';
|
3
|
+
import { b as StandardHandlerOptions, i as StandardHandler } from './server.CaWivVk3.js';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
/**
|
7
|
+
* Enables or disables the StrictGetMethodPlugin.
|
8
|
+
*
|
9
|
+
* @default true
|
10
|
+
*/
|
11
|
+
strictGetMethodPluginEnabled?: boolean;
|
12
|
+
}
|
13
|
+
declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
|
14
|
+
constructor(router: Router<any, T>, options: StandardRPCHandlerOptions<T>);
|
15
|
+
}
|
16
|
+
|
17
|
+
export { StandardRPCHandler as a };
|
18
|
+
export type { StandardRPCHandlerOptions as S };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { C as Context } from './server.
|
2
|
-
import {
|
1
|
+
import { C as Context } from './server.BVHsfJ99.mjs';
|
2
|
+
import { g as StandardHandleOptions } from './server.B1oIHH_j.mjs';
|
3
3
|
|
4
4
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
5
5
|
context?: T;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.6f0af5e",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -34,16 +34,6 @@
|
|
34
34
|
"import": "./dist/adapters/fetch/index.mjs",
|
35
35
|
"default": "./dist/adapters/fetch/index.mjs"
|
36
36
|
},
|
37
|
-
"./hono": {
|
38
|
-
"types": "./dist/adapters/hono/index.d.mts",
|
39
|
-
"import": "./dist/adapters/hono/index.mjs",
|
40
|
-
"default": "./dist/adapters/hono/index.mjs"
|
41
|
-
},
|
42
|
-
"./next": {
|
43
|
-
"types": "./dist/adapters/next/index.d.mts",
|
44
|
-
"import": "./dist/adapters/next/index.mjs",
|
45
|
-
"default": "./dist/adapters/next/index.mjs"
|
46
|
-
},
|
47
37
|
"./node": {
|
48
38
|
"types": "./dist/adapters/node/index.d.mts",
|
49
39
|
"import": "./dist/adapters/node/index.mjs",
|
@@ -53,20 +43,16 @@
|
|
53
43
|
"files": [
|
54
44
|
"dist"
|
55
45
|
],
|
56
|
-
"peerDependencies": {
|
57
|
-
"hono": ">=4.6.0",
|
58
|
-
"next": ">=14.0.0"
|
59
|
-
},
|
60
46
|
"dependencies": {
|
61
|
-
"@orpc/client": "0.0.0-next.
|
62
|
-
"@orpc/
|
63
|
-
"@orpc/
|
64
|
-
"@orpc/standard-server": "0.0.0-next.
|
65
|
-
"@orpc/standard-server-
|
66
|
-
"@orpc/
|
47
|
+
"@orpc/client": "0.0.0-next.6f0af5e",
|
48
|
+
"@orpc/contract": "0.0.0-next.6f0af5e",
|
49
|
+
"@orpc/standard-server": "0.0.0-next.6f0af5e",
|
50
|
+
"@orpc/standard-server-fetch": "0.0.0-next.6f0af5e",
|
51
|
+
"@orpc/standard-server-node": "0.0.0-next.6f0af5e",
|
52
|
+
"@orpc/shared": "0.0.0-next.6f0af5e"
|
67
53
|
},
|
68
54
|
"devDependencies": {
|
69
|
-
"supertest": "^7.
|
55
|
+
"supertest": "^7.1.0"
|
70
56
|
},
|
71
57
|
"scripts": {
|
72
58
|
"build": "unbuild",
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
-
export { FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
|
3
|
-
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
import { Context as Context$1, MiddlewareHandler } from 'hono';
|
5
|
-
import { C as Context } from '../../shared/server.MZvbGc3n.mjs';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.DJqfB27m.mjs';
|
7
|
-
import '../../shared/server.C-CCcROC.mjs';
|
8
|
-
import '@orpc/standard-server-fetch';
|
9
|
-
import '../../shared/server.CIbpOMZX.mjs';
|
10
|
-
import '@orpc/client/standard';
|
11
|
-
import '@orpc/client';
|
12
|
-
import '@orpc/contract';
|
13
|
-
import '@orpc/standard-server';
|
14
|
-
|
15
|
-
type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
16
|
-
context?: Value<T, [Context$1]>;
|
17
|
-
} : {
|
18
|
-
context: Value<T, [Context$1]>;
|
19
|
-
});
|
20
|
-
declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
21
|
-
|
22
|
-
export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { FetchHandler } from '../fetch/index.js';
|
2
|
-
export { FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
|
3
|
-
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
import { Context as Context$1, MiddlewareHandler } from 'hono';
|
5
|
-
import { C as Context } from '../../shared/server.MZvbGc3n.js';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.23VRZIfj.js';
|
7
|
-
import '../../shared/server.BG5ftPWa.js';
|
8
|
-
import '@orpc/standard-server-fetch';
|
9
|
-
import '../../shared/server.DCcCuA52.js';
|
10
|
-
import '@orpc/client/standard';
|
11
|
-
import '@orpc/client';
|
12
|
-
import '@orpc/contract';
|
13
|
-
import '@orpc/standard-server';
|
14
|
-
|
15
|
-
type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
16
|
-
context?: Value<T, [Context$1]>;
|
17
|
-
} : {
|
18
|
-
context: Value<T, [Context$1]>;
|
19
|
-
});
|
20
|
-
declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
21
|
-
|
22
|
-
export { type CreateMiddlewareOptions, FetchHandler, createMiddleware };
|
@@ -1,32 +0,0 @@
|
|
1
|
-
export { F as FetchHandler, R as RPCHandler } from '../../shared/server.CTt4UYhI.mjs';
|
2
|
-
import { value } from '@orpc/shared';
|
3
|
-
import '@orpc/client/standard';
|
4
|
-
import '../../shared/server.CVNC_Jz8.mjs';
|
5
|
-
import '@orpc/client';
|
6
|
-
import '../../shared/server.BtxZnWJ9.mjs';
|
7
|
-
import '@orpc/contract';
|
8
|
-
import '@orpc/standard-server-fetch';
|
9
|
-
import '../../shared/server.BVwwTHyO.mjs';
|
10
|
-
|
11
|
-
function createMiddleware(handler, ...[options]) {
|
12
|
-
return async (c, next) => {
|
13
|
-
const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
|
14
|
-
const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
|
15
|
-
// https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
|
16
|
-
get(target, prop) {
|
17
|
-
if (bodyProps.has(prop)) {
|
18
|
-
return () => c.req[prop]();
|
19
|
-
}
|
20
|
-
return Reflect.get(target, prop, target);
|
21
|
-
}
|
22
|
-
});
|
23
|
-
const context = await value(options?.context ?? {}, c);
|
24
|
-
const { matched, response } = await handler.handle(request, { ...options, context });
|
25
|
-
if (matched) {
|
26
|
-
return c.newResponse(response.body, response);
|
27
|
-
}
|
28
|
-
await next();
|
29
|
-
};
|
30
|
-
}
|
31
|
-
|
32
|
-
export { createMiddleware };
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
-
export { FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
|
3
|
-
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
import { NextRequest } from 'next/server';
|
5
|
-
import { C as Context } from '../../shared/server.MZvbGc3n.mjs';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.DJqfB27m.mjs';
|
7
|
-
import '../../shared/server.C-CCcROC.mjs';
|
8
|
-
import '@orpc/standard-server-fetch';
|
9
|
-
import '../../shared/server.CIbpOMZX.mjs';
|
10
|
-
import '@orpc/client/standard';
|
11
|
-
import '@orpc/client';
|
12
|
-
import '@orpc/contract';
|
13
|
-
import '@orpc/standard-server';
|
14
|
-
|
15
|
-
type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
16
|
-
context?: Value<T, [NextRequest]>;
|
17
|
-
} : {
|
18
|
-
context: Value<T, [NextRequest]>;
|
19
|
-
});
|
20
|
-
interface ServeResult {
|
21
|
-
GET(req: NextRequest): Promise<Response>;
|
22
|
-
POST(req: NextRequest): Promise<Response>;
|
23
|
-
PUT(req: NextRequest): Promise<Response>;
|
24
|
-
PATCH(req: NextRequest): Promise<Response>;
|
25
|
-
DELETE(req: NextRequest): Promise<Response>;
|
26
|
-
}
|
27
|
-
declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
28
|
-
|
29
|
-
export { FetchHandler, type ServeOptions, type ServeResult, serve };
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { FetchHandler } from '../fetch/index.js';
|
2
|
-
export { FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
|
3
|
-
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
import { NextRequest } from 'next/server';
|
5
|
-
import { C as Context } from '../../shared/server.MZvbGc3n.js';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.23VRZIfj.js';
|
7
|
-
import '../../shared/server.BG5ftPWa.js';
|
8
|
-
import '@orpc/standard-server-fetch';
|
9
|
-
import '../../shared/server.DCcCuA52.js';
|
10
|
-
import '@orpc/client/standard';
|
11
|
-
import '@orpc/client';
|
12
|
-
import '@orpc/contract';
|
13
|
-
import '@orpc/standard-server';
|
14
|
-
|
15
|
-
type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
16
|
-
context?: Value<T, [NextRequest]>;
|
17
|
-
} : {
|
18
|
-
context: Value<T, [NextRequest]>;
|
19
|
-
});
|
20
|
-
interface ServeResult {
|
21
|
-
GET(req: NextRequest): Promise<Response>;
|
22
|
-
POST(req: NextRequest): Promise<Response>;
|
23
|
-
PUT(req: NextRequest): Promise<Response>;
|
24
|
-
PATCH(req: NextRequest): Promise<Response>;
|
25
|
-
DELETE(req: NextRequest): Promise<Response>;
|
26
|
-
}
|
27
|
-
declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
28
|
-
|
29
|
-
export { FetchHandler, type ServeOptions, type ServeResult, serve };
|
@@ -1,29 +0,0 @@
|
|
1
|
-
export { F as FetchHandler, R as RPCHandler } from '../../shared/server.CTt4UYhI.mjs';
|
2
|
-
import { value } from '@orpc/shared';
|
3
|
-
import '@orpc/client/standard';
|
4
|
-
import '../../shared/server.CVNC_Jz8.mjs';
|
5
|
-
import '@orpc/client';
|
6
|
-
import '../../shared/server.BtxZnWJ9.mjs';
|
7
|
-
import '@orpc/contract';
|
8
|
-
import '@orpc/standard-server-fetch';
|
9
|
-
import '../../shared/server.BVwwTHyO.mjs';
|
10
|
-
|
11
|
-
function serve(handler, ...[options]) {
|
12
|
-
const main = async (req) => {
|
13
|
-
const context = await value(options?.context ?? {}, req);
|
14
|
-
const { matched, response } = await handler.handle(req, { ...options, context });
|
15
|
-
if (matched) {
|
16
|
-
return response;
|
17
|
-
}
|
18
|
-
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
19
|
-
};
|
20
|
-
return {
|
21
|
-
GET: main,
|
22
|
-
POST: main,
|
23
|
-
PUT: main,
|
24
|
-
PATCH: main,
|
25
|
-
DELETE: main
|
26
|
-
};
|
27
|
-
}
|
28
|
-
|
29
|
-
export { serve };
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
-
import { C as Context } from './server.MZvbGc3n.mjs';
|
3
|
-
import { a as StandardHandlerOptions } from './server.DJqfB27m.mjs';
|
4
|
-
|
5
|
-
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
-
}
|
7
|
-
|
8
|
-
export type { StandardRPCHandlerOptions as S };
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
|
-
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.CVNC_Jz8.mjs';
|
3
|
-
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
5
|
-
import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
|
6
|
-
|
7
|
-
class FetchHandler {
|
8
|
-
constructor(standardHandler, options = {}) {
|
9
|
-
this.standardHandler = standardHandler;
|
10
|
-
for (const plugin of toArray(options.plugins)) {
|
11
|
-
plugin.initRuntimeAdapter?.(options);
|
12
|
-
}
|
13
|
-
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
14
|
-
this.toFetchResponseOptions = options;
|
15
|
-
}
|
16
|
-
toFetchResponseOptions;
|
17
|
-
adapterInterceptors;
|
18
|
-
async handle(request, ...rest) {
|
19
|
-
return intercept(
|
20
|
-
this.adapterInterceptors,
|
21
|
-
{
|
22
|
-
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
23
|
-
request,
|
24
|
-
toFetchResponseOptions: this.toFetchResponseOptions
|
25
|
-
},
|
26
|
-
async ({ request: request2, toFetchResponseOptions, ...options }) => {
|
27
|
-
const standardRequest = toStandardLazyRequest(request2);
|
28
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
29
|
-
if (!result.matched) {
|
30
|
-
return result;
|
31
|
-
}
|
32
|
-
return {
|
33
|
-
matched: true,
|
34
|
-
response: toFetchResponse(result.response, toFetchResponseOptions)
|
35
|
-
};
|
36
|
-
}
|
37
|
-
);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
class RPCHandler extends FetchHandler {
|
42
|
-
constructor(router, options = {}) {
|
43
|
-
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
44
|
-
const serializer = new StandardRPCSerializer(jsonSerializer);
|
45
|
-
const matcher = new StandardRPCMatcher();
|
46
|
-
const codec = new StandardRPCCodec(serializer);
|
47
|
-
super(new StandardHandler(router, matcher, codec, options), options);
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
export { FetchHandler as F, RPCHandler as R };
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
-
import { C as Context } from './server.MZvbGc3n.js';
|
3
|
-
import { a as StandardHandlerOptions } from './server.23VRZIfj.js';
|
4
|
-
|
5
|
-
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
-
}
|
7
|
-
|
8
|
-
export type { StandardRPCHandlerOptions as S };
|