@h3ravel/arquebus 0.6.6 → 0.6.8
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 +5 -4
- package/bin/index.cjs +270 -425
- package/bin/{index.js → index.mjs} +230 -409
- package/bin/seeders-C0schOjT.mjs +3 -0
- package/bin/seeders-D-v59HCz.cjs +3 -0
- package/dist/browser/index.cjs +4 -12
- package/dist/browser/index.d.cts +203 -203
- package/dist/browser/{index.d.ts → index.d.mts} +203 -203
- package/dist/browser/{index.js → index.mjs} +4 -11
- package/dist/index.cjs +21 -59
- package/dist/index.d.cts +133 -133
- package/dist/{index.d.ts → index.d.mts} +133 -133
- package/dist/{index.js → index.mjs} +21 -54
- package/dist/inspector/index.cjs +15 -46
- package/dist/inspector/{index.js → index.mjs} +15 -43
- package/dist/migrations/{chunk-PECeCxCb.js → chunk-BD38OWEx.mjs} +1 -1
- package/dist/migrations/index.cjs +20 -57
- package/dist/migrations/index.d.cts +186 -186
- package/dist/migrations/{index.d.ts → index.d.mts} +186 -186
- package/dist/migrations/{index.js → index.mjs} +22 -54
- package/dist/seeders/index.cjs +1 -5
- package/dist/seeders/index.d.cts +184 -184
- package/dist/seeders/{index.d.ts → index.d.mts} +184 -184
- package/dist/seeders/{index.js → index.mjs} +2 -3
- package/dist/stubs/seeder-js.stub +4 -4
- package/dist/stubs/seeder-ts.stub +5 -0
- package/package.json +5 -4
- package/bin/seeders-8GJzfIIN.js +0 -3
- package/bin/seeders-ByeSoCAQ.cjs +0 -131
- package/bin/seeders-CltigymO.js +0 -79
- package/bin/seeders-_xJ6VGVS.cjs +0 -3
- /package/bin/{index.d.ts → index.d.mts} +0 -0
- /package/dist/inspector/{index.d.ts → index.d.mts} +0 -0
package/bin/index.cjs
CHANGED
|
@@ -1,37 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
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 in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
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
|
|
3
33
|
let commander = require("commander");
|
|
4
|
-
commander = require_seeders.__toESM(commander);
|
|
5
34
|
let __h3ravel_shared = require("@h3ravel/shared");
|
|
6
|
-
__h3ravel_shared = require_seeders.__toESM(__h3ravel_shared);
|
|
7
35
|
let path = require("path");
|
|
8
|
-
path =
|
|
36
|
+
path = __toESM(path);
|
|
9
37
|
let resolve_from = require("resolve-from");
|
|
10
|
-
resolve_from =
|
|
38
|
+
resolve_from = __toESM(resolve_from);
|
|
11
39
|
let node_fs_promises = require("node:fs/promises");
|
|
12
|
-
node_fs_promises =
|
|
40
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
13
41
|
let radashi = require("radashi");
|
|
14
|
-
radashi = require_seeders.__toESM(radashi);
|
|
15
42
|
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
16
|
-
dayjs_plugin_advancedFormat_js =
|
|
43
|
+
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js);
|
|
17
44
|
let dayjs = require("dayjs");
|
|
18
|
-
dayjs =
|
|
45
|
+
dayjs = __toESM(dayjs);
|
|
19
46
|
let collect_js = require("collect.js");
|
|
20
|
-
collect_js =
|
|
47
|
+
collect_js = __toESM(collect_js);
|
|
21
48
|
let knex = require("knex");
|
|
22
|
-
knex =
|
|
49
|
+
knex = __toESM(knex);
|
|
23
50
|
let fs = require("fs");
|
|
24
|
-
fs = require_seeders.__toESM(fs);
|
|
25
51
|
let pluralize = require("pluralize");
|
|
26
|
-
pluralize =
|
|
52
|
+
pluralize = __toESM(pluralize);
|
|
27
53
|
let node_path = require("node:path");
|
|
28
|
-
node_path = require_seeders.__toESM(node_path);
|
|
29
54
|
let node_url = require("node:url");
|
|
30
|
-
node_url = require_seeders.__toESM(node_url);
|
|
31
55
|
let __h3ravel_support = require("@h3ravel/support");
|
|
32
|
-
__h3ravel_support = require_seeders.__toESM(__h3ravel_support);
|
|
33
56
|
let dotenv = require("dotenv");
|
|
34
|
-
dotenv = require_seeders.__toESM(dotenv);
|
|
35
57
|
|
|
36
58
|
//#region src/cli/utils.ts
|
|
37
59
|
const join = path.default.join;
|
|
@@ -46,8 +68,8 @@ var Utils = class {
|
|
|
46
68
|
if (!resolved) return;
|
|
47
69
|
return path.default.join(path.default.dirname(resolved), parts.join("/"));
|
|
48
70
|
}
|
|
49
|
-
static async getMigrationPaths(cwd, migrator, defaultPath, path$
|
|
50
|
-
if (path$
|
|
71
|
+
static async getMigrationPaths(cwd, migrator, defaultPath, path$8) {
|
|
72
|
+
if (path$8) return [join(cwd, path$8)];
|
|
51
73
|
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
52
74
|
}
|
|
53
75
|
};
|
|
@@ -131,8 +153,8 @@ var MigrationRepository = class {
|
|
|
131
153
|
getConnection() {
|
|
132
154
|
return this.resolver.fire(this.connection);
|
|
133
155
|
}
|
|
134
|
-
setSource(name
|
|
135
|
-
this.connection = name
|
|
156
|
+
setSource(name) {
|
|
157
|
+
this.connection = name;
|
|
136
158
|
}
|
|
137
159
|
};
|
|
138
160
|
|
|
@@ -606,10 +628,7 @@ var MSSQL = class {
|
|
|
606
628
|
AND ISNULL([i].[index_column_count], 1) = 1
|
|
607
629
|
AND ISNULL([i].[index_priority], 1) = 1`).where({ "s.name": this.schema });
|
|
608
630
|
if (table) query.andWhere({ "o.name": table });
|
|
609
|
-
if (column) {
|
|
610
|
-
const rawColumn = await query.andWhere({ "c.name": column }).first();
|
|
611
|
-
return rawColumnToColumn$2(rawColumn);
|
|
612
|
-
}
|
|
631
|
+
if (column) return rawColumnToColumn$2(await query.andWhere({ "c.name": column }).first());
|
|
613
632
|
return (await query).map(rawColumnToColumn$2);
|
|
614
633
|
}
|
|
615
634
|
/**
|
|
@@ -760,10 +779,7 @@ var MySQL = class {
|
|
|
760
779
|
this.on("rc.TABLE_NAME", "=", "fk.TABLE_NAME").andOn("rc.CONSTRAINT_NAME", "=", "fk.CONSTRAINT_NAME").andOn("rc.CONSTRAINT_SCHEMA", "=", "fk.CONSTRAINT_SCHEMA");
|
|
761
780
|
}).where({ "c.TABLE_SCHEMA": this.knex.client.database() });
|
|
762
781
|
if (table) query.andWhere({ "c.TABLE_NAME": table });
|
|
763
|
-
if (column) {
|
|
764
|
-
const rawColumn = await query.andWhere({ "c.column_name": column }).first();
|
|
765
|
-
return rawColumnToColumn$1(rawColumn);
|
|
766
|
-
}
|
|
782
|
+
if (column) return rawColumnToColumn$1(await query.andWhere({ "c.column_name": column }).first());
|
|
767
783
|
return (await query).map(rawColumnToColumn$1).sort((column$1) => +!column$1.foreign_key_column).filter((column$1, index, records) => {
|
|
768
784
|
return records.findIndex((_column) => {
|
|
769
785
|
return column$1.name === _column.name && column$1.table === _column.table;
|
|
@@ -862,7 +878,7 @@ var oracleDB = class {
|
|
|
862
878
|
return (await this.knex.select(this.knex.raw(`
|
|
863
879
|
/*+ OPTIMIZER_FEATURES_ENABLE('${OPTIMIZER_FEATURES}') */
|
|
864
880
|
"TABLE_NAME" "name"
|
|
865
|
-
`)).from("USER_TABLES")).map(({ name
|
|
881
|
+
`)).from("USER_TABLES")).map(({ name }) => name);
|
|
866
882
|
}
|
|
867
883
|
async tableInfo(table) {
|
|
868
884
|
const query = this.knex.select(this.knex.raw(`
|
|
@@ -949,10 +965,7 @@ var oracleDB = class {
|
|
|
949
965
|
ON "ct"."R_CONSTRAINT_NAME" = "fk"."CONSTRAINT_NAME"
|
|
950
966
|
`)).where({ "c.HIDDEN_COLUMN": "NO" });
|
|
951
967
|
if (table) query.andWhere({ "c.TABLE_NAME": table });
|
|
952
|
-
if (column) {
|
|
953
|
-
const rawColumn = await query.andWhere({ "c.COLUMN_NAME": column }).first();
|
|
954
|
-
return rawColumnToColumn(rawColumn);
|
|
955
|
-
}
|
|
968
|
+
if (column) return rawColumnToColumn(await query.andWhere({ "c.COLUMN_NAME": column }).first());
|
|
956
969
|
return (await query).map(rawColumnToColumn);
|
|
957
970
|
}
|
|
958
971
|
/**
|
|
@@ -1368,8 +1381,8 @@ var Postgres = class {
|
|
|
1368
1381
|
* Extracts the length value out of a given datatype
|
|
1369
1382
|
* For example: `varchar(32)` => 32
|
|
1370
1383
|
*/
|
|
1371
|
-
function extractMaxLength(type
|
|
1372
|
-
const matches = /\(([^)]+)\)/.exec(type
|
|
1384
|
+
function extractMaxLength(type) {
|
|
1385
|
+
const matches = /\(([^)]+)\)/.exec(type);
|
|
1373
1386
|
if (matches && matches.length > 0 && matches[1]) return Number(matches[1]);
|
|
1374
1387
|
return null;
|
|
1375
1388
|
}
|
|
@@ -1380,8 +1393,8 @@ function extractMaxLength(type$1) {
|
|
|
1380
1393
|
* Extracts the type out of a given datatype
|
|
1381
1394
|
* For example: `varchar(32)` => varchar
|
|
1382
1395
|
*/
|
|
1383
|
-
function extractType(type
|
|
1384
|
-
return type
|
|
1396
|
+
function extractType(type) {
|
|
1397
|
+
return type.replace(/[^a-zA-Z]/g, "").toLowerCase();
|
|
1385
1398
|
}
|
|
1386
1399
|
|
|
1387
1400
|
//#endregion
|
|
@@ -1454,7 +1467,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
1454
1467
|
|
|
1455
1468
|
//#endregion
|
|
1456
1469
|
//#region src/mixin.ts
|
|
1457
|
-
var mixin_exports = /* @__PURE__ */
|
|
1470
|
+
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
1458
1471
|
/**
|
|
1459
1472
|
* Compose function that merges multiple classes and mixins
|
|
1460
1473
|
*
|
|
@@ -1514,8 +1527,8 @@ function compose$1(Base, ...mixins) {
|
|
|
1514
1527
|
/**
|
|
1515
1528
|
* Copy instance properties from mixin prototype
|
|
1516
1529
|
*/
|
|
1517
|
-
Object.getOwnPropertyNames(mixin.prototype).forEach((name
|
|
1518
|
-
if (name
|
|
1530
|
+
Object.getOwnPropertyNames(mixin.prototype).forEach((name) => {
|
|
1531
|
+
if (name !== "constructor") Object.defineProperty(this, name, Object.getOwnPropertyDescriptor(mixin.prototype, name));
|
|
1519
1532
|
});
|
|
1520
1533
|
}
|
|
1521
1534
|
};
|
|
@@ -1839,9 +1852,7 @@ const HasAttributes = (Model$1) => {
|
|
|
1839
1852
|
}
|
|
1840
1853
|
originalIsEquivalent(key) {
|
|
1841
1854
|
if (this.original[key] === void 0) return false;
|
|
1842
|
-
|
|
1843
|
-
const original = this.original[key];
|
|
1844
|
-
if (attribute === original) return true;
|
|
1855
|
+
if (this.attributes[key] === this.original[key]) return true;
|
|
1845
1856
|
else return false;
|
|
1846
1857
|
}
|
|
1847
1858
|
setAttributes(attributes) {
|
|
@@ -1983,10 +1994,10 @@ const HasAttributes = (Model$1) => {
|
|
|
1983
1994
|
else convertedCastType = String(castType).toLocaleLowerCase().trim();
|
|
1984
1995
|
return this.getConstructor()[castTypeCacheKey] = convertedCastType;
|
|
1985
1996
|
}
|
|
1986
|
-
hasCast(key, types
|
|
1997
|
+
hasCast(key, types = []) {
|
|
1987
1998
|
if (key in this.casts) {
|
|
1988
|
-
types
|
|
1989
|
-
return types
|
|
1999
|
+
types = (0, radashi.flat)(types);
|
|
2000
|
+
return types.length > 0 ? types.includes(this.getCastType(key)) : true;
|
|
1990
2001
|
}
|
|
1991
2002
|
return false;
|
|
1992
2003
|
}
|
|
@@ -2023,8 +2034,7 @@ const HasAttributes = (Model$1) => {
|
|
|
2023
2034
|
return new Date(value);
|
|
2024
2035
|
}
|
|
2025
2036
|
asDate(value) {
|
|
2026
|
-
|
|
2027
|
-
return (0, dayjs.default)(date).startOf("day").toDate();
|
|
2037
|
+
return (0, dayjs.default)(this.asDateTime(value)).startOf("day").toDate();
|
|
2028
2038
|
}
|
|
2029
2039
|
};
|
|
2030
2040
|
};
|
|
@@ -2163,15 +2173,15 @@ var has_hooks_default = HasHooks;
|
|
|
2163
2173
|
//#region src/relations/has-one-or-many.ts
|
|
2164
2174
|
const HasOneOrMany = (Relation$1) => {
|
|
2165
2175
|
return class extends Relation$1 {
|
|
2166
|
-
getRelationValue(dictionary, key, type
|
|
2176
|
+
getRelationValue(dictionary, key, type) {
|
|
2167
2177
|
const value = dictionary[key];
|
|
2168
|
-
return type
|
|
2178
|
+
return type === "one" ? value[0] : new collection_default(value);
|
|
2169
2179
|
}
|
|
2170
|
-
matchOneOrMany(models, results, relation, type
|
|
2180
|
+
matchOneOrMany(models, results, relation, type) {
|
|
2171
2181
|
const dictionary = this.buildDictionary(results);
|
|
2172
2182
|
models.map((model) => {
|
|
2173
2183
|
const key = model.attributes[this.localKey];
|
|
2174
|
-
if (dictionary[key] !== void 0) model.setRelation(relation, this.getRelationValue(dictionary, key, type
|
|
2184
|
+
if (dictionary[key] !== void 0) model.setRelation(relation, this.getRelationValue(dictionary, key, type));
|
|
2175
2185
|
});
|
|
2176
2186
|
return models;
|
|
2177
2187
|
}
|
|
@@ -2538,10 +2548,7 @@ const HasRelations = (Model$1) => {
|
|
|
2538
2548
|
return this.relations[relation] !== void 0;
|
|
2539
2549
|
}
|
|
2540
2550
|
related(relation) {
|
|
2541
|
-
if (typeof this[getRelationMethod(relation)] !== "function") {
|
|
2542
|
-
const message = `Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`;
|
|
2543
|
-
throw new RelationNotFoundError(message);
|
|
2544
|
-
}
|
|
2551
|
+
if (typeof this[getRelationMethod(relation)] !== "function") throw new RelationNotFoundError(`Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`);
|
|
2545
2552
|
return this[getRelationMethod(relation)]();
|
|
2546
2553
|
}
|
|
2547
2554
|
async getRelated(relation) {
|
|
@@ -3052,8 +3059,8 @@ var arquebus = class arquebus {
|
|
|
3052
3059
|
static getConnectorFactory() {
|
|
3053
3060
|
return this.connectorFactory ?? knex.default;
|
|
3054
3061
|
}
|
|
3055
|
-
static addConnection(config, name
|
|
3056
|
-
return this.getInstance().addConnection(config, name
|
|
3062
|
+
static addConnection(config, name = "default") {
|
|
3063
|
+
return this.getInstance().addConnection(config, name);
|
|
3057
3064
|
}
|
|
3058
3065
|
static beginTransaction(connection = null) {
|
|
3059
3066
|
return this.getInstance().beginTransaction(connection);
|
|
@@ -3061,8 +3068,8 @@ var arquebus = class arquebus {
|
|
|
3061
3068
|
static transaction(callback, connection = null) {
|
|
3062
3069
|
return this.getInstance().transaction(callback, connection);
|
|
3063
3070
|
}
|
|
3064
|
-
static table(name
|
|
3065
|
-
return this.getInstance().table(name
|
|
3071
|
+
static table(name, connection = null) {
|
|
3072
|
+
return this.getInstance().table(name, connection);
|
|
3066
3073
|
}
|
|
3067
3074
|
static schema(connection = null) {
|
|
3068
3075
|
return this.getInstance().schema(connection);
|
|
@@ -3070,23 +3077,23 @@ var arquebus = class arquebus {
|
|
|
3070
3077
|
static async destroyAll() {
|
|
3071
3078
|
await this.getInstance().destroyAll();
|
|
3072
3079
|
}
|
|
3073
|
-
static createModel(name
|
|
3074
|
-
return this.getInstance().createModel(name
|
|
3080
|
+
static createModel(name, options) {
|
|
3081
|
+
return this.getInstance().createModel(name, options);
|
|
3075
3082
|
}
|
|
3076
3083
|
connection(connection = null) {
|
|
3077
3084
|
return this.getConnection(connection);
|
|
3078
3085
|
}
|
|
3079
|
-
getConnection(name
|
|
3080
|
-
name
|
|
3081
|
-
const resolvedName = this.connections[name
|
|
3086
|
+
getConnection(name = null) {
|
|
3087
|
+
name = name || "default";
|
|
3088
|
+
const resolvedName = this.connections[name] ? name : "default";
|
|
3082
3089
|
if (this.manager[resolvedName] === void 0) {
|
|
3083
3090
|
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
3084
3091
|
this.manager[resolvedName] = queryBuilder;
|
|
3085
3092
|
}
|
|
3086
3093
|
return this.manager[resolvedName];
|
|
3087
3094
|
}
|
|
3088
|
-
addConnection(config, name
|
|
3089
|
-
this.connections[name
|
|
3095
|
+
addConnection(config, name = "default") {
|
|
3096
|
+
this.connections[name] = {
|
|
3090
3097
|
...config,
|
|
3091
3098
|
connection: {
|
|
3092
3099
|
...config.connection,
|
|
@@ -3148,8 +3155,8 @@ var arquebus = class arquebus {
|
|
|
3148
3155
|
transaction(callback, connection = null) {
|
|
3149
3156
|
return this.connection(connection).transaction(callback);
|
|
3150
3157
|
}
|
|
3151
|
-
table(name
|
|
3152
|
-
return this.connection(connection).table(name
|
|
3158
|
+
table(name, connection = null) {
|
|
3159
|
+
return this.connection(connection).table(name);
|
|
3153
3160
|
}
|
|
3154
3161
|
schema(connection = null) {
|
|
3155
3162
|
return this.connection(connection).schema;
|
|
@@ -3159,12 +3166,12 @@ var arquebus = class arquebus {
|
|
|
3159
3166
|
return connection === null || connection === void 0 ? void 0 : connection.destroy();
|
|
3160
3167
|
}));
|
|
3161
3168
|
}
|
|
3162
|
-
createModel(name
|
|
3169
|
+
createModel(name, options = {}) {
|
|
3163
3170
|
let BaseModel$1 = Model;
|
|
3164
3171
|
if ("plugins" in options) BaseModel$1 = compose(BaseModel$1, ...options.plugins ?? []);
|
|
3165
3172
|
this.models = {
|
|
3166
3173
|
...this.models,
|
|
3167
|
-
[name
|
|
3174
|
+
[name]: class extends BaseModel$1 {
|
|
3168
3175
|
table = (options === null || options === void 0 ? void 0 : options.table) ?? null;
|
|
3169
3176
|
connection = (options === null || options === void 0 ? void 0 : options.connection) ?? null;
|
|
3170
3177
|
timestamps = (options === null || options === void 0 ? void 0 : options.timestamps) ?? true;
|
|
@@ -3180,18 +3187,18 @@ var arquebus = class arquebus {
|
|
|
3180
3187
|
};
|
|
3181
3188
|
if ("attributes" in options) for (const attribute in options.attributes) {
|
|
3182
3189
|
if (options.attributes[attribute] instanceof attribute_default === false) throw new Error("Attribute must be an instance of \"Attribute\"");
|
|
3183
|
-
this.models[name
|
|
3190
|
+
this.models[name].prototype[getAttrMethod(attribute)] = () => {
|
|
3184
3191
|
var _options$attributes;
|
|
3185
3192
|
return (_options$attributes = options.attributes) === null || _options$attributes === void 0 ? void 0 : _options$attributes[attribute];
|
|
3186
3193
|
};
|
|
3187
3194
|
}
|
|
3188
|
-
if ("relations" in options) for (const relation in options.relations) this.models[name
|
|
3195
|
+
if ("relations" in options) for (const relation in options.relations) this.models[name].prototype[getRelationMethod(relation)] = function() {
|
|
3189
3196
|
var _options$relations;
|
|
3190
3197
|
return (_options$relations = options.relations) === null || _options$relations === void 0 ? void 0 : _options$relations[relation](this);
|
|
3191
3198
|
};
|
|
3192
|
-
if ("scopes" in options) for (const scope in options.scopes) this.models[name
|
|
3193
|
-
this.models[name
|
|
3194
|
-
return this.models[name
|
|
3199
|
+
if ("scopes" in options) for (const scope in options.scopes) this.models[name].prototype[getScopeMethod(scope)] = options.scopes[scope];
|
|
3200
|
+
this.models[name].setConnectionResolver(this);
|
|
3201
|
+
return this.models[name];
|
|
3195
3202
|
}
|
|
3196
3203
|
};
|
|
3197
3204
|
var arquebus_default = arquebus;
|
|
@@ -3351,8 +3358,8 @@ var Model = class Model extends BaseModel {
|
|
|
3351
3358
|
}
|
|
3352
3359
|
return builder;
|
|
3353
3360
|
}
|
|
3354
|
-
hasNamedScope(name
|
|
3355
|
-
const scope = getScopeMethod(name
|
|
3361
|
+
hasNamedScope(name) {
|
|
3362
|
+
const scope = getScopeMethod(name);
|
|
3356
3363
|
return typeof this[scope] === "function";
|
|
3357
3364
|
}
|
|
3358
3365
|
callNamedScope(scope, parameters) {
|
|
@@ -3836,8 +3843,8 @@ const InteractsWithPivotTable = (Relation$1) => {
|
|
|
3836
3843
|
castKey(key) {
|
|
3837
3844
|
return this.getTypeSwapValue(this.related.getKeyType(), key);
|
|
3838
3845
|
}
|
|
3839
|
-
getTypeSwapValue(type
|
|
3840
|
-
switch (type
|
|
3846
|
+
getTypeSwapValue(type, value) {
|
|
3847
|
+
switch (type.toLowerCase()) {
|
|
3841
3848
|
case "int":
|
|
3842
3849
|
case "integer": return parseInt(value);
|
|
3843
3850
|
case "real":
|
|
@@ -4042,8 +4049,7 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
4042
4049
|
return columns.concat(this.aliasedPivotColumns());
|
|
4043
4050
|
}
|
|
4044
4051
|
aliasedPivotColumns() {
|
|
4045
|
-
|
|
4046
|
-
return (0, collect_js.collect)(defaults.concat(this.pivotColumns)).map((column) => {
|
|
4052
|
+
return (0, collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
|
|
4047
4053
|
return this.qualifyPivotColumn(column) + " as pivot_" + column;
|
|
4048
4054
|
}).unique().all();
|
|
4049
4055
|
}
|
|
@@ -4336,8 +4342,7 @@ var Builder = class Builder extends Inference {
|
|
|
4336
4342
|
}
|
|
4337
4343
|
addUpdatedAtColumn(values) {
|
|
4338
4344
|
if (!this.model.usesTimestamps() || this.model.getUpdatedAtColumn() === null) return values;
|
|
4339
|
-
|
|
4340
|
-
values = (0, radashi.assign)({ [column]: this.model.freshTimestampString() }, values);
|
|
4345
|
+
values = (0, radashi.assign)({ [this.model.getUpdatedAtColumn()]: this.model.freshTimestampString() }, values);
|
|
4341
4346
|
return values;
|
|
4342
4347
|
}
|
|
4343
4348
|
delete() {
|
|
@@ -4387,8 +4392,8 @@ var Builder = class Builder extends Inference {
|
|
|
4387
4392
|
}
|
|
4388
4393
|
return this;
|
|
4389
4394
|
}
|
|
4390
|
-
hasNamedScope(name
|
|
4391
|
-
return this.model && this.model.hasNamedScope(name
|
|
4395
|
+
hasNamedScope(name) {
|
|
4396
|
+
return this.model && this.model.hasNamedScope(name);
|
|
4392
4397
|
}
|
|
4393
4398
|
callNamedScope(scope, parameters) {
|
|
4394
4399
|
return this.model.callNamedScope(scope, [this, ...parameters]);
|
|
@@ -4413,15 +4418,15 @@ var Builder = class Builder extends Inference {
|
|
|
4413
4418
|
this.globalScopes = (0, radashi.omit)(this.globalScopes, [scope]);
|
|
4414
4419
|
return this;
|
|
4415
4420
|
}
|
|
4416
|
-
macro(name
|
|
4417
|
-
this.localMacros[name
|
|
4421
|
+
macro(name, callback) {
|
|
4422
|
+
this.localMacros[name] = callback;
|
|
4418
4423
|
return this;
|
|
4419
4424
|
}
|
|
4420
|
-
hasMacro(name
|
|
4421
|
-
return name
|
|
4425
|
+
hasMacro(name) {
|
|
4426
|
+
return name in this.localMacros;
|
|
4422
4427
|
}
|
|
4423
|
-
getMacro(name
|
|
4424
|
-
return this.localMacros[name
|
|
4428
|
+
getMacro(name) {
|
|
4429
|
+
return this.localMacros[name];
|
|
4425
4430
|
}
|
|
4426
4431
|
with(...args) {
|
|
4427
4432
|
let eagerLoads = {};
|
|
@@ -4502,8 +4507,8 @@ var Builder = class Builder extends Inference {
|
|
|
4502
4507
|
return this.canUseExistsForExistenceCheck(operator, count) ? this.addWhereExistsQuery(hasQuery.getQuery(), boolean, operator === "<" && count === 1) : this.addWhereCountQuery(hasQuery.getQuery(), operator, count, boolean);
|
|
4503
4508
|
}
|
|
4504
4509
|
addWhereExistsQuery(query, boolean = "and", not = false) {
|
|
4505
|
-
const type
|
|
4506
|
-
const method = boolean === "and" ? "where" + type
|
|
4510
|
+
const type = not ? "NotExists" : "Exists";
|
|
4511
|
+
const method = boolean === "and" ? "where" + type : "orWhere" + type;
|
|
4507
4512
|
this[method](query.connector);
|
|
4508
4513
|
return this;
|
|
4509
4514
|
}
|
|
@@ -4525,12 +4530,12 @@ var Builder = class Builder extends Inference {
|
|
|
4525
4530
|
const db = this.model.getConnection();
|
|
4526
4531
|
if (this.query._statements.filter((item) => item.grouping == "columns").map((item) => item.value).flat().length === 0) this.query.select([this.query._single.table + ".*"]);
|
|
4527
4532
|
const parses = this.parseWithRelations(relations);
|
|
4528
|
-
for (let name
|
|
4529
|
-
const constraints = parses[name
|
|
4530
|
-
const segments = name
|
|
4533
|
+
for (let name in parses) {
|
|
4534
|
+
const constraints = parses[name];
|
|
4535
|
+
const segments = name.split(" ");
|
|
4531
4536
|
let alias, expression;
|
|
4532
|
-
if (segments.length === 3 && segments[1].toLocaleLowerCase() === "as") [name
|
|
4533
|
-
const relation = this.getRelationWithoutConstraints(getRelationMethod(name
|
|
4537
|
+
if (segments.length === 3 && segments[1].toLocaleLowerCase() === "as") [name, alias] = [segments[0], segments[2]];
|
|
4538
|
+
const relation = this.getRelationWithoutConstraints(getRelationMethod(name));
|
|
4534
4539
|
if (action) {
|
|
4535
4540
|
const hashedColumn = this.query._single.table === relation.query.query._single.table ? `${relation.getRelationCountHash(false)}.${column}` : column;
|
|
4536
4541
|
const wrappedColumn = column === "*" ? column : relation.getRelated().qualifyColumn(hashedColumn);
|
|
@@ -4538,7 +4543,7 @@ var Builder = class Builder extends Inference {
|
|
|
4538
4543
|
} else expression = column;
|
|
4539
4544
|
const query = relation.getRelationExistenceQuery(relation.getRelated().newModelQuery(), this, db.raw(expression));
|
|
4540
4545
|
constraints(query);
|
|
4541
|
-
alias = alias || (0, radashi.snake)(`${name
|
|
4546
|
+
alias = alias || (0, radashi.snake)(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
|
|
4542
4547
|
if (action === "exists") this.select(db.raw(`exists(${query.toSql().sql}) as ${alias}`));
|
|
4543
4548
|
else this.selectSub(action ? query : query.limit(1), alias);
|
|
4544
4549
|
}
|
|
@@ -4599,15 +4604,15 @@ var Builder = class Builder extends Inference {
|
|
|
4599
4604
|
if (relations.length === 0) return [];
|
|
4600
4605
|
let results = {};
|
|
4601
4606
|
const constraintsMap = this.prepareNestedWithRelationships(relations);
|
|
4602
|
-
for (const name
|
|
4603
|
-
results = this.addNestedWiths(name
|
|
4604
|
-
results[name
|
|
4607
|
+
for (const name in constraintsMap) {
|
|
4608
|
+
results = this.addNestedWiths(name, results);
|
|
4609
|
+
results[name] = constraintsMap[name];
|
|
4605
4610
|
}
|
|
4606
4611
|
return results;
|
|
4607
4612
|
}
|
|
4608
|
-
addNestedWiths(name
|
|
4613
|
+
addNestedWiths(name, results) {
|
|
4609
4614
|
const progress = [];
|
|
4610
|
-
name
|
|
4615
|
+
name.split(".").map((segment) => {
|
|
4611
4616
|
progress.push(segment);
|
|
4612
4617
|
const last = progress.join(".");
|
|
4613
4618
|
if (results[last] === void 0) results[last] = () => {};
|
|
@@ -4640,22 +4645,19 @@ var Builder = class Builder extends Inference {
|
|
|
4640
4645
|
return builder;
|
|
4641
4646
|
};
|
|
4642
4647
|
}
|
|
4643
|
-
parseNameAndAttributeSelectionConstraint(name
|
|
4644
|
-
return name
|
|
4648
|
+
parseNameAndAttributeSelectionConstraint(name, value) {
|
|
4649
|
+
return name.includes(":") ? this.createSelectWithConstraint(name) : [name, value];
|
|
4645
4650
|
}
|
|
4646
|
-
createSelectWithConstraint(name
|
|
4647
|
-
return [name
|
|
4648
|
-
query.select(name
|
|
4651
|
+
createSelectWithConstraint(name) {
|
|
4652
|
+
return [name.split(":")[0], (query) => {
|
|
4653
|
+
query.select(name.split(":")[1].split(",").map((column) => {
|
|
4649
4654
|
if (column.includes(".")) return column;
|
|
4650
4655
|
return query instanceof belongs_to_many_default ? query.related.getTable() + "." + column : column;
|
|
4651
4656
|
}));
|
|
4652
4657
|
}];
|
|
4653
4658
|
}
|
|
4654
4659
|
related(relation) {
|
|
4655
|
-
if (typeof this.model[getRelationMethod(relation)] !== "function") {
|
|
4656
|
-
const message = `Model [${this.model.constructor.name}]'s relation [${relation}] doesn't exist.`;
|
|
4657
|
-
throw new RelationNotFoundError(message);
|
|
4658
|
-
}
|
|
4660
|
+
if (typeof this.model[getRelationMethod(relation)] !== "function") throw new RelationNotFoundError(`Model [${this.model.constructor.name}]'s relation [${relation}] doesn't exist.`);
|
|
4659
4661
|
return this.model[getRelationMethod(relation)]();
|
|
4660
4662
|
}
|
|
4661
4663
|
take(...args) {
|
|
@@ -4728,8 +4730,7 @@ var Builder = class Builder extends Inference {
|
|
|
4728
4730
|
return await this.whereIn(this.model.getKeyName(), ids).get(columns);
|
|
4729
4731
|
}
|
|
4730
4732
|
async pluck(column) {
|
|
4731
|
-
|
|
4732
|
-
return new collection_default(data);
|
|
4733
|
+
return new collection_default(await this.query.pluck(column));
|
|
4733
4734
|
}
|
|
4734
4735
|
async destroy(ids) {
|
|
4735
4736
|
if (ids instanceof collection_default) ids = ids.modelKeys();
|
|
@@ -4773,37 +4774,34 @@ var Builder = class Builder extends Inference {
|
|
|
4773
4774
|
}
|
|
4774
4775
|
return this.hydrate(await this.query.get()).all();
|
|
4775
4776
|
}
|
|
4776
|
-
getRelation(name
|
|
4777
|
-
if (typeof this.model[getRelationMethod(name
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
}
|
|
4781
|
-
const relation = relation_default.noConstraints(() => this.model.newInstance(this.model.attributes)[getRelationMethod(name$1)]());
|
|
4782
|
-
const nested = this.relationsNestedUnder(name$1);
|
|
4777
|
+
getRelation(name) {
|
|
4778
|
+
if (typeof this.model[getRelationMethod(name)] !== "function") throw new RelationNotFoundError(`Model [${this.model.constructor.name}]'s relation [${name}] doesn't exist.`);
|
|
4779
|
+
const relation = relation_default.noConstraints(() => this.model.newInstance(this.model.attributes)[getRelationMethod(name)]());
|
|
4780
|
+
const nested = this.relationsNestedUnder(name);
|
|
4783
4781
|
if (Object.keys(nested).length > 0) relation.query.with(nested);
|
|
4784
4782
|
return relation.asProxy();
|
|
4785
4783
|
}
|
|
4786
4784
|
relationsNestedUnder(relation) {
|
|
4787
4785
|
const nested = {};
|
|
4788
|
-
for (const name
|
|
4789
|
-
const constraints = this.eagerLoad[name
|
|
4790
|
-
if (this.isNestedUnder(relation, name
|
|
4786
|
+
for (const name in this.eagerLoad) {
|
|
4787
|
+
const constraints = this.eagerLoad[name];
|
|
4788
|
+
if (this.isNestedUnder(relation, name)) nested[name.substring((relation + ".").length)] = constraints;
|
|
4791
4789
|
}
|
|
4792
4790
|
return nested;
|
|
4793
4791
|
}
|
|
4794
|
-
isNestedUnder(relation, name
|
|
4795
|
-
return name
|
|
4792
|
+
isNestedUnder(relation, name) {
|
|
4793
|
+
return name.includes(".") && name.startsWith(relation + ".");
|
|
4796
4794
|
}
|
|
4797
|
-
async eagerLoadRelation(models, name
|
|
4798
|
-
const relation = this.getRelation(name
|
|
4795
|
+
async eagerLoadRelation(models, name, constraints) {
|
|
4796
|
+
const relation = this.getRelation(name);
|
|
4799
4797
|
relation.addEagerConstraints(models);
|
|
4800
4798
|
constraints(relation);
|
|
4801
|
-
return relation.match(relation.initRelation(models, name
|
|
4799
|
+
return relation.match(relation.initRelation(models, name), await relation.get(), name);
|
|
4802
4800
|
}
|
|
4803
4801
|
async eagerLoadRelations(models) {
|
|
4804
|
-
for (const name
|
|
4805
|
-
const constraints = this.eagerLoad[name
|
|
4806
|
-
if (!name
|
|
4802
|
+
for (const name in this.eagerLoad) {
|
|
4803
|
+
const constraints = this.eagerLoad[name];
|
|
4804
|
+
if (!name.includes(".")) models = await this.eagerLoadRelation(models, name, constraints);
|
|
4807
4805
|
}
|
|
4808
4806
|
return models;
|
|
4809
4807
|
}
|
|
@@ -4816,6 +4814,79 @@ var Builder = class Builder extends Inference {
|
|
|
4816
4814
|
};
|
|
4817
4815
|
var builder_default = Builder;
|
|
4818
4816
|
|
|
4817
|
+
//#endregion
|
|
4818
|
+
//#region src/seeders/runner.ts
|
|
4819
|
+
async function glob$1(folderPath) {
|
|
4820
|
+
const { default: escalade } = await import("escalade");
|
|
4821
|
+
const entries = [];
|
|
4822
|
+
await escalade(folderPath, async (dir, names) => {
|
|
4823
|
+
await Promise.all(names.map(async (name) => {
|
|
4824
|
+
const p = path.default.join(dir, name);
|
|
4825
|
+
try {
|
|
4826
|
+
await (0, node_fs_promises.access)(p);
|
|
4827
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
4828
|
+
} catch {}
|
|
4829
|
+
}));
|
|
4830
|
+
return "";
|
|
4831
|
+
});
|
|
4832
|
+
return entries;
|
|
4833
|
+
}
|
|
4834
|
+
var SeederRunner = class {
|
|
4835
|
+
resolver;
|
|
4836
|
+
connection;
|
|
4837
|
+
paths = [];
|
|
4838
|
+
constructor(resolver) {
|
|
4839
|
+
this.resolver = resolver;
|
|
4840
|
+
}
|
|
4841
|
+
path(p) {
|
|
4842
|
+
this.paths = Array.from(new Set([...this.paths, p]));
|
|
4843
|
+
}
|
|
4844
|
+
getPaths() {
|
|
4845
|
+
return this.paths;
|
|
4846
|
+
}
|
|
4847
|
+
resolveConnection(connection) {
|
|
4848
|
+
var _getInstance, _ref, _instance$connections;
|
|
4849
|
+
const name = connection || this.connection || "default";
|
|
4850
|
+
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
4851
|
+
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
4852
|
+
/** noop */
|
|
4853
|
+
});
|
|
4854
|
+
return this.resolver.fire(name);
|
|
4855
|
+
}
|
|
4856
|
+
setConnection(connection) {
|
|
4857
|
+
this.connection = connection;
|
|
4858
|
+
return this;
|
|
4859
|
+
}
|
|
4860
|
+
async getSeederFiles(paths) {
|
|
4861
|
+
const files = [];
|
|
4862
|
+
for (const p of paths) {
|
|
4863
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
4864
|
+
files.push(p);
|
|
4865
|
+
continue;
|
|
4866
|
+
}
|
|
4867
|
+
files.push(...await glob$1(p));
|
|
4868
|
+
}
|
|
4869
|
+
return files;
|
|
4870
|
+
}
|
|
4871
|
+
async resolvePath(filePath) {
|
|
4872
|
+
try {
|
|
4873
|
+
const mod = await import(filePath);
|
|
4874
|
+
return new (mod.default ?? mod.Seeder)();
|
|
4875
|
+
} catch {
|
|
4876
|
+
return null;
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
async run(paths, connection) {
|
|
4880
|
+
const files = await this.getSeederFiles(paths);
|
|
4881
|
+
const conn = this.resolveConnection(connection);
|
|
4882
|
+
for (const file of files) {
|
|
4883
|
+
const seeder = await this.resolvePath(file);
|
|
4884
|
+
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
};
|
|
4888
|
+
var runner_default = SeederRunner;
|
|
4889
|
+
|
|
4819
4890
|
//#endregion
|
|
4820
4891
|
//#region src/inspector/dialects/sqlite.ts
|
|
4821
4892
|
function parseDefaultValue(value) {
|
|
@@ -4831,7 +4902,7 @@ var SQLite = class {
|
|
|
4831
4902
|
* List all existing tables in the current schema/database
|
|
4832
4903
|
*/
|
|
4833
4904
|
async tables() {
|
|
4834
|
-
return (await this.knex.select("name").from("sqlite_master").whereRaw("type = 'table' AND name NOT LIKE 'sqlite_%'")).map(({ name
|
|
4905
|
+
return (await this.knex.select("name").from("sqlite_master").whereRaw("type = 'table' AND name NOT LIKE 'sqlite_%'")).map(({ name }) => name);
|
|
4835
4906
|
}
|
|
4836
4907
|
async tableInfo(table) {
|
|
4837
4908
|
const query = this.knex.select("name", "sql").from("sqlite_master").where({ type: "table" }).andWhereRaw("name NOT LIKE 'sqlite_%'");
|
|
@@ -4862,12 +4933,11 @@ var SQLite = class {
|
|
|
4862
4933
|
column: column.name
|
|
4863
4934
|
}));
|
|
4864
4935
|
const tables = await this.tables();
|
|
4865
|
-
|
|
4866
|
-
return flatten(columnsPerTable);
|
|
4936
|
+
return flatten(await Promise.all(tables.map(async (table$1) => await this.columns(table$1))));
|
|
4867
4937
|
}
|
|
4868
4938
|
async columnInfo(table, column) {
|
|
4869
4939
|
const getColumnsForTable = async (table$1) => {
|
|
4870
|
-
const tablesWithAutoIncrementPrimaryKeys = (await this.knex.select("name").from("sqlite_master").whereRaw("sql LIKE '%AUTOINCREMENT%'")).map(({ name
|
|
4940
|
+
const tablesWithAutoIncrementPrimaryKeys = (await this.knex.select("name").from("sqlite_master").whereRaw("sql LIKE '%AUTOINCREMENT%'")).map(({ name }) => name);
|
|
4871
4941
|
const columns = await this.knex.raw("PRAGMA table_xinfo(??)", table$1);
|
|
4872
4942
|
const foreignKeys = await this.knex.raw("PRAGMA foreign_key_list(??)", table$1);
|
|
4873
4943
|
const indexList = await this.knex.raw("PRAGMA index_list(??)", table$1);
|
|
@@ -4898,8 +4968,7 @@ var SQLite = class {
|
|
|
4898
4968
|
};
|
|
4899
4969
|
if (!table) {
|
|
4900
4970
|
const tables = await this.tables();
|
|
4901
|
-
|
|
4902
|
-
return flatten(columnsPerTable);
|
|
4971
|
+
return flatten(await Promise.all(tables.map(async (table$1) => await getColumnsForTable(table$1))));
|
|
4903
4972
|
}
|
|
4904
4973
|
if (table && !column) return await getColumnsForTable(table);
|
|
4905
4974
|
return (await getColumnsForTable(table)).find((columnInfo) => columnInfo.name === column);
|
|
@@ -4930,8 +4999,7 @@ var SQLite = class {
|
|
|
4930
4999
|
constraint_name: null
|
|
4931
5000
|
}));
|
|
4932
5001
|
const tables = await this.tables();
|
|
4933
|
-
|
|
4934
|
-
return flatten(keysPerTable);
|
|
5002
|
+
return flatten(await Promise.all(tables.map(async (table$1) => await this.foreignKeys(table$1))));
|
|
4935
5003
|
}
|
|
4936
5004
|
async uniqueConstraints(table) {
|
|
4937
5005
|
if (table) {
|
|
@@ -4947,8 +5015,7 @@ var SQLite = class {
|
|
|
4947
5015
|
});
|
|
4948
5016
|
}
|
|
4949
5017
|
const tables = await this.tables();
|
|
4950
|
-
|
|
4951
|
-
return flatten(constraintsPerTable);
|
|
5018
|
+
return flatten(await Promise.all(tables.map(async (table$1) => await this.uniqueConstraints(table$1))));
|
|
4952
5019
|
}
|
|
4953
5020
|
};
|
|
4954
5021
|
|
|
@@ -4988,9 +5055,9 @@ var SchemaInspector = class {
|
|
|
4988
5055
|
//#endregion
|
|
4989
5056
|
//#region src/migrations/migrator.ts
|
|
4990
5057
|
async function glob(folderPath) {
|
|
4991
|
-
const files
|
|
5058
|
+
const files = await node_fs_promises.default.readdir(folderPath);
|
|
4992
5059
|
const allFiles = [];
|
|
4993
|
-
for (const file of files
|
|
5060
|
+
for (const file of files) {
|
|
4994
5061
|
const filePath = `${folderPath}/${file}`;
|
|
4995
5062
|
const stats = await node_fs_promises.default.stat(filePath);
|
|
4996
5063
|
if (stats.isFile()) allFiles.push(filePath);
|
|
@@ -5009,21 +5076,21 @@ var Migrator = class {
|
|
|
5009
5076
|
connection;
|
|
5010
5077
|
paths = [];
|
|
5011
5078
|
output = null;
|
|
5012
|
-
constructor(repository
|
|
5013
|
-
this.repository = repository
|
|
5014
|
-
this.files = files
|
|
5079
|
+
constructor(repository, resolver = null, files = null, dispatcher = null) {
|
|
5080
|
+
this.repository = repository;
|
|
5081
|
+
this.files = files;
|
|
5015
5082
|
this.resolver = resolver;
|
|
5016
5083
|
this.events = dispatcher;
|
|
5017
5084
|
}
|
|
5018
5085
|
async run(paths = [], options = {}) {
|
|
5019
|
-
const files
|
|
5086
|
+
const files = await this.getMigrationFiles(paths);
|
|
5020
5087
|
const ran = await this.repository.getRan();
|
|
5021
|
-
const migrations = this.pendingMigrations(files
|
|
5088
|
+
const migrations = this.pendingMigrations(files, ran);
|
|
5022
5089
|
await this.runPending(migrations, options);
|
|
5023
5090
|
return migrations;
|
|
5024
5091
|
}
|
|
5025
|
-
pendingMigrations(files
|
|
5026
|
-
return Object.values(files
|
|
5092
|
+
pendingMigrations(files, ran) {
|
|
5093
|
+
return Object.values(files).filter((file) => !ran.includes(this.getMigrationName(file)));
|
|
5027
5094
|
}
|
|
5028
5095
|
async runPending(migrations, options = {}) {
|
|
5029
5096
|
if (migrations.length === 0 && !options.quiet) {
|
|
@@ -5041,14 +5108,14 @@ var Migrator = class {
|
|
|
5041
5108
|
}
|
|
5042
5109
|
async runUp(file, batch, _pretend) {
|
|
5043
5110
|
const migration = await this.resolvePath(file);
|
|
5044
|
-
const name
|
|
5045
|
-
await __h3ravel_shared.TaskManager.taskRunner(name
|
|
5046
|
-
await this.repository.log(name
|
|
5111
|
+
const name = this.getMigrationName(file);
|
|
5112
|
+
await __h3ravel_shared.TaskManager.taskRunner(name, () => this.runMigration(migration, "up"));
|
|
5113
|
+
await this.repository.log(name, batch);
|
|
5047
5114
|
}
|
|
5048
5115
|
async runDown(file, migration, _pretend) {
|
|
5049
5116
|
const instance = await this.resolvePath(file);
|
|
5050
|
-
const name
|
|
5051
|
-
await __h3ravel_shared.TaskManager.taskRunner(name
|
|
5117
|
+
const name = this.getMigrationName(file);
|
|
5118
|
+
await __h3ravel_shared.TaskManager.taskRunner(name, () => this.runMigration(instance, "down"));
|
|
5052
5119
|
await this.repository.delete(migration);
|
|
5053
5120
|
}
|
|
5054
5121
|
async rollback(paths = [], options = {}) {
|
|
@@ -5066,10 +5133,10 @@ var Migrator = class {
|
|
|
5066
5133
|
}
|
|
5067
5134
|
async rollbackMigrations(migrations, paths, options) {
|
|
5068
5135
|
const rolledBack = [];
|
|
5069
|
-
const files
|
|
5136
|
+
const files = await this.getMigrationFiles(paths);
|
|
5070
5137
|
__h3ravel_shared.Logger.info("INFO: Rolling back migrations...");
|
|
5071
5138
|
for (const migration of migrations) {
|
|
5072
|
-
const file = files
|
|
5139
|
+
const file = files[migration.migration];
|
|
5073
5140
|
if (!file) {
|
|
5074
5141
|
__h3ravel_shared.Logger.twoColumnDetail(__h3ravel_shared.Logger.parse([[migration.migration, "green"]], "", false), __h3ravel_shared.Logger.parse([["Migration not found", "yellow"]], "", false));
|
|
5075
5142
|
continue;
|
|
@@ -5132,15 +5199,15 @@ var Migrator = class {
|
|
|
5132
5199
|
return migrationName.split("_").slice(4).map((str) => str.charAt(0).toUpperCase() + str.slice(1)).join("");
|
|
5133
5200
|
}
|
|
5134
5201
|
async getMigrationFiles(paths) {
|
|
5135
|
-
const files
|
|
5202
|
+
const files = [];
|
|
5136
5203
|
for (const p of paths) {
|
|
5137
5204
|
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
5138
|
-
files
|
|
5205
|
+
files.push(p);
|
|
5139
5206
|
continue;
|
|
5140
5207
|
}
|
|
5141
|
-
files
|
|
5208
|
+
files.push(...await glob(p));
|
|
5142
5209
|
}
|
|
5143
|
-
return files
|
|
5210
|
+
return files.filter(Boolean).reduce((result, file) => {
|
|
5144
5211
|
result[this.getMigrationName(file)] = file;
|
|
5145
5212
|
return result;
|
|
5146
5213
|
}, {});
|
|
@@ -5295,21 +5362,19 @@ var Migrate = class {
|
|
|
5295
5362
|
const getAllMigrationFiles = async () => {
|
|
5296
5363
|
return await migrator.getMigrationFiles(await Utils.getMigrationPaths(this.basePath ?? process.cwd(), migrator, config.migrations.path, options.path));
|
|
5297
5364
|
};
|
|
5298
|
-
async function getStatusFor(ran
|
|
5299
|
-
const files
|
|
5300
|
-
return Object.values(files
|
|
5365
|
+
async function getStatusFor(ran, batches) {
|
|
5366
|
+
const files = await getAllMigrationFiles();
|
|
5367
|
+
return Object.values(files).map((migration) => {
|
|
5301
5368
|
const migrationName = migrator.getMigrationName(migration);
|
|
5302
5369
|
return {
|
|
5303
5370
|
name: migrationName,
|
|
5304
|
-
ran: ran
|
|
5305
|
-
batch: ran
|
|
5371
|
+
ran: ran.includes(migrationName),
|
|
5372
|
+
batch: ran.includes(migrationName) ? batches[migrationName] : null
|
|
5306
5373
|
};
|
|
5307
5374
|
});
|
|
5308
5375
|
}
|
|
5309
5376
|
if (!await migrator.repositoryExists()) this.callback("ERROR: Migration table does not exist.", "error");
|
|
5310
|
-
const
|
|
5311
|
-
const batches = await migrator.getRepository().getMigrationBatches();
|
|
5312
|
-
const migrations = await getStatusFor(ran, batches);
|
|
5377
|
+
const migrations = await getStatusFor(await migrator.repository.getRan(), await migrator.getRepository().getMigrationBatches());
|
|
5313
5378
|
if (destroyAll) await arquebus$1.destroyAll();
|
|
5314
5379
|
return migrations;
|
|
5315
5380
|
}
|
|
@@ -5324,15 +5389,13 @@ var Migrate = class {
|
|
|
5324
5389
|
const table = (config === null || config === void 0 || (_config$migrations = config.migrations) === null || _config$migrations === void 0 ? void 0 : _config$migrations.table) || "migrations";
|
|
5325
5390
|
if (config.skipConnection !== true) {
|
|
5326
5391
|
arquebus_default.addConnection(config, "default");
|
|
5327
|
-
Object.entries(config.connections || {}).forEach(([name
|
|
5328
|
-
arquebus_default.addConnection(connection, name
|
|
5392
|
+
Object.entries(config.connections || {}).forEach(([name, connection]) => {
|
|
5393
|
+
arquebus_default.addConnection(connection, name);
|
|
5329
5394
|
});
|
|
5330
5395
|
}
|
|
5331
|
-
const repository$1 = new MigrationRepository(arquebus_default, table);
|
|
5332
|
-
const migrator = new migrator_default(repository$1, arquebus_default);
|
|
5333
5396
|
return {
|
|
5334
5397
|
arquebus: arquebus_default,
|
|
5335
|
-
migrator
|
|
5398
|
+
migrator: new migrator_default(new MigrationRepository(arquebus_default, table), arquebus_default)
|
|
5336
5399
|
};
|
|
5337
5400
|
}
|
|
5338
5401
|
};
|
|
@@ -5341,9 +5404,9 @@ var Migrate = class {
|
|
|
5341
5404
|
//#region src/migrations/migration-creator.ts
|
|
5342
5405
|
var MigrationCreator = class {
|
|
5343
5406
|
postCreate = [];
|
|
5344
|
-
constructor(customStubPath, type
|
|
5407
|
+
constructor(customStubPath, type = "js") {
|
|
5345
5408
|
this.customStubPath = customStubPath;
|
|
5346
|
-
this.type = type
|
|
5409
|
+
this.type = type;
|
|
5347
5410
|
}
|
|
5348
5411
|
/**
|
|
5349
5412
|
* Create a new migration file
|
|
@@ -5354,9 +5417,9 @@ var MigrationCreator = class {
|
|
|
5354
5417
|
* @param create
|
|
5355
5418
|
* @returns
|
|
5356
5419
|
*/
|
|
5357
|
-
async create(name
|
|
5420
|
+
async create(name, dir, table, create = false) {
|
|
5358
5421
|
const stub = await this.getStub(table, create);
|
|
5359
|
-
const filePath = this.getPath(name
|
|
5422
|
+
const filePath = this.getPath(name, dir);
|
|
5360
5423
|
await this.ensureDirectoryExists(path.default.dirname(filePath));
|
|
5361
5424
|
await (0, node_fs_promises.writeFile)(filePath, this.populateStub(stub, table));
|
|
5362
5425
|
await this.firePostCreateHooks(table, filePath);
|
|
@@ -5397,12 +5460,12 @@ var MigrationCreator = class {
|
|
|
5397
5460
|
if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
5398
5461
|
return stub;
|
|
5399
5462
|
}
|
|
5400
|
-
getClassName(name
|
|
5401
|
-
return name
|
|
5463
|
+
getClassName(name) {
|
|
5464
|
+
return name.replace(/_+([a-z])/g, (match, char) => char.toUpperCase());
|
|
5402
5465
|
}
|
|
5403
|
-
getPath(name
|
|
5466
|
+
getPath(name, dir) {
|
|
5404
5467
|
const datePrefix = (0, dayjs.default)().format("YYYY_MM_DD_HHmmss");
|
|
5405
|
-
return path.default.join(dir, `${datePrefix}_${name
|
|
5468
|
+
return path.default.join(dir, `${datePrefix}_${name}.${this.type}`);
|
|
5406
5469
|
}
|
|
5407
5470
|
async firePostCreateHooks(table, filePath) {
|
|
5408
5471
|
for (const callback of this.postCreate) await callback(table, filePath);
|
|
@@ -5426,224 +5489,7 @@ var MigrationCreator = class {
|
|
|
5426
5489
|
|
|
5427
5490
|
//#endregion
|
|
5428
5491
|
//#region package.json
|
|
5429
|
-
var
|
|
5430
|
-
var version = "0.6.6";
|
|
5431
|
-
var packageManager = "pnpm@10.14.0";
|
|
5432
|
-
var description = "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.";
|
|
5433
|
-
var homepage = "https://h3ravel.toneflix.net/arquebus";
|
|
5434
|
-
var bin = { "arquebus": "./bin/index.js" };
|
|
5435
|
-
var publishConfig = { "access": "public" };
|
|
5436
|
-
var main = "./dist/index.cjs";
|
|
5437
|
-
var module$1 = "./dist/index.js";
|
|
5438
|
-
var type = "module";
|
|
5439
|
-
var types = "./dist/index.d.ts";
|
|
5440
|
-
var files = [
|
|
5441
|
-
"dist",
|
|
5442
|
-
"bin",
|
|
5443
|
-
"types"
|
|
5444
|
-
];
|
|
5445
|
-
var exports$1 = {
|
|
5446
|
-
".": {
|
|
5447
|
-
"cli": {
|
|
5448
|
-
"import": {
|
|
5449
|
-
"types": "./bin/index.d.ts",
|
|
5450
|
-
"default": "./bin/index.js"
|
|
5451
|
-
},
|
|
5452
|
-
"require": {
|
|
5453
|
-
"types": "./bin/index.d.cts",
|
|
5454
|
-
"default": "./bin/index.cjs"
|
|
5455
|
-
}
|
|
5456
|
-
},
|
|
5457
|
-
"worker": {
|
|
5458
|
-
"import": {
|
|
5459
|
-
"types": "./dist/index.d.ts",
|
|
5460
|
-
"default": "./dist/index.js"
|
|
5461
|
-
},
|
|
5462
|
-
"require": {
|
|
5463
|
-
"types": "./dist/index.d.cts",
|
|
5464
|
-
"default": "./dist/index.cjs"
|
|
5465
|
-
}
|
|
5466
|
-
},
|
|
5467
|
-
"node": {
|
|
5468
|
-
"import": {
|
|
5469
|
-
"types": "./dist/index.d.ts",
|
|
5470
|
-
"default": "./dist/index.js"
|
|
5471
|
-
},
|
|
5472
|
-
"require": {
|
|
5473
|
-
"types": "./dist/index.d.cts",
|
|
5474
|
-
"default": "./dist/index.cjs"
|
|
5475
|
-
}
|
|
5476
|
-
},
|
|
5477
|
-
"browser": {
|
|
5478
|
-
"import": {
|
|
5479
|
-
"types": "./dist/browser/index.d.ts",
|
|
5480
|
-
"default": "./dist/browser/index.js"
|
|
5481
|
-
},
|
|
5482
|
-
"require": {
|
|
5483
|
-
"types": "./dist/browser/index.d.cts",
|
|
5484
|
-
"default": "./dist/browser/index.cjs"
|
|
5485
|
-
}
|
|
5486
|
-
},
|
|
5487
|
-
"default": {
|
|
5488
|
-
"import": {
|
|
5489
|
-
"types": "./dist/index.d.ts",
|
|
5490
|
-
"default": "./dist/index.js"
|
|
5491
|
-
},
|
|
5492
|
-
"require": {
|
|
5493
|
-
"types": "./dist/index.d.cts",
|
|
5494
|
-
"default": "./dist/index.cjs"
|
|
5495
|
-
}
|
|
5496
|
-
}
|
|
5497
|
-
},
|
|
5498
|
-
"./migrations": {
|
|
5499
|
-
"import": {
|
|
5500
|
-
"types": "./dist/migrations/index.d.ts",
|
|
5501
|
-
"default": "./dist/migrations/index.js"
|
|
5502
|
-
},
|
|
5503
|
-
"require": {
|
|
5504
|
-
"types": "./dist/migrations/index.d.cts",
|
|
5505
|
-
"default": "./dist/migrations/index.cjs"
|
|
5506
|
-
}
|
|
5507
|
-
},
|
|
5508
|
-
"./inspector": {
|
|
5509
|
-
"import": {
|
|
5510
|
-
"types": "./dist/inspector/index.d.ts",
|
|
5511
|
-
"default": "./dist/inspector/index.js"
|
|
5512
|
-
},
|
|
5513
|
-
"require": {
|
|
5514
|
-
"types": "./dist/inspector/index.d.cts",
|
|
5515
|
-
"default": "./dist/inspector/index.cjs"
|
|
5516
|
-
}
|
|
5517
|
-
},
|
|
5518
|
-
"./seeders": {
|
|
5519
|
-
"import": {
|
|
5520
|
-
"types": "./dist/seeders/index.d.ts",
|
|
5521
|
-
"default": "./dist/seeders/index.js"
|
|
5522
|
-
},
|
|
5523
|
-
"require": {
|
|
5524
|
-
"types": "./dist/seeders/index.d.cts",
|
|
5525
|
-
"default": "./dist/seeders/index.cjs"
|
|
5526
|
-
}
|
|
5527
|
-
},
|
|
5528
|
-
"./browser": {
|
|
5529
|
-
"import": {
|
|
5530
|
-
"types": "./dist/browser/index.d.ts",
|
|
5531
|
-
"default": "./dist/browser/index.js"
|
|
5532
|
-
},
|
|
5533
|
-
"require": {
|
|
5534
|
-
"types": "./dist/browser/index.d.cts",
|
|
5535
|
-
"default": "./dist/browser/index.cjs"
|
|
5536
|
-
}
|
|
5537
|
-
},
|
|
5538
|
-
"./package.json": "./package.json",
|
|
5539
|
-
"./types": "./types/index.ts"
|
|
5540
|
-
};
|
|
5541
|
-
var repository = {
|
|
5542
|
-
"type": "git",
|
|
5543
|
-
"url": "https://github.com/h3ravel/arquebus.git"
|
|
5544
|
-
};
|
|
5545
|
-
var engines = {
|
|
5546
|
-
"node": ">=14",
|
|
5547
|
-
"pnpm": ">=4"
|
|
5548
|
-
};
|
|
5549
|
-
var scripts = {
|
|
5550
|
-
"build": "tsdown",
|
|
5551
|
-
"lint": "eslint . --ext .ts",
|
|
5552
|
-
"barrel": "barrelize >/dev/null",
|
|
5553
|
-
"postinstall": "pnpm barrel",
|
|
5554
|
-
"cmd": "cross-env TEST=true tsx --experimental-specifier-resolution=node src/cli",
|
|
5555
|
-
"cmd:watch": "cross-env TEST=true tsx watch --experimental-specifier-resolution=node src/cli",
|
|
5556
|
-
"test": "cross-env vitest --project generic",
|
|
5557
|
-
"test:mysql": "cross-env DB=mysql vitest --project node",
|
|
5558
|
-
"test:postgres": "cross-env DB=postgres vitest --project node",
|
|
5559
|
-
"test:sqlite": "cross-env DB=sqlite vitest --project node",
|
|
5560
|
-
"test:browser": "vitest --project browser",
|
|
5561
|
-
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version\" && pnpm version patch && pnpm publish --tag latest"
|
|
5562
|
-
};
|
|
5563
|
-
var husky = { "hooks": { "pre-commit": "lint-staged" } };
|
|
5564
|
-
var lint_staged = { "*.{js,json}": ["prettier --write", "git add"] };
|
|
5565
|
-
var dependencies = {
|
|
5566
|
-
"@h3ravel/shared": "^0.21.0",
|
|
5567
|
-
"@h3ravel/support": "^0.12.0",
|
|
5568
|
-
"barrelize": "^1.6.4",
|
|
5569
|
-
"chalk": "^5.6.2",
|
|
5570
|
-
"collect.js": "^4.36.1",
|
|
5571
|
-
"commander": "^14.0.1",
|
|
5572
|
-
"cross-env": "^10.0.0",
|
|
5573
|
-
"dayjs": "^1.11.18",
|
|
5574
|
-
"dotenv": "^17.2.2",
|
|
5575
|
-
"escalade": "^3.2.0",
|
|
5576
|
-
"husky": "^9.1.7",
|
|
5577
|
-
"knex": "^3.1.0",
|
|
5578
|
-
"lint-staged": "^16.2.0",
|
|
5579
|
-
"mysql2": "^3.15.0",
|
|
5580
|
-
"pg": "^8.16.3",
|
|
5581
|
-
"pluralize": "^8.0.0",
|
|
5582
|
-
"radashi": "^12.6.2",
|
|
5583
|
-
"resolve-from": "^5.0.0",
|
|
5584
|
-
"tedious": "^19.0.0"
|
|
5585
|
-
};
|
|
5586
|
-
var devDependencies = {
|
|
5587
|
-
"@eslint/js": "^9.36.0",
|
|
5588
|
-
"@types/node": "^24.5.2",
|
|
5589
|
-
"@types/pluralize": "^0.0.33",
|
|
5590
|
-
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
5591
|
-
"@typescript-eslint/parser": "^8.44.0",
|
|
5592
|
-
"@vitest/coverage-v8": "^3.2.4",
|
|
5593
|
-
"eslint": "^9.36.0",
|
|
5594
|
-
"jsdom": "^26.1.0",
|
|
5595
|
-
"prettier": "^3.6.2",
|
|
5596
|
-
"sqlite3": "5.1.7",
|
|
5597
|
-
"terser": "^5.44.0",
|
|
5598
|
-
"ts-node": "^10.9.2",
|
|
5599
|
-
"tsdown": "^0.15.4",
|
|
5600
|
-
"tsx": "^4.20.5",
|
|
5601
|
-
"typescript": "^5.9.2",
|
|
5602
|
-
"typescript-eslint": "^8.44.0",
|
|
5603
|
-
"vite-tsconfig-paths": "^5.1.4",
|
|
5604
|
-
"vitest": "^3.2.4"
|
|
5605
|
-
};
|
|
5606
|
-
var keywords = [
|
|
5607
|
-
"arquebus",
|
|
5608
|
-
"ORM",
|
|
5609
|
-
"mysql",
|
|
5610
|
-
"mariadb",
|
|
5611
|
-
"sqlite",
|
|
5612
|
-
"postgresql",
|
|
5613
|
-
"postgres",
|
|
5614
|
-
"pg",
|
|
5615
|
-
"mssql",
|
|
5616
|
-
"active record"
|
|
5617
|
-
];
|
|
5618
|
-
var pnpm = { "onlyBuiltDependencies": ["sqlite3"] };
|
|
5619
|
-
var readmeFilename = "README.md";
|
|
5620
|
-
var license = "MIT";
|
|
5621
|
-
var package_default = {
|
|
5622
|
-
name,
|
|
5623
|
-
version,
|
|
5624
|
-
packageManager,
|
|
5625
|
-
description,
|
|
5626
|
-
homepage,
|
|
5627
|
-
bin,
|
|
5628
|
-
publishConfig,
|
|
5629
|
-
main,
|
|
5630
|
-
module: module$1,
|
|
5631
|
-
type,
|
|
5632
|
-
types,
|
|
5633
|
-
files,
|
|
5634
|
-
exports: exports$1,
|
|
5635
|
-
repository,
|
|
5636
|
-
engines,
|
|
5637
|
-
scripts,
|
|
5638
|
-
husky,
|
|
5639
|
-
"lint-staged": lint_staged,
|
|
5640
|
-
dependencies,
|
|
5641
|
-
devDependencies,
|
|
5642
|
-
keywords,
|
|
5643
|
-
pnpm,
|
|
5644
|
-
readmeFilename,
|
|
5645
|
-
license
|
|
5646
|
-
};
|
|
5492
|
+
var version = "0.6.7";
|
|
5647
5493
|
|
|
5648
5494
|
//#endregion
|
|
5649
5495
|
//#region src/cli/cli.ts
|
|
@@ -5700,26 +5546,26 @@ var Cli = class Cli {
|
|
|
5700
5546
|
return this;
|
|
5701
5547
|
}
|
|
5702
5548
|
async run() {
|
|
5703
|
-
const cliVersion = ["Arquebus CLI version:", __h3ravel_shared.Logger.log(
|
|
5549
|
+
const cliVersion = ["Arquebus CLI version:", __h3ravel_shared.Logger.log(version, "green", false)].join(" ");
|
|
5704
5550
|
const localVersion = ["Arquebus Local version:", __h3ravel_shared.Logger.log(this.modulePackage.version || "None", "green", false)].join(" ");
|
|
5705
5551
|
commander.program.name("arquebus").version(`${cliVersion}\n${localVersion}`);
|
|
5706
|
-
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
|
|
5552
|
+
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) => {
|
|
5707
5553
|
if (!this.modulePath) this.output.error(["ERROR: No local arquebus install found", " Try running: npm install arquebus --save"]);
|
|
5708
5554
|
if (this.configPath) this.output.error(`ERROR: ${this.configPath} already exists`);
|
|
5709
5555
|
try {
|
|
5710
|
-
const stubPath = `./arquebus.config.${type
|
|
5711
|
-
const code = await (0, node_fs_promises.readFile)(path.default.join(this.modulePath, `/src/stubs/arquebus.config-${type
|
|
5556
|
+
const stubPath = `./arquebus.config.${type}`;
|
|
5557
|
+
const code = await (0, node_fs_promises.readFile)(path.default.join(this.modulePath, `/src/stubs/arquebus.config-${type}.stub`), { encoding: "utf8" });
|
|
5712
5558
|
await (0, node_fs_promises.writeFile)(path.default.join(this.cwd, stubPath), code);
|
|
5713
5559
|
this.output.success(`Initialized: Arquebus has been initialized as ${stubPath}`);
|
|
5714
5560
|
} catch (e) {
|
|
5715
5561
|
this.output.error("ERROR: " + e);
|
|
5716
5562
|
}
|
|
5717
5563
|
});
|
|
5718
|
-
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
|
|
5564
|
+
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, opts) => {
|
|
5719
5565
|
if (!this.configPath) this.terminateNotFound();
|
|
5720
5566
|
try {
|
|
5721
5567
|
var _this$config$migratio3;
|
|
5722
|
-
name
|
|
5568
|
+
name = (0, radashi.snake)(name);
|
|
5723
5569
|
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");
|
|
5724
5570
|
let table = opts.table;
|
|
5725
5571
|
let create = Boolean(opts.create) && opts.create !== "";
|
|
@@ -5728,12 +5574,12 @@ var Cli = class Cli {
|
|
|
5728
5574
|
create = true;
|
|
5729
5575
|
}
|
|
5730
5576
|
if (!table) {
|
|
5731
|
-
const guessed = TableGuesser.guess(name
|
|
5577
|
+
const guessed = TableGuesser.guess(name);
|
|
5732
5578
|
table = guessed[0];
|
|
5733
5579
|
create = !!guessed[1];
|
|
5734
5580
|
}
|
|
5735
5581
|
this.output.info("INFO: Creating Migration");
|
|
5736
|
-
const fileName = await new MigrationCreator(void 0, opts.type).create(name
|
|
5582
|
+
const fileName = await new MigrationCreator(void 0, opts.type).create(name, migrationPath, table, create);
|
|
5737
5583
|
this.output.success(`INFO: Migration Created \n ${__h3ravel_shared.Logger.log(path.default.basename(fileName), "gray", false)}`, true);
|
|
5738
5584
|
} catch (e) {
|
|
5739
5585
|
this.output.error("ERROR: " + e);
|
|
@@ -5868,8 +5714,8 @@ var Cli = class Cli {
|
|
|
5868
5714
|
...this.config,
|
|
5869
5715
|
skipConnection: false
|
|
5870
5716
|
});
|
|
5871
|
-
const { SeederRunner } = await Promise.resolve().then(() => require("./seeders-
|
|
5872
|
-
const runner = new SeederRunner(arquebus$1);
|
|
5717
|
+
const { SeederRunner: SeederRunner$1 } = await Promise.resolve().then(() => require("./seeders-D-v59HCz.cjs"));
|
|
5718
|
+
const runner = new SeederRunner$1(arquebus$1);
|
|
5873
5719
|
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");
|
|
5874
5720
|
await runner.setConnection(this.config.client).run([seederPath]);
|
|
5875
5721
|
this.output.success("Seeders executed successfully.");
|
|
@@ -5880,16 +5726,15 @@ var Cli = class Cli {
|
|
|
5880
5726
|
/**
|
|
5881
5727
|
* Create a new seeder file
|
|
5882
5728
|
*/
|
|
5883
|
-
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
|
|
5729
|
+
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, opts) => {
|
|
5884
5730
|
var _this$config$seeders2;
|
|
5885
5731
|
if (!this.configPath) this.terminateNotFound();
|
|
5886
|
-
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
|
|
5732
|
+
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).snake("-") + "." + opts.type);
|
|
5887
5733
|
try {
|
|
5888
5734
|
if (!opts.force && await __h3ravel_shared.FileSystem.fileExists(seederPath)) this.output.error("ERROR: Seeder already exists.");
|
|
5889
5735
|
await (0, node_fs_promises.mkdir)(path.default.dirname(seederPath), { recursive: true });
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
stub = stub.replace(/{{ name }}/g, name$1);
|
|
5736
|
+
let stub = await (0, node_fs_promises.readFile)(path.default.join(this.modulePath, `src/stubs/seeder-${opts.type}.stub`), "utf-8");
|
|
5737
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
5893
5738
|
await (0, node_fs_promises.writeFile)(seederPath, stub);
|
|
5894
5739
|
this.output.split("INFO: Created Seeder", path.default.relative(this.cwd, seederPath));
|
|
5895
5740
|
} catch (e) {
|
|
@@ -5899,16 +5744,15 @@ var Cli = class Cli {
|
|
|
5899
5744
|
/**
|
|
5900
5745
|
* Create a new model file
|
|
5901
5746
|
*/
|
|
5902
|
-
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
|
|
5747
|
+
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, opts) => {
|
|
5903
5748
|
var _this$config$models;
|
|
5904
5749
|
if (!this.configPath) this.terminateNotFound();
|
|
5905
|
-
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
|
|
5750
|
+
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.toLowerCase() + "." + opts.type);
|
|
5906
5751
|
try {
|
|
5907
5752
|
if (!opts.force && await __h3ravel_shared.FileSystem.fileExists(modelPath)) this.output.error("ERROR: Model already exists.");
|
|
5908
5753
|
await (0, node_fs_promises.mkdir)(path.default.dirname(modelPath), { recursive: true });
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
stub = stub.replace(/{{ name }}/g, name$1);
|
|
5754
|
+
let stub = await (0, node_fs_promises.readFile)(path.default.join(this.modulePath, `src/stubs/model-${opts.type}.stub`), "utf-8");
|
|
5755
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
5912
5756
|
await (0, node_fs_promises.writeFile)(modelPath, stub);
|
|
5913
5757
|
this.output.success(`Created Model: ${modelPath}`);
|
|
5914
5758
|
} catch (e) {
|
|
@@ -5924,4 +5768,5 @@ var Cli = class Cli {
|
|
|
5924
5768
|
//#region src/cli/index.ts
|
|
5925
5769
|
Cli.init();
|
|
5926
5770
|
|
|
5927
|
-
//#endregion
|
|
5771
|
+
//#endregion
|
|
5772
|
+
exports.runner_default = runner_default;
|