arri 0.0.6 → 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.
@@ -314,7 +314,7 @@ var typebox = {};
314
314
  function TConstructor(schema) {
315
315
  // prettier-ignore
316
316
  return (TKindOf(schema, 'Constructor') &&
317
- schema.type === 'constructor' &&
317
+ schema.type === 'Constructor' &&
318
318
  IsOptionalString(schema.$id) &&
319
319
  ValueGuard.IsArray(schema.parameters) &&
320
320
  schema.parameters.every(schema => TSchema(schema)) &&
@@ -337,7 +337,7 @@ var typebox = {};
337
337
  function TFunction(schema) {
338
338
  // prettier-ignore
339
339
  return (TKindOf(schema, 'Function') &&
340
- schema.type === 'function' &&
340
+ schema.type === 'Function' &&
341
341
  IsOptionalString(schema.$id) &&
342
342
  ValueGuard.IsArray(schema.parameters) &&
343
343
  schema.parameters.every(schema => TSchema(schema)) &&
@@ -2306,7 +2306,7 @@ var typebox = {};
2306
2306
  /** `[JavaScript]` Creates a Constructor type */
2307
2307
  Constructor(parameters, returns, options) {
2308
2308
  const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
2309
- return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'constructor', parameters: clonedParameters, returns: clonedReturns });
2309
+ return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'Constructor', parameters: clonedParameters, returns: clonedReturns });
2310
2310
  }
2311
2311
  /** `[JavaScript]` Creates a Date type */
2312
2312
  Date(options = {}) {
@@ -2315,7 +2315,7 @@ var typebox = {};
2315
2315
  /** `[JavaScript]` Creates a Function type */
2316
2316
  Function(parameters, returns, options) {
2317
2317
  const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
2318
- return this.Create({ ...options, [exports.Kind]: 'Function', type: 'function', parameters: clonedParameters, returns: clonedReturns });
2318
+ return this.Create({ ...options, [exports.Kind]: 'Function', type: 'Function', parameters: clonedParameters, returns: clonedReturns });
2319
2319
  }
2320
2320
  /** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
2321
2321
  InstanceType(schema, options = {}) {
@@ -2372,7 +2372,23 @@ var typebox = {};
2372
2372
  exports.Type = new JavaScriptTypeBuilder();
2373
2373
  } (typebox));
2374
2374
 
2375
+ const HASH_RE = /#/g;
2376
+ const AMPERSAND_RE = /&/g;
2377
+ const EQUAL_RE = /=/g;
2375
2378
  const PLUS_RE = /\+/g;
2379
+ const ENC_CARET_RE = /%5e/gi;
2380
+ const ENC_BACKTICK_RE = /%60/gi;
2381
+ const ENC_PIPE_RE = /%7c/gi;
2382
+ const ENC_SPACE_RE = /%20/gi;
2383
+ function encode(text) {
2384
+ return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
2385
+ }
2386
+ function encodeQueryValue(input) {
2387
+ 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, "^");
2388
+ }
2389
+ function encodeQueryKey(text) {
2390
+ return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
2391
+ }
2376
2392
  function decode(text = "") {
2377
2393
  try {
2378
2394
  return decodeURIComponent("" + text);
@@ -2412,6 +2428,21 @@ function parseQuery(parametersString = "") {
2412
2428
  }
2413
2429
  return object;
2414
2430
  }
2431
+ function encodeQueryItem(key, value) {
2432
+ if (typeof value === "number" || typeof value === "boolean") {
2433
+ value = String(value);
2434
+ }
2435
+ if (!value) {
2436
+ return encodeQueryKey(key);
2437
+ }
2438
+ if (Array.isArray(value)) {
2439
+ return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
2440
+ }
2441
+ return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
2442
+ }
2443
+ function stringifyQuery(query) {
2444
+ return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
2445
+ }
2415
2446
  const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
2416
2447
  const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
2417
2448
  const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
@@ -2451,9 +2482,28 @@ function withTrailingSlash(input = "", queryParameters = false) {
2451
2482
  const [s0, ...s] = input.split("?");
2452
2483
  return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
2453
2484
  }
2485
+ function withBase(input, base) {
2486
+ if (isEmptyURL(base) || hasProtocol(input)) {
2487
+ return input;
2488
+ }
2489
+ const _base = withoutTrailingSlash(base);
2490
+ if (input.startsWith(_base)) {
2491
+ return input;
2492
+ }
2493
+ return joinURL(_base, input);
2494
+ }
2495
+ function withQuery(input, query) {
2496
+ const parsed = parseURL(input);
2497
+ const mergedQuery = { ...parseQuery(parsed.search), ...query };
2498
+ parsed.search = stringifyQuery(mergedQuery);
2499
+ return stringifyParsedURL(parsed);
2500
+ }
2454
2501
  function getQuery$1(input) {
2455
2502
  return parseQuery(parseURL(input).search);
2456
2503
  }
2504
+ function isEmptyURL(url) {
2505
+ return !url || url === "/";
2506
+ }
2457
2507
  function isNonEmptyURL(url) {
2458
2508
  return url && url !== "/";
2459
2509
  }
@@ -2512,6 +2562,15 @@ function parsePath(input = "") {
2512
2562
  hash
2513
2563
  };
2514
2564
  }
2565
+ function stringifyParsedURL(parsed) {
2566
+ const pathname = parsed.pathname || "";
2567
+ const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
2568
+ const hash = parsed.hash || "";
2569
+ const auth = parsed.auth ? parsed.auth + "@" : "";
2570
+ const host = parsed.host || "";
2571
+ const proto = parsed.protocol ? parsed.protocol + "//" : "";
2572
+ return proto + auth + host + pathname + search + hash;
2573
+ }
2515
2574
 
2516
2575
  const NODE_TYPES = {
2517
2576
  NORMAL: 0,
@@ -2794,12 +2853,29 @@ function destr(value, options = {}) {
2794
2853
  }
2795
2854
  }
2796
2855
 
2856
+ function hasProp(obj, prop) {
2857
+ try {
2858
+ return prop in obj;
2859
+ } catch {
2860
+ return false;
2861
+ }
2862
+ }
2863
+
2864
+ var __defProp$1 = Object.defineProperty;
2865
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2866
+ var __publicField$1 = (obj, key, value) => {
2867
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2868
+ return value;
2869
+ };
2797
2870
  class H3Error extends Error {
2798
2871
  constructor(message, opts = {}) {
2799
2872
  super(message, opts);
2800
- this.statusCode = 500;
2801
- this.fatal = false;
2802
- this.unhandled = false;
2873
+ __publicField$1(this, "statusCode", 500);
2874
+ __publicField$1(this, "fatal", false);
2875
+ __publicField$1(this, "unhandled", false);
2876
+ __publicField$1(this, "statusMessage");
2877
+ __publicField$1(this, "data");
2878
+ __publicField$1(this, "cause");
2803
2879
  if (opts.cause && !this.cause) {
2804
2880
  this.cause = opts.cause;
2805
2881
  }
@@ -2818,7 +2894,7 @@ class H3Error extends Error {
2818
2894
  return obj;
2819
2895
  }
2820
2896
  }
2821
- H3Error.__h3_error__ = true;
2897
+ __publicField$1(H3Error, "__h3_error__", true);
2822
2898
  function createError(input) {
2823
2899
  if (typeof input === "string") {
2824
2900
  return new H3Error(input);
@@ -2829,7 +2905,7 @@ function createError(input) {
2829
2905
  const err = new H3Error(input.message ?? input.statusMessage ?? "", {
2830
2906
  cause: input.cause || input
2831
2907
  });
2832
- if ("stack" in input) {
2908
+ if (hasProp(input, "stack")) {
2833
2909
  try {
2834
2910
  Object.defineProperty(err, "stack", {
2835
2911
  get() {
@@ -3028,7 +3104,7 @@ function readRawBody(event, encoding = "utf8") {
3028
3104
  }
3029
3105
  async function readBody(event, options = {}) {
3030
3106
  const request = event.node.req;
3031
- if (ParsedBodySymbol in request) {
3107
+ if (hasProp(request, ParsedBodySymbol)) {
3032
3108
  return request[ParsedBodySymbol];
3033
3109
  }
3034
3110
  const contentType = request.headers["content-type"] || "";
@@ -3068,7 +3144,7 @@ function _parseURLEncodedBody(body) {
3068
3144
  const form = new URLSearchParams(body);
3069
3145
  const parsedForm = /* @__PURE__ */ Object.create(null);
3070
3146
  for (const [key, value] of form.entries()) {
3071
- if (key in parsedForm) {
3147
+ if (hasProp(parsedForm, key)) {
3072
3148
  if (!Array.isArray(parsedForm[key])) {
3073
3149
  parsedForm[key] = [parsedForm[key]];
3074
3150
  }
@@ -3230,7 +3306,7 @@ function sendStream(event, stream) {
3230
3306
  event._handled = true;
3231
3307
  return Promise.resolve();
3232
3308
  }
3233
- if ("pipeTo" in stream) {
3309
+ if (hasProp(stream, "pipeTo") && typeof stream.pipeTo === "function") {
3234
3310
  return stream.pipeTo(
3235
3311
  new WritableStream({
3236
3312
  write(chunk) {
@@ -3241,7 +3317,7 @@ function sendStream(event, stream) {
3241
3317
  event.node.res.end();
3242
3318
  });
3243
3319
  }
3244
- if (typeof stream.pipe === "function") {
3320
+ if (hasProp(stream, "pipe") && typeof stream.pipe === "function") {
3245
3321
  return new Promise((resolve, reject) => {
3246
3322
  stream.pipe(event.node.res);
3247
3323
  if (stream.on) {
@@ -3297,13 +3373,29 @@ function isPreflightRequest(event) {
3297
3373
  return event.method === "OPTIONS" && !!origin && !!accessControlRequestMethod;
3298
3374
  }
3299
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
+ };
3300
3382
  class H3Event {
3301
3383
  constructor(req, res) {
3302
- this["__is_event__"] = true;
3384
+ __publicField$2(this, "__is_event__", true);
3385
+ // Context
3386
+ __publicField$2(this, "node");
3387
+ // Node
3388
+ __publicField$2(this, "web");
3303
3389
  // Web
3304
- this.context = {};
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");
3305
3397
  // Response
3306
- this._handled = false;
3398
+ __publicField$2(this, "_handled", false);
3307
3399
  this.node = { req, res };
3308
3400
  }
3309
3401
  // --- Request ---
@@ -3401,7 +3493,7 @@ async function _callHandler(event, handler, hooks) {
3401
3493
  }
3402
3494
  const eventHandler = defineEventHandler;
3403
3495
  function isEventHandler(input) {
3404
- return "__is_handler__" in input;
3496
+ return hasProp(input, "__is_handler__");
3405
3497
  }
3406
3498
  function toEventHandler(input, _, _route) {
3407
3499
  if (!isEventHandler(input)) {
@@ -8202,6 +8294,17 @@ function isProcedureDefinition(input) {
8202
8294
  }
8203
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");
8204
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
+ }
8205
8308
  function unflattenObject(data) {
8206
8309
  if (Object(data) !== data || Array.isArray(data))
8207
8310
  return data;
@@ -8219,6 +8322,9 @@ function unflattenObject(data) {
8219
8322
  }
8220
8323
  return result[""] || result;
8221
8324
  }
8325
+ function unflattenProcedures(procedures) {
8326
+ return unflattenObject(procedures);
8327
+ }
8222
8328
  const removeDisallowedChars = (input, disallowedChars) => {
8223
8329
  let result = input;
8224
8330
  for (const char of disallowedChars) {
@@ -8654,6 +8760,7 @@ exports.isJsonSchemaObject = isJsonSchemaObject;
8654
8760
  exports.isJsonSchemaScalarType = isJsonSchemaScalarType;
8655
8761
  exports.isProcedureDefinition = isProcedureDefinition;
8656
8762
  exports.isRpc = isRpc;
8763
+ exports.isServiceDefinition = isServiceDefinition;
8657
8764
  exports.joinURL = joinURL;
8658
8765
  exports.kebabCase = kebabCase;
8659
8766
  exports.pascalCase = pascalCase;
@@ -8663,3 +8770,6 @@ exports.removeDisallowedChars = removeDisallowedChars;
8663
8770
  exports.toNodeListener = toNodeListener;
8664
8771
  exports.typebox = typebox;
8665
8772
  exports.unflattenObject = unflattenObject;
8773
+ exports.unflattenProcedures = unflattenProcedures;
8774
+ exports.withBase = withBase;
8775
+ exports.withQuery = withQuery;
package/package.json CHANGED
@@ -11,17 +11,18 @@
11
11
  "arri": "./dist/cli.mjs"
12
12
  },
13
13
  "dependencies": {
14
- "@sinclair/typebox": "^0.31.4",
15
- "h3": "^1.8.0",
14
+ "@sinclair/typebox": "^0.31.5",
15
+ "h3": "^1.8.1",
16
16
  "scule": "^1.0.0",
17
17
  "citty": "^0.1.3",
18
+ "ofetch": "^1.3.3",
18
19
  "pathe": "^1.1.1",
19
20
  "globby": "^13.2.2",
20
21
  "c12": "^1.4.2",
21
22
  "chokidar": "^3.5.3",
22
- "listhen": "^1.4.0"
23
+ "listhen": "^1.4.3"
23
24
  },
24
- "version": "0.0.6",
25
+ "version": "0.0.7",
25
26
  "repository": {
26
27
  "url": "https://github.com/modiimedia/arri"
27
28
  }
@@ -1,6 +1,13 @@
1
1
  import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
2
2
  import { H3Event, Router, App, AppOptions } from 'h3';
3
3
 
4
+ interface ApplicationDefinition {
5
+ schemaVersion: "0.0.1";
6
+ description: string;
7
+ procedures: Record<string, ProcedureDefinition>;
8
+ models: Record<string, JsonSchemaObject>;
9
+ errors: Omit<TObject, symbol>;
10
+ }
4
11
  interface ProcedureDefinition {
5
12
  path: string;
6
13
  description?: string;
@@ -11,13 +18,6 @@ interface ProcedureDefinition {
11
18
  interface ServiceDefinition {
12
19
  [key: string]: ProcedureDefinition | ServiceDefinition;
13
20
  }
14
- interface ApplicationDefinition {
15
- schemaVersion: "0.0.1";
16
- description: string;
17
- procedures: Record<string, ProcedureDefinition>;
18
- models: Record<string, JsonSchemaObject>;
19
- errors: Omit<TObject, symbol>;
20
- }
21
21
  declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
22
22
  declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
23
23
  type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
@@ -1,6 +1,13 @@
1
1
  import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
2
2
  import { H3Event, Router, App, AppOptions } from 'h3';
3
3
 
4
+ interface ApplicationDefinition {
5
+ schemaVersion: "0.0.1";
6
+ description: string;
7
+ procedures: Record<string, ProcedureDefinition>;
8
+ models: Record<string, JsonSchemaObject>;
9
+ errors: Omit<TObject, symbol>;
10
+ }
4
11
  interface ProcedureDefinition {
5
12
  path: string;
6
13
  description?: string;
@@ -11,13 +18,6 @@ interface ProcedureDefinition {
11
18
  interface ServiceDefinition {
12
19
  [key: string]: ProcedureDefinition | ServiceDefinition;
13
20
  }
14
- interface ApplicationDefinition {
15
- schemaVersion: "0.0.1";
16
- description: string;
17
- procedures: Record<string, ProcedureDefinition>;
18
- models: Record<string, JsonSchemaObject>;
19
- errors: Omit<TObject, symbol>;
20
- }
21
21
  declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
22
22
  declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
23
23
  type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;
@@ -1,6 +1,13 @@
1
1
  import { TObject, Static, TVoid, TSchema } from '@sinclair/typebox';
2
2
  import { H3Event, Router, App, AppOptions } from 'h3';
3
3
 
4
+ interface ApplicationDefinition {
5
+ schemaVersion: "0.0.1";
6
+ description: string;
7
+ procedures: Record<string, ProcedureDefinition>;
8
+ models: Record<string, JsonSchemaObject>;
9
+ errors: Omit<TObject, symbol>;
10
+ }
4
11
  interface ProcedureDefinition {
5
12
  path: string;
6
13
  description?: string;
@@ -11,13 +18,6 @@ interface ProcedureDefinition {
11
18
  interface ServiceDefinition {
12
19
  [key: string]: ProcedureDefinition | ServiceDefinition;
13
20
  }
14
- interface ApplicationDefinition {
15
- schemaVersion: "0.0.1";
16
- description: string;
17
- procedures: Record<string, ProcedureDefinition>;
18
- models: Record<string, JsonSchemaObject>;
19
- errors: Omit<TObject, symbol>;
20
- }
21
21
  declare const JsonSchemaScalarTypeValues: readonly ["integer", "number", "bigint", "string", "boolean", "Date"];
22
22
  declare const JsonSchemaNullTypeValues: readonly ["null", "undefined"];
23
23
  type JsonSchemaType = JsonSchemaScalarType | JsonSchemaNullType | JsonSchemaComplexType;