@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/browser/index.cjs
CHANGED
|
@@ -33,13 +33,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
enumerable: true
|
|
34
34
|
}) : target, mod));
|
|
35
35
|
//#endregion
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
let radashi = require("radashi");
|
|
39
|
-
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
40
|
-
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
|
|
36
|
+
let _h3ravel_collect_js = require("@h3ravel/collect.js");
|
|
37
|
+
let _h3ravel_support = require("@h3ravel/support");
|
|
41
38
|
let dayjs = require("dayjs");
|
|
42
39
|
dayjs = __toESM(dayjs, 1);
|
|
40
|
+
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
41
|
+
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
|
|
43
42
|
let pluralize = require("pluralize");
|
|
44
43
|
pluralize = __toESM(pluralize, 1);
|
|
45
44
|
//#region src/casts/attribute.ts
|
|
@@ -162,29 +161,33 @@ function compose$1(Base, ...mixins) {
|
|
|
162
161
|
}, Base);
|
|
163
162
|
}
|
|
164
163
|
//#endregion
|
|
164
|
+
//#region src/dayjs.ts
|
|
165
|
+
const dayjs$1 = dayjs.default ?? dayjs;
|
|
166
|
+
const advancedFormat = dayjs_plugin_advancedFormat_js.default ?? dayjs_plugin_advancedFormat_js;
|
|
167
|
+
dayjs$1.extend(advancedFormat);
|
|
168
|
+
//#endregion
|
|
165
169
|
//#region src/utils.ts
|
|
166
|
-
dayjs.
|
|
167
|
-
const now = (format = "YYYY-MM-DD HH:mm:ss") => (0, dayjs.default)().format(format);
|
|
170
|
+
const now = (format = "YYYY-MM-DD HH:mm:ss") => dayjs$1().format(format);
|
|
168
171
|
const getRelationName = (relationMethod) => {
|
|
169
|
-
return
|
|
172
|
+
return _h3ravel_support.Str.snake(relationMethod.substring(8));
|
|
170
173
|
};
|
|
171
174
|
const getScopeName = (scopeMethod) => {
|
|
172
|
-
return
|
|
175
|
+
return _h3ravel_support.Str.snake(scopeMethod.substring(5));
|
|
173
176
|
};
|
|
174
177
|
const getRelationMethod = (relation) => {
|
|
175
|
-
return
|
|
178
|
+
return _h3ravel_support.Str.camel(`relation_${relation}`);
|
|
176
179
|
};
|
|
177
180
|
const getScopeMethod = (scope) => {
|
|
178
|
-
return
|
|
181
|
+
return _h3ravel_support.Str.camel(`scope_${scope}`);
|
|
179
182
|
};
|
|
180
183
|
const getAttrMethod = (attr) => {
|
|
181
|
-
return
|
|
184
|
+
return _h3ravel_support.Str.camel(`attribute_${attr}`);
|
|
182
185
|
};
|
|
183
186
|
const getGetterMethod = (attr) => {
|
|
184
|
-
return
|
|
187
|
+
return _h3ravel_support.Str.camel(`get_${attr}_attribute`);
|
|
185
188
|
};
|
|
186
189
|
const getSetterMethod = (attr) => {
|
|
187
|
-
return
|
|
190
|
+
return _h3ravel_support.Str.camel(`set_${attr}_attribute`);
|
|
188
191
|
};
|
|
189
192
|
const getAttrName = (attrMethod) => {
|
|
190
193
|
return attrMethod.substring(3, attrMethod.length - 9).toLowerCase();
|
|
@@ -203,8 +206,8 @@ const tap = (instance, callback) => {
|
|
|
203
206
|
const { compose } = mixin_exports;
|
|
204
207
|
const flatten = (arr) => arr.flat();
|
|
205
208
|
const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
|
|
206
|
-
const kebabCase = (str) =>
|
|
207
|
-
const snakeCase = (str) =>
|
|
209
|
+
const kebabCase = (str) => _h3ravel_support.Str.trim(_h3ravel_support.Str.kebab(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/-+/g, "-");
|
|
210
|
+
const snakeCase = (str) => _h3ravel_support.Str.trim(_h3ravel_support.Str.snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/_+/g, "_");
|
|
208
211
|
const defineConfig = (config) => {
|
|
209
212
|
return config;
|
|
210
213
|
};
|
|
@@ -292,8 +295,7 @@ const HasAttributes = (Model) => {
|
|
|
292
295
|
return this;
|
|
293
296
|
}
|
|
294
297
|
normalizeCastClassResponse(key, value) {
|
|
295
|
-
|
|
296
|
-
return (value === null || value === void 0 || (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) === "Object" ? value : { [key]: value };
|
|
298
|
+
return value?.constructor?.name === "Object" ? value : { [key]: value };
|
|
297
299
|
}
|
|
298
300
|
syncOriginal() {
|
|
299
301
|
this.original = this.getAttributes();
|
|
@@ -403,9 +405,9 @@ const HasAttributes = (Model) => {
|
|
|
403
405
|
return null;
|
|
404
406
|
}
|
|
405
407
|
case "collection": try {
|
|
406
|
-
return (0,
|
|
408
|
+
return (0, _h3ravel_collect_js.collect)(JSON.parse(value));
|
|
407
409
|
} catch {
|
|
408
|
-
return (0,
|
|
410
|
+
return (0, _h3ravel_collect_js.collect)([]);
|
|
409
411
|
}
|
|
410
412
|
case "date": return this.asDate(value);
|
|
411
413
|
case "datetime":
|
|
@@ -418,8 +420,8 @@ const HasAttributes = (Model) => {
|
|
|
418
420
|
attributesToData() {
|
|
419
421
|
let attributes = { ...this.attributes };
|
|
420
422
|
for (const key in attributes) {
|
|
421
|
-
if (this.hidden.includes(key)) attributes =
|
|
422
|
-
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes =
|
|
423
|
+
if (this.hidden.includes(key)) attributes = _h3ravel_support.Arr.except(attributes, [key]);
|
|
424
|
+
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = _h3ravel_support.Arr.except(attributes, [key]);
|
|
423
425
|
}
|
|
424
426
|
for (const key of this.getDates()) {
|
|
425
427
|
if (attributes[key] === void 0) continue;
|
|
@@ -431,7 +433,7 @@ const HasAttributes = (Model) => {
|
|
|
431
433
|
if (key in attributes === false) continue;
|
|
432
434
|
attributes[key] = this.castAttribute(key, attributes[key]);
|
|
433
435
|
if (key in attributes && ["date", "datetime"].includes(String(value))) attributes[key] = this.serializeDate(attributes[key]);
|
|
434
|
-
if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] =
|
|
436
|
+
if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = dayjs$1(attributes[key]).format(String(value).split(":")[1]);
|
|
435
437
|
}
|
|
436
438
|
for (const key of this.appends) attributes[key] = this.mutateAttribute(key, null);
|
|
437
439
|
return attributes;
|
|
@@ -447,7 +449,7 @@ const HasAttributes = (Model) => {
|
|
|
447
449
|
return this.getDates().includes(key) || this.isDateCastable(key);
|
|
448
450
|
}
|
|
449
451
|
serializeDate(date) {
|
|
450
|
-
return date ?
|
|
452
|
+
return date ? dayjs$1(date).toISOString() : null;
|
|
451
453
|
}
|
|
452
454
|
getDates() {
|
|
453
455
|
return this.usesTimestamps() ? [this.getCreatedAtColumn(), this.getUpdatedAtColumn()] : [];
|
|
@@ -474,13 +476,13 @@ const HasAttributes = (Model) => {
|
|
|
474
476
|
}
|
|
475
477
|
hasCast(key, types = []) {
|
|
476
478
|
if (key in this.casts) {
|
|
477
|
-
types = (
|
|
479
|
+
types = flatten(types);
|
|
478
480
|
return types.length > 0 ? types.includes(this.getCastType(key)) : true;
|
|
479
481
|
}
|
|
480
482
|
return false;
|
|
481
483
|
}
|
|
482
484
|
withDayjs(date) {
|
|
483
|
-
return
|
|
485
|
+
return dayjs$1(date);
|
|
484
486
|
}
|
|
485
487
|
isCustomCast(cast) {
|
|
486
488
|
return typeof cast === "function" && new cast() instanceof CastsAttributes;
|
|
@@ -497,7 +499,7 @@ const HasAttributes = (Model) => {
|
|
|
497
499
|
return this.hasCast(key, ["date", "datetime"]);
|
|
498
500
|
}
|
|
499
501
|
fromDateTime(value) {
|
|
500
|
-
return
|
|
502
|
+
return dayjs$1(this.asDateTime(value)).format(this.getDateFormat());
|
|
501
503
|
}
|
|
502
504
|
getDateFormat() {
|
|
503
505
|
return this.dateFormat || "YYYY-MM-DD HH:mm:ss";
|
|
@@ -512,7 +514,7 @@ const HasAttributes = (Model) => {
|
|
|
512
514
|
return new Date(value);
|
|
513
515
|
}
|
|
514
516
|
asDate(value) {
|
|
515
|
-
return
|
|
517
|
+
return dayjs$1(this.asDateTime(value)).startOf("day").toDate();
|
|
516
518
|
}
|
|
517
519
|
};
|
|
518
520
|
};
|
|
@@ -581,7 +583,7 @@ var ModelNotFoundError = class extends BaseError {
|
|
|
581
583
|
}
|
|
582
584
|
setModel(model, ids = []) {
|
|
583
585
|
this.model = model;
|
|
584
|
-
this.ids =
|
|
586
|
+
this.ids = Array.isArray(ids) ? ids : [ids];
|
|
585
587
|
this.message = `No query results for model [${model}]`;
|
|
586
588
|
if (this.ids.length > 0) this.message += " " + this.ids.join(", ");
|
|
587
589
|
else this.message += ".";
|
|
@@ -609,7 +611,7 @@ const HasRelations = (Instance) => {
|
|
|
609
611
|
return this;
|
|
610
612
|
}
|
|
611
613
|
unsetRelation(relation) {
|
|
612
|
-
this.relations =
|
|
614
|
+
this.relations = _h3ravel_support.Arr.except(this.relations, [relation]);
|
|
613
615
|
return this;
|
|
614
616
|
}
|
|
615
617
|
relationLoaded(relation) {
|
|
@@ -642,9 +644,9 @@ const HasRelations = (Instance) => {
|
|
|
642
644
|
else if (frame.includes("at ")) {
|
|
643
645
|
const match = frame.match(/at\s+([^(]+)\s*\(/);
|
|
644
646
|
functionName = match ? match[1].trim() : "anonymous";
|
|
645
|
-
if (functionName
|
|
647
|
+
if (functionName?.includes(".")) functionName = functionName.split(".").pop();
|
|
646
648
|
}
|
|
647
|
-
functionName = functionName
|
|
649
|
+
functionName = functionName?.replace(/^</, "").replace(/>$/, "").trim();
|
|
648
650
|
return getRelationName(functionName || "anonymous");
|
|
649
651
|
}
|
|
650
652
|
joiningTable(related, instance = null) {
|
|
@@ -751,7 +753,7 @@ const HidesAttributes = (Model) => {
|
|
|
751
753
|
makeVisible(...keys) {
|
|
752
754
|
const visible = flattenDeep(keys);
|
|
753
755
|
if (this.visible.length > 0) this.visible = [...this.visible, ...visible];
|
|
754
|
-
this.hidden = (0,
|
|
756
|
+
this.hidden = (0, _h3ravel_collect_js.collect)(this.hidden).diff(visible).all();
|
|
755
757
|
return this;
|
|
756
758
|
}
|
|
757
759
|
makeHidden(key, ...keys) {
|
|
@@ -907,7 +909,7 @@ var Model = class Model extends BaseModel {
|
|
|
907
909
|
return this;
|
|
908
910
|
}
|
|
909
911
|
toData() {
|
|
910
|
-
return
|
|
912
|
+
return _h3ravel_support.Obj.deepMerge(this.attributesToData(), this.relationsToData());
|
|
911
913
|
}
|
|
912
914
|
toJSON() {
|
|
913
915
|
return this.toData();
|
|
@@ -978,7 +980,7 @@ var Pivot = class extends Model {
|
|
|
978
980
|
};
|
|
979
981
|
//#endregion
|
|
980
982
|
//#region src/browser/collection.ts
|
|
981
|
-
var Collection = class
|
|
983
|
+
var Collection = class extends _h3ravel_collect_js.Collection {
|
|
982
984
|
mapThen(callback) {
|
|
983
985
|
return Promise.all(this.map(callback));
|
|
984
986
|
}
|
|
@@ -997,20 +999,21 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
997
999
|
diff(items) {
|
|
998
1000
|
const diff = new this.constructor();
|
|
999
1001
|
const dictionary = this.getDictionary(items);
|
|
1000
|
-
this.
|
|
1002
|
+
this.all().map((item) => {
|
|
1001
1003
|
if (dictionary[item.getKey()] == null) diff.add(item);
|
|
1002
1004
|
});
|
|
1003
1005
|
return diff;
|
|
1004
1006
|
}
|
|
1005
|
-
except(keys) {
|
|
1006
|
-
const
|
|
1007
|
+
except(...keys) {
|
|
1008
|
+
const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
|
|
1009
|
+
const dictionary = _h3ravel_support.Arr.except(this.getDictionary(), values);
|
|
1007
1010
|
return new this.constructor(Object.values(dictionary));
|
|
1008
1011
|
}
|
|
1009
1012
|
intersect(items) {
|
|
1010
1013
|
const intersect = new this.constructor();
|
|
1011
|
-
if (
|
|
1014
|
+
if (_h3ravel_support.Arr.isEmpty(items)) return intersect;
|
|
1012
1015
|
const dictionary = this.getDictionary(items);
|
|
1013
|
-
for (const item of this.
|
|
1016
|
+
for (const item of this.all()) if (dictionary[item.getKey()] != null) intersect.add(item);
|
|
1014
1017
|
return intersect;
|
|
1015
1018
|
}
|
|
1016
1019
|
unique(key, _strict = false) {
|
|
@@ -1019,14 +1022,14 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
1019
1022
|
}
|
|
1020
1023
|
find(key, defaultValue = null) {
|
|
1021
1024
|
if (key instanceof Model) key = key.getKey();
|
|
1022
|
-
if (
|
|
1025
|
+
if (Array.isArray(key)) {
|
|
1023
1026
|
if (this.isEmpty()) return new this.constructor();
|
|
1024
1027
|
return this.whereIn(this.first().getKeyName(), key);
|
|
1025
1028
|
}
|
|
1026
|
-
(0,
|
|
1029
|
+
(0, _h3ravel_collect_js.collect)(this.all()).first((model) => {
|
|
1027
1030
|
return model.getKey() == key;
|
|
1028
1031
|
});
|
|
1029
|
-
return this.
|
|
1032
|
+
return this.all().filter((model) => {
|
|
1030
1033
|
return model.getKey() == key;
|
|
1031
1034
|
})[0] || defaultValue;
|
|
1032
1035
|
}
|
|
@@ -1045,15 +1048,15 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
1045
1048
|
item.append(attributes);
|
|
1046
1049
|
});
|
|
1047
1050
|
}
|
|
1048
|
-
only(keys) {
|
|
1049
|
-
|
|
1050
|
-
const dictionary =
|
|
1051
|
+
only(...keys) {
|
|
1052
|
+
const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
|
|
1053
|
+
const dictionary = _h3ravel_support.Arr.select(this.getDictionary(), values);
|
|
1051
1054
|
return new this.constructor(Object.values(dictionary));
|
|
1052
1055
|
}
|
|
1053
1056
|
getDictionary(items) {
|
|
1054
|
-
|
|
1057
|
+
const values = !items ? this.all() : items instanceof _h3ravel_collect_js.Collection ? items.all() : items;
|
|
1055
1058
|
const dictionary = {};
|
|
1056
|
-
|
|
1059
|
+
values.map((value) => {
|
|
1057
1060
|
dictionary[value.getKey()] = value;
|
|
1058
1061
|
});
|
|
1059
1062
|
return dictionary;
|
|
@@ -1068,8 +1071,8 @@ var Collection = class Collection extends collect_js.Collection {
|
|
|
1068
1071
|
return JSON.stringify(this.toData(), ...args);
|
|
1069
1072
|
}
|
|
1070
1073
|
[Symbol.iterator] = () => {
|
|
1071
|
-
const items = this.
|
|
1072
|
-
const length =
|
|
1074
|
+
const items = this.all();
|
|
1075
|
+
const length = items.length;
|
|
1073
1076
|
let n = 0;
|
|
1074
1077
|
return { next() {
|
|
1075
1078
|
return n < length ? {
|
|
@@ -1192,7 +1195,7 @@ var pivot_default = Pivot;
|
|
|
1192
1195
|
const make = (model, data, options = {}) => {
|
|
1193
1196
|
const { paginated } = options;
|
|
1194
1197
|
if (paginated) return new Paginator(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
1195
|
-
if (
|
|
1198
|
+
if (Array.isArray(data)) return new Collection(data.map((item) => model.make(item)));
|
|
1196
1199
|
return model.make(data);
|
|
1197
1200
|
};
|
|
1198
1201
|
const makeCollection = (model, data) => new Collection(data.map((item) => model.make(item)));
|