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