@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.
- package/README.md +20 -1
- package/bin/index.cjs +225 -171
- package/bin/index.js +208 -122
- 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 +3655 -183
- package/dist/browser/index.d.ts +3655 -183
- package/dist/browser/index.js +9 -9
- package/dist/index.cjs +270 -135
- package/dist/index.d.cts +3797 -294
- package/dist/index.d.ts +3797 -294
- package/dist/index.js +263 -133
- package/dist/inspector/index.cjs +122 -46
- package/dist/inspector/index.js +119 -46
- package/dist/migrations/index.cjs +171 -151
- package/dist/migrations/index.d.cts +3510 -27
- package/dist/migrations/index.d.ts +3510 -27
- package/dist/migrations/index.js +177 -150
- 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 +15 -4
- package/types/builder.ts +158 -80
- package/types/container.ts +79 -66
- package/types/generics.ts +75 -36
- package/types/modeling.ts +213 -158
- package/types/query-builder.ts +223 -186
- package/types/query-methods.ts +160 -104
- package/types/utils.ts +64 -55
package/bin/index.cjs
CHANGED
|
@@ -1,83 +1,51 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
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);
|
|
61
|
-
let node_fs = require("node:fs");
|
|
62
|
-
node_fs = __toESM(node_fs);
|
|
30
|
+
pluralize = require_seeders.__toESM(pluralize);
|
|
63
31
|
let node_path = require("node:path");
|
|
64
|
-
node_path = __toESM(node_path);
|
|
32
|
+
node_path = require_seeders.__toESM(node_path);
|
|
65
33
|
let node_url = require("node:url");
|
|
66
|
-
node_url = __toESM(node_url);
|
|
67
|
-
let
|
|
68
|
-
|
|
34
|
+
node_url = require_seeders.__toESM(node_url);
|
|
35
|
+
let __h3ravel_support = require("@h3ravel/support");
|
|
36
|
+
__h3ravel_support = require_seeders.__toESM(__h3ravel_support);
|
|
69
37
|
let dotenv = require("dotenv");
|
|
70
|
-
dotenv = __toESM(dotenv);
|
|
38
|
+
dotenv = require_seeders.__toESM(dotenv);
|
|
71
39
|
|
|
72
40
|
//#region src/cli/utils.ts
|
|
73
41
|
const join = path.default.join;
|
|
74
42
|
var Utils = class {
|
|
75
43
|
/**
|
|
76
44
|
* Wraps text with chalk
|
|
77
|
-
*
|
|
78
|
-
* @param txt
|
|
79
|
-
* @param color
|
|
80
|
-
* @returns
|
|
45
|
+
*
|
|
46
|
+
* @param txt
|
|
47
|
+
* @param color
|
|
48
|
+
* @returns
|
|
81
49
|
*/
|
|
82
50
|
static textFormat(txt, color) {
|
|
83
51
|
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
@@ -98,9 +66,9 @@ var Utils = class {
|
|
|
98
66
|
}
|
|
99
67
|
/**
|
|
100
68
|
* Check if file exists
|
|
101
|
-
*
|
|
102
|
-
* @param path
|
|
103
|
-
* @returns
|
|
69
|
+
*
|
|
70
|
+
* @param path
|
|
71
|
+
* @returns
|
|
104
72
|
*/
|
|
105
73
|
static async fileExists(path$6) {
|
|
106
74
|
try {
|
|
@@ -1523,10 +1491,10 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
1523
1491
|
|
|
1524
1492
|
//#endregion
|
|
1525
1493
|
//#region src/mixin.ts
|
|
1526
|
-
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
1494
|
+
var mixin_exports = /* @__PURE__ */ require_seeders.__export({ compose: () => compose$1 });
|
|
1527
1495
|
/**
|
|
1528
1496
|
* Compose function that merges multiple classes and mixins
|
|
1529
|
-
*
|
|
1497
|
+
*
|
|
1530
1498
|
* @example
|
|
1531
1499
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
1532
1500
|
* return class extends Base {
|
|
@@ -1563,10 +1531,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
1563
1531
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
1564
1532
|
* console.log(user.pluginMethod()) // "plugin"
|
|
1565
1533
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
1566
|
-
*
|
|
1567
|
-
* @param Base
|
|
1568
|
-
* @param mixins
|
|
1569
|
-
* @returns
|
|
1534
|
+
*
|
|
1535
|
+
* @param Base
|
|
1536
|
+
* @param mixins
|
|
1537
|
+
* @returns
|
|
1570
1538
|
*/
|
|
1571
1539
|
function compose$1(Base, ...mixins) {
|
|
1572
1540
|
/**
|
|
@@ -1620,10 +1588,10 @@ const getSetterMethod = (attr) => {
|
|
|
1620
1588
|
};
|
|
1621
1589
|
/**
|
|
1622
1590
|
* Tap into a model a collection instance
|
|
1623
|
-
*
|
|
1624
|
-
* @param instance
|
|
1625
|
-
* @param callback
|
|
1626
|
-
* @returns
|
|
1591
|
+
*
|
|
1592
|
+
* @param instance
|
|
1593
|
+
* @param callback
|
|
1594
|
+
* @returns
|
|
1627
1595
|
*/
|
|
1628
1596
|
const tap = (instance, callback) => {
|
|
1629
1597
|
const result = callback(instance);
|
|
@@ -2459,8 +2427,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
2459
2427
|
const results = await this.take(1).get(columns);
|
|
2460
2428
|
return results.count() > 0 ? results.first() : null;
|
|
2461
2429
|
}
|
|
2462
|
-
async firstOrFail(columns
|
|
2463
|
-
const model = await this.first(columns);
|
|
2430
|
+
async firstOrFail(...columns) {
|
|
2431
|
+
const model = await this.first(...columns);
|
|
2464
2432
|
if (model) return model;
|
|
2465
2433
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2466
2434
|
}
|
|
@@ -2499,7 +2467,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
2499
2467
|
}
|
|
2500
2468
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
2501
2469
|
this.query.addSelect(this.shouldSelect(columns));
|
|
2502
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
2470
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
2503
2471
|
}
|
|
2504
2472
|
shouldSelect(columns = ["*"]) {
|
|
2505
2473
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -2777,9 +2745,6 @@ const UniqueIds = (Model$1) => {
|
|
|
2777
2745
|
uniqueIds() {
|
|
2778
2746
|
return [];
|
|
2779
2747
|
}
|
|
2780
|
-
newUniqueId() {
|
|
2781
|
-
return null;
|
|
2782
|
-
}
|
|
2783
2748
|
setUniqueIds() {
|
|
2784
2749
|
const uniqueIds = this.uniqueIds();
|
|
2785
2750
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -2801,6 +2766,7 @@ var Paginator = class {
|
|
|
2801
2766
|
options = {};
|
|
2802
2767
|
static setFormatter(formatter) {
|
|
2803
2768
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
2769
|
+
if (!formatter) return;
|
|
2804
2770
|
this.formatter = formatter;
|
|
2805
2771
|
}
|
|
2806
2772
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -2889,8 +2855,10 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2889
2855
|
asProxy() {
|
|
2890
2856
|
return new Proxy(this, {
|
|
2891
2857
|
get: function(target, prop) {
|
|
2858
|
+
var _target$connector$cli;
|
|
2892
2859
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2893
2860
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
2861
|
+
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";
|
|
2894
2862
|
if ([
|
|
2895
2863
|
"select",
|
|
2896
2864
|
"from",
|
|
@@ -2953,7 +2921,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2953
2921
|
"clearWhere",
|
|
2954
2922
|
"clearHaving",
|
|
2955
2923
|
"clearGroup"
|
|
2956
|
-
].includes(prop)) return (...args) => {
|
|
2924
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2957
2925
|
target.connector[prop](...args);
|
|
2958
2926
|
return target.asProxy();
|
|
2959
2927
|
};
|
|
@@ -3010,7 +2978,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
3010
2978
|
} while (countResults === count);
|
|
3011
2979
|
return true;
|
|
3012
2980
|
}
|
|
3013
|
-
async paginate(page = 1, perPage = 15) {
|
|
2981
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
3014
2982
|
const total = await this.clone().clearOrder().count("*");
|
|
3015
2983
|
let results;
|
|
3016
2984
|
if (total > 0) {
|
|
@@ -3095,22 +3063,22 @@ var arquebus = class arquebus {
|
|
|
3095
3063
|
return this.instance;
|
|
3096
3064
|
}
|
|
3097
3065
|
/**
|
|
3098
|
-
* Initialize a new database connection
|
|
3099
|
-
*
|
|
3100
|
-
* @returns
|
|
3066
|
+
* Initialize a new database connection
|
|
3067
|
+
*
|
|
3068
|
+
* @returns
|
|
3101
3069
|
*/
|
|
3102
3070
|
static fire(connection = null) {
|
|
3103
3071
|
return this.getInstance().getConnection(connection);
|
|
3104
3072
|
}
|
|
3105
3073
|
/**
|
|
3106
|
-
* Initialize a new database connection
|
|
3107
|
-
*
|
|
3074
|
+
* Initialize a new database connection
|
|
3075
|
+
*
|
|
3108
3076
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
3109
|
-
*
|
|
3077
|
+
*
|
|
3110
3078
|
* @deprecated since version 0.3.0
|
|
3111
3079
|
* @alias fire
|
|
3112
|
-
*
|
|
3113
|
-
* @returns
|
|
3080
|
+
*
|
|
3081
|
+
* @returns
|
|
3114
3082
|
*/
|
|
3115
3083
|
static connection(connection = null) {
|
|
3116
3084
|
return this.fire(connection);
|
|
@@ -3147,11 +3115,12 @@ var arquebus = class arquebus {
|
|
|
3147
3115
|
}
|
|
3148
3116
|
getConnection(name$1 = null) {
|
|
3149
3117
|
name$1 = name$1 || "default";
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
this.
|
|
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;
|
|
3153
3122
|
}
|
|
3154
|
-
return this.manager[
|
|
3123
|
+
return this.manager[resolvedName];
|
|
3155
3124
|
}
|
|
3156
3125
|
addConnection(config, name$1 = "default") {
|
|
3157
3126
|
this.connections[name$1] = {
|
|
@@ -3168,13 +3137,13 @@ var arquebus = class arquebus {
|
|
|
3168
3137
|
}
|
|
3169
3138
|
/**
|
|
3170
3139
|
* Autoload the config file
|
|
3171
|
-
*
|
|
3172
|
-
* @param addConnection
|
|
3140
|
+
*
|
|
3141
|
+
* @param addConnection
|
|
3173
3142
|
* @default true
|
|
3174
|
-
* 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
|
|
3175
3144
|
* will just go ahead and return the config
|
|
3176
|
-
*
|
|
3177
|
-
* @returns
|
|
3145
|
+
*
|
|
3146
|
+
* @returns
|
|
3178
3147
|
*/
|
|
3179
3148
|
static async autoLoad(addConnection = true) {
|
|
3180
3149
|
let config;
|
|
@@ -3191,6 +3160,23 @@ var arquebus = class arquebus {
|
|
|
3191
3160
|
if (addConnection) instance.addConnection(config, config.client);
|
|
3192
3161
|
return config;
|
|
3193
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
|
+
}
|
|
3194
3180
|
return {};
|
|
3195
3181
|
}
|
|
3196
3182
|
beginTransaction(connection = null) {
|
|
@@ -3249,14 +3235,15 @@ var arquebus_default = arquebus;
|
|
|
3249
3235
|
|
|
3250
3236
|
//#endregion
|
|
3251
3237
|
//#region src/model.ts
|
|
3252
|
-
const
|
|
3238
|
+
const ModelClass = class {};
|
|
3239
|
+
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);
|
|
3253
3240
|
var Model = class Model extends BaseModel {
|
|
3254
|
-
primaryKey = "id";
|
|
3255
3241
|
builder = null;
|
|
3256
3242
|
table = null;
|
|
3257
3243
|
keyType = "int";
|
|
3258
3244
|
incrementing = true;
|
|
3259
3245
|
withCount = [];
|
|
3246
|
+
primaryKey = "id";
|
|
3260
3247
|
perPage = 15;
|
|
3261
3248
|
static globalScopes = {};
|
|
3262
3249
|
static pluginInitializers = {};
|
|
@@ -3266,6 +3253,7 @@ var Model = class Model extends BaseModel {
|
|
|
3266
3253
|
eagerLoad = {};
|
|
3267
3254
|
exists = false;
|
|
3268
3255
|
with = [];
|
|
3256
|
+
name;
|
|
3269
3257
|
trx = null;
|
|
3270
3258
|
constructor(attributes = {}) {
|
|
3271
3259
|
super();
|
|
@@ -4037,8 +4025,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
4037
4025
|
const results = await this.take(1).get(columns);
|
|
4038
4026
|
return results.count() > 0 ? results.first() : null;
|
|
4039
4027
|
}
|
|
4040
|
-
async firstOrFail(columns
|
|
4041
|
-
const model = await this.first(columns);
|
|
4028
|
+
async firstOrFail(...columns) {
|
|
4029
|
+
const model = await this.first(...columns);
|
|
4042
4030
|
if (model !== null) return model;
|
|
4043
4031
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
4044
4032
|
}
|
|
@@ -4214,7 +4202,9 @@ var Builder = class Builder extends Inference {
|
|
|
4214
4202
|
}
|
|
4215
4203
|
asProxy() {
|
|
4216
4204
|
return new Proxy(this, { get(target, prop) {
|
|
4205
|
+
var _target$query$connect;
|
|
4217
4206
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
4207
|
+
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";
|
|
4218
4208
|
if ([
|
|
4219
4209
|
"select",
|
|
4220
4210
|
"from",
|
|
@@ -4277,7 +4267,7 @@ var Builder = class Builder extends Inference {
|
|
|
4277
4267
|
"clearWhere",
|
|
4278
4268
|
"clearHaving",
|
|
4279
4269
|
"clearGroup"
|
|
4280
|
-
].includes(prop)) return (...args) => {
|
|
4270
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
4281
4271
|
target.query[prop](...args);
|
|
4282
4272
|
return target.asProxy();
|
|
4283
4273
|
};
|
|
@@ -5136,9 +5126,9 @@ var Migrator = class {
|
|
|
5136
5126
|
}
|
|
5137
5127
|
/**
|
|
5138
5128
|
* Drop all tables and re-run all migrations
|
|
5139
|
-
*
|
|
5140
|
-
* @param paths
|
|
5141
|
-
* @param options
|
|
5129
|
+
*
|
|
5130
|
+
* @param paths
|
|
5131
|
+
* @param options
|
|
5142
5132
|
*/
|
|
5143
5133
|
async fresh(paths, options) {
|
|
5144
5134
|
/** Initialise connections */
|
|
@@ -5241,10 +5231,10 @@ var Migrate = class {
|
|
|
5241
5231
|
}
|
|
5242
5232
|
/**
|
|
5243
5233
|
* Runs all pending migrations
|
|
5244
|
-
*
|
|
5245
|
-
* @param config
|
|
5246
|
-
* @param options
|
|
5247
|
-
* @param destroyAll
|
|
5234
|
+
*
|
|
5235
|
+
* @param config
|
|
5236
|
+
* @param options
|
|
5237
|
+
* @param destroyAll
|
|
5248
5238
|
*/
|
|
5249
5239
|
async run(config, options = {}, destroyAll = false) {
|
|
5250
5240
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5258,10 +5248,10 @@ var Migrate = class {
|
|
|
5258
5248
|
}
|
|
5259
5249
|
/**
|
|
5260
5250
|
* Rollback the last migration
|
|
5261
|
-
*
|
|
5262
|
-
* @param config
|
|
5263
|
-
* @param options
|
|
5264
|
-
* @param destroyAll
|
|
5251
|
+
*
|
|
5252
|
+
* @param config
|
|
5253
|
+
* @param options
|
|
5254
|
+
* @param destroyAll
|
|
5265
5255
|
*/
|
|
5266
5256
|
async rollback(config, options = {}, destroyAll = false) {
|
|
5267
5257
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5275,10 +5265,10 @@ var Migrate = class {
|
|
|
5275
5265
|
}
|
|
5276
5266
|
/**
|
|
5277
5267
|
* Rollback all database migrations
|
|
5278
|
-
*
|
|
5279
|
-
* @param config
|
|
5280
|
-
* @param options
|
|
5281
|
-
* @param destroyAll
|
|
5268
|
+
*
|
|
5269
|
+
* @param config
|
|
5270
|
+
* @param options
|
|
5271
|
+
* @param destroyAll
|
|
5282
5272
|
*/
|
|
5283
5273
|
async reset(config, options = {}, destroyAll = false) {
|
|
5284
5274
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5293,10 +5283,10 @@ var Migrate = class {
|
|
|
5293
5283
|
}
|
|
5294
5284
|
/**
|
|
5295
5285
|
* Reset and re-run all migrations
|
|
5296
|
-
*
|
|
5297
|
-
* @param config
|
|
5298
|
-
* @param options
|
|
5299
|
-
* @param destroyAll
|
|
5286
|
+
*
|
|
5287
|
+
* @param config
|
|
5288
|
+
* @param options
|
|
5289
|
+
* @param destroyAll
|
|
5300
5290
|
*/
|
|
5301
5291
|
async refresh(config, options = {}, destroyAll = false) {
|
|
5302
5292
|
await this.reset(config, Object.assign({}, options, { quiet: true }), false);
|
|
@@ -5305,10 +5295,10 @@ var Migrate = class {
|
|
|
5305
5295
|
}
|
|
5306
5296
|
/**
|
|
5307
5297
|
* Drop all tables and re-run all migrations
|
|
5308
|
-
*
|
|
5309
|
-
* @param config
|
|
5310
|
-
* @param options
|
|
5311
|
-
* @param destroyAll
|
|
5298
|
+
*
|
|
5299
|
+
* @param config
|
|
5300
|
+
* @param options
|
|
5301
|
+
* @param destroyAll
|
|
5312
5302
|
*/
|
|
5313
5303
|
async fresh(config, options = {}, destroyAll = false) {
|
|
5314
5304
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5318,8 +5308,8 @@ var Migrate = class {
|
|
|
5318
5308
|
}
|
|
5319
5309
|
/**
|
|
5320
5310
|
* Prepares the database for migration
|
|
5321
|
-
*
|
|
5322
|
-
* @param migrator
|
|
5311
|
+
*
|
|
5312
|
+
* @param migrator
|
|
5323
5313
|
*/
|
|
5324
5314
|
async prepareDatabase(migrator) {
|
|
5325
5315
|
if (!await migrator.repositoryExists()) {
|
|
@@ -5331,11 +5321,11 @@ var Migrate = class {
|
|
|
5331
5321
|
}
|
|
5332
5322
|
/**
|
|
5333
5323
|
* Check the status of available migrations
|
|
5334
|
-
*
|
|
5335
|
-
* @param config
|
|
5336
|
-
* @param options
|
|
5337
|
-
* @param destroyAll
|
|
5338
|
-
* @returns
|
|
5324
|
+
*
|
|
5325
|
+
* @param config
|
|
5326
|
+
* @param options
|
|
5327
|
+
* @param destroyAll
|
|
5328
|
+
* @returns
|
|
5339
5329
|
*/
|
|
5340
5330
|
async status(config, options = {}, destroyAll = false) {
|
|
5341
5331
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5362,9 +5352,9 @@ var Migrate = class {
|
|
|
5362
5352
|
}
|
|
5363
5353
|
/**
|
|
5364
5354
|
* Setup the database connection
|
|
5365
|
-
*
|
|
5366
|
-
* @param config
|
|
5367
|
-
* @returns
|
|
5355
|
+
*
|
|
5356
|
+
* @param config
|
|
5357
|
+
* @returns
|
|
5368
5358
|
*/
|
|
5369
5359
|
async setupConnection(config) {
|
|
5370
5360
|
var _config$migrations;
|
|
@@ -5394,54 +5384,54 @@ var MigrationCreator = class {
|
|
|
5394
5384
|
}
|
|
5395
5385
|
/**
|
|
5396
5386
|
* Create a new migration file
|
|
5397
|
-
*
|
|
5398
|
-
* @param name
|
|
5399
|
-
* @param dir
|
|
5400
|
-
* @param table
|
|
5401
|
-
* @param create
|
|
5402
|
-
* @returns
|
|
5387
|
+
*
|
|
5388
|
+
* @param name
|
|
5389
|
+
* @param dir
|
|
5390
|
+
* @param table
|
|
5391
|
+
* @param create
|
|
5392
|
+
* @returns
|
|
5403
5393
|
*/
|
|
5404
5394
|
async create(name$1, dir, table, create = false) {
|
|
5405
|
-
const stub = this.getStub(table, create);
|
|
5395
|
+
const stub = await this.getStub(table, create);
|
|
5406
5396
|
const filePath = this.getPath(name$1, dir);
|
|
5407
5397
|
await this.ensureDirectoryExists(path.default.dirname(filePath));
|
|
5408
|
-
await node_fs_promises.
|
|
5398
|
+
await (0, node_fs_promises.writeFile)(filePath, this.populateStub(stub, table));
|
|
5409
5399
|
await this.firePostCreateHooks(table, filePath);
|
|
5410
5400
|
return filePath;
|
|
5411
5401
|
}
|
|
5412
5402
|
/**
|
|
5413
5403
|
* Publish migrations from third party vendors
|
|
5414
|
-
*
|
|
5415
|
-
* @param dir
|
|
5416
|
-
* @param callback
|
|
5404
|
+
*
|
|
5405
|
+
* @param dir
|
|
5406
|
+
* @param callback
|
|
5417
5407
|
*/
|
|
5418
5408
|
async publish(dir, callback) {
|
|
5419
|
-
const migrationFiles = await node_fs_promises.
|
|
5409
|
+
const migrationFiles = await (0, node_fs_promises.readdir)(this.customStubPath ?? "");
|
|
5420
5410
|
await this.ensureDirectoryExists(dir);
|
|
5421
5411
|
for (const migrationFile of migrationFiles) {
|
|
5422
5412
|
const sourceFilePath = path.default.join(this.customStubPath ?? "", migrationFile);
|
|
5423
5413
|
const destinationFilePath = path.default.join(dir, migrationFile);
|
|
5424
|
-
await node_fs_promises.
|
|
5414
|
+
await (0, node_fs_promises.copyFile)(sourceFilePath, destinationFilePath);
|
|
5425
5415
|
if (callback) callback(migrationFile, sourceFilePath, destinationFilePath);
|
|
5426
5416
|
}
|
|
5427
5417
|
}
|
|
5428
|
-
getStub(table, create = false) {
|
|
5418
|
+
async getStub(table, create = false) {
|
|
5429
5419
|
let stub;
|
|
5430
5420
|
if (!table) {
|
|
5431
5421
|
const customPath = path.default.join(this.customStubPath ?? "", `migration-${this.type}.stub`);
|
|
5432
5422
|
console.log("\n", customPath, "---");
|
|
5433
|
-
stub =
|
|
5423
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration-${this.type}.stub`);
|
|
5434
5424
|
} else if (create) {
|
|
5435
5425
|
const customPath = path.default.join(this.customStubPath ?? "", `migration.create-${this.type}.stub`);
|
|
5436
|
-
stub =
|
|
5426
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.create-${this.type}.stub`);
|
|
5437
5427
|
} else {
|
|
5438
5428
|
const customPath = path.default.join(this.customStubPath ?? "", `migration.update-${this.type}.stub`);
|
|
5439
|
-
stub =
|
|
5429
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.update-${this.type}.stub`);
|
|
5440
5430
|
}
|
|
5441
|
-
return (0,
|
|
5431
|
+
return await (0, node_fs_promises.readFile)(stub, "utf-8");
|
|
5442
5432
|
}
|
|
5443
5433
|
populateStub(stub, table) {
|
|
5444
|
-
if (table
|
|
5434
|
+
if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
5445
5435
|
return stub;
|
|
5446
5436
|
}
|
|
5447
5437
|
getClassName(name$1) {
|
|
@@ -5458,7 +5448,7 @@ var MigrationCreator = class {
|
|
|
5458
5448
|
this.postCreate.push(callback);
|
|
5459
5449
|
}
|
|
5460
5450
|
async ensureDirectoryExists(dir) {
|
|
5461
|
-
await node_fs_promises.
|
|
5451
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
5462
5452
|
}
|
|
5463
5453
|
stubPath(stub = "") {
|
|
5464
5454
|
const __dirname$1 = this.getDirname({});
|
|
@@ -5474,7 +5464,7 @@ var MigrationCreator = class {
|
|
|
5474
5464
|
//#endregion
|
|
5475
5465
|
//#region package.json
|
|
5476
5466
|
var name = "@h3ravel/arquebus";
|
|
5477
|
-
var version = "0.
|
|
5467
|
+
var version = "0.5.0";
|
|
5478
5468
|
var packageManager = "pnpm@10.14.0";
|
|
5479
5469
|
var description = "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.";
|
|
5480
5470
|
var homepage = "https://h3ravel.toneflix.net/arquebus";
|
|
@@ -5562,6 +5552,16 @@ var exports$1 = {
|
|
|
5562
5552
|
"default": "./dist/inspector/index.cjs"
|
|
5563
5553
|
}
|
|
5564
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
|
+
},
|
|
5565
5565
|
"./browser": {
|
|
5566
5566
|
"import": {
|
|
5567
5567
|
"types": "./dist/browser/index.d.ts",
|
|
@@ -5592,12 +5592,13 @@ var scripts = {
|
|
|
5592
5592
|
"test:postgres": "cross-env DB=postgres vitest --project node",
|
|
5593
5593
|
"test:sqlite": "cross-env DB=sqlite vitest --project node",
|
|
5594
5594
|
"test:browser": "vitest --project browser",
|
|
5595
|
-
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version
|
|
5595
|
+
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version\" && pnpm version patch && pnpm publish --tag latest"
|
|
5596
5596
|
};
|
|
5597
5597
|
var husky = { "hooks": { "pre-commit": "lint-staged" } };
|
|
5598
5598
|
var lint_staged = { "*.{js,json}": ["prettier --write", "git add"] };
|
|
5599
5599
|
var dependencies = {
|
|
5600
|
-
"@h3ravel/shared": "^0.
|
|
5600
|
+
"@h3ravel/shared": "^0.20.12",
|
|
5601
|
+
"@h3ravel/support": "^0.12.0",
|
|
5601
5602
|
"chalk": "^5.6.2",
|
|
5602
5603
|
"collect.js": "^4.36.1",
|
|
5603
5604
|
"commander": "^14.0.1",
|
|
@@ -5611,7 +5612,6 @@ var dependencies = {
|
|
|
5611
5612
|
"mysql2": "^3.15.0",
|
|
5612
5613
|
"pg": "^8.16.3",
|
|
5613
5614
|
"pluralize": "^8.0.0",
|
|
5614
|
-
"prettier": "^3.6.2",
|
|
5615
5615
|
"radashi": "^12.6.2",
|
|
5616
5616
|
"resolve-from": "^5.0.0",
|
|
5617
5617
|
"tedious": "^19.0.0"
|
|
@@ -5625,6 +5625,7 @@ var devDependencies = {
|
|
|
5625
5625
|
"@vitest/coverage-v8": "^3.2.4",
|
|
5626
5626
|
"eslint": "^9.36.0",
|
|
5627
5627
|
"jsdom": "^26.1.0",
|
|
5628
|
+
"prettier": "^3.6.2",
|
|
5628
5629
|
"sqlite3": "5.1.7",
|
|
5629
5630
|
"terser": "^5.44.0",
|
|
5630
5631
|
"ts-node": "^10.9.2",
|
|
@@ -5691,7 +5692,12 @@ var Cli = class Cli {
|
|
|
5691
5692
|
this.basePath = basePath ?? (process.env.TEST === "true" ? "test/cli" : "");
|
|
5692
5693
|
}
|
|
5693
5694
|
terminateNotFound() {
|
|
5694
|
-
|
|
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.`);
|
|
5695
5701
|
}
|
|
5696
5702
|
static init() {
|
|
5697
5703
|
(0, dotenv.config)({ quiet: true });
|
|
@@ -5727,8 +5733,8 @@ var Cli = class Cli {
|
|
|
5727
5733
|
return this;
|
|
5728
5734
|
}
|
|
5729
5735
|
async run() {
|
|
5730
|
-
const cliVersion = ["Arquebus CLI version:",
|
|
5731
|
-
const localVersion = ["Arquebus Local version:",
|
|
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(" ");
|
|
5732
5738
|
commander.program.name("arquebus").version(`${cliVersion}\n${localVersion}`);
|
|
5733
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) => {
|
|
5734
5740
|
if (!this.modulePath) this.output.error(["ERROR: No local arquebus install found", " Try running: npm install arquebus --save"]);
|
|
@@ -5742,16 +5748,16 @@ var Cli = class Cli {
|
|
|
5742
5748
|
this.output.error("ERROR: " + e);
|
|
5743
5749
|
}
|
|
5744
5750
|
});
|
|
5745
|
-
commander.program.command("
|
|
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) => {
|
|
5746
5752
|
if (!this.configPath) this.terminateNotFound();
|
|
5747
5753
|
try {
|
|
5748
5754
|
var _this$config$migratio3;
|
|
5749
5755
|
name$1 = (0, radashi.snake)(name$1);
|
|
5750
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");
|
|
5751
5757
|
let table = opts.table;
|
|
5752
|
-
let create = opts.create
|
|
5753
|
-
if (!table && typeof create === "string") {
|
|
5754
|
-
table = create;
|
|
5758
|
+
let create = Boolean(opts.create) && opts.create !== "";
|
|
5759
|
+
if (!table && typeof opts.create === "string") {
|
|
5760
|
+
table = opts.create;
|
|
5755
5761
|
create = true;
|
|
5756
5762
|
}
|
|
5757
5763
|
if (!table) {
|
|
@@ -5761,7 +5767,7 @@ var Cli = class Cli {
|
|
|
5761
5767
|
}
|
|
5762
5768
|
this.output.info("INFO: Creating Migration");
|
|
5763
5769
|
const fileName = await new MigrationCreator(void 0, opts.type).create(name$1, migrationPath, table, create);
|
|
5764
|
-
this.output.success(`INFO: Migration Created \n ${
|
|
5770
|
+
this.output.success(`INFO: Migration Created \n ${__h3ravel_shared.Logger.log(path.default.basename(fileName), "gray", false)}`, true);
|
|
5765
5771
|
} catch (e) {
|
|
5766
5772
|
this.output.error("ERROR: " + e);
|
|
5767
5773
|
}
|
|
@@ -5778,9 +5784,10 @@ var Cli = class Cli {
|
|
|
5778
5784
|
const pkgJson = await import(path.default.join(packagePath, "package.json"));
|
|
5779
5785
|
if (!packagePath) this.output.error(`ERROR: package ${pkg} not found`);
|
|
5780
5786
|
const creator = new MigrationCreator(path.default.join(packagePath, pkgJson.migrations ?? "migrations"));
|
|
5781
|
-
|
|
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}`);
|
|
5782
5789
|
await creator.publish(basePath, (fileName) => {
|
|
5783
|
-
|
|
5790
|
+
this.output.split("INFO: Migration Published", fileName, "success");
|
|
5784
5791
|
});
|
|
5785
5792
|
} catch (e) {
|
|
5786
5793
|
this.output.error("ERROR: " + e);
|
|
@@ -5793,7 +5800,11 @@ var Cli = class Cli {
|
|
|
5793
5800
|
if (!this.configPath) this.terminateNotFound();
|
|
5794
5801
|
const basePath = opts.path ? path.default.join(this.cwd, opts.path) : this.cwd;
|
|
5795
5802
|
try {
|
|
5796
|
-
|
|
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);
|
|
5797
5808
|
} catch (e) {
|
|
5798
5809
|
this.output.error("ERROR: " + e);
|
|
5799
5810
|
}
|
|
@@ -5807,7 +5818,10 @@ var Cli = class Cli {
|
|
|
5807
5818
|
try {
|
|
5808
5819
|
await new Migrate(basePath, void 0, (msg, sts) => {
|
|
5809
5820
|
if (sts) this.output[sts](msg);
|
|
5810
|
-
}).rollback(this.config,
|
|
5821
|
+
}).rollback(this.config, {
|
|
5822
|
+
...opts,
|
|
5823
|
+
step: typeof opts.step === "string" ? parseInt(opts.step) : opts.step
|
|
5824
|
+
}, true);
|
|
5811
5825
|
} catch (e) {
|
|
5812
5826
|
this.output.error("ERROR: " + e);
|
|
5813
5827
|
}
|
|
@@ -5865,9 +5879,9 @@ var Cli = class Cli {
|
|
|
5865
5879
|
if (sts) this.output[sts](msg);
|
|
5866
5880
|
}).status(this.config, opts, true);
|
|
5867
5881
|
if (migrations.length > 0) {
|
|
5868
|
-
__h3ravel_shared.Logger.twoColumnLog(
|
|
5882
|
+
__h3ravel_shared.Logger.twoColumnLog(__h3ravel_shared.Logger.log("Migration name", "gray", false), __h3ravel_shared.Logger.log("Batch / Status", "gray", false));
|
|
5869
5883
|
migrations.forEach((migration) => {
|
|
5870
|
-
const status = migration.ran ? `[${migration.batch}] ${
|
|
5884
|
+
const status = migration.ran ? `[${migration.batch}] ${__h3ravel_shared.Logger.log("Ran", "green", false)}` : __h3ravel_shared.Logger.log("Pending", "yellow", false);
|
|
5871
5885
|
__h3ravel_shared.Logger.twoColumnLog(migration.name, status);
|
|
5872
5886
|
});
|
|
5873
5887
|
} else console.log("No migrations found");
|
|
@@ -5876,9 +5890,49 @@ var Cli = class Cli {
|
|
|
5876
5890
|
}
|
|
5877
5891
|
});
|
|
5878
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
|
+
/**
|
|
5879
5933
|
* Create a new model file
|
|
5880
5934
|
*/
|
|
5881
|
-
commander.program.command("model
|
|
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) => {
|
|
5882
5936
|
var _this$config$models;
|
|
5883
5937
|
if (!this.configPath) this.terminateNotFound();
|
|
5884
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);
|