@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.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
// src/casts/attribute.
|
|
1
|
+
// src/casts/attribute.ts
|
|
2
2
|
var Attribute = class _Attribute {
|
|
3
3
|
get;
|
|
4
4
|
set;
|
|
5
5
|
withCaching = false;
|
|
6
6
|
withObjectCaching = true;
|
|
7
|
-
constructor({
|
|
7
|
+
constructor({
|
|
8
|
+
get = null,
|
|
9
|
+
set = null
|
|
10
|
+
}) {
|
|
8
11
|
this.get = get;
|
|
9
12
|
this.set = set;
|
|
10
13
|
}
|
|
11
|
-
static make(get = null, set = null) {
|
|
12
|
-
return new _Attribute(get, set);
|
|
14
|
+
static make({ get = null, set = null }) {
|
|
15
|
+
return new _Attribute({ get, set });
|
|
13
16
|
}
|
|
14
17
|
static get(get) {
|
|
15
|
-
return new _Attribute(get);
|
|
18
|
+
return new _Attribute({ get });
|
|
16
19
|
}
|
|
17
20
|
static set(set) {
|
|
18
|
-
return new _Attribute(
|
|
21
|
+
return new _Attribute({ set });
|
|
19
22
|
}
|
|
20
23
|
withoutObjectCaching() {
|
|
21
24
|
this.withObjectCaching = false;
|
|
@@ -28,27 +31,27 @@ var Attribute = class _Attribute {
|
|
|
28
31
|
};
|
|
29
32
|
var attribute_default = Attribute;
|
|
30
33
|
|
|
31
|
-
// src/casts-attributes.
|
|
34
|
+
// src/casts-attributes.ts
|
|
32
35
|
var CastsAttributes = class _CastsAttributes {
|
|
33
36
|
constructor() {
|
|
34
37
|
if (this.constructor === _CastsAttributes) {
|
|
35
38
|
throw new Error("CastsAttributes cannot be instantiated");
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
|
-
static get() {
|
|
41
|
+
static get(_model, _key, _value, _attributes) {
|
|
39
42
|
throw new Error("get not implemented");
|
|
40
43
|
}
|
|
41
|
-
static set() {
|
|
44
|
+
static set(_model, _key, _value, _attributes) {
|
|
42
45
|
throw new Error("set not implemented");
|
|
43
46
|
}
|
|
44
47
|
};
|
|
45
48
|
var casts_attributes_default = CastsAttributes;
|
|
46
49
|
|
|
47
|
-
// src/browser/collection.
|
|
50
|
+
// src/browser/collection.ts
|
|
48
51
|
import { Collection as BaseCollection, collect as collect2 } from "collect.js";
|
|
49
52
|
import { isArray as isArray2, isEmpty, omit as omit3, pick } from "radashi";
|
|
50
53
|
|
|
51
|
-
// src/utils.
|
|
54
|
+
// src/utils.ts
|
|
52
55
|
import { camel, dash, snake, trim } from "radashi";
|
|
53
56
|
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
54
57
|
import dayjs from "dayjs";
|
|
@@ -83,16 +86,16 @@ var tap = (instance, callback) => {
|
|
|
83
86
|
return result instanceof Promise ? result.then(() => instance) : instance;
|
|
84
87
|
};
|
|
85
88
|
function compose(Base, ...mixins) {
|
|
86
|
-
return mixins.reduce(
|
|
87
|
-
(cls, mixin) => mixin(cls),
|
|
88
|
-
Base
|
|
89
|
-
);
|
|
89
|
+
return mixins.reduce((acc, mixin) => mixin(acc), Base);
|
|
90
90
|
}
|
|
91
91
|
var flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
|
|
92
92
|
var kebabCase = (str) => trim(dash(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
|
|
93
93
|
var snakeCase = (str) => trim(snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
|
|
94
|
+
var defineConfig = (config) => {
|
|
95
|
+
return config;
|
|
96
|
+
};
|
|
94
97
|
|
|
95
|
-
// src/browser/relations/relation.
|
|
98
|
+
// src/browser/relations/relation.ts
|
|
96
99
|
var Relation = class {
|
|
97
100
|
parent;
|
|
98
101
|
related;
|
|
@@ -121,7 +124,7 @@ var Relation = class {
|
|
|
121
124
|
};
|
|
122
125
|
var relation_default = Relation;
|
|
123
126
|
|
|
124
|
-
// src/browser/relations/belongs-to.
|
|
127
|
+
// src/browser/relations/belongs-to.ts
|
|
125
128
|
var BelongsTo = class extends relation_default {
|
|
126
129
|
foreignKey;
|
|
127
130
|
ownerKey;
|
|
@@ -138,7 +141,7 @@ var BelongsTo = class extends relation_default {
|
|
|
138
141
|
};
|
|
139
142
|
var belongs_to_default = BelongsTo;
|
|
140
143
|
|
|
141
|
-
// src/browser/relations/belongs-to-many.
|
|
144
|
+
// src/browser/relations/belongs-to-many.ts
|
|
142
145
|
var BelongsToMany = class extends relation_default {
|
|
143
146
|
table;
|
|
144
147
|
foreignPivotKey;
|
|
@@ -151,7 +154,6 @@ var BelongsToMany = class extends relation_default {
|
|
|
151
154
|
pivotWhereIns = [];
|
|
152
155
|
pivotWhereNulls = [];
|
|
153
156
|
accessor = "pivot";
|
|
154
|
-
// withTimestamps = false;
|
|
155
157
|
using;
|
|
156
158
|
pivotCreatedAt;
|
|
157
159
|
pivotUpdatedAt;
|
|
@@ -167,7 +169,7 @@ var BelongsToMany = class extends relation_default {
|
|
|
167
169
|
};
|
|
168
170
|
var belongs_to_many_default = BelongsToMany;
|
|
169
171
|
|
|
170
|
-
// src/concerns/has-attributes.
|
|
172
|
+
// src/concerns/has-attributes.ts
|
|
171
173
|
import { flat as flatten, omit } from "radashi";
|
|
172
174
|
import collect from "collect.js";
|
|
173
175
|
import dayjs2 from "dayjs";
|
|
@@ -281,8 +283,8 @@ var HasAttributes = (Model2) => {
|
|
|
281
283
|
}
|
|
282
284
|
const casts = this.getCasts();
|
|
283
285
|
const castType = casts[key];
|
|
284
|
-
if (this.isCustomCast(castType)) {
|
|
285
|
-
value = castType.set(this, key, value, this.attributes);
|
|
286
|
+
if (this.isCustomCast(castType) && typeof castType !== "string") {
|
|
287
|
+
value = castType.set(this, key, value, this.attributes) ?? "";
|
|
286
288
|
}
|
|
287
289
|
if (castType === "json") {
|
|
288
290
|
value = JSON.stringify(value);
|
|
@@ -350,13 +352,13 @@ var HasAttributes = (Model2) => {
|
|
|
350
352
|
case "json":
|
|
351
353
|
try {
|
|
352
354
|
return JSON.parse(value);
|
|
353
|
-
} catch
|
|
355
|
+
} catch {
|
|
354
356
|
return null;
|
|
355
357
|
}
|
|
356
358
|
case "collection":
|
|
357
359
|
try {
|
|
358
360
|
return collect(JSON.parse(value));
|
|
359
|
-
} catch
|
|
361
|
+
} catch {
|
|
360
362
|
return collect([]);
|
|
361
363
|
}
|
|
362
364
|
case "date":
|
|
@@ -395,11 +397,11 @@ var HasAttributes = (Model2) => {
|
|
|
395
397
|
continue;
|
|
396
398
|
}
|
|
397
399
|
attributes[key] = this.castAttribute(key, attributes[key]);
|
|
398
|
-
if (key in attributes && ["date", "datetime"].includes(value)) {
|
|
400
|
+
if (key in attributes && ["date", "datetime"].includes(String(value))) {
|
|
399
401
|
attributes[key] = this.serializeDate(attributes[key]);
|
|
400
402
|
}
|
|
401
403
|
if (key in attributes && this.isCustomDateTimeCast(value)) {
|
|
402
|
-
attributes[key] = dayjs2(attributes[key]).format(value.split(":")[1]);
|
|
404
|
+
attributes[key] = dayjs2(attributes[key]).format(String(value).split(":")[1]);
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
407
|
for (const key of this.appends) {
|
|
@@ -418,7 +420,7 @@ var HasAttributes = (Model2) => {
|
|
|
418
420
|
}
|
|
419
421
|
return value;
|
|
420
422
|
}
|
|
421
|
-
mutateAttributeForArray(
|
|
423
|
+
mutateAttributeForArray(_key, _value) {
|
|
422
424
|
}
|
|
423
425
|
isDateAttribute(key) {
|
|
424
426
|
return this.getDates().includes(key) || this.isDateCastable(key);
|
|
@@ -449,8 +451,8 @@ var HasAttributes = (Model2) => {
|
|
|
449
451
|
} else if (new castType() instanceof casts_attributes_default) {
|
|
450
452
|
castTypeCacheKey = castType.name;
|
|
451
453
|
}
|
|
452
|
-
if (castTypeCacheKey && this.
|
|
453
|
-
return this.
|
|
454
|
+
if (castTypeCacheKey && this.getConstructor().castTypeCache[castTypeCacheKey] !== void 0) {
|
|
455
|
+
return this.getConstructor().castTypeCache[castTypeCacheKey];
|
|
454
456
|
}
|
|
455
457
|
let convertedCastType;
|
|
456
458
|
if (this.isCustomDateTimeCast(castType)) {
|
|
@@ -460,9 +462,9 @@ var HasAttributes = (Model2) => {
|
|
|
460
462
|
} else if (this.isCustomCast(castType)) {
|
|
461
463
|
convertedCastType = castType;
|
|
462
464
|
} else {
|
|
463
|
-
convertedCastType = castType.toLocaleLowerCase().trim();
|
|
465
|
+
convertedCastType = String(castType).toLocaleLowerCase().trim();
|
|
464
466
|
}
|
|
465
|
-
return this.
|
|
467
|
+
return this.getConstructor()[castTypeCacheKey] = convertedCastType;
|
|
466
468
|
}
|
|
467
469
|
hasCast(key, types = []) {
|
|
468
470
|
if (key in this.casts) {
|
|
@@ -521,7 +523,7 @@ var HasAttributes = (Model2) => {
|
|
|
521
523
|
};
|
|
522
524
|
var has_attributes_default = HasAttributes;
|
|
523
525
|
|
|
524
|
-
// src/browser/relations/has-many.
|
|
526
|
+
// src/browser/relations/has-many.ts
|
|
525
527
|
var HasMany = class extends relation_default {
|
|
526
528
|
foreignKey;
|
|
527
529
|
localKey;
|
|
@@ -534,7 +536,7 @@ var HasMany = class extends relation_default {
|
|
|
534
536
|
};
|
|
535
537
|
var has_many_default = HasMany;
|
|
536
538
|
|
|
537
|
-
// src/browser/relations/has-one.
|
|
539
|
+
// src/browser/relations/has-one.ts
|
|
538
540
|
var HasOne = class extends relation_default {
|
|
539
541
|
foreignKey;
|
|
540
542
|
localKey;
|
|
@@ -547,7 +549,7 @@ var HasOne = class extends relation_default {
|
|
|
547
549
|
};
|
|
548
550
|
var has_one_default = HasOne;
|
|
549
551
|
|
|
550
|
-
// src/browser/relations/has-many-through.
|
|
552
|
+
// src/browser/relations/has-many-through.ts
|
|
551
553
|
var HasManyThrough = class extends relation_default {
|
|
552
554
|
throughParent;
|
|
553
555
|
farParent;
|
|
@@ -568,15 +570,15 @@ var HasManyThrough = class extends relation_default {
|
|
|
568
570
|
};
|
|
569
571
|
var has_many_through_default = HasManyThrough;
|
|
570
572
|
|
|
571
|
-
// src/browser/relations/has-one-through.
|
|
573
|
+
// src/browser/relations/has-one-through.ts
|
|
572
574
|
var HasOneThrough = class extends has_many_through_default {
|
|
573
575
|
};
|
|
574
576
|
var has_one_through_default = HasOneThrough;
|
|
575
577
|
|
|
576
|
-
// src/errors.
|
|
578
|
+
// src/errors.ts
|
|
577
579
|
import { isArray } from "radashi";
|
|
578
580
|
var BaseError = class extends Error {
|
|
579
|
-
constructor(message,
|
|
581
|
+
constructor(message, _entity) {
|
|
580
582
|
super(message);
|
|
581
583
|
Error.captureStackTrace(this, this.constructor);
|
|
582
584
|
this.name = this.constructor.name;
|
|
@@ -585,7 +587,10 @@ var BaseError = class extends Error {
|
|
|
585
587
|
};
|
|
586
588
|
var ModelNotFoundError = class extends BaseError {
|
|
587
589
|
model;
|
|
588
|
-
ids;
|
|
590
|
+
ids = [];
|
|
591
|
+
constructor() {
|
|
592
|
+
super("");
|
|
593
|
+
}
|
|
589
594
|
setModel(model, ids = []) {
|
|
590
595
|
this.model = model;
|
|
591
596
|
this.ids = isArray(ids) ? ids : [ids];
|
|
@@ -609,7 +614,7 @@ var RelationNotFoundError = class extends BaseError {
|
|
|
609
614
|
var InvalidArgumentError = class extends BaseError {
|
|
610
615
|
};
|
|
611
616
|
|
|
612
|
-
// src/browser/concerns/has-relations.
|
|
617
|
+
// src/browser/concerns/has-relations.ts
|
|
613
618
|
import { omit as omit2 } from "radashi";
|
|
614
619
|
var HasRelations = (Model2) => {
|
|
615
620
|
return class extends Model2 {
|
|
@@ -652,9 +657,9 @@ var HasRelations = (Model2) => {
|
|
|
652
657
|
return data;
|
|
653
658
|
}
|
|
654
659
|
guessBelongsToRelation() {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
660
|
+
const e = new Error();
|
|
661
|
+
const frame = e.stack?.split("\n")[2];
|
|
662
|
+
const functionName = frame?.split(" ")[5];
|
|
658
663
|
return getRelationName(functionName);
|
|
659
664
|
}
|
|
660
665
|
joiningTable(related, instance = null) {
|
|
@@ -714,7 +719,7 @@ var HasRelations = (Model2) => {
|
|
|
714
719
|
};
|
|
715
720
|
var has_relations_default = HasRelations;
|
|
716
721
|
|
|
717
|
-
// src/concerns/has-timestamps.
|
|
722
|
+
// src/concerns/has-timestamps.ts
|
|
718
723
|
var HasTimestamps = (Model2) => {
|
|
719
724
|
return class extends Model2 {
|
|
720
725
|
static CREATED_AT = "created_at";
|
|
@@ -763,7 +768,7 @@ var HasTimestamps = (Model2) => {
|
|
|
763
768
|
};
|
|
764
769
|
var has_timestamps_default = HasTimestamps;
|
|
765
770
|
|
|
766
|
-
// src/concerns/hides-attributes.
|
|
771
|
+
// src/concerns/hides-attributes.ts
|
|
767
772
|
import { diff as difference } from "radashi";
|
|
768
773
|
var HidesAttributes = (Model2) => {
|
|
769
774
|
return class extends Model2 {
|
|
@@ -777,8 +782,8 @@ var HidesAttributes = (Model2) => {
|
|
|
777
782
|
this.hidden = difference(this.hidden, visible);
|
|
778
783
|
return this;
|
|
779
784
|
}
|
|
780
|
-
makeHidden(...keys) {
|
|
781
|
-
const hidden = flattenDeep(keys);
|
|
785
|
+
makeHidden(key, ...keys) {
|
|
786
|
+
const hidden = flattenDeep([...key, ...keys]);
|
|
782
787
|
if (this.hidden.length > 0) {
|
|
783
788
|
this.hidden = [...this.hidden, ...hidden];
|
|
784
789
|
}
|
|
@@ -802,25 +807,34 @@ var HidesAttributes = (Model2) => {
|
|
|
802
807
|
};
|
|
803
808
|
var hides_attributes_default = HidesAttributes;
|
|
804
809
|
|
|
805
|
-
// src/browser/model.
|
|
810
|
+
// src/browser/model.ts
|
|
806
811
|
import { assign as merge } from "radashi";
|
|
807
812
|
import pluralize from "pluralize";
|
|
808
|
-
var BaseModel = compose(
|
|
809
|
-
|
|
813
|
+
var BaseModel = compose(
|
|
814
|
+
class {
|
|
815
|
+
},
|
|
816
|
+
has_attributes_default,
|
|
817
|
+
hides_attributes_default,
|
|
818
|
+
has_relations_default,
|
|
819
|
+
has_timestamps_default
|
|
820
|
+
);
|
|
810
821
|
var Model = class _Model extends BaseModel {
|
|
811
822
|
primaryKey = "id";
|
|
812
|
-
// protected
|
|
813
|
-
table = null;
|
|
814
|
-
// protected
|
|
815
|
-
keyType = "int";
|
|
816
|
-
// protected
|
|
817
823
|
perPage = 15;
|
|
818
|
-
// protected
|
|
819
824
|
static globalScopes = {};
|
|
820
825
|
static pluginInitializers = {};
|
|
821
826
|
static _booted = {};
|
|
822
|
-
static resolver
|
|
827
|
+
static resolver;
|
|
823
828
|
static browser = true;
|
|
829
|
+
connection = null;
|
|
830
|
+
constructor(attributes = {}) {
|
|
831
|
+
super();
|
|
832
|
+
this.bootIfNotBooted();
|
|
833
|
+
this.initializePlugins();
|
|
834
|
+
this.syncOriginal();
|
|
835
|
+
this.fill(attributes);
|
|
836
|
+
return this.asProxy();
|
|
837
|
+
}
|
|
824
838
|
static init(attributes = {}) {
|
|
825
839
|
return new this(attributes);
|
|
826
840
|
}
|
|
@@ -829,7 +843,7 @@ var Model = class _Model extends BaseModel {
|
|
|
829
843
|
}
|
|
830
844
|
static make(attributes = {}) {
|
|
831
845
|
const instance = new this();
|
|
832
|
-
for (
|
|
846
|
+
for (const attribute in attributes) {
|
|
833
847
|
if (typeof instance[getRelationMethod(attribute)] !== "function") {
|
|
834
848
|
instance.setAttribute(attribute, attributes[attribute]);
|
|
835
849
|
} else {
|
|
@@ -843,14 +857,6 @@ var Model = class _Model extends BaseModel {
|
|
|
843
857
|
}
|
|
844
858
|
return instance;
|
|
845
859
|
}
|
|
846
|
-
constructor(attributes = {}) {
|
|
847
|
-
super();
|
|
848
|
-
this.bootIfNotBooted();
|
|
849
|
-
this.initializePlugins();
|
|
850
|
-
this.syncOriginal();
|
|
851
|
-
this.fill(attributes);
|
|
852
|
-
return this.asProxy();
|
|
853
|
-
}
|
|
854
860
|
bootIfNotBooted() {
|
|
855
861
|
if (this.constructor._booted[this.constructor.name] === void 0) {
|
|
856
862
|
this.constructor._booted[this.constructor.name] = true;
|
|
@@ -1035,7 +1041,7 @@ var Pivot = class extends Model {
|
|
|
1035
1041
|
};
|
|
1036
1042
|
var model_default = Model;
|
|
1037
1043
|
|
|
1038
|
-
// src/browser/collection.
|
|
1044
|
+
// src/browser/collection.ts
|
|
1039
1045
|
var Collection = class _Collection extends BaseCollection {
|
|
1040
1046
|
mapThen(callback) {
|
|
1041
1047
|
return Promise.all(this.map(callback));
|
|
@@ -1043,9 +1049,9 @@ var Collection = class _Collection extends BaseCollection {
|
|
|
1043
1049
|
modelKeys() {
|
|
1044
1050
|
return this.all().map((item) => item.getKey());
|
|
1045
1051
|
}
|
|
1046
|
-
contains(key, operator
|
|
1052
|
+
contains(key, operator, value) {
|
|
1047
1053
|
if (arguments.length > 1) {
|
|
1048
|
-
return super.contains(key, operator
|
|
1054
|
+
return super.contains(key, value ?? operator);
|
|
1049
1055
|
}
|
|
1050
1056
|
if (key instanceof model_default) {
|
|
1051
1057
|
return super.contains((model) => {
|
|
@@ -1076,22 +1082,21 @@ var Collection = class _Collection extends BaseCollection {
|
|
|
1076
1082
|
return intersect;
|
|
1077
1083
|
}
|
|
1078
1084
|
const dictionary = this.getDictionary(items);
|
|
1079
|
-
for (
|
|
1085
|
+
for (const item of this.items) {
|
|
1080
1086
|
if (dictionary[item.getKey()] !== void 0) {
|
|
1081
1087
|
intersect.add(item);
|
|
1082
1088
|
}
|
|
1083
1089
|
}
|
|
1084
1090
|
return intersect;
|
|
1085
1091
|
}
|
|
1086
|
-
unique(key
|
|
1087
|
-
if (key
|
|
1088
|
-
return super.unique(key
|
|
1092
|
+
unique(key, _strict = false) {
|
|
1093
|
+
if (key) {
|
|
1094
|
+
return super.unique(key);
|
|
1089
1095
|
}
|
|
1090
1096
|
return new this.constructor(Object.values(this.getDictionary()));
|
|
1091
1097
|
}
|
|
1092
1098
|
find(key, defaultValue = null) {
|
|
1093
|
-
|
|
1094
|
-
if (key instanceof Model2) {
|
|
1099
|
+
if (key instanceof model_default) {
|
|
1095
1100
|
key = key.getKey();
|
|
1096
1101
|
}
|
|
1097
1102
|
if (isArray2(key)) {
|
|
@@ -1129,8 +1134,8 @@ var Collection = class _Collection extends BaseCollection {
|
|
|
1129
1134
|
const dictionary = pick(this.getDictionary(), keys);
|
|
1130
1135
|
return new this.constructor(Object.values(dictionary));
|
|
1131
1136
|
}
|
|
1132
|
-
getDictionary(items
|
|
1133
|
-
items = items
|
|
1137
|
+
getDictionary(items) {
|
|
1138
|
+
items = !items ? this.items : items;
|
|
1134
1139
|
const dictionary = {};
|
|
1135
1140
|
items.map((value) => {
|
|
1136
1141
|
dictionary[value.getKey()] = value;
|
|
@@ -1146,9 +1151,9 @@ var Collection = class _Collection extends BaseCollection {
|
|
|
1146
1151
|
toJson(...args) {
|
|
1147
1152
|
return JSON.stringify(this.toData(), ...args);
|
|
1148
1153
|
}
|
|
1149
|
-
[Symbol.iterator]() {
|
|
1154
|
+
[Symbol.iterator] = () => {
|
|
1150
1155
|
const items = this.items;
|
|
1151
|
-
|
|
1156
|
+
const length = this.items.length;
|
|
1152
1157
|
let n = 0;
|
|
1153
1158
|
return {
|
|
1154
1159
|
next() {
|
|
@@ -1160,11 +1165,11 @@ var Collection = class _Collection extends BaseCollection {
|
|
|
1160
1165
|
};
|
|
1161
1166
|
}
|
|
1162
1167
|
};
|
|
1163
|
-
}
|
|
1168
|
+
};
|
|
1164
1169
|
};
|
|
1165
1170
|
var collection_default = Collection;
|
|
1166
1171
|
|
|
1167
|
-
// src/concerns/has-unique-ids.
|
|
1172
|
+
// src/concerns/has-unique-ids.ts
|
|
1168
1173
|
var HasUniqueIds = (Model2) => {
|
|
1169
1174
|
return class extends Model2 {
|
|
1170
1175
|
useUniqueIds = true;
|
|
@@ -1187,32 +1192,35 @@ var HasUniqueIds = (Model2) => {
|
|
|
1187
1192
|
};
|
|
1188
1193
|
var has_unique_ids_default = HasUniqueIds;
|
|
1189
1194
|
|
|
1190
|
-
// src/browser/paginator.
|
|
1195
|
+
// src/browser/paginator.ts
|
|
1191
1196
|
var Paginator = class {
|
|
1192
|
-
static formatter
|
|
1197
|
+
static formatter;
|
|
1193
1198
|
_items;
|
|
1194
1199
|
_total;
|
|
1195
1200
|
_perPage;
|
|
1196
1201
|
_lastPage;
|
|
1197
1202
|
_currentPage;
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
}
|
|
1202
|
-
this.formatter = formatter;
|
|
1203
|
-
}
|
|
1204
|
-
constructor(items, total, perPage, currentPage = null, options = {}) {
|
|
1203
|
+
hasMore = false;
|
|
1204
|
+
options = {};
|
|
1205
|
+
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
1205
1206
|
this.options = options;
|
|
1206
1207
|
for (const key in options) {
|
|
1207
1208
|
const value = options[key];
|
|
1208
1209
|
this[key] = value;
|
|
1209
1210
|
}
|
|
1211
|
+
this._items = new collection_default([]);
|
|
1210
1212
|
this._total = total;
|
|
1211
|
-
this._perPage = parseInt(perPage);
|
|
1213
|
+
this._perPage = parseInt(String(perPage));
|
|
1212
1214
|
this._lastPage = Math.max(Math.ceil(total / perPage), 1);
|
|
1213
1215
|
this._currentPage = currentPage;
|
|
1214
1216
|
this.setItems(items);
|
|
1215
1217
|
}
|
|
1218
|
+
static setFormatter(formatter) {
|
|
1219
|
+
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) {
|
|
1220
|
+
throw new Error("Paginator formatter must be a function or null");
|
|
1221
|
+
}
|
|
1222
|
+
this.formatter = formatter;
|
|
1223
|
+
}
|
|
1216
1224
|
setItems(items) {
|
|
1217
1225
|
this._items = items instanceof collection_default ? items : new collection_default(items);
|
|
1218
1226
|
this.hasMore = this._items.count() > this._perPage;
|
|
@@ -1222,7 +1230,7 @@ var Paginator = class {
|
|
|
1222
1230
|
return this.count() > 0 ? (this._currentPage - 1) * this._perPage + 1 : null;
|
|
1223
1231
|
}
|
|
1224
1232
|
lastItem() {
|
|
1225
|
-
return this.count() > 0 ? this.firstItem() + this.count() - 1 : null;
|
|
1233
|
+
return this.count() > 0 ? (this.firstItem() ?? 0) + this.count() - 1 : null;
|
|
1226
1234
|
}
|
|
1227
1235
|
hasMorePages() {
|
|
1228
1236
|
return this._currentPage < this._lastPage;
|
|
@@ -1276,15 +1284,20 @@ var Paginator = class {
|
|
|
1276
1284
|
};
|
|
1277
1285
|
var paginator_default = Paginator;
|
|
1278
1286
|
|
|
1279
|
-
// src/browser/pivot.
|
|
1287
|
+
// src/browser/pivot.ts
|
|
1280
1288
|
var pivot_default = Pivot;
|
|
1281
1289
|
|
|
1282
|
-
// src/browser/index.
|
|
1290
|
+
// src/browser/index.ts
|
|
1283
1291
|
import { isArray as isArray3 } from "radashi";
|
|
1284
1292
|
var make = (model, data, options = {}) => {
|
|
1285
1293
|
const { paginated } = options;
|
|
1286
1294
|
if (paginated) {
|
|
1287
|
-
return new paginator_default(
|
|
1295
|
+
return new paginator_default(
|
|
1296
|
+
data.data.map((item) => model.make(item)),
|
|
1297
|
+
data.total,
|
|
1298
|
+
data.per_page,
|
|
1299
|
+
data.current_page
|
|
1300
|
+
);
|
|
1288
1301
|
}
|
|
1289
1302
|
if (isArray3(data)) {
|
|
1290
1303
|
return new collection_default(data.map((item) => model.make(item)));
|
|
@@ -1292,7 +1305,12 @@ var make = (model, data, options = {}) => {
|
|
|
1292
1305
|
return model.make(data);
|
|
1293
1306
|
};
|
|
1294
1307
|
var makeCollection = (model, data) => new collection_default(data.map((item) => model.make(item)));
|
|
1295
|
-
var makePaginator = (model, data) => new paginator_default(
|
|
1308
|
+
var makePaginator = (model, data) => new paginator_default(
|
|
1309
|
+
data.data.map((item) => model.make(item)),
|
|
1310
|
+
data.total,
|
|
1311
|
+
data.per_page,
|
|
1312
|
+
data.current_page
|
|
1313
|
+
);
|
|
1296
1314
|
var isBrowser = true;
|
|
1297
1315
|
var index_default = {
|
|
1298
1316
|
isBrowser,
|
|
@@ -1320,6 +1338,7 @@ export {
|
|
|
1320
1338
|
RelationNotFoundError,
|
|
1321
1339
|
compose,
|
|
1322
1340
|
index_default as default,
|
|
1341
|
+
defineConfig,
|
|
1323
1342
|
flattenDeep,
|
|
1324
1343
|
getAttrMethod,
|
|
1325
1344
|
getAttrName,
|