arri 0.0.5 → 0.0.6

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.
@@ -1,5 +1,34 @@
1
1
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
2
 
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ function getAugmentedNamespace(n) {
8
+ if (n.__esModule) return n;
9
+ var f = n.default;
10
+ if (typeof f == "function") {
11
+ var a = function a () {
12
+ if (this instanceof a) {
13
+ return Reflect.construct(f, arguments, this.constructor);
14
+ }
15
+ return f.apply(this, arguments);
16
+ };
17
+ a.prototype = f.prototype;
18
+ } else a = {};
19
+ Object.defineProperty(a, '__esModule', {value: true});
20
+ Object.keys(n).forEach(function (k) {
21
+ var d = Object.getOwnPropertyDescriptor(n, k);
22
+ Object.defineProperty(a, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () {
25
+ return n[k];
26
+ }
27
+ });
28
+ });
29
+ return a;
30
+ }
31
+
3
32
  var typebox = {};
4
33
 
5
34
  (function (exports) {
@@ -2410,9 +2439,35 @@ function withoutTrailingSlash(input = "", queryParameters = false) {
2410
2439
  const [s0, ...s] = input.split("?");
2411
2440
  return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
2412
2441
  }
2442
+ function withTrailingSlash(input = "", queryParameters = false) {
2443
+ if (!queryParameters) {
2444
+ return input.endsWith("/") ? input : input + "/";
2445
+ }
2446
+ if (hasTrailingSlash(input, true)) {
2447
+ return input || "/";
2448
+ }
2449
+ const [s0, ...s] = input.split("?");
2450
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
2451
+ }
2413
2452
  function getQuery$1(input) {
2414
2453
  return parseQuery(parseURL(input).search);
2415
2454
  }
2455
+ function isNonEmptyURL(url) {
2456
+ return url && url !== "/";
2457
+ }
2458
+ const JOIN_LEADING_SLASH_RE = /^\.?\//;
2459
+ function joinURL(base, ...input) {
2460
+ let url = base || "";
2461
+ for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
2462
+ if (url) {
2463
+ const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
2464
+ url = withTrailingSlash(url) + _segment;
2465
+ } else {
2466
+ url = segment;
2467
+ }
2468
+ }
2469
+ return url;
2470
+ }
2416
2471
 
2417
2472
  function parseURL(input = "", defaultProto) {
2418
2473
  const _specialProtoMatch = input.match(
@@ -3240,6 +3295,74 @@ function isPreflightRequest(event) {
3240
3295
  return event.method === "OPTIONS" && !!origin && !!accessControlRequestMethod;
3241
3296
  }
3242
3297
 
3298
+ class H3Event {
3299
+ constructor(req, res) {
3300
+ this["__is_event__"] = true;
3301
+ // Web
3302
+ this.context = {};
3303
+ // Response
3304
+ this._handled = false;
3305
+ this.node = { req, res };
3306
+ }
3307
+ // --- Request ---
3308
+ get method() {
3309
+ if (!this._method) {
3310
+ this._method = (this.node.req.method || "GET").toUpperCase();
3311
+ }
3312
+ return this._method;
3313
+ }
3314
+ get path() {
3315
+ return this._path || this.node.req.url || "/";
3316
+ }
3317
+ get headers() {
3318
+ if (!this._headers) {
3319
+ this._headers = _normalizeNodeHeaders(this.node.req.headers);
3320
+ }
3321
+ return this._headers;
3322
+ }
3323
+ // --- Respoonse ---
3324
+ get handled() {
3325
+ return this._handled || this.node.res.writableEnded || this.node.res.headersSent;
3326
+ }
3327
+ respondWith(response) {
3328
+ return Promise.resolve(response).then(
3329
+ (_response) => sendWebResponse(this, _response)
3330
+ );
3331
+ }
3332
+ // --- Utils ---
3333
+ toString() {
3334
+ return `[${this.method}] ${this.path}`;
3335
+ }
3336
+ toJSON() {
3337
+ return this.toString();
3338
+ }
3339
+ // --- Deprecated ---
3340
+ /** @deprecated Please use `event.node.req` instead. **/
3341
+ get req() {
3342
+ return this.node.req;
3343
+ }
3344
+ /** @deprecated Please use `event.node.res` instead. **/
3345
+ get res() {
3346
+ return this.node.res;
3347
+ }
3348
+ }
3349
+ function createEvent(req, res) {
3350
+ return new H3Event(req, res);
3351
+ }
3352
+ function _normalizeNodeHeaders(nodeHeaders) {
3353
+ const headers = new Headers();
3354
+ for (const [name, value] of Object.entries(nodeHeaders)) {
3355
+ if (Array.isArray(value)) {
3356
+ for (const item of value) {
3357
+ headers.append(name, item);
3358
+ }
3359
+ } else if (value) {
3360
+ headers.set(name, value);
3361
+ }
3362
+ }
3363
+ return headers;
3364
+ }
3365
+
3243
3366
  function defineEventHandler(handler) {
3244
3367
  if (typeof handler === "function") {
3245
3368
  return Object.assign(handler, { __is_handler__: true });
@@ -3563,6 +3686,30 @@ function createRouter(opts = {}) {
3563
3686
  });
3564
3687
  return router;
3565
3688
  }
3689
+ function toNodeListener(app) {
3690
+ const toNodeHandle = async function(req, res) {
3691
+ const event = createEvent(req, res);
3692
+ try {
3693
+ await app.handler(event);
3694
+ } catch (_error) {
3695
+ const error = createError(_error);
3696
+ if (!isError(_error)) {
3697
+ error.unhandled = true;
3698
+ }
3699
+ if (app.options.onError) {
3700
+ await app.options.onError(error, event);
3701
+ }
3702
+ if (event.handled) {
3703
+ return;
3704
+ }
3705
+ if (error.unhandled || error.fatal) {
3706
+ console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
3707
+ }
3708
+ await sendError(event, error, !!app.options.debug);
3709
+ }
3710
+ };
3711
+ return toNodeHandle;
3712
+ }
3566
3713
 
3567
3714
  var value$1 = {};
3568
3715
 
@@ -8479,4 +8626,4 @@ const isHttpMethod = (input) => {
8479
8626
  return HttpMethodValues.includes(input);
8480
8627
  };
8481
8628
 
8482
- export { ArriServer as A, ErrorResponse as E, HttpMethodValues as H, isJsonSchemaScalarType as a, isJsonSchemaNullType as b, isJsonSchemaObject as c, isJsonSchemaEnum as d, isJsonSchemaArray as e, camelCase as f, isHttpMethod as g, isRpc as h, isProcedureDefinition as i, defineRpc as j, createRpcDefinition as k, getRpcPath as l, getRpcParamName as m, getRpcParamDefinition as n, getRpcResponseName as o, pascalCase as p, defineRoute as q, registerRpc as r, defineMiddleware as s, registerRoute as t, unflattenObject as u, defineError as v, errorResponseFromValidationErrors as w };
8629
+ export { ArriServer as A, registerRpc as B, defineRoute as C, defineMiddleware as D, ErrorResponse as E, registerRoute as F, defineError as G, HttpMethodValues as H, errorResponseFromValidationErrors as I, isJsonSchemaScalarType as a, isJsonSchemaNullType as b, isJsonSchemaObject as c, isJsonSchemaEnum as d, isJsonSchemaArray as e, camelCase as f, commonjsGlobal as g, getDefaultExportFromCjs as h, isProcedureDefinition as i, getAugmentedNamespace as j, destr as k, joinURL as l, isRpc as m, typebox as n, kebabCase as o, pascalCase as p, isHttpMethod as q, removeDisallowedChars as r, defineRpc as s, toNodeListener as t, unflattenObject as u, createRpcDefinition as v, getRpcPath as w, getRpcParamName as x, getRpcParamDefinition as y, getRpcResponseName as z };
@@ -2,6 +2,35 @@
2
2
 
3
3
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
4
4
 
5
+ function getDefaultExportFromCjs (x) {
6
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
7
+ }
8
+
9
+ function getAugmentedNamespace(n) {
10
+ if (n.__esModule) return n;
11
+ var f = n.default;
12
+ if (typeof f == "function") {
13
+ var a = function a () {
14
+ if (this instanceof a) {
15
+ return Reflect.construct(f, arguments, this.constructor);
16
+ }
17
+ return f.apply(this, arguments);
18
+ };
19
+ a.prototype = f.prototype;
20
+ } else a = {};
21
+ Object.defineProperty(a, '__esModule', {value: true});
22
+ Object.keys(n).forEach(function (k) {
23
+ var d = Object.getOwnPropertyDescriptor(n, k);
24
+ Object.defineProperty(a, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () {
27
+ return n[k];
28
+ }
29
+ });
30
+ });
31
+ return a;
32
+ }
33
+
5
34
  var typebox = {};
6
35
 
7
36
  (function (exports) {
@@ -2412,9 +2441,35 @@ function withoutTrailingSlash(input = "", queryParameters = false) {
2412
2441
  const [s0, ...s] = input.split("?");
2413
2442
  return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
2414
2443
  }
2444
+ function withTrailingSlash(input = "", queryParameters = false) {
2445
+ if (!queryParameters) {
2446
+ return input.endsWith("/") ? input : input + "/";
2447
+ }
2448
+ if (hasTrailingSlash(input, true)) {
2449
+ return input || "/";
2450
+ }
2451
+ const [s0, ...s] = input.split("?");
2452
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
2453
+ }
2415
2454
  function getQuery$1(input) {
2416
2455
  return parseQuery(parseURL(input).search);
2417
2456
  }
2457
+ function isNonEmptyURL(url) {
2458
+ return url && url !== "/";
2459
+ }
2460
+ const JOIN_LEADING_SLASH_RE = /^\.?\//;
2461
+ function joinURL(base, ...input) {
2462
+ let url = base || "";
2463
+ for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
2464
+ if (url) {
2465
+ const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
2466
+ url = withTrailingSlash(url) + _segment;
2467
+ } else {
2468
+ url = segment;
2469
+ }
2470
+ }
2471
+ return url;
2472
+ }
2418
2473
 
2419
2474
  function parseURL(input = "", defaultProto) {
2420
2475
  const _specialProtoMatch = input.match(
@@ -3242,6 +3297,74 @@ function isPreflightRequest(event) {
3242
3297
  return event.method === "OPTIONS" && !!origin && !!accessControlRequestMethod;
3243
3298
  }
3244
3299
 
3300
+ class H3Event {
3301
+ constructor(req, res) {
3302
+ this["__is_event__"] = true;
3303
+ // Web
3304
+ this.context = {};
3305
+ // Response
3306
+ this._handled = false;
3307
+ this.node = { req, res };
3308
+ }
3309
+ // --- Request ---
3310
+ get method() {
3311
+ if (!this._method) {
3312
+ this._method = (this.node.req.method || "GET").toUpperCase();
3313
+ }
3314
+ return this._method;
3315
+ }
3316
+ get path() {
3317
+ return this._path || this.node.req.url || "/";
3318
+ }
3319
+ get headers() {
3320
+ if (!this._headers) {
3321
+ this._headers = _normalizeNodeHeaders(this.node.req.headers);
3322
+ }
3323
+ return this._headers;
3324
+ }
3325
+ // --- Respoonse ---
3326
+ get handled() {
3327
+ return this._handled || this.node.res.writableEnded || this.node.res.headersSent;
3328
+ }
3329
+ respondWith(response) {
3330
+ return Promise.resolve(response).then(
3331
+ (_response) => sendWebResponse(this, _response)
3332
+ );
3333
+ }
3334
+ // --- Utils ---
3335
+ toString() {
3336
+ return `[${this.method}] ${this.path}`;
3337
+ }
3338
+ toJSON() {
3339
+ return this.toString();
3340
+ }
3341
+ // --- Deprecated ---
3342
+ /** @deprecated Please use `event.node.req` instead. **/
3343
+ get req() {
3344
+ return this.node.req;
3345
+ }
3346
+ /** @deprecated Please use `event.node.res` instead. **/
3347
+ get res() {
3348
+ return this.node.res;
3349
+ }
3350
+ }
3351
+ function createEvent(req, res) {
3352
+ return new H3Event(req, res);
3353
+ }
3354
+ function _normalizeNodeHeaders(nodeHeaders) {
3355
+ const headers = new Headers();
3356
+ for (const [name, value] of Object.entries(nodeHeaders)) {
3357
+ if (Array.isArray(value)) {
3358
+ for (const item of value) {
3359
+ headers.append(name, item);
3360
+ }
3361
+ } else if (value) {
3362
+ headers.set(name, value);
3363
+ }
3364
+ }
3365
+ return headers;
3366
+ }
3367
+
3245
3368
  function defineEventHandler(handler) {
3246
3369
  if (typeof handler === "function") {
3247
3370
  return Object.assign(handler, { __is_handler__: true });
@@ -3565,6 +3688,30 @@ function createRouter(opts = {}) {
3565
3688
  });
3566
3689
  return router;
3567
3690
  }
3691
+ function toNodeListener(app) {
3692
+ const toNodeHandle = async function(req, res) {
3693
+ const event = createEvent(req, res);
3694
+ try {
3695
+ await app.handler(event);
3696
+ } catch (_error) {
3697
+ const error = createError(_error);
3698
+ if (!isError(_error)) {
3699
+ error.unhandled = true;
3700
+ }
3701
+ if (app.options.onError) {
3702
+ await app.options.onError(error, event);
3703
+ }
3704
+ if (event.handled) {
3705
+ return;
3706
+ }
3707
+ if (error.unhandled || error.fatal) {
3708
+ console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
3709
+ }
3710
+ await sendError(event, error, !!app.options.debug);
3711
+ }
3712
+ };
3713
+ return toNodeHandle;
3714
+ }
3568
3715
 
3569
3716
  var value$1 = {};
3570
3717
 
@@ -8485,12 +8632,16 @@ exports.ArriServer = ArriServer;
8485
8632
  exports.ErrorResponse = ErrorResponse;
8486
8633
  exports.HttpMethodValues = HttpMethodValues;
8487
8634
  exports.camelCase = camelCase;
8635
+ exports.commonjsGlobal = commonjsGlobal;
8488
8636
  exports.createRpcDefinition = createRpcDefinition;
8489
8637
  exports.defineError = defineError;
8490
8638
  exports.defineMiddleware = defineMiddleware;
8491
8639
  exports.defineRoute = defineRoute;
8492
8640
  exports.defineRpc = defineRpc;
8641
+ exports.destr = destr;
8493
8642
  exports.errorResponseFromValidationErrors = errorResponseFromValidationErrors;
8643
+ exports.getAugmentedNamespace = getAugmentedNamespace;
8644
+ exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
8494
8645
  exports.getRpcParamDefinition = getRpcParamDefinition;
8495
8646
  exports.getRpcParamName = getRpcParamName;
8496
8647
  exports.getRpcPath = getRpcPath;
@@ -8503,7 +8654,12 @@ exports.isJsonSchemaObject = isJsonSchemaObject;
8503
8654
  exports.isJsonSchemaScalarType = isJsonSchemaScalarType;
8504
8655
  exports.isProcedureDefinition = isProcedureDefinition;
8505
8656
  exports.isRpc = isRpc;
8657
+ exports.joinURL = joinURL;
8658
+ exports.kebabCase = kebabCase;
8506
8659
  exports.pascalCase = pascalCase;
8507
8660
  exports.registerRoute = registerRoute;
8508
8661
  exports.registerRpc = registerRpc;
8662
+ exports.removeDisallowedChars = removeDisallowedChars;
8663
+ exports.toNodeListener = toNodeListener;
8664
+ exports.typebox = typebox;
8509
8665
  exports.unflattenObject = unflattenObject;
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "chokidar": "^3.5.3",
22
22
  "listhen": "^1.4.0"
23
23
  },
24
- "version": "0.0.5",
24
+ "version": "0.0.6",
25
25
  "repository": {
26
26
  "url": "https://github.com/modiimedia/arri"
27
27
  }