@h3ravel/arquebus 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/bin/index.cjs +225 -171
- package/bin/index.js +208 -122
- package/bin/seeders-8GJzfIIN.js +3 -0
- package/bin/seeders-ByeSoCAQ.cjs +131 -0
- package/bin/seeders-CltigymO.js +79 -0
- package/bin/seeders-_xJ6VGVS.cjs +3 -0
- package/dist/browser/index.cjs +9 -9
- package/dist/browser/index.d.cts +3655 -183
- package/dist/browser/index.d.ts +3655 -183
- package/dist/browser/index.js +9 -9
- package/dist/index.cjs +270 -135
- package/dist/index.d.cts +3797 -294
- package/dist/index.d.ts +3797 -294
- package/dist/index.js +263 -133
- package/dist/inspector/index.cjs +122 -46
- package/dist/inspector/index.js +119 -46
- package/dist/migrations/index.cjs +171 -151
- package/dist/migrations/index.d.cts +3510 -27
- package/dist/migrations/index.d.ts +3510 -27
- package/dist/migrations/index.js +177 -150
- package/dist/migrations/stubs/migration-js.stub +1 -1
- package/dist/migrations/stubs/migration-ts.stub +1 -1
- package/dist/migrations/stubs/migration.create-js.stub +5 -5
- package/dist/migrations/stubs/migration.create-ts.stub +5 -5
- package/dist/migrations/stubs/migration.update-js.stub +2 -2
- package/dist/migrations/stubs/migration.update-ts.stub +3 -3
- package/dist/seeders/index.cjs +141 -0
- package/dist/seeders/index.d.cts +4766 -0
- package/dist/seeders/index.d.ts +4766 -0
- package/dist/seeders/index.js +118 -0
- package/dist/seeders/index.ts +3 -0
- package/dist/seeders/runner.ts +102 -0
- package/dist/seeders/seeder-creator.ts +42 -0
- package/dist/seeders/seeder.ts +10 -0
- package/dist/stubs/seeder-js.stub +13 -0
- package/dist/stubs/seeder-ts.stub +9 -0
- package/package.json +15 -4
- package/types/builder.ts +158 -80
- package/types/container.ts +79 -66
- package/types/generics.ts +75 -36
- package/types/modeling.ts +213 -158
- package/types/query-builder.ts +223 -186
- package/types/query-methods.ts +160 -104
- package/types/utils.ts +64 -55
package/bin/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import "./seeders-CltigymO.js";
|
|
2
3
|
import "node:module";
|
|
3
4
|
import { Argument, Option, program } from "commander";
|
|
4
5
|
import { access } from "fs/promises";
|
|
5
6
|
import escalade from "escalade/sync";
|
|
6
7
|
import path from "path";
|
|
7
8
|
import resolveFrom from "resolve-from";
|
|
8
|
-
import fs, { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
9
|
-
import { Logger, TaskManager } from "@h3ravel/shared";
|
|
9
|
+
import fs, { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
10
|
+
import { FileSystem, Logger, TaskManager } from "@h3ravel/shared";
|
|
10
11
|
import { assign, camel, diff, flat, get, isArray, isEmpty, isEqual, isString, omit, pick, set, snake, trim } from "radashi";
|
|
11
12
|
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
12
13
|
import dayjs from "dayjs";
|
|
@@ -14,10 +15,9 @@ import collect, { Collection, collect as collect$1 } from "collect.js";
|
|
|
14
15
|
import Knex from "knex";
|
|
15
16
|
import { existsSync } from "fs";
|
|
16
17
|
import pluralize from "pluralize";
|
|
17
|
-
import { existsSync as existsSync$1, readFileSync } from "node:fs";
|
|
18
18
|
import { dirname } from "node:path";
|
|
19
19
|
import { fileURLToPath } from "node:url";
|
|
20
|
-
import
|
|
20
|
+
import { Str } from "@h3ravel/support";
|
|
21
21
|
import { config } from "dotenv";
|
|
22
22
|
|
|
23
23
|
//#region rolldown:runtime
|
|
@@ -37,10 +37,10 @@ const join = path.join;
|
|
|
37
37
|
var Utils = class {
|
|
38
38
|
/**
|
|
39
39
|
* Wraps text with chalk
|
|
40
|
-
*
|
|
41
|
-
* @param txt
|
|
42
|
-
* @param color
|
|
43
|
-
* @returns
|
|
40
|
+
*
|
|
41
|
+
* @param txt
|
|
42
|
+
* @param color
|
|
43
|
+
* @returns
|
|
44
44
|
*/
|
|
45
45
|
static textFormat(txt, color) {
|
|
46
46
|
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
@@ -61,9 +61,9 @@ var Utils = class {
|
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Check if file exists
|
|
64
|
-
*
|
|
65
|
-
* @param path
|
|
66
|
-
* @returns
|
|
64
|
+
*
|
|
65
|
+
* @param path
|
|
66
|
+
* @returns
|
|
67
67
|
*/
|
|
68
68
|
static async fileExists(path$1) {
|
|
69
69
|
try {
|
|
@@ -1489,7 +1489,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
1489
1489
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
1490
1490
|
/**
|
|
1491
1491
|
* Compose function that merges multiple classes and mixins
|
|
1492
|
-
*
|
|
1492
|
+
*
|
|
1493
1493
|
* @example
|
|
1494
1494
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
1495
1495
|
* return class extends Base {
|
|
@@ -1526,10 +1526,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
1526
1526
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
1527
1527
|
* console.log(user.pluginMethod()) // "plugin"
|
|
1528
1528
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
1529
|
-
*
|
|
1530
|
-
* @param Base
|
|
1531
|
-
* @param mixins
|
|
1532
|
-
* @returns
|
|
1529
|
+
*
|
|
1530
|
+
* @param Base
|
|
1531
|
+
* @param mixins
|
|
1532
|
+
* @returns
|
|
1533
1533
|
*/
|
|
1534
1534
|
function compose$1(Base, ...mixins) {
|
|
1535
1535
|
/**
|
|
@@ -1583,10 +1583,10 @@ const getSetterMethod = (attr) => {
|
|
|
1583
1583
|
};
|
|
1584
1584
|
/**
|
|
1585
1585
|
* Tap into a model a collection instance
|
|
1586
|
-
*
|
|
1587
|
-
* @param instance
|
|
1588
|
-
* @param callback
|
|
1589
|
-
* @returns
|
|
1586
|
+
*
|
|
1587
|
+
* @param instance
|
|
1588
|
+
* @param callback
|
|
1589
|
+
* @returns
|
|
1590
1590
|
*/
|
|
1591
1591
|
const tap = (instance, callback) => {
|
|
1592
1592
|
const result = callback(instance);
|
|
@@ -2422,8 +2422,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
2422
2422
|
const results = await this.take(1).get(columns);
|
|
2423
2423
|
return results.count() > 0 ? results.first() : null;
|
|
2424
2424
|
}
|
|
2425
|
-
async firstOrFail(columns
|
|
2426
|
-
const model = await this.first(columns);
|
|
2425
|
+
async firstOrFail(...columns) {
|
|
2426
|
+
const model = await this.first(...columns);
|
|
2427
2427
|
if (model) return model;
|
|
2428
2428
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2429
2429
|
}
|
|
@@ -2462,7 +2462,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
2462
2462
|
}
|
|
2463
2463
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
2464
2464
|
this.query.addSelect(this.shouldSelect(columns));
|
|
2465
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
2465
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
2466
2466
|
}
|
|
2467
2467
|
shouldSelect(columns = ["*"]) {
|
|
2468
2468
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -2740,9 +2740,6 @@ const UniqueIds = (Model$1) => {
|
|
|
2740
2740
|
uniqueIds() {
|
|
2741
2741
|
return [];
|
|
2742
2742
|
}
|
|
2743
|
-
newUniqueId() {
|
|
2744
|
-
return null;
|
|
2745
|
-
}
|
|
2746
2743
|
setUniqueIds() {
|
|
2747
2744
|
const uniqueIds = this.uniqueIds();
|
|
2748
2745
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -2764,6 +2761,7 @@ var Paginator = class {
|
|
|
2764
2761
|
options = {};
|
|
2765
2762
|
static setFormatter(formatter) {
|
|
2766
2763
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
2764
|
+
if (!formatter) return;
|
|
2767
2765
|
this.formatter = formatter;
|
|
2768
2766
|
}
|
|
2769
2767
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -2852,8 +2850,10 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2852
2850
|
asProxy() {
|
|
2853
2851
|
return new Proxy(this, {
|
|
2854
2852
|
get: function(target, prop) {
|
|
2853
|
+
var _target$connector$cli;
|
|
2855
2854
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2856
2855
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
2856
|
+
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";
|
|
2857
2857
|
if ([
|
|
2858
2858
|
"select",
|
|
2859
2859
|
"from",
|
|
@@ -2916,7 +2916,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2916
2916
|
"clearWhere",
|
|
2917
2917
|
"clearHaving",
|
|
2918
2918
|
"clearGroup"
|
|
2919
|
-
].includes(prop)) return (...args) => {
|
|
2919
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2920
2920
|
target.connector[prop](...args);
|
|
2921
2921
|
return target.asProxy();
|
|
2922
2922
|
};
|
|
@@ -2973,7 +2973,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2973
2973
|
} while (countResults === count);
|
|
2974
2974
|
return true;
|
|
2975
2975
|
}
|
|
2976
|
-
async paginate(page = 1, perPage = 15) {
|
|
2976
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
2977
2977
|
const total = await this.clone().clearOrder().count("*");
|
|
2978
2978
|
let results;
|
|
2979
2979
|
if (total > 0) {
|
|
@@ -3058,22 +3058,22 @@ var arquebus = class arquebus {
|
|
|
3058
3058
|
return this.instance;
|
|
3059
3059
|
}
|
|
3060
3060
|
/**
|
|
3061
|
-
* Initialize a new database connection
|
|
3062
|
-
*
|
|
3063
|
-
* @returns
|
|
3061
|
+
* Initialize a new database connection
|
|
3062
|
+
*
|
|
3063
|
+
* @returns
|
|
3064
3064
|
*/
|
|
3065
3065
|
static fire(connection = null) {
|
|
3066
3066
|
return this.getInstance().getConnection(connection);
|
|
3067
3067
|
}
|
|
3068
3068
|
/**
|
|
3069
|
-
* Initialize a new database connection
|
|
3070
|
-
*
|
|
3069
|
+
* Initialize a new database connection
|
|
3070
|
+
*
|
|
3071
3071
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
3072
|
-
*
|
|
3072
|
+
*
|
|
3073
3073
|
* @deprecated since version 0.3.0
|
|
3074
3074
|
* @alias fire
|
|
3075
|
-
*
|
|
3076
|
-
* @returns
|
|
3075
|
+
*
|
|
3076
|
+
* @returns
|
|
3077
3077
|
*/
|
|
3078
3078
|
static connection(connection = null) {
|
|
3079
3079
|
return this.fire(connection);
|
|
@@ -3110,11 +3110,12 @@ var arquebus = class arquebus {
|
|
|
3110
3110
|
}
|
|
3111
3111
|
getConnection(name$1 = null) {
|
|
3112
3112
|
name$1 = name$1 || "default";
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
this.
|
|
3113
|
+
const resolvedName = this.connections[name$1] ? name$1 : "default";
|
|
3114
|
+
if (this.manager[resolvedName] === void 0) {
|
|
3115
|
+
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
3116
|
+
this.manager[resolvedName] = queryBuilder;
|
|
3116
3117
|
}
|
|
3117
|
-
return this.manager[
|
|
3118
|
+
return this.manager[resolvedName];
|
|
3118
3119
|
}
|
|
3119
3120
|
addConnection(config$1, name$1 = "default") {
|
|
3120
3121
|
this.connections[name$1] = {
|
|
@@ -3131,13 +3132,13 @@ var arquebus = class arquebus {
|
|
|
3131
3132
|
}
|
|
3132
3133
|
/**
|
|
3133
3134
|
* Autoload the config file
|
|
3134
|
-
*
|
|
3135
|
-
* @param addConnection
|
|
3135
|
+
*
|
|
3136
|
+
* @param addConnection
|
|
3136
3137
|
* @default true
|
|
3137
|
-
* If set to `false` we will no attempt add the connection, we
|
|
3138
|
+
* If set to `false` we will no attempt add the connection, we
|
|
3138
3139
|
* will just go ahead and return the config
|
|
3139
|
-
*
|
|
3140
|
-
* @returns
|
|
3140
|
+
*
|
|
3141
|
+
* @returns
|
|
3141
3142
|
*/
|
|
3142
3143
|
static async autoLoad(addConnection = true) {
|
|
3143
3144
|
let config$1;
|
|
@@ -3154,6 +3155,23 @@ var arquebus = class arquebus {
|
|
|
3154
3155
|
if (addConnection) instance.addConnection(config$1, config$1.client);
|
|
3155
3156
|
return config$1;
|
|
3156
3157
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3158
|
+
const candidateDirs = [
|
|
3159
|
+
process.cwd(),
|
|
3160
|
+
path.join(process.cwd(), "test", "cli"),
|
|
3161
|
+
path.join(process.cwd(), "test")
|
|
3162
|
+
];
|
|
3163
|
+
for (const dir of candidateDirs) {
|
|
3164
|
+
const found = Utils.findUpConfig(dir, "arquebus.config", [
|
|
3165
|
+
"js",
|
|
3166
|
+
"ts",
|
|
3167
|
+
"cjs"
|
|
3168
|
+
]);
|
|
3169
|
+
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
3170
|
+
config$1 = (await import(found)).default;
|
|
3171
|
+
if (addConnection) instance.addConnection(config$1, config$1.client);
|
|
3172
|
+
return config$1;
|
|
3173
|
+
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3174
|
+
}
|
|
3157
3175
|
return {};
|
|
3158
3176
|
}
|
|
3159
3177
|
beginTransaction(connection = null) {
|
|
@@ -3212,14 +3230,15 @@ var arquebus_default = arquebus;
|
|
|
3212
3230
|
|
|
3213
3231
|
//#endregion
|
|
3214
3232
|
//#region src/model.ts
|
|
3215
|
-
const
|
|
3233
|
+
const ModelClass = class {};
|
|
3234
|
+
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);
|
|
3216
3235
|
var Model = class Model extends BaseModel {
|
|
3217
|
-
primaryKey = "id";
|
|
3218
3236
|
builder = null;
|
|
3219
3237
|
table = null;
|
|
3220
3238
|
keyType = "int";
|
|
3221
3239
|
incrementing = true;
|
|
3222
3240
|
withCount = [];
|
|
3241
|
+
primaryKey = "id";
|
|
3223
3242
|
perPage = 15;
|
|
3224
3243
|
static globalScopes = {};
|
|
3225
3244
|
static pluginInitializers = {};
|
|
@@ -3229,6 +3248,7 @@ var Model = class Model extends BaseModel {
|
|
|
3229
3248
|
eagerLoad = {};
|
|
3230
3249
|
exists = false;
|
|
3231
3250
|
with = [];
|
|
3251
|
+
name;
|
|
3232
3252
|
trx = null;
|
|
3233
3253
|
constructor(attributes = {}) {
|
|
3234
3254
|
super();
|
|
@@ -4000,8 +4020,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
4000
4020
|
const results = await this.take(1).get(columns);
|
|
4001
4021
|
return results.count() > 0 ? results.first() : null;
|
|
4002
4022
|
}
|
|
4003
|
-
async firstOrFail(columns
|
|
4004
|
-
const model = await this.first(columns);
|
|
4023
|
+
async firstOrFail(...columns) {
|
|
4024
|
+
const model = await this.first(...columns);
|
|
4005
4025
|
if (model !== null) return model;
|
|
4006
4026
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
4007
4027
|
}
|
|
@@ -4177,7 +4197,9 @@ var Builder = class Builder extends Inference {
|
|
|
4177
4197
|
}
|
|
4178
4198
|
asProxy() {
|
|
4179
4199
|
return new Proxy(this, { get(target, prop) {
|
|
4200
|
+
var _target$query$connect;
|
|
4180
4201
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
4202
|
+
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";
|
|
4181
4203
|
if ([
|
|
4182
4204
|
"select",
|
|
4183
4205
|
"from",
|
|
@@ -4240,7 +4262,7 @@ var Builder = class Builder extends Inference {
|
|
|
4240
4262
|
"clearWhere",
|
|
4241
4263
|
"clearHaving",
|
|
4242
4264
|
"clearGroup"
|
|
4243
|
-
].includes(prop)) return (...args) => {
|
|
4265
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
4244
4266
|
target.query[prop](...args);
|
|
4245
4267
|
return target.asProxy();
|
|
4246
4268
|
};
|
|
@@ -5099,9 +5121,9 @@ var Migrator = class {
|
|
|
5099
5121
|
}
|
|
5100
5122
|
/**
|
|
5101
5123
|
* Drop all tables and re-run all migrations
|
|
5102
|
-
*
|
|
5103
|
-
* @param paths
|
|
5104
|
-
* @param options
|
|
5124
|
+
*
|
|
5125
|
+
* @param paths
|
|
5126
|
+
* @param options
|
|
5105
5127
|
*/
|
|
5106
5128
|
async fresh(paths, options) {
|
|
5107
5129
|
/** Initialise connections */
|
|
@@ -5204,10 +5226,10 @@ var Migrate = class {
|
|
|
5204
5226
|
}
|
|
5205
5227
|
/**
|
|
5206
5228
|
* Runs all pending migrations
|
|
5207
|
-
*
|
|
5208
|
-
* @param config
|
|
5209
|
-
* @param options
|
|
5210
|
-
* @param destroyAll
|
|
5229
|
+
*
|
|
5230
|
+
* @param config
|
|
5231
|
+
* @param options
|
|
5232
|
+
* @param destroyAll
|
|
5211
5233
|
*/
|
|
5212
5234
|
async run(config$1, options = {}, destroyAll = false) {
|
|
5213
5235
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5221,10 +5243,10 @@ var Migrate = class {
|
|
|
5221
5243
|
}
|
|
5222
5244
|
/**
|
|
5223
5245
|
* Rollback the last migration
|
|
5224
|
-
*
|
|
5225
|
-
* @param config
|
|
5226
|
-
* @param options
|
|
5227
|
-
* @param destroyAll
|
|
5246
|
+
*
|
|
5247
|
+
* @param config
|
|
5248
|
+
* @param options
|
|
5249
|
+
* @param destroyAll
|
|
5228
5250
|
*/
|
|
5229
5251
|
async rollback(config$1, options = {}, destroyAll = false) {
|
|
5230
5252
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5238,10 +5260,10 @@ var Migrate = class {
|
|
|
5238
5260
|
}
|
|
5239
5261
|
/**
|
|
5240
5262
|
* Rollback all database migrations
|
|
5241
|
-
*
|
|
5242
|
-
* @param config
|
|
5243
|
-
* @param options
|
|
5244
|
-
* @param destroyAll
|
|
5263
|
+
*
|
|
5264
|
+
* @param config
|
|
5265
|
+
* @param options
|
|
5266
|
+
* @param destroyAll
|
|
5245
5267
|
*/
|
|
5246
5268
|
async reset(config$1, options = {}, destroyAll = false) {
|
|
5247
5269
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5256,10 +5278,10 @@ var Migrate = class {
|
|
|
5256
5278
|
}
|
|
5257
5279
|
/**
|
|
5258
5280
|
* Reset and re-run all migrations
|
|
5259
|
-
*
|
|
5260
|
-
* @param config
|
|
5261
|
-
* @param options
|
|
5262
|
-
* @param destroyAll
|
|
5281
|
+
*
|
|
5282
|
+
* @param config
|
|
5283
|
+
* @param options
|
|
5284
|
+
* @param destroyAll
|
|
5263
5285
|
*/
|
|
5264
5286
|
async refresh(config$1, options = {}, destroyAll = false) {
|
|
5265
5287
|
await this.reset(config$1, Object.assign({}, options, { quiet: true }), false);
|
|
@@ -5268,10 +5290,10 @@ var Migrate = class {
|
|
|
5268
5290
|
}
|
|
5269
5291
|
/**
|
|
5270
5292
|
* Drop all tables and re-run all migrations
|
|
5271
|
-
*
|
|
5272
|
-
* @param config
|
|
5273
|
-
* @param options
|
|
5274
|
-
* @param destroyAll
|
|
5293
|
+
*
|
|
5294
|
+
* @param config
|
|
5295
|
+
* @param options
|
|
5296
|
+
* @param destroyAll
|
|
5275
5297
|
*/
|
|
5276
5298
|
async fresh(config$1, options = {}, destroyAll = false) {
|
|
5277
5299
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5281,8 +5303,8 @@ var Migrate = class {
|
|
|
5281
5303
|
}
|
|
5282
5304
|
/**
|
|
5283
5305
|
* Prepares the database for migration
|
|
5284
|
-
*
|
|
5285
|
-
* @param migrator
|
|
5306
|
+
*
|
|
5307
|
+
* @param migrator
|
|
5286
5308
|
*/
|
|
5287
5309
|
async prepareDatabase(migrator) {
|
|
5288
5310
|
if (!await migrator.repositoryExists()) {
|
|
@@ -5294,11 +5316,11 @@ var Migrate = class {
|
|
|
5294
5316
|
}
|
|
5295
5317
|
/**
|
|
5296
5318
|
* Check the status of available migrations
|
|
5297
|
-
*
|
|
5298
|
-
* @param config
|
|
5299
|
-
* @param options
|
|
5300
|
-
* @param destroyAll
|
|
5301
|
-
* @returns
|
|
5319
|
+
*
|
|
5320
|
+
* @param config
|
|
5321
|
+
* @param options
|
|
5322
|
+
* @param destroyAll
|
|
5323
|
+
* @returns
|
|
5302
5324
|
*/
|
|
5303
5325
|
async status(config$1, options = {}, destroyAll = false) {
|
|
5304
5326
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config$1);
|
|
@@ -5325,9 +5347,9 @@ var Migrate = class {
|
|
|
5325
5347
|
}
|
|
5326
5348
|
/**
|
|
5327
5349
|
* Setup the database connection
|
|
5328
|
-
*
|
|
5329
|
-
* @param config
|
|
5330
|
-
* @returns
|
|
5350
|
+
*
|
|
5351
|
+
* @param config
|
|
5352
|
+
* @returns
|
|
5331
5353
|
*/
|
|
5332
5354
|
async setupConnection(config$1) {
|
|
5333
5355
|
var _config$migrations;
|
|
@@ -5357,54 +5379,54 @@ var MigrationCreator = class {
|
|
|
5357
5379
|
}
|
|
5358
5380
|
/**
|
|
5359
5381
|
* Create a new migration file
|
|
5360
|
-
*
|
|
5361
|
-
* @param name
|
|
5362
|
-
* @param dir
|
|
5363
|
-
* @param table
|
|
5364
|
-
* @param create
|
|
5365
|
-
* @returns
|
|
5382
|
+
*
|
|
5383
|
+
* @param name
|
|
5384
|
+
* @param dir
|
|
5385
|
+
* @param table
|
|
5386
|
+
* @param create
|
|
5387
|
+
* @returns
|
|
5366
5388
|
*/
|
|
5367
5389
|
async create(name$1, dir, table, create = false) {
|
|
5368
|
-
const stub = this.getStub(table, create);
|
|
5390
|
+
const stub = await this.getStub(table, create);
|
|
5369
5391
|
const filePath = this.getPath(name$1, dir);
|
|
5370
5392
|
await this.ensureDirectoryExists(path.dirname(filePath));
|
|
5371
|
-
await
|
|
5393
|
+
await writeFile(filePath, this.populateStub(stub, table));
|
|
5372
5394
|
await this.firePostCreateHooks(table, filePath);
|
|
5373
5395
|
return filePath;
|
|
5374
5396
|
}
|
|
5375
5397
|
/**
|
|
5376
5398
|
* Publish migrations from third party vendors
|
|
5377
|
-
*
|
|
5378
|
-
* @param dir
|
|
5379
|
-
* @param callback
|
|
5399
|
+
*
|
|
5400
|
+
* @param dir
|
|
5401
|
+
* @param callback
|
|
5380
5402
|
*/
|
|
5381
5403
|
async publish(dir, callback) {
|
|
5382
|
-
const migrationFiles = await
|
|
5404
|
+
const migrationFiles = await readdir(this.customStubPath ?? "");
|
|
5383
5405
|
await this.ensureDirectoryExists(dir);
|
|
5384
5406
|
for (const migrationFile of migrationFiles) {
|
|
5385
5407
|
const sourceFilePath = path.join(this.customStubPath ?? "", migrationFile);
|
|
5386
5408
|
const destinationFilePath = path.join(dir, migrationFile);
|
|
5387
|
-
await
|
|
5409
|
+
await copyFile(sourceFilePath, destinationFilePath);
|
|
5388
5410
|
if (callback) callback(migrationFile, sourceFilePath, destinationFilePath);
|
|
5389
5411
|
}
|
|
5390
5412
|
}
|
|
5391
|
-
getStub(table, create = false) {
|
|
5413
|
+
async getStub(table, create = false) {
|
|
5392
5414
|
let stub;
|
|
5393
5415
|
if (!table) {
|
|
5394
5416
|
const customPath = path.join(this.customStubPath ?? "", `migration-${this.type}.stub`);
|
|
5395
5417
|
console.log("\n", customPath, "---");
|
|
5396
|
-
stub =
|
|
5418
|
+
stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration-${this.type}.stub`);
|
|
5397
5419
|
} else if (create) {
|
|
5398
5420
|
const customPath = path.join(this.customStubPath ?? "", `migration.create-${this.type}.stub`);
|
|
5399
|
-
stub =
|
|
5421
|
+
stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.create-${this.type}.stub`);
|
|
5400
5422
|
} else {
|
|
5401
5423
|
const customPath = path.join(this.customStubPath ?? "", `migration.update-${this.type}.stub`);
|
|
5402
|
-
stub =
|
|
5424
|
+
stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.update-${this.type}.stub`);
|
|
5403
5425
|
}
|
|
5404
|
-
return
|
|
5426
|
+
return await readFile(stub, "utf-8");
|
|
5405
5427
|
}
|
|
5406
5428
|
populateStub(stub, table) {
|
|
5407
|
-
if (table
|
|
5429
|
+
if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
5408
5430
|
return stub;
|
|
5409
5431
|
}
|
|
5410
5432
|
getClassName(name$1) {
|
|
@@ -5421,7 +5443,7 @@ var MigrationCreator = class {
|
|
|
5421
5443
|
this.postCreate.push(callback);
|
|
5422
5444
|
}
|
|
5423
5445
|
async ensureDirectoryExists(dir) {
|
|
5424
|
-
await
|
|
5446
|
+
await mkdir(dir, { recursive: true });
|
|
5425
5447
|
}
|
|
5426
5448
|
stubPath(stub = "") {
|
|
5427
5449
|
const __dirname$1 = this.getDirname(import.meta);
|
|
@@ -5437,7 +5459,7 @@ var MigrationCreator = class {
|
|
|
5437
5459
|
//#endregion
|
|
5438
5460
|
//#region package.json
|
|
5439
5461
|
var name = "@h3ravel/arquebus";
|
|
5440
|
-
var version = "0.
|
|
5462
|
+
var version = "0.5.0";
|
|
5441
5463
|
var packageManager = "pnpm@10.14.0";
|
|
5442
5464
|
var description = "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.";
|
|
5443
5465
|
var homepage = "https://h3ravel.toneflix.net/arquebus";
|
|
@@ -5525,6 +5547,16 @@ var exports = {
|
|
|
5525
5547
|
"default": "./dist/inspector/index.cjs"
|
|
5526
5548
|
}
|
|
5527
5549
|
},
|
|
5550
|
+
"./seeders": {
|
|
5551
|
+
"import": {
|
|
5552
|
+
"types": "./dist/seeders/index.d.ts",
|
|
5553
|
+
"default": "./dist/seeders/index.js"
|
|
5554
|
+
},
|
|
5555
|
+
"require": {
|
|
5556
|
+
"types": "./dist/seeders/index.d.cts",
|
|
5557
|
+
"default": "./dist/seeders/index.cjs"
|
|
5558
|
+
}
|
|
5559
|
+
},
|
|
5528
5560
|
"./browser": {
|
|
5529
5561
|
"import": {
|
|
5530
5562
|
"types": "./dist/browser/index.d.ts",
|
|
@@ -5555,12 +5587,13 @@ var scripts = {
|
|
|
5555
5587
|
"test:postgres": "cross-env DB=postgres vitest --project node",
|
|
5556
5588
|
"test:sqlite": "cross-env DB=sqlite vitest --project node",
|
|
5557
5589
|
"test:browser": "vitest --project browser",
|
|
5558
|
-
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version
|
|
5590
|
+
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version\" && pnpm version patch && pnpm publish --tag latest"
|
|
5559
5591
|
};
|
|
5560
5592
|
var husky = { "hooks": { "pre-commit": "lint-staged" } };
|
|
5561
5593
|
var lint_staged = { "*.{js,json}": ["prettier --write", "git add"] };
|
|
5562
5594
|
var dependencies = {
|
|
5563
|
-
"@h3ravel/shared": "^0.
|
|
5595
|
+
"@h3ravel/shared": "^0.20.12",
|
|
5596
|
+
"@h3ravel/support": "^0.12.0",
|
|
5564
5597
|
"chalk": "^5.6.2",
|
|
5565
5598
|
"collect.js": "^4.36.1",
|
|
5566
5599
|
"commander": "^14.0.1",
|
|
@@ -5574,7 +5607,6 @@ var dependencies = {
|
|
|
5574
5607
|
"mysql2": "^3.15.0",
|
|
5575
5608
|
"pg": "^8.16.3",
|
|
5576
5609
|
"pluralize": "^8.0.0",
|
|
5577
|
-
"prettier": "^3.6.2",
|
|
5578
5610
|
"radashi": "^12.6.2",
|
|
5579
5611
|
"resolve-from": "^5.0.0",
|
|
5580
5612
|
"tedious": "^19.0.0"
|
|
@@ -5588,6 +5620,7 @@ var devDependencies = {
|
|
|
5588
5620
|
"@vitest/coverage-v8": "^3.2.4",
|
|
5589
5621
|
"eslint": "^9.36.0",
|
|
5590
5622
|
"jsdom": "^26.1.0",
|
|
5623
|
+
"prettier": "^3.6.2",
|
|
5591
5624
|
"sqlite3": "5.1.7",
|
|
5592
5625
|
"terser": "^5.44.0",
|
|
5593
5626
|
"ts-node": "^10.9.2",
|
|
@@ -5654,7 +5687,12 @@ var Cli = class Cli {
|
|
|
5654
5687
|
this.basePath = basePath ?? (process.env.TEST === "true" ? "test/cli" : "");
|
|
5655
5688
|
}
|
|
5656
5689
|
terminateNotFound() {
|
|
5657
|
-
|
|
5690
|
+
const cmd = Logger.log([["arquebus init", [
|
|
5691
|
+
"italic",
|
|
5692
|
+
"black",
|
|
5693
|
+
"bgGray"
|
|
5694
|
+
]]], "", false);
|
|
5695
|
+
this.output.error(`ERROR: Arquebus config not found. Run ${cmd} first.`);
|
|
5658
5696
|
}
|
|
5659
5697
|
static init() {
|
|
5660
5698
|
config({ quiet: true });
|
|
@@ -5690,8 +5728,8 @@ var Cli = class Cli {
|
|
|
5690
5728
|
return this;
|
|
5691
5729
|
}
|
|
5692
5730
|
async run() {
|
|
5693
|
-
const cliVersion = ["Arquebus CLI version:",
|
|
5694
|
-
const localVersion = ["Arquebus Local version:",
|
|
5731
|
+
const cliVersion = ["Arquebus CLI version:", Logger.log(package_default.version, "green", false)].join(" ");
|
|
5732
|
+
const localVersion = ["Arquebus Local version:", Logger.log(this.modulePackage.version || "None", "green", false)].join(" ");
|
|
5695
5733
|
program.name("arquebus").version(`${cliVersion}\n${localVersion}`);
|
|
5696
5734
|
program.command("init").description("Create a fresh Arquebus config.").addArgument(new Argument("[type]", "Type of config to generate.").choices(["js", "ts"]).default("js", "generates a js config")).action(async (type$1) => {
|
|
5697
5735
|
if (!this.modulePath) this.output.error(["ERROR: No local arquebus install found", " Try running: npm install arquebus --save"]);
|
|
@@ -5705,16 +5743,16 @@ var Cli = class Cli {
|
|
|
5705
5743
|
this.output.error("ERROR: " + e);
|
|
5706
5744
|
}
|
|
5707
5745
|
});
|
|
5708
|
-
program.command("
|
|
5746
|
+
program.command("make:migration <name>").description("Create a new migration file.").addOption(new Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("-t, --table [string]", "The table to migrate").option("-c, --create [string]", "The table to be created").option("-p, --path [path]", "The path to the migrations directory.").action(async (name$1, opts) => {
|
|
5709
5747
|
if (!this.configPath) this.terminateNotFound();
|
|
5710
5748
|
try {
|
|
5711
5749
|
var _this$config$migratio3;
|
|
5712
5750
|
name$1 = snake(name$1);
|
|
5713
5751
|
const migrationPath = path.join(this.cwd, opts.path ?? ((_this$config$migratio3 = this.config.migrations) === null || _this$config$migratio3 === void 0 ? void 0 : _this$config$migratio3.path) ?? "./migrations");
|
|
5714
5752
|
let table = opts.table;
|
|
5715
|
-
let create = opts.create
|
|
5716
|
-
if (!table && typeof create === "string") {
|
|
5717
|
-
table = create;
|
|
5753
|
+
let create = Boolean(opts.create) && opts.create !== "";
|
|
5754
|
+
if (!table && typeof opts.create === "string") {
|
|
5755
|
+
table = opts.create;
|
|
5718
5756
|
create = true;
|
|
5719
5757
|
}
|
|
5720
5758
|
if (!table) {
|
|
@@ -5724,7 +5762,7 @@ var Cli = class Cli {
|
|
|
5724
5762
|
}
|
|
5725
5763
|
this.output.info("INFO: Creating Migration");
|
|
5726
5764
|
const fileName = await new MigrationCreator(void 0, opts.type).create(name$1, migrationPath, table, create);
|
|
5727
|
-
this.output.success(`INFO: Migration Created \n ${
|
|
5765
|
+
this.output.success(`INFO: Migration Created \n ${Logger.log(path.basename(fileName), "gray", false)}`, true);
|
|
5728
5766
|
} catch (e) {
|
|
5729
5767
|
this.output.error("ERROR: " + e);
|
|
5730
5768
|
}
|
|
@@ -5741,9 +5779,10 @@ var Cli = class Cli {
|
|
|
5741
5779
|
const pkgJson = await import(path.join(packagePath, "package.json"));
|
|
5742
5780
|
if (!packagePath) this.output.error(`ERROR: package ${pkg} not found`);
|
|
5743
5781
|
const creator = new MigrationCreator(path.join(packagePath, pkgJson.migrations ?? "migrations"));
|
|
5744
|
-
|
|
5782
|
+
const pkgInf = Logger.log(path.basename(pkgJson.name + "@" + pkgJson.version), ["italic", "gray"], false);
|
|
5783
|
+
this.output.info(`INFO: Publishing migrations from ${pkgInf}`);
|
|
5745
5784
|
await creator.publish(basePath, (fileName) => {
|
|
5746
|
-
|
|
5785
|
+
this.output.split("INFO: Migration Published", fileName, "success");
|
|
5747
5786
|
});
|
|
5748
5787
|
} catch (e) {
|
|
5749
5788
|
this.output.error("ERROR: " + e);
|
|
@@ -5756,7 +5795,11 @@ var Cli = class Cli {
|
|
|
5756
5795
|
if (!this.configPath) this.terminateNotFound();
|
|
5757
5796
|
const basePath = opts.path ? path.join(this.cwd, opts.path) : this.cwd;
|
|
5758
5797
|
try {
|
|
5759
|
-
|
|
5798
|
+
const step = typeof opts.step === "string" ? parseInt(opts.step) : opts.step;
|
|
5799
|
+
await new Migrate(basePath).run(this.config, {
|
|
5800
|
+
...opts,
|
|
5801
|
+
step
|
|
5802
|
+
}, true);
|
|
5760
5803
|
} catch (e) {
|
|
5761
5804
|
this.output.error("ERROR: " + e);
|
|
5762
5805
|
}
|
|
@@ -5770,7 +5813,10 @@ var Cli = class Cli {
|
|
|
5770
5813
|
try {
|
|
5771
5814
|
await new Migrate(basePath, void 0, (msg, sts) => {
|
|
5772
5815
|
if (sts) this.output[sts](msg);
|
|
5773
|
-
}).rollback(this.config,
|
|
5816
|
+
}).rollback(this.config, {
|
|
5817
|
+
...opts,
|
|
5818
|
+
step: typeof opts.step === "string" ? parseInt(opts.step) : opts.step
|
|
5819
|
+
}, true);
|
|
5774
5820
|
} catch (e) {
|
|
5775
5821
|
this.output.error("ERROR: " + e);
|
|
5776
5822
|
}
|
|
@@ -5828,9 +5874,9 @@ var Cli = class Cli {
|
|
|
5828
5874
|
if (sts) this.output[sts](msg);
|
|
5829
5875
|
}).status(this.config, opts, true);
|
|
5830
5876
|
if (migrations.length > 0) {
|
|
5831
|
-
Logger.twoColumnLog(
|
|
5877
|
+
Logger.twoColumnLog(Logger.log("Migration name", "gray", false), Logger.log("Batch / Status", "gray", false));
|
|
5832
5878
|
migrations.forEach((migration) => {
|
|
5833
|
-
const status = migration.ran ? `[${migration.batch}] ${
|
|
5879
|
+
const status = migration.ran ? `[${migration.batch}] ${Logger.log("Ran", "green", false)}` : Logger.log("Pending", "yellow", false);
|
|
5834
5880
|
Logger.twoColumnLog(migration.name, status);
|
|
5835
5881
|
});
|
|
5836
5882
|
} else console.log("No migrations found");
|
|
@@ -5839,9 +5885,49 @@ var Cli = class Cli {
|
|
|
5839
5885
|
}
|
|
5840
5886
|
});
|
|
5841
5887
|
/**
|
|
5888
|
+
* Run database seeders
|
|
5889
|
+
*/
|
|
5890
|
+
program.command("db:seed").description("Run database seeders.").option("-p, --path [path]", "The path to the seeders directory.").action(async (opts) => {
|
|
5891
|
+
if (!this.configPath) this.terminateNotFound();
|
|
5892
|
+
const basePath = opts.path ? path.join(this.cwd, opts.path) : this.cwd;
|
|
5893
|
+
try {
|
|
5894
|
+
var _this$config$seeders;
|
|
5895
|
+
const { arquebus: arquebus$1 } = await new Migrate(basePath).setupConnection({
|
|
5896
|
+
...this.config,
|
|
5897
|
+
skipConnection: false
|
|
5898
|
+
});
|
|
5899
|
+
const { SeederRunner } = await import("./seeders-8GJzfIIN.js");
|
|
5900
|
+
const runner = new SeederRunner(arquebus$1);
|
|
5901
|
+
const seederPath = path.join(basePath, ((_this$config$seeders = this.config.seeders) === null || _this$config$seeders === void 0 ? void 0 : _this$config$seeders.path) ?? "./seeders");
|
|
5902
|
+
await runner.setConnection(this.config.client).run([seederPath]);
|
|
5903
|
+
this.output.success("Seeders executed successfully.");
|
|
5904
|
+
} catch (e) {
|
|
5905
|
+
this.output.error("ERROR: " + e);
|
|
5906
|
+
}
|
|
5907
|
+
});
|
|
5908
|
+
/**
|
|
5909
|
+
* Create a new seeder file
|
|
5910
|
+
*/
|
|
5911
|
+
program.command("make:seeder <name>").description("Create a new Seeder file.").addOption(new Option("-l, --type [string]", "Type of seeder file to generate.").choices(["js", "ts"]).default("js", "generates a js seeder file")).option("--force", "Force creation if seeder already exists.", false).option("-p, --path [path]", "The path to the seeders directory.").action(async (name$1, opts) => {
|
|
5912
|
+
var _this$config$seeders2;
|
|
5913
|
+
if (!this.configPath) this.terminateNotFound();
|
|
5914
|
+
const seederPath = path.join(this.cwd, opts.path ?? ((_this$config$seeders2 = this.config.seeders) === null || _this$config$seeders2 === void 0 ? void 0 : _this$config$seeders2.path) ?? "./seeders", Str.of(name$1).snake("-") + "." + opts.type);
|
|
5915
|
+
try {
|
|
5916
|
+
if (!opts.force && await Utils.fileExists(seederPath)) this.output.error("ERROR: Seeder already exists.");
|
|
5917
|
+
await mkdir(path.dirname(seederPath), { recursive: true });
|
|
5918
|
+
const stubPath = path.join(this.modulePath, `src/stubs/seeder-${opts.type}.stub`);
|
|
5919
|
+
let stub = await readFile(stubPath, "utf-8");
|
|
5920
|
+
stub = stub.replace(/{{ name }}/g, name$1);
|
|
5921
|
+
await writeFile(seederPath, stub);
|
|
5922
|
+
this.output.split("INFO: Created Seeder", path.relative(this.cwd, seederPath));
|
|
5923
|
+
} catch (e) {
|
|
5924
|
+
this.output.error("ERROR: " + e);
|
|
5925
|
+
}
|
|
5926
|
+
});
|
|
5927
|
+
/**
|
|
5842
5928
|
* Create a new model file
|
|
5843
5929
|
*/
|
|
5844
|
-
program.command("model
|
|
5930
|
+
program.command("make:model <name>").description("Create a new Model file.").addOption(new Option("-l, --type [string]", "Type of migration file to generate.").choices(["js", "ts"]).default("js", "generates a js migration file")).option("--force", "Force creation if model already exists.", false).option("-p, --path [path]", "The path to the models directory.").action(async (name$1, opts) => {
|
|
5845
5931
|
var _this$config$models;
|
|
5846
5932
|
if (!this.configPath) this.terminateNotFound();
|
|
5847
5933
|
const modelPath = path.join(this.cwd, opts.path ?? ((_this$config$models = this.config.models) === null || _this$config$models === void 0 ? void 0 : _this$config$models.path) ?? "./models", name$1.toLowerCase() + "." + opts.type);
|