@h3ravel/arquebus 2.0.0 → 3.0.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 +580 -451
- package/bin/index.js +566 -437
- package/dist/browser/index.cjs +54 -51
- package/dist/browser/index.d.ts +804 -737
- package/dist/browser/index.js +48 -44
- package/dist/concerns/index.cjs +152 -143
- package/dist/concerns/index.d.ts +849 -776
- package/dist/concerns/index.js +143 -133
- package/dist/index.cjs +186 -185
- package/dist/index.d.ts +856 -782
- package/dist/index.js +179 -177
- package/dist/inspector/index.cjs +175 -174
- package/dist/inspector/index.d.ts +0 -1
- package/dist/inspector/index.js +161 -159
- package/dist/migrations/index.cjs +183 -182
- package/dist/migrations/index.d.ts +799 -727
- package/dist/migrations/index.js +172 -170
- package/dist/relations/index.cjs +152 -143
- package/dist/relations/index.d.ts +835 -762
- package/dist/relations/index.js +143 -133
- package/dist/seeders/index.cjs +7 -5
- package/dist/seeders/index.d.ts +797 -724
- package/dist/seeders/index.js +8 -6
- package/dist/{migrations/stubs/stubs → stubs}/migration-js.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration-ts.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration.create-js.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration.create-ts.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration.update-js.stub +1 -0
- package/dist/{migrations/stubs/stubs → stubs}/migration.update-ts.stub +1 -0
- package/dist/stubs/model-ts.stub +9 -0
- package/package.json +31 -31
- package/types/builder.ts +1 -1
- package/types/database.ts +69 -0
- package/types/index.ts +3 -0
- package/types/model-builder.ts +132 -0
- package/types/query-builder.ts +0 -1
- package/types/query-methods.ts +0 -1
- package/types/schema.ts +92 -0
- package/types/utils.ts +1 -40
- package/dist/stubs/stubs/model-ts.stub +0 -5
- /package/dist/stubs/{stubs/arquebus.config-js.stub → arquebus.config-js.stub} +0 -0
- /package/dist/stubs/{stubs/arquebus.config-ts.stub → arquebus.config-ts.stub} +0 -0
- /package/dist/stubs/{stubs/model-js.stub → model-js.stub} +0 -0
- /package/dist/stubs/{stubs/seeder-js.stub → seeder-js.stub} +0 -0
- /package/dist/stubs/{stubs/seeder-ts.stub → seeder-ts.stub} +0 -0
|
@@ -36,14 +36,14 @@ node_fs_promises = __toESM(node_fs_promises, 1);
|
|
|
36
36
|
let path = require("path");
|
|
37
37
|
path = __toESM(path, 1);
|
|
38
38
|
let node_path = require("node:path");
|
|
39
|
+
let node_fs = require("node:fs");
|
|
39
40
|
let node_url = require("node:url");
|
|
40
|
-
let
|
|
41
|
-
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
42
|
-
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
|
|
41
|
+
let _h3ravel_support = require("@h3ravel/support");
|
|
43
42
|
let dayjs = require("dayjs");
|
|
44
43
|
dayjs = __toESM(dayjs, 1);
|
|
45
|
-
let
|
|
46
|
-
|
|
44
|
+
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
45
|
+
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
|
|
46
|
+
let _h3ravel_collect_js = require("@h3ravel/collect.js");
|
|
47
47
|
let knex = require("knex");
|
|
48
48
|
knex = __toESM(knex, 1);
|
|
49
49
|
let fs = require("fs");
|
|
@@ -196,8 +196,7 @@ var CockroachDB = class {
|
|
|
196
196
|
*/
|
|
197
197
|
async hasTable(table) {
|
|
198
198
|
const subquery = this.knex.select().from("information_schema.tables").whereIn("table_schema", this.explodedSchema).andWhere({ table_name: table });
|
|
199
|
-
|
|
200
|
-
return (record === null || record === void 0 ? void 0 : record.exists) || false;
|
|
199
|
+
return (await this.knex.select(this.knex.raw("exists (?)", [subquery])).first())?.exists || false;
|
|
201
200
|
}
|
|
202
201
|
/**
|
|
203
202
|
* Get all the available columns in the current schema/database. Can be filtered to a specific table
|
|
@@ -297,18 +296,17 @@ var CockroachDB = class {
|
|
|
297
296
|
${column ? "AND att.attname = ?" : ""}
|
|
298
297
|
`, bindings)]);
|
|
299
298
|
const parsedColumms = columns.rows.map((col) => {
|
|
300
|
-
var _col$default_value;
|
|
301
299
|
const constraintsForColumn = constraints.rows.filter((constraint) => constraint.table === col.table && constraint.column === col.name);
|
|
302
300
|
const foreignKeyConstraint = constraintsForColumn.find((constraint) => constraint.type === "f");
|
|
303
301
|
return {
|
|
304
302
|
...col,
|
|
305
303
|
is_unique: constraintsForColumn.some((constraint) => ["u", "p"].includes(constraint.type)),
|
|
306
304
|
is_primary_key: constraintsForColumn.some((constraint) => constraint.type === "p"),
|
|
307
|
-
has_auto_increment: ["integer", "bigint"].includes(col.data_type) && (
|
|
305
|
+
has_auto_increment: ["integer", "bigint"].includes(col.data_type) && (col.default_value?.startsWith("nextval(") ?? false),
|
|
308
306
|
default_value: parseDefaultValue$5(col.default_value),
|
|
309
|
-
foreign_key_schema:
|
|
310
|
-
foreign_key_table:
|
|
311
|
-
foreign_key_column:
|
|
307
|
+
foreign_key_schema: foreignKeyConstraint?.foreign_key_schema ?? null,
|
|
308
|
+
foreign_key_table: foreignKeyConstraint?.foreign_key_table ?? null,
|
|
309
|
+
foreign_key_column: foreignKeyConstraint?.foreign_key_column ?? null
|
|
312
310
|
};
|
|
313
311
|
});
|
|
314
312
|
if (table && column) return parsedColumms[0];
|
|
@@ -322,8 +320,7 @@ var CockroachDB = class {
|
|
|
322
320
|
table_name: table,
|
|
323
321
|
column_name: column
|
|
324
322
|
});
|
|
325
|
-
|
|
326
|
-
return (record === null || record === void 0 ? void 0 : record.exists) || false;
|
|
323
|
+
return (await this.knex.select(this.knex.raw("exists (?)", [subquery])).first())?.exists || false;
|
|
327
324
|
}
|
|
328
325
|
/**
|
|
329
326
|
* Get the primary key column for the given table
|
|
@@ -635,14 +632,13 @@ var MSSQL = class {
|
|
|
635
632
|
WHERE
|
|
636
633
|
OBJECT_SCHEMA_NAME (f.parent_object_id) = ?;
|
|
637
634
|
`, [this.schema]);
|
|
638
|
-
if (table) return result
|
|
635
|
+
if (table) return result?.filter((row) => row.table === table);
|
|
639
636
|
return result;
|
|
640
637
|
}
|
|
641
638
|
};
|
|
642
639
|
//#endregion
|
|
643
640
|
//#region src/inspector/dialects/mysql.ts
|
|
644
641
|
function rawColumnToColumn$1(rawColumn) {
|
|
645
|
-
var _rawColumn$EXTRA;
|
|
646
642
|
let dataType = rawColumn.COLUMN_TYPE.replace(/\(.*?\)/, "");
|
|
647
643
|
if (rawColumn.COLUMN_TYPE.startsWith("tinyint(1)")) dataType = "boolean";
|
|
648
644
|
return {
|
|
@@ -655,7 +651,7 @@ function rawColumnToColumn$1(rawColumn) {
|
|
|
655
651
|
max_length: rawColumn.CHARACTER_MAXIMUM_LENGTH,
|
|
656
652
|
numeric_precision: rawColumn.NUMERIC_PRECISION,
|
|
657
653
|
numeric_scale: rawColumn.NUMERIC_SCALE,
|
|
658
|
-
is_generated: !!
|
|
654
|
+
is_generated: !!rawColumn.EXTRA?.endsWith("GENERATED"),
|
|
659
655
|
is_nullable: rawColumn.IS_NULLABLE === "YES",
|
|
660
656
|
is_unique: rawColumn.COLUMN_KEY === "UNI",
|
|
661
657
|
is_primary_key: rawColumn.CONSTRAINT_NAME === "PRIMARY" || rawColumn.COLUMN_KEY === "PRI",
|
|
@@ -848,11 +844,10 @@ var oracleDB = class {
|
|
|
848
844
|
* Check if a table exists in the current schema/database
|
|
849
845
|
*/
|
|
850
846
|
async hasTable(table) {
|
|
851
|
-
|
|
847
|
+
return !!(await this.knex.select(this.knex.raw(`
|
|
852
848
|
/*+ OPTIMIZER_FEATURES_ENABLE('${OPTIMIZER_FEATURES}') */
|
|
853
849
|
COUNT(*) "count"
|
|
854
|
-
`)).from("USER_TABLES").where({ TABLE_NAME: table }).first();
|
|
855
|
-
return !!(result === null || result === void 0 ? void 0 : result.count);
|
|
850
|
+
`)).from("USER_TABLES").where({ TABLE_NAME: table }).first())?.count;
|
|
856
851
|
}
|
|
857
852
|
/**
|
|
858
853
|
* Get all the available columns in the current schema/database. Can be filtered to a specific table
|
|
@@ -928,15 +923,14 @@ var oracleDB = class {
|
|
|
928
923
|
* Check if a table exists in the current schema/database
|
|
929
924
|
*/
|
|
930
925
|
async hasColumn(table, column) {
|
|
931
|
-
|
|
926
|
+
return !!(await this.knex.select(this.knex.raw(`
|
|
932
927
|
/*+ OPTIMIZER_FEATURES_ENABLE('${OPTIMIZER_FEATURES}') NO_QUERY_TRANSFORMATION */
|
|
933
928
|
COUNT(*) "count"
|
|
934
929
|
`)).from("USER_TAB_COLS").where({
|
|
935
930
|
TABLE_NAME: table,
|
|
936
931
|
COLUMN_NAME: column,
|
|
937
932
|
HIDDEN_COLUMN: "NO"
|
|
938
|
-
}).first();
|
|
939
|
-
return !!(result === null || result === void 0 ? void 0 : result.count);
|
|
933
|
+
}).first())?.count;
|
|
940
934
|
}
|
|
941
935
|
/**
|
|
942
936
|
* Get the primary key column for the given table
|
|
@@ -1102,13 +1096,12 @@ var Postgres = class {
|
|
|
1102
1096
|
`, bindings)).rows;
|
|
1103
1097
|
}
|
|
1104
1098
|
async columnInfo(table, column) {
|
|
1105
|
-
var _versionResponse$rows;
|
|
1106
1099
|
const { knex } = this;
|
|
1107
1100
|
const bindings = [];
|
|
1108
1101
|
if (table) bindings.push(table);
|
|
1109
1102
|
if (column) bindings.push(column);
|
|
1110
1103
|
const schemaIn = this.explodedSchema.map((schemaName) => `${this.knex.raw("?", [schemaName])}::regnamespace`);
|
|
1111
|
-
const majorVersion = (
|
|
1104
|
+
const majorVersion = (await this.knex.raw("SHOW server_version")).rows?.[0]?.server_version?.split(".")?.[0] ?? 10;
|
|
1112
1105
|
let generationSelect = `
|
|
1113
1106
|
NULL AS generation_expression,
|
|
1114
1107
|
pg_get_expr(ad.adbin, ad.adrelid) AS default_value,
|
|
@@ -1200,9 +1193,9 @@ var Postgres = class {
|
|
|
1200
1193
|
is_primary_key: constraintsForColumn.some((constraint) => constraint.type === "p"),
|
|
1201
1194
|
has_auto_increment: constraintsForColumn.some((constraint) => constraint.has_auto_increment),
|
|
1202
1195
|
default_value: parseDefaultValue$1(col.default_value),
|
|
1203
|
-
foreign_key_schema:
|
|
1204
|
-
foreign_key_table:
|
|
1205
|
-
foreign_key_column:
|
|
1196
|
+
foreign_key_schema: foreignKeyConstraint?.foreign_key_schema ?? null,
|
|
1197
|
+
foreign_key_table: foreignKeyConstraint?.foreign_key_table ?? null,
|
|
1198
|
+
foreign_key_column: foreignKeyConstraint?.foreign_key_column ?? null
|
|
1206
1199
|
};
|
|
1207
1200
|
});
|
|
1208
1201
|
if (table && column) return parsedColumms[0];
|
|
@@ -1399,7 +1392,7 @@ var ModelNotFoundError = class extends BaseError {
|
|
|
1399
1392
|
}
|
|
1400
1393
|
setModel(model, ids = []) {
|
|
1401
1394
|
this.model = model;
|
|
1402
|
-
this.ids =
|
|
1395
|
+
this.ids = Array.isArray(ids) ? ids : [ids];
|
|
1403
1396
|
this.message = `No query results for model [${model}]`;
|
|
1404
1397
|
if (this.ids.length > 0) this.message += " " + this.ids.join(", ");
|
|
1405
1398
|
else this.message += ".";
|
|
@@ -1490,25 +1483,29 @@ function compose$1(Base, ...mixins) {
|
|
|
1490
1483
|
}, Base);
|
|
1491
1484
|
}
|
|
1492
1485
|
//#endregion
|
|
1486
|
+
//#region src/dayjs.ts
|
|
1487
|
+
const dayjs$1 = dayjs.default ?? dayjs;
|
|
1488
|
+
const advancedFormat = dayjs_plugin_advancedFormat_js.default ?? dayjs_plugin_advancedFormat_js;
|
|
1489
|
+
dayjs$1.extend(advancedFormat);
|
|
1490
|
+
//#endregion
|
|
1493
1491
|
//#region src/utils.ts
|
|
1494
|
-
dayjs.default.extend(dayjs_plugin_advancedFormat_js.default);
|
|
1495
1492
|
const getRelationName = (relationMethod) => {
|
|
1496
|
-
return
|
|
1493
|
+
return _h3ravel_support.Str.snake(relationMethod.substring(8));
|
|
1497
1494
|
};
|
|
1498
1495
|
const getRelationMethod = (relation) => {
|
|
1499
|
-
return
|
|
1496
|
+
return _h3ravel_support.Str.camel(`relation_${relation}`);
|
|
1500
1497
|
};
|
|
1501
1498
|
const getScopeMethod = (scope) => {
|
|
1502
|
-
return
|
|
1499
|
+
return _h3ravel_support.Str.camel(`scope_${scope}`);
|
|
1503
1500
|
};
|
|
1504
1501
|
const getAttrMethod = (attr) => {
|
|
1505
|
-
return
|
|
1502
|
+
return _h3ravel_support.Str.camel(`attribute_${attr}`);
|
|
1506
1503
|
};
|
|
1507
1504
|
const getGetterMethod = (attr) => {
|
|
1508
|
-
return
|
|
1505
|
+
return _h3ravel_support.Str.camel(`get_${attr}_attribute`);
|
|
1509
1506
|
};
|
|
1510
1507
|
const getSetterMethod = (attr) => {
|
|
1511
|
-
return
|
|
1508
|
+
return _h3ravel_support.Str.camel(`set_${attr}_attribute`);
|
|
1512
1509
|
};
|
|
1513
1510
|
/**
|
|
1514
1511
|
* Tap into a model a collection instance
|
|
@@ -1522,9 +1519,9 @@ const tap = (instance, callback) => {
|
|
|
1522
1519
|
return result instanceof Promise ? result.then(() => instance) : instance;
|
|
1523
1520
|
};
|
|
1524
1521
|
const { compose } = mixin_exports;
|
|
1525
|
-
const flatten
|
|
1522
|
+
const flatten = (arr) => arr.flat();
|
|
1526
1523
|
const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
|
|
1527
|
-
const snakeCase = (str) =>
|
|
1524
|
+
const snakeCase = (str) => _h3ravel_support.Str.trim(_h3ravel_support.Str.snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/_+/g, "_");
|
|
1528
1525
|
//#endregion
|
|
1529
1526
|
//#region src/relations/relation.ts
|
|
1530
1527
|
var Relation = class {
|
|
@@ -1611,8 +1608,7 @@ var Relation = class {
|
|
|
1611
1608
|
return this.parent.getQualifiedKeyName();
|
|
1612
1609
|
}
|
|
1613
1610
|
getExistenceCompareKey() {
|
|
1614
|
-
|
|
1615
|
-
return (_this$getQualifiedFor = this.getQualifiedForeignKeyName) === null || _this$getQualifiedFor === void 0 ? void 0 : _this$getQualifiedFor.call(this);
|
|
1611
|
+
return this.getQualifiedForeignKeyName?.();
|
|
1616
1612
|
}
|
|
1617
1613
|
};
|
|
1618
1614
|
//#endregion
|
|
@@ -1753,8 +1749,7 @@ const HasAttributes = (Model) => {
|
|
|
1753
1749
|
return this;
|
|
1754
1750
|
}
|
|
1755
1751
|
normalizeCastClassResponse(key, value) {
|
|
1756
|
-
|
|
1757
|
-
return (value === null || value === void 0 || (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) === "Object" ? value : { [key]: value };
|
|
1752
|
+
return value?.constructor?.name === "Object" ? value : { [key]: value };
|
|
1758
1753
|
}
|
|
1759
1754
|
syncOriginal() {
|
|
1760
1755
|
this.original = this.getAttributes();
|
|
@@ -1864,9 +1859,9 @@ const HasAttributes = (Model) => {
|
|
|
1864
1859
|
return null;
|
|
1865
1860
|
}
|
|
1866
1861
|
case "collection": try {
|
|
1867
|
-
return (0,
|
|
1862
|
+
return (0, _h3ravel_collect_js.collect)(JSON.parse(value));
|
|
1868
1863
|
} catch {
|
|
1869
|
-
return (0,
|
|
1864
|
+
return (0, _h3ravel_collect_js.collect)([]);
|
|
1870
1865
|
}
|
|
1871
1866
|
case "date": return this.asDate(value);
|
|
1872
1867
|
case "datetime":
|
|
@@ -1879,8 +1874,8 @@ const HasAttributes = (Model) => {
|
|
|
1879
1874
|
attributesToData() {
|
|
1880
1875
|
let attributes = { ...this.attributes };
|
|
1881
1876
|
for (const key in attributes) {
|
|
1882
|
-
if (this.hidden.includes(key)) attributes =
|
|
1883
|
-
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes =
|
|
1877
|
+
if (this.hidden.includes(key)) attributes = _h3ravel_support.Arr.except(attributes, [key]);
|
|
1878
|
+
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = _h3ravel_support.Arr.except(attributes, [key]);
|
|
1884
1879
|
}
|
|
1885
1880
|
for (const key of this.getDates()) {
|
|
1886
1881
|
if (attributes[key] === void 0) continue;
|
|
@@ -1892,7 +1887,7 @@ const HasAttributes = (Model) => {
|
|
|
1892
1887
|
if (key in attributes === false) continue;
|
|
1893
1888
|
attributes[key] = this.castAttribute(key, attributes[key]);
|
|
1894
1889
|
if (key in attributes && ["date", "datetime"].includes(String(value))) attributes[key] = this.serializeDate(attributes[key]);
|
|
1895
|
-
if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] =
|
|
1890
|
+
if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = dayjs$1(attributes[key]).format(String(value).split(":")[1]);
|
|
1896
1891
|
}
|
|
1897
1892
|
for (const key of this.appends) attributes[key] = this.mutateAttribute(key, null);
|
|
1898
1893
|
return attributes;
|
|
@@ -1908,7 +1903,7 @@ const HasAttributes = (Model) => {
|
|
|
1908
1903
|
return this.getDates().includes(key) || this.isDateCastable(key);
|
|
1909
1904
|
}
|
|
1910
1905
|
serializeDate(date) {
|
|
1911
|
-
return date ?
|
|
1906
|
+
return date ? dayjs$1(date).toISOString() : null;
|
|
1912
1907
|
}
|
|
1913
1908
|
getDates() {
|
|
1914
1909
|
return this.usesTimestamps() ? [this.getCreatedAtColumn(), this.getUpdatedAtColumn()] : [];
|
|
@@ -1935,13 +1930,13 @@ const HasAttributes = (Model) => {
|
|
|
1935
1930
|
}
|
|
1936
1931
|
hasCast(key, types = []) {
|
|
1937
1932
|
if (key in this.casts) {
|
|
1938
|
-
types = (
|
|
1933
|
+
types = flatten(types);
|
|
1939
1934
|
return types.length > 0 ? types.includes(this.getCastType(key)) : true;
|
|
1940
1935
|
}
|
|
1941
1936
|
return false;
|
|
1942
1937
|
}
|
|
1943
1938
|
withDayjs(date) {
|
|
1944
|
-
return
|
|
1939
|
+
return dayjs$1(date);
|
|
1945
1940
|
}
|
|
1946
1941
|
isCustomCast(cast) {
|
|
1947
1942
|
return typeof cast === "function" && new cast() instanceof CastsAttributes;
|
|
@@ -1958,7 +1953,7 @@ const HasAttributes = (Model) => {
|
|
|
1958
1953
|
return this.hasCast(key, ["date", "datetime"]);
|
|
1959
1954
|
}
|
|
1960
1955
|
fromDateTime(value) {
|
|
1961
|
-
return
|
|
1956
|
+
return dayjs$1(this.asDateTime(value)).format(this.getDateFormat());
|
|
1962
1957
|
}
|
|
1963
1958
|
getDateFormat() {
|
|
1964
1959
|
return this.dateFormat || "YYYY-MM-DD HH:mm:ss";
|
|
@@ -1973,7 +1968,7 @@ const HasAttributes = (Model) => {
|
|
|
1973
1968
|
return new Date(value);
|
|
1974
1969
|
}
|
|
1975
1970
|
asDate(value) {
|
|
1976
|
-
return
|
|
1971
|
+
return dayjs$1(this.asDateTime(value)).startOf("day").toDate();
|
|
1977
1972
|
}
|
|
1978
1973
|
};
|
|
1979
1974
|
};
|
|
@@ -1994,10 +1989,14 @@ const HasGlobalScopes = (Model) => {
|
|
|
1994
1989
|
static globalScopes;
|
|
1995
1990
|
static addGlobalScope(scope, implementation = null) {
|
|
1996
1991
|
if (typeof scope === "string" && implementation instanceof Scope) {
|
|
1997
|
-
|
|
1992
|
+
const scopes = this.globalScopes ?? {};
|
|
1993
|
+
(0, _h3ravel_support.data_set)(scopes, this.name + "." + scope, implementation);
|
|
1994
|
+
this.globalScopes = scopes;
|
|
1998
1995
|
return implementation;
|
|
1999
1996
|
} else if (scope instanceof Scope) {
|
|
2000
|
-
|
|
1997
|
+
const scopes = this.globalScopes ?? {};
|
|
1998
|
+
(0, _h3ravel_support.data_set)(scopes, this.name + "." + scope.constructor.name, scope);
|
|
1999
|
+
this.globalScopes = scopes;
|
|
2001
2000
|
return scope;
|
|
2002
2001
|
}
|
|
2003
2002
|
throw new InvalidArgumentError("Global scope must be an instance of Scope.");
|
|
@@ -2006,8 +2005,8 @@ const HasGlobalScopes = (Model) => {
|
|
|
2006
2005
|
return this.getGlobalScope(scope) !== null;
|
|
2007
2006
|
}
|
|
2008
2007
|
static getGlobalScope(scope) {
|
|
2009
|
-
if (typeof scope === "string") return (0,
|
|
2010
|
-
return (0,
|
|
2008
|
+
if (typeof scope === "string") return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope);
|
|
2009
|
+
return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope.constructor.name);
|
|
2011
2010
|
}
|
|
2012
2011
|
static getAllGlobalScopes() {
|
|
2013
2012
|
return this.globalScopes;
|
|
@@ -2016,7 +2015,7 @@ const HasGlobalScopes = (Model) => {
|
|
|
2016
2015
|
this.globalScopes = scopes;
|
|
2017
2016
|
}
|
|
2018
2017
|
getGlobalScopes() {
|
|
2019
|
-
return (0,
|
|
2018
|
+
return (0, _h3ravel_support.data_get)(this.constructor.globalScopes ?? {}, this.constructor.name, {});
|
|
2020
2019
|
}
|
|
2021
2020
|
};
|
|
2022
2021
|
};
|
|
@@ -2116,7 +2115,7 @@ const HasOneOrMany = (Relation) => {
|
|
|
2116
2115
|
}
|
|
2117
2116
|
buildDictionary(results) {
|
|
2118
2117
|
const foreign = this.getForeignKeyName();
|
|
2119
|
-
return (0,
|
|
2118
|
+
return (0, _h3ravel_collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
|
|
2120
2119
|
}
|
|
2121
2120
|
async save(model) {
|
|
2122
2121
|
this.setForeignAttributesForCreate(model);
|
|
@@ -2187,13 +2186,11 @@ var HasMany = class extends compose(Relation, HasOneOrMany) {
|
|
|
2187
2186
|
return this.getParentKey() !== null ? await this.query.get() : new Collection([]);
|
|
2188
2187
|
}
|
|
2189
2188
|
getForeignKeyName() {
|
|
2190
|
-
|
|
2191
|
-
const segments = (_this$foreignKey = this.foreignKey) === null || _this$foreignKey === void 0 ? void 0 : _this$foreignKey.split(".");
|
|
2192
|
-
return segments === null || segments === void 0 ? void 0 : segments.pop();
|
|
2189
|
+
return (this.foreignKey?.split("."))?.pop();
|
|
2193
2190
|
}
|
|
2194
2191
|
buildDictionary(results) {
|
|
2195
2192
|
const foreign = this.getForeignKeyName();
|
|
2196
|
-
return (0,
|
|
2193
|
+
return (0, _h3ravel_collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
|
|
2197
2194
|
}
|
|
2198
2195
|
match(models, results, relation) {
|
|
2199
2196
|
return this.matchOneOrMany(models, results, relation, "many");
|
|
@@ -2224,9 +2221,7 @@ var HasOne = class extends compose(Relation, HasOneOrMany, SupportsDefaultModels
|
|
|
2224
2221
|
return this.matchOneOrMany(models, results, relation, "one");
|
|
2225
2222
|
}
|
|
2226
2223
|
getForeignKeyName() {
|
|
2227
|
-
|
|
2228
|
-
const segments = (_this$foreignKey = this.foreignKey) === null || _this$foreignKey === void 0 ? void 0 : _this$foreignKey.split(".");
|
|
2229
|
-
return segments === null || segments === void 0 ? void 0 : segments.pop();
|
|
2224
|
+
return (this.foreignKey?.split("."))?.pop();
|
|
2230
2225
|
}
|
|
2231
2226
|
async getResults() {
|
|
2232
2227
|
if (this.getParentKey() === null) return this.getDefaultFor(this.parent);
|
|
@@ -2335,10 +2330,10 @@ var HasManyThrough = class extends Relation {
|
|
|
2335
2330
|
}
|
|
2336
2331
|
const model = await this.first(columns);
|
|
2337
2332
|
if (model) return model;
|
|
2338
|
-
return callback
|
|
2333
|
+
return callback?.();
|
|
2339
2334
|
}
|
|
2340
2335
|
async find(id, columns = ["*"]) {
|
|
2341
|
-
if (
|
|
2336
|
+
if (Array.isArray(id)) return await this.findMany(id, columns);
|
|
2342
2337
|
return await this.where(this.getRelated().getQualifiedKeyName(), "=", id).first(columns);
|
|
2343
2338
|
}
|
|
2344
2339
|
async findMany(ids, columns = ["*"]) {
|
|
@@ -2366,7 +2361,7 @@ var HasManyThrough = class extends Relation {
|
|
|
2366
2361
|
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
2367
2362
|
}
|
|
2368
2363
|
shouldSelect(columns = ["*"]) {
|
|
2369
|
-
if (
|
|
2364
|
+
if (columns?.at(0) == "*") columns = [this.related.getTable() + ".*"];
|
|
2370
2365
|
return [...columns, this.getQualifiedFirstKeyName() + " as laravel_through_key"];
|
|
2371
2366
|
}
|
|
2372
2367
|
async chunk(count, callback) {
|
|
@@ -2460,7 +2455,7 @@ const HasRelations = (Model) => {
|
|
|
2460
2455
|
return this;
|
|
2461
2456
|
}
|
|
2462
2457
|
unsetRelation(relation) {
|
|
2463
|
-
this.relations =
|
|
2458
|
+
this.relations = _h3ravel_support.Arr.except(this.relations, [relation]);
|
|
2464
2459
|
return this;
|
|
2465
2460
|
}
|
|
2466
2461
|
relationLoaded(relation) {
|
|
@@ -2483,8 +2478,7 @@ const HasRelations = (Model) => {
|
|
|
2483
2478
|
return data;
|
|
2484
2479
|
}
|
|
2485
2480
|
guessBelongsToRelation() {
|
|
2486
|
-
|
|
2487
|
-
const functionName = (((_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2]) ?? "").split(" ")[5];
|
|
2481
|
+
const functionName = ((/* @__PURE__ */ new Error()).stack?.split("\n")[2] ?? "").split(" ")[5];
|
|
2488
2482
|
return getRelationName(functionName);
|
|
2489
2483
|
}
|
|
2490
2484
|
joiningTable(related, instance = null) {
|
|
@@ -2594,7 +2588,7 @@ const HidesAttributes = (Model) => {
|
|
|
2594
2588
|
makeVisible(...keys) {
|
|
2595
2589
|
const visible = flattenDeep(keys);
|
|
2596
2590
|
if (this.visible.length > 0) this.visible = [...this.visible, ...visible];
|
|
2597
|
-
this.hidden = (0,
|
|
2591
|
+
this.hidden = (0, _h3ravel_collect_js.collect)(this.hidden).diff(visible).all();
|
|
2598
2592
|
return this;
|
|
2599
2593
|
}
|
|
2600
2594
|
makeHidden(key, ...keys) {
|
|
@@ -2738,10 +2732,9 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
2738
2732
|
asProxy() {
|
|
2739
2733
|
return new Proxy(this, {
|
|
2740
2734
|
get: function(target, prop) {
|
|
2741
|
-
var _target$connector$cli;
|
|
2742
2735
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2743
2736
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
2744
|
-
const skipReturning = !!
|
|
2737
|
+
const skipReturning = !!target.connector.client.config?.client?.includes("mysql") && prop === "returning";
|
|
2745
2738
|
if ([
|
|
2746
2739
|
"select",
|
|
2747
2740
|
"from",
|
|
@@ -2944,6 +2937,9 @@ var arquebus = class arquebus {
|
|
|
2944
2937
|
if (this.instance === null) this.instance = new arquebus();
|
|
2945
2938
|
return this.instance;
|
|
2946
2939
|
}
|
|
2940
|
+
static withSchema() {
|
|
2941
|
+
return this;
|
|
2942
|
+
}
|
|
2947
2943
|
/**
|
|
2948
2944
|
* Initialize a new database connection
|
|
2949
2945
|
*
|
|
@@ -3033,12 +3029,12 @@ var arquebus = class arquebus {
|
|
|
3033
3029
|
const tsPath = path.default.resolve("arquebus.config.ts");
|
|
3034
3030
|
const instance = this.getInstance();
|
|
3035
3031
|
if ((0, fs.existsSync)(jsPath)) {
|
|
3036
|
-
config = (await
|
|
3032
|
+
config = (await (0, _h3ravel_shared.importFile)(jsPath)).default;
|
|
3037
3033
|
if (addConnection) instance.addConnection(config, config.client);
|
|
3038
3034
|
return config;
|
|
3039
3035
|
}
|
|
3040
3036
|
if ((0, fs.existsSync)(tsPath)) if (process.env.NODE_ENV !== "production") {
|
|
3041
|
-
config = (await
|
|
3037
|
+
config = (await (0, _h3ravel_shared.importFile)(tsPath)).default;
|
|
3042
3038
|
if (addConnection) instance.addConnection(config, config.client);
|
|
3043
3039
|
return config;
|
|
3044
3040
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
@@ -3054,7 +3050,7 @@ var arquebus = class arquebus {
|
|
|
3054
3050
|
"cjs"
|
|
3055
3051
|
], dir);
|
|
3056
3052
|
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
3057
|
-
config = (await
|
|
3053
|
+
config = (await (0, _h3ravel_shared.importFile)(found)).default;
|
|
3058
3054
|
if (addConnection) instance.addConnection(config, config.client);
|
|
3059
3055
|
return config;
|
|
3060
3056
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
@@ -3075,7 +3071,7 @@ var arquebus = class arquebus {
|
|
|
3075
3071
|
}
|
|
3076
3072
|
async destroyAll() {
|
|
3077
3073
|
await Promise.all(Object.values(this.manager).map((connection) => {
|
|
3078
|
-
return connection
|
|
3074
|
+
return connection?.destroy();
|
|
3079
3075
|
}));
|
|
3080
3076
|
}
|
|
3081
3077
|
createModel(name, options = {}) {
|
|
@@ -3084,29 +3080,25 @@ var arquebus = class arquebus {
|
|
|
3084
3080
|
this.models = {
|
|
3085
3081
|
...this.models,
|
|
3086
3082
|
[name]: class extends BaseModel {
|
|
3087
|
-
table =
|
|
3088
|
-
connection =
|
|
3089
|
-
timestamps =
|
|
3090
|
-
primaryKey =
|
|
3091
|
-
keyType =
|
|
3092
|
-
incrementing =
|
|
3093
|
-
with =
|
|
3094
|
-
casts =
|
|
3095
|
-
static CREATED_AT =
|
|
3096
|
-
static UPDATED_AT =
|
|
3097
|
-
static DELETED_AT =
|
|
3083
|
+
table = options?.table ?? null;
|
|
3084
|
+
connection = options?.connection ?? null;
|
|
3085
|
+
timestamps = options?.timestamps ?? true;
|
|
3086
|
+
primaryKey = options?.primaryKey ?? "id";
|
|
3087
|
+
keyType = options?.keyType ?? "int";
|
|
3088
|
+
incrementing = options?.incrementing ?? true;
|
|
3089
|
+
with = options?.with ?? [];
|
|
3090
|
+
casts = options?.casts ?? {};
|
|
3091
|
+
static CREATED_AT = options?.CREATED_AT ?? "created_at";
|
|
3092
|
+
static UPDATED_AT = options?.UPDATED_AT ?? "updated_at";
|
|
3093
|
+
static DELETED_AT = options?.DELETED_AT ?? "deleted_at";
|
|
3098
3094
|
}
|
|
3099
3095
|
};
|
|
3100
3096
|
if ("attributes" in options) for (const attribute in options.attributes) {
|
|
3101
3097
|
if (options.attributes[attribute] instanceof Attribute === false) throw new Error("Attribute must be an instance of \"Attribute\"");
|
|
3102
|
-
this.models[name].prototype[getAttrMethod(attribute)] = () =>
|
|
3103
|
-
var _options$attributes;
|
|
3104
|
-
return (_options$attributes = options.attributes) === null || _options$attributes === void 0 ? void 0 : _options$attributes[attribute];
|
|
3105
|
-
};
|
|
3098
|
+
this.models[name].prototype[getAttrMethod(attribute)] = () => options.attributes?.[attribute];
|
|
3106
3099
|
}
|
|
3107
3100
|
if ("relations" in options) for (const relation in options.relations) this.models[name].prototype[getRelationMethod(relation)] = function() {
|
|
3108
|
-
|
|
3109
|
-
return (_options$relations = options.relations) === null || _options$relations === void 0 ? void 0 : _options$relations[relation](this);
|
|
3101
|
+
return options.relations?.[relation](this);
|
|
3110
3102
|
};
|
|
3111
3103
|
if ("scopes" in options) for (const scope in options.scopes) this.models[name].prototype[getScopeMethod(scope)] = options.scopes[scope];
|
|
3112
3104
|
this.models[name].setConnectionResolver(this);
|
|
@@ -3144,6 +3136,9 @@ var Model = class Model extends BaseModel {
|
|
|
3144
3136
|
this.buildRelationships(attributes);
|
|
3145
3137
|
return this.asProxy();
|
|
3146
3138
|
}
|
|
3139
|
+
static define() {
|
|
3140
|
+
return this;
|
|
3141
|
+
}
|
|
3147
3142
|
static query(trx = null) {
|
|
3148
3143
|
return new this().newQuery(trx);
|
|
3149
3144
|
}
|
|
@@ -3327,7 +3322,7 @@ var Model = class Model extends BaseModel {
|
|
|
3327
3322
|
});
|
|
3328
3323
|
}
|
|
3329
3324
|
toData() {
|
|
3330
|
-
return
|
|
3325
|
+
return _h3ravel_support.Obj.deepMerge(this.attributesToData(), this.relationsToData());
|
|
3331
3326
|
}
|
|
3332
3327
|
toJSON() {
|
|
3333
3328
|
return this.toData();
|
|
@@ -3338,6 +3333,15 @@ var Model = class Model extends BaseModel {
|
|
|
3338
3333
|
toString() {
|
|
3339
3334
|
return this.toJson();
|
|
3340
3335
|
}
|
|
3336
|
+
getAttributes() {
|
|
3337
|
+
return super.getAttributes();
|
|
3338
|
+
}
|
|
3339
|
+
getAttribute(key) {
|
|
3340
|
+
return super.getAttribute(key);
|
|
3341
|
+
}
|
|
3342
|
+
setAttribute(key, value) {
|
|
3343
|
+
return super.setAttribute(key, value);
|
|
3344
|
+
}
|
|
3341
3345
|
fill(attributes) {
|
|
3342
3346
|
for (const key in attributes) this.setAttribute(key, attributes[key]);
|
|
3343
3347
|
return this;
|
|
@@ -3378,10 +3382,9 @@ var Model = class Model extends BaseModel {
|
|
|
3378
3382
|
if (this.usesTimestamps()) this.updateTimestamps();
|
|
3379
3383
|
const attributes = this.getAttributes();
|
|
3380
3384
|
if (this.getIncrementing()) {
|
|
3381
|
-
var _data$;
|
|
3382
3385
|
const keyName = this.getKeyName();
|
|
3383
3386
|
const data = await query.insert([attributes], [keyName]);
|
|
3384
|
-
this.setAttribute(keyName,
|
|
3387
|
+
this.setAttribute(keyName, data[0]?.[keyName] || data[0]);
|
|
3385
3388
|
} else if (Object.keys(attributes).length > 0) await query.insert(attributes);
|
|
3386
3389
|
this.exists = true;
|
|
3387
3390
|
await this.execHooks("created", options);
|
|
@@ -3423,7 +3426,7 @@ var Model = class Model extends BaseModel {
|
|
|
3423
3426
|
if (!this.exists) return Promise.resolve(void 0);
|
|
3424
3427
|
const model = await this.constructor.query().where(this.getKeyName(), this.getKey()).first();
|
|
3425
3428
|
this.attributes = { ...model.attributes };
|
|
3426
|
-
await this.load((0,
|
|
3429
|
+
await this.load((0, _h3ravel_collect_js.collect)(this.relations).reject((relation) => {
|
|
3427
3430
|
return relation instanceof Pivot;
|
|
3428
3431
|
}).keys().all());
|
|
3429
3432
|
this.syncOriginal();
|
|
@@ -3487,7 +3490,7 @@ var Pivot = class extends Model {
|
|
|
3487
3490
|
};
|
|
3488
3491
|
//#endregion
|
|
3489
3492
|
//#region src/collection.ts
|
|
3490
|
-
var Collection = class
|
|
3493
|
+
var Collection = class extends _h3ravel_collect_js.Collection {
|
|
3491
3494
|
newConstructor(...args) {
|
|
3492
3495
|
return new (this.getConstructor())(...args);
|
|
3493
3496
|
}
|
|
@@ -3496,17 +3499,18 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
3496
3499
|
}
|
|
3497
3500
|
async load(...relations) {
|
|
3498
3501
|
if (this.isNotEmpty()) {
|
|
3499
|
-
const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.
|
|
3502
|
+
const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.all());
|
|
3500
3503
|
return this.newConstructor(items);
|
|
3501
3504
|
}
|
|
3502
3505
|
return this;
|
|
3503
3506
|
}
|
|
3504
3507
|
async loadAggregate(relations, column, action = null) {
|
|
3505
3508
|
if (this.isEmpty()) return this;
|
|
3506
|
-
const
|
|
3507
|
-
const
|
|
3509
|
+
const first = this.first();
|
|
3510
|
+
const models = (await first.newModelQuery().whereIn(first.getKeyName(), this.modelKeys()).select(first.getKeyName()).withAggregate(relations, column, action).get()).keyBy(first.getKeyName());
|
|
3511
|
+
const attributes = (0, _h3ravel_collect_js.collect)(Object.keys(models.first().getAttributes())).diff([models.first().getKeyName()]).all();
|
|
3508
3512
|
this.each((model) => {
|
|
3509
|
-
const extraAttributes =
|
|
3513
|
+
const extraAttributes = _h3ravel_support.Arr.select(models.get(model.getKey()).getAttributes(), attributes);
|
|
3510
3514
|
model.fill(extraAttributes).syncOriginalAttributes(...attributes);
|
|
3511
3515
|
});
|
|
3512
3516
|
return this;
|
|
@@ -3544,20 +3548,21 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
3544
3548
|
diff(items) {
|
|
3545
3549
|
const diff = new this.constructor();
|
|
3546
3550
|
const dictionary = this.getDictionary(items);
|
|
3547
|
-
this.
|
|
3551
|
+
this.all().map((item) => {
|
|
3548
3552
|
if (dictionary[item.getKey()] === void 0) diff.add(item);
|
|
3549
3553
|
});
|
|
3550
3554
|
return diff;
|
|
3551
3555
|
}
|
|
3552
|
-
except(keys) {
|
|
3553
|
-
const
|
|
3556
|
+
except(...keys) {
|
|
3557
|
+
const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
|
|
3558
|
+
const dictionary = _h3ravel_support.Arr.except(this.getDictionary(), values);
|
|
3554
3559
|
return new this.constructor(Object.values(dictionary));
|
|
3555
3560
|
}
|
|
3556
3561
|
intersect(items) {
|
|
3557
3562
|
const intersect = new this.constructor();
|
|
3558
|
-
if (
|
|
3563
|
+
if (_h3ravel_support.Arr.isEmpty(items)) return intersect;
|
|
3559
3564
|
const dictionary = this.getDictionary(items);
|
|
3560
|
-
for (const item of this.
|
|
3565
|
+
for (const item of this.all()) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
|
|
3561
3566
|
return intersect;
|
|
3562
3567
|
}
|
|
3563
3568
|
unique(key, _strict = false) {
|
|
@@ -3566,20 +3571,21 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
3566
3571
|
}
|
|
3567
3572
|
find(key, defaultValue = null) {
|
|
3568
3573
|
if (key instanceof Model) key = key.getKey();
|
|
3569
|
-
if (
|
|
3574
|
+
if (Array.isArray(key)) {
|
|
3570
3575
|
if (this.isEmpty()) return new this.constructor();
|
|
3571
3576
|
return this.whereIn(this.first().getKeyName(), key);
|
|
3572
3577
|
}
|
|
3573
|
-
(0,
|
|
3578
|
+
(0, _h3ravel_collect_js.collect)(this.all()).first((model) => {
|
|
3574
3579
|
return model.getKey() == key;
|
|
3575
3580
|
});
|
|
3576
|
-
return this.
|
|
3581
|
+
return this.all().filter((model) => {
|
|
3577
3582
|
return model.getKey() == key;
|
|
3578
3583
|
})[0] || defaultValue;
|
|
3579
3584
|
}
|
|
3580
3585
|
async fresh(...args) {
|
|
3581
3586
|
if (this.isEmpty()) return new this.constructor();
|
|
3582
3587
|
const model = this.first();
|
|
3588
|
+
if (!model) return new this.constructor();
|
|
3583
3589
|
const freshModels = (await model.newQuery().with(...args).whereIn(model.getKeyName(), this.modelKeys()).get()).getDictionary();
|
|
3584
3590
|
return this.filter((model) => {
|
|
3585
3591
|
return model.exists && freshModels[model.getKey()] !== void 0;
|
|
@@ -3602,15 +3608,15 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
3602
3608
|
item.append(attributes);
|
|
3603
3609
|
});
|
|
3604
3610
|
}
|
|
3605
|
-
only(keys) {
|
|
3606
|
-
|
|
3607
|
-
const dictionary =
|
|
3611
|
+
only(...keys) {
|
|
3612
|
+
const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
|
|
3613
|
+
const dictionary = _h3ravel_support.Arr.select(this.getDictionary(), values);
|
|
3608
3614
|
return new this.constructor(Object.values(dictionary));
|
|
3609
3615
|
}
|
|
3610
3616
|
getDictionary(items) {
|
|
3611
|
-
|
|
3617
|
+
const values = !items ? this.all() : items instanceof _h3ravel_collect_js.Collection ? items.all() : items;
|
|
3612
3618
|
const dictionary = {};
|
|
3613
|
-
|
|
3619
|
+
values.map((value) => {
|
|
3614
3620
|
dictionary[value.getKey()] = value;
|
|
3615
3621
|
});
|
|
3616
3622
|
return dictionary;
|
|
@@ -3634,8 +3640,8 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
3634
3640
|
return JSON.stringify(this.toData(), ...args);
|
|
3635
3641
|
}
|
|
3636
3642
|
[Symbol.iterator] = () => {
|
|
3637
|
-
const items = this.
|
|
3638
|
-
const length =
|
|
3643
|
+
const items = this.all();
|
|
3644
|
+
const length = items.length;
|
|
3639
3645
|
let n = 0;
|
|
3640
3646
|
return { next() {
|
|
3641
3647
|
return n < length ? {
|
|
@@ -3682,24 +3688,24 @@ const InteractsWithPivotTable = (Relation) => {
|
|
|
3682
3688
|
let records;
|
|
3683
3689
|
const results = await this.getCurrentlyAttachedPivots();
|
|
3684
3690
|
const current = results.length === 0 ? [] : results.map((result) => result.toData()).pluck(this.relatedPivotKey).all().map((i) => String(i));
|
|
3685
|
-
const detach = (0,
|
|
3691
|
+
const detach = (0, _h3ravel_collect_js.collect)(current).diff(Object.keys(records = this.formatRecordsList(this.parseIds(ids)))).all();
|
|
3686
3692
|
if (detaching && detach.length > 0) {
|
|
3687
3693
|
await this.detach(detach);
|
|
3688
3694
|
changes.detached = this.castKeys(detach);
|
|
3689
3695
|
}
|
|
3690
|
-
changes =
|
|
3696
|
+
changes = _h3ravel_support.Obj.deepMerge(changes, await this.attachNew(records, current, false));
|
|
3691
3697
|
return changes;
|
|
3692
3698
|
}
|
|
3693
3699
|
syncWithoutDetaching(ids) {
|
|
3694
3700
|
return this.sync(ids, false);
|
|
3695
3701
|
}
|
|
3696
3702
|
syncWithPivotValues(ids, values, detaching = true) {
|
|
3697
|
-
return this.sync((0,
|
|
3698
|
-
return [id, values];
|
|
3703
|
+
return this.sync((0, _h3ravel_collect_js.collect)(this.parseIds(ids)).mapWithKeys((id) => {
|
|
3704
|
+
return [String(id), values];
|
|
3699
3705
|
}), detaching);
|
|
3700
3706
|
}
|
|
3701
3707
|
withPivot(columns) {
|
|
3702
|
-
this.pivotColumns = this.pivotColumns.concat(
|
|
3708
|
+
this.pivotColumns = this.pivotColumns.concat(Array.isArray(columns) ? columns : Array.prototype.slice.call(columns));
|
|
3703
3709
|
return this;
|
|
3704
3710
|
}
|
|
3705
3711
|
async attachNew(records, current, touch = true) {
|
|
@@ -3735,9 +3741,9 @@ const InteractsWithPivotTable = (Relation) => {
|
|
|
3735
3741
|
return parseInt(updated);
|
|
3736
3742
|
}
|
|
3737
3743
|
formatRecordsList(records) {
|
|
3738
|
-
return (0,
|
|
3739
|
-
if (!
|
|
3740
|
-
return [id, attributes];
|
|
3744
|
+
return (0, _h3ravel_collect_js.collect)(records).mapWithKeys((attributes, id) => {
|
|
3745
|
+
if (!Array.isArray(attributes)) [id, attributes] = [attributes, {}];
|
|
3746
|
+
return [String(id), attributes];
|
|
3741
3747
|
}).all();
|
|
3742
3748
|
}
|
|
3743
3749
|
async getCurrentlyAttachedPivots() {
|
|
@@ -3807,7 +3813,7 @@ const InteractsWithPivotTable = (Relation) => {
|
|
|
3807
3813
|
}
|
|
3808
3814
|
formatAttachRecord(key, value, attributes, hasTimestamps) {
|
|
3809
3815
|
const [id, newAttributes] = this.extractAttachIdAndAttributes(key, value, attributes);
|
|
3810
|
-
return
|
|
3816
|
+
return _h3ravel_support.Obj.deepMerge(this.baseAttachRecord(id, hasTimestamps), newAttributes);
|
|
3811
3817
|
}
|
|
3812
3818
|
baseAttachRecord(id, timed) {
|
|
3813
3819
|
let record = {};
|
|
@@ -3820,7 +3826,7 @@ const InteractsWithPivotTable = (Relation) => {
|
|
|
3820
3826
|
return record;
|
|
3821
3827
|
}
|
|
3822
3828
|
extractAttachIdAndAttributes(key, value, newAttributes) {
|
|
3823
|
-
return
|
|
3829
|
+
return Array.isArray(value) ? [key, {
|
|
3824
3830
|
...value,
|
|
3825
3831
|
...newAttributes
|
|
3826
3832
|
}] : [value, newAttributes];
|
|
@@ -3831,7 +3837,7 @@ const InteractsWithPivotTable = (Relation) => {
|
|
|
3831
3837
|
parseIds(value) {
|
|
3832
3838
|
if (value instanceof Model) return [value[this.relatedKey]];
|
|
3833
3839
|
if (value instanceof Collection) return value.pluck(this.relatedKey).all();
|
|
3834
|
-
return
|
|
3840
|
+
return Array.isArray(value) ? value : [value];
|
|
3835
3841
|
}
|
|
3836
3842
|
};
|
|
3837
3843
|
};
|
|
@@ -3891,9 +3897,8 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
|
|
|
3891
3897
|
return this;
|
|
3892
3898
|
}
|
|
3893
3899
|
async get(columns) {
|
|
3894
|
-
var _builder$query;
|
|
3895
3900
|
const builder = this.query.applyScopes();
|
|
3896
|
-
columns =
|
|
3901
|
+
columns = builder.query?._statements?.find((item) => item.grouping == "columns") ? [] : columns;
|
|
3897
3902
|
let models = await builder.select(this.shouldSelect(columns)).getModels();
|
|
3898
3903
|
this.hydratePivotRelation(models);
|
|
3899
3904
|
if (models.length > 0) models = await builder.eagerLoadRelations(models);
|
|
@@ -3942,7 +3947,7 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
|
|
|
3942
3947
|
const value = model.attributes[key];
|
|
3943
3948
|
if (key.startsWith("pivot_")) {
|
|
3944
3949
|
values[key.substring(6)] = value;
|
|
3945
|
-
model.attributes =
|
|
3950
|
+
model.attributes = _h3ravel_support.Arr.except(model.attributes, [key]);
|
|
3946
3951
|
}
|
|
3947
3952
|
}
|
|
3948
3953
|
return values;
|
|
@@ -3953,11 +3958,11 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
|
|
|
3953
3958
|
return this.withPivot(this.createdAt(), this.updatedAt());
|
|
3954
3959
|
}
|
|
3955
3960
|
shouldSelect(columns = ["*"]) {
|
|
3956
|
-
if (
|
|
3961
|
+
if (columns.length === 1 && columns[0] === "*") columns = [this.related.getTable() + ".*"];
|
|
3957
3962
|
return columns.concat(this.aliasedPivotColumns());
|
|
3958
3963
|
}
|
|
3959
3964
|
aliasedPivotColumns() {
|
|
3960
|
-
return (0,
|
|
3965
|
+
return (0, _h3ravel_collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
|
|
3961
3966
|
return this.qualifyPivotColumn(column) + " as pivot_" + column;
|
|
3962
3967
|
}).unique().all();
|
|
3963
3968
|
}
|
|
@@ -4077,9 +4082,8 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4077
4082
|
}
|
|
4078
4083
|
asProxy() {
|
|
4079
4084
|
return new Proxy(this, { get(target, prop) {
|
|
4080
|
-
var _target$query$connect;
|
|
4081
4085
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
4082
|
-
const skipReturning = !!
|
|
4086
|
+
const skipReturning = !!target.query.connector?.client.config?.client?.includes("mysql") && prop === "returning";
|
|
4083
4087
|
if ([
|
|
4084
4088
|
"select",
|
|
4085
4089
|
"from",
|
|
@@ -4173,7 +4177,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4173
4177
|
};
|
|
4174
4178
|
}
|
|
4175
4179
|
if (prop.startsWith("where")) {
|
|
4176
|
-
const column =
|
|
4180
|
+
const column = _h3ravel_support.Str.snake(prop.substring(5));
|
|
4177
4181
|
return (...args) => {
|
|
4178
4182
|
target.query.where(column, ...args);
|
|
4179
4183
|
return target.asProxy();
|
|
@@ -4248,7 +4252,8 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4248
4252
|
}
|
|
4249
4253
|
addUpdatedAtColumn(values) {
|
|
4250
4254
|
if (!this.model.usesTimestamps() || this.model.getUpdatedAtColumn() === null) return values;
|
|
4251
|
-
|
|
4255
|
+
const column = this.model.getUpdatedAtColumn();
|
|
4256
|
+
values = _h3ravel_support.Obj.deepMerge({ [column]: this.model.freshTimestampString() }, values);
|
|
4252
4257
|
return values;
|
|
4253
4258
|
}
|
|
4254
4259
|
delete() {
|
|
@@ -4276,9 +4281,8 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4276
4281
|
return this.model;
|
|
4277
4282
|
}
|
|
4278
4283
|
setModel(model) {
|
|
4279
|
-
var _this$query;
|
|
4280
4284
|
this.model = model;
|
|
4281
|
-
if (typeof
|
|
4285
|
+
if (typeof this.query?.client?.table == "function") this.query = this.query.client.table(this.model.getTable());
|
|
4282
4286
|
else this.query = this.query.table(this.model.getTable());
|
|
4283
4287
|
return this;
|
|
4284
4288
|
}
|
|
@@ -4321,7 +4325,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4321
4325
|
}
|
|
4322
4326
|
withoutGlobalScope(scope) {
|
|
4323
4327
|
if (typeof scope !== "string") scope = scope.constructor.name;
|
|
4324
|
-
this.globalScopes =
|
|
4328
|
+
this.globalScopes = _h3ravel_support.Arr.except(this.globalScopes, [scope]);
|
|
4325
4329
|
return this;
|
|
4326
4330
|
}
|
|
4327
4331
|
macro(name, callback) {
|
|
@@ -4338,7 +4342,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4338
4342
|
let eagerLoads = {};
|
|
4339
4343
|
if (typeof args[1] === "function") {
|
|
4340
4344
|
const eagerLoad = this.parseWithRelations({ [args[0]]: args[1] });
|
|
4341
|
-
this.eagerLoad =
|
|
4345
|
+
this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, eagerLoad);
|
|
4342
4346
|
return this;
|
|
4343
4347
|
}
|
|
4344
4348
|
const relations = flattenDeep(args);
|
|
@@ -4347,13 +4351,13 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4347
4351
|
let eagerLoad;
|
|
4348
4352
|
if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
|
|
4349
4353
|
else if (typeof relation === "object") eagerLoad = relation;
|
|
4350
|
-
eagerLoads =
|
|
4354
|
+
eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
|
|
4351
4355
|
}
|
|
4352
|
-
this.eagerLoad =
|
|
4356
|
+
this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, this.parseWithRelations(eagerLoads));
|
|
4353
4357
|
return this;
|
|
4354
4358
|
}
|
|
4355
4359
|
has(relation, operator = ">=", count = 1, boolean = "and", callback = null) {
|
|
4356
|
-
if (
|
|
4360
|
+
if (typeof relation === "string") {
|
|
4357
4361
|
if (relation.includes(".")) return this.hasNested(relation, operator, count, boolean, callback);
|
|
4358
4362
|
relation = this.getRelationWithoutConstraints(getRelationMethod(relation));
|
|
4359
4363
|
}
|
|
@@ -4430,7 +4434,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4430
4434
|
let eagerLoad;
|
|
4431
4435
|
if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
|
|
4432
4436
|
else if (typeof relation === "object") eagerLoad = relation;
|
|
4433
|
-
eagerLoads =
|
|
4437
|
+
eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
|
|
4434
4438
|
}
|
|
4435
4439
|
relations = eagerLoads;
|
|
4436
4440
|
const db = this.model.getConnection();
|
|
@@ -4449,7 +4453,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4449
4453
|
} else expression = column;
|
|
4450
4454
|
const query = relation.getRelationExistenceQuery(relation.getRelated().newModelQuery(), this, db.raw(expression));
|
|
4451
4455
|
constraints(query);
|
|
4452
|
-
alias = alias ||
|
|
4456
|
+
alias = alias || _h3ravel_support.Str.snake(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
|
|
4453
4457
|
if (action === "exists") this.select(db.raw(`exists(${query.toSql().sql}) as ${alias}`));
|
|
4454
4458
|
else this.selectSub(action ? query : query.limit(1), alias);
|
|
4455
4459
|
}
|
|
@@ -4473,7 +4477,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4473
4477
|
}
|
|
4474
4478
|
parseSub(query) {
|
|
4475
4479
|
if (query instanceof Builder || query instanceof Relation) return [query.toSql().sql, query.toSql().bindings];
|
|
4476
|
-
else if (
|
|
4480
|
+
else if (typeof query === "string") return [query, []];
|
|
4477
4481
|
else throw new Error("A subquery must be a query builder instance, a Closure, or a string.");
|
|
4478
4482
|
}
|
|
4479
4483
|
prependDatabaseNameIfCrossDatabaseQuery(query) {
|
|
@@ -4530,15 +4534,15 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4530
4534
|
if (prefix !== "") prefix += ".";
|
|
4531
4535
|
for (const key in relations) {
|
|
4532
4536
|
const value = relations[key];
|
|
4533
|
-
if (
|
|
4537
|
+
if (typeof value === "string" || Number.isFinite(parseInt(value))) continue;
|
|
4534
4538
|
const [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(key, value);
|
|
4535
4539
|
preparedRelationships = Object.assign({}, preparedRelationships, { [`${prefix}${attribute}`]: attributeSelectConstraint }, this.prepareNestedWithRelationships(value, `${prefix}${attribute}`));
|
|
4536
|
-
relations =
|
|
4540
|
+
relations = _h3ravel_support.Arr.except(relations, [key]);
|
|
4537
4541
|
}
|
|
4538
4542
|
for (const key in relations) {
|
|
4539
4543
|
const value = relations[key];
|
|
4540
4544
|
let attribute = key, attributeSelectConstraint = value;
|
|
4541
|
-
if (
|
|
4545
|
+
if (typeof value === "string") [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(value);
|
|
4542
4546
|
preparedRelationships[`${prefix}${attribute}`] = this.combineConstraints([attributeSelectConstraint, preparedRelationships[`${prefix}${attribute}`] || (() => {})]);
|
|
4543
4547
|
}
|
|
4544
4548
|
return preparedRelationships;
|
|
@@ -4586,8 +4590,8 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4586
4590
|
}
|
|
4587
4591
|
async findOrFail(...args) {
|
|
4588
4592
|
const data = await this.find(...args);
|
|
4589
|
-
if (
|
|
4590
|
-
if (data.count() !== args[0].length) throw new ModelNotFoundError().setModel(this.model.constructor.name, (0,
|
|
4593
|
+
if (Array.isArray(args[0])) {
|
|
4594
|
+
if (data.count() !== args[0].length) throw new ModelNotFoundError().setModel(this.model.constructor.name, (0, _h3ravel_collect_js.collect)(args[0]).diff(data.modelKeys()).all());
|
|
4591
4595
|
return data;
|
|
4592
4596
|
}
|
|
4593
4597
|
if (data === null) throw new ModelNotFoundError().setModel(this.model.constructor.name, args[0]);
|
|
@@ -4601,12 +4605,12 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4601
4605
|
async firstOrNew(attributes = {}, values = {}) {
|
|
4602
4606
|
const instance = await this.where(attributes).first();
|
|
4603
4607
|
if (instance !== null) return instance;
|
|
4604
|
-
return this.newModelInstance(
|
|
4608
|
+
return this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values));
|
|
4605
4609
|
}
|
|
4606
4610
|
async firstOrCreate(attributes = {}, values = {}) {
|
|
4607
4611
|
const instance = await this.where(attributes).first();
|
|
4608
4612
|
if (instance !== null) return instance;
|
|
4609
|
-
return tap(this.newModelInstance(
|
|
4613
|
+
return tap(this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values)), async (instance) => {
|
|
4610
4614
|
await instance.save({ client: this.query });
|
|
4611
4615
|
});
|
|
4612
4616
|
}
|
|
@@ -4626,22 +4630,21 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4626
4630
|
return this;
|
|
4627
4631
|
}
|
|
4628
4632
|
async find(id, columns) {
|
|
4629
|
-
if (
|
|
4633
|
+
if (Array.isArray(id) || id instanceof Collection) return await this.findMany(id, columns);
|
|
4630
4634
|
return await this.where(this.model.getKeyName(), id).first(columns);
|
|
4631
4635
|
}
|
|
4632
4636
|
async findMany(ids, columns = ["*"]) {
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
return await this.whereIn(this.model.getKeyName(), ids).get(columns);
|
|
4637
|
+
const values = ids instanceof Collection ? ids.modelKeys() : Array.isArray(ids) ? ids : [ids];
|
|
4638
|
+
if (values.length === 0) return new Collection([]);
|
|
4639
|
+
return await this.whereIn(this.model.getKeyName(), values).get(columns);
|
|
4637
4640
|
}
|
|
4638
4641
|
async pluck(column) {
|
|
4639
4642
|
return new Collection(await this.query.pluck(column));
|
|
4640
4643
|
}
|
|
4641
4644
|
async destroy(ids) {
|
|
4642
4645
|
if (ids instanceof Collection) ids = ids.modelKeys();
|
|
4643
|
-
if (ids instanceof
|
|
4644
|
-
ids =
|
|
4646
|
+
if (ids instanceof _h3ravel_collect_js.Collection) ids = ids.all();
|
|
4647
|
+
ids = Array.isArray(ids) ? ids : Array.prototype.slice.call(ids);
|
|
4645
4648
|
if (ids.length === 0) return 0;
|
|
4646
4649
|
const key = this.model.newInstance().getKeyName();
|
|
4647
4650
|
let count = 0;
|
|
@@ -4659,12 +4662,11 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4659
4662
|
return await this.model.newModelQuery().get(columns);
|
|
4660
4663
|
}
|
|
4661
4664
|
async paginate(page = 1, perPage = 10) {
|
|
4662
|
-
var _this;
|
|
4663
4665
|
page = page || 1;
|
|
4664
|
-
perPage = perPage ||
|
|
4666
|
+
perPage = perPage || this?.model?.perPage || 15;
|
|
4665
4667
|
this.applyScopes();
|
|
4666
4668
|
const total = await this.query.clone().clearOrder().clearSelect().count(this.primaryKey);
|
|
4667
|
-
let results
|
|
4669
|
+
let results;
|
|
4668
4670
|
if (total > 0) {
|
|
4669
4671
|
const skip = (page - 1) * (perPage ?? 10);
|
|
4670
4672
|
this.take(perPage).skip(skip);
|
|
@@ -4674,7 +4676,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
4674
4676
|
return new Paginator(results, parseInt(total), perPage, page);
|
|
4675
4677
|
}
|
|
4676
4678
|
async getModels(...columns) {
|
|
4677
|
-
columns = (
|
|
4679
|
+
columns = flatten(columns);
|
|
4678
4680
|
if (columns.length > 0) {
|
|
4679
4681
|
if (this.query._statements.filter((item) => item.grouping == "columns").length == 0 && columns[0] !== "*") this.query.select(...columns);
|
|
4680
4682
|
}
|
|
@@ -4778,7 +4780,7 @@ var SQLite = class {
|
|
|
4778
4780
|
column: column.name
|
|
4779
4781
|
}));
|
|
4780
4782
|
const tables = await this.tables();
|
|
4781
|
-
return flatten
|
|
4783
|
+
return flatten(await Promise.all(tables.map(async (table) => await this.columns(table))));
|
|
4782
4784
|
}
|
|
4783
4785
|
async columnInfo(table, column) {
|
|
4784
4786
|
const getColumnsForTable = async (table) => {
|
|
@@ -4804,17 +4806,17 @@ var SQLite = class {
|
|
|
4804
4806
|
is_generated: raw.hidden !== 0,
|
|
4805
4807
|
generation_expression: null,
|
|
4806
4808
|
is_nullable: raw.notnull === 0,
|
|
4807
|
-
is_unique: !!
|
|
4809
|
+
is_unique: !!index?.unique && indexInfo?.length === 1,
|
|
4808
4810
|
is_primary_key: raw.pk === 1,
|
|
4809
4811
|
has_auto_increment: raw.pk === 1 && tablesWithAutoIncrementPrimaryKeys.includes(table),
|
|
4810
|
-
foreign_key_column:
|
|
4811
|
-
foreign_key_table:
|
|
4812
|
+
foreign_key_column: foreignKey?.to || null,
|
|
4813
|
+
foreign_key_table: foreignKey?.table || null
|
|
4812
4814
|
};
|
|
4813
4815
|
});
|
|
4814
4816
|
};
|
|
4815
4817
|
if (!table) {
|
|
4816
4818
|
const tables = await this.tables();
|
|
4817
|
-
return flatten
|
|
4819
|
+
return flatten(await Promise.all(tables.map(async (table) => await getColumnsForTable(table))));
|
|
4818
4820
|
}
|
|
4819
4821
|
if (table && !column) return await getColumnsForTable(table);
|
|
4820
4822
|
return (await getColumnsForTable(table)).find((columnInfo) => columnInfo.name === column);
|
|
@@ -4845,7 +4847,7 @@ var SQLite = class {
|
|
|
4845
4847
|
constraint_name: null
|
|
4846
4848
|
}));
|
|
4847
4849
|
const tables = await this.tables();
|
|
4848
|
-
return flatten
|
|
4850
|
+
return flatten(await Promise.all(tables.map(async (table) => await this.foreignKeys(table))));
|
|
4849
4851
|
}
|
|
4850
4852
|
async uniqueConstraints(table) {
|
|
4851
4853
|
if (table) {
|
|
@@ -4861,7 +4863,7 @@ var SQLite = class {
|
|
|
4861
4863
|
});
|
|
4862
4864
|
}
|
|
4863
4865
|
const tables = await this.tables();
|
|
4864
|
-
return flatten
|
|
4866
|
+
return flatten(await Promise.all(tables.map(async (table) => await this.uniqueConstraints(table))));
|
|
4865
4867
|
}
|
|
4866
4868
|
};
|
|
4867
4869
|
//#endregion
|
|
@@ -5034,8 +5036,7 @@ var Migrator = class {
|
|
|
5034
5036
|
else await callback(connection);
|
|
5035
5037
|
}
|
|
5036
5038
|
async runMethod(connection, migration, method) {
|
|
5037
|
-
|
|
5038
|
-
await ((_migration$method = migration[method]) === null || _migration$method === void 0 ? void 0 : _migration$method.call(migration, connection.schema, connection));
|
|
5039
|
+
await migration[method]?.(connection.schema, connection);
|
|
5039
5040
|
}
|
|
5040
5041
|
async resolvePath(filePath) {
|
|
5041
5042
|
try {
|
|
@@ -5064,7 +5065,7 @@ var Migrator = class {
|
|
|
5064
5065
|
return path.default.basename(filePath).replace(".js", "");
|
|
5065
5066
|
}
|
|
5066
5067
|
path(p) {
|
|
5067
|
-
this.paths = Array.from(new Set([...this.paths, p]));
|
|
5068
|
+
this.paths = Array.from(/* @__PURE__ */ new Set([...this.paths, p]));
|
|
5068
5069
|
}
|
|
5069
5070
|
getPaths() {
|
|
5070
5071
|
return this.paths;
|
|
@@ -5252,8 +5253,7 @@ var Migrate = class {
|
|
|
5252
5253
|
* @returns
|
|
5253
5254
|
*/
|
|
5254
5255
|
async setupConnection(config) {
|
|
5255
|
-
|
|
5256
|
-
const table = (config === null || config === void 0 || (_config$migrations = config.migrations) === null || _config$migrations === void 0 ? void 0 : _config$migrations.table) || "migrations";
|
|
5256
|
+
const table = config?.migrations?.table || "migrations";
|
|
5257
5257
|
if (config.skipConnection !== true) {
|
|
5258
5258
|
arquebus.addConnection(config, "default");
|
|
5259
5259
|
Object.entries(config.connections || {}).forEach(([name, connection]) => {
|
|
@@ -5313,7 +5313,6 @@ var MigrationCreator = class {
|
|
|
5313
5313
|
let stub;
|
|
5314
5314
|
if (!table) {
|
|
5315
5315
|
const customPath = path.default.join(this.customStubPath ?? "", `migration-${this.type}.stub`);
|
|
5316
|
-
console.log("\n", customPath, "---");
|
|
5317
5316
|
stub = await _h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration-${this.type}.stub`);
|
|
5318
5317
|
} else if (create) {
|
|
5319
5318
|
const customPath = path.default.join(this.customStubPath ?? "", `migration.create-${this.type}.stub`);
|
|
@@ -5332,7 +5331,7 @@ var MigrationCreator = class {
|
|
|
5332
5331
|
return name.replace(/_+([a-z])/g, (match, char) => char.toUpperCase());
|
|
5333
5332
|
}
|
|
5334
5333
|
getPath(name, dir) {
|
|
5335
|
-
const datePrefix =
|
|
5334
|
+
const datePrefix = dayjs$1().format("YYYY_MM_DD_HHmmss");
|
|
5336
5335
|
return path.default.join(dir, `${datePrefix}_${name}.${this.type}`);
|
|
5337
5336
|
}
|
|
5338
5337
|
async firePostCreateHooks(table, filePath) {
|
|
@@ -5346,7 +5345,9 @@ var MigrationCreator = class {
|
|
|
5346
5345
|
}
|
|
5347
5346
|
stubPath(stub = "") {
|
|
5348
5347
|
const __dirname = this.getDirname({});
|
|
5349
|
-
|
|
5348
|
+
const resolved = [path.default.join(__dirname, "stubs", stub), path.default.join(__dirname, "../stubs", stub)].find((candidate) => (0, node_fs.existsSync)(candidate));
|
|
5349
|
+
if (!resolved) throw new Error(`Migration stub not found: ${stub}`);
|
|
5350
|
+
return resolved;
|
|
5350
5351
|
}
|
|
5351
5352
|
getDirname(meta) {
|
|
5352
5353
|
if (typeof __dirname !== "undefined") return __dirname;
|