@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
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  [![Framework][ix]][lx]
8
8
  [![Arquebus ORM][i1]][l1]
9
- [![Downloads][d1]][d1]
9
+ [![Downloads][d1]][l1]
10
10
  [![Tests][tei]][tel]
11
11
  [![License][lini]][linl]
12
12
 
@@ -94,6 +94,25 @@ const users = await User.query()
94
94
  await user.load('posts');
95
95
  ```
96
96
 
97
+ ## Seeders
98
+
99
+ - Create a seeder: `npx arquebus make:seeder UsersSeeder`
100
+ - Run seeders: `npx arquebus db:seed` or `npx arquebus db:seed --path ./database/seeders`
101
+ - Seeder class example (TypeScript):
102
+
103
+ ```ts
104
+ import { Seeder } from '@h3ravel/arquebus';
105
+ import type QueryBuilder from '@h3ravel/arquebus/types/query-builder';
106
+
107
+ export default class UsersSeeder extends Seeder {
108
+ async run(connection: QueryBuilder) {
109
+ await connection.table('users').insert({ name: 'Alice' });
110
+ }
111
+ }
112
+ ```
113
+
114
+ Seeders execute with the same connection setup as migrations. The CLI resolves paths from `--basePath` and `--path` and loads seeders from `.ts`/`.js` files exporting a default class with a `run` method.
115
+
97
116
  ## Show Your Support
98
117
 
99
118
  Please ⭐️ this repository if this project helped you
package/bin/index.cjs CHANGED
@@ -1,81 +1,51 @@
1
1
  #!/usr/bin/env node
2
- //#region rolldown:runtime
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (all) => {
10
- let target = {};
11
- for (var name$1 in all) __defProp(target, name$1, {
12
- get: all[name$1],
13
- enumerable: true
14
- });
15
- return target;
16
- };
17
- var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
19
- key = keys[i];
20
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
21
- get: ((k) => from[k]).bind(null, key),
22
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
23
- });
24
- }
25
- return to;
26
- };
27
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
30
- }) : target, mod));
31
-
32
- //#endregion
2
+ const require_seeders = require('./seeders-ByeSoCAQ.cjs');
33
3
  let commander = require("commander");
34
- commander = __toESM(commander);
4
+ commander = require_seeders.__toESM(commander);
35
5
  let fs_promises = require("fs/promises");
36
- fs_promises = __toESM(fs_promises);
6
+ fs_promises = require_seeders.__toESM(fs_promises);
37
7
  let escalade_sync = require("escalade/sync");
38
- escalade_sync = __toESM(escalade_sync);
8
+ escalade_sync = require_seeders.__toESM(escalade_sync);
39
9
  let path = require("path");
40
- path = __toESM(path);
10
+ path = require_seeders.__toESM(path);
41
11
  let resolve_from = require("resolve-from");
42
- resolve_from = __toESM(resolve_from);
12
+ resolve_from = require_seeders.__toESM(resolve_from);
43
13
  let node_fs_promises = require("node:fs/promises");
44
- node_fs_promises = __toESM(node_fs_promises);
14
+ node_fs_promises = require_seeders.__toESM(node_fs_promises);
45
15
  let __h3ravel_shared = require("@h3ravel/shared");
46
- __h3ravel_shared = __toESM(__h3ravel_shared);
16
+ __h3ravel_shared = require_seeders.__toESM(__h3ravel_shared);
47
17
  let radashi = require("radashi");
48
- radashi = __toESM(radashi);
18
+ radashi = require_seeders.__toESM(radashi);
49
19
  let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
50
- dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js);
20
+ dayjs_plugin_advancedFormat_js = require_seeders.__toESM(dayjs_plugin_advancedFormat_js);
51
21
  let dayjs = require("dayjs");
52
- dayjs = __toESM(dayjs);
22
+ dayjs = require_seeders.__toESM(dayjs);
53
23
  let collect_js = require("collect.js");
54
- collect_js = __toESM(collect_js);
24
+ collect_js = require_seeders.__toESM(collect_js);
55
25
  let knex = require("knex");
56
- knex = __toESM(knex);
26
+ knex = require_seeders.__toESM(knex);
57
27
  let fs = require("fs");
58
- fs = __toESM(fs);
28
+ fs = require_seeders.__toESM(fs);
59
29
  let pluralize = require("pluralize");
60
- pluralize = __toESM(pluralize);
30
+ pluralize = require_seeders.__toESM(pluralize);
61
31
  let node_path = require("node:path");
62
- node_path = __toESM(node_path);
32
+ node_path = require_seeders.__toESM(node_path);
63
33
  let node_url = require("node:url");
64
- node_url = __toESM(node_url);
65
- let chalk = require("chalk");
66
- chalk = __toESM(chalk);
34
+ node_url = require_seeders.__toESM(node_url);
35
+ let __h3ravel_support = require("@h3ravel/support");
36
+ __h3ravel_support = require_seeders.__toESM(__h3ravel_support);
67
37
  let dotenv = require("dotenv");
68
- dotenv = __toESM(dotenv);
38
+ dotenv = require_seeders.__toESM(dotenv);
69
39
 
70
40
  //#region src/cli/utils.ts
71
41
  const join = path.default.join;
72
42
  var Utils = class {
73
43
  /**
74
44
  * Wraps text with chalk
75
- *
76
- * @param txt
77
- * @param color
78
- * @returns
45
+ *
46
+ * @param txt
47
+ * @param color
48
+ * @returns
79
49
  */
80
50
  static textFormat(txt, color) {
81
51
  return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
@@ -96,9 +66,9 @@ var Utils = class {
96
66
  }
97
67
  /**
98
68
  * Check if file exists
99
- *
100
- * @param path
101
- * @returns
69
+ *
70
+ * @param path
71
+ * @returns
102
72
  */
103
73
  static async fileExists(path$6) {
104
74
  try {
@@ -1521,10 +1491,10 @@ var InvalidArgumentError = class extends BaseError {};
1521
1491
 
1522
1492
  //#endregion
1523
1493
  //#region src/mixin.ts
1524
- var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
1494
+ var mixin_exports = /* @__PURE__ */ require_seeders.__export({ compose: () => compose$1 });
1525
1495
  /**
1526
1496
  * Compose function that merges multiple classes and mixins
1527
- *
1497
+ *
1528
1498
  * @example
1529
1499
  * const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
1530
1500
  * return class extends Base {
@@ -1561,10 +1531,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
1561
1531
  * console.log(user.pluginMethod('w')) // "plugin"
1562
1532
  * console.log(user.pluginMethod()) // "plugin"
1563
1533
  * console.log(user.relationPosts()) // "hasMany Posts"
1564
- *
1565
- * @param Base
1566
- * @param mixins
1567
- * @returns
1534
+ *
1535
+ * @param Base
1536
+ * @param mixins
1537
+ * @returns
1568
1538
  */
1569
1539
  function compose$1(Base, ...mixins) {
1570
1540
  /**
@@ -1618,10 +1588,10 @@ const getSetterMethod = (attr) => {
1618
1588
  };
1619
1589
  /**
1620
1590
  * Tap into a model a collection instance
1621
- *
1622
- * @param instance
1623
- * @param callback
1624
- * @returns
1591
+ *
1592
+ * @param instance
1593
+ * @param callback
1594
+ * @returns
1625
1595
  */
1626
1596
  const tap = (instance, callback) => {
1627
1597
  const result = callback(instance);
@@ -3093,22 +3063,22 @@ var arquebus = class arquebus {
3093
3063
  return this.instance;
3094
3064
  }
3095
3065
  /**
3096
- * Initialize a new database connection
3097
- *
3098
- * @returns
3066
+ * Initialize a new database connection
3067
+ *
3068
+ * @returns
3099
3069
  */
3100
3070
  static fire(connection = null) {
3101
3071
  return this.getInstance().getConnection(connection);
3102
3072
  }
3103
3073
  /**
3104
- * Initialize a new database connection
3105
- *
3074
+ * Initialize a new database connection
3075
+ *
3106
3076
  * This is an alias of `arquebus.fire()` and will be removed in the future
3107
- *
3077
+ *
3108
3078
  * @deprecated since version 0.3.0
3109
3079
  * @alias fire
3110
- *
3111
- * @returns
3080
+ *
3081
+ * @returns
3112
3082
  */
3113
3083
  static connection(connection = null) {
3114
3084
  return this.fire(connection);
@@ -3145,11 +3115,12 @@ var arquebus = class arquebus {
3145
3115
  }
3146
3116
  getConnection(name$1 = null) {
3147
3117
  name$1 = name$1 || "default";
3148
- if (this.manager[name$1] === void 0) {
3149
- const queryBuilder = new query_builder_default(this.connections[name$1], arquebus.getConnectorFactory());
3150
- this.manager[name$1] = queryBuilder;
3118
+ const resolvedName = this.connections[name$1] ? name$1 : "default";
3119
+ if (this.manager[resolvedName] === void 0) {
3120
+ const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
3121
+ this.manager[resolvedName] = queryBuilder;
3151
3122
  }
3152
- return this.manager[name$1];
3123
+ return this.manager[resolvedName];
3153
3124
  }
3154
3125
  addConnection(config, name$1 = "default") {
3155
3126
  this.connections[name$1] = {
@@ -3166,13 +3137,13 @@ var arquebus = class arquebus {
3166
3137
  }
3167
3138
  /**
3168
3139
  * Autoload the config file
3169
- *
3170
- * @param addConnection
3140
+ *
3141
+ * @param addConnection
3171
3142
  * @default true
3172
- * If set to `false` we will no attempt add the connection, we
3143
+ * If set to `false` we will no attempt add the connection, we
3173
3144
  * will just go ahead and return the config
3174
- *
3175
- * @returns
3145
+ *
3146
+ * @returns
3176
3147
  */
3177
3148
  static async autoLoad(addConnection = true) {
3178
3149
  let config;
@@ -3189,6 +3160,23 @@ var arquebus = class arquebus {
3189
3160
  if (addConnection) instance.addConnection(config, config.client);
3190
3161
  return config;
3191
3162
  } else throw new Error("arquebus.config.ts found in production without build step");
3163
+ const candidateDirs = [
3164
+ process.cwd(),
3165
+ path.default.join(process.cwd(), "test", "cli"),
3166
+ path.default.join(process.cwd(), "test")
3167
+ ];
3168
+ for (const dir of candidateDirs) {
3169
+ const found = Utils.findUpConfig(dir, "arquebus.config", [
3170
+ "js",
3171
+ "ts",
3172
+ "cjs"
3173
+ ]);
3174
+ if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
3175
+ config = (await import(found)).default;
3176
+ if (addConnection) instance.addConnection(config, config.client);
3177
+ return config;
3178
+ } else throw new Error("arquebus.config.ts found in production without build step");
3179
+ }
3192
3180
  return {};
3193
3181
  }
3194
3182
  beginTransaction(connection = null) {
@@ -5138,9 +5126,9 @@ var Migrator = class {
5138
5126
  }
5139
5127
  /**
5140
5128
  * Drop all tables and re-run all migrations
5141
- *
5142
- * @param paths
5143
- * @param options
5129
+ *
5130
+ * @param paths
5131
+ * @param options
5144
5132
  */
5145
5133
  async fresh(paths, options) {
5146
5134
  /** Initialise connections */
@@ -5243,10 +5231,10 @@ var Migrate = class {
5243
5231
  }
5244
5232
  /**
5245
5233
  * Runs all pending migrations
5246
- *
5247
- * @param config
5248
- * @param options
5249
- * @param destroyAll
5234
+ *
5235
+ * @param config
5236
+ * @param options
5237
+ * @param destroyAll
5250
5238
  */
5251
5239
  async run(config, options = {}, destroyAll = false) {
5252
5240
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5260,10 +5248,10 @@ var Migrate = class {
5260
5248
  }
5261
5249
  /**
5262
5250
  * Rollback the last migration
5263
- *
5264
- * @param config
5265
- * @param options
5266
- * @param destroyAll
5251
+ *
5252
+ * @param config
5253
+ * @param options
5254
+ * @param destroyAll
5267
5255
  */
5268
5256
  async rollback(config, options = {}, destroyAll = false) {
5269
5257
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5277,10 +5265,10 @@ var Migrate = class {
5277
5265
  }
5278
5266
  /**
5279
5267
  * Rollback all database migrations
5280
- *
5281
- * @param config
5282
- * @param options
5283
- * @param destroyAll
5268
+ *
5269
+ * @param config
5270
+ * @param options
5271
+ * @param destroyAll
5284
5272
  */
5285
5273
  async reset(config, options = {}, destroyAll = false) {
5286
5274
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5295,10 +5283,10 @@ var Migrate = class {
5295
5283
  }
5296
5284
  /**
5297
5285
  * Reset and re-run all migrations
5298
- *
5299
- * @param config
5300
- * @param options
5301
- * @param destroyAll
5286
+ *
5287
+ * @param config
5288
+ * @param options
5289
+ * @param destroyAll
5302
5290
  */
5303
5291
  async refresh(config, options = {}, destroyAll = false) {
5304
5292
  await this.reset(config, Object.assign({}, options, { quiet: true }), false);
@@ -5307,10 +5295,10 @@ var Migrate = class {
5307
5295
  }
5308
5296
  /**
5309
5297
  * Drop all tables and re-run all migrations
5310
- *
5311
- * @param config
5312
- * @param options
5313
- * @param destroyAll
5298
+ *
5299
+ * @param config
5300
+ * @param options
5301
+ * @param destroyAll
5314
5302
  */
5315
5303
  async fresh(config, options = {}, destroyAll = false) {
5316
5304
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5320,8 +5308,8 @@ var Migrate = class {
5320
5308
  }
5321
5309
  /**
5322
5310
  * Prepares the database for migration
5323
- *
5324
- * @param migrator
5311
+ *
5312
+ * @param migrator
5325
5313
  */
5326
5314
  async prepareDatabase(migrator) {
5327
5315
  if (!await migrator.repositoryExists()) {
@@ -5333,11 +5321,11 @@ var Migrate = class {
5333
5321
  }
5334
5322
  /**
5335
5323
  * Check the status of available migrations
5336
- *
5337
- * @param config
5338
- * @param options
5339
- * @param destroyAll
5340
- * @returns
5324
+ *
5325
+ * @param config
5326
+ * @param options
5327
+ * @param destroyAll
5328
+ * @returns
5341
5329
  */
5342
5330
  async status(config, options = {}, destroyAll = false) {
5343
5331
  const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
@@ -5364,9 +5352,9 @@ var Migrate = class {
5364
5352
  }
5365
5353
  /**
5366
5354
  * Setup the database connection
5367
- *
5368
- * @param config
5369
- * @returns
5355
+ *
5356
+ * @param config
5357
+ * @returns
5370
5358
  */
5371
5359
  async setupConnection(config) {
5372
5360
  var _config$migrations;
@@ -5396,12 +5384,12 @@ var MigrationCreator = class {
5396
5384
  }
5397
5385
  /**
5398
5386
  * Create a new migration file
5399
- *
5400
- * @param name
5401
- * @param dir
5402
- * @param table
5403
- * @param create
5404
- * @returns
5387
+ *
5388
+ * @param name
5389
+ * @param dir
5390
+ * @param table
5391
+ * @param create
5392
+ * @returns
5405
5393
  */
5406
5394
  async create(name$1, dir, table, create = false) {
5407
5395
  const stub = await this.getStub(table, create);
@@ -5413,9 +5401,9 @@ var MigrationCreator = class {
5413
5401
  }
5414
5402
  /**
5415
5403
  * Publish migrations from third party vendors
5416
- *
5417
- * @param dir
5418
- * @param callback
5404
+ *
5405
+ * @param dir
5406
+ * @param callback
5419
5407
  */
5420
5408
  async publish(dir, callback) {
5421
5409
  const migrationFiles = await (0, node_fs_promises.readdir)(this.customStubPath ?? "");
@@ -5443,7 +5431,7 @@ var MigrationCreator = class {
5443
5431
  return await (0, node_fs_promises.readFile)(stub, "utf-8");
5444
5432
  }
5445
5433
  populateStub(stub, table) {
5446
- if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
5434
+ if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
5447
5435
  return stub;
5448
5436
  }
5449
5437
  getClassName(name$1) {
@@ -5476,7 +5464,7 @@ var MigrationCreator = class {
5476
5464
  //#endregion
5477
5465
  //#region package.json
5478
5466
  var name = "@h3ravel/arquebus";
5479
- var version = "0.5.0";
5467
+ var version = "0.6.0";
5480
5468
  var packageManager = "pnpm@10.14.0";
5481
5469
  var description = "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.";
5482
5470
  var homepage = "https://h3ravel.toneflix.net/arquebus";
@@ -5564,6 +5552,16 @@ var exports$1 = {
5564
5552
  "default": "./dist/inspector/index.cjs"
5565
5553
  }
5566
5554
  },
5555
+ "./seeders": {
5556
+ "import": {
5557
+ "types": "./dist/seeders/index.d.ts",
5558
+ "default": "./dist/seeders/index.js"
5559
+ },
5560
+ "require": {
5561
+ "types": "./dist/seeders/index.d.cts",
5562
+ "default": "./dist/seeders/index.cjs"
5563
+ }
5564
+ },
5567
5565
  "./browser": {
5568
5566
  "import": {
5569
5567
  "types": "./dist/browser/index.d.ts",
@@ -5599,7 +5597,8 @@ var scripts = {
5599
5597
  var husky = { "hooks": { "pre-commit": "lint-staged" } };
5600
5598
  var lint_staged = { "*.{js,json}": ["prettier --write", "git add"] };
5601
5599
  var dependencies = {
5602
- "@h3ravel/shared": "^0.20.1",
5600
+ "@h3ravel/shared": "^0.20.12",
5601
+ "@h3ravel/support": "^0.12.0",
5603
5602
  "chalk": "^5.6.2",
5604
5603
  "collect.js": "^4.36.1",
5605
5604
  "commander": "^14.0.1",
@@ -5613,7 +5612,6 @@ var dependencies = {
5613
5612
  "mysql2": "^3.15.0",
5614
5613
  "pg": "^8.16.3",
5615
5614
  "pluralize": "^8.0.0",
5616
- "prettier": "^3.6.2",
5617
5615
  "radashi": "^12.6.2",
5618
5616
  "resolve-from": "^5.0.0",
5619
5617
  "tedious": "^19.0.0"
@@ -5627,6 +5625,7 @@ var devDependencies = {
5627
5625
  "@vitest/coverage-v8": "^3.2.4",
5628
5626
  "eslint": "^9.36.0",
5629
5627
  "jsdom": "^26.1.0",
5628
+ "prettier": "^3.6.2",
5630
5629
  "sqlite3": "5.1.7",
5631
5630
  "terser": "^5.44.0",
5632
5631
  "ts-node": "^10.9.2",
@@ -5693,7 +5692,12 @@ var Cli = class Cli {
5693
5692
  this.basePath = basePath ?? (process.env.TEST === "true" ? "test/cli" : "");
5694
5693
  }
5695
5694
  terminateNotFound() {
5696
- this.output.error(`ERROR: Arquebus config not found. Run ${chalk.default.italic.black.bgGray("arquebus init")} first.`);
5695
+ const cmd = __h3ravel_shared.Logger.log([["arquebus init", [
5696
+ "italic",
5697
+ "black",
5698
+ "bgGray"
5699
+ ]]], "", false);
5700
+ this.output.error(`ERROR: Arquebus config not found. Run ${cmd} first.`);
5697
5701
  }
5698
5702
  static init() {
5699
5703
  (0, dotenv.config)({ quiet: true });
@@ -5729,8 +5733,8 @@ var Cli = class Cli {
5729
5733
  return this;
5730
5734
  }
5731
5735
  async run() {
5732
- const cliVersion = ["Arquebus CLI version:", chalk.default.green(package_default.version)].join(" ");
5733
- const localVersion = ["Arquebus Local version:", chalk.default.green(this.modulePackage.version || "None")].join(" ");
5736
+ const cliVersion = ["Arquebus CLI version:", __h3ravel_shared.Logger.log(package_default.version, "green", false)].join(" ");
5737
+ const localVersion = ["Arquebus Local version:", __h3ravel_shared.Logger.log(this.modulePackage.version || "None", "green", false)].join(" ");
5734
5738
  commander.program.name("arquebus").version(`${cliVersion}\n${localVersion}`);
5735
5739
  commander.program.command("init").description("Create a fresh Arquebus config.").addArgument(new commander.Argument("[type]", "Type of config to generate.").choices(["js", "ts"]).default("js", "generates a js config")).action(async (type$1) => {
5736
5740
  if (!this.modulePath) this.output.error(["ERROR: No local arquebus install found", " Try running: npm install arquebus --save"]);
@@ -5744,16 +5748,16 @@ var Cli = class Cli {
5744
5748
  this.output.error("ERROR: " + e);
5745
5749
  }
5746
5750
  });
5747
- commander.program.command("migrate:make <name>").description("Create a new migration file.").addOption(new commander.Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("-t, --table [string]", "The table to migrate").option("-c, --create [string]", "The table to be created").option("-p, --path [path]", "The path to the migrations directory.").action(async (name$1, opts) => {
5751
+ commander.program.command("make:migration <name>").description("Create a new migration file.").addOption(new commander.Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("-t, --table [string]", "The table to migrate").option("-c, --create [string]", "The table to be created").option("-p, --path [path]", "The path to the migrations directory.").action(async (name$1, opts) => {
5748
5752
  if (!this.configPath) this.terminateNotFound();
5749
5753
  try {
5750
5754
  var _this$config$migratio3;
5751
5755
  name$1 = (0, radashi.snake)(name$1);
5752
5756
  const migrationPath = path.default.join(this.cwd, opts.path ?? ((_this$config$migratio3 = this.config.migrations) === null || _this$config$migratio3 === void 0 ? void 0 : _this$config$migratio3.path) ?? "./migrations");
5753
5757
  let table = opts.table;
5754
- let create = opts.create || false;
5755
- if (!table && typeof create === "string") {
5756
- table = create;
5758
+ let create = Boolean(opts.create) && opts.create !== "";
5759
+ if (!table && typeof opts.create === "string") {
5760
+ table = opts.create;
5757
5761
  create = true;
5758
5762
  }
5759
5763
  if (!table) {
@@ -5763,7 +5767,7 @@ var Cli = class Cli {
5763
5767
  }
5764
5768
  this.output.info("INFO: Creating Migration");
5765
5769
  const fileName = await new MigrationCreator(void 0, opts.type).create(name$1, migrationPath, table, create);
5766
- this.output.success(`INFO: Migration Created \n ${chalk.default.gray(path.default.basename(fileName))}`, true);
5770
+ this.output.success(`INFO: Migration Created \n ${__h3ravel_shared.Logger.log(path.default.basename(fileName), "gray", false)}`, true);
5767
5771
  } catch (e) {
5768
5772
  this.output.error("ERROR: " + e);
5769
5773
  }
@@ -5780,9 +5784,10 @@ var Cli = class Cli {
5780
5784
  const pkgJson = await import(path.default.join(packagePath, "package.json"));
5781
5785
  if (!packagePath) this.output.error(`ERROR: package ${pkg} not found`);
5782
5786
  const creator = new MigrationCreator(path.default.join(packagePath, pkgJson.migrations ?? "migrations"));
5783
- this.output.info(`INFO: Publishing migrations from ${chalk.default.italic.gray(pkgJson.name + "@" + pkgJson.version)}`);
5787
+ const pkgInf = __h3ravel_shared.Logger.log(path.default.basename(pkgJson.name + "@" + pkgJson.version), ["italic", "gray"], false);
5788
+ this.output.info(`INFO: Publishing migrations from ${pkgInf}`);
5784
5789
  await creator.publish(basePath, (fileName) => {
5785
- __h3ravel_shared.Logger.twoColumnLog(fileName, chalk.default.green("PUBLISHED"));
5790
+ this.output.split("INFO: Migration Published", fileName, "success");
5786
5791
  });
5787
5792
  } catch (e) {
5788
5793
  this.output.error("ERROR: " + e);
@@ -5795,7 +5800,11 @@ var Cli = class Cli {
5795
5800
  if (!this.configPath) this.terminateNotFound();
5796
5801
  const basePath = opts.path ? path.default.join(this.cwd, opts.path) : this.cwd;
5797
5802
  try {
5798
- await new Migrate(basePath).run(this.config, opts, true);
5803
+ const step = typeof opts.step === "string" ? parseInt(opts.step) : opts.step;
5804
+ await new Migrate(basePath).run(this.config, {
5805
+ ...opts,
5806
+ step
5807
+ }, true);
5799
5808
  } catch (e) {
5800
5809
  this.output.error("ERROR: " + e);
5801
5810
  }
@@ -5809,7 +5818,10 @@ var Cli = class Cli {
5809
5818
  try {
5810
5819
  await new Migrate(basePath, void 0, (msg, sts) => {
5811
5820
  if (sts) this.output[sts](msg);
5812
- }).rollback(this.config, opts, true);
5821
+ }).rollback(this.config, {
5822
+ ...opts,
5823
+ step: typeof opts.step === "string" ? parseInt(opts.step) : opts.step
5824
+ }, true);
5813
5825
  } catch (e) {
5814
5826
  this.output.error("ERROR: " + e);
5815
5827
  }
@@ -5867,9 +5879,9 @@ var Cli = class Cli {
5867
5879
  if (sts) this.output[sts](msg);
5868
5880
  }).status(this.config, opts, true);
5869
5881
  if (migrations.length > 0) {
5870
- __h3ravel_shared.Logger.twoColumnLog(chalk.default.gray("Migration name"), chalk.default.gray("Batch / Status"));
5882
+ __h3ravel_shared.Logger.twoColumnLog(__h3ravel_shared.Logger.log("Migration name", "gray", false), __h3ravel_shared.Logger.log("Batch / Status", "gray", false));
5871
5883
  migrations.forEach((migration) => {
5872
- const status = migration.ran ? `[${migration.batch}] ${chalk.default.green("Ran")}` : chalk.default.yellow("Pending");
5884
+ const status = migration.ran ? `[${migration.batch}] ${__h3ravel_shared.Logger.log("Ran", "green", false)}` : __h3ravel_shared.Logger.log("Pending", "yellow", false);
5873
5885
  __h3ravel_shared.Logger.twoColumnLog(migration.name, status);
5874
5886
  });
5875
5887
  } else console.log("No migrations found");
@@ -5878,9 +5890,49 @@ var Cli = class Cli {
5878
5890
  }
5879
5891
  });
5880
5892
  /**
5893
+ * Run database seeders
5894
+ */
5895
+ commander.program.command("db:seed").description("Run database seeders.").option("-p, --path [path]", "The path to the seeders directory.").action(async (opts) => {
5896
+ if (!this.configPath) this.terminateNotFound();
5897
+ const basePath = opts.path ? path.default.join(this.cwd, opts.path) : this.cwd;
5898
+ try {
5899
+ var _this$config$seeders;
5900
+ const { arquebus: arquebus$1 } = await new Migrate(basePath).setupConnection({
5901
+ ...this.config,
5902
+ skipConnection: false
5903
+ });
5904
+ const { SeederRunner } = await Promise.resolve().then(() => require("./seeders-_xJ6VGVS.cjs"));
5905
+ const runner = new SeederRunner(arquebus$1);
5906
+ const seederPath = path.default.join(basePath, ((_this$config$seeders = this.config.seeders) === null || _this$config$seeders === void 0 ? void 0 : _this$config$seeders.path) ?? "./seeders");
5907
+ await runner.setConnection(this.config.client).run([seederPath]);
5908
+ this.output.success("Seeders executed successfully.");
5909
+ } catch (e) {
5910
+ this.output.error("ERROR: " + e);
5911
+ }
5912
+ });
5913
+ /**
5914
+ * Create a new seeder file
5915
+ */
5916
+ commander.program.command("make:seeder <name>").description("Create a new Seeder file.").addOption(new commander.Option("-l, --type [string]", "Type of seeder file to generate.").choices(["js", "ts"]).default("js", "generates a js seeder file")).option("--force", "Force creation if seeder already exists.", false).option("-p, --path [path]", "The path to the seeders directory.").action(async (name$1, opts) => {
5917
+ var _this$config$seeders2;
5918
+ if (!this.configPath) this.terminateNotFound();
5919
+ const seederPath = path.default.join(this.cwd, opts.path ?? ((_this$config$seeders2 = this.config.seeders) === null || _this$config$seeders2 === void 0 ? void 0 : _this$config$seeders2.path) ?? "./seeders", __h3ravel_support.Str.of(name$1).snake("-") + "." + opts.type);
5920
+ try {
5921
+ if (!opts.force && await Utils.fileExists(seederPath)) this.output.error("ERROR: Seeder already exists.");
5922
+ await (0, node_fs_promises.mkdir)(path.default.dirname(seederPath), { recursive: true });
5923
+ const stubPath = path.default.join(this.modulePath, `src/stubs/seeder-${opts.type}.stub`);
5924
+ let stub = await (0, node_fs_promises.readFile)(stubPath, "utf-8");
5925
+ stub = stub.replace(/{{ name }}/g, name$1);
5926
+ await (0, node_fs_promises.writeFile)(seederPath, stub);
5927
+ this.output.split("INFO: Created Seeder", path.default.relative(this.cwd, seederPath));
5928
+ } catch (e) {
5929
+ this.output.error("ERROR: " + e);
5930
+ }
5931
+ });
5932
+ /**
5881
5933
  * Create a new model file
5882
5934
  */
5883
- commander.program.command("model:make <name>").description("Create a new Model file.").addOption(new commander.Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("--force", "Force creation if model already exists.", false).option("-p, --path [path]", "The path to the models directory.").action(async (name$1, opts) => {
5935
+ commander.program.command("make:model <name>").description("Create a new Model file.").addOption(new commander.Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("--force", "Force creation if model already exists.", false).option("-p, --path [path]", "The path to the models directory.").action(async (name$1, opts) => {
5884
5936
  var _this$config$models;
5885
5937
  if (!this.configPath) this.terminateNotFound();
5886
5938
  const modelPath = path.default.join(this.cwd, opts.path ?? ((_this$config$models = this.config.models) === null || _this$config$models === void 0 ? void 0 : _this$config$models.path) ?? "./models", name$1.toLowerCase() + "." + opts.type);