@orpc/server 0.0.0-next.1431467 → 0.0.0-next.15d9202
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 +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/hono/index.d.mts +2 -2
- package/dist/adapters/hono/index.d.ts +2 -2
- package/dist/adapters/hono/index.mjs +3 -3
- package/dist/adapters/next/index.d.mts +2 -2
- package/dist/adapters/next/index.d.ts +2 -2
- package/dist/adapters/next/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +2 -2
- package/dist/adapters/standard/index.d.mts +4 -4
- package/dist/adapters/standard/index.d.ts +4 -4
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/index.d.mts +135 -112
- package/dist/index.d.ts +135 -112
- package/dist/index.mjs +56 -43
- 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.DKrKGnk2.mjs → server.3mOimouH.mjs} +8 -11
- package/dist/shared/{server.V6zT5iYQ.mjs → server.B_5ZADvP.mjs} +142 -158
- package/dist/shared/{server.BHIDiY4a.mjs → server.BgDZnmUZ.mjs} +1 -1
- package/dist/shared/{server.Drm1Lma3.d.ts → server.CL84X8p4.d.mts} +12 -14
- package/dist/shared/server.DnmJuN02.d.mts +144 -0
- package/dist/shared/server.DnmJuN02.d.ts +144 -0
- package/dist/shared/{server.CtBp-i4f.d.mts → server.hqPWnakL.d.ts} +12 -14
- package/package.json +7 -7
- package/dist/shared/server.ptXwNGQr.d.mts +0 -158
- package/dist/shared/server.ptXwNGQr.d.ts +0 -158
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.B_5ZADvP.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, b as createContractedProcedure, j as createORPCErrorConstructorMap, q as getHiddenRouterContract, k as getLazyMeta, n as isStartWithMiddlewares, o as mergeMiddlewares, m as middlewareOutputFn, w as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.B_5ZADvP.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,14 +217,13 @@ 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
|
226
|
+
function mergeCurrentContext(context, other) {
|
216
227
|
return { ...context, ...other };
|
217
228
|
}
|
218
229
|
|
@@ -223,12 +234,16 @@ function implementerInternal(contract, config, middlewares) {
|
|
223
234
|
config,
|
224
235
|
middlewares,
|
225
236
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
226
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
237
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
|
238
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
227
239
|
});
|
228
240
|
return impl2;
|
229
241
|
}
|
230
242
|
const impl = new Proxy(contract, {
|
231
243
|
get: (target, key) => {
|
244
|
+
if (typeof key !== "string") {
|
245
|
+
return Reflect.get(target, key);
|
246
|
+
}
|
232
247
|
let method;
|
233
248
|
if (key === "middleware") {
|
234
249
|
method = (mid) => decorateMiddleware(mid);
|
@@ -242,23 +257,29 @@ function implementerInternal(contract, config, middlewares) {
|
|
242
257
|
};
|
243
258
|
} else if (key === "router") {
|
244
259
|
method = (router) => {
|
245
|
-
const adapted =
|
260
|
+
const adapted = enhanceRouter(router, {
|
246
261
|
middlewares,
|
247
|
-
errorMap: {}
|
262
|
+
errorMap: {},
|
263
|
+
prefix: void 0,
|
264
|
+
tags: void 0,
|
265
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
248
266
|
});
|
249
|
-
return
|
267
|
+
return setHiddenRouterContract(adapted, contract);
|
250
268
|
};
|
251
269
|
} else if (key === "lazy") {
|
252
270
|
method = (loader) => {
|
253
|
-
const adapted =
|
271
|
+
const adapted = enhanceRouter(lazy(loader), {
|
254
272
|
middlewares,
|
255
|
-
errorMap: {}
|
273
|
+
errorMap: {},
|
274
|
+
prefix: void 0,
|
275
|
+
tags: void 0,
|
276
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
256
277
|
});
|
257
|
-
return
|
278
|
+
return setHiddenRouterContract(adapted, contract);
|
258
279
|
};
|
259
280
|
}
|
260
|
-
const next =
|
261
|
-
if (!next
|
281
|
+
const next = getContractRouter(target, [key]);
|
282
|
+
if (!next) {
|
262
283
|
return method ?? next;
|
263
284
|
}
|
264
285
|
const nextImpl = implementerInternal(next, config, middlewares);
|
@@ -285,42 +306,34 @@ function implement(contract, config = {}) {
|
|
285
306
|
method = (config2) => implement(contract, config2);
|
286
307
|
}
|
287
308
|
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
|
-
});
|
309
|
+
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
310
|
+
return method || next;
|
297
311
|
}
|
298
|
-
return
|
312
|
+
return new Proxy(method, {
|
313
|
+
get(_, key2) {
|
314
|
+
return Reflect.get(next, key2);
|
315
|
+
}
|
316
|
+
});
|
299
317
|
}
|
300
318
|
});
|
301
319
|
return impl;
|
302
320
|
}
|
303
321
|
|
304
|
-
function
|
305
|
-
return createProcedureClient(procedure, ...rest)(input);
|
306
|
-
}
|
307
|
-
|
308
|
-
function createRouterClient(router, ...rest) {
|
322
|
+
function createRouterClient(router, ...[options]) {
|
309
323
|
if (isProcedure(router)) {
|
310
|
-
const caller = createProcedureClient(router,
|
324
|
+
const caller = createProcedureClient(router, options);
|
311
325
|
return caller;
|
312
326
|
}
|
313
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(
|
327
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
314
328
|
const recursive = new Proxy(procedureCaller, {
|
315
329
|
get(target, key) {
|
316
330
|
if (typeof key !== "string") {
|
317
331
|
return Reflect.get(target, key);
|
318
332
|
}
|
319
|
-
const next =
|
333
|
+
const next = getRouter(router, [key]);
|
320
334
|
if (!next) {
|
321
335
|
return Reflect.get(target, key);
|
322
336
|
}
|
323
|
-
const [options] = rest;
|
324
337
|
return createRouterClient(next, {
|
325
338
|
...options,
|
326
339
|
path: [...options?.path ?? [], key]
|
@@ -330,4 +343,4 @@ function createRouterClient(router, ...rest) {
|
|
330
343
|
return recursive;
|
331
344
|
}
|
332
345
|
|
333
|
-
export { Builder, DecoratedProcedure, Procedure,
|
346
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, mergeCurrentContext, os, setHiddenRouterContract };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
import { a as StandardHandlerInterceptorOptions,
|
2
|
-
export { C as CompositePlugin } from '../shared/server.
|
1
|
+
import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CL84X8p4.mjs';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.CL84X8p4.mjs';
|
3
3
|
import { Value } from '@orpc/shared';
|
4
|
-
import { C as Context } from '../shared/server.
|
4
|
+
import { C as Context } from '../shared/server.DnmJuN02.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 { a as StandardHandlerInterceptorOptions,
|
2
|
-
export { C as CompositePlugin } from '../shared/server.
|
1
|
+
import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.hqPWnakL.js';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.hqPWnakL.js';
|
3
3
|
import { Value } from '@orpc/shared';
|
4
|
-
import { C as Context } from '../shared/server.
|
4
|
+
import { C as Context } from '../shared/server.DnmJuN02.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,7 +1,7 @@
|
|
1
1
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
2
|
import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
|
3
3
|
import { C as CompositePlugin } from './server.Q6ZmnTgO.mjs';
|
4
|
-
import { c as createProcedureClient,
|
4
|
+
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.B_5ZADvP.mjs';
|
5
5
|
|
6
6
|
class StandardHandler {
|
7
7
|
constructor(router, matcher, codec, options) {
|
@@ -97,11 +97,8 @@ class RPCMatcher {
|
|
97
97
|
tree = {};
|
98
98
|
pendingRouters = [];
|
99
99
|
init(router, path = []) {
|
100
|
-
const laziedOptions =
|
101
|
-
|
102
|
-
path
|
103
|
-
}, ({ path: path2, contract }) => {
|
104
|
-
const httpPath = convertPathToHttpPath(path2);
|
100
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
101
|
+
const httpPath = toHttpPath(path2);
|
105
102
|
if (isProcedure(contract)) {
|
106
103
|
this.tree[httpPath] = {
|
107
104
|
path: path2,
|
@@ -121,7 +118,7 @@ class RPCMatcher {
|
|
121
118
|
});
|
122
119
|
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
123
120
|
...option,
|
124
|
-
httpPathPrefix:
|
121
|
+
httpPathPrefix: toHttpPath(option.path)
|
125
122
|
})));
|
126
123
|
}
|
127
124
|
async match(_method, pathname) {
|
@@ -129,7 +126,7 @@ class RPCMatcher {
|
|
129
126
|
const newPendingRouters = [];
|
130
127
|
for (const pendingRouter of this.pendingRouters) {
|
131
128
|
if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
132
|
-
const { default: router } = await unlazy(pendingRouter.
|
129
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
133
130
|
this.init(router, pendingRouter.path);
|
134
131
|
} else {
|
135
132
|
newPendingRouters.push(pendingRouter);
|
@@ -142,14 +139,14 @@ class RPCMatcher {
|
|
142
139
|
return void 0;
|
143
140
|
}
|
144
141
|
if (!match.procedure) {
|
145
|
-
const { default: maybeProcedure } = await unlazy(
|
142
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
|
146
143
|
if (!isProcedure(maybeProcedure)) {
|
147
144
|
throw new Error(`
|
148
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${
|
145
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
|
149
146
|
Ensure that the procedure is correctly defined and matches the expected contract.
|
150
147
|
`);
|
151
148
|
}
|
152
|
-
match.procedure = createContractedProcedure(match.contract
|
149
|
+
match.procedure = createContractedProcedure(maybeProcedure, match.contract);
|
153
150
|
}
|
154
151
|
return {
|
155
152
|
path: match.path,
|