@temporary-name/server 1.9.3-alpha.6f8b694b2a090fe0182bfd5f16d29ca20f259307 → 1.9.3-alpha.70ac9623e5fa2a8af7954e34ef97cee968e5cad9
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 +5 -7
- package/dist/adapters/aws-lambda/index.d.ts +5 -7
- package/dist/adapters/aws-lambda/index.mjs +6 -9
- package/dist/adapters/fetch/index.d.mts +8 -86
- package/dist/adapters/fetch/index.d.ts +8 -86
- package/dist/adapters/fetch/index.mjs +18 -160
- package/dist/adapters/node/index.d.mts +9 -64
- package/dist/adapters/node/index.d.ts +9 -64
- package/dist/adapters/node/index.mjs +16 -125
- package/dist/handler/index.d.mts +28 -0
- package/dist/handler/index.d.ts +28 -0
- package/dist/handler/index.mjs +8 -0
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +373 -493
- package/dist/index.d.ts +373 -493
- package/dist/index.mjs +547 -469
- package/dist/openapi/index.d.mts +18 -53
- package/dist/openapi/index.d.ts +18 -53
- package/dist/openapi/index.mjs +384 -378
- package/dist/shared/server.BGG3eatg.mjs +315 -0
- package/dist/shared/server.BJw16psR.d.mts +39 -0
- package/dist/shared/server.BM9lK_Yv.mjs +523 -0
- package/dist/shared/server.BpMVFPn5.d.ts +39 -0
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.CjPiuQYH.d.mts +51 -0
- package/dist/shared/server.CjPiuQYH.d.ts +51 -0
- package/dist/shared/server.CmNVzZVe.mjs +156 -0
- package/dist/shared/server.DX_j7xyF.d.mts +805 -0
- package/dist/shared/server.DX_j7xyF.d.ts +805 -0
- package/dist/shared/server.X8F6e8eV.mjs +499 -0
- package/package.json +13 -30
- package/dist/adapters/standard/index.d.mts +0 -42
- package/dist/adapters/standard/index.d.ts +0 -42
- package/dist/adapters/standard/index.mjs +0 -11
- package/dist/plugins/index.d.mts +0 -160
- package/dist/plugins/index.d.ts +0 -160
- package/dist/plugins/index.mjs +0 -288
- package/dist/shared/server.BEHw7Eyx.mjs +0 -247
- package/dist/shared/server.BKSOrA6h.d.mts +0 -192
- package/dist/shared/server.BKSOrA6h.d.ts +0 -192
- package/dist/shared/server.BKh8I1Ny.mjs +0 -239
- package/dist/shared/server.BeuTpcmO.d.mts +0 -23
- package/dist/shared/server.C1fnTLq0.d.mts +0 -57
- package/dist/shared/server.CQyYNJ1H.d.ts +0 -57
- package/dist/shared/server.DLsti1Pv.mjs +0 -293
- package/dist/shared/server.SLLuK6_v.d.ts +0 -23
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
|
|
2
|
+
import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
|
|
3
|
+
import { safeDecodeAsync, safeEncodeAsync } from '@temporary-name/zod';
|
|
4
|
+
import { u as unlazy, B as BadRequestError, V as ValidationError, I as InternalServerError } from './server.X8F6e8eV.mjs';
|
|
5
|
+
|
|
6
|
+
function mergeCurrentContext(context, other) {
|
|
7
|
+
return { ...context, ...other };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function middlewareOutputFn(output) {
|
|
11
|
+
return { output, context: {} };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function createProcedureClient(lazyableProcedure, ...rest) {
|
|
15
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
16
|
+
return async (...[input, callerOptions]) => {
|
|
17
|
+
const path = toArray(options.path);
|
|
18
|
+
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
19
|
+
const clientContext = callerOptions?.context ?? {};
|
|
20
|
+
const context = await value(options.context ?? {}, clientContext);
|
|
21
|
+
const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
|
|
22
|
+
span?.setAttribute("procedure.path", [...path]);
|
|
23
|
+
return executeProcedureInternal(procedure, input, {
|
|
24
|
+
context,
|
|
25
|
+
path,
|
|
26
|
+
procedure,
|
|
27
|
+
request: callerOptions?.request,
|
|
28
|
+
signal: callerOptions?.signal,
|
|
29
|
+
lastEventId: callerOptions?.lastEventId
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
if (isAsyncIteratorObject(output)) {
|
|
33
|
+
if (output instanceof HibernationEventIterator) {
|
|
34
|
+
return output;
|
|
35
|
+
}
|
|
36
|
+
return overlayProxy(
|
|
37
|
+
output,
|
|
38
|
+
mapEventIterator(
|
|
39
|
+
asyncIteratorWithSpan(
|
|
40
|
+
{ name: "consume_event_iterator_output", signal: callerOptions?.signal },
|
|
41
|
+
output
|
|
42
|
+
),
|
|
43
|
+
{
|
|
44
|
+
value: (v) => v,
|
|
45
|
+
error: async (e) => e
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return output;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function validateInput(procedure, input) {
|
|
54
|
+
const schemas = procedure["~orpc"].schemas;
|
|
55
|
+
return runWithSpan({ name: "validate_input" }, async () => {
|
|
56
|
+
const resultBody = await safeDecodeAsync(schemas.bodySchema, input.body, { parseType: "body" });
|
|
57
|
+
const resultPath = await safeDecodeAsync(schemas.pathSchema, input.path, { parseType: "path" });
|
|
58
|
+
const resultQuery = await safeDecodeAsync(schemas.querySchema, input.query, { parseType: "query" });
|
|
59
|
+
const issues = [];
|
|
60
|
+
if (!resultBody.success) {
|
|
61
|
+
issues.push(...resultBody.error.issues.map((i) => ({ ...i, path: ["body", ...i.path] })));
|
|
62
|
+
}
|
|
63
|
+
if (!resultPath.success) {
|
|
64
|
+
issues.push(...resultPath.error.issues.map((i) => ({ ...i, path: ["path", ...i.path] })));
|
|
65
|
+
}
|
|
66
|
+
if (!resultQuery.success) {
|
|
67
|
+
issues.push(...resultQuery.error.issues.map((i) => ({ ...i, path: ["query", ...i.path] })));
|
|
68
|
+
}
|
|
69
|
+
if (issues.length > 0) {
|
|
70
|
+
throw new BadRequestError({
|
|
71
|
+
code: "input_validation_failed",
|
|
72
|
+
message: "Input validation failed",
|
|
73
|
+
cause: new ValidationError({
|
|
74
|
+
issues,
|
|
75
|
+
data: input
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const results = {
|
|
80
|
+
body: resultBody.data,
|
|
81
|
+
path: resultPath.data,
|
|
82
|
+
query: resultQuery.data
|
|
83
|
+
};
|
|
84
|
+
return results;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async function validateOutput(procedure, output) {
|
|
88
|
+
const schema = procedure["~orpc"].schemas.outputSchema;
|
|
89
|
+
if (!schema) {
|
|
90
|
+
return output;
|
|
91
|
+
}
|
|
92
|
+
return runWithSpan({ name: "validate_output" }, async () => {
|
|
93
|
+
const result = await safeEncodeAsync(schema, output, { parseType: "output" });
|
|
94
|
+
if (!result.success) {
|
|
95
|
+
throw new InternalServerError({
|
|
96
|
+
message: "Output validation failed",
|
|
97
|
+
cause: new ValidationError({
|
|
98
|
+
issues: result.error.issues,
|
|
99
|
+
data: output
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return result.data;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async function executeProcedureInternal(procedure, input, options) {
|
|
107
|
+
const middlewares = procedure["~orpc"].middlewares;
|
|
108
|
+
const inputValidationIndex = Math.min(
|
|
109
|
+
Math.max(0, procedure["~orpc"].inputValidationIndex),
|
|
110
|
+
middlewares.length
|
|
111
|
+
);
|
|
112
|
+
const outputValidationIndex = Math.min(
|
|
113
|
+
Math.max(0, procedure["~orpc"].outputValidationIndex),
|
|
114
|
+
middlewares.length
|
|
115
|
+
);
|
|
116
|
+
const next = async (index, context, input2) => {
|
|
117
|
+
let currentInput = input2;
|
|
118
|
+
if (index === inputValidationIndex) {
|
|
119
|
+
currentInput = await validateInput(procedure, currentInput);
|
|
120
|
+
}
|
|
121
|
+
const mid = middlewares[index];
|
|
122
|
+
const output = mid ? await runWithSpan({ name: `middleware.${mid.name}`, signal: options.signal }, async (span) => {
|
|
123
|
+
span?.setAttribute("middleware.index", index);
|
|
124
|
+
span?.setAttribute("middleware.name", mid.name);
|
|
125
|
+
const result = await mid(
|
|
126
|
+
{
|
|
127
|
+
...options,
|
|
128
|
+
context,
|
|
129
|
+
next: async (nextOptions) => {
|
|
130
|
+
const nextContext = nextOptions?.context ?? {};
|
|
131
|
+
return {
|
|
132
|
+
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
|
|
133
|
+
// NB: Pretty sure this isn't used (or meant to be used) at runtime, it's just there
|
|
134
|
+
// to get type inference in the builder (via the caller returning the output of next() in
|
|
135
|
+
// the middleware function)
|
|
136
|
+
context: nextContext
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
currentInput,
|
|
141
|
+
middlewareOutputFn
|
|
142
|
+
);
|
|
143
|
+
return result.output;
|
|
144
|
+
}) : await runWithSpan(
|
|
145
|
+
{ name: "handler", signal: options.signal },
|
|
146
|
+
() => procedure["~orpc"].handler(currentInput, { ...options, context })
|
|
147
|
+
);
|
|
148
|
+
if (index === outputValidationIndex) {
|
|
149
|
+
return await validateOutput(procedure, output);
|
|
150
|
+
}
|
|
151
|
+
return output;
|
|
152
|
+
};
|
|
153
|
+
return next(0, options.context, input);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { middlewareOutputFn as a, createProcedureClient as c, mergeCurrentContext as m };
|