@ember-data/store 5.4.0-alpha.135 → 5.4.0-alpha.136

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/-private.js CHANGED
@@ -1 +1 @@
1
- export { A as ARRAY_SIGNAL, C as CacheHandler, j as CollectionRecordArray, I as LiveArray, M as MUTATE, R as RecordArrayManager, k as SOURCE, S as Store, q as StoreMap, _ as _clearCaches, u as _deprecatingNormalize, g as coerceId, f as constructResource, h as ensureStringId, l as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, m as removeRecordDataFor, t as setCacheFor, o as setRecordIdentifier, s as storeFor } from "./handler-DX830Swd.js";
1
+ export { A as ARRAY_SIGNAL, C as CacheHandler, j as CollectionRecordArray, I as LiveArray, M as MUTATE, R as RecordArrayManager, k as SOURCE, S as Store, q as StoreMap, _ as _clearCaches, u as _deprecatingNormalize, g as coerceId, f as constructResource, h as ensureStringId, l as fastPush, i as isStableIdentifier, v as log, w as logGroup, n as notifyArray, p as peekCache, r as recordIdentifierFor, m as removeRecordDataFor, t as setCacheFor, o as setRecordIdentifier, s as storeFor } from "./handler-DampzYZU.js";
@@ -129,10 +129,9 @@ function hasType(resource) {
129
129
  /**
130
130
  @module @ember-data/store
131
131
  */
132
- const IDENTIFIERS = getOrSetGlobal('IDENTIFIERS', new Set());
133
132
  const DOCUMENTS = getOrSetGlobal('DOCUMENTS', new Set());
134
133
  function isStableIdentifier(identifier) {
135
- return identifier[CACHE_OWNER] !== undefined || IDENTIFIERS.has(identifier);
134
+ return identifier[CACHE_OWNER] !== undefined;
136
135
  }
137
136
  function isDocumentIdentifier(identifier) {
138
137
  return DOCUMENTS.has(identifier);
@@ -621,7 +620,6 @@ class IdentifierCache {
621
620
  identifier[DEBUG_STALE_CACHE_OWNER] = identifier[CACHE_OWNER];
622
621
  }
623
622
  identifier[CACHE_OWNER] = undefined;
624
- IDENTIFIERS.delete(identifier);
625
623
  this._forget(identifier, 'record');
626
624
  if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
627
625
  // eslint-disable-next-line no-console
@@ -637,7 +635,6 @@ class IdentifierCache {
637
635
  }
638
636
  }
639
637
  function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated) {
640
- IDENTIFIERS.add(recordIdentifier);
641
638
  if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
642
639
  // we enforce immutability in dev
643
640
  // but preserve our ability to do controlled updates to the reference
@@ -692,7 +689,6 @@ function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated)
692
689
  });
693
690
  wrapper[DEBUG_CLIENT_ORIGINATED] = clientOriginated;
694
691
  wrapper[DEBUG_IDENTIFIER_BUCKET] = bucket;
695
- IDENTIFIERS.add(wrapper);
696
692
  DEBUG_MAP.set(wrapper, recordIdentifier);
697
693
  wrapper = freeze(wrapper);
698
694
  return wrapper;
@@ -796,6 +792,87 @@ function addResourceToCache(cache, identifier) {
796
792
  typeSet.id.set(identifier.id, identifier);
797
793
  }
798
794
  }
795
+ const TEXT_COLORS = {
796
+ TEXT: 'inherit',
797
+ notify: ['white', 'white', 'inherit', 'magenta', 'inherit'],
798
+ 'reactive-ui': ['white', 'white', 'inherit', 'magenta', 'inherit'],
799
+ graph: ['white', 'white', 'inherit', 'magenta', 'inherit'],
800
+ request: ['white', 'white', 'inherit', 'magenta', 'inherit'],
801
+ cache: ['white', 'white', 'inherit', 'magenta', 'inherit']
802
+ };
803
+ const BG_COLORS = {
804
+ TEXT: 'transparent',
805
+ notify: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
806
+ 'reactive-ui': ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
807
+ graph: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
808
+ request: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
809
+ cache: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent']
810
+ };
811
+ const NOTIFY_BORDER = {
812
+ TEXT: 0,
813
+ notify: [3, 2, 0, 0, 0],
814
+ 'reactive-ui': [3, 2, 0, 0, 0],
815
+ graph: [3, 2, 0, 0, 0],
816
+ request: [3, 2, 0, 0, 0],
817
+ cache: [3, 2, 0, 0, 0]
818
+ };
819
+ const LIGHT_DARK_ALT = {
820
+ lightgreen: 'green',
821
+ green: 'lightgreen'
822
+ };
823
+ function badge(isLight, color, bgColor, border) {
824
+ 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};`];
825
+ }
826
+ function colorForBucket(isLight, scope, bucket) {
827
+ if (scope === 'notify') {
828
+ 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]);
829
+ }
830
+ if (scope === 'reactive-ui') {
831
+ 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]);
832
+ }
833
+ if (scope === 'cache') {
834
+ 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]);
835
+ }
836
+ return badge(isLight, TEXT_COLORS[scope][3], BG_COLORS[scope][3], NOTIFY_BORDER[scope][3]);
837
+ }
838
+ function logGroup(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
839
+ // eslint-disable-next-line no-console
840
+ console.groupCollapsed(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
841
+ }
842
+ function log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
843
+ // eslint-disable-next-line no-console
844
+ console.log(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
845
+ }
846
+ function correctColor(isLight, color) {
847
+ if (!isLight) {
848
+ return color;
849
+ }
850
+ return color in LIGHT_DARK_ALT ? LIGHT_DARK_ALT[color] : color;
851
+ }
852
+ function isLightMode() {
853
+ if (window?.matchMedia?.('(prefers-color-scheme: light)').matches) {
854
+ return true;
855
+ }
856
+ return false;
857
+ }
858
+ function _log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
859
+ const isLight = isLightMode();
860
+ switch (scope) {
861
+ case 'reactive-ui':
862
+ case 'notify':
863
+ {
864
+ const scopePath = prefix ? `[${prefix}] ${scope}` : scope;
865
+ const path = subScop4 ? `${subScop3}.${subScop4}` : subScop3;
866
+ 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)];
867
+ }
868
+ case 'cache':
869
+ {
870
+ const scopePath = prefix ? `${scope} (${prefix})` : scope;
871
+ 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])];
872
+ }
873
+ }
874
+ return [];
875
+ }
799
876
 
800
877
  /**
801
878
  @module @ember-data/store
@@ -1253,8 +1330,13 @@ class InstanceCache {
1253
1330
  StoreMap.set(record, this.store);
1254
1331
  this.__instances.record.set(identifier, record);
1255
1332
  if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1333
+ logGroup('reactive-ui', '', identifier.type, identifier.lid, 'created', '');
1334
+ // eslint-disable-next-line no-console
1335
+ console.log({
1336
+ properties
1337
+ });
1256
1338
  // eslint-disable-next-line no-console
1257
- console.log(`InstanceCache: created Record for ${String(identifier)}`, properties);
1339
+ console.groupEnd();
1258
1340
  }
1259
1341
  }
1260
1342
  return record;
@@ -1301,8 +1383,7 @@ class InstanceCache {
1301
1383
  removeRecordDataFor(identifier);
1302
1384
  this.store._requestCache._clearEntries(identifier);
1303
1385
  if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1304
- // eslint-disable-next-line no-console
1305
- console.log(`InstanceCache: disconnected ${String(identifier)}`);
1386
+ log('reactive-ui', '', identifier.type, identifier.lid, 'disconnected', '');
1306
1387
  }
1307
1388
  }
1308
1389
  unloadRecord(identifier) {
@@ -2167,6 +2248,14 @@ function runLoopIsFlushing() {
2167
2248
  //@ts-expect-error
2168
2249
  return !!_backburner.currentInstance && _backburner._autorun !== true;
2169
2250
  }
2251
+ function count(label) {
2252
+ // @ts-expect-error
2253
+ // eslint-disable-next-line
2254
+ globalThis.counts = globalThis.counts || {};
2255
+ // @ts-expect-error
2256
+ // eslint-disable-next-line
2257
+ wglobalThis.counts[label] = (globalThis.counts[label] || 0) + 1;
2258
+ }
2170
2259
  function _unsubscribe(tokens, token, cache) {
2171
2260
  const identifier = tokens.get(token);
2172
2261
  if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
@@ -2286,10 +2375,6 @@ class NotificationManager {
2286
2375
  }
2287
2376
  return false;
2288
2377
  }
2289
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
2290
- // eslint-disable-next-line no-console
2291
- console.log(`Buffering Notify: ${String(identifier.lid)}\t${value}\t${key || ''}`);
2292
- }
2293
2378
  const hasSubscribers = Boolean(this._cache.get(identifier)?.size);
2294
2379
  if (isCacheOperationValue(value) || hasSubscribers) {
2295
2380
  let buffer = this._buffered.get(identifier);
@@ -2298,7 +2383,16 @@ class NotificationManager {
2298
2383
  this._buffered.set(identifier, buffer);
2299
2384
  }
2300
2385
  buffer.push([value, key]);
2301
- this._scheduleNotify();
2386
+ if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_METRIC_COUNTS)) {
2387
+ count(`notify ${'type' in identifier ? identifier.type : '<document>'} ${value} ${key}`);
2388
+ }
2389
+ if (!this._scheduleNotify()) {
2390
+ if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
2391
+ log('notify', 'buffered', `${'type' in identifier ? identifier.type : 'document'}`, identifier.lid, `${value}`, key || '');
2392
+ }
2393
+ }
2394
+ } else if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_METRIC_COUNTS)) {
2395
+ count(`DISCARDED notify ${'type' in identifier ? identifier.type : '<document>'} ${value} ${key}`);
2302
2396
  }
2303
2397
  return hasSubscribers;
2304
2398
  }
@@ -2309,14 +2403,15 @@ class NotificationManager {
2309
2403
  const asyncFlush = this.store._enableAsyncFlush;
2310
2404
  if (this._hasFlush) {
2311
2405
  if (asyncFlush !== false && !runLoopIsFlushing()) {
2312
- return;
2406
+ return false;
2313
2407
  }
2314
2408
  }
2315
2409
  if (asyncFlush && !runLoopIsFlushing()) {
2316
2410
  this._hasFlush = true;
2317
- return;
2411
+ return false;
2318
2412
  }
2319
2413
  this._flush();
2414
+ return true;
2320
2415
  }
2321
2416
  _flush() {
2322
2417
  const buffered = this._buffered;
@@ -2335,8 +2430,7 @@ class NotificationManager {
2335
2430
  }
2336
2431
  _flushNotification(identifier, value, key) {
2337
2432
  if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
2338
- // eslint-disable-next-line no-console
2339
- console.log(`Notifying: ${String(identifier)}\t${value}\t${key || ''}`);
2433
+ log('notify', '', `${'type' in identifier ? identifier.type : 'document'}`, identifier.lid, `${value}`, key || '');
2340
2434
  }
2341
2435
 
2342
2436
  // TODO for documents this will need to switch based on Identifier kind
@@ -6063,4 +6157,4 @@ function fetchContentAndHydrate(next, context, identifier, priority) {
6063
6157
  }]
6064
6158
  });
6065
6159
  }
6066
- 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, SOURCE as k, fastPush as l, removeRecordDataFor as m, notifyArray as n, setRecordIdentifier as o, peekCache as p, StoreMap as q, recordIdentifierFor as r, storeFor as s, setCacheFor as t, normalizeModelName as u };
6160
+ 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, SOURCE as k, fastPush as l, removeRecordDataFor as m, notifyArray as n, setRecordIdentifier as o, peekCache as p, StoreMap as q, recordIdentifierFor as r, storeFor as s, setCacheFor as t, normalizeModelName as u, log as v, logGroup as w };