@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
package/dist/index.cjs
CHANGED
|
@@ -35,14 +35,14 @@ node_fs_promises = __toESM(node_fs_promises, 1);
|
|
|
35
35
|
let path = require("path");
|
|
36
36
|
path = __toESM(path, 1);
|
|
37
37
|
let node_path = require("node:path");
|
|
38
|
+
let node_fs = require("node:fs");
|
|
38
39
|
let node_url = require("node:url");
|
|
39
|
-
let
|
|
40
|
-
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
41
|
-
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
|
|
40
|
+
let _h3ravel_support = require("@h3ravel/support");
|
|
42
41
|
let dayjs = require("dayjs");
|
|
43
42
|
dayjs = __toESM(dayjs, 1);
|
|
44
|
-
let
|
|
45
|
-
|
|
43
|
+
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
44
|
+
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
|
|
45
|
+
let _h3ravel_collect_js = require("@h3ravel/collect.js");
|
|
46
46
|
let knex = require("knex");
|
|
47
47
|
knex = __toESM(knex, 1);
|
|
48
48
|
let fs = require("fs");
|
|
@@ -78,16 +78,14 @@ var SeederRunner = class {
|
|
|
78
78
|
this.resolver = resolver;
|
|
79
79
|
}
|
|
80
80
|
path(p) {
|
|
81
|
-
this.paths = Array.from(new Set([...this.paths, p]));
|
|
81
|
+
this.paths = Array.from(/* @__PURE__ */ new Set([...this.paths, p]));
|
|
82
82
|
}
|
|
83
83
|
getPaths() {
|
|
84
84
|
return this.paths;
|
|
85
85
|
}
|
|
86
86
|
resolveConnection(connection) {
|
|
87
|
-
var _getInstance, _ref, _instance$connections;
|
|
88
87
|
const name = connection || this.connection || "default";
|
|
89
|
-
|
|
90
|
-
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
88
|
+
if (!!!(this.resolver.getInstance?.() ?? null)?.connections?.[name]) this.resolver.autoLoad().catch(() => {
|
|
91
89
|
/** noop */
|
|
92
90
|
});
|
|
93
91
|
return this.resolver.fire(name);
|
|
@@ -142,7 +140,10 @@ var SeederCreator = class {
|
|
|
142
140
|
getStubPath(type) {
|
|
143
141
|
if (this.customStubPath) return path.default.join(this.customStubPath, `seeder-${type}.stub`);
|
|
144
142
|
const __dirname = this.getDirname({});
|
|
145
|
-
|
|
143
|
+
const name = `seeder-${type}.stub`;
|
|
144
|
+
const resolved = [path.default.join(__dirname, "stubs", name), path.default.join(__dirname, "../stubs", name)].find((candidate) => (0, node_fs.existsSync)(candidate));
|
|
145
|
+
if (!resolved) throw new Error(`Seeder stub not found: ${name}`);
|
|
146
|
+
return resolved;
|
|
146
147
|
}
|
|
147
148
|
getDirname(meta) {
|
|
148
149
|
if (typeof __dirname !== "undefined") return __dirname;
|
|
@@ -200,7 +201,7 @@ var ModelNotFoundError = class extends BaseError {
|
|
|
200
201
|
}
|
|
201
202
|
setModel(model, ids = []) {
|
|
202
203
|
this.model = model;
|
|
203
|
-
this.ids =
|
|
204
|
+
this.ids = Array.isArray(ids) ? ids : [ids];
|
|
204
205
|
this.message = `No query results for model [${model}]`;
|
|
205
206
|
if (this.ids.length > 0) this.message += " " + this.ids.join(", ");
|
|
206
207
|
else this.message += ".";
|
|
@@ -291,29 +292,33 @@ function compose$1(Base, ...mixins) {
|
|
|
291
292
|
}, Base);
|
|
292
293
|
}
|
|
293
294
|
//#endregion
|
|
295
|
+
//#region src/dayjs.ts
|
|
296
|
+
const dayjs$1 = dayjs.default ?? dayjs;
|
|
297
|
+
const advancedFormat = dayjs_plugin_advancedFormat_js.default ?? dayjs_plugin_advancedFormat_js;
|
|
298
|
+
dayjs$1.extend(advancedFormat);
|
|
299
|
+
//#endregion
|
|
294
300
|
//#region src/utils.ts
|
|
295
|
-
dayjs.
|
|
296
|
-
const now = (format = "YYYY-MM-DD HH:mm:ss") => (0, dayjs.default)().format(format);
|
|
301
|
+
const now = (format = "YYYY-MM-DD HH:mm:ss") => dayjs$1().format(format);
|
|
297
302
|
const getRelationName = (relationMethod) => {
|
|
298
|
-
return
|
|
303
|
+
return _h3ravel_support.Str.snake(relationMethod.substring(8));
|
|
299
304
|
};
|
|
300
305
|
const getScopeName = (scopeMethod) => {
|
|
301
|
-
return
|
|
306
|
+
return _h3ravel_support.Str.snake(scopeMethod.substring(5));
|
|
302
307
|
};
|
|
303
308
|
const getRelationMethod = (relation) => {
|
|
304
|
-
return
|
|
309
|
+
return _h3ravel_support.Str.camel(`relation_${relation}`);
|
|
305
310
|
};
|
|
306
311
|
const getScopeMethod = (scope) => {
|
|
307
|
-
return
|
|
312
|
+
return _h3ravel_support.Str.camel(`scope_${scope}`);
|
|
308
313
|
};
|
|
309
314
|
const getAttrMethod = (attr) => {
|
|
310
|
-
return
|
|
315
|
+
return _h3ravel_support.Str.camel(`attribute_${attr}`);
|
|
311
316
|
};
|
|
312
317
|
const getGetterMethod = (attr) => {
|
|
313
|
-
return
|
|
318
|
+
return _h3ravel_support.Str.camel(`get_${attr}_attribute`);
|
|
314
319
|
};
|
|
315
320
|
const getSetterMethod = (attr) => {
|
|
316
|
-
return
|
|
321
|
+
return _h3ravel_support.Str.camel(`set_${attr}_attribute`);
|
|
317
322
|
};
|
|
318
323
|
const getAttrName = (attrMethod) => {
|
|
319
324
|
return attrMethod.substring(3, attrMethod.length - 9).toLowerCase();
|
|
@@ -332,8 +337,8 @@ const tap = (instance, callback) => {
|
|
|
332
337
|
const { compose } = mixin_exports;
|
|
333
338
|
const flatten = (arr) => arr.flat();
|
|
334
339
|
const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
|
|
335
|
-
const kebabCase = (str) =>
|
|
336
|
-
const snakeCase = (str) =>
|
|
340
|
+
const kebabCase = (str) => _h3ravel_support.Str.trim(_h3ravel_support.Str.kebab(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/-+/g, "-");
|
|
341
|
+
const snakeCase = (str) => _h3ravel_support.Str.trim(_h3ravel_support.Str.snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/_+/g, "_");
|
|
337
342
|
const defineConfig = (config) => {
|
|
338
343
|
return config;
|
|
339
344
|
};
|
|
@@ -423,8 +428,7 @@ var Relation$1 = class {
|
|
|
423
428
|
return this.parent.getQualifiedKeyName();
|
|
424
429
|
}
|
|
425
430
|
getExistenceCompareKey() {
|
|
426
|
-
|
|
427
|
-
return (_this$getQualifiedFor = this.getQualifiedForeignKeyName) === null || _this$getQualifiedFor === void 0 ? void 0 : _this$getQualifiedFor.call(this);
|
|
431
|
+
return this.getQualifiedForeignKeyName?.();
|
|
428
432
|
}
|
|
429
433
|
};
|
|
430
434
|
//#endregion
|
|
@@ -565,8 +569,7 @@ const HasAttributes = (Model) => {
|
|
|
565
569
|
return this;
|
|
566
570
|
}
|
|
567
571
|
normalizeCastClassResponse(key, value) {
|
|
568
|
-
|
|
569
|
-
return (value === null || value === void 0 || (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) === "Object" ? value : { [key]: value };
|
|
572
|
+
return value?.constructor?.name === "Object" ? value : { [key]: value };
|
|
570
573
|
}
|
|
571
574
|
syncOriginal() {
|
|
572
575
|
this.original = this.getAttributes();
|
|
@@ -676,9 +679,9 @@ const HasAttributes = (Model) => {
|
|
|
676
679
|
return null;
|
|
677
680
|
}
|
|
678
681
|
case "collection": try {
|
|
679
|
-
return (0,
|
|
682
|
+
return (0, _h3ravel_collect_js.collect)(JSON.parse(value));
|
|
680
683
|
} catch {
|
|
681
|
-
return (0,
|
|
684
|
+
return (0, _h3ravel_collect_js.collect)([]);
|
|
682
685
|
}
|
|
683
686
|
case "date": return this.asDate(value);
|
|
684
687
|
case "datetime":
|
|
@@ -691,8 +694,8 @@ const HasAttributes = (Model) => {
|
|
|
691
694
|
attributesToData() {
|
|
692
695
|
let attributes = { ...this.attributes };
|
|
693
696
|
for (const key in attributes) {
|
|
694
|
-
if (this.hidden.includes(key)) attributes =
|
|
695
|
-
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes =
|
|
697
|
+
if (this.hidden.includes(key)) attributes = _h3ravel_support.Arr.except(attributes, [key]);
|
|
698
|
+
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = _h3ravel_support.Arr.except(attributes, [key]);
|
|
696
699
|
}
|
|
697
700
|
for (const key of this.getDates()) {
|
|
698
701
|
if (attributes[key] === void 0) continue;
|
|
@@ -704,7 +707,7 @@ const HasAttributes = (Model) => {
|
|
|
704
707
|
if (key in attributes === false) continue;
|
|
705
708
|
attributes[key] = this.castAttribute(key, attributes[key]);
|
|
706
709
|
if (key in attributes && ["date", "datetime"].includes(String(value))) attributes[key] = this.serializeDate(attributes[key]);
|
|
707
|
-
if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] =
|
|
710
|
+
if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = dayjs$1(attributes[key]).format(String(value).split(":")[1]);
|
|
708
711
|
}
|
|
709
712
|
for (const key of this.appends) attributes[key] = this.mutateAttribute(key, null);
|
|
710
713
|
return attributes;
|
|
@@ -720,7 +723,7 @@ const HasAttributes = (Model) => {
|
|
|
720
723
|
return this.getDates().includes(key) || this.isDateCastable(key);
|
|
721
724
|
}
|
|
722
725
|
serializeDate(date) {
|
|
723
|
-
return date ?
|
|
726
|
+
return date ? dayjs$1(date).toISOString() : null;
|
|
724
727
|
}
|
|
725
728
|
getDates() {
|
|
726
729
|
return this.usesTimestamps() ? [this.getCreatedAtColumn(), this.getUpdatedAtColumn()] : [];
|
|
@@ -747,13 +750,13 @@ const HasAttributes = (Model) => {
|
|
|
747
750
|
}
|
|
748
751
|
hasCast(key, types = []) {
|
|
749
752
|
if (key in this.casts) {
|
|
750
|
-
types = (
|
|
753
|
+
types = flatten(types);
|
|
751
754
|
return types.length > 0 ? types.includes(this.getCastType(key)) : true;
|
|
752
755
|
}
|
|
753
756
|
return false;
|
|
754
757
|
}
|
|
755
758
|
withDayjs(date) {
|
|
756
|
-
return
|
|
759
|
+
return dayjs$1(date);
|
|
757
760
|
}
|
|
758
761
|
isCustomCast(cast) {
|
|
759
762
|
return typeof cast === "function" && new cast() instanceof CastsAttributes;
|
|
@@ -770,7 +773,7 @@ const HasAttributes = (Model) => {
|
|
|
770
773
|
return this.hasCast(key, ["date", "datetime"]);
|
|
771
774
|
}
|
|
772
775
|
fromDateTime(value) {
|
|
773
|
-
return
|
|
776
|
+
return dayjs$1(this.asDateTime(value)).format(this.getDateFormat());
|
|
774
777
|
}
|
|
775
778
|
getDateFormat() {
|
|
776
779
|
return this.dateFormat || "YYYY-MM-DD HH:mm:ss";
|
|
@@ -785,7 +788,7 @@ const HasAttributes = (Model) => {
|
|
|
785
788
|
return new Date(value);
|
|
786
789
|
}
|
|
787
790
|
asDate(value) {
|
|
788
|
-
return
|
|
791
|
+
return dayjs$1(this.asDateTime(value)).startOf("day").toDate();
|
|
789
792
|
}
|
|
790
793
|
};
|
|
791
794
|
};
|
|
@@ -806,10 +809,14 @@ const HasGlobalScopes = (Model) => {
|
|
|
806
809
|
static globalScopes;
|
|
807
810
|
static addGlobalScope(scope, implementation = null) {
|
|
808
811
|
if (typeof scope === "string" && implementation instanceof Scope) {
|
|
809
|
-
|
|
812
|
+
const scopes = this.globalScopes ?? {};
|
|
813
|
+
(0, _h3ravel_support.data_set)(scopes, this.name + "." + scope, implementation);
|
|
814
|
+
this.globalScopes = scopes;
|
|
810
815
|
return implementation;
|
|
811
816
|
} else if (scope instanceof Scope) {
|
|
812
|
-
|
|
817
|
+
const scopes = this.globalScopes ?? {};
|
|
818
|
+
(0, _h3ravel_support.data_set)(scopes, this.name + "." + scope.constructor.name, scope);
|
|
819
|
+
this.globalScopes = scopes;
|
|
813
820
|
return scope;
|
|
814
821
|
}
|
|
815
822
|
throw new InvalidArgumentError("Global scope must be an instance of Scope.");
|
|
@@ -818,8 +825,8 @@ const HasGlobalScopes = (Model) => {
|
|
|
818
825
|
return this.getGlobalScope(scope) !== null;
|
|
819
826
|
}
|
|
820
827
|
static getGlobalScope(scope) {
|
|
821
|
-
if (typeof scope === "string") return (0,
|
|
822
|
-
return (0,
|
|
828
|
+
if (typeof scope === "string") return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope);
|
|
829
|
+
return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope.constructor.name);
|
|
823
830
|
}
|
|
824
831
|
static getAllGlobalScopes() {
|
|
825
832
|
return this.globalScopes;
|
|
@@ -828,7 +835,7 @@ const HasGlobalScopes = (Model) => {
|
|
|
828
835
|
this.globalScopes = scopes;
|
|
829
836
|
}
|
|
830
837
|
getGlobalScopes() {
|
|
831
|
-
return (0,
|
|
838
|
+
return (0, _h3ravel_support.data_get)(this.constructor.globalScopes ?? {}, this.constructor.name, {});
|
|
832
839
|
}
|
|
833
840
|
};
|
|
834
841
|
};
|
|
@@ -928,7 +935,7 @@ const HasOneOrMany$1 = (Relation) => {
|
|
|
928
935
|
}
|
|
929
936
|
buildDictionary(results) {
|
|
930
937
|
const foreign = this.getForeignKeyName();
|
|
931
|
-
return (0,
|
|
938
|
+
return (0, _h3ravel_collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
|
|
932
939
|
}
|
|
933
940
|
async save(model) {
|
|
934
941
|
this.setForeignAttributesForCreate(model);
|
|
@@ -999,13 +1006,11 @@ var HasMany$1 = class extends compose(Relation$1, HasOneOrMany$1) {
|
|
|
999
1006
|
return this.getParentKey() !== null ? await this.query.get() : new Collection([]);
|
|
1000
1007
|
}
|
|
1001
1008
|
getForeignKeyName() {
|
|
1002
|
-
|
|
1003
|
-
const segments = (_this$foreignKey = this.foreignKey) === null || _this$foreignKey === void 0 ? void 0 : _this$foreignKey.split(".");
|
|
1004
|
-
return segments === null || segments === void 0 ? void 0 : segments.pop();
|
|
1009
|
+
return (this.foreignKey?.split("."))?.pop();
|
|
1005
1010
|
}
|
|
1006
1011
|
buildDictionary(results) {
|
|
1007
1012
|
const foreign = this.getForeignKeyName();
|
|
1008
|
-
return (0,
|
|
1013
|
+
return (0, _h3ravel_collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
|
|
1009
1014
|
}
|
|
1010
1015
|
match(models, results, relation) {
|
|
1011
1016
|
return this.matchOneOrMany(models, results, relation, "many");
|
|
@@ -1036,9 +1041,7 @@ var HasOne$1 = class extends compose(Relation$1, HasOneOrMany$1, SupportsDefault
|
|
|
1036
1041
|
return this.matchOneOrMany(models, results, relation, "one");
|
|
1037
1042
|
}
|
|
1038
1043
|
getForeignKeyName() {
|
|
1039
|
-
|
|
1040
|
-
const segments = (_this$foreignKey = this.foreignKey) === null || _this$foreignKey === void 0 ? void 0 : _this$foreignKey.split(".");
|
|
1041
|
-
return segments === null || segments === void 0 ? void 0 : segments.pop();
|
|
1044
|
+
return (this.foreignKey?.split("."))?.pop();
|
|
1042
1045
|
}
|
|
1043
1046
|
async getResults() {
|
|
1044
1047
|
if (this.getParentKey() === null) return this.getDefaultFor(this.parent);
|
|
@@ -1147,10 +1150,10 @@ var HasManyThrough$1 = class extends Relation$1 {
|
|
|
1147
1150
|
}
|
|
1148
1151
|
const model = await this.first(columns);
|
|
1149
1152
|
if (model) return model;
|
|
1150
|
-
return callback
|
|
1153
|
+
return callback?.();
|
|
1151
1154
|
}
|
|
1152
1155
|
async find(id, columns = ["*"]) {
|
|
1153
|
-
if (
|
|
1156
|
+
if (Array.isArray(id)) return await this.findMany(id, columns);
|
|
1154
1157
|
return await this.where(this.getRelated().getQualifiedKeyName(), "=", id).first(columns);
|
|
1155
1158
|
}
|
|
1156
1159
|
async findMany(ids, columns = ["*"]) {
|
|
@@ -1178,7 +1181,7 @@ var HasManyThrough$1 = class extends Relation$1 {
|
|
|
1178
1181
|
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
1179
1182
|
}
|
|
1180
1183
|
shouldSelect(columns = ["*"]) {
|
|
1181
|
-
if (
|
|
1184
|
+
if (columns?.at(0) == "*") columns = [this.related.getTable() + ".*"];
|
|
1182
1185
|
return [...columns, this.getQualifiedFirstKeyName() + " as laravel_through_key"];
|
|
1183
1186
|
}
|
|
1184
1187
|
async chunk(count, callback) {
|
|
@@ -1272,7 +1275,7 @@ const HasRelations = (Model) => {
|
|
|
1272
1275
|
return this;
|
|
1273
1276
|
}
|
|
1274
1277
|
unsetRelation(relation) {
|
|
1275
|
-
this.relations =
|
|
1278
|
+
this.relations = _h3ravel_support.Arr.except(this.relations, [relation]);
|
|
1276
1279
|
return this;
|
|
1277
1280
|
}
|
|
1278
1281
|
relationLoaded(relation) {
|
|
@@ -1295,8 +1298,7 @@ const HasRelations = (Model) => {
|
|
|
1295
1298
|
return data;
|
|
1296
1299
|
}
|
|
1297
1300
|
guessBelongsToRelation() {
|
|
1298
|
-
|
|
1299
|
-
const functionName = (((_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2]) ?? "").split(" ")[5];
|
|
1301
|
+
const functionName = ((/* @__PURE__ */ new Error()).stack?.split("\n")[2] ?? "").split(" ")[5];
|
|
1300
1302
|
return getRelationName(functionName);
|
|
1301
1303
|
}
|
|
1302
1304
|
joiningTable(related, instance = null) {
|
|
@@ -1406,7 +1408,7 @@ const HidesAttributes = (Model) => {
|
|
|
1406
1408
|
makeVisible(...keys) {
|
|
1407
1409
|
const visible = flattenDeep(keys);
|
|
1408
1410
|
if (this.visible.length > 0) this.visible = [...this.visible, ...visible];
|
|
1409
|
-
this.hidden = (0,
|
|
1411
|
+
this.hidden = (0, _h3ravel_collect_js.collect)(this.hidden).diff(visible).all();
|
|
1410
1412
|
return this;
|
|
1411
1413
|
}
|
|
1412
1414
|
makeHidden(key, ...keys) {
|
|
@@ -1550,10 +1552,9 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1550
1552
|
asProxy() {
|
|
1551
1553
|
return new Proxy(this, {
|
|
1552
1554
|
get: function(target, prop) {
|
|
1553
|
-
var _target$connector$cli;
|
|
1554
1555
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
1555
1556
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
1556
|
-
const skipReturning = !!
|
|
1557
|
+
const skipReturning = !!target.connector.client.config?.client?.includes("mysql") && prop === "returning";
|
|
1557
1558
|
if ([
|
|
1558
1559
|
"select",
|
|
1559
1560
|
"from",
|
|
@@ -1756,6 +1757,9 @@ var arquebus = class arquebus {
|
|
|
1756
1757
|
if (this.instance === null) this.instance = new arquebus();
|
|
1757
1758
|
return this.instance;
|
|
1758
1759
|
}
|
|
1760
|
+
static withSchema() {
|
|
1761
|
+
return this;
|
|
1762
|
+
}
|
|
1759
1763
|
/**
|
|
1760
1764
|
* Initialize a new database connection
|
|
1761
1765
|
*
|
|
@@ -1845,12 +1849,12 @@ var arquebus = class arquebus {
|
|
|
1845
1849
|
const tsPath = path.default.resolve("arquebus.config.ts");
|
|
1846
1850
|
const instance = this.getInstance();
|
|
1847
1851
|
if ((0, fs.existsSync)(jsPath)) {
|
|
1848
|
-
config = (await
|
|
1852
|
+
config = (await (0, _h3ravel_shared.importFile)(jsPath)).default;
|
|
1849
1853
|
if (addConnection) instance.addConnection(config, config.client);
|
|
1850
1854
|
return config;
|
|
1851
1855
|
}
|
|
1852
1856
|
if ((0, fs.existsSync)(tsPath)) if (process.env.NODE_ENV !== "production") {
|
|
1853
|
-
config = (await
|
|
1857
|
+
config = (await (0, _h3ravel_shared.importFile)(tsPath)).default;
|
|
1854
1858
|
if (addConnection) instance.addConnection(config, config.client);
|
|
1855
1859
|
return config;
|
|
1856
1860
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
@@ -1866,7 +1870,7 @@ var arquebus = class arquebus {
|
|
|
1866
1870
|
"cjs"
|
|
1867
1871
|
], dir);
|
|
1868
1872
|
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
1869
|
-
config = (await
|
|
1873
|
+
config = (await (0, _h3ravel_shared.importFile)(found)).default;
|
|
1870
1874
|
if (addConnection) instance.addConnection(config, config.client);
|
|
1871
1875
|
return config;
|
|
1872
1876
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
@@ -1887,7 +1891,7 @@ var arquebus = class arquebus {
|
|
|
1887
1891
|
}
|
|
1888
1892
|
async destroyAll() {
|
|
1889
1893
|
await Promise.all(Object.values(this.manager).map((connection) => {
|
|
1890
|
-
return connection
|
|
1894
|
+
return connection?.destroy();
|
|
1891
1895
|
}));
|
|
1892
1896
|
}
|
|
1893
1897
|
createModel(name, options = {}) {
|
|
@@ -1896,29 +1900,25 @@ var arquebus = class arquebus {
|
|
|
1896
1900
|
this.models = {
|
|
1897
1901
|
...this.models,
|
|
1898
1902
|
[name]: class extends BaseModel {
|
|
1899
|
-
table =
|
|
1900
|
-
connection =
|
|
1901
|
-
timestamps =
|
|
1902
|
-
primaryKey =
|
|
1903
|
-
keyType =
|
|
1904
|
-
incrementing =
|
|
1905
|
-
with =
|
|
1906
|
-
casts =
|
|
1907
|
-
static CREATED_AT =
|
|
1908
|
-
static UPDATED_AT =
|
|
1909
|
-
static DELETED_AT =
|
|
1903
|
+
table = options?.table ?? null;
|
|
1904
|
+
connection = options?.connection ?? null;
|
|
1905
|
+
timestamps = options?.timestamps ?? true;
|
|
1906
|
+
primaryKey = options?.primaryKey ?? "id";
|
|
1907
|
+
keyType = options?.keyType ?? "int";
|
|
1908
|
+
incrementing = options?.incrementing ?? true;
|
|
1909
|
+
with = options?.with ?? [];
|
|
1910
|
+
casts = options?.casts ?? {};
|
|
1911
|
+
static CREATED_AT = options?.CREATED_AT ?? "created_at";
|
|
1912
|
+
static UPDATED_AT = options?.UPDATED_AT ?? "updated_at";
|
|
1913
|
+
static DELETED_AT = options?.DELETED_AT ?? "deleted_at";
|
|
1910
1914
|
}
|
|
1911
1915
|
};
|
|
1912
1916
|
if ("attributes" in options) for (const attribute in options.attributes) {
|
|
1913
1917
|
if (options.attributes[attribute] instanceof Attribute === false) throw new Error("Attribute must be an instance of \"Attribute\"");
|
|
1914
|
-
this.models[name].prototype[getAttrMethod(attribute)] = () =>
|
|
1915
|
-
var _options$attributes;
|
|
1916
|
-
return (_options$attributes = options.attributes) === null || _options$attributes === void 0 ? void 0 : _options$attributes[attribute];
|
|
1917
|
-
};
|
|
1918
|
+
this.models[name].prototype[getAttrMethod(attribute)] = () => options.attributes?.[attribute];
|
|
1918
1919
|
}
|
|
1919
1920
|
if ("relations" in options) for (const relation in options.relations) this.models[name].prototype[getRelationMethod(relation)] = function() {
|
|
1920
|
-
|
|
1921
|
-
return (_options$relations = options.relations) === null || _options$relations === void 0 ? void 0 : _options$relations[relation](this);
|
|
1921
|
+
return options.relations?.[relation](this);
|
|
1922
1922
|
};
|
|
1923
1923
|
if ("scopes" in options) for (const scope in options.scopes) this.models[name].prototype[getScopeMethod(scope)] = options.scopes[scope];
|
|
1924
1924
|
this.models[name].setConnectionResolver(this);
|
|
@@ -1956,6 +1956,9 @@ var Model = class Model extends BaseModel {
|
|
|
1956
1956
|
this.buildRelationships(attributes);
|
|
1957
1957
|
return this.asProxy();
|
|
1958
1958
|
}
|
|
1959
|
+
static define() {
|
|
1960
|
+
return this;
|
|
1961
|
+
}
|
|
1959
1962
|
static query(trx = null) {
|
|
1960
1963
|
return new this().newQuery(trx);
|
|
1961
1964
|
}
|
|
@@ -2139,7 +2142,7 @@ var Model = class Model extends BaseModel {
|
|
|
2139
2142
|
});
|
|
2140
2143
|
}
|
|
2141
2144
|
toData() {
|
|
2142
|
-
return
|
|
2145
|
+
return _h3ravel_support.Obj.deepMerge(this.attributesToData(), this.relationsToData());
|
|
2143
2146
|
}
|
|
2144
2147
|
toJSON() {
|
|
2145
2148
|
return this.toData();
|
|
@@ -2150,6 +2153,15 @@ var Model = class Model extends BaseModel {
|
|
|
2150
2153
|
toString() {
|
|
2151
2154
|
return this.toJson();
|
|
2152
2155
|
}
|
|
2156
|
+
getAttributes() {
|
|
2157
|
+
return super.getAttributes();
|
|
2158
|
+
}
|
|
2159
|
+
getAttribute(key) {
|
|
2160
|
+
return super.getAttribute(key);
|
|
2161
|
+
}
|
|
2162
|
+
setAttribute(key, value) {
|
|
2163
|
+
return super.setAttribute(key, value);
|
|
2164
|
+
}
|
|
2153
2165
|
fill(attributes) {
|
|
2154
2166
|
for (const key in attributes) this.setAttribute(key, attributes[key]);
|
|
2155
2167
|
return this;
|
|
@@ -2190,10 +2202,9 @@ var Model = class Model extends BaseModel {
|
|
|
2190
2202
|
if (this.usesTimestamps()) this.updateTimestamps();
|
|
2191
2203
|
const attributes = this.getAttributes();
|
|
2192
2204
|
if (this.getIncrementing()) {
|
|
2193
|
-
var _data$;
|
|
2194
2205
|
const keyName = this.getKeyName();
|
|
2195
2206
|
const data = await query.insert([attributes], [keyName]);
|
|
2196
|
-
this.setAttribute(keyName,
|
|
2207
|
+
this.setAttribute(keyName, data[0]?.[keyName] || data[0]);
|
|
2197
2208
|
} else if (Object.keys(attributes).length > 0) await query.insert(attributes);
|
|
2198
2209
|
this.exists = true;
|
|
2199
2210
|
await this.execHooks("created", options);
|
|
@@ -2235,7 +2246,7 @@ var Model = class Model extends BaseModel {
|
|
|
2235
2246
|
if (!this.exists) return Promise.resolve(void 0);
|
|
2236
2247
|
const model = await this.constructor.query().where(this.getKeyName(), this.getKey()).first();
|
|
2237
2248
|
this.attributes = { ...model.attributes };
|
|
2238
|
-
await this.load((0,
|
|
2249
|
+
await this.load((0, _h3ravel_collect_js.collect)(this.relations).reject((relation) => {
|
|
2239
2250
|
return relation instanceof Pivot;
|
|
2240
2251
|
}).keys().all());
|
|
2241
2252
|
this.syncOriginal();
|
|
@@ -2299,7 +2310,7 @@ var Pivot = class extends Model {
|
|
|
2299
2310
|
};
|
|
2300
2311
|
//#endregion
|
|
2301
2312
|
//#region src/collection.ts
|
|
2302
|
-
var Collection = class
|
|
2313
|
+
var Collection = class extends _h3ravel_collect_js.Collection {
|
|
2303
2314
|
newConstructor(...args) {
|
|
2304
2315
|
return new (this.getConstructor())(...args);
|
|
2305
2316
|
}
|
|
@@ -2308,17 +2319,18 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
2308
2319
|
}
|
|
2309
2320
|
async load(...relations) {
|
|
2310
2321
|
if (this.isNotEmpty()) {
|
|
2311
|
-
const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.
|
|
2322
|
+
const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.all());
|
|
2312
2323
|
return this.newConstructor(items);
|
|
2313
2324
|
}
|
|
2314
2325
|
return this;
|
|
2315
2326
|
}
|
|
2316
2327
|
async loadAggregate(relations, column, action = null) {
|
|
2317
2328
|
if (this.isEmpty()) return this;
|
|
2318
|
-
const
|
|
2319
|
-
const
|
|
2329
|
+
const first = this.first();
|
|
2330
|
+
const models = (await first.newModelQuery().whereIn(first.getKeyName(), this.modelKeys()).select(first.getKeyName()).withAggregate(relations, column, action).get()).keyBy(first.getKeyName());
|
|
2331
|
+
const attributes = (0, _h3ravel_collect_js.collect)(Object.keys(models.first().getAttributes())).diff([models.first().getKeyName()]).all();
|
|
2320
2332
|
this.each((model) => {
|
|
2321
|
-
const extraAttributes =
|
|
2333
|
+
const extraAttributes = _h3ravel_support.Arr.select(models.get(model.getKey()).getAttributes(), attributes);
|
|
2322
2334
|
model.fill(extraAttributes).syncOriginalAttributes(...attributes);
|
|
2323
2335
|
});
|
|
2324
2336
|
return this;
|
|
@@ -2356,20 +2368,21 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
2356
2368
|
diff(items) {
|
|
2357
2369
|
const diff = new this.constructor();
|
|
2358
2370
|
const dictionary = this.getDictionary(items);
|
|
2359
|
-
this.
|
|
2371
|
+
this.all().map((item) => {
|
|
2360
2372
|
if (dictionary[item.getKey()] === void 0) diff.add(item);
|
|
2361
2373
|
});
|
|
2362
2374
|
return diff;
|
|
2363
2375
|
}
|
|
2364
|
-
except(keys) {
|
|
2365
|
-
const
|
|
2376
|
+
except(...keys) {
|
|
2377
|
+
const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
|
|
2378
|
+
const dictionary = _h3ravel_support.Arr.except(this.getDictionary(), values);
|
|
2366
2379
|
return new this.constructor(Object.values(dictionary));
|
|
2367
2380
|
}
|
|
2368
2381
|
intersect(items) {
|
|
2369
2382
|
const intersect = new this.constructor();
|
|
2370
|
-
if (
|
|
2383
|
+
if (_h3ravel_support.Arr.isEmpty(items)) return intersect;
|
|
2371
2384
|
const dictionary = this.getDictionary(items);
|
|
2372
|
-
for (const item of this.
|
|
2385
|
+
for (const item of this.all()) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
|
|
2373
2386
|
return intersect;
|
|
2374
2387
|
}
|
|
2375
2388
|
unique(key, _strict = false) {
|
|
@@ -2378,20 +2391,21 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
2378
2391
|
}
|
|
2379
2392
|
find(key, defaultValue = null) {
|
|
2380
2393
|
if (key instanceof Model) key = key.getKey();
|
|
2381
|
-
if (
|
|
2394
|
+
if (Array.isArray(key)) {
|
|
2382
2395
|
if (this.isEmpty()) return new this.constructor();
|
|
2383
2396
|
return this.whereIn(this.first().getKeyName(), key);
|
|
2384
2397
|
}
|
|
2385
|
-
(0,
|
|
2398
|
+
(0, _h3ravel_collect_js.collect)(this.all()).first((model) => {
|
|
2386
2399
|
return model.getKey() == key;
|
|
2387
2400
|
});
|
|
2388
|
-
return this.
|
|
2401
|
+
return this.all().filter((model) => {
|
|
2389
2402
|
return model.getKey() == key;
|
|
2390
2403
|
})[0] || defaultValue;
|
|
2391
2404
|
}
|
|
2392
2405
|
async fresh(...args) {
|
|
2393
2406
|
if (this.isEmpty()) return new this.constructor();
|
|
2394
2407
|
const model = this.first();
|
|
2408
|
+
if (!model) return new this.constructor();
|
|
2395
2409
|
const freshModels = (await model.newQuery().with(...args).whereIn(model.getKeyName(), this.modelKeys()).get()).getDictionary();
|
|
2396
2410
|
return this.filter((model) => {
|
|
2397
2411
|
return model.exists && freshModels[model.getKey()] !== void 0;
|
|
@@ -2414,15 +2428,15 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
2414
2428
|
item.append(attributes);
|
|
2415
2429
|
});
|
|
2416
2430
|
}
|
|
2417
|
-
only(keys) {
|
|
2418
|
-
|
|
2419
|
-
const dictionary =
|
|
2431
|
+
only(...keys) {
|
|
2432
|
+
const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
|
|
2433
|
+
const dictionary = _h3ravel_support.Arr.select(this.getDictionary(), values);
|
|
2420
2434
|
return new this.constructor(Object.values(dictionary));
|
|
2421
2435
|
}
|
|
2422
2436
|
getDictionary(items) {
|
|
2423
|
-
|
|
2437
|
+
const values = !items ? this.all() : items instanceof _h3ravel_collect_js.Collection ? items.all() : items;
|
|
2424
2438
|
const dictionary = {};
|
|
2425
|
-
|
|
2439
|
+
values.map((value) => {
|
|
2426
2440
|
dictionary[value.getKey()] = value;
|
|
2427
2441
|
});
|
|
2428
2442
|
return dictionary;
|
|
@@ -2446,8 +2460,8 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
2446
2460
|
return JSON.stringify(this.toData(), ...args);
|
|
2447
2461
|
}
|
|
2448
2462
|
[Symbol.iterator] = () => {
|
|
2449
|
-
const items = this.
|
|
2450
|
-
const length =
|
|
2463
|
+
const items = this.all();
|
|
2464
|
+
const length = items.length;
|
|
2451
2465
|
let n = 0;
|
|
2452
2466
|
return { next() {
|
|
2453
2467
|
return n < length ? {
|
|
@@ -2494,24 +2508,24 @@ const InteractsWithPivotTable$1 = (Relation) => {
|
|
|
2494
2508
|
let records;
|
|
2495
2509
|
const results = await this.getCurrentlyAttachedPivots();
|
|
2496
2510
|
const current = results.length === 0 ? [] : results.map((result) => result.toData()).pluck(this.relatedPivotKey).all().map((i) => String(i));
|
|
2497
|
-
const detach = (0,
|
|
2511
|
+
const detach = (0, _h3ravel_collect_js.collect)(current).diff(Object.keys(records = this.formatRecordsList(this.parseIds(ids)))).all();
|
|
2498
2512
|
if (detaching && detach.length > 0) {
|
|
2499
2513
|
await this.detach(detach);
|
|
2500
2514
|
changes.detached = this.castKeys(detach);
|
|
2501
2515
|
}
|
|
2502
|
-
changes =
|
|
2516
|
+
changes = _h3ravel_support.Obj.deepMerge(changes, await this.attachNew(records, current, false));
|
|
2503
2517
|
return changes;
|
|
2504
2518
|
}
|
|
2505
2519
|
syncWithoutDetaching(ids) {
|
|
2506
2520
|
return this.sync(ids, false);
|
|
2507
2521
|
}
|
|
2508
2522
|
syncWithPivotValues(ids, values, detaching = true) {
|
|
2509
|
-
return this.sync((0,
|
|
2510
|
-
return [id, values];
|
|
2523
|
+
return this.sync((0, _h3ravel_collect_js.collect)(this.parseIds(ids)).mapWithKeys((id) => {
|
|
2524
|
+
return [String(id), values];
|
|
2511
2525
|
}), detaching);
|
|
2512
2526
|
}
|
|
2513
2527
|
withPivot(columns) {
|
|
2514
|
-
this.pivotColumns = this.pivotColumns.concat(
|
|
2528
|
+
this.pivotColumns = this.pivotColumns.concat(Array.isArray(columns) ? columns : Array.prototype.slice.call(columns));
|
|
2515
2529
|
return this;
|
|
2516
2530
|
}
|
|
2517
2531
|
async attachNew(records, current, touch = true) {
|
|
@@ -2547,9 +2561,9 @@ const InteractsWithPivotTable$1 = (Relation) => {
|
|
|
2547
2561
|
return parseInt(updated);
|
|
2548
2562
|
}
|
|
2549
2563
|
formatRecordsList(records) {
|
|
2550
|
-
return (0,
|
|
2551
|
-
if (!
|
|
2552
|
-
return [id, attributes];
|
|
2564
|
+
return (0, _h3ravel_collect_js.collect)(records).mapWithKeys((attributes, id) => {
|
|
2565
|
+
if (!Array.isArray(attributes)) [id, attributes] = [attributes, {}];
|
|
2566
|
+
return [String(id), attributes];
|
|
2553
2567
|
}).all();
|
|
2554
2568
|
}
|
|
2555
2569
|
async getCurrentlyAttachedPivots() {
|
|
@@ -2619,7 +2633,7 @@ const InteractsWithPivotTable$1 = (Relation) => {
|
|
|
2619
2633
|
}
|
|
2620
2634
|
formatAttachRecord(key, value, attributes, hasTimestamps) {
|
|
2621
2635
|
const [id, newAttributes] = this.extractAttachIdAndAttributes(key, value, attributes);
|
|
2622
|
-
return
|
|
2636
|
+
return _h3ravel_support.Obj.deepMerge(this.baseAttachRecord(id, hasTimestamps), newAttributes);
|
|
2623
2637
|
}
|
|
2624
2638
|
baseAttachRecord(id, timed) {
|
|
2625
2639
|
let record = {};
|
|
@@ -2632,7 +2646,7 @@ const InteractsWithPivotTable$1 = (Relation) => {
|
|
|
2632
2646
|
return record;
|
|
2633
2647
|
}
|
|
2634
2648
|
extractAttachIdAndAttributes(key, value, newAttributes) {
|
|
2635
|
-
return
|
|
2649
|
+
return Array.isArray(value) ? [key, {
|
|
2636
2650
|
...value,
|
|
2637
2651
|
...newAttributes
|
|
2638
2652
|
}] : [value, newAttributes];
|
|
@@ -2643,7 +2657,7 @@ const InteractsWithPivotTable$1 = (Relation) => {
|
|
|
2643
2657
|
parseIds(value) {
|
|
2644
2658
|
if (value instanceof Model) return [value[this.relatedKey]];
|
|
2645
2659
|
if (value instanceof Collection) return value.pluck(this.relatedKey).all();
|
|
2646
|
-
return
|
|
2660
|
+
return Array.isArray(value) ? value : [value];
|
|
2647
2661
|
}
|
|
2648
2662
|
};
|
|
2649
2663
|
};
|
|
@@ -2703,9 +2717,8 @@ var BelongsToMany$1 = class extends compose(Relation$1, InteractsWithPivotTable$
|
|
|
2703
2717
|
return this;
|
|
2704
2718
|
}
|
|
2705
2719
|
async get(columns) {
|
|
2706
|
-
var _builder$query;
|
|
2707
2720
|
const builder = this.query.applyScopes();
|
|
2708
|
-
columns =
|
|
2721
|
+
columns = builder.query?._statements?.find((item) => item.grouping == "columns") ? [] : columns;
|
|
2709
2722
|
let models = await builder.select(this.shouldSelect(columns)).getModels();
|
|
2710
2723
|
this.hydratePivotRelation(models);
|
|
2711
2724
|
if (models.length > 0) models = await builder.eagerLoadRelations(models);
|
|
@@ -2754,7 +2767,7 @@ var BelongsToMany$1 = class extends compose(Relation$1, InteractsWithPivotTable$
|
|
|
2754
2767
|
const value = model.attributes[key];
|
|
2755
2768
|
if (key.startsWith("pivot_")) {
|
|
2756
2769
|
values[key.substring(6)] = value;
|
|
2757
|
-
model.attributes =
|
|
2770
|
+
model.attributes = _h3ravel_support.Arr.except(model.attributes, [key]);
|
|
2758
2771
|
}
|
|
2759
2772
|
}
|
|
2760
2773
|
return values;
|
|
@@ -2765,11 +2778,11 @@ var BelongsToMany$1 = class extends compose(Relation$1, InteractsWithPivotTable$
|
|
|
2765
2778
|
return this.withPivot(this.createdAt(), this.updatedAt());
|
|
2766
2779
|
}
|
|
2767
2780
|
shouldSelect(columns = ["*"]) {
|
|
2768
|
-
if (
|
|
2781
|
+
if (columns.length === 1 && columns[0] === "*") columns = [this.related.getTable() + ".*"];
|
|
2769
2782
|
return columns.concat(this.aliasedPivotColumns());
|
|
2770
2783
|
}
|
|
2771
2784
|
aliasedPivotColumns() {
|
|
2772
|
-
return (0,
|
|
2785
|
+
return (0, _h3ravel_collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
|
|
2773
2786
|
return this.qualifyPivotColumn(column) + " as pivot_" + column;
|
|
2774
2787
|
}).unique().all();
|
|
2775
2788
|
}
|
|
@@ -2889,9 +2902,8 @@ var Builder = class Builder extends Inference$1 {
|
|
|
2889
2902
|
}
|
|
2890
2903
|
asProxy() {
|
|
2891
2904
|
return new Proxy(this, { get(target, prop) {
|
|
2892
|
-
var _target$query$connect;
|
|
2893
2905
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2894
|
-
const skipReturning = !!
|
|
2906
|
+
const skipReturning = !!target.query.connector?.client.config?.client?.includes("mysql") && prop === "returning";
|
|
2895
2907
|
if ([
|
|
2896
2908
|
"select",
|
|
2897
2909
|
"from",
|
|
@@ -2985,7 +2997,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
2985
2997
|
};
|
|
2986
2998
|
}
|
|
2987
2999
|
if (prop.startsWith("where")) {
|
|
2988
|
-
const column =
|
|
3000
|
+
const column = _h3ravel_support.Str.snake(prop.substring(5));
|
|
2989
3001
|
return (...args) => {
|
|
2990
3002
|
target.query.where(column, ...args);
|
|
2991
3003
|
return target.asProxy();
|
|
@@ -3060,7 +3072,8 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3060
3072
|
}
|
|
3061
3073
|
addUpdatedAtColumn(values) {
|
|
3062
3074
|
if (!this.model.usesTimestamps() || this.model.getUpdatedAtColumn() === null) return values;
|
|
3063
|
-
|
|
3075
|
+
const column = this.model.getUpdatedAtColumn();
|
|
3076
|
+
values = _h3ravel_support.Obj.deepMerge({ [column]: this.model.freshTimestampString() }, values);
|
|
3064
3077
|
return values;
|
|
3065
3078
|
}
|
|
3066
3079
|
delete() {
|
|
@@ -3088,9 +3101,8 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3088
3101
|
return this.model;
|
|
3089
3102
|
}
|
|
3090
3103
|
setModel(model) {
|
|
3091
|
-
var _this$query;
|
|
3092
3104
|
this.model = model;
|
|
3093
|
-
if (typeof
|
|
3105
|
+
if (typeof this.query?.client?.table == "function") this.query = this.query.client.table(this.model.getTable());
|
|
3094
3106
|
else this.query = this.query.table(this.model.getTable());
|
|
3095
3107
|
return this;
|
|
3096
3108
|
}
|
|
@@ -3133,7 +3145,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3133
3145
|
}
|
|
3134
3146
|
withoutGlobalScope(scope) {
|
|
3135
3147
|
if (typeof scope !== "string") scope = scope.constructor.name;
|
|
3136
|
-
this.globalScopes =
|
|
3148
|
+
this.globalScopes = _h3ravel_support.Arr.except(this.globalScopes, [scope]);
|
|
3137
3149
|
return this;
|
|
3138
3150
|
}
|
|
3139
3151
|
macro(name, callback) {
|
|
@@ -3150,7 +3162,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3150
3162
|
let eagerLoads = {};
|
|
3151
3163
|
if (typeof args[1] === "function") {
|
|
3152
3164
|
const eagerLoad = this.parseWithRelations({ [args[0]]: args[1] });
|
|
3153
|
-
this.eagerLoad =
|
|
3165
|
+
this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, eagerLoad);
|
|
3154
3166
|
return this;
|
|
3155
3167
|
}
|
|
3156
3168
|
const relations = flattenDeep(args);
|
|
@@ -3159,13 +3171,13 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3159
3171
|
let eagerLoad;
|
|
3160
3172
|
if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
|
|
3161
3173
|
else if (typeof relation === "object") eagerLoad = relation;
|
|
3162
|
-
eagerLoads =
|
|
3174
|
+
eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
|
|
3163
3175
|
}
|
|
3164
|
-
this.eagerLoad =
|
|
3176
|
+
this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, this.parseWithRelations(eagerLoads));
|
|
3165
3177
|
return this;
|
|
3166
3178
|
}
|
|
3167
3179
|
has(relation, operator = ">=", count = 1, boolean = "and", callback = null) {
|
|
3168
|
-
if (
|
|
3180
|
+
if (typeof relation === "string") {
|
|
3169
3181
|
if (relation.includes(".")) return this.hasNested(relation, operator, count, boolean, callback);
|
|
3170
3182
|
relation = this.getRelationWithoutConstraints(getRelationMethod(relation));
|
|
3171
3183
|
}
|
|
@@ -3242,7 +3254,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3242
3254
|
let eagerLoad;
|
|
3243
3255
|
if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
|
|
3244
3256
|
else if (typeof relation === "object") eagerLoad = relation;
|
|
3245
|
-
eagerLoads =
|
|
3257
|
+
eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
|
|
3246
3258
|
}
|
|
3247
3259
|
relations = eagerLoads;
|
|
3248
3260
|
const db = this.model.getConnection();
|
|
@@ -3261,7 +3273,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3261
3273
|
} else expression = column;
|
|
3262
3274
|
const query = relation.getRelationExistenceQuery(relation.getRelated().newModelQuery(), this, db.raw(expression));
|
|
3263
3275
|
constraints(query);
|
|
3264
|
-
alias = alias ||
|
|
3276
|
+
alias = alias || _h3ravel_support.Str.snake(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
|
|
3265
3277
|
if (action === "exists") this.select(db.raw(`exists(${query.toSql().sql}) as ${alias}`));
|
|
3266
3278
|
else this.selectSub(action ? query : query.limit(1), alias);
|
|
3267
3279
|
}
|
|
@@ -3285,7 +3297,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3285
3297
|
}
|
|
3286
3298
|
parseSub(query) {
|
|
3287
3299
|
if (query instanceof Builder || query instanceof Relation$1) return [query.toSql().sql, query.toSql().bindings];
|
|
3288
|
-
else if (
|
|
3300
|
+
else if (typeof query === "string") return [query, []];
|
|
3289
3301
|
else throw new Error("A subquery must be a query builder instance, a Closure, or a string.");
|
|
3290
3302
|
}
|
|
3291
3303
|
prependDatabaseNameIfCrossDatabaseQuery(query) {
|
|
@@ -3342,15 +3354,15 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3342
3354
|
if (prefix !== "") prefix += ".";
|
|
3343
3355
|
for (const key in relations) {
|
|
3344
3356
|
const value = relations[key];
|
|
3345
|
-
if (
|
|
3357
|
+
if (typeof value === "string" || Number.isFinite(parseInt(value))) continue;
|
|
3346
3358
|
const [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(key, value);
|
|
3347
3359
|
preparedRelationships = Object.assign({}, preparedRelationships, { [`${prefix}${attribute}`]: attributeSelectConstraint }, this.prepareNestedWithRelationships(value, `${prefix}${attribute}`));
|
|
3348
|
-
relations =
|
|
3360
|
+
relations = _h3ravel_support.Arr.except(relations, [key]);
|
|
3349
3361
|
}
|
|
3350
3362
|
for (const key in relations) {
|
|
3351
3363
|
const value = relations[key];
|
|
3352
3364
|
let attribute = key, attributeSelectConstraint = value;
|
|
3353
|
-
if (
|
|
3365
|
+
if (typeof value === "string") [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(value);
|
|
3354
3366
|
preparedRelationships[`${prefix}${attribute}`] = this.combineConstraints([attributeSelectConstraint, preparedRelationships[`${prefix}${attribute}`] || (() => {})]);
|
|
3355
3367
|
}
|
|
3356
3368
|
return preparedRelationships;
|
|
@@ -3398,8 +3410,8 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3398
3410
|
}
|
|
3399
3411
|
async findOrFail(...args) {
|
|
3400
3412
|
const data = await this.find(...args);
|
|
3401
|
-
if (
|
|
3402
|
-
if (data.count() !== args[0].length) throw new ModelNotFoundError().setModel(this.model.constructor.name, (0,
|
|
3413
|
+
if (Array.isArray(args[0])) {
|
|
3414
|
+
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());
|
|
3403
3415
|
return data;
|
|
3404
3416
|
}
|
|
3405
3417
|
if (data === null) throw new ModelNotFoundError().setModel(this.model.constructor.name, args[0]);
|
|
@@ -3413,12 +3425,12 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3413
3425
|
async firstOrNew(attributes = {}, values = {}) {
|
|
3414
3426
|
const instance = await this.where(attributes).first();
|
|
3415
3427
|
if (instance !== null) return instance;
|
|
3416
|
-
return this.newModelInstance(
|
|
3428
|
+
return this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values));
|
|
3417
3429
|
}
|
|
3418
3430
|
async firstOrCreate(attributes = {}, values = {}) {
|
|
3419
3431
|
const instance = await this.where(attributes).first();
|
|
3420
3432
|
if (instance !== null) return instance;
|
|
3421
|
-
return tap(this.newModelInstance(
|
|
3433
|
+
return tap(this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values)), async (instance) => {
|
|
3422
3434
|
await instance.save({ client: this.query });
|
|
3423
3435
|
});
|
|
3424
3436
|
}
|
|
@@ -3438,22 +3450,21 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3438
3450
|
return this;
|
|
3439
3451
|
}
|
|
3440
3452
|
async find(id, columns) {
|
|
3441
|
-
if (
|
|
3453
|
+
if (Array.isArray(id) || id instanceof Collection) return await this.findMany(id, columns);
|
|
3442
3454
|
return await this.where(this.model.getKeyName(), id).first(columns);
|
|
3443
3455
|
}
|
|
3444
3456
|
async findMany(ids, columns = ["*"]) {
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
return await this.whereIn(this.model.getKeyName(), ids).get(columns);
|
|
3457
|
+
const values = ids instanceof Collection ? ids.modelKeys() : Array.isArray(ids) ? ids : [ids];
|
|
3458
|
+
if (values.length === 0) return new Collection([]);
|
|
3459
|
+
return await this.whereIn(this.model.getKeyName(), values).get(columns);
|
|
3449
3460
|
}
|
|
3450
3461
|
async pluck(column) {
|
|
3451
3462
|
return new Collection(await this.query.pluck(column));
|
|
3452
3463
|
}
|
|
3453
3464
|
async destroy(ids) {
|
|
3454
3465
|
if (ids instanceof Collection) ids = ids.modelKeys();
|
|
3455
|
-
if (ids instanceof
|
|
3456
|
-
ids =
|
|
3466
|
+
if (ids instanceof _h3ravel_collect_js.Collection) ids = ids.all();
|
|
3467
|
+
ids = Array.isArray(ids) ? ids : Array.prototype.slice.call(ids);
|
|
3457
3468
|
if (ids.length === 0) return 0;
|
|
3458
3469
|
const key = this.model.newInstance().getKeyName();
|
|
3459
3470
|
let count = 0;
|
|
@@ -3471,12 +3482,11 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3471
3482
|
return await this.model.newModelQuery().get(columns);
|
|
3472
3483
|
}
|
|
3473
3484
|
async paginate(page = 1, perPage = 10) {
|
|
3474
|
-
var _this;
|
|
3475
3485
|
page = page || 1;
|
|
3476
|
-
perPage = perPage ||
|
|
3486
|
+
perPage = perPage || this?.model?.perPage || 15;
|
|
3477
3487
|
this.applyScopes();
|
|
3478
3488
|
const total = await this.query.clone().clearOrder().clearSelect().count(this.primaryKey);
|
|
3479
|
-
let results
|
|
3489
|
+
let results;
|
|
3480
3490
|
if (total > 0) {
|
|
3481
3491
|
const skip = (page - 1) * (perPage ?? 10);
|
|
3482
3492
|
this.take(perPage).skip(skip);
|
|
@@ -3486,7 +3496,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
3486
3496
|
return new Paginator(results, parseInt(total), perPage, page);
|
|
3487
3497
|
}
|
|
3488
3498
|
async getModels(...columns) {
|
|
3489
|
-
columns = (
|
|
3499
|
+
columns = flatten(columns);
|
|
3490
3500
|
if (columns.length > 0) {
|
|
3491
3501
|
if (this.query._statements.filter((item) => item.grouping == "columns").length == 0 && columns[0] !== "*") this.query.select(...columns);
|
|
3492
3502
|
}
|
|
@@ -3694,8 +3704,7 @@ var CockroachDB = class {
|
|
|
3694
3704
|
*/
|
|
3695
3705
|
async hasTable(table) {
|
|
3696
3706
|
const subquery = this.knex.select().from("information_schema.tables").whereIn("table_schema", this.explodedSchema).andWhere({ table_name: table });
|
|
3697
|
-
|
|
3698
|
-
return (record === null || record === void 0 ? void 0 : record.exists) || false;
|
|
3707
|
+
return (await this.knex.select(this.knex.raw("exists (?)", [subquery])).first())?.exists || false;
|
|
3699
3708
|
}
|
|
3700
3709
|
/**
|
|
3701
3710
|
* Get all the available columns in the current schema/database. Can be filtered to a specific table
|
|
@@ -3795,18 +3804,17 @@ var CockroachDB = class {
|
|
|
3795
3804
|
${column ? "AND att.attname = ?" : ""}
|
|
3796
3805
|
`, bindings)]);
|
|
3797
3806
|
const parsedColumms = columns.rows.map((col) => {
|
|
3798
|
-
var _col$default_value;
|
|
3799
3807
|
const constraintsForColumn = constraints.rows.filter((constraint) => constraint.table === col.table && constraint.column === col.name);
|
|
3800
3808
|
const foreignKeyConstraint = constraintsForColumn.find((constraint) => constraint.type === "f");
|
|
3801
3809
|
return {
|
|
3802
3810
|
...col,
|
|
3803
3811
|
is_unique: constraintsForColumn.some((constraint) => ["u", "p"].includes(constraint.type)),
|
|
3804
3812
|
is_primary_key: constraintsForColumn.some((constraint) => constraint.type === "p"),
|
|
3805
|
-
has_auto_increment: ["integer", "bigint"].includes(col.data_type) && (
|
|
3813
|
+
has_auto_increment: ["integer", "bigint"].includes(col.data_type) && (col.default_value?.startsWith("nextval(") ?? false),
|
|
3806
3814
|
default_value: parseDefaultValue$5(col.default_value),
|
|
3807
|
-
foreign_key_schema:
|
|
3808
|
-
foreign_key_table:
|
|
3809
|
-
foreign_key_column:
|
|
3815
|
+
foreign_key_schema: foreignKeyConstraint?.foreign_key_schema ?? null,
|
|
3816
|
+
foreign_key_table: foreignKeyConstraint?.foreign_key_table ?? null,
|
|
3817
|
+
foreign_key_column: foreignKeyConstraint?.foreign_key_column ?? null
|
|
3810
3818
|
};
|
|
3811
3819
|
});
|
|
3812
3820
|
if (table && column) return parsedColumms[0];
|
|
@@ -3820,8 +3828,7 @@ var CockroachDB = class {
|
|
|
3820
3828
|
table_name: table,
|
|
3821
3829
|
column_name: column
|
|
3822
3830
|
});
|
|
3823
|
-
|
|
3824
|
-
return (record === null || record === void 0 ? void 0 : record.exists) || false;
|
|
3831
|
+
return (await this.knex.select(this.knex.raw("exists (?)", [subquery])).first())?.exists || false;
|
|
3825
3832
|
}
|
|
3826
3833
|
/**
|
|
3827
3834
|
* Get the primary key column for the given table
|
|
@@ -4133,14 +4140,13 @@ var MSSQL = class {
|
|
|
4133
4140
|
WHERE
|
|
4134
4141
|
OBJECT_SCHEMA_NAME (f.parent_object_id) = ?;
|
|
4135
4142
|
`, [this.schema]);
|
|
4136
|
-
if (table) return result
|
|
4143
|
+
if (table) return result?.filter((row) => row.table === table);
|
|
4137
4144
|
return result;
|
|
4138
4145
|
}
|
|
4139
4146
|
};
|
|
4140
4147
|
//#endregion
|
|
4141
4148
|
//#region src/inspector/dialects/mysql.ts
|
|
4142
4149
|
function rawColumnToColumn$1(rawColumn) {
|
|
4143
|
-
var _rawColumn$EXTRA;
|
|
4144
4150
|
let dataType = rawColumn.COLUMN_TYPE.replace(/\(.*?\)/, "");
|
|
4145
4151
|
if (rawColumn.COLUMN_TYPE.startsWith("tinyint(1)")) dataType = "boolean";
|
|
4146
4152
|
return {
|
|
@@ -4153,7 +4159,7 @@ function rawColumnToColumn$1(rawColumn) {
|
|
|
4153
4159
|
max_length: rawColumn.CHARACTER_MAXIMUM_LENGTH,
|
|
4154
4160
|
numeric_precision: rawColumn.NUMERIC_PRECISION,
|
|
4155
4161
|
numeric_scale: rawColumn.NUMERIC_SCALE,
|
|
4156
|
-
is_generated: !!
|
|
4162
|
+
is_generated: !!rawColumn.EXTRA?.endsWith("GENERATED"),
|
|
4157
4163
|
is_nullable: rawColumn.IS_NULLABLE === "YES",
|
|
4158
4164
|
is_unique: rawColumn.COLUMN_KEY === "UNI",
|
|
4159
4165
|
is_primary_key: rawColumn.CONSTRAINT_NAME === "PRIMARY" || rawColumn.COLUMN_KEY === "PRI",
|
|
@@ -4346,11 +4352,10 @@ var oracleDB = class {
|
|
|
4346
4352
|
* Check if a table exists in the current schema/database
|
|
4347
4353
|
*/
|
|
4348
4354
|
async hasTable(table) {
|
|
4349
|
-
|
|
4355
|
+
return !!(await this.knex.select(this.knex.raw(`
|
|
4350
4356
|
/*+ OPTIMIZER_FEATURES_ENABLE('${OPTIMIZER_FEATURES}') */
|
|
4351
4357
|
COUNT(*) "count"
|
|
4352
|
-
`)).from("USER_TABLES").where({ TABLE_NAME: table }).first();
|
|
4353
|
-
return !!(result === null || result === void 0 ? void 0 : result.count);
|
|
4358
|
+
`)).from("USER_TABLES").where({ TABLE_NAME: table }).first())?.count;
|
|
4354
4359
|
}
|
|
4355
4360
|
/**
|
|
4356
4361
|
* Get all the available columns in the current schema/database. Can be filtered to a specific table
|
|
@@ -4426,15 +4431,14 @@ var oracleDB = class {
|
|
|
4426
4431
|
* Check if a table exists in the current schema/database
|
|
4427
4432
|
*/
|
|
4428
4433
|
async hasColumn(table, column) {
|
|
4429
|
-
|
|
4434
|
+
return !!(await this.knex.select(this.knex.raw(`
|
|
4430
4435
|
/*+ OPTIMIZER_FEATURES_ENABLE('${OPTIMIZER_FEATURES}') NO_QUERY_TRANSFORMATION */
|
|
4431
4436
|
COUNT(*) "count"
|
|
4432
4437
|
`)).from("USER_TAB_COLS").where({
|
|
4433
4438
|
TABLE_NAME: table,
|
|
4434
4439
|
COLUMN_NAME: column,
|
|
4435
4440
|
HIDDEN_COLUMN: "NO"
|
|
4436
|
-
}).first();
|
|
4437
|
-
return !!(result === null || result === void 0 ? void 0 : result.count);
|
|
4441
|
+
}).first())?.count;
|
|
4438
4442
|
}
|
|
4439
4443
|
/**
|
|
4440
4444
|
* Get the primary key column for the given table
|
|
@@ -4600,13 +4604,12 @@ var Postgres = class {
|
|
|
4600
4604
|
`, bindings)).rows;
|
|
4601
4605
|
}
|
|
4602
4606
|
async columnInfo(table, column) {
|
|
4603
|
-
var _versionResponse$rows;
|
|
4604
4607
|
const { knex } = this;
|
|
4605
4608
|
const bindings = [];
|
|
4606
4609
|
if (table) bindings.push(table);
|
|
4607
4610
|
if (column) bindings.push(column);
|
|
4608
4611
|
const schemaIn = this.explodedSchema.map((schemaName) => `${this.knex.raw("?", [schemaName])}::regnamespace`);
|
|
4609
|
-
const majorVersion = (
|
|
4612
|
+
const majorVersion = (await this.knex.raw("SHOW server_version")).rows?.[0]?.server_version?.split(".")?.[0] ?? 10;
|
|
4610
4613
|
let generationSelect = `
|
|
4611
4614
|
NULL AS generation_expression,
|
|
4612
4615
|
pg_get_expr(ad.adbin, ad.adrelid) AS default_value,
|
|
@@ -4698,9 +4701,9 @@ var Postgres = class {
|
|
|
4698
4701
|
is_primary_key: constraintsForColumn.some((constraint) => constraint.type === "p"),
|
|
4699
4702
|
has_auto_increment: constraintsForColumn.some((constraint) => constraint.has_auto_increment),
|
|
4700
4703
|
default_value: parseDefaultValue$1(col.default_value),
|
|
4701
|
-
foreign_key_schema:
|
|
4702
|
-
foreign_key_table:
|
|
4703
|
-
foreign_key_column:
|
|
4704
|
+
foreign_key_schema: foreignKeyConstraint?.foreign_key_schema ?? null,
|
|
4705
|
+
foreign_key_table: foreignKeyConstraint?.foreign_key_table ?? null,
|
|
4706
|
+
foreign_key_column: foreignKeyConstraint?.foreign_key_column ?? null
|
|
4704
4707
|
};
|
|
4705
4708
|
});
|
|
4706
4709
|
if (table && column) return parsedColumms[0];
|
|
@@ -4919,11 +4922,11 @@ var SQLite = class {
|
|
|
4919
4922
|
is_generated: raw.hidden !== 0,
|
|
4920
4923
|
generation_expression: null,
|
|
4921
4924
|
is_nullable: raw.notnull === 0,
|
|
4922
|
-
is_unique: !!
|
|
4925
|
+
is_unique: !!index?.unique && indexInfo?.length === 1,
|
|
4923
4926
|
is_primary_key: raw.pk === 1,
|
|
4924
4927
|
has_auto_increment: raw.pk === 1 && tablesWithAutoIncrementPrimaryKeys.includes(table),
|
|
4925
|
-
foreign_key_column:
|
|
4926
|
-
foreign_key_table:
|
|
4928
|
+
foreign_key_column: foreignKey?.to || null,
|
|
4929
|
+
foreign_key_table: foreignKey?.table || null
|
|
4927
4930
|
};
|
|
4928
4931
|
});
|
|
4929
4932
|
};
|
|
@@ -5145,8 +5148,7 @@ var Migrator = class {
|
|
|
5145
5148
|
else await callback(connection);
|
|
5146
5149
|
}
|
|
5147
5150
|
async runMethod(connection, migration, method) {
|
|
5148
|
-
|
|
5149
|
-
await ((_migration$method = migration[method]) === null || _migration$method === void 0 ? void 0 : _migration$method.call(migration, connection.schema, connection));
|
|
5151
|
+
await migration[method]?.(connection.schema, connection);
|
|
5150
5152
|
}
|
|
5151
5153
|
async resolvePath(filePath) {
|
|
5152
5154
|
try {
|
|
@@ -5175,7 +5177,7 @@ var Migrator = class {
|
|
|
5175
5177
|
return path.default.basename(filePath).replace(".js", "");
|
|
5176
5178
|
}
|
|
5177
5179
|
path(p) {
|
|
5178
|
-
this.paths = Array.from(new Set([...this.paths, p]));
|
|
5180
|
+
this.paths = Array.from(/* @__PURE__ */ new Set([...this.paths, p]));
|
|
5179
5181
|
}
|
|
5180
5182
|
getPaths() {
|
|
5181
5183
|
return this.paths;
|
|
@@ -5363,8 +5365,7 @@ var Migrate = class {
|
|
|
5363
5365
|
* @returns
|
|
5364
5366
|
*/
|
|
5365
5367
|
async setupConnection(config) {
|
|
5366
|
-
|
|
5367
|
-
const table = (config === null || config === void 0 || (_config$migrations = config.migrations) === null || _config$migrations === void 0 ? void 0 : _config$migrations.table) || "migrations";
|
|
5368
|
+
const table = config?.migrations?.table || "migrations";
|
|
5368
5369
|
if (config.skipConnection !== true) {
|
|
5369
5370
|
arquebus.addConnection(config, "default");
|
|
5370
5371
|
Object.entries(config.connections || {}).forEach(([name, connection]) => {
|
|
@@ -5393,7 +5394,7 @@ var pivot_default = Pivot;
|
|
|
5393
5394
|
//#endregion
|
|
5394
5395
|
//#region src/soft-deleting-scope.ts
|
|
5395
5396
|
const hasJoins = (statements) => {
|
|
5396
|
-
for (const statement of statements) if (
|
|
5397
|
+
for (const statement of statements) if (statement?.grouping === "join") return true;
|
|
5397
5398
|
return false;
|
|
5398
5399
|
};
|
|
5399
5400
|
var SoftDeletingScope = class extends Scope {
|
|
@@ -5520,7 +5521,7 @@ const softDeletes = (Model) => {
|
|
|
5520
5521
|
return this.withoutEvents(() => this.restore());
|
|
5521
5522
|
}
|
|
5522
5523
|
trashed() {
|
|
5523
|
-
return
|
|
5524
|
+
return this[this.getDeletedAtColumn()] != null;
|
|
5524
5525
|
}
|
|
5525
5526
|
static softDeleted(callback) {
|
|
5526
5527
|
this.addHook("trashed", callback);
|
|
@@ -5618,7 +5619,7 @@ function Relationship(target, context, descriptor) {
|
|
|
5618
5619
|
const make = (model, data, options = {}) => {
|
|
5619
5620
|
const { paginated } = options;
|
|
5620
5621
|
if (paginated) return new Paginator(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5621
|
-
if (
|
|
5622
|
+
if (Array.isArray(data)) return new Collection(data.map((item) => model.make(item)));
|
|
5622
5623
|
return model.make(data);
|
|
5623
5624
|
};
|
|
5624
5625
|
const makeCollection = (model, data) => new Collection(data.map((item) => model.make(item)));
|