@orpc/server 0.0.0-next.33ca37d → 0.0.0-next.350a165
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 +11 -0
- package/dist/adapters/fetch/index.d.mts +41 -11
- package/dist/adapters/fetch/index.d.ts +41 -11
- package/dist/adapters/fetch/index.mjs +6 -6
- package/dist/adapters/hono/index.d.mts +5 -4
- package/dist/adapters/hono/index.d.ts +5 -4
- package/dist/adapters/hono/index.mjs +6 -6
- package/dist/adapters/next/index.d.mts +5 -4
- package/dist/adapters/next/index.d.ts +5 -4
- package/dist/adapters/next/index.mjs +6 -6
- package/dist/adapters/node/index.d.mts +43 -22
- package/dist/adapters/node/index.d.ts +43 -22
- package/dist/adapters/node/index.mjs +81 -21
- package/dist/adapters/standard/index.d.mts +6 -6
- package/dist/adapters/standard/index.d.ts +6 -6
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +56 -43
- package/dist/index.d.ts +56 -43
- package/dist/index.mjs +27 -6
- package/dist/plugins/index.d.mts +51 -14
- package/dist/plugins/index.d.ts +51 -14
- package/dist/plugins/index.mjs +101 -6
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/{server.BtxZnWJ9.mjs → server.C37gDhSZ.mjs} +19 -29
- package/dist/shared/server.C56IpPNj.d.mts +10 -0
- package/dist/shared/{server.jG7ZuX3S.mjs → server.C78d5yfh.mjs} +43 -28
- package/dist/shared/server.CSIDw0mq.mjs +106 -0
- package/dist/shared/{server.EhgR_5_I.d.ts → server.CyrwhzzU.d.ts} +2 -2
- package/dist/shared/{server.BYTulgUc.d.mts → server.DLt5njUb.d.mts} +9 -10
- package/dist/shared/{server.BYTulgUc.d.ts → server.DLt5njUb.d.ts} +9 -10
- package/dist/shared/{server.B3Tm0IXY.d.ts → server.DfyOFejj.d.ts} +27 -29
- package/dist/shared/{server.Bz_xNBjz.d.mts → server.DgrNIRDf.d.mts} +2 -2
- package/dist/shared/{server.BeJithK4.d.mts → server.Dm5DEJl5.d.mts} +27 -29
- package/dist/shared/server.DnuwaDJo.d.ts +10 -0
- package/package.json +8 -8
- package/dist/shared/server.DoP20NVH.mjs +0 -29
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
@@ -0,0 +1,106 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
3
|
+
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.C78d5yfh.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
|
+
import '@orpc/contract';
|
8
|
+
|
9
|
+
class BodyLimitPlugin {
|
10
|
+
maxBodySize;
|
11
|
+
constructor(options) {
|
12
|
+
this.maxBodySize = options.maxBodySize;
|
13
|
+
}
|
14
|
+
initRuntimeAdapter(options) {
|
15
|
+
options.adapterInterceptors ??= [];
|
16
|
+
options.adapterInterceptors.push(async (options2) => {
|
17
|
+
if (!options2.request.body) {
|
18
|
+
return options2.next();
|
19
|
+
}
|
20
|
+
let currentBodySize = 0;
|
21
|
+
const rawReader = options2.request.body.getReader();
|
22
|
+
const reader = new ReadableStream({
|
23
|
+
start: async (controller) => {
|
24
|
+
try {
|
25
|
+
if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
|
26
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
while (true) {
|
30
|
+
const { done, value } = await rawReader.read();
|
31
|
+
if (done) {
|
32
|
+
break;
|
33
|
+
}
|
34
|
+
currentBodySize += value.length;
|
35
|
+
if (currentBodySize > this.maxBodySize) {
|
36
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
37
|
+
break;
|
38
|
+
}
|
39
|
+
controller.enqueue(value);
|
40
|
+
}
|
41
|
+
} finally {
|
42
|
+
controller.close();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
});
|
46
|
+
const requestInit = { body: reader, duplex: "half" };
|
47
|
+
return options2.next({
|
48
|
+
...options2,
|
49
|
+
request: new Request(options2.request, requestInit)
|
50
|
+
});
|
51
|
+
});
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
class CompositeFetchHandlerPlugin extends CompositeStandardHandlerPlugin {
|
56
|
+
initRuntimeAdapter(options) {
|
57
|
+
for (const plugin of this.plugins) {
|
58
|
+
plugin.initRuntimeAdapter?.(options);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
class FetchHandler {
|
64
|
+
constructor(standardHandler, options = {}) {
|
65
|
+
this.standardHandler = standardHandler;
|
66
|
+
const plugin = new CompositeFetchHandlerPlugin(options.plugins);
|
67
|
+
plugin.initRuntimeAdapter(options);
|
68
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
69
|
+
this.toFetchResponseOptions = options;
|
70
|
+
}
|
71
|
+
toFetchResponseOptions;
|
72
|
+
adapterInterceptors;
|
73
|
+
async handle(request, ...rest) {
|
74
|
+
return intercept(
|
75
|
+
this.adapterInterceptors,
|
76
|
+
{
|
77
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
78
|
+
request,
|
79
|
+
toFetchResponseOptions: this.toFetchResponseOptions
|
80
|
+
},
|
81
|
+
async ({ request: request2, toFetchResponseOptions, ...options }) => {
|
82
|
+
const standardRequest = toStandardLazyRequest(request2);
|
83
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
84
|
+
if (!result.matched) {
|
85
|
+
return result;
|
86
|
+
}
|
87
|
+
return {
|
88
|
+
matched: true,
|
89
|
+
response: toFetchResponse(result.response, toFetchResponseOptions)
|
90
|
+
};
|
91
|
+
}
|
92
|
+
);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
class RPCHandler extends FetchHandler {
|
97
|
+
constructor(router, options = {}) {
|
98
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
99
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
100
|
+
const matcher = new StandardRPCMatcher();
|
101
|
+
const codec = new StandardRPCCodec(serializer);
|
102
|
+
super(new StandardHandler(router, matcher, codec, options), options);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
export { BodyLimitPlugin as B, CompositeFetchHandlerPlugin as C, FetchHandler as F, RPCHandler as R };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
-
import { C as Context } from './server.
|
3
|
-
import { a as StandardHandlerOptions } from './server.
|
2
|
+
import { C as Context } from './server.DLt5njUb.js';
|
3
|
+
import { a as StandardHandlerOptions } from './server.DfyOFejj.js';
|
4
4
|
|
5
5
|
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
6
|
}
|
@@ -1,12 +1,11 @@
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
|
2
2
|
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
-
import { ErrorMap, ErrorMapItem, InferSchemaInput,
|
3
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
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>;
|
9
|
-
type ContextExtendsGuard<T extends Context, U extends Context> = T extends U ? unknown : never;
|
10
9
|
|
11
10
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
11
|
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
@@ -98,9 +97,9 @@ interface MapInputMiddleware<TInput, TMappedInput> {
|
|
98
97
|
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
99
98
|
|
100
99
|
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
101
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context,
|
100
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
102
101
|
context: TInitialContext;
|
103
|
-
input:
|
102
|
+
input: unknown;
|
104
103
|
errors: ORPCErrorConstructorMap<TErrorMap>;
|
105
104
|
path: readonly string[];
|
106
105
|
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
@@ -110,18 +109,18 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TIn
|
|
110
109
|
/**
|
111
110
|
* Options for creating a procedure caller with comprehensive type safety
|
112
111
|
*/
|
113
|
-
type CreateProcedureClientOptions<TInitialContext extends Context,
|
112
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
114
113
|
/**
|
115
114
|
* This is helpful for logging and analytics.
|
116
115
|
*/
|
117
116
|
path?: readonly string[];
|
118
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext,
|
117
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
|
119
118
|
} & (Record<never, never> extends TInitialContext ? {
|
120
119
|
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
120
|
} : {
|
122
121
|
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
123
122
|
});
|
124
|
-
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>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext,
|
123
|
+
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>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
125
124
|
|
126
125
|
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> : {
|
127
126
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
@@ -141,4 +140,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
141
140
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
141
|
};
|
143
142
|
|
144
|
-
export { type AnyProcedure as A,
|
143
|
+
export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
|
@@ -1,12 +1,11 @@
|
|
1
|
-
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client';
|
2
2
|
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
-
import { ErrorMap, ErrorMapItem, InferSchemaInput,
|
3
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
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>;
|
9
|
-
type ContextExtendsGuard<T extends Context, U extends Context> = T extends U ? unknown : never;
|
10
9
|
|
11
10
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
11
|
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
@@ -98,9 +97,9 @@ interface MapInputMiddleware<TInput, TMappedInput> {
|
|
98
97
|
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
99
98
|
|
100
99
|
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
101
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context,
|
100
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
102
101
|
context: TInitialContext;
|
103
|
-
input:
|
102
|
+
input: unknown;
|
104
103
|
errors: ORPCErrorConstructorMap<TErrorMap>;
|
105
104
|
path: readonly string[];
|
106
105
|
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
@@ -110,18 +109,18 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TIn
|
|
110
109
|
/**
|
111
110
|
* Options for creating a procedure caller with comprehensive type safety
|
112
111
|
*/
|
113
|
-
type CreateProcedureClientOptions<TInitialContext extends Context,
|
112
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
114
113
|
/**
|
115
114
|
* This is helpful for logging and analytics.
|
116
115
|
*/
|
117
116
|
path?: readonly string[];
|
118
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext,
|
117
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
|
119
118
|
} & (Record<never, never> extends TInitialContext ? {
|
120
119
|
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
120
|
} : {
|
122
121
|
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
123
122
|
});
|
124
|
-
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>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext,
|
123
|
+
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>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
125
124
|
|
126
125
|
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> : {
|
127
126
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
@@ -141,4 +140,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
141
140
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
141
|
};
|
143
142
|
|
144
|
-
export { type AnyProcedure as A,
|
143
|
+
export { type AnyProcedure as A, middlewareOutputFn as B, type Context as C, type ProcedureHandlerOptions as D, type ProcedureDef as E, isProcedure as F, createProcedureClient as G, type InferRouterInitialContexts as H, type InferRouterInitialContext as I, type InferRouterCurrentContexts as J, type InferRouterInputs as K, type Lazyable as L, type Middleware as M, type InferRouterOutputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type MergedInitialContext as c, type MergedCurrentContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, type ORPCErrorConstructorMapItemOptions as k, type ORPCErrorConstructorMapItem as l, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, type LazyMeta as p, lazy as q, isLazy as r, getLazyMeta as s, type MiddlewareResult as t, unlazy as u, validateORPCError as v, type MiddlewareNextFnOptions as w, type MiddlewareNextFn as x, type MiddlewareOutputFn as y, type MiddlewareOptions as z };
|
@@ -1,8 +1,8 @@
|
|
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 { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.
|
5
|
-
import { ORPCError } from '@orpc/client';
|
5
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.js';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
8
8
|
type StandardMatchResult = {
|
@@ -20,13 +20,20 @@ interface StandardCodec {
|
|
20
20
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
21
|
}
|
22
22
|
|
23
|
-
|
23
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
24
|
+
order?: number;
|
25
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
26
|
+
}
|
27
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
28
|
+
protected readonly plugins: TPlugin[];
|
29
|
+
constructor(plugins?: readonly TPlugin[]);
|
30
|
+
init(options: StandardHandlerOptions<T>): void;
|
31
|
+
}
|
32
|
+
|
33
|
+
interface StandardHandleOptions<T extends Context> {
|
24
34
|
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
35
|
context: T;
|
29
|
-
}
|
36
|
+
}
|
30
37
|
type StandardHandleResult = {
|
31
38
|
matched: true;
|
32
39
|
response: StandardResponse;
|
@@ -34,42 +41,33 @@ type StandardHandleResult = {
|
|
34
41
|
matched: false;
|
35
42
|
response: undefined;
|
36
43
|
};
|
37
|
-
|
38
|
-
context: T;
|
44
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
39
45
|
request: StandardLazyRequest;
|
40
|
-
}
|
46
|
+
}
|
41
47
|
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
-
plugins?:
|
48
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
43
49
|
/**
|
44
50
|
* Interceptors at the request level, helpful when you want catch errors
|
45
51
|
*/
|
46
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult,
|
52
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
47
53
|
/**
|
48
54
|
* Interceptors at the root level, helpful when you want override the request/response
|
49
55
|
*/
|
50
|
-
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult,
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
51
57
|
/**
|
52
58
|
*
|
53
59
|
* Interceptors for procedure client.
|
54
60
|
*/
|
55
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext,
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
56
62
|
}
|
57
63
|
declare class StandardHandler<T extends Context> {
|
58
64
|
private readonly matcher;
|
59
65
|
private readonly codec;
|
60
|
-
private readonly
|
61
|
-
private readonly
|
66
|
+
private readonly interceptors;
|
67
|
+
private readonly clientInterceptors;
|
68
|
+
private readonly rootInterceptors;
|
62
69
|
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
-
handle(request: StandardLazyRequest,
|
64
|
-
}
|
65
|
-
|
66
|
-
interface HandlerPlugin<TContext extends Context> {
|
67
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
-
}
|
69
|
-
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
-
private readonly plugins;
|
71
|
-
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
70
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
73
71
|
}
|
74
72
|
|
75
|
-
export {
|
73
|
+
export { CompositeStandardHandlerPlugin as C, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardCodec as b, type StandardParams as c, type StandardMatcher as d, type StandardMatchResult as e, type StandardHandleResult as f, type StandardHandlerInterceptorOptions as g, StandardHandler as h, type StandardHandlerPlugin as i };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
-
import { C as Context } from './server.
|
3
|
-
import { a as StandardHandlerOptions } from './server.
|
2
|
+
import { C as Context } from './server.DLt5njUb.mjs';
|
3
|
+
import { a as StandardHandlerOptions } from './server.Dm5DEJl5.mjs';
|
4
4
|
|
5
5
|
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
6
|
}
|
@@ -1,8 +1,8 @@
|
|
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 { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.
|
5
|
-
import { ORPCError } from '@orpc/client';
|
5
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.mjs';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
8
8
|
type StandardMatchResult = {
|
@@ -20,13 +20,20 @@ interface StandardCodec {
|
|
20
20
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
21
|
}
|
22
22
|
|
23
|
-
|
23
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
24
|
+
order?: number;
|
25
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
26
|
+
}
|
27
|
+
declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
|
28
|
+
protected readonly plugins: TPlugin[];
|
29
|
+
constructor(plugins?: readonly TPlugin[]);
|
30
|
+
init(options: StandardHandlerOptions<T>): void;
|
31
|
+
}
|
32
|
+
|
33
|
+
interface StandardHandleOptions<T extends Context> {
|
24
34
|
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
35
|
context: T;
|
29
|
-
}
|
36
|
+
}
|
30
37
|
type StandardHandleResult = {
|
31
38
|
matched: true;
|
32
39
|
response: StandardResponse;
|
@@ -34,42 +41,33 @@ type StandardHandleResult = {
|
|
34
41
|
matched: false;
|
35
42
|
response: undefined;
|
36
43
|
};
|
37
|
-
|
38
|
-
context: T;
|
44
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
39
45
|
request: StandardLazyRequest;
|
40
|
-
}
|
46
|
+
}
|
41
47
|
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
-
plugins?:
|
48
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
43
49
|
/**
|
44
50
|
* Interceptors at the request level, helpful when you want catch errors
|
45
51
|
*/
|
46
|
-
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult,
|
52
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
47
53
|
/**
|
48
54
|
* Interceptors at the root level, helpful when you want override the request/response
|
49
55
|
*/
|
50
|
-
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult,
|
56
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
|
51
57
|
/**
|
52
58
|
*
|
53
59
|
* Interceptors for procedure client.
|
54
60
|
*/
|
55
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext,
|
61
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
56
62
|
}
|
57
63
|
declare class StandardHandler<T extends Context> {
|
58
64
|
private readonly matcher;
|
59
65
|
private readonly codec;
|
60
|
-
private readonly
|
61
|
-
private readonly
|
66
|
+
private readonly interceptors;
|
67
|
+
private readonly clientInterceptors;
|
68
|
+
private readonly rootInterceptors;
|
62
69
|
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
-
handle(request: StandardLazyRequest,
|
64
|
-
}
|
65
|
-
|
66
|
-
interface HandlerPlugin<TContext extends Context> {
|
67
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
-
}
|
69
|
-
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
-
private readonly plugins;
|
71
|
-
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
70
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
73
71
|
}
|
74
72
|
|
75
|
-
export {
|
73
|
+
export { CompositeStandardHandlerPlugin as C, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardCodec as b, type StandardParams as c, type StandardMatcher as d, type StandardMatchResult as e, type StandardHandleResult as f, type StandardHandlerInterceptorOptions as g, StandardHandler as h, type StandardHandlerPlugin as i };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { C as Context } from './server.DLt5njUb.js';
|
2
|
+
import { S as StandardHandleOptions } from './server.DfyOFejj.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 };
|
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.350a165",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -58,15 +58,15 @@
|
|
58
58
|
"next": ">=14.0.0"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@orpc/
|
62
|
-
"@orpc/
|
63
|
-
"@orpc/shared": "0.0.0-next.
|
64
|
-
"@orpc/standard-server": "0.0.0-next.
|
65
|
-
"@orpc/standard-server
|
66
|
-
"@orpc/standard-server-node": "0.0.0-next.
|
61
|
+
"@orpc/client": "0.0.0-next.350a165",
|
62
|
+
"@orpc/contract": "0.0.0-next.350a165",
|
63
|
+
"@orpc/shared": "0.0.0-next.350a165",
|
64
|
+
"@orpc/standard-server-fetch": "0.0.0-next.350a165",
|
65
|
+
"@orpc/standard-server": "0.0.0-next.350a165",
|
66
|
+
"@orpc/standard-server-node": "0.0.0-next.350a165"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
|
-
"
|
69
|
+
"supertest": "^7.0.0"
|
70
70
|
},
|
71
71
|
"scripts": {
|
72
72
|
"build": "unbuild",
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
|
-
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
-
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.jG7ZuX3S.mjs';
|
4
|
-
|
5
|
-
class RPCHandler {
|
6
|
-
standardHandler;
|
7
|
-
constructor(router, options = {}) {
|
8
|
-
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
9
|
-
const serializer = new StandardRPCSerializer(jsonSerializer);
|
10
|
-
const matcher = new StandardRPCMatcher();
|
11
|
-
const codec = new StandardRPCCodec(serializer);
|
12
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
13
|
-
}
|
14
|
-
async handle(request, ...[
|
15
|
-
options = {}
|
16
|
-
]) {
|
17
|
-
const standardRequest = toStandardLazyRequest(request);
|
18
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
19
|
-
if (!result.matched) {
|
20
|
-
return result;
|
21
|
-
}
|
22
|
-
return {
|
23
|
-
matched: true,
|
24
|
-
response: toFetchResponse(result.response, options)
|
25
|
-
};
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
export { RPCHandler as R };
|