@orpc/server 0.46.0 → 1.0.0-beta.1
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 +3 -1
- package/dist/adapters/fetch/index.d.mts +5 -4
- package/dist/adapters/fetch/index.d.ts +5 -4
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/hono/index.d.mts +4 -3
- package/dist/adapters/hono/index.d.ts +4 -3
- package/dist/adapters/hono/index.mjs +4 -4
- package/dist/adapters/next/index.d.mts +4 -3
- package/dist/adapters/next/index.d.ts +4 -3
- package/dist/adapters/next/index.mjs +4 -4
- package/dist/adapters/node/index.d.mts +5 -4
- package/dist/adapters/node/index.d.ts +5 -4
- package/dist/adapters/node/index.mjs +8 -6
- package/dist/adapters/standard/index.d.mts +10 -13
- package/dist/adapters/standard/index.d.ts +10 -13
- package/dist/adapters/standard/index.mjs +2 -3
- package/dist/index.d.mts +140 -117
- package/dist/index.d.ts +140 -117
- package/dist/index.mjs +55 -46
- package/dist/plugins/index.d.mts +12 -12
- package/dist/plugins/index.d.ts +12 -12
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/{server.B-ewprcf.d.ts → server.B3Tm0IXY.d.ts} +12 -14
- package/dist/shared/server.BYTulgUc.d.mts +144 -0
- package/dist/shared/server.BYTulgUc.d.ts +144 -0
- package/dist/shared/{server.DJrh0Ceu.d.mts → server.BeJithK4.d.mts} +12 -14
- package/dist/shared/{server.V6zT5iYQ.mjs → server.BtxZnWJ9.mjs} +155 -160
- package/dist/shared/server.Bz_xNBjz.d.mts +8 -0
- package/dist/shared/{server.KwueCzFr.mjs → server.DoP20NVH.mjs} +7 -4
- package/dist/shared/server.EhgR_5_I.d.ts +8 -0
- package/dist/shared/{server.BBGuTxHE.mjs → server.jG7ZuX3S.mjs} +14 -19
- package/package.json +7 -7
- package/dist/shared/server.CA-o8cUY.d.mts +0 -9
- package/dist/shared/server.Cn9ybJtE.d.mts +0 -152
- package/dist/shared/server.Cn9ybJtE.d.ts +0 -152
- package/dist/shared/server.DPQt9YYq.d.ts +0 -9
package/dist/index.mjs
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure } from '@orpc/contract';
|
1
|
+
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
2
2
|
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { P as Procedure, d as addMiddleware, c as createProcedureClient,
|
4
|
-
export { L as
|
3
|
+
import { P as Procedure, d as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, f as isLazy, h as createAssertedLazyProcedure, g as getRouter } from './shared/server.BtxZnWJ9.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, q as call, w as createAccessibleLazyRouter, b as createContractedProcedure, j as createORPCErrorConstructorMap, r as getHiddenRouterContract, k as getLazyMeta, o as isStartWithMiddlewares, m as mergeCurrentContext, p as mergeMiddlewares, n as middlewareOutputFn, x as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, y as unlazyRouter, v as validateORPCError } from './shared/server.BtxZnWJ9.mjs';
|
5
5
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
6
6
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
7
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
8
8
|
|
9
9
|
const DEFAULT_CONFIG = {
|
10
10
|
initialInputValidationIndex: 0,
|
11
|
-
initialOutputValidationIndex: 0
|
11
|
+
initialOutputValidationIndex: 0,
|
12
|
+
dedupeLeadingMiddlewares: true
|
12
13
|
};
|
13
14
|
function fallbackConfig(key, value) {
|
14
15
|
if (value === void 0) {
|
@@ -18,7 +19,7 @@ function fallbackConfig(key, value) {
|
|
18
19
|
}
|
19
20
|
|
20
21
|
function decorateMiddleware(middleware) {
|
21
|
-
const decorated = middleware;
|
22
|
+
const decorated = (...args) => middleware(...args);
|
22
23
|
decorated.mapInput = (mapInput) => {
|
23
24
|
const mapped = decorateMiddleware(
|
24
25
|
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
@@ -73,9 +74,13 @@ class DecoratedProcedure extends Procedure {
|
|
73
74
|
* Make this procedure callable (works like a function while still being a procedure).
|
74
75
|
*/
|
75
76
|
callable(...rest) {
|
76
|
-
return
|
77
|
-
|
78
|
-
|
77
|
+
return new Proxy(createProcedureClient(this, ...rest), {
|
78
|
+
get: (target, key) => {
|
79
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
80
|
+
},
|
81
|
+
has: (target, key) => {
|
82
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
83
|
+
}
|
79
84
|
});
|
80
85
|
}
|
81
86
|
/**
|
@@ -100,6 +105,7 @@ class Builder {
|
|
100
105
|
return new Builder({
|
101
106
|
...this["~orpc"],
|
102
107
|
config,
|
108
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
|
103
109
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
104
110
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
105
111
|
});
|
@@ -133,6 +139,12 @@ class Builder {
|
|
133
139
|
route: initialRoute
|
134
140
|
});
|
135
141
|
}
|
142
|
+
$input(initialInputSchema) {
|
143
|
+
return new Builder({
|
144
|
+
...this["~orpc"],
|
145
|
+
inputSchema: initialInputSchema
|
146
|
+
});
|
147
|
+
}
|
136
148
|
middleware(middleware) {
|
137
149
|
return decorateMiddleware(middleware);
|
138
150
|
}
|
@@ -194,10 +206,10 @@ class Builder {
|
|
194
206
|
});
|
195
207
|
}
|
196
208
|
router(router) {
|
197
|
-
return
|
209
|
+
return enhanceRouter(router, this["~orpc"]);
|
198
210
|
}
|
199
211
|
lazy(loader) {
|
200
|
-
return
|
212
|
+
return enhanceRouter(lazy(loader), this["~orpc"]);
|
201
213
|
}
|
202
214
|
}
|
203
215
|
const os = new Builder({
|
@@ -205,17 +217,12 @@ const os = new Builder({
|
|
205
217
|
route: {},
|
206
218
|
meta: {},
|
207
219
|
errorMap: {},
|
208
|
-
inputSchema: void 0,
|
209
|
-
outputSchema: void 0,
|
210
220
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
211
221
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
212
|
-
middlewares: []
|
222
|
+
middlewares: [],
|
223
|
+
dedupeLeadingMiddlewares: true
|
213
224
|
});
|
214
225
|
|
215
|
-
function mergeContext(context, other) {
|
216
|
-
return { ...context, ...other };
|
217
|
-
}
|
218
|
-
|
219
226
|
function implementerInternal(contract, config, middlewares) {
|
220
227
|
if (isContractProcedure(contract)) {
|
221
228
|
const impl2 = new Builder({
|
@@ -223,12 +230,16 @@ function implementerInternal(contract, config, middlewares) {
|
|
223
230
|
config,
|
224
231
|
middlewares,
|
225
232
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
226
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
233
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
|
234
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
227
235
|
});
|
228
236
|
return impl2;
|
229
237
|
}
|
230
238
|
const impl = new Proxy(contract, {
|
231
239
|
get: (target, key) => {
|
240
|
+
if (typeof key !== "string") {
|
241
|
+
return Reflect.get(target, key);
|
242
|
+
}
|
232
243
|
let method;
|
233
244
|
if (key === "middleware") {
|
234
245
|
method = (mid) => decorateMiddleware(mid);
|
@@ -242,23 +253,29 @@ function implementerInternal(contract, config, middlewares) {
|
|
242
253
|
};
|
243
254
|
} else if (key === "router") {
|
244
255
|
method = (router) => {
|
245
|
-
const adapted =
|
256
|
+
const adapted = enhanceRouter(router, {
|
246
257
|
middlewares,
|
247
|
-
errorMap: {}
|
258
|
+
errorMap: {},
|
259
|
+
prefix: void 0,
|
260
|
+
tags: void 0,
|
261
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
248
262
|
});
|
249
|
-
return
|
263
|
+
return setHiddenRouterContract(adapted, contract);
|
250
264
|
};
|
251
265
|
} else if (key === "lazy") {
|
252
266
|
method = (loader) => {
|
253
|
-
const adapted =
|
267
|
+
const adapted = enhanceRouter(lazy(loader), {
|
254
268
|
middlewares,
|
255
|
-
errorMap: {}
|
269
|
+
errorMap: {},
|
270
|
+
prefix: void 0,
|
271
|
+
tags: void 0,
|
272
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
256
273
|
});
|
257
|
-
return
|
274
|
+
return setHiddenRouterContract(adapted, contract);
|
258
275
|
};
|
259
276
|
}
|
260
|
-
const next =
|
261
|
-
if (!next
|
277
|
+
const next = getContractRouter(target, [key]);
|
278
|
+
if (!next) {
|
262
279
|
return method ?? next;
|
263
280
|
}
|
264
281
|
const nextImpl = implementerInternal(next, config, middlewares);
|
@@ -285,42 +302,34 @@ function implement(contract, config = {}) {
|
|
285
302
|
method = (config2) => implement(contract, config2);
|
286
303
|
}
|
287
304
|
const next = Reflect.get(target, key);
|
288
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
289
|
-
return method
|
305
|
+
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
306
|
+
return method || next;
|
290
307
|
}
|
291
|
-
|
292
|
-
|
293
|
-
get(
|
294
|
-
|
295
|
-
|
296
|
-
});
|
297
|
-
}
|
298
|
-
return next;
|
308
|
+
return new Proxy(method, {
|
309
|
+
get(_, key2) {
|
310
|
+
return Reflect.get(next, key2);
|
311
|
+
}
|
312
|
+
});
|
299
313
|
}
|
300
314
|
});
|
301
315
|
return impl;
|
302
316
|
}
|
303
317
|
|
304
|
-
function
|
305
|
-
return createProcedureClient(procedure, ...rest)(input);
|
306
|
-
}
|
307
|
-
|
308
|
-
function createRouterClient(router, ...rest) {
|
318
|
+
function createRouterClient(router, ...[options]) {
|
309
319
|
if (isProcedure(router)) {
|
310
|
-
const caller = createProcedureClient(router,
|
320
|
+
const caller = createProcedureClient(router, options);
|
311
321
|
return caller;
|
312
322
|
}
|
313
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(
|
323
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
314
324
|
const recursive = new Proxy(procedureCaller, {
|
315
325
|
get(target, key) {
|
316
326
|
if (typeof key !== "string") {
|
317
327
|
return Reflect.get(target, key);
|
318
328
|
}
|
319
|
-
const next =
|
329
|
+
const next = getRouter(router, [key]);
|
320
330
|
if (!next) {
|
321
331
|
return Reflect.get(target, key);
|
322
332
|
}
|
323
|
-
const [options] = rest;
|
324
333
|
return createRouterClient(next, {
|
325
334
|
...options,
|
326
335
|
path: [...options?.path ?? [], key]
|
@@ -330,4 +339,4 @@ function createRouterClient(router, ...rest) {
|
|
330
339
|
return recursive;
|
331
340
|
}
|
332
341
|
|
333
|
-
export { Builder, DecoratedProcedure, Procedure,
|
342
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
import {
|
2
|
-
export { C as CompositePlugin } from '../shared/server.
|
1
|
+
import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.BeJithK4.mjs';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.BeJithK4.mjs';
|
3
3
|
import { Value } from '@orpc/shared';
|
4
|
-
import { C as Context } from '../shared/server.
|
4
|
+
import { C as Context } from '../shared/server.BYTulgUc.mjs';
|
5
5
|
import '@orpc/contract';
|
6
6
|
import '@orpc/standard-server';
|
7
7
|
import '@orpc/client';
|
8
8
|
|
9
9
|
interface CORSOptions<TContext extends Context> {
|
10
|
-
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
-
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
-
allowMethods?: string[];
|
13
|
-
allowHeaders?: string[];
|
10
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: readonly string[];
|
13
|
+
allowHeaders?: readonly string[];
|
14
14
|
maxAge?: number;
|
15
15
|
credentials?: boolean;
|
16
|
-
exposeHeaders?: string[];
|
16
|
+
exposeHeaders?: readonly string[];
|
17
17
|
}
|
18
|
-
declare class CORSPlugin<TContext extends Context> implements
|
18
|
+
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
19
|
private readonly options;
|
20
|
-
constructor(options?:
|
20
|
+
constructor(options?: CORSOptions<TContext>);
|
21
21
|
init(options: StandardHandlerOptions<TContext>): void;
|
22
22
|
}
|
23
23
|
|
24
24
|
interface ResponseHeadersPluginContext {
|
25
25
|
resHeaders?: Headers;
|
26
26
|
}
|
27
|
-
declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements
|
27
|
+
declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
|
28
28
|
init(options: StandardHandlerOptions<TContext>): void;
|
29
29
|
}
|
30
30
|
|
31
|
-
export { type CORSOptions, CORSPlugin,
|
31
|
+
export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
import {
|
2
|
-
export { C as CompositePlugin } from '../shared/server.
|
1
|
+
import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.B3Tm0IXY.js';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.B3Tm0IXY.js';
|
3
3
|
import { Value } from '@orpc/shared';
|
4
|
-
import { C as Context } from '../shared/server.
|
4
|
+
import { C as Context } from '../shared/server.BYTulgUc.js';
|
5
5
|
import '@orpc/contract';
|
6
6
|
import '@orpc/standard-server';
|
7
7
|
import '@orpc/client';
|
8
8
|
|
9
9
|
interface CORSOptions<TContext extends Context> {
|
10
|
-
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
-
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
-
allowMethods?: string[];
|
13
|
-
allowHeaders?: string[];
|
10
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: readonly string[];
|
13
|
+
allowHeaders?: readonly string[];
|
14
14
|
maxAge?: number;
|
15
15
|
credentials?: boolean;
|
16
|
-
exposeHeaders?: string[];
|
16
|
+
exposeHeaders?: readonly string[];
|
17
17
|
}
|
18
|
-
declare class CORSPlugin<TContext extends Context> implements
|
18
|
+
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
19
|
private readonly options;
|
20
|
-
constructor(options?:
|
20
|
+
constructor(options?: CORSOptions<TContext>);
|
21
21
|
init(options: StandardHandlerOptions<TContext>): void;
|
22
22
|
}
|
23
23
|
|
24
24
|
interface ResponseHeadersPluginContext {
|
25
25
|
resHeaders?: Headers;
|
26
26
|
}
|
27
|
-
declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements
|
27
|
+
declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
|
28
28
|
init(options: StandardHandlerOptions<TContext>): void;
|
29
29
|
}
|
30
30
|
|
31
|
-
export { type CORSOptions, CORSPlugin,
|
31
|
+
export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
package/dist/plugins/index.mjs
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import { HTTPPath,
|
1
|
+
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
-
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.js';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
8
8
|
type StandardMatchResult = {
|
9
|
-
path: string[];
|
9
|
+
path: readonly string[];
|
10
10
|
procedure: AnyProcedure;
|
11
11
|
params?: StandardParams;
|
12
12
|
} | undefined;
|
@@ -27,9 +27,6 @@ type StandardHandleOptions<T extends Context> = {
|
|
27
27
|
} : {
|
28
28
|
context: T;
|
29
29
|
});
|
30
|
-
type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
31
|
-
context: T;
|
32
|
-
};
|
33
30
|
type StandardHandleResult = {
|
34
31
|
matched: true;
|
35
32
|
response: StandardResponse;
|
@@ -37,11 +34,12 @@ type StandardHandleResult = {
|
|
37
34
|
matched: false;
|
38
35
|
response: undefined;
|
39
36
|
};
|
40
|
-
type StandardHandlerInterceptorOptions<
|
37
|
+
type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
|
38
|
+
context: T;
|
41
39
|
request: StandardLazyRequest;
|
42
40
|
};
|
43
41
|
interface StandardHandlerOptions<TContext extends Context> {
|
44
|
-
plugins?:
|
42
|
+
plugins?: HandlerPlugin<TContext>[];
|
45
43
|
/**
|
46
44
|
* Interceptors at the request level, helpful when you want catch errors
|
47
45
|
*/
|
@@ -54,24 +52,24 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
54
52
|
*
|
55
53
|
* Interceptors for procedure client.
|
56
54
|
*/
|
57
|
-
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext,
|
55
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
58
56
|
}
|
59
57
|
declare class StandardHandler<T extends Context> {
|
60
58
|
private readonly matcher;
|
61
59
|
private readonly codec;
|
62
60
|
private readonly options;
|
63
61
|
private readonly plugin;
|
64
|
-
constructor(router: Router<
|
62
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
65
63
|
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
66
64
|
}
|
67
65
|
|
68
|
-
interface
|
66
|
+
interface HandlerPlugin<TContext extends Context> {
|
69
67
|
init?(options: StandardHandlerOptions<TContext>): void;
|
70
68
|
}
|
71
|
-
declare class CompositePlugin<TContext extends Context> implements
|
69
|
+
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
72
70
|
private readonly plugins;
|
73
|
-
constructor(plugins?:
|
71
|
+
constructor(plugins?: HandlerPlugin<TContext>[]);
|
74
72
|
init(options: StandardHandlerOptions<TContext>): void;
|
75
73
|
}
|
76
74
|
|
77
|
-
export { CompositePlugin as C, type
|
75
|
+
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
|
2
|
+
import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
|
3
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
4
|
+
|
5
|
+
type Context = Record<string, any>;
|
6
|
+
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
7
|
+
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
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
|
+
|
11
|
+
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
12
|
+
type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
13
|
+
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
14
|
+
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
|
15
|
+
};
|
16
|
+
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
17
|
+
declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
18
|
+
|
19
|
+
declare const LAZY_SYMBOL: unique symbol;
|
20
|
+
interface LazyMeta {
|
21
|
+
prefix?: HTTPPath;
|
22
|
+
}
|
23
|
+
interface Lazy<T> {
|
24
|
+
[LAZY_SYMBOL]: {
|
25
|
+
loader: () => Promise<{
|
26
|
+
default: T;
|
27
|
+
}>;
|
28
|
+
meta: LazyMeta;
|
29
|
+
};
|
30
|
+
}
|
31
|
+
type Lazyable<T> = T | Lazy<T>;
|
32
|
+
declare function lazy<T>(loader: () => Promise<{
|
33
|
+
default: T;
|
34
|
+
}>, meta?: LazyMeta): Lazy<T>;
|
35
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
36
|
+
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
37
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
38
|
+
default: T extends Lazy<infer U> ? U : T;
|
39
|
+
}>;
|
40
|
+
|
41
|
+
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
42
|
+
context: TCurrentContext;
|
43
|
+
input: TInput;
|
44
|
+
path: readonly string[];
|
45
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
46
|
+
signal?: AbortSignal;
|
47
|
+
lastEventId: string | undefined;
|
48
|
+
errors: TErrorConstructorMap;
|
49
|
+
}
|
50
|
+
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
51
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
52
|
+
}
|
53
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
54
|
+
__initialContext?: (type: TInitialContext) => unknown;
|
55
|
+
middlewares: readonly AnyMiddleware[];
|
56
|
+
inputValidationIndex: number;
|
57
|
+
outputValidationIndex: number;
|
58
|
+
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
59
|
+
}
|
60
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
61
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
62
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
63
|
+
}
|
64
|
+
type AnyProcedure = Procedure<any, any, any, any, any, any>;
|
65
|
+
declare function isProcedure(item: unknown): item is AnyProcedure;
|
66
|
+
|
67
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
68
|
+
output: TOutput;
|
69
|
+
context: TOutContext;
|
70
|
+
}>;
|
71
|
+
type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
72
|
+
context?: TOutContext;
|
73
|
+
} : {
|
74
|
+
context: TOutContext;
|
75
|
+
};
|
76
|
+
interface MiddlewareNextFn<TOutput> {
|
77
|
+
<U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
78
|
+
}
|
79
|
+
interface MiddlewareOutputFn<TOutput> {
|
80
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
81
|
+
}
|
82
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
83
|
+
context: TInContext;
|
84
|
+
path: readonly string[];
|
85
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
86
|
+
signal?: AbortSignal;
|
87
|
+
lastEventId: string | undefined;
|
88
|
+
next: MiddlewareNextFn<TOutput>;
|
89
|
+
errors: TErrorConstructorMap;
|
90
|
+
}
|
91
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
92
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
93
|
+
}
|
94
|
+
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
95
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
96
|
+
(input: TInput): TMappedInput;
|
97
|
+
}
|
98
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
99
|
+
|
100
|
+
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, TInputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
102
|
+
context: TInitialContext;
|
103
|
+
input: InferSchemaInput<TInputSchema>;
|
104
|
+
errors: ORPCErrorConstructorMap<TErrorMap>;
|
105
|
+
path: readonly string[];
|
106
|
+
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
107
|
+
signal?: AbortSignal;
|
108
|
+
lastEventId: string | undefined;
|
109
|
+
}
|
110
|
+
/**
|
111
|
+
* Options for creating a procedure caller with comprehensive type safety
|
112
|
+
*/
|
113
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
114
|
+
/**
|
115
|
+
* This is helpful for logging and analytics.
|
116
|
+
*/
|
117
|
+
path?: readonly string[];
|
118
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
|
119
|
+
} & (Record<never, never> extends TInitialContext ? {
|
120
|
+
context?: Value<TInitialContext, [clientContext: TClientContext]>;
|
121
|
+
} : {
|
122
|
+
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
123
|
+
});
|
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, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
125
|
+
|
126
|
+
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
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
128
|
+
};
|
129
|
+
type AnyRouter = Router<any, any>;
|
130
|
+
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
|
131
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
|
132
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
133
|
+
};
|
134
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
|
135
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
136
|
+
};
|
137
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
138
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
139
|
+
};
|
140
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
141
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
142
|
+
};
|
143
|
+
|
144
|
+
export { type AnyProcedure as A, type MiddlewareOptions as B, type Context as C, middlewareOutputFn as D, type ProcedureHandlerOptions as E, type ProcedureDef as F, isProcedure as G, createProcedureClient as H, type InferRouterInitialContext as I, type InferRouterInitialContexts as J, type InferRouterCurrentContexts as K, type Lazyable as L, type Middleware as M, type InferRouterInputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type InferRouterOutputs as Q, type Router as R, type AnyRouter as a, Procedure as b, type ContextExtendsGuard as c, type MergedCurrentContext as d, type MergedInitialContext as e, type MapInputMiddleware as f, type CreateProcedureClientOptions as g, type ProcedureClient as h, type AnyMiddleware as i, type Lazy as j, type ProcedureHandler as k, type ORPCErrorConstructorMapItemOptions as l, mergeCurrentContext as m, type ORPCErrorConstructorMapItem as n, createORPCErrorConstructorMap as o, LAZY_SYMBOL as p, type LazyMeta as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u, validateORPCError as v, type MiddlewareResult as w, type MiddlewareNextFnOptions as x, type MiddlewareNextFn as y, type MiddlewareOutputFn as z };
|