@temporary-name/server 1.9.3-alpha.592ae1e02e18c5274906b132313b083116248636 → 1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e
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/dist/adapters/aws-lambda/index.d.mts +3 -3
- package/dist/adapters/aws-lambda/index.d.ts +3 -3
- package/dist/adapters/aws-lambda/index.mjs +4 -6
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +4 -6
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +4 -6
- package/dist/adapters/standard/index.d.mts +14 -30
- package/dist/adapters/standard/index.d.ts +14 -30
- package/dist/adapters/standard/index.mjs +4 -6
- package/dist/index.d.mts +60 -334
- package/dist/index.d.ts +60 -334
- package/dist/index.mjs +111 -354
- package/dist/openapi/index.mjs +30 -64
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.BKSOrA6h.d.mts → server.B5czSQQh.d.mts} +114 -71
- package/dist/shared/{server.BKSOrA6h.d.ts → server.B5czSQQh.d.ts} +114 -71
- package/dist/shared/server.BdGbIyq8.mjs +396 -0
- package/dist/shared/{server.BeuTpcmO.d.mts → server.Bk8Hmx7Z.d.mts} +2 -2
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.C4l2ZA3m.d.ts} +1 -2
- package/dist/shared/{server.SLLuK6_v.d.ts → server.D7UjcuIv.d.ts} +2 -2
- package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
- package/dist/shared/{server.DLsti1Pv.mjs → server.SmOM3Fae.mjs} +58 -89
- package/dist/shared/{server.C1fnTLq0.d.mts → server.TgmlNh8r.d.mts} +1 -2
- package/package.json +10 -9
- package/dist/shared/server.BKh8I1Ny.mjs +0 -239
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Meta } from '@temporary-name/contract';
|
|
2
2
|
import { HTTPPath, Interceptor } from '@temporary-name/shared';
|
|
3
3
|
import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
|
|
4
|
-
import { C as Context, R as Router,
|
|
4
|
+
import { C as Context, R as Router, H as ProcedureClientInterceptorOptions } from './server.B5czSQQh.js';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|
|
@@ -48,7 +48,6 @@ declare class StandardHandler<T extends Context> {
|
|
|
48
48
|
private readonly clientInterceptors;
|
|
49
49
|
private readonly rootInterceptors;
|
|
50
50
|
private readonly matcher;
|
|
51
|
-
private readonly codec;
|
|
52
51
|
constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
|
|
53
52
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
54
53
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTTPPath } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context } from './server.
|
|
3
|
-
import { c as StandardHandleOptions } from './server.
|
|
2
|
+
import { C as Context } from './server.B5czSQQh.js';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.C4l2ZA3m.js';
|
|
4
4
|
|
|
5
5
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
6
|
context?: T;
|
|
@@ -244,4 +244,4 @@ function getDynamicParams(path) {
|
|
|
244
244
|
})) : void 0;
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
export { standardizeHTTPPath as a, deserialize as d, getDynamicParams as g, jsonSerialize as j, serialize as s };
|
|
247
|
+
export { standardizeHTTPPath as a, bracketNotationDeserialize as b, deserialize as d, getDynamicParams as g, jsonSerialize as j, serialize as s };
|
|
@@ -1,67 +1,45 @@
|
|
|
1
|
-
import { isObject, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent,
|
|
1
|
+
import { isObject, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { flattenHeader } from '@temporary-name/standard-server';
|
|
3
|
-
import { c as createProcedureClient } from './server.
|
|
3
|
+
import { c as createProcedureClient } from './server.BdGbIyq8.mjs';
|
|
4
4
|
import { fallbackContractConfig } from '@temporary-name/contract';
|
|
5
|
-
import { d as deserialize, s as serialize, a as standardizeHTTPPath } from './server.
|
|
5
|
+
import { d as deserialize, s as serialize, b as bracketNotationDeserialize, a as standardizeHTTPPath } from './server.Kxw442A9.mjs';
|
|
6
6
|
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
|
|
7
7
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
async function decode(request, pathParams) {
|
|
10
|
+
const deserializeSearchParams = () => {
|
|
11
|
+
return bracketNotationDeserialize(Array.from(request.url.searchParams.entries()));
|
|
12
|
+
};
|
|
13
|
+
const data = request.method === "GET" ? deserializeSearchParams() : deserialize(await request.body());
|
|
14
|
+
if (data === void 0) {
|
|
15
|
+
return pathParams;
|
|
11
16
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
);
|
|
17
|
-
if (inputStructure === "compact") {
|
|
18
|
-
const data = request.method === "GET" ? deserialize(request.url.searchParams) : deserialize(await request.body());
|
|
19
|
-
if (data === void 0) {
|
|
20
|
-
return params;
|
|
21
|
-
}
|
|
22
|
-
if (isObject(data)) {
|
|
23
|
-
return {
|
|
24
|
-
...params,
|
|
25
|
-
...data
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
const deserializeSearchParams = () => {
|
|
31
|
-
return deserialize(request.url.searchParams);
|
|
17
|
+
if (isObject(data)) {
|
|
18
|
+
return {
|
|
19
|
+
...pathParams,
|
|
20
|
+
...data
|
|
32
21
|
};
|
|
22
|
+
}
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
function encode(output, procedure) {
|
|
26
|
+
const successStatus = fallbackContractConfig(
|
|
27
|
+
"defaultSuccessStatus",
|
|
28
|
+
procedure["~orpc"].route.successStatus
|
|
29
|
+
);
|
|
30
|
+
const outputStructure = fallbackContractConfig(
|
|
31
|
+
"defaultOutputStructure",
|
|
32
|
+
procedure["~orpc"].route.outputStructure
|
|
33
|
+
);
|
|
34
|
+
if (outputStructure === "compact") {
|
|
33
35
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Object.defineProperty(this, "query", { value, writable: true });
|
|
38
|
-
return value;
|
|
39
|
-
},
|
|
40
|
-
set query(value) {
|
|
41
|
-
Object.defineProperty(this, "query", { value, writable: true });
|
|
42
|
-
},
|
|
43
|
-
headers: request.headers,
|
|
44
|
-
body: deserialize(await request.body())
|
|
36
|
+
status: successStatus,
|
|
37
|
+
headers: {},
|
|
38
|
+
body: serialize(output)
|
|
45
39
|
};
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"defaultSuccessStatus",
|
|
50
|
-
procedure["~orpc"].route.successStatus
|
|
51
|
-
);
|
|
52
|
-
const outputStructure = fallbackContractConfig(
|
|
53
|
-
"defaultOutputStructure",
|
|
54
|
-
procedure["~orpc"].route.outputStructure
|
|
55
|
-
);
|
|
56
|
-
if (outputStructure === "compact") {
|
|
57
|
-
return {
|
|
58
|
-
status: successStatus,
|
|
59
|
-
headers: {},
|
|
60
|
-
body: serialize(output)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (!this.#isDetailedOutput(output)) {
|
|
64
|
-
throw new Error(`
|
|
41
|
+
if (!isDetailedOutput(output)) {
|
|
42
|
+
throw new Error(`
|
|
65
43
|
Invalid "detailed" output structure:
|
|
66
44
|
\u2022 Expected an object with optional properties:
|
|
67
45
|
- status (number 200-399)
|
|
@@ -72,32 +50,31 @@ class StandardOpenAPICodec {
|
|
|
72
50
|
Actual value:
|
|
73
51
|
${stringifyJSON(output)}
|
|
74
52
|
`);
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
status: output.status ?? successStatus,
|
|
78
|
-
headers: output.headers ?? {},
|
|
79
|
-
body: serialize(output.body)
|
|
80
|
-
};
|
|
81
53
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
54
|
+
return {
|
|
55
|
+
status: output.status ?? successStatus,
|
|
56
|
+
headers: output.headers ?? {},
|
|
57
|
+
body: serialize(output.body)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function encodeError(error) {
|
|
61
|
+
return {
|
|
62
|
+
status: error.status,
|
|
63
|
+
headers: {},
|
|
64
|
+
body: serialize(error.toJSON(), { outputFormat: "plain" })
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function isDetailedOutput(output) {
|
|
68
|
+
if (!isObject(output)) {
|
|
69
|
+
return false;
|
|
88
70
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
71
|
+
if (output.headers && !isObject(output.headers)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
75
|
+
return false;
|
|
100
76
|
}
|
|
77
|
+
return true;
|
|
101
78
|
}
|
|
102
79
|
|
|
103
80
|
function resolveFriendlyStandardHandleOptions(options) {
|
|
@@ -121,9 +98,6 @@ class StandardOpenAPIMatcher {
|
|
|
121
98
|
pendingRouters = [];
|
|
122
99
|
init(router, path = []) {
|
|
123
100
|
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
|
124
|
-
if (!value(true, traverseOptions)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
101
|
const { path: path2, contract } = traverseOptions;
|
|
128
102
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
129
103
|
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
@@ -204,10 +178,8 @@ class StandardHandler {
|
|
|
204
178
|
clientInterceptors;
|
|
205
179
|
rootInterceptors;
|
|
206
180
|
matcher;
|
|
207
|
-
codec;
|
|
208
181
|
constructor(router, options) {
|
|
209
182
|
this.matcher = new StandardOpenAPIMatcher();
|
|
210
|
-
this.codec = new StandardOpenAPICodec();
|
|
211
183
|
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
|
|
212
184
|
plugins.init(options, router);
|
|
213
185
|
this.interceptors = toArray(options.interceptors);
|
|
@@ -242,10 +214,7 @@ class StandardHandler {
|
|
|
242
214
|
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
243
215
|
span?.setAttribute("rpc.method", match.path.join("."));
|
|
244
216
|
step = "decode_input";
|
|
245
|
-
let input = await runWithSpan(
|
|
246
|
-
{ name: "decode_input" },
|
|
247
|
-
() => this.codec.decode(request2, match.params, match.procedure)
|
|
248
|
-
);
|
|
217
|
+
let input = await runWithSpan({ name: "decode_input" }, () => decode(request2, match.params));
|
|
249
218
|
step = void 0;
|
|
250
219
|
if (isAsyncIteratorObject(input)) {
|
|
251
220
|
input = asyncIteratorWithSpan(
|
|
@@ -264,7 +233,7 @@ class StandardHandler {
|
|
|
264
233
|
lastEventId: flattenHeader(request2.headers["last-event-id"])
|
|
265
234
|
});
|
|
266
235
|
step = void 0;
|
|
267
|
-
const response =
|
|
236
|
+
const response = encode(output, match.procedure);
|
|
268
237
|
return {
|
|
269
238
|
matched: true,
|
|
270
239
|
response
|
|
@@ -279,7 +248,7 @@ class StandardHandler {
|
|
|
279
248
|
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
|
280
249
|
cause: e
|
|
281
250
|
}) : toORPCError(e);
|
|
282
|
-
const response =
|
|
251
|
+
const response = encodeError(error);
|
|
283
252
|
return {
|
|
284
253
|
matched: true,
|
|
285
254
|
response
|
|
@@ -290,4 +259,4 @@ class StandardHandler {
|
|
|
290
259
|
}
|
|
291
260
|
}
|
|
292
261
|
|
|
293
|
-
export { CompositeStandardHandlerPlugin as C, StandardHandler as S,
|
|
262
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, encodeError as a, StandardOpenAPIMatcher as b, decodeParams as c, decode as d, encode as e, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Meta } from '@temporary-name/contract';
|
|
2
2
|
import { HTTPPath, Interceptor } from '@temporary-name/shared';
|
|
3
3
|
import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
|
|
4
|
-
import { C as Context, R as Router,
|
|
4
|
+
import { C as Context, R as Router, H as ProcedureClientInterceptorOptions } from './server.B5czSQQh.mjs';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|
|
@@ -48,7 +48,6 @@ declare class StandardHandler<T extends Context> {
|
|
|
48
48
|
private readonly clientInterceptors;
|
|
49
49
|
private readonly rootInterceptors;
|
|
50
50
|
private readonly matcher;
|
|
51
|
-
private readonly codec;
|
|
52
51
|
constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
|
|
53
52
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
54
53
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporary-name/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.9.3-alpha.
|
|
4
|
+
"version": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -71,16 +71,17 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"cookie": "^1.0.2",
|
|
74
|
-
"@standard-schema/spec": "^1.0.0",
|
|
75
74
|
"rou3": "^0.7.7",
|
|
76
75
|
"zod": "^4.1.12",
|
|
77
|
-
"@temporary-name/interop": "1.9.3-alpha.
|
|
78
|
-
"@temporary-name/
|
|
79
|
-
"@temporary-name/shared": "1.9.3-alpha.
|
|
80
|
-
"@temporary-name/
|
|
81
|
-
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.
|
|
82
|
-
"@temporary-name/
|
|
83
|
-
"@temporary-name/standard-server-
|
|
76
|
+
"@temporary-name/interop": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
77
|
+
"@temporary-name/json-schema": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
78
|
+
"@temporary-name/shared": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
79
|
+
"@temporary-name/standard-server": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
80
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
81
|
+
"@temporary-name/contract": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
82
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
83
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
|
|
84
|
+
"@temporary-name/zod": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
87
|
"@types/supertest": "^6.0.3",
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { validateORPCError, ValidationError } from '@temporary-name/contract';
|
|
2
|
-
import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
|
|
3
|
-
import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
|
|
4
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
|
-
import 'zod';
|
|
6
|
-
import * as z4 from 'zod/v4/core';
|
|
7
|
-
|
|
8
|
-
const gatingContext = new AsyncLocalStorage();
|
|
9
|
-
function withoutGatedFields(data, schema, isGateEnabled) {
|
|
10
|
-
const filtered = { ...data };
|
|
11
|
-
const gatedFields = getGatedFields(schema);
|
|
12
|
-
for (const [fieldName, gate] of gatedFields) {
|
|
13
|
-
if (!isGateEnabled(gate)) {
|
|
14
|
-
delete filtered[fieldName];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return filtered;
|
|
18
|
-
}
|
|
19
|
-
function getGatedFields(schema) {
|
|
20
|
-
if (!schema || schema["~standard"].vendor !== "zod") {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
const gatedFields = [];
|
|
24
|
-
const zodDef = schema._zod.def;
|
|
25
|
-
if (zodDef.type === "object") {
|
|
26
|
-
const shape = zodDef.shape;
|
|
27
|
-
for (const fieldName in shape) {
|
|
28
|
-
const fieldSchema = shape[fieldName];
|
|
29
|
-
const gate = z4.globalRegistry.get(fieldSchema)?.gate;
|
|
30
|
-
if (gate) {
|
|
31
|
-
gatedFields.push([fieldName, gate]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return gatedFields;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
|
39
|
-
function lazy(loader, meta = {}) {
|
|
40
|
-
return {
|
|
41
|
-
[LAZY_SYMBOL]: {
|
|
42
|
-
loader,
|
|
43
|
-
meta
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function isLazy(item) {
|
|
48
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
|
|
49
|
-
}
|
|
50
|
-
function getLazyMeta(lazied) {
|
|
51
|
-
return lazied[LAZY_SYMBOL].meta;
|
|
52
|
-
}
|
|
53
|
-
function unlazy(lazied) {
|
|
54
|
-
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function mergeCurrentContext(context, other) {
|
|
58
|
-
return { ...context, ...other };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function createORPCErrorConstructorMap(errors) {
|
|
62
|
-
const proxy = new Proxy(errors, {
|
|
63
|
-
get(target, code) {
|
|
64
|
-
if (typeof code !== "string") {
|
|
65
|
-
return Reflect.get(target, code);
|
|
66
|
-
}
|
|
67
|
-
const item = (...rest) => {
|
|
68
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
69
|
-
const config = errors[code];
|
|
70
|
-
return new ORPCError(code, {
|
|
71
|
-
defined: Boolean(config),
|
|
72
|
-
status: config?.status,
|
|
73
|
-
message: options.message ?? config?.message,
|
|
74
|
-
data: options.data,
|
|
75
|
-
cause: options.cause
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
return item;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return proxy;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function middlewareOutputFn(output) {
|
|
85
|
-
return { output, context: {} };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function createProcedureClient(lazyableProcedure, ...rest) {
|
|
89
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
90
|
-
return async (...[input, callerOptions]) => {
|
|
91
|
-
const path = toArray(options.path);
|
|
92
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
93
|
-
const clientContext = callerOptions?.context ?? {};
|
|
94
|
-
const context = await value(options.context ?? {}, clientContext);
|
|
95
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
|
|
96
|
-
const validateError = async (e) => {
|
|
97
|
-
if (e instanceof ORPCError) {
|
|
98
|
-
return await validateORPCError(procedure["~orpc"].errorMap, e);
|
|
99
|
-
}
|
|
100
|
-
return e;
|
|
101
|
-
};
|
|
102
|
-
try {
|
|
103
|
-
const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
|
|
104
|
-
span?.setAttribute("procedure.path", [...path]);
|
|
105
|
-
return intercept(
|
|
106
|
-
toArray(options.interceptors),
|
|
107
|
-
{
|
|
108
|
-
context,
|
|
109
|
-
input,
|
|
110
|
-
// input only optional when it undefinable so we can safely cast it
|
|
111
|
-
errors,
|
|
112
|
-
path,
|
|
113
|
-
procedure,
|
|
114
|
-
signal: callerOptions?.signal,
|
|
115
|
-
lastEventId: callerOptions?.lastEventId
|
|
116
|
-
},
|
|
117
|
-
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
|
118
|
-
);
|
|
119
|
-
});
|
|
120
|
-
if (isAsyncIteratorObject(output)) {
|
|
121
|
-
if (output instanceof HibernationEventIterator) {
|
|
122
|
-
return output;
|
|
123
|
-
}
|
|
124
|
-
return overlayProxy(
|
|
125
|
-
output,
|
|
126
|
-
mapEventIterator(
|
|
127
|
-
asyncIteratorWithSpan(
|
|
128
|
-
{ name: "consume_event_iterator_output", signal: callerOptions?.signal },
|
|
129
|
-
output
|
|
130
|
-
),
|
|
131
|
-
{
|
|
132
|
-
value: (v) => v,
|
|
133
|
-
error: (e) => validateError(e)
|
|
134
|
-
}
|
|
135
|
-
)
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
return output;
|
|
139
|
-
} catch (e) {
|
|
140
|
-
throw await validateError(e);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
async function validateInput(procedure, input) {
|
|
145
|
-
const schema = procedure["~orpc"].inputSchema;
|
|
146
|
-
if (!schema) {
|
|
147
|
-
return input;
|
|
148
|
-
}
|
|
149
|
-
return runWithSpan({ name: "validate_input" }, async () => {
|
|
150
|
-
const result = await schema["~standard"].validate(input);
|
|
151
|
-
if (result.issues) {
|
|
152
|
-
throw new ORPCError("BAD_REQUEST", {
|
|
153
|
-
message: "Input validation failed",
|
|
154
|
-
data: {
|
|
155
|
-
issues: result.issues
|
|
156
|
-
},
|
|
157
|
-
cause: new ValidationError({
|
|
158
|
-
message: "Input validation failed",
|
|
159
|
-
issues: result.issues,
|
|
160
|
-
data: input
|
|
161
|
-
})
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return result.value;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
async function validateOutput(schema, output) {
|
|
168
|
-
return runWithSpan({ name: "validate_output" }, async () => {
|
|
169
|
-
const result = await schema["~standard"].validate(output);
|
|
170
|
-
if (result.issues) {
|
|
171
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
172
|
-
message: "Output validation failed",
|
|
173
|
-
cause: new ValidationError({
|
|
174
|
-
message: "Output validation failed",
|
|
175
|
-
issues: result.issues,
|
|
176
|
-
data: output
|
|
177
|
-
})
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return result.value;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
async function executeProcedureInternal(procedure, options) {
|
|
184
|
-
const middlewares = procedure["~orpc"].middlewares;
|
|
185
|
-
const inputValidationIndex = Math.min(
|
|
186
|
-
Math.max(0, procedure["~orpc"].inputValidationIndex),
|
|
187
|
-
middlewares.length
|
|
188
|
-
);
|
|
189
|
-
const outputValidationIndex = Math.min(
|
|
190
|
-
Math.max(0, procedure["~orpc"].outputValidationIndex),
|
|
191
|
-
middlewares.length
|
|
192
|
-
);
|
|
193
|
-
const next = async (index, context, input) => {
|
|
194
|
-
let currentInput = input;
|
|
195
|
-
if (index === inputValidationIndex) {
|
|
196
|
-
currentInput = await validateInput(procedure, currentInput);
|
|
197
|
-
}
|
|
198
|
-
const mid = middlewares[index];
|
|
199
|
-
const output = mid ? await runWithSpan({ name: `middleware.${mid.name}`, signal: options.signal }, async (span) => {
|
|
200
|
-
span?.setAttribute("middleware.index", index);
|
|
201
|
-
span?.setAttribute("middleware.name", mid.name);
|
|
202
|
-
const result = await mid(
|
|
203
|
-
{
|
|
204
|
-
...options,
|
|
205
|
-
context,
|
|
206
|
-
next: async (...[nextOptions]) => {
|
|
207
|
-
const nextContext = nextOptions?.context ?? {};
|
|
208
|
-
return {
|
|
209
|
-
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
|
|
210
|
-
context: nextContext
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
currentInput,
|
|
215
|
-
middlewareOutputFn
|
|
216
|
-
);
|
|
217
|
-
return result.output;
|
|
218
|
-
}) : await runWithSpan(
|
|
219
|
-
{ name: "handler", signal: options.signal },
|
|
220
|
-
() => procedure["~orpc"].handler({ ...options, context, input: currentInput })
|
|
221
|
-
);
|
|
222
|
-
if (index === outputValidationIndex) {
|
|
223
|
-
const schema = procedure["~orpc"].outputSchema;
|
|
224
|
-
if (!schema) {
|
|
225
|
-
return output;
|
|
226
|
-
}
|
|
227
|
-
const validated = await validateOutput(schema, output);
|
|
228
|
-
const isGateEnabled = gatingContext.getStore();
|
|
229
|
-
if (!validated || !isGateEnabled) {
|
|
230
|
-
return validated;
|
|
231
|
-
}
|
|
232
|
-
return withoutGatedFields(validated, schema, isGateEnabled);
|
|
233
|
-
}
|
|
234
|
-
return output;
|
|
235
|
-
};
|
|
236
|
-
return next(0, options.context, options.input);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export { LAZY_SYMBOL as L, gatingContext as a, createORPCErrorConstructorMap as b, createProcedureClient as c, middlewareOutputFn as d, getLazyMeta as g, isLazy as i, lazy as l, mergeCurrentContext as m, unlazy as u };
|