@orpc/server 0.0.0-next.783ae4e → 0.0.0-next.7844b89
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 +26 -26
- 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 +45 -0
- package/dist/adapters/fastify/index.d.mts +53 -0
- package/dist/adapters/fastify/index.d.ts +53 -0
- package/dist/adapters/fastify/index.mjs +54 -0
- package/dist/adapters/fetch/index.d.mts +80 -10
- package/dist/adapters/fetch/index.d.ts +80 -10
- package/dist/adapters/fetch/index.mjs +179 -8
- package/dist/adapters/message-port/index.d.mts +57 -0
- package/dist/adapters/message-port/index.d.ts +57 -0
- package/dist/adapters/message-port/index.mjs +55 -0
- package/dist/adapters/node/index.d.mts +58 -12
- package/dist/adapters/node/index.d.ts +58 -12
- package/dist/adapters/node/index.mjs +89 -22
- package/dist/adapters/standard/index.d.mts +8 -13
- package/dist/adapters/standard/index.d.ts +8 -13
- package/dist/adapters/standard/index.mjs +5 -3
- package/dist/adapters/standard-peer/index.d.mts +18 -0
- package/dist/adapters/standard-peer/index.d.ts +18 -0
- package/dist/adapters/standard-peer/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +56 -0
- package/dist/adapters/websocket/index.d.ts +56 -0
- package/dist/adapters/websocket/index.mjs +67 -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 +37 -0
- package/dist/helpers/index.d.mts +149 -0
- package/dist/helpers/index.d.ts +149 -0
- package/dist/helpers/index.mjs +198 -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 +584 -72
- package/dist/index.d.ts +584 -72
- package/dist/index.mjs +143 -14
- package/dist/plugins/index.d.mts +151 -9
- package/dist/plugins/index.d.ts +151 -9
- package/dist/plugins/index.mjs +191 -11
- package/dist/shared/{server.DHBkTokD.d.mts → server.7cEtMB30.d.ts} +17 -9
- package/dist/shared/server.B8gYOD5g.d.mts +12 -0
- package/dist/shared/{server.DNoBYd3E.d.ts → server.BqadksTP.d.mts} +17 -9
- package/dist/shared/server.Bxx6tqNe.mjs +219 -0
- package/dist/shared/server.C8_sRzQB.d.mts +42 -0
- package/dist/shared/server.ChUyt5-i.d.mts +32 -0
- package/dist/shared/server.ChyoA9XY.d.ts +42 -0
- package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
- package/dist/shared/{server.CjWkNG6l.mjs → server.Ds4HPpvH.mjs} +125 -86
- package/dist/shared/server.EfTOZ2Q7.d.ts +12 -0
- package/dist/shared/server.TEVCLCFC.mjs +39 -0
- package/dist/shared/server.UVMTOWrk.mjs +26 -0
- package/dist/shared/{server.CYBq7eu_.d.mts → server.qKsRrdxW.d.mts} +61 -11
- package/dist/shared/{server.CYBq7eu_.d.ts → server.qKsRrdxW.d.ts} +61 -11
- package/dist/shared/server.yoEB3Fx4.d.ts +32 -0
- package/package.json +81 -21
- 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.B0kTII1X.d.ts +0 -10
- package/dist/shared/server.CBh2jYIX.d.mts +0 -10
- package/dist/shared/server.D9QduY95.mjs +0 -161
- package/dist/shared/server.DatI0acO.d.mts +0 -8
- package/dist/shared/server.Et1O6Bm7.mjs +0 -98
- package/dist/shared/server.uEHRR3Pg.d.ts +0 -8
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ORPCError, fallbackContractConfig } from '@orpc/contract';
|
|
2
|
+
|
|
3
|
+
const STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL = Symbol("STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT");
|
|
4
|
+
class StrictGetMethodPlugin {
|
|
5
|
+
error;
|
|
6
|
+
/**
|
|
7
|
+
* make sure execute before batch plugin to get real method
|
|
8
|
+
*/
|
|
9
|
+
order = 7e6;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.error = options.error ?? new ORPCError("METHOD_NOT_SUPPORTED");
|
|
12
|
+
}
|
|
13
|
+
init(options) {
|
|
14
|
+
options.rootInterceptors ??= [];
|
|
15
|
+
options.clientInterceptors ??= [];
|
|
16
|
+
options.rootInterceptors.unshift((options2) => {
|
|
17
|
+
const isGetMethod = options2.request.method === "GET";
|
|
18
|
+
return options2.next({
|
|
19
|
+
...options2,
|
|
20
|
+
context: {
|
|
21
|
+
...options2.context,
|
|
22
|
+
[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL]: isGetMethod
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
options.clientInterceptors.unshift((options2) => {
|
|
27
|
+
if (typeof options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] !== "boolean") {
|
|
28
|
+
throw new TypeError("[StrictGetMethodPlugin] strict GET method context has been corrupted or modified by another plugin or interceptor");
|
|
29
|
+
}
|
|
30
|
+
const procedureMethod = fallbackContractConfig("defaultMethod", options2.procedure["~orpc"].route.method);
|
|
31
|
+
if (options2.context[STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL] && procedureMethod !== "GET") {
|
|
32
|
+
throw this.error;
|
|
33
|
+
}
|
|
34
|
+
return options2.next();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { StrictGetMethodPlugin as S };
|
|
@@ -0,0 +1,26 @@
|
|
|
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 handle = createServerPeerHandleRequestFn(handler, options);
|
|
14
|
+
await peer.response(id, await handle(request));
|
|
15
|
+
}
|
|
16
|
+
function createServerPeerHandleRequestFn(handler, options) {
|
|
17
|
+
return async (request) => {
|
|
18
|
+
const { response } = await handler.handle(
|
|
19
|
+
{ ...request, body: () => Promise.resolve(request.body) },
|
|
20
|
+
resolveFriendlyStandardHandleOptions(options)
|
|
21
|
+
);
|
|
22
|
+
return response ?? { status: 404, headers: {}, body: "No procedure matched" };
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { createServerPeerHandleRequestFn as c, handleStandardServerPeerMessage as h };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
|
|
2
|
-
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
|
3
2
|
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
|
3
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, Value } from '@orpc/shared';
|
|
4
4
|
|
|
5
|
-
type Context = Record<
|
|
5
|
+
type Context = Record<PropertyKey, any>;
|
|
6
6
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
|
7
7
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
|
8
8
|
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
|
@@ -13,7 +13,6 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
|
13
13
|
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
|
14
14
|
};
|
|
15
15
|
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
|
16
|
-
declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
|
17
16
|
|
|
18
17
|
declare const LAZY_SYMBOL: unique symbol;
|
|
19
18
|
interface LazyMeta {
|
|
@@ -28,6 +27,11 @@ interface Lazy<T> {
|
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
29
|
type Lazyable<T> = T | Lazy<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a lazy-loaded item.
|
|
32
|
+
*
|
|
33
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
|
|
34
|
+
*/
|
|
31
35
|
declare function lazy<T>(loader: () => Promise<{
|
|
32
36
|
default: T;
|
|
33
37
|
}>, meta?: LazyMeta): Lazy<T>;
|
|
@@ -56,7 +60,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
|
|
|
56
60
|
outputValidationIndex: number;
|
|
57
61
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
|
58
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* This class represents a procedure.
|
|
65
|
+
*
|
|
66
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
67
|
+
*/
|
|
59
68
|
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
69
|
+
/**
|
|
70
|
+
* This property holds the defined options.
|
|
71
|
+
*/
|
|
60
72
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
61
73
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
62
74
|
}
|
|
@@ -87,6 +99,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
|
|
|
87
99
|
next: MiddlewareNextFn<TOutput>;
|
|
88
100
|
errors: TErrorConstructorMap;
|
|
89
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* A function that represents a middleware.
|
|
104
|
+
*
|
|
105
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
106
|
+
*/
|
|
90
107
|
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
91
108
|
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
92
109
|
}
|
|
@@ -106,38 +123,71 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TEr
|
|
|
106
123
|
signal?: AbortSignal;
|
|
107
124
|
lastEventId: string | undefined;
|
|
108
125
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Options for creating a procedure caller with comprehensive type safety
|
|
111
|
-
*/
|
|
112
126
|
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
|
113
127
|
/**
|
|
114
128
|
* This is helpful for logging and analytics.
|
|
115
129
|
*/
|
|
116
130
|
path?: readonly string[];
|
|
117
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap
|
|
131
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
|
118
132
|
} & (Record<never, never> extends TInitialContext ? {
|
|
119
|
-
context?: Value<TInitialContext
|
|
133
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
120
134
|
} : {
|
|
121
|
-
context: Value<TInitialContext
|
|
135
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
122
136
|
});
|
|
123
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Create Server-side client from a procedure.
|
|
139
|
+
*
|
|
140
|
+
* @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
|
|
141
|
+
*/
|
|
142
|
+
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
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Represents a router, which defines a hierarchical structure of procedures.
|
|
146
|
+
*
|
|
147
|
+
* @info A procedure is a router too.
|
|
148
|
+
* @see {@link https://orpc.dev/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
149
|
+
*/
|
|
125
150
|
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
151
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
|
127
152
|
};
|
|
128
153
|
type AnyRouter = Router<any, any>;
|
|
129
154
|
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
|
155
|
+
/**
|
|
156
|
+
* Infer all initial context of the router.
|
|
157
|
+
*
|
|
158
|
+
* @info A procedure is a router too.
|
|
159
|
+
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
160
|
+
*/
|
|
130
161
|
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
|
131
162
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
132
163
|
};
|
|
164
|
+
/**
|
|
165
|
+
* Infer all current context of the router.
|
|
166
|
+
*
|
|
167
|
+
* @info A procedure is a router too.
|
|
168
|
+
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
169
|
+
*/
|
|
133
170
|
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
|
134
171
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
|
135
172
|
};
|
|
173
|
+
/**
|
|
174
|
+
* Infer all router inputs
|
|
175
|
+
*
|
|
176
|
+
* @info A procedure is a router too.
|
|
177
|
+
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
178
|
+
*/
|
|
136
179
|
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
137
180
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
138
181
|
};
|
|
182
|
+
/**
|
|
183
|
+
* Infer all router outputs
|
|
184
|
+
*
|
|
185
|
+
* @info A procedure is a router too.
|
|
186
|
+
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
187
|
+
*/
|
|
139
188
|
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
140
189
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
141
190
|
};
|
|
142
191
|
|
|
143
|
-
export {
|
|
192
|
+
export { isProcedure as E, createProcedureClient as F, 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, middlewareOutputFn as z };
|
|
193
|
+
export type { AnyProcedure as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, 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 v, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
|
|
2
|
-
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
|
3
2
|
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
|
3
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, Value } from '@orpc/shared';
|
|
4
4
|
|
|
5
|
-
type Context = Record<
|
|
5
|
+
type Context = Record<PropertyKey, any>;
|
|
6
6
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
|
7
7
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
|
8
8
|
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
|
@@ -13,7 +13,6 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
|
13
13
|
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
|
14
14
|
};
|
|
15
15
|
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
|
16
|
-
declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
|
17
16
|
|
|
18
17
|
declare const LAZY_SYMBOL: unique symbol;
|
|
19
18
|
interface LazyMeta {
|
|
@@ -28,6 +27,11 @@ interface Lazy<T> {
|
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
29
|
type Lazyable<T> = T | Lazy<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a lazy-loaded item.
|
|
32
|
+
*
|
|
33
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
|
|
34
|
+
*/
|
|
31
35
|
declare function lazy<T>(loader: () => Promise<{
|
|
32
36
|
default: T;
|
|
33
37
|
}>, meta?: LazyMeta): Lazy<T>;
|
|
@@ -56,7 +60,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
|
|
|
56
60
|
outputValidationIndex: number;
|
|
57
61
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
|
58
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* This class represents a procedure.
|
|
65
|
+
*
|
|
66
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
67
|
+
*/
|
|
59
68
|
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
69
|
+
/**
|
|
70
|
+
* This property holds the defined options.
|
|
71
|
+
*/
|
|
60
72
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
61
73
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
62
74
|
}
|
|
@@ -87,6 +99,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
|
|
|
87
99
|
next: MiddlewareNextFn<TOutput>;
|
|
88
100
|
errors: TErrorConstructorMap;
|
|
89
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* A function that represents a middleware.
|
|
104
|
+
*
|
|
105
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
106
|
+
*/
|
|
90
107
|
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
91
108
|
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
92
109
|
}
|
|
@@ -106,38 +123,71 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TEr
|
|
|
106
123
|
signal?: AbortSignal;
|
|
107
124
|
lastEventId: string | undefined;
|
|
108
125
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Options for creating a procedure caller with comprehensive type safety
|
|
111
|
-
*/
|
|
112
126
|
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
|
113
127
|
/**
|
|
114
128
|
* This is helpful for logging and analytics.
|
|
115
129
|
*/
|
|
116
130
|
path?: readonly string[];
|
|
117
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap
|
|
131
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
|
118
132
|
} & (Record<never, never> extends TInitialContext ? {
|
|
119
|
-
context?: Value<TInitialContext
|
|
133
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
120
134
|
} : {
|
|
121
|
-
context: Value<TInitialContext
|
|
135
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
122
136
|
});
|
|
123
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Create Server-side client from a procedure.
|
|
139
|
+
*
|
|
140
|
+
* @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
|
|
141
|
+
*/
|
|
142
|
+
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
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Represents a router, which defines a hierarchical structure of procedures.
|
|
146
|
+
*
|
|
147
|
+
* @info A procedure is a router too.
|
|
148
|
+
* @see {@link https://orpc.dev/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
149
|
+
*/
|
|
125
150
|
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
151
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
|
127
152
|
};
|
|
128
153
|
type AnyRouter = Router<any, any>;
|
|
129
154
|
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
|
155
|
+
/**
|
|
156
|
+
* Infer all initial context of the router.
|
|
157
|
+
*
|
|
158
|
+
* @info A procedure is a router too.
|
|
159
|
+
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
160
|
+
*/
|
|
130
161
|
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
|
131
162
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
132
163
|
};
|
|
164
|
+
/**
|
|
165
|
+
* Infer all current context of the router.
|
|
166
|
+
*
|
|
167
|
+
* @info A procedure is a router too.
|
|
168
|
+
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
169
|
+
*/
|
|
133
170
|
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
|
134
171
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
|
135
172
|
};
|
|
173
|
+
/**
|
|
174
|
+
* Infer all router inputs
|
|
175
|
+
*
|
|
176
|
+
* @info A procedure is a router too.
|
|
177
|
+
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
178
|
+
*/
|
|
136
179
|
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
137
180
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
138
181
|
};
|
|
182
|
+
/**
|
|
183
|
+
* Infer all router outputs
|
|
184
|
+
*
|
|
185
|
+
* @info A procedure is a router too.
|
|
186
|
+
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
187
|
+
*/
|
|
139
188
|
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
140
189
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
141
190
|
};
|
|
142
191
|
|
|
143
|
-
export {
|
|
192
|
+
export { isProcedure as E, createProcedureClient as F, 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, middlewareOutputFn as z };
|
|
193
|
+
export type { AnyProcedure as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, 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 v, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
|
2
|
+
import { b as AnyRouter, C as Context, R as Router } from './server.qKsRrdxW.js';
|
|
3
|
+
import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.7cEtMB30.js';
|
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
|
5
|
+
import { Value } from '@orpc/shared';
|
|
6
|
+
import { T as TraverseContractProcedureCallbackOptions } from './server.ChyoA9XY.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 };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.7844b89",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://orpc.
|
|
6
|
+
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/unnoq/orpc.git",
|
|
@@ -19,54 +19,114 @@
|
|
|
19
19
|
"import": "./dist/index.mjs",
|
|
20
20
|
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
|
+
"./helpers": {
|
|
23
|
+
"types": "./dist/helpers/index.d.mts",
|
|
24
|
+
"import": "./dist/helpers/index.mjs",
|
|
25
|
+
"default": "./dist/helpers/index.mjs"
|
|
26
|
+
},
|
|
22
27
|
"./plugins": {
|
|
23
28
|
"types": "./dist/plugins/index.d.mts",
|
|
24
29
|
"import": "./dist/plugins/index.mjs",
|
|
25
30
|
"default": "./dist/plugins/index.mjs"
|
|
26
31
|
},
|
|
32
|
+
"./hibernation": {
|
|
33
|
+
"types": "./dist/hibernation/index.d.mts",
|
|
34
|
+
"import": "./dist/hibernation/index.mjs",
|
|
35
|
+
"default": "./dist/hibernation/index.mjs"
|
|
36
|
+
},
|
|
27
37
|
"./standard": {
|
|
28
38
|
"types": "./dist/adapters/standard/index.d.mts",
|
|
29
39
|
"import": "./dist/adapters/standard/index.mjs",
|
|
30
40
|
"default": "./dist/adapters/standard/index.mjs"
|
|
31
41
|
},
|
|
42
|
+
"./standard-peer": {
|
|
43
|
+
"types": "./dist/adapters/standard-peer/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/standard-peer/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/standard-peer/index.mjs"
|
|
46
|
+
},
|
|
32
47
|
"./fetch": {
|
|
33
48
|
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
49
|
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
50
|
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
51
|
},
|
|
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
52
|
"./node": {
|
|
48
53
|
"types": "./dist/adapters/node/index.d.mts",
|
|
49
54
|
"import": "./dist/adapters/node/index.mjs",
|
|
50
55
|
"default": "./dist/adapters/node/index.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./fastify": {
|
|
58
|
+
"types": "./dist/adapters/fastify/index.d.mts",
|
|
59
|
+
"import": "./dist/adapters/fastify/index.mjs",
|
|
60
|
+
"default": "./dist/adapters/fastify/index.mjs"
|
|
61
|
+
},
|
|
62
|
+
"./aws-lambda": {
|
|
63
|
+
"types": "./dist/adapters/aws-lambda/index.d.mts",
|
|
64
|
+
"import": "./dist/adapters/aws-lambda/index.mjs",
|
|
65
|
+
"default": "./dist/adapters/aws-lambda/index.mjs"
|
|
66
|
+
},
|
|
67
|
+
"./websocket": {
|
|
68
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
69
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
70
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
71
|
+
},
|
|
72
|
+
"./crossws": {
|
|
73
|
+
"types": "./dist/adapters/crossws/index.d.mts",
|
|
74
|
+
"import": "./dist/adapters/crossws/index.mjs",
|
|
75
|
+
"default": "./dist/adapters/crossws/index.mjs"
|
|
76
|
+
},
|
|
77
|
+
"./ws": {
|
|
78
|
+
"types": "./dist/adapters/ws/index.d.mts",
|
|
79
|
+
"import": "./dist/adapters/ws/index.mjs",
|
|
80
|
+
"default": "./dist/adapters/ws/index.mjs"
|
|
81
|
+
},
|
|
82
|
+
"./bun-ws": {
|
|
83
|
+
"types": "./dist/adapters/bun-ws/index.d.mts",
|
|
84
|
+
"import": "./dist/adapters/bun-ws/index.mjs",
|
|
85
|
+
"default": "./dist/adapters/bun-ws/index.mjs"
|
|
86
|
+
},
|
|
87
|
+
"./message-port": {
|
|
88
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
89
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
90
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
51
91
|
}
|
|
52
92
|
},
|
|
53
93
|
"files": [
|
|
54
94
|
"dist"
|
|
55
95
|
],
|
|
56
96
|
"peerDependencies": {
|
|
57
|
-
"
|
|
58
|
-
"
|
|
97
|
+
"crossws": ">=0.3.4",
|
|
98
|
+
"ws": ">=8.18.1"
|
|
99
|
+
},
|
|
100
|
+
"peerDependenciesMeta": {
|
|
101
|
+
"crossws": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"ws": {
|
|
105
|
+
"optional": true
|
|
106
|
+
}
|
|
59
107
|
},
|
|
60
108
|
"dependencies": {
|
|
61
|
-
"
|
|
62
|
-
"@orpc/
|
|
63
|
-
"@orpc/
|
|
64
|
-
"@orpc/
|
|
65
|
-
"@orpc/
|
|
66
|
-
"@orpc/
|
|
109
|
+
"cookie": "^1.0.2",
|
|
110
|
+
"@orpc/client": "0.0.0-next.7844b89",
|
|
111
|
+
"@orpc/contract": "0.0.0-next.7844b89",
|
|
112
|
+
"@orpc/interop": "0.0.0-next.7844b89",
|
|
113
|
+
"@orpc/shared": "0.0.0-next.7844b89",
|
|
114
|
+
"@orpc/standard-server": "0.0.0-next.7844b89",
|
|
115
|
+
"@orpc/standard-server-fetch": "0.0.0-next.7844b89",
|
|
116
|
+
"@orpc/standard-server-fastify": "0.0.0-next.7844b89",
|
|
117
|
+
"@orpc/standard-server-node": "0.0.0-next.7844b89",
|
|
118
|
+
"@orpc/standard-server-peer": "0.0.0-next.7844b89",
|
|
119
|
+
"@orpc/standard-server-aws-lambda": "0.0.0-next.7844b89"
|
|
67
120
|
},
|
|
68
121
|
"devDependencies": {
|
|
69
|
-
"
|
|
122
|
+
"@tanstack/router-core": "^1.139.1",
|
|
123
|
+
"@types/ws": "^8.18.1",
|
|
124
|
+
"crossws": "^0.4.1",
|
|
125
|
+
"fastify": "^5.6.2",
|
|
126
|
+
"next": "^16.0.3",
|
|
127
|
+
"supertest": "^7.1.4",
|
|
128
|
+
"ws": "^8.18.3",
|
|
129
|
+
"zod": "^4.1.12"
|
|
70
130
|
},
|
|
71
131
|
"scripts": {
|
|
72
132
|
"build": "unbuild",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { FetchHandler } from '../fetch/index.mjs';
|
|
2
|
-
export { BodyLimitPlugin, BodyLimitPluginOptions, 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.CYBq7eu_.mjs';
|
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.DHBkTokD.mjs';
|
|
7
|
-
import '../../shared/server.CBh2jYIX.mjs';
|
|
8
|
-
import '@orpc/standard-server-fetch';
|
|
9
|
-
import '../../shared/server.DatI0acO.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 { BodyLimitPlugin, BodyLimitPluginOptions, 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.CYBq7eu_.js';
|
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.DNoBYd3E.js';
|
|
7
|
-
import '../../shared/server.B0kTII1X.js';
|
|
8
|
-
import '@orpc/standard-server-fetch';
|
|
9
|
-
import '../../shared/server.uEHRR3Pg.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 { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.Et1O6Bm7.mjs';
|
|
2
|
-
import { value } from '@orpc/shared';
|
|
3
|
-
import '@orpc/client';
|
|
4
|
-
import '@orpc/client/standard';
|
|
5
|
-
import '../../shared/server.D9QduY95.mjs';
|
|
6
|
-
import '../../shared/server.CjWkNG6l.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 { BodyLimitPlugin, BodyLimitPluginOptions, 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.CYBq7eu_.mjs';
|
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.DHBkTokD.mjs';
|
|
7
|
-
import '../../shared/server.CBh2jYIX.mjs';
|
|
8
|
-
import '@orpc/standard-server-fetch';
|
|
9
|
-
import '../../shared/server.DatI0acO.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 };
|