@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.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Collection as Collection$1, collect } from "@h3ravel/collect.js";
|
|
2
|
+
import { Arr, Obj, Str } from "@h3ravel/support";
|
|
3
|
+
import * as dayjsModule from "dayjs";
|
|
4
|
+
import * as advancedFormatModule from "dayjs/plugin/advancedFormat.js";
|
|
5
5
|
import pluralize from "pluralize";
|
|
6
6
|
//#region \0rolldown/runtime.js
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
@@ -135,29 +135,33 @@ function compose$1(Base, ...mixins) {
|
|
|
135
135
|
}, Base);
|
|
136
136
|
}
|
|
137
137
|
//#endregion
|
|
138
|
-
//#region src/
|
|
138
|
+
//#region src/dayjs.ts
|
|
139
|
+
const dayjs = dayjsModule.default ?? dayjsModule;
|
|
140
|
+
const advancedFormat = advancedFormatModule.default ?? advancedFormatModule;
|
|
139
141
|
dayjs.extend(advancedFormat);
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/utils.ts
|
|
140
144
|
const now = (format = "YYYY-MM-DD HH:mm:ss") => dayjs().format(format);
|
|
141
145
|
const getRelationName = (relationMethod) => {
|
|
142
|
-
return snake(relationMethod.substring(8));
|
|
146
|
+
return Str.snake(relationMethod.substring(8));
|
|
143
147
|
};
|
|
144
148
|
const getScopeName = (scopeMethod) => {
|
|
145
|
-
return snake(scopeMethod.substring(5));
|
|
149
|
+
return Str.snake(scopeMethod.substring(5));
|
|
146
150
|
};
|
|
147
151
|
const getRelationMethod = (relation) => {
|
|
148
|
-
return camel(`relation_${relation}`);
|
|
152
|
+
return Str.camel(`relation_${relation}`);
|
|
149
153
|
};
|
|
150
154
|
const getScopeMethod = (scope) => {
|
|
151
|
-
return camel(`scope_${scope}`);
|
|
155
|
+
return Str.camel(`scope_${scope}`);
|
|
152
156
|
};
|
|
153
157
|
const getAttrMethod = (attr) => {
|
|
154
|
-
return camel(`attribute_${attr}`);
|
|
158
|
+
return Str.camel(`attribute_${attr}`);
|
|
155
159
|
};
|
|
156
160
|
const getGetterMethod = (attr) => {
|
|
157
|
-
return camel(`get_${attr}_attribute`);
|
|
161
|
+
return Str.camel(`get_${attr}_attribute`);
|
|
158
162
|
};
|
|
159
163
|
const getSetterMethod = (attr) => {
|
|
160
|
-
return camel(`set_${attr}_attribute`);
|
|
164
|
+
return Str.camel(`set_${attr}_attribute`);
|
|
161
165
|
};
|
|
162
166
|
const getAttrName = (attrMethod) => {
|
|
163
167
|
return attrMethod.substring(3, attrMethod.length - 9).toLowerCase();
|
|
@@ -176,8 +180,8 @@ const tap = (instance, callback) => {
|
|
|
176
180
|
const { compose } = mixin_exports;
|
|
177
181
|
const flatten = (arr) => arr.flat();
|
|
178
182
|
const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
|
|
179
|
-
const kebabCase = (str) => trim(
|
|
180
|
-
const snakeCase = (str) => trim(snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
|
|
183
|
+
const kebabCase = (str) => Str.trim(Str.kebab(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/-+/g, "-");
|
|
184
|
+
const snakeCase = (str) => Str.trim(Str.snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/_+/g, "_");
|
|
181
185
|
const defineConfig = (config) => {
|
|
182
186
|
return config;
|
|
183
187
|
};
|
|
@@ -265,8 +269,7 @@ const HasAttributes = (Model) => {
|
|
|
265
269
|
return this;
|
|
266
270
|
}
|
|
267
271
|
normalizeCastClassResponse(key, value) {
|
|
268
|
-
|
|
269
|
-
return (value === null || value === void 0 || (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) === "Object" ? value : { [key]: value };
|
|
272
|
+
return value?.constructor?.name === "Object" ? value : { [key]: value };
|
|
270
273
|
}
|
|
271
274
|
syncOriginal() {
|
|
272
275
|
this.original = this.getAttributes();
|
|
@@ -376,9 +379,9 @@ const HasAttributes = (Model) => {
|
|
|
376
379
|
return null;
|
|
377
380
|
}
|
|
378
381
|
case "collection": try {
|
|
379
|
-
return collect
|
|
382
|
+
return collect(JSON.parse(value));
|
|
380
383
|
} catch {
|
|
381
|
-
return collect
|
|
384
|
+
return collect([]);
|
|
382
385
|
}
|
|
383
386
|
case "date": return this.asDate(value);
|
|
384
387
|
case "datetime":
|
|
@@ -391,8 +394,8 @@ const HasAttributes = (Model) => {
|
|
|
391
394
|
attributesToData() {
|
|
392
395
|
let attributes = { ...this.attributes };
|
|
393
396
|
for (const key in attributes) {
|
|
394
|
-
if (this.hidden.includes(key)) attributes =
|
|
395
|
-
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes =
|
|
397
|
+
if (this.hidden.includes(key)) attributes = Arr.except(attributes, [key]);
|
|
398
|
+
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = Arr.except(attributes, [key]);
|
|
396
399
|
}
|
|
397
400
|
for (const key of this.getDates()) {
|
|
398
401
|
if (attributes[key] === void 0) continue;
|
|
@@ -447,7 +450,7 @@ const HasAttributes = (Model) => {
|
|
|
447
450
|
}
|
|
448
451
|
hasCast(key, types = []) {
|
|
449
452
|
if (key in this.casts) {
|
|
450
|
-
types =
|
|
453
|
+
types = flatten(types);
|
|
451
454
|
return types.length > 0 ? types.includes(this.getCastType(key)) : true;
|
|
452
455
|
}
|
|
453
456
|
return false;
|
|
@@ -554,7 +557,7 @@ var ModelNotFoundError = class extends BaseError {
|
|
|
554
557
|
}
|
|
555
558
|
setModel(model, ids = []) {
|
|
556
559
|
this.model = model;
|
|
557
|
-
this.ids = isArray(ids) ? ids : [ids];
|
|
560
|
+
this.ids = Array.isArray(ids) ? ids : [ids];
|
|
558
561
|
this.message = `No query results for model [${model}]`;
|
|
559
562
|
if (this.ids.length > 0) this.message += " " + this.ids.join(", ");
|
|
560
563
|
else this.message += ".";
|
|
@@ -582,7 +585,7 @@ const HasRelations = (Instance) => {
|
|
|
582
585
|
return this;
|
|
583
586
|
}
|
|
584
587
|
unsetRelation(relation) {
|
|
585
|
-
this.relations =
|
|
588
|
+
this.relations = Arr.except(this.relations, [relation]);
|
|
586
589
|
return this;
|
|
587
590
|
}
|
|
588
591
|
relationLoaded(relation) {
|
|
@@ -615,9 +618,9 @@ const HasRelations = (Instance) => {
|
|
|
615
618
|
else if (frame.includes("at ")) {
|
|
616
619
|
const match = frame.match(/at\s+([^(]+)\s*\(/);
|
|
617
620
|
functionName = match ? match[1].trim() : "anonymous";
|
|
618
|
-
if (functionName
|
|
621
|
+
if (functionName?.includes(".")) functionName = functionName.split(".").pop();
|
|
619
622
|
}
|
|
620
|
-
functionName = functionName
|
|
623
|
+
functionName = functionName?.replace(/^</, "").replace(/>$/, "").trim();
|
|
621
624
|
return getRelationName(functionName || "anonymous");
|
|
622
625
|
}
|
|
623
626
|
joiningTable(related, instance = null) {
|
|
@@ -724,7 +727,7 @@ const HidesAttributes = (Model) => {
|
|
|
724
727
|
makeVisible(...keys) {
|
|
725
728
|
const visible = flattenDeep(keys);
|
|
726
729
|
if (this.visible.length > 0) this.visible = [...this.visible, ...visible];
|
|
727
|
-
this.hidden =
|
|
730
|
+
this.hidden = collect(this.hidden).diff(visible).all();
|
|
728
731
|
return this;
|
|
729
732
|
}
|
|
730
733
|
makeHidden(key, ...keys) {
|
|
@@ -880,7 +883,7 @@ var Model = class Model extends BaseModel {
|
|
|
880
883
|
return this;
|
|
881
884
|
}
|
|
882
885
|
toData() {
|
|
883
|
-
return
|
|
886
|
+
return Obj.deepMerge(this.attributesToData(), this.relationsToData());
|
|
884
887
|
}
|
|
885
888
|
toJSON() {
|
|
886
889
|
return this.toData();
|
|
@@ -951,7 +954,7 @@ var Pivot = class extends Model {
|
|
|
951
954
|
};
|
|
952
955
|
//#endregion
|
|
953
956
|
//#region src/browser/collection.ts
|
|
954
|
-
var Collection = class
|
|
957
|
+
var Collection = class extends Collection$1 {
|
|
955
958
|
mapThen(callback) {
|
|
956
959
|
return Promise.all(this.map(callback));
|
|
957
960
|
}
|
|
@@ -970,20 +973,21 @@ var Collection = class Collection extends Collection$1 {
|
|
|
970
973
|
diff(items) {
|
|
971
974
|
const diff = new this.constructor();
|
|
972
975
|
const dictionary = this.getDictionary(items);
|
|
973
|
-
this.
|
|
976
|
+
this.all().map((item) => {
|
|
974
977
|
if (dictionary[item.getKey()] == null) diff.add(item);
|
|
975
978
|
});
|
|
976
979
|
return diff;
|
|
977
980
|
}
|
|
978
|
-
except(keys) {
|
|
979
|
-
const
|
|
981
|
+
except(...keys) {
|
|
982
|
+
const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
|
|
983
|
+
const dictionary = Arr.except(this.getDictionary(), values);
|
|
980
984
|
return new this.constructor(Object.values(dictionary));
|
|
981
985
|
}
|
|
982
986
|
intersect(items) {
|
|
983
987
|
const intersect = new this.constructor();
|
|
984
|
-
if (isEmpty(items)) return intersect;
|
|
988
|
+
if (Arr.isEmpty(items)) return intersect;
|
|
985
989
|
const dictionary = this.getDictionary(items);
|
|
986
|
-
for (const item of this.
|
|
990
|
+
for (const item of this.all()) if (dictionary[item.getKey()] != null) intersect.add(item);
|
|
987
991
|
return intersect;
|
|
988
992
|
}
|
|
989
993
|
unique(key, _strict = false) {
|
|
@@ -992,14 +996,14 @@ var Collection = class Collection extends Collection$1 {
|
|
|
992
996
|
}
|
|
993
997
|
find(key, defaultValue = null) {
|
|
994
998
|
if (key instanceof Model) key = key.getKey();
|
|
995
|
-
if (isArray(key)) {
|
|
999
|
+
if (Array.isArray(key)) {
|
|
996
1000
|
if (this.isEmpty()) return new this.constructor();
|
|
997
1001
|
return this.whereIn(this.first().getKeyName(), key);
|
|
998
1002
|
}
|
|
999
|
-
collect(this.
|
|
1003
|
+
collect(this.all()).first((model) => {
|
|
1000
1004
|
return model.getKey() == key;
|
|
1001
1005
|
});
|
|
1002
|
-
return this.
|
|
1006
|
+
return this.all().filter((model) => {
|
|
1003
1007
|
return model.getKey() == key;
|
|
1004
1008
|
})[0] || defaultValue;
|
|
1005
1009
|
}
|
|
@@ -1018,15 +1022,15 @@ var Collection = class Collection extends Collection$1 {
|
|
|
1018
1022
|
item.append(attributes);
|
|
1019
1023
|
});
|
|
1020
1024
|
}
|
|
1021
|
-
only(keys) {
|
|
1022
|
-
|
|
1023
|
-
const dictionary =
|
|
1025
|
+
only(...keys) {
|
|
1026
|
+
const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
|
|
1027
|
+
const dictionary = Arr.select(this.getDictionary(), values);
|
|
1024
1028
|
return new this.constructor(Object.values(dictionary));
|
|
1025
1029
|
}
|
|
1026
1030
|
getDictionary(items) {
|
|
1027
|
-
|
|
1031
|
+
const values = !items ? this.all() : items instanceof Collection$1 ? items.all() : items;
|
|
1028
1032
|
const dictionary = {};
|
|
1029
|
-
|
|
1033
|
+
values.map((value) => {
|
|
1030
1034
|
dictionary[value.getKey()] = value;
|
|
1031
1035
|
});
|
|
1032
1036
|
return dictionary;
|
|
@@ -1041,8 +1045,8 @@ var Collection = class Collection extends Collection$1 {
|
|
|
1041
1045
|
return JSON.stringify(this.toData(), ...args);
|
|
1042
1046
|
}
|
|
1043
1047
|
[Symbol.iterator] = () => {
|
|
1044
|
-
const items = this.
|
|
1045
|
-
const length =
|
|
1048
|
+
const items = this.all();
|
|
1049
|
+
const length = items.length;
|
|
1046
1050
|
let n = 0;
|
|
1047
1051
|
return { next() {
|
|
1048
1052
|
return n < length ? {
|
|
@@ -1165,7 +1169,7 @@ var pivot_default = Pivot;
|
|
|
1165
1169
|
const make = (model, data, options = {}) => {
|
|
1166
1170
|
const { paginated } = options;
|
|
1167
1171
|
if (paginated) return new Paginator(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
1168
|
-
if (isArray(data)) return new Collection(data.map((item) => model.make(item)));
|
|
1172
|
+
if (Array.isArray(data)) return new Collection(data.map((item) => model.make(item)));
|
|
1169
1173
|
return model.make(data);
|
|
1170
1174
|
};
|
|
1171
1175
|
const makeCollection = (model, data) => new Collection(data.map((item) => model.make(item)));
|