pinia-orm-edge 1.10.0-28586201.60fc813 → 1.10.0-28683029.86bd359
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/dist/casts.d.cts +2 -2
- package/dist/casts.d.mts +2 -2
- package/dist/casts.d.ts +2 -2
- package/dist/decorators.cjs +11 -0
- package/dist/decorators.d.cts +9 -4
- package/dist/decorators.d.mts +9 -4
- package/dist/decorators.d.ts +9 -4
- package/dist/decorators.mjs +11 -1
- package/dist/helpers.cjs +1 -0
- package/dist/helpers.d.cts +8 -3
- package/dist/helpers.d.mts +8 -3
- package/dist/helpers.d.ts +8 -3
- package/dist/helpers.mjs +1 -1
- package/dist/index.cjs +306 -173
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +306 -173
- package/dist/nanoid/async.d.cts +2 -2
- package/dist/nanoid/async.d.mts +2 -2
- package/dist/nanoid/async.d.ts +2 -2
- package/dist/nanoid/index.d.cts +2 -2
- package/dist/nanoid/index.d.mts +2 -2
- package/dist/nanoid/index.d.ts +2 -2
- package/dist/nanoid/non-secure.d.cts +2 -2
- package/dist/nanoid/non-secure.d.mts +2 -2
- package/dist/nanoid/non-secure.d.ts +2 -2
- package/dist/shared/{pinia-orm.f37062c8.d.cts → pinia-orm.52557866.d.cts} +62 -25
- package/dist/shared/{pinia-orm.f37062c8.d.mts → pinia-orm.52557866.d.mts} +62 -25
- package/dist/shared/{pinia-orm.f37062c8.d.ts → pinia-orm.52557866.d.ts} +62 -25
- package/dist/uuid/v1.d.cts +2 -2
- package/dist/uuid/v1.d.mts +2 -2
- package/dist/uuid/v1.d.ts +2 -2
- package/dist/uuid/v4.d.cts +2 -2
- package/dist/uuid/v4.d.mts +2 -2
- package/dist/uuid/v4.d.ts +2 -2
- package/package.json +21 -21
package/dist/index.cjs
CHANGED
@@ -5,10 +5,10 @@ const pinia = require('pinia');
|
|
5
5
|
const normalizr = require('@pinia-orm/normalizr');
|
6
6
|
const CastAttribute = require('./shared/pinia-orm.a7e3e0f3.cjs');
|
7
7
|
|
8
|
-
var __defProp$
|
9
|
-
var __defNormalProp$
|
10
|
-
var __publicField$
|
11
|
-
__defNormalProp$
|
8
|
+
var __defProp$l = Object.defineProperty;
|
9
|
+
var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
+
var __publicField$l = (obj, key, value) => {
|
11
|
+
__defNormalProp$l(obj, typeof key !== "symbol" ? key + "" : key, value);
|
12
12
|
return value;
|
13
13
|
};
|
14
14
|
class Attribute {
|
@@ -19,11 +19,11 @@ class Attribute {
|
|
19
19
|
/**
|
20
20
|
* The model instance.
|
21
21
|
*/
|
22
|
-
__publicField$
|
22
|
+
__publicField$l(this, "model");
|
23
23
|
/**
|
24
24
|
* The field name
|
25
25
|
*/
|
26
|
-
__publicField$
|
26
|
+
__publicField$l(this, "key");
|
27
27
|
this.model = model;
|
28
28
|
this.key = "";
|
29
29
|
}
|
@@ -36,10 +36,10 @@ class Attribute {
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
var __defProp$
|
40
|
-
var __defNormalProp$
|
41
|
-
var __publicField$
|
42
|
-
__defNormalProp$
|
39
|
+
var __defProp$k = Object.defineProperty;
|
40
|
+
var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
41
|
+
var __publicField$k = (obj, key, value) => {
|
42
|
+
__defNormalProp$k(obj, typeof key !== "symbol" ? key + "" : key, value);
|
43
43
|
return value;
|
44
44
|
};
|
45
45
|
class Relation extends Attribute {
|
@@ -51,15 +51,15 @@ class Relation extends Attribute {
|
|
51
51
|
/**
|
52
52
|
* The parent model.
|
53
53
|
*/
|
54
|
-
__publicField$
|
54
|
+
__publicField$k(this, "parent");
|
55
55
|
/**
|
56
56
|
* The related model.
|
57
57
|
*/
|
58
|
-
__publicField$
|
58
|
+
__publicField$k(this, "related");
|
59
59
|
/**
|
60
60
|
* The delete mode
|
61
61
|
*/
|
62
|
-
__publicField$
|
62
|
+
__publicField$k(this, "onDeleteMode");
|
63
63
|
this.parent = parent;
|
64
64
|
this.related = related;
|
65
65
|
}
|
@@ -121,10 +121,10 @@ class Relation extends Attribute {
|
|
121
121
|
}
|
122
122
|
}
|
123
123
|
|
124
|
-
var __defProp$
|
125
|
-
var __defNormalProp$
|
126
|
-
var __publicField$
|
127
|
-
__defNormalProp$
|
124
|
+
var __defProp$j = Object.defineProperty;
|
125
|
+
var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
126
|
+
var __publicField$j = (obj, key, value) => {
|
127
|
+
__defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
|
128
128
|
return value;
|
129
129
|
};
|
130
130
|
class MorphTo extends Relation {
|
@@ -136,23 +136,23 @@ class MorphTo extends Relation {
|
|
136
136
|
/**
|
137
137
|
* The related models.
|
138
138
|
*/
|
139
|
-
__publicField$
|
139
|
+
__publicField$j(this, "relatedModels");
|
140
140
|
/**
|
141
141
|
* The related model dictionary.
|
142
142
|
*/
|
143
|
-
__publicField$
|
143
|
+
__publicField$j(this, "relatedTypes");
|
144
144
|
/**
|
145
145
|
* The field name that contains id of the parent model.
|
146
146
|
*/
|
147
|
-
__publicField$
|
147
|
+
__publicField$j(this, "morphId");
|
148
148
|
/**
|
149
149
|
* The field name that contains type of the parent model.
|
150
150
|
*/
|
151
|
-
__publicField$
|
151
|
+
__publicField$j(this, "morphType");
|
152
152
|
/**
|
153
153
|
* The associated key of the child model.
|
154
154
|
*/
|
155
|
-
__publicField$
|
155
|
+
__publicField$j(this, "ownerKey");
|
156
156
|
this.relatedModels = relatedModels;
|
157
157
|
this.relatedTypes = this.createRelatedTypes(relatedModels);
|
158
158
|
this.morphId = morphId;
|
@@ -267,27 +267,33 @@ class MorphTo extends Relation {
|
|
267
267
|
}
|
268
268
|
}
|
269
269
|
|
270
|
-
var __defProp$
|
271
|
-
var __defNormalProp$
|
272
|
-
var __publicField$
|
273
|
-
__defNormalProp$
|
270
|
+
var __defProp$i = Object.defineProperty;
|
271
|
+
var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
272
|
+
var __publicField$i = (obj, key, value) => {
|
273
|
+
__defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
|
274
274
|
return value;
|
275
275
|
};
|
276
276
|
class Type extends Attribute {
|
277
277
|
/**
|
278
278
|
* Create a new Type attribute instance.
|
279
279
|
*/
|
280
|
-
constructor(model,
|
280
|
+
constructor(model, defaultValue = null) {
|
281
281
|
super(model);
|
282
282
|
/**
|
283
|
-
* The default value for the attribute.
|
283
|
+
* The raw default value for the attribute (can be a function).
|
284
284
|
*/
|
285
|
-
__publicField$
|
285
|
+
__publicField$i(this, "rawDefaultValue");
|
286
286
|
/**
|
287
287
|
* Whether the attribute accepts `null` value or not.
|
288
288
|
*/
|
289
|
-
__publicField$
|
290
|
-
this.
|
289
|
+
__publicField$i(this, "isNullable", true);
|
290
|
+
this.rawDefaultValue = defaultValue;
|
291
|
+
}
|
292
|
+
/**
|
293
|
+
* The computed default value of the attribute.
|
294
|
+
*/
|
295
|
+
get defaultValue() {
|
296
|
+
return typeof this.rawDefaultValue === "function" ? this.rawDefaultValue() : this.rawDefaultValue;
|
291
297
|
}
|
292
298
|
/**
|
293
299
|
* Set the nullable option to false.
|
@@ -298,7 +304,7 @@ class Type extends Attribute {
|
|
298
304
|
}
|
299
305
|
makeReturn(type, value) {
|
300
306
|
if (value === void 0) {
|
301
|
-
return this.
|
307
|
+
return this.defaultValue;
|
302
308
|
}
|
303
309
|
if (value === null) {
|
304
310
|
if (!this.isNullable) {
|
@@ -319,24 +325,24 @@ class Type extends Attribute {
|
|
319
325
|
}
|
320
326
|
}
|
321
327
|
|
322
|
-
var __defProp$
|
323
|
-
var __defNormalProp$
|
324
|
-
var __publicField$
|
325
|
-
__defNormalProp$
|
328
|
+
var __defProp$h = Object.defineProperty;
|
329
|
+
var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
330
|
+
var __publicField$h = (obj, key, value) => {
|
331
|
+
__defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
|
326
332
|
return value;
|
327
333
|
};
|
328
334
|
class Uid extends Type {
|
329
335
|
constructor(model, options = {}) {
|
330
336
|
super(model);
|
331
|
-
__publicField$
|
337
|
+
__publicField$h(this, "options");
|
332
338
|
// This alphabet uses `A-Za-z0-9_-` symbols.
|
333
339
|
// The order of characters is optimized for better gzip and brotli compression.
|
334
340
|
// References to the same file (works both for gzip and brotli):
|
335
341
|
// `'use`, `andom`, and `rict'`
|
336
342
|
// References to the brotli default dictionary:
|
337
343
|
// `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
|
338
|
-
__publicField$
|
339
|
-
__publicField$
|
344
|
+
__publicField$h(this, "alphabet", "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict");
|
345
|
+
__publicField$h(this, "size", 21);
|
340
346
|
this.options = typeof options === "number" ? { size: options } : options;
|
341
347
|
this.alphabet = this.options.alphabet ?? this.alphabet;
|
342
348
|
this.size = this.options.size ?? this.size;
|
@@ -353,10 +359,10 @@ class Uid extends Type {
|
|
353
359
|
}
|
354
360
|
}
|
355
361
|
|
356
|
-
var __defProp$
|
357
|
-
var __defNormalProp$
|
358
|
-
var __publicField$
|
359
|
-
__defNormalProp$
|
362
|
+
var __defProp$g = Object.defineProperty;
|
363
|
+
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
364
|
+
var __publicField$g = (obj, key, value) => {
|
365
|
+
__defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
|
360
366
|
return value;
|
361
367
|
};
|
362
368
|
class Schema {
|
@@ -367,11 +373,11 @@ class Schema {
|
|
367
373
|
/**
|
368
374
|
* The list of generated schemas.
|
369
375
|
*/
|
370
|
-
__publicField$
|
376
|
+
__publicField$g(this, "schemas", {});
|
371
377
|
/**
|
372
378
|
* The model instance.
|
373
379
|
*/
|
374
|
-
__publicField$
|
380
|
+
__publicField$g(this, "model");
|
375
381
|
this.model = model;
|
376
382
|
}
|
377
383
|
/**
|
@@ -486,10 +492,10 @@ class Schema {
|
|
486
492
|
}
|
487
493
|
}
|
488
494
|
|
489
|
-
var __defProp$
|
490
|
-
var __defNormalProp$
|
491
|
-
var __publicField$
|
492
|
-
__defNormalProp$
|
495
|
+
var __defProp$f = Object.defineProperty;
|
496
|
+
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
497
|
+
var __publicField$f = (obj, key, value) => {
|
498
|
+
__defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
|
493
499
|
return value;
|
494
500
|
};
|
495
501
|
class Interpreter {
|
@@ -500,7 +506,7 @@ class Interpreter {
|
|
500
506
|
/**
|
501
507
|
* The model object.
|
502
508
|
*/
|
503
|
-
__publicField$
|
509
|
+
__publicField$f(this, "model");
|
504
510
|
this.model = model;
|
505
511
|
}
|
506
512
|
process(data) {
|
@@ -588,10 +594,10 @@ function useDataStore(id, options, query) {
|
|
588
594
|
});
|
589
595
|
}
|
590
596
|
|
591
|
-
var __defProp$
|
592
|
-
var __defNormalProp$
|
593
|
-
var __publicField$
|
594
|
-
__defNormalProp$
|
597
|
+
var __defProp$e = Object.defineProperty;
|
598
|
+
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
599
|
+
var __publicField$e = (obj, key, value) => {
|
600
|
+
__defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
|
595
601
|
return value;
|
596
602
|
};
|
597
603
|
class BelongsToMany extends Relation {
|
@@ -603,27 +609,27 @@ class BelongsToMany extends Relation {
|
|
603
609
|
/**
|
604
610
|
* The pivot model.
|
605
611
|
*/
|
606
|
-
__publicField$
|
612
|
+
__publicField$e(this, "pivot");
|
607
613
|
/**
|
608
614
|
* The foreign key of the parent model.
|
609
615
|
*/
|
610
|
-
__publicField$
|
616
|
+
__publicField$e(this, "foreignPivotKey");
|
611
617
|
/**
|
612
618
|
* The associated key of the relation.
|
613
619
|
*/
|
614
|
-
__publicField$
|
620
|
+
__publicField$e(this, "relatedPivotKey");
|
615
621
|
/**
|
616
622
|
* The key name of the parent model.
|
617
623
|
*/
|
618
|
-
__publicField$
|
624
|
+
__publicField$e(this, "parentKey");
|
619
625
|
/**
|
620
626
|
* The key name of the related model.
|
621
627
|
*/
|
622
|
-
__publicField$
|
628
|
+
__publicField$e(this, "relatedKey");
|
623
629
|
/**
|
624
630
|
* The key name of the pivot data.
|
625
631
|
*/
|
626
|
-
__publicField$
|
632
|
+
__publicField$e(this, "pivotKey", "pivot");
|
627
633
|
this.pivot = pivot;
|
628
634
|
this.foreignPivotKey = foreignPivotKey;
|
629
635
|
this.relatedPivotKey = relatedPivotKey;
|
@@ -649,7 +655,7 @@ class BelongsToMany extends Relation {
|
|
649
655
|
const pivot = child.pivot ?? {};
|
650
656
|
pivot[this.foreignPivotKey] = record[this.parentKey];
|
651
657
|
pivot[this.relatedPivotKey] = child[this.relatedKey];
|
652
|
-
child[`pivot_${this.pivot.$entity()}`] = pivot;
|
658
|
+
child[`pivot_${this.relatedPivotKey}_${this.pivot.$entity()}`] = pivot;
|
653
659
|
}
|
654
660
|
/**
|
655
661
|
* Convert given value to the appropriate value for the attribute.
|
@@ -662,7 +668,7 @@ class BelongsToMany extends Relation {
|
|
662
668
|
*/
|
663
669
|
match(relation, models, query) {
|
664
670
|
const relatedModels = query.get(false);
|
665
|
-
const pivotModels = query.newQuery(this.pivot.$
|
671
|
+
const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedPivotKey, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.foreignPivotKey, this.getKeys(models, this.parentKey)).groupBy(this.foreignPivotKey, this.relatedPivotKey).get();
|
666
672
|
models.forEach((parentModel) => {
|
667
673
|
const relationResults = [];
|
668
674
|
relatedModels.forEach((relatedModel) => {
|
@@ -670,7 +676,7 @@ class BelongsToMany extends Relation {
|
|
670
676
|
if (!pivot) {
|
671
677
|
return;
|
672
678
|
}
|
673
|
-
const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson());
|
679
|
+
const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson(), { operation: void 0 });
|
674
680
|
relatedModelCopy.$setRelation("pivot", pivot);
|
675
681
|
relationResults.push(relatedModelCopy);
|
676
682
|
});
|
@@ -684,10 +690,10 @@ class BelongsToMany extends Relation {
|
|
684
690
|
}
|
685
691
|
}
|
686
692
|
|
687
|
-
var __defProp$
|
688
|
-
var __defNormalProp$
|
689
|
-
var __publicField$
|
690
|
-
__defNormalProp$
|
693
|
+
var __defProp$d = Object.defineProperty;
|
694
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
695
|
+
var __publicField$d = (obj, key, value) => {
|
696
|
+
__defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
|
691
697
|
return value;
|
692
698
|
};
|
693
699
|
class Query {
|
@@ -698,58 +704,58 @@ class Query {
|
|
698
704
|
/**
|
699
705
|
* The database instance.
|
700
706
|
*/
|
701
|
-
__publicField$
|
707
|
+
__publicField$d(this, "database");
|
702
708
|
/**
|
703
709
|
* The model object.
|
704
710
|
*/
|
705
|
-
__publicField$
|
711
|
+
__publicField$d(this, "model");
|
706
712
|
/**
|
707
713
|
* The where constraints for the query.
|
708
714
|
*/
|
709
|
-
__publicField$
|
715
|
+
__publicField$d(this, "wheres", []);
|
710
716
|
/**
|
711
717
|
* The orderings for the query.
|
712
718
|
*/
|
713
|
-
__publicField$
|
719
|
+
__publicField$d(this, "orders", []);
|
714
720
|
/**
|
715
721
|
* The orderings for the query.
|
716
722
|
*/
|
717
|
-
__publicField$
|
723
|
+
__publicField$d(this, "groups", []);
|
718
724
|
/**
|
719
725
|
* The maximum number of records to return.
|
720
726
|
*/
|
721
|
-
__publicField$
|
727
|
+
__publicField$d(this, "take", null);
|
722
728
|
/**
|
723
729
|
* The number of records to skip.
|
724
730
|
*/
|
725
|
-
__publicField$
|
731
|
+
__publicField$d(this, "skip", 0);
|
726
732
|
/**
|
727
733
|
* Fields that should be visible.
|
728
734
|
*/
|
729
|
-
__publicField$
|
735
|
+
__publicField$d(this, "visible", ["*"]);
|
730
736
|
/**
|
731
737
|
* Fields that should be hidden.
|
732
738
|
*/
|
733
|
-
__publicField$
|
739
|
+
__publicField$d(this, "hidden", []);
|
734
740
|
/**
|
735
741
|
* The cache object.
|
736
742
|
*/
|
737
|
-
__publicField$
|
743
|
+
__publicField$d(this, "cache");
|
738
744
|
/**
|
739
745
|
* The relationships that should be eager loaded.
|
740
746
|
*/
|
741
|
-
__publicField$
|
747
|
+
__publicField$d(this, "eagerLoad", {});
|
742
748
|
/**
|
743
749
|
* The pinia store.
|
744
750
|
*/
|
745
|
-
__publicField$
|
746
|
-
__publicField$
|
747
|
-
__publicField$
|
748
|
-
__publicField$
|
751
|
+
__publicField$d(this, "pinia");
|
752
|
+
__publicField$d(this, "fromCache", false);
|
753
|
+
__publicField$d(this, "cacheConfig", {});
|
754
|
+
__publicField$d(this, "getNewHydrated", false);
|
749
755
|
/**
|
750
756
|
* Hydrated models. They are stored to prevent rerendering of child components.
|
751
757
|
*/
|
752
|
-
__publicField$
|
758
|
+
__publicField$d(this, "hydratedDataCache");
|
753
759
|
this.database = database;
|
754
760
|
this.model = model;
|
755
761
|
this.pinia = pinia;
|
@@ -1314,7 +1320,7 @@ class Query {
|
|
1314
1320
|
const recordsByTypes = {};
|
1315
1321
|
records = Utils.isArray(records) ? records : [records];
|
1316
1322
|
records.forEach((record) => {
|
1317
|
-
const recordType = modelTypesKeys.includes(`${record[this.model.$typeKey()]}`) || isChildEntity ? record[this.model.$typeKey()] ?? this.model.$fields()[this.model.$typeKey()].
|
1323
|
+
const recordType = modelTypesKeys.includes(`${record[this.model.$typeKey()]}`) || isChildEntity ? record[this.model.$typeKey()] ?? this.model.$fields()[this.model.$typeKey()].defaultValue : modelTypesKeys[0];
|
1318
1324
|
if (!recordsByTypes[recordType]) {
|
1319
1325
|
recordsByTypes[recordType] = [];
|
1320
1326
|
}
|
@@ -1354,7 +1360,7 @@ class Query {
|
|
1354
1360
|
continue;
|
1355
1361
|
}
|
1356
1362
|
if (model.$isDirty()) {
|
1357
|
-
model = this.hydrate(model.$getAttributes(), { operation: "set", action:
|
1363
|
+
model = this.hydrate(model.$getAttributes(), { operation: "set", action: "update" });
|
1358
1364
|
}
|
1359
1365
|
afterSavingHooks.push(() => model.$self().saved(model, record));
|
1360
1366
|
afterSavingHooks.push(() => existing ? model.$self().updated(model, record) : model.$self().created(model, record));
|
@@ -1544,10 +1550,10 @@ class Query {
|
|
1544
1550
|
}
|
1545
1551
|
}
|
1546
1552
|
|
1547
|
-
var __defProp$
|
1548
|
-
var __defNormalProp$
|
1549
|
-
var __publicField$
|
1550
|
-
__defNormalProp$
|
1553
|
+
var __defProp$c = Object.defineProperty;
|
1554
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
1555
|
+
var __publicField$c = (obj, key, value) => {
|
1556
|
+
__defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
1551
1557
|
return value;
|
1552
1558
|
};
|
1553
1559
|
var __accessCheck = (obj, member, msg) => {
|
@@ -1567,7 +1573,7 @@ var _a, _map;
|
|
1567
1573
|
class WeakCache {
|
1568
1574
|
constructor() {
|
1569
1575
|
// @ts-expect-error dont know
|
1570
|
-
__publicField$
|
1576
|
+
__publicField$c(this, _a);
|
1571
1577
|
__privateAdd(this, _map, /* @__PURE__ */ new Map());
|
1572
1578
|
}
|
1573
1579
|
has(key) {
|
@@ -1650,10 +1656,10 @@ const CONFIG_DEFAULTS = {
|
|
1650
1656
|
};
|
1651
1657
|
const config = { ...CONFIG_DEFAULTS };
|
1652
1658
|
|
1653
|
-
var __defProp$
|
1654
|
-
var __defNormalProp$
|
1655
|
-
var __publicField$
|
1656
|
-
__defNormalProp$
|
1659
|
+
var __defProp$b = Object.defineProperty;
|
1660
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
1661
|
+
var __publicField$b = (obj, key, value) => {
|
1662
|
+
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
1657
1663
|
return value;
|
1658
1664
|
};
|
1659
1665
|
class Repository {
|
@@ -1664,31 +1670,31 @@ class Repository {
|
|
1664
1670
|
/**
|
1665
1671
|
* The database instance.
|
1666
1672
|
*/
|
1667
|
-
__publicField$
|
1673
|
+
__publicField$b(this, "database");
|
1668
1674
|
/**
|
1669
1675
|
* The model instance.
|
1670
1676
|
*/
|
1671
|
-
__publicField$
|
1677
|
+
__publicField$b(this, "model");
|
1672
1678
|
/**
|
1673
1679
|
* The pinia instance
|
1674
1680
|
*/
|
1675
|
-
__publicField$
|
1681
|
+
__publicField$b(this, "pinia");
|
1676
1682
|
/**
|
1677
1683
|
* The cache instance
|
1678
1684
|
*/
|
1679
|
-
__publicField$
|
1685
|
+
__publicField$b(this, "queryCache");
|
1680
1686
|
/**
|
1681
1687
|
* Hydrated models. They are stored to prevent rerendering of child components.
|
1682
1688
|
*/
|
1683
|
-
__publicField$
|
1689
|
+
__publicField$b(this, "hydratedDataCache");
|
1684
1690
|
/**
|
1685
1691
|
* The model object to be used for the custom repository.
|
1686
1692
|
*/
|
1687
|
-
__publicField$
|
1693
|
+
__publicField$b(this, "use");
|
1688
1694
|
/**
|
1689
1695
|
* Global config
|
1690
1696
|
*/
|
1691
|
-
__publicField$
|
1697
|
+
__publicField$b(this, "config");
|
1692
1698
|
this.config = config;
|
1693
1699
|
this.database = database;
|
1694
1700
|
this.pinia = pinia;
|
@@ -1959,16 +1965,16 @@ class Repository {
|
|
1959
1965
|
* used when retrieving repository instance from `store.$repo()` method to
|
1960
1966
|
* determine whether the passed in class is either a repository or a model.
|
1961
1967
|
*/
|
1962
|
-
__publicField$
|
1968
|
+
__publicField$b(Repository, "_isRepository", true);
|
1963
1969
|
/**
|
1964
1970
|
* The model object to be used for the custom repository.
|
1965
1971
|
*/
|
1966
|
-
__publicField$
|
1972
|
+
__publicField$b(Repository, "useModel");
|
1967
1973
|
|
1968
|
-
var __defProp$
|
1969
|
-
var __defNormalProp$
|
1970
|
-
var __publicField$
|
1971
|
-
__defNormalProp$
|
1974
|
+
var __defProp$a = Object.defineProperty;
|
1975
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
1976
|
+
var __publicField$a = (obj, key, value) => {
|
1977
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
1972
1978
|
return value;
|
1973
1979
|
};
|
1974
1980
|
class Database {
|
@@ -1976,7 +1982,7 @@ class Database {
|
|
1976
1982
|
/**
|
1977
1983
|
* The list of registered models.
|
1978
1984
|
*/
|
1979
|
-
__publicField$
|
1985
|
+
__publicField$a(this, "models", {});
|
1980
1986
|
}
|
1981
1987
|
/**
|
1982
1988
|
* Register the given model.
|
@@ -2067,7 +2073,7 @@ class Attr extends Type {
|
|
2067
2073
|
* Make the value for the attribute.
|
2068
2074
|
*/
|
2069
2075
|
make(value) {
|
2070
|
-
return value === void 0 ? this.
|
2076
|
+
return value === void 0 ? this.defaultValue : value;
|
2071
2077
|
}
|
2072
2078
|
}
|
2073
2079
|
|
@@ -2116,10 +2122,10 @@ class Boolean extends Type {
|
|
2116
2122
|
}
|
2117
2123
|
}
|
2118
2124
|
|
2119
|
-
var __defProp$
|
2120
|
-
var __defNormalProp$
|
2121
|
-
var __publicField$
|
2122
|
-
__defNormalProp$
|
2125
|
+
var __defProp$9 = Object.defineProperty;
|
2126
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2127
|
+
var __publicField$9 = (obj, key, value) => {
|
2128
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2123
2129
|
return value;
|
2124
2130
|
};
|
2125
2131
|
class HasOne extends Relation {
|
@@ -2131,11 +2137,11 @@ class HasOne extends Relation {
|
|
2131
2137
|
/**
|
2132
2138
|
* The foreign key of the parent model.
|
2133
2139
|
*/
|
2134
|
-
__publicField$
|
2140
|
+
__publicField$9(this, "foreignKey");
|
2135
2141
|
/**
|
2136
2142
|
* The local key of the parent model.
|
2137
2143
|
*/
|
2138
|
-
__publicField$
|
2144
|
+
__publicField$9(this, "localKey");
|
2139
2145
|
this.foreignKey = foreignKey;
|
2140
2146
|
this.localKey = localKey;
|
2141
2147
|
}
|
@@ -2199,10 +2205,10 @@ class HasOne extends Relation {
|
|
2199
2205
|
}
|
2200
2206
|
}
|
2201
2207
|
|
2202
|
-
var __defProp$
|
2203
|
-
var __defNormalProp$
|
2204
|
-
var __publicField$
|
2205
|
-
__defNormalProp$
|
2208
|
+
var __defProp$8 = Object.defineProperty;
|
2209
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2210
|
+
var __publicField$8 = (obj, key, value) => {
|
2211
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2206
2212
|
return value;
|
2207
2213
|
};
|
2208
2214
|
class BelongsTo extends Relation {
|
@@ -2214,15 +2220,15 @@ class BelongsTo extends Relation {
|
|
2214
2220
|
/**
|
2215
2221
|
* The child model instance of the relation.
|
2216
2222
|
*/
|
2217
|
-
__publicField$
|
2223
|
+
__publicField$8(this, "child");
|
2218
2224
|
/**
|
2219
2225
|
* The foreign key of the parent model.
|
2220
2226
|
*/
|
2221
|
-
__publicField$
|
2227
|
+
__publicField$8(this, "foreignKey");
|
2222
2228
|
/**
|
2223
2229
|
* The associated key on the parent model.
|
2224
2230
|
*/
|
2225
|
-
__publicField$
|
2231
|
+
__publicField$8(this, "ownerKey");
|
2226
2232
|
this.foreignKey = foreignKey;
|
2227
2233
|
this.ownerKey = ownerKey;
|
2228
2234
|
this.child = child;
|
@@ -2299,10 +2305,10 @@ class BelongsTo extends Relation {
|
|
2299
2305
|
}
|
2300
2306
|
}
|
2301
2307
|
|
2302
|
-
var __defProp$
|
2303
|
-
var __defNormalProp$
|
2304
|
-
var __publicField$
|
2305
|
-
__defNormalProp$
|
2308
|
+
var __defProp$7 = Object.defineProperty;
|
2309
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2310
|
+
var __publicField$7 = (obj, key, value) => {
|
2311
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2306
2312
|
return value;
|
2307
2313
|
};
|
2308
2314
|
class HasMany extends Relation {
|
@@ -2314,11 +2320,11 @@ class HasMany extends Relation {
|
|
2314
2320
|
/**
|
2315
2321
|
* The foreign key of the parent model.
|
2316
2322
|
*/
|
2317
|
-
__publicField$
|
2323
|
+
__publicField$7(this, "foreignKey");
|
2318
2324
|
/**
|
2319
2325
|
* The local key of the parent model.
|
2320
2326
|
*/
|
2321
|
-
__publicField$
|
2327
|
+
__publicField$7(this, "localKey");
|
2322
2328
|
this.foreignKey = foreignKey;
|
2323
2329
|
this.localKey = localKey;
|
2324
2330
|
}
|
@@ -2387,10 +2393,10 @@ class HasMany extends Relation {
|
|
2387
2393
|
}
|
2388
2394
|
}
|
2389
2395
|
|
2390
|
-
var __defProp$
|
2391
|
-
var __defNormalProp$
|
2392
|
-
var __publicField$
|
2393
|
-
__defNormalProp$
|
2396
|
+
var __defProp$6 = Object.defineProperty;
|
2397
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2398
|
+
var __publicField$6 = (obj, key, value) => {
|
2399
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2394
2400
|
return value;
|
2395
2401
|
};
|
2396
2402
|
class HasManyBy extends Relation {
|
@@ -2402,15 +2408,15 @@ class HasManyBy extends Relation {
|
|
2402
2408
|
/**
|
2403
2409
|
* The child model instance of the relation.
|
2404
2410
|
*/
|
2405
|
-
__publicField$
|
2411
|
+
__publicField$6(this, "child");
|
2406
2412
|
/**
|
2407
2413
|
* The foreign key of the parent model.
|
2408
2414
|
*/
|
2409
|
-
__publicField$
|
2415
|
+
__publicField$6(this, "foreignKey");
|
2410
2416
|
/**
|
2411
2417
|
* The owner key of the parent model.
|
2412
2418
|
*/
|
2413
|
-
__publicField$
|
2419
|
+
__publicField$6(this, "ownerKey");
|
2414
2420
|
this.foreignKey = foreignKey;
|
2415
2421
|
this.ownerKey = ownerKey;
|
2416
2422
|
this.child = child;
|
@@ -2502,10 +2508,10 @@ class HasManyBy extends Relation {
|
|
2502
2508
|
}
|
2503
2509
|
}
|
2504
2510
|
|
2505
|
-
var __defProp$
|
2506
|
-
var __defNormalProp$
|
2507
|
-
var __publicField$
|
2508
|
-
__defNormalProp$
|
2511
|
+
var __defProp$5 = Object.defineProperty;
|
2512
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2513
|
+
var __publicField$5 = (obj, key, value) => {
|
2514
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2509
2515
|
return value;
|
2510
2516
|
};
|
2511
2517
|
class MorphOne extends Relation {
|
@@ -2517,15 +2523,15 @@ class MorphOne extends Relation {
|
|
2517
2523
|
/**
|
2518
2524
|
* The field name that contains id of the parent model.
|
2519
2525
|
*/
|
2520
|
-
__publicField$
|
2526
|
+
__publicField$5(this, "morphId");
|
2521
2527
|
/**
|
2522
2528
|
* The field name that contains type of the parent model.
|
2523
2529
|
*/
|
2524
|
-
__publicField$
|
2530
|
+
__publicField$5(this, "morphType");
|
2525
2531
|
/**
|
2526
2532
|
* The local key of the model.
|
2527
2533
|
*/
|
2528
|
-
__publicField$
|
2534
|
+
__publicField$5(this, "localKey");
|
2529
2535
|
this.morphId = morphId;
|
2530
2536
|
this.morphType = morphType;
|
2531
2537
|
this.localKey = localKey;
|
@@ -2582,10 +2588,10 @@ class MorphOne extends Relation {
|
|
2582
2588
|
}
|
2583
2589
|
}
|
2584
2590
|
|
2585
|
-
var __defProp$
|
2586
|
-
var __defNormalProp$
|
2587
|
-
var __publicField$
|
2588
|
-
__defNormalProp$
|
2591
|
+
var __defProp$4 = Object.defineProperty;
|
2592
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2593
|
+
var __publicField$4 = (obj, key, value) => {
|
2594
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2589
2595
|
return value;
|
2590
2596
|
};
|
2591
2597
|
class MorphMany extends Relation {
|
@@ -2597,15 +2603,15 @@ class MorphMany extends Relation {
|
|
2597
2603
|
/**
|
2598
2604
|
* The field name that contains id of the parent model.
|
2599
2605
|
*/
|
2600
|
-
__publicField$
|
2606
|
+
__publicField$4(this, "morphId");
|
2601
2607
|
/**
|
2602
2608
|
* The field name that contains type of the parent model.
|
2603
2609
|
*/
|
2604
|
-
__publicField$
|
2610
|
+
__publicField$4(this, "morphType");
|
2605
2611
|
/**
|
2606
2612
|
* The local key of the model.
|
2607
2613
|
*/
|
2608
|
-
__publicField$
|
2614
|
+
__publicField$4(this, "localKey");
|
2609
2615
|
this.morphId = morphId;
|
2610
2616
|
this.morphType = morphType;
|
2611
2617
|
this.localKey = localKey;
|
@@ -2662,10 +2668,10 @@ class MorphMany extends Relation {
|
|
2662
2668
|
}
|
2663
2669
|
}
|
2664
2670
|
|
2665
|
-
var __defProp$
|
2666
|
-
var __defNormalProp$
|
2667
|
-
var __publicField$
|
2668
|
-
__defNormalProp$
|
2671
|
+
var __defProp$3 = Object.defineProperty;
|
2672
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2673
|
+
var __publicField$3 = (obj, key, value) => {
|
2674
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2669
2675
|
return value;
|
2670
2676
|
};
|
2671
2677
|
class HasManyThrough extends Relation {
|
@@ -2677,23 +2683,23 @@ class HasManyThrough extends Relation {
|
|
2677
2683
|
/**
|
2678
2684
|
* The "through" parent model.
|
2679
2685
|
*/
|
2680
|
-
__publicField$
|
2686
|
+
__publicField$3(this, "through");
|
2681
2687
|
/**
|
2682
2688
|
* The near key on the relationship.
|
2683
2689
|
*/
|
2684
|
-
__publicField$
|
2690
|
+
__publicField$3(this, "firstKey");
|
2685
2691
|
/**
|
2686
2692
|
* The far key on the relationship.
|
2687
2693
|
*/
|
2688
|
-
__publicField$
|
2694
|
+
__publicField$3(this, "secondKey");
|
2689
2695
|
/**
|
2690
2696
|
* The local key on the relationship.
|
2691
2697
|
*/
|
2692
|
-
__publicField$
|
2698
|
+
__publicField$3(this, "localKey");
|
2693
2699
|
/**
|
2694
2700
|
* The local key on the intermediary model.
|
2695
2701
|
*/
|
2696
|
-
__publicField$
|
2702
|
+
__publicField$3(this, "secondLocalKey");
|
2697
2703
|
this.through = through;
|
2698
2704
|
this.firstKey = firstKey;
|
2699
2705
|
this.secondKey = secondKey;
|
@@ -2751,13 +2757,114 @@ class HasManyThrough extends Relation {
|
|
2751
2757
|
}
|
2752
2758
|
}
|
2753
2759
|
|
2760
|
+
var __defProp$2 = Object.defineProperty;
|
2761
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2762
|
+
var __publicField$2 = (obj, key, value) => {
|
2763
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2764
|
+
return value;
|
2765
|
+
};
|
2766
|
+
class MorphToMany extends Relation {
|
2767
|
+
/**
|
2768
|
+
* Create a new morph to many to instance.
|
2769
|
+
*/
|
2770
|
+
constructor(parent, related, pivot, relatedId, morphId, morphType, parentKey, relatedKey) {
|
2771
|
+
super(parent, related);
|
2772
|
+
/**
|
2773
|
+
* The pivot model.
|
2774
|
+
*/
|
2775
|
+
__publicField$2(this, "pivot");
|
2776
|
+
/**
|
2777
|
+
* The field name that contains id of the parent model.
|
2778
|
+
*/
|
2779
|
+
__publicField$2(this, "morphId");
|
2780
|
+
/**
|
2781
|
+
* The field name that contains type of the parent model.
|
2782
|
+
*/
|
2783
|
+
__publicField$2(this, "morphType");
|
2784
|
+
/**
|
2785
|
+
* The associated key of the relation.
|
2786
|
+
*/
|
2787
|
+
__publicField$2(this, "relatedId");
|
2788
|
+
/**
|
2789
|
+
* The key name of the parent model.
|
2790
|
+
*/
|
2791
|
+
__publicField$2(this, "parentKey");
|
2792
|
+
/**
|
2793
|
+
* The key name of the related model.
|
2794
|
+
*/
|
2795
|
+
__publicField$2(this, "relatedKey");
|
2796
|
+
/**
|
2797
|
+
* The key name of the pivot data.
|
2798
|
+
*/
|
2799
|
+
__publicField$2(this, "pivotKey", "pivot");
|
2800
|
+
this.pivot = pivot;
|
2801
|
+
this.morphId = morphId;
|
2802
|
+
this.morphType = morphType;
|
2803
|
+
this.relatedId = relatedId;
|
2804
|
+
this.parentKey = parentKey;
|
2805
|
+
this.relatedKey = relatedKey;
|
2806
|
+
}
|
2807
|
+
/**
|
2808
|
+
* Get all related models for the relationship.
|
2809
|
+
*/
|
2810
|
+
getRelateds() {
|
2811
|
+
return [this.related, this.pivot];
|
2812
|
+
}
|
2813
|
+
/**
|
2814
|
+
* Define the normalizr schema for the relationship.
|
2815
|
+
*/
|
2816
|
+
define(schema) {
|
2817
|
+
return schema.many(this.related, this.parent);
|
2818
|
+
}
|
2819
|
+
/**
|
2820
|
+
* Attach the parent type and id to the given relation.
|
2821
|
+
*/
|
2822
|
+
attach(record, child) {
|
2823
|
+
const pivot = child.pivot ?? {};
|
2824
|
+
pivot[this.morphId] = record[this.parentKey];
|
2825
|
+
pivot[this.morphType] = this.parent.$entity();
|
2826
|
+
pivot[this.relatedId] = child[this.relatedKey];
|
2827
|
+
child[`pivot_${this.relatedId}_${this.pivot.$entity()}`] = pivot;
|
2828
|
+
}
|
2829
|
+
/**
|
2830
|
+
* Convert given value to the appropriate value for the attribute.
|
2831
|
+
*/
|
2832
|
+
make(elements) {
|
2833
|
+
return elements ? elements.map((element) => this.related.$newInstance(element)) : [];
|
2834
|
+
}
|
2835
|
+
/**
|
2836
|
+
* Match the eagerly loaded results to their parents.
|
2837
|
+
*/
|
2838
|
+
match(relation, models, query) {
|
2839
|
+
const relatedModels = query.get(false);
|
2840
|
+
const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedId, this.getKeys(relatedModels, this.relatedKey)).whereIn(this.morphId, this.getKeys(models, this.parentKey)).groupBy(this.morphId, this.relatedId, this.morphType).get();
|
2841
|
+
models.forEach((parentModel) => {
|
2842
|
+
const relationResults = [];
|
2843
|
+
relatedModels.forEach((relatedModel) => {
|
2844
|
+
const pivot = pivotModels[`[${parentModel[this.parentKey]},${relatedModel[this.relatedKey]},${this.parent.$entity()}]`]?.[0] ?? null;
|
2845
|
+
const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson(), { operation: void 0 });
|
2846
|
+
relatedModelCopy.$setRelation("pivot", pivot);
|
2847
|
+
if (pivot) {
|
2848
|
+
relationResults.push(relatedModelCopy);
|
2849
|
+
}
|
2850
|
+
});
|
2851
|
+
parentModel.$setRelation(relation, relationResults);
|
2852
|
+
});
|
2853
|
+
}
|
2854
|
+
/**
|
2855
|
+
* Set the constraints for the related relation.
|
2856
|
+
*/
|
2857
|
+
addEagerConstraints(_query, _collection) {
|
2858
|
+
}
|
2859
|
+
}
|
2860
|
+
|
2754
2861
|
var __defProp$1 = Object.defineProperty;
|
2755
2862
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2756
2863
|
var __publicField$1 = (obj, key, value) => {
|
2757
2864
|
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2758
2865
|
return value;
|
2759
2866
|
};
|
2760
|
-
class
|
2867
|
+
class MorphedByMany extends Relation {
|
2761
2868
|
/**
|
2762
2869
|
* Create a new morph to many to instance.
|
2763
2870
|
*/
|
@@ -2814,11 +2921,11 @@ class MorphToMany extends Relation {
|
|
2814
2921
|
* Attach the parent type and id to the given relation.
|
2815
2922
|
*/
|
2816
2923
|
attach(record, child) {
|
2817
|
-
const pivot =
|
2818
|
-
pivot[this.morphId] =
|
2819
|
-
pivot[this.morphType] = this.
|
2820
|
-
pivot[this.relatedId] =
|
2821
|
-
child[`pivot_${this.pivot.$entity()}`] = pivot;
|
2924
|
+
const pivot = record.pivot ?? {};
|
2925
|
+
pivot[this.morphId] = child[this.relatedKey];
|
2926
|
+
pivot[this.morphType] = this.related.$entity();
|
2927
|
+
pivot[this.relatedId] = record[this.parentKey];
|
2928
|
+
child[`pivot_${this.relatedId}_${this.pivot.$entity()}`] = pivot;
|
2822
2929
|
}
|
2823
2930
|
/**
|
2824
2931
|
* Convert given value to the appropriate value for the attribute.
|
@@ -2831,16 +2938,18 @@ class MorphToMany extends Relation {
|
|
2831
2938
|
*/
|
2832
2939
|
match(relation, models, query) {
|
2833
2940
|
const relatedModels = query.get(false);
|
2834
|
-
const pivotModels = query.newQuery(this.pivot.$
|
2941
|
+
const pivotModels = query.newQuery(this.pivot.$modelEntity()).whereIn(this.relatedId, this.getKeys(models, this.parentKey)).whereIn(this.morphId, this.getKeys(relatedModels, this.relatedKey)).groupBy(this.relatedId, this.morphType).get();
|
2835
2942
|
models.forEach((parentModel) => {
|
2836
2943
|
const relationResults = [];
|
2837
|
-
|
2838
|
-
|
2839
|
-
|
2840
|
-
|
2944
|
+
const resultModelIds = this.getKeys(pivotModels[`[${parentModel[this.parentKey]},${this.related.$entity()}]`] ?? [], this.morphId);
|
2945
|
+
const relatedModelsFiltered = relatedModels.filter((filterdModel) => resultModelIds.includes(filterdModel[this.relatedKey]));
|
2946
|
+
relatedModelsFiltered.forEach((relatedModel) => {
|
2947
|
+
const pivot = (pivotModels[`[${parentModel[this.parentKey]},${this.related.$entity()}]`] ?? []).find((pivotModel) => pivotModel[this.morphId] === relatedModel[this.relatedKey]) ?? null;
|
2948
|
+
const relatedModelCopy = relatedModel.$newInstance(relatedModel.$toJson(), { operation: void 0 });
|
2841
2949
|
if (pivot) {
|
2842
|
-
|
2950
|
+
relatedModelCopy.$setRelation("pivot", pivot);
|
2843
2951
|
}
|
2952
|
+
relationResults.push(relatedModelCopy);
|
2844
2953
|
});
|
2845
2954
|
parentModel.$setRelation(relation, relationResults);
|
2846
2955
|
});
|
@@ -3026,7 +3135,7 @@ class Model {
|
|
3026
3135
|
const pivotInstance = pivot.newRawInstance();
|
3027
3136
|
parentKey = parentKey ?? model.$getLocalKey();
|
3028
3137
|
relatedKey = relatedKey ?? instance.$getLocalKey();
|
3029
|
-
this.schemas[related.
|
3138
|
+
this.schemas[related.modelEntity()][`pivot_${relatedPivotKey}_${pivotInstance.$entity()}`] = new HasOne(instance, pivotInstance, relatedPivotKey, relatedKey);
|
3030
3139
|
return new BelongsToMany(
|
3031
3140
|
model,
|
3032
3141
|
instance,
|
@@ -3046,7 +3155,7 @@ class Model {
|
|
3046
3155
|
const pivotInstance = pivot.newRawInstance();
|
3047
3156
|
parentKey = parentKey ?? model.$getLocalKey();
|
3048
3157
|
relatedKey = relatedKey ?? instance.$getLocalKey();
|
3049
|
-
this.schemas[related.
|
3158
|
+
this.schemas[related.modelEntity()][`pivot_${relatedId}_${pivotInstance.$entity()}`] = new MorphOne(instance, pivotInstance, relatedId, model.$entity(), relatedKey);
|
3050
3159
|
return new MorphToMany(
|
3051
3160
|
model,
|
3052
3161
|
instance,
|
@@ -3058,6 +3167,27 @@ class Model {
|
|
3058
3167
|
relatedKey
|
3059
3168
|
);
|
3060
3169
|
}
|
3170
|
+
/**
|
3171
|
+
* Create a new MorphedByMany relation instance.
|
3172
|
+
*/
|
3173
|
+
static morphedByMany(related, pivot, relatedId, id, type, parentKey, relatedKey) {
|
3174
|
+
const instance = related.newRawInstance();
|
3175
|
+
const model = this.newRawInstance();
|
3176
|
+
const pivotInstance = pivot.newRawInstance();
|
3177
|
+
parentKey = parentKey ?? model.$getLocalKey();
|
3178
|
+
relatedKey = relatedKey ?? instance.$getLocalKey();
|
3179
|
+
this.schemas[related.modelEntity()][`pivot_${relatedId}_${pivotInstance.$entity()}`] = new MorphOne(model, pivotInstance, id, type, relatedKey);
|
3180
|
+
return new MorphedByMany(
|
3181
|
+
model,
|
3182
|
+
instance,
|
3183
|
+
pivotInstance,
|
3184
|
+
relatedId,
|
3185
|
+
id,
|
3186
|
+
type,
|
3187
|
+
parentKey,
|
3188
|
+
relatedKey
|
3189
|
+
);
|
3190
|
+
}
|
3061
3191
|
/**
|
3062
3192
|
* Create a new HasMany relation instance.
|
3063
3193
|
*/
|
@@ -3285,7 +3415,7 @@ class Model {
|
|
3285
3415
|
keyValue = mutator.set(keyValue);
|
3286
3416
|
}
|
3287
3417
|
if (cast && operation === "set") {
|
3288
|
-
keyValue = cast.set(keyValue);
|
3418
|
+
keyValue = options.action === "update" ? cast.get(keyValue) : cast.set(keyValue);
|
3289
3419
|
}
|
3290
3420
|
this[key] = this[key] ?? keyValue;
|
3291
3421
|
}
|
@@ -3524,6 +3654,9 @@ class Model {
|
|
3524
3654
|
*/
|
3525
3655
|
serializeObject(value) {
|
3526
3656
|
const obj = {};
|
3657
|
+
if (value.serialize && typeof value.serialize === "function") {
|
3658
|
+
return value.serialize(value);
|
3659
|
+
}
|
3527
3660
|
for (const key in value) {
|
3528
3661
|
obj[key] = this.serializeValue(value[key]);
|
3529
3662
|
}
|