@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
@@ -3,8 +3,8 @@
3
3
  */
4
4
  import { getOwner } from '@ember/application';
5
5
  import { A } from '@ember/array';
6
- import { assert, deprecate, inspect, warn } from '@ember/debug';
7
- import { computed, defineProperty, set } from '@ember/object';
6
+ import { assert, inspect, warn } from '@ember/debug';
7
+ import { set } from '@ember/object';
8
8
  import { _backburner as emberBackburner } from '@ember/runloop';
9
9
  import type { Backburner } from '@ember/runloop/-private/backburner';
10
10
  import Service from '@ember/service';
@@ -16,16 +16,7 @@ import Ember from 'ember';
16
16
  import require from 'require';
17
17
  import { all, default as RSVP, Promise, resolve } from 'rsvp';
18
18
 
19
- import {
20
- HAS_ADAPTER_PACKAGE,
21
- HAS_EMBER_DATA_PACKAGE,
22
- HAS_RECORD_DATA_PACKAGE,
23
- HAS_SERIALIZER_PACKAGE,
24
- } from '@ember-data/private-build-infra';
25
- import {
26
- DEPRECATE_DEFAULT_ADAPTER,
27
- DEPRECATE_LEGACY_TEST_REGISTRATIONS,
28
- } from '@ember-data/private-build-infra/deprecations';
19
+ import { HAS_RECORD_DATA_PACKAGE } from '@ember-data/private-build-infra';
29
20
  import type {
30
21
  BelongsToRelationship,
31
22
  ManyRelationship,
@@ -33,8 +24,7 @@ import type {
33
24
  } from '@ember-data/record-data/-private';
34
25
  import type { RelationshipState } from '@ember-data/record-data/-private/graph/-state';
35
26
 
36
- import type { IdentifierCache } from '../identifiers/cache';
37
- import { identifierCacheFor } from '../identifiers/cache';
27
+ import { IdentifierCache } from '../identifiers/cache';
38
28
  import type { DSModel } from '../ts-interfaces/ds-model';
39
29
  import type {
40
30
  CollectionResourceDocument,
@@ -79,8 +69,7 @@ import NotificationManager from './record-notification-manager';
79
69
  import type { BelongsToReference, HasManyReference } from './references';
80
70
  import { RecordReference } from './references';
81
71
  import type RequestCache from './request-cache';
82
- import type { default as Snapshot } from './snapshot';
83
- import { _find, _findAll, _findBelongsTo, _findHasMany, _findMany, _query, _queryRecord } from './store/finders';
72
+ import { _findAll, _findBelongsTo, _findHasMany, _query, _queryRecord } from './store/finders';
84
73
  import {
85
74
  internalModelFactoryFor,
86
75
  peekRecordIdentifier,
@@ -88,6 +77,7 @@ import {
88
77
  setRecordIdentifier,
89
78
  } from './store/internal-model-factory';
90
79
  import RecordDataStoreWrapper from './store/record-data-store-wrapper';
80
+ import WeakCache from './weak-cache';
91
81
 
92
82
  type RecordDataConstruct = typeof RecordDataClass;
93
83
  let _RecordData: RecordDataConstruct | undefined;
@@ -95,18 +85,8 @@ let _RecordData: RecordDataConstruct | undefined;
95
85
  const { ENV } = Ember;
96
86
  type AsyncTrackingToken = Readonly<{ label: string; trace: Error | string }>;
97
87
  type PromiseArray<T> = Promise<T[]>;
98
- type PendingFetchItem = {
99
- internalModel: InternalModel;
100
- resolver: RSVP.Deferred<InternalModel>;
101
- options: any;
102
- trace?: Error;
103
- };
104
- type PendingSaveItem = {
105
- snapshot: Snapshot;
106
- resolver: RSVP.Deferred<void>;
107
- };
108
-
109
- const RECORD_REFERENCES = new WeakMap<StableRecordIdentifier, RecordReference>();
88
+
89
+ const RECORD_REFERENCES = new WeakCache<StableRecordIdentifier, RecordReference>(DEBUG ? 'reference' : '');
110
90
 
111
91
  function freeze<T>(obj: T): T {
112
92
  if (typeof Object.freeze === 'function') {
@@ -116,26 +96,6 @@ function freeze<T>(obj: T): T {
116
96
  return obj;
117
97
  }
118
98
 
119
- function deprecateTestRegistration(factoryType: 'adapter', factoryName: '-json-api'): void;
120
- function deprecateTestRegistration(factoryType: 'serializer', factoryName: '-json-api' | '-rest' | '-default'): void;
121
- function deprecateTestRegistration(
122
- factoryType: 'serializer' | 'adapter',
123
- factoryName: '-json-api' | '-rest' | '-default'
124
- ): void {
125
- deprecate(
126
- `You looked up the ${factoryType} "${factoryName}" but it was not found. Likely this means you are using a legacy ember-qunit moduleFor helper. Add "needs: ['${factoryType}:${factoryName}']", "integration: true", or refactor to modern syntax to resolve this deprecation.`,
127
- false,
128
- {
129
- id: 'ember-data:-legacy-test-registrations',
130
- until: '3.17',
131
- for: '@ember-data/store',
132
- since: {
133
- available: '3.15',
134
- enabled: '3.15',
135
- },
136
- }
137
- );
138
- }
139
99
  /**
140
100
  The store contains all of the data for records loaded from the server.
141
101
  It is also responsible for creating instances of `Model` that wrap
@@ -209,9 +169,6 @@ function deprecateTestRegistration(
209
169
  @public
210
170
  @extends Ember.Service
211
171
  */
212
- interface CoreStore {
213
- adapter: string;
214
- }
215
172
 
216
173
  abstract class CoreStore extends Service {
217
174
  /**
@@ -223,6 +180,7 @@ abstract class CoreStore extends Service {
223
180
  public recordArrayManager: RecordArrayManager = new RecordArrayManager({ store: this });
224
181
 
225
182
  declare _notificationManager: NotificationManager;
183
+ declare identifierCache: IdentifierCache;
226
184
  private _adapterCache = Object.create(null);
227
185
  private _serializerCache = Object.create(null);
228
186
  public _storeWrapper = new RecordDataStoreWrapper(this);
@@ -234,20 +192,14 @@ abstract class CoreStore extends Service {
234
192
  These queues are currently controlled by a flush scheduled into
235
193
  ember-data's custom backburner instance.
236
194
  */
237
- // used for coalescing record save requests
238
- private _pendingSave: PendingSaveItem[] = [];
239
195
  // used for coalescing internal model updates
240
196
  private _updatedInternalModels: InternalModel[] = [];
241
197
 
242
- // used to keep track of all the find requests that need to be coalesced
243
- private _pendingFetch = new Map<string, PendingFetchItem[]>();
244
-
245
198
  declare _fetchManager: FetchManager;
246
199
  declare _schemaDefinitionService: SchemaDefinitionService;
247
200
 
248
201
  // DEBUG-only properties
249
202
  declare _trackedAsyncRequests: AsyncTrackingToken[];
250
- shouldAssertMethodCallsOnDestroyedStore: boolean = true;
251
203
  shouldTrackAsyncRequests: boolean = false;
252
204
  generateStackTracesForTrackedRequests: boolean = false;
253
205
  declare _trackAsyncRequestStart: (str: string) => void;
@@ -301,60 +253,27 @@ abstract class CoreStore extends Service {
301
253
  constructor() {
302
254
  super(...arguments);
303
255
 
256
+ RECORD_REFERENCES._generator = (identifier) => {
257
+ return new RecordReference(this, identifier);
258
+ };
259
+
304
260
  this._fetchManager = new FetchManager(this);
305
261
  this._notificationManager = new NotificationManager(this);
306
262
  this.__recordDataFor = this.__recordDataFor.bind(this);
307
263
 
308
- if (DEBUG) {
309
- if (HAS_EMBER_DATA_PACKAGE && HAS_SERIALIZER_PACKAGE) {
310
- // support for legacy moduleFor style unit tests
311
- // that did not include transforms in "needs"
312
- // or which were not set to integration:true
313
- // that were relying on ember-test-helpers
314
- // doing an auto-registration of the transform
315
- // or us doing one
316
- const Mapping = {
317
- date: 'DateTransform',
318
- boolean: 'BooleanTransform',
319
- number: 'NumberTransform',
320
- string: 'StringTransform',
321
- };
322
- type MapKeys = keyof typeof Mapping;
323
- const keys = Object.keys(Mapping) as MapKeys[];
324
- let shouldWarn = false;
325
-
326
- let owner = getOwner(this);
327
- keys.forEach((attributeType) => {
328
- const transformFactory = owner.factoryFor(`transform:${attributeType}`);
329
-
330
- if (!transformFactory) {
331
- // we don't deprecate this because the moduleFor style tests with the closed
332
- // resolver will be deprecated on their own. When that deprecation completes
333
- // we can drop this.
334
- const Transform = require(`@ember-data/serializer/-private`)[Mapping[attributeType]];
335
- owner.register(`transform:${attributeType}`, Transform);
336
- shouldWarn = true;
337
- }
338
- });
264
+ /**
265
+ * Provides access to the IdentifierCache instance
266
+ * for this store.
267
+ *
268
+ * The IdentifierCache can be used to generate or
269
+ * retrieve a stable unique identifier for any resource.
270
+ *
271
+ * @property {IdentifierCache} identifierCache
272
+ * @public
273
+ */
274
+ this.identifierCache = new IdentifierCache();
339
275
 
340
- if (shouldWarn) {
341
- deprecate(
342
- `You are relying on the automatic registration of the transforms "date", "number", "boolean", and "string". Likely this means you are using a legacy ember-qunit moduleFor helper. Add "needs: ['transform:date', 'transform:boolean', 'transform:number', 'transform:string']", "integration: true", or refactor to modern syntax to resolve this deprecation.`,
343
- false,
344
- {
345
- id: 'ember-data:-legacy-test-registrations',
346
- until: '3.17',
347
- for: '@ember-data/store',
348
- since: {
349
- available: '3.15',
350
- enabled: '3.15',
351
- },
352
- }
353
- );
354
- }
355
- }
356
-
357
- this.shouldAssertMethodCallsOnDestroyedStore = this.shouldAssertMethodCallsOnDestroyedStore || false;
276
+ if (DEBUG) {
358
277
  if (this.shouldTrackAsyncRequests === undefined) {
359
278
  this.shouldTrackAsyncRequests = false;
360
279
  }
@@ -364,14 +283,14 @@ abstract class CoreStore extends Service {
364
283
 
365
284
  this._trackedAsyncRequests = [];
366
285
  this._trackAsyncRequestStart = (label) => {
367
- let trace =
286
+ let trace: string | Error =
368
287
  'set `store.generateStackTracesForTrackedRequests = true;` to get a detailed trace for where this request originated';
369
288
 
370
289
  if (this.generateStackTracesForTrackedRequests) {
371
290
  try {
372
291
  throw new Error(`EmberData TrackedRequest: ${label}`);
373
292
  } catch (e) {
374
- trace = e;
293
+ trace = e as Error;
375
294
  }
376
295
  }
377
296
 
@@ -411,20 +330,6 @@ abstract class CoreStore extends Service {
411
330
  return this._fetchManager.requestCache;
412
331
  }
413
332
 
414
- /**
415
- * Provides access to the IdentifierCache instance
416
- * for this store.
417
- *
418
- * The IdentifierCache can be used to generate or
419
- * retrieve a stable unique identifier for any resource.
420
- *
421
- * @property {IdentifierCache} identifierCache
422
- * @public
423
- */
424
- get identifierCache(): IdentifierCache {
425
- return identifierCacheFor(this);
426
- }
427
-
428
333
  _instantiateRecord(
429
334
  internalModel: InternalModel,
430
335
  modelName: string,
@@ -444,7 +349,7 @@ abstract class CoreStore extends Service {
444
349
  }
445
350
 
446
351
  // convert relationship Records to RecordDatas before passing to RecordData
447
- let defs = this._relationshipsDefinitionFor(modelName);
352
+ let defs = this._relationshipsDefinitionFor({ type: modelName });
448
353
 
449
354
  if (defs !== null) {
450
355
  let keys = Object.keys(properties);
@@ -493,20 +398,12 @@ abstract class CoreStore extends Service {
493
398
  }
494
399
 
495
400
  // FeatureFlagged in the DSModelStore claas
496
- _attributesDefinitionFor(modelName: string, identifier?: StableRecordIdentifier): AttributesSchema {
497
- if (identifier) {
498
- return this.getSchemaDefinitionService().attributesDefinitionFor(identifier);
499
- } else {
500
- return this.getSchemaDefinitionService().attributesDefinitionFor(modelName);
501
- }
401
+ _attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {
402
+ return this.getSchemaDefinitionService().attributesDefinitionFor(identifier);
502
403
  }
503
404
 
504
- _relationshipsDefinitionFor(modelName: string, identifier?: StableRecordIdentifier) {
505
- if (identifier) {
506
- return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier);
507
- } else {
508
- return this.getSchemaDefinitionService().relationshipsDefinitionFor(modelName);
509
- }
405
+ _relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }) {
406
+ return this.getSchemaDefinitionService().relationshipsDefinitionFor(identifier);
510
407
  }
511
408
 
512
409
  registerSchemaDefinitionService(schema: SchemaDefinitionService) {
@@ -519,7 +416,7 @@ abstract class CoreStore extends Service {
519
416
 
520
417
  // TODO Double check this return value is correct
521
418
  _relationshipMetaFor(modelName: string, id: string | null, key: string) {
522
- return this._relationshipsDefinitionFor(modelName)[key];
419
+ return this._relationshipsDefinitionFor({ type: modelName })[key];
523
420
  }
524
421
 
525
422
  /**
@@ -1278,29 +1175,6 @@ abstract class CoreStore extends Service {
1278
1175
  return promiseArray(all(promises).then(A, null, `DS: Store#findByIds of ${normalizedModelName} complete`));
1279
1176
  }
1280
1177
 
1281
- /**
1282
- This method is called by `findRecord` if it discovers that a particular
1283
- type/id pair hasn't been loaded yet to kick off a request to the
1284
- adapter.
1285
-
1286
- @method _fetchRecord
1287
- @private
1288
- @param {InternalModel} internalModel model
1289
- @return {Promise} promise
1290
- */
1291
- _fetchRecord(internalModel: InternalModel, options): Promise<InternalModel> {
1292
- let modelName = internalModel.modelName;
1293
- let adapter = this.adapterFor(modelName);
1294
-
1295
- assert(`You tried to find a record but you have no adapter (for ${modelName})`, adapter);
1296
- assert(
1297
- `You tried to find a record but your adapter (for ${modelName}) does not implement 'findRecord'`,
1298
- typeof adapter.findRecord === 'function'
1299
- );
1300
-
1301
- return _find(adapter, this, internalModel.modelClass, internalModel.id, internalModel, options);
1302
- }
1303
-
1304
1178
  _scheduleFetchMany(internalModels, options) {
1305
1179
  let fetches = new Array(internalModels.length);
1306
1180
 
@@ -1311,7 +1185,7 @@ abstract class CoreStore extends Service {
1311
1185
  return Promise.all(fetches);
1312
1186
  }
1313
1187
 
1314
- _scheduleFetchThroughFetchManager(internalModel: InternalModel, options = {}): RSVP.Promise<InternalModel> {
1188
+ _scheduleFetch(internalModel: InternalModel, options = {}): RSVP.Promise<InternalModel> {
1315
1189
  let generateStackTrace = this.generateStackTracesForTrackedRequests;
1316
1190
  // TODO remove this once we don't rely on state machine
1317
1191
  internalModel.send('loadingData');
@@ -1346,165 +1220,6 @@ abstract class CoreStore extends Service {
1346
1220
  );
1347
1221
  }
1348
1222
 
1349
- _scheduleFetch(internalModel: InternalModel, options): RSVP.Promise<InternalModel> {
1350
- return this._scheduleFetchThroughFetchManager(internalModel, options);
1351
- }
1352
-
1353
- flushAllPendingFetches() {
1354
- return;
1355
- //assert here
1356
- }
1357
-
1358
- _flushPendingFetchForType(pendingFetchItems: PendingFetchItem[], modelName: string) {
1359
- let store = this;
1360
- let adapter = store.adapterFor(modelName);
1361
- let shouldCoalesce = !!adapter.findMany && adapter.coalesceFindRequests;
1362
- let totalItems = pendingFetchItems.length;
1363
- let internalModels = new Array(totalItems);
1364
- let seeking = Object.create(null);
1365
-
1366
- let optionsMap = new WeakMap();
1367
-
1368
- for (let i = 0; i < totalItems; i++) {
1369
- let pendingItem = pendingFetchItems[i];
1370
- let internalModel = pendingItem.internalModel;
1371
- internalModels[i] = internalModel;
1372
- optionsMap.set(internalModel, pendingItem.options);
1373
- // We can remove this "not null" cast once we have enough typing
1374
- // to know we are only dealing with ExistingResourceIdentifierObjects
1375
- seeking[internalModel.id!] = pendingItem;
1376
- }
1377
-
1378
- function _fetchRecord(recordResolverPair) {
1379
- let recordFetch = store._fetchRecord(recordResolverPair.internalModel, recordResolverPair.options);
1380
-
1381
- recordResolverPair.resolver.resolve(recordFetch);
1382
- }
1383
-
1384
- function handleFoundRecords(foundInternalModels: InternalModel[], expectedInternalModels: InternalModel[]) {
1385
- // resolve found records
1386
- let found = Object.create(null);
1387
- for (let i = 0, l = foundInternalModels.length; i < l; i++) {
1388
- let internalModel = foundInternalModels[i];
1389
-
1390
- // We can remove this "not null" cast once we have enough typing
1391
- // to know we are only dealing with ExistingResourceIdentifierObjects
1392
- let pair = seeking[internalModel.id!];
1393
- found[internalModel.id!] = internalModel;
1394
-
1395
- if (pair) {
1396
- let resolver = pair.resolver;
1397
- resolver.resolve(internalModel);
1398
- }
1399
- }
1400
-
1401
- // reject missing records
1402
- let missingInternalModels: InternalModel[] = [];
1403
-
1404
- for (let i = 0, l = expectedInternalModels.length; i < l; i++) {
1405
- let internalModel = expectedInternalModels[i];
1406
-
1407
- // We can remove this "not null" cast once we have enough typing
1408
- // to know we are only dealing with ExistingResourceIdentifierObjects
1409
- if (!found[internalModel.id!]) {
1410
- missingInternalModels.push(internalModel);
1411
- }
1412
- }
1413
-
1414
- if (missingInternalModels.length) {
1415
- warn(
1416
- 'Ember Data expected to find records with the following ids in the adapter response but they were missing: [ "' +
1417
- missingInternalModels.map((r) => r.id).join('", "') +
1418
- '" ]',
1419
- false,
1420
- {
1421
- id: 'ds.store.missing-records-from-adapter',
1422
- }
1423
- );
1424
- rejectInternalModels(missingInternalModels);
1425
- }
1426
- }
1427
-
1428
- function rejectInternalModels(internalModels: InternalModel[], error?: Error) {
1429
- for (let i = 0, l = internalModels.length; i < l; i++) {
1430
- let internalModel = internalModels[i];
1431
-
1432
- // We can remove this "not null" cast once we have enough typing
1433
- // to know we are only dealing with ExistingResourceIdentifierObjects
1434
- let pair = seeking[internalModel.id!];
1435
-
1436
- if (pair) {
1437
- pair.resolver.reject(
1438
- error ||
1439
- new Error(
1440
- `Expected: '${internalModel}' to be present in the adapter provided payload, but it was not found.`
1441
- )
1442
- );
1443
- }
1444
- }
1445
- }
1446
-
1447
- if (shouldCoalesce) {
1448
- // TODO: Improve records => snapshots => records => snapshots
1449
- //
1450
- // We want to provide records to all store methods and snapshots to all
1451
- // adapter methods. To make sure we're doing that we're providing an array
1452
- // of snapshots to adapter.groupRecordsForFindMany(), which in turn will
1453
- // return grouped snapshots instead of grouped records.
1454
- //
1455
- // But since the _findMany() finder is a store method we need to get the
1456
- // records from the grouped snapshots even though the _findMany() finder
1457
- // will once again convert the records to snapshots for adapter.findMany()
1458
- let snapshots = new Array(totalItems);
1459
- for (let i = 0; i < totalItems; i++) {
1460
- let internalModel = internalModels[i];
1461
- snapshots[i] = internalModel.createSnapshot(optionsMap.get(internalModel));
1462
- }
1463
-
1464
- let groups;
1465
- if (adapter.groupRecordsForFindMany) {
1466
- groups = adapter.groupRecordsForFindMany(this, snapshots);
1467
- } else {
1468
- groups = [snapshots];
1469
- }
1470
-
1471
- for (let i = 0, l = groups.length; i < l; i++) {
1472
- let group = groups[i];
1473
- let totalInGroup = groups[i].length;
1474
- let ids = new Array(totalInGroup);
1475
- let groupedInternalModels = new Array(totalInGroup);
1476
-
1477
- for (let j = 0; j < totalInGroup; j++) {
1478
- let internalModel = group[j]._internalModel;
1479
-
1480
- groupedInternalModels[j] = internalModel;
1481
- ids[j] = internalModel.id;
1482
- }
1483
-
1484
- if (totalInGroup > 1) {
1485
- (function (groupedInternalModels) {
1486
- _findMany(adapter, store, modelName, ids, groupedInternalModels, optionsMap)
1487
- .then(function (foundInternalModels) {
1488
- handleFoundRecords(foundInternalModels, groupedInternalModels);
1489
- })
1490
- .catch(function (error) {
1491
- rejectInternalModels(groupedInternalModels, error);
1492
- });
1493
- })(groupedInternalModels);
1494
- } else if (ids.length === 1) {
1495
- let pair = seeking[groupedInternalModels[0].id];
1496
- _fetchRecord(pair);
1497
- } else {
1498
- assert("You cannot return an empty array from adapter's method groupRecordsForFindMany");
1499
- }
1500
- }
1501
- } else {
1502
- for (let i = 0; i < totalItems; i++) {
1503
- _fetchRecord(pendingFetchItems[i]);
1504
- }
1505
- }
1506
- }
1507
-
1508
1223
  /**
1509
1224
  Get the reference for the specified record.
1510
1225
 
@@ -1562,15 +1277,9 @@ abstract class CoreStore extends Service {
1562
1277
  isMaybeIdentifier(resourceIdentifier)
1563
1278
  );
1564
1279
 
1565
- let identifier: StableRecordIdentifier = identifierCacheFor(this).getOrCreateRecordIdentifier(resourceIdentifier);
1280
+ let identifier: StableRecordIdentifier = this.identifierCache.getOrCreateRecordIdentifier(resourceIdentifier);
1566
1281
  if (identifier) {
1567
- if (RECORD_REFERENCES.has(identifier)) {
1568
- return RECORD_REFERENCES.get(identifier);
1569
- }
1570
-
1571
- let reference = new RecordReference(this, identifier);
1572
- RECORD_REFERENCES.set(identifier, reference);
1573
- return reference;
1282
+ return RECORD_REFERENCES.lookup(identifier);
1574
1283
  }
1575
1284
  }
1576
1285
 
@@ -1626,7 +1335,7 @@ abstract class CoreStore extends Service {
1626
1335
  peekRecord(identifier: ResourceIdentifierObject): RecordInstance | null;
1627
1336
  peekRecord(identifier: ResourceIdentifierObject | string, id?: string | number): RecordInstance | null {
1628
1337
  if (arguments.length === 1 && isMaybeIdentifier(identifier)) {
1629
- let stableIdentifier = identifierCacheFor(this).peekRecordIdentifier(identifier);
1338
+ let stableIdentifier = this.identifierCache.peekRecordIdentifier(identifier);
1630
1339
  if (stableIdentifier) {
1631
1340
  return internalModelFactoryFor(this).peek(stableIdentifier)?.getRecord() || null;
1632
1341
  }
@@ -1716,7 +1425,7 @@ abstract class CoreStore extends Service {
1716
1425
  const trueId = ensureStringId(id);
1717
1426
  const resource = { type, id: trueId };
1718
1427
 
1719
- const identifier = identifierCacheFor(this).peekRecordIdentifier(resource);
1428
+ const identifier = this.identifierCache.peekRecordIdentifier(resource);
1720
1429
  const internalModel = identifier && internalModelFactoryFor(this).peek(identifier);
1721
1430
 
1722
1431
  return !!internalModel && internalModel.currentState.isLoaded;
@@ -2646,7 +2355,7 @@ abstract class CoreStore extends Service {
2646
2355
  );
2647
2356
  }
2648
2357
 
2649
- const cache = identifierCacheFor(this);
2358
+ const cache = this.identifierCache;
2650
2359
  const identifier = internalModel.identifier;
2651
2360
 
2652
2361
  if (op !== 'deleteRecord' && data) {
@@ -2734,7 +2443,7 @@ abstract class CoreStore extends Service {
2734
2443
  // exclude store.push (root.empty) case
2735
2444
  let identifier = internalModel.identifier;
2736
2445
  if (isUpdate || isLoading) {
2737
- let updatedIdentifier = identifierCacheFor(this).updateRecordIdentifier(identifier, data);
2446
+ let updatedIdentifier = this.identifierCache.updateRecordIdentifier(identifier, data);
2738
2447
 
2739
2448
  if (updatedIdentifier !== identifier) {
2740
2449
  // we encountered a merge of identifiers in which
@@ -3153,7 +2862,7 @@ abstract class CoreStore extends Service {
3153
2862
  }
3154
2863
 
3155
2864
  relationshipReferenceFor(identifier: RecordIdentifier, key: string): BelongsToReference | HasManyReference {
3156
- let stableIdentifier = identifierCacheFor(this).getOrCreateRecordIdentifier(identifier);
2865
+ let stableIdentifier = this.identifierCache.getOrCreateRecordIdentifier(identifier);
3157
2866
  let internalModel = internalModelFactoryFor(this).peek(stableIdentifier);
3158
2867
  // TODO we used to check if the record was destroyed here
3159
2868
  return internalModel!.referenceFor(null, key);
@@ -3202,7 +2911,7 @@ abstract class CoreStore extends Service {
3202
2911
  _RecordData = require('@ember-data/record-data/-private').RecordData as RecordDataConstruct;
3203
2912
  }
3204
2913
 
3205
- let identifier = identifierCacheFor(this).getOrCreateRecordIdentifier({
2914
+ let identifier = this.identifierCache.getOrCreateRecordIdentifier({
3206
2915
  type: modelName,
3207
2916
  id,
3208
2917
  lid: clientId,
@@ -3217,7 +2926,7 @@ abstract class CoreStore extends Service {
3217
2926
  * @internal
3218
2927
  */
3219
2928
  __recordDataFor(resource: RecordIdentifier) {
3220
- const identifier = identifierCacheFor(this).getOrCreateRecordIdentifier(resource);
2929
+ const identifier = this.identifierCache.getOrCreateRecordIdentifier(resource);
3221
2930
  return this.recordDataFor(identifier, false);
3222
2931
  }
3223
2932
 
@@ -3335,25 +3044,15 @@ abstract class CoreStore extends Service {
3335
3044
 
3336
3045
  let owner = getOwner(this);
3337
3046
 
3047
+ // name specific adapter
3338
3048
  adapter = owner.lookup(`adapter:${normalizedModelName}`);
3339
-
3340
- // in production this is handled by the re-export
3341
- if (DEBUG && HAS_EMBER_DATA_PACKAGE && HAS_ADAPTER_PACKAGE && adapter === undefined) {
3342
- if (normalizedModelName === '-json-api') {
3343
- const Adapter = require('@ember-data/adapter/json-api').default;
3344
- owner.register(`adapter:-json-api`, Adapter);
3345
- adapter = owner.lookup(`adapter:-json-api`);
3346
- deprecateTestRegistration('adapter', '-json-api');
3347
- }
3348
- }
3349
-
3350
3049
  if (adapter !== undefined) {
3351
3050
  set(adapter, 'store', this);
3352
3051
  _adapterCache[normalizedModelName] = adapter;
3353
3052
  return adapter;
3354
3053
  }
3355
3054
 
3356
- // no adapter found for the specific model, fallback and check for application adapter
3055
+ // no adapter found for the specific name, fallback and check for application adapter
3357
3056
  adapter = _adapterCache.application || owner.lookup('adapter:application');
3358
3057
  if (adapter !== undefined) {
3359
3058
  set(adapter, 'store', this);
@@ -3362,30 +3061,9 @@ abstract class CoreStore extends Service {
3362
3061
  return adapter;
3363
3062
  }
3364
3063
 
3365
- // no model specific adapter or application adapter, check for an `adapter`
3366
- // property defined on the store
3367
- let adapterName = this.adapter || '-json-api';
3368
- adapter = adapterName ? _adapterCache[adapterName] || owner.lookup(`adapter:${adapterName}`) : undefined;
3369
-
3370
- // in production this is handled by the re-export
3371
- if (DEBUG && HAS_EMBER_DATA_PACKAGE && HAS_ADAPTER_PACKAGE && adapter === undefined) {
3372
- if (adapterName === '-json-api') {
3373
- const Adapter = require('@ember-data/adapter/json-api').default;
3374
- owner.register(`adapter:-json-api`, Adapter);
3375
- adapter = owner.lookup(`adapter:-json-api`);
3376
- deprecateTestRegistration('adapter', '-json-api');
3377
- }
3378
- }
3379
-
3380
- if (adapter !== undefined) {
3381
- set(adapter, 'store', this);
3382
- _adapterCache[normalizedModelName] = adapter;
3383
- _adapterCache[adapterName] = adapter;
3384
- return adapter;
3385
- }
3386
-
3387
3064
  // final fallback, no model specific adapter, no application adapter, no
3388
3065
  // `adapter` property on store: use json-api adapter
3066
+ // TODO we should likely deprecate this?
3389
3067
  adapter = _adapterCache['-json-api'] || owner.lookup('adapter:-json-api');
3390
3068
  assert(
3391
3069
  `No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`,
@@ -3437,30 +3115,8 @@ abstract class CoreStore extends Service {
3437
3115
 
3438
3116
  let owner = getOwner(this);
3439
3117
 
3118
+ // by name
3440
3119
  serializer = owner.lookup(`serializer:${normalizedModelName}`);
3441
-
3442
- if (DEPRECATE_LEGACY_TEST_REGISTRATIONS) {
3443
- // in production this is handled by the re-export
3444
- if (DEBUG && HAS_EMBER_DATA_PACKAGE && HAS_SERIALIZER_PACKAGE && serializer === undefined) {
3445
- if (normalizedModelName === '-json-api') {
3446
- const Serializer = require('@ember-data/serializer/json-api').default;
3447
- owner.register(`serializer:-json-api`, Serializer);
3448
- serializer = owner.lookup(`serializer:-json-api`);
3449
- deprecateTestRegistration('serializer', '-json-api');
3450
- } else if (normalizedModelName === '-rest') {
3451
- const Serializer = require('@ember-data/serializer/rest').default;
3452
- owner.register(`serializer:-rest`, Serializer);
3453
- serializer = owner.lookup(`serializer:-rest`);
3454
- deprecateTestRegistration('serializer', '-rest');
3455
- } else if (normalizedModelName === '-default') {
3456
- const Serializer = require('@ember-data/serializer/json').default;
3457
- owner.register(`serializer:-default`, Serializer);
3458
- serializer = owner.lookup(`serializer:-default`);
3459
- serializer && deprecateTestRegistration('serializer', '-default');
3460
- }
3461
- }
3462
- }
3463
-
3464
3120
  if (serializer !== undefined) {
3465
3121
  set(serializer, 'store', this);
3466
3122
  _serializerCache[normalizedModelName] = serializer;
@@ -3476,37 +3132,6 @@ abstract class CoreStore extends Service {
3476
3132
  return serializer;
3477
3133
  }
3478
3134
 
3479
- let serializerName;
3480
-
3481
- if (DEPRECATE_LEGACY_TEST_REGISTRATIONS) {
3482
- // in production this is handled by the re-export
3483
- if (DEBUG && HAS_EMBER_DATA_PACKAGE && HAS_SERIALIZER_PACKAGE && serializer === undefined) {
3484
- if (serializerName === '-json-api') {
3485
- const Serializer = require('@ember-data/serializer/json-api').default;
3486
- owner.register(`serializer:-json-api`, Serializer);
3487
- serializer = owner.lookup(`serializer:-json-api`);
3488
- deprecateTestRegistration('serializer', '-json-api');
3489
- } else if (serializerName === '-rest') {
3490
- const Serializer = require('@ember-data/serializer/rest').default;
3491
- owner.register(`serializer:-rest`, Serializer);
3492
- serializer = owner.lookup(`serializer:-rest`);
3493
- deprecateTestRegistration('serializer', '-rest');
3494
- } else if (serializerName === '-default') {
3495
- const Serializer = require('@ember-data/serializer/json').default;
3496
- owner.register(`serializer:-default`, Serializer);
3497
- serializer = owner.lookup(`serializer:-default`);
3498
- serializer && deprecateTestRegistration('serializer', '-default');
3499
- }
3500
- }
3501
-
3502
- if (serializer !== undefined) {
3503
- set(serializer, 'store', this);
3504
- _serializerCache[normalizedModelName] = serializer;
3505
- _serializerCache[serializerName] = serializer;
3506
- return serializer;
3507
- }
3508
- }
3509
-
3510
3135
  assert(
3511
3136
  `No serializer was found for '${modelName}' and no 'application' serializer was found as a fallback`,
3512
3137
  serializer !== undefined
@@ -3544,7 +3169,7 @@ abstract class CoreStore extends Service {
3544
3169
  super.willDestroy();
3545
3170
  this.recordArrayManager.destroy();
3546
3171
 
3547
- identifierCacheFor(this).destroy();
3172
+ this.identifierCache.destroy();
3548
3173
 
3549
3174
  // destroy the graph before unloadAll
3550
3175
  // since then we avoid churning relationships
@@ -3604,39 +3229,6 @@ abstract class CoreStore extends Service {
3604
3229
  }
3605
3230
  }
3606
3231
 
3607
- if (DEPRECATE_DEFAULT_ADAPTER) {
3608
- defineProperty(
3609
- CoreStore.prototype,
3610
- 'defaultAdapter',
3611
- computed('adapter', function () {
3612
- deprecate(
3613
- `store.adapterFor(modelName) resolved the ("${
3614
- this.adapter || '-json-api'
3615
- }") adapter via the deprecated \`store.defaultAdapter\` property.\n\n\tPreviously, applications could define the store's \`adapter\` property which would be used by \`defaultAdapter\` and \`adapterFor\` as a fallback for when an adapter was not found by an exact name match. This behavior is deprecated in favor of explicitly defining an application or type-specific adapter.`,
3616
- false,
3617
- {
3618
- id: 'ember-data:default-adapter',
3619
- until: '4.0',
3620
- url: 'https://deprecations.emberjs.com/ember-data/v3.x/#toc_ember-data-default-adapter',
3621
- for: '@ember-data/store',
3622
- since: {
3623
- available: '3.15',
3624
- enabled: '3.15',
3625
- },
3626
- }
3627
- );
3628
- let adapter = this.adapter || '-json-api';
3629
-
3630
- assert(
3631
- 'You tried to set `adapter` property to an instance of `Adapter`, where it should be a name',
3632
- typeof adapter === 'string'
3633
- );
3634
-
3635
- return this.adapterFor(adapter);
3636
- })
3637
- );
3638
- }
3639
-
3640
3232
  export default CoreStore;
3641
3233
 
3642
3234
  let assertDestroyingStore: Function;
@@ -3644,48 +3236,16 @@ let assertDestroyedStoreOnly: Function;
3644
3236
 
3645
3237
  if (DEBUG) {
3646
3238
  assertDestroyingStore = function assertDestroyedStore(store, method) {
3647
- if (!store.shouldAssertMethodCallsOnDestroyedStore) {
3648
- deprecate(
3649
- `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
3650
- !(store.isDestroying || store.isDestroyed),
3651
- {
3652
- id: 'ember-data:method-calls-on-destroyed-store',
3653
- until: '3.8',
3654
- for: '@ember-data/store',
3655
- since: {
3656
- available: '3.8',
3657
- enabled: '3.8',
3658
- },
3659
- }
3660
- );
3661
- } else {
3662
- assert(
3663
- `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
3664
- !(store.isDestroying || store.isDestroyed)
3665
- );
3666
- }
3239
+ assert(
3240
+ `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
3241
+ !(store.isDestroying || store.isDestroyed)
3242
+ );
3667
3243
  };
3668
3244
  assertDestroyedStoreOnly = function assertDestroyedStoreOnly(store, method) {
3669
- if (!store.shouldAssertMethodCallsOnDestroyedStore) {
3670
- deprecate(
3671
- `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
3672
- !store.isDestroyed,
3673
- {
3674
- id: 'ember-data:method-calls-on-destroyed-store',
3675
- until: '3.8',
3676
- for: '@ember-data/store',
3677
- since: {
3678
- available: '3.8',
3679
- enabled: '3.8',
3680
- },
3681
- }
3682
- );
3683
- } else {
3684
- assert(
3685
- `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
3686
- !store.isDestroyed
3687
- );
3688
- }
3245
+ assert(
3246
+ `Attempted to call store.${method}(), but the store instance has already been destroyed.`,
3247
+ !store.isDestroyed
3248
+ );
3689
3249
  };
3690
3250
  }
3691
3251
 
@@ -3700,7 +3260,7 @@ if (DEBUG) {
3700
3260
  * @return {boolean}
3701
3261
  */
3702
3262
  function areAllInverseRecordsLoaded(store: CoreStore, resource: JsonApiRelationship): boolean {
3703
- const cache = identifierCacheFor(store);
3263
+ const cache = store.identifierCache;
3704
3264
 
3705
3265
  if (Array.isArray(resource.data)) {
3706
3266
  // treat as collection