@h3ravel/arquebus 0.4.1 → 0.6.0

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 +225 -171
  3. package/bin/index.js +208 -122
  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 +3655 -183
  10. package/dist/browser/index.d.ts +3655 -183
  11. package/dist/browser/index.js +9 -9
  12. package/dist/index.cjs +270 -135
  13. package/dist/index.d.cts +3797 -294
  14. package/dist/index.d.ts +3797 -294
  15. package/dist/index.js +263 -133
  16. package/dist/inspector/index.cjs +122 -46
  17. package/dist/inspector/index.js +119 -46
  18. package/dist/migrations/index.cjs +171 -151
  19. package/dist/migrations/index.d.cts +3510 -27
  20. package/dist/migrations/index.d.ts +3510 -27
  21. package/dist/migrations/index.js +177 -150
  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 +102 -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 +15 -4
  39. package/types/builder.ts +158 -80
  40. package/types/container.ts +79 -66
  41. package/types/generics.ts +75 -36
  42. package/types/modeling.ts +213 -158
  43. package/types/query-builder.ts +223 -186
  44. package/types/query-methods.ts +160 -104
  45. package/types/utils.ts +64 -55
@@ -1,5 +1,5 @@
1
1
  import { __export } from "./chunk-PECeCxCb.js";
2
- import { Logger, TaskManager } from "@h3ravel/shared";
2
+ import { FileSystem, Logger, TaskManager } from "@h3ravel/shared";
3
3
  import { assign, camel, diff, flat, get, isArray, isEmpty, isEqual, isString, omit, pick, set, snake, trim } from "radashi";
4
4
  import advancedFormat from "dayjs/plugin/advancedFormat.js";
5
5
  import dayjs from "dayjs";
@@ -7,13 +7,12 @@ import collect, { Collection, collect as collect$1 } from "collect.js";
7
7
  import Knex$1 from "knex";
8
8
  import path from "path";
9
9
  import { existsSync } from "fs";
10
- import pluralize from "pluralize";
11
- import fs from "node:fs/promises";
12
10
  import { access } from "fs/promises";
13
11
  import escalade from "escalade/sync";
14
12
  import resolveFrom from "resolve-from";
15
- import { existsSync as existsSync$1, readFileSync } from "node:fs";
16
- import { dirname } from "node:path";
13
+ import pluralize from "pluralize";
14
+ import fs, { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
15
+ import path$1, { dirname } from "node:path";
17
16
  import { fileURLToPath } from "node:url";
18
17
 
19
18
  //#region src/migrations/migration-repository.ts
@@ -1405,7 +1404,7 @@ var InvalidArgumentError = class extends BaseError {};
1405
1404
  var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
1406
1405
  /**
1407
1406
  * Compose function that merges multiple classes and mixins
1408
- *
1407
+ *
1409
1408
  * @example
1410
1409
  * const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
1411
1410
  * return class extends Base {
@@ -1442,10 +1441,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
1442
1441
  * console.log(user.pluginMethod('w')) // "plugin"
1443
1442
  * console.log(user.pluginMethod()) // "plugin"
1444
1443
  * console.log(user.relationPosts()) // "hasMany Posts"
1445
- *
1446
- * @param Base
1447
- * @param mixins
1448
- * @returns
1444
+ *
1445
+ * @param Base
1446
+ * @param mixins
1447
+ * @returns
1449
1448
  */
1450
1449
  function compose$1(Base, ...mixins) {
1451
1450
  /**
@@ -1499,10 +1498,10 @@ const getSetterMethod = (attr) => {
1499
1498
  };
1500
1499
  /**
1501
1500
  * Tap into a model a collection instance
1502
- *
1503
- * @param instance
1504
- * @param callback
1505
- * @returns
1501
+ *
1502
+ * @param instance
1503
+ * @param callback
1504
+ * @returns
1506
1505
  */
1507
1506
  const tap = (instance, callback) => {
1508
1507
  const result = callback(instance);
@@ -2338,8 +2337,8 @@ var HasManyThrough = class extends relation_default {
2338
2337
  const results = await this.take(1).get(columns);
2339
2338
  return results.count() > 0 ? results.first() : null;
2340
2339
  }
2341
- async firstOrFail(columns = ["*"]) {
2342
- const model = await this.first(columns);
2340
+ async firstOrFail(...columns) {
2341
+ const model = await this.first(...columns);
2343
2342
  if (model) return model;
2344
2343
  throw new ModelNotFoundError().setModel(this.related.constructor);
2345
2344
  }
@@ -2378,7 +2377,7 @@ var HasManyThrough = class extends relation_default {
2378
2377
  }
2379
2378
  async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
2380
2379
  this.query.addSelect(this.shouldSelect(columns));
2381
- return await this.query.paginate(perPage, columns, pageName, page);
2380
+ return await this.query.paginate(perPage ?? 15, columns, pageName, page);
2382
2381
  }
2383
2382
  shouldSelect(columns = ["*"]) {
2384
2383
  if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
@@ -2656,9 +2655,6 @@ const UniqueIds = (Model$1) => {
2656
2655
  uniqueIds() {
2657
2656
  return [];
2658
2657
  }
2659
- newUniqueId() {
2660
- return null;
2661
- }
2662
2658
  setUniqueIds() {
2663
2659
  const uniqueIds = this.uniqueIds();
2664
2660
  for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
@@ -2680,6 +2676,7 @@ var Paginator = class {
2680
2676
  options = {};
2681
2677
  static setFormatter(formatter) {
2682
2678
  if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
2679
+ if (!formatter) return;
2683
2680
  this.formatter = formatter;
2684
2681
  }
2685
2682
  constructor(items, total, perPage, currentPage = 1, options = {}) {
@@ -2768,8 +2765,10 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
2768
2765
  asProxy() {
2769
2766
  return new Proxy(this, {
2770
2767
  get: function(target, prop) {
2768
+ var _target$connector$cli;
2771
2769
  if (typeof target[prop] !== "undefined") return target[prop];
2772
2770
  if (["destroy", "schema"].includes(prop)) return target.connector.schema;
2771
+ const skipReturning = !!((_target$connector$cli = target.connector.client.config) === null || _target$connector$cli === void 0 || (_target$connector$cli = _target$connector$cli.client) === null || _target$connector$cli === void 0 ? void 0 : _target$connector$cli.includes("mysql")) && prop === "returning";
2773
2772
  if ([
2774
2773
  "select",
2775
2774
  "from",
@@ -2832,7 +2831,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
2832
2831
  "clearWhere",
2833
2832
  "clearHaving",
2834
2833
  "clearGroup"
2835
- ].includes(prop)) return (...args) => {
2834
+ ].includes(prop) && !skipReturning) return (...args) => {
2836
2835
  target.connector[prop](...args);
2837
2836
  return target.asProxy();
2838
2837
  };
@@ -2889,7 +2888,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
2889
2888
  } while (countResults === count);
2890
2889
  return true;
2891
2890
  }
2892
- async paginate(page = 1, perPage = 15) {
2891
+ async paginate(page = 1, perPage = 15, _pageName, _page) {
2893
2892
  const total = await this.clone().clearOrder().count("*");
2894
2893
  let results;
2895
2894
  if (total > 0) {
@@ -2953,6 +2952,59 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
2953
2952
  };
2954
2953
  var query_builder_default = QueryBuilder;
2955
2954
 
2955
+ //#endregion
2956
+ //#region src/cli/utils.ts
2957
+ const join = path.join;
2958
+ var Utils = class {
2959
+ /**
2960
+ * Wraps text with chalk
2961
+ *
2962
+ * @param txt
2963
+ * @param color
2964
+ * @returns
2965
+ */
2966
+ static textFormat(txt, color) {
2967
+ return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
2968
+ }
2969
+ static findModulePkg(moduleId, cwd) {
2970
+ const parts = moduleId.replace(/\\/g, "/").split("/");
2971
+ let packageName = "";
2972
+ if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
2973
+ packageName += parts.shift();
2974
+ const packageJson = path.join(packageName, "package.json");
2975
+ const resolved = resolveFrom.silent(cwd ?? process.cwd(), packageJson);
2976
+ if (!resolved) return;
2977
+ return path.join(path.dirname(resolved), parts.join("/"));
2978
+ }
2979
+ static async getMigrationPaths(cwd, migrator, defaultPath, path$2) {
2980
+ if (path$2) return [join(cwd, path$2)];
2981
+ return [...migrator.getPaths(), join(cwd, defaultPath)];
2982
+ }
2983
+ /**
2984
+ * Check if file exists
2985
+ *
2986
+ * @param path
2987
+ * @returns
2988
+ */
2989
+ static async fileExists(path$2) {
2990
+ try {
2991
+ await access(path$2);
2992
+ return true;
2993
+ } catch {
2994
+ return false;
2995
+ }
2996
+ }
2997
+ static findUpConfig(cwd, name, extensions) {
2998
+ return escalade(cwd, (_dir, names) => {
2999
+ for (const ext of extensions) {
3000
+ const filename = `${name}.${ext}`;
3001
+ if (names.includes(filename)) return filename;
3002
+ }
3003
+ return false;
3004
+ });
3005
+ }
3006
+ };
3007
+
2956
3008
  //#endregion
2957
3009
  //#region src/arquebus.ts
2958
3010
  var arquebus = class arquebus {
@@ -2974,22 +3026,22 @@ var arquebus = class arquebus {
2974
3026
  return this.instance;
2975
3027
  }
2976
3028
  /**
2977
- * Initialize a new database connection
2978
- *
2979
- * @returns
3029
+ * Initialize a new database connection
3030
+ *
3031
+ * @returns
2980
3032
  */
2981
3033
  static fire(connection = null) {
2982
3034
  return this.getInstance().getConnection(connection);
2983
3035
  }
2984
3036
  /**
2985
- * Initialize a new database connection
2986
- *
3037
+ * Initialize a new database connection
3038
+ *
2987
3039
  * This is an alias of `arquebus.fire()` and will be removed in the future
2988
- *
3040
+ *
2989
3041
  * @deprecated since version 0.3.0
2990
3042
  * @alias fire
2991
- *
2992
- * @returns
3043
+ *
3044
+ * @returns
2993
3045
  */
2994
3046
  static connection(connection = null) {
2995
3047
  return this.fire(connection);
@@ -3026,11 +3078,12 @@ var arquebus = class arquebus {
3026
3078
  }
3027
3079
  getConnection(name = null) {
3028
3080
  name = name || "default";
3029
- if (this.manager[name] === void 0) {
3030
- const queryBuilder = new query_builder_default(this.connections[name], arquebus.getConnectorFactory());
3031
- this.manager[name] = queryBuilder;
3081
+ const resolvedName = this.connections[name] ? name : "default";
3082
+ if (this.manager[resolvedName] === void 0) {
3083
+ const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
3084
+ this.manager[resolvedName] = queryBuilder;
3032
3085
  }
3033
- return this.manager[name];
3086
+ return this.manager[resolvedName];
3034
3087
  }
3035
3088
  addConnection(config, name = "default") {
3036
3089
  this.connections[name] = {
@@ -3047,13 +3100,13 @@ var arquebus = class arquebus {
3047
3100
  }
3048
3101
  /**
3049
3102
  * Autoload the config file
3050
- *
3051
- * @param addConnection
3103
+ *
3104
+ * @param addConnection
3052
3105
  * @default true
3053
- * If set to `false` we will no attempt add the connection, we
3106
+ * If set to `false` we will no attempt add the connection, we
3054
3107
  * will just go ahead and return the config
3055
- *
3056
- * @returns
3108
+ *
3109
+ * @returns
3057
3110
  */
3058
3111
  static async autoLoad(addConnection = true) {
3059
3112
  let config;
@@ -3070,6 +3123,23 @@ var arquebus = class arquebus {
3070
3123
  if (addConnection) instance.addConnection(config, config.client);
3071
3124
  return config;
3072
3125
  } else throw new Error("arquebus.config.ts found in production without build step");
3126
+ const candidateDirs = [
3127
+ process.cwd(),
3128
+ path.join(process.cwd(), "test", "cli"),
3129
+ path.join(process.cwd(), "test")
3130
+ ];
3131
+ for (const dir of candidateDirs) {
3132
+ const found = Utils.findUpConfig(dir, "arquebus.config", [
3133
+ "js",
3134
+ "ts",
3135
+ "cjs"
3136
+ ]);
3137
+ if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
3138
+ config = (await import(found)).default;
3139
+ if (addConnection) instance.addConnection(config, config.client);
3140
+ return config;
3141
+ } else throw new Error("arquebus.config.ts found in production without build step");
3142
+ }
3073
3143
  return {};
3074
3144
  }
3075
3145
  beginTransaction(connection = null) {
@@ -3128,14 +3198,15 @@ var arquebus_default = arquebus;
3128
3198
 
3129
3199
  //#endregion
3130
3200
  //#region src/model.ts
3131
- const BaseModel = compose(class {}, has_attributes_default, hides_attributes_default, has_relations_default, has_timestamps_default, has_hooks_default, has_global_scopes_default, unique_ids_default);
3201
+ const ModelClass = class {};
3202
+ const BaseModel = compose(ModelClass, has_attributes_default, hides_attributes_default, has_relations_default, has_timestamps_default, has_hooks_default, has_global_scopes_default, unique_ids_default);
3132
3203
  var Model = class Model extends BaseModel {
3133
- primaryKey = "id";
3134
3204
  builder = null;
3135
3205
  table = null;
3136
3206
  keyType = "int";
3137
3207
  incrementing = true;
3138
3208
  withCount = [];
3209
+ primaryKey = "id";
3139
3210
  perPage = 15;
3140
3211
  static globalScopes = {};
3141
3212
  static pluginInitializers = {};
@@ -3145,6 +3216,7 @@ var Model = class Model extends BaseModel {
3145
3216
  eagerLoad = {};
3146
3217
  exists = false;
3147
3218
  with = [];
3219
+ name;
3148
3220
  trx = null;
3149
3221
  constructor(attributes = {}) {
3150
3222
  super();
@@ -3916,8 +3988,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
3916
3988
  const results = await this.take(1).get(columns);
3917
3989
  return results.count() > 0 ? results.first() : null;
3918
3990
  }
3919
- async firstOrFail(columns = ["*"]) {
3920
- const model = await this.first(columns);
3991
+ async firstOrFail(...columns) {
3992
+ const model = await this.first(...columns);
3921
3993
  if (model !== null) return model;
3922
3994
  throw new ModelNotFoundError().setModel(this.related.constructor);
3923
3995
  }
@@ -4093,7 +4165,9 @@ var Builder = class Builder extends Inference$1 {
4093
4165
  }
4094
4166
  asProxy() {
4095
4167
  return new Proxy(this, { get(target, prop) {
4168
+ var _target$query$connect;
4096
4169
  if (typeof target[prop] !== "undefined") return target[prop];
4170
+ const skipReturning = !!((_target$query$connect = target.query.connector) === null || _target$query$connect === void 0 || (_target$query$connect = _target$query$connect.client.config) === null || _target$query$connect === void 0 || (_target$query$connect = _target$query$connect.client) === null || _target$query$connect === void 0 ? void 0 : _target$query$connect.includes("mysql")) && prop === "returning";
4097
4171
  if ([
4098
4172
  "select",
4099
4173
  "from",
@@ -4156,7 +4230,7 @@ var Builder = class Builder extends Inference$1 {
4156
4230
  "clearWhere",
4157
4231
  "clearHaving",
4158
4232
  "clearGroup"
4159
- ].includes(prop)) return (...args) => {
4233
+ ].includes(prop) && !skipReturning) return (...args) => {
4160
4234
  target.query[prop](...args);
4161
4235
  return target.asProxy();
4162
4236
  };
@@ -4758,6 +4832,12 @@ var Migration = class extends Inference {
4758
4832
  };
4759
4833
  var migration_default = Migration;
4760
4834
 
4835
+ //#endregion
4836
+ //#region node_modules/.pnpm/tsdown@0.15.6_typescript@5.9.3/node_modules/tsdown/esm-shims.js
4837
+ const getFilename = () => fileURLToPath(import.meta.url);
4838
+ const getDirname = () => path$1.dirname(getFilename());
4839
+ const __dirname = /* @__PURE__ */ getDirname();
4840
+
4761
4841
  //#endregion
4762
4842
  //#region src/inspector/dialects/sqlite.ts
4763
4843
  function parseDefaultValue(value) {
@@ -5035,9 +5115,9 @@ var Migrator = class {
5035
5115
  }
5036
5116
  /**
5037
5117
  * Drop all tables and re-run all migrations
5038
- *
5039
- * @param paths
5040
- * @param options
5118
+ *
5119
+ * @param paths
5120
+ * @param options
5041
5121
  */
5042
5122
  async fresh(paths, options) {
5043
5123
  /** Initialise connections */
@@ -5129,59 +5209,6 @@ var Migrator = class {
5129
5209
  };
5130
5210
  var migrator_default = Migrator;
5131
5211
 
5132
- //#endregion
5133
- //#region src/cli/utils.ts
5134
- const join = path.join;
5135
- var Utils = class {
5136
- /**
5137
- * Wraps text with chalk
5138
- *
5139
- * @param txt
5140
- * @param color
5141
- * @returns
5142
- */
5143
- static textFormat(txt, color) {
5144
- return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
5145
- }
5146
- static findModulePkg(moduleId, cwd) {
5147
- const parts = moduleId.replace(/\\/g, "/").split("/");
5148
- let packageName = "";
5149
- if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
5150
- packageName += parts.shift();
5151
- const packageJson = path.join(packageName, "package.json");
5152
- const resolved = resolveFrom.silent(cwd ?? process.cwd(), packageJson);
5153
- if (!resolved) return;
5154
- return path.join(path.dirname(resolved), parts.join("/"));
5155
- }
5156
- static async getMigrationPaths(cwd, migrator, defaultPath, path$1) {
5157
- if (path$1) return [join(cwd, path$1)];
5158
- return [...migrator.getPaths(), join(cwd, defaultPath)];
5159
- }
5160
- /**
5161
- * Check if file exists
5162
- *
5163
- * @param path
5164
- * @returns
5165
- */
5166
- static async fileExists(path$1) {
5167
- try {
5168
- await access(path$1);
5169
- return true;
5170
- } catch {
5171
- return false;
5172
- }
5173
- }
5174
- static findUpConfig(cwd, name, extensions) {
5175
- return escalade(cwd, (_dir, names) => {
5176
- for (const ext of extensions) {
5177
- const filename = `${name}.${ext}`;
5178
- if (names.includes(filename)) return filename;
5179
- }
5180
- return false;
5181
- });
5182
- }
5183
- };
5184
-
5185
5212
  //#endregion
5186
5213
  //#region src/migrate.ts
5187
5214
  var Migrate = class {
@@ -5193,10 +5220,10 @@ var Migrate = class {
5193
5220
  }
5194
5221
  /**
5195
5222
  * Runs all pending migrations
5196
- *
5197
- * @param config
5198
- * @param options
5199
- * @param destroyAll
5223
+ *
5224
+ * @param config
5225
+ * @param options
5226
+ * @param destroyAll
5200
5227
  */
5201
5228
  async run(config, options = {}, destroyAll = false) {
5202
5229
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5210,10 +5237,10 @@ var Migrate = class {
5210
5237
  }
5211
5238
  /**
5212
5239
  * Rollback the last migration
5213
- *
5214
- * @param config
5215
- * @param options
5216
- * @param destroyAll
5240
+ *
5241
+ * @param config
5242
+ * @param options
5243
+ * @param destroyAll
5217
5244
  */
5218
5245
  async rollback(config, options = {}, destroyAll = false) {
5219
5246
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5227,10 +5254,10 @@ var Migrate = class {
5227
5254
  }
5228
5255
  /**
5229
5256
  * Rollback all database migrations
5230
- *
5231
- * @param config
5232
- * @param options
5233
- * @param destroyAll
5257
+ *
5258
+ * @param config
5259
+ * @param options
5260
+ * @param destroyAll
5234
5261
  */
5235
5262
  async reset(config, options = {}, destroyAll = false) {
5236
5263
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5245,10 +5272,10 @@ var Migrate = class {
5245
5272
  }
5246
5273
  /**
5247
5274
  * Reset and re-run all migrations
5248
- *
5249
- * @param config
5250
- * @param options
5251
- * @param destroyAll
5275
+ *
5276
+ * @param config
5277
+ * @param options
5278
+ * @param destroyAll
5252
5279
  */
5253
5280
  async refresh(config, options = {}, destroyAll = false) {
5254
5281
  await this.reset(config, Object.assign({}, options, { quiet: true }), false);
@@ -5257,10 +5284,10 @@ var Migrate = class {
5257
5284
  }
5258
5285
  /**
5259
5286
  * Drop all tables and re-run all migrations
5260
- *
5261
- * @param config
5262
- * @param options
5263
- * @param destroyAll
5287
+ *
5288
+ * @param config
5289
+ * @param options
5290
+ * @param destroyAll
5264
5291
  */
5265
5292
  async fresh(config, options = {}, destroyAll = false) {
5266
5293
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5270,8 +5297,8 @@ var Migrate = class {
5270
5297
  }
5271
5298
  /**
5272
5299
  * Prepares the database for migration
5273
- *
5274
- * @param migrator
5300
+ *
5301
+ * @param migrator
5275
5302
  */
5276
5303
  async prepareDatabase(migrator) {
5277
5304
  if (!await migrator.repositoryExists()) {
@@ -5283,11 +5310,11 @@ var Migrate = class {
5283
5310
  }
5284
5311
  /**
5285
5312
  * Check the status of available migrations
5286
- *
5287
- * @param config
5288
- * @param options
5289
- * @param destroyAll
5290
- * @returns
5313
+ *
5314
+ * @param config
5315
+ * @param options
5316
+ * @param destroyAll
5317
+ * @returns
5291
5318
  */
5292
5319
  async status(config, options = {}, destroyAll = false) {
5293
5320
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5314,9 +5341,9 @@ var Migrate = class {
5314
5341
  }
5315
5342
  /**
5316
5343
  * Setup the database connection
5317
- *
5318
- * @param config
5319
- * @returns
5344
+ *
5345
+ * @param config
5346
+ * @returns
5320
5347
  */
5321
5348
  async setupConnection(config) {
5322
5349
  var _config$migrations;
@@ -5346,54 +5373,54 @@ var MigrationCreator = class {
5346
5373
  }
5347
5374
  /**
5348
5375
  * Create a new migration file
5349
- *
5350
- * @param name
5351
- * @param dir
5352
- * @param table
5353
- * @param create
5354
- * @returns
5376
+ *
5377
+ * @param name
5378
+ * @param dir
5379
+ * @param table
5380
+ * @param create
5381
+ * @returns
5355
5382
  */
5356
5383
  async create(name, dir, table, create = false) {
5357
- const stub = this.getStub(table, create);
5384
+ const stub = await this.getStub(table, create);
5358
5385
  const filePath = this.getPath(name, dir);
5359
5386
  await this.ensureDirectoryExists(path.dirname(filePath));
5360
- await fs.writeFile(filePath, this.populateStub(stub, table));
5387
+ await writeFile(filePath, this.populateStub(stub, table));
5361
5388
  await this.firePostCreateHooks(table, filePath);
5362
5389
  return filePath;
5363
5390
  }
5364
5391
  /**
5365
5392
  * Publish migrations from third party vendors
5366
- *
5367
- * @param dir
5368
- * @param callback
5393
+ *
5394
+ * @param dir
5395
+ * @param callback
5369
5396
  */
5370
5397
  async publish(dir, callback) {
5371
- const migrationFiles = await fs.readdir(this.customStubPath ?? "");
5398
+ const migrationFiles = await readdir(this.customStubPath ?? "");
5372
5399
  await this.ensureDirectoryExists(dir);
5373
5400
  for (const migrationFile of migrationFiles) {
5374
5401
  const sourceFilePath = path.join(this.customStubPath ?? "", migrationFile);
5375
5402
  const destinationFilePath = path.join(dir, migrationFile);
5376
- await fs.copyFile(sourceFilePath, destinationFilePath);
5403
+ await copyFile(sourceFilePath, destinationFilePath);
5377
5404
  if (callback) callback(migrationFile, sourceFilePath, destinationFilePath);
5378
5405
  }
5379
5406
  }
5380
- getStub(table, create = false) {
5407
+ async getStub(table, create = false) {
5381
5408
  let stub;
5382
5409
  if (!table) {
5383
5410
  const customPath = path.join(this.customStubPath ?? "", `migration-${this.type}.stub`);
5384
5411
  console.log("\n", customPath, "---");
5385
- stub = existsSync$1(customPath) ? customPath : this.stubPath(`/migration-${this.type}.stub`);
5412
+ stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration-${this.type}.stub`);
5386
5413
  } else if (create) {
5387
5414
  const customPath = path.join(this.customStubPath ?? "", `migration.create-${this.type}.stub`);
5388
- stub = existsSync$1(customPath) ? customPath : this.stubPath(`/migration.create-${this.type}.stub`);
5415
+ stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.create-${this.type}.stub`);
5389
5416
  } else {
5390
5417
  const customPath = path.join(this.customStubPath ?? "", `migration.update-${this.type}.stub`);
5391
- stub = existsSync$1(customPath) ? customPath : this.stubPath(`/migration.update-${this.type}.stub`);
5418
+ stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.update-${this.type}.stub`);
5392
5419
  }
5393
- return readFileSync(stub, "utf-8");
5420
+ return await readFile(stub, "utf-8");
5394
5421
  }
5395
5422
  populateStub(stub, table) {
5396
- if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
5423
+ if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
5397
5424
  return stub;
5398
5425
  }
5399
5426
  getClassName(name) {
@@ -5410,7 +5437,7 @@ var MigrationCreator = class {
5410
5437
  this.postCreate.push(callback);
5411
5438
  }
5412
5439
  async ensureDirectoryExists(dir) {
5413
- await fs.mkdir(dir, { recursive: true });
5440
+ await mkdir(dir, { recursive: true });
5414
5441
  }
5415
5442
  stubPath(stub = "") {
5416
5443
  const __dirname$1 = this.getDirname(import.meta);
@@ -18,4 +18,4 @@ export default class extends Migration {
18
18
  async down(schema) {
19
19
  //
20
20
  }
21
- };
21
+ }
@@ -15,4 +15,4 @@ export default class extends Migration {
15
15
  async down (schema: SchemaBuilder) {
16
16
  //
17
17
  }
18
- };
18
+ }
@@ -8,9 +8,9 @@ export default class extends Migration {
8
8
  */
9
9
  async up(schema) {
10
10
  await schema.createTable('{{ table }}', (table) => {
11
- table.increments('id');
12
- table.timestamps();
13
- });
11
+ table.increments('id')
12
+ table.timestamps()
13
+ })
14
14
  }
15
15
 
16
16
  /**
@@ -19,6 +19,6 @@ export default class extends Migration {
19
19
  * @param {(import('@h3ravel/arquebus/types/query-builder').SchemaBuilder)} schema
20
20
  */
21
21
  async down(schema) {
22
- await schema.dropTableIfExists('{{ table }}');
22
+ await schema.dropTableIfExists('{{ table }}')
23
23
  }
24
- };
24
+ }
@@ -7,15 +7,15 @@ export default class extends Migration {
7
7
  */
8
8
  async up(schema: SchemaBuilder) {
9
9
  await schema.createTable('{{ table }}', (table) => {
10
- table.increments('id');
11
- table.timestamps();
12
- });
10
+ table.increments('id')
11
+ table.timestamps()
12
+ })
13
13
  }
14
14
 
15
15
  /**
16
16
  * Reverse the migrations.
17
17
  */
18
18
  async down(schema: SchemaBuilder) {
19
- await schema.dropTableIfExists('{{ table }}');
19
+ await schema.dropTableIfExists('{{ table }}')
20
20
  }
21
- };
21
+ }
@@ -9,7 +9,7 @@ export default class extends Migration {
9
9
  async up(schema) {
10
10
  await schema.table('{{ table }}', (table) => {
11
11
  //
12
- });
12
+ })
13
13
  }
14
14
 
15
15
  /**
@@ -20,6 +20,6 @@ export default class extends Migration {
20
20
  async down(schema) {
21
21
  await schema.table('{{ table }}', (table) => {
22
22
  //
23
- });
23
+ })
24
24
  }
25
25
  };