arri 0.0.13 → 0.0.15
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/chunks/index.cjs +19 -19
- package/dist/chunks/index.mjs +19 -19
- package/dist/chunks/index2.cjs +18 -18
- package/dist/chunks/index2.mjs +18 -18
- package/dist/chunks/index3.cjs +1670 -8702
- package/dist/chunks/index3.mjs +1667 -8687
- package/dist/chunks/index4.cjs +256 -0
- package/dist/chunks/index4.mjs +247 -0
- package/dist/chunks/index5.cjs +8854 -0
- package/dist/chunks/index5.mjs +8832 -0
- package/dist/cli.cjs +21663 -19012
- package/dist/cli.mjs +21641 -18993
- package/dist/codegen.cjs +8 -8
- package/dist/codegen.d.cts +1 -1
- package/dist/codegen.d.mts +1 -1
- package/dist/codegen.d.ts +1 -1
- package/dist/codegen.mjs +9 -9
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{arri.d31eb2d5.cjs → arri.9717f131.cjs} +16 -28
- package/dist/shared/{arri.2ff96786.d.cts → arri.bb7e9a4e.d.cts} +55 -60
- package/dist/shared/{arri.2ff96786.d.mts → arri.bb7e9a4e.d.mts} +55 -60
- package/dist/shared/{arri.2ff96786.d.ts → arri.bb7e9a4e.d.ts} +55 -60
- package/dist/shared/{arri.3605a96c.cjs → arri.bfebed73.cjs} +534 -619
- package/dist/shared/{arri.b0ab6d2f.mjs → arri.dab1f9df.mjs} +531 -617
- package/dist/shared/{arri.a90e77aa.mjs → arri.e335c10b.mjs} +10 -22
- package/package.json +6 -4
|
@@ -3373,90 +3373,6 @@ function isPreflightRequest(event) {
|
|
|
3373
3373
|
return event.method === "OPTIONS" && !!origin && !!accessControlRequestMethod;
|
|
3374
3374
|
}
|
|
3375
3375
|
|
|
3376
|
-
var __defProp$2 = Object.defineProperty;
|
|
3377
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3378
|
-
var __publicField$2 = (obj, key, value) => {
|
|
3379
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3380
|
-
return value;
|
|
3381
|
-
};
|
|
3382
|
-
class H3Event {
|
|
3383
|
-
constructor(req, res) {
|
|
3384
|
-
__publicField$2(this, "__is_event__", true);
|
|
3385
|
-
// Context
|
|
3386
|
-
__publicField$2(this, "node");
|
|
3387
|
-
// Node
|
|
3388
|
-
__publicField$2(this, "web");
|
|
3389
|
-
// Web
|
|
3390
|
-
__publicField$2(this, "context", {});
|
|
3391
|
-
// Shared
|
|
3392
|
-
// Request
|
|
3393
|
-
__publicField$2(this, "_method");
|
|
3394
|
-
__publicField$2(this, "_path");
|
|
3395
|
-
__publicField$2(this, "_headers");
|
|
3396
|
-
__publicField$2(this, "_requestBody");
|
|
3397
|
-
// Response
|
|
3398
|
-
__publicField$2(this, "_handled", false);
|
|
3399
|
-
this.node = { req, res };
|
|
3400
|
-
}
|
|
3401
|
-
// --- Request ---
|
|
3402
|
-
get method() {
|
|
3403
|
-
if (!this._method) {
|
|
3404
|
-
this._method = (this.node.req.method || "GET").toUpperCase();
|
|
3405
|
-
}
|
|
3406
|
-
return this._method;
|
|
3407
|
-
}
|
|
3408
|
-
get path() {
|
|
3409
|
-
return this._path || this.node.req.url || "/";
|
|
3410
|
-
}
|
|
3411
|
-
get headers() {
|
|
3412
|
-
if (!this._headers) {
|
|
3413
|
-
this._headers = _normalizeNodeHeaders(this.node.req.headers);
|
|
3414
|
-
}
|
|
3415
|
-
return this._headers;
|
|
3416
|
-
}
|
|
3417
|
-
// --- Respoonse ---
|
|
3418
|
-
get handled() {
|
|
3419
|
-
return this._handled || this.node.res.writableEnded || this.node.res.headersSent;
|
|
3420
|
-
}
|
|
3421
|
-
respondWith(response) {
|
|
3422
|
-
return Promise.resolve(response).then(
|
|
3423
|
-
(_response) => sendWebResponse(this, _response)
|
|
3424
|
-
);
|
|
3425
|
-
}
|
|
3426
|
-
// --- Utils ---
|
|
3427
|
-
toString() {
|
|
3428
|
-
return `[${this.method}] ${this.path}`;
|
|
3429
|
-
}
|
|
3430
|
-
toJSON() {
|
|
3431
|
-
return this.toString();
|
|
3432
|
-
}
|
|
3433
|
-
// --- Deprecated ---
|
|
3434
|
-
/** @deprecated Please use `event.node.req` instead. **/
|
|
3435
|
-
get req() {
|
|
3436
|
-
return this.node.req;
|
|
3437
|
-
}
|
|
3438
|
-
/** @deprecated Please use `event.node.res` instead. **/
|
|
3439
|
-
get res() {
|
|
3440
|
-
return this.node.res;
|
|
3441
|
-
}
|
|
3442
|
-
}
|
|
3443
|
-
function createEvent(req, res) {
|
|
3444
|
-
return new H3Event(req, res);
|
|
3445
|
-
}
|
|
3446
|
-
function _normalizeNodeHeaders(nodeHeaders) {
|
|
3447
|
-
const headers = new Headers();
|
|
3448
|
-
for (const [name, value] of Object.entries(nodeHeaders)) {
|
|
3449
|
-
if (Array.isArray(value)) {
|
|
3450
|
-
for (const item of value) {
|
|
3451
|
-
headers.append(name, item);
|
|
3452
|
-
}
|
|
3453
|
-
} else if (value) {
|
|
3454
|
-
headers.set(name, value);
|
|
3455
|
-
}
|
|
3456
|
-
}
|
|
3457
|
-
return headers;
|
|
3458
|
-
}
|
|
3459
|
-
|
|
3460
3376
|
function defineEventHandler(handler) {
|
|
3461
3377
|
if (typeof handler === "function") {
|
|
3462
3378
|
return Object.assign(handler, { __is_handler__: true });
|
|
@@ -3780,32 +3696,189 @@ function createRouter(opts = {}) {
|
|
|
3780
3696
|
});
|
|
3781
3697
|
return router;
|
|
3782
3698
|
}
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3699
|
+
|
|
3700
|
+
const ErrorResponse = typebox.Type.Object(
|
|
3701
|
+
{
|
|
3702
|
+
statusCode: typebox.Type.Integer(),
|
|
3703
|
+
statusMessage: typebox.Type.String(),
|
|
3704
|
+
stack: typebox.Type.Array(typebox.Type.Any()),
|
|
3705
|
+
data: typebox.Type.Optional(typebox.Type.Object({}, { additionalProperties: true }))
|
|
3706
|
+
},
|
|
3707
|
+
{ $id: "ErrorResponse" }
|
|
3708
|
+
);
|
|
3709
|
+
function defineError(statusCode, input = {}) {
|
|
3710
|
+
const defaultVals = errorResponseDefaults[statusCode];
|
|
3711
|
+
return createError({
|
|
3712
|
+
statusCode,
|
|
3713
|
+
statusMessage: input.statusMessage ?? defaultVals.message ?? "An unknown error occurred",
|
|
3714
|
+
stack: input.stack ?? "",
|
|
3715
|
+
data: input.data
|
|
3716
|
+
});
|
|
3717
|
+
}
|
|
3718
|
+
function errorResponseFromValidationErrors(errors, prefixText = `Missing or invalid parameters`) {
|
|
3719
|
+
const errorParts = [];
|
|
3720
|
+
for (const err of errors) {
|
|
3721
|
+
const propName = err.path.split("/");
|
|
3722
|
+
propName.shift();
|
|
3723
|
+
if (!errorParts.includes(propName.join("."))) {
|
|
3724
|
+
errorParts.push(propName.join("."));
|
|
3803
3725
|
}
|
|
3804
|
-
}
|
|
3805
|
-
|
|
3726
|
+
}
|
|
3727
|
+
throw defineError(400, {
|
|
3728
|
+
statusMessage: `${prefixText}: [${errorParts.join(",")}]`,
|
|
3729
|
+
data: errors
|
|
3730
|
+
});
|
|
3806
3731
|
}
|
|
3807
|
-
|
|
3808
|
-
|
|
3732
|
+
const errorResponseDefaults = {
|
|
3733
|
+
400: {
|
|
3734
|
+
name: "BAD_REQUEST",
|
|
3735
|
+
message: "Bad Request"
|
|
3736
|
+
},
|
|
3737
|
+
401: {
|
|
3738
|
+
name: "UNAUTHORIZED",
|
|
3739
|
+
message: "Unauthorized"
|
|
3740
|
+
},
|
|
3741
|
+
402: {
|
|
3742
|
+
name: "PAYMENT_REQUIRED",
|
|
3743
|
+
message: "Payment Required"
|
|
3744
|
+
},
|
|
3745
|
+
403: {
|
|
3746
|
+
name: "FORBIDDEN",
|
|
3747
|
+
message: "Forbidden"
|
|
3748
|
+
},
|
|
3749
|
+
404: {
|
|
3750
|
+
name: "NOT_FOUND",
|
|
3751
|
+
message: "Not Found"
|
|
3752
|
+
},
|
|
3753
|
+
405: {
|
|
3754
|
+
name: "METHOD_NOT_ALLOWED",
|
|
3755
|
+
message: "Method Not Allowed"
|
|
3756
|
+
},
|
|
3757
|
+
406: {
|
|
3758
|
+
name: "NOT_ACCEPTABLE",
|
|
3759
|
+
message: "Not Acceptable"
|
|
3760
|
+
},
|
|
3761
|
+
407: {
|
|
3762
|
+
name: "PROXY_AUTHENTICATION_REQUIRED",
|
|
3763
|
+
message: "Proxy Authentication Required"
|
|
3764
|
+
},
|
|
3765
|
+
408: {
|
|
3766
|
+
name: "REQUEST_TIMEOUT",
|
|
3767
|
+
message: "Request Timeout"
|
|
3768
|
+
},
|
|
3769
|
+
409: {
|
|
3770
|
+
name: "CONFLICT",
|
|
3771
|
+
message: "Conflict"
|
|
3772
|
+
},
|
|
3773
|
+
410: {
|
|
3774
|
+
name: "GONE",
|
|
3775
|
+
message: "Gone"
|
|
3776
|
+
},
|
|
3777
|
+
411: {
|
|
3778
|
+
name: "LENGTH_REQUIRED",
|
|
3779
|
+
message: "Length Required"
|
|
3780
|
+
},
|
|
3781
|
+
412: {
|
|
3782
|
+
name: "PRECONDITION_FAILED",
|
|
3783
|
+
message: "Precondition Failed"
|
|
3784
|
+
},
|
|
3785
|
+
413: {
|
|
3786
|
+
name: "REQUEST_TOO_LONG",
|
|
3787
|
+
message: "Request Entity Too Large"
|
|
3788
|
+
},
|
|
3789
|
+
414: {
|
|
3790
|
+
name: "REQUEST_URI_TOO_LONG",
|
|
3791
|
+
message: "Request-URI Too Long"
|
|
3792
|
+
},
|
|
3793
|
+
415: {
|
|
3794
|
+
name: "UNSUPPORTED_MEDIA_TYPE",
|
|
3795
|
+
message: "Unsupported Media Type"
|
|
3796
|
+
},
|
|
3797
|
+
416: {
|
|
3798
|
+
name: "REQUESTED_RANGE_NOT_SATISFIABLE",
|
|
3799
|
+
message: "Requested Range Not Satisfiable"
|
|
3800
|
+
},
|
|
3801
|
+
417: {
|
|
3802
|
+
name: "EXPECTATION_FAILED",
|
|
3803
|
+
message: "Expectation Failed"
|
|
3804
|
+
},
|
|
3805
|
+
418: {
|
|
3806
|
+
name: "IM_A_TEAPOT",
|
|
3807
|
+
message: "I'm a teapot"
|
|
3808
|
+
},
|
|
3809
|
+
419: {
|
|
3810
|
+
name: "INSUFFICIENT_SPACE_ON_RESOURCE",
|
|
3811
|
+
message: "Insufficient Space on Resource"
|
|
3812
|
+
},
|
|
3813
|
+
420: {
|
|
3814
|
+
name: "METHOD_FAILURE",
|
|
3815
|
+
message: "Method Failure"
|
|
3816
|
+
},
|
|
3817
|
+
421: {
|
|
3818
|
+
name: "MISDIRECTED_REQUEST",
|
|
3819
|
+
message: "Misdirected Request"
|
|
3820
|
+
},
|
|
3821
|
+
422: {
|
|
3822
|
+
name: "UNPROCESSABLE_ENTITY",
|
|
3823
|
+
message: "Unprocessable Entity"
|
|
3824
|
+
},
|
|
3825
|
+
423: {
|
|
3826
|
+
name: "LOCKED",
|
|
3827
|
+
message: "Locked"
|
|
3828
|
+
},
|
|
3829
|
+
424: {
|
|
3830
|
+
name: "FAILED_DEPENDENCY",
|
|
3831
|
+
message: "Failed Dependency"
|
|
3832
|
+
},
|
|
3833
|
+
428: {
|
|
3834
|
+
name: "PRECONDITION_REQUIRED",
|
|
3835
|
+
message: "Precondition Required"
|
|
3836
|
+
},
|
|
3837
|
+
429: {
|
|
3838
|
+
name: "TOO_MANY_REQUESTS",
|
|
3839
|
+
message: "Too Many Requests"
|
|
3840
|
+
},
|
|
3841
|
+
431: {
|
|
3842
|
+
name: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
3843
|
+
message: "Request Header Fields Too Large"
|
|
3844
|
+
},
|
|
3845
|
+
451: {
|
|
3846
|
+
name: "UNAVAILABLE_FOR_LEGAL_REASONS",
|
|
3847
|
+
message: "Unavailable For Legal Reasons"
|
|
3848
|
+
},
|
|
3849
|
+
500: {
|
|
3850
|
+
name: "INTERNAL_SERVER_ERROR",
|
|
3851
|
+
message: "Internal Server Error"
|
|
3852
|
+
},
|
|
3853
|
+
501: {
|
|
3854
|
+
name: "NOT_IMPLEMENTED",
|
|
3855
|
+
message: "Not Implemented"
|
|
3856
|
+
},
|
|
3857
|
+
502: {
|
|
3858
|
+
name: "BAD_GATEWAY",
|
|
3859
|
+
message: "Bad Gateway"
|
|
3860
|
+
},
|
|
3861
|
+
503: {
|
|
3862
|
+
name: "SERVICE_UNAVAILABLE",
|
|
3863
|
+
message: "Service Unavailable"
|
|
3864
|
+
},
|
|
3865
|
+
504: {
|
|
3866
|
+
name: "GATEWAY_TIMEOUT",
|
|
3867
|
+
message: "Gateway Timeout"
|
|
3868
|
+
},
|
|
3869
|
+
505: {
|
|
3870
|
+
name: "HTTP_VERSION_NOT_SUPPORTED",
|
|
3871
|
+
message: "HTTP Version Not Supported"
|
|
3872
|
+
},
|
|
3873
|
+
507: {
|
|
3874
|
+
name: "INSUFFICIENT_STORAGE",
|
|
3875
|
+
message: "Insufficient Storage"
|
|
3876
|
+
},
|
|
3877
|
+
511: {
|
|
3878
|
+
name: "NETWORK_AUTHENTICATION_REQUIRED",
|
|
3879
|
+
message: "Network Authentication Required"
|
|
3880
|
+
}
|
|
3881
|
+
};
|
|
3809
3882
|
|
|
3810
3883
|
var errors$1 = {};
|
|
3811
3884
|
|
|
@@ -5088,55 +5161,255 @@ function requireErrors () {
|
|
|
5088
5161
|
__exportStar(requireErrors(), exports);
|
|
5089
5162
|
} (errors$1));
|
|
5090
5163
|
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5164
|
+
const NUMBER_CHAR_RE = /\d/;
|
|
5165
|
+
const STR_SPLITTERS = ["-", "_", "/", "."];
|
|
5166
|
+
function isUppercase(char = "") {
|
|
5167
|
+
if (NUMBER_CHAR_RE.test(char)) {
|
|
5168
|
+
return void 0;
|
|
5169
|
+
}
|
|
5170
|
+
return char.toUpperCase() === char;
|
|
5171
|
+
}
|
|
5172
|
+
function splitByCase(string_, separators) {
|
|
5173
|
+
const splitters = separators ?? STR_SPLITTERS;
|
|
5174
|
+
const parts = [];
|
|
5175
|
+
if (!string_ || typeof string_ !== "string") {
|
|
5176
|
+
return parts;
|
|
5177
|
+
}
|
|
5178
|
+
let buff = "";
|
|
5179
|
+
let previousUpper;
|
|
5180
|
+
let previousSplitter;
|
|
5181
|
+
for (const char of string_) {
|
|
5182
|
+
const isSplitter = splitters.includes(char);
|
|
5183
|
+
if (isSplitter === true) {
|
|
5184
|
+
parts.push(buff);
|
|
5185
|
+
buff = "";
|
|
5186
|
+
previousUpper = void 0;
|
|
5187
|
+
continue;
|
|
5188
|
+
}
|
|
5189
|
+
const isUpper = isUppercase(char);
|
|
5190
|
+
if (previousSplitter === false) {
|
|
5191
|
+
if (previousUpper === false && isUpper === true) {
|
|
5192
|
+
parts.push(buff);
|
|
5193
|
+
buff = char;
|
|
5194
|
+
previousUpper = isUpper;
|
|
5195
|
+
continue;
|
|
5196
|
+
}
|
|
5197
|
+
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
5198
|
+
const lastChar = buff[buff.length - 1];
|
|
5199
|
+
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
5200
|
+
buff = lastChar + char;
|
|
5201
|
+
previousUpper = isUpper;
|
|
5202
|
+
continue;
|
|
5203
|
+
}
|
|
5204
|
+
}
|
|
5205
|
+
buff += char;
|
|
5206
|
+
previousUpper = isUpper;
|
|
5207
|
+
previousSplitter = isSplitter;
|
|
5208
|
+
}
|
|
5209
|
+
parts.push(buff);
|
|
5210
|
+
return parts;
|
|
5211
|
+
}
|
|
5212
|
+
function upperFirst(string_) {
|
|
5213
|
+
return !string_ ? "" : string_[0].toUpperCase() + string_.slice(1);
|
|
5214
|
+
}
|
|
5215
|
+
function lowerFirst(string_) {
|
|
5216
|
+
return !string_ ? "" : string_[0].toLowerCase() + string_.slice(1);
|
|
5217
|
+
}
|
|
5218
|
+
function pascalCase(string_) {
|
|
5219
|
+
return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => upperFirst(p)).join("");
|
|
5220
|
+
}
|
|
5221
|
+
function camelCase(string_) {
|
|
5222
|
+
return lowerFirst(pascalCase(string_));
|
|
5223
|
+
}
|
|
5224
|
+
function kebabCase(string_, joiner) {
|
|
5225
|
+
return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => p.toLowerCase()).join(joiner ?? "-");
|
|
5226
|
+
}
|
|
5227
|
+
|
|
5228
|
+
function isProcedureDefinition(input) {
|
|
5229
|
+
if (typeof input !== "object") {
|
|
5230
|
+
return false;
|
|
5231
|
+
}
|
|
5232
|
+
const expectedKeys = ["path", "method"];
|
|
5233
|
+
const existingKeys = Object.keys(input);
|
|
5234
|
+
for (const key of expectedKeys) {
|
|
5235
|
+
if (!existingKeys.includes(key)) {
|
|
5236
|
+
return false;
|
|
5237
|
+
}
|
|
5238
|
+
}
|
|
5239
|
+
return isHttpMethod(input.method) && typeof input.path === "string" && (typeof input.params === "string" || typeof input.params === "undefined") && (typeof input.response === "string" || typeof input.response === "undefined");
|
|
5240
|
+
}
|
|
5241
|
+
function isServiceDefinition(input) {
|
|
5242
|
+
if (typeof input !== "object") {
|
|
5243
|
+
return false;
|
|
5244
|
+
}
|
|
5245
|
+
for (const key of Object.keys(input)) {
|
|
5246
|
+
if (typeof input[key] !== "object") {
|
|
5247
|
+
return false;
|
|
5248
|
+
}
|
|
5249
|
+
}
|
|
5250
|
+
return true;
|
|
5251
|
+
}
|
|
5252
|
+
function isApplicationDefinition(input) {
|
|
5253
|
+
if (typeof input !== "object") {
|
|
5254
|
+
return false;
|
|
5255
|
+
}
|
|
5256
|
+
if (!("procedures" in input) || typeof input.procedures !== "object") {
|
|
5257
|
+
return false;
|
|
5258
|
+
}
|
|
5259
|
+
if (!("models" in input) || typeof input.models !== "object") {
|
|
5260
|
+
return false;
|
|
5261
|
+
}
|
|
5262
|
+
if (!("errors" in input) || typeof input.errors !== "object") {
|
|
5263
|
+
return false;
|
|
5264
|
+
}
|
|
5265
|
+
return true;
|
|
5266
|
+
}
|
|
5267
|
+
function unflattenObject(data) {
|
|
5268
|
+
if (Object(data) !== data || Array.isArray(data))
|
|
5269
|
+
return data;
|
|
5270
|
+
const regex = /\.?([^.[\]]+)|\[(\d+)\]/g;
|
|
5271
|
+
const result = {};
|
|
5272
|
+
for (const p in data) {
|
|
5273
|
+
let cur = result;
|
|
5274
|
+
let prop = "";
|
|
5275
|
+
let m;
|
|
5276
|
+
while (m = regex.exec(p)) {
|
|
5277
|
+
cur = cur[prop] || (cur[prop] = m[2] ? [] : {});
|
|
5278
|
+
prop = m[2] || m[1];
|
|
5279
|
+
}
|
|
5280
|
+
cur[prop] = data[p];
|
|
5281
|
+
}
|
|
5282
|
+
return result[""] || result;
|
|
5283
|
+
}
|
|
5284
|
+
function unflattenProcedures(procedures) {
|
|
5285
|
+
return unflattenObject(procedures);
|
|
5286
|
+
}
|
|
5287
|
+
const removeDisallowedChars = (input, disallowedChars) => {
|
|
5288
|
+
let result = input;
|
|
5289
|
+
for (const char of disallowedChars) {
|
|
5290
|
+
if (result.includes(char)) {
|
|
5291
|
+
result = result.split(char).join("");
|
|
5292
|
+
}
|
|
5293
|
+
}
|
|
5294
|
+
return result;
|
|
5295
|
+
};
|
|
5296
|
+
const JsonSchemaScalarTypeValues = [
|
|
5297
|
+
"integer",
|
|
5298
|
+
"number",
|
|
5299
|
+
"bigint",
|
|
5300
|
+
"string",
|
|
5301
|
+
"boolean",
|
|
5302
|
+
"Date"
|
|
5303
|
+
];
|
|
5304
|
+
const JsonSchemaNullTypeValues = ["null", "undefined"];
|
|
5305
|
+
function isJsonSchemaScalarType(input) {
|
|
5306
|
+
if (typeof input !== "object") {
|
|
5307
|
+
return false;
|
|
5308
|
+
}
|
|
5309
|
+
if (!("type" in input)) {
|
|
5310
|
+
return false;
|
|
5311
|
+
}
|
|
5312
|
+
return JsonSchemaScalarTypeValues.includes(input.type);
|
|
5313
|
+
}
|
|
5314
|
+
function isJsonSchemaNullType(input) {
|
|
5315
|
+
if (typeof input !== "object") {
|
|
5316
|
+
return false;
|
|
5317
|
+
}
|
|
5318
|
+
if (!("type" in input)) {
|
|
5319
|
+
return false;
|
|
5320
|
+
}
|
|
5321
|
+
return JsonSchemaNullTypeValues.includes(input.type);
|
|
5322
|
+
}
|
|
5323
|
+
const isJsonSchemaObject = (input) => {
|
|
5324
|
+
if (typeof input !== "object") {
|
|
5325
|
+
return false;
|
|
5326
|
+
}
|
|
5327
|
+
return "type" in input && input.type === "object" && "properties" in input && typeof input.properties === "object";
|
|
5328
|
+
};
|
|
5329
|
+
function isJsonSchemaArray(input) {
|
|
5330
|
+
if (typeof input !== "object") {
|
|
5331
|
+
return false;
|
|
5332
|
+
}
|
|
5333
|
+
if ("type" in input && input.type === "array") {
|
|
5334
|
+
return true;
|
|
5335
|
+
}
|
|
5336
|
+
return false;
|
|
5337
|
+
}
|
|
5338
|
+
function isJsonSchemaEnum(input) {
|
|
5339
|
+
if (typeof input !== "object") {
|
|
5340
|
+
return false;
|
|
5341
|
+
}
|
|
5342
|
+
if (!("anyOf" in input) || !Array.isArray(input.anyOf)) {
|
|
5343
|
+
return false;
|
|
5344
|
+
}
|
|
5345
|
+
let prevType;
|
|
5346
|
+
for (const item of input.anyOf) {
|
|
5347
|
+
if (!isJsonSchemaScalarType(item)) {
|
|
5348
|
+
return false;
|
|
5349
|
+
}
|
|
5350
|
+
if (item.type !== "string" && item.type !== "integer" && item.type !== "number") {
|
|
5351
|
+
return false;
|
|
5352
|
+
}
|
|
5353
|
+
if (!prevType) {
|
|
5354
|
+
prevType = item.type;
|
|
5355
|
+
} else if (prevType !== item.type) {
|
|
5356
|
+
return false;
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
return true;
|
|
5360
|
+
}
|
|
5361
|
+
|
|
5362
|
+
var value$1 = {};
|
|
5363
|
+
|
|
5364
|
+
var delta = {};
|
|
5365
|
+
|
|
5366
|
+
var pointer = {};
|
|
5367
|
+
|
|
5368
|
+
/*--------------------------------------------------------------------------
|
|
5369
|
+
|
|
5370
|
+
@sinclair/typebox/value
|
|
5371
|
+
|
|
5372
|
+
The MIT License (MIT)
|
|
5373
|
+
|
|
5374
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
5375
|
+
|
|
5376
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5377
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5378
|
+
in the Software without restriction, including without limitation the rights
|
|
5379
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
5380
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
5381
|
+
furnished to do so, subject to the following conditions:
|
|
5382
|
+
|
|
5383
|
+
The above copyright notice and this permission notice shall be included in
|
|
5384
|
+
all copies or substantial portions of the Software.
|
|
5385
|
+
|
|
5386
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
5387
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
5388
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
5389
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
5390
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
5391
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
5392
|
+
THE SOFTWARE.
|
|
5393
|
+
|
|
5394
|
+
---------------------------------------------------------------------------*/
|
|
5395
|
+
Object.defineProperty(pointer, "__esModule", { value: true });
|
|
5396
|
+
pointer.ValuePointer = pointer.ValuePointerRootDeleteError = pointer.ValuePointerRootSetError = void 0;
|
|
5397
|
+
// --------------------------------------------------------------------------
|
|
5398
|
+
// Errors
|
|
5399
|
+
// --------------------------------------------------------------------------
|
|
5400
|
+
class ValuePointerRootSetError extends Error {
|
|
5401
|
+
constructor(value, path, update) {
|
|
5402
|
+
super('Cannot set root value');
|
|
5403
|
+
this.value = value;
|
|
5404
|
+
this.path = path;
|
|
5405
|
+
this.update = update;
|
|
5406
|
+
}
|
|
5407
|
+
}
|
|
5408
|
+
pointer.ValuePointerRootSetError = ValuePointerRootSetError;
|
|
5409
|
+
class ValuePointerRootDeleteError extends Error {
|
|
5410
|
+
constructor(value, path) {
|
|
5411
|
+
super('Cannot delete root value');
|
|
5412
|
+
this.value = value;
|
|
5140
5413
|
this.path = path;
|
|
5141
5414
|
}
|
|
5142
5415
|
}
|
|
@@ -8022,448 +8295,6 @@ function typeboxSafeValidate(schema, coerce = false) {
|
|
|
8022
8295
|
return fn;
|
|
8023
8296
|
}
|
|
8024
8297
|
|
|
8025
|
-
const ErrorResponse = typebox.Type.Object(
|
|
8026
|
-
{
|
|
8027
|
-
statusCode: typebox.Type.Integer(),
|
|
8028
|
-
statusMessage: typebox.Type.String(),
|
|
8029
|
-
stack: typebox.Type.Array(typebox.Type.Any()),
|
|
8030
|
-
data: typebox.Type.Optional(typebox.Type.Object({}, { additionalProperties: true }))
|
|
8031
|
-
},
|
|
8032
|
-
{ $id: "ErrorResponse" }
|
|
8033
|
-
);
|
|
8034
|
-
function defineError(statusCode, input = {}) {
|
|
8035
|
-
const defaultVals = errorResponseDefaults[statusCode];
|
|
8036
|
-
return createError({
|
|
8037
|
-
statusCode,
|
|
8038
|
-
statusMessage: input.statusMessage ?? defaultVals.message ?? "An unknown error occurred",
|
|
8039
|
-
stack: input.stack ?? "",
|
|
8040
|
-
data: input.data
|
|
8041
|
-
});
|
|
8042
|
-
}
|
|
8043
|
-
function errorResponseFromValidationErrors(errors, prefixText = `Missing or invalid parameters`) {
|
|
8044
|
-
const errorParts = [];
|
|
8045
|
-
for (const err of errors) {
|
|
8046
|
-
const propName = err.path.split("/");
|
|
8047
|
-
propName.shift();
|
|
8048
|
-
if (!errorParts.includes(propName.join("."))) {
|
|
8049
|
-
errorParts.push(propName.join("."));
|
|
8050
|
-
}
|
|
8051
|
-
}
|
|
8052
|
-
throw defineError(400, {
|
|
8053
|
-
statusMessage: `${prefixText}: [${errorParts.join(",")}]`,
|
|
8054
|
-
data: errors
|
|
8055
|
-
});
|
|
8056
|
-
}
|
|
8057
|
-
const errorResponseDefaults = {
|
|
8058
|
-
400: {
|
|
8059
|
-
name: "BAD_REQUEST",
|
|
8060
|
-
message: "Bad Request"
|
|
8061
|
-
},
|
|
8062
|
-
401: {
|
|
8063
|
-
name: "UNAUTHORIZED",
|
|
8064
|
-
message: "Unauthorized"
|
|
8065
|
-
},
|
|
8066
|
-
402: {
|
|
8067
|
-
name: "PAYMENT_REQUIRED",
|
|
8068
|
-
message: "Payment Required"
|
|
8069
|
-
},
|
|
8070
|
-
403: {
|
|
8071
|
-
name: "FORBIDDEN",
|
|
8072
|
-
message: "Forbidden"
|
|
8073
|
-
},
|
|
8074
|
-
404: {
|
|
8075
|
-
name: "NOT_FOUND",
|
|
8076
|
-
message: "Not Found"
|
|
8077
|
-
},
|
|
8078
|
-
405: {
|
|
8079
|
-
name: "METHOD_NOT_ALLOWED",
|
|
8080
|
-
message: "Method Not Allowed"
|
|
8081
|
-
},
|
|
8082
|
-
406: {
|
|
8083
|
-
name: "NOT_ACCEPTABLE",
|
|
8084
|
-
message: "Not Acceptable"
|
|
8085
|
-
},
|
|
8086
|
-
407: {
|
|
8087
|
-
name: "PROXY_AUTHENTICATION_REQUIRED",
|
|
8088
|
-
message: "Proxy Authentication Required"
|
|
8089
|
-
},
|
|
8090
|
-
408: {
|
|
8091
|
-
name: "REQUEST_TIMEOUT",
|
|
8092
|
-
message: "Request Timeout"
|
|
8093
|
-
},
|
|
8094
|
-
409: {
|
|
8095
|
-
name: "CONFLICT",
|
|
8096
|
-
message: "Conflict"
|
|
8097
|
-
},
|
|
8098
|
-
410: {
|
|
8099
|
-
name: "GONE",
|
|
8100
|
-
message: "Gone"
|
|
8101
|
-
},
|
|
8102
|
-
411: {
|
|
8103
|
-
name: "LENGTH_REQUIRED",
|
|
8104
|
-
message: "Length Required"
|
|
8105
|
-
},
|
|
8106
|
-
412: {
|
|
8107
|
-
name: "PRECONDITION_FAILED",
|
|
8108
|
-
message: "Precondition Failed"
|
|
8109
|
-
},
|
|
8110
|
-
413: {
|
|
8111
|
-
name: "REQUEST_TOO_LONG",
|
|
8112
|
-
message: "Request Entity Too Large"
|
|
8113
|
-
},
|
|
8114
|
-
414: {
|
|
8115
|
-
name: "REQUEST_URI_TOO_LONG",
|
|
8116
|
-
message: "Request-URI Too Long"
|
|
8117
|
-
},
|
|
8118
|
-
415: {
|
|
8119
|
-
name: "UNSUPPORTED_MEDIA_TYPE",
|
|
8120
|
-
message: "Unsupported Media Type"
|
|
8121
|
-
},
|
|
8122
|
-
416: {
|
|
8123
|
-
name: "REQUESTED_RANGE_NOT_SATISFIABLE",
|
|
8124
|
-
message: "Requested Range Not Satisfiable"
|
|
8125
|
-
},
|
|
8126
|
-
417: {
|
|
8127
|
-
name: "EXPECTATION_FAILED",
|
|
8128
|
-
message: "Expectation Failed"
|
|
8129
|
-
},
|
|
8130
|
-
418: {
|
|
8131
|
-
name: "IM_A_TEAPOT",
|
|
8132
|
-
message: "I'm a teapot"
|
|
8133
|
-
},
|
|
8134
|
-
419: {
|
|
8135
|
-
name: "INSUFFICIENT_SPACE_ON_RESOURCE",
|
|
8136
|
-
message: "Insufficient Space on Resource"
|
|
8137
|
-
},
|
|
8138
|
-
420: {
|
|
8139
|
-
name: "METHOD_FAILURE",
|
|
8140
|
-
message: "Method Failure"
|
|
8141
|
-
},
|
|
8142
|
-
421: {
|
|
8143
|
-
name: "MISDIRECTED_REQUEST",
|
|
8144
|
-
message: "Misdirected Request"
|
|
8145
|
-
},
|
|
8146
|
-
422: {
|
|
8147
|
-
name: "UNPROCESSABLE_ENTITY",
|
|
8148
|
-
message: "Unprocessable Entity"
|
|
8149
|
-
},
|
|
8150
|
-
423: {
|
|
8151
|
-
name: "LOCKED",
|
|
8152
|
-
message: "Locked"
|
|
8153
|
-
},
|
|
8154
|
-
424: {
|
|
8155
|
-
name: "FAILED_DEPENDENCY",
|
|
8156
|
-
message: "Failed Dependency"
|
|
8157
|
-
},
|
|
8158
|
-
428: {
|
|
8159
|
-
name: "PRECONDITION_REQUIRED",
|
|
8160
|
-
message: "Precondition Required"
|
|
8161
|
-
},
|
|
8162
|
-
429: {
|
|
8163
|
-
name: "TOO_MANY_REQUESTS",
|
|
8164
|
-
message: "Too Many Requests"
|
|
8165
|
-
},
|
|
8166
|
-
431: {
|
|
8167
|
-
name: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
8168
|
-
message: "Request Header Fields Too Large"
|
|
8169
|
-
},
|
|
8170
|
-
451: {
|
|
8171
|
-
name: "UNAVAILABLE_FOR_LEGAL_REASONS",
|
|
8172
|
-
message: "Unavailable For Legal Reasons"
|
|
8173
|
-
},
|
|
8174
|
-
500: {
|
|
8175
|
-
name: "INTERNAL_SERVER_ERROR",
|
|
8176
|
-
message: "Internal Server Error"
|
|
8177
|
-
},
|
|
8178
|
-
501: {
|
|
8179
|
-
name: "NOT_IMPLEMENTED",
|
|
8180
|
-
message: "Not Implemented"
|
|
8181
|
-
},
|
|
8182
|
-
502: {
|
|
8183
|
-
name: "BAD_GATEWAY",
|
|
8184
|
-
message: "Bad Gateway"
|
|
8185
|
-
},
|
|
8186
|
-
503: {
|
|
8187
|
-
name: "SERVICE_UNAVAILABLE",
|
|
8188
|
-
message: "Service Unavailable"
|
|
8189
|
-
},
|
|
8190
|
-
504: {
|
|
8191
|
-
name: "GATEWAY_TIMEOUT",
|
|
8192
|
-
message: "Gateway Timeout"
|
|
8193
|
-
},
|
|
8194
|
-
505: {
|
|
8195
|
-
name: "HTTP_VERSION_NOT_SUPPORTED",
|
|
8196
|
-
message: "HTTP Version Not Supported"
|
|
8197
|
-
},
|
|
8198
|
-
507: {
|
|
8199
|
-
name: "INSUFFICIENT_STORAGE",
|
|
8200
|
-
message: "Insufficient Storage"
|
|
8201
|
-
},
|
|
8202
|
-
511: {
|
|
8203
|
-
name: "NETWORK_AUTHENTICATION_REQUIRED",
|
|
8204
|
-
message: "Network Authentication Required"
|
|
8205
|
-
}
|
|
8206
|
-
};
|
|
8207
|
-
|
|
8208
|
-
function defineRoute(config) {
|
|
8209
|
-
return config;
|
|
8210
|
-
}
|
|
8211
|
-
const defineMiddleware = (middleware) => middleware;
|
|
8212
|
-
function registerRoute(router, route, middleware, prefix) {
|
|
8213
|
-
const handler = async (event) => {
|
|
8214
|
-
const context = {
|
|
8215
|
-
event
|
|
8216
|
-
};
|
|
8217
|
-
if (middleware.length) {
|
|
8218
|
-
for (const m of middleware) {
|
|
8219
|
-
await m(context);
|
|
8220
|
-
}
|
|
8221
|
-
}
|
|
8222
|
-
if (route.query) {
|
|
8223
|
-
const result = await getValidatedQuery(
|
|
8224
|
-
event,
|
|
8225
|
-
typeboxSafeValidate(route.query)
|
|
8226
|
-
);
|
|
8227
|
-
if (!result.success) {
|
|
8228
|
-
throw errorResponseFromValidationErrors(
|
|
8229
|
-
result.errors,
|
|
8230
|
-
"Missing or invalid query parameters"
|
|
8231
|
-
);
|
|
8232
|
-
}
|
|
8233
|
-
context.query = result.value;
|
|
8234
|
-
}
|
|
8235
|
-
if (route.body && route.method !== "get" && route.method !== "head") {
|
|
8236
|
-
const result = await readValidatedBody(
|
|
8237
|
-
event,
|
|
8238
|
-
typeboxSafeValidate(route.body)
|
|
8239
|
-
);
|
|
8240
|
-
if (!result.success) {
|
|
8241
|
-
throw errorResponseFromValidationErrors(
|
|
8242
|
-
result.errors,
|
|
8243
|
-
"Missing or invalid body parameters"
|
|
8244
|
-
);
|
|
8245
|
-
}
|
|
8246
|
-
context.body = result.value;
|
|
8247
|
-
}
|
|
8248
|
-
const response = await route.handler(context);
|
|
8249
|
-
if (typeof response === "object") {
|
|
8250
|
-
setResponseHeader(event, "Content-Type", "application/json");
|
|
8251
|
-
await send(event, JSON.stringify(response));
|
|
8252
|
-
} else {
|
|
8253
|
-
await send(event, response);
|
|
8254
|
-
}
|
|
8255
|
-
if (route.postHandler) {
|
|
8256
|
-
context.response = response;
|
|
8257
|
-
await route.postHandler(context);
|
|
8258
|
-
}
|
|
8259
|
-
return null;
|
|
8260
|
-
};
|
|
8261
|
-
const finalPath = (prefix ? `/${prefix}${route.path}` : route.path).split("//").join("/");
|
|
8262
|
-
switch (route.method) {
|
|
8263
|
-
case "get":
|
|
8264
|
-
router.get(finalPath, handler);
|
|
8265
|
-
break;
|
|
8266
|
-
case "head":
|
|
8267
|
-
router.head(finalPath, handler);
|
|
8268
|
-
break;
|
|
8269
|
-
case "delete":
|
|
8270
|
-
router.delete(finalPath, handler);
|
|
8271
|
-
break;
|
|
8272
|
-
case "patch":
|
|
8273
|
-
router.patch(finalPath, handler);
|
|
8274
|
-
break;
|
|
8275
|
-
case "post":
|
|
8276
|
-
router.post(finalPath, handler);
|
|
8277
|
-
break;
|
|
8278
|
-
case "put":
|
|
8279
|
-
router.put(finalPath, handler);
|
|
8280
|
-
break;
|
|
8281
|
-
}
|
|
8282
|
-
}
|
|
8283
|
-
|
|
8284
|
-
function isProcedureDefinition(input) {
|
|
8285
|
-
if (typeof input !== "object") {
|
|
8286
|
-
return false;
|
|
8287
|
-
}
|
|
8288
|
-
const expectedKeys = ["path", "method"];
|
|
8289
|
-
const existingKeys = Object.keys(input);
|
|
8290
|
-
for (const key of expectedKeys) {
|
|
8291
|
-
if (!existingKeys.includes(key)) {
|
|
8292
|
-
return false;
|
|
8293
|
-
}
|
|
8294
|
-
}
|
|
8295
|
-
return isHttpMethod(input.method) && typeof input.path === "string" && (typeof input.params === "string" || typeof input.params === "undefined") && (typeof input.response === "string" || typeof input.response === "undefined");
|
|
8296
|
-
}
|
|
8297
|
-
function isServiceDefinition(input) {
|
|
8298
|
-
if (typeof input !== "object") {
|
|
8299
|
-
return false;
|
|
8300
|
-
}
|
|
8301
|
-
for (const key of Object.keys(input)) {
|
|
8302
|
-
if (typeof input[key] !== "object") {
|
|
8303
|
-
return false;
|
|
8304
|
-
}
|
|
8305
|
-
}
|
|
8306
|
-
return true;
|
|
8307
|
-
}
|
|
8308
|
-
function unflattenObject(data) {
|
|
8309
|
-
if (Object(data) !== data || Array.isArray(data))
|
|
8310
|
-
return data;
|
|
8311
|
-
const regex = /\.?([^.[\]]+)|\[(\d+)\]/g;
|
|
8312
|
-
const result = {};
|
|
8313
|
-
for (const p in data) {
|
|
8314
|
-
let cur = result;
|
|
8315
|
-
let prop = "";
|
|
8316
|
-
let m;
|
|
8317
|
-
while (m = regex.exec(p)) {
|
|
8318
|
-
cur = cur[prop] || (cur[prop] = m[2] ? [] : {});
|
|
8319
|
-
prop = m[2] || m[1];
|
|
8320
|
-
}
|
|
8321
|
-
cur[prop] = data[p];
|
|
8322
|
-
}
|
|
8323
|
-
return result[""] || result;
|
|
8324
|
-
}
|
|
8325
|
-
function unflattenProcedures(procedures) {
|
|
8326
|
-
return unflattenObject(procedures);
|
|
8327
|
-
}
|
|
8328
|
-
const removeDisallowedChars = (input, disallowedChars) => {
|
|
8329
|
-
let result = input;
|
|
8330
|
-
for (const char of disallowedChars) {
|
|
8331
|
-
if (result.includes(char)) {
|
|
8332
|
-
result = result.split(char).join("");
|
|
8333
|
-
}
|
|
8334
|
-
}
|
|
8335
|
-
return result;
|
|
8336
|
-
};
|
|
8337
|
-
const JsonSchemaScalarTypeValues = [
|
|
8338
|
-
"integer",
|
|
8339
|
-
"number",
|
|
8340
|
-
"bigint",
|
|
8341
|
-
"string",
|
|
8342
|
-
"boolean",
|
|
8343
|
-
"Date"
|
|
8344
|
-
];
|
|
8345
|
-
const JsonSchemaNullTypeValues = ["null", "undefined"];
|
|
8346
|
-
function isJsonSchemaScalarType(input) {
|
|
8347
|
-
if (typeof input !== "object") {
|
|
8348
|
-
return false;
|
|
8349
|
-
}
|
|
8350
|
-
if (!("type" in input)) {
|
|
8351
|
-
return false;
|
|
8352
|
-
}
|
|
8353
|
-
return JsonSchemaScalarTypeValues.includes(input.type);
|
|
8354
|
-
}
|
|
8355
|
-
function isJsonSchemaNullType(input) {
|
|
8356
|
-
if (typeof input !== "object") {
|
|
8357
|
-
return false;
|
|
8358
|
-
}
|
|
8359
|
-
if (!("type" in input)) {
|
|
8360
|
-
return false;
|
|
8361
|
-
}
|
|
8362
|
-
return JsonSchemaNullTypeValues.includes(input.type);
|
|
8363
|
-
}
|
|
8364
|
-
const isJsonSchemaObject = (input) => {
|
|
8365
|
-
if (typeof input !== "object") {
|
|
8366
|
-
return false;
|
|
8367
|
-
}
|
|
8368
|
-
return "type" in input && input.type === "object" && "properties" in input && typeof input.properties === "object";
|
|
8369
|
-
};
|
|
8370
|
-
function isJsonSchemaArray(input) {
|
|
8371
|
-
if (typeof input !== "object") {
|
|
8372
|
-
return false;
|
|
8373
|
-
}
|
|
8374
|
-
if ("type" in input && input.type === "array") {
|
|
8375
|
-
return true;
|
|
8376
|
-
}
|
|
8377
|
-
return false;
|
|
8378
|
-
}
|
|
8379
|
-
function isJsonSchemaEnum(input) {
|
|
8380
|
-
if (typeof input !== "object") {
|
|
8381
|
-
return false;
|
|
8382
|
-
}
|
|
8383
|
-
if (!("anyOf" in input) || !Array.isArray(input.anyOf)) {
|
|
8384
|
-
return false;
|
|
8385
|
-
}
|
|
8386
|
-
let prevType;
|
|
8387
|
-
for (const item of input.anyOf) {
|
|
8388
|
-
if (!isJsonSchemaScalarType(item)) {
|
|
8389
|
-
return false;
|
|
8390
|
-
}
|
|
8391
|
-
if (item.type !== "string" && item.type !== "integer" && item.type !== "number") {
|
|
8392
|
-
return false;
|
|
8393
|
-
}
|
|
8394
|
-
if (!prevType) {
|
|
8395
|
-
prevType = item.type;
|
|
8396
|
-
} else if (prevType !== item.type) {
|
|
8397
|
-
return false;
|
|
8398
|
-
}
|
|
8399
|
-
}
|
|
8400
|
-
return true;
|
|
8401
|
-
}
|
|
8402
|
-
|
|
8403
|
-
const NUMBER_CHAR_RE = /\d/;
|
|
8404
|
-
const STR_SPLITTERS = ["-", "_", "/", "."];
|
|
8405
|
-
function isUppercase(char = "") {
|
|
8406
|
-
if (NUMBER_CHAR_RE.test(char)) {
|
|
8407
|
-
return void 0;
|
|
8408
|
-
}
|
|
8409
|
-
return char.toUpperCase() === char;
|
|
8410
|
-
}
|
|
8411
|
-
function splitByCase(string_, separators) {
|
|
8412
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
8413
|
-
const parts = [];
|
|
8414
|
-
if (!string_ || typeof string_ !== "string") {
|
|
8415
|
-
return parts;
|
|
8416
|
-
}
|
|
8417
|
-
let buff = "";
|
|
8418
|
-
let previousUpper;
|
|
8419
|
-
let previousSplitter;
|
|
8420
|
-
for (const char of string_) {
|
|
8421
|
-
const isSplitter = splitters.includes(char);
|
|
8422
|
-
if (isSplitter === true) {
|
|
8423
|
-
parts.push(buff);
|
|
8424
|
-
buff = "";
|
|
8425
|
-
previousUpper = void 0;
|
|
8426
|
-
continue;
|
|
8427
|
-
}
|
|
8428
|
-
const isUpper = isUppercase(char);
|
|
8429
|
-
if (previousSplitter === false) {
|
|
8430
|
-
if (previousUpper === false && isUpper === true) {
|
|
8431
|
-
parts.push(buff);
|
|
8432
|
-
buff = char;
|
|
8433
|
-
previousUpper = isUpper;
|
|
8434
|
-
continue;
|
|
8435
|
-
}
|
|
8436
|
-
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
8437
|
-
const lastChar = buff[buff.length - 1];
|
|
8438
|
-
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
8439
|
-
buff = lastChar + char;
|
|
8440
|
-
previousUpper = isUpper;
|
|
8441
|
-
continue;
|
|
8442
|
-
}
|
|
8443
|
-
}
|
|
8444
|
-
buff += char;
|
|
8445
|
-
previousUpper = isUpper;
|
|
8446
|
-
previousSplitter = isSplitter;
|
|
8447
|
-
}
|
|
8448
|
-
parts.push(buff);
|
|
8449
|
-
return parts;
|
|
8450
|
-
}
|
|
8451
|
-
function upperFirst(string_) {
|
|
8452
|
-
return !string_ ? "" : string_[0].toUpperCase() + string_.slice(1);
|
|
8453
|
-
}
|
|
8454
|
-
function lowerFirst(string_) {
|
|
8455
|
-
return !string_ ? "" : string_[0].toLowerCase() + string_.slice(1);
|
|
8456
|
-
}
|
|
8457
|
-
function pascalCase(string_) {
|
|
8458
|
-
return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => upperFirst(p)).join("");
|
|
8459
|
-
}
|
|
8460
|
-
function camelCase(string_) {
|
|
8461
|
-
return lowerFirst(pascalCase(string_));
|
|
8462
|
-
}
|
|
8463
|
-
function kebabCase(string_, joiner) {
|
|
8464
|
-
return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => p.toLowerCase()).join(joiner ?? "-");
|
|
8465
|
-
}
|
|
8466
|
-
|
|
8467
8298
|
function isRpc(input) {
|
|
8468
8299
|
if (typeof input !== "object") {
|
|
8469
8300
|
return false;
|
|
@@ -8545,6 +8376,7 @@ function getRpcResponseDefinition(rpcName, procedure) {
|
|
|
8545
8376
|
function registerRpc(router, path, procedure, middleware) {
|
|
8546
8377
|
const httpMethod = procedure.method ?? "post";
|
|
8547
8378
|
const handler = eventHandler(async (event) => {
|
|
8379
|
+
console.log(getRequestHeaders(event));
|
|
8548
8380
|
const context = {
|
|
8549
8381
|
event
|
|
8550
8382
|
};
|
|
@@ -8655,24 +8487,103 @@ function registerRpc(router, path, procedure, middleware) {
|
|
|
8655
8487
|
}
|
|
8656
8488
|
}
|
|
8657
8489
|
|
|
8490
|
+
function defineRoute(config) {
|
|
8491
|
+
return config;
|
|
8492
|
+
}
|
|
8493
|
+
const defineMiddleware = (middleware) => middleware;
|
|
8494
|
+
function registerRoute(router, route, middleware, prefix) {
|
|
8495
|
+
const handler = async (event) => {
|
|
8496
|
+
const context = {
|
|
8497
|
+
event
|
|
8498
|
+
};
|
|
8499
|
+
if (middleware.length) {
|
|
8500
|
+
for (const m of middleware) {
|
|
8501
|
+
await m(context);
|
|
8502
|
+
}
|
|
8503
|
+
}
|
|
8504
|
+
if (route.query) {
|
|
8505
|
+
const result = await getValidatedQuery(
|
|
8506
|
+
event,
|
|
8507
|
+
typeboxSafeValidate(route.query)
|
|
8508
|
+
);
|
|
8509
|
+
if (!result.success) {
|
|
8510
|
+
throw errorResponseFromValidationErrors(
|
|
8511
|
+
result.errors,
|
|
8512
|
+
"Missing or invalid query parameters"
|
|
8513
|
+
);
|
|
8514
|
+
}
|
|
8515
|
+
context.query = result.value;
|
|
8516
|
+
}
|
|
8517
|
+
if (route.body && route.method !== "get" && route.method !== "head") {
|
|
8518
|
+
const result = await readValidatedBody(
|
|
8519
|
+
event,
|
|
8520
|
+
typeboxSafeValidate(route.body)
|
|
8521
|
+
);
|
|
8522
|
+
if (!result.success) {
|
|
8523
|
+
throw errorResponseFromValidationErrors(
|
|
8524
|
+
result.errors,
|
|
8525
|
+
"Missing or invalid body parameters"
|
|
8526
|
+
);
|
|
8527
|
+
}
|
|
8528
|
+
context.body = result.value;
|
|
8529
|
+
}
|
|
8530
|
+
const response = await route.handler(context);
|
|
8531
|
+
if (typeof response === "object") {
|
|
8532
|
+
setResponseHeader(event, "Content-Type", "application/json");
|
|
8533
|
+
await send(event, JSON.stringify(response));
|
|
8534
|
+
} else {
|
|
8535
|
+
await send(event, response);
|
|
8536
|
+
}
|
|
8537
|
+
if (route.postHandler) {
|
|
8538
|
+
context.response = response;
|
|
8539
|
+
await route.postHandler(context);
|
|
8540
|
+
}
|
|
8541
|
+
return null;
|
|
8542
|
+
};
|
|
8543
|
+
const finalPath = (prefix ? `/${prefix}${route.path}` : route.path).split("//").join("/");
|
|
8544
|
+
switch (route.method) {
|
|
8545
|
+
case "get":
|
|
8546
|
+
router.get(finalPath, handler);
|
|
8547
|
+
break;
|
|
8548
|
+
case "head":
|
|
8549
|
+
router.head(finalPath, handler);
|
|
8550
|
+
break;
|
|
8551
|
+
case "delete":
|
|
8552
|
+
router.delete(finalPath, handler);
|
|
8553
|
+
break;
|
|
8554
|
+
case "patch":
|
|
8555
|
+
router.patch(finalPath, handler);
|
|
8556
|
+
break;
|
|
8557
|
+
case "post":
|
|
8558
|
+
router.post(finalPath, handler);
|
|
8559
|
+
break;
|
|
8560
|
+
case "put":
|
|
8561
|
+
router.put(finalPath, handler);
|
|
8562
|
+
break;
|
|
8563
|
+
}
|
|
8564
|
+
}
|
|
8565
|
+
|
|
8658
8566
|
var __defProp = Object.defineProperty;
|
|
8659
8567
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8660
8568
|
var __publicField = (obj, key, value) => {
|
|
8661
8569
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8662
8570
|
return value;
|
|
8663
8571
|
};
|
|
8664
|
-
|
|
8572
|
+
const DEV_ENDPOINT_ROOT = `/__arri_dev__`;
|
|
8573
|
+
const DEV_DEFINITION_ENDPOINT = `${DEV_ENDPOINT_ROOT}/definition`;
|
|
8574
|
+
class Arri {
|
|
8665
8575
|
constructor(opts) {
|
|
8666
|
-
__publicField(this, "
|
|
8667
|
-
__publicField(this, "
|
|
8668
|
-
__publicField(this, "
|
|
8576
|
+
__publicField(this, "__isArri__", true);
|
|
8577
|
+
__publicField(this, "h3App");
|
|
8578
|
+
__publicField(this, "h3Router", createRouter());
|
|
8669
8579
|
__publicField(this, "rpcDefinitionPath");
|
|
8580
|
+
__publicField(this, "rpcRoutePrefix");
|
|
8670
8581
|
__publicField(this, "procedures", {});
|
|
8671
8582
|
__publicField(this, "models", {});
|
|
8672
8583
|
__publicField(this, "middlewares", []);
|
|
8673
8584
|
__publicField(this, "appDescription");
|
|
8674
8585
|
this.appDescription = opts?.appDescription ?? "";
|
|
8675
|
-
this.
|
|
8586
|
+
this.h3App = createApp({
|
|
8676
8587
|
debug: opts?.debug,
|
|
8677
8588
|
onAfterResponse: opts?.onAfterResponse,
|
|
8678
8589
|
onBeforeResponse: opts?.onBeforeResponse,
|
|
@@ -8689,22 +8600,22 @@ class ArriServer {
|
|
|
8689
8600
|
}
|
|
8690
8601
|
});
|
|
8691
8602
|
this.rpcRoutePrefix = opts?.rpcRoutePrefix ?? "";
|
|
8692
|
-
this.rpcDefinitionPath = opts?.rpcDefinitionPath ?? "
|
|
8693
|
-
this.
|
|
8694
|
-
this.rpcRoutePrefix ? `/${this.rpcRoutePrefix}
|
|
8603
|
+
this.rpcDefinitionPath = opts?.rpcDefinitionPath ?? "__definition";
|
|
8604
|
+
this.h3Router.get(
|
|
8605
|
+
this.rpcRoutePrefix ? `/${this.rpcRoutePrefix}/${this.rpcDefinitionPath}`.split("//").join("/") : `/${this.rpcDefinitionPath}`,
|
|
8695
8606
|
eventHandler((_) => this.getAppDefinition())
|
|
8696
8607
|
);
|
|
8608
|
+
this.h3App.use(this.h3Router);
|
|
8609
|
+
if (process.env.ARRI_DEV_MODE === "true") {
|
|
8610
|
+
this.h3Router.get(
|
|
8611
|
+
DEV_DEFINITION_ENDPOINT,
|
|
8612
|
+
eventHandler((_) => this.getAppDefinition())
|
|
8613
|
+
);
|
|
8614
|
+
}
|
|
8697
8615
|
}
|
|
8698
8616
|
registerMiddleware(middleware) {
|
|
8699
8617
|
this.middlewares.push(middleware);
|
|
8700
8618
|
}
|
|
8701
|
-
/**
|
|
8702
|
-
* Statically register routes to the server router
|
|
8703
|
-
* Routes will not be served until this is done
|
|
8704
|
-
*/
|
|
8705
|
-
initializeRoutes() {
|
|
8706
|
-
this.app.use(this.router);
|
|
8707
|
-
}
|
|
8708
8619
|
registerRpc(name, procedure) {
|
|
8709
8620
|
const path = getRpcPath(name, this.rpcRoutePrefix);
|
|
8710
8621
|
this.procedures[name] = createRpcDefinition(name, path, procedure);
|
|
@@ -8720,10 +8631,10 @@ class ArriServer {
|
|
|
8720
8631
|
this.models[responseName] = procedure.response;
|
|
8721
8632
|
}
|
|
8722
8633
|
}
|
|
8723
|
-
registerRpc(this.
|
|
8634
|
+
registerRpc(this.h3Router, path, procedure, this.middlewares);
|
|
8724
8635
|
}
|
|
8725
8636
|
registerRoute(route) {
|
|
8726
|
-
registerRoute(this.
|
|
8637
|
+
registerRoute(this.h3Router, route, this.middlewares);
|
|
8727
8638
|
}
|
|
8728
8639
|
getAppDefinition() {
|
|
8729
8640
|
const appDef = {
|
|
@@ -8739,6 +8650,9 @@ class ArriServer {
|
|
|
8739
8650
|
});
|
|
8740
8651
|
return appDef;
|
|
8741
8652
|
}
|
|
8653
|
+
getH3Instance() {
|
|
8654
|
+
return this.h3App;
|
|
8655
|
+
}
|
|
8742
8656
|
}
|
|
8743
8657
|
const HttpMethodValues = [
|
|
8744
8658
|
"get",
|
|
@@ -8755,7 +8669,9 @@ const isHttpMethod = (input) => {
|
|
|
8755
8669
|
return HttpMethodValues.includes(input);
|
|
8756
8670
|
};
|
|
8757
8671
|
|
|
8758
|
-
exports.
|
|
8672
|
+
exports.Arri = Arri;
|
|
8673
|
+
exports.DEV_DEFINITION_ENDPOINT = DEV_DEFINITION_ENDPOINT;
|
|
8674
|
+
exports.DEV_ENDPOINT_ROOT = DEV_ENDPOINT_ROOT;
|
|
8759
8675
|
exports.ErrorResponse = ErrorResponse;
|
|
8760
8676
|
exports.HttpMethodValues = HttpMethodValues;
|
|
8761
8677
|
exports.camelCase = camelCase;
|
|
@@ -8773,6 +8689,7 @@ exports.getRpcParamDefinition = getRpcParamDefinition;
|
|
|
8773
8689
|
exports.getRpcParamName = getRpcParamName;
|
|
8774
8690
|
exports.getRpcPath = getRpcPath;
|
|
8775
8691
|
exports.getRpcResponseName = getRpcResponseName;
|
|
8692
|
+
exports.isApplicationDefinition = isApplicationDefinition;
|
|
8776
8693
|
exports.isHttpMethod = isHttpMethod;
|
|
8777
8694
|
exports.isJsonSchemaArray = isJsonSchemaArray;
|
|
8778
8695
|
exports.isJsonSchemaEnum = isJsonSchemaEnum;
|
|
@@ -8788,8 +8705,6 @@ exports.pascalCase = pascalCase;
|
|
|
8788
8705
|
exports.registerRoute = registerRoute;
|
|
8789
8706
|
exports.registerRpc = registerRpc;
|
|
8790
8707
|
exports.removeDisallowedChars = removeDisallowedChars;
|
|
8791
|
-
exports.toNodeListener = toNodeListener;
|
|
8792
|
-
exports.typebox = typebox;
|
|
8793
8708
|
exports.unflattenObject = unflattenObject;
|
|
8794
8709
|
exports.unflattenProcedures = unflattenProcedures;
|
|
8795
8710
|
exports.withBase = withBase;
|