@h3ravel/arquebus 0.4.0 → 0.5.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/bin/index.cjs +47 -56
- package/bin/index.js +49 -57
- package/dist/browser/index.d.cts +3648 -176
- package/dist/browser/index.d.ts +3648 -176
- package/dist/index.cjs +21 -28
- package/dist/index.d.cts +3757 -287
- package/dist/index.d.ts +3757 -287
- package/dist/index.js +22 -29
- package/dist/inspector/index.cjs +17 -13
- package/dist/inspector/index.js +17 -13
- package/dist/migrations/index.cjs +30 -39
- package/dist/migrations/index.d.cts +3500 -18
- package/dist/migrations/index.d.ts +3500 -18
- package/dist/migrations/index.js +43 -45
- package/package.json +17 -17
- package/types/builder.ts +21 -16
- package/types/generics.ts +1 -0
- package/types/modeling.ts +7 -7
- package/types/query-builder.ts +9 -2
- package/types/query-methods.ts +20 -0
- package/types/utils.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -1072,8 +1072,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
1072
1072
|
const results = await this.take(1).get(columns);
|
|
1073
1073
|
return results.count() > 0 ? results.first() : null;
|
|
1074
1074
|
}
|
|
1075
|
-
async firstOrFail(columns
|
|
1076
|
-
const model = await this.first(columns);
|
|
1075
|
+
async firstOrFail(...columns) {
|
|
1076
|
+
const model = await this.first(...columns);
|
|
1077
1077
|
if (model) return model;
|
|
1078
1078
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
1079
1079
|
}
|
|
@@ -1112,7 +1112,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
1112
1112
|
}
|
|
1113
1113
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
1114
1114
|
this.query.addSelect(this.shouldSelect(columns));
|
|
1115
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
1115
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
1116
1116
|
}
|
|
1117
1117
|
shouldSelect(columns = ["*"]) {
|
|
1118
1118
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -1390,9 +1390,6 @@ const UniqueIds = (Model$1) => {
|
|
|
1390
1390
|
uniqueIds() {
|
|
1391
1391
|
return [];
|
|
1392
1392
|
}
|
|
1393
|
-
newUniqueId() {
|
|
1394
|
-
return null;
|
|
1395
|
-
}
|
|
1396
1393
|
setUniqueIds() {
|
|
1397
1394
|
const uniqueIds = this.uniqueIds();
|
|
1398
1395
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -1414,6 +1411,7 @@ var Paginator = class {
|
|
|
1414
1411
|
options = {};
|
|
1415
1412
|
static setFormatter(formatter) {
|
|
1416
1413
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
1414
|
+
if (!formatter) return;
|
|
1417
1415
|
this.formatter = formatter;
|
|
1418
1416
|
}
|
|
1419
1417
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -1502,8 +1500,10 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1502
1500
|
asProxy() {
|
|
1503
1501
|
return new Proxy(this, {
|
|
1504
1502
|
get: function(target, prop) {
|
|
1503
|
+
var _target$connector$cli;
|
|
1505
1504
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
1506
1505
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
1506
|
+
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";
|
|
1507
1507
|
if ([
|
|
1508
1508
|
"select",
|
|
1509
1509
|
"from",
|
|
@@ -1566,7 +1566,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1566
1566
|
"clearWhere",
|
|
1567
1567
|
"clearHaving",
|
|
1568
1568
|
"clearGroup"
|
|
1569
|
-
].includes(prop)) return (...args) => {
|
|
1569
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
1570
1570
|
target.connector[prop](...args);
|
|
1571
1571
|
return target.asProxy();
|
|
1572
1572
|
};
|
|
@@ -1623,7 +1623,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1623
1623
|
} while (countResults === count);
|
|
1624
1624
|
return true;
|
|
1625
1625
|
}
|
|
1626
|
-
async paginate(page = 1, perPage = 15) {
|
|
1626
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
1627
1627
|
const total = await this.clone().clearOrder().count("*");
|
|
1628
1628
|
let results;
|
|
1629
1629
|
if (total > 0) {
|
|
@@ -1862,14 +1862,15 @@ var arquebus_default = arquebus;
|
|
|
1862
1862
|
|
|
1863
1863
|
//#endregion
|
|
1864
1864
|
//#region src/model.ts
|
|
1865
|
-
const
|
|
1865
|
+
const ModelClass = class {};
|
|
1866
|
+
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);
|
|
1866
1867
|
var Model = class Model extends BaseModel {
|
|
1867
|
-
primaryKey = "id";
|
|
1868
1868
|
builder = null;
|
|
1869
1869
|
table = null;
|
|
1870
1870
|
keyType = "int";
|
|
1871
1871
|
incrementing = true;
|
|
1872
1872
|
withCount = [];
|
|
1873
|
+
primaryKey = "id";
|
|
1873
1874
|
perPage = 15;
|
|
1874
1875
|
static globalScopes = {};
|
|
1875
1876
|
static pluginInitializers = {};
|
|
@@ -1879,6 +1880,7 @@ var Model = class Model extends BaseModel {
|
|
|
1879
1880
|
eagerLoad = {};
|
|
1880
1881
|
exists = false;
|
|
1881
1882
|
with = [];
|
|
1883
|
+
name;
|
|
1882
1884
|
trx = null;
|
|
1883
1885
|
constructor(attributes = {}) {
|
|
1884
1886
|
super();
|
|
@@ -2650,8 +2652,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
2650
2652
|
const results = await this.take(1).get(columns);
|
|
2651
2653
|
return results.count() > 0 ? results.first() : null;
|
|
2652
2654
|
}
|
|
2653
|
-
async firstOrFail(columns
|
|
2654
|
-
const model = await this.first(columns);
|
|
2655
|
+
async firstOrFail(...columns) {
|
|
2656
|
+
const model = await this.first(...columns);
|
|
2655
2657
|
if (model !== null) return model;
|
|
2656
2658
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2657
2659
|
}
|
|
@@ -2827,7 +2829,9 @@ var Builder = class Builder extends Inference$1 {
|
|
|
2827
2829
|
}
|
|
2828
2830
|
asProxy() {
|
|
2829
2831
|
return new Proxy(this, { get(target, prop) {
|
|
2832
|
+
var _target$query$connect;
|
|
2830
2833
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2834
|
+
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";
|
|
2831
2835
|
if ([
|
|
2832
2836
|
"select",
|
|
2833
2837
|
"from",
|
|
@@ -2890,7 +2894,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
2890
2894
|
"clearWhere",
|
|
2891
2895
|
"clearHaving",
|
|
2892
2896
|
"clearGroup"
|
|
2893
|
-
].includes(prop)) return (...args) => {
|
|
2897
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2894
2898
|
target.query[prop](...args);
|
|
2895
2899
|
return target.asProxy();
|
|
2896
2900
|
};
|
|
@@ -5039,13 +5043,13 @@ var Migrator = class {
|
|
|
5039
5043
|
async runUp(file, batch, _pretend) {
|
|
5040
5044
|
const migration = await this.resolvePath(file);
|
|
5041
5045
|
const name = this.getMigrationName(file);
|
|
5042
|
-
await
|
|
5046
|
+
await __h3ravel_shared.TaskManager.taskRunner(name, () => this.runMigration(migration, "up"));
|
|
5043
5047
|
await this.repository.log(name, batch);
|
|
5044
5048
|
}
|
|
5045
5049
|
async runDown(file, migration, _pretend) {
|
|
5046
5050
|
const instance = await this.resolvePath(file);
|
|
5047
5051
|
const name = this.getMigrationName(file);
|
|
5048
|
-
await
|
|
5052
|
+
await __h3ravel_shared.TaskManager.taskRunner(name, () => this.runMigration(instance, "down"));
|
|
5049
5053
|
await this.repository.delete(migration);
|
|
5050
5054
|
}
|
|
5051
5055
|
async rollback(paths = [], options = {}) {
|
|
@@ -5096,7 +5100,7 @@ var Migrator = class {
|
|
|
5096
5100
|
const inspector = SchemaInspector.inspect(connection);
|
|
5097
5101
|
await connection.raw("SET foreign_key_checks = 0");
|
|
5098
5102
|
/** Drop all existing tables */
|
|
5099
|
-
for (const table of await inspector.tables())
|
|
5103
|
+
for (const table of await inspector.tables()) await __h3ravel_shared.TaskManager.taskRunner(`Dropping ${__h3ravel_shared.Logger.parse([[table, "grey"]], "", false)} table`, () => connection.schema.dropTableIfExists(table));
|
|
5100
5104
|
await connection.raw("SET foreign_key_checks = 1");
|
|
5101
5105
|
/** Create the migration repository */
|
|
5102
5106
|
await this.repository.createRepository();
|
|
@@ -5177,17 +5181,6 @@ var Migrator = class {
|
|
|
5177
5181
|
write(...args) {
|
|
5178
5182
|
if (this.output) console.log(...args);
|
|
5179
5183
|
}
|
|
5180
|
-
async taskRunner(description, task) {
|
|
5181
|
-
const startTime = process.hrtime();
|
|
5182
|
-
let result = false;
|
|
5183
|
-
try {
|
|
5184
|
-
result = await Promise.all([(task || (() => true))()].flat());
|
|
5185
|
-
} finally {
|
|
5186
|
-
const endTime = process.hrtime(startTime);
|
|
5187
|
-
const duration = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
5188
|
-
__h3ravel_shared.Logger.twoColumnLog(__h3ravel_shared.Logger.parse([[description, "green"]], "", false), [__h3ravel_shared.Logger.parse([[`${Math.floor(duration)}ms`, "gray"]], "", false), __h3ravel_shared.Logger.parse([[result !== false ? "✔" : "✘", result !== false ? "green" : "red"]], "", false)].join(" "));
|
|
5189
|
-
}
|
|
5190
|
-
}
|
|
5191
5184
|
};
|
|
5192
5185
|
var migrator_default = Migrator;
|
|
5193
5186
|
|
|
@@ -5585,7 +5578,7 @@ const make = (model, data, options = {}) => {
|
|
|
5585
5578
|
return model.make(data);
|
|
5586
5579
|
};
|
|
5587
5580
|
const makeCollection = (model, data) => new collection_default(data.map((item) => model.make(item)));
|
|
5588
|
-
const makePaginator = (model, data) => new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5581
|
+
const makePaginator = (model, data, _) => new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5589
5582
|
|
|
5590
5583
|
//#endregion
|
|
5591
5584
|
exports.Attribute = attribute_default;
|