@orpc/server 2.0.0-beta.4 → 2.0.0-beta.41
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 +97 -94
- package/dist/adapters/aws-lambda/index.d.mts +50 -0
- package/dist/adapters/aws-lambda/index.d.ts +50 -0
- package/dist/adapters/aws-lambda/index.mjs +39 -0
- package/dist/adapters/crossws/index.d.mts +21 -12
- package/dist/adapters/crossws/index.d.ts +21 -12
- package/dist/adapters/crossws/index.mjs +14 -10
- package/dist/adapters/fastify/index.d.mts +42 -0
- package/dist/adapters/fastify/index.d.ts +42 -0
- package/dist/adapters/fastify/index.mjs +39 -0
- package/dist/adapters/fetch/index.d.mts +21 -114
- package/dist/adapters/fetch/index.d.ts +21 -114
- package/dist/adapters/fetch/index.mjs +20 -182
- package/dist/adapters/message-port/index.d.mts +23 -20
- package/dist/adapters/message-port/index.d.ts +23 -20
- package/dist/adapters/message-port/index.mjs +31 -34
- package/dist/adapters/node/index.d.mts +19 -96
- package/dist/adapters/node/index.d.ts +19 -96
- package/dist/adapters/node/index.mjs +19 -157
- package/dist/adapters/standard/index.d.mts +91 -17
- package/dist/adapters/standard/index.d.ts +91 -17
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/adapters/standard-peer/index.d.mts +6 -11
- package/dist/adapters/standard-peer/index.d.ts +6 -11
- package/dist/adapters/standard-peer/index.mjs +10 -2
- package/dist/adapters/websocket/index.d.mts +45 -29
- package/dist/adapters/websocket/index.d.ts +45 -29
- package/dist/adapters/websocket/index.mjs +39 -28
- package/dist/extensions/callable.d.mts +5 -5
- package/dist/extensions/callable.d.ts +5 -5
- package/dist/extensions/callable.mjs +2 -2
- package/dist/helpers/index.d.mts +23 -6
- package/dist/helpers/index.d.ts +23 -6
- package/dist/helpers/index.mjs +13 -5
- package/dist/index.d.mts +332 -37
- package/dist/index.d.ts +332 -37
- package/dist/index.mjs +141 -65
- package/dist/plugins/index.d.mts +255 -31
- package/dist/plugins/index.d.ts +255 -31
- package/dist/plugins/index.mjs +559 -38
- package/dist/shared/server.1ExWFMze.mjs +69 -0
- package/dist/shared/{server.CjOb6ItT.mjs → server.AVQWL-DI.mjs} +1 -1
- package/dist/shared/{server.BL22TloH.d.mts → server.BEdOJs6S.d.mts} +41 -62
- package/dist/shared/{server.BL22TloH.d.ts → server.BEdOJs6S.d.ts} +41 -62
- package/dist/shared/{server.GDpX6Df8.mjs → server.BFEVk-EI.mjs} +164 -70
- package/dist/shared/{server.BwHnWUuN.mjs → server.BgvqVW_v.mjs} +25 -20
- package/dist/shared/server.BllfVJLm.d.mts +34 -0
- package/dist/shared/server.COfbQ0D8.d.ts +34 -0
- package/dist/shared/{server.DBANIheG.d.ts → server.CVO0hWyj.d.mts} +24 -13
- package/dist/shared/{server.BsNNjG5J.d.mts → server.DD1roZl9.d.mts} +32 -20
- package/dist/shared/server.DFEuNUt4.d.ts +14 -0
- package/dist/shared/{server.DJIkub_t.d.mts → server.DJNkZPfD.d.ts} +24 -13
- package/dist/shared/{server.Pa0F03f_.d.ts → server.DZeVx8K9.d.ts} +32 -20
- package/dist/shared/{server.CrlKQucM.mjs → server.FEqy7Hrj.mjs} +25 -53
- package/dist/shared/server.UG_xdTub.d.mts +14 -0
- package/package.json +48 -14
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.Cj5lgPuG.d.mts +0 -66
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.d_2NS3g5.d.ts +0 -66
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
|
2
|
+
import { toArray } from '@orpc/shared';
|
|
3
|
+
import { flattenStandardHeader } from '@standard-server/core';
|
|
4
|
+
import { toFetchHeaders, toStandardBody } from '@standard-server/fetch';
|
|
5
|
+
|
|
6
|
+
class RequestLimitHandlerPlugin {
|
|
7
|
+
name = "~request-limit";
|
|
8
|
+
/**
|
|
9
|
+
* Should limit the original batch request body instead of sub-requests.
|
|
10
|
+
*/
|
|
11
|
+
after = ["~batch"];
|
|
12
|
+
/**
|
|
13
|
+
* Should limit the final body size instead of the compressed one.
|
|
14
|
+
*/
|
|
15
|
+
before = ["~request-compression"];
|
|
16
|
+
maxBodySize;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.maxBodySize = options.maxBodySize;
|
|
19
|
+
}
|
|
20
|
+
init(options) {
|
|
21
|
+
const maxBodySize = this.maxBodySize;
|
|
22
|
+
const routingInterceptor = async ({ next, ...interceptorOptions }) => {
|
|
23
|
+
return next({
|
|
24
|
+
...interceptorOptions,
|
|
25
|
+
request: {
|
|
26
|
+
...interceptorOptions.request,
|
|
27
|
+
async resolveBody(hint) {
|
|
28
|
+
const contentLength = Number(
|
|
29
|
+
flattenStandardHeader(interceptorOptions.request.headers["content-length"])
|
|
30
|
+
);
|
|
31
|
+
if (Number.isFinite(contentLength) && contentLength > maxBodySize) {
|
|
32
|
+
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
|
33
|
+
}
|
|
34
|
+
const stream = await interceptorOptions.request.resolveBody("octet-stream");
|
|
35
|
+
if (!(stream instanceof ReadableStream)) {
|
|
36
|
+
return stream;
|
|
37
|
+
}
|
|
38
|
+
let currentBodySize = 0;
|
|
39
|
+
const limitedStream = stream.pipeThrough(
|
|
40
|
+
new TransformStream({
|
|
41
|
+
transform(chunk, controller) {
|
|
42
|
+
currentBodySize += chunk.byteLength;
|
|
43
|
+
if (currentBodySize > maxBodySize) {
|
|
44
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
controller.enqueue(chunk);
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
const response = new Response(limitedStream, {
|
|
52
|
+
headers: toFetchHeaders(interceptorOptions.request.headers)
|
|
53
|
+
});
|
|
54
|
+
return toStandardBody(response, { hint });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
...options,
|
|
61
|
+
routingInterceptors: [
|
|
62
|
+
routingInterceptor,
|
|
63
|
+
...toArray(options.routingInterceptors)
|
|
64
|
+
]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { RequestLimitHandlerPlugin as R };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveMetaPlugins, mergeErrorMap, getHiddenMetaPlugins } from '@orpc/contract';
|
|
2
|
-
import { P as Procedure } from './server.
|
|
2
|
+
import { P as Procedure } from './server.FEqy7Hrj.mjs';
|
|
3
3
|
|
|
4
4
|
class DecoratedProcedure extends Procedure {
|
|
5
5
|
meta(...plugins) {
|
|
@@ -1,46 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ErrorMap,
|
|
3
|
-
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
|
|
1
|
+
import { ClientContext, Client } from '@orpc/client';
|
|
2
|
+
import { ErrorMap, AnyMetaPlugin, ORPCErrorConstructorMap, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap, InferSchemaInput } from '@orpc/contract';
|
|
3
|
+
import { DistributiveOmit, MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
|
|
4
4
|
|
|
5
5
|
interface Context {
|
|
6
6
|
[key: PropertyKey]: any;
|
|
7
7
|
}
|
|
8
|
-
type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial &
|
|
9
|
-
type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent :
|
|
10
|
-
|
|
11
|
-
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
|
|
12
|
-
interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
13
|
-
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
14
|
-
}
|
|
15
|
-
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
16
|
-
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Creates a map of ORPC error constructors.
|
|
20
|
-
*
|
|
21
|
-
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
22
|
-
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
23
|
-
* will create a **defined** `ORPCError`.
|
|
24
|
-
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
25
|
-
*
|
|
26
|
-
* The `in` operator can be used to check whether an error code is explicitly
|
|
27
|
-
* defined in the map.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const errorMap = createORPCErrorConstructorMap({
|
|
32
|
-
* NOT_FOUND: {
|
|
33
|
-
* status: 404,
|
|
34
|
-
* message: 'Not Found',
|
|
35
|
-
* },
|
|
36
|
-
* })
|
|
37
|
-
*
|
|
38
|
-
* if ('NOT_FOUND' in errorMap) {
|
|
39
|
-
* const error = errorMap.NOT_FOUND()
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
8
|
+
type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = TInContext extends any ? Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & DistributiveOmit<TInContext, keyof TInitial | keyof TOutContext> : never;
|
|
9
|
+
type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : DistributiveOmit<TCurrent, keyof TOutContext> & TOutContext;
|
|
44
10
|
|
|
45
11
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
46
12
|
output: TOutput;
|
|
@@ -94,7 +60,7 @@ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErro
|
|
|
94
60
|
context: TCurrentContext;
|
|
95
61
|
input: TInput;
|
|
96
62
|
path: string[];
|
|
97
|
-
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap
|
|
63
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap>;
|
|
98
64
|
signal?: AbortSignal | undefined;
|
|
99
65
|
lastEventId?: string | undefined;
|
|
100
66
|
errors: TErrorConstructorMap;
|
|
@@ -119,32 +85,45 @@ interface OrderedMiddleware {
|
|
|
119
85
|
outputSchemasLengthAtUse?: number | undefined;
|
|
120
86
|
middleware: AnyMiddleware;
|
|
121
87
|
}
|
|
122
|
-
interface
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
88
|
+
interface ProcedureConfig {
|
|
89
|
+
/**
|
|
90
|
+
* When enabled, input schemas are not validated at runtime.
|
|
91
|
+
* Schemas are still used for type inference and OpenAPI generation.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* **Warning**: Do not disable validation for schemas that transform values.
|
|
95
|
+
*
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
disableInputValidation?: boolean | undefined;
|
|
126
99
|
/**
|
|
127
|
-
* When enabled,
|
|
128
|
-
*
|
|
100
|
+
* When enabled, output schemas are not validated at runtime.
|
|
101
|
+
* Schemas are still used for type inference and OpenAPI generation.
|
|
102
|
+
*
|
|
103
|
+
* Useful when output schemas exist only for specification generation.
|
|
129
104
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* **Warning**: Do not disable validation for schemas that transform values.
|
|
132
107
|
*
|
|
133
108
|
* @default false
|
|
134
109
|
*/
|
|
135
|
-
|
|
110
|
+
disableOutputValidation?: boolean | undefined;
|
|
111
|
+
}
|
|
112
|
+
interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
|
|
113
|
+
__TInitialContext?: (type: TInitialContext) => unknown;
|
|
114
|
+
__TInjectedContext?: (type: TInjectedContext) => unknown;
|
|
136
115
|
orderedMiddlewares: OrderedMiddleware[];
|
|
137
116
|
handler: ProcedureHandler<any, any, any, any>;
|
|
138
117
|
}
|
|
139
|
-
declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap
|
|
140
|
-
'~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap
|
|
141
|
-
constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap
|
|
118
|
+
declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
119
|
+
'~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
120
|
+
constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>);
|
|
142
121
|
/**
|
|
143
|
-
* Checks if the given instance satisfies the {@
|
|
122
|
+
* Checks if the given instance satisfies the {@link Procedure} class/interface.
|
|
144
123
|
*/
|
|
145
124
|
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
146
125
|
}
|
|
147
|
-
type AnyProcedure = Procedure<any, any, any, any, any
|
|
126
|
+
type AnyProcedure = Procedure<any, any, any, any, any>;
|
|
148
127
|
|
|
149
128
|
interface LazyDefinition<T> {
|
|
150
129
|
meta: Meta;
|
|
@@ -157,7 +136,7 @@ declare class Lazy<T> {
|
|
|
157
136
|
'~orpc': LazyDefinition<T>;
|
|
158
137
|
constructor(def: LazyDefinition<T>);
|
|
159
138
|
/**
|
|
160
|
-
* Checks if the given instance satisfies the {@
|
|
139
|
+
* Checks if the given instance satisfies the {@link Lazy} class/interface.
|
|
161
140
|
*/
|
|
162
141
|
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
163
142
|
}
|
|
@@ -166,19 +145,19 @@ declare function unlazy<T extends Lazyable<any>>(maybeLazy: T): Promise<{
|
|
|
166
145
|
default: T extends Lazy<infer U> ? U : T;
|
|
167
146
|
}>;
|
|
168
147
|
|
|
169
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap
|
|
148
|
+
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
|
|
170
149
|
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap> extends ProcedureHandlerOptions<TInitialContext, unknown, ORPCErrorConstructorMap<TErrorMap>> {
|
|
171
150
|
}
|
|
172
|
-
type ProcedureClientInterceptor<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap
|
|
173
|
-
type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap,
|
|
151
|
+
type ProcedureClientInterceptor<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
|
|
152
|
+
type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TClientContext extends ClientContext> = {
|
|
174
153
|
path?: string[];
|
|
175
|
-
interceptors?: ProcedureClientInterceptor<TInitialContext, TOutputSchema, TErrorMap
|
|
154
|
+
interceptors?: ProcedureClientInterceptor<TInitialContext, TOutputSchema, TErrorMap>[];
|
|
176
155
|
} & (object extends TInitialContext ? {
|
|
177
156
|
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
178
157
|
} : {
|
|
179
158
|
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
180
159
|
});
|
|
181
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap,
|
|
160
|
+
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
182
161
|
|
|
183
|
-
export { Procedure as a, Lazy as
|
|
184
|
-
export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M,
|
|
162
|
+
export { Procedure as a, Lazy as h, createProcedureClient as u, unlazy as v };
|
|
163
|
+
export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, OrderedMiddleware as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ProcedureClientInterceptorOptions as r, ProcedureDefinition as s, ProcedureHandlerOptions as t };
|
|
@@ -1,46 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ErrorMap,
|
|
3
|
-
import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
|
|
1
|
+
import { ClientContext, Client } from '@orpc/client';
|
|
2
|
+
import { ErrorMap, AnyMetaPlugin, ORPCErrorConstructorMap, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap, InferSchemaInput } from '@orpc/contract';
|
|
3
|
+
import { DistributiveOmit, MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
|
|
4
4
|
|
|
5
5
|
interface Context {
|
|
6
6
|
[key: PropertyKey]: any;
|
|
7
7
|
}
|
|
8
|
-
type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial &
|
|
9
|
-
type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent :
|
|
10
|
-
|
|
11
|
-
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
|
|
12
|
-
interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
13
|
-
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
14
|
-
}
|
|
15
|
-
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
16
|
-
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Creates a map of ORPC error constructors.
|
|
20
|
-
*
|
|
21
|
-
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
22
|
-
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
23
|
-
* will create a **defined** `ORPCError`.
|
|
24
|
-
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
25
|
-
*
|
|
26
|
-
* The `in` operator can be used to check whether an error code is explicitly
|
|
27
|
-
* defined in the map.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const errorMap = createORPCErrorConstructorMap({
|
|
32
|
-
* NOT_FOUND: {
|
|
33
|
-
* status: 404,
|
|
34
|
-
* message: 'Not Found',
|
|
35
|
-
* },
|
|
36
|
-
* })
|
|
37
|
-
*
|
|
38
|
-
* if ('NOT_FOUND' in errorMap) {
|
|
39
|
-
* const error = errorMap.NOT_FOUND()
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
8
|
+
type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = TInContext extends any ? Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & DistributiveOmit<TInContext, keyof TInitial | keyof TOutContext> : never;
|
|
9
|
+
type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : DistributiveOmit<TCurrent, keyof TOutContext> & TOutContext;
|
|
44
10
|
|
|
45
11
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
46
12
|
output: TOutput;
|
|
@@ -94,7 +60,7 @@ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErro
|
|
|
94
60
|
context: TCurrentContext;
|
|
95
61
|
input: TInput;
|
|
96
62
|
path: string[];
|
|
97
|
-
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap
|
|
63
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap>;
|
|
98
64
|
signal?: AbortSignal | undefined;
|
|
99
65
|
lastEventId?: string | undefined;
|
|
100
66
|
errors: TErrorConstructorMap;
|
|
@@ -119,32 +85,45 @@ interface OrderedMiddleware {
|
|
|
119
85
|
outputSchemasLengthAtUse?: number | undefined;
|
|
120
86
|
middleware: AnyMiddleware;
|
|
121
87
|
}
|
|
122
|
-
interface
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
88
|
+
interface ProcedureConfig {
|
|
89
|
+
/**
|
|
90
|
+
* When enabled, input schemas are not validated at runtime.
|
|
91
|
+
* Schemas are still used for type inference and OpenAPI generation.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* **Warning**: Do not disable validation for schemas that transform values.
|
|
95
|
+
*
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
disableInputValidation?: boolean | undefined;
|
|
126
99
|
/**
|
|
127
|
-
* When enabled,
|
|
128
|
-
*
|
|
100
|
+
* When enabled, output schemas are not validated at runtime.
|
|
101
|
+
* Schemas are still used for type inference and OpenAPI generation.
|
|
102
|
+
*
|
|
103
|
+
* Useful when output schemas exist only for specification generation.
|
|
129
104
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* **Warning**: Do not disable validation for schemas that transform values.
|
|
132
107
|
*
|
|
133
108
|
* @default false
|
|
134
109
|
*/
|
|
135
|
-
|
|
110
|
+
disableOutputValidation?: boolean | undefined;
|
|
111
|
+
}
|
|
112
|
+
interface ProcedureDefinition<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>, ProcedureConfig {
|
|
113
|
+
__TInitialContext?: (type: TInitialContext) => unknown;
|
|
114
|
+
__TInjectedContext?: (type: TInjectedContext) => unknown;
|
|
136
115
|
orderedMiddlewares: OrderedMiddleware[];
|
|
137
116
|
handler: ProcedureHandler<any, any, any, any>;
|
|
138
117
|
}
|
|
139
|
-
declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap
|
|
140
|
-
'~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap
|
|
141
|
-
constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap
|
|
118
|
+
declare class Procedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
119
|
+
'~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
120
|
+
constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>);
|
|
142
121
|
/**
|
|
143
|
-
* Checks if the given instance satisfies the {@
|
|
122
|
+
* Checks if the given instance satisfies the {@link Procedure} class/interface.
|
|
144
123
|
*/
|
|
145
124
|
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
146
125
|
}
|
|
147
|
-
type AnyProcedure = Procedure<any, any, any, any, any
|
|
126
|
+
type AnyProcedure = Procedure<any, any, any, any, any>;
|
|
148
127
|
|
|
149
128
|
interface LazyDefinition<T> {
|
|
150
129
|
meta: Meta;
|
|
@@ -157,7 +136,7 @@ declare class Lazy<T> {
|
|
|
157
136
|
'~orpc': LazyDefinition<T>;
|
|
158
137
|
constructor(def: LazyDefinition<T>);
|
|
159
138
|
/**
|
|
160
|
-
* Checks if the given instance satisfies the {@
|
|
139
|
+
* Checks if the given instance satisfies the {@link Lazy} class/interface.
|
|
161
140
|
*/
|
|
162
141
|
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
163
142
|
}
|
|
@@ -166,19 +145,19 @@ declare function unlazy<T extends Lazyable<any>>(maybeLazy: T): Promise<{
|
|
|
166
145
|
default: T extends Lazy<infer U> ? U : T;
|
|
167
146
|
}>;
|
|
168
147
|
|
|
169
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap
|
|
148
|
+
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
|
|
170
149
|
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap> extends ProcedureHandlerOptions<TInitialContext, unknown, ORPCErrorConstructorMap<TErrorMap>> {
|
|
171
150
|
}
|
|
172
|
-
type ProcedureClientInterceptor<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap
|
|
173
|
-
type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap,
|
|
151
|
+
type ProcedureClientInterceptor<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
|
|
152
|
+
type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TClientContext extends ClientContext> = {
|
|
174
153
|
path?: string[];
|
|
175
|
-
interceptors?: ProcedureClientInterceptor<TInitialContext, TOutputSchema, TErrorMap
|
|
154
|
+
interceptors?: ProcedureClientInterceptor<TInitialContext, TOutputSchema, TErrorMap>[];
|
|
176
155
|
} & (object extends TInitialContext ? {
|
|
177
156
|
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
178
157
|
} : {
|
|
179
158
|
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
180
159
|
});
|
|
181
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap,
|
|
160
|
+
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
182
161
|
|
|
183
|
-
export { Procedure as a, Lazy as
|
|
184
|
-
export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M,
|
|
162
|
+
export { Procedure as a, Lazy as h, createProcedureClient as u, unlazy as v };
|
|
163
|
+
export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, OrderedMiddleware as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ProcedureClientInterceptorOptions as r, ProcedureDefinition as s, ProcedureHandlerOptions as t };
|