arri 0.0.6 → 0.0.9

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.
@@ -312,7 +312,7 @@ var typebox = {};
312
312
  function TConstructor(schema) {
313
313
  // prettier-ignore
314
314
  return (TKindOf(schema, 'Constructor') &&
315
- schema.type === 'constructor' &&
315
+ schema.type === 'Constructor' &&
316
316
  IsOptionalString(schema.$id) &&
317
317
  ValueGuard.IsArray(schema.parameters) &&
318
318
  schema.parameters.every(schema => TSchema(schema)) &&
@@ -335,7 +335,7 @@ var typebox = {};
335
335
  function TFunction(schema) {
336
336
  // prettier-ignore
337
337
  return (TKindOf(schema, 'Function') &&
338
- schema.type === 'function' &&
338
+ schema.type === 'Function' &&
339
339
  IsOptionalString(schema.$id) &&
340
340
  ValueGuard.IsArray(schema.parameters) &&
341
341
  schema.parameters.every(schema => TSchema(schema)) &&
@@ -2304,7 +2304,7 @@ var typebox = {};
2304
2304
  /** `[JavaScript]` Creates a Constructor type */
2305
2305
  Constructor(parameters, returns, options) {
2306
2306
  const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
2307
- 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 });
2308
2308
  }
2309
2309
  /** `[JavaScript]` Creates a Date type */
2310
2310
  Date(options = {}) {
@@ -2313,7 +2313,7 @@ var typebox = {};
2313
2313
  /** `[JavaScript]` Creates a Function type */
2314
2314
  Function(parameters, returns, options) {
2315
2315
  const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
2316
- 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 });
2317
2317
  }
2318
2318
  /** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
2319
2319
  InstanceType(schema, options = {}) {
@@ -2370,7 +2370,23 @@ var typebox = {};
2370
2370
  exports.Type = new JavaScriptTypeBuilder();
2371
2371
  } (typebox));
2372
2372
 
2373
+ const HASH_RE = /#/g;
2374
+ const AMPERSAND_RE = /&/g;
2375
+ const EQUAL_RE = /=/g;
2373
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
+ }
2374
2390
  function decode(text = "") {
2375
2391
  try {
2376
2392
  return decodeURIComponent("" + text);
@@ -2410,6 +2426,21 @@ function parseQuery(parametersString = "") {
2410
2426
  }
2411
2427
  return object;
2412
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
+ }
2413
2444
  const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
2414
2445
  const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
2415
2446
  const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
@@ -2449,9 +2480,28 @@ function withTrailingSlash(input = "", queryParameters = false) {
2449
2480
  const [s0, ...s] = input.split("?");
2450
2481
  return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
2451
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
+ }
2452
2499
  function getQuery$1(input) {
2453
2500
  return parseQuery(parseURL(input).search);
2454
2501
  }
2502
+ function isEmptyURL(url) {
2503
+ return !url || url === "/";
2504
+ }
2455
2505
  function isNonEmptyURL(url) {
2456
2506
  return url && url !== "/";
2457
2507
  }
@@ -2510,6 +2560,15 @@ function parsePath(input = "") {
2510
2560
  hash
2511
2561
  };
2512
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
+ }
2513
2572
 
2514
2573
  const NODE_TYPES = {
2515
2574
  NORMAL: 0,
@@ -2792,12 +2851,29 @@ function destr(value, options = {}) {
2792
2851
  }
2793
2852
  }
2794
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
+ };
2795
2868
  class H3Error extends Error {
2796
2869
  constructor(message, opts = {}) {
2797
2870
  super(message, opts);
2798
- this.statusCode = 500;
2799
- this.fatal = false;
2800
- 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");
2801
2877
  if (opts.cause && !this.cause) {
2802
2878
  this.cause = opts.cause;
2803
2879
  }
@@ -2816,7 +2892,7 @@ class H3Error extends Error {
2816
2892
  return obj;
2817
2893
  }
2818
2894
  }
2819
- H3Error.__h3_error__ = true;
2895
+ __publicField$1(H3Error, "__h3_error__", true);
2820
2896
  function createError(input) {
2821
2897
  if (typeof input === "string") {
2822
2898
  return new H3Error(input);
@@ -2827,7 +2903,7 @@ function createError(input) {
2827
2903
  const err = new H3Error(input.message ?? input.statusMessage ?? "", {
2828
2904
  cause: input.cause || input
2829
2905
  });
2830
- if ("stack" in input) {
2906
+ if (hasProp(input, "stack")) {
2831
2907
  try {
2832
2908
  Object.defineProperty(err, "stack", {
2833
2909
  get() {
@@ -3026,7 +3102,7 @@ function readRawBody(event, encoding = "utf8") {
3026
3102
  }
3027
3103
  async function readBody(event, options = {}) {
3028
3104
  const request = event.node.req;
3029
- if (ParsedBodySymbol in request) {
3105
+ if (hasProp(request, ParsedBodySymbol)) {
3030
3106
  return request[ParsedBodySymbol];
3031
3107
  }
3032
3108
  const contentType = request.headers["content-type"] || "";
@@ -3066,7 +3142,7 @@ function _parseURLEncodedBody(body) {
3066
3142
  const form = new URLSearchParams(body);
3067
3143
  const parsedForm = /* @__PURE__ */ Object.create(null);
3068
3144
  for (const [key, value] of form.entries()) {
3069
- if (key in parsedForm) {
3145
+ if (hasProp(parsedForm, key)) {
3070
3146
  if (!Array.isArray(parsedForm[key])) {
3071
3147
  parsedForm[key] = [parsedForm[key]];
3072
3148
  }
@@ -3228,7 +3304,7 @@ function sendStream(event, stream) {
3228
3304
  event._handled = true;
3229
3305
  return Promise.resolve();
3230
3306
  }
3231
- if ("pipeTo" in stream) {
3307
+ if (hasProp(stream, "pipeTo") && typeof stream.pipeTo === "function") {
3232
3308
  return stream.pipeTo(
3233
3309
  new WritableStream({
3234
3310
  write(chunk) {
@@ -3239,7 +3315,7 @@ function sendStream(event, stream) {
3239
3315
  event.node.res.end();
3240
3316
  });
3241
3317
  }
3242
- if (typeof stream.pipe === "function") {
3318
+ if (hasProp(stream, "pipe") && typeof stream.pipe === "function") {
3243
3319
  return new Promise((resolve, reject) => {
3244
3320
  stream.pipe(event.node.res);
3245
3321
  if (stream.on) {
@@ -3295,13 +3371,29 @@ function isPreflightRequest(event) {
3295
3371
  return event.method === "OPTIONS" && !!origin && !!accessControlRequestMethod;
3296
3372
  }
3297
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
+ };
3298
3380
  class H3Event {
3299
3381
  constructor(req, res) {
3300
- this["__is_event__"] = true;
3382
+ __publicField$2(this, "__is_event__", true);
3383
+ // Context
3384
+ __publicField$2(this, "node");
3385
+ // Node
3386
+ __publicField$2(this, "web");
3301
3387
  // Web
3302
- this.context = {};
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");
3303
3395
  // Response
3304
- this._handled = false;
3396
+ __publicField$2(this, "_handled", false);
3305
3397
  this.node = { req, res };
3306
3398
  }
3307
3399
  // --- Request ---
@@ -3399,7 +3491,7 @@ async function _callHandler(event, handler, hooks) {
3399
3491
  }
3400
3492
  const eventHandler = defineEventHandler;
3401
3493
  function isEventHandler(input) {
3402
- return "__is_handler__" in input;
3494
+ return hasProp(input, "__is_handler__");
3403
3495
  }
3404
3496
  function toEventHandler(input, _, _route) {
3405
3497
  if (!isEventHandler(input)) {
@@ -8200,6 +8292,17 @@ function isProcedureDefinition(input) {
8200
8292
  }
8201
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");
8202
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
+ }
8203
8306
  function unflattenObject(data) {
8204
8307
  if (Object(data) !== data || Array.isArray(data))
8205
8308
  return data;
@@ -8217,6 +8320,9 @@ function unflattenObject(data) {
8217
8320
  }
8218
8321
  return result[""] || result;
8219
8322
  }
8323
+ function unflattenProcedures(procedures) {
8324
+ return unflattenObject(procedures);
8325
+ }
8220
8326
  const removeDisallowedChars = (input, disallowedChars) => {
8221
8327
  let result = input;
8222
8328
  for (const char of disallowedChars) {
@@ -8626,4 +8732,4 @@ const isHttpMethod = (input) => {
8626
8732
  return HttpMethodValues.includes(input);
8627
8733
  };
8628
8734
 
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 };
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 };