@ember-data/store 4.0.0 → 4.0.1

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.
@@ -1278,7 +1278,7 @@ abstract class CoreStore extends Service {
1278
1278
  return Promise.resolve(internalModel);
1279
1279
  }
1280
1280
 
1281
- _findByInternalModel(internalModel, options: { preload?: any } = {}) {
1281
+ _findByInternalModel(internalModel: InternalModel, options: FindOptions = {}) {
1282
1282
  if (options.preload) {
1283
1283
  this._backburner.join(() => {
1284
1284
  internalModel.preloadData(options.preload);
@@ -1293,7 +1293,7 @@ abstract class CoreStore extends Service {
1293
1293
  );
1294
1294
  }
1295
1295
 
1296
- _findEmptyInternalModel(internalModel, options) {
1296
+ _findEmptyInternalModel(internalModel: InternalModel, options: FindOptions) {
1297
1297
  if (internalModel.currentState.isEmpty) {
1298
1298
  return this._scheduleFetch(internalModel, options);
1299
1299
  }
@@ -1305,9 +1305,9 @@ abstract class CoreStore extends Service {
1305
1305
  }
1306
1306
  } else {
1307
1307
  if (internalModel.currentState.isLoading) {
1308
- let pending = this._fetchManager.getPendingFetch(internalModel.identifier);
1309
- if (pending) {
1310
- return pending.then(() => Promise.resolve(internalModel));
1308
+ let pendingRequest = this._fetchManager.getPendingFetch(internalModel.identifier, options);
1309
+ if (pendingRequest) {
1310
+ return pendingRequest.then(() => Promise.resolve(internalModel));
1311
1311
  }
1312
1312
  return this._scheduleFetch(internalModel, options);
1313
1313
  }
@@ -2049,7 +2049,7 @@ abstract class CoreStore extends Service {
2049
2049
  if (internalModel) {
2050
2050
  // short circuit if we are already loading
2051
2051
  if (REQUEST_SERVICE) {
2052
- let pendingRequest = this._fetchManager.getPendingFetch(internalModel.identifier);
2052
+ let pendingRequest = this._fetchManager.getPendingFetch(internalModel.identifier, options);
2053
2053
  if (pendingRequest) {
2054
2054
  return pendingRequest.then(() => internalModel.getRecord());
2055
2055
  }
@@ -2081,6 +2081,10 @@ abstract class CoreStore extends Service {
2081
2081
  return resolve(null);
2082
2082
  }
2083
2083
 
2084
+ if (!internalModel) {
2085
+ assert(`No InternalModel found for ${resource.lid}`, internalModel);
2086
+ }
2087
+
2084
2088
  return this._findByInternalModel(internalModel, options);
2085
2089
  }
2086
2090
 
@@ -501,10 +501,10 @@ export default class FetchManager {
501
501
  }
502
502
  }
503
503
 
504
- getPendingFetch(identifier: StableRecordIdentifier) {
505
- let pendingRequests = this.requestCache
506
- .getPendingRequestsForRecord(identifier)
507
- .filter((req) => req.type === 'query');
504
+ getPendingFetch(identifier: StableRecordIdentifier, options) {
505
+ let pendingRequests = this.requestCache.getPendingRequestsForRecord(identifier).filter((req) => {
506
+ return req.type === 'query' && isSameRequest(options, req.request.data[0].options);
507
+ });
508
508
 
509
509
  if (pendingRequests.length > 0) {
510
510
  return pendingRequests[0][RequestPromise];
@@ -532,3 +532,8 @@ function assertIsString(id: string | null): asserts id is string {
532
532
  }
533
533
  }
534
534
  }
535
+
536
+ // this function helps resolve whether we have a pending request that we should use instead
537
+ function isSameRequest(options: Dict<unknown> = {}, reqOptions: Dict<unknown> = {}) {
538
+ return options.include === reqOptions.include;
539
+ }
@@ -1,7 +1,11 @@
1
+ import type { Dict } from '@ember-data/store/-private/ts-interfaces/utils';
2
+
1
3
  import type { RecordIdentifier } from './identifier';
2
4
 
3
5
  export interface Operation {
4
6
  op: string;
7
+ options: Dict<unknown> | undefined;
8
+ recordIdentifier: RecordIdentifier;
5
9
  }
6
10
 
7
11
  export interface FindRecordQuery extends Operation {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/store",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "The default blueprint for ember-cli addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -17,8 +17,8 @@
17
17
  "start": "ember serve"
18
18
  },
19
19
  "dependencies": {
20
- "@ember-data/canary-features": "4.0.0",
21
- "@ember-data/private-build-infra": "4.0.0",
20
+ "@ember-data/canary-features": "4.0.1",
21
+ "@ember-data/private-build-infra": "4.0.1",
22
22
  "@ember/string": "^3.0.0",
23
23
  "@glimmer/tracking": "^1.0.4",
24
24
  "ember-auto-import": "^2.2.4",
@@ -27,7 +27,7 @@
27
27
  "ember-cli-typescript": "^4.1.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@ember-data/unpublished-test-infra": "4.0.0",
30
+ "@ember-data/unpublished-test-infra": "4.0.1",
31
31
  "@ember/optional-features": "^2.0.0",
32
32
  "@ember/test-helpers": "^2.6.0",
33
33
  "@types/ember": "^3.16.5",