@h3ravel/arquebus 0.1.6 → 0.2.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/.gitkeep +0 -0
- package/{dist/index.cjs → bin/cli.cjs} +1160 -802
- package/bin/cli.d.cts +18 -0
- package/bin/cli.d.ts +18 -0
- package/bin/cli.js +4887 -183
- package/bin/index.cjs +4948 -0
- package/bin/index.d.cts +2 -0
- package/bin/index.d.ts +2 -0
- package/bin/index.js +4923 -0
- package/bin/migrations/stubs/migration-js.stub +21 -0
- package/bin/migrations/stubs/migration-ts.stub +18 -0
- package/bin/migrations/stubs/migration.create-js.stub +24 -0
- package/bin/migrations/stubs/migration.create-ts.stub +21 -0
- package/bin/migrations/stubs/migration.update-js.stub +25 -0
- package/bin/migrations/stubs/migration.update-ts.stub +22 -0
- package/bin/stubs/arquebus.config-js.stub +25 -0
- package/bin/stubs/arquebus.config-ts.stub +24 -0
- package/bin/stubs/model-js.stub +5 -0
- package/bin/stubs/model-ts.stub +5 -0
- package/dist/browser/index.cjs +116 -96
- package/dist/browser/index.d.cts +1205 -165
- package/dist/browser/index.d.ts +1205 -165
- package/dist/browser/index.js +114 -95
- package/dist/index.d.ts +1279 -347
- package/dist/index.js +3757 -3546
- package/package.json +24 -9
- package/src/migrations/stubs/migration-js.stub +21 -0
- package/src/migrations/stubs/migration-ts.stub +18 -0
- package/src/migrations/stubs/migration.create-js.stub +24 -0
- package/src/migrations/stubs/migration.create-ts.stub +21 -0
- package/src/migrations/stubs/migration.update-js.stub +25 -0
- package/src/migrations/stubs/migration.update-ts.stub +22 -0
- package/src/stubs/arquebus.config-js.stub +25 -0
- package/src/stubs/arquebus.config-ts.stub +24 -0
- package/src/stubs/model-js.stub +5 -0
- package/src/stubs/model-ts.stub +5 -0
- package/dist/index.d.cts +0 -457
package/dist/browser/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// src/browser/index.
|
|
30
|
+
// src/browser/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
Attribute: () => attribute_default,
|
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
RelationNotFoundError: () => RelationNotFoundError,
|
|
43
43
|
compose: () => compose,
|
|
44
44
|
default: () => index_default,
|
|
45
|
+
defineConfig: () => defineConfig,
|
|
45
46
|
flattenDeep: () => flattenDeep,
|
|
46
47
|
getAttrMethod: () => getAttrMethod,
|
|
47
48
|
getAttrName: () => getAttrName,
|
|
@@ -62,24 +63,27 @@ __export(index_exports, {
|
|
|
62
63
|
});
|
|
63
64
|
module.exports = __toCommonJS(index_exports);
|
|
64
65
|
|
|
65
|
-
// src/casts/attribute.
|
|
66
|
+
// src/casts/attribute.ts
|
|
66
67
|
var Attribute = class _Attribute {
|
|
67
68
|
get;
|
|
68
69
|
set;
|
|
69
70
|
withCaching = false;
|
|
70
71
|
withObjectCaching = true;
|
|
71
|
-
constructor({
|
|
72
|
+
constructor({
|
|
73
|
+
get = null,
|
|
74
|
+
set = null
|
|
75
|
+
}) {
|
|
72
76
|
this.get = get;
|
|
73
77
|
this.set = set;
|
|
74
78
|
}
|
|
75
|
-
static make(get = null, set = null) {
|
|
76
|
-
return new _Attribute(get, set);
|
|
79
|
+
static make({ get = null, set = null }) {
|
|
80
|
+
return new _Attribute({ get, set });
|
|
77
81
|
}
|
|
78
82
|
static get(get) {
|
|
79
|
-
return new _Attribute(get);
|
|
83
|
+
return new _Attribute({ get });
|
|
80
84
|
}
|
|
81
85
|
static set(set) {
|
|
82
|
-
return new _Attribute(
|
|
86
|
+
return new _Attribute({ set });
|
|
83
87
|
}
|
|
84
88
|
withoutObjectCaching() {
|
|
85
89
|
this.withObjectCaching = false;
|
|
@@ -92,27 +96,27 @@ var Attribute = class _Attribute {
|
|
|
92
96
|
};
|
|
93
97
|
var attribute_default = Attribute;
|
|
94
98
|
|
|
95
|
-
// src/casts-attributes.
|
|
99
|
+
// src/casts-attributes.ts
|
|
96
100
|
var CastsAttributes = class _CastsAttributes {
|
|
97
101
|
constructor() {
|
|
98
102
|
if (this.constructor === _CastsAttributes) {
|
|
99
103
|
throw new Error("CastsAttributes cannot be instantiated");
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
|
-
static get() {
|
|
106
|
+
static get(_model, _key, _value, _attributes) {
|
|
103
107
|
throw new Error("get not implemented");
|
|
104
108
|
}
|
|
105
|
-
static set() {
|
|
109
|
+
static set(_model, _key, _value, _attributes) {
|
|
106
110
|
throw new Error("set not implemented");
|
|
107
111
|
}
|
|
108
112
|
};
|
|
109
113
|
var casts_attributes_default = CastsAttributes;
|
|
110
114
|
|
|
111
|
-
// src/browser/collection.
|
|
115
|
+
// src/browser/collection.ts
|
|
112
116
|
var import_collect2 = require("collect.js");
|
|
113
117
|
var import_radashi7 = require("radashi");
|
|
114
118
|
|
|
115
|
-
// src/utils.
|
|
119
|
+
// src/utils.ts
|
|
116
120
|
var import_radashi = require("radashi");
|
|
117
121
|
var import_advancedFormat = __toESM(require("dayjs/plugin/advancedFormat.js"), 1);
|
|
118
122
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
@@ -147,16 +151,16 @@ var tap = (instance, callback) => {
|
|
|
147
151
|
return result instanceof Promise ? result.then(() => instance) : instance;
|
|
148
152
|
};
|
|
149
153
|
function compose(Base, ...mixins) {
|
|
150
|
-
return mixins.reduce(
|
|
151
|
-
(cls, mixin) => mixin(cls),
|
|
152
|
-
Base
|
|
153
|
-
);
|
|
154
|
+
return mixins.reduce((acc, mixin) => mixin(acc), Base);
|
|
154
155
|
}
|
|
155
156
|
var flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
|
|
156
157
|
var kebabCase = (str) => (0, import_radashi.trim)((0, import_radashi.dash)(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
|
|
157
158
|
var snakeCase = (str) => (0, import_radashi.trim)((0, import_radashi.snake)(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
|
|
159
|
+
var defineConfig = (config) => {
|
|
160
|
+
return config;
|
|
161
|
+
};
|
|
158
162
|
|
|
159
|
-
// src/browser/relations/relation.
|
|
163
|
+
// src/browser/relations/relation.ts
|
|
160
164
|
var Relation = class {
|
|
161
165
|
parent;
|
|
162
166
|
related;
|
|
@@ -185,7 +189,7 @@ var Relation = class {
|
|
|
185
189
|
};
|
|
186
190
|
var relation_default = Relation;
|
|
187
191
|
|
|
188
|
-
// src/browser/relations/belongs-to.
|
|
192
|
+
// src/browser/relations/belongs-to.ts
|
|
189
193
|
var BelongsTo = class extends relation_default {
|
|
190
194
|
foreignKey;
|
|
191
195
|
ownerKey;
|
|
@@ -202,7 +206,7 @@ var BelongsTo = class extends relation_default {
|
|
|
202
206
|
};
|
|
203
207
|
var belongs_to_default = BelongsTo;
|
|
204
208
|
|
|
205
|
-
// src/browser/relations/belongs-to-many.
|
|
209
|
+
// src/browser/relations/belongs-to-many.ts
|
|
206
210
|
var BelongsToMany = class extends relation_default {
|
|
207
211
|
table;
|
|
208
212
|
foreignPivotKey;
|
|
@@ -215,7 +219,6 @@ var BelongsToMany = class extends relation_default {
|
|
|
215
219
|
pivotWhereIns = [];
|
|
216
220
|
pivotWhereNulls = [];
|
|
217
221
|
accessor = "pivot";
|
|
218
|
-
// withTimestamps = false;
|
|
219
222
|
using;
|
|
220
223
|
pivotCreatedAt;
|
|
221
224
|
pivotUpdatedAt;
|
|
@@ -231,7 +234,7 @@ var BelongsToMany = class extends relation_default {
|
|
|
231
234
|
};
|
|
232
235
|
var belongs_to_many_default = BelongsToMany;
|
|
233
236
|
|
|
234
|
-
// src/concerns/has-attributes.
|
|
237
|
+
// src/concerns/has-attributes.ts
|
|
235
238
|
var import_radashi2 = require("radashi");
|
|
236
239
|
var import_collect = __toESM(require("collect.js"), 1);
|
|
237
240
|
var import_dayjs2 = __toESM(require("dayjs"), 1);
|
|
@@ -345,8 +348,8 @@ var HasAttributes = (Model2) => {
|
|
|
345
348
|
}
|
|
346
349
|
const casts = this.getCasts();
|
|
347
350
|
const castType = casts[key];
|
|
348
|
-
if (this.isCustomCast(castType)) {
|
|
349
|
-
value = castType.set(this, key, value, this.attributes);
|
|
351
|
+
if (this.isCustomCast(castType) && typeof castType !== "string") {
|
|
352
|
+
value = castType.set(this, key, value, this.attributes) ?? "";
|
|
350
353
|
}
|
|
351
354
|
if (castType === "json") {
|
|
352
355
|
value = JSON.stringify(value);
|
|
@@ -414,13 +417,13 @@ var HasAttributes = (Model2) => {
|
|
|
414
417
|
case "json":
|
|
415
418
|
try {
|
|
416
419
|
return JSON.parse(value);
|
|
417
|
-
} catch
|
|
420
|
+
} catch {
|
|
418
421
|
return null;
|
|
419
422
|
}
|
|
420
423
|
case "collection":
|
|
421
424
|
try {
|
|
422
425
|
return (0, import_collect.default)(JSON.parse(value));
|
|
423
|
-
} catch
|
|
426
|
+
} catch {
|
|
424
427
|
return (0, import_collect.default)([]);
|
|
425
428
|
}
|
|
426
429
|
case "date":
|
|
@@ -459,11 +462,11 @@ var HasAttributes = (Model2) => {
|
|
|
459
462
|
continue;
|
|
460
463
|
}
|
|
461
464
|
attributes[key] = this.castAttribute(key, attributes[key]);
|
|
462
|
-
if (key in attributes && ["date", "datetime"].includes(value)) {
|
|
465
|
+
if (key in attributes && ["date", "datetime"].includes(String(value))) {
|
|
463
466
|
attributes[key] = this.serializeDate(attributes[key]);
|
|
464
467
|
}
|
|
465
468
|
if (key in attributes && this.isCustomDateTimeCast(value)) {
|
|
466
|
-
attributes[key] = (0, import_dayjs2.default)(attributes[key]).format(value.split(":")[1]);
|
|
469
|
+
attributes[key] = (0, import_dayjs2.default)(attributes[key]).format(String(value).split(":")[1]);
|
|
467
470
|
}
|
|
468
471
|
}
|
|
469
472
|
for (const key of this.appends) {
|
|
@@ -482,7 +485,7 @@ var HasAttributes = (Model2) => {
|
|
|
482
485
|
}
|
|
483
486
|
return value;
|
|
484
487
|
}
|
|
485
|
-
mutateAttributeForArray(
|
|
488
|
+
mutateAttributeForArray(_key, _value) {
|
|
486
489
|
}
|
|
487
490
|
isDateAttribute(key) {
|
|
488
491
|
return this.getDates().includes(key) || this.isDateCastable(key);
|
|
@@ -513,8 +516,8 @@ var HasAttributes = (Model2) => {
|
|
|
513
516
|
} else if (new castType() instanceof casts_attributes_default) {
|
|
514
517
|
castTypeCacheKey = castType.name;
|
|
515
518
|
}
|
|
516
|
-
if (castTypeCacheKey && this.
|
|
517
|
-
return this.
|
|
519
|
+
if (castTypeCacheKey && this.getConstructor().castTypeCache[castTypeCacheKey] !== void 0) {
|
|
520
|
+
return this.getConstructor().castTypeCache[castTypeCacheKey];
|
|
518
521
|
}
|
|
519
522
|
let convertedCastType;
|
|
520
523
|
if (this.isCustomDateTimeCast(castType)) {
|
|
@@ -524,9 +527,9 @@ var HasAttributes = (Model2) => {
|
|
|
524
527
|
} else if (this.isCustomCast(castType)) {
|
|
525
528
|
convertedCastType = castType;
|
|
526
529
|
} else {
|
|
527
|
-
convertedCastType = castType.toLocaleLowerCase().trim();
|
|
530
|
+
convertedCastType = String(castType).toLocaleLowerCase().trim();
|
|
528
531
|
}
|
|
529
|
-
return this.
|
|
532
|
+
return this.getConstructor()[castTypeCacheKey] = convertedCastType;
|
|
530
533
|
}
|
|
531
534
|
hasCast(key, types = []) {
|
|
532
535
|
if (key in this.casts) {
|
|
@@ -585,7 +588,7 @@ var HasAttributes = (Model2) => {
|
|
|
585
588
|
};
|
|
586
589
|
var has_attributes_default = HasAttributes;
|
|
587
590
|
|
|
588
|
-
// src/browser/relations/has-many.
|
|
591
|
+
// src/browser/relations/has-many.ts
|
|
589
592
|
var HasMany = class extends relation_default {
|
|
590
593
|
foreignKey;
|
|
591
594
|
localKey;
|
|
@@ -598,7 +601,7 @@ var HasMany = class extends relation_default {
|
|
|
598
601
|
};
|
|
599
602
|
var has_many_default = HasMany;
|
|
600
603
|
|
|
601
|
-
// src/browser/relations/has-one.
|
|
604
|
+
// src/browser/relations/has-one.ts
|
|
602
605
|
var HasOne = class extends relation_default {
|
|
603
606
|
foreignKey;
|
|
604
607
|
localKey;
|
|
@@ -611,7 +614,7 @@ var HasOne = class extends relation_default {
|
|
|
611
614
|
};
|
|
612
615
|
var has_one_default = HasOne;
|
|
613
616
|
|
|
614
|
-
// src/browser/relations/has-many-through.
|
|
617
|
+
// src/browser/relations/has-many-through.ts
|
|
615
618
|
var HasManyThrough = class extends relation_default {
|
|
616
619
|
throughParent;
|
|
617
620
|
farParent;
|
|
@@ -632,15 +635,15 @@ var HasManyThrough = class extends relation_default {
|
|
|
632
635
|
};
|
|
633
636
|
var has_many_through_default = HasManyThrough;
|
|
634
637
|
|
|
635
|
-
// src/browser/relations/has-one-through.
|
|
638
|
+
// src/browser/relations/has-one-through.ts
|
|
636
639
|
var HasOneThrough = class extends has_many_through_default {
|
|
637
640
|
};
|
|
638
641
|
var has_one_through_default = HasOneThrough;
|
|
639
642
|
|
|
640
|
-
// src/errors.
|
|
643
|
+
// src/errors.ts
|
|
641
644
|
var import_radashi3 = require("radashi");
|
|
642
645
|
var BaseError = class extends Error {
|
|
643
|
-
constructor(message,
|
|
646
|
+
constructor(message, _entity) {
|
|
644
647
|
super(message);
|
|
645
648
|
Error.captureStackTrace(this, this.constructor);
|
|
646
649
|
this.name = this.constructor.name;
|
|
@@ -649,7 +652,10 @@ var BaseError = class extends Error {
|
|
|
649
652
|
};
|
|
650
653
|
var ModelNotFoundError = class extends BaseError {
|
|
651
654
|
model;
|
|
652
|
-
ids;
|
|
655
|
+
ids = [];
|
|
656
|
+
constructor() {
|
|
657
|
+
super("");
|
|
658
|
+
}
|
|
653
659
|
setModel(model, ids = []) {
|
|
654
660
|
this.model = model;
|
|
655
661
|
this.ids = (0, import_radashi3.isArray)(ids) ? ids : [ids];
|
|
@@ -673,7 +679,7 @@ var RelationNotFoundError = class extends BaseError {
|
|
|
673
679
|
var InvalidArgumentError = class extends BaseError {
|
|
674
680
|
};
|
|
675
681
|
|
|
676
|
-
// src/browser/concerns/has-relations.
|
|
682
|
+
// src/browser/concerns/has-relations.ts
|
|
677
683
|
var import_radashi4 = require("radashi");
|
|
678
684
|
var HasRelations = (Model2) => {
|
|
679
685
|
return class extends Model2 {
|
|
@@ -716,9 +722,9 @@ var HasRelations = (Model2) => {
|
|
|
716
722
|
return data;
|
|
717
723
|
}
|
|
718
724
|
guessBelongsToRelation() {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
725
|
+
const e = new Error();
|
|
726
|
+
const frame = e.stack?.split("\n")[2];
|
|
727
|
+
const functionName = frame?.split(" ")[5];
|
|
722
728
|
return getRelationName(functionName);
|
|
723
729
|
}
|
|
724
730
|
joiningTable(related, instance = null) {
|
|
@@ -778,7 +784,7 @@ var HasRelations = (Model2) => {
|
|
|
778
784
|
};
|
|
779
785
|
var has_relations_default = HasRelations;
|
|
780
786
|
|
|
781
|
-
// src/concerns/has-timestamps.
|
|
787
|
+
// src/concerns/has-timestamps.ts
|
|
782
788
|
var HasTimestamps = (Model2) => {
|
|
783
789
|
return class extends Model2 {
|
|
784
790
|
static CREATED_AT = "created_at";
|
|
@@ -827,7 +833,7 @@ var HasTimestamps = (Model2) => {
|
|
|
827
833
|
};
|
|
828
834
|
var has_timestamps_default = HasTimestamps;
|
|
829
835
|
|
|
830
|
-
// src/concerns/hides-attributes.
|
|
836
|
+
// src/concerns/hides-attributes.ts
|
|
831
837
|
var import_radashi5 = require("radashi");
|
|
832
838
|
var HidesAttributes = (Model2) => {
|
|
833
839
|
return class extends Model2 {
|
|
@@ -841,8 +847,8 @@ var HidesAttributes = (Model2) => {
|
|
|
841
847
|
this.hidden = (0, import_radashi5.diff)(this.hidden, visible);
|
|
842
848
|
return this;
|
|
843
849
|
}
|
|
844
|
-
makeHidden(...keys) {
|
|
845
|
-
const hidden = flattenDeep(keys);
|
|
850
|
+
makeHidden(key, ...keys) {
|
|
851
|
+
const hidden = flattenDeep([...key, ...keys]);
|
|
846
852
|
if (this.hidden.length > 0) {
|
|
847
853
|
this.hidden = [...this.hidden, ...hidden];
|
|
848
854
|
}
|
|
@@ -866,25 +872,34 @@ var HidesAttributes = (Model2) => {
|
|
|
866
872
|
};
|
|
867
873
|
var hides_attributes_default = HidesAttributes;
|
|
868
874
|
|
|
869
|
-
// src/browser/model.
|
|
875
|
+
// src/browser/model.ts
|
|
870
876
|
var import_radashi6 = require("radashi");
|
|
871
877
|
var import_pluralize = __toESM(require("pluralize"), 1);
|
|
872
|
-
var BaseModel = compose(
|
|
873
|
-
|
|
878
|
+
var BaseModel = compose(
|
|
879
|
+
class {
|
|
880
|
+
},
|
|
881
|
+
has_attributes_default,
|
|
882
|
+
hides_attributes_default,
|
|
883
|
+
has_relations_default,
|
|
884
|
+
has_timestamps_default
|
|
885
|
+
);
|
|
874
886
|
var Model = class _Model extends BaseModel {
|
|
875
887
|
primaryKey = "id";
|
|
876
|
-
// protected
|
|
877
|
-
table = null;
|
|
878
|
-
// protected
|
|
879
|
-
keyType = "int";
|
|
880
|
-
// protected
|
|
881
888
|
perPage = 15;
|
|
882
|
-
// protected
|
|
883
889
|
static globalScopes = {};
|
|
884
890
|
static pluginInitializers = {};
|
|
885
891
|
static _booted = {};
|
|
886
|
-
static resolver
|
|
892
|
+
static resolver;
|
|
887
893
|
static browser = true;
|
|
894
|
+
connection = null;
|
|
895
|
+
constructor(attributes = {}) {
|
|
896
|
+
super();
|
|
897
|
+
this.bootIfNotBooted();
|
|
898
|
+
this.initializePlugins();
|
|
899
|
+
this.syncOriginal();
|
|
900
|
+
this.fill(attributes);
|
|
901
|
+
return this.asProxy();
|
|
902
|
+
}
|
|
888
903
|
static init(attributes = {}) {
|
|
889
904
|
return new this(attributes);
|
|
890
905
|
}
|
|
@@ -893,7 +908,7 @@ var Model = class _Model extends BaseModel {
|
|
|
893
908
|
}
|
|
894
909
|
static make(attributes = {}) {
|
|
895
910
|
const instance = new this();
|
|
896
|
-
for (
|
|
911
|
+
for (const attribute in attributes) {
|
|
897
912
|
if (typeof instance[getRelationMethod(attribute)] !== "function") {
|
|
898
913
|
instance.setAttribute(attribute, attributes[attribute]);
|
|
899
914
|
} else {
|
|
@@ -907,14 +922,6 @@ var Model = class _Model extends BaseModel {
|
|
|
907
922
|
}
|
|
908
923
|
return instance;
|
|
909
924
|
}
|
|
910
|
-
constructor(attributes = {}) {
|
|
911
|
-
super();
|
|
912
|
-
this.bootIfNotBooted();
|
|
913
|
-
this.initializePlugins();
|
|
914
|
-
this.syncOriginal();
|
|
915
|
-
this.fill(attributes);
|
|
916
|
-
return this.asProxy();
|
|
917
|
-
}
|
|
918
925
|
bootIfNotBooted() {
|
|
919
926
|
if (this.constructor._booted[this.constructor.name] === void 0) {
|
|
920
927
|
this.constructor._booted[this.constructor.name] = true;
|
|
@@ -1099,7 +1106,7 @@ var Pivot = class extends Model {
|
|
|
1099
1106
|
};
|
|
1100
1107
|
var model_default = Model;
|
|
1101
1108
|
|
|
1102
|
-
// src/browser/collection.
|
|
1109
|
+
// src/browser/collection.ts
|
|
1103
1110
|
var Collection = class _Collection extends import_collect2.Collection {
|
|
1104
1111
|
mapThen(callback) {
|
|
1105
1112
|
return Promise.all(this.map(callback));
|
|
@@ -1107,9 +1114,9 @@ var Collection = class _Collection extends import_collect2.Collection {
|
|
|
1107
1114
|
modelKeys() {
|
|
1108
1115
|
return this.all().map((item) => item.getKey());
|
|
1109
1116
|
}
|
|
1110
|
-
contains(key, operator
|
|
1117
|
+
contains(key, operator, value) {
|
|
1111
1118
|
if (arguments.length > 1) {
|
|
1112
|
-
return super.contains(key, operator
|
|
1119
|
+
return super.contains(key, value ?? operator);
|
|
1113
1120
|
}
|
|
1114
1121
|
if (key instanceof model_default) {
|
|
1115
1122
|
return super.contains((model) => {
|
|
@@ -1140,22 +1147,21 @@ var Collection = class _Collection extends import_collect2.Collection {
|
|
|
1140
1147
|
return intersect;
|
|
1141
1148
|
}
|
|
1142
1149
|
const dictionary = this.getDictionary(items);
|
|
1143
|
-
for (
|
|
1150
|
+
for (const item of this.items) {
|
|
1144
1151
|
if (dictionary[item.getKey()] !== void 0) {
|
|
1145
1152
|
intersect.add(item);
|
|
1146
1153
|
}
|
|
1147
1154
|
}
|
|
1148
1155
|
return intersect;
|
|
1149
1156
|
}
|
|
1150
|
-
unique(key
|
|
1151
|
-
if (key
|
|
1152
|
-
return super.unique(key
|
|
1157
|
+
unique(key, _strict = false) {
|
|
1158
|
+
if (key) {
|
|
1159
|
+
return super.unique(key);
|
|
1153
1160
|
}
|
|
1154
1161
|
return new this.constructor(Object.values(this.getDictionary()));
|
|
1155
1162
|
}
|
|
1156
1163
|
find(key, defaultValue = null) {
|
|
1157
|
-
|
|
1158
|
-
if (key instanceof Model2) {
|
|
1164
|
+
if (key instanceof model_default) {
|
|
1159
1165
|
key = key.getKey();
|
|
1160
1166
|
}
|
|
1161
1167
|
if ((0, import_radashi7.isArray)(key)) {
|
|
@@ -1193,8 +1199,8 @@ var Collection = class _Collection extends import_collect2.Collection {
|
|
|
1193
1199
|
const dictionary = (0, import_radashi7.pick)(this.getDictionary(), keys);
|
|
1194
1200
|
return new this.constructor(Object.values(dictionary));
|
|
1195
1201
|
}
|
|
1196
|
-
getDictionary(items
|
|
1197
|
-
items = items
|
|
1202
|
+
getDictionary(items) {
|
|
1203
|
+
items = !items ? this.items : items;
|
|
1198
1204
|
const dictionary = {};
|
|
1199
1205
|
items.map((value) => {
|
|
1200
1206
|
dictionary[value.getKey()] = value;
|
|
@@ -1210,9 +1216,9 @@ var Collection = class _Collection extends import_collect2.Collection {
|
|
|
1210
1216
|
toJson(...args) {
|
|
1211
1217
|
return JSON.stringify(this.toData(), ...args);
|
|
1212
1218
|
}
|
|
1213
|
-
[Symbol.iterator]() {
|
|
1219
|
+
[Symbol.iterator] = () => {
|
|
1214
1220
|
const items = this.items;
|
|
1215
|
-
|
|
1221
|
+
const length = this.items.length;
|
|
1216
1222
|
let n = 0;
|
|
1217
1223
|
return {
|
|
1218
1224
|
next() {
|
|
@@ -1224,11 +1230,11 @@ var Collection = class _Collection extends import_collect2.Collection {
|
|
|
1224
1230
|
};
|
|
1225
1231
|
}
|
|
1226
1232
|
};
|
|
1227
|
-
}
|
|
1233
|
+
};
|
|
1228
1234
|
};
|
|
1229
1235
|
var collection_default = Collection;
|
|
1230
1236
|
|
|
1231
|
-
// src/concerns/has-unique-ids.
|
|
1237
|
+
// src/concerns/has-unique-ids.ts
|
|
1232
1238
|
var HasUniqueIds = (Model2) => {
|
|
1233
1239
|
return class extends Model2 {
|
|
1234
1240
|
useUniqueIds = true;
|
|
@@ -1251,32 +1257,35 @@ var HasUniqueIds = (Model2) => {
|
|
|
1251
1257
|
};
|
|
1252
1258
|
var has_unique_ids_default = HasUniqueIds;
|
|
1253
1259
|
|
|
1254
|
-
// src/browser/paginator.
|
|
1260
|
+
// src/browser/paginator.ts
|
|
1255
1261
|
var Paginator = class {
|
|
1256
|
-
static formatter
|
|
1262
|
+
static formatter;
|
|
1257
1263
|
_items;
|
|
1258
1264
|
_total;
|
|
1259
1265
|
_perPage;
|
|
1260
1266
|
_lastPage;
|
|
1261
1267
|
_currentPage;
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
}
|
|
1266
|
-
this.formatter = formatter;
|
|
1267
|
-
}
|
|
1268
|
-
constructor(items, total, perPage, currentPage = null, options = {}) {
|
|
1268
|
+
hasMore = false;
|
|
1269
|
+
options = {};
|
|
1270
|
+
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
1269
1271
|
this.options = options;
|
|
1270
1272
|
for (const key in options) {
|
|
1271
1273
|
const value = options[key];
|
|
1272
1274
|
this[key] = value;
|
|
1273
1275
|
}
|
|
1276
|
+
this._items = new collection_default([]);
|
|
1274
1277
|
this._total = total;
|
|
1275
|
-
this._perPage = parseInt(perPage);
|
|
1278
|
+
this._perPage = parseInt(String(perPage));
|
|
1276
1279
|
this._lastPage = Math.max(Math.ceil(total / perPage), 1);
|
|
1277
1280
|
this._currentPage = currentPage;
|
|
1278
1281
|
this.setItems(items);
|
|
1279
1282
|
}
|
|
1283
|
+
static setFormatter(formatter) {
|
|
1284
|
+
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) {
|
|
1285
|
+
throw new Error("Paginator formatter must be a function or null");
|
|
1286
|
+
}
|
|
1287
|
+
this.formatter = formatter;
|
|
1288
|
+
}
|
|
1280
1289
|
setItems(items) {
|
|
1281
1290
|
this._items = items instanceof collection_default ? items : new collection_default(items);
|
|
1282
1291
|
this.hasMore = this._items.count() > this._perPage;
|
|
@@ -1286,7 +1295,7 @@ var Paginator = class {
|
|
|
1286
1295
|
return this.count() > 0 ? (this._currentPage - 1) * this._perPage + 1 : null;
|
|
1287
1296
|
}
|
|
1288
1297
|
lastItem() {
|
|
1289
|
-
return this.count() > 0 ? this.firstItem() + this.count() - 1 : null;
|
|
1298
|
+
return this.count() > 0 ? (this.firstItem() ?? 0) + this.count() - 1 : null;
|
|
1290
1299
|
}
|
|
1291
1300
|
hasMorePages() {
|
|
1292
1301
|
return this._currentPage < this._lastPage;
|
|
@@ -1340,15 +1349,20 @@ var Paginator = class {
|
|
|
1340
1349
|
};
|
|
1341
1350
|
var paginator_default = Paginator;
|
|
1342
1351
|
|
|
1343
|
-
// src/browser/pivot.
|
|
1352
|
+
// src/browser/pivot.ts
|
|
1344
1353
|
var pivot_default = Pivot;
|
|
1345
1354
|
|
|
1346
|
-
// src/browser/index.
|
|
1355
|
+
// src/browser/index.ts
|
|
1347
1356
|
var import_radashi8 = require("radashi");
|
|
1348
1357
|
var make = (model, data, options = {}) => {
|
|
1349
1358
|
const { paginated } = options;
|
|
1350
1359
|
if (paginated) {
|
|
1351
|
-
return new paginator_default(
|
|
1360
|
+
return new paginator_default(
|
|
1361
|
+
data.data.map((item) => model.make(item)),
|
|
1362
|
+
data.total,
|
|
1363
|
+
data.per_page,
|
|
1364
|
+
data.current_page
|
|
1365
|
+
);
|
|
1352
1366
|
}
|
|
1353
1367
|
if ((0, import_radashi8.isArray)(data)) {
|
|
1354
1368
|
return new collection_default(data.map((item) => model.make(item)));
|
|
@@ -1356,7 +1370,12 @@ var make = (model, data, options = {}) => {
|
|
|
1356
1370
|
return model.make(data);
|
|
1357
1371
|
};
|
|
1358
1372
|
var makeCollection = (model, data) => new collection_default(data.map((item) => model.make(item)));
|
|
1359
|
-
var makePaginator = (model, data) => new paginator_default(
|
|
1373
|
+
var makePaginator = (model, data) => new paginator_default(
|
|
1374
|
+
data.data.map((item) => model.make(item)),
|
|
1375
|
+
data.total,
|
|
1376
|
+
data.per_page,
|
|
1377
|
+
data.current_page
|
|
1378
|
+
);
|
|
1360
1379
|
var isBrowser = true;
|
|
1361
1380
|
var index_default = {
|
|
1362
1381
|
isBrowser,
|
|
@@ -1384,6 +1403,7 @@ var index_default = {
|
|
|
1384
1403
|
Pivot,
|
|
1385
1404
|
RelationNotFoundError,
|
|
1386
1405
|
compose,
|
|
1406
|
+
defineConfig,
|
|
1387
1407
|
flattenDeep,
|
|
1388
1408
|
getAttrMethod,
|
|
1389
1409
|
getAttrName,
|