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