@ember-data/model 5.5.0-alpha.1 → 5.5.0-alpha.11
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/addon/-private.js +2 -2
- package/addon/{has-many-774c4c4b.js → has-many-3776fded.js} +12 -197
- package/addon/has-many-3776fded.js.map +1 -0
- package/addon/{hooks-6d5c2fc2.js → hooks-3bc51bea.js} +2 -5
- package/addon/hooks-3bc51bea.js.map +1 -0
- package/addon/hooks.js +1 -1
- package/addon/index.js +3 -3
- package/addon/{model-b638e17c.js → model-7d6eaf05.js} +187 -349
- package/addon/model-7d6eaf05.js.map +1 -0
- package/package.json +34 -23
- package/addon/has-many-774c4c4b.js.map +0 -1
- package/addon/hooks-6d5c2fc2.js.map +0 -1
- package/addon/model-b638e17c.js.map +0 -1
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';
|
|
2
1
|
import { deprecate, assert, warn } from '@ember/debug';
|
|
3
2
|
import { dasherize } from '@ember/string';
|
|
3
|
+
import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';
|
|
4
4
|
import EmberObject, { computed, get } from '@ember/object';
|
|
5
|
-
import { dependentKeyCompat } from '@ember/object/compat';
|
|
6
|
-
import { cached, tracked } from '@glimmer/tracking';
|
|
7
|
-
import Ember from 'ember';
|
|
8
5
|
import { recordIdentifierFor as recordIdentifierFor$1, storeFor as storeFor$1 } from '@ember-data/store';
|
|
9
|
-
import { RecordArray, MUTATE, SOURCE, recordIdentifierFor,
|
|
6
|
+
import { RecordArray, MUTATE, SOURCE, recordIdentifierFor, ARRAY_SIGNAL, notifyArray, isStableIdentifier, storeFor, peekCache, fastPush, coerceId } from '@ember-data/store/-private';
|
|
7
|
+
import { cached, compat } from '@ember-data/tracking';
|
|
8
|
+
import { defineSignal, getSignal, subscribe, peekSignal, addToTransaction } from '@ember-data/tracking/-private';
|
|
10
9
|
import { A } from '@ember/array';
|
|
11
10
|
import ArrayProxy from '@ember/array/proxy';
|
|
12
11
|
import { mapBy, not } from '@ember/object/computed';
|
|
13
12
|
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
|
14
13
|
import ObjectProxy from '@ember/object/proxy';
|
|
15
14
|
import { cacheFor } from '@ember/object/internals';
|
|
16
|
-
import { addToTransaction, subscribe } from '@ember-data/tracking/-private';
|
|
17
15
|
function isElementDescriptor(args) {
|
|
18
16
|
let [maybeTarget, maybeKey, maybeDesc] = args;
|
|
19
17
|
return (
|
|
@@ -48,15 +46,6 @@ function normalizeModelName(type) {
|
|
|
48
46
|
}
|
|
49
47
|
return type;
|
|
50
48
|
}
|
|
51
|
-
function _initializerDefineProperty(target, property, descriptor, context) {
|
|
52
|
-
if (!descriptor) return;
|
|
53
|
-
Object.defineProperty(target, property, {
|
|
54
|
-
enumerable: descriptor.enumerable,
|
|
55
|
-
configurable: descriptor.configurable,
|
|
56
|
-
writable: descriptor.writable,
|
|
57
|
-
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
49
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
|
|
61
50
|
var desc = {};
|
|
62
51
|
Object.keys(descriptor).forEach(function (key) {
|
|
@@ -80,7 +69,16 @@ function _applyDecoratedDescriptor(target, property, decorators, descriptor, con
|
|
|
80
69
|
}
|
|
81
70
|
return desc;
|
|
82
71
|
}
|
|
83
|
-
|
|
72
|
+
function _initializerDefineProperty(target, property, descriptor, context) {
|
|
73
|
+
if (!descriptor) return;
|
|
74
|
+
Object.defineProperty(target, property, {
|
|
75
|
+
enumerable: descriptor.enumerable,
|
|
76
|
+
configurable: descriptor.configurable,
|
|
77
|
+
writable: descriptor.writable,
|
|
78
|
+
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
var _dec$1, _dec2, _dec3, _dec4, _class$6, _descriptor, _descriptor2;
|
|
84
82
|
|
|
85
83
|
/**
|
|
86
84
|
@module @ember-data/model
|
|
@@ -183,7 +181,7 @@ let Errors = (_dec$1 = computed(), _dec2 = mapBy('content', 'message'), _dec3 =
|
|
|
183
181
|
@public
|
|
184
182
|
@type {Array}
|
|
185
183
|
*/
|
|
186
|
-
_initializerDefineProperty(this, "messages", _descriptor
|
|
184
|
+
_initializerDefineProperty(this, "messages", _descriptor, this);
|
|
187
185
|
/**
|
|
188
186
|
Total number of errors.
|
|
189
187
|
@property length
|
|
@@ -198,7 +196,7 @@ let Errors = (_dec$1 = computed(), _dec2 = mapBy('content', 'message'), _dec3 =
|
|
|
198
196
|
@public
|
|
199
197
|
@readOnly
|
|
200
198
|
*/
|
|
201
|
-
_initializerDefineProperty(this, "isEmpty", _descriptor2
|
|
199
|
+
_initializerDefineProperty(this, "isEmpty", _descriptor2, this);
|
|
202
200
|
}
|
|
203
201
|
/**
|
|
204
202
|
@property errorsByAttributeName
|
|
@@ -439,12 +437,12 @@ let Errors = (_dec$1 = computed(), _dec2 = mapBy('content', 'message'), _dec3 =
|
|
|
439
437
|
has(attribute) {
|
|
440
438
|
return this.errorsFor(attribute).length > 0;
|
|
441
439
|
}
|
|
442
|
-
}, (_applyDecoratedDescriptor(_class$6.prototype, "errorsByAttributeName", [_dec$1], Object.getOwnPropertyDescriptor(_class$6.prototype, "errorsByAttributeName"), _class$6.prototype), _descriptor
|
|
440
|
+
}, (_applyDecoratedDescriptor(_class$6.prototype, "errorsByAttributeName", [_dec$1], Object.getOwnPropertyDescriptor(_class$6.prototype, "errorsByAttributeName"), _class$6.prototype), _descriptor = _applyDecoratedDescriptor(_class$6.prototype, "messages", [_dec2], {
|
|
443
441
|
configurable: true,
|
|
444
442
|
enumerable: true,
|
|
445
443
|
writable: true,
|
|
446
444
|
initializer: null
|
|
447
|
-
}), _applyDecoratedDescriptor(_class$6.prototype, "content", [_dec3], Object.getOwnPropertyDescriptor(_class$6.prototype, "content"), _class$6.prototype), _descriptor2
|
|
445
|
+
}), _applyDecoratedDescriptor(_class$6.prototype, "content", [_dec3], Object.getOwnPropertyDescriptor(_class$6.prototype, "content"), _class$6.prototype), _descriptor2 = _applyDecoratedDescriptor(_class$6.prototype, "isEmpty", [_dec4], {
|
|
448
446
|
configurable: true,
|
|
449
447
|
enumerable: true,
|
|
450
448
|
writable: true,
|
|
@@ -666,8 +664,8 @@ class RelatedCollection extends RecordArray {
|
|
|
666
664
|
}
|
|
667
665
|
}
|
|
668
666
|
notify() {
|
|
669
|
-
const
|
|
670
|
-
|
|
667
|
+
const signal = this[ARRAY_SIGNAL];
|
|
668
|
+
signal.shouldReset = true;
|
|
671
669
|
// @ts-expect-error
|
|
672
670
|
notifyArray(this);
|
|
673
671
|
}
|
|
@@ -804,7 +802,7 @@ let PromiseBelongsTo = (_dec = computed(), (_class$5 = class PromiseBelongsTo ex
|
|
|
804
802
|
return this;
|
|
805
803
|
}
|
|
806
804
|
}, (_applyDecoratedDescriptor(_class$5.prototype, "id", [cached], Object.getOwnPropertyDescriptor(_class$5.prototype, "id"), _class$5.prototype), _applyDecoratedDescriptor(_class$5.prototype, "meta", [_dec], Object.getOwnPropertyDescriptor(_class$5.prototype, "meta"), _class$5.prototype)), _class$5));
|
|
807
|
-
var _class$4
|
|
805
|
+
var _class$4;
|
|
808
806
|
/**
|
|
809
807
|
@module @ember-data/model
|
|
810
808
|
*/
|
|
@@ -826,46 +824,12 @@ var _class$4, _descriptor$4, _descriptor2$1, _descriptor3, _descriptor4, _descri
|
|
|
826
824
|
*/
|
|
827
825
|
let PromiseManyArray = (_class$4 = class PromiseManyArray {
|
|
828
826
|
constructor(promise, content) {
|
|
829
|
-
//---- Methods/Properties on ArrayProxy that we will keep as our API
|
|
830
|
-
_initializerDefineProperty(this, "content", _descriptor$4, this);
|
|
831
|
-
//---- Properties/Methods from the PromiseProxyMixin that we will keep as our API
|
|
832
|
-
/**
|
|
833
|
-
* Whether the loading promise is still pending
|
|
834
|
-
*
|
|
835
|
-
* @property {boolean} isPending
|
|
836
|
-
* @public
|
|
837
|
-
*/
|
|
838
|
-
_initializerDefineProperty(this, "isPending", _descriptor2$1, this);
|
|
839
|
-
/**
|
|
840
|
-
* Whether the loading promise rejected
|
|
841
|
-
*
|
|
842
|
-
* @property {boolean} isRejected
|
|
843
|
-
* @public
|
|
844
|
-
*/
|
|
845
|
-
_initializerDefineProperty(this, "isRejected", _descriptor3, this);
|
|
846
|
-
/**
|
|
847
|
-
* Whether the loading promise succeeded
|
|
848
|
-
*
|
|
849
|
-
* @property {boolean} isFulfilled
|
|
850
|
-
* @public
|
|
851
|
-
*/
|
|
852
|
-
_initializerDefineProperty(this, "isFulfilled", _descriptor4, this);
|
|
853
|
-
/**
|
|
854
|
-
* Whether the loading promise completed (resolved or rejected)
|
|
855
|
-
*
|
|
856
|
-
* @property {boolean} isSettled
|
|
857
|
-
* @public
|
|
858
|
-
*/
|
|
859
|
-
_initializerDefineProperty(this, "isSettled", _descriptor5, this);
|
|
860
827
|
this._update(promise, content);
|
|
861
828
|
this.isDestroyed = false;
|
|
862
|
-
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
863
|
-
const meta = Ember.meta(this);
|
|
864
|
-
meta.addMixin = mixin => {
|
|
865
|
-
assert(`Do not use A() on an EmberData PromiseManyArray`);
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
829
|
}
|
|
830
|
+
|
|
831
|
+
//---- Methods/Properties on ArrayProxy that we will keep as our API
|
|
832
|
+
|
|
869
833
|
/**
|
|
870
834
|
* Retrieve the length of the content
|
|
871
835
|
* @property length
|
|
@@ -880,16 +844,6 @@ let PromiseManyArray = (_class$4 = class PromiseManyArray {
|
|
|
880
844
|
return this.content ? this.content.length : 0;
|
|
881
845
|
}
|
|
882
846
|
|
|
883
|
-
// ember-source < 3.23 (e.g. 3.20 lts)
|
|
884
|
-
// requires that the tag `'[]'` be notified
|
|
885
|
-
// on the ArrayProxy in order for `{{#each}}`
|
|
886
|
-
// to recompute. We entangle the '[]' tag from
|
|
887
|
-
get '[]'() {
|
|
888
|
-
if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
|
|
889
|
-
return this.content?.length && this.content;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
|
|
893
847
|
/**
|
|
894
848
|
* Iterate the proxied content. Called by the glimmer iterator in #each
|
|
895
849
|
* We do not guarantee that forEach will always be available. This
|
|
@@ -918,6 +872,33 @@ let PromiseManyArray = (_class$4 = class PromiseManyArray {
|
|
|
918
872
|
this.content.reload(options);
|
|
919
873
|
return this;
|
|
920
874
|
}
|
|
875
|
+
|
|
876
|
+
//---- Properties/Methods from the PromiseProxyMixin that we will keep as our API
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Whether the loading promise is still pending
|
|
880
|
+
*
|
|
881
|
+
* @property {boolean} isPending
|
|
882
|
+
* @public
|
|
883
|
+
*/
|
|
884
|
+
/**
|
|
885
|
+
* Whether the loading promise rejected
|
|
886
|
+
*
|
|
887
|
+
* @property {boolean} isRejected
|
|
888
|
+
* @public
|
|
889
|
+
*/
|
|
890
|
+
/**
|
|
891
|
+
* Whether the loading promise succeeded
|
|
892
|
+
*
|
|
893
|
+
* @property {boolean} isFulfilled
|
|
894
|
+
* @public
|
|
895
|
+
*/
|
|
896
|
+
/**
|
|
897
|
+
* Whether the loading promise completed (resolved or rejected)
|
|
898
|
+
*
|
|
899
|
+
* @property {boolean} isSettled
|
|
900
|
+
* @public
|
|
901
|
+
*/
|
|
921
902
|
/**
|
|
922
903
|
* chain this promise
|
|
923
904
|
*
|
|
@@ -996,42 +977,33 @@ let PromiseManyArray = (_class$4 = class PromiseManyArray {
|
|
|
996
977
|
}) {
|
|
997
978
|
return new this(promise, content);
|
|
998
979
|
}
|
|
999
|
-
}, (
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
}
|
|
1027
|
-
}), _descriptor5 = _applyDecoratedDescriptor(_class$4.prototype, "isSettled", [tracked], {
|
|
1028
|
-
configurable: true,
|
|
1029
|
-
enumerable: true,
|
|
1030
|
-
writable: true,
|
|
1031
|
-
initializer: function () {
|
|
1032
|
-
return false;
|
|
1033
|
-
}
|
|
1034
|
-
}), _applyDecoratedDescriptor(_class$4.prototype, "links", [dependentKeyCompat], Object.getOwnPropertyDescriptor(_class$4.prototype, "links"), _class$4.prototype), _applyDecoratedDescriptor(_class$4.prototype, "meta", [dependentKeyCompat], Object.getOwnPropertyDescriptor(_class$4.prototype, "meta"), _class$4.prototype)), _class$4);
|
|
980
|
+
}, (_applyDecoratedDescriptor(_class$4.prototype, "length", [compat], Object.getOwnPropertyDescriptor(_class$4.prototype, "length"), _class$4.prototype), _applyDecoratedDescriptor(_class$4.prototype, "links", [compat], Object.getOwnPropertyDescriptor(_class$4.prototype, "links"), _class$4.prototype), _applyDecoratedDescriptor(_class$4.prototype, "meta", [compat], Object.getOwnPropertyDescriptor(_class$4.prototype, "meta"), _class$4.prototype)), _class$4);
|
|
981
|
+
defineSignal(PromiseManyArray.prototype, 'content', null);
|
|
982
|
+
defineSignal(PromiseManyArray.prototype, 'isPending', false);
|
|
983
|
+
defineSignal(PromiseManyArray.prototype, 'isRejected', false);
|
|
984
|
+
defineSignal(PromiseManyArray.prototype, 'isFulfilled', false);
|
|
985
|
+
defineSignal(PromiseManyArray.prototype, 'isSettled', false);
|
|
986
|
+
|
|
987
|
+
// this will error if someone tries to call
|
|
988
|
+
// A(identifierArray) since it is not configurable
|
|
989
|
+
// which is preferrable to the `meta` override we used
|
|
990
|
+
// before which required importing all of Ember
|
|
991
|
+
if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
|
|
992
|
+
const desc = {
|
|
993
|
+
enumerable: true,
|
|
994
|
+
configurable: false,
|
|
995
|
+
get: function () {
|
|
996
|
+
return this.content?.length && this.content;
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
compat(desc);
|
|
1000
|
+
|
|
1001
|
+
// ember-source < 3.23 (e.g. 3.20 lts)
|
|
1002
|
+
// requires that the tag `'[]'` be notified
|
|
1003
|
+
// on the ArrayProxy in order for `{{#each}}`
|
|
1004
|
+
// to recompute. We entangle the '[]' tag from content
|
|
1005
|
+
Object.defineProperty(PromiseManyArray.prototype, '[]', desc);
|
|
1006
|
+
}
|
|
1035
1007
|
function tapPromise(proxy, promise) {
|
|
1036
1008
|
proxy.isPending = true;
|
|
1037
1009
|
proxy.isSettled = false;
|
|
@@ -1051,19 +1023,6 @@ function tapPromise(proxy, promise) {
|
|
|
1051
1023
|
throw error;
|
|
1052
1024
|
});
|
|
1053
1025
|
}
|
|
1054
|
-
|
|
1055
|
-
/*
|
|
1056
|
-
Assert that `addedRecord` has a valid type so it can be added to the
|
|
1057
|
-
relationship of the `record`.
|
|
1058
|
-
|
|
1059
|
-
The assert basically checks if the `addedRecord` can be added to the
|
|
1060
|
-
relationship (specified via `relationshipMeta`) of the `record`.
|
|
1061
|
-
|
|
1062
|
-
This utility should only be used internally, as both record parameters must
|
|
1063
|
-
be stable record identifiers and the `relationshipMeta` needs to be the meta
|
|
1064
|
-
information about the relationship, retrieved via
|
|
1065
|
-
`record.relationshipFor(key)`.
|
|
1066
|
-
*/
|
|
1067
1026
|
let assertPolymorphicType;
|
|
1068
1027
|
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
1069
1028
|
assertPolymorphicType = function assertPolymorphicType(parentIdentifier, parentDefinition, addedIdentifier, store) {
|
|
@@ -1076,12 +1035,7 @@ if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
|
1076
1035
|
}
|
|
1077
1036
|
};
|
|
1078
1037
|
}
|
|
1079
|
-
var _class$3
|
|
1080
|
-
|
|
1081
|
-
/**
|
|
1082
|
-
@module @ember-data/model
|
|
1083
|
-
*/
|
|
1084
|
-
|
|
1038
|
+
var _class$3;
|
|
1085
1039
|
function isResourceIdentiferWithRelatedLinks$1(value) {
|
|
1086
1040
|
return Boolean(value && value.links && value.links.related);
|
|
1087
1041
|
}
|
|
@@ -1095,9 +1049,9 @@ function isResourceIdentiferWithRelatedLinks$1(value) {
|
|
|
1095
1049
|
@public
|
|
1096
1050
|
*/
|
|
1097
1051
|
let BelongsToReference = (_class$3 = class BelongsToReference {
|
|
1052
|
+
// unsubscribe tokens given to us by the notification manager
|
|
1053
|
+
|
|
1098
1054
|
constructor(store, graph, parentIdentifier, belongsToRelationship, key) {
|
|
1099
|
-
// unsubscribe tokens given to us by the notification manager
|
|
1100
|
-
_initializerDefineProperty(this, "_ref", _descriptor$3, this);
|
|
1101
1055
|
this.graph = graph;
|
|
1102
1056
|
this.key = key;
|
|
1103
1057
|
this.belongsToRelationship = belongsToRelationship;
|
|
@@ -1546,20 +1500,9 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
|
|
|
1546
1500
|
const support = LEGACY_SUPPORT.get(this.___identifier);
|
|
1547
1501
|
return support.reloadBelongsTo(this.key, options).then(() => this.value());
|
|
1548
1502
|
}
|
|
1549
|
-
}, (
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
writable: true,
|
|
1553
|
-
initializer: function () {
|
|
1554
|
-
return 0;
|
|
1555
|
-
}
|
|
1556
|
-
}), _applyDecoratedDescriptor(_class$3.prototype, "identifier", [cached, dependentKeyCompat], Object.getOwnPropertyDescriptor(_class$3.prototype, "identifier"), _class$3.prototype)), _class$3);
|
|
1557
|
-
var _class$2, _descriptor$2;
|
|
1558
|
-
|
|
1559
|
-
/**
|
|
1560
|
-
@module @ember-data/model
|
|
1561
|
-
*/
|
|
1562
|
-
|
|
1503
|
+
}, _applyDecoratedDescriptor(_class$3.prototype, "identifier", [cached, compat], Object.getOwnPropertyDescriptor(_class$3.prototype, "identifier"), _class$3.prototype), _class$3);
|
|
1504
|
+
defineSignal(BelongsToReference.prototype, '_ref', 0);
|
|
1505
|
+
var _class$2;
|
|
1563
1506
|
function isResourceIdentiferWithRelatedLinks(value) {
|
|
1564
1507
|
return Boolean(value && value.links && value.links.related);
|
|
1565
1508
|
}
|
|
@@ -1577,7 +1520,6 @@ let HasManyReference = (_class$2 = class HasManyReference {
|
|
|
1577
1520
|
this.___token = void 0;
|
|
1578
1521
|
this.___identifier = void 0;
|
|
1579
1522
|
this.___relatedTokenMap = void 0;
|
|
1580
|
-
_initializerDefineProperty(this, "_ref", _descriptor$2, this);
|
|
1581
1523
|
this.graph = graph;
|
|
1582
1524
|
this.key = key;
|
|
1583
1525
|
this.hasManyRelationship = hasManyRelationship;
|
|
@@ -2054,14 +1996,8 @@ let HasManyReference = (_class$2 = class HasManyReference {
|
|
|
2054
1996
|
const support = LEGACY_SUPPORT.get(this.___identifier);
|
|
2055
1997
|
return support.reloadHasMany(this.key, options);
|
|
2056
1998
|
}
|
|
2057
|
-
}, (
|
|
2058
|
-
|
|
2059
|
-
enumerable: true,
|
|
2060
|
-
writable: true,
|
|
2061
|
-
initializer: function () {
|
|
2062
|
-
return 0;
|
|
2063
|
-
}
|
|
2064
|
-
}), _applyDecoratedDescriptor(_class$2.prototype, "identifiers", [cached, dependentKeyCompat], Object.getOwnPropertyDescriptor(_class$2.prototype, "identifiers"), _class$2.prototype)), _class$2);
|
|
1999
|
+
}, _applyDecoratedDescriptor(_class$2.prototype, "identifiers", [cached, compat], Object.getOwnPropertyDescriptor(_class$2.prototype, "identifiers"), _class$2.prototype), _class$2);
|
|
2000
|
+
defineSignal(HasManyReference.prototype, '_ref', 0);
|
|
2065
2001
|
class LegacySupport {
|
|
2066
2002
|
constructor(record) {
|
|
2067
2003
|
this.record = record;
|
|
@@ -2546,6 +2482,7 @@ function handleCompletedRelationshipRequest(recordExt, key, relationship, value,
|
|
|
2546
2482
|
// for the async reload case there will be no proxy if the ui
|
|
2547
2483
|
// has never been accessed
|
|
2548
2484
|
if (proxy && !isHasMany) {
|
|
2485
|
+
// @ts-expect-error unsure why this is not resolving the boolean but async belongsTo is weird
|
|
2549
2486
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
2550
2487
|
if (proxy.content && proxy.content.isDestroying) {
|
|
2551
2488
|
proxy.set('content', null);
|
|
@@ -2652,7 +2589,7 @@ function notifyAttribute(store, identifier, key, record) {
|
|
|
2652
2589
|
record.notifyPropertyChange(key);
|
|
2653
2590
|
}
|
|
2654
2591
|
}
|
|
2655
|
-
var _class$1
|
|
2592
|
+
var _class$1;
|
|
2656
2593
|
const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
|
|
2657
2594
|
const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
|
|
2658
2595
|
const PRIMARY_ATTRIBUTE_KEY = 'base';
|
|
@@ -2661,69 +2598,10 @@ function isInvalidError(error) {
|
|
|
2661
2598
|
}
|
|
2662
2599
|
|
|
2663
2600
|
/**
|
|
2664
|
-
*
|
|
2665
|
-
* that recomputes only when a specific
|
|
2666
|
-
* tracked property that it manages is dirtied.
|
|
2667
|
-
*
|
|
2668
|
-
* This allows us to bust the cache for a value
|
|
2669
|
-
* that otherwise doesn't access anything tracked
|
|
2670
|
-
* as well as control the timing of that notification.
|
|
2671
|
-
*
|
|
2672
|
-
* @internal
|
|
2673
|
-
*/
|
|
2674
|
-
let Tag = (_class$1 = class Tag {
|
|
2675
|
-
constructor() {
|
|
2676
|
-
_initializerDefineProperty(this, "ref", _descriptor$1, this);
|
|
2677
|
-
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
2678
|
-
const [base, prop] = arguments;
|
|
2679
|
-
this._debug_base = base;
|
|
2680
|
-
this._debug_prop = prop;
|
|
2681
|
-
}
|
|
2682
|
-
this.rev = 1;
|
|
2683
|
-
this.isDirty = true;
|
|
2684
|
-
this.value = undefined;
|
|
2685
|
-
/*
|
|
2686
|
-
* whether this was part of a transaction when mutated
|
|
2687
|
-
*/
|
|
2688
|
-
this.t = false;
|
|
2689
|
-
}
|
|
2690
|
-
notify() {
|
|
2691
|
-
this.isDirty = true;
|
|
2692
|
-
addToTransaction(this);
|
|
2693
|
-
this.rev++;
|
|
2694
|
-
}
|
|
2695
|
-
consume(v) {
|
|
2696
|
-
this.isDirty = false;
|
|
2697
|
-
this.value = v; // set cached value
|
|
2698
|
-
}
|
|
2699
|
-
}, _descriptor$1 = _applyDecoratedDescriptor(_class$1.prototype, "ref", [tracked], {
|
|
2700
|
-
configurable: true,
|
|
2701
|
-
enumerable: true,
|
|
2702
|
-
writable: true,
|
|
2703
|
-
initializer: function () {
|
|
2704
|
-
return null;
|
|
2705
|
-
}
|
|
2706
|
-
}), _class$1);
|
|
2707
|
-
const Tags = new WeakMap();
|
|
2708
|
-
function getTag(record, key) {
|
|
2709
|
-
let tags = Tags.get(record);
|
|
2710
|
-
if (!tags) {
|
|
2711
|
-
tags = Object.create(null);
|
|
2712
|
-
Tags.set(record, tags);
|
|
2713
|
-
}
|
|
2714
|
-
// @ts-expect-error
|
|
2715
|
-
return tags[key] = tags[key] || (macroCondition(getOwnConfig().env.DEBUG) ? new Tag(record.constructor.modelName, key) : new Tag());
|
|
2716
|
-
}
|
|
2717
|
-
function peekTag(record, key) {
|
|
2718
|
-
let tags = Tags.get(record);
|
|
2719
|
-
return tags && tags[key];
|
|
2720
|
-
}
|
|
2721
|
-
|
|
2722
|
-
/**
|
|
2723
|
-
* A decorattor that caches a getter while
|
|
2601
|
+
* A decorator that caches a getter while
|
|
2724
2602
|
* providing the ability to bust that cache
|
|
2725
2603
|
* when we so choose in a way that notifies
|
|
2726
|
-
*
|
|
2604
|
+
* tracking systems.
|
|
2727
2605
|
*
|
|
2728
2606
|
* @internal
|
|
2729
2607
|
*/
|
|
@@ -2731,21 +2609,29 @@ function tagged(_target, key, desc) {
|
|
|
2731
2609
|
const getter = desc.get;
|
|
2732
2610
|
const setter = desc.set;
|
|
2733
2611
|
desc.get = function () {
|
|
2734
|
-
|
|
2735
|
-
subscribe(
|
|
2736
|
-
if (
|
|
2737
|
-
|
|
2612
|
+
const signal = getSignal(this, key, true);
|
|
2613
|
+
subscribe(signal);
|
|
2614
|
+
if (signal.shouldReset) {
|
|
2615
|
+
signal.shouldReset = false;
|
|
2616
|
+
signal.lastValue = getter.call(this);
|
|
2738
2617
|
}
|
|
2739
|
-
return
|
|
2618
|
+
return signal.lastValue;
|
|
2740
2619
|
};
|
|
2741
2620
|
desc.set = function (v) {
|
|
2742
|
-
|
|
2621
|
+
getSignal(this, key, true); // ensure signal is setup in case we want to use it.
|
|
2743
2622
|
// probably notify here but not yet.
|
|
2744
2623
|
setter.call(this, v);
|
|
2745
2624
|
};
|
|
2746
|
-
|
|
2625
|
+
compat(desc);
|
|
2747
2626
|
return desc;
|
|
2748
2627
|
}
|
|
2628
|
+
function notifySignal(obj, key) {
|
|
2629
|
+
const signal = peekSignal(obj, key);
|
|
2630
|
+
if (signal) {
|
|
2631
|
+
signal.shouldReset = true;
|
|
2632
|
+
addToTransaction(signal);
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2749
2635
|
|
|
2750
2636
|
/**
|
|
2751
2637
|
Historically EmberData managed a state machine
|
|
@@ -2786,9 +2672,8 @@ root
|
|
|
2786
2672
|
|
|
2787
2673
|
@internal
|
|
2788
2674
|
*/
|
|
2789
|
-
let RecordState = (
|
|
2675
|
+
let RecordState = (_class$1 = class RecordState {
|
|
2790
2676
|
constructor(record) {
|
|
2791
|
-
_initializerDefineProperty(this, "isSaving", _descriptor2, this);
|
|
2792
2677
|
const store = storeFor$1(record);
|
|
2793
2678
|
const identity = recordIdentifierFor(record);
|
|
2794
2679
|
this.identifier = identity;
|
|
@@ -2854,11 +2739,9 @@ let RecordState = (_class3 = class RecordState {
|
|
|
2854
2739
|
|
|
2855
2740
|
// we instantiate lazily
|
|
2856
2741
|
// so we grab anything we don't have yet
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
handleRequest(lastRequest);
|
|
2861
|
-
}
|
|
2742
|
+
const lastRequest = requests.getLastRequestForRecord(identity);
|
|
2743
|
+
if (lastRequest) {
|
|
2744
|
+
handleRequest(lastRequest);
|
|
2862
2745
|
}
|
|
2863
2746
|
this.handler = notifications.subscribe(identity, (identifier, type, key) => {
|
|
2864
2747
|
switch (type) {
|
|
@@ -2883,7 +2766,7 @@ let RecordState = (_class3 = class RecordState {
|
|
|
2883
2766
|
storeFor$1(this.record).notifications.unsubscribe(this.handler);
|
|
2884
2767
|
}
|
|
2885
2768
|
notify(key) {
|
|
2886
|
-
|
|
2769
|
+
notifySignal(this, key);
|
|
2887
2770
|
}
|
|
2888
2771
|
updateInvalidErrors(errors) {
|
|
2889
2772
|
assert(`Expected the Cache instance for ${this.identifier.lid} to implement getErrors(identifier)`, typeof this.cache.getErrors === 'function');
|
|
@@ -3044,23 +2927,14 @@ let RecordState = (_class3 = class RecordState {
|
|
|
3044
2927
|
return '';
|
|
3045
2928
|
}
|
|
3046
2929
|
}
|
|
3047
|
-
}, (
|
|
3048
|
-
|
|
3049
|
-
enumerable: true,
|
|
3050
|
-
writable: true,
|
|
3051
|
-
initializer: function () {
|
|
3052
|
-
return false;
|
|
3053
|
-
}
|
|
3054
|
-
}), _applyDecoratedDescriptor(_class3.prototype, "isLoading", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isLoading"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isLoaded", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isLoaded"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isSaved", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isSaved"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isEmpty", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isEmpty"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isNew", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isNew"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isDeleted", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isDeleted"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isValid", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isValid"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isDirty", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isDirty"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isError", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "isError"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "adapterError", [tagged], Object.getOwnPropertyDescriptor(_class3.prototype, "adapterError"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "isPreloaded", [cached], Object.getOwnPropertyDescriptor(_class3.prototype, "isPreloaded"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "stateName", [cached], Object.getOwnPropertyDescriptor(_class3.prototype, "stateName"), _class3.prototype), _applyDecoratedDescriptor(_class3.prototype, "dirtyType", [cached], Object.getOwnPropertyDescriptor(_class3.prototype, "dirtyType"), _class3.prototype)), _class3);
|
|
2930
|
+
}, (_applyDecoratedDescriptor(_class$1.prototype, "isLoading", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isLoading"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isLoaded", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isLoaded"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isSaved", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isSaved"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isEmpty", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isEmpty"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isNew", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isNew"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isDeleted", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isDeleted"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isValid", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isValid"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isDirty", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isDirty"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isError", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isError"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "adapterError", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "adapterError"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isPreloaded", [cached], Object.getOwnPropertyDescriptor(_class$1.prototype, "isPreloaded"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "stateName", [cached], Object.getOwnPropertyDescriptor(_class$1.prototype, "stateName"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "dirtyType", [cached], Object.getOwnPropertyDescriptor(_class$1.prototype, "dirtyType"), _class$1.prototype)), _class$1);
|
|
2931
|
+
defineSignal(RecordState.prototype, 'isSaving', false);
|
|
3055
2932
|
function notifyErrorsStateChanged(state) {
|
|
3056
2933
|
state.notify('isValid');
|
|
3057
2934
|
state.notify('isError');
|
|
3058
2935
|
state.notify('adapterError');
|
|
3059
2936
|
}
|
|
3060
|
-
var _class,
|
|
3061
|
-
const {
|
|
3062
|
-
changeProperties
|
|
3063
|
-
} = Ember;
|
|
2937
|
+
var _class, _class2;
|
|
3064
2938
|
const LEGACY_SUPPORT = new Map();
|
|
3065
2939
|
function lookupLegacySupport(record) {
|
|
3066
2940
|
const identifier = recordIdentifierFor$1(record);
|
|
@@ -3103,7 +2977,7 @@ function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
|
|
|
3103
2977
|
* an expensive getter on first-access and thereafter
|
|
3104
2978
|
* never recompute it.
|
|
3105
2979
|
*/
|
|
3106
|
-
function computeOnce(target,
|
|
2980
|
+
function computeOnce(target, propertyName, desc) {
|
|
3107
2981
|
const cache = new WeakMap();
|
|
3108
2982
|
let getter = desc.get;
|
|
3109
2983
|
desc.get = function () {
|
|
@@ -3143,20 +3017,6 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3143
3017
|
constructor(...args) {
|
|
3144
3018
|
super(...args);
|
|
3145
3019
|
this.___private_notifications = void 0;
|
|
3146
|
-
/**
|
|
3147
|
-
If `true` the store is attempting to reload the record from the adapter.
|
|
3148
|
-
Example
|
|
3149
|
-
```javascript
|
|
3150
|
-
record.isReloading; // false
|
|
3151
|
-
record.reload();
|
|
3152
|
-
record.isReloading; // true
|
|
3153
|
-
```
|
|
3154
|
-
@property isReloading
|
|
3155
|
-
@public
|
|
3156
|
-
@type {Boolean}
|
|
3157
|
-
@readOnly
|
|
3158
|
-
*/
|
|
3159
|
-
_initializerDefineProperty(this, "isReloading", _descriptor, this);
|
|
3160
3020
|
}
|
|
3161
3021
|
init(options = {}) {
|
|
3162
3022
|
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
@@ -3175,8 +3035,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3175
3035
|
this.___recordState = macroCondition(getOwnConfig().env.DEBUG) ? new RecordState(this) : null;
|
|
3176
3036
|
this.setProperties(createProps);
|
|
3177
3037
|
let notifications = store.notifications;
|
|
3178
|
-
this.___private_notifications = notifications.subscribe(identity, (identifier, type,
|
|
3179
|
-
notifyChanges(identifier, type,
|
|
3038
|
+
this.___private_notifications = notifications.subscribe(identity, (identifier, type, field) => {
|
|
3039
|
+
notifyChanges(identifier, type, field, this, store);
|
|
3180
3040
|
});
|
|
3181
3041
|
}
|
|
3182
3042
|
destroy() {
|
|
@@ -3191,9 +3051,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3191
3051
|
// notify individual changes once the delete has been signaled,
|
|
3192
3052
|
// this decision is left to model instances.
|
|
3193
3053
|
|
|
3194
|
-
this.eachRelationship((
|
|
3054
|
+
this.eachRelationship((name, meta) => {
|
|
3195
3055
|
if (meta.kind === 'belongsTo') {
|
|
3196
|
-
this.notifyPropertyChange(
|
|
3056
|
+
this.notifyPropertyChange(name);
|
|
3197
3057
|
}
|
|
3198
3058
|
});
|
|
3199
3059
|
LEGACY_SUPPORT.get(this)?.destroy();
|
|
@@ -3421,6 +3281,21 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3421
3281
|
throw new Error(`isError is not directly settable`);
|
|
3422
3282
|
}
|
|
3423
3283
|
}
|
|
3284
|
+
|
|
3285
|
+
/**
|
|
3286
|
+
If `true` the store is attempting to reload the record from the adapter.
|
|
3287
|
+
Example
|
|
3288
|
+
```javascript
|
|
3289
|
+
record.isReloading; // false
|
|
3290
|
+
record.reload();
|
|
3291
|
+
record.isReloading; // true
|
|
3292
|
+
```
|
|
3293
|
+
@property isReloading
|
|
3294
|
+
@public
|
|
3295
|
+
@type {Boolean}
|
|
3296
|
+
@readOnly
|
|
3297
|
+
*/
|
|
3298
|
+
|
|
3424
3299
|
/**
|
|
3425
3300
|
All ember models have an id property. This is an identifier
|
|
3426
3301
|
managed by an external source. These are always coerced to be
|
|
@@ -3584,12 +3459,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3584
3459
|
to trigger their flush. We wouldn't need to
|
|
3585
3460
|
super in 4.0+ where sync observers are removed.
|
|
3586
3461
|
*/
|
|
3587
|
-
notifyPropertyChange(
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
tag.notify();
|
|
3591
|
-
}
|
|
3592
|
-
super.notifyPropertyChange(key);
|
|
3462
|
+
notifyPropertyChange(prop) {
|
|
3463
|
+
notifySignal(this, prop);
|
|
3464
|
+
super.notifyPropertyChange(prop);
|
|
3593
3465
|
}
|
|
3594
3466
|
|
|
3595
3467
|
/**
|
|
@@ -3598,21 +3470,17 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3598
3470
|
method if you want to allow the user to still `rollbackAttributes()`
|
|
3599
3471
|
after a delete was made.
|
|
3600
3472
|
Example
|
|
3601
|
-
```
|
|
3602
|
-
import
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
softDelete() {
|
|
3607
|
-
this.model.deleteRecord();
|
|
3473
|
+
```js
|
|
3474
|
+
import Component from '@glimmer/component';
|
|
3475
|
+
export default class extends Component {
|
|
3476
|
+
softDelete = () => {
|
|
3477
|
+
this.args.model.deleteRecord();
|
|
3608
3478
|
}
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
this.model.save();
|
|
3479
|
+
confirm = () => {
|
|
3480
|
+
this.args.model.save();
|
|
3612
3481
|
}
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
this.model.rollbackAttributes();
|
|
3482
|
+
undo = () => {
|
|
3483
|
+
this.args.model.rollbackAttributes();
|
|
3616
3484
|
}
|
|
3617
3485
|
}
|
|
3618
3486
|
```
|
|
@@ -3629,13 +3497,11 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3629
3497
|
/**
|
|
3630
3498
|
Same as `deleteRecord`, but saves the record immediately.
|
|
3631
3499
|
Example
|
|
3632
|
-
```
|
|
3633
|
-
import
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
delete() {
|
|
3638
|
-
this.model.destroyRecord().then(function() {
|
|
3500
|
+
```js
|
|
3501
|
+
import Component from '@glimmer/component';
|
|
3502
|
+
export default class extends Component {
|
|
3503
|
+
delete = () => {
|
|
3504
|
+
this.args.model.destroyRecord().then(function() {
|
|
3639
3505
|
this.transitionToRoute('model.index');
|
|
3640
3506
|
});
|
|
3641
3507
|
}
|
|
@@ -3690,23 +3556,6 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3690
3556
|
storeFor$1(this).unloadRecord(this);
|
|
3691
3557
|
}
|
|
3692
3558
|
|
|
3693
|
-
/**
|
|
3694
|
-
@method _notifyProperties
|
|
3695
|
-
@private
|
|
3696
|
-
*/
|
|
3697
|
-
_notifyProperties(keys) {
|
|
3698
|
-
// changeProperties defers notifications until after the delegate
|
|
3699
|
-
// and protects with a try...finally block
|
|
3700
|
-
// previously used begin...endPropertyChanges but this is private API
|
|
3701
|
-
changeProperties(() => {
|
|
3702
|
-
let key;
|
|
3703
|
-
for (let i = 0, length = keys.length; i < length; i++) {
|
|
3704
|
-
key = keys[i];
|
|
3705
|
-
this.notifyPropertyChange(key);
|
|
3706
|
-
}
|
|
3707
|
-
});
|
|
3708
|
-
}
|
|
3709
|
-
|
|
3710
3559
|
/**
|
|
3711
3560
|
Returns an object, whose keys are changed properties, and value is
|
|
3712
3561
|
an [oldProp, newProp] array.
|
|
@@ -3841,15 +3690,12 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3841
3690
|
Reload the record from the adapter.
|
|
3842
3691
|
This will only work if the record has already finished loading.
|
|
3843
3692
|
Example
|
|
3844
|
-
```
|
|
3845
|
-
import
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
reload() {
|
|
3850
|
-
this.model.reload().then(function(model) {
|
|
3693
|
+
```js
|
|
3694
|
+
import Component from '@glimmer/component';
|
|
3695
|
+
export default class extends Component {
|
|
3696
|
+
async reload = () => {
|
|
3697
|
+
await this.args.model.reload();
|
|
3851
3698
|
// do something with the reloaded model
|
|
3852
|
-
});
|
|
3853
3699
|
}
|
|
3854
3700
|
}
|
|
3855
3701
|
```
|
|
@@ -4005,7 +3851,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4005
3851
|
- `name` the name of the current property in the iteration
|
|
4006
3852
|
- `descriptor` the meta object that describes this relationship
|
|
4007
3853
|
The relationship descriptor argument is an object with the following properties.
|
|
4008
|
-
- **
|
|
3854
|
+
- **name** <span class="type">String</span> the name of this relationship on the Model
|
|
4009
3855
|
- **kind** <span class="type">String</span> "hasMany" or "belongsTo"
|
|
4010
3856
|
- **options** <span class="type">Object</span> the original options hash passed when the relationship was declared
|
|
4011
3857
|
- **parentType** <span class="type">Model</span> the type of the Model that owns this relationship
|
|
@@ -4039,8 +3885,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4039
3885
|
relationshipFor(name) {
|
|
4040
3886
|
return this.constructor.relationshipsByName.get(name);
|
|
4041
3887
|
}
|
|
4042
|
-
inverseFor(
|
|
4043
|
-
return this.constructor.inverseFor(
|
|
3888
|
+
inverseFor(name) {
|
|
3889
|
+
return this.constructor.inverseFor(name, storeFor$1(this));
|
|
4044
3890
|
}
|
|
4045
3891
|
eachAttribute(callback, binding) {
|
|
4046
3892
|
this.constructor.eachAttribute(callback, binding);
|
|
@@ -4221,7 +4067,6 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4221
4067
|
This computed property would return a map describing these
|
|
4222
4068
|
relationships, like this:
|
|
4223
4069
|
```javascript
|
|
4224
|
-
import { get } from '@ember/object';
|
|
4225
4070
|
import Blog from 'app/models/blog';
|
|
4226
4071
|
import User from 'app/models/user';
|
|
4227
4072
|
import Post from 'app/models/post';
|
|
@@ -4271,7 +4116,6 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4271
4116
|
```
|
|
4272
4117
|
This property would contain the following:
|
|
4273
4118
|
```javascript
|
|
4274
|
-
import { get } from '@ember/object';
|
|
4275
4119
|
import Blog from 'app/models/blog';
|
|
4276
4120
|
let relationshipNames = Blog.relationshipNames;
|
|
4277
4121
|
relationshipNames.hasMany;
|
|
@@ -4292,7 +4136,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4292
4136
|
belongsTo: []
|
|
4293
4137
|
};
|
|
4294
4138
|
this.eachComputedProperty((name, meta) => {
|
|
4295
|
-
if (meta.
|
|
4139
|
+
if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
|
|
4296
4140
|
names[meta.kind].push(name);
|
|
4297
4141
|
}
|
|
4298
4142
|
});
|
|
@@ -4314,15 +4158,14 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4314
4158
|
```
|
|
4315
4159
|
This property would contain the following:
|
|
4316
4160
|
```javascript
|
|
4317
|
-
import { get } from '@ember/object';
|
|
4318
4161
|
import Blog from 'app/models/blog';
|
|
4319
4162
|
let relatedTypes = Blog.relatedTypes');
|
|
4320
4163
|
//=> ['user', 'post']
|
|
4321
4164
|
```
|
|
4322
4165
|
@property relatedTypes
|
|
4323
|
-
|
|
4166
|
+
@public
|
|
4324
4167
|
@static
|
|
4325
|
-
@type
|
|
4168
|
+
@type Array
|
|
4326
4169
|
@readOnly
|
|
4327
4170
|
*/
|
|
4328
4171
|
static get relatedTypes() {
|
|
@@ -4359,13 +4202,12 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4359
4202
|
```
|
|
4360
4203
|
This property would contain the following:
|
|
4361
4204
|
```javascript
|
|
4362
|
-
import { get } from '@ember/object';
|
|
4363
4205
|
import Blog from 'app/models/blog';
|
|
4364
4206
|
let relationshipsByName = Blog.relationshipsByName;
|
|
4365
4207
|
relationshipsByName.users;
|
|
4366
|
-
//=> {
|
|
4208
|
+
//=> { name: 'users', kind: 'hasMany', type: 'user', options: Object }
|
|
4367
4209
|
relationshipsByName.owner;
|
|
4368
|
-
//=> {
|
|
4210
|
+
//=> { name: 'owner', kind: 'belongsTo', type: 'user', options: Object }
|
|
4369
4211
|
```
|
|
4370
4212
|
@property relationshipsByName
|
|
4371
4213
|
@public
|
|
@@ -4379,9 +4221,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4379
4221
|
let rels = this.relationshipsObject;
|
|
4380
4222
|
let relationships = Object.keys(rels);
|
|
4381
4223
|
for (let i = 0; i < relationships.length; i++) {
|
|
4382
|
-
let
|
|
4383
|
-
let value = rels[
|
|
4384
|
-
map.set(value.name
|
|
4224
|
+
let name = relationships[i];
|
|
4225
|
+
let value = rels[name];
|
|
4226
|
+
map.set(value.name, value);
|
|
4385
4227
|
}
|
|
4386
4228
|
return map;
|
|
4387
4229
|
}
|
|
@@ -4390,7 +4232,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4390
4232
|
let relationships = Object.create(null);
|
|
4391
4233
|
let modelName = this.modelName;
|
|
4392
4234
|
this.eachComputedProperty((name, meta) => {
|
|
4393
|
-
if (meta.
|
|
4235
|
+
if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
|
|
4236
|
+
// TODO deprecate key being here
|
|
4394
4237
|
meta.key = name;
|
|
4395
4238
|
meta.name = name;
|
|
4396
4239
|
meta.parentModelName = modelName;
|
|
@@ -4416,7 +4259,6 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4416
4259
|
}
|
|
4417
4260
|
```
|
|
4418
4261
|
```js
|
|
4419
|
-
import { get } from '@ember/object';
|
|
4420
4262
|
import Blog from 'app/models/blog'
|
|
4421
4263
|
let fields = Blog.fields;
|
|
4422
4264
|
fields.forEach(function(kind, field) {
|
|
@@ -4438,10 +4280,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4438
4280
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4439
4281
|
let map = new Map();
|
|
4440
4282
|
this.eachComputedProperty((name, meta) => {
|
|
4441
|
-
|
|
4442
|
-
if (meta.isRelationship) {
|
|
4283
|
+
if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
|
|
4443
4284
|
map.set(name, meta.kind);
|
|
4444
|
-
} else if (meta.
|
|
4285
|
+
} else if (meta.kind === 'attribute') {
|
|
4445
4286
|
map.set(name, 'attribute');
|
|
4446
4287
|
}
|
|
4447
4288
|
});
|
|
@@ -4486,7 +4327,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4486
4327
|
}
|
|
4487
4328
|
static determineRelationshipType(knownSide, store) {
|
|
4488
4329
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4489
|
-
let knownKey = knownSide.
|
|
4330
|
+
let knownKey = knownSide.name;
|
|
4490
4331
|
let knownKind = knownSide.kind;
|
|
4491
4332
|
let inverse = this.inverseFor(knownKey, store);
|
|
4492
4333
|
// let key;
|
|
@@ -4518,16 +4359,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4518
4359
|
}
|
|
4519
4360
|
```
|
|
4520
4361
|
```javascript
|
|
4521
|
-
import { get } from '@ember/object';
|
|
4522
4362
|
import Person from 'app/models/person'
|
|
4523
4363
|
let attributes = Person.attributes
|
|
4524
4364
|
attributes.forEach(function(meta, name) {
|
|
4525
4365
|
// do thing
|
|
4526
4366
|
});
|
|
4527
4367
|
// prints:
|
|
4528
|
-
// firstName {type: "string",
|
|
4529
|
-
// lastName {type: "string",
|
|
4530
|
-
// birthday {type: "date",
|
|
4368
|
+
// firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
|
|
4369
|
+
// lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
|
|
4370
|
+
// birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
|
|
4531
4371
|
```
|
|
4532
4372
|
@property attributes
|
|
4533
4373
|
@public
|
|
@@ -4539,8 +4379,11 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4539
4379
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4540
4380
|
let map = new Map();
|
|
4541
4381
|
this.eachComputedProperty((name, meta) => {
|
|
4542
|
-
if (meta.
|
|
4382
|
+
if (meta.kind === 'attribute') {
|
|
4543
4383
|
assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " + this.toString(), name !== 'id');
|
|
4384
|
+
|
|
4385
|
+
// TODO deprecate key being here
|
|
4386
|
+
meta.key = name;
|
|
4544
4387
|
meta.name = name;
|
|
4545
4388
|
map.set(name, meta);
|
|
4546
4389
|
}
|
|
@@ -4563,7 +4406,6 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4563
4406
|
}
|
|
4564
4407
|
```
|
|
4565
4408
|
```javascript
|
|
4566
|
-
import { get } from '@ember/object';
|
|
4567
4409
|
import Person from 'app/models/person';
|
|
4568
4410
|
let transformedAttributes = Person.transformedAttributes
|
|
4569
4411
|
transformedAttributes.forEach(function(field, type) {
|
|
@@ -4582,9 +4424,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4582
4424
|
static get transformedAttributes() {
|
|
4583
4425
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4584
4426
|
let map = new Map();
|
|
4585
|
-
this.eachAttribute((
|
|
4427
|
+
this.eachAttribute((name, meta) => {
|
|
4586
4428
|
if (meta.type) {
|
|
4587
|
-
map.set(
|
|
4429
|
+
map.set(name, meta.type);
|
|
4588
4430
|
}
|
|
4589
4431
|
});
|
|
4590
4432
|
return map;
|
|
@@ -4614,9 +4456,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4614
4456
|
// do thing
|
|
4615
4457
|
});
|
|
4616
4458
|
// prints:
|
|
4617
|
-
// firstName {type: "string",
|
|
4618
|
-
// lastName {type: "string",
|
|
4619
|
-
// birthday {type: "date",
|
|
4459
|
+
// firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
|
|
4460
|
+
// lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
|
|
4461
|
+
// birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
|
|
4620
4462
|
```
|
|
4621
4463
|
@method eachAttribute
|
|
4622
4464
|
@public
|
|
@@ -4683,14 +4525,10 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4683
4525
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4684
4526
|
return `model:${this.modelName}`;
|
|
4685
4527
|
}
|
|
4686
|
-
}, _class2.isModel = true, _class2.modelName = null, _class2), (_applyDecoratedDescriptor(_class.prototype, "isEmpty", [
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
initializer: function () {
|
|
4691
|
-
return false;
|
|
4692
|
-
}
|
|
4693
|
-
}), _applyDecoratedDescriptor(_class.prototype, "id", [tagged], Object.getOwnPropertyDescriptor(_class.prototype, "id"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "currentState", [tagged], Object.getOwnPropertyDescriptor(_class.prototype, "currentState"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "errors", [computeOnce], Object.getOwnPropertyDescriptor(_class.prototype, "errors"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "adapterError", [dependentKeyCompat], Object.getOwnPropertyDescriptor(_class.prototype, "adapterError"), _class.prototype), _applyDecoratedDescriptor(_class, "inverseMap", [computeOnce], Object.getOwnPropertyDescriptor(_class, "inverseMap"), _class), _applyDecoratedDescriptor(_class, "relationships", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationships"), _class), _applyDecoratedDescriptor(_class, "relationshipNames", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipNames"), _class), _applyDecoratedDescriptor(_class, "relatedTypes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relatedTypes"), _class), _applyDecoratedDescriptor(_class, "relationshipsByName", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipsByName"), _class), _applyDecoratedDescriptor(_class, "relationshipsObject", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipsObject"), _class), _applyDecoratedDescriptor(_class, "fields", [computeOnce], Object.getOwnPropertyDescriptor(_class, "fields"), _class), _applyDecoratedDescriptor(_class, "attributes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "attributes"), _class), _applyDecoratedDescriptor(_class, "transformedAttributes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "transformedAttributes"), _class)), _class); // this is required to prevent `init` from passing
|
|
4528
|
+
}, _class2.isModel = true, _class2.modelName = null, _class2), (_applyDecoratedDescriptor(_class.prototype, "isEmpty", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isEmpty"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isLoading", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isLoading"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isLoaded", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isLoaded"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "hasDirtyAttributes", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "hasDirtyAttributes"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isSaving", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isSaving"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isDeleted", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isDeleted"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isNew", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isNew"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isValid", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isValid"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "dirtyType", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "dirtyType"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isError", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isError"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "id", [tagged], Object.getOwnPropertyDescriptor(_class.prototype, "id"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "currentState", [tagged], Object.getOwnPropertyDescriptor(_class.prototype, "currentState"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "errors", [computeOnce], Object.getOwnPropertyDescriptor(_class.prototype, "errors"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "adapterError", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "adapterError"), _class.prototype), _applyDecoratedDescriptor(_class, "inverseMap", [computeOnce], Object.getOwnPropertyDescriptor(_class, "inverseMap"), _class), _applyDecoratedDescriptor(_class, "relationships", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationships"), _class), _applyDecoratedDescriptor(_class, "relationshipNames", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipNames"), _class), _applyDecoratedDescriptor(_class, "relatedTypes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relatedTypes"), _class), _applyDecoratedDescriptor(_class, "relationshipsByName", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipsByName"), _class), _applyDecoratedDescriptor(_class, "relationshipsObject", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipsObject"), _class), _applyDecoratedDescriptor(_class, "fields", [computeOnce], Object.getOwnPropertyDescriptor(_class, "fields"), _class), _applyDecoratedDescriptor(_class, "attributes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "attributes"), _class), _applyDecoratedDescriptor(_class, "transformedAttributes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "transformedAttributes"), _class)), _class);
|
|
4529
|
+
defineSignal(Model.prototype, 'isReloading', false);
|
|
4530
|
+
|
|
4531
|
+
// this is required to prevent `init` from passing
|
|
4694
4532
|
// the values initialized during create to `setUnknownProperty`
|
|
4695
4533
|
Model.prototype._createProps = null;
|
|
4696
4534
|
Model.prototype._secretInit = null;
|