@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/dist/inspector/index.cjs
CHANGED
|
@@ -43,13 +43,18 @@ let path = require("path");
|
|
|
43
43
|
path = __toESM(path);
|
|
44
44
|
let fs = require("fs");
|
|
45
45
|
fs = __toESM(fs);
|
|
46
|
+
let fs_promises = require("fs/promises");
|
|
47
|
+
fs_promises = __toESM(fs_promises);
|
|
48
|
+
let escalade_sync = require("escalade/sync");
|
|
49
|
+
escalade_sync = __toESM(escalade_sync);
|
|
50
|
+
let resolve_from = require("resolve-from");
|
|
51
|
+
resolve_from = __toESM(resolve_from);
|
|
46
52
|
let pluralize = require("pluralize");
|
|
47
53
|
pluralize = __toESM(pluralize);
|
|
48
54
|
require("@h3ravel/shared");
|
|
49
55
|
require("node:fs/promises");
|
|
50
|
-
require("
|
|
51
|
-
require("
|
|
52
|
-
require("resolve-from");
|
|
56
|
+
require("node:path");
|
|
57
|
+
require("node:url");
|
|
53
58
|
|
|
54
59
|
//#region src/inspector/utils/strip-quotes.ts
|
|
55
60
|
/**
|
|
@@ -1371,7 +1376,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
1371
1376
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
1372
1377
|
/**
|
|
1373
1378
|
* Compose function that merges multiple classes and mixins
|
|
1374
|
-
*
|
|
1379
|
+
*
|
|
1375
1380
|
* @example
|
|
1376
1381
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
1377
1382
|
* return class extends Base {
|
|
@@ -1408,10 +1413,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
1408
1413
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
1409
1414
|
* console.log(user.pluginMethod()) // "plugin"
|
|
1410
1415
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
1411
|
-
*
|
|
1412
|
-
* @param Base
|
|
1413
|
-
* @param mixins
|
|
1414
|
-
* @returns
|
|
1416
|
+
*
|
|
1417
|
+
* @param Base
|
|
1418
|
+
* @param mixins
|
|
1419
|
+
* @returns
|
|
1415
1420
|
*/
|
|
1416
1421
|
function compose$1(Base, ...mixins) {
|
|
1417
1422
|
/**
|
|
@@ -1465,10 +1470,10 @@ const getSetterMethod = (attr) => {
|
|
|
1465
1470
|
};
|
|
1466
1471
|
/**
|
|
1467
1472
|
* Tap into a model a collection instance
|
|
1468
|
-
*
|
|
1469
|
-
* @param instance
|
|
1470
|
-
* @param callback
|
|
1471
|
-
* @returns
|
|
1473
|
+
*
|
|
1474
|
+
* @param instance
|
|
1475
|
+
* @param callback
|
|
1476
|
+
* @returns
|
|
1472
1477
|
*/
|
|
1473
1478
|
const tap = (instance, callback) => {
|
|
1474
1479
|
const result = callback(instance);
|
|
@@ -2304,8 +2309,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
2304
2309
|
const results = await this.take(1).get(columns);
|
|
2305
2310
|
return results.count() > 0 ? results.first() : null;
|
|
2306
2311
|
}
|
|
2307
|
-
async firstOrFail(columns
|
|
2308
|
-
const model = await this.first(columns);
|
|
2312
|
+
async firstOrFail(...columns) {
|
|
2313
|
+
const model = await this.first(...columns);
|
|
2309
2314
|
if (model) return model;
|
|
2310
2315
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2311
2316
|
}
|
|
@@ -2344,7 +2349,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
2344
2349
|
}
|
|
2345
2350
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
2346
2351
|
this.query.addSelect(this.shouldSelect(columns));
|
|
2347
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
2352
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
2348
2353
|
}
|
|
2349
2354
|
shouldSelect(columns = ["*"]) {
|
|
2350
2355
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -2622,9 +2627,6 @@ const UniqueIds = (Model$1) => {
|
|
|
2622
2627
|
uniqueIds() {
|
|
2623
2628
|
return [];
|
|
2624
2629
|
}
|
|
2625
|
-
newUniqueId() {
|
|
2626
|
-
return null;
|
|
2627
|
-
}
|
|
2628
2630
|
setUniqueIds() {
|
|
2629
2631
|
const uniqueIds = this.uniqueIds();
|
|
2630
2632
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -2646,6 +2648,7 @@ var Paginator = class {
|
|
|
2646
2648
|
options = {};
|
|
2647
2649
|
static setFormatter(formatter) {
|
|
2648
2650
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
2651
|
+
if (!formatter) return;
|
|
2649
2652
|
this.formatter = formatter;
|
|
2650
2653
|
}
|
|
2651
2654
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -2734,8 +2737,10 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2734
2737
|
asProxy() {
|
|
2735
2738
|
return new Proxy(this, {
|
|
2736
2739
|
get: function(target, prop) {
|
|
2740
|
+
var _target$connector$cli;
|
|
2737
2741
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2738
2742
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
2743
|
+
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";
|
|
2739
2744
|
if ([
|
|
2740
2745
|
"select",
|
|
2741
2746
|
"from",
|
|
@@ -2798,7 +2803,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2798
2803
|
"clearWhere",
|
|
2799
2804
|
"clearHaving",
|
|
2800
2805
|
"clearGroup"
|
|
2801
|
-
].includes(prop)) return (...args) => {
|
|
2806
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2802
2807
|
target.connector[prop](...args);
|
|
2803
2808
|
return target.asProxy();
|
|
2804
2809
|
};
|
|
@@ -2855,7 +2860,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2855
2860
|
} while (countResults === count);
|
|
2856
2861
|
return true;
|
|
2857
2862
|
}
|
|
2858
|
-
async paginate(page = 1, perPage = 15) {
|
|
2863
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
2859
2864
|
const total = await this.clone().clearOrder().count("*");
|
|
2860
2865
|
let results;
|
|
2861
2866
|
if (total > 0) {
|
|
@@ -2919,6 +2924,59 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2919
2924
|
};
|
|
2920
2925
|
var query_builder_default = QueryBuilder;
|
|
2921
2926
|
|
|
2927
|
+
//#endregion
|
|
2928
|
+
//#region src/cli/utils.ts
|
|
2929
|
+
const join = path.default.join;
|
|
2930
|
+
var Utils = class {
|
|
2931
|
+
/**
|
|
2932
|
+
* Wraps text with chalk
|
|
2933
|
+
*
|
|
2934
|
+
* @param txt
|
|
2935
|
+
* @param color
|
|
2936
|
+
* @returns
|
|
2937
|
+
*/
|
|
2938
|
+
static textFormat(txt, color) {
|
|
2939
|
+
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
2940
|
+
}
|
|
2941
|
+
static findModulePkg(moduleId, cwd) {
|
|
2942
|
+
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
2943
|
+
let packageName = "";
|
|
2944
|
+
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
2945
|
+
packageName += parts.shift();
|
|
2946
|
+
const packageJson = path.default.join(packageName, "package.json");
|
|
2947
|
+
const resolved = resolve_from.default.silent(cwd ?? process.cwd(), packageJson);
|
|
2948
|
+
if (!resolved) return;
|
|
2949
|
+
return path.default.join(path.default.dirname(resolved), parts.join("/"));
|
|
2950
|
+
}
|
|
2951
|
+
static async getMigrationPaths(cwd, migrator, defaultPath, path$6) {
|
|
2952
|
+
if (path$6) return [join(cwd, path$6)];
|
|
2953
|
+
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
2954
|
+
}
|
|
2955
|
+
/**
|
|
2956
|
+
* Check if file exists
|
|
2957
|
+
*
|
|
2958
|
+
* @param path
|
|
2959
|
+
* @returns
|
|
2960
|
+
*/
|
|
2961
|
+
static async fileExists(path$6) {
|
|
2962
|
+
try {
|
|
2963
|
+
await (0, fs_promises.access)(path$6);
|
|
2964
|
+
return true;
|
|
2965
|
+
} catch {
|
|
2966
|
+
return false;
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
static findUpConfig(cwd, name, extensions) {
|
|
2970
|
+
return (0, escalade_sync.default)(cwd, (_dir, names) => {
|
|
2971
|
+
for (const ext of extensions) {
|
|
2972
|
+
const filename = `${name}.${ext}`;
|
|
2973
|
+
if (names.includes(filename)) return filename;
|
|
2974
|
+
}
|
|
2975
|
+
return false;
|
|
2976
|
+
});
|
|
2977
|
+
}
|
|
2978
|
+
};
|
|
2979
|
+
|
|
2922
2980
|
//#endregion
|
|
2923
2981
|
//#region src/arquebus.ts
|
|
2924
2982
|
var arquebus = class arquebus {
|
|
@@ -2940,22 +2998,22 @@ var arquebus = class arquebus {
|
|
|
2940
2998
|
return this.instance;
|
|
2941
2999
|
}
|
|
2942
3000
|
/**
|
|
2943
|
-
* Initialize a new database connection
|
|
2944
|
-
*
|
|
2945
|
-
* @returns
|
|
3001
|
+
* Initialize a new database connection
|
|
3002
|
+
*
|
|
3003
|
+
* @returns
|
|
2946
3004
|
*/
|
|
2947
3005
|
static fire(connection = null) {
|
|
2948
3006
|
return this.getInstance().getConnection(connection);
|
|
2949
3007
|
}
|
|
2950
3008
|
/**
|
|
2951
|
-
* Initialize a new database connection
|
|
2952
|
-
*
|
|
3009
|
+
* Initialize a new database connection
|
|
3010
|
+
*
|
|
2953
3011
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
2954
|
-
*
|
|
3012
|
+
*
|
|
2955
3013
|
* @deprecated since version 0.3.0
|
|
2956
3014
|
* @alias fire
|
|
2957
|
-
*
|
|
2958
|
-
* @returns
|
|
3015
|
+
*
|
|
3016
|
+
* @returns
|
|
2959
3017
|
*/
|
|
2960
3018
|
static connection(connection = null) {
|
|
2961
3019
|
return this.fire(connection);
|
|
@@ -2992,11 +3050,12 @@ var arquebus = class arquebus {
|
|
|
2992
3050
|
}
|
|
2993
3051
|
getConnection(name = null) {
|
|
2994
3052
|
name = name || "default";
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
this.
|
|
3053
|
+
const resolvedName = this.connections[name] ? name : "default";
|
|
3054
|
+
if (this.manager[resolvedName] === void 0) {
|
|
3055
|
+
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
3056
|
+
this.manager[resolvedName] = queryBuilder;
|
|
2998
3057
|
}
|
|
2999
|
-
return this.manager[
|
|
3058
|
+
return this.manager[resolvedName];
|
|
3000
3059
|
}
|
|
3001
3060
|
addConnection(config, name = "default") {
|
|
3002
3061
|
this.connections[name] = {
|
|
@@ -3013,13 +3072,13 @@ var arquebus = class arquebus {
|
|
|
3013
3072
|
}
|
|
3014
3073
|
/**
|
|
3015
3074
|
* Autoload the config file
|
|
3016
|
-
*
|
|
3017
|
-
* @param addConnection
|
|
3075
|
+
*
|
|
3076
|
+
* @param addConnection
|
|
3018
3077
|
* @default true
|
|
3019
|
-
* If set to `false` we will no attempt add the connection, we
|
|
3078
|
+
* If set to `false` we will no attempt add the connection, we
|
|
3020
3079
|
* will just go ahead and return the config
|
|
3021
|
-
*
|
|
3022
|
-
* @returns
|
|
3080
|
+
*
|
|
3081
|
+
* @returns
|
|
3023
3082
|
*/
|
|
3024
3083
|
static async autoLoad(addConnection = true) {
|
|
3025
3084
|
let config;
|
|
@@ -3036,6 +3095,23 @@ var arquebus = class arquebus {
|
|
|
3036
3095
|
if (addConnection) instance.addConnection(config, config.client);
|
|
3037
3096
|
return config;
|
|
3038
3097
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3098
|
+
const candidateDirs = [
|
|
3099
|
+
process.cwd(),
|
|
3100
|
+
path.default.join(process.cwd(), "test", "cli"),
|
|
3101
|
+
path.default.join(process.cwd(), "test")
|
|
3102
|
+
];
|
|
3103
|
+
for (const dir of candidateDirs) {
|
|
3104
|
+
const found = Utils.findUpConfig(dir, "arquebus.config", [
|
|
3105
|
+
"js",
|
|
3106
|
+
"ts",
|
|
3107
|
+
"cjs"
|
|
3108
|
+
]);
|
|
3109
|
+
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
3110
|
+
config = (await import(found)).default;
|
|
3111
|
+
if (addConnection) instance.addConnection(config, config.client);
|
|
3112
|
+
return config;
|
|
3113
|
+
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3114
|
+
}
|
|
3039
3115
|
return {};
|
|
3040
3116
|
}
|
|
3041
3117
|
beginTransaction(connection = null) {
|
|
@@ -3094,14 +3170,15 @@ var arquebus_default = arquebus;
|
|
|
3094
3170
|
|
|
3095
3171
|
//#endregion
|
|
3096
3172
|
//#region src/model.ts
|
|
3097
|
-
const
|
|
3173
|
+
const ModelClass = class {};
|
|
3174
|
+
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);
|
|
3098
3175
|
var Model = class Model extends BaseModel {
|
|
3099
|
-
primaryKey = "id";
|
|
3100
3176
|
builder = null;
|
|
3101
3177
|
table = null;
|
|
3102
3178
|
keyType = "int";
|
|
3103
3179
|
incrementing = true;
|
|
3104
3180
|
withCount = [];
|
|
3181
|
+
primaryKey = "id";
|
|
3105
3182
|
perPage = 15;
|
|
3106
3183
|
static globalScopes = {};
|
|
3107
3184
|
static pluginInitializers = {};
|
|
@@ -3111,6 +3188,7 @@ var Model = class Model extends BaseModel {
|
|
|
3111
3188
|
eagerLoad = {};
|
|
3112
3189
|
exists = false;
|
|
3113
3190
|
with = [];
|
|
3191
|
+
name;
|
|
3114
3192
|
trx = null;
|
|
3115
3193
|
constructor(attributes = {}) {
|
|
3116
3194
|
super();
|
|
@@ -3882,8 +3960,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
3882
3960
|
const results = await this.take(1).get(columns);
|
|
3883
3961
|
return results.count() > 0 ? results.first() : null;
|
|
3884
3962
|
}
|
|
3885
|
-
async firstOrFail(columns
|
|
3886
|
-
const model = await this.first(columns);
|
|
3963
|
+
async firstOrFail(...columns) {
|
|
3964
|
+
const model = await this.first(...columns);
|
|
3887
3965
|
if (model !== null) return model;
|
|
3888
3966
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
3889
3967
|
}
|
|
@@ -4059,7 +4137,9 @@ var Builder = class Builder extends Inference {
|
|
|
4059
4137
|
}
|
|
4060
4138
|
asProxy() {
|
|
4061
4139
|
return new Proxy(this, { get(target, prop) {
|
|
4140
|
+
var _target$query$connect;
|
|
4062
4141
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
4142
|
+
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";
|
|
4063
4143
|
if ([
|
|
4064
4144
|
"select",
|
|
4065
4145
|
"from",
|
|
@@ -4122,7 +4202,7 @@ var Builder = class Builder extends Inference {
|
|
|
4122
4202
|
"clearWhere",
|
|
4123
4203
|
"clearHaving",
|
|
4124
4204
|
"clearGroup"
|
|
4125
|
-
].includes(prop)) return (...args) => {
|
|
4205
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
4126
4206
|
target.query[prop](...args);
|
|
4127
4207
|
return target.asProxy();
|
|
4128
4208
|
};
|
|
@@ -4708,10 +4788,6 @@ var Builder = class Builder extends Inference {
|
|
|
4708
4788
|
};
|
|
4709
4789
|
var builder_default = Builder;
|
|
4710
4790
|
|
|
4711
|
-
//#endregion
|
|
4712
|
-
//#region src/cli/utils.ts
|
|
4713
|
-
const join = path.default.join;
|
|
4714
|
-
|
|
4715
4791
|
//#endregion
|
|
4716
4792
|
//#region src/inspector/dialects/sqlite.ts
|
|
4717
4793
|
function parseDefaultValue(value) {
|
package/dist/inspector/index.js
CHANGED
|
@@ -6,12 +6,14 @@ import collect$1, { Collection, collect } from "collect.js";
|
|
|
6
6
|
import Knex$1 from "knex";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { existsSync } from "fs";
|
|
9
|
+
import { access } from "fs/promises";
|
|
10
|
+
import escalade from "escalade/sync";
|
|
11
|
+
import resolveFrom from "resolve-from";
|
|
9
12
|
import pluralize from "pluralize";
|
|
10
13
|
import "@h3ravel/shared";
|
|
11
14
|
import "node:fs/promises";
|
|
12
|
-
import "
|
|
13
|
-
import "
|
|
14
|
-
import "resolve-from";
|
|
15
|
+
import "node:path";
|
|
16
|
+
import "node:url";
|
|
15
17
|
|
|
16
18
|
//#region rolldown:runtime
|
|
17
19
|
var __defProp = Object.defineProperty;
|
|
@@ -1345,7 +1347,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
1345
1347
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
1346
1348
|
/**
|
|
1347
1349
|
* Compose function that merges multiple classes and mixins
|
|
1348
|
-
*
|
|
1350
|
+
*
|
|
1349
1351
|
* @example
|
|
1350
1352
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
1351
1353
|
* return class extends Base {
|
|
@@ -1382,10 +1384,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
1382
1384
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
1383
1385
|
* console.log(user.pluginMethod()) // "plugin"
|
|
1384
1386
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
1385
|
-
*
|
|
1386
|
-
* @param Base
|
|
1387
|
-
* @param mixins
|
|
1388
|
-
* @returns
|
|
1387
|
+
*
|
|
1388
|
+
* @param Base
|
|
1389
|
+
* @param mixins
|
|
1390
|
+
* @returns
|
|
1389
1391
|
*/
|
|
1390
1392
|
function compose$1(Base, ...mixins) {
|
|
1391
1393
|
/**
|
|
@@ -1439,10 +1441,10 @@ const getSetterMethod = (attr) => {
|
|
|
1439
1441
|
};
|
|
1440
1442
|
/**
|
|
1441
1443
|
* Tap into a model a collection instance
|
|
1442
|
-
*
|
|
1443
|
-
* @param instance
|
|
1444
|
-
* @param callback
|
|
1445
|
-
* @returns
|
|
1444
|
+
*
|
|
1445
|
+
* @param instance
|
|
1446
|
+
* @param callback
|
|
1447
|
+
* @returns
|
|
1446
1448
|
*/
|
|
1447
1449
|
const tap = (instance, callback) => {
|
|
1448
1450
|
const result = callback(instance);
|
|
@@ -2278,8 +2280,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
2278
2280
|
const results = await this.take(1).get(columns);
|
|
2279
2281
|
return results.count() > 0 ? results.first() : null;
|
|
2280
2282
|
}
|
|
2281
|
-
async firstOrFail(columns
|
|
2282
|
-
const model = await this.first(columns);
|
|
2283
|
+
async firstOrFail(...columns) {
|
|
2284
|
+
const model = await this.first(...columns);
|
|
2283
2285
|
if (model) return model;
|
|
2284
2286
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2285
2287
|
}
|
|
@@ -2318,7 +2320,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
2318
2320
|
}
|
|
2319
2321
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
2320
2322
|
this.query.addSelect(this.shouldSelect(columns));
|
|
2321
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
2323
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
2322
2324
|
}
|
|
2323
2325
|
shouldSelect(columns = ["*"]) {
|
|
2324
2326
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -2596,9 +2598,6 @@ const UniqueIds = (Model$1) => {
|
|
|
2596
2598
|
uniqueIds() {
|
|
2597
2599
|
return [];
|
|
2598
2600
|
}
|
|
2599
|
-
newUniqueId() {
|
|
2600
|
-
return null;
|
|
2601
|
-
}
|
|
2602
2601
|
setUniqueIds() {
|
|
2603
2602
|
const uniqueIds = this.uniqueIds();
|
|
2604
2603
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -2620,6 +2619,7 @@ var Paginator = class {
|
|
|
2620
2619
|
options = {};
|
|
2621
2620
|
static setFormatter(formatter) {
|
|
2622
2621
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
2622
|
+
if (!formatter) return;
|
|
2623
2623
|
this.formatter = formatter;
|
|
2624
2624
|
}
|
|
2625
2625
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -2708,8 +2708,10 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2708
2708
|
asProxy() {
|
|
2709
2709
|
return new Proxy(this, {
|
|
2710
2710
|
get: function(target, prop) {
|
|
2711
|
+
var _target$connector$cli;
|
|
2711
2712
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2712
2713
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
2714
|
+
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";
|
|
2713
2715
|
if ([
|
|
2714
2716
|
"select",
|
|
2715
2717
|
"from",
|
|
@@ -2772,7 +2774,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2772
2774
|
"clearWhere",
|
|
2773
2775
|
"clearHaving",
|
|
2774
2776
|
"clearGroup"
|
|
2775
|
-
].includes(prop)) return (...args) => {
|
|
2777
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2776
2778
|
target.connector[prop](...args);
|
|
2777
2779
|
return target.asProxy();
|
|
2778
2780
|
};
|
|
@@ -2829,7 +2831,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2829
2831
|
} while (countResults === count);
|
|
2830
2832
|
return true;
|
|
2831
2833
|
}
|
|
2832
|
-
async paginate(page = 1, perPage = 15) {
|
|
2834
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
2833
2835
|
const total = await this.clone().clearOrder().count("*");
|
|
2834
2836
|
let results;
|
|
2835
2837
|
if (total > 0) {
|
|
@@ -2893,6 +2895,59 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2893
2895
|
};
|
|
2894
2896
|
var query_builder_default = QueryBuilder;
|
|
2895
2897
|
|
|
2898
|
+
//#endregion
|
|
2899
|
+
//#region src/cli/utils.ts
|
|
2900
|
+
const join = path.join;
|
|
2901
|
+
var Utils = class {
|
|
2902
|
+
/**
|
|
2903
|
+
* Wraps text with chalk
|
|
2904
|
+
*
|
|
2905
|
+
* @param txt
|
|
2906
|
+
* @param color
|
|
2907
|
+
* @returns
|
|
2908
|
+
*/
|
|
2909
|
+
static textFormat(txt, color) {
|
|
2910
|
+
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
2911
|
+
}
|
|
2912
|
+
static findModulePkg(moduleId, cwd) {
|
|
2913
|
+
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
2914
|
+
let packageName = "";
|
|
2915
|
+
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
2916
|
+
packageName += parts.shift();
|
|
2917
|
+
const packageJson = path.join(packageName, "package.json");
|
|
2918
|
+
const resolved = resolveFrom.silent(cwd ?? process.cwd(), packageJson);
|
|
2919
|
+
if (!resolved) return;
|
|
2920
|
+
return path.join(path.dirname(resolved), parts.join("/"));
|
|
2921
|
+
}
|
|
2922
|
+
static async getMigrationPaths(cwd, migrator, defaultPath, path$1) {
|
|
2923
|
+
if (path$1) return [join(cwd, path$1)];
|
|
2924
|
+
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
2925
|
+
}
|
|
2926
|
+
/**
|
|
2927
|
+
* Check if file exists
|
|
2928
|
+
*
|
|
2929
|
+
* @param path
|
|
2930
|
+
* @returns
|
|
2931
|
+
*/
|
|
2932
|
+
static async fileExists(path$1) {
|
|
2933
|
+
try {
|
|
2934
|
+
await access(path$1);
|
|
2935
|
+
return true;
|
|
2936
|
+
} catch {
|
|
2937
|
+
return false;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
static findUpConfig(cwd, name, extensions) {
|
|
2941
|
+
return escalade(cwd, (_dir, names) => {
|
|
2942
|
+
for (const ext of extensions) {
|
|
2943
|
+
const filename = `${name}.${ext}`;
|
|
2944
|
+
if (names.includes(filename)) return filename;
|
|
2945
|
+
}
|
|
2946
|
+
return false;
|
|
2947
|
+
});
|
|
2948
|
+
}
|
|
2949
|
+
};
|
|
2950
|
+
|
|
2896
2951
|
//#endregion
|
|
2897
2952
|
//#region src/arquebus.ts
|
|
2898
2953
|
var arquebus = class arquebus {
|
|
@@ -2914,22 +2969,22 @@ var arquebus = class arquebus {
|
|
|
2914
2969
|
return this.instance;
|
|
2915
2970
|
}
|
|
2916
2971
|
/**
|
|
2917
|
-
* Initialize a new database connection
|
|
2918
|
-
*
|
|
2919
|
-
* @returns
|
|
2972
|
+
* Initialize a new database connection
|
|
2973
|
+
*
|
|
2974
|
+
* @returns
|
|
2920
2975
|
*/
|
|
2921
2976
|
static fire(connection = null) {
|
|
2922
2977
|
return this.getInstance().getConnection(connection);
|
|
2923
2978
|
}
|
|
2924
2979
|
/**
|
|
2925
|
-
* Initialize a new database connection
|
|
2926
|
-
*
|
|
2980
|
+
* Initialize a new database connection
|
|
2981
|
+
*
|
|
2927
2982
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
2928
|
-
*
|
|
2983
|
+
*
|
|
2929
2984
|
* @deprecated since version 0.3.0
|
|
2930
2985
|
* @alias fire
|
|
2931
|
-
*
|
|
2932
|
-
* @returns
|
|
2986
|
+
*
|
|
2987
|
+
* @returns
|
|
2933
2988
|
*/
|
|
2934
2989
|
static connection(connection = null) {
|
|
2935
2990
|
return this.fire(connection);
|
|
@@ -2966,11 +3021,12 @@ var arquebus = class arquebus {
|
|
|
2966
3021
|
}
|
|
2967
3022
|
getConnection(name = null) {
|
|
2968
3023
|
name = name || "default";
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
this.
|
|
3024
|
+
const resolvedName = this.connections[name] ? name : "default";
|
|
3025
|
+
if (this.manager[resolvedName] === void 0) {
|
|
3026
|
+
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
3027
|
+
this.manager[resolvedName] = queryBuilder;
|
|
2972
3028
|
}
|
|
2973
|
-
return this.manager[
|
|
3029
|
+
return this.manager[resolvedName];
|
|
2974
3030
|
}
|
|
2975
3031
|
addConnection(config, name = "default") {
|
|
2976
3032
|
this.connections[name] = {
|
|
@@ -2987,13 +3043,13 @@ var arquebus = class arquebus {
|
|
|
2987
3043
|
}
|
|
2988
3044
|
/**
|
|
2989
3045
|
* Autoload the config file
|
|
2990
|
-
*
|
|
2991
|
-
* @param addConnection
|
|
3046
|
+
*
|
|
3047
|
+
* @param addConnection
|
|
2992
3048
|
* @default true
|
|
2993
|
-
* If set to `false` we will no attempt add the connection, we
|
|
3049
|
+
* If set to `false` we will no attempt add the connection, we
|
|
2994
3050
|
* will just go ahead and return the config
|
|
2995
|
-
*
|
|
2996
|
-
* @returns
|
|
3051
|
+
*
|
|
3052
|
+
* @returns
|
|
2997
3053
|
*/
|
|
2998
3054
|
static async autoLoad(addConnection = true) {
|
|
2999
3055
|
let config;
|
|
@@ -3010,6 +3066,23 @@ var arquebus = class arquebus {
|
|
|
3010
3066
|
if (addConnection) instance.addConnection(config, config.client);
|
|
3011
3067
|
return config;
|
|
3012
3068
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3069
|
+
const candidateDirs = [
|
|
3070
|
+
process.cwd(),
|
|
3071
|
+
path.join(process.cwd(), "test", "cli"),
|
|
3072
|
+
path.join(process.cwd(), "test")
|
|
3073
|
+
];
|
|
3074
|
+
for (const dir of candidateDirs) {
|
|
3075
|
+
const found = Utils.findUpConfig(dir, "arquebus.config", [
|
|
3076
|
+
"js",
|
|
3077
|
+
"ts",
|
|
3078
|
+
"cjs"
|
|
3079
|
+
]);
|
|
3080
|
+
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
3081
|
+
config = (await import(found)).default;
|
|
3082
|
+
if (addConnection) instance.addConnection(config, config.client);
|
|
3083
|
+
return config;
|
|
3084
|
+
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3085
|
+
}
|
|
3013
3086
|
return {};
|
|
3014
3087
|
}
|
|
3015
3088
|
beginTransaction(connection = null) {
|
|
@@ -3068,14 +3141,15 @@ var arquebus_default = arquebus;
|
|
|
3068
3141
|
|
|
3069
3142
|
//#endregion
|
|
3070
3143
|
//#region src/model.ts
|
|
3071
|
-
const
|
|
3144
|
+
const ModelClass = class {};
|
|
3145
|
+
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);
|
|
3072
3146
|
var Model = class Model extends BaseModel {
|
|
3073
|
-
primaryKey = "id";
|
|
3074
3147
|
builder = null;
|
|
3075
3148
|
table = null;
|
|
3076
3149
|
keyType = "int";
|
|
3077
3150
|
incrementing = true;
|
|
3078
3151
|
withCount = [];
|
|
3152
|
+
primaryKey = "id";
|
|
3079
3153
|
perPage = 15;
|
|
3080
3154
|
static globalScopes = {};
|
|
3081
3155
|
static pluginInitializers = {};
|
|
@@ -3085,6 +3159,7 @@ var Model = class Model extends BaseModel {
|
|
|
3085
3159
|
eagerLoad = {};
|
|
3086
3160
|
exists = false;
|
|
3087
3161
|
with = [];
|
|
3162
|
+
name;
|
|
3088
3163
|
trx = null;
|
|
3089
3164
|
constructor(attributes = {}) {
|
|
3090
3165
|
super();
|
|
@@ -3856,8 +3931,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
3856
3931
|
const results = await this.take(1).get(columns);
|
|
3857
3932
|
return results.count() > 0 ? results.first() : null;
|
|
3858
3933
|
}
|
|
3859
|
-
async firstOrFail(columns
|
|
3860
|
-
const model = await this.first(columns);
|
|
3934
|
+
async firstOrFail(...columns) {
|
|
3935
|
+
const model = await this.first(...columns);
|
|
3861
3936
|
if (model !== null) return model;
|
|
3862
3937
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
3863
3938
|
}
|
|
@@ -4033,7 +4108,9 @@ var Builder = class Builder extends Inference {
|
|
|
4033
4108
|
}
|
|
4034
4109
|
asProxy() {
|
|
4035
4110
|
return new Proxy(this, { get(target, prop) {
|
|
4111
|
+
var _target$query$connect;
|
|
4036
4112
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
4113
|
+
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";
|
|
4037
4114
|
if ([
|
|
4038
4115
|
"select",
|
|
4039
4116
|
"from",
|
|
@@ -4096,7 +4173,7 @@ var Builder = class Builder extends Inference {
|
|
|
4096
4173
|
"clearWhere",
|
|
4097
4174
|
"clearHaving",
|
|
4098
4175
|
"clearGroup"
|
|
4099
|
-
].includes(prop)) return (...args) => {
|
|
4176
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
4100
4177
|
target.query[prop](...args);
|
|
4101
4178
|
return target.asProxy();
|
|
4102
4179
|
};
|
|
@@ -4682,10 +4759,6 @@ var Builder = class Builder extends Inference {
|
|
|
4682
4759
|
};
|
|
4683
4760
|
var builder_default = Builder;
|
|
4684
4761
|
|
|
4685
|
-
//#endregion
|
|
4686
|
-
//#region src/cli/utils.ts
|
|
4687
|
-
const join = path.join;
|
|
4688
|
-
|
|
4689
4762
|
//#endregion
|
|
4690
4763
|
//#region src/inspector/dialects/sqlite.ts
|
|
4691
4764
|
function parseDefaultValue(value) {
|