@temporary-name/server 1.9.3-alpha.fb7b7d19964e1b2def7056f4345b63d6fcacce10 → 1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3
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 +4 -4
- package/dist/adapters/aws-lambda/index.d.ts +4 -4
- package/dist/adapters/aws-lambda/index.mjs +5 -6
- package/dist/adapters/fetch/index.d.mts +4 -4
- package/dist/adapters/fetch/index.d.ts +4 -4
- package/dist/adapters/fetch/index.mjs +5 -6
- package/dist/adapters/node/index.d.mts +5 -5
- package/dist/adapters/node/index.d.ts +5 -5
- package/dist/adapters/node/index.mjs +5 -6
- package/dist/{adapters/standard → handler}/index.d.mts +4 -5
- package/dist/{adapters/standard → handler}/index.d.ts +4 -5
- package/dist/handler/index.mjs +8 -0
- package/dist/index.d.mts +273 -34
- package/dist/index.d.ts +273 -34
- package/dist/index.mjs +347 -35
- package/dist/openapi/index.d.mts +3 -2
- package/dist/openapi/index.d.ts +3 -2
- package/dist/openapi/index.mjs +64 -13
- package/dist/shared/server.-tR-4rQ5.mjs +523 -0
- package/dist/shared/{server.DXPMDozZ.d.mts → server.BwcJq6aP.d.mts} +462 -42
- package/dist/shared/{server.DXPMDozZ.d.ts → server.BwcJq6aP.d.ts} +462 -42
- package/dist/shared/server.CjPiuQYH.d.mts +51 -0
- package/dist/shared/server.CjPiuQYH.d.ts +51 -0
- package/dist/shared/{server.Cza0RB3u.mjs → server.D2NXNHIf.mjs} +5 -9
- package/dist/shared/{server.B0LJ_wu-.d.ts → server.Deg5phAY.d.ts} +4 -6
- package/dist/shared/{server.ChOv1yG3.mjs → server.DvgWQUGK.mjs} +189 -12
- package/dist/shared/{server.BQZMQrPe.d.mts → server.hAH-LVh_.d.mts} +4 -6
- package/dist/shared/{server.CYa9puL2.mjs → server.n1y5fcVQ.mjs} +24 -112
- package/package.json +11 -12
- package/dist/adapters/standard/index.mjs +0 -9
- package/dist/shared/server.CQIFwyhc.mjs +0 -40
- package/dist/shared/server.YUvuxHty.mjs +0 -48
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTTPPath, StandardResponse, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context,
|
|
2
|
+
import { C as Context, m as Router } from './server.BwcJq6aP.js';
|
|
3
3
|
|
|
4
4
|
interface StandardHandleOptions<T extends Context> {
|
|
5
5
|
prefix?: HTTPPath;
|
|
@@ -12,11 +12,9 @@ type StandardHandleResult = {
|
|
|
12
12
|
matched: false;
|
|
13
13
|
response: undefined;
|
|
14
14
|
};
|
|
15
|
-
interface StandardHandlerOptions<_TContext extends Context> {
|
|
16
|
-
}
|
|
17
15
|
declare class StandardHandler<T extends Context> {
|
|
18
16
|
private readonly matcher;
|
|
19
|
-
constructor(router: Router<T
|
|
17
|
+
constructor(router: Router<T>);
|
|
20
18
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
21
19
|
}
|
|
22
20
|
|
|
@@ -37,5 +35,5 @@ declare function toRou3Pattern(path: HTTPPath): string;
|
|
|
37
35
|
*/
|
|
38
36
|
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
39
37
|
|
|
40
|
-
export { StandardHandler as
|
|
41
|
-
export type { FriendlyStandardHandleOptions as F, StandardHandleOptions as S, StandardHandleResult as a
|
|
38
|
+
export { StandardHandler as b, decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
39
|
+
export type { FriendlyStandardHandleOptions as F, StandardHandleOptions as S, StandardHandleResult as a };
|
|
@@ -1,5 +1,189 @@
|
|
|
1
|
-
import { HTTPMethods } from '@temporary-name/shared';
|
|
2
1
|
import * as z from '@temporary-name/zod';
|
|
2
|
+
import { HTTPMethods } from '@temporary-name/shared';
|
|
3
|
+
|
|
4
|
+
class ValidationError extends Error {
|
|
5
|
+
issues;
|
|
6
|
+
data;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super("Validation error");
|
|
9
|
+
this.issues = options.issues;
|
|
10
|
+
this.data = options.data;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
class APIError extends Error {
|
|
14
|
+
extra;
|
|
15
|
+
static extraSchema = {};
|
|
16
|
+
static status;
|
|
17
|
+
static type;
|
|
18
|
+
static staticDefaultMessage = void 0;
|
|
19
|
+
constructor(...args) {
|
|
20
|
+
const { message, cause, ...extra } = args[0] ?? {};
|
|
21
|
+
super(message, { cause });
|
|
22
|
+
this.message = message ?? this.constructor.defaultMessage;
|
|
23
|
+
this.extra = extra;
|
|
24
|
+
}
|
|
25
|
+
static get defaultMessage() {
|
|
26
|
+
return this.staticDefaultMessage ?? this.type.split("_").map((word) => word[0]?.toUpperCase() + word.slice(1)).join(" ");
|
|
27
|
+
}
|
|
28
|
+
toJSON() {
|
|
29
|
+
return {
|
|
30
|
+
type: this.constructor.type,
|
|
31
|
+
message: this.message,
|
|
32
|
+
...this.extra
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class BadRequestError extends APIError {
|
|
37
|
+
static status = 400;
|
|
38
|
+
static type = "bad_request";
|
|
39
|
+
static extraSchema = { code: z.string() };
|
|
40
|
+
}
|
|
41
|
+
class UnauthorizedError extends APIError {
|
|
42
|
+
static status = 401;
|
|
43
|
+
static type = "unauthorized";
|
|
44
|
+
}
|
|
45
|
+
class ForbiddenError extends APIError {
|
|
46
|
+
static status = 403;
|
|
47
|
+
static type = "forbidden";
|
|
48
|
+
}
|
|
49
|
+
class NotFoundError extends APIError {
|
|
50
|
+
static status = 404;
|
|
51
|
+
static type = "not_found";
|
|
52
|
+
}
|
|
53
|
+
class InternalServerError extends APIError {
|
|
54
|
+
static status = 500;
|
|
55
|
+
static type = "internal_server_error";
|
|
56
|
+
}
|
|
57
|
+
const COMMON_ERRORS = {
|
|
58
|
+
BadRequestError,
|
|
59
|
+
UnauthorizedError,
|
|
60
|
+
ForbiddenError,
|
|
61
|
+
NotFoundError,
|
|
62
|
+
MethodNotAllowedError: class MethodNotAllowedError extends APIError {
|
|
63
|
+
static status = 405;
|
|
64
|
+
static type = "method_not_allowed";
|
|
65
|
+
},
|
|
66
|
+
NotAcceptableError: class NotAcceptableError extends APIError {
|
|
67
|
+
static status = 406;
|
|
68
|
+
static type = "not_acceptable";
|
|
69
|
+
},
|
|
70
|
+
RequestTimeoutError: class RequestTimeoutError extends APIError {
|
|
71
|
+
static status = 408;
|
|
72
|
+
static type = "request_timeout";
|
|
73
|
+
},
|
|
74
|
+
ConflictError: class ConflictError extends APIError {
|
|
75
|
+
static status = 409;
|
|
76
|
+
static type = "conflict";
|
|
77
|
+
},
|
|
78
|
+
PreconditionFailedError: class PreconditionFailedError extends APIError {
|
|
79
|
+
static status = 412;
|
|
80
|
+
static type = "precondition_failed";
|
|
81
|
+
},
|
|
82
|
+
ContentTooLargeError: class ContentTooLargeError extends APIError {
|
|
83
|
+
static status = 413;
|
|
84
|
+
static type = "content_too_large";
|
|
85
|
+
},
|
|
86
|
+
UnsupportedMediaTypeError: class UnsupportedMediaTypeError extends APIError {
|
|
87
|
+
static status = 415;
|
|
88
|
+
static type = "unsupported_media_type";
|
|
89
|
+
},
|
|
90
|
+
UnprocessableContentError: class UnprocessableContentError extends APIError {
|
|
91
|
+
static status = 422;
|
|
92
|
+
static type = "unprocessable_content";
|
|
93
|
+
},
|
|
94
|
+
TooManyRequestsError: class TooManyRequestsError extends APIError {
|
|
95
|
+
static status = 429;
|
|
96
|
+
static type = "too_many_requests";
|
|
97
|
+
},
|
|
98
|
+
InternalServerError,
|
|
99
|
+
NotImplementedError: class NotImplementedError extends APIError {
|
|
100
|
+
static status = 501;
|
|
101
|
+
static type = "not_implemented";
|
|
102
|
+
},
|
|
103
|
+
BadGatewayError: class BadGatewayError extends APIError {
|
|
104
|
+
static status = 502;
|
|
105
|
+
static type = "bad_gateway";
|
|
106
|
+
},
|
|
107
|
+
ServiceUnavailableError: class ServiceUnavailableError extends APIError {
|
|
108
|
+
static status = 503;
|
|
109
|
+
static type = "service_unavailable";
|
|
110
|
+
},
|
|
111
|
+
GatewayTimeoutError: class GatewayTimeoutError extends APIError {
|
|
112
|
+
static status = 504;
|
|
113
|
+
static type = "gateway_timeout";
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const DEFAULT_ERRORS_CONFIG = {
|
|
117
|
+
BadRequestError: { extraFields: { code: z.string() } },
|
|
118
|
+
UnauthorizedError: true,
|
|
119
|
+
ForbiddenError: true,
|
|
120
|
+
NotFoundError: true,
|
|
121
|
+
InternalServerError: true
|
|
122
|
+
};
|
|
123
|
+
function makeErrors(config) {
|
|
124
|
+
const configWithDefaults = { ...DEFAULT_ERRORS_CONFIG, ...config };
|
|
125
|
+
const errors = {};
|
|
126
|
+
for (const [key, value] of Object.entries(configWithDefaults)) {
|
|
127
|
+
if (key in COMMON_ERRORS) {
|
|
128
|
+
const errorClass = COMMON_ERRORS[key];
|
|
129
|
+
if (value === true) {
|
|
130
|
+
errors[key] = errorClass;
|
|
131
|
+
} else if (typeof value === "object") {
|
|
132
|
+
if ("extends" in value && value["extends"] !== key) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Invalid error config for ${key}: cannot use extends for pre-defined error class. Please us a different name or remove extends.`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const extraSchema = value.extraFields;
|
|
138
|
+
const childErrorClass = class extends errorClass {
|
|
139
|
+
static extraSchema = { ...errorClass.extraSchema, ...extraSchema };
|
|
140
|
+
};
|
|
141
|
+
Object.defineProperty(childErrorClass, "name", { value: key });
|
|
142
|
+
errors[key] = childErrorClass;
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
if (typeof value === "boolean") {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Unknown error class ${key}: custom error classes should be defined as a class, not a boolean`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
if (!("status" in value) || !("type" in value)) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Invalid error config for ${key}: custom error classes must have a "status" and "type" property`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const { status, type, defaultMessage, extraFields } = value;
|
|
156
|
+
const childErrorClass = class extends APIError {
|
|
157
|
+
static status = status;
|
|
158
|
+
static type = type;
|
|
159
|
+
static staticDefaultMessage = defaultMessage;
|
|
160
|
+
static extraSchema = extraFields ?? {};
|
|
161
|
+
};
|
|
162
|
+
Object.defineProperty(childErrorClass, "name", { value: key });
|
|
163
|
+
errors[key] = childErrorClass;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return errors;
|
|
167
|
+
}
|
|
168
|
+
function isAPIErrorStatus(status) {
|
|
169
|
+
return status < 200 || status >= 400;
|
|
170
|
+
}
|
|
171
|
+
function toAPIError(error) {
|
|
172
|
+
if (error instanceof APIError) {
|
|
173
|
+
return error;
|
|
174
|
+
}
|
|
175
|
+
return new InternalServerError({
|
|
176
|
+
message: error instanceof Error ? error.message : void 0,
|
|
177
|
+
cause: error
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function encodeError(error) {
|
|
181
|
+
return {
|
|
182
|
+
status: error.constructor.status,
|
|
183
|
+
headers: new Headers(),
|
|
184
|
+
body: error.toJSON()
|
|
185
|
+
};
|
|
186
|
+
}
|
|
3
187
|
|
|
4
188
|
function isStartWithMiddlewares(middlewares, compare) {
|
|
5
189
|
if (compare.length > middlewares.length) {
|
|
@@ -41,16 +225,6 @@ function isProcedure(item) {
|
|
|
41
225
|
(typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "route" in item["~orpc"] && "meta" in item["~orpc"] && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
|
42
226
|
}
|
|
43
227
|
|
|
44
|
-
class ValidationError extends Error {
|
|
45
|
-
issues;
|
|
46
|
-
data;
|
|
47
|
-
constructor(options) {
|
|
48
|
-
super(options.message, options);
|
|
49
|
-
this.issues = options.issues;
|
|
50
|
-
this.data = options.data;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
228
|
function mergeRoute(a, b) {
|
|
55
229
|
return { ...a, ...b };
|
|
56
230
|
}
|
|
@@ -241,6 +415,9 @@ function unlazy(lazied) {
|
|
|
241
415
|
}
|
|
242
416
|
|
|
243
417
|
const endpointRegex = new RegExp(`^(${HTTPMethods.join("|")})`);
|
|
418
|
+
function isDevelopment() {
|
|
419
|
+
return process.env.NODE_ENV === "development";
|
|
420
|
+
}
|
|
244
421
|
function standardizeHTTPPath(path) {
|
|
245
422
|
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
246
423
|
}
|
|
@@ -316,4 +493,4 @@ function parseEndpointDefinition(stringsOrEndpoint, values) {
|
|
|
316
493
|
return { method, path, pathSchema };
|
|
317
494
|
}
|
|
318
495
|
|
|
319
|
-
export { Contract as C, LAZY_SYMBOL as L, Procedure as P, ValidationError as V, mergeTags as a,
|
|
496
|
+
export { APIError as A, BadRequestError as B, Contract as C, endpointRegex as D, isDevelopment as E, ForbiddenError as F, InternalServerError as I, LAZY_SYMBOL as L, NotFoundError as N, Procedure as P, UnauthorizedError as U, ValidationError as V, mergeTags as a, enhanceRouter as b, mergeRoute as c, prefixRoute as d, encodeError as e, addMiddleware as f, getDynamicParams as g, getLazyMeta as h, isAPIErrorStatus as i, isProcedure as j, makeErrors as k, lazyInternal as l, mergePrefix as m, lazy as n, isLazy as o, parseEndpointDefinition as p, isStartWithMiddlewares as q, resolveContractProcedures as r, standardizeHTTPPath as s, toAPIError as t, unlazy as u, mergeMiddlewares as v, getRouter as w, createAccessibleLazyRouter as x, traverseContractProcedures as y, unlazyRouter as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTTPPath, StandardResponse, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context,
|
|
2
|
+
import { C as Context, m as Router } from './server.BwcJq6aP.mjs';
|
|
3
3
|
|
|
4
4
|
interface StandardHandleOptions<T extends Context> {
|
|
5
5
|
prefix?: HTTPPath;
|
|
@@ -12,11 +12,9 @@ type StandardHandleResult = {
|
|
|
12
12
|
matched: false;
|
|
13
13
|
response: undefined;
|
|
14
14
|
};
|
|
15
|
-
interface StandardHandlerOptions<_TContext extends Context> {
|
|
16
|
-
}
|
|
17
15
|
declare class StandardHandler<T extends Context> {
|
|
18
16
|
private readonly matcher;
|
|
19
|
-
constructor(router: Router<T
|
|
17
|
+
constructor(router: Router<T>);
|
|
20
18
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
21
19
|
}
|
|
22
20
|
|
|
@@ -37,5 +35,5 @@ declare function toRou3Pattern(path: HTTPPath): string;
|
|
|
37
35
|
*/
|
|
38
36
|
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
39
37
|
|
|
40
|
-
export { StandardHandler as
|
|
41
|
-
export type { FriendlyStandardHandleOptions as F, StandardHandleOptions as S, StandardHandleResult as a
|
|
38
|
+
export { StandardHandler as b, decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
39
|
+
export type { FriendlyStandardHandleOptions as F, StandardHandleOptions as S, StandardHandleResult as a };
|
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import { isObject, NullProtoObj,
|
|
2
|
-
import {
|
|
1
|
+
import { isObject, NullProtoObj, fallbackContractConfig, stringifyJSON, isAsyncIteratorObject, tryDecodeURIComponent, toHttpPath, runWithSpan, ORPC_NAME, asyncIteratorWithSpan, setSpanError } from '@temporary-name/shared';
|
|
2
|
+
import { e as encodeError, i as isAPIErrorStatus, s as standardizeHTTPPath, A as APIError, B as BadRequestError, t as toAPIError$1 } from './server.DvgWQUGK.mjs';
|
|
3
|
+
import { c as createProcedureClient } from './server.D2NXNHIf.mjs';
|
|
4
|
+
import { toAPIError, traverseContractProcedures, getLazyMeta, unlazy } from '@temporary-name/server';
|
|
3
5
|
import { mapEventIterator, ErrorEvent } from '@temporary-name/standard-server';
|
|
4
|
-
import { j as jsonSerialize } from './server.CQIFwyhc.mjs';
|
|
5
|
-
import { traverseContractProcedures, getLazyMeta, unlazy } from '@temporary-name/server';
|
|
6
6
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
7
|
-
import { s as standardizeHTTPPath } from './server.ChOv1yG3.mjs';
|
|
8
7
|
|
|
9
|
-
function bracketNotationSerialize(data, segments = [], result = []) {
|
|
10
|
-
if (Array.isArray(data)) {
|
|
11
|
-
data.forEach((item, i) => {
|
|
12
|
-
bracketNotationSerialize(item, [...segments, i], result);
|
|
13
|
-
});
|
|
14
|
-
} else if (isObject(data)) {
|
|
15
|
-
for (const key in data) {
|
|
16
|
-
bracketNotationSerialize(data[key], [...segments, key], result);
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
result.push([stringifyPath(segments), data]);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
8
|
function bracketNotationDeserialize(serialized, { maxArrayIndex = 9999 } = {}) {
|
|
24
9
|
if (serialized.length === 0) {
|
|
25
10
|
return {};
|
|
@@ -77,28 +62,6 @@ function bracketNotationDeserialize(serialized, { maxArrayIndex = 9999 } = {}) {
|
|
|
77
62
|
}
|
|
78
63
|
return ref.value;
|
|
79
64
|
}
|
|
80
|
-
function stringifyPath(segments) {
|
|
81
|
-
return segments.map((segment) => {
|
|
82
|
-
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
83
|
-
switch (match) {
|
|
84
|
-
case "\\":
|
|
85
|
-
return "\\\\";
|
|
86
|
-
case "[":
|
|
87
|
-
return "\\[";
|
|
88
|
-
case "]":
|
|
89
|
-
return "\\]";
|
|
90
|
-
/* v8 ignore next 2 */
|
|
91
|
-
default:
|
|
92
|
-
return match;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}).reduce((result, segment, i) => {
|
|
96
|
-
if (i === 0) {
|
|
97
|
-
return segment;
|
|
98
|
-
}
|
|
99
|
-
return `${result}[${segment}]`;
|
|
100
|
-
}, "");
|
|
101
|
-
}
|
|
102
65
|
function parsePath(path) {
|
|
103
66
|
const segments = [];
|
|
104
67
|
let inBrackets = false;
|
|
@@ -143,73 +106,28 @@ function pushStyleArrayToObject(array) {
|
|
|
143
106
|
return obj;
|
|
144
107
|
}
|
|
145
108
|
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
cause: e
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
return _serialize(data, options);
|
|
159
|
-
}
|
|
160
|
-
function _serialize(data, options) {
|
|
161
|
-
const [json, hasBlob] = jsonSerialize(data);
|
|
162
|
-
if (options.outputFormat === "plain") {
|
|
163
|
-
return json;
|
|
164
|
-
}
|
|
165
|
-
if (options.outputFormat === "URLSearchParams") {
|
|
166
|
-
const params = new URLSearchParams();
|
|
167
|
-
for (const [path, value] of bracketNotationSerialize(json)) {
|
|
168
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
169
|
-
params.append(path, value.toString());
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return params;
|
|
173
|
-
}
|
|
174
|
-
if (json instanceof Blob || json === void 0 || !hasBlob) {
|
|
175
|
-
return json;
|
|
176
|
-
}
|
|
177
|
-
const form = new FormData();
|
|
178
|
-
for (const [path, value] of bracketNotationSerialize(json)) {
|
|
179
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
180
|
-
form.append(path, value.toString());
|
|
181
|
-
} else if (value instanceof Blob) {
|
|
182
|
-
form.append(path, value);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return form;
|
|
109
|
+
async function decode(request, pathParams) {
|
|
110
|
+
return {
|
|
111
|
+
path: pathParams ?? {},
|
|
112
|
+
query: bracketNotationDeserialize(Array.from(request.url.searchParams.entries())),
|
|
113
|
+
headers: request.headers,
|
|
114
|
+
body: await request.body() ?? {}
|
|
115
|
+
};
|
|
186
116
|
}
|
|
187
|
-
function
|
|
188
|
-
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
189
|
-
return bracketNotationDeserialize(Array.from(data.entries()));
|
|
190
|
-
}
|
|
117
|
+
function asyncSafeSerialize(data) {
|
|
191
118
|
if (isAsyncIteratorObject(data)) {
|
|
192
119
|
return mapEventIterator(data, {
|
|
193
120
|
value: async (value) => value,
|
|
194
121
|
error: async (e) => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
122
|
+
return new ErrorEvent({
|
|
123
|
+
data: encodeError(toAPIError(e))["body"],
|
|
124
|
+
cause: e
|
|
125
|
+
});
|
|
199
126
|
}
|
|
200
127
|
});
|
|
201
128
|
}
|
|
202
129
|
return data;
|
|
203
130
|
}
|
|
204
|
-
|
|
205
|
-
async function decode(request, pathParams) {
|
|
206
|
-
return {
|
|
207
|
-
path: pathParams ?? {},
|
|
208
|
-
query: bracketNotationDeserialize(Array.from(request.url.searchParams.entries())),
|
|
209
|
-
headers: request.headers,
|
|
210
|
-
body: deserialize(await request.body()) ?? {}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
131
|
function encode(output, procedure) {
|
|
214
132
|
const successStatus = fallbackContractConfig(
|
|
215
133
|
"defaultSuccessStatus",
|
|
@@ -223,7 +141,7 @@ function encode(output, procedure) {
|
|
|
223
141
|
return {
|
|
224
142
|
status: successStatus,
|
|
225
143
|
headers: new Headers(),
|
|
226
|
-
body:
|
|
144
|
+
body: asyncSafeSerialize(output)
|
|
227
145
|
};
|
|
228
146
|
}
|
|
229
147
|
if (!isDetailedOutput(output)) {
|
|
@@ -242,14 +160,7 @@ function encode(output, procedure) {
|
|
|
242
160
|
return {
|
|
243
161
|
status: output.status ?? successStatus,
|
|
244
162
|
headers: output.headers ?? new Headers(),
|
|
245
|
-
body:
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
function encodeError(error) {
|
|
249
|
-
return {
|
|
250
|
-
status: error.status,
|
|
251
|
-
headers: new Headers(),
|
|
252
|
-
body: serialize(error.toJSON(), { outputFormat: "plain" })
|
|
163
|
+
body: asyncSafeSerialize(output.body)
|
|
253
164
|
};
|
|
254
165
|
}
|
|
255
166
|
function isDetailedOutput(output) {
|
|
@@ -259,7 +170,7 @@ function isDetailedOutput(output) {
|
|
|
259
170
|
if (output.headers && !isObject(output.headers)) {
|
|
260
171
|
return false;
|
|
261
172
|
}
|
|
262
|
-
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) ||
|
|
173
|
+
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isAPIErrorStatus(output.status))) {
|
|
263
174
|
return false;
|
|
264
175
|
}
|
|
265
176
|
return true;
|
|
@@ -331,7 +242,7 @@ class StandardOpenAPIMatcher {
|
|
|
331
242
|
|
|
332
243
|
class StandardHandler {
|
|
333
244
|
matcher;
|
|
334
|
-
constructor(router
|
|
245
|
+
constructor(router) {
|
|
335
246
|
this.matcher = new StandardOpenAPIMatcher();
|
|
336
247
|
this.matcher.init(router);
|
|
337
248
|
}
|
|
@@ -386,10 +297,11 @@ class StandardHandler {
|
|
|
386
297
|
if (step !== "call_procedure") {
|
|
387
298
|
setSpanError(span, e);
|
|
388
299
|
}
|
|
389
|
-
const error = step === "decode_input" && !(e instanceof
|
|
300
|
+
const error = step === "decode_input" && !(e instanceof APIError) ? new BadRequestError({
|
|
301
|
+
code: "malformed_request",
|
|
390
302
|
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
|
391
303
|
cause: e
|
|
392
|
-
}) :
|
|
304
|
+
}) : toAPIError$1(e);
|
|
393
305
|
const response = encodeError(error);
|
|
394
306
|
return {
|
|
395
307
|
matched: true,
|
|
@@ -400,4 +312,4 @@ class StandardHandler {
|
|
|
400
312
|
}
|
|
401
313
|
}
|
|
402
314
|
|
|
403
|
-
export { StandardHandler as S,
|
|
315
|
+
export { StandardHandler as S, StandardOpenAPIMatcher as a, decodeParams as b, decode as d, encode as e, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
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.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"default": "./dist/helpers/index.mjs"
|
|
25
25
|
},
|
|
26
26
|
"./standard": {
|
|
27
|
-
"types": "./dist/
|
|
28
|
-
"import": "./dist/
|
|
29
|
-
"default": "./dist/
|
|
27
|
+
"types": "./dist/handler/index.d.mts",
|
|
28
|
+
"import": "./dist/handler/index.mjs",
|
|
29
|
+
"default": "./dist/handler/index.mjs"
|
|
30
30
|
},
|
|
31
31
|
"./fetch": {
|
|
32
32
|
"types": "./dist/adapters/fetch/index.d.mts",
|
|
@@ -56,14 +56,13 @@
|
|
|
56
56
|
"cookie": "^1.0.2",
|
|
57
57
|
"rou3": "^0.7.7",
|
|
58
58
|
"zod": "^4.1.12",
|
|
59
|
-
"@temporary-name/
|
|
60
|
-
"@temporary-name/
|
|
61
|
-
"@temporary-name/
|
|
62
|
-
"@temporary-name/standard-server-
|
|
63
|
-
"@temporary-name/
|
|
64
|
-
"@temporary-name/
|
|
65
|
-
"@temporary-name/
|
|
66
|
-
"@temporary-name/zod": "1.9.3-alpha.fb7b7d19964e1b2def7056f4345b63d6fcacce10"
|
|
59
|
+
"@temporary-name/standard-server": "1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3",
|
|
60
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3",
|
|
61
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3",
|
|
62
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3",
|
|
63
|
+
"@temporary-name/interop": "1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3",
|
|
64
|
+
"@temporary-name/zod": "1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3",
|
|
65
|
+
"@temporary-name/shared": "1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3"
|
|
67
66
|
},
|
|
68
67
|
"devDependencies": {
|
|
69
68
|
"@types/supertest": "^6.0.3",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { S as StandardHandler, b as StandardOpenAPIMatcher, d as decode, c as decodeParams, e as encode, a as encodeError, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.CYa9puL2.mjs';
|
|
2
|
-
import '@temporary-name/shared';
|
|
3
|
-
import '../../shared/server.Cza0RB3u.mjs';
|
|
4
|
-
import '@temporary-name/standard-server';
|
|
5
|
-
import '@temporary-name/zod';
|
|
6
|
-
import '../../shared/server.ChOv1yG3.mjs';
|
|
7
|
-
import '../../shared/server.CQIFwyhc.mjs';
|
|
8
|
-
import '@temporary-name/server';
|
|
9
|
-
import 'rou3';
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { isObject } from '@temporary-name/shared';
|
|
2
|
-
|
|
3
|
-
function jsonSerialize(data, hasBlobRef = { value: false }) {
|
|
4
|
-
if (data instanceof Blob) {
|
|
5
|
-
hasBlobRef.value = true;
|
|
6
|
-
return [data, hasBlobRef.value];
|
|
7
|
-
}
|
|
8
|
-
if (data instanceof Set) {
|
|
9
|
-
return jsonSerialize(Array.from(data), hasBlobRef);
|
|
10
|
-
}
|
|
11
|
-
if (data instanceof Map) {
|
|
12
|
-
return jsonSerialize(Array.from(data.entries()), hasBlobRef);
|
|
13
|
-
}
|
|
14
|
-
if (Array.isArray(data)) {
|
|
15
|
-
const json = data.map((v) => v === void 0 ? null : jsonSerialize(v, hasBlobRef)[0]);
|
|
16
|
-
return [json, hasBlobRef.value];
|
|
17
|
-
}
|
|
18
|
-
if (isObject(data)) {
|
|
19
|
-
const json = {};
|
|
20
|
-
for (const k in data) {
|
|
21
|
-
if (k === "toJSON" && typeof data[k] === "function") {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
json[k] = jsonSerialize(data[k], hasBlobRef)[0];
|
|
25
|
-
}
|
|
26
|
-
return [json, hasBlobRef.value];
|
|
27
|
-
}
|
|
28
|
-
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
29
|
-
return [data.toString(), hasBlobRef.value];
|
|
30
|
-
}
|
|
31
|
-
if (data instanceof Date) {
|
|
32
|
-
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
33
|
-
}
|
|
34
|
-
if (Number.isNaN(data)) {
|
|
35
|
-
return [null, hasBlobRef.value];
|
|
36
|
-
}
|
|
37
|
-
return [data, hasBlobRef.value];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { jsonSerialize as j };
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { isAsyncIteratorObject, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import { mapEventIterator } from '@temporary-name/standard-server';
|
|
3
|
-
import { custom, safeParseAsync } from '@temporary-name/zod';
|
|
4
|
-
import { V as ValidationError } from './server.ChOv1yG3.mjs';
|
|
5
|
-
|
|
6
|
-
const EVENT_ITERATOR_DETAILS_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_DETAILS");
|
|
7
|
-
function eventIterator(yields, returns) {
|
|
8
|
-
const schema = custom(
|
|
9
|
-
(iterator) => isAsyncIteratorObject(iterator)
|
|
10
|
-
).transform((iterator) => {
|
|
11
|
-
const mapped = mapEventIterator(iterator, {
|
|
12
|
-
async value(value, done) {
|
|
13
|
-
const schema2 = done ? returns : yields;
|
|
14
|
-
if (!schema2) {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
const result = await safeParseAsync(schema2, value);
|
|
18
|
-
if (result.success) {
|
|
19
|
-
return result.data;
|
|
20
|
-
} else {
|
|
21
|
-
throw new ORPCError("EVENT_ITERATOR_VALIDATION_FAILED", {
|
|
22
|
-
message: "Event iterator validation failed",
|
|
23
|
-
cause: new ValidationError({
|
|
24
|
-
issues: result.error.issues,
|
|
25
|
-
message: "Event iterator validation failed",
|
|
26
|
-
data: value
|
|
27
|
-
})
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
error: async (error) => error
|
|
32
|
-
});
|
|
33
|
-
return mapped;
|
|
34
|
-
});
|
|
35
|
-
schema[EVENT_ITERATOR_DETAILS_SYMBOL] = {
|
|
36
|
-
yields,
|
|
37
|
-
returns
|
|
38
|
-
};
|
|
39
|
-
return schema;
|
|
40
|
-
}
|
|
41
|
-
function getEventIteratorSchemaDetails(schema) {
|
|
42
|
-
if (schema === void 0) {
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
|
-
return schema[EVENT_ITERATOR_DETAILS_SYMBOL];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { eventIterator as e, getEventIteratorSchemaDetails as g };
|