@ember-data/store 4.0.0-beta.4 → 4.0.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.
@@ -22,7 +22,6 @@ import type {
22
22
  import { DEBUG_CLIENT_ORIGINATED, DEBUG_IDENTIFIER_BUCKET } from '../ts-interfaces/identifier';
23
23
  import type { ConfidentDict } from '../ts-interfaces/utils';
24
24
  import isNonEmptyString from '../utils/is-non-empty-string';
25
- import { addSymbol } from '../utils/symbol';
26
25
  import isStableIdentifier, { markStableIdentifier, unmarkStableIdentifier } from './is-stable-identifier';
27
26
  import uuidv4 from './utils/uuid-v4';
28
27
 
@@ -510,8 +509,8 @@ function makeStableRecordIdentifier(
510
509
  return `${clientOriginated ? '[CLIENT_ORIGINATED] ' : ''}${type}:${id} (${lid})`;
511
510
  },
512
511
  };
513
- addSymbol(wrapper, DEBUG_CLIENT_ORIGINATED, clientOriginated);
514
- addSymbol(wrapper, DEBUG_IDENTIFIER_BUCKET, bucket);
512
+ wrapper[DEBUG_CLIENT_ORIGINATED] = clientOriginated;
513
+ wrapper[DEBUG_IDENTIFIER_BUCKET] = bucket;
515
514
  wrapper = freeze(wrapper);
516
515
  markStableIdentifier(wrapper);
517
516
  DEBUG_MAP.set(wrapper, recordIdentifier);
@@ -2,13 +2,6 @@
2
2
  @module @ember-data/store
3
3
  */
4
4
 
5
- // support IE11
6
- declare global {
7
- interface Window {
8
- msCrypto: Crypto;
9
- }
10
- }
11
-
12
5
  const CRYPTO = (() => {
13
6
  const hasWindow = typeof window !== 'undefined';
14
7
  const isFastBoot = typeof FastBoot !== 'undefined';
@@ -27,12 +20,6 @@ const CRYPTO = (() => {
27
20
  };
28
21
  } else if (hasWindow && typeof window.crypto !== 'undefined') {
29
22
  return window.crypto;
30
- } else if (
31
- hasWindow &&
32
- typeof window.msCrypto !== 'undefined' &&
33
- typeof window.msCrypto.getRandomValues === 'function'
34
- ) {
35
- return window.msCrypto;
36
23
  } else {
37
24
  throw new Error('ember-data: Cannot find a valid way to generate local identifiers');
38
25
  }
@@ -25,7 +25,6 @@ export { default as RootState } from './system/model/states';
25
25
  export { default as InternalModel } from './system/model/internal-model';
26
26
 
27
27
  export { PromiseArray, PromiseObject } from './system/promise-proxies';
28
- export { addSymbol, symbol } from './utils/symbol';
29
28
 
30
29
  export { RecordArray, AdapterPopulatedRecordArray } from './system/record-arrays';
31
30
 
@@ -67,7 +67,6 @@ import type { FindOptions } from '../ts-interfaces/store';
67
67
  import type { Dict } from '../ts-interfaces/utils';
68
68
  import constructResource from '../utils/construct-resource';
69
69
  import promiseRecord from '../utils/promise-record';
70
- import { addSymbol } from '../utils/symbol';
71
70
  import edBackburner from './backburner';
72
71
  import coerceId, { ensureStringId } from './coerce-id';
73
72
  import { errorsArrayToHash } from './errors-utils';
@@ -1600,18 +1599,14 @@ abstract class CoreStore extends Service {
1600
1599
  groups = [snapshots];
1601
1600
  }
1602
1601
 
1603
- // we use var here because babel transpiles let
1604
- // in a manner that causes a mega-bad perf scenario here
1605
- // when targets no longer include IE11 we can drop this.
1606
- /* eslint-disable no-var */
1607
- for (var i = 0, l = groups.length; i < l; i++) {
1608
- var group = groups[i];
1609
- var totalInGroup = groups[i].length;
1610
- var ids = new Array(totalInGroup);
1611
- var groupedInternalModels = new Array(totalInGroup);
1602
+ for (let i = 0, l = groups.length; i < l; i++) {
1603
+ let group = groups[i];
1604
+ let totalInGroup = groups[i].length;
1605
+ let ids = new Array(totalInGroup);
1606
+ let groupedInternalModels = new Array(totalInGroup);
1612
1607
 
1613
- for (var j = 0; j < totalInGroup; j++) {
1614
- var internalModel = group[j]._internalModel;
1608
+ for (let j = 0; j < totalInGroup; j++) {
1609
+ let internalModel = group[j]._internalModel;
1615
1610
 
1616
1611
  groupedInternalModels[j] = internalModel;
1617
1612
  ids[j] = internalModel.id;
@@ -1628,7 +1623,7 @@ abstract class CoreStore extends Service {
1628
1623
  });
1629
1624
  })(groupedInternalModels);
1630
1625
  } else if (ids.length === 1) {
1631
- var pair = seeking[groupedInternalModels[0].id];
1626
+ let pair = seeking[groupedInternalModels[0].id];
1632
1627
  _fetchRecord(pair);
1633
1628
  } else {
1634
1629
  assert("You cannot return an empty array from adapter's method groupRecordsForFindMany");
@@ -2713,7 +2708,7 @@ abstract class CoreStore extends Service {
2713
2708
  operation = 'deleteRecord';
2714
2709
  }
2715
2710
 
2716
- addSymbol(options, SaveOp, operation);
2711
+ options[SaveOp] = operation;
2717
2712
 
2718
2713
  let fetchManagerPromise = this._fetchManager.scheduleSave(internalModel.identifier, options);
2719
2714
  let promise = fetchManagerPromise.then(
@@ -12,7 +12,6 @@ import type { CollectionResourceDocument, SingleResourceDocument } from '../ts-i
12
12
  import type { FindRecordQuery, Request, SaveRecordMutation } from '../ts-interfaces/fetch-manager';
13
13
  import type { ExistingRecordIdentifier, RecordIdentifier, StableRecordIdentifier } from '../ts-interfaces/identifier';
14
14
  import type { Dict } from '../ts-interfaces/utils';
15
- import { symbol } from '../utils/symbol';
16
15
  import coerceId from './coerce-id';
17
16
  import type CoreStore from './core-store';
18
17
  import { errorsArrayToHash } from './errors-utils';
@@ -30,7 +29,7 @@ function payloadIsNotBlank(adapterPayload): boolean {
30
29
  }
31
30
  }
32
31
 
33
- export const SaveOp: unique symbol = symbol('SaveOp');
32
+ export const SaveOp: unique symbol = Symbol('SaveOp');
34
33
 
35
34
  interface PendingFetchItem {
36
35
  identifier: ExistingRecordIdentifier;
@@ -1455,15 +1455,11 @@ export function extractRecordDataFromRecord(recordOrPromiseRecord) {
1455
1455
  }
1456
1456
 
1457
1457
  function anyUnloaded(store: CoreStore, relationship: ManyRelationship) {
1458
- // Can't use `find` because of IE11 and these arrays are potentially massive
1459
1458
  let state = relationship.currentState;
1460
- let unloaded = false;
1461
- for (let i = 0; i < state.length; i++) {
1462
- let im = store._internalModelForResource(state[i]);
1463
- if (im._isDematerializing || !im.currentState.isLoaded) {
1464
- unloaded = true;
1465
- break;
1466
- }
1467
- }
1468
- return unloaded;
1459
+ const unloaded = state.find((s) => {
1460
+ let im = store._internalModelForResource(s);
1461
+ return im._isDematerializing || !im.currentState.isLoaded;
1462
+ });
1463
+
1464
+ return unloaded || false;
1469
1465
  }
@@ -7,10 +7,9 @@ import type {
7
7
  } from '../ts-interfaces/fetch-manager';
8
8
  import { RequestStateEnum } from '../ts-interfaces/fetch-manager';
9
9
  import type { RecordIdentifier } from '../ts-interfaces/identifier';
10
- import { addSymbol, symbol } from '../utils/symbol';
11
10
 
12
- const Touching: unique symbol = symbol('touching');
13
- export const RequestPromise: unique symbol = symbol('promise');
11
+ const Touching: unique symbol = Symbol('touching');
12
+ export const RequestPromise: unique symbol = Symbol('promise');
14
13
 
15
14
  interface InternalRequest extends RequestState {
16
15
  [Touching]: RecordIdentifier[];
@@ -41,8 +40,8 @@ export default class RequestCache {
41
40
  request: queryRequest,
42
41
  type,
43
42
  } as InternalRequest;
44
- addSymbol(request, Touching, [query.recordIdentifier]);
45
- addSymbol(request, RequestPromise, promise);
43
+ request[Touching] = [query.recordIdentifier];
44
+ request[RequestPromise] = promise;
46
45
  this._pending[lid].push(request);
47
46
  this._triggerSubscriptions(request);
48
47
  promise.then(
@@ -54,7 +53,7 @@ export default class RequestCache {
54
53
  type,
55
54
  response: { data: result },
56
55
  } as InternalRequest;
57
- addSymbol(finalizedRequest, Touching, request[Touching]);
56
+ finalizedRequest[Touching] = request[Touching];
58
57
  this._addDone(finalizedRequest);
59
58
  this._triggerSubscriptions(finalizedRequest);
60
59
  },
@@ -66,7 +65,7 @@ export default class RequestCache {
66
65
  type,
67
66
  response: { data: error && error.error },
68
67
  } as InternalRequest;
69
- addSymbol(finalizedRequest, Touching, request[Touching]);
68
+ finalizedRequest[Touching] = request[Touching];
70
69
  this._addDone(finalizedRequest);
71
70
  this._triggerSubscriptions(finalizedRequest);
72
71
  }
@@ -273,18 +273,12 @@ function fixRelationshipData(relationshipData, relationshipKind, { id, modelName
273
273
  if (relationshipKind === 'hasMany') {
274
274
  payload = relationshipData || [];
275
275
  if (relationshipData) {
276
- // IE11 does not support array.find
277
276
  // these arrays could be massive so this is better than filter
278
277
  // Note: this is potentially problematic if type/id are not in the
279
278
  // same state of normalization.
280
- let found = false;
281
- for (let i = 0; i < relationshipData.length; i++) {
282
- let v = relationshipData[i];
283
- if (v.type === parentRelationshipData.type && v.id === parentRelationshipData.id) {
284
- found = true;
285
- break;
286
- }
287
- }
279
+ let found = relationshipData.find((v) => {
280
+ return v.type === parentRelationshipData.type && v.id === parentRelationshipData.id;
281
+ });
288
282
  if (!found) {
289
283
  payload.push(parentRelationshipData);
290
284
  }
@@ -1,15 +1,14 @@
1
1
  /**
2
2
  @module @ember-data/store
3
3
  */
4
- import { symbol } from '../utils/symbol';
5
4
  import type { ExistingResourceObject, ResourceIdentifierObject } from './ember-data-json-api';
6
5
 
7
6
  export type ResourceData = ResourceIdentifierObject | ExistingResourceObject;
8
7
  export type IdentifierBucket = 'record';
9
8
 
10
9
  // provided for additional debuggability
11
- export const DEBUG_CLIENT_ORIGINATED: unique symbol = symbol('record-originated-on-client');
12
- export const DEBUG_IDENTIFIER_BUCKET: unique symbol = symbol('identifier-bucket');
10
+ export const DEBUG_CLIENT_ORIGINATED: unique symbol = Symbol('record-originated-on-client');
11
+ export const DEBUG_IDENTIFIER_BUCKET: unique symbol = Symbol('identifier-bucket');
13
12
 
14
13
  export interface Identifier {
15
14
  lid: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/store",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.0",
4
4
  "description": "The default blueprint for ember-cli addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -17,22 +17,22 @@
17
17
  "start": "ember serve"
18
18
  },
19
19
  "dependencies": {
20
- "@ember-data/canary-features": "4.0.0-beta.4",
21
- "@ember-data/private-build-infra": "4.0.0-beta.4",
20
+ "@ember-data/canary-features": "4.0.0",
21
+ "@ember-data/private-build-infra": "4.0.0",
22
22
  "@ember/string": "^3.0.0",
23
23
  "@glimmer/tracking": "^1.0.4",
24
+ "ember-auto-import": "^2.2.4",
24
25
  "ember-cli-babel": "^7.26.6",
25
26
  "ember-cli-path-utils": "^1.0.0",
26
27
  "ember-cli-typescript": "^4.1.0"
27
28
  },
28
29
  "devDependencies": {
29
- "@ember-data/unpublished-test-infra": "4.0.0-beta.4",
30
+ "@ember-data/unpublished-test-infra": "4.0.0",
30
31
  "@ember/optional-features": "^2.0.0",
31
- "@ember/test-helpers": "^2.2.5",
32
+ "@ember/test-helpers": "^2.6.0",
32
33
  "@types/ember": "^3.16.5",
33
34
  "@types/rsvp": "^4.0.3",
34
35
  "broccoli-asset-rev": "^3.0.0",
35
- "ember-auto-import": "^2.0.0",
36
36
  "ember-cli": "~3.26.1",
37
37
  "ember-cli-dependency-checker": "^3.2.0",
38
38
  "ember-cli-htmlbars": "^5.1.2",
@@ -43,9 +43,9 @@
43
43
  "ember-export-application-global": "^2.0.1",
44
44
  "ember-load-initializers": "^2.1.1",
45
45
  "ember-maybe-import-regenerator": "^0.1.6",
46
- "ember-qunit": "^5.1.4",
46
+ "ember-qunit": "^5.1.5",
47
47
  "ember-resolver": "^8.0.0",
48
- "ember-source": "~3.27.1",
48
+ "ember-source": "~4.0.0",
49
49
  "ember-source-channel-url": "^3.0.0",
50
50
  "ember-try": "^1.4.0",
51
51
  "loader.js": "^4.7.0",
@@ -1,33 +0,0 @@
1
- /**
2
- @module @ember-data/store
3
- */
4
-
5
- /**
6
- * This symbol provides a Symbol replacement for browsers that do not have it
7
- * (eg. IE 11).
8
- *
9
- * The replacement is different from the native Symbol in some ways. It is a
10
- * function that produces an output:
11
- * - iterable;
12
- * - that is a string, not a symbol.
13
- *
14
- * @internal
15
- */
16
- export const symbol =
17
- typeof Symbol !== 'undefined'
18
- ? Symbol
19
- : (key: string) => `__${key}${Math.floor(Math.random() * Date.now())}__` as any;
20
-
21
- export function addSymbol(obj: object, symbol: Symbol | string, value: any): void {
22
- if (typeof symbol === 'string') {
23
- Object.defineProperty(obj, symbol, {
24
- value,
25
- configurable: false,
26
- enumerable: false,
27
- writable: false,
28
- });
29
- } else {
30
- // Typescript doesn't allow Symbol as an index type
31
- obj[symbol as unknown as string] = value;
32
- }
33
- }