@ember-data/store 4.2.0-alpha.8 → 4.3.0-beta.0

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.
Files changed (28) hide show
  1. package/addon/-private/identifiers/cache.ts +3 -16
  2. package/addon/-private/identifiers/is-stable-identifier.ts +2 -2
  3. package/addon/-private/index.ts +1 -3
  4. package/addon/-private/system/core-store.ts +57 -497
  5. package/addon/-private/system/ds-model-store.ts +15 -55
  6. package/addon/-private/system/fetch-manager.ts +2 -1
  7. package/addon/-private/system/model/internal-model.ts +2 -3
  8. package/addon/-private/system/model/shim-model-class.ts +15 -16
  9. package/addon/-private/system/record-array-manager.js +20 -42
  10. package/addon/-private/system/record-arrays/adapter-populated-record-array.js +1 -20
  11. package/addon/-private/system/record-arrays/record-array.js +1 -8
  12. package/addon/-private/system/record-data-for.ts +10 -8
  13. package/addon/-private/system/record-notification-manager.ts +11 -10
  14. package/addon/-private/system/references/belongs-to.ts +20 -40
  15. package/addon/-private/system/references/has-many.ts +7 -8
  16. package/addon/-private/system/references/record.ts +6 -4
  17. package/addon/-private/system/references/reference.ts +4 -11
  18. package/addon/-private/system/schema-definition-service.ts +2 -2
  19. package/addon/-private/system/snapshot.ts +10 -4
  20. package/addon/-private/system/store/finders.js +2 -40
  21. package/addon/-private/system/store/internal-model-factory.ts +34 -28
  22. package/addon/-private/system/store/record-data-store-wrapper.ts +11 -12
  23. package/addon/-private/system/weak-cache.ts +125 -0
  24. package/addon/-private/ts-interfaces/identifier.ts +2 -2
  25. package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +0 -1
  26. package/addon/-private/ts-interfaces/schema-definition-service.ts +2 -2
  27. package/package.json +11 -11
  28. package/addon/-private/system/deprecated-evented.js +0 -92
@@ -1,5 +1,5 @@
1
1
  import { getOwner, setOwner } from '@ember/application';
2
- import { assert, deprecate } from '@ember/debug';
2
+ import { assert } from '@ember/debug';
3
3
  import EmberError from '@ember/error';
4
4
  import { isPresent } from '@ember/utils';
5
5
  import { DEBUG } from '@glimmer/env';
@@ -7,7 +7,7 @@ import { DEBUG } from '@glimmer/env';
7
7
  import type DSModelClass from '@ember-data/model';
8
8
 
9
9
  import type { DSModel } from '../ts-interfaces/ds-model';
10
- import type { StableRecordIdentifier } from '../ts-interfaces/identifier';
10
+ import type { RecordIdentifier, StableRecordIdentifier } from '../ts-interfaces/identifier';
11
11
  import type { RecordDataRecordWrapper } from '../ts-interfaces/record-data-record-wrapper';
12
12
  import type { RelationshipsSchema } from '../ts-interfaces/record-data-schemas';
13
13
  import type { SchemaDefinitionService } from '../ts-interfaces/schema-definition-service';
@@ -105,23 +105,15 @@ class Store extends CoreStore {
105
105
  }
106
106
 
107
107
  _relationshipMetaFor(modelName: string, id: string | null, key: string) {
108
- return this._relationshipsDefinitionFor(modelName)[key];
108
+ return this._relationshipsDefinitionFor({ type: modelName })[key];
109
109
  }
110
110
 
111
- _attributesDefinitionFor(modelName: string, identifier?: StableRecordIdentifier) {
112
- if (identifier) {
113
- return this.getSchemaDefinitionService().attributesDefinitionFor(identifier);
114
- } else {
115
- return this.getSchemaDefinitionService().attributesDefinitionFor(modelName);
116
- }
111
+ _attributesDefinitionFor(identifier: RecordIdentifier | { type: string }) {
112
+ return this.getSchemaDefinitionService().attributesDefinitionFor(identifier);
117
113
  }
118
114
 
119
- _relationshipsDefinitionFor(modelName: string, identifier?: StableRecordIdentifier): RelationshipsSchema {
120
- if (identifier) {
121
- return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier);
122
- } else {
123
- return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName);
124
- }
115
+ _relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {
116
+ return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier);
125
117
  }
126
118
 
127
119
  getSchemaDefinitionService(): SchemaDefinitionService {
@@ -137,48 +129,16 @@ let assertDestroyedStoreOnly: Function;
137
129
 
138
130
  if (DEBUG) {
139
131
  assertDestroyingStore = function assertDestroyedStore(store, method) {
140
- if (!store.shouldAssertMethodCallsOnDestroyedStore) {
141
- deprecate(
142
- `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
143
- !(store.isDestroying || store.isDestroyed),
144
- {
145
- id: 'ember-data:method-calls-on-destroyed-store',
146
- until: '3.8',
147
- for: '@ember-data/store',
148
- since: {
149
- available: '3.8',
150
- enabled: '3.8',
151
- },
152
- }
153
- );
154
- } else {
155
- assert(
156
- `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
157
- !(store.isDestroying || store.isDestroyed)
158
- );
159
- }
132
+ assert(
133
+ `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
134
+ !(store.isDestroying || store.isDestroyed)
135
+ );
160
136
  };
161
137
  assertDestroyedStoreOnly = function assertDestroyedStoreOnly(store, method) {
162
- if (!store.shouldAssertMethodCallsOnDestroyedStore) {
163
- deprecate(
164
- `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
165
- !store.isDestroyed,
166
- {
167
- id: 'ember-data:method-calls-on-destroyed-store',
168
- until: '3.8',
169
- for: '@ember-data/store',
170
- since: {
171
- available: '3.8',
172
- enabled: '3.8',
173
- },
174
- }
175
- );
176
- } else {
177
- assert(
178
- `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
179
- !store.isDestroyed
180
- );
181
- }
138
+ assert(
139
+ `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
140
+ !store.isDestroyed
141
+ );
182
142
  };
183
143
  }
184
144
 
@@ -20,6 +20,7 @@ import type { PrivateSnapshot } from './snapshot';
20
20
  import Snapshot from './snapshot';
21
21
  import { _bind, _guard, _objectIsAlive, guardDestroyedStore } from './store/common';
22
22
  import { normalizeResponseHelper } from './store/serializer-response';
23
+ import WeakCache from './weak-cache';
23
24
 
24
25
  function payloadIsNotBlank(adapterPayload): boolean {
25
26
  if (Array.isArray(adapterPayload)) {
@@ -455,7 +456,7 @@ export default class FetchManager {
455
456
  let identifiers = new Array(totalItems);
456
457
  let seeking: { [id: string]: PendingFetchItem } = Object.create(null);
457
458
 
458
- let optionsMap = new WeakMap<RecordIdentifier, Dict<unknown>>();
459
+ let optionsMap = new WeakCache<RecordIdentifier, Dict<unknown>>(DEBUG ? 'fetch-options' : '');
459
460
 
460
461
  for (let i = 0; i < totalItems; i++) {
461
462
  let pendingItem = pendingFetchItems[i];
@@ -15,7 +15,6 @@ import type {
15
15
  } from '@ember-data/record-data/-private';
16
16
  import type { UpgradedMeta } from '@ember-data/record-data/-private/graph/-edge-definition';
17
17
 
18
- import { identifierCacheFor } from '../../identifiers/cache';
19
18
  import { DSModel } from '../../ts-interfaces/ds-model';
20
19
  import type { StableRecordIdentifier } from '../../ts-interfaces/identifier';
21
20
  import type { RecordData } from '../../ts-interfaces/record-data';
@@ -174,7 +173,7 @@ export default class InternalModel {
174
173
  set id(value: string | null) {
175
174
  if (value !== this._id) {
176
175
  let newIdentifier = { type: this.identifier.type, lid: this.identifier.lid, id: value };
177
- identifierCacheFor(this.store).updateRecordIdentifier(this.identifier, newIdentifier);
176
+ this.store.identifierCache.updateRecordIdentifier(this.identifier, newIdentifier);
178
177
  this.notifyPropertyChange('id');
179
178
  }
180
179
  }
@@ -437,7 +436,7 @@ export default class InternalModel {
437
436
  getBelongsTo(key, options) {
438
437
  let resource = (this._recordData as DefaultRecordData).getBelongsTo(key);
439
438
  let identifier =
440
- resource && resource.data ? identifierCacheFor(this.store).getOrCreateRecordIdentifier(resource.data) : null;
439
+ resource && resource.data ? this.store.identifierCache.getOrCreateRecordIdentifier(resource.data) : null;
441
440
  let relationshipMeta = this.store._relationshipMetaFor(this.modelName, null, key);
442
441
  if (!relationshipMeta) return;
443
442
 
@@ -1,18 +1,17 @@
1
+ import { DEBUG } from '@glimmer/env';
2
+
1
3
  import { ModelSchema } from '../../ts-interfaces/ds-model';
2
4
  import type { AttributeSchema, RelationshipSchema } from '../../ts-interfaces/record-data-schemas';
3
5
  import type { Dict } from '../../ts-interfaces/utils';
4
6
  import type CoreStore from '../core-store';
7
+ import WeakCache from '../weak-cache';
5
8
 
6
- const AvailableShims = new WeakMap<CoreStore, Dict<ShimModelClass>>();
7
-
9
+ const AvailableShims = new WeakCache<CoreStore, Dict<ShimModelClass>>(DEBUG ? 'schema-shims' : '');
10
+ AvailableShims._generator = () => {
11
+ return Object.create(null) as Dict<ShimModelClass>;
12
+ };
8
13
  export function getShimClass(store: CoreStore, modelName: string): ShimModelClass {
9
- let shims = AvailableShims.get(store);
10
-
11
- if (shims === undefined) {
12
- shims = Object.create(null) as Dict<ShimModelClass>;
13
- AvailableShims.set(store, shims);
14
- }
15
-
14
+ let shims = AvailableShims.lookup(store);
16
15
  let shim = shims[modelName];
17
16
  if (shim === undefined) {
18
17
  shim = shims[modelName] = new ShimModelClass(store, modelName);
@@ -37,8 +36,8 @@ export default class ShimModelClass implements ModelSchema {
37
36
  constructor(private __store: CoreStore, public modelName: string) {}
38
37
 
39
38
  get fields(): Map<string, 'attribute' | 'belongsTo' | 'hasMany'> {
40
- let attrs = this.__store._attributesDefinitionFor(this.modelName);
41
- let relationships = this.__store._relationshipsDefinitionFor(this.modelName);
39
+ let attrs = this.__store._attributesDefinitionFor({ type: this.modelName });
40
+ let relationships = this.__store._relationshipsDefinitionFor({ type: this.modelName });
42
41
  let fields = new Map<string, 'attribute' | 'belongsTo' | 'hasMany'>();
43
42
  Object.keys(attrs).forEach((key) => fields.set(key, 'attribute'));
44
43
  Object.keys(relationships).forEach((key) => fields.set(key, relationships[key]!.kind));
@@ -46,17 +45,17 @@ export default class ShimModelClass implements ModelSchema {
46
45
  }
47
46
 
48
47
  get attributes(): Map<string, AttributeSchema> {
49
- let attrs = this.__store._attributesDefinitionFor(this.modelName);
48
+ let attrs = this.__store._attributesDefinitionFor({ type: this.modelName });
50
49
  return mapFromHash(attrs);
51
50
  }
52
51
 
53
52
  get relationshipsByName(): Map<string, RelationshipSchema> {
54
- let relationships = this.__store._relationshipsDefinitionFor(this.modelName);
53
+ let relationships = this.__store._relationshipsDefinitionFor({ type: this.modelName });
55
54
  return mapFromHash(relationships);
56
55
  }
57
56
 
58
57
  eachAttribute<T>(callback: (this: T | undefined, key: string, attribute: AttributeSchema) => void, binding?: T) {
59
- let attrDefs = this.__store._attributesDefinitionFor(this.modelName);
58
+ let attrDefs = this.__store._attributesDefinitionFor({ type: this.modelName });
60
59
  Object.keys(attrDefs).forEach((key) => {
61
60
  callback.call(binding, key, attrDefs[key] as AttributeSchema);
62
61
  });
@@ -66,7 +65,7 @@ export default class ShimModelClass implements ModelSchema {
66
65
  callback: (this: T | undefined, key: string, relationship: RelationshipSchema) => void,
67
66
  binding?: T
68
67
  ) {
69
- let relationshipDefs = this.__store._relationshipsDefinitionFor(this.modelName);
68
+ let relationshipDefs = this.__store._relationshipsDefinitionFor({ type: this.modelName });
70
69
  Object.keys(relationshipDefs).forEach((key) => {
71
70
  callback.call(binding, key, relationshipDefs[key] as RelationshipSchema);
72
71
  });
@@ -76,7 +75,7 @@ export default class ShimModelClass implements ModelSchema {
76
75
  callback: (this: T | undefined, key: string, relationship: RelationshipSchema) => void,
77
76
  binding?: T
78
77
  ) {
79
- let relationshipDefs = this.__store._relationshipsDefinitionFor(this.modelName);
78
+ let relationshipDefs = this.__store._relationshipsDefinitionFor({ type: this.modelName });
80
79
  Object.keys(relationshipDefs).forEach((key) => {
81
80
  if (relationshipDefs[key]!.type) {
82
81
  callback.call(binding, key, relationshipDefs[key] as RelationshipSchema);
@@ -6,27 +6,22 @@ import { A } from '@ember/array';
6
6
  import { assert } from '@ember/debug';
7
7
  import { get, set } from '@ember/object';
8
8
  import { _backburner as emberBackburner } from '@ember/runloop';
9
+ import { DEBUG } from '@glimmer/env';
9
10
 
10
11
  import isStableIdentifier from '../identifiers/is-stable-identifier';
11
12
  import { AdapterPopulatedRecordArray, RecordArray } from './record-arrays';
12
13
  import { internalModelFactoryFor } from './store/internal-model-factory';
14
+ import WeakCache from './weak-cache';
13
15
 
14
- const RecordArraysCache = new WeakMap();
15
-
16
+ const RecordArraysCache = new WeakCache(DEBUG ? 'record-arrays' : '');
17
+ RecordArraysCache._generator = () => new Set();
16
18
  export function recordArraysForIdentifier(identifierOrInternalModel) {
17
- if (RecordArraysCache.has(identifierOrInternalModel)) {
18
- // return existing Set if exists
19
- return RecordArraysCache.get(identifierOrInternalModel);
20
- }
21
-
22
- // returns workable Set instance
23
- RecordArraysCache.set(identifierOrInternalModel, new Set());
24
- return RecordArraysCache.get(identifierOrInternalModel);
19
+ return RecordArraysCache.lookup(identifierOrInternalModel);
25
20
  }
26
21
 
27
22
  const pendingForIdentifier = new Set([]);
28
23
 
29
- const getIdentifier = function getIdentifier(identifierOrInternalModel) {
24
+ function getIdentifier(identifierOrInternalModel) {
30
25
  let i = identifierOrInternalModel;
31
26
  if (!isStableIdentifier(identifierOrInternalModel)) {
32
27
  // identifier may actually be an internalModel
@@ -37,13 +32,9 @@ const getIdentifier = function getIdentifier(identifierOrInternalModel) {
37
32
  }
38
33
 
39
34
  return i;
40
- };
41
-
42
- const peekIMCache = function peekIMCache(cache, identifier) {
43
- return cache.peek(identifier);
44
- };
35
+ }
45
36
 
46
- const shouldIncludeInRecordArrays = function shouldIncludeInRecordArrays(store, identifier) {
37
+ function shouldIncludeInRecordArrays(store, identifier) {
47
38
  const cache = internalModelFactoryFor(store);
48
39
  const internalModel = cache.peek(identifier);
49
40
 
@@ -51,7 +42,7 @@ const shouldIncludeInRecordArrays = function shouldIncludeInRecordArrays(store,
51
42
  return false;
52
43
  }
53
44
  return !internalModel.isHiddenFromRecordArrays();
54
- };
45
+ }
55
46
 
56
47
  /**
57
48
  @class RecordArrayManager
@@ -364,7 +355,7 @@ class RecordArrayManager {
364
355
  }
365
356
  }
366
357
 
367
- const removeFromArray = function removeFromArray(array, item) {
358
+ function removeFromArray(array, item) {
368
359
  let index = array.indexOf(item);
369
360
 
370
361
  if (index !== -1) {
@@ -373,9 +364,9 @@ const removeFromArray = function removeFromArray(array, item) {
373
364
  }
374
365
 
375
366
  return false;
376
- };
367
+ }
377
368
 
378
- const updateLiveRecordArray = function updateLiveRecordArray(store, recordArray, identifiers) {
369
+ function updateLiveRecordArray(store, recordArray, identifiers) {
379
370
  let identifiersToAdd = [];
380
371
  let identifiersToRemove = [];
381
372
 
@@ -398,41 +389,28 @@ const updateLiveRecordArray = function updateLiveRecordArray(store, recordArray,
398
389
  }
399
390
 
400
391
  if (identifiersToAdd.length > 0) {
401
- pushIdentifiers(recordArray, identifiersToAdd, internalModelFactoryFor(store));
392
+ recordArray._pushIdentifiers(identifiersToAdd);
402
393
  }
403
394
  if (identifiersToRemove.length > 0) {
404
- removeIdentifiers(recordArray, identifiersToRemove, internalModelFactoryFor(store));
405
- }
406
- };
407
-
408
- const pushIdentifiers = function pushIdentifiers(recordArray, identifiers, cache) {
409
- recordArray._pushIdentifiers(identifiers);
410
- };
411
- const removeIdentifiers = function removeIdentifiers(recordArray, identifiers, cache) {
412
- if (!recordArray._removeIdentifiers) {
413
- // deprecate('not allowed to use this intimate api any more');
414
- recordArray._removeInternalModels(identifiers.map((i) => peekIMCache(cache, i)));
415
- } else {
416
- recordArray._removeIdentifiers(identifiers);
395
+ recordArray._removeIdentifiers(identifiersToRemove);
417
396
  }
418
- };
397
+ }
419
398
 
420
- const removeFromAdapterPopulatedRecordArrays = function removeFromAdapterPopulatedRecordArrays(store, identifiers) {
399
+ function removeFromAdapterPopulatedRecordArrays(store, identifiers) {
421
400
  for (let i = 0; i < identifiers.length; i++) {
422
401
  removeFromAll(store, identifiers[i]);
423
402
  }
424
- };
403
+ }
425
404
 
426
- const removeFromAll = function removeFromAll(store, identifier) {
405
+ function removeFromAll(store, identifier) {
427
406
  identifier = getIdentifier(identifier);
428
407
  const recordArrays = recordArraysForIdentifier(identifier);
429
- const cache = internalModelFactoryFor(store);
430
408
 
431
409
  recordArrays.forEach(function (recordArray) {
432
- removeIdentifiers(recordArray, [identifier], cache);
410
+ recordArray._removeIdentifiers([identifier]);
433
411
  });
434
412
 
435
413
  recordArrays.clear();
436
- };
414
+ }
437
415
 
438
416
  export default RecordArrayManager;
@@ -1,9 +1,5 @@
1
1
  import { A } from '@ember/array';
2
2
  import { get } from '@ember/object';
3
- import { once } from '@ember/runloop';
4
- import { DEBUG } from '@glimmer/env';
5
-
6
- import { DEPRECATE_EVENTED_API_USAGE } from '@ember-data/private-build-infra/deprecations';
7
3
 
8
4
  import RecordArray from './record-array';
9
5
 
@@ -51,18 +47,13 @@ import RecordArray from './record-array';
51
47
  @public
52
48
  @extends RecordArray
53
49
  */
54
- let AdapterPopulatedRecordArray = RecordArray.extend({
50
+ export default RecordArray.extend({
55
51
  init() {
56
52
  this.set('content', this.get('content') || A());
57
53
 
58
54
  this._super(...arguments);
59
55
  this.query = this.query || null;
60
56
  this.links = this.links || null;
61
-
62
- if (DEBUG) {
63
- this._getDeprecatedEventedInfo = () =>
64
- `AdapterPopulatedRecordArray containing ${this.modelName} for query: ${this.query}`;
65
- }
66
57
  },
67
58
 
68
59
  replace() {
@@ -90,14 +81,6 @@ let AdapterPopulatedRecordArray = RecordArray.extend({
90
81
  });
91
82
 
92
83
  this.manager._associateWithRecordArray(identifiersOrInternalModels, this);
93
-
94
- if (DEPRECATE_EVENTED_API_USAGE) {
95
- let _hasDidLoad = DEBUG ? this._has('didLoad') : this.has('didLoad');
96
- if (_hasDidLoad) {
97
- // TODO: should triggering didLoad event be the last action of the runLoop?
98
- once(this, 'trigger', 'didLoad');
99
- }
100
- }
101
84
  },
102
85
 
103
86
  /**
@@ -110,5 +93,3 @@ let AdapterPopulatedRecordArray = RecordArray.extend({
110
93
  this._setObjects(identifiers, payload);
111
94
  },
112
95
  });
113
-
114
- export default AdapterPopulatedRecordArray;
@@ -3,11 +3,9 @@
3
3
  */
4
4
  import ArrayProxy from '@ember/array/proxy';
5
5
  import { computed, get, set } from '@ember/object';
6
- import { DEBUG } from '@glimmer/env';
7
6
 
8
7
  import { Promise } from 'rsvp';
9
8
 
10
- import DeprecatedEvented from '../deprecated-evented';
11
9
  import { PromiseArray } from '../promise-proxies';
12
10
  import SnapshotRecordArray from '../snapshot-record-array';
13
11
  import { internalModelFactoryFor } from '../store/internal-model-factory';
@@ -28,17 +26,12 @@ function recordForIdentifier(store, identifier) {
28
26
  @class RecordArray
29
27
  @public
30
28
  @extends Ember.ArrayProxy
31
- @uses Ember.Evented
32
29
  */
33
30
 
34
- let RecordArray = ArrayProxy.extend(DeprecatedEvented, {
31
+ let RecordArray = ArrayProxy.extend({
35
32
  init(args) {
36
33
  this._super(args);
37
34
 
38
- if (DEBUG) {
39
- this._getDeprecatedEventedInfo = () => `RecordArray containing ${this.modelName}`;
40
- }
41
-
42
35
  /**
43
36
  The array of client ids backing the record array. When a
44
37
  record is requested from the record array, the record
@@ -1,7 +1,9 @@
1
1
  import { assert } from '@ember/debug';
2
+ import { DEBUG } from '@glimmer/env';
2
3
 
3
4
  import type { StableRecordIdentifier } from '../ts-interfaces/identifier';
4
5
  import type { RecordData } from '../ts-interfaces/record-data';
6
+ import WeakCache from './weak-cache';
5
7
 
6
8
  /*
7
9
  * Returns the RecordData instance associated with a given
@@ -25,23 +27,23 @@ type Reference = { internalModel: InternalModel };
25
27
 
26
28
  type Instance = StableRecordIdentifier | InternalModel | RecordData | DSModelOrSnapshot | Reference;
27
29
 
28
- const IdentifierCache = new WeakMap<StableRecordIdentifier, RecordData>();
30
+ const RecordDataForIdentifierCache = new WeakCache<StableRecordIdentifier, RecordData>(DEBUG ? 'recordData' : '');
29
31
 
30
- export function setRecordDataFor(identifier: StableRecordIdentifier, recordData: RecordData) {
31
- assert(`Illegal set of identifier`, !IdentifierCache.has(identifier));
32
- IdentifierCache.set(identifier, recordData);
32
+ export function setRecordDataFor(identifier: StableRecordIdentifier, recordData: RecordData): void {
33
+ assert(`Illegal set of identifier`, !RecordDataForIdentifierCache.has(identifier));
34
+ RecordDataForIdentifierCache.set(identifier, recordData);
33
35
  }
34
36
 
35
- export function removeRecordDataFor(identifier) {
36
- IdentifierCache.delete(identifier);
37
+ export function removeRecordDataFor(identifier: StableRecordIdentifier): void {
38
+ RecordDataForIdentifierCache.delete(identifier);
37
39
  }
38
40
 
39
41
  export default function recordDataFor(instance: StableRecordIdentifier): RecordData | null;
40
42
  export default function recordDataFor(instance: Instance): RecordData;
41
43
  export default function recordDataFor(instance: object): null;
42
44
  export default function recordDataFor(instance: Instance | object): RecordData | null {
43
- if (IdentifierCache.has(instance as StableRecordIdentifier)) {
44
- return IdentifierCache.get(instance as StableRecordIdentifier) as RecordData;
45
+ if (RecordDataForIdentifierCache.has(instance as StableRecordIdentifier)) {
46
+ return RecordDataForIdentifierCache.get(instance as StableRecordIdentifier) as RecordData;
45
47
  }
46
48
  let internalModel =
47
49
  (instance as DSModelOrSnapshot)._internalModel || (instance as Reference).internalModel || instance;
@@ -1,11 +1,16 @@
1
- import { identifierCacheFor } from '../identifiers/cache';
1
+ import { DEBUG } from '@glimmer/env';
2
+
2
3
  import type { RecordIdentifier, StableRecordIdentifier } from '../ts-interfaces/identifier';
3
4
  import type CoreStore from './core-store';
5
+ import WeakCache from './weak-cache';
4
6
 
5
7
  type UnsubscribeToken = Object;
6
8
 
7
- const Cache = new WeakMap<StableRecordIdentifier, Map<UnsubscribeToken, NotificationCallback>>();
8
- const Tokens = new WeakMap<UnsubscribeToken, StableRecordIdentifier>();
9
+ const Cache = new WeakCache<StableRecordIdentifier, Map<UnsubscribeToken, NotificationCallback>>(
10
+ DEBUG ? 'subscribers' : ''
11
+ );
12
+ Cache._generator = () => new Map();
13
+ const Tokens = new WeakCache<UnsubscribeToken, StableRecordIdentifier>(DEBUG ? 'identifier' : '');
9
14
 
10
15
  export type NotificationType =
11
16
  | 'attributes'
@@ -39,12 +44,8 @@ export default class NotificationManager {
39
44
  constructor(private store: CoreStore) {}
40
45
 
41
46
  subscribe(identifier: RecordIdentifier, callback: NotificationCallback): UnsubscribeToken {
42
- let stableIdentifier = identifierCacheFor(this.store).getOrCreateRecordIdentifier(identifier);
43
- let map = Cache.get(stableIdentifier);
44
- if (map === undefined) {
45
- map = new Map();
46
- Cache.set(stableIdentifier, map);
47
- }
47
+ let stableIdentifier = this.store.identifierCache.getOrCreateRecordIdentifier(identifier);
48
+ let map = Cache.lookup(stableIdentifier);
48
49
  let unsubToken = {};
49
50
  map.set(unsubToken, callback);
50
51
  Tokens.set(unsubToken, stableIdentifier);
@@ -54,7 +55,7 @@ export default class NotificationManager {
54
55
  notify(identifier: RecordIdentifier, value: 'attributes' | 'relationships' | 'property', key?: string): boolean;
55
56
  notify(identifier: RecordIdentifier, value: 'errors' | 'meta' | 'identity' | 'unload' | 'state'): boolean;
56
57
  notify(identifier: RecordIdentifier, value: NotificationType, key?: string): boolean {
57
- let stableIdentifier = identifierCacheFor(this.store).getOrCreateRecordIdentifier(identifier);
58
+ let stableIdentifier = this.store.identifierCache.getOrCreateRecordIdentifier(identifier);
58
59
  let callbackMap = Cache.get(stableIdentifier);
59
60
  if (!callbackMap || !callbackMap.size) {
60
61
  return false;
@@ -1,10 +1,8 @@
1
- import { deprecate } from '@ember/debug';
2
1
  import { dependentKeyCompat } from '@ember/object/compat';
3
2
  import { cached, tracked } from '@glimmer/tracking';
4
3
 
5
4
  import { resolve } from 'rsvp';
6
5
 
7
- import { DEPRECATE_BELONGS_TO_REFERENCE_PUSH } from '@ember-data/private-build-infra/deprecations';
8
6
  import type { BelongsToRelationship } from '@ember-data/record-data/-private';
9
7
  import { assertPolymorphicType } from '@ember-data/store/-debug';
10
8
 
@@ -12,7 +10,7 @@ import { SingleResourceDocument } from '../../ts-interfaces/ember-data-json-api'
12
10
  import { StableRecordIdentifier } from '../../ts-interfaces/identifier';
13
11
  import CoreStore from '../core-store';
14
12
  import { NotificationType, unsubscribe } from '../record-notification-manager';
15
- import { internalModelFactoryFor, peekRecordIdentifier, recordIdentifierFor } from '../store/internal-model-factory';
13
+ import { internalModelFactoryFor, recordIdentifierFor } from '../store/internal-model-factory';
16
14
  import RecordReference from './record';
17
15
  import Reference from './reference';
18
16
 
@@ -195,46 +193,28 @@ export default class BelongsToReference extends Reference {
195
193
  @param {Object|Promise} objectOrPromise a promise that resolves to a JSONAPI document object describing the new value of this relationship.
196
194
  @return {Promise<record>} A promise that resolves with the new value in this belongs-to relationship.
197
195
  */
198
- async push(objectOrPromise: Object | SingleResourceDocument): Promise<Object> {
199
- // TODO deprecate thenable support
200
- return resolve(objectOrPromise).then((data) => {
201
- let record: Object;
202
-
203
- if (DEPRECATE_BELONGS_TO_REFERENCE_PUSH && peekRecordIdentifier(data)) {
204
- deprecate('Pushing a record into a BelongsToReference is deprecated', false, {
205
- id: 'ember-data:belongs-to-reference-push-record',
206
- until: '4.0',
207
- for: '@ember-data/store',
208
- since: {
209
- available: '3.16',
210
- enabled: '3.16',
211
- },
212
- });
213
- record = data as Object;
214
- } else {
215
- record = this.store.push(data as SingleResourceDocument);
216
- }
217
-
218
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
219
- assertPolymorphicType(
220
- this.belongsToRelationship.identifier,
221
- this.belongsToRelationship.definition,
222
- recordIdentifierFor(record),
223
- this.store
224
- );
196
+ async push(data: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<Object> {
197
+ const jsonApiDoc = await resolve(data);
198
+ let record = this.store.push(jsonApiDoc);
199
+
200
+ assertPolymorphicType(
201
+ this.belongsToRelationship.identifier,
202
+ this.belongsToRelationship.definition,
203
+ recordIdentifierFor(record),
204
+ this.store
205
+ );
225
206
 
226
- const { graph, identifier } = this.belongsToRelationship;
227
- this.store._backburner.join(() => {
228
- graph.push({
229
- op: 'replaceRelatedRecord',
230
- record: identifier,
231
- field: this.key,
232
- value: recordIdentifierFor(record),
233
- });
207
+ const { graph, identifier } = this.belongsToRelationship;
208
+ this.store._backburner.join(() => {
209
+ graph.push({
210
+ op: 'replaceRelatedRecord',
211
+ record: identifier,
212
+ field: this.key,
213
+ value: recordIdentifierFor(record),
234
214
  });
235
-
236
- return record;
237
215
  });
216
+
217
+ return record;
238
218
  }
239
219
 
240
220
  /**