@temporary-name/server 1.9.3-alpha.afd18ec2afa743b08cf1b5c2eb6252ded18a1f43 → 1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56
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 +5 -7
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +5 -7
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +5 -7
- package/dist/adapters/standard/index.d.mts +5 -51
- package/dist/adapters/standard/index.d.ts +5 -51
- package/dist/adapters/standard/index.mjs +4 -6
- package/dist/index.d.mts +42 -264
- package/dist/index.d.ts +42 -264
- package/dist/index.mjs +108 -151
- package/dist/openapi/index.d.mts +0 -1
- package/dist/openapi/index.d.ts +0 -1
- package/dist/openapi/index.mjs +4 -12
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.SLLuK6_v.d.ts → server.8gkXYsTZ.d.ts} +2 -2
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.B15EEOr0.d.ts} +1 -1
- package/dist/shared/{server._YqJjI50.mjs → server.B9VxPdeK.mjs} +10 -14
- package/dist/shared/server.BEHw7Eyx.mjs +247 -0
- package/dist/shared/{server.BKSOrA6h.d.mts → server.CZNLCQBm.d.mts} +2 -2
- package/dist/shared/{server.BKSOrA6h.d.ts → server.CZNLCQBm.d.ts} +2 -2
- package/dist/shared/{server.BeuTpcmO.d.mts → server.ChraIVaQ.d.mts} +2 -2
- package/dist/shared/{server.BKh8I1Ny.mjs → server.DcfsPloY.mjs} +17 -54
- package/dist/shared/{server.C1fnTLq0.d.mts → server.YXplw8TW.d.mts} +1 -1
- package/package.json +10 -9
- package/dist/shared/server.DhdDYN-Z.mjs +0 -261
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { isObject, NullProtoObj, isAsyncIteratorObject, isORPCErrorJson, createORPCErrorFromJson, toORPCError } from '@temporary-name/shared';
|
|
2
|
+
import { mapEventIterator, ErrorEvent } from '@temporary-name/standard-server';
|
|
3
|
+
|
|
4
|
+
function bracketNotationSerialize(data, segments = [], result = []) {
|
|
5
|
+
if (Array.isArray(data)) {
|
|
6
|
+
data.forEach((item, i) => {
|
|
7
|
+
bracketNotationSerialize(item, [...segments, i], result);
|
|
8
|
+
});
|
|
9
|
+
} else if (isObject(data)) {
|
|
10
|
+
for (const key in data) {
|
|
11
|
+
bracketNotationSerialize(data[key], [...segments, key], result);
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
result.push([stringifyPath(segments), data]);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
function bracketNotationDeserialize(serialized, { maxArrayIndex = 9999 } = {}) {
|
|
19
|
+
if (serialized.length === 0) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
23
|
+
const ref = { value: [] };
|
|
24
|
+
for (const [path, value] of serialized) {
|
|
25
|
+
const segments = parsePath(path);
|
|
26
|
+
let currentRef = ref;
|
|
27
|
+
let nextSegment = "value";
|
|
28
|
+
segments.forEach((segment, i) => {
|
|
29
|
+
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
30
|
+
currentRef[nextSegment] = [];
|
|
31
|
+
}
|
|
32
|
+
if (i !== segments.length - 1) {
|
|
33
|
+
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment, maxArrayIndex)) {
|
|
34
|
+
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
35
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
36
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
37
|
+
} else {
|
|
38
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
if (Array.isArray(currentRef[nextSegment])) {
|
|
43
|
+
if (segment === "") {
|
|
44
|
+
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
45
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
49
|
+
arrayPushStyles.delete(currentRef[nextSegment]);
|
|
50
|
+
currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
|
|
51
|
+
} else if (!isValidArrayIndex(segment, maxArrayIndex)) {
|
|
52
|
+
currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
currentRef = currentRef[nextSegment];
|
|
58
|
+
nextSegment = segment;
|
|
59
|
+
});
|
|
60
|
+
if (Array.isArray(currentRef) && nextSegment === "") {
|
|
61
|
+
arrayPushStyles.add(currentRef);
|
|
62
|
+
currentRef.push(value);
|
|
63
|
+
} else if (nextSegment in currentRef) {
|
|
64
|
+
if (Array.isArray(currentRef[nextSegment])) {
|
|
65
|
+
currentRef[nextSegment].push(value);
|
|
66
|
+
} else {
|
|
67
|
+
currentRef[nextSegment] = [currentRef[nextSegment], value];
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
currentRef[nextSegment] = value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return ref.value;
|
|
74
|
+
}
|
|
75
|
+
function stringifyPath(segments) {
|
|
76
|
+
return segments.map((segment) => {
|
|
77
|
+
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
78
|
+
switch (match) {
|
|
79
|
+
case "\\":
|
|
80
|
+
return "\\\\";
|
|
81
|
+
case "[":
|
|
82
|
+
return "\\[";
|
|
83
|
+
case "]":
|
|
84
|
+
return "\\]";
|
|
85
|
+
/* v8 ignore next 2 */
|
|
86
|
+
default:
|
|
87
|
+
return match;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}).reduce((result, segment, i) => {
|
|
91
|
+
if (i === 0) {
|
|
92
|
+
return segment;
|
|
93
|
+
}
|
|
94
|
+
return `${result}[${segment}]`;
|
|
95
|
+
}, "");
|
|
96
|
+
}
|
|
97
|
+
function parsePath(path) {
|
|
98
|
+
const segments = [];
|
|
99
|
+
let inBrackets = false;
|
|
100
|
+
let currentSegment = "";
|
|
101
|
+
let backslashCount = 0;
|
|
102
|
+
for (let i = 0; i < path.length; i++) {
|
|
103
|
+
const char = path[i];
|
|
104
|
+
const nextChar = path[i + 1];
|
|
105
|
+
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
106
|
+
if (nextChar === void 0) {
|
|
107
|
+
inBrackets = false;
|
|
108
|
+
}
|
|
109
|
+
segments.push(currentSegment);
|
|
110
|
+
currentSegment = "";
|
|
111
|
+
i++;
|
|
112
|
+
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
113
|
+
inBrackets = true;
|
|
114
|
+
segments.push(currentSegment);
|
|
115
|
+
currentSegment = "";
|
|
116
|
+
} else if (char === "\\") {
|
|
117
|
+
backslashCount++;
|
|
118
|
+
} else {
|
|
119
|
+
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
120
|
+
backslashCount = 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
124
|
+
}
|
|
125
|
+
function isValidArrayIndex(value, maxIndex) {
|
|
126
|
+
return /^0$|^[1-9]\d*$/.test(value) && Number(value) <= maxIndex;
|
|
127
|
+
}
|
|
128
|
+
function arrayToObject(array) {
|
|
129
|
+
const obj = new NullProtoObj();
|
|
130
|
+
array.forEach((item, i) => {
|
|
131
|
+
obj[i] = item;
|
|
132
|
+
});
|
|
133
|
+
return obj;
|
|
134
|
+
}
|
|
135
|
+
function pushStyleArrayToObject(array) {
|
|
136
|
+
const obj = new NullProtoObj();
|
|
137
|
+
obj[""] = array.length === 1 ? array[0] : array;
|
|
138
|
+
return obj;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function jsonSerialize(data, hasBlobRef = { value: false }) {
|
|
142
|
+
if (data instanceof Blob) {
|
|
143
|
+
hasBlobRef.value = true;
|
|
144
|
+
return [data, hasBlobRef.value];
|
|
145
|
+
}
|
|
146
|
+
if (data instanceof Set) {
|
|
147
|
+
return jsonSerialize(Array.from(data), hasBlobRef);
|
|
148
|
+
}
|
|
149
|
+
if (data instanceof Map) {
|
|
150
|
+
return jsonSerialize(Array.from(data.entries()), hasBlobRef);
|
|
151
|
+
}
|
|
152
|
+
if (Array.isArray(data)) {
|
|
153
|
+
const json = data.map((v) => v === void 0 ? null : jsonSerialize(v, hasBlobRef)[0]);
|
|
154
|
+
return [json, hasBlobRef.value];
|
|
155
|
+
}
|
|
156
|
+
if (isObject(data)) {
|
|
157
|
+
const json = {};
|
|
158
|
+
for (const k in data) {
|
|
159
|
+
if (k === "toJSON" && typeof data[k] === "function") {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
json[k] = jsonSerialize(data[k], hasBlobRef)[0];
|
|
163
|
+
}
|
|
164
|
+
return [json, hasBlobRef.value];
|
|
165
|
+
}
|
|
166
|
+
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
167
|
+
return [data.toString(), hasBlobRef.value];
|
|
168
|
+
}
|
|
169
|
+
if (data instanceof Date) {
|
|
170
|
+
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
171
|
+
}
|
|
172
|
+
if (Number.isNaN(data)) {
|
|
173
|
+
return [null, hasBlobRef.value];
|
|
174
|
+
}
|
|
175
|
+
return [data, hasBlobRef.value];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function serialize(data, options = {}) {
|
|
179
|
+
if (isAsyncIteratorObject(data) && !options.outputFormat) {
|
|
180
|
+
return mapEventIterator(data, {
|
|
181
|
+
value: async (value) => _serialize(value, { outputFormat: "plain" }),
|
|
182
|
+
error: async (e) => {
|
|
183
|
+
return new ErrorEvent({
|
|
184
|
+
data: _serialize(toORPCError(e).toJSON(), { outputFormat: "plain" }),
|
|
185
|
+
cause: e
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return _serialize(data, options);
|
|
191
|
+
}
|
|
192
|
+
function _serialize(data, options) {
|
|
193
|
+
const [json, hasBlob] = jsonSerialize(data);
|
|
194
|
+
if (options.outputFormat === "plain") {
|
|
195
|
+
return json;
|
|
196
|
+
}
|
|
197
|
+
if (options.outputFormat === "URLSearchParams") {
|
|
198
|
+
const params = new URLSearchParams();
|
|
199
|
+
for (const [path, value] of bracketNotationSerialize(json)) {
|
|
200
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
201
|
+
params.append(path, value.toString());
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return params;
|
|
205
|
+
}
|
|
206
|
+
if (json instanceof Blob || json === void 0 || !hasBlob) {
|
|
207
|
+
return json;
|
|
208
|
+
}
|
|
209
|
+
const form = new FormData();
|
|
210
|
+
for (const [path, value] of bracketNotationSerialize(json)) {
|
|
211
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
212
|
+
form.append(path, value.toString());
|
|
213
|
+
} else if (value instanceof Blob) {
|
|
214
|
+
form.append(path, value);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return form;
|
|
218
|
+
}
|
|
219
|
+
function deserialize(data) {
|
|
220
|
+
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
221
|
+
return bracketNotationDeserialize(Array.from(data.entries()));
|
|
222
|
+
}
|
|
223
|
+
if (isAsyncIteratorObject(data)) {
|
|
224
|
+
return mapEventIterator(data, {
|
|
225
|
+
value: async (value) => value,
|
|
226
|
+
error: async (e) => {
|
|
227
|
+
if (e instanceof ErrorEvent && isORPCErrorJson(e.data)) {
|
|
228
|
+
return createORPCErrorFromJson(e.data, { cause: e });
|
|
229
|
+
}
|
|
230
|
+
return e;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return data;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function standardizeHTTPPath(path) {
|
|
238
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
239
|
+
}
|
|
240
|
+
function getDynamicParams(path) {
|
|
241
|
+
return path ? standardizeHTTPPath(path).match(/\/\{[^}]+\}/g)?.map((v) => ({
|
|
242
|
+
raw: v,
|
|
243
|
+
name: v.match(/\{\+?([^}]+)\}/)[1]
|
|
244
|
+
})) : void 0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export { standardizeHTTPPath as a, deserialize as d, getDynamicParams as g, jsonSerialize as j, serialize as s };
|
|
@@ -71,7 +71,7 @@ declare class Procedure<TInitialContext extends Context, TCurrentContext extends
|
|
|
71
71
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
72
72
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
73
73
|
}
|
|
74
|
-
type AnyProcedure = Procedure<any, any,
|
|
74
|
+
type AnyProcedure = Procedure<any, any, AnySchema, AnySchema, any, any>;
|
|
75
75
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
76
76
|
|
|
77
77
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
@@ -189,4 +189,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
export { isProcedure as D, createProcedureClient as F, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, middlewareOutputFn as y };
|
|
192
|
-
export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L,
|
|
192
|
+
export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, CreateProcedureClientOptions as a, ProcedureClient as b, AnyRouter as c, Lazy as d, AnyProcedure as e, Middleware as f, MergedCurrentContext as g, ProcedureHandler as h, MapInputMiddleware as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };
|
|
@@ -71,7 +71,7 @@ declare class Procedure<TInitialContext extends Context, TCurrentContext extends
|
|
|
71
71
|
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
72
72
|
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
73
73
|
}
|
|
74
|
-
type AnyProcedure = Procedure<any, any,
|
|
74
|
+
type AnyProcedure = Procedure<any, any, AnySchema, AnySchema, any, any>;
|
|
75
75
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
76
76
|
|
|
77
77
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
@@ -189,4 +189,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
|
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
export { isProcedure as D, createProcedureClient as F, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, middlewareOutputFn as y };
|
|
192
|
-
export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L,
|
|
192
|
+
export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, CreateProcedureClientOptions as a, ProcedureClient as b, AnyRouter as c, Lazy as d, AnyProcedure as e, Middleware as f, MergedCurrentContext as g, ProcedureHandler as h, MapInputMiddleware as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };
|
|
@@ -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.CZNLCQBm.mjs';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.YXplw8TW.mjs';
|
|
4
4
|
|
|
5
5
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
6
|
context?: T;
|
|
@@ -1,39 +1,7 @@
|
|
|
1
1
|
import { validateORPCError, ValidationError } from '@temporary-name/contract';
|
|
2
2
|
import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
|
|
3
3
|
import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
|
|
4
|
-
import {
|
|
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
|
-
}
|
|
4
|
+
import { safeParseAsync } from '@temporary-name/zod';
|
|
37
5
|
|
|
38
6
|
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
|
39
7
|
function lazy(loader, meta = {}) {
|
|
@@ -147,37 +115,41 @@ async function validateInput(procedure, input) {
|
|
|
147
115
|
return input;
|
|
148
116
|
}
|
|
149
117
|
return runWithSpan({ name: "validate_input" }, async () => {
|
|
150
|
-
const result = await schema
|
|
151
|
-
if (result.
|
|
118
|
+
const result = await safeParseAsync(schema, input);
|
|
119
|
+
if (!result.success) {
|
|
152
120
|
throw new ORPCError("BAD_REQUEST", {
|
|
153
121
|
message: "Input validation failed",
|
|
154
122
|
data: {
|
|
155
|
-
issues: result.issues
|
|
123
|
+
issues: result.error.issues
|
|
156
124
|
},
|
|
157
125
|
cause: new ValidationError({
|
|
158
126
|
message: "Input validation failed",
|
|
159
|
-
issues: result.issues,
|
|
127
|
+
issues: result.error.issues,
|
|
160
128
|
data: input
|
|
161
129
|
})
|
|
162
130
|
});
|
|
163
131
|
}
|
|
164
|
-
return result.
|
|
132
|
+
return result.data;
|
|
165
133
|
});
|
|
166
134
|
}
|
|
167
|
-
async function validateOutput(
|
|
135
|
+
async function validateOutput(procedure, output) {
|
|
136
|
+
const schema = procedure["~orpc"].outputSchema;
|
|
137
|
+
if (!schema) {
|
|
138
|
+
return output;
|
|
139
|
+
}
|
|
168
140
|
return runWithSpan({ name: "validate_output" }, async () => {
|
|
169
|
-
const result = await schema
|
|
170
|
-
if (result.
|
|
141
|
+
const result = await safeParseAsync(schema, output);
|
|
142
|
+
if (!result.success) {
|
|
171
143
|
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
172
144
|
message: "Output validation failed",
|
|
173
145
|
cause: new ValidationError({
|
|
174
146
|
message: "Output validation failed",
|
|
175
|
-
issues: result.issues,
|
|
147
|
+
issues: result.error.issues,
|
|
176
148
|
data: output
|
|
177
149
|
})
|
|
178
150
|
});
|
|
179
151
|
}
|
|
180
|
-
return result.
|
|
152
|
+
return result.data;
|
|
181
153
|
});
|
|
182
154
|
}
|
|
183
155
|
async function executeProcedureInternal(procedure, options) {
|
|
@@ -220,20 +192,11 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
220
192
|
() => procedure["~orpc"].handler({ ...options, context, input: currentInput })
|
|
221
193
|
);
|
|
222
194
|
if (index === outputValidationIndex) {
|
|
223
|
-
|
|
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);
|
|
195
|
+
return await validateOutput(procedure, output);
|
|
233
196
|
}
|
|
234
197
|
return output;
|
|
235
198
|
};
|
|
236
199
|
return next(0, options.context, options.input);
|
|
237
200
|
}
|
|
238
201
|
|
|
239
|
-
export { LAZY_SYMBOL as L,
|
|
202
|
+
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 };
|
|
@@ -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, E as ProcedureClientInterceptorOptions } from './server.
|
|
4
|
+
import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.CZNLCQBm.mjs';
|
|
5
5
|
|
|
6
6
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
7
|
order?: number;
|
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.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
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/
|
|
78
|
-
"@temporary-name/
|
|
79
|
-
"@temporary-name/
|
|
80
|
-
"@temporary-name/standard-server
|
|
81
|
-
"@temporary-name/standard-server-fetch": "1.9.3-alpha.
|
|
82
|
-
"@temporary-name/
|
|
83
|
-
"@temporary-name/
|
|
76
|
+
"@temporary-name/interop": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
77
|
+
"@temporary-name/shared": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
78
|
+
"@temporary-name/contract": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
79
|
+
"@temporary-name/standard-server": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
80
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
81
|
+
"@temporary-name/zod": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
82
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
83
|
+
"@temporary-name/json-schema": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56",
|
|
84
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
87
|
"@types/supertest": "^6.0.3",
|