@h3ravel/arquebus 0.5.0 → 0.6.1

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.
Files changed (45) hide show
  1. package/README.md +20 -1
  2. package/bin/index.cjs +197 -145
  3. package/bin/index.js +178 -95
  4. package/bin/seeders-8GJzfIIN.js +3 -0
  5. package/bin/seeders-ByeSoCAQ.cjs +131 -0
  6. package/bin/seeders-CltigymO.js +79 -0
  7. package/bin/seeders-_xJ6VGVS.cjs +3 -0
  8. package/dist/browser/index.cjs +9 -9
  9. package/dist/browser/index.d.cts +8 -8
  10. package/dist/browser/index.d.ts +8 -8
  11. package/dist/browser/index.js +9 -9
  12. package/dist/index.cjs +252 -121
  13. package/dist/index.d.cts +41 -9
  14. package/dist/index.d.ts +41 -9
  15. package/dist/index.js +245 -119
  16. package/dist/inspector/index.cjs +105 -33
  17. package/dist/inspector/index.js +102 -33
  18. package/dist/migrations/index.cjs +144 -126
  19. package/dist/migrations/index.d.cts +11 -11
  20. package/dist/migrations/index.d.ts +11 -11
  21. package/dist/migrations/index.js +148 -130
  22. package/dist/migrations/stubs/migration-js.stub +1 -1
  23. package/dist/migrations/stubs/migration-ts.stub +1 -1
  24. package/dist/migrations/stubs/migration.create-js.stub +5 -5
  25. package/dist/migrations/stubs/migration.create-ts.stub +5 -5
  26. package/dist/migrations/stubs/migration.update-js.stub +2 -2
  27. package/dist/migrations/stubs/migration.update-ts.stub +3 -3
  28. package/dist/seeders/index.cjs +141 -0
  29. package/dist/seeders/index.d.cts +4766 -0
  30. package/dist/seeders/index.d.ts +4766 -0
  31. package/dist/seeders/index.js +118 -0
  32. package/dist/seeders/index.ts +3 -0
  33. package/dist/seeders/runner.ts +101 -0
  34. package/dist/seeders/seeder-creator.ts +42 -0
  35. package/dist/seeders/seeder.ts +10 -0
  36. package/dist/stubs/seeder-js.stub +13 -0
  37. package/dist/stubs/seeder-ts.stub +9 -0
  38. package/package.json +14 -3
  39. package/types/builder.ts +153 -80
  40. package/types/container.ts +79 -66
  41. package/types/generics.ts +75 -37
  42. package/types/modeling.ts +213 -158
  43. package/types/query-builder.ts +221 -191
  44. package/types/query-methods.ts +145 -109
  45. package/types/utils.ts +64 -56
@@ -43,13 +43,18 @@ let path = require("path");
43
43
  path = __toESM(path);
44
44
  let fs = require("fs");
45
45
  fs = __toESM(fs);
46
+ let fs_promises = require("fs/promises");
47
+ fs_promises = __toESM(fs_promises);
48
+ let escalade_sync = require("escalade/sync");
49
+ escalade_sync = __toESM(escalade_sync);
50
+ let resolve_from = require("resolve-from");
51
+ resolve_from = __toESM(resolve_from);
46
52
  let pluralize = require("pluralize");
47
53
  pluralize = __toESM(pluralize);
48
54
  require("@h3ravel/shared");
49
55
  require("node:fs/promises");
50
- require("fs/promises");
51
- require("escalade/sync");
52
- require("resolve-from");
56
+ require("node:path");
57
+ require("node:url");
53
58
 
54
59
  //#region src/inspector/utils/strip-quotes.ts
55
60
  /**
@@ -1371,7 +1376,7 @@ var InvalidArgumentError = class extends BaseError {};
1371
1376
  var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
1372
1377
  /**
1373
1378
  * Compose function that merges multiple classes and mixins
1374
- *
1379
+ *
1375
1380
  * @example
1376
1381
  * const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
1377
1382
  * return class extends Base {
@@ -1408,10 +1413,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
1408
1413
  * console.log(user.pluginMethod('w')) // "plugin"
1409
1414
  * console.log(user.pluginMethod()) // "plugin"
1410
1415
  * console.log(user.relationPosts()) // "hasMany Posts"
1411
- *
1412
- * @param Base
1413
- * @param mixins
1414
- * @returns
1416
+ *
1417
+ * @param Base
1418
+ * @param mixins
1419
+ * @returns
1415
1420
  */
1416
1421
  function compose$1(Base, ...mixins) {
1417
1422
  /**
@@ -1465,10 +1470,10 @@ const getSetterMethod = (attr) => {
1465
1470
  };
1466
1471
  /**
1467
1472
  * Tap into a model a collection instance
1468
- *
1469
- * @param instance
1470
- * @param callback
1471
- * @returns
1473
+ *
1474
+ * @param instance
1475
+ * @param callback
1476
+ * @returns
1472
1477
  */
1473
1478
  const tap = (instance, callback) => {
1474
1479
  const result = callback(instance);
@@ -2919,6 +2924,59 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
2919
2924
  };
2920
2925
  var query_builder_default = QueryBuilder;
2921
2926
 
2927
+ //#endregion
2928
+ //#region src/cli/utils.ts
2929
+ const join = path.default.join;
2930
+ var Utils = class {
2931
+ /**
2932
+ * Wraps text with chalk
2933
+ *
2934
+ * @param txt
2935
+ * @param color
2936
+ * @returns
2937
+ */
2938
+ static textFormat(txt, color) {
2939
+ return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
2940
+ }
2941
+ static findModulePkg(moduleId, cwd) {
2942
+ const parts = moduleId.replace(/\\/g, "/").split("/");
2943
+ let packageName = "";
2944
+ if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
2945
+ packageName += parts.shift();
2946
+ const packageJson = path.default.join(packageName, "package.json");
2947
+ const resolved = resolve_from.default.silent(cwd ?? process.cwd(), packageJson);
2948
+ if (!resolved) return;
2949
+ return path.default.join(path.default.dirname(resolved), parts.join("/"));
2950
+ }
2951
+ static async getMigrationPaths(cwd, migrator, defaultPath, path$6) {
2952
+ if (path$6) return [join(cwd, path$6)];
2953
+ return [...migrator.getPaths(), join(cwd, defaultPath)];
2954
+ }
2955
+ /**
2956
+ * Check if file exists
2957
+ *
2958
+ * @param path
2959
+ * @returns
2960
+ */
2961
+ static async fileExists(path$6) {
2962
+ try {
2963
+ await (0, fs_promises.access)(path$6);
2964
+ return true;
2965
+ } catch {
2966
+ return false;
2967
+ }
2968
+ }
2969
+ static findUpConfig(cwd, name, extensions) {
2970
+ return (0, escalade_sync.default)(cwd, (_dir, names) => {
2971
+ for (const ext of extensions) {
2972
+ const filename = `${name}.${ext}`;
2973
+ if (names.includes(filename)) return filename;
2974
+ }
2975
+ return false;
2976
+ });
2977
+ }
2978
+ };
2979
+
2922
2980
  //#endregion
2923
2981
  //#region src/arquebus.ts
2924
2982
  var arquebus = class arquebus {
@@ -2940,22 +2998,22 @@ var arquebus = class arquebus {
2940
2998
  return this.instance;
2941
2999
  }
2942
3000
  /**
2943
- * Initialize a new database connection
2944
- *
2945
- * @returns
3001
+ * Initialize a new database connection
3002
+ *
3003
+ * @returns
2946
3004
  */
2947
3005
  static fire(connection = null) {
2948
3006
  return this.getInstance().getConnection(connection);
2949
3007
  }
2950
3008
  /**
2951
- * Initialize a new database connection
2952
- *
3009
+ * Initialize a new database connection
3010
+ *
2953
3011
  * This is an alias of `arquebus.fire()` and will be removed in the future
2954
- *
3012
+ *
2955
3013
  * @deprecated since version 0.3.0
2956
3014
  * @alias fire
2957
- *
2958
- * @returns
3015
+ *
3016
+ * @returns
2959
3017
  */
2960
3018
  static connection(connection = null) {
2961
3019
  return this.fire(connection);
@@ -2992,11 +3050,12 @@ var arquebus = class arquebus {
2992
3050
  }
2993
3051
  getConnection(name = null) {
2994
3052
  name = name || "default";
2995
- if (this.manager[name] === void 0) {
2996
- const queryBuilder = new query_builder_default(this.connections[name], arquebus.getConnectorFactory());
2997
- this.manager[name] = queryBuilder;
3053
+ const resolvedName = this.connections[name] ? name : "default";
3054
+ if (this.manager[resolvedName] === void 0) {
3055
+ const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
3056
+ this.manager[resolvedName] = queryBuilder;
2998
3057
  }
2999
- return this.manager[name];
3058
+ return this.manager[resolvedName];
3000
3059
  }
3001
3060
  addConnection(config, name = "default") {
3002
3061
  this.connections[name] = {
@@ -3013,13 +3072,13 @@ var arquebus = class arquebus {
3013
3072
  }
3014
3073
  /**
3015
3074
  * Autoload the config file
3016
- *
3017
- * @param addConnection
3075
+ *
3076
+ * @param addConnection
3018
3077
  * @default true
3019
- * If set to `false` we will no attempt add the connection, we
3078
+ * If set to `false` we will no attempt add the connection, we
3020
3079
  * will just go ahead and return the config
3021
- *
3022
- * @returns
3080
+ *
3081
+ * @returns
3023
3082
  */
3024
3083
  static async autoLoad(addConnection = true) {
3025
3084
  let config;
@@ -3036,6 +3095,23 @@ var arquebus = class arquebus {
3036
3095
  if (addConnection) instance.addConnection(config, config.client);
3037
3096
  return config;
3038
3097
  } else throw new Error("arquebus.config.ts found in production without build step");
3098
+ const candidateDirs = [
3099
+ process.cwd(),
3100
+ path.default.join(process.cwd(), "test", "cli"),
3101
+ path.default.join(process.cwd(), "test")
3102
+ ];
3103
+ for (const dir of candidateDirs) {
3104
+ const found = Utils.findUpConfig(dir, "arquebus.config", [
3105
+ "js",
3106
+ "ts",
3107
+ "cjs"
3108
+ ]);
3109
+ if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
3110
+ config = (await import(found)).default;
3111
+ if (addConnection) instance.addConnection(config, config.client);
3112
+ return config;
3113
+ } else throw new Error("arquebus.config.ts found in production without build step");
3114
+ }
3039
3115
  return {};
3040
3116
  }
3041
3117
  beginTransaction(connection = null) {
@@ -4712,10 +4788,6 @@ var Builder = class Builder extends Inference {
4712
4788
  };
4713
4789
  var builder_default = Builder;
4714
4790
 
4715
- //#endregion
4716
- //#region src/cli/utils.ts
4717
- const join = path.default.join;
4718
-
4719
4791
  //#endregion
4720
4792
  //#region src/inspector/dialects/sqlite.ts
4721
4793
  function parseDefaultValue(value) {
@@ -6,12 +6,14 @@ import collect$1, { Collection, collect } from "collect.js";
6
6
  import Knex$1 from "knex";
7
7
  import path from "path";
8
8
  import { existsSync } from "fs";
9
+ import { access } from "fs/promises";
10
+ import escalade from "escalade/sync";
11
+ import resolveFrom from "resolve-from";
9
12
  import pluralize from "pluralize";
10
13
  import "@h3ravel/shared";
11
14
  import "node:fs/promises";
12
- import "fs/promises";
13
- import "escalade/sync";
14
- import "resolve-from";
15
+ import "node:path";
16
+ import "node:url";
15
17
 
16
18
  //#region rolldown:runtime
17
19
  var __defProp = Object.defineProperty;
@@ -1345,7 +1347,7 @@ var InvalidArgumentError = class extends BaseError {};
1345
1347
  var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
1346
1348
  /**
1347
1349
  * Compose function that merges multiple classes and mixins
1348
- *
1350
+ *
1349
1351
  * @example
1350
1352
  * const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
1351
1353
  * return class extends Base {
@@ -1382,10 +1384,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
1382
1384
  * console.log(user.pluginMethod('w')) // "plugin"
1383
1385
  * console.log(user.pluginMethod()) // "plugin"
1384
1386
  * console.log(user.relationPosts()) // "hasMany Posts"
1385
- *
1386
- * @param Base
1387
- * @param mixins
1388
- * @returns
1387
+ *
1388
+ * @param Base
1389
+ * @param mixins
1390
+ * @returns
1389
1391
  */
1390
1392
  function compose$1(Base, ...mixins) {
1391
1393
  /**
@@ -1439,10 +1441,10 @@ const getSetterMethod = (attr) => {
1439
1441
  };
1440
1442
  /**
1441
1443
  * Tap into a model a collection instance
1442
- *
1443
- * @param instance
1444
- * @param callback
1445
- * @returns
1444
+ *
1445
+ * @param instance
1446
+ * @param callback
1447
+ * @returns
1446
1448
  */
1447
1449
  const tap = (instance, callback) => {
1448
1450
  const result = callback(instance);
@@ -2893,6 +2895,59 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
2893
2895
  };
2894
2896
  var query_builder_default = QueryBuilder;
2895
2897
 
2898
+ //#endregion
2899
+ //#region src/cli/utils.ts
2900
+ const join = path.join;
2901
+ var Utils = class {
2902
+ /**
2903
+ * Wraps text with chalk
2904
+ *
2905
+ * @param txt
2906
+ * @param color
2907
+ * @returns
2908
+ */
2909
+ static textFormat(txt, color) {
2910
+ return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
2911
+ }
2912
+ static findModulePkg(moduleId, cwd) {
2913
+ const parts = moduleId.replace(/\\/g, "/").split("/");
2914
+ let packageName = "";
2915
+ if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
2916
+ packageName += parts.shift();
2917
+ const packageJson = path.join(packageName, "package.json");
2918
+ const resolved = resolveFrom.silent(cwd ?? process.cwd(), packageJson);
2919
+ if (!resolved) return;
2920
+ return path.join(path.dirname(resolved), parts.join("/"));
2921
+ }
2922
+ static async getMigrationPaths(cwd, migrator, defaultPath, path$1) {
2923
+ if (path$1) return [join(cwd, path$1)];
2924
+ return [...migrator.getPaths(), join(cwd, defaultPath)];
2925
+ }
2926
+ /**
2927
+ * Check if file exists
2928
+ *
2929
+ * @param path
2930
+ * @returns
2931
+ */
2932
+ static async fileExists(path$1) {
2933
+ try {
2934
+ await access(path$1);
2935
+ return true;
2936
+ } catch {
2937
+ return false;
2938
+ }
2939
+ }
2940
+ static findUpConfig(cwd, name, extensions) {
2941
+ return escalade(cwd, (_dir, names) => {
2942
+ for (const ext of extensions) {
2943
+ const filename = `${name}.${ext}`;
2944
+ if (names.includes(filename)) return filename;
2945
+ }
2946
+ return false;
2947
+ });
2948
+ }
2949
+ };
2950
+
2896
2951
  //#endregion
2897
2952
  //#region src/arquebus.ts
2898
2953
  var arquebus = class arquebus {
@@ -2914,22 +2969,22 @@ var arquebus = class arquebus {
2914
2969
  return this.instance;
2915
2970
  }
2916
2971
  /**
2917
- * Initialize a new database connection
2918
- *
2919
- * @returns
2972
+ * Initialize a new database connection
2973
+ *
2974
+ * @returns
2920
2975
  */
2921
2976
  static fire(connection = null) {
2922
2977
  return this.getInstance().getConnection(connection);
2923
2978
  }
2924
2979
  /**
2925
- * Initialize a new database connection
2926
- *
2980
+ * Initialize a new database connection
2981
+ *
2927
2982
  * This is an alias of `arquebus.fire()` and will be removed in the future
2928
- *
2983
+ *
2929
2984
  * @deprecated since version 0.3.0
2930
2985
  * @alias fire
2931
- *
2932
- * @returns
2986
+ *
2987
+ * @returns
2933
2988
  */
2934
2989
  static connection(connection = null) {
2935
2990
  return this.fire(connection);
@@ -2966,11 +3021,12 @@ var arquebus = class arquebus {
2966
3021
  }
2967
3022
  getConnection(name = null) {
2968
3023
  name = name || "default";
2969
- if (this.manager[name] === void 0) {
2970
- const queryBuilder = new query_builder_default(this.connections[name], arquebus.getConnectorFactory());
2971
- this.manager[name] = queryBuilder;
3024
+ const resolvedName = this.connections[name] ? name : "default";
3025
+ if (this.manager[resolvedName] === void 0) {
3026
+ const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
3027
+ this.manager[resolvedName] = queryBuilder;
2972
3028
  }
2973
- return this.manager[name];
3029
+ return this.manager[resolvedName];
2974
3030
  }
2975
3031
  addConnection(config, name = "default") {
2976
3032
  this.connections[name] = {
@@ -2987,13 +3043,13 @@ var arquebus = class arquebus {
2987
3043
  }
2988
3044
  /**
2989
3045
  * Autoload the config file
2990
- *
2991
- * @param addConnection
3046
+ *
3047
+ * @param addConnection
2992
3048
  * @default true
2993
- * If set to `false` we will no attempt add the connection, we
3049
+ * If set to `false` we will no attempt add the connection, we
2994
3050
  * will just go ahead and return the config
2995
- *
2996
- * @returns
3051
+ *
3052
+ * @returns
2997
3053
  */
2998
3054
  static async autoLoad(addConnection = true) {
2999
3055
  let config;
@@ -3010,6 +3066,23 @@ var arquebus = class arquebus {
3010
3066
  if (addConnection) instance.addConnection(config, config.client);
3011
3067
  return config;
3012
3068
  } else throw new Error("arquebus.config.ts found in production without build step");
3069
+ const candidateDirs = [
3070
+ process.cwd(),
3071
+ path.join(process.cwd(), "test", "cli"),
3072
+ path.join(process.cwd(), "test")
3073
+ ];
3074
+ for (const dir of candidateDirs) {
3075
+ const found = Utils.findUpConfig(dir, "arquebus.config", [
3076
+ "js",
3077
+ "ts",
3078
+ "cjs"
3079
+ ]);
3080
+ if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
3081
+ config = (await import(found)).default;
3082
+ if (addConnection) instance.addConnection(config, config.client);
3083
+ return config;
3084
+ } else throw new Error("arquebus.config.ts found in production without build step");
3085
+ }
3013
3086
  return {};
3014
3087
  }
3015
3088
  beginTransaction(connection = null) {
@@ -4686,10 +4759,6 @@ var Builder = class Builder extends Inference {
4686
4759
  };
4687
4760
  var builder_default = Builder;
4688
4761
 
4689
- //#endregion
4690
- //#region src/cli/utils.ts
4691
- const join = path.join;
4692
-
4693
4762
  //#endregion
4694
4763
  //#region src/inspector/dialects/sqlite.ts
4695
4764
  function parseDefaultValue(value) {