@ember-data/store 4.12.0 → 4.12.2
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/README.md +1 -1
- package/addon/-private.js +1 -1
- package/addon/{index-8b77b852.js → index-0b6637cb.js} +306 -240
- package/addon/index-0b6637cb.js.map +1 -0
- package/addon/index.js +1 -1
- package/addon-main.js +1 -1
- package/package.json +7 -7
- package/addon/index-8b77b852.js.map +0 -1
|
@@ -2,11 +2,11 @@ import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';
|
|
|
2
2
|
import { assert, warn, deprecate } from '@ember/debug';
|
|
3
3
|
import { dasherize } from '@ember/string';
|
|
4
4
|
import { getOwner, setOwner } from '@ember/application';
|
|
5
|
+
import EmberObject, { get, set } from '@ember/object';
|
|
5
6
|
import { _backburner } from '@ember/runloop';
|
|
6
7
|
import { tracked } from '@glimmer/tracking';
|
|
7
|
-
import {
|
|
8
|
+
import { addToTransaction, subscribe, addTransactionCB } from '@ember-data/tracking/-private';
|
|
8
9
|
import { tagForProperty } from '@ember/-internals/metal';
|
|
9
|
-
import { get, set } from '@ember/object';
|
|
10
10
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
11
11
|
import { compare } from '@ember/utils';
|
|
12
12
|
import { dirtyTag } from '@glimmer/validator';
|
|
@@ -200,6 +200,7 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
|
|
|
200
200
|
return document;
|
|
201
201
|
}
|
|
202
202
|
const data = recordArrayManager.createArray({
|
|
203
|
+
type: request.url,
|
|
203
204
|
identifiers: document.data,
|
|
204
205
|
doc: document,
|
|
205
206
|
query: request
|
|
@@ -213,6 +214,7 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
|
|
|
213
214
|
let managed = recordArrayManager._keyedArrays.get(identifier.lid);
|
|
214
215
|
if (!managed) {
|
|
215
216
|
managed = recordArrayManager.createArray({
|
|
217
|
+
type: identifier.lid,
|
|
216
218
|
identifiers: document.data,
|
|
217
219
|
doc: document
|
|
218
220
|
});
|
|
@@ -1084,205 +1086,11 @@ function detectMerge(typesCache, identifier, data, newId, lids) {
|
|
|
1084
1086
|
}
|
|
1085
1087
|
return false;
|
|
1086
1088
|
}
|
|
1087
|
-
|
|
1088
|
-
const CacheOperations = new Set(['added', 'removed', 'state', 'updated']);
|
|
1089
|
-
function isCacheOperationValue(value) {
|
|
1090
|
-
return CacheOperations.has(value);
|
|
1091
|
-
}
|
|
1092
|
-
function runLoopIsFlushing() {
|
|
1093
|
-
//@ts-expect-error
|
|
1094
|
-
return !!_backburner.currentInstance && _backburner._autorun !== true;
|
|
1095
|
-
}
|
|
1096
|
-
const Cache = new Map();
|
|
1097
|
-
const Tokens = new Map();
|
|
1098
|
-
// TODO this isn't importable anyway, remove and use a map on the manager?
|
|
1099
|
-
function unsubscribe(token) {
|
|
1100
|
-
let identifier = Tokens.get(token);
|
|
1101
|
-
if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
|
|
1102
|
-
if (!identifier) {
|
|
1103
|
-
// eslint-disable-next-line no-console
|
|
1104
|
-
console.log('Passed unknown unsubscribe token to unsubscribe', identifier);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
if (identifier) {
|
|
1108
|
-
Tokens.delete(token);
|
|
1109
|
-
const map = Cache.get(identifier);
|
|
1110
|
-
map?.delete(token);
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1089
|
+
var _class$2, _descriptor$2;
|
|
1113
1090
|
|
|
1114
1091
|
/**
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
*
|
|
1118
|
-
* This Feature is what allows EmberData to create subscriptions that
|
|
1119
|
-
* work with any framework or change-notification system.
|
|
1120
|
-
*
|
|
1121
|
-
* @class NotificationManager
|
|
1122
|
-
* @public
|
|
1123
|
-
*/
|
|
1124
|
-
class NotificationManager {
|
|
1125
|
-
constructor(store) {
|
|
1126
|
-
this.store = store;
|
|
1127
|
-
this.isDestroyed = false;
|
|
1128
|
-
this._buffered = new Map();
|
|
1129
|
-
this._hasFlush = false;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
/**
|
|
1133
|
-
* Subscribe to changes for a given resource identifier, resource addition/removal, or document addition/removal.
|
|
1134
|
-
*
|
|
1135
|
-
* ```ts
|
|
1136
|
-
* export type CacheOperation = 'added' | 'removed' | 'updated' | 'state';
|
|
1137
|
-
*
|
|
1138
|
-
* export interface NotificationCallback {
|
|
1139
|
-
* (identifier: StableRecordIdentifier, notificationType: 'attributes' | 'relationships', key?: string): void;
|
|
1140
|
-
* (identifier: StableRecordIdentifier, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;
|
|
1141
|
-
* (identifier: StableRecordIdentifier, notificationType: NotificationType, key?: string): void;
|
|
1142
|
-
* }
|
|
1143
|
-
* export interface ResourceOperationCallback {
|
|
1144
|
-
* // resource updates
|
|
1145
|
-
* (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
|
|
1146
|
-
* }
|
|
1147
|
-
* export interface DocumentOperationCallback {
|
|
1148
|
-
* // document updates
|
|
1149
|
-
* (identifier: StableDocumentIdentifier, notificationType: CacheOperation): void;
|
|
1150
|
-
* }
|
|
1151
|
-
* ```
|
|
1152
|
-
*
|
|
1153
|
-
* @method subscribe
|
|
1154
|
-
* @public
|
|
1155
|
-
* @param {StableDocumentIdentifier | StableRecordIdentifier | 'resource' | 'document'} identifier
|
|
1156
|
-
* @param {NotificationCallback | ResourceOperationCallback | DocumentOperationCallback} callback
|
|
1157
|
-
* @returns {UnsubscribeToken} an opaque token to be used with unsubscribe
|
|
1158
|
-
*/
|
|
1159
|
-
|
|
1160
|
-
subscribe(identifier, callback) {
|
|
1161
|
-
assert(`Expected to receive a stable Identifier to subscribe to`, identifier === 'resource' || identifier === 'document' || isStableIdentifier(identifier) || isDocumentIdentifier(identifier));
|
|
1162
|
-
let map = Cache.get(identifier);
|
|
1163
|
-
if (!map) {
|
|
1164
|
-
map = new Map();
|
|
1165
|
-
Cache.set(identifier, map);
|
|
1166
|
-
}
|
|
1167
|
-
let unsubToken = macroCondition(getOwnConfig().env.DEBUG) ? {
|
|
1168
|
-
_tokenRef: tokenId++
|
|
1169
|
-
} : {};
|
|
1170
|
-
map.set(unsubToken, callback);
|
|
1171
|
-
Tokens.set(unsubToken, identifier);
|
|
1172
|
-
return unsubToken;
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
/**
|
|
1176
|
-
* remove a previous subscription
|
|
1177
|
-
*
|
|
1178
|
-
* @method unsubscribe
|
|
1179
|
-
* @public
|
|
1180
|
-
* @param {UnsubscribeToken} token
|
|
1181
|
-
*/
|
|
1182
|
-
unsubscribe(token) {
|
|
1183
|
-
if (!this.isDestroyed) {
|
|
1184
|
-
unsubscribe(token);
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
/**
|
|
1189
|
-
* Custom Caches and Application Code should not call this method directly.
|
|
1190
|
-
*
|
|
1191
|
-
* @method notify
|
|
1192
|
-
* @param identifier
|
|
1193
|
-
* @param value
|
|
1194
|
-
* @param key
|
|
1195
|
-
* @return {Boolean} whether a notification was delivered to any subscribers
|
|
1196
|
-
* @private
|
|
1197
|
-
*/
|
|
1198
|
-
|
|
1199
|
-
notify(identifier, value, key) {
|
|
1200
|
-
assert(`Notify does not accept a key argument for the namespace '${value}'. Received key '${key || ''}'.`, !key || value === 'attributes' || value === 'relationships');
|
|
1201
|
-
if (!isStableIdentifier(identifier) && !isDocumentIdentifier(identifier)) {
|
|
1202
|
-
if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
|
|
1203
|
-
// eslint-disable-next-line no-console
|
|
1204
|
-
console.log(`Notifying: Expected to receive a stable Identifier to notify '${value}' '${key || ''}' with, but ${String(identifier)} is not in the cache`, identifier);
|
|
1205
|
-
}
|
|
1206
|
-
return false;
|
|
1207
|
-
}
|
|
1208
|
-
if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
|
|
1209
|
-
// eslint-disable-next-line no-console
|
|
1210
|
-
console.log(`Buffering Notify: ${String(identifier.lid)}\t${value}\t${key || ''}`);
|
|
1211
|
-
}
|
|
1212
|
-
const hasSubscribers = Boolean(Cache.get(identifier)?.size);
|
|
1213
|
-
if (isCacheOperationValue(value) || hasSubscribers) {
|
|
1214
|
-
let buffer = this._buffered.get(identifier);
|
|
1215
|
-
if (!buffer) {
|
|
1216
|
-
buffer = [];
|
|
1217
|
-
this._buffered.set(identifier, buffer);
|
|
1218
|
-
}
|
|
1219
|
-
buffer.push([value, key]);
|
|
1220
|
-
void this._scheduleNotify();
|
|
1221
|
-
}
|
|
1222
|
-
return hasSubscribers;
|
|
1223
|
-
}
|
|
1224
|
-
_onNextFlush(cb) {
|
|
1225
|
-
this._onFlushCB = cb;
|
|
1226
|
-
}
|
|
1227
|
-
_scheduleNotify() {
|
|
1228
|
-
const asyncFlush = this.store._enableAsyncFlush;
|
|
1229
|
-
if (this._hasFlush) {
|
|
1230
|
-
if (asyncFlush !== false && !runLoopIsFlushing()) {
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
if (asyncFlush && !runLoopIsFlushing()) {
|
|
1235
|
-
this._hasFlush = true;
|
|
1236
|
-
return;
|
|
1237
|
-
}
|
|
1238
|
-
this._flush();
|
|
1239
|
-
}
|
|
1240
|
-
_flush() {
|
|
1241
|
-
if (this._buffered.size) {
|
|
1242
|
-
this._buffered.forEach((states, identifier) => {
|
|
1243
|
-
states.forEach(args => {
|
|
1244
|
-
// @ts-expect-error
|
|
1245
|
-
this._flushNotification(identifier, args[0], args[1]);
|
|
1246
|
-
});
|
|
1247
|
-
});
|
|
1248
|
-
this._buffered = new Map();
|
|
1249
|
-
}
|
|
1250
|
-
this._hasFlush = false;
|
|
1251
|
-
this._onFlushCB?.();
|
|
1252
|
-
this._onFlushCB = undefined;
|
|
1253
|
-
}
|
|
1254
|
-
_flushNotification(identifier, value, key) {
|
|
1255
|
-
if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
|
|
1256
|
-
// eslint-disable-next-line no-console
|
|
1257
|
-
console.log(`Notifying: ${String(identifier)}\t${value}\t${key || ''}`);
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
// TODO for documents this will need to switch based on Identifier kind
|
|
1261
|
-
if (isCacheOperationValue(value)) {
|
|
1262
|
-
let callbackMap = Cache.get(isDocumentIdentifier(identifier) ? 'document' : 'resource');
|
|
1263
|
-
if (callbackMap) {
|
|
1264
|
-
callbackMap.forEach(cb => {
|
|
1265
|
-
cb(identifier, value);
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
let callbackMap = Cache.get(identifier);
|
|
1270
|
-
if (!callbackMap || !callbackMap.size) {
|
|
1271
|
-
return false;
|
|
1272
|
-
}
|
|
1273
|
-
callbackMap.forEach(cb => {
|
|
1274
|
-
// @ts-expect-error overload doesn't narrow within body
|
|
1275
|
-
cb(identifier, value, key);
|
|
1276
|
-
});
|
|
1277
|
-
return true;
|
|
1278
|
-
}
|
|
1279
|
-
destroy() {
|
|
1280
|
-
this.isDestroyed = true;
|
|
1281
|
-
Tokens.clear();
|
|
1282
|
-
Cache.clear();
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
var _class$2, _descriptor$2;
|
|
1092
|
+
@module @ember-data/store
|
|
1093
|
+
*/
|
|
1286
1094
|
/**
|
|
1287
1095
|
@module @ember-data/store
|
|
1288
1096
|
*/
|
|
@@ -1310,7 +1118,7 @@ let RecordReference = (_class$2 = class RecordReference {
|
|
|
1310
1118
|
});
|
|
1311
1119
|
}
|
|
1312
1120
|
destroy() {
|
|
1313
|
-
unsubscribe(this.___token);
|
|
1121
|
+
this.store.notifications.unsubscribe(this.___token);
|
|
1314
1122
|
}
|
|
1315
1123
|
get type() {
|
|
1316
1124
|
return this.identifier().type;
|
|
@@ -1992,8 +1800,20 @@ class NonSingletonCacheManager {
|
|
|
1992
1800
|
* @public
|
|
1993
1801
|
* @param identifier
|
|
1994
1802
|
*/
|
|
1995
|
-
willCommit(identifier) {
|
|
1996
|
-
|
|
1803
|
+
willCommit(identifier, context) {
|
|
1804
|
+
// called by something V1
|
|
1805
|
+
if (!isStableIdentifier(identifier)) {
|
|
1806
|
+
identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
|
|
1807
|
+
}
|
|
1808
|
+
const cache = _classPrivateFieldBase(this, _cache)[_cache];
|
|
1809
|
+
|
|
1810
|
+
// TODO deprecate return value
|
|
1811
|
+
if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
|
|
1812
|
+
cache.willCommit();
|
|
1813
|
+
} else {
|
|
1814
|
+
assert(`Cannot call a v2 cache willCommit from a v1 cache`, !!context);
|
|
1815
|
+
cache.willCommit(identifier, context);
|
|
1816
|
+
}
|
|
1997
1817
|
}
|
|
1998
1818
|
|
|
1999
1819
|
/**
|
|
@@ -2005,14 +1825,34 @@ class NonSingletonCacheManager {
|
|
|
2005
1825
|
* @param identifier
|
|
2006
1826
|
* @param data
|
|
2007
1827
|
*/
|
|
2008
|
-
didCommit(identifier,
|
|
2009
|
-
// called by something V1
|
|
2010
|
-
if (!isStableIdentifier(identifier)) {
|
|
2011
|
-
data = identifier;
|
|
2012
|
-
identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
|
|
2013
|
-
}
|
|
1828
|
+
didCommit(identifier, result) {
|
|
2014
1829
|
const cache = _classPrivateFieldBase(this, _cache)[_cache];
|
|
2015
|
-
_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)
|
|
1830
|
+
if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
|
|
1831
|
+
// called by something V1
|
|
1832
|
+
if (!isStableIdentifier(identifier)) {
|
|
1833
|
+
cache.didCommit(identifier);
|
|
1834
|
+
return {
|
|
1835
|
+
data: _classPrivateFieldBase(this, _identifier)[_identifier]
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
cache.didCommit(result.content?.data);
|
|
1839
|
+
return {
|
|
1840
|
+
data: _classPrivateFieldBase(this, _identifier)[_identifier]
|
|
1841
|
+
};
|
|
1842
|
+
} else {
|
|
1843
|
+
// called by something V1
|
|
1844
|
+
if (!isStableIdentifier(identifier)) {
|
|
1845
|
+
cache.didCommit(_classPrivateFieldBase(this, _identifier)[_identifier], {
|
|
1846
|
+
content: {
|
|
1847
|
+
data: identifier
|
|
1848
|
+
}
|
|
1849
|
+
});
|
|
1850
|
+
return {
|
|
1851
|
+
data: _classPrivateFieldBase(this, _identifier)[_identifier]
|
|
1852
|
+
};
|
|
1853
|
+
}
|
|
1854
|
+
return cache.didCommit(identifier, result);
|
|
1855
|
+
}
|
|
2016
1856
|
}
|
|
2017
1857
|
|
|
2018
1858
|
/**
|
|
@@ -2484,11 +2324,11 @@ class SingletonCacheManager {
|
|
|
2484
2324
|
clientDidCreate(identifier, options) {
|
|
2485
2325
|
return _classPrivateFieldBase(this, _cache3)[_cache3].clientDidCreate(identifier, options);
|
|
2486
2326
|
}
|
|
2487
|
-
willCommit(identifier) {
|
|
2488
|
-
_classPrivateFieldBase(this, _cache3)[_cache3].willCommit(identifier);
|
|
2327
|
+
willCommit(identifier, context) {
|
|
2328
|
+
_classPrivateFieldBase(this, _cache3)[_cache3].willCommit(identifier, context);
|
|
2489
2329
|
}
|
|
2490
|
-
didCommit(identifier,
|
|
2491
|
-
_classPrivateFieldBase(this, _cache3)[_cache3].didCommit(identifier,
|
|
2330
|
+
didCommit(identifier, result) {
|
|
2331
|
+
return _classPrivateFieldBase(this, _cache3)[_cache3].didCommit(identifier, result);
|
|
2492
2332
|
}
|
|
2493
2333
|
commitWasRejected(identifier, errors) {
|
|
2494
2334
|
_classPrivateFieldBase(this, _cache3)[_cache3].commitWasRejected(identifier, errors);
|
|
@@ -3658,6 +3498,203 @@ class ShimModelClass {
|
|
|
3658
3498
|
});
|
|
3659
3499
|
}
|
|
3660
3500
|
}
|
|
3501
|
+
let tokenId = 0;
|
|
3502
|
+
const CacheOperations = new Set(['added', 'removed', 'state', 'updated']);
|
|
3503
|
+
function isCacheOperationValue(value) {
|
|
3504
|
+
return CacheOperations.has(value);
|
|
3505
|
+
}
|
|
3506
|
+
function runLoopIsFlushing() {
|
|
3507
|
+
//@ts-expect-error
|
|
3508
|
+
return !!_backburner.currentInstance && _backburner._autorun !== true;
|
|
3509
|
+
}
|
|
3510
|
+
function _unsubscribe(tokens, token, cache) {
|
|
3511
|
+
let identifier = tokens.get(token);
|
|
3512
|
+
if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
|
|
3513
|
+
if (!identifier) {
|
|
3514
|
+
// eslint-disable-next-line no-console
|
|
3515
|
+
console.log('Passed unknown unsubscribe token to unsubscribe', identifier);
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
if (identifier) {
|
|
3519
|
+
tokens.delete(token);
|
|
3520
|
+
const map = cache.get(identifier);
|
|
3521
|
+
map?.delete(token);
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
/**
|
|
3526
|
+
* The NotificationManager provides the ability to subscribe to
|
|
3527
|
+
* changes to Cache state.
|
|
3528
|
+
*
|
|
3529
|
+
* This Feature is what allows EmberData to create subscriptions that
|
|
3530
|
+
* work with any framework or change-notification system.
|
|
3531
|
+
*
|
|
3532
|
+
* @class NotificationManager
|
|
3533
|
+
* @public
|
|
3534
|
+
*/
|
|
3535
|
+
class NotificationManager {
|
|
3536
|
+
constructor(store) {
|
|
3537
|
+
this.store = store;
|
|
3538
|
+
this.isDestroyed = false;
|
|
3539
|
+
this._buffered = new Map();
|
|
3540
|
+
this._hasFlush = false;
|
|
3541
|
+
this._cache = new Map();
|
|
3542
|
+
this._tokens = new Map();
|
|
3543
|
+
}
|
|
3544
|
+
|
|
3545
|
+
/**
|
|
3546
|
+
* Subscribe to changes for a given resource identifier, resource addition/removal, or document addition/removal.
|
|
3547
|
+
*
|
|
3548
|
+
* ```ts
|
|
3549
|
+
* export type CacheOperation = 'added' | 'removed' | 'updated' | 'state';
|
|
3550
|
+
*
|
|
3551
|
+
* export interface NotificationCallback {
|
|
3552
|
+
* (identifier: StableRecordIdentifier, notificationType: 'attributes' | 'relationships', key?: string): void;
|
|
3553
|
+
* (identifier: StableRecordIdentifier, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;
|
|
3554
|
+
* (identifier: StableRecordIdentifier, notificationType: NotificationType, key?: string): void;
|
|
3555
|
+
* }
|
|
3556
|
+
* export interface ResourceOperationCallback {
|
|
3557
|
+
* // resource updates
|
|
3558
|
+
* (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
|
|
3559
|
+
* }
|
|
3560
|
+
* export interface DocumentOperationCallback {
|
|
3561
|
+
* // document updates
|
|
3562
|
+
* (identifier: StableDocumentIdentifier, notificationType: CacheOperation): void;
|
|
3563
|
+
* }
|
|
3564
|
+
* ```
|
|
3565
|
+
*
|
|
3566
|
+
* @method subscribe
|
|
3567
|
+
* @public
|
|
3568
|
+
* @param {StableDocumentIdentifier | StableRecordIdentifier | 'resource' | 'document'} identifier
|
|
3569
|
+
* @param {NotificationCallback | ResourceOperationCallback | DocumentOperationCallback} callback
|
|
3570
|
+
* @returns {UnsubscribeToken} an opaque token to be used with unsubscribe
|
|
3571
|
+
*/
|
|
3572
|
+
|
|
3573
|
+
subscribe(identifier, callback) {
|
|
3574
|
+
assert(`Expected to receive a stable Identifier to subscribe to`, identifier === 'resource' || identifier === 'document' || isStableIdentifier(identifier) || isDocumentIdentifier(identifier));
|
|
3575
|
+
let map = this._cache.get(identifier);
|
|
3576
|
+
if (!map) {
|
|
3577
|
+
map = new Map();
|
|
3578
|
+
this._cache.set(identifier, map);
|
|
3579
|
+
}
|
|
3580
|
+
let unsubToken = macroCondition(getOwnConfig().env.DEBUG) ? {
|
|
3581
|
+
_tokenRef: tokenId++
|
|
3582
|
+
} : {};
|
|
3583
|
+
map.set(unsubToken, callback);
|
|
3584
|
+
this._tokens.set(unsubToken, identifier);
|
|
3585
|
+
return unsubToken;
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
/**
|
|
3589
|
+
* remove a previous subscription
|
|
3590
|
+
*
|
|
3591
|
+
* @method unsubscribe
|
|
3592
|
+
* @public
|
|
3593
|
+
* @param {UnsubscribeToken} token
|
|
3594
|
+
*/
|
|
3595
|
+
unsubscribe(token) {
|
|
3596
|
+
if (!this.isDestroyed) {
|
|
3597
|
+
_unsubscribe(this._tokens, token, this._cache);
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
/**
|
|
3602
|
+
* Custom Caches and Application Code should not call this method directly.
|
|
3603
|
+
*
|
|
3604
|
+
* @method notify
|
|
3605
|
+
* @param identifier
|
|
3606
|
+
* @param value
|
|
3607
|
+
* @param key
|
|
3608
|
+
* @return {Boolean} whether a notification was delivered to any subscribers
|
|
3609
|
+
* @private
|
|
3610
|
+
*/
|
|
3611
|
+
|
|
3612
|
+
notify(identifier, value, key) {
|
|
3613
|
+
assert(`Notify does not accept a key argument for the namespace '${value}'. Received key '${key || ''}'.`, !key || value === 'attributes' || value === 'relationships');
|
|
3614
|
+
if (!isStableIdentifier(identifier) && !isDocumentIdentifier(identifier)) {
|
|
3615
|
+
if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
|
|
3616
|
+
// eslint-disable-next-line no-console
|
|
3617
|
+
console.log(`Notifying: Expected to receive a stable Identifier to notify '${value}' '${key || ''}' with, but ${String(identifier)} is not in the cache`, identifier);
|
|
3618
|
+
}
|
|
3619
|
+
return false;
|
|
3620
|
+
}
|
|
3621
|
+
if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
|
|
3622
|
+
// eslint-disable-next-line no-console
|
|
3623
|
+
console.log(`Buffering Notify: ${String(identifier.lid)}\t${value}\t${key || ''}`);
|
|
3624
|
+
}
|
|
3625
|
+
const hasSubscribers = Boolean(this._cache.get(identifier)?.size);
|
|
3626
|
+
if (isCacheOperationValue(value) || hasSubscribers) {
|
|
3627
|
+
let buffer = this._buffered.get(identifier);
|
|
3628
|
+
if (!buffer) {
|
|
3629
|
+
buffer = [];
|
|
3630
|
+
this._buffered.set(identifier, buffer);
|
|
3631
|
+
}
|
|
3632
|
+
buffer.push([value, key]);
|
|
3633
|
+
void this._scheduleNotify();
|
|
3634
|
+
}
|
|
3635
|
+
return hasSubscribers;
|
|
3636
|
+
}
|
|
3637
|
+
_onNextFlush(cb) {
|
|
3638
|
+
this._onFlushCB = cb;
|
|
3639
|
+
}
|
|
3640
|
+
_scheduleNotify() {
|
|
3641
|
+
const asyncFlush = this.store._enableAsyncFlush;
|
|
3642
|
+
if (this._hasFlush) {
|
|
3643
|
+
if (asyncFlush !== false && !runLoopIsFlushing()) {
|
|
3644
|
+
return;
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
if (asyncFlush && !runLoopIsFlushing()) {
|
|
3648
|
+
this._hasFlush = true;
|
|
3649
|
+
return;
|
|
3650
|
+
}
|
|
3651
|
+
this._flush();
|
|
3652
|
+
}
|
|
3653
|
+
_flush() {
|
|
3654
|
+
if (this._buffered.size) {
|
|
3655
|
+
this._buffered.forEach((states, identifier) => {
|
|
3656
|
+
states.forEach(args => {
|
|
3657
|
+
// @ts-expect-error
|
|
3658
|
+
this._flushNotification(identifier, args[0], args[1]);
|
|
3659
|
+
});
|
|
3660
|
+
});
|
|
3661
|
+
this._buffered = new Map();
|
|
3662
|
+
}
|
|
3663
|
+
this._hasFlush = false;
|
|
3664
|
+
this._onFlushCB?.();
|
|
3665
|
+
this._onFlushCB = undefined;
|
|
3666
|
+
}
|
|
3667
|
+
_flushNotification(identifier, value, key) {
|
|
3668
|
+
if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
|
|
3669
|
+
// eslint-disable-next-line no-console
|
|
3670
|
+
console.log(`Notifying: ${String(identifier)}\t${value}\t${key || ''}`);
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
// TODO for documents this will need to switch based on Identifier kind
|
|
3674
|
+
if (isCacheOperationValue(value)) {
|
|
3675
|
+
let callbackMap = this._cache.get(isDocumentIdentifier(identifier) ? 'document' : 'resource');
|
|
3676
|
+
if (callbackMap) {
|
|
3677
|
+
callbackMap.forEach(cb => {
|
|
3678
|
+
cb(identifier, value);
|
|
3679
|
+
});
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
let callbackMap = this._cache.get(identifier);
|
|
3683
|
+
if (!callbackMap || !callbackMap.size) {
|
|
3684
|
+
return false;
|
|
3685
|
+
}
|
|
3686
|
+
callbackMap.forEach(cb => {
|
|
3687
|
+
// @ts-expect-error overload doesn't narrow within body
|
|
3688
|
+
cb(identifier, value, key);
|
|
3689
|
+
});
|
|
3690
|
+
return true;
|
|
3691
|
+
}
|
|
3692
|
+
destroy() {
|
|
3693
|
+
this.isDestroyed = true;
|
|
3694
|
+
this._tokens.clear();
|
|
3695
|
+
this._cache.clear();
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3661
3698
|
const PromiseArrayProxy = ArrayProxy.extend(PromiseProxyMixin);
|
|
3662
3699
|
const PromiseObjectProxy = ObjectProxy.extend(PromiseProxyMixin);
|
|
3663
3700
|
var _dec, _class$1, _descriptor$1;
|
|
@@ -3821,7 +3858,7 @@ const MUTATE = Symbol('#update');
|
|
|
3821
3858
|
const NOTIFY = Symbol('#notify');
|
|
3822
3859
|
const IS_COLLECTION = Symbol.for('Collection');
|
|
3823
3860
|
function notifyArray(arr) {
|
|
3824
|
-
arr[IDENTIFIER_ARRAY_TAG]
|
|
3861
|
+
addToTransaction(arr[IDENTIFIER_ARRAY_TAG]);
|
|
3825
3862
|
if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
|
|
3826
3863
|
// eslint-disable-next-line
|
|
3827
3864
|
dirtyTag(tagForProperty(arr, 'length'));
|
|
@@ -3842,6 +3879,11 @@ let Tag = (_class = class Tag {
|
|
|
3842
3879
|
|
|
3843
3880
|
constructor() {
|
|
3844
3881
|
_initializerDefineProperty(this, "ref", _descriptor, this);
|
|
3882
|
+
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
3883
|
+
const [arr, prop] = arguments;
|
|
3884
|
+
this._debug_base = arr.constructor.name + ':' + String(arr.modelName);
|
|
3885
|
+
this._debug_prop = prop;
|
|
3886
|
+
}
|
|
3845
3887
|
this.shouldReset = false;
|
|
3846
3888
|
this.t = false;
|
|
3847
3889
|
}
|
|
@@ -3961,7 +4003,6 @@ let IdentifierArray = (_class3 = class IdentifierArray {
|
|
|
3961
4003
|
this.isDestroyed = false;
|
|
3962
4004
|
this._updatingPromise = null;
|
|
3963
4005
|
this[IS_COLLECTION] = true;
|
|
3964
|
-
this[IDENTIFIER_ARRAY_TAG] = new Tag();
|
|
3965
4006
|
this[SOURCE] = void 0;
|
|
3966
4007
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3967
4008
|
let self = this;
|
|
@@ -3969,6 +4010,8 @@ let IdentifierArray = (_class3 = class IdentifierArray {
|
|
|
3969
4010
|
this.store = options.store;
|
|
3970
4011
|
this._manager = options.manager;
|
|
3971
4012
|
this[SOURCE] = options.identifiers;
|
|
4013
|
+
// @ts-expect-error
|
|
4014
|
+
this[IDENTIFIER_ARRAY_TAG] = macroCondition(getOwnConfig().env.DEBUG) ? new Tag(this, 'length') : new Tag();
|
|
3972
4015
|
const store = options.store;
|
|
3973
4016
|
const boundFns = new Map();
|
|
3974
4017
|
const _TAG = this[IDENTIFIER_ARRAY_TAG];
|
|
@@ -4602,7 +4645,6 @@ function isPromiseRecord$1(record) {
|
|
|
4602
4645
|
/**
|
|
4603
4646
|
@module @ember-data/store
|
|
4604
4647
|
*/
|
|
4605
|
-
const RecordArraysCache = new Map();
|
|
4606
4648
|
const FAKE_ARR = {};
|
|
4607
4649
|
const SLICE_BATCH_SIZE = 1200;
|
|
4608
4650
|
/**
|
|
@@ -4668,7 +4710,7 @@ class RecordArrayManager {
|
|
|
4668
4710
|
this._pending = new Map();
|
|
4669
4711
|
this._staged = new Map();
|
|
4670
4712
|
this._keyedArrays = new Map();
|
|
4671
|
-
this._identifiers =
|
|
4713
|
+
this._identifiers = new Map();
|
|
4672
4714
|
this._subscription = this.store.notifications.subscribe('resource', (identifier, type) => {
|
|
4673
4715
|
if (type === 'added') {
|
|
4674
4716
|
this.identifierAdded(identifier);
|
|
@@ -4735,7 +4777,7 @@ class RecordArrayManager {
|
|
|
4735
4777
|
let array = new Collection(options);
|
|
4736
4778
|
this._managed.add(array);
|
|
4737
4779
|
if (config.identifiers) {
|
|
4738
|
-
associate(array, config.identifiers);
|
|
4780
|
+
associate(this._identifiers, array, config.identifiers);
|
|
4739
4781
|
}
|
|
4740
4782
|
return array;
|
|
4741
4783
|
}
|
|
@@ -4759,7 +4801,7 @@ class RecordArrayManager {
|
|
|
4759
4801
|
const allPending = this._pending;
|
|
4760
4802
|
let pending = new Map();
|
|
4761
4803
|
if (includeManaged) {
|
|
4762
|
-
let managed =
|
|
4804
|
+
let managed = this._identifiers.get(identifier);
|
|
4763
4805
|
if (managed) {
|
|
4764
4806
|
managed.forEach(arr => {
|
|
4765
4807
|
let changes = allPending.get(arr);
|
|
@@ -4809,8 +4851,8 @@ class RecordArrayManager {
|
|
|
4809
4851
|
array.meta = payload.meta || null;
|
|
4810
4852
|
array.links = payload.links || null;
|
|
4811
4853
|
array.isLoaded = true;
|
|
4812
|
-
disassociate(array, old);
|
|
4813
|
-
associate(array, identifiers);
|
|
4854
|
+
disassociate(this._identifiers, array, old);
|
|
4855
|
+
associate(this._identifiers, array, identifiers);
|
|
4814
4856
|
}
|
|
4815
4857
|
identifierAdded(identifier) {
|
|
4816
4858
|
let changeSets = this._getPendingFor(identifier, false);
|
|
@@ -4852,7 +4894,7 @@ class RecordArrayManager {
|
|
|
4852
4894
|
this._live.forEach(array => array.destroy());
|
|
4853
4895
|
this._managed.forEach(array => array.destroy());
|
|
4854
4896
|
this._managed.clear();
|
|
4855
|
-
|
|
4897
|
+
this._identifiers.clear();
|
|
4856
4898
|
}
|
|
4857
4899
|
destroy() {
|
|
4858
4900
|
this.isDestroying = true;
|
|
@@ -4863,24 +4905,24 @@ class RecordArrayManager {
|
|
|
4863
4905
|
this.store.notifications.unsubscribe(this._subscription);
|
|
4864
4906
|
}
|
|
4865
4907
|
}
|
|
4866
|
-
function associate(array, identifiers) {
|
|
4908
|
+
function associate(ArraysCache, array, identifiers) {
|
|
4867
4909
|
for (let i = 0; i < identifiers.length; i++) {
|
|
4868
4910
|
let identifier = identifiers[i];
|
|
4869
|
-
let cache =
|
|
4911
|
+
let cache = ArraysCache.get(identifier);
|
|
4870
4912
|
if (!cache) {
|
|
4871
4913
|
cache = new Set();
|
|
4872
|
-
|
|
4914
|
+
ArraysCache.set(identifier, cache);
|
|
4873
4915
|
}
|
|
4874
4916
|
cache.add(array);
|
|
4875
4917
|
}
|
|
4876
4918
|
}
|
|
4877
|
-
function disassociate(array, identifiers) {
|
|
4919
|
+
function disassociate(ArraysCache, array, identifiers) {
|
|
4878
4920
|
for (let i = 0; i < identifiers.length; i++) {
|
|
4879
|
-
disassociateIdentifier(array, identifiers[i]);
|
|
4921
|
+
disassociateIdentifier(ArraysCache, array, identifiers[i]);
|
|
4880
4922
|
}
|
|
4881
4923
|
}
|
|
4882
|
-
function disassociateIdentifier(array, identifier) {
|
|
4883
|
-
let cache =
|
|
4924
|
+
function disassociateIdentifier(ArraysCache, array, identifier) {
|
|
4925
|
+
let cache = ArraysCache.get(identifier);
|
|
4884
4926
|
if (cache) {
|
|
4885
4927
|
cache.delete(array);
|
|
4886
4928
|
}
|
|
@@ -4897,7 +4939,9 @@ function sync(array, changes) {
|
|
|
4897
4939
|
}
|
|
4898
4940
|
adds.push(key);
|
|
4899
4941
|
} else {
|
|
4900
|
-
|
|
4942
|
+
if (state.includes(key)) {
|
|
4943
|
+
removes.push(key);
|
|
4944
|
+
}
|
|
4901
4945
|
}
|
|
4902
4946
|
});
|
|
4903
4947
|
if (removes.length) {
|
|
@@ -5150,9 +5194,8 @@ let _Cache;
|
|
|
5150
5194
|
|
|
5151
5195
|
@class Store
|
|
5152
5196
|
@public
|
|
5153
|
-
*/
|
|
5154
|
-
|
|
5155
|
-
class Store {
|
|
5197
|
+
*/ // @ts-expect-error
|
|
5198
|
+
class Store extends EmberObject {
|
|
5156
5199
|
/**
|
|
5157
5200
|
* Provides access to the NotificationManager associated
|
|
5158
5201
|
* with this Store instance.
|
|
@@ -5251,13 +5294,27 @@ class Store {
|
|
|
5251
5294
|
|
|
5252
5295
|
// DEBUG-only properties
|
|
5253
5296
|
|
|
5297
|
+
// @ts-expect-error
|
|
5298
|
+
get isDestroying() {
|
|
5299
|
+
return this._isDestroying;
|
|
5300
|
+
}
|
|
5301
|
+
set isDestroying(value) {
|
|
5302
|
+
this._isDestroying = value;
|
|
5303
|
+
}
|
|
5304
|
+
// @ts-expect-error
|
|
5305
|
+
get isDestroyed() {
|
|
5306
|
+
return this._isDestroyed;
|
|
5307
|
+
}
|
|
5308
|
+
set isDestroyed(value) {
|
|
5309
|
+
this._isDestroyed = value;
|
|
5310
|
+
}
|
|
5311
|
+
|
|
5254
5312
|
/**
|
|
5255
5313
|
@method init
|
|
5256
5314
|
@private
|
|
5257
5315
|
*/
|
|
5258
5316
|
constructor(createArgs) {
|
|
5259
|
-
|
|
5260
|
-
this.isDestroyed = false;
|
|
5317
|
+
super(createArgs);
|
|
5261
5318
|
Object.assign(this, createArgs);
|
|
5262
5319
|
this.identifierCache = new IdentifierCache();
|
|
5263
5320
|
this.notifications = new NotificationManager(this);
|
|
@@ -5274,6 +5331,8 @@ class Store {
|
|
|
5274
5331
|
this._serializerCache = Object.create(null);
|
|
5275
5332
|
this._modelFactoryCache = Object.create(null);
|
|
5276
5333
|
this._documentCache = new Map();
|
|
5334
|
+
this.isDestroying = false;
|
|
5335
|
+
this.isDestroyed = false;
|
|
5277
5336
|
}
|
|
5278
5337
|
_run(cb) {
|
|
5279
5338
|
assert(`EmberData should never encounter a nested run`, !this._cbs);
|
|
@@ -6675,12 +6734,11 @@ class Store {
|
|
|
6675
6734
|
// during unload
|
|
6676
6735
|
if (macroCondition(getOwnConfig().packages.HAS_GRAPH_PACKAGE)) {
|
|
6677
6736
|
const peekGraph = importSync('@ember-data/graph/-private').peekGraph;
|
|
6678
|
-
|
|
6737
|
+
const graph = peekGraph(this);
|
|
6679
6738
|
if (graph) {
|
|
6680
6739
|
graph.identifiers.clear();
|
|
6681
6740
|
}
|
|
6682
6741
|
}
|
|
6683
|
-
this.notifications.destroy();
|
|
6684
6742
|
this.recordArrayManager.clear();
|
|
6685
6743
|
this._instanceCache.clear();
|
|
6686
6744
|
} else {
|
|
@@ -6983,7 +7041,6 @@ class Store {
|
|
|
6983
7041
|
if (resourceIsFullyDeleted(this._instanceCache, identifier)) {
|
|
6984
7042
|
return Promise.resolve(record);
|
|
6985
7043
|
}
|
|
6986
|
-
cache.willCommit(identifier);
|
|
6987
7044
|
if (isDSModel(record)) {
|
|
6988
7045
|
record.errors.clear();
|
|
6989
7046
|
}
|
|
@@ -6996,7 +7053,7 @@ class Store {
|
|
|
6996
7053
|
} else if (cache.isDeleted(identifier)) {
|
|
6997
7054
|
operation = 'deleteRecord';
|
|
6998
7055
|
}
|
|
6999
|
-
|
|
7056
|
+
const request = {
|
|
7000
7057
|
op: operation,
|
|
7001
7058
|
data: {
|
|
7002
7059
|
options,
|
|
@@ -7005,7 +7062,13 @@ class Store {
|
|
|
7005
7062
|
cacheOptions: {
|
|
7006
7063
|
[SkipCache]: true
|
|
7007
7064
|
}
|
|
7008
|
-
}
|
|
7065
|
+
};
|
|
7066
|
+
|
|
7067
|
+
// we lie here on the type because legacy doesn't have enough context
|
|
7068
|
+
cache.willCommit(identifier, {
|
|
7069
|
+
request
|
|
7070
|
+
});
|
|
7071
|
+
return this.request(request).then(document => document.content);
|
|
7009
7072
|
}
|
|
7010
7073
|
|
|
7011
7074
|
/**
|
|
@@ -7205,6 +7268,8 @@ class Store {
|
|
|
7205
7268
|
}
|
|
7206
7269
|
return null;
|
|
7207
7270
|
}
|
|
7271
|
+
|
|
7272
|
+
// @ts-expect-error
|
|
7208
7273
|
destroy() {
|
|
7209
7274
|
if (this.isDestroyed) {
|
|
7210
7275
|
// @ember/test-helpers will call destroy multiple times
|
|
@@ -7231,6 +7296,7 @@ class Store {
|
|
|
7231
7296
|
graph.destroy();
|
|
7232
7297
|
}
|
|
7233
7298
|
}
|
|
7299
|
+
this.notifications.destroy();
|
|
7234
7300
|
this.recordArrayManager.destroy();
|
|
7235
7301
|
this.identifierCache.destroy();
|
|
7236
7302
|
this.unloadAll();
|