@ember-data/store 4.13.0-alpha.3 → 4.13.0-alpha.4
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 +3 -6
- package/dist/{-private-Cy8UqsrK.js → -private-C5j0gwYO.js} +118 -27
- package/dist/-private-C5j0gwYO.js.map +1 -0
- package/dist/-private.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +23 -13
- package/unstable-preview-types/-private/cache-handler/handler.d.ts +0 -2
- package/unstable-preview-types/-private/cache-handler/handler.d.ts.map +1 -1
- package/unstable-preview-types/-private/caches/identifier-cache.d.ts.map +1 -1
- package/unstable-preview-types/-private/caches/instance-cache.d.ts.map +1 -1
- package/unstable-preview-types/-private/debug/utils.d.ts +9 -0
- package/unstable-preview-types/-private/debug/utils.d.ts.map +1 -0
- package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts +3 -3
- package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/managers/notification-manager.d.ts +3 -2
- package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/store-service.d.ts +3 -6
- package/unstable-preview-types/-private/store-service.d.ts.map +1 -1
- package/unstable-preview-types/-private.d.ts +1 -0
- package/unstable-preview-types/-private.d.ts.map +1 -1
- package/unstable-preview-types/-types/q/cache-capabilities-manager.d.ts +4 -4
- package/unstable-preview-types/-types/q/cache-capabilities-manager.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +25 -27
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/dist/-private-Cy8UqsrK.js.map +0 -1
package/README.md
CHANGED
|
@@ -108,12 +108,9 @@ import RequestManager from '@ember-data/request';
|
|
|
108
108
|
import Fetch from '@ember-data/request/fetch';
|
|
109
109
|
|
|
110
110
|
export default class extends Store {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.requestManager.use([Fetch]);
|
|
115
|
-
this.requestManager.useCache(CacheHandler);
|
|
116
|
-
}
|
|
111
|
+
requestManager = new RequestManager()
|
|
112
|
+
.use([Fetch])
|
|
113
|
+
.useCache(CacheHandler);
|
|
117
114
|
}
|
|
118
115
|
```
|
|
119
116
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { deprecate, warn, assert } from '@ember/debug';
|
|
2
2
|
import { dasherize } from '@ember-data/request-utils/string';
|
|
3
3
|
import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
|
|
4
|
-
import {
|
|
5
|
-
import { getOrSetGlobal,
|
|
4
|
+
import { EnableHydration, SkipCache } from '@warp-drive/core-types/request';
|
|
5
|
+
import { getOrSetGlobal, peekTransient, setTransient } from '@warp-drive/core-types/-private';
|
|
6
6
|
import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_CLIENT_ORIGINATED, DEBUG_IDENTIFIER_BUCKET } from '@warp-drive/core-types/identifier';
|
|
7
7
|
import { defineSignal, createSignal, subscribe, createArrayTags, addToTransaction, addTransactionCB } from '@ember-data/tracking/-private';
|
|
8
8
|
import { _backburner } from '@ember/runloop';
|
|
@@ -136,10 +136,9 @@ function hasType(resource) {
|
|
|
136
136
|
/**
|
|
137
137
|
@module @ember-data/store
|
|
138
138
|
*/
|
|
139
|
-
const IDENTIFIERS = getOrSetGlobal('IDENTIFIERS', new Set());
|
|
140
139
|
const DOCUMENTS = getOrSetGlobal('DOCUMENTS', new Set());
|
|
141
140
|
function isStableIdentifier(identifier) {
|
|
142
|
-
return identifier[CACHE_OWNER] !== undefined
|
|
141
|
+
return identifier[CACHE_OWNER] !== undefined;
|
|
143
142
|
}
|
|
144
143
|
function isDocumentIdentifier(identifier) {
|
|
145
144
|
return DOCUMENTS.has(identifier);
|
|
@@ -628,7 +627,6 @@ class IdentifierCache {
|
|
|
628
627
|
identifier[DEBUG_STALE_CACHE_OWNER] = identifier[CACHE_OWNER];
|
|
629
628
|
}
|
|
630
629
|
identifier[CACHE_OWNER] = undefined;
|
|
631
|
-
IDENTIFIERS.delete(identifier);
|
|
632
630
|
this._forget(identifier, 'record');
|
|
633
631
|
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
|
|
634
632
|
// eslint-disable-next-line no-console
|
|
@@ -644,7 +642,6 @@ class IdentifierCache {
|
|
|
644
642
|
}
|
|
645
643
|
}
|
|
646
644
|
function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated) {
|
|
647
|
-
IDENTIFIERS.add(recordIdentifier);
|
|
648
645
|
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
649
646
|
// we enforce immutability in dev
|
|
650
647
|
// but preserve our ability to do controlled updates to the reference
|
|
@@ -699,7 +696,6 @@ function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated)
|
|
|
699
696
|
});
|
|
700
697
|
wrapper[DEBUG_CLIENT_ORIGINATED] = clientOriginated;
|
|
701
698
|
wrapper[DEBUG_IDENTIFIER_BUCKET] = bucket;
|
|
702
|
-
IDENTIFIERS.add(wrapper);
|
|
703
699
|
DEBUG_MAP.set(wrapper, recordIdentifier);
|
|
704
700
|
wrapper = freeze(wrapper);
|
|
705
701
|
return wrapper;
|
|
@@ -803,6 +799,87 @@ function addResourceToCache(cache, identifier) {
|
|
|
803
799
|
typeSet.id.set(identifier.id, identifier);
|
|
804
800
|
}
|
|
805
801
|
}
|
|
802
|
+
const TEXT_COLORS = {
|
|
803
|
+
TEXT: 'inherit',
|
|
804
|
+
notify: ['white', 'white', 'inherit', 'magenta', 'inherit'],
|
|
805
|
+
'reactive-ui': ['white', 'white', 'inherit', 'magenta', 'inherit'],
|
|
806
|
+
graph: ['white', 'white', 'inherit', 'magenta', 'inherit'],
|
|
807
|
+
request: ['white', 'white', 'inherit', 'magenta', 'inherit'],
|
|
808
|
+
cache: ['white', 'white', 'inherit', 'magenta', 'inherit']
|
|
809
|
+
};
|
|
810
|
+
const BG_COLORS = {
|
|
811
|
+
TEXT: 'transparent',
|
|
812
|
+
notify: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
|
|
813
|
+
'reactive-ui': ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
|
|
814
|
+
graph: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
|
|
815
|
+
request: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
|
|
816
|
+
cache: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent']
|
|
817
|
+
};
|
|
818
|
+
const NOTIFY_BORDER = {
|
|
819
|
+
TEXT: 0,
|
|
820
|
+
notify: [3, 2, 0, 0, 0],
|
|
821
|
+
'reactive-ui': [3, 2, 0, 0, 0],
|
|
822
|
+
graph: [3, 2, 0, 0, 0],
|
|
823
|
+
request: [3, 2, 0, 0, 0],
|
|
824
|
+
cache: [3, 2, 0, 0, 0]
|
|
825
|
+
};
|
|
826
|
+
const LIGHT_DARK_ALT = {
|
|
827
|
+
lightgreen: 'green',
|
|
828
|
+
green: 'lightgreen'
|
|
829
|
+
};
|
|
830
|
+
function badge(isLight, color, bgColor, border) {
|
|
831
|
+
return [`color: ${correctColor(isLight, color)}; background-color: ${correctColor(isLight, bgColor)}; padding: ${border}px ${2 * border}px; border-radius: ${border}px;`, `color: ${TEXT_COLORS.TEXT}; background-color: ${BG_COLORS.TEXT};`];
|
|
832
|
+
}
|
|
833
|
+
function colorForBucket(isLight, scope, bucket) {
|
|
834
|
+
if (scope === 'notify') {
|
|
835
|
+
return bucket === 'added' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'removed' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
|
|
836
|
+
}
|
|
837
|
+
if (scope === 'reactive-ui') {
|
|
838
|
+
return bucket === 'created' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'disconnected' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
|
|
839
|
+
}
|
|
840
|
+
if (scope === 'cache') {
|
|
841
|
+
return bucket === 'inserted' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'removed' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
|
|
842
|
+
}
|
|
843
|
+
return badge(isLight, TEXT_COLORS[scope][3], BG_COLORS[scope][3], NOTIFY_BORDER[scope][3]);
|
|
844
|
+
}
|
|
845
|
+
function logGroup(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
|
|
846
|
+
// eslint-disable-next-line no-console
|
|
847
|
+
console.groupCollapsed(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
|
|
848
|
+
}
|
|
849
|
+
function log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
|
|
850
|
+
// eslint-disable-next-line no-console
|
|
851
|
+
console.log(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
|
|
852
|
+
}
|
|
853
|
+
function correctColor(isLight, color) {
|
|
854
|
+
if (!isLight) {
|
|
855
|
+
return color;
|
|
856
|
+
}
|
|
857
|
+
return color in LIGHT_DARK_ALT ? LIGHT_DARK_ALT[color] : color;
|
|
858
|
+
}
|
|
859
|
+
function isLightMode() {
|
|
860
|
+
if (window?.matchMedia?.('(prefers-color-scheme: light)').matches) {
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
function _log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
|
|
866
|
+
const isLight = isLightMode();
|
|
867
|
+
switch (scope) {
|
|
868
|
+
case 'reactive-ui':
|
|
869
|
+
case 'notify':
|
|
870
|
+
{
|
|
871
|
+
const scopePath = prefix ? `[${prefix}] ${scope}` : scope;
|
|
872
|
+
const path = subScop4 ? `${subScop3}.${subScop4}` : subScop3;
|
|
873
|
+
return [`%c@warp%c-%cdrive%c %c${scopePath}%c %c${subScop1}%c %c${subScop2}%c %c${path}%c`, ...badge(isLight, 'lightgreen', 'transparent', 0), ...badge(isLight, 'magenta', 'transparent', 0), ...badge(isLight, TEXT_COLORS[scope][0], BG_COLORS[scope][0], NOTIFY_BORDER[scope][0]), ...badge(isLight, TEXT_COLORS[scope][1], BG_COLORS[scope][1], NOTIFY_BORDER[scope][1]), ...badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]), ...colorForBucket(isLight, scope, path)];
|
|
874
|
+
}
|
|
875
|
+
case 'cache':
|
|
876
|
+
{
|
|
877
|
+
const scopePath = prefix ? `${scope} (${prefix})` : scope;
|
|
878
|
+
return [`%c@warp%c-%cdrive%c %c${scopePath}%c %c${subScop1}%c %c${subScop2}%c %c${subScop3}%c %c${subScop4}%c`, ...badge(isLight, 'lightgreen', 'transparent', 0), ...badge(isLight, 'magenta', 'transparent', 0), ...badge(isLight, TEXT_COLORS[scope][0], BG_COLORS[scope][0], NOTIFY_BORDER[scope][0]), ...badge(isLight, TEXT_COLORS[scope][1], BG_COLORS[scope][1], NOTIFY_BORDER[scope][1]), ...badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]), ...colorForBucket(isLight, scope, subScop3), ...badge(isLight, TEXT_COLORS[scope][4], BG_COLORS[scope][4], NOTIFY_BORDER[scope][4])];
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return [];
|
|
882
|
+
}
|
|
806
883
|
|
|
807
884
|
/**
|
|
808
885
|
@module @ember-data/store
|
|
@@ -1260,8 +1337,13 @@ class InstanceCache {
|
|
|
1260
1337
|
StoreMap.set(record, this.store);
|
|
1261
1338
|
this.__instances.record.set(identifier, record);
|
|
1262
1339
|
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
|
|
1340
|
+
logGroup('reactive-ui', '', identifier.type, identifier.lid, 'created', '');
|
|
1341
|
+
// eslint-disable-next-line no-console
|
|
1342
|
+
console.log({
|
|
1343
|
+
properties
|
|
1344
|
+
});
|
|
1263
1345
|
// eslint-disable-next-line no-console
|
|
1264
|
-
console.
|
|
1346
|
+
console.groupEnd();
|
|
1265
1347
|
}
|
|
1266
1348
|
}
|
|
1267
1349
|
return record;
|
|
@@ -1308,8 +1390,7 @@ class InstanceCache {
|
|
|
1308
1390
|
removeRecordDataFor(identifier);
|
|
1309
1391
|
this.store._requestCache._clearEntries(identifier);
|
|
1310
1392
|
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
|
|
1311
|
-
|
|
1312
|
-
console.log(`InstanceCache: disconnected ${String(identifier)}`);
|
|
1393
|
+
log('reactive-ui', '', identifier.type, identifier.lid, 'disconnected', '');
|
|
1313
1394
|
}
|
|
1314
1395
|
}
|
|
1315
1396
|
unloadRecord(identifier) {
|
|
@@ -2174,6 +2255,14 @@ function runLoopIsFlushing() {
|
|
|
2174
2255
|
//@ts-expect-error
|
|
2175
2256
|
return !!_backburner.currentInstance && _backburner._autorun !== true;
|
|
2176
2257
|
}
|
|
2258
|
+
function count(label) {
|
|
2259
|
+
// @ts-expect-error
|
|
2260
|
+
// eslint-disable-next-line
|
|
2261
|
+
globalThis.counts = globalThis.counts || {};
|
|
2262
|
+
// @ts-expect-error
|
|
2263
|
+
// eslint-disable-next-line
|
|
2264
|
+
globalThis.counts[label] = (globalThis.counts[label] || 0) + 1;
|
|
2265
|
+
}
|
|
2177
2266
|
function _unsubscribe(tokens, token, cache) {
|
|
2178
2267
|
const identifier = tokens.get(token);
|
|
2179
2268
|
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
|
|
@@ -2293,10 +2382,6 @@ class NotificationManager {
|
|
|
2293
2382
|
}
|
|
2294
2383
|
return false;
|
|
2295
2384
|
}
|
|
2296
|
-
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
|
|
2297
|
-
// eslint-disable-next-line no-console
|
|
2298
|
-
console.log(`Buffering Notify: ${String(identifier.lid)}\t${value}\t${key || ''}`);
|
|
2299
|
-
}
|
|
2300
2385
|
const hasSubscribers = Boolean(this._cache.get(identifier)?.size);
|
|
2301
2386
|
if (isCacheOperationValue(value) || hasSubscribers) {
|
|
2302
2387
|
let buffer = this._buffered.get(identifier);
|
|
@@ -2305,7 +2390,16 @@ class NotificationManager {
|
|
|
2305
2390
|
this._buffered.set(identifier, buffer);
|
|
2306
2391
|
}
|
|
2307
2392
|
buffer.push([value, key]);
|
|
2308
|
-
|
|
2393
|
+
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_METRIC_COUNTS)) {
|
|
2394
|
+
count(`notify ${'type' in identifier ? identifier.type : '<document>'} ${value} ${key}`);
|
|
2395
|
+
}
|
|
2396
|
+
if (!this._scheduleNotify()) {
|
|
2397
|
+
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
|
|
2398
|
+
log('notify', 'buffered', `${'type' in identifier ? identifier.type : 'document'}`, identifier.lid, `${value}`, key || '');
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
} else if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_METRIC_COUNTS)) {
|
|
2402
|
+
count(`DISCARDED notify ${'type' in identifier ? identifier.type : '<document>'} ${value} ${key}`);
|
|
2309
2403
|
}
|
|
2310
2404
|
return hasSubscribers;
|
|
2311
2405
|
}
|
|
@@ -2316,14 +2410,15 @@ class NotificationManager {
|
|
|
2316
2410
|
const asyncFlush = this.store._enableAsyncFlush;
|
|
2317
2411
|
if (this._hasFlush) {
|
|
2318
2412
|
if (asyncFlush !== false && !runLoopIsFlushing()) {
|
|
2319
|
-
return;
|
|
2413
|
+
return false;
|
|
2320
2414
|
}
|
|
2321
2415
|
}
|
|
2322
2416
|
if (asyncFlush && !runLoopIsFlushing()) {
|
|
2323
2417
|
this._hasFlush = true;
|
|
2324
|
-
return;
|
|
2418
|
+
return false;
|
|
2325
2419
|
}
|
|
2326
2420
|
this._flush();
|
|
2421
|
+
return true;
|
|
2327
2422
|
}
|
|
2328
2423
|
_flush() {
|
|
2329
2424
|
const buffered = this._buffered;
|
|
@@ -2342,8 +2437,7 @@ class NotificationManager {
|
|
|
2342
2437
|
}
|
|
2343
2438
|
_flushNotification(identifier, value, key) {
|
|
2344
2439
|
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
|
|
2345
|
-
|
|
2346
|
-
console.log(`Notifying: ${String(identifier)}\t${value}\t${key || ''}`);
|
|
2440
|
+
log('notify', '', `${'type' in identifier ? identifier.type : 'document'}`, identifier.lid, `${value}`, key || '');
|
|
2347
2441
|
}
|
|
2348
2442
|
|
|
2349
2443
|
// TODO for documents this will need to switch based on Identifier kind
|
|
@@ -4274,12 +4368,9 @@ class Store extends BaseClass {
|
|
|
4274
4368
|
* import Fetch from '@ember-data/request/fetch';
|
|
4275
4369
|
*
|
|
4276
4370
|
* class extends Store {
|
|
4277
|
-
*
|
|
4278
|
-
*
|
|
4279
|
-
*
|
|
4280
|
-
* this.requestManager.use([Fetch]);
|
|
4281
|
-
* this.requestManager.useCache(CacheHandler);
|
|
4282
|
-
* }
|
|
4371
|
+
* requestManager = new RequestManager()
|
|
4372
|
+
* .use([Fetch])
|
|
4373
|
+
* .useCache(CacheHandler);
|
|
4283
4374
|
* }
|
|
4284
4375
|
* ```
|
|
4285
4376
|
*
|
|
@@ -4521,7 +4612,7 @@ class Store extends BaseClass {
|
|
|
4521
4612
|
// the user has had the chance to set the prop.
|
|
4522
4613
|
const opts = {
|
|
4523
4614
|
store: this,
|
|
4524
|
-
[EnableHydration]: true
|
|
4615
|
+
[EnableHydration]: requestConfig[EnableHydration] ?? true
|
|
4525
4616
|
};
|
|
4526
4617
|
if (requestConfig.records) {
|
|
4527
4618
|
const identifierCache = this.identifierCache;
|
|
@@ -6909,4 +7000,4 @@ function normalizeModelName(modelName) {
|
|
|
6909
7000
|
}
|
|
6910
7001
|
assert(`normalizeModelName support has been removed`);
|
|
6911
7002
|
}
|
|
6912
|
-
export { ARRAY_SIGNAL as A, CacheHandler as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, setKeyInfoForResource as e, constructResource as f, coerceId as g, ensureStringId as h, isStableIdentifier as i, Collection as j, notifyArray as k, SOURCE as l, fastPush as m, normalizeModelName as n, removeRecordDataFor as o, peekCache as p, setRecordIdentifier as q, recordIdentifierFor as r, storeFor as s, StoreMap as t, setCacheFor as u };
|
|
7003
|
+
export { ARRAY_SIGNAL as A, CacheHandler as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, setKeyInfoForResource as e, constructResource as f, coerceId as g, ensureStringId as h, isStableIdentifier as i, Collection as j, notifyArray as k, SOURCE as l, fastPush as m, normalizeModelName as n, removeRecordDataFor as o, peekCache as p, setRecordIdentifier as q, recordIdentifierFor as r, storeFor as s, StoreMap as t, setCacheFor as u, log as v, logGroup as w };
|