@temporary-name/server 1.9.3-alpha.121f1a14eceb7f2aa23c6993c2adce0ccca377db → 1.9.3-alpha.1a5ff4923d25c9d83e80d717687ebc859f5312f2
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 -3
- 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 -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 +4 -3
- package/dist/adapters/standard/index.d.mts +20 -31
- package/dist/adapters/standard/index.d.ts +20 -31
- package/dist/adapters/standard/index.mjs +4 -3
- package/dist/index.d.mts +53 -1047
- package/dist/index.d.ts +53 -1047
- package/dist/index.mjs +77 -1886
- package/dist/openapi/index.d.mts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.mjs +59 -76
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.CMTfy2UB.mjs → server.B--sAUhn.mjs} +55 -94
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.BCcLYvdF.d.mts} +1 -2
- package/dist/shared/server.CHV9AQHl.mjs +412 -0
- package/dist/shared/{server.C1fnTLq0.d.mts → server.CdeqmULw.d.ts} +1 -2
- package/dist/shared/{server.BeuTpcmO.d.mts → server.DHezmW6C.d.mts} +2 -2
- package/dist/shared/{server.SLLuK6_v.d.ts → server.Da-qLzdU.d.ts} +2 -2
- package/dist/shared/{server.BKSOrA6h.d.mts → server.DecvGKtb.d.mts} +125 -75
- package/dist/shared/{server.BKSOrA6h.d.ts → server.DecvGKtb.d.ts} +125 -75
- package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
- package/package.json +10 -9
- package/dist/shared/server.BZtKt8i8.mjs +0 -201
|
@@ -1,201 +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
|
-
|
|
5
|
-
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
|
6
|
-
function lazy(loader, meta = {}) {
|
|
7
|
-
return {
|
|
8
|
-
[LAZY_SYMBOL]: {
|
|
9
|
-
loader,
|
|
10
|
-
meta
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function isLazy(item) {
|
|
15
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
|
|
16
|
-
}
|
|
17
|
-
function getLazyMeta(lazied) {
|
|
18
|
-
return lazied[LAZY_SYMBOL].meta;
|
|
19
|
-
}
|
|
20
|
-
function unlazy(lazied) {
|
|
21
|
-
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function mergeCurrentContext(context, other) {
|
|
25
|
-
return { ...context, ...other };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function createORPCErrorConstructorMap(errors) {
|
|
29
|
-
const proxy = new Proxy(errors, {
|
|
30
|
-
get(target, code) {
|
|
31
|
-
if (typeof code !== "string") {
|
|
32
|
-
return Reflect.get(target, code);
|
|
33
|
-
}
|
|
34
|
-
const item = (...rest) => {
|
|
35
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
36
|
-
const config = errors[code];
|
|
37
|
-
return new ORPCError(code, {
|
|
38
|
-
defined: Boolean(config),
|
|
39
|
-
status: config?.status,
|
|
40
|
-
message: options.message ?? config?.message,
|
|
41
|
-
data: options.data,
|
|
42
|
-
cause: options.cause
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
return item;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
return proxy;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function middlewareOutputFn(output) {
|
|
52
|
-
return { output, context: {} };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function createProcedureClient(lazyableProcedure, ...rest) {
|
|
56
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
57
|
-
return async (...[input, callerOptions]) => {
|
|
58
|
-
const path = toArray(options.path);
|
|
59
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
60
|
-
const clientContext = callerOptions?.context ?? {};
|
|
61
|
-
const context = await value(options.context ?? {}, clientContext);
|
|
62
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
|
|
63
|
-
const validateError = async (e) => {
|
|
64
|
-
if (e instanceof ORPCError) {
|
|
65
|
-
return await validateORPCError(procedure["~orpc"].errorMap, e);
|
|
66
|
-
}
|
|
67
|
-
return e;
|
|
68
|
-
};
|
|
69
|
-
try {
|
|
70
|
-
const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
|
|
71
|
-
span?.setAttribute("procedure.path", [...path]);
|
|
72
|
-
return intercept(
|
|
73
|
-
toArray(options.interceptors),
|
|
74
|
-
{
|
|
75
|
-
context,
|
|
76
|
-
input,
|
|
77
|
-
// input only optional when it undefinable so we can safely cast it
|
|
78
|
-
errors,
|
|
79
|
-
path,
|
|
80
|
-
procedure,
|
|
81
|
-
signal: callerOptions?.signal,
|
|
82
|
-
lastEventId: callerOptions?.lastEventId
|
|
83
|
-
},
|
|
84
|
-
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
if (isAsyncIteratorObject(output)) {
|
|
88
|
-
if (output instanceof HibernationEventIterator) {
|
|
89
|
-
return output;
|
|
90
|
-
}
|
|
91
|
-
return overlayProxy(
|
|
92
|
-
output,
|
|
93
|
-
mapEventIterator(
|
|
94
|
-
asyncIteratorWithSpan(
|
|
95
|
-
{ name: "consume_event_iterator_output", signal: callerOptions?.signal },
|
|
96
|
-
output
|
|
97
|
-
),
|
|
98
|
-
{
|
|
99
|
-
value: (v) => v,
|
|
100
|
-
error: (e) => validateError(e)
|
|
101
|
-
}
|
|
102
|
-
)
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
return output;
|
|
106
|
-
} catch (e) {
|
|
107
|
-
throw await validateError(e);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
async function validateInput(procedure, input) {
|
|
112
|
-
const schema = procedure["~orpc"].inputSchema;
|
|
113
|
-
if (!schema) {
|
|
114
|
-
return input;
|
|
115
|
-
}
|
|
116
|
-
return runWithSpan({ name: "validate_input" }, async () => {
|
|
117
|
-
const result = await schema["~standard"].validate(input);
|
|
118
|
-
if (result.issues) {
|
|
119
|
-
throw new ORPCError("BAD_REQUEST", {
|
|
120
|
-
message: "Input validation failed",
|
|
121
|
-
data: {
|
|
122
|
-
issues: result.issues
|
|
123
|
-
},
|
|
124
|
-
cause: new ValidationError({
|
|
125
|
-
message: "Input validation failed",
|
|
126
|
-
issues: result.issues,
|
|
127
|
-
data: input
|
|
128
|
-
})
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return result.value;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
async function validateOutput(procedure, output) {
|
|
135
|
-
const schema = procedure["~orpc"].outputSchema;
|
|
136
|
-
if (!schema) {
|
|
137
|
-
return output;
|
|
138
|
-
}
|
|
139
|
-
return runWithSpan({ name: "validate_output" }, async () => {
|
|
140
|
-
const result = await schema["~standard"].validate(output);
|
|
141
|
-
if (result.issues) {
|
|
142
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
143
|
-
message: "Output validation failed",
|
|
144
|
-
cause: new ValidationError({
|
|
145
|
-
message: "Output validation failed",
|
|
146
|
-
issues: result.issues,
|
|
147
|
-
data: output
|
|
148
|
-
})
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
return result.value;
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
async function executeProcedureInternal(procedure, options) {
|
|
155
|
-
const middlewares = procedure["~orpc"].middlewares;
|
|
156
|
-
const inputValidationIndex = Math.min(
|
|
157
|
-
Math.max(0, procedure["~orpc"].inputValidationIndex),
|
|
158
|
-
middlewares.length
|
|
159
|
-
);
|
|
160
|
-
const outputValidationIndex = Math.min(
|
|
161
|
-
Math.max(0, procedure["~orpc"].outputValidationIndex),
|
|
162
|
-
middlewares.length
|
|
163
|
-
);
|
|
164
|
-
const next = async (index, context, input) => {
|
|
165
|
-
let currentInput = input;
|
|
166
|
-
if (index === inputValidationIndex) {
|
|
167
|
-
currentInput = await validateInput(procedure, currentInput);
|
|
168
|
-
}
|
|
169
|
-
const mid = middlewares[index];
|
|
170
|
-
const output = mid ? await runWithSpan({ name: `middleware.${mid.name}`, signal: options.signal }, async (span) => {
|
|
171
|
-
span?.setAttribute("middleware.index", index);
|
|
172
|
-
span?.setAttribute("middleware.name", mid.name);
|
|
173
|
-
const result = await mid(
|
|
174
|
-
{
|
|
175
|
-
...options,
|
|
176
|
-
context,
|
|
177
|
-
next: async (...[nextOptions]) => {
|
|
178
|
-
const nextContext = nextOptions?.context ?? {};
|
|
179
|
-
return {
|
|
180
|
-
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
|
|
181
|
-
context: nextContext
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
currentInput,
|
|
186
|
-
middlewareOutputFn
|
|
187
|
-
);
|
|
188
|
-
return result.output;
|
|
189
|
-
}) : await runWithSpan(
|
|
190
|
-
{ name: "handler", signal: options.signal },
|
|
191
|
-
() => procedure["~orpc"].handler({ ...options, context, input: currentInput })
|
|
192
|
-
);
|
|
193
|
-
if (index === outputValidationIndex) {
|
|
194
|
-
return await validateOutput(procedure, output);
|
|
195
|
-
}
|
|
196
|
-
return output;
|
|
197
|
-
};
|
|
198
|
-
return next(0, options.context, options.input);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export { LAZY_SYMBOL as L, createORPCErrorConstructorMap as a, middlewareOutputFn as b, createProcedureClient as c, getLazyMeta as g, isLazy as i, lazy as l, mergeCurrentContext as m, unlazy as u };
|