@orpc/server 0.0.0-next.9b9ade5 → 0.0.0-next.9dfcee8
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 +2 -1
- package/dist/adapters/fetch/index.d.mts +5 -3
- package/dist/adapters/fetch/index.d.ts +5 -3
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/hono/index.d.mts +4 -2
- package/dist/adapters/hono/index.d.ts +4 -2
- package/dist/adapters/hono/index.mjs +3 -3
- package/dist/adapters/next/index.d.mts +4 -2
- package/dist/adapters/next/index.d.ts +4 -2
- package/dist/adapters/next/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +5 -3
- package/dist/adapters/node/index.d.ts +5 -3
- package/dist/adapters/node/index.mjs +7 -6
- package/dist/adapters/standard/index.d.mts +9 -8
- package/dist/adapters/standard/index.d.ts +9 -8
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/index.d.mts +53 -44
- package/dist/index.d.ts +53 -44
- package/dist/index.mjs +21 -22
- package/dist/plugins/index.d.mts +3 -3
- package/dist/plugins/index.d.ts +3 -3
- package/dist/shared/{server.DmW25ynm.d.ts → server.B3Tm0IXY.d.ts} +2 -2
- package/dist/shared/{server.CPteJIPP.d.mts → server.BYTulgUc.d.mts} +12 -11
- package/dist/shared/{server.CPteJIPP.d.ts → server.BYTulgUc.d.ts} +12 -11
- package/dist/shared/{server.CM3tWr3C.d.mts → server.BeJithK4.d.mts} +2 -2
- package/dist/shared/{server.CMrS28Go.mjs → server.BtxZnWJ9.mjs} +35 -7
- package/dist/shared/server.Bz_xNBjz.d.mts +8 -0
- package/dist/shared/{server.Cq3B6PoL.mjs → server.DoP20NVH.mjs} +6 -5
- package/dist/shared/server.EhgR_5_I.d.ts +8 -0
- package/dist/shared/{server.CSZRzcSW.mjs → server.jG7ZuX3S.mjs} +4 -4
- package/package.json +7 -7
@@ -1,7 +1,7 @@
|
|
1
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.mjs';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
6
6
|
|
7
7
|
type StandardParams = Record<string, string>;
|
@@ -72,4 +72,4 @@ declare class CompositePlugin<TContext extends Context> implements HandlerPlugin
|
|
72
72
|
init(options: StandardHandlerOptions<TContext>): void;
|
73
73
|
}
|
74
74
|
|
75
|
-
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, 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 };
|
@@ -21,7 +21,24 @@ function unlazy(lazied) {
|
|
21
21
|
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
|
22
22
|
}
|
23
23
|
|
24
|
-
function
|
24
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
25
|
+
if (compare.length > middlewares.length) {
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
for (let i = 0; i < middlewares.length; i++) {
|
29
|
+
if (compare[i] === void 0) {
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
if (middlewares[i] !== compare[i]) {
|
33
|
+
return false;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
function mergeMiddlewares(first, second, options) {
|
39
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
40
|
+
return second;
|
41
|
+
}
|
25
42
|
return [...first, ...second];
|
26
43
|
}
|
27
44
|
function addMiddleware(middlewares, addition) {
|
@@ -41,6 +58,10 @@ function isProcedure(item) {
|
|
41
58
|
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
42
59
|
}
|
43
60
|
|
61
|
+
function mergeCurrentContext(context, other) {
|
62
|
+
return { ...context, ...other };
|
63
|
+
}
|
64
|
+
|
44
65
|
function createORPCErrorConstructorMap(errors) {
|
45
66
|
const proxy = new Proxy(errors, {
|
46
67
|
get(target, code) {
|
@@ -153,23 +174,30 @@ async function executeProcedureInternal(procedure, options) {
|
|
153
174
|
let currentInput = options.input;
|
154
175
|
const next = async (...[nextOptions]) => {
|
155
176
|
const index = currentIndex;
|
177
|
+
const midContext = nextOptions?.context ?? {};
|
156
178
|
currentIndex += 1;
|
157
|
-
currentContext =
|
179
|
+
currentContext = mergeCurrentContext(currentContext, midContext);
|
158
180
|
if (index === inputValidationIndex) {
|
159
181
|
currentInput = await validateInput(procedure, currentInput);
|
160
182
|
}
|
161
183
|
const mid = middlewares[index];
|
162
|
-
const result = mid ?
|
184
|
+
const result = mid ? {
|
185
|
+
context: midContext,
|
186
|
+
output: (await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn)).output
|
187
|
+
} : {
|
188
|
+
context: midContext,
|
189
|
+
output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput })
|
190
|
+
};
|
163
191
|
if (index === outputValidationIndex) {
|
164
192
|
const validatedOutput = await validateOutput(procedure, result.output);
|
165
193
|
return {
|
166
|
-
|
194
|
+
context: result.context,
|
167
195
|
output: validatedOutput
|
168
196
|
};
|
169
197
|
}
|
170
198
|
return result;
|
171
199
|
};
|
172
|
-
return (await next(
|
200
|
+
return (await next()).output;
|
173
201
|
}
|
174
202
|
|
175
203
|
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
@@ -239,7 +267,7 @@ function enhanceRouter(router, options) {
|
|
239
267
|
return accessible;
|
240
268
|
}
|
241
269
|
if (isProcedure(router)) {
|
242
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
|
270
|
+
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
|
243
271
|
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
244
272
|
const enhanced2 = new Procedure({
|
245
273
|
...router["~orpc"],
|
@@ -343,4 +371,4 @@ function toHttpPath(path) {
|
|
343
371
|
return `/${path.map(encodeURIComponent).join("/")}`;
|
344
372
|
}
|
345
373
|
|
346
|
-
export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i,
|
374
|
+
export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i, createORPCErrorConstructorMap as j, getLazyMeta as k, lazy as l, mergeCurrentContext as m, middlewareOutputFn as n, isStartWithMiddlewares as o, mergeMiddlewares as p, call as q, getHiddenRouterContract as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, createAccessibleLazyRouter as w, resolveContractProcedures as x, unlazyRouter as y };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.BYTulgUc.mjs';
|
3
|
+
import { a as StandardHandlerOptions } from './server.BeJithK4.mjs';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|
@@ -1,13 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
2
|
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
-
import { S as StandardHandler,
|
3
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.jG7ZuX3S.mjs';
|
4
4
|
|
5
5
|
class RPCHandler {
|
6
6
|
standardHandler;
|
7
7
|
constructor(router, options = {}) {
|
8
|
-
const
|
9
|
-
const
|
10
|
-
const
|
8
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
9
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
10
|
+
const matcher = new StandardRPCMatcher();
|
11
|
+
const codec = new StandardRPCCodec(serializer);
|
11
12
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
12
13
|
}
|
13
14
|
async handle(request, ...[
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.BYTulgUc.js';
|
3
|
+
import { a as StandardHandlerOptions } from './server.B3Tm0IXY.js';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|
@@ -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, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.
|
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.BtxZnWJ9.mjs';
|
5
5
|
|
6
6
|
class StandardHandler {
|
7
7
|
constructor(router, matcher, codec, options) {
|
@@ -69,7 +69,7 @@ class StandardHandler {
|
|
69
69
|
}
|
70
70
|
}
|
71
71
|
|
72
|
-
class
|
72
|
+
class StandardRPCCodec {
|
73
73
|
constructor(serializer) {
|
74
74
|
this.serializer = serializer;
|
75
75
|
}
|
@@ -93,7 +93,7 @@ class RPCCodec {
|
|
93
93
|
}
|
94
94
|
}
|
95
95
|
|
96
|
-
class
|
96
|
+
class StandardRPCMatcher {
|
97
97
|
tree = {};
|
98
98
|
pendingRouters = [];
|
99
99
|
init(router, path = []) {
|
@@ -155,4 +155,4 @@ class RPCMatcher {
|
|
155
155
|
}
|
156
156
|
}
|
157
157
|
|
158
|
-
export {
|
158
|
+
export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.9dfcee8",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -58,12 +58,12 @@
|
|
58
58
|
"next": ">=14.0.0"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@orpc/
|
62
|
-
"@orpc/
|
63
|
-
"@orpc/
|
64
|
-
"@orpc/
|
65
|
-
"@orpc/standard-server-fetch": "0.0.0-next.
|
66
|
-
"@orpc/standard-server-node": "0.0.0-next.
|
61
|
+
"@orpc/client": "0.0.0-next.9dfcee8",
|
62
|
+
"@orpc/shared": "0.0.0-next.9dfcee8",
|
63
|
+
"@orpc/standard-server": "0.0.0-next.9dfcee8",
|
64
|
+
"@orpc/contract": "0.0.0-next.9dfcee8",
|
65
|
+
"@orpc/standard-server-fetch": "0.0.0-next.9dfcee8",
|
66
|
+
"@orpc/standard-server-node": "0.0.0-next.9dfcee8"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
69
|
"light-my-request": "^6.5.1"
|