@h3ravel/arquebus 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/bin/index.cjs +225 -171
- package/bin/index.js +208 -122
- package/bin/seeders-8GJzfIIN.js +3 -0
- package/bin/seeders-ByeSoCAQ.cjs +131 -0
- package/bin/seeders-CltigymO.js +79 -0
- package/bin/seeders-_xJ6VGVS.cjs +3 -0
- package/dist/browser/index.cjs +9 -9
- package/dist/browser/index.d.cts +3655 -183
- package/dist/browser/index.d.ts +3655 -183
- package/dist/browser/index.js +9 -9
- package/dist/index.cjs +270 -135
- package/dist/index.d.cts +3797 -294
- package/dist/index.d.ts +3797 -294
- package/dist/index.js +263 -133
- package/dist/inspector/index.cjs +122 -46
- package/dist/inspector/index.js +119 -46
- package/dist/migrations/index.cjs +171 -151
- package/dist/migrations/index.d.cts +3510 -27
- package/dist/migrations/index.d.ts +3510 -27
- package/dist/migrations/index.js +177 -150
- package/dist/migrations/stubs/migration-js.stub +1 -1
- package/dist/migrations/stubs/migration-ts.stub +1 -1
- package/dist/migrations/stubs/migration.create-js.stub +5 -5
- package/dist/migrations/stubs/migration.create-ts.stub +5 -5
- package/dist/migrations/stubs/migration.update-js.stub +2 -2
- package/dist/migrations/stubs/migration.update-ts.stub +3 -3
- package/dist/seeders/index.cjs +141 -0
- package/dist/seeders/index.d.cts +4766 -0
- package/dist/seeders/index.d.ts +4766 -0
- package/dist/seeders/index.js +118 -0
- package/dist/seeders/index.ts +3 -0
- package/dist/seeders/runner.ts +102 -0
- package/dist/seeders/seeder-creator.ts +42 -0
- package/dist/seeders/seeder.ts +10 -0
- package/dist/stubs/seeder-js.stub +13 -0
- package/dist/stubs/seeder-ts.stub +9 -0
- package/package.json +15 -4
- package/types/builder.ts +158 -80
- package/types/container.ts +79 -66
- package/types/generics.ts +75 -36
- package/types/modeling.ts +213 -158
- package/types/query-builder.ts +223 -186
- package/types/query-methods.ts +160 -104
- package/types/utils.ts +64 -55
|
@@ -45,18 +45,16 @@ let path = require("path");
|
|
|
45
45
|
path = __toESM(path);
|
|
46
46
|
let fs = require("fs");
|
|
47
47
|
fs = __toESM(fs);
|
|
48
|
-
let pluralize = require("pluralize");
|
|
49
|
-
pluralize = __toESM(pluralize);
|
|
50
|
-
let node_fs_promises = require("node:fs/promises");
|
|
51
|
-
node_fs_promises = __toESM(node_fs_promises);
|
|
52
48
|
let fs_promises = require("fs/promises");
|
|
53
49
|
fs_promises = __toESM(fs_promises);
|
|
54
50
|
let escalade_sync = require("escalade/sync");
|
|
55
51
|
escalade_sync = __toESM(escalade_sync);
|
|
56
52
|
let resolve_from = require("resolve-from");
|
|
57
53
|
resolve_from = __toESM(resolve_from);
|
|
58
|
-
let
|
|
59
|
-
|
|
54
|
+
let pluralize = require("pluralize");
|
|
55
|
+
pluralize = __toESM(pluralize);
|
|
56
|
+
let node_fs_promises = require("node:fs/promises");
|
|
57
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
60
58
|
let node_path = require("node:path");
|
|
61
59
|
node_path = __toESM(node_path);
|
|
62
60
|
let node_url = require("node:url");
|
|
@@ -1451,7 +1449,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
1451
1449
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
1452
1450
|
/**
|
|
1453
1451
|
* Compose function that merges multiple classes and mixins
|
|
1454
|
-
*
|
|
1452
|
+
*
|
|
1455
1453
|
* @example
|
|
1456
1454
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
1457
1455
|
* return class extends Base {
|
|
@@ -1488,10 +1486,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
1488
1486
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
1489
1487
|
* console.log(user.pluginMethod()) // "plugin"
|
|
1490
1488
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
1491
|
-
*
|
|
1492
|
-
* @param Base
|
|
1493
|
-
* @param mixins
|
|
1494
|
-
* @returns
|
|
1489
|
+
*
|
|
1490
|
+
* @param Base
|
|
1491
|
+
* @param mixins
|
|
1492
|
+
* @returns
|
|
1495
1493
|
*/
|
|
1496
1494
|
function compose$1(Base, ...mixins) {
|
|
1497
1495
|
/**
|
|
@@ -1545,10 +1543,10 @@ const getSetterMethod = (attr) => {
|
|
|
1545
1543
|
};
|
|
1546
1544
|
/**
|
|
1547
1545
|
* Tap into a model a collection instance
|
|
1548
|
-
*
|
|
1549
|
-
* @param instance
|
|
1550
|
-
* @param callback
|
|
1551
|
-
* @returns
|
|
1546
|
+
*
|
|
1547
|
+
* @param instance
|
|
1548
|
+
* @param callback
|
|
1549
|
+
* @returns
|
|
1552
1550
|
*/
|
|
1553
1551
|
const tap = (instance, callback) => {
|
|
1554
1552
|
const result = callback(instance);
|
|
@@ -2384,8 +2382,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
2384
2382
|
const results = await this.take(1).get(columns);
|
|
2385
2383
|
return results.count() > 0 ? results.first() : null;
|
|
2386
2384
|
}
|
|
2387
|
-
async firstOrFail(columns
|
|
2388
|
-
const model = await this.first(columns);
|
|
2385
|
+
async firstOrFail(...columns) {
|
|
2386
|
+
const model = await this.first(...columns);
|
|
2389
2387
|
if (model) return model;
|
|
2390
2388
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2391
2389
|
}
|
|
@@ -2424,7 +2422,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
2424
2422
|
}
|
|
2425
2423
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
2426
2424
|
this.query.addSelect(this.shouldSelect(columns));
|
|
2427
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
2425
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
2428
2426
|
}
|
|
2429
2427
|
shouldSelect(columns = ["*"]) {
|
|
2430
2428
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -2702,9 +2700,6 @@ const UniqueIds = (Model$1) => {
|
|
|
2702
2700
|
uniqueIds() {
|
|
2703
2701
|
return [];
|
|
2704
2702
|
}
|
|
2705
|
-
newUniqueId() {
|
|
2706
|
-
return null;
|
|
2707
|
-
}
|
|
2708
2703
|
setUniqueIds() {
|
|
2709
2704
|
const uniqueIds = this.uniqueIds();
|
|
2710
2705
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -2726,6 +2721,7 @@ var Paginator = class {
|
|
|
2726
2721
|
options = {};
|
|
2727
2722
|
static setFormatter(formatter) {
|
|
2728
2723
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
2724
|
+
if (!formatter) return;
|
|
2729
2725
|
this.formatter = formatter;
|
|
2730
2726
|
}
|
|
2731
2727
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -2814,8 +2810,10 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
2814
2810
|
asProxy() {
|
|
2815
2811
|
return new Proxy(this, {
|
|
2816
2812
|
get: function(target, prop) {
|
|
2813
|
+
var _target$connector$cli;
|
|
2817
2814
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2818
2815
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
2816
|
+
const skipReturning = !!((_target$connector$cli = target.connector.client.config) === null || _target$connector$cli === void 0 || (_target$connector$cli = _target$connector$cli.client) === null || _target$connector$cli === void 0 ? void 0 : _target$connector$cli.includes("mysql")) && prop === "returning";
|
|
2819
2817
|
if ([
|
|
2820
2818
|
"select",
|
|
2821
2819
|
"from",
|
|
@@ -2878,7 +2876,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
2878
2876
|
"clearWhere",
|
|
2879
2877
|
"clearHaving",
|
|
2880
2878
|
"clearGroup"
|
|
2881
|
-
].includes(prop)) return (...args) => {
|
|
2879
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2882
2880
|
target.connector[prop](...args);
|
|
2883
2881
|
return target.asProxy();
|
|
2884
2882
|
};
|
|
@@ -2935,7 +2933,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
2935
2933
|
} while (countResults === count);
|
|
2936
2934
|
return true;
|
|
2937
2935
|
}
|
|
2938
|
-
async paginate(page = 1, perPage = 15) {
|
|
2936
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
2939
2937
|
const total = await this.clone().clearOrder().count("*");
|
|
2940
2938
|
let results;
|
|
2941
2939
|
if (total > 0) {
|
|
@@ -2999,6 +2997,59 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
2999
2997
|
};
|
|
3000
2998
|
var query_builder_default = QueryBuilder;
|
|
3001
2999
|
|
|
3000
|
+
//#endregion
|
|
3001
|
+
//#region src/cli/utils.ts
|
|
3002
|
+
const join = path.default.join;
|
|
3003
|
+
var Utils = class {
|
|
3004
|
+
/**
|
|
3005
|
+
* Wraps text with chalk
|
|
3006
|
+
*
|
|
3007
|
+
* @param txt
|
|
3008
|
+
* @param color
|
|
3009
|
+
* @returns
|
|
3010
|
+
*/
|
|
3011
|
+
static textFormat(txt, color) {
|
|
3012
|
+
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
3013
|
+
}
|
|
3014
|
+
static findModulePkg(moduleId, cwd) {
|
|
3015
|
+
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
3016
|
+
let packageName = "";
|
|
3017
|
+
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
3018
|
+
packageName += parts.shift();
|
|
3019
|
+
const packageJson = path.default.join(packageName, "package.json");
|
|
3020
|
+
const resolved = resolve_from.default.silent(cwd ?? process.cwd(), packageJson);
|
|
3021
|
+
if (!resolved) return;
|
|
3022
|
+
return path.default.join(path.default.dirname(resolved), parts.join("/"));
|
|
3023
|
+
}
|
|
3024
|
+
static async getMigrationPaths(cwd, migrator, defaultPath, path$7) {
|
|
3025
|
+
if (path$7) return [join(cwd, path$7)];
|
|
3026
|
+
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
3027
|
+
}
|
|
3028
|
+
/**
|
|
3029
|
+
* Check if file exists
|
|
3030
|
+
*
|
|
3031
|
+
* @param path
|
|
3032
|
+
* @returns
|
|
3033
|
+
*/
|
|
3034
|
+
static async fileExists(path$7) {
|
|
3035
|
+
try {
|
|
3036
|
+
await (0, fs_promises.access)(path$7);
|
|
3037
|
+
return true;
|
|
3038
|
+
} catch {
|
|
3039
|
+
return false;
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
static findUpConfig(cwd, name, extensions) {
|
|
3043
|
+
return (0, escalade_sync.default)(cwd, (_dir, names) => {
|
|
3044
|
+
for (const ext of extensions) {
|
|
3045
|
+
const filename = `${name}.${ext}`;
|
|
3046
|
+
if (names.includes(filename)) return filename;
|
|
3047
|
+
}
|
|
3048
|
+
return false;
|
|
3049
|
+
});
|
|
3050
|
+
}
|
|
3051
|
+
};
|
|
3052
|
+
|
|
3002
3053
|
//#endregion
|
|
3003
3054
|
//#region src/arquebus.ts
|
|
3004
3055
|
var arquebus = class arquebus {
|
|
@@ -3020,22 +3071,22 @@ var arquebus = class arquebus {
|
|
|
3020
3071
|
return this.instance;
|
|
3021
3072
|
}
|
|
3022
3073
|
/**
|
|
3023
|
-
* Initialize a new database connection
|
|
3024
|
-
*
|
|
3025
|
-
* @returns
|
|
3074
|
+
* Initialize a new database connection
|
|
3075
|
+
*
|
|
3076
|
+
* @returns
|
|
3026
3077
|
*/
|
|
3027
3078
|
static fire(connection = null) {
|
|
3028
3079
|
return this.getInstance().getConnection(connection);
|
|
3029
3080
|
}
|
|
3030
3081
|
/**
|
|
3031
|
-
* Initialize a new database connection
|
|
3032
|
-
*
|
|
3082
|
+
* Initialize a new database connection
|
|
3083
|
+
*
|
|
3033
3084
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
3034
|
-
*
|
|
3085
|
+
*
|
|
3035
3086
|
* @deprecated since version 0.3.0
|
|
3036
3087
|
* @alias fire
|
|
3037
|
-
*
|
|
3038
|
-
* @returns
|
|
3088
|
+
*
|
|
3089
|
+
* @returns
|
|
3039
3090
|
*/
|
|
3040
3091
|
static connection(connection = null) {
|
|
3041
3092
|
return this.fire(connection);
|
|
@@ -3072,11 +3123,12 @@ var arquebus = class arquebus {
|
|
|
3072
3123
|
}
|
|
3073
3124
|
getConnection(name = null) {
|
|
3074
3125
|
name = name || "default";
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
this.
|
|
3126
|
+
const resolvedName = this.connections[name] ? name : "default";
|
|
3127
|
+
if (this.manager[resolvedName] === void 0) {
|
|
3128
|
+
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
3129
|
+
this.manager[resolvedName] = queryBuilder;
|
|
3078
3130
|
}
|
|
3079
|
-
return this.manager[
|
|
3131
|
+
return this.manager[resolvedName];
|
|
3080
3132
|
}
|
|
3081
3133
|
addConnection(config, name = "default") {
|
|
3082
3134
|
this.connections[name] = {
|
|
@@ -3093,13 +3145,13 @@ var arquebus = class arquebus {
|
|
|
3093
3145
|
}
|
|
3094
3146
|
/**
|
|
3095
3147
|
* Autoload the config file
|
|
3096
|
-
*
|
|
3097
|
-
* @param addConnection
|
|
3148
|
+
*
|
|
3149
|
+
* @param addConnection
|
|
3098
3150
|
* @default true
|
|
3099
|
-
* If set to `false` we will no attempt add the connection, we
|
|
3151
|
+
* If set to `false` we will no attempt add the connection, we
|
|
3100
3152
|
* will just go ahead and return the config
|
|
3101
|
-
*
|
|
3102
|
-
* @returns
|
|
3153
|
+
*
|
|
3154
|
+
* @returns
|
|
3103
3155
|
*/
|
|
3104
3156
|
static async autoLoad(addConnection = true) {
|
|
3105
3157
|
let config;
|
|
@@ -3116,6 +3168,23 @@ var arquebus = class arquebus {
|
|
|
3116
3168
|
if (addConnection) instance.addConnection(config, config.client);
|
|
3117
3169
|
return config;
|
|
3118
3170
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3171
|
+
const candidateDirs = [
|
|
3172
|
+
process.cwd(),
|
|
3173
|
+
path.default.join(process.cwd(), "test", "cli"),
|
|
3174
|
+
path.default.join(process.cwd(), "test")
|
|
3175
|
+
];
|
|
3176
|
+
for (const dir of candidateDirs) {
|
|
3177
|
+
const found = Utils.findUpConfig(dir, "arquebus.config", [
|
|
3178
|
+
"js",
|
|
3179
|
+
"ts",
|
|
3180
|
+
"cjs"
|
|
3181
|
+
]);
|
|
3182
|
+
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
3183
|
+
config = (await import(found)).default;
|
|
3184
|
+
if (addConnection) instance.addConnection(config, config.client);
|
|
3185
|
+
return config;
|
|
3186
|
+
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3187
|
+
}
|
|
3119
3188
|
return {};
|
|
3120
3189
|
}
|
|
3121
3190
|
beginTransaction(connection = null) {
|
|
@@ -3174,14 +3243,15 @@ var arquebus_default = arquebus;
|
|
|
3174
3243
|
|
|
3175
3244
|
//#endregion
|
|
3176
3245
|
//#region src/model.ts
|
|
3177
|
-
const
|
|
3246
|
+
const ModelClass = class {};
|
|
3247
|
+
const BaseModel = compose(ModelClass, has_attributes_default, hides_attributes_default, has_relations_default, has_timestamps_default, has_hooks_default, has_global_scopes_default, unique_ids_default);
|
|
3178
3248
|
var Model = class Model extends BaseModel {
|
|
3179
|
-
primaryKey = "id";
|
|
3180
3249
|
builder = null;
|
|
3181
3250
|
table = null;
|
|
3182
3251
|
keyType = "int";
|
|
3183
3252
|
incrementing = true;
|
|
3184
3253
|
withCount = [];
|
|
3254
|
+
primaryKey = "id";
|
|
3185
3255
|
perPage = 15;
|
|
3186
3256
|
static globalScopes = {};
|
|
3187
3257
|
static pluginInitializers = {};
|
|
@@ -3191,6 +3261,7 @@ var Model = class Model extends BaseModel {
|
|
|
3191
3261
|
eagerLoad = {};
|
|
3192
3262
|
exists = false;
|
|
3193
3263
|
with = [];
|
|
3264
|
+
name;
|
|
3194
3265
|
trx = null;
|
|
3195
3266
|
constructor(attributes = {}) {
|
|
3196
3267
|
super();
|
|
@@ -3962,8 +4033,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
3962
4033
|
const results = await this.take(1).get(columns);
|
|
3963
4034
|
return results.count() > 0 ? results.first() : null;
|
|
3964
4035
|
}
|
|
3965
|
-
async firstOrFail(columns
|
|
3966
|
-
const model = await this.first(columns);
|
|
4036
|
+
async firstOrFail(...columns) {
|
|
4037
|
+
const model = await this.first(...columns);
|
|
3967
4038
|
if (model !== null) return model;
|
|
3968
4039
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
3969
4040
|
}
|
|
@@ -4139,7 +4210,9 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4139
4210
|
}
|
|
4140
4211
|
asProxy() {
|
|
4141
4212
|
return new Proxy(this, { get(target, prop) {
|
|
4213
|
+
var _target$query$connect;
|
|
4142
4214
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
4215
|
+
const skipReturning = !!((_target$query$connect = target.query.connector) === null || _target$query$connect === void 0 || (_target$query$connect = _target$query$connect.client.config) === null || _target$query$connect === void 0 || (_target$query$connect = _target$query$connect.client) === null || _target$query$connect === void 0 ? void 0 : _target$query$connect.includes("mysql")) && prop === "returning";
|
|
4143
4216
|
if ([
|
|
4144
4217
|
"select",
|
|
4145
4218
|
"from",
|
|
@@ -4202,7 +4275,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4202
4275
|
"clearWhere",
|
|
4203
4276
|
"clearHaving",
|
|
4204
4277
|
"clearGroup"
|
|
4205
|
-
].includes(prop)) return (...args) => {
|
|
4278
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
4206
4279
|
target.query[prop](...args);
|
|
4207
4280
|
return target.asProxy();
|
|
4208
4281
|
};
|
|
@@ -5081,9 +5154,9 @@ var Migrator = class {
|
|
|
5081
5154
|
}
|
|
5082
5155
|
/**
|
|
5083
5156
|
* Drop all tables and re-run all migrations
|
|
5084
|
-
*
|
|
5085
|
-
* @param paths
|
|
5086
|
-
* @param options
|
|
5157
|
+
*
|
|
5158
|
+
* @param paths
|
|
5159
|
+
* @param options
|
|
5087
5160
|
*/
|
|
5088
5161
|
async fresh(paths, options) {
|
|
5089
5162
|
/** Initialise connections */
|
|
@@ -5175,59 +5248,6 @@ var Migrator = class {
|
|
|
5175
5248
|
};
|
|
5176
5249
|
var migrator_default = Migrator;
|
|
5177
5250
|
|
|
5178
|
-
//#endregion
|
|
5179
|
-
//#region src/cli/utils.ts
|
|
5180
|
-
const join = path.default.join;
|
|
5181
|
-
var Utils = class {
|
|
5182
|
-
/**
|
|
5183
|
-
* Wraps text with chalk
|
|
5184
|
-
*
|
|
5185
|
-
* @param txt
|
|
5186
|
-
* @param color
|
|
5187
|
-
* @returns
|
|
5188
|
-
*/
|
|
5189
|
-
static textFormat(txt, color) {
|
|
5190
|
-
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
5191
|
-
}
|
|
5192
|
-
static findModulePkg(moduleId, cwd) {
|
|
5193
|
-
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
5194
|
-
let packageName = "";
|
|
5195
|
-
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
5196
|
-
packageName += parts.shift();
|
|
5197
|
-
const packageJson = path.default.join(packageName, "package.json");
|
|
5198
|
-
const resolved = resolve_from.default.silent(cwd ?? process.cwd(), packageJson);
|
|
5199
|
-
if (!resolved) return;
|
|
5200
|
-
return path.default.join(path.default.dirname(resolved), parts.join("/"));
|
|
5201
|
-
}
|
|
5202
|
-
static async getMigrationPaths(cwd, migrator, defaultPath, path$5) {
|
|
5203
|
-
if (path$5) return [join(cwd, path$5)];
|
|
5204
|
-
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
5205
|
-
}
|
|
5206
|
-
/**
|
|
5207
|
-
* Check if file exists
|
|
5208
|
-
*
|
|
5209
|
-
* @param path
|
|
5210
|
-
* @returns
|
|
5211
|
-
*/
|
|
5212
|
-
static async fileExists(path$5) {
|
|
5213
|
-
try {
|
|
5214
|
-
await (0, fs_promises.access)(path$5);
|
|
5215
|
-
return true;
|
|
5216
|
-
} catch {
|
|
5217
|
-
return false;
|
|
5218
|
-
}
|
|
5219
|
-
}
|
|
5220
|
-
static findUpConfig(cwd, name, extensions) {
|
|
5221
|
-
return (0, escalade_sync.default)(cwd, (_dir, names) => {
|
|
5222
|
-
for (const ext of extensions) {
|
|
5223
|
-
const filename = `${name}.${ext}`;
|
|
5224
|
-
if (names.includes(filename)) return filename;
|
|
5225
|
-
}
|
|
5226
|
-
return false;
|
|
5227
|
-
});
|
|
5228
|
-
}
|
|
5229
|
-
};
|
|
5230
|
-
|
|
5231
5251
|
//#endregion
|
|
5232
5252
|
//#region src/migrate.ts
|
|
5233
5253
|
var Migrate = class {
|
|
@@ -5239,10 +5259,10 @@ var Migrate = class {
|
|
|
5239
5259
|
}
|
|
5240
5260
|
/**
|
|
5241
5261
|
* Runs all pending migrations
|
|
5242
|
-
*
|
|
5243
|
-
* @param config
|
|
5244
|
-
* @param options
|
|
5245
|
-
* @param destroyAll
|
|
5262
|
+
*
|
|
5263
|
+
* @param config
|
|
5264
|
+
* @param options
|
|
5265
|
+
* @param destroyAll
|
|
5246
5266
|
*/
|
|
5247
5267
|
async run(config, options = {}, destroyAll = false) {
|
|
5248
5268
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5256,10 +5276,10 @@ var Migrate = class {
|
|
|
5256
5276
|
}
|
|
5257
5277
|
/**
|
|
5258
5278
|
* Rollback the last migration
|
|
5259
|
-
*
|
|
5260
|
-
* @param config
|
|
5261
|
-
* @param options
|
|
5262
|
-
* @param destroyAll
|
|
5279
|
+
*
|
|
5280
|
+
* @param config
|
|
5281
|
+
* @param options
|
|
5282
|
+
* @param destroyAll
|
|
5263
5283
|
*/
|
|
5264
5284
|
async rollback(config, options = {}, destroyAll = false) {
|
|
5265
5285
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5273,10 +5293,10 @@ var Migrate = class {
|
|
|
5273
5293
|
}
|
|
5274
5294
|
/**
|
|
5275
5295
|
* Rollback all database migrations
|
|
5276
|
-
*
|
|
5277
|
-
* @param config
|
|
5278
|
-
* @param options
|
|
5279
|
-
* @param destroyAll
|
|
5296
|
+
*
|
|
5297
|
+
* @param config
|
|
5298
|
+
* @param options
|
|
5299
|
+
* @param destroyAll
|
|
5280
5300
|
*/
|
|
5281
5301
|
async reset(config, options = {}, destroyAll = false) {
|
|
5282
5302
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5291,10 +5311,10 @@ var Migrate = class {
|
|
|
5291
5311
|
}
|
|
5292
5312
|
/**
|
|
5293
5313
|
* Reset and re-run all migrations
|
|
5294
|
-
*
|
|
5295
|
-
* @param config
|
|
5296
|
-
* @param options
|
|
5297
|
-
* @param destroyAll
|
|
5314
|
+
*
|
|
5315
|
+
* @param config
|
|
5316
|
+
* @param options
|
|
5317
|
+
* @param destroyAll
|
|
5298
5318
|
*/
|
|
5299
5319
|
async refresh(config, options = {}, destroyAll = false) {
|
|
5300
5320
|
await this.reset(config, Object.assign({}, options, { quiet: true }), false);
|
|
@@ -5303,10 +5323,10 @@ var Migrate = class {
|
|
|
5303
5323
|
}
|
|
5304
5324
|
/**
|
|
5305
5325
|
* Drop all tables and re-run all migrations
|
|
5306
|
-
*
|
|
5307
|
-
* @param config
|
|
5308
|
-
* @param options
|
|
5309
|
-
* @param destroyAll
|
|
5326
|
+
*
|
|
5327
|
+
* @param config
|
|
5328
|
+
* @param options
|
|
5329
|
+
* @param destroyAll
|
|
5310
5330
|
*/
|
|
5311
5331
|
async fresh(config, options = {}, destroyAll = false) {
|
|
5312
5332
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5316,8 +5336,8 @@ var Migrate = class {
|
|
|
5316
5336
|
}
|
|
5317
5337
|
/**
|
|
5318
5338
|
* Prepares the database for migration
|
|
5319
|
-
*
|
|
5320
|
-
* @param migrator
|
|
5339
|
+
*
|
|
5340
|
+
* @param migrator
|
|
5321
5341
|
*/
|
|
5322
5342
|
async prepareDatabase(migrator) {
|
|
5323
5343
|
if (!await migrator.repositoryExists()) {
|
|
@@ -5329,11 +5349,11 @@ var Migrate = class {
|
|
|
5329
5349
|
}
|
|
5330
5350
|
/**
|
|
5331
5351
|
* Check the status of available migrations
|
|
5332
|
-
*
|
|
5333
|
-
* @param config
|
|
5334
|
-
* @param options
|
|
5335
|
-
* @param destroyAll
|
|
5336
|
-
* @returns
|
|
5352
|
+
*
|
|
5353
|
+
* @param config
|
|
5354
|
+
* @param options
|
|
5355
|
+
* @param destroyAll
|
|
5356
|
+
* @returns
|
|
5337
5357
|
*/
|
|
5338
5358
|
async status(config, options = {}, destroyAll = false) {
|
|
5339
5359
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5360,9 +5380,9 @@ var Migrate = class {
|
|
|
5360
5380
|
}
|
|
5361
5381
|
/**
|
|
5362
5382
|
* Setup the database connection
|
|
5363
|
-
*
|
|
5364
|
-
* @param config
|
|
5365
|
-
* @returns
|
|
5383
|
+
*
|
|
5384
|
+
* @param config
|
|
5385
|
+
* @returns
|
|
5366
5386
|
*/
|
|
5367
5387
|
async setupConnection(config) {
|
|
5368
5388
|
var _config$migrations;
|
|
@@ -5392,54 +5412,54 @@ var MigrationCreator = class {
|
|
|
5392
5412
|
}
|
|
5393
5413
|
/**
|
|
5394
5414
|
* Create a new migration file
|
|
5395
|
-
*
|
|
5396
|
-
* @param name
|
|
5397
|
-
* @param dir
|
|
5398
|
-
* @param table
|
|
5399
|
-
* @param create
|
|
5400
|
-
* @returns
|
|
5415
|
+
*
|
|
5416
|
+
* @param name
|
|
5417
|
+
* @param dir
|
|
5418
|
+
* @param table
|
|
5419
|
+
* @param create
|
|
5420
|
+
* @returns
|
|
5401
5421
|
*/
|
|
5402
5422
|
async create(name, dir, table, create = false) {
|
|
5403
|
-
const stub = this.getStub(table, create);
|
|
5423
|
+
const stub = await this.getStub(table, create);
|
|
5404
5424
|
const filePath = this.getPath(name, dir);
|
|
5405
5425
|
await this.ensureDirectoryExists(path.default.dirname(filePath));
|
|
5406
|
-
await node_fs_promises.
|
|
5426
|
+
await (0, node_fs_promises.writeFile)(filePath, this.populateStub(stub, table));
|
|
5407
5427
|
await this.firePostCreateHooks(table, filePath);
|
|
5408
5428
|
return filePath;
|
|
5409
5429
|
}
|
|
5410
5430
|
/**
|
|
5411
5431
|
* Publish migrations from third party vendors
|
|
5412
|
-
*
|
|
5413
|
-
* @param dir
|
|
5414
|
-
* @param callback
|
|
5432
|
+
*
|
|
5433
|
+
* @param dir
|
|
5434
|
+
* @param callback
|
|
5415
5435
|
*/
|
|
5416
5436
|
async publish(dir, callback) {
|
|
5417
|
-
const migrationFiles = await node_fs_promises.
|
|
5437
|
+
const migrationFiles = await (0, node_fs_promises.readdir)(this.customStubPath ?? "");
|
|
5418
5438
|
await this.ensureDirectoryExists(dir);
|
|
5419
5439
|
for (const migrationFile of migrationFiles) {
|
|
5420
5440
|
const sourceFilePath = path.default.join(this.customStubPath ?? "", migrationFile);
|
|
5421
5441
|
const destinationFilePath = path.default.join(dir, migrationFile);
|
|
5422
|
-
await node_fs_promises.
|
|
5442
|
+
await (0, node_fs_promises.copyFile)(sourceFilePath, destinationFilePath);
|
|
5423
5443
|
if (callback) callback(migrationFile, sourceFilePath, destinationFilePath);
|
|
5424
5444
|
}
|
|
5425
5445
|
}
|
|
5426
|
-
getStub(table, create = false) {
|
|
5446
|
+
async getStub(table, create = false) {
|
|
5427
5447
|
let stub;
|
|
5428
5448
|
if (!table) {
|
|
5429
5449
|
const customPath = path.default.join(this.customStubPath ?? "", `migration-${this.type}.stub`);
|
|
5430
5450
|
console.log("\n", customPath, "---");
|
|
5431
|
-
stub =
|
|
5451
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration-${this.type}.stub`);
|
|
5432
5452
|
} else if (create) {
|
|
5433
5453
|
const customPath = path.default.join(this.customStubPath ?? "", `migration.create-${this.type}.stub`);
|
|
5434
|
-
stub =
|
|
5454
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.create-${this.type}.stub`);
|
|
5435
5455
|
} else {
|
|
5436
5456
|
const customPath = path.default.join(this.customStubPath ?? "", `migration.update-${this.type}.stub`);
|
|
5437
|
-
stub =
|
|
5457
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.update-${this.type}.stub`);
|
|
5438
5458
|
}
|
|
5439
|
-
return (0,
|
|
5459
|
+
return await (0, node_fs_promises.readFile)(stub, "utf-8");
|
|
5440
5460
|
}
|
|
5441
5461
|
populateStub(stub, table) {
|
|
5442
|
-
if (table
|
|
5462
|
+
if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
5443
5463
|
return stub;
|
|
5444
5464
|
}
|
|
5445
5465
|
getClassName(name) {
|
|
@@ -5456,7 +5476,7 @@ var MigrationCreator = class {
|
|
|
5456
5476
|
this.postCreate.push(callback);
|
|
5457
5477
|
}
|
|
5458
5478
|
async ensureDirectoryExists(dir) {
|
|
5459
|
-
await node_fs_promises.
|
|
5479
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
5460
5480
|
}
|
|
5461
5481
|
stubPath(stub = "") {
|
|
5462
5482
|
const __dirname$1 = this.getDirname({});
|