@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
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import "./seeders-CltigymO.js";
|
|
3
2
|
import "node:module";
|
|
4
3
|
import { Argument, Option, program } from "commander";
|
|
5
4
|
import { FileSystem, Logger, TaskManager } from "@h3ravel/shared";
|
|
6
5
|
import path from "path";
|
|
7
6
|
import resolveFrom from "resolve-from";
|
|
8
|
-
import fs, { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
7
|
+
import fs, { access, copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
9
8
|
import { assign, camel, diff, flat, get, isArray, isEmpty, isEqual, isString, omit, pick, set, snake, trim } from "radashi";
|
|
10
9
|
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
11
10
|
import dayjs from "dayjs";
|
|
@@ -22,8 +21,8 @@ import { config } from "dotenv";
|
|
|
22
21
|
var __defProp = Object.defineProperty;
|
|
23
22
|
var __export = (all) => {
|
|
24
23
|
let target = {};
|
|
25
|
-
for (var name
|
|
26
|
-
get: all[name
|
|
24
|
+
for (var name in all) __defProp(target, name, {
|
|
25
|
+
get: all[name],
|
|
27
26
|
enumerable: true
|
|
28
27
|
});
|
|
29
28
|
return target;
|
|
@@ -128,8 +127,8 @@ var MigrationRepository = class {
|
|
|
128
127
|
getConnection() {
|
|
129
128
|
return this.resolver.fire(this.connection);
|
|
130
129
|
}
|
|
131
|
-
setSource(name
|
|
132
|
-
this.connection = name
|
|
130
|
+
setSource(name) {
|
|
131
|
+
this.connection = name;
|
|
133
132
|
}
|
|
134
133
|
};
|
|
135
134
|
|
|
@@ -603,10 +602,7 @@ var MSSQL = class {
|
|
|
603
602
|
AND ISNULL([i].[index_column_count], 1) = 1
|
|
604
603
|
AND ISNULL([i].[index_priority], 1) = 1`).where({ "s.name": this.schema });
|
|
605
604
|
if (table) query.andWhere({ "o.name": table });
|
|
606
|
-
if (column) {
|
|
607
|
-
const rawColumn = await query.andWhere({ "c.name": column }).first();
|
|
608
|
-
return rawColumnToColumn$2(rawColumn);
|
|
609
|
-
}
|
|
605
|
+
if (column) return rawColumnToColumn$2(await query.andWhere({ "c.name": column }).first());
|
|
610
606
|
return (await query).map(rawColumnToColumn$2);
|
|
611
607
|
}
|
|
612
608
|
/**
|
|
@@ -757,10 +753,7 @@ var MySQL = class {
|
|
|
757
753
|
this.on("rc.TABLE_NAME", "=", "fk.TABLE_NAME").andOn("rc.CONSTRAINT_NAME", "=", "fk.CONSTRAINT_NAME").andOn("rc.CONSTRAINT_SCHEMA", "=", "fk.CONSTRAINT_SCHEMA");
|
|
758
754
|
}).where({ "c.TABLE_SCHEMA": this.knex.client.database() });
|
|
759
755
|
if (table) query.andWhere({ "c.TABLE_NAME": table });
|
|
760
|
-
if (column) {
|
|
761
|
-
const rawColumn = await query.andWhere({ "c.column_name": column }).first();
|
|
762
|
-
return rawColumnToColumn$1(rawColumn);
|
|
763
|
-
}
|
|
756
|
+
if (column) return rawColumnToColumn$1(await query.andWhere({ "c.column_name": column }).first());
|
|
764
757
|
return (await query).map(rawColumnToColumn$1).sort((column$1) => +!column$1.foreign_key_column).filter((column$1, index, records) => {
|
|
765
758
|
return records.findIndex((_column) => {
|
|
766
759
|
return column$1.name === _column.name && column$1.table === _column.table;
|
|
@@ -859,7 +852,7 @@ var oracleDB = class {
|
|
|
859
852
|
return (await this.knex.select(this.knex.raw(`
|
|
860
853
|
/*+ OPTIMIZER_FEATURES_ENABLE('${OPTIMIZER_FEATURES}') */
|
|
861
854
|
"TABLE_NAME" "name"
|
|
862
|
-
`)).from("USER_TABLES")).map(({ name
|
|
855
|
+
`)).from("USER_TABLES")).map(({ name }) => name);
|
|
863
856
|
}
|
|
864
857
|
async tableInfo(table) {
|
|
865
858
|
const query = this.knex.select(this.knex.raw(`
|
|
@@ -946,10 +939,7 @@ var oracleDB = class {
|
|
|
946
939
|
ON "ct"."R_CONSTRAINT_NAME" = "fk"."CONSTRAINT_NAME"
|
|
947
940
|
`)).where({ "c.HIDDEN_COLUMN": "NO" });
|
|
948
941
|
if (table) query.andWhere({ "c.TABLE_NAME": table });
|
|
949
|
-
if (column) {
|
|
950
|
-
const rawColumn = await query.andWhere({ "c.COLUMN_NAME": column }).first();
|
|
951
|
-
return rawColumnToColumn(rawColumn);
|
|
952
|
-
}
|
|
942
|
+
if (column) return rawColumnToColumn(await query.andWhere({ "c.COLUMN_NAME": column }).first());
|
|
953
943
|
return (await query).map(rawColumnToColumn);
|
|
954
944
|
}
|
|
955
945
|
/**
|
|
@@ -1365,8 +1355,8 @@ var Postgres = class {
|
|
|
1365
1355
|
* Extracts the length value out of a given datatype
|
|
1366
1356
|
* For example: `varchar(32)` => 32
|
|
1367
1357
|
*/
|
|
1368
|
-
function extractMaxLength(type
|
|
1369
|
-
const matches = /\(([^)]+)\)/.exec(type
|
|
1358
|
+
function extractMaxLength(type) {
|
|
1359
|
+
const matches = /\(([^)]+)\)/.exec(type);
|
|
1370
1360
|
if (matches && matches.length > 0 && matches[1]) return Number(matches[1]);
|
|
1371
1361
|
return null;
|
|
1372
1362
|
}
|
|
@@ -1377,8 +1367,8 @@ function extractMaxLength(type$1) {
|
|
|
1377
1367
|
* Extracts the type out of a given datatype
|
|
1378
1368
|
* For example: `varchar(32)` => varchar
|
|
1379
1369
|
*/
|
|
1380
|
-
function extractType(type
|
|
1381
|
-
return type
|
|
1370
|
+
function extractType(type) {
|
|
1371
|
+
return type.replace(/[^a-zA-Z]/g, "").toLowerCase();
|
|
1382
1372
|
}
|
|
1383
1373
|
|
|
1384
1374
|
//#endregion
|
|
@@ -1511,8 +1501,8 @@ function compose$1(Base, ...mixins) {
|
|
|
1511
1501
|
/**
|
|
1512
1502
|
* Copy instance properties from mixin prototype
|
|
1513
1503
|
*/
|
|
1514
|
-
Object.getOwnPropertyNames(mixin.prototype).forEach((name
|
|
1515
|
-
if (name
|
|
1504
|
+
Object.getOwnPropertyNames(mixin.prototype).forEach((name) => {
|
|
1505
|
+
if (name !== "constructor") Object.defineProperty(this, name, Object.getOwnPropertyDescriptor(mixin.prototype, name));
|
|
1516
1506
|
});
|
|
1517
1507
|
}
|
|
1518
1508
|
};
|
|
@@ -1836,9 +1826,7 @@ const HasAttributes = (Model$1) => {
|
|
|
1836
1826
|
}
|
|
1837
1827
|
originalIsEquivalent(key) {
|
|
1838
1828
|
if (this.original[key] === void 0) return false;
|
|
1839
|
-
|
|
1840
|
-
const original = this.original[key];
|
|
1841
|
-
if (attribute === original) return true;
|
|
1829
|
+
if (this.attributes[key] === this.original[key]) return true;
|
|
1842
1830
|
else return false;
|
|
1843
1831
|
}
|
|
1844
1832
|
setAttributes(attributes) {
|
|
@@ -1980,10 +1968,10 @@ const HasAttributes = (Model$1) => {
|
|
|
1980
1968
|
else convertedCastType = String(castType).toLocaleLowerCase().trim();
|
|
1981
1969
|
return this.getConstructor()[castTypeCacheKey] = convertedCastType;
|
|
1982
1970
|
}
|
|
1983
|
-
hasCast(key, types
|
|
1971
|
+
hasCast(key, types = []) {
|
|
1984
1972
|
if (key in this.casts) {
|
|
1985
|
-
types
|
|
1986
|
-
return types
|
|
1973
|
+
types = flat(types);
|
|
1974
|
+
return types.length > 0 ? types.includes(this.getCastType(key)) : true;
|
|
1987
1975
|
}
|
|
1988
1976
|
return false;
|
|
1989
1977
|
}
|
|
@@ -2020,8 +2008,7 @@ const HasAttributes = (Model$1) => {
|
|
|
2020
2008
|
return new Date(value);
|
|
2021
2009
|
}
|
|
2022
2010
|
asDate(value) {
|
|
2023
|
-
|
|
2024
|
-
return dayjs(date).startOf("day").toDate();
|
|
2011
|
+
return dayjs(this.asDateTime(value)).startOf("day").toDate();
|
|
2025
2012
|
}
|
|
2026
2013
|
};
|
|
2027
2014
|
};
|
|
@@ -2160,15 +2147,15 @@ var has_hooks_default = HasHooks;
|
|
|
2160
2147
|
//#region src/relations/has-one-or-many.ts
|
|
2161
2148
|
const HasOneOrMany = (Relation$1) => {
|
|
2162
2149
|
return class extends Relation$1 {
|
|
2163
|
-
getRelationValue(dictionary, key, type
|
|
2150
|
+
getRelationValue(dictionary, key, type) {
|
|
2164
2151
|
const value = dictionary[key];
|
|
2165
|
-
return type
|
|
2152
|
+
return type === "one" ? value[0] : new collection_default(value);
|
|
2166
2153
|
}
|
|
2167
|
-
matchOneOrMany(models, results, relation, type
|
|
2154
|
+
matchOneOrMany(models, results, relation, type) {
|
|
2168
2155
|
const dictionary = this.buildDictionary(results);
|
|
2169
2156
|
models.map((model) => {
|
|
2170
2157
|
const key = model.attributes[this.localKey];
|
|
2171
|
-
if (dictionary[key] !== void 0) model.setRelation(relation, this.getRelationValue(dictionary, key, type
|
|
2158
|
+
if (dictionary[key] !== void 0) model.setRelation(relation, this.getRelationValue(dictionary, key, type));
|
|
2172
2159
|
});
|
|
2173
2160
|
return models;
|
|
2174
2161
|
}
|
|
@@ -2535,10 +2522,7 @@ const HasRelations = (Model$1) => {
|
|
|
2535
2522
|
return this.relations[relation] !== void 0;
|
|
2536
2523
|
}
|
|
2537
2524
|
related(relation) {
|
|
2538
|
-
if (typeof this[getRelationMethod(relation)] !== "function") {
|
|
2539
|
-
const message = `Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`;
|
|
2540
|
-
throw new RelationNotFoundError(message);
|
|
2541
|
-
}
|
|
2525
|
+
if (typeof this[getRelationMethod(relation)] !== "function") throw new RelationNotFoundError(`Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`);
|
|
2542
2526
|
return this[getRelationMethod(relation)]();
|
|
2543
2527
|
}
|
|
2544
2528
|
async getRelated(relation) {
|
|
@@ -3049,8 +3033,8 @@ var arquebus = class arquebus {
|
|
|
3049
3033
|
static getConnectorFactory() {
|
|
3050
3034
|
return this.connectorFactory ?? Knex;
|
|
3051
3035
|
}
|
|
3052
|
-
static addConnection(config$1, name
|
|
3053
|
-
return this.getInstance().addConnection(config$1, name
|
|
3036
|
+
static addConnection(config$1, name = "default") {
|
|
3037
|
+
return this.getInstance().addConnection(config$1, name);
|
|
3054
3038
|
}
|
|
3055
3039
|
static beginTransaction(connection = null) {
|
|
3056
3040
|
return this.getInstance().beginTransaction(connection);
|
|
@@ -3058,8 +3042,8 @@ var arquebus = class arquebus {
|
|
|
3058
3042
|
static transaction(callback, connection = null) {
|
|
3059
3043
|
return this.getInstance().transaction(callback, connection);
|
|
3060
3044
|
}
|
|
3061
|
-
static table(name
|
|
3062
|
-
return this.getInstance().table(name
|
|
3045
|
+
static table(name, connection = null) {
|
|
3046
|
+
return this.getInstance().table(name, connection);
|
|
3063
3047
|
}
|
|
3064
3048
|
static schema(connection = null) {
|
|
3065
3049
|
return this.getInstance().schema(connection);
|
|
@@ -3067,23 +3051,23 @@ var arquebus = class arquebus {
|
|
|
3067
3051
|
static async destroyAll() {
|
|
3068
3052
|
await this.getInstance().destroyAll();
|
|
3069
3053
|
}
|
|
3070
|
-
static createModel(name
|
|
3071
|
-
return this.getInstance().createModel(name
|
|
3054
|
+
static createModel(name, options) {
|
|
3055
|
+
return this.getInstance().createModel(name, options);
|
|
3072
3056
|
}
|
|
3073
3057
|
connection(connection = null) {
|
|
3074
3058
|
return this.getConnection(connection);
|
|
3075
3059
|
}
|
|
3076
|
-
getConnection(name
|
|
3077
|
-
name
|
|
3078
|
-
const resolvedName = this.connections[name
|
|
3060
|
+
getConnection(name = null) {
|
|
3061
|
+
name = name || "default";
|
|
3062
|
+
const resolvedName = this.connections[name] ? name : "default";
|
|
3079
3063
|
if (this.manager[resolvedName] === void 0) {
|
|
3080
3064
|
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
3081
3065
|
this.manager[resolvedName] = queryBuilder;
|
|
3082
3066
|
}
|
|
3083
3067
|
return this.manager[resolvedName];
|
|
3084
3068
|
}
|
|
3085
|
-
addConnection(config$1, name
|
|
3086
|
-
this.connections[name
|
|
3069
|
+
addConnection(config$1, name = "default") {
|
|
3070
|
+
this.connections[name] = {
|
|
3087
3071
|
...config$1,
|
|
3088
3072
|
connection: {
|
|
3089
3073
|
...config$1.connection,
|
|
@@ -3145,8 +3129,8 @@ var arquebus = class arquebus {
|
|
|
3145
3129
|
transaction(callback, connection = null) {
|
|
3146
3130
|
return this.connection(connection).transaction(callback);
|
|
3147
3131
|
}
|
|
3148
|
-
table(name
|
|
3149
|
-
return this.connection(connection).table(name
|
|
3132
|
+
table(name, connection = null) {
|
|
3133
|
+
return this.connection(connection).table(name);
|
|
3150
3134
|
}
|
|
3151
3135
|
schema(connection = null) {
|
|
3152
3136
|
return this.connection(connection).schema;
|
|
@@ -3156,12 +3140,12 @@ var arquebus = class arquebus {
|
|
|
3156
3140
|
return connection === null || connection === void 0 ? void 0 : connection.destroy();
|
|
3157
3141
|
}));
|
|
3158
3142
|
}
|
|
3159
|
-
createModel(name
|
|
3143
|
+
createModel(name, options = {}) {
|
|
3160
3144
|
let BaseModel$1 = Model;
|
|
3161
3145
|
if ("plugins" in options) BaseModel$1 = compose(BaseModel$1, ...options.plugins ?? []);
|
|
3162
3146
|
this.models = {
|
|
3163
3147
|
...this.models,
|
|
3164
|
-
[name
|
|
3148
|
+
[name]: class extends BaseModel$1 {
|
|
3165
3149
|
table = (options === null || options === void 0 ? void 0 : options.table) ?? null;
|
|
3166
3150
|
connection = (options === null || options === void 0 ? void 0 : options.connection) ?? null;
|
|
3167
3151
|
timestamps = (options === null || options === void 0 ? void 0 : options.timestamps) ?? true;
|
|
@@ -3177,18 +3161,18 @@ var arquebus = class arquebus {
|
|
|
3177
3161
|
};
|
|
3178
3162
|
if ("attributes" in options) for (const attribute in options.attributes) {
|
|
3179
3163
|
if (options.attributes[attribute] instanceof attribute_default === false) throw new Error("Attribute must be an instance of \"Attribute\"");
|
|
3180
|
-
this.models[name
|
|
3164
|
+
this.models[name].prototype[getAttrMethod(attribute)] = () => {
|
|
3181
3165
|
var _options$attributes;
|
|
3182
3166
|
return (_options$attributes = options.attributes) === null || _options$attributes === void 0 ? void 0 : _options$attributes[attribute];
|
|
3183
3167
|
};
|
|
3184
3168
|
}
|
|
3185
|
-
if ("relations" in options) for (const relation in options.relations) this.models[name
|
|
3169
|
+
if ("relations" in options) for (const relation in options.relations) this.models[name].prototype[getRelationMethod(relation)] = function() {
|
|
3186
3170
|
var _options$relations;
|
|
3187
3171
|
return (_options$relations = options.relations) === null || _options$relations === void 0 ? void 0 : _options$relations[relation](this);
|
|
3188
3172
|
};
|
|
3189
|
-
if ("scopes" in options) for (const scope in options.scopes) this.models[name
|
|
3190
|
-
this.models[name
|
|
3191
|
-
return this.models[name
|
|
3173
|
+
if ("scopes" in options) for (const scope in options.scopes) this.models[name].prototype[getScopeMethod(scope)] = options.scopes[scope];
|
|
3174
|
+
this.models[name].setConnectionResolver(this);
|
|
3175
|
+
return this.models[name];
|
|
3192
3176
|
}
|
|
3193
3177
|
};
|
|
3194
3178
|
var arquebus_default = arquebus;
|
|
@@ -3348,8 +3332,8 @@ var Model = class Model extends BaseModel {
|
|
|
3348
3332
|
}
|
|
3349
3333
|
return builder;
|
|
3350
3334
|
}
|
|
3351
|
-
hasNamedScope(name
|
|
3352
|
-
const scope = getScopeMethod(name
|
|
3335
|
+
hasNamedScope(name) {
|
|
3336
|
+
const scope = getScopeMethod(name);
|
|
3353
3337
|
return typeof this[scope] === "function";
|
|
3354
3338
|
}
|
|
3355
3339
|
callNamedScope(scope, parameters) {
|
|
@@ -3833,8 +3817,8 @@ const InteractsWithPivotTable = (Relation$1) => {
|
|
|
3833
3817
|
castKey(key) {
|
|
3834
3818
|
return this.getTypeSwapValue(this.related.getKeyType(), key);
|
|
3835
3819
|
}
|
|
3836
|
-
getTypeSwapValue(type
|
|
3837
|
-
switch (type
|
|
3820
|
+
getTypeSwapValue(type, value) {
|
|
3821
|
+
switch (type.toLowerCase()) {
|
|
3838
3822
|
case "int":
|
|
3839
3823
|
case "integer": return parseInt(value);
|
|
3840
3824
|
case "real":
|
|
@@ -4039,8 +4023,7 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
4039
4023
|
return columns.concat(this.aliasedPivotColumns());
|
|
4040
4024
|
}
|
|
4041
4025
|
aliasedPivotColumns() {
|
|
4042
|
-
|
|
4043
|
-
return collect$1(defaults.concat(this.pivotColumns)).map((column) => {
|
|
4026
|
+
return collect$1([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
|
|
4044
4027
|
return this.qualifyPivotColumn(column) + " as pivot_" + column;
|
|
4045
4028
|
}).unique().all();
|
|
4046
4029
|
}
|
|
@@ -4333,8 +4316,7 @@ var Builder = class Builder extends Inference {
|
|
|
4333
4316
|
}
|
|
4334
4317
|
addUpdatedAtColumn(values) {
|
|
4335
4318
|
if (!this.model.usesTimestamps() || this.model.getUpdatedAtColumn() === null) return values;
|
|
4336
|
-
|
|
4337
|
-
values = assign({ [column]: this.model.freshTimestampString() }, values);
|
|
4319
|
+
values = assign({ [this.model.getUpdatedAtColumn()]: this.model.freshTimestampString() }, values);
|
|
4338
4320
|
return values;
|
|
4339
4321
|
}
|
|
4340
4322
|
delete() {
|
|
@@ -4384,8 +4366,8 @@ var Builder = class Builder extends Inference {
|
|
|
4384
4366
|
}
|
|
4385
4367
|
return this;
|
|
4386
4368
|
}
|
|
4387
|
-
hasNamedScope(name
|
|
4388
|
-
return this.model && this.model.hasNamedScope(name
|
|
4369
|
+
hasNamedScope(name) {
|
|
4370
|
+
return this.model && this.model.hasNamedScope(name);
|
|
4389
4371
|
}
|
|
4390
4372
|
callNamedScope(scope, parameters) {
|
|
4391
4373
|
return this.model.callNamedScope(scope, [this, ...parameters]);
|
|
@@ -4410,15 +4392,15 @@ var Builder = class Builder extends Inference {
|
|
|
4410
4392
|
this.globalScopes = omit(this.globalScopes, [scope]);
|
|
4411
4393
|
return this;
|
|
4412
4394
|
}
|
|
4413
|
-
macro(name
|
|
4414
|
-
this.localMacros[name
|
|
4395
|
+
macro(name, callback) {
|
|
4396
|
+
this.localMacros[name] = callback;
|
|
4415
4397
|
return this;
|
|
4416
4398
|
}
|
|
4417
|
-
hasMacro(name
|
|
4418
|
-
return name
|
|
4399
|
+
hasMacro(name) {
|
|
4400
|
+
return name in this.localMacros;
|
|
4419
4401
|
}
|
|
4420
|
-
getMacro(name
|
|
4421
|
-
return this.localMacros[name
|
|
4402
|
+
getMacro(name) {
|
|
4403
|
+
return this.localMacros[name];
|
|
4422
4404
|
}
|
|
4423
4405
|
with(...args) {
|
|
4424
4406
|
let eagerLoads = {};
|
|
@@ -4499,8 +4481,8 @@ var Builder = class Builder extends Inference {
|
|
|
4499
4481
|
return this.canUseExistsForExistenceCheck(operator, count) ? this.addWhereExistsQuery(hasQuery.getQuery(), boolean, operator === "<" && count === 1) : this.addWhereCountQuery(hasQuery.getQuery(), operator, count, boolean);
|
|
4500
4482
|
}
|
|
4501
4483
|
addWhereExistsQuery(query, boolean = "and", not = false) {
|
|
4502
|
-
const type
|
|
4503
|
-
const method = boolean === "and" ? "where" + type
|
|
4484
|
+
const type = not ? "NotExists" : "Exists";
|
|
4485
|
+
const method = boolean === "and" ? "where" + type : "orWhere" + type;
|
|
4504
4486
|
this[method](query.connector);
|
|
4505
4487
|
return this;
|
|
4506
4488
|
}
|
|
@@ -4522,12 +4504,12 @@ var Builder = class Builder extends Inference {
|
|
|
4522
4504
|
const db = this.model.getConnection();
|
|
4523
4505
|
if (this.query._statements.filter((item) => item.grouping == "columns").map((item) => item.value).flat().length === 0) this.query.select([this.query._single.table + ".*"]);
|
|
4524
4506
|
const parses = this.parseWithRelations(relations);
|
|
4525
|
-
for (let name
|
|
4526
|
-
const constraints = parses[name
|
|
4527
|
-
const segments = name
|
|
4507
|
+
for (let name in parses) {
|
|
4508
|
+
const constraints = parses[name];
|
|
4509
|
+
const segments = name.split(" ");
|
|
4528
4510
|
let alias, expression;
|
|
4529
|
-
if (segments.length === 3 && segments[1].toLocaleLowerCase() === "as") [name
|
|
4530
|
-
const relation = this.getRelationWithoutConstraints(getRelationMethod(name
|
|
4511
|
+
if (segments.length === 3 && segments[1].toLocaleLowerCase() === "as") [name, alias] = [segments[0], segments[2]];
|
|
4512
|
+
const relation = this.getRelationWithoutConstraints(getRelationMethod(name));
|
|
4531
4513
|
if (action) {
|
|
4532
4514
|
const hashedColumn = this.query._single.table === relation.query.query._single.table ? `${relation.getRelationCountHash(false)}.${column}` : column;
|
|
4533
4515
|
const wrappedColumn = column === "*" ? column : relation.getRelated().qualifyColumn(hashedColumn);
|
|
@@ -4535,7 +4517,7 @@ var Builder = class Builder extends Inference {
|
|
|
4535
4517
|
} else expression = column;
|
|
4536
4518
|
const query = relation.getRelationExistenceQuery(relation.getRelated().newModelQuery(), this, db.raw(expression));
|
|
4537
4519
|
constraints(query);
|
|
4538
|
-
alias = alias || snake(`${name
|
|
4520
|
+
alias = alias || snake(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
|
|
4539
4521
|
if (action === "exists") this.select(db.raw(`exists(${query.toSql().sql}) as ${alias}`));
|
|
4540
4522
|
else this.selectSub(action ? query : query.limit(1), alias);
|
|
4541
4523
|
}
|
|
@@ -4596,15 +4578,15 @@ var Builder = class Builder extends Inference {
|
|
|
4596
4578
|
if (relations.length === 0) return [];
|
|
4597
4579
|
let results = {};
|
|
4598
4580
|
const constraintsMap = this.prepareNestedWithRelationships(relations);
|
|
4599
|
-
for (const name
|
|
4600
|
-
results = this.addNestedWiths(name
|
|
4601
|
-
results[name
|
|
4581
|
+
for (const name in constraintsMap) {
|
|
4582
|
+
results = this.addNestedWiths(name, results);
|
|
4583
|
+
results[name] = constraintsMap[name];
|
|
4602
4584
|
}
|
|
4603
4585
|
return results;
|
|
4604
4586
|
}
|
|
4605
|
-
addNestedWiths(name
|
|
4587
|
+
addNestedWiths(name, results) {
|
|
4606
4588
|
const progress = [];
|
|
4607
|
-
name
|
|
4589
|
+
name.split(".").map((segment) => {
|
|
4608
4590
|
progress.push(segment);
|
|
4609
4591
|
const last = progress.join(".");
|
|
4610
4592
|
if (results[last] === void 0) results[last] = () => {};
|
|
@@ -4637,22 +4619,19 @@ var Builder = class Builder extends Inference {
|
|
|
4637
4619
|
return builder;
|
|
4638
4620
|
};
|
|
4639
4621
|
}
|
|
4640
|
-
parseNameAndAttributeSelectionConstraint(name
|
|
4641
|
-
return name
|
|
4622
|
+
parseNameAndAttributeSelectionConstraint(name, value) {
|
|
4623
|
+
return name.includes(":") ? this.createSelectWithConstraint(name) : [name, value];
|
|
4642
4624
|
}
|
|
4643
|
-
createSelectWithConstraint(name
|
|
4644
|
-
return [name
|
|
4645
|
-
query.select(name
|
|
4625
|
+
createSelectWithConstraint(name) {
|
|
4626
|
+
return [name.split(":")[0], (query) => {
|
|
4627
|
+
query.select(name.split(":")[1].split(",").map((column) => {
|
|
4646
4628
|
if (column.includes(".")) return column;
|
|
4647
4629
|
return query instanceof belongs_to_many_default ? query.related.getTable() + "." + column : column;
|
|
4648
4630
|
}));
|
|
4649
4631
|
}];
|
|
4650
4632
|
}
|
|
4651
4633
|
related(relation) {
|
|
4652
|
-
if (typeof this.model[getRelationMethod(relation)] !== "function") {
|
|
4653
|
-
const message = `Model [${this.model.constructor.name}]'s relation [${relation}] doesn't exist.`;
|
|
4654
|
-
throw new RelationNotFoundError(message);
|
|
4655
|
-
}
|
|
4634
|
+
if (typeof this.model[getRelationMethod(relation)] !== "function") throw new RelationNotFoundError(`Model [${this.model.constructor.name}]'s relation [${relation}] doesn't exist.`);
|
|
4656
4635
|
return this.model[getRelationMethod(relation)]();
|
|
4657
4636
|
}
|
|
4658
4637
|
take(...args) {
|
|
@@ -4725,8 +4704,7 @@ var Builder = class Builder extends Inference {
|
|
|
4725
4704
|
return await this.whereIn(this.model.getKeyName(), ids).get(columns);
|
|
4726
4705
|
}
|
|
4727
4706
|
async pluck(column) {
|
|
4728
|
-
|
|
4729
|
-
return new collection_default(data);
|
|
4707
|
+
return new collection_default(await this.query.pluck(column));
|
|
4730
4708
|
}
|
|
4731
4709
|
async destroy(ids) {
|
|
4732
4710
|
if (ids instanceof collection_default) ids = ids.modelKeys();
|
|
@@ -4770,37 +4748,34 @@ var Builder = class Builder extends Inference {
|
|
|
4770
4748
|
}
|
|
4771
4749
|
return this.hydrate(await this.query.get()).all();
|
|
4772
4750
|
}
|
|
4773
|
-
getRelation(name
|
|
4774
|
-
if (typeof this.model[getRelationMethod(name
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
}
|
|
4778
|
-
const relation = relation_default.noConstraints(() => this.model.newInstance(this.model.attributes)[getRelationMethod(name$1)]());
|
|
4779
|
-
const nested = this.relationsNestedUnder(name$1);
|
|
4751
|
+
getRelation(name) {
|
|
4752
|
+
if (typeof this.model[getRelationMethod(name)] !== "function") throw new RelationNotFoundError(`Model [${this.model.constructor.name}]'s relation [${name}] doesn't exist.`);
|
|
4753
|
+
const relation = relation_default.noConstraints(() => this.model.newInstance(this.model.attributes)[getRelationMethod(name)]());
|
|
4754
|
+
const nested = this.relationsNestedUnder(name);
|
|
4780
4755
|
if (Object.keys(nested).length > 0) relation.query.with(nested);
|
|
4781
4756
|
return relation.asProxy();
|
|
4782
4757
|
}
|
|
4783
4758
|
relationsNestedUnder(relation) {
|
|
4784
4759
|
const nested = {};
|
|
4785
|
-
for (const name
|
|
4786
|
-
const constraints = this.eagerLoad[name
|
|
4787
|
-
if (this.isNestedUnder(relation, name
|
|
4760
|
+
for (const name in this.eagerLoad) {
|
|
4761
|
+
const constraints = this.eagerLoad[name];
|
|
4762
|
+
if (this.isNestedUnder(relation, name)) nested[name.substring((relation + ".").length)] = constraints;
|
|
4788
4763
|
}
|
|
4789
4764
|
return nested;
|
|
4790
4765
|
}
|
|
4791
|
-
isNestedUnder(relation, name
|
|
4792
|
-
return name
|
|
4766
|
+
isNestedUnder(relation, name) {
|
|
4767
|
+
return name.includes(".") && name.startsWith(relation + ".");
|
|
4793
4768
|
}
|
|
4794
|
-
async eagerLoadRelation(models, name
|
|
4795
|
-
const relation = this.getRelation(name
|
|
4769
|
+
async eagerLoadRelation(models, name, constraints) {
|
|
4770
|
+
const relation = this.getRelation(name);
|
|
4796
4771
|
relation.addEagerConstraints(models);
|
|
4797
4772
|
constraints(relation);
|
|
4798
|
-
return relation.match(relation.initRelation(models, name
|
|
4773
|
+
return relation.match(relation.initRelation(models, name), await relation.get(), name);
|
|
4799
4774
|
}
|
|
4800
4775
|
async eagerLoadRelations(models) {
|
|
4801
|
-
for (const name
|
|
4802
|
-
const constraints = this.eagerLoad[name
|
|
4803
|
-
if (!name
|
|
4776
|
+
for (const name in this.eagerLoad) {
|
|
4777
|
+
const constraints = this.eagerLoad[name];
|
|
4778
|
+
if (!name.includes(".")) models = await this.eagerLoadRelation(models, name, constraints);
|
|
4804
4779
|
}
|
|
4805
4780
|
return models;
|
|
4806
4781
|
}
|
|
@@ -4813,6 +4788,79 @@ var Builder = class Builder extends Inference {
|
|
|
4813
4788
|
};
|
|
4814
4789
|
var builder_default = Builder;
|
|
4815
4790
|
|
|
4791
|
+
//#endregion
|
|
4792
|
+
//#region src/seeders/runner.ts
|
|
4793
|
+
async function glob$1(folderPath) {
|
|
4794
|
+
const { default: escalade } = await import("escalade");
|
|
4795
|
+
const entries = [];
|
|
4796
|
+
await escalade(folderPath, async (dir, names) => {
|
|
4797
|
+
await Promise.all(names.map(async (name) => {
|
|
4798
|
+
const p = path.join(dir, name);
|
|
4799
|
+
try {
|
|
4800
|
+
await access(p);
|
|
4801
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
4802
|
+
} catch {}
|
|
4803
|
+
}));
|
|
4804
|
+
return "";
|
|
4805
|
+
});
|
|
4806
|
+
return entries;
|
|
4807
|
+
}
|
|
4808
|
+
var SeederRunner = class {
|
|
4809
|
+
resolver;
|
|
4810
|
+
connection;
|
|
4811
|
+
paths = [];
|
|
4812
|
+
constructor(resolver) {
|
|
4813
|
+
this.resolver = resolver;
|
|
4814
|
+
}
|
|
4815
|
+
path(p) {
|
|
4816
|
+
this.paths = Array.from(new Set([...this.paths, p]));
|
|
4817
|
+
}
|
|
4818
|
+
getPaths() {
|
|
4819
|
+
return this.paths;
|
|
4820
|
+
}
|
|
4821
|
+
resolveConnection(connection) {
|
|
4822
|
+
var _getInstance, _ref, _instance$connections;
|
|
4823
|
+
const name = connection || this.connection || "default";
|
|
4824
|
+
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
4825
|
+
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
4826
|
+
/** noop */
|
|
4827
|
+
});
|
|
4828
|
+
return this.resolver.fire(name);
|
|
4829
|
+
}
|
|
4830
|
+
setConnection(connection) {
|
|
4831
|
+
this.connection = connection;
|
|
4832
|
+
return this;
|
|
4833
|
+
}
|
|
4834
|
+
async getSeederFiles(paths) {
|
|
4835
|
+
const files = [];
|
|
4836
|
+
for (const p of paths) {
|
|
4837
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
4838
|
+
files.push(p);
|
|
4839
|
+
continue;
|
|
4840
|
+
}
|
|
4841
|
+
files.push(...await glob$1(p));
|
|
4842
|
+
}
|
|
4843
|
+
return files;
|
|
4844
|
+
}
|
|
4845
|
+
async resolvePath(filePath) {
|
|
4846
|
+
try {
|
|
4847
|
+
const mod = await import(filePath);
|
|
4848
|
+
return new (mod.default ?? mod.Seeder)();
|
|
4849
|
+
} catch {
|
|
4850
|
+
return null;
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
async run(paths, connection) {
|
|
4854
|
+
const files = await this.getSeederFiles(paths);
|
|
4855
|
+
const conn = this.resolveConnection(connection);
|
|
4856
|
+
for (const file of files) {
|
|
4857
|
+
const seeder = await this.resolvePath(file);
|
|
4858
|
+
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
};
|
|
4862
|
+
var runner_default = SeederRunner;
|
|
4863
|
+
|
|
4816
4864
|
//#endregion
|
|
4817
4865
|
//#region src/inspector/dialects/sqlite.ts
|
|
4818
4866
|
function parseDefaultValue(value) {
|
|
@@ -4828,7 +4876,7 @@ var SQLite = class {
|
|
|
4828
4876
|
* List all existing tables in the current schema/database
|
|
4829
4877
|
*/
|
|
4830
4878
|
async tables() {
|
|
4831
|
-
return (await this.knex.select("name").from("sqlite_master").whereRaw("type = 'table' AND name NOT LIKE 'sqlite_%'")).map(({ name
|
|
4879
|
+
return (await this.knex.select("name").from("sqlite_master").whereRaw("type = 'table' AND name NOT LIKE 'sqlite_%'")).map(({ name }) => name);
|
|
4832
4880
|
}
|
|
4833
4881
|
async tableInfo(table) {
|
|
4834
4882
|
const query = this.knex.select("name", "sql").from("sqlite_master").where({ type: "table" }).andWhereRaw("name NOT LIKE 'sqlite_%'");
|
|
@@ -4859,12 +4907,11 @@ var SQLite = class {
|
|
|
4859
4907
|
column: column.name
|
|
4860
4908
|
}));
|
|
4861
4909
|
const tables = await this.tables();
|
|
4862
|
-
|
|
4863
|
-
return flatten(columnsPerTable);
|
|
4910
|
+
return flatten(await Promise.all(tables.map(async (table$1) => await this.columns(table$1))));
|
|
4864
4911
|
}
|
|
4865
4912
|
async columnInfo(table, column) {
|
|
4866
4913
|
const getColumnsForTable = async (table$1) => {
|
|
4867
|
-
const tablesWithAutoIncrementPrimaryKeys = (await this.knex.select("name").from("sqlite_master").whereRaw("sql LIKE '%AUTOINCREMENT%'")).map(({ name
|
|
4914
|
+
const tablesWithAutoIncrementPrimaryKeys = (await this.knex.select("name").from("sqlite_master").whereRaw("sql LIKE '%AUTOINCREMENT%'")).map(({ name }) => name);
|
|
4868
4915
|
const columns = await this.knex.raw("PRAGMA table_xinfo(??)", table$1);
|
|
4869
4916
|
const foreignKeys = await this.knex.raw("PRAGMA foreign_key_list(??)", table$1);
|
|
4870
4917
|
const indexList = await this.knex.raw("PRAGMA index_list(??)", table$1);
|
|
@@ -4895,8 +4942,7 @@ var SQLite = class {
|
|
|
4895
4942
|
};
|
|
4896
4943
|
if (!table) {
|
|
4897
4944
|
const tables = await this.tables();
|
|
4898
|
-
|
|
4899
|
-
return flatten(columnsPerTable);
|
|
4945
|
+
return flatten(await Promise.all(tables.map(async (table$1) => await getColumnsForTable(table$1))));
|
|
4900
4946
|
}
|
|
4901
4947
|
if (table && !column) return await getColumnsForTable(table);
|
|
4902
4948
|
return (await getColumnsForTable(table)).find((columnInfo) => columnInfo.name === column);
|
|
@@ -4927,8 +4973,7 @@ var SQLite = class {
|
|
|
4927
4973
|
constraint_name: null
|
|
4928
4974
|
}));
|
|
4929
4975
|
const tables = await this.tables();
|
|
4930
|
-
|
|
4931
|
-
return flatten(keysPerTable);
|
|
4976
|
+
return flatten(await Promise.all(tables.map(async (table$1) => await this.foreignKeys(table$1))));
|
|
4932
4977
|
}
|
|
4933
4978
|
async uniqueConstraints(table) {
|
|
4934
4979
|
if (table) {
|
|
@@ -4944,8 +4989,7 @@ var SQLite = class {
|
|
|
4944
4989
|
});
|
|
4945
4990
|
}
|
|
4946
4991
|
const tables = await this.tables();
|
|
4947
|
-
|
|
4948
|
-
return flatten(constraintsPerTable);
|
|
4992
|
+
return flatten(await Promise.all(tables.map(async (table$1) => await this.uniqueConstraints(table$1))));
|
|
4949
4993
|
}
|
|
4950
4994
|
};
|
|
4951
4995
|
|
|
@@ -4985,9 +5029,9 @@ var SchemaInspector = class {
|
|
|
4985
5029
|
//#endregion
|
|
4986
5030
|
//#region src/migrations/migrator.ts
|
|
4987
5031
|
async function glob(folderPath) {
|
|
4988
|
-
const files
|
|
5032
|
+
const files = await fs.readdir(folderPath);
|
|
4989
5033
|
const allFiles = [];
|
|
4990
|
-
for (const file of files
|
|
5034
|
+
for (const file of files) {
|
|
4991
5035
|
const filePath = `${folderPath}/${file}`;
|
|
4992
5036
|
const stats = await fs.stat(filePath);
|
|
4993
5037
|
if (stats.isFile()) allFiles.push(filePath);
|
|
@@ -5006,21 +5050,21 @@ var Migrator = class {
|
|
|
5006
5050
|
connection;
|
|
5007
5051
|
paths = [];
|
|
5008
5052
|
output = null;
|
|
5009
|
-
constructor(repository
|
|
5010
|
-
this.repository = repository
|
|
5011
|
-
this.files = files
|
|
5053
|
+
constructor(repository, resolver = null, files = null, dispatcher = null) {
|
|
5054
|
+
this.repository = repository;
|
|
5055
|
+
this.files = files;
|
|
5012
5056
|
this.resolver = resolver;
|
|
5013
5057
|
this.events = dispatcher;
|
|
5014
5058
|
}
|
|
5015
5059
|
async run(paths = [], options = {}) {
|
|
5016
|
-
const files
|
|
5060
|
+
const files = await this.getMigrationFiles(paths);
|
|
5017
5061
|
const ran = await this.repository.getRan();
|
|
5018
|
-
const migrations = this.pendingMigrations(files
|
|
5062
|
+
const migrations = this.pendingMigrations(files, ran);
|
|
5019
5063
|
await this.runPending(migrations, options);
|
|
5020
5064
|
return migrations;
|
|
5021
5065
|
}
|
|
5022
|
-
pendingMigrations(files
|
|
5023
|
-
return Object.values(files
|
|
5066
|
+
pendingMigrations(files, ran) {
|
|
5067
|
+
return Object.values(files).filter((file) => !ran.includes(this.getMigrationName(file)));
|
|
5024
5068
|
}
|
|
5025
5069
|
async runPending(migrations, options = {}) {
|
|
5026
5070
|
if (migrations.length === 0 && !options.quiet) {
|
|
@@ -5038,14 +5082,14 @@ var Migrator = class {
|
|
|
5038
5082
|
}
|
|
5039
5083
|
async runUp(file, batch, _pretend) {
|
|
5040
5084
|
const migration = await this.resolvePath(file);
|
|
5041
|
-
const name
|
|
5042
|
-
await TaskManager.taskRunner(name
|
|
5043
|
-
await this.repository.log(name
|
|
5085
|
+
const name = this.getMigrationName(file);
|
|
5086
|
+
await TaskManager.taskRunner(name, () => this.runMigration(migration, "up"));
|
|
5087
|
+
await this.repository.log(name, batch);
|
|
5044
5088
|
}
|
|
5045
5089
|
async runDown(file, migration, _pretend) {
|
|
5046
5090
|
const instance = await this.resolvePath(file);
|
|
5047
|
-
const name
|
|
5048
|
-
await TaskManager.taskRunner(name
|
|
5091
|
+
const name = this.getMigrationName(file);
|
|
5092
|
+
await TaskManager.taskRunner(name, () => this.runMigration(instance, "down"));
|
|
5049
5093
|
await this.repository.delete(migration);
|
|
5050
5094
|
}
|
|
5051
5095
|
async rollback(paths = [], options = {}) {
|
|
@@ -5063,10 +5107,10 @@ var Migrator = class {
|
|
|
5063
5107
|
}
|
|
5064
5108
|
async rollbackMigrations(migrations, paths, options) {
|
|
5065
5109
|
const rolledBack = [];
|
|
5066
|
-
const files
|
|
5110
|
+
const files = await this.getMigrationFiles(paths);
|
|
5067
5111
|
Logger.info("INFO: Rolling back migrations...");
|
|
5068
5112
|
for (const migration of migrations) {
|
|
5069
|
-
const file = files
|
|
5113
|
+
const file = files[migration.migration];
|
|
5070
5114
|
if (!file) {
|
|
5071
5115
|
Logger.twoColumnDetail(Logger.parse([[migration.migration, "green"]], "", false), Logger.parse([["Migration not found", "yellow"]], "", false));
|
|
5072
5116
|
continue;
|
|
@@ -5129,15 +5173,15 @@ var Migrator = class {
|
|
|
5129
5173
|
return migrationName.split("_").slice(4).map((str) => str.charAt(0).toUpperCase() + str.slice(1)).join("");
|
|
5130
5174
|
}
|
|
5131
5175
|
async getMigrationFiles(paths) {
|
|
5132
|
-
const files
|
|
5176
|
+
const files = [];
|
|
5133
5177
|
for (const p of paths) {
|
|
5134
5178
|
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
5135
|
-
files
|
|
5179
|
+
files.push(p);
|
|
5136
5180
|
continue;
|
|
5137
5181
|
}
|
|
5138
|
-
files
|
|
5182
|
+
files.push(...await glob(p));
|
|
5139
5183
|
}
|
|
5140
|
-
return files
|
|
5184
|
+
return files.filter(Boolean).reduce((result, file) => {
|
|
5141
5185
|
result[this.getMigrationName(file)] = file;
|
|
5142
5186
|
return result;
|
|
5143
5187
|
}, {});
|
|
@@ -5292,21 +5336,19 @@ var Migrate = class {
|
|
|
5292
5336
|
const getAllMigrationFiles = async () => {
|
|
5293
5337
|
return await migrator.getMigrationFiles(await Utils.getMigrationPaths(this.basePath ?? process.cwd(), migrator, config$1.migrations.path, options.path));
|
|
5294
5338
|
};
|
|
5295
|
-
async function getStatusFor(ran
|
|
5296
|
-
const files
|
|
5297
|
-
return Object.values(files
|
|
5339
|
+
async function getStatusFor(ran, batches) {
|
|
5340
|
+
const files = await getAllMigrationFiles();
|
|
5341
|
+
return Object.values(files).map((migration) => {
|
|
5298
5342
|
const migrationName = migrator.getMigrationName(migration);
|
|
5299
5343
|
return {
|
|
5300
5344
|
name: migrationName,
|
|
5301
|
-
ran: ran
|
|
5302
|
-
batch: ran
|
|
5345
|
+
ran: ran.includes(migrationName),
|
|
5346
|
+
batch: ran.includes(migrationName) ? batches[migrationName] : null
|
|
5303
5347
|
};
|
|
5304
5348
|
});
|
|
5305
5349
|
}
|
|
5306
5350
|
if (!await migrator.repositoryExists()) this.callback("ERROR: Migration table does not exist.", "error");
|
|
5307
|
-
const
|
|
5308
|
-
const batches = await migrator.getRepository().getMigrationBatches();
|
|
5309
|
-
const migrations = await getStatusFor(ran, batches);
|
|
5351
|
+
const migrations = await getStatusFor(await migrator.repository.getRan(), await migrator.getRepository().getMigrationBatches());
|
|
5310
5352
|
if (destroyAll) await arquebus$1.destroyAll();
|
|
5311
5353
|
return migrations;
|
|
5312
5354
|
}
|
|
@@ -5321,15 +5363,13 @@ var Migrate = class {
|
|
|
5321
5363
|
const table = (config$1 === null || config$1 === void 0 || (_config$migrations = config$1.migrations) === null || _config$migrations === void 0 ? void 0 : _config$migrations.table) || "migrations";
|
|
5322
5364
|
if (config$1.skipConnection !== true) {
|
|
5323
5365
|
arquebus_default.addConnection(config$1, "default");
|
|
5324
|
-
Object.entries(config$1.connections || {}).forEach(([name
|
|
5325
|
-
arquebus_default.addConnection(connection, name
|
|
5366
|
+
Object.entries(config$1.connections || {}).forEach(([name, connection]) => {
|
|
5367
|
+
arquebus_default.addConnection(connection, name);
|
|
5326
5368
|
});
|
|
5327
5369
|
}
|
|
5328
|
-
const repository$1 = new MigrationRepository(arquebus_default, table);
|
|
5329
|
-
const migrator = new migrator_default(repository$1, arquebus_default);
|
|
5330
5370
|
return {
|
|
5331
5371
|
arquebus: arquebus_default,
|
|
5332
|
-
migrator
|
|
5372
|
+
migrator: new migrator_default(new MigrationRepository(arquebus_default, table), arquebus_default)
|
|
5333
5373
|
};
|
|
5334
5374
|
}
|
|
5335
5375
|
};
|
|
@@ -5338,9 +5378,9 @@ var Migrate = class {
|
|
|
5338
5378
|
//#region src/migrations/migration-creator.ts
|
|
5339
5379
|
var MigrationCreator = class {
|
|
5340
5380
|
postCreate = [];
|
|
5341
|
-
constructor(customStubPath, type
|
|
5381
|
+
constructor(customStubPath, type = "js") {
|
|
5342
5382
|
this.customStubPath = customStubPath;
|
|
5343
|
-
this.type = type
|
|
5383
|
+
this.type = type;
|
|
5344
5384
|
}
|
|
5345
5385
|
/**
|
|
5346
5386
|
* Create a new migration file
|
|
@@ -5351,9 +5391,9 @@ var MigrationCreator = class {
|
|
|
5351
5391
|
* @param create
|
|
5352
5392
|
* @returns
|
|
5353
5393
|
*/
|
|
5354
|
-
async create(name
|
|
5394
|
+
async create(name, dir, table, create = false) {
|
|
5355
5395
|
const stub = await this.getStub(table, create);
|
|
5356
|
-
const filePath = this.getPath(name
|
|
5396
|
+
const filePath = this.getPath(name, dir);
|
|
5357
5397
|
await this.ensureDirectoryExists(path.dirname(filePath));
|
|
5358
5398
|
await writeFile(filePath, this.populateStub(stub, table));
|
|
5359
5399
|
await this.firePostCreateHooks(table, filePath);
|
|
@@ -5394,12 +5434,12 @@ var MigrationCreator = class {
|
|
|
5394
5434
|
if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
5395
5435
|
return stub;
|
|
5396
5436
|
}
|
|
5397
|
-
getClassName(name
|
|
5398
|
-
return name
|
|
5437
|
+
getClassName(name) {
|
|
5438
|
+
return name.replace(/_+([a-z])/g, (match, char) => char.toUpperCase());
|
|
5399
5439
|
}
|
|
5400
|
-
getPath(name
|
|
5440
|
+
getPath(name, dir) {
|
|
5401
5441
|
const datePrefix = dayjs().format("YYYY_MM_DD_HHmmss");
|
|
5402
|
-
return path.join(dir, `${datePrefix}_${name
|
|
5442
|
+
return path.join(dir, `${datePrefix}_${name}.${this.type}`);
|
|
5403
5443
|
}
|
|
5404
5444
|
async firePostCreateHooks(table, filePath) {
|
|
5405
5445
|
for (const callback of this.postCreate) await callback(table, filePath);
|
|
@@ -5423,224 +5463,7 @@ var MigrationCreator = class {
|
|
|
5423
5463
|
|
|
5424
5464
|
//#endregion
|
|
5425
5465
|
//#region package.json
|
|
5426
|
-
var
|
|
5427
|
-
var version = "0.6.6";
|
|
5428
|
-
var packageManager = "pnpm@10.14.0";
|
|
5429
|
-
var description = "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.";
|
|
5430
|
-
var homepage = "https://h3ravel.toneflix.net/arquebus";
|
|
5431
|
-
var bin = { "arquebus": "./bin/index.js" };
|
|
5432
|
-
var publishConfig = { "access": "public" };
|
|
5433
|
-
var main = "./dist/index.cjs";
|
|
5434
|
-
var module = "./dist/index.js";
|
|
5435
|
-
var type = "module";
|
|
5436
|
-
var types = "./dist/index.d.ts";
|
|
5437
|
-
var files = [
|
|
5438
|
-
"dist",
|
|
5439
|
-
"bin",
|
|
5440
|
-
"types"
|
|
5441
|
-
];
|
|
5442
|
-
var exports = {
|
|
5443
|
-
".": {
|
|
5444
|
-
"cli": {
|
|
5445
|
-
"import": {
|
|
5446
|
-
"types": "./bin/index.d.ts",
|
|
5447
|
-
"default": "./bin/index.js"
|
|
5448
|
-
},
|
|
5449
|
-
"require": {
|
|
5450
|
-
"types": "./bin/index.d.cts",
|
|
5451
|
-
"default": "./bin/index.cjs"
|
|
5452
|
-
}
|
|
5453
|
-
},
|
|
5454
|
-
"worker": {
|
|
5455
|
-
"import": {
|
|
5456
|
-
"types": "./dist/index.d.ts",
|
|
5457
|
-
"default": "./dist/index.js"
|
|
5458
|
-
},
|
|
5459
|
-
"require": {
|
|
5460
|
-
"types": "./dist/index.d.cts",
|
|
5461
|
-
"default": "./dist/index.cjs"
|
|
5462
|
-
}
|
|
5463
|
-
},
|
|
5464
|
-
"node": {
|
|
5465
|
-
"import": {
|
|
5466
|
-
"types": "./dist/index.d.ts",
|
|
5467
|
-
"default": "./dist/index.js"
|
|
5468
|
-
},
|
|
5469
|
-
"require": {
|
|
5470
|
-
"types": "./dist/index.d.cts",
|
|
5471
|
-
"default": "./dist/index.cjs"
|
|
5472
|
-
}
|
|
5473
|
-
},
|
|
5474
|
-
"browser": {
|
|
5475
|
-
"import": {
|
|
5476
|
-
"types": "./dist/browser/index.d.ts",
|
|
5477
|
-
"default": "./dist/browser/index.js"
|
|
5478
|
-
},
|
|
5479
|
-
"require": {
|
|
5480
|
-
"types": "./dist/browser/index.d.cts",
|
|
5481
|
-
"default": "./dist/browser/index.cjs"
|
|
5482
|
-
}
|
|
5483
|
-
},
|
|
5484
|
-
"default": {
|
|
5485
|
-
"import": {
|
|
5486
|
-
"types": "./dist/index.d.ts",
|
|
5487
|
-
"default": "./dist/index.js"
|
|
5488
|
-
},
|
|
5489
|
-
"require": {
|
|
5490
|
-
"types": "./dist/index.d.cts",
|
|
5491
|
-
"default": "./dist/index.cjs"
|
|
5492
|
-
}
|
|
5493
|
-
}
|
|
5494
|
-
},
|
|
5495
|
-
"./migrations": {
|
|
5496
|
-
"import": {
|
|
5497
|
-
"types": "./dist/migrations/index.d.ts",
|
|
5498
|
-
"default": "./dist/migrations/index.js"
|
|
5499
|
-
},
|
|
5500
|
-
"require": {
|
|
5501
|
-
"types": "./dist/migrations/index.d.cts",
|
|
5502
|
-
"default": "./dist/migrations/index.cjs"
|
|
5503
|
-
}
|
|
5504
|
-
},
|
|
5505
|
-
"./inspector": {
|
|
5506
|
-
"import": {
|
|
5507
|
-
"types": "./dist/inspector/index.d.ts",
|
|
5508
|
-
"default": "./dist/inspector/index.js"
|
|
5509
|
-
},
|
|
5510
|
-
"require": {
|
|
5511
|
-
"types": "./dist/inspector/index.d.cts",
|
|
5512
|
-
"default": "./dist/inspector/index.cjs"
|
|
5513
|
-
}
|
|
5514
|
-
},
|
|
5515
|
-
"./seeders": {
|
|
5516
|
-
"import": {
|
|
5517
|
-
"types": "./dist/seeders/index.d.ts",
|
|
5518
|
-
"default": "./dist/seeders/index.js"
|
|
5519
|
-
},
|
|
5520
|
-
"require": {
|
|
5521
|
-
"types": "./dist/seeders/index.d.cts",
|
|
5522
|
-
"default": "./dist/seeders/index.cjs"
|
|
5523
|
-
}
|
|
5524
|
-
},
|
|
5525
|
-
"./browser": {
|
|
5526
|
-
"import": {
|
|
5527
|
-
"types": "./dist/browser/index.d.ts",
|
|
5528
|
-
"default": "./dist/browser/index.js"
|
|
5529
|
-
},
|
|
5530
|
-
"require": {
|
|
5531
|
-
"types": "./dist/browser/index.d.cts",
|
|
5532
|
-
"default": "./dist/browser/index.cjs"
|
|
5533
|
-
}
|
|
5534
|
-
},
|
|
5535
|
-
"./package.json": "./package.json",
|
|
5536
|
-
"./types": "./types/index.ts"
|
|
5537
|
-
};
|
|
5538
|
-
var repository = {
|
|
5539
|
-
"type": "git",
|
|
5540
|
-
"url": "https://github.com/h3ravel/arquebus.git"
|
|
5541
|
-
};
|
|
5542
|
-
var engines = {
|
|
5543
|
-
"node": ">=14",
|
|
5544
|
-
"pnpm": ">=4"
|
|
5545
|
-
};
|
|
5546
|
-
var scripts = {
|
|
5547
|
-
"build": "tsdown",
|
|
5548
|
-
"lint": "eslint . --ext .ts",
|
|
5549
|
-
"barrel": "barrelize >/dev/null",
|
|
5550
|
-
"postinstall": "pnpm barrel",
|
|
5551
|
-
"cmd": "cross-env TEST=true tsx --experimental-specifier-resolution=node src/cli",
|
|
5552
|
-
"cmd:watch": "cross-env TEST=true tsx watch --experimental-specifier-resolution=node src/cli",
|
|
5553
|
-
"test": "cross-env vitest --project generic",
|
|
5554
|
-
"test:mysql": "cross-env DB=mysql vitest --project node",
|
|
5555
|
-
"test:postgres": "cross-env DB=postgres vitest --project node",
|
|
5556
|
-
"test:sqlite": "cross-env DB=sqlite vitest --project node",
|
|
5557
|
-
"test:browser": "vitest --project browser",
|
|
5558
|
-
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version\" && pnpm version patch && pnpm publish --tag latest"
|
|
5559
|
-
};
|
|
5560
|
-
var husky = { "hooks": { "pre-commit": "lint-staged" } };
|
|
5561
|
-
var lint_staged = { "*.{js,json}": ["prettier --write", "git add"] };
|
|
5562
|
-
var dependencies = {
|
|
5563
|
-
"@h3ravel/shared": "^0.21.0",
|
|
5564
|
-
"@h3ravel/support": "^0.12.0",
|
|
5565
|
-
"barrelize": "^1.6.4",
|
|
5566
|
-
"chalk": "^5.6.2",
|
|
5567
|
-
"collect.js": "^4.36.1",
|
|
5568
|
-
"commander": "^14.0.1",
|
|
5569
|
-
"cross-env": "^10.0.0",
|
|
5570
|
-
"dayjs": "^1.11.18",
|
|
5571
|
-
"dotenv": "^17.2.2",
|
|
5572
|
-
"escalade": "^3.2.0",
|
|
5573
|
-
"husky": "^9.1.7",
|
|
5574
|
-
"knex": "^3.1.0",
|
|
5575
|
-
"lint-staged": "^16.2.0",
|
|
5576
|
-
"mysql2": "^3.15.0",
|
|
5577
|
-
"pg": "^8.16.3",
|
|
5578
|
-
"pluralize": "^8.0.0",
|
|
5579
|
-
"radashi": "^12.6.2",
|
|
5580
|
-
"resolve-from": "^5.0.0",
|
|
5581
|
-
"tedious": "^19.0.0"
|
|
5582
|
-
};
|
|
5583
|
-
var devDependencies = {
|
|
5584
|
-
"@eslint/js": "^9.36.0",
|
|
5585
|
-
"@types/node": "^24.5.2",
|
|
5586
|
-
"@types/pluralize": "^0.0.33",
|
|
5587
|
-
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
5588
|
-
"@typescript-eslint/parser": "^8.44.0",
|
|
5589
|
-
"@vitest/coverage-v8": "^3.2.4",
|
|
5590
|
-
"eslint": "^9.36.0",
|
|
5591
|
-
"jsdom": "^26.1.0",
|
|
5592
|
-
"prettier": "^3.6.2",
|
|
5593
|
-
"sqlite3": "5.1.7",
|
|
5594
|
-
"terser": "^5.44.0",
|
|
5595
|
-
"ts-node": "^10.9.2",
|
|
5596
|
-
"tsdown": "^0.15.4",
|
|
5597
|
-
"tsx": "^4.20.5",
|
|
5598
|
-
"typescript": "^5.9.2",
|
|
5599
|
-
"typescript-eslint": "^8.44.0",
|
|
5600
|
-
"vite-tsconfig-paths": "^5.1.4",
|
|
5601
|
-
"vitest": "^3.2.4"
|
|
5602
|
-
};
|
|
5603
|
-
var keywords = [
|
|
5604
|
-
"arquebus",
|
|
5605
|
-
"ORM",
|
|
5606
|
-
"mysql",
|
|
5607
|
-
"mariadb",
|
|
5608
|
-
"sqlite",
|
|
5609
|
-
"postgresql",
|
|
5610
|
-
"postgres",
|
|
5611
|
-
"pg",
|
|
5612
|
-
"mssql",
|
|
5613
|
-
"active record"
|
|
5614
|
-
];
|
|
5615
|
-
var pnpm = { "onlyBuiltDependencies": ["sqlite3"] };
|
|
5616
|
-
var readmeFilename = "README.md";
|
|
5617
|
-
var license = "MIT";
|
|
5618
|
-
var package_default = {
|
|
5619
|
-
name,
|
|
5620
|
-
version,
|
|
5621
|
-
packageManager,
|
|
5622
|
-
description,
|
|
5623
|
-
homepage,
|
|
5624
|
-
bin,
|
|
5625
|
-
publishConfig,
|
|
5626
|
-
main,
|
|
5627
|
-
module,
|
|
5628
|
-
type,
|
|
5629
|
-
types,
|
|
5630
|
-
files,
|
|
5631
|
-
exports,
|
|
5632
|
-
repository,
|
|
5633
|
-
engines,
|
|
5634
|
-
scripts,
|
|
5635
|
-
husky,
|
|
5636
|
-
"lint-staged": lint_staged,
|
|
5637
|
-
dependencies,
|
|
5638
|
-
devDependencies,
|
|
5639
|
-
keywords,
|
|
5640
|
-
pnpm,
|
|
5641
|
-
readmeFilename,
|
|
5642
|
-
license
|
|
5643
|
-
};
|
|
5466
|
+
var version = "0.6.7";
|
|
5644
5467
|
|
|
5645
5468
|
//#endregion
|
|
5646
5469
|
//#region src/cli/cli.ts
|
|
@@ -5697,26 +5520,26 @@ var Cli = class Cli {
|
|
|
5697
5520
|
return this;
|
|
5698
5521
|
}
|
|
5699
5522
|
async run() {
|
|
5700
|
-
const cliVersion = ["Arquebus CLI version:", Logger.log(
|
|
5523
|
+
const cliVersion = ["Arquebus CLI version:", Logger.log(version, "green", false)].join(" ");
|
|
5701
5524
|
const localVersion = ["Arquebus Local version:", Logger.log(this.modulePackage.version || "None", "green", false)].join(" ");
|
|
5702
5525
|
program.name("arquebus").version(`${cliVersion}\n${localVersion}`);
|
|
5703
|
-
program.command("init").description("Create a fresh Arquebus config.").addArgument(new Argument("[type]", "Type of config to generate.").choices(["js", "ts"]).default("js", "generates a js config")).action(async (type
|
|
5526
|
+
program.command("init").description("Create a fresh Arquebus config.").addArgument(new Argument("[type]", "Type of config to generate.").choices(["js", "ts"]).default("js", "generates a js config")).action(async (type) => {
|
|
5704
5527
|
if (!this.modulePath) this.output.error(["ERROR: No local arquebus install found", " Try running: npm install arquebus --save"]);
|
|
5705
5528
|
if (this.configPath) this.output.error(`ERROR: ${this.configPath} already exists`);
|
|
5706
5529
|
try {
|
|
5707
|
-
const stubPath = `./arquebus.config.${type
|
|
5708
|
-
const code = await readFile(path.join(this.modulePath, `/src/stubs/arquebus.config-${type
|
|
5530
|
+
const stubPath = `./arquebus.config.${type}`;
|
|
5531
|
+
const code = await readFile(path.join(this.modulePath, `/src/stubs/arquebus.config-${type}.stub`), { encoding: "utf8" });
|
|
5709
5532
|
await writeFile(path.join(this.cwd, stubPath), code);
|
|
5710
5533
|
this.output.success(`Initialized: Arquebus has been initialized as ${stubPath}`);
|
|
5711
5534
|
} catch (e) {
|
|
5712
5535
|
this.output.error("ERROR: " + e);
|
|
5713
5536
|
}
|
|
5714
5537
|
});
|
|
5715
|
-
program.command("make:migration <name>").description("Create a new migration file.").addOption(new Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("-t, --table [string]", "The table to migrate").option("-c, --create [string]", "The table to be created").option("-p, --path [path]", "The path to the migrations directory.").action(async (name
|
|
5538
|
+
program.command("make:migration <name>").description("Create a new migration file.").addOption(new Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("-t, --table [string]", "The table to migrate").option("-c, --create [string]", "The table to be created").option("-p, --path [path]", "The path to the migrations directory.").action(async (name, opts) => {
|
|
5716
5539
|
if (!this.configPath) this.terminateNotFound();
|
|
5717
5540
|
try {
|
|
5718
5541
|
var _this$config$migratio3;
|
|
5719
|
-
name
|
|
5542
|
+
name = snake(name);
|
|
5720
5543
|
const migrationPath = path.join(this.cwd, opts.path ?? ((_this$config$migratio3 = this.config.migrations) === null || _this$config$migratio3 === void 0 ? void 0 : _this$config$migratio3.path) ?? "./migrations");
|
|
5721
5544
|
let table = opts.table;
|
|
5722
5545
|
let create = Boolean(opts.create) && opts.create !== "";
|
|
@@ -5725,12 +5548,12 @@ var Cli = class Cli {
|
|
|
5725
5548
|
create = true;
|
|
5726
5549
|
}
|
|
5727
5550
|
if (!table) {
|
|
5728
|
-
const guessed = TableGuesser.guess(name
|
|
5551
|
+
const guessed = TableGuesser.guess(name);
|
|
5729
5552
|
table = guessed[0];
|
|
5730
5553
|
create = !!guessed[1];
|
|
5731
5554
|
}
|
|
5732
5555
|
this.output.info("INFO: Creating Migration");
|
|
5733
|
-
const fileName = await new MigrationCreator(void 0, opts.type).create(name
|
|
5556
|
+
const fileName = await new MigrationCreator(void 0, opts.type).create(name, migrationPath, table, create);
|
|
5734
5557
|
this.output.success(`INFO: Migration Created \n ${Logger.log(path.basename(fileName), "gray", false)}`, true);
|
|
5735
5558
|
} catch (e) {
|
|
5736
5559
|
this.output.error("ERROR: " + e);
|
|
@@ -5865,8 +5688,8 @@ var Cli = class Cli {
|
|
|
5865
5688
|
...this.config,
|
|
5866
5689
|
skipConnection: false
|
|
5867
5690
|
});
|
|
5868
|
-
const { SeederRunner } = await import("./seeders-
|
|
5869
|
-
const runner = new SeederRunner(arquebus$1);
|
|
5691
|
+
const { SeederRunner: SeederRunner$1 } = await import("./seeders-C0schOjT.mjs");
|
|
5692
|
+
const runner = new SeederRunner$1(arquebus$1);
|
|
5870
5693
|
const seederPath = path.join(basePath, ((_this$config$seeders = this.config.seeders) === null || _this$config$seeders === void 0 ? void 0 : _this$config$seeders.path) ?? "./seeders");
|
|
5871
5694
|
await runner.setConnection(this.config.client).run([seederPath]);
|
|
5872
5695
|
this.output.success("Seeders executed successfully.");
|
|
@@ -5877,16 +5700,15 @@ var Cli = class Cli {
|
|
|
5877
5700
|
/**
|
|
5878
5701
|
* Create a new seeder file
|
|
5879
5702
|
*/
|
|
5880
|
-
program.command("make:seeder <name>").description("Create a new Seeder file.").addOption(new Option("-l, --type [string]", "Type of seeder file to generate.").choices(["js", "ts"]).default("js", "generates a js seeder file")).option("--force", "Force creation if seeder already exists.", false).option("-p, --path [path]", "The path to the seeders directory.").action(async (name
|
|
5703
|
+
program.command("make:seeder <name>").description("Create a new Seeder file.").addOption(new Option("-l, --type [string]", "Type of seeder file to generate.").choices(["js", "ts"]).default("js", "generates a js seeder file")).option("--force", "Force creation if seeder already exists.", false).option("-p, --path [path]", "The path to the seeders directory.").action(async (name, opts) => {
|
|
5881
5704
|
var _this$config$seeders2;
|
|
5882
5705
|
if (!this.configPath) this.terminateNotFound();
|
|
5883
|
-
const seederPath = path.join(this.cwd, opts.path ?? ((_this$config$seeders2 = this.config.seeders) === null || _this$config$seeders2 === void 0 ? void 0 : _this$config$seeders2.path) ?? "./seeders", Str.of(name
|
|
5706
|
+
const seederPath = path.join(this.cwd, opts.path ?? ((_this$config$seeders2 = this.config.seeders) === null || _this$config$seeders2 === void 0 ? void 0 : _this$config$seeders2.path) ?? "./seeders", Str.of(name).snake("-") + "." + opts.type);
|
|
5884
5707
|
try {
|
|
5885
5708
|
if (!opts.force && await FileSystem.fileExists(seederPath)) this.output.error("ERROR: Seeder already exists.");
|
|
5886
5709
|
await mkdir(path.dirname(seederPath), { recursive: true });
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
stub = stub.replace(/{{ name }}/g, name$1);
|
|
5710
|
+
let stub = await readFile(path.join(this.modulePath, `src/stubs/seeder-${opts.type}.stub`), "utf-8");
|
|
5711
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
5890
5712
|
await writeFile(seederPath, stub);
|
|
5891
5713
|
this.output.split("INFO: Created Seeder", path.relative(this.cwd, seederPath));
|
|
5892
5714
|
} catch (e) {
|
|
@@ -5896,16 +5718,15 @@ var Cli = class Cli {
|
|
|
5896
5718
|
/**
|
|
5897
5719
|
* Create a new model file
|
|
5898
5720
|
*/
|
|
5899
|
-
program.command("make:model <name>").description("Create a new Model file.").addOption(new Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("--force", "Force creation if model already exists.", false).option("-p, --path [path]", "The path to the models directory.").action(async (name
|
|
5721
|
+
program.command("make:model <name>").description("Create a new Model file.").addOption(new Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("--force", "Force creation if model already exists.", false).option("-p, --path [path]", "The path to the models directory.").action(async (name, opts) => {
|
|
5900
5722
|
var _this$config$models;
|
|
5901
5723
|
if (!this.configPath) this.terminateNotFound();
|
|
5902
|
-
const modelPath = path.join(this.cwd, opts.path ?? ((_this$config$models = this.config.models) === null || _this$config$models === void 0 ? void 0 : _this$config$models.path) ?? "./models", name
|
|
5724
|
+
const modelPath = path.join(this.cwd, opts.path ?? ((_this$config$models = this.config.models) === null || _this$config$models === void 0 ? void 0 : _this$config$models.path) ?? "./models", name.toLowerCase() + "." + opts.type);
|
|
5903
5725
|
try {
|
|
5904
5726
|
if (!opts.force && await FileSystem.fileExists(modelPath)) this.output.error("ERROR: Model already exists.");
|
|
5905
5727
|
await mkdir(path.dirname(modelPath), { recursive: true });
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
stub = stub.replace(/{{ name }}/g, name$1);
|
|
5728
|
+
let stub = await readFile(path.join(this.modulePath, `src/stubs/model-${opts.type}.stub`), "utf-8");
|
|
5729
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
5909
5730
|
await writeFile(modelPath, stub);
|
|
5910
5731
|
this.output.success(`Created Model: ${modelPath}`);
|
|
5911
5732
|
} catch (e) {
|
|
@@ -5922,4 +5743,4 @@ var Cli = class Cli {
|
|
|
5922
5743
|
Cli.init();
|
|
5923
5744
|
|
|
5924
5745
|
//#endregion
|
|
5925
|
-
export {
|
|
5746
|
+
export { runner_default as t };
|