@ember-data/legacy-compat 5.4.0-alpha.3 → 5.4.0-alpha.30
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.
|
@@ -10,7 +10,7 @@ import { createDeferred } from '@ember-data/request';
|
|
|
10
10
|
/**
|
|
11
11
|
SnapshotRecordArray is not directly instantiable.
|
|
12
12
|
Instances are provided to consuming application's
|
|
13
|
-
adapters for certain requests.
|
|
13
|
+
adapters for certain `findAll` requests.
|
|
14
14
|
|
|
15
15
|
@class SnapshotRecordArray
|
|
16
16
|
@public
|
|
@@ -140,6 +140,7 @@ class SnapshotRecordArray {
|
|
|
140
140
|
if (this._snapshots !== null) {
|
|
141
141
|
return this._snapshots;
|
|
142
142
|
}
|
|
143
|
+
upgradeStore(this.__store);
|
|
143
144
|
const {
|
|
144
145
|
_fetchManager
|
|
145
146
|
} = this.__store;
|
|
@@ -148,7 +149,7 @@ class SnapshotRecordArray {
|
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
function assertIdentifierHasId(identifier) {
|
|
151
|
-
assert(`Attempted to schedule a fetch for a record without an id.`, identifier.id !== null);
|
|
152
|
+
assert(`Attempted to schedule a fetch for a record without an id.`, identifier && identifier.id !== null);
|
|
152
153
|
}
|
|
153
154
|
function iterateData(data, fn) {
|
|
154
155
|
if (Array.isArray(data)) {
|
|
@@ -175,7 +176,7 @@ function payloadIsNotBlank(adapterPayload) {
|
|
|
175
176
|
*/
|
|
176
177
|
function validateDocumentStructure(doc) {
|
|
177
178
|
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
178
|
-
|
|
179
|
+
const errors = [];
|
|
179
180
|
if (!doc || typeof doc !== 'object') {
|
|
180
181
|
errors.push('Top level of a JSON API document must be an object');
|
|
181
182
|
} else {
|
|
@@ -221,7 +222,7 @@ function validateDocumentStructure(doc) {
|
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
function normalizeResponseHelper(serializer, store, modelClass, payload, id, requestType) {
|
|
224
|
-
|
|
225
|
+
const normalizedResponse = serializer ? serializer.normalizeResponse(store, modelClass, payload, id, requestType) : payload;
|
|
225
226
|
validateDocumentStructure(normalizedResponse);
|
|
226
227
|
return normalizedResponse;
|
|
227
228
|
}
|
|
@@ -333,7 +334,9 @@ class Snapshot {
|
|
|
333
334
|
@public
|
|
334
335
|
*/
|
|
335
336
|
get record() {
|
|
336
|
-
|
|
337
|
+
const record = this._store.peekRecord(this.identifier);
|
|
338
|
+
assert(`Record ${this.identifier.type} ${this.identifier.id} (${this.identifier.lid}) is not yet loaded and thus cannot be accessed from the Snapshot during serialization`, record !== null);
|
|
339
|
+
return record;
|
|
337
340
|
}
|
|
338
341
|
get _attributes() {
|
|
339
342
|
if (this.__attributes !== null) {
|
|
@@ -406,13 +409,13 @@ class Snapshot {
|
|
|
406
409
|
@public
|
|
407
410
|
*/
|
|
408
411
|
changedAttributes() {
|
|
409
|
-
|
|
412
|
+
const changedAttributes = Object.create(null);
|
|
410
413
|
if (!this._changedAttributes) {
|
|
411
414
|
return changedAttributes;
|
|
412
415
|
}
|
|
413
|
-
|
|
416
|
+
const changedAttributeKeys = Object.keys(this._changedAttributes);
|
|
414
417
|
for (let i = 0, length = changedAttributeKeys.length; i < length; i++) {
|
|
415
|
-
|
|
418
|
+
const key = changedAttributeKeys[i];
|
|
416
419
|
changedAttributes[key] = this._changedAttributes[key].slice();
|
|
417
420
|
}
|
|
418
421
|
return changedAttributes;
|
|
@@ -447,16 +450,16 @@ class Snapshot {
|
|
|
447
450
|
will be returned if the contents of the relationship is unknown.
|
|
448
451
|
*/
|
|
449
452
|
belongsTo(keyName, options) {
|
|
450
|
-
|
|
453
|
+
const returnModeIsId = !!(options && options.id);
|
|
451
454
|
let result;
|
|
452
|
-
|
|
455
|
+
const store = this._store;
|
|
453
456
|
if (returnModeIsId === true && keyName in this._belongsToIds) {
|
|
454
457
|
return this._belongsToIds[keyName];
|
|
455
458
|
}
|
|
456
459
|
if (returnModeIsId === false && keyName in this._belongsToRelationships) {
|
|
457
460
|
return this._belongsToRelationships[keyName];
|
|
458
461
|
}
|
|
459
|
-
|
|
462
|
+
const relationshipMeta = store.getSchemaDefinitionService().relationshipsDefinitionFor({
|
|
460
463
|
type: this.modelName
|
|
461
464
|
})[keyName];
|
|
462
465
|
assert(`Model '${this.identifier.lid}' has no belongsTo relationship named '${keyName}' defined.`, relationshipMeta && relationshipMeta.kind === 'belongsTo');
|
|
@@ -478,9 +481,9 @@ class Snapshot {
|
|
|
478
481
|
assert(`You looked up the ${keyName} belongsTo relationship for { type: ${identifier.type}, id: ${identifier.id || ''}, lid: ${identifier.lid} but no such relationship was found.`, relationship);
|
|
479
482
|
assert(`You looked up the ${keyName} belongsTo relationship for { type: ${identifier.type}, id: ${identifier.id || ''}, lid: ${identifier.lid} but that relationship is a hasMany.`, relationship.definition.kind === 'belongsTo');
|
|
480
483
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
+
const value = graphFor(this._store).getData(identifier, keyName);
|
|
485
|
+
const data = value && value.data;
|
|
486
|
+
const inverseIdentifier = data ? store.identifierCache.getOrCreateRecordIdentifier(data) : null;
|
|
484
487
|
if (value && value.data !== undefined) {
|
|
485
488
|
const cache = store.cache;
|
|
486
489
|
if (inverseIdentifier && !cache.isDeleted(inverseIdentifier)) {
|
|
@@ -525,18 +528,18 @@ class Snapshot {
|
|
|
525
528
|
undefined will be returned if the contents of the relationship is unknown.
|
|
526
529
|
*/
|
|
527
530
|
hasMany(keyName, options) {
|
|
528
|
-
|
|
531
|
+
const returnModeIsIds = !!(options && options.ids);
|
|
529
532
|
let results;
|
|
530
|
-
|
|
531
|
-
|
|
533
|
+
const cachedIds = this._hasManyIds[keyName];
|
|
534
|
+
const cachedSnapshots = this._hasManyRelationships[keyName];
|
|
532
535
|
if (returnModeIsIds === true && keyName in this._hasManyIds) {
|
|
533
536
|
return cachedIds;
|
|
534
537
|
}
|
|
535
538
|
if (returnModeIsIds === false && keyName in this._hasManyRelationships) {
|
|
536
539
|
return cachedSnapshots;
|
|
537
540
|
}
|
|
538
|
-
|
|
539
|
-
|
|
541
|
+
const store = this._store;
|
|
542
|
+
const relationshipMeta = store.getSchemaDefinitionService().relationshipsDefinitionFor({
|
|
540
543
|
type: this.modelName
|
|
541
544
|
})[keyName];
|
|
542
545
|
assert(`Model '${this.identifier.lid}' has no hasMany relationship named '${keyName}' defined.`, relationshipMeta && relationshipMeta.kind === 'hasMany');
|
|
@@ -558,11 +561,11 @@ class Snapshot {
|
|
|
558
561
|
assert(`You looked up the ${keyName} hasMany relationship for { type: ${identifier.type}, id: ${identifier.id || ''}, lid: ${identifier.lid} but no such relationship was found.`, relationship);
|
|
559
562
|
assert(`You looked up the ${keyName} hasMany relationship for { type: ${identifier.type}, id: ${identifier.id || ''}, lid: ${identifier.lid} but that relationship is a belongsTo.`, relationship.definition.kind === 'hasMany');
|
|
560
563
|
}
|
|
561
|
-
|
|
564
|
+
const value = graphFor(this._store).getData(identifier, keyName);
|
|
562
565
|
if (value.data) {
|
|
563
566
|
results = [];
|
|
564
567
|
value.data.forEach(member => {
|
|
565
|
-
|
|
568
|
+
const inverseIdentifier = store.identifierCache.getOrCreateRecordIdentifier(member);
|
|
566
569
|
const cache = store.cache;
|
|
567
570
|
if (!cache.isDeleted(inverseIdentifier)) {
|
|
568
571
|
if (returnModeIsIds) {
|
|
@@ -599,7 +602,7 @@ class Snapshot {
|
|
|
599
602
|
@public
|
|
600
603
|
*/
|
|
601
604
|
eachAttribute(callback, binding) {
|
|
602
|
-
|
|
605
|
+
const attrDefs = this._store.getSchemaDefinitionService().attributesDefinitionFor(this.identifier);
|
|
603
606
|
Object.keys(attrDefs).forEach(key => {
|
|
604
607
|
callback.call(binding, key, attrDefs[key]);
|
|
605
608
|
});
|
|
@@ -620,7 +623,7 @@ class Snapshot {
|
|
|
620
623
|
@public
|
|
621
624
|
*/
|
|
622
625
|
eachRelationship(callback, binding) {
|
|
623
|
-
|
|
626
|
+
const relationshipDefs = this._store.getSchemaDefinitionService().relationshipsDefinitionFor(this.identifier);
|
|
624
627
|
Object.keys(relationshipDefs).forEach(key => {
|
|
625
628
|
callback.call(binding, key, relationshipDefs[key]);
|
|
626
629
|
});
|
|
@@ -648,6 +651,7 @@ class Snapshot {
|
|
|
648
651
|
@public
|
|
649
652
|
*/
|
|
650
653
|
serialize(options) {
|
|
654
|
+
upgradeStore(this._store);
|
|
651
655
|
const serializer = this._store.serializerFor(this.modelName);
|
|
652
656
|
assert(`Cannot serialize record, no serializer found`, serializer);
|
|
653
657
|
return serializer.serialize(this, options);
|
|
@@ -675,13 +679,13 @@ class FetchManager {
|
|
|
675
679
|
@internal
|
|
676
680
|
*/
|
|
677
681
|
scheduleSave(identifier, options) {
|
|
678
|
-
|
|
679
|
-
|
|
682
|
+
const resolver = createDeferred();
|
|
683
|
+
const query = {
|
|
680
684
|
op: 'saveRecord',
|
|
681
685
|
recordIdentifier: identifier,
|
|
682
686
|
options
|
|
683
687
|
};
|
|
684
|
-
|
|
688
|
+
const queryRequest = {
|
|
685
689
|
data: [query]
|
|
686
690
|
};
|
|
687
691
|
const snapshot = this.createSnapshot(identifier, options);
|
|
@@ -697,19 +701,19 @@ class FetchManager {
|
|
|
697
701
|
return monitored;
|
|
698
702
|
}
|
|
699
703
|
scheduleFetch(identifier, options, request) {
|
|
700
|
-
|
|
704
|
+
const query = {
|
|
701
705
|
op: 'findRecord',
|
|
702
706
|
recordIdentifier: identifier,
|
|
703
707
|
options
|
|
704
708
|
};
|
|
705
|
-
|
|
709
|
+
const queryRequest = {
|
|
706
710
|
data: [query]
|
|
707
711
|
};
|
|
708
|
-
|
|
712
|
+
const pendingFetch = this.getPendingFetch(identifier, options);
|
|
709
713
|
if (pendingFetch) {
|
|
710
714
|
return pendingFetch;
|
|
711
715
|
}
|
|
712
|
-
|
|
716
|
+
const modelName = identifier.type;
|
|
713
717
|
const resolver = createDeferred();
|
|
714
718
|
const pendingFetchItem = {
|
|
715
719
|
identifier,
|
|
@@ -717,7 +721,7 @@ class FetchManager {
|
|
|
717
721
|
options,
|
|
718
722
|
queryRequest
|
|
719
723
|
};
|
|
720
|
-
|
|
724
|
+
const resolverPromise = resolver.promise;
|
|
721
725
|
const store = this._store;
|
|
722
726
|
const isInitialLoad = !store._instanceCache.recordIsLoaded(identifier); // we don't use isLoading directly because we are the request
|
|
723
727
|
|
|
@@ -730,7 +734,7 @@ class FetchManager {
|
|
|
730
734
|
|
|
731
735
|
// additional data received in the payload
|
|
732
736
|
// may result in the merging of identifiers (and thus records)
|
|
733
|
-
|
|
737
|
+
const potentiallyNewIm = store._push(payload, options.reload);
|
|
734
738
|
if (potentiallyNewIm && !Array.isArray(potentiallyNewIm)) {
|
|
735
739
|
return potentiallyNewIm;
|
|
736
740
|
}
|
|
@@ -763,7 +767,7 @@ class FetchManager {
|
|
|
763
767
|
this.flushAllPendingFetches();
|
|
764
768
|
});
|
|
765
769
|
}
|
|
766
|
-
|
|
770
|
+
const fetchesByType = this._pendingFetch;
|
|
767
771
|
let fetchesById = fetchesByType.get(modelName);
|
|
768
772
|
if (!fetchesById) {
|
|
769
773
|
fetchesById = new Map();
|
|
@@ -787,11 +791,11 @@ class FetchManager {
|
|
|
787
791
|
return promise;
|
|
788
792
|
}
|
|
789
793
|
getPendingFetch(identifier, options) {
|
|
790
|
-
|
|
794
|
+
const pendingFetches = this._pendingFetch.get(identifier.type)?.get(identifier);
|
|
791
795
|
|
|
792
796
|
// We already have a pending fetch for this
|
|
793
797
|
if (pendingFetches) {
|
|
794
|
-
|
|
798
|
+
const matchingPendingFetch = pendingFetches.find(fetch => isSameRequest(options, fetch.options));
|
|
795
799
|
if (matchingPendingFetch) {
|
|
796
800
|
return matchingPendingFetch.promise;
|
|
797
801
|
}
|
|
@@ -887,27 +891,27 @@ function isSameRequest(options = {}, existingOptions = {}) {
|
|
|
887
891
|
return optionsSatisfies(options.adapterOptions, existingOptions.adapterOptions) && includesSatisfies(options.include, existingOptions.include);
|
|
888
892
|
}
|
|
889
893
|
function _findMany(store, adapter, modelName, snapshots) {
|
|
890
|
-
|
|
891
|
-
|
|
894
|
+
const modelClass = store.modelFor(modelName); // `adapter.findMany` gets the modelClass still
|
|
895
|
+
const promise = Promise.resolve().then(() => {
|
|
892
896
|
const ids = snapshots.map(s => s.id);
|
|
893
897
|
assert(`Cannot fetch a record without an id`, ids.every(v => v !== null));
|
|
894
898
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
895
899
|
assert(`Expected this adapter to implement findMany for coalescing`, adapter.findMany);
|
|
896
|
-
|
|
900
|
+
const ret = adapter.findMany(store, modelClass, ids, snapshots);
|
|
897
901
|
assert('adapter.findMany returned undefined, this was very likely a mistake', ret !== undefined);
|
|
898
902
|
return ret;
|
|
899
903
|
});
|
|
900
904
|
return promise.then(adapterPayload => {
|
|
901
905
|
assert(`You made a 'findMany' request for '${modelName}' records with ids '[${snapshots.map(s => s.id).join(',')}]', but the adapter's response did not have any data`, !!payloadIsNotBlank(adapterPayload));
|
|
902
|
-
|
|
903
|
-
|
|
906
|
+
const serializer = store.serializerFor(modelName);
|
|
907
|
+
const payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findMany');
|
|
904
908
|
return payload;
|
|
905
909
|
});
|
|
906
910
|
}
|
|
907
911
|
function rejectFetchedItems(fetchMap, snapshots, error) {
|
|
908
912
|
for (let i = 0, l = snapshots.length; i < l; i++) {
|
|
909
|
-
|
|
910
|
-
|
|
913
|
+
const snapshot = snapshots[i];
|
|
914
|
+
const pair = fetchMap.get(snapshot);
|
|
911
915
|
if (pair) {
|
|
912
916
|
pair.resolver.reject(error || new Error(`Expected: '<${snapshot.modelName}:${snapshot.id}>' to be present in the adapter provided payload, but it was not found.`));
|
|
913
917
|
}
|
|
@@ -923,9 +927,9 @@ function handleFoundRecords(store, fetchMap, snapshots, coalescedPayload) {
|
|
|
923
927
|
options object, we resolve all snapshots by id with
|
|
924
928
|
the first response we see.
|
|
925
929
|
*/
|
|
926
|
-
|
|
930
|
+
const snapshotsById = new Map();
|
|
927
931
|
for (let i = 0; i < snapshots.length; i++) {
|
|
928
|
-
|
|
932
|
+
const id = snapshots[i].id;
|
|
929
933
|
let snapshotGroup = snapshotsById.get(id);
|
|
930
934
|
if (!snapshotGroup) {
|
|
931
935
|
snapshotGroup = [];
|
|
@@ -936,18 +940,18 @@ function handleFoundRecords(store, fetchMap, snapshots, coalescedPayload) {
|
|
|
936
940
|
const included = Array.isArray(coalescedPayload.included) ? coalescedPayload.included : [];
|
|
937
941
|
|
|
938
942
|
// resolve found records
|
|
939
|
-
|
|
943
|
+
const resources = coalescedPayload.data;
|
|
940
944
|
for (let i = 0, l = resources.length; i < l; i++) {
|
|
941
|
-
|
|
942
|
-
|
|
945
|
+
const resource = resources[i];
|
|
946
|
+
const snapshotGroup = snapshotsById.get(resource.id);
|
|
943
947
|
snapshotsById.delete(resource.id);
|
|
944
948
|
if (!snapshotGroup) {
|
|
945
949
|
// TODO consider whether this should be a deprecation/assertion
|
|
946
950
|
included.push(resource);
|
|
947
951
|
} else {
|
|
948
952
|
snapshotGroup.forEach(snapshot => {
|
|
949
|
-
|
|
950
|
-
|
|
953
|
+
const pair = fetchMap.get(snapshot);
|
|
954
|
+
const resolver = pair.resolver;
|
|
951
955
|
resolver.resolve({
|
|
952
956
|
data: resource
|
|
953
957
|
});
|
|
@@ -965,7 +969,7 @@ function handleFoundRecords(store, fetchMap, snapshots, coalescedPayload) {
|
|
|
965
969
|
}
|
|
966
970
|
|
|
967
971
|
// reject missing records
|
|
968
|
-
|
|
972
|
+
const rejected = [];
|
|
969
973
|
snapshotsById.forEach(snapshotArray => {
|
|
970
974
|
rejected.push(...snapshotArray);
|
|
971
975
|
});
|
|
@@ -975,21 +979,21 @@ function handleFoundRecords(store, fetchMap, snapshots, coalescedPayload) {
|
|
|
975
979
|
rejectFetchedItems(fetchMap, rejected);
|
|
976
980
|
}
|
|
977
981
|
function _fetchRecord(store, adapter, fetchItem) {
|
|
978
|
-
|
|
979
|
-
|
|
982
|
+
const identifier = fetchItem.identifier;
|
|
983
|
+
const modelName = identifier.type;
|
|
980
984
|
assert(`You tried to find a record but you have no adapter (for ${modelName})`, adapter);
|
|
981
985
|
assert(`You tried to find a record but your adapter (for ${modelName}) does not implement 'findRecord'`, typeof adapter.findRecord === 'function');
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
986
|
+
const snapshot = store._fetchManager.createSnapshot(identifier, fetchItem.options);
|
|
987
|
+
const klass = store.modelFor(identifier.type);
|
|
988
|
+
const id = identifier.id;
|
|
985
989
|
let promise = Promise.resolve().then(() => {
|
|
986
990
|
return adapter.findRecord(store, klass, identifier.id, snapshot);
|
|
987
991
|
});
|
|
988
992
|
promise = promise.then(adapterPayload => {
|
|
989
993
|
assert(`Async Leak Detected: Expected the store to not be destroyed`, !(store.isDestroyed || store.isDestroying));
|
|
990
994
|
assert(`You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`, !!payloadIsNotBlank(adapterPayload));
|
|
991
|
-
|
|
992
|
-
|
|
995
|
+
const serializer = store.serializerFor(modelName);
|
|
996
|
+
const payload = normalizeResponseHelper(serializer, store, klass, adapterPayload, id, 'findRecord');
|
|
993
997
|
assert(`Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`, !Array.isArray(payload.data));
|
|
994
998
|
assert(`The 'findRecord' request for ${modelName}:${id} resolved indicating success but contained no primary data. To indicate a 404 not found you should either reject the promise returned by the adapter's findRecord method or throw a NotFoundError.`, 'data' in payload && payload.data !== null && typeof payload.data === 'object');
|
|
995
999
|
warn(`You requested a record of type '${modelName}' with id '${id}' but the adapter returned a payload with primary data having an id of '${payload.data.id}'. Use 'store.findRecord()' when the requested id is the same as the one returned by the adapter. In other cases use 'store.queryRecord()' instead.`, coerceId(payload.data.id) === coerceId(id), {
|
|
@@ -1013,8 +1017,8 @@ function _processCoalescedGroup(store, fetchMap, group, adapter, modelName) {
|
|
|
1013
1017
|
}
|
|
1014
1018
|
}
|
|
1015
1019
|
function _flushPendingFetchForType(store, pendingFetchMap, modelName) {
|
|
1016
|
-
|
|
1017
|
-
|
|
1020
|
+
const adapter = store.adapterFor(modelName);
|
|
1021
|
+
const shouldCoalesce = !!adapter.findMany && adapter.coalesceFindRequests;
|
|
1018
1022
|
if (shouldCoalesce) {
|
|
1019
1023
|
const pendingFetchItems = [];
|
|
1020
1024
|
pendingFetchMap.forEach((requestsForIdentifier, identifier) => {
|
|
@@ -1026,12 +1030,12 @@ function _flushPendingFetchForType(store, pendingFetchMap, modelName) {
|
|
|
1026
1030
|
pendingFetchMap.delete(identifier);
|
|
1027
1031
|
pendingFetchItems.push(requestsForIdentifier[0]);
|
|
1028
1032
|
});
|
|
1029
|
-
|
|
1033
|
+
const totalItems = pendingFetchItems.length;
|
|
1030
1034
|
if (totalItems > 1) {
|
|
1031
|
-
|
|
1032
|
-
|
|
1035
|
+
const snapshots = new Array(totalItems);
|
|
1036
|
+
const fetchMap = new Map();
|
|
1033
1037
|
for (let i = 0; i < totalItems; i++) {
|
|
1034
|
-
|
|
1038
|
+
const fetchItem = pendingFetchItems[i];
|
|
1035
1039
|
snapshots[i] = store._fetchManager.createSnapshot(fetchItem.identifier, fetchItem.options);
|
|
1036
1040
|
fetchMap.set(snapshots[i], fetchItem);
|
|
1037
1041
|
}
|
|
@@ -1045,12 +1049,12 @@ function _flushPendingFetchForType(store, pendingFetchMap, modelName) {
|
|
|
1045
1049
|
_processCoalescedGroup(store, fetchMap, groups[i], adapter, modelName);
|
|
1046
1050
|
}
|
|
1047
1051
|
} else if (totalItems === 1) {
|
|
1048
|
-
|
|
1052
|
+
_fetchRecord(store, adapter, pendingFetchItems[0]);
|
|
1049
1053
|
}
|
|
1050
1054
|
}
|
|
1051
1055
|
pendingFetchMap.forEach(pendingFetchItems => {
|
|
1052
1056
|
pendingFetchItems.forEach(pendingFetchItem => {
|
|
1053
|
-
|
|
1057
|
+
_fetchRecord(store, adapter, pendingFetchItem);
|
|
1054
1058
|
});
|
|
1055
1059
|
});
|
|
1056
1060
|
}
|
|
@@ -1063,12 +1067,12 @@ function _flushPendingSave(store, pending) {
|
|
|
1063
1067
|
} = pending;
|
|
1064
1068
|
const adapter = store.adapterFor(identifier.type);
|
|
1065
1069
|
const operation = options[SaveOp];
|
|
1066
|
-
|
|
1067
|
-
|
|
1070
|
+
const modelName = snapshot.modelName;
|
|
1071
|
+
const modelClass = store.modelFor(modelName);
|
|
1068
1072
|
assert(`You tried to update a record but you have no adapter (for ${modelName})`, adapter);
|
|
1069
1073
|
assert(`You tried to update a record but your adapter (for ${modelName}) does not implement '${operation}'`, typeof adapter[operation] === 'function');
|
|
1070
1074
|
let promise = Promise.resolve().then(() => adapter[operation](store, modelClass, snapshot));
|
|
1071
|
-
|
|
1075
|
+
const serializer = store.serializerFor(modelName);
|
|
1072
1076
|
assert(`Your adapter's '${operation}' method must return a value, but it returned 'undefined'`, promise !== undefined);
|
|
1073
1077
|
promise = promise.then(adapterPayload => {
|
|
1074
1078
|
if (adapterPayload) {
|
|
@@ -1077,4 +1081,13 @@ function _flushPendingSave(store, pending) {
|
|
|
1077
1081
|
});
|
|
1078
1082
|
resolver.resolve(promise);
|
|
1079
1083
|
}
|
|
1080
|
-
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Utilities - often temporary - for maintaining backwards compatibility with
|
|
1087
|
+
* older parts of EmberData.
|
|
1088
|
+
*
|
|
1089
|
+
@module @ember-data/legacy-compat
|
|
1090
|
+
@main @ember-data/legacy-compat
|
|
1091
|
+
*/
|
|
1092
|
+
function upgradeStore(store) {}
|
|
1093
|
+
export { FetchManager as F, SaveOp as S, assertIdentifierHasId as a, SnapshotRecordArray as b, Snapshot as c, iterateData as i, normalizeResponseHelper as n, payloadIsNotBlank as p, upgradeStore as u };
|