@h3ravel/arquebus 0.5.0 → 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.
- package/README.md +20 -1
- package/bin/index.cjs +196 -144
- package/bin/index.js +177 -94
- package/bin/seeders-8GJzfIIN.js +3 -0
- package/bin/seeders-ByeSoCAQ.cjs +131 -0
- package/bin/seeders-CltigymO.js +79 -0
- package/bin/seeders-_xJ6VGVS.cjs +3 -0
- package/dist/browser/index.cjs +9 -9
- package/dist/browser/index.d.cts +7 -7
- package/dist/browser/index.d.ts +7 -7
- package/dist/browser/index.js +9 -9
- package/dist/index.cjs +252 -121
- package/dist/index.d.cts +40 -8
- package/dist/index.d.ts +40 -8
- package/dist/index.js +245 -119
- package/dist/inspector/index.cjs +105 -33
- package/dist/inspector/index.js +102 -33
- package/dist/migrations/index.cjs +144 -126
- package/dist/migrations/index.d.cts +10 -10
- package/dist/migrations/index.d.ts +10 -10
- package/dist/migrations/index.js +148 -130
- package/dist/migrations/stubs/migration-js.stub +1 -1
- package/dist/migrations/stubs/migration-ts.stub +1 -1
- package/dist/migrations/stubs/migration.create-js.stub +5 -5
- package/dist/migrations/stubs/migration.create-ts.stub +5 -5
- package/dist/migrations/stubs/migration.update-js.stub +2 -2
- package/dist/migrations/stubs/migration.update-ts.stub +3 -3
- package/dist/seeders/index.cjs +141 -0
- package/dist/seeders/index.d.cts +4766 -0
- package/dist/seeders/index.d.ts +4766 -0
- package/dist/seeders/index.js +118 -0
- package/dist/seeders/index.ts +3 -0
- package/dist/seeders/runner.ts +102 -0
- package/dist/seeders/seeder-creator.ts +42 -0
- package/dist/seeders/seeder.ts +10 -0
- package/dist/stubs/seeder-js.stub +13 -0
- package/dist/stubs/seeder-ts.stub +9 -0
- package/package.json +14 -3
- package/types/builder.ts +153 -80
- package/types/container.ts +79 -66
- package/types/generics.ts +75 -37
- package/types/modeling.ts +213 -158
- package/types/query-builder.ts +221 -191
- package/types/query-methods.ts +145 -109
- package/types/utils.ts +64 -56
package/bin/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import "./seeders-CltigymO.js";
|
|
2
3
|
import "node:module";
|
|
3
4
|
import { Argument, Option, program } from "commander";
|
|
4
5
|
import { access } from "fs/promises";
|
|
@@ -16,7 +17,7 @@ import { existsSync } from "fs";
|
|
|
16
17
|
import pluralize from "pluralize";
|
|
17
18
|
import { dirname } from "node:path";
|
|
18
19
|
import { fileURLToPath } from "node:url";
|
|
19
|
-
import
|
|
20
|
+
import { Str } from "@h3ravel/support";
|
|
20
21
|
import { config } from "dotenv";
|
|
21
22
|
|
|
22
23
|
//#region rolldown:runtime
|
|
@@ -36,10 +37,10 @@ const join = path.join;
|
|
|
36
37
|
var Utils = class {
|
|
37
38
|
/**
|
|
38
39
|
* Wraps text with chalk
|
|
39
|
-
*
|
|
40
|
-
* @param txt
|
|
41
|
-
* @param color
|
|
42
|
-
* @returns
|
|
40
|
+
*
|
|
41
|
+
* @param txt
|
|
42
|
+
* @param color
|
|
43
|
+
* @returns
|
|
43
44
|
*/
|
|
44
45
|
static textFormat(txt, color) {
|
|
45
46
|
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
@@ -60,9 +61,9 @@ var Utils = class {
|
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Check if file exists
|
|
63
|
-
*
|
|
64
|
-
* @param path
|
|
65
|
-
* @returns
|
|
64
|
+
*
|
|
65
|
+
* @param path
|
|
66
|
+
* @returns
|
|
66
67
|
*/
|
|
67
68
|
static async fileExists(path$1) {
|
|
68
69
|
try {
|
|
@@ -1488,7 +1489,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
1488
1489
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
1489
1490
|
/**
|
|
1490
1491
|
* Compose function that merges multiple classes and mixins
|
|
1491
|
-
*
|
|
1492
|
+
*
|
|
1492
1493
|
* @example
|
|
1493
1494
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
1494
1495
|
* return class extends Base {
|
|
@@ -1525,10 +1526,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
1525
1526
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
1526
1527
|
* console.log(user.pluginMethod()) // "plugin"
|
|
1527
1528
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
1528
|
-
*
|
|
1529
|
-
* @param Base
|
|
1530
|
-
* @param mixins
|
|
1531
|
-
* @returns
|
|
1529
|
+
*
|
|
1530
|
+
* @param Base
|
|
1531
|
+
* @param mixins
|
|
1532
|
+
* @returns
|
|
1532
1533
|
*/
|
|
1533
1534
|
function compose$1(Base, ...mixins) {
|
|
1534
1535
|
/**
|
|
@@ -1582,10 +1583,10 @@ const getSetterMethod = (attr) => {
|
|
|
1582
1583
|
};
|
|
1583
1584
|
/**
|
|
1584
1585
|
* Tap into a model a collection instance
|
|
1585
|
-
*
|
|
1586
|
-
* @param instance
|
|
1587
|
-
* @param callback
|
|
1588
|
-
* @returns
|
|
1586
|
+
*
|
|
1587
|
+
* @param instance
|
|
1588
|
+
* @param callback
|
|
1589
|
+
* @returns
|
|
1589
1590
|
*/
|
|
1590
1591
|
const tap = (instance, callback) => {
|
|
1591
1592
|
const result = callback(instance);
|
|
@@ -3057,22 +3058,22 @@ var arquebus = class arquebus {
|
|
|
3057
3058
|
return this.instance;
|
|
3058
3059
|
}
|
|
3059
3060
|
/**
|
|
3060
|
-
* Initialize a new database connection
|
|
3061
|
-
*
|
|
3062
|
-
* @returns
|
|
3061
|
+
* Initialize a new database connection
|
|
3062
|
+
*
|
|
3063
|
+
* @returns
|
|
3063
3064
|
*/
|
|
3064
3065
|
static fire(connection = null) {
|
|
3065
3066
|
return this.getInstance().getConnection(connection);
|
|
3066
3067
|
}
|
|
3067
3068
|
/**
|
|
3068
|
-
* Initialize a new database connection
|
|
3069
|
-
*
|
|
3069
|
+
* Initialize a new database connection
|
|
3070
|
+
*
|
|
3070
3071
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
3071
|
-
*
|
|
3072
|
+
*
|
|
3072
3073
|
* @deprecated since version 0.3.0
|
|
3073
3074
|
* @alias fire
|
|
3074
|
-
*
|
|
3075
|
-
* @returns
|
|
3075
|
+
*
|
|
3076
|
+
* @returns
|
|
3076
3077
|
*/
|
|
3077
3078
|
static connection(connection = null) {
|
|
3078
3079
|
return this.fire(connection);
|
|
@@ -3109,11 +3110,12 @@ var arquebus = class arquebus {
|
|
|
3109
3110
|
}
|
|
3110
3111
|
getConnection(name$1 = null) {
|
|
3111
3112
|
name$1 = name$1 || "default";
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
this.
|
|
3113
|
+
const resolvedName = this.connections[name$1] ? name$1 : "default";
|
|
3114
|
+
if (this.manager[resolvedName] === void 0) {
|
|
3115
|
+
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
3116
|
+
this.manager[resolvedName] = queryBuilder;
|
|
3115
3117
|
}
|
|
3116
|
-
return this.manager[
|
|
3118
|
+
return this.manager[resolvedName];
|
|
3117
3119
|
}
|
|
3118
3120
|
addConnection(config$1, name$1 = "default") {
|
|
3119
3121
|
this.connections[name$1] = {
|
|
@@ -3130,13 +3132,13 @@ var arquebus = class arquebus {
|
|
|
3130
3132
|
}
|
|
3131
3133
|
/**
|
|
3132
3134
|
* Autoload the config file
|
|
3133
|
-
*
|
|
3134
|
-
* @param addConnection
|
|
3135
|
+
*
|
|
3136
|
+
* @param addConnection
|
|
3135
3137
|
* @default true
|
|
3136
|
-
* If set to `false` we will no attempt add the connection, we
|
|
3138
|
+
* If set to `false` we will no attempt add the connection, we
|
|
3137
3139
|
* will just go ahead and return the config
|
|
3138
|
-
*
|
|
3139
|
-
* @returns
|
|
3140
|
+
*
|
|
3141
|
+
* @returns
|
|
3140
3142
|
*/
|
|
3141
3143
|
static async autoLoad(addConnection = true) {
|
|
3142
3144
|
let config$1;
|
|
@@ -3153,6 +3155,23 @@ var arquebus = class arquebus {
|
|
|
3153
3155
|
if (addConnection) instance.addConnection(config$1, config$1.client);
|
|
3154
3156
|
return config$1;
|
|
3155
3157
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3158
|
+
const candidateDirs = [
|
|
3159
|
+
process.cwd(),
|
|
3160
|
+
path.join(process.cwd(), "test", "cli"),
|
|
3161
|
+
path.join(process.cwd(), "test")
|
|
3162
|
+
];
|
|
3163
|
+
for (const dir of candidateDirs) {
|
|
3164
|
+
const found = Utils.findUpConfig(dir, "arquebus.config", [
|
|
3165
|
+
"js",
|
|
3166
|
+
"ts",
|
|
3167
|
+
"cjs"
|
|
3168
|
+
]);
|
|
3169
|
+
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
3170
|
+
config$1 = (await import(found)).default;
|
|
3171
|
+
if (addConnection) instance.addConnection(config$1, config$1.client);
|
|
3172
|
+
return config$1;
|
|
3173
|
+
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3174
|
+
}
|
|
3156
3175
|
return {};
|
|
3157
3176
|
}
|
|
3158
3177
|
beginTransaction(connection = null) {
|
|
@@ -5102,9 +5121,9 @@ var Migrator = class {
|
|
|
5102
5121
|
}
|
|
5103
5122
|
/**
|
|
5104
5123
|
* Drop all tables and re-run all migrations
|
|
5105
|
-
*
|
|
5106
|
-
* @param paths
|
|
5107
|
-
* @param options
|
|
5124
|
+
*
|
|
5125
|
+
* @param paths
|
|
5126
|
+
* @param options
|
|
5108
5127
|
*/
|
|
5109
5128
|
async fresh(paths, options) {
|
|
5110
5129
|
/** Initialise connections */
|
|
@@ -5207,10 +5226,10 @@ var Migrate = class {
|
|
|
5207
5226
|
}
|
|
5208
5227
|
/**
|
|
5209
5228
|
* Runs all pending migrations
|
|
5210
|
-
*
|
|
5211
|
-
* @param config
|
|
5212
|
-
* @param options
|
|
5213
|
-
* @param destroyAll
|
|
5229
|
+
*
|
|
5230
|
+
* @param config
|
|
5231
|
+
* @param options
|
|
5232
|
+
* @param destroyAll
|
|
5214
5233
|
*/
|
|
5215
5234
|
async run(config$1, options = {}, destroyAll = false) {
|
|
5216
5235
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5224,10 +5243,10 @@ var Migrate = class {
|
|
|
5224
5243
|
}
|
|
5225
5244
|
/**
|
|
5226
5245
|
* Rollback the last migration
|
|
5227
|
-
*
|
|
5228
|
-
* @param config
|
|
5229
|
-
* @param options
|
|
5230
|
-
* @param destroyAll
|
|
5246
|
+
*
|
|
5247
|
+
* @param config
|
|
5248
|
+
* @param options
|
|
5249
|
+
* @param destroyAll
|
|
5231
5250
|
*/
|
|
5232
5251
|
async rollback(config$1, options = {}, destroyAll = false) {
|
|
5233
5252
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5241,10 +5260,10 @@ var Migrate = class {
|
|
|
5241
5260
|
}
|
|
5242
5261
|
/**
|
|
5243
5262
|
* Rollback all database migrations
|
|
5244
|
-
*
|
|
5245
|
-
* @param config
|
|
5246
|
-
* @param options
|
|
5247
|
-
* @param destroyAll
|
|
5263
|
+
*
|
|
5264
|
+
* @param config
|
|
5265
|
+
* @param options
|
|
5266
|
+
* @param destroyAll
|
|
5248
5267
|
*/
|
|
5249
5268
|
async reset(config$1, options = {}, destroyAll = false) {
|
|
5250
5269
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5259,10 +5278,10 @@ var Migrate = class {
|
|
|
5259
5278
|
}
|
|
5260
5279
|
/**
|
|
5261
5280
|
* Reset and re-run all migrations
|
|
5262
|
-
*
|
|
5263
|
-
* @param config
|
|
5264
|
-
* @param options
|
|
5265
|
-
* @param destroyAll
|
|
5281
|
+
*
|
|
5282
|
+
* @param config
|
|
5283
|
+
* @param options
|
|
5284
|
+
* @param destroyAll
|
|
5266
5285
|
*/
|
|
5267
5286
|
async refresh(config$1, options = {}, destroyAll = false) {
|
|
5268
5287
|
await this.reset(config$1, Object.assign({}, options, { quiet: true }), false);
|
|
@@ -5271,10 +5290,10 @@ var Migrate = class {
|
|
|
5271
5290
|
}
|
|
5272
5291
|
/**
|
|
5273
5292
|
* Drop all tables and re-run all migrations
|
|
5274
|
-
*
|
|
5275
|
-
* @param config
|
|
5276
|
-
* @param options
|
|
5277
|
-
* @param destroyAll
|
|
5293
|
+
*
|
|
5294
|
+
* @param config
|
|
5295
|
+
* @param options
|
|
5296
|
+
* @param destroyAll
|
|
5278
5297
|
*/
|
|
5279
5298
|
async fresh(config$1, options = {}, destroyAll = false) {
|
|
5280
5299
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5284,8 +5303,8 @@ var Migrate = class {
|
|
|
5284
5303
|
}
|
|
5285
5304
|
/**
|
|
5286
5305
|
* Prepares the database for migration
|
|
5287
|
-
*
|
|
5288
|
-
* @param migrator
|
|
5306
|
+
*
|
|
5307
|
+
* @param migrator
|
|
5289
5308
|
*/
|
|
5290
5309
|
async prepareDatabase(migrator) {
|
|
5291
5310
|
if (!await migrator.repositoryExists()) {
|
|
@@ -5297,11 +5316,11 @@ var Migrate = class {
|
|
|
5297
5316
|
}
|
|
5298
5317
|
/**
|
|
5299
5318
|
* Check the status of available migrations
|
|
5300
|
-
*
|
|
5301
|
-
* @param config
|
|
5302
|
-
* @param options
|
|
5303
|
-
* @param destroyAll
|
|
5304
|
-
* @returns
|
|
5319
|
+
*
|
|
5320
|
+
* @param config
|
|
5321
|
+
* @param options
|
|
5322
|
+
* @param destroyAll
|
|
5323
|
+
* @returns
|
|
5305
5324
|
*/
|
|
5306
5325
|
async status(config$1, options = {}, destroyAll = false) {
|
|
5307
5326
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5328,9 +5347,9 @@ var Migrate = class {
|
|
|
5328
5347
|
}
|
|
5329
5348
|
/**
|
|
5330
5349
|
* Setup the database connection
|
|
5331
|
-
*
|
|
5332
|
-
* @param config
|
|
5333
|
-
* @returns
|
|
5350
|
+
*
|
|
5351
|
+
* @param config
|
|
5352
|
+
* @returns
|
|
5334
5353
|
*/
|
|
5335
5354
|
async setupConnection(config$1) {
|
|
5336
5355
|
var _config$migrations;
|
|
@@ -5360,12 +5379,12 @@ var MigrationCreator = class {
|
|
|
5360
5379
|
}
|
|
5361
5380
|
/**
|
|
5362
5381
|
* Create a new migration file
|
|
5363
|
-
*
|
|
5364
|
-
* @param name
|
|
5365
|
-
* @param dir
|
|
5366
|
-
* @param table
|
|
5367
|
-
* @param create
|
|
5368
|
-
* @returns
|
|
5382
|
+
*
|
|
5383
|
+
* @param name
|
|
5384
|
+
* @param dir
|
|
5385
|
+
* @param table
|
|
5386
|
+
* @param create
|
|
5387
|
+
* @returns
|
|
5369
5388
|
*/
|
|
5370
5389
|
async create(name$1, dir, table, create = false) {
|
|
5371
5390
|
const stub = await this.getStub(table, create);
|
|
@@ -5377,9 +5396,9 @@ var MigrationCreator = class {
|
|
|
5377
5396
|
}
|
|
5378
5397
|
/**
|
|
5379
5398
|
* Publish migrations from third party vendors
|
|
5380
|
-
*
|
|
5381
|
-
* @param dir
|
|
5382
|
-
* @param callback
|
|
5399
|
+
*
|
|
5400
|
+
* @param dir
|
|
5401
|
+
* @param callback
|
|
5383
5402
|
*/
|
|
5384
5403
|
async publish(dir, callback) {
|
|
5385
5404
|
const migrationFiles = await readdir(this.customStubPath ?? "");
|
|
@@ -5407,7 +5426,7 @@ var MigrationCreator = class {
|
|
|
5407
5426
|
return await readFile(stub, "utf-8");
|
|
5408
5427
|
}
|
|
5409
5428
|
populateStub(stub, table) {
|
|
5410
|
-
if (table
|
|
5429
|
+
if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
5411
5430
|
return stub;
|
|
5412
5431
|
}
|
|
5413
5432
|
getClassName(name$1) {
|
|
@@ -5528,6 +5547,16 @@ var exports = {
|
|
|
5528
5547
|
"default": "./dist/inspector/index.cjs"
|
|
5529
5548
|
}
|
|
5530
5549
|
},
|
|
5550
|
+
"./seeders": {
|
|
5551
|
+
"import": {
|
|
5552
|
+
"types": "./dist/seeders/index.d.ts",
|
|
5553
|
+
"default": "./dist/seeders/index.js"
|
|
5554
|
+
},
|
|
5555
|
+
"require": {
|
|
5556
|
+
"types": "./dist/seeders/index.d.cts",
|
|
5557
|
+
"default": "./dist/seeders/index.cjs"
|
|
5558
|
+
}
|
|
5559
|
+
},
|
|
5531
5560
|
"./browser": {
|
|
5532
5561
|
"import": {
|
|
5533
5562
|
"types": "./dist/browser/index.d.ts",
|
|
@@ -5563,7 +5592,8 @@ var scripts = {
|
|
|
5563
5592
|
var husky = { "hooks": { "pre-commit": "lint-staged" } };
|
|
5564
5593
|
var lint_staged = { "*.{js,json}": ["prettier --write", "git add"] };
|
|
5565
5594
|
var dependencies = {
|
|
5566
|
-
"@h3ravel/shared": "^0.20.
|
|
5595
|
+
"@h3ravel/shared": "^0.20.12",
|
|
5596
|
+
"@h3ravel/support": "^0.12.0",
|
|
5567
5597
|
"chalk": "^5.6.2",
|
|
5568
5598
|
"collect.js": "^4.36.1",
|
|
5569
5599
|
"commander": "^14.0.1",
|
|
@@ -5577,7 +5607,6 @@ var dependencies = {
|
|
|
5577
5607
|
"mysql2": "^3.15.0",
|
|
5578
5608
|
"pg": "^8.16.3",
|
|
5579
5609
|
"pluralize": "^8.0.0",
|
|
5580
|
-
"prettier": "^3.6.2",
|
|
5581
5610
|
"radashi": "^12.6.2",
|
|
5582
5611
|
"resolve-from": "^5.0.0",
|
|
5583
5612
|
"tedious": "^19.0.0"
|
|
@@ -5591,6 +5620,7 @@ var devDependencies = {
|
|
|
5591
5620
|
"@vitest/coverage-v8": "^3.2.4",
|
|
5592
5621
|
"eslint": "^9.36.0",
|
|
5593
5622
|
"jsdom": "^26.1.0",
|
|
5623
|
+
"prettier": "^3.6.2",
|
|
5594
5624
|
"sqlite3": "5.1.7",
|
|
5595
5625
|
"terser": "^5.44.0",
|
|
5596
5626
|
"ts-node": "^10.9.2",
|
|
@@ -5657,7 +5687,12 @@ var Cli = class Cli {
|
|
|
5657
5687
|
this.basePath = basePath ?? (process.env.TEST === "true" ? "test/cli" : "");
|
|
5658
5688
|
}
|
|
5659
5689
|
terminateNotFound() {
|
|
5660
|
-
|
|
5690
|
+
const cmd = Logger.log([["arquebus init", [
|
|
5691
|
+
"italic",
|
|
5692
|
+
"black",
|
|
5693
|
+
"bgGray"
|
|
5694
|
+
]]], "", false);
|
|
5695
|
+
this.output.error(`ERROR: Arquebus config not found. Run ${cmd} first.`);
|
|
5661
5696
|
}
|
|
5662
5697
|
static init() {
|
|
5663
5698
|
config({ quiet: true });
|
|
@@ -5693,8 +5728,8 @@ var Cli = class Cli {
|
|
|
5693
5728
|
return this;
|
|
5694
5729
|
}
|
|
5695
5730
|
async run() {
|
|
5696
|
-
const cliVersion = ["Arquebus CLI version:",
|
|
5697
|
-
const localVersion = ["Arquebus Local version:",
|
|
5731
|
+
const cliVersion = ["Arquebus CLI version:", Logger.log(package_default.version, "green", false)].join(" ");
|
|
5732
|
+
const localVersion = ["Arquebus Local version:", Logger.log(this.modulePackage.version || "None", "green", false)].join(" ");
|
|
5698
5733
|
program.name("arquebus").version(`${cliVersion}\n${localVersion}`);
|
|
5699
5734
|
program.command("init").description("Create a fresh Arquebus config.").addArgument(new Argument("[type]", "Type of config to generate.").choices(["js", "ts"]).default("js", "generates a js config")).action(async (type$1) => {
|
|
5700
5735
|
if (!this.modulePath) this.output.error(["ERROR: No local arquebus install found", " Try running: npm install arquebus --save"]);
|
|
@@ -5708,16 +5743,16 @@ var Cli = class Cli {
|
|
|
5708
5743
|
this.output.error("ERROR: " + e);
|
|
5709
5744
|
}
|
|
5710
5745
|
});
|
|
5711
|
-
program.command("
|
|
5746
|
+
program.command("make:migration <name>").description("Create a new migration file.").addOption(new 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) => {
|
|
5712
5747
|
if (!this.configPath) this.terminateNotFound();
|
|
5713
5748
|
try {
|
|
5714
5749
|
var _this$config$migratio3;
|
|
5715
5750
|
name$1 = snake(name$1);
|
|
5716
5751
|
const migrationPath = path.join(this.cwd, opts.path ?? ((_this$config$migratio3 = this.config.migrations) === null || _this$config$migratio3 === void 0 ? void 0 : _this$config$migratio3.path) ?? "./migrations");
|
|
5717
5752
|
let table = opts.table;
|
|
5718
|
-
let create = opts.create
|
|
5719
|
-
if (!table && typeof create === "string") {
|
|
5720
|
-
table = create;
|
|
5753
|
+
let create = Boolean(opts.create) && opts.create !== "";
|
|
5754
|
+
if (!table && typeof opts.create === "string") {
|
|
5755
|
+
table = opts.create;
|
|
5721
5756
|
create = true;
|
|
5722
5757
|
}
|
|
5723
5758
|
if (!table) {
|
|
@@ -5727,7 +5762,7 @@ var Cli = class Cli {
|
|
|
5727
5762
|
}
|
|
5728
5763
|
this.output.info("INFO: Creating Migration");
|
|
5729
5764
|
const fileName = await new MigrationCreator(void 0, opts.type).create(name$1, migrationPath, table, create);
|
|
5730
|
-
this.output.success(`INFO: Migration Created \n ${
|
|
5765
|
+
this.output.success(`INFO: Migration Created \n ${Logger.log(path.basename(fileName), "gray", false)}`, true);
|
|
5731
5766
|
} catch (e) {
|
|
5732
5767
|
this.output.error("ERROR: " + e);
|
|
5733
5768
|
}
|
|
@@ -5744,9 +5779,10 @@ var Cli = class Cli {
|
|
|
5744
5779
|
const pkgJson = await import(path.join(packagePath, "package.json"));
|
|
5745
5780
|
if (!packagePath) this.output.error(`ERROR: package ${pkg} not found`);
|
|
5746
5781
|
const creator = new MigrationCreator(path.join(packagePath, pkgJson.migrations ?? "migrations"));
|
|
5747
|
-
|
|
5782
|
+
const pkgInf = Logger.log(path.basename(pkgJson.name + "@" + pkgJson.version), ["italic", "gray"], false);
|
|
5783
|
+
this.output.info(`INFO: Publishing migrations from ${pkgInf}`);
|
|
5748
5784
|
await creator.publish(basePath, (fileName) => {
|
|
5749
|
-
|
|
5785
|
+
this.output.split("INFO: Migration Published", fileName, "success");
|
|
5750
5786
|
});
|
|
5751
5787
|
} catch (e) {
|
|
5752
5788
|
this.output.error("ERROR: " + e);
|
|
@@ -5759,7 +5795,11 @@ var Cli = class Cli {
|
|
|
5759
5795
|
if (!this.configPath) this.terminateNotFound();
|
|
5760
5796
|
const basePath = opts.path ? path.join(this.cwd, opts.path) : this.cwd;
|
|
5761
5797
|
try {
|
|
5762
|
-
|
|
5798
|
+
const step = typeof opts.step === "string" ? parseInt(opts.step) : opts.step;
|
|
5799
|
+
await new Migrate(basePath).run(this.config, {
|
|
5800
|
+
...opts,
|
|
5801
|
+
step
|
|
5802
|
+
}, true);
|
|
5763
5803
|
} catch (e) {
|
|
5764
5804
|
this.output.error("ERROR: " + e);
|
|
5765
5805
|
}
|
|
@@ -5773,7 +5813,10 @@ var Cli = class Cli {
|
|
|
5773
5813
|
try {
|
|
5774
5814
|
await new Migrate(basePath, void 0, (msg, sts) => {
|
|
5775
5815
|
if (sts) this.output[sts](msg);
|
|
5776
|
-
}).rollback(this.config,
|
|
5816
|
+
}).rollback(this.config, {
|
|
5817
|
+
...opts,
|
|
5818
|
+
step: typeof opts.step === "string" ? parseInt(opts.step) : opts.step
|
|
5819
|
+
}, true);
|
|
5777
5820
|
} catch (e) {
|
|
5778
5821
|
this.output.error("ERROR: " + e);
|
|
5779
5822
|
}
|
|
@@ -5831,9 +5874,9 @@ var Cli = class Cli {
|
|
|
5831
5874
|
if (sts) this.output[sts](msg);
|
|
5832
5875
|
}).status(this.config, opts, true);
|
|
5833
5876
|
if (migrations.length > 0) {
|
|
5834
|
-
Logger.twoColumnLog(
|
|
5877
|
+
Logger.twoColumnLog(Logger.log("Migration name", "gray", false), Logger.log("Batch / Status", "gray", false));
|
|
5835
5878
|
migrations.forEach((migration) => {
|
|
5836
|
-
const status = migration.ran ? `[${migration.batch}] ${
|
|
5879
|
+
const status = migration.ran ? `[${migration.batch}] ${Logger.log("Ran", "green", false)}` : Logger.log("Pending", "yellow", false);
|
|
5837
5880
|
Logger.twoColumnLog(migration.name, status);
|
|
5838
5881
|
});
|
|
5839
5882
|
} else console.log("No migrations found");
|
|
@@ -5842,9 +5885,49 @@ var Cli = class Cli {
|
|
|
5842
5885
|
}
|
|
5843
5886
|
});
|
|
5844
5887
|
/**
|
|
5888
|
+
* Run database seeders
|
|
5889
|
+
*/
|
|
5890
|
+
program.command("db:seed").description("Run database seeders.").option("-p, --path [path]", "The path to the seeders directory.").action(async (opts) => {
|
|
5891
|
+
if (!this.configPath) this.terminateNotFound();
|
|
5892
|
+
const basePath = opts.path ? path.join(this.cwd, opts.path) : this.cwd;
|
|
5893
|
+
try {
|
|
5894
|
+
var _this$config$seeders;
|
|
5895
|
+
const { arquebus: arquebus$1 } = await new Migrate(basePath).setupConnection({
|
|
5896
|
+
...this.config,
|
|
5897
|
+
skipConnection: false
|
|
5898
|
+
});
|
|
5899
|
+
const { SeederRunner } = await import("./seeders-8GJzfIIN.js");
|
|
5900
|
+
const runner = new SeederRunner(arquebus$1);
|
|
5901
|
+
const seederPath = path.join(basePath, ((_this$config$seeders = this.config.seeders) === null || _this$config$seeders === void 0 ? void 0 : _this$config$seeders.path) ?? "./seeders");
|
|
5902
|
+
await runner.setConnection(this.config.client).run([seederPath]);
|
|
5903
|
+
this.output.success("Seeders executed successfully.");
|
|
5904
|
+
} catch (e) {
|
|
5905
|
+
this.output.error("ERROR: " + e);
|
|
5906
|
+
}
|
|
5907
|
+
});
|
|
5908
|
+
/**
|
|
5909
|
+
* Create a new seeder file
|
|
5910
|
+
*/
|
|
5911
|
+
program.command("make:seeder <name>").description("Create a new Seeder file.").addOption(new 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) => {
|
|
5912
|
+
var _this$config$seeders2;
|
|
5913
|
+
if (!this.configPath) this.terminateNotFound();
|
|
5914
|
+
const seederPath = path.join(this.cwd, opts.path ?? ((_this$config$seeders2 = this.config.seeders) === null || _this$config$seeders2 === void 0 ? void 0 : _this$config$seeders2.path) ?? "./seeders", Str.of(name$1).snake("-") + "." + opts.type);
|
|
5915
|
+
try {
|
|
5916
|
+
if (!opts.force && await Utils.fileExists(seederPath)) this.output.error("ERROR: Seeder already exists.");
|
|
5917
|
+
await mkdir(path.dirname(seederPath), { recursive: true });
|
|
5918
|
+
const stubPath = path.join(this.modulePath, `src/stubs/seeder-${opts.type}.stub`);
|
|
5919
|
+
let stub = await readFile(stubPath, "utf-8");
|
|
5920
|
+
stub = stub.replace(/{{ name }}/g, name$1);
|
|
5921
|
+
await writeFile(seederPath, stub);
|
|
5922
|
+
this.output.split("INFO: Created Seeder", path.relative(this.cwd, seederPath));
|
|
5923
|
+
} catch (e) {
|
|
5924
|
+
this.output.error("ERROR: " + e);
|
|
5925
|
+
}
|
|
5926
|
+
});
|
|
5927
|
+
/**
|
|
5845
5928
|
* Create a new model file
|
|
5846
5929
|
*/
|
|
5847
|
-
program.command("model
|
|
5930
|
+
program.command("make:model <name>").description("Create a new Model file.").addOption(new 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) => {
|
|
5848
5931
|
var _this$config$models;
|
|
5849
5932
|
if (!this.configPath) this.terminateNotFound();
|
|
5850
5933
|
const modelPath = path.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);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (all) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
18
|
+
key = keys[i];
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
20
|
+
get: ((k) => from[k]).bind(null, key),
|
|
21
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
27
|
+
value: mod,
|
|
28
|
+
enumerable: true
|
|
29
|
+
}) : target, mod));
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
let path = require("path");
|
|
33
|
+
path = __toESM(path);
|
|
34
|
+
let node_fs_promises = require("node:fs/promises");
|
|
35
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
36
|
+
let node_path = require("node:path");
|
|
37
|
+
node_path = __toESM(node_path);
|
|
38
|
+
let node_url = require("node:url");
|
|
39
|
+
node_url = __toESM(node_url);
|
|
40
|
+
|
|
41
|
+
//#region src/seeders/runner.ts
|
|
42
|
+
async function glob(folderPath) {
|
|
43
|
+
const { default: escalade } = await import("escalade");
|
|
44
|
+
const entries = [];
|
|
45
|
+
await escalade(folderPath, async (dir, names) => {
|
|
46
|
+
await Promise.all(names.map(async (name) => {
|
|
47
|
+
const p = path.default.join(dir, name);
|
|
48
|
+
try {
|
|
49
|
+
await (0, node_fs_promises.access)(p);
|
|
50
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
51
|
+
} catch {}
|
|
52
|
+
}));
|
|
53
|
+
return "";
|
|
54
|
+
});
|
|
55
|
+
return entries;
|
|
56
|
+
}
|
|
57
|
+
var SeederRunner = class {
|
|
58
|
+
resolver;
|
|
59
|
+
connection;
|
|
60
|
+
paths = [];
|
|
61
|
+
constructor(resolver) {
|
|
62
|
+
this.resolver = resolver;
|
|
63
|
+
}
|
|
64
|
+
path(p) {
|
|
65
|
+
this.paths = Array.from(new Set([...this.paths, p]));
|
|
66
|
+
}
|
|
67
|
+
getPaths() {
|
|
68
|
+
return this.paths;
|
|
69
|
+
}
|
|
70
|
+
resolveConnection(connection) {
|
|
71
|
+
var _getInstance, _ref, _instance$connections;
|
|
72
|
+
const name = connection || this.connection || "default";
|
|
73
|
+
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
74
|
+
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
75
|
+
/** noop */
|
|
76
|
+
});
|
|
77
|
+
return this.resolver.fire(name);
|
|
78
|
+
}
|
|
79
|
+
setConnection(connection) {
|
|
80
|
+
this.connection = connection;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
async getSeederFiles(paths) {
|
|
84
|
+
const files = [];
|
|
85
|
+
for (const p of paths) {
|
|
86
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
87
|
+
files.push(p);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
files.push(...await glob(p));
|
|
91
|
+
}
|
|
92
|
+
return files;
|
|
93
|
+
}
|
|
94
|
+
async resolvePath(filePath) {
|
|
95
|
+
try {
|
|
96
|
+
const mod = await import(filePath);
|
|
97
|
+
return new (mod.default ?? mod.Seeder)();
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async run(paths, connection) {
|
|
103
|
+
const files = await this.getSeederFiles(paths);
|
|
104
|
+
const conn = this.resolveConnection(connection);
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
const seeder = await this.resolvePath(file);
|
|
107
|
+
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var runner_default = SeederRunner;
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
Object.defineProperty(exports, '__export', {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function () {
|
|
117
|
+
return __export;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(exports, '__toESM', {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return __toESM;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(exports, 'runner_default', {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: function () {
|
|
129
|
+
return runner_default;
|
|
130
|
+
}
|
|
131
|
+
});
|