arri 0.0.5 → 0.0.7

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) {
@@ -283,7 +312,7 @@ var typebox = {};
283
312
  function TConstructor(schema) {
284
313
  // prettier-ignore
285
314
  return (TKindOf(schema, 'Constructor') &&
286
- schema.type === 'constructor' &&
315
+ schema.type === 'Constructor' &&
287
316
  IsOptionalString(schema.$id) &&
288
317
  ValueGuard.IsArray(schema.parameters) &&
289
318
  schema.parameters.every(schema => TSchema(schema)) &&
@@ -306,7 +335,7 @@ var typebox = {};
306
335
  function TFunction(schema) {
307
336
  // prettier-ignore
308
337
  return (TKindOf(schema, 'Function') &&
309
- schema.type === 'function' &&
338
+ schema.type === 'Function' &&
310
339
  IsOptionalString(schema.$id) &&
311
340
  ValueGuard.IsArray(schema.parameters) &&
312
341
  schema.parameters.every(schema => TSchema(schema)) &&
@@ -2275,7 +2304,7 @@ var typebox = {};
2275
2304
  /** `[JavaScript]` Creates a Constructor type */
2276
2305
  Constructor(parameters, returns, options) {
2277
2306
  const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
2278
- return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'constructor', parameters: clonedParameters, returns: clonedReturns });
2307
+ return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'Constructor', parameters: clonedParameters, returns: clonedReturns });
2279
2308
  }
2280
2309
  /** `[JavaScript]` Creates a Date type */
2281
2310
  Date(options = {}) {
@@ -2284,7 +2313,7 @@ var typebox = {};
2284
2313
  /** `[JavaScript]` Creates a Function type */
2285
2314
  Function(parameters, returns, options) {
2286
2315
  const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
2287
- return this.Create({ ...options, [exports.Kind]: 'Function', type: 'function', parameters: clonedParameters, returns: clonedReturns });
2316
+ return this.Create({ ...options, [exports.Kind]: 'Function', type: 'Function', parameters: clonedParameters, returns: clonedReturns });
2288
2317
  }
2289
2318
  /** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
2290
2319
  InstanceType(schema, options = {}) {
@@ -2341,7 +2370,23 @@ var typebox = {};
2341
2370
  exports.Type = new JavaScriptTypeBuilder();
2342
2371
  } (typebox));
2343
2372
 
2373
+ const HASH_RE = /#/g;
2374
+ const AMPERSAND_RE = /&/g;
2375
+ const EQUAL_RE = /=/g;
2344
2376
  const PLUS_RE = /\+/g;
2377
+ const ENC_CARET_RE = /%5e/gi;
2378
+ const ENC_BACKTICK_RE = /%60/gi;
2379
+ const ENC_PIPE_RE = /%7c/gi;
2380
+ const ENC_SPACE_RE = /%20/gi;
2381
+ function encode(text) {
2382
+ return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
2383
+ }
2384
+ function encodeQueryValue(input) {
2385
+ return encode(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^");
2386
+ }
2387
+ function encodeQueryKey(text) {
2388
+ return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
2389
+ }
2345
2390
  function decode(text = "") {
2346
2391
  try {
2347
2392
  return decodeURIComponent("" + text);
@@ -2381,6 +2426,21 @@ function parseQuery(parametersString = "") {
2381
2426
  }
2382
2427
  return object;
2383
2428
  }
2429
+ function encodeQueryItem(key, value) {
2430
+ if (typeof value === "number" || typeof value === "boolean") {
2431
+ value = String(value);
2432
+ }
2433
+ if (!value) {
2434
+ return encodeQueryKey(key);
2435
+ }
2436
+ if (Array.isArray(value)) {
2437
+ return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
2438
+ }
2439
+ return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
2440
+ }
2441
+ function stringifyQuery(query) {
2442
+ return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
2443
+ }
2384
2444
  const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
2385
2445
  const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
2386
2446
  const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
@@ -2410,9 +2470,54 @@ function withoutTrailingSlash(input = "", queryParameters = false) {
2410
2470
  const [s0, ...s] = input.split("?");
2411
2471
  return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
2412
2472
  }
2473
+ function withTrailingSlash(input = "", queryParameters = false) {
2474
+ if (!queryParameters) {
2475
+ return input.endsWith("/") ? input : input + "/";
2476
+ }
2477
+ if (hasTrailingSlash(input, true)) {
2478
+ return input || "/";
2479
+ }
2480
+ const [s0, ...s] = input.split("?");
2481
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
2482
+ }
2483
+ function withBase(input, base) {
2484
+ if (isEmptyURL(base) || hasProtocol(input)) {
2485
+ return input;
2486
+ }
2487
+ const _base = withoutTrailingSlash(base);
2488
+ if (input.startsWith(_base)) {
2489
+ return input;
2490
+ }
2491
+ return joinURL(_base, input);
2492
+ }
2493
+ function withQuery(input, query) {
2494
+ const parsed = parseURL(input);
2495
+ const mergedQuery = { ...parseQuery(parsed.search), ...query };
2496
+ parsed.search = stringifyQuery(mergedQuery);
2497
+ return stringifyParsedURL(parsed);
2498
+ }
2413
2499
  function getQuery$1(input) {
2414
2500
  return parseQuery(parseURL(input).search);
2415
2501
  }
2502
+ function isEmptyURL(url) {
2503
+ return !url || url === "/";
2504
+ }
2505
+ function isNonEmptyURL(url) {
2506
+ return url && url !== "/";
2507
+ }
2508
+ const JOIN_LEADING_SLASH_RE = /^\.?\//;
2509
+ function joinURL(base, ...input) {
2510
+ let url = base || "";
2511
+ for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
2512
+ if (url) {
2513
+ const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
2514
+ url = withTrailingSlash(url) + _segment;
2515
+ } else {
2516
+ url = segment;
2517
+ }
2518
+ }
2519
+ return url;
2520
+ }
2416
2521
 
2417
2522
  function parseURL(input = "", defaultProto) {
2418
2523
  const _specialProtoMatch = input.match(
@@ -2455,6 +2560,15 @@ function parsePath(input = "") {
2455
2560
  hash
2456
2561
  };
2457
2562
  }
2563
+ function stringifyParsedURL(parsed) {
2564
+ const pathname = parsed.pathname || "";
2565
+ const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
2566
+ const hash = parsed.hash || "";
2567
+ const auth = parsed.auth ? parsed.auth + "@" : "";
2568
+ const host = parsed.host || "";
2569
+ const proto = parsed.protocol ? parsed.protocol + "//" : "";
2570
+ return proto + auth + host + pathname + search + hash;
2571
+ }
2458
2572
 
2459
2573
  const NODE_TYPES = {
2460
2574
  NORMAL: 0,
@@ -2737,12 +2851,29 @@ function destr(value, options = {}) {
2737
2851
  }
2738
2852
  }
2739
2853
 
2854
+ function hasProp(obj, prop) {
2855
+ try {
2856
+ return prop in obj;
2857
+ } catch {
2858
+ return false;
2859
+ }
2860
+ }
2861
+
2862
+ var __defProp$1 = Object.defineProperty;
2863
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2864
+ var __publicField$1 = (obj, key, value) => {
2865
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2866
+ return value;
2867
+ };
2740
2868
  class H3Error extends Error {
2741
2869
  constructor(message, opts = {}) {
2742
2870
  super(message, opts);
2743
- this.statusCode = 500;
2744
- this.fatal = false;
2745
- this.unhandled = false;
2871
+ __publicField$1(this, "statusCode", 500);
2872
+ __publicField$1(this, "fatal", false);
2873
+ __publicField$1(this, "unhandled", false);
2874
+ __publicField$1(this, "statusMessage");
2875
+ __publicField$1(this, "data");
2876
+ __publicField$1(this, "cause");
2746
2877
  if (opts.cause && !this.cause) {
2747
2878
  this.cause = opts.cause;
2748
2879
  }
@@ -2761,7 +2892,7 @@ class H3Error extends Error {
2761
2892
  return obj;
2762
2893
  }
2763
2894
  }
2764
- H3Error.__h3_error__ = true;
2895
+ __publicField$1(H3Error, "__h3_error__", true);
2765
2896
  function createError(input) {
2766
2897
  if (typeof input === "string") {
2767
2898
  return new H3Error(input);
@@ -2772,7 +2903,7 @@ function createError(input) {
2772
2903
  const err = new H3Error(input.message ?? input.statusMessage ?? "", {
2773
2904
  cause: input.cause || input
2774
2905
  });
2775
- if ("stack" in input) {
2906
+ if (hasProp(input, "stack")) {
2776
2907
  try {
2777
2908
  Object.defineProperty(err, "stack", {
2778
2909
  get() {
@@ -2971,7 +3102,7 @@ function readRawBody(event, encoding = "utf8") {
2971
3102
  }
2972
3103
  async function readBody(event, options = {}) {
2973
3104
  const request = event.node.req;
2974
- if (ParsedBodySymbol in request) {
3105
+ if (hasProp(request, ParsedBodySymbol)) {
2975
3106
  return request[ParsedBodySymbol];
2976
3107
  }
2977
3108
  const contentType = request.headers["content-type"] || "";
@@ -3011,7 +3142,7 @@ function _parseURLEncodedBody(body) {
3011
3142
  const form = new URLSearchParams(body);
3012
3143
  const parsedForm = /* @__PURE__ */ Object.create(null);
3013
3144
  for (const [key, value] of form.entries()) {
3014
- if (key in parsedForm) {
3145
+ if (hasProp(parsedForm, key)) {
3015
3146
  if (!Array.isArray(parsedForm[key])) {
3016
3147
  parsedForm[key] = [parsedForm[key]];
3017
3148
  }
@@ -3173,7 +3304,7 @@ function sendStream(event, stream) {
3173
3304
  event._handled = true;
3174
3305
  return Promise.resolve();
3175
3306
  }
3176
- if ("pipeTo" in stream) {
3307
+ if (hasProp(stream, "pipeTo") && typeof stream.pipeTo === "function") {
3177
3308
  return stream.pipeTo(
3178
3309
  new WritableStream({
3179
3310
  write(chunk) {
@@ -3184,7 +3315,7 @@ function sendStream(event, stream) {
3184
3315
  event.node.res.end();
3185
3316
  });
3186
3317
  }
3187
- if (typeof stream.pipe === "function") {
3318
+ if (hasProp(stream, "pipe") && typeof stream.pipe === "function") {
3188
3319
  return new Promise((resolve, reject) => {
3189
3320
  stream.pipe(event.node.res);
3190
3321
  if (stream.on) {
@@ -3240,6 +3371,90 @@ function isPreflightRequest(event) {
3240
3371
  return event.method === "OPTIONS" && !!origin && !!accessControlRequestMethod;
3241
3372
  }
3242
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
+
3243
3458
  function defineEventHandler(handler) {
3244
3459
  if (typeof handler === "function") {
3245
3460
  return Object.assign(handler, { __is_handler__: true });
@@ -3276,7 +3491,7 @@ async function _callHandler(event, handler, hooks) {
3276
3491
  }
3277
3492
  const eventHandler = defineEventHandler;
3278
3493
  function isEventHandler(input) {
3279
- return "__is_handler__" in input;
3494
+ return hasProp(input, "__is_handler__");
3280
3495
  }
3281
3496
  function toEventHandler(input, _, _route) {
3282
3497
  if (!isEventHandler(input)) {
@@ -3563,6 +3778,30 @@ function createRouter(opts = {}) {
3563
3778
  });
3564
3779
  return router;
3565
3780
  }
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);
3801
+ }
3802
+ };
3803
+ return toNodeHandle;
3804
+ }
3566
3805
 
3567
3806
  var value$1 = {};
3568
3807
 
@@ -8053,6 +8292,17 @@ function isProcedureDefinition(input) {
8053
8292
  }
8054
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");
8055
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
+ }
8056
8306
  function unflattenObject(data) {
8057
8307
  if (Object(data) !== data || Array.isArray(data))
8058
8308
  return data;
@@ -8070,6 +8320,9 @@ function unflattenObject(data) {
8070
8320
  }
8071
8321
  return result[""] || result;
8072
8322
  }
8323
+ function unflattenProcedures(procedures) {
8324
+ return unflattenObject(procedures);
8325
+ }
8073
8326
  const removeDisallowedChars = (input, disallowedChars) => {
8074
8327
  let result = input;
8075
8328
  for (const char of disallowedChars) {
@@ -8479,4 +8732,4 @@ const isHttpMethod = (input) => {
8479
8732
  return HttpMethodValues.includes(input);
8480
8733
  };
8481
8734
 
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 };
8735
+ 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 };