@h3ravel/arquebus 0.4.1 → 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 +30 -28
- package/bin/index.js +32 -29
- package/dist/browser/index.d.cts +3648 -176
- package/dist/browser/index.d.ts +3648 -176
- package/dist/index.cjs +18 -14
- package/dist/index.d.cts +3757 -286
- package/dist/index.d.ts +3757 -286
- package/dist/index.js +18 -14
- package/dist/inspector/index.cjs +17 -13
- package/dist/inspector/index.js +17 -13
- package/dist/migrations/index.cjs +27 -25
- package/dist/migrations/index.d.cts +3500 -17
- package/dist/migrations/index.d.ts +3500 -17
- package/dist/migrations/index.js +40 -31
- package/package.json +3 -3
- 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
|
};
|
|
@@ -5574,7 +5578,7 @@ const make = (model, data, options = {}) => {
|
|
|
5574
5578
|
return model.make(data);
|
|
5575
5579
|
};
|
|
5576
5580
|
const makeCollection = (model, data) => new collection_default(data.map((item) => model.make(item)));
|
|
5577
|
-
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);
|
|
5578
5582
|
|
|
5579
5583
|
//#endregion
|
|
5580
5584
|
exports.Attribute = attribute_default;
|