@ember-data/store 4.12.0-beta.0 → 4.12.0-beta.2

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/addon/-private.js CHANGED
@@ -1 +1 @@
1
- export { C as AdapterPopulatedRecordArray, h as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, a as Snapshot, k as SnapshotRecordArray, S as Store, f as coerceId, j as fastPush, i as isStableIdentifier, n as normalizeModelName, l as recordDataFor, r as recordIdentifierFor, m as removeRecordDataFor, d as setIdentifierForgetMethod, b as setIdentifierGenerationMethod, e as setIdentifierResetMethod, c as setIdentifierUpdateMethod, s as storeFor } from "./index-12e1fcb9";
1
+ export { C as AdapterPopulatedRecordArray, j as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, h as SOURCE, a as Snapshot, l as SnapshotRecordArray, S as Store, f as coerceId, k as fastPush, i as isStableIdentifier, n as normalizeModelName, g as notifyArray, m as recordDataFor, r as recordIdentifierFor, o as removeRecordDataFor, d as setIdentifierForgetMethod, b as setIdentifierGenerationMethod, e as setIdentifierResetMethod, c as setIdentifierUpdateMethod, s as storeFor } from "./index-6511184b";
@@ -1,4 +1,4 @@
1
- import { macroCondition, getOwnConfig, isDevelopingApp, moduleExists, importSync } from '@embroider/macros';
1
+ import { macroCondition, getOwnConfig, isDevelopingApp, dependencySatisfies, importSync } from '@embroider/macros';
2
2
  import { assert, warn, deprecate } from '@ember/debug';
3
3
  import { dasherize } from '@ember/string';
4
4
  import { getOwner, setOwner } from '@ember/application';
@@ -6,10 +6,12 @@ import { _backburner } from '@ember/runloop';
6
6
  import { registerWaiter, unregisterWaiter } from '@ember/test';
7
7
  import RSVP, { resolve, Promise as Promise$1, reject } from 'rsvp';
8
8
  import { tracked } from '@glimmer/tracking';
9
- import { subscribe, addToTransaction } from '@ember-data/tracking/-private';
9
+ import { subscribe, addToTransaction, addTransactionCB } from '@ember-data/tracking/-private';
10
+ import { tagForProperty } from '@ember/-internals/metal';
10
11
  import { get, set } from '@ember/object';
11
12
  import { dependentKeyCompat } from '@ember/object/compat';
12
13
  import { compare } from '@ember/utils';
14
+ import { dirtyTag } from '@glimmer/validator';
13
15
  import Ember from 'ember';
14
16
  import { reads } from '@ember/object/computed';
15
17
  import ArrayProxy from '@ember/array/proxy';
@@ -2433,7 +2435,7 @@ class Snapshot {
2433
2435
  // function without access to intimate API contracts between RecordData and Model.
2434
2436
  // This is a requirement we should fix as soon as the relationship layer does not require
2435
2437
  // this intimate API usage.
2436
- if (!moduleExists("@ember-data/json-api")) {
2438
+ if (macroCondition(!dependencySatisfies("@ember-data/json-api", "*"))) {
2437
2439
  assert(`snapshot.belongsTo only supported when using the package @ember-data/json-api`);
2438
2440
  }
2439
2441
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
@@ -2510,7 +2512,7 @@ class Snapshot {
2510
2512
  // function without access to intimate API contracts between RecordData and Model.
2511
2513
  // This is a requirement we should fix as soon as the relationship layer does not require
2512
2514
  // this intimate API usage.
2513
- if (!moduleExists("@ember-data/json-api")) {
2515
+ if (macroCondition(!dependencySatisfies("@ember-data/json-api", "*"))) {
2514
2516
  assert(`snapshot.hasMany only supported when using the package @ember-data/json-api`);
2515
2517
  }
2516
2518
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
@@ -2654,7 +2656,7 @@ function recordDataFor(instance) {
2654
2656
  return null;
2655
2657
  }
2656
2658
  let _peekGraph;
2657
- if (moduleExists("@ember-data/graph")) {
2659
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
2658
2660
  let __peekGraph;
2659
2661
  _peekGraph = wrapper => {
2660
2662
  let a = importSync('@ember-data/graph/-private').peekGraph;
@@ -2766,7 +2768,7 @@ class InstanceCache {
2766
2768
  record: staleIdentifier,
2767
2769
  value: keptIdentifier
2768
2770
  });
2769
- } else if (moduleExists("@ember-data/json-api")) {
2771
+ } else if (macroCondition(dependencySatisfies("@ember-data/json-api", "*"))) {
2770
2772
  // TODO notify cache always, this requires it always being a singleton
2771
2773
  // and not ever specific to one record-data
2772
2774
  this.store.__private_singleton_recordData?.sync({
@@ -2910,7 +2912,7 @@ class InstanceCache {
2910
2912
  disconnect(identifier) {
2911
2913
  const record = this.__instances.record.get(identifier);
2912
2914
  assert('Cannot destroy record while it is still materialized', !record || record.isDestroyed || record.isDestroying);
2913
- if (moduleExists("@ember-data/graph")) {
2915
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
2914
2916
  let graph = _peekGraph(this.store);
2915
2917
  if (graph) {
2916
2918
  graph.remove(identifier);
@@ -3180,7 +3182,7 @@ function _isLoading(cache, identifier) {
3180
3182
  req.getPendingRequestsForRecord(identifier).some(req => req.type === 'query');
3181
3183
  }
3182
3184
  let _modelForMixin;
3183
- if (moduleExists("@ember-data/model")) {
3185
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
3184
3186
  let _found;
3185
3187
  _modelForMixin = function () {
3186
3188
  if (!_found) {
@@ -3268,9 +3270,11 @@ function getModelFactory(store, cache, normalizedModelName) {
3268
3270
  if (!factory) {
3269
3271
  let owner = getOwner(store);
3270
3272
  factory = owner.factoryFor(`model:${normalizedModelName}`);
3271
- if (!factory && moduleExists("@ember-data/model")) {
3272
- //Support looking up mixins as base types for polymorphic relationships
3273
- factory = _modelForMixin(store, normalizedModelName);
3273
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
3274
+ if (!factory) {
3275
+ //Support looking up mixins as base types for polymorphic relationships
3276
+ factory = _modelForMixin(store, normalizedModelName);
3277
+ }
3274
3278
  }
3275
3279
  if (!factory) {
3276
3280
  // we don't cache misses in case someone wants to register a missing model
@@ -3533,6 +3537,16 @@ function isArraySetter(prop) {
3533
3537
  const IDENTIFIER_ARRAY_TAG = Symbol('#tag');
3534
3538
  const SOURCE = Symbol('#source');
3535
3539
  const MUTATE = Symbol('#update');
3540
+ const NOTIFY = Symbol('#notify');
3541
+ function notifyArray(arr) {
3542
+ arr[IDENTIFIER_ARRAY_TAG].ref = null;
3543
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
3544
+ // eslint-disable-next-line
3545
+ dirtyTag(tagForProperty(arr, 'length'));
3546
+ // eslint-disable-next-line
3547
+ dirtyTag(tagForProperty(arr, '[]'));
3548
+ }
3549
+ }
3536
3550
  function convertToInt(prop) {
3537
3551
  if (typeof prop === 'symbol') return null;
3538
3552
  const num = Number(prop);
@@ -3611,12 +3625,15 @@ let IdentifierArray = (_class3 = class IdentifierArray {
3611
3625
  @type Boolean
3612
3626
  */
3613
3627
 
3628
+ [NOTIFY]() {
3629
+ notifyArray(this);
3630
+ }
3614
3631
  destroy() {
3615
3632
  this.isDestroying = true;
3616
3633
  // changing the reference breaks the Proxy
3617
3634
  // this[SOURCE] = [];
3618
3635
  this[SOURCE].length = 0;
3619
- this[IDENTIFIER_ARRAY_TAG].ref = null;
3636
+ this[NOTIFY]();
3620
3637
  this.isDestroyed = true;
3621
3638
  }
3622
3639
 
@@ -3627,6 +3644,14 @@ let IdentifierArray = (_class3 = class IdentifierArray {
3627
3644
  set length(value) {
3628
3645
  this[SOURCE].length = value;
3629
3646
  }
3647
+
3648
+ // here to support computed chains
3649
+ // and {{#each}}
3650
+ get '[]'() {
3651
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
3652
+ return this;
3653
+ }
3654
+ }
3630
3655
  constructor(options) {
3631
3656
  _initializerDefineProperty(this, "isUpdating", _descriptor2, this);
3632
3657
  this.isLoaded = true;
@@ -3732,6 +3757,9 @@ let IdentifierArray = (_class3 = class IdentifierArray {
3732
3757
  return receiver[receiver.length - 1];
3733
3758
  }
3734
3759
  }
3760
+ if (prop === NOTIFY || prop === IDENTIFIER_ARRAY_TAG || prop === SOURCE) {
3761
+ return self[prop];
3762
+ }
3735
3763
  let fn = boundFns.get(prop);
3736
3764
  if (fn) return fn;
3737
3765
  let outcome = self[prop];
@@ -3828,6 +3856,7 @@ let IdentifierArray = (_class3 = class IdentifierArray {
3828
3856
  assert(`Do not call A() on EmberData RecordArrays`);
3829
3857
  };
3830
3858
  }
3859
+ this[NOTIFY] = this[NOTIFY].bind(proxy);
3831
3860
  return proxy;
3832
3861
  }
3833
3862
 
@@ -3956,7 +3985,7 @@ class Collection extends IdentifierArray {
3956
3985
  Collection.prototype.query = null;
3957
3986
 
3958
3987
  // Ensure instanceof works correctly
3959
- // Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
3988
+ //Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
3960
3989
 
3961
3990
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_ARRAY_LIKE)) {
3962
3991
  IdentifierArray.prototype.DEPRECATED_CLASS_NAME = 'RecordArray';
@@ -4178,28 +4207,22 @@ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_ARRAY_LIKE)) {
4178
4207
  IdentifierArray.prototype.arrayContentDidChange = function () {
4179
4208
  deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'arrayContentDidChange', 'derived state or reacting at the change source.');
4180
4209
  };
4181
-
4182
- // @ts-expect-error
4183
- IdentifierArray.prototype.reject = function (key, value) {
4210
+ IdentifierArray.prototype.reject = function (callback, target) {
4184
4211
  deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'reject', 'filter');
4185
- if (arguments.length === 2) {
4186
- return this.filter(value => {
4187
- return !get(value, key);
4188
- });
4189
- }
4190
- return this.filter(value => {
4191
- return !get(value, key);
4212
+ assert('`reject` expects a function as first argument.', typeof callback === 'function');
4213
+ return this.filter((...args) => {
4214
+ return !callback.apply(target, args);
4192
4215
  });
4193
4216
  };
4194
4217
  IdentifierArray.prototype.rejectBy = function (key, value) {
4195
4218
  deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'rejectBy', 'filter');
4196
4219
  if (arguments.length === 2) {
4197
- return this.filter(value => {
4198
- return !get(value, key);
4220
+ return this.filter(record => {
4221
+ return get(record, key) !== value;
4199
4222
  });
4200
4223
  }
4201
- return this.filter(value => {
4202
- return !get(value, key);
4224
+ return this.filter(record => {
4225
+ return !get(record, key);
4203
4226
  });
4204
4227
  };
4205
4228
  IdentifierArray.prototype.setEach = function (key, value) {
@@ -4407,9 +4430,9 @@ class RecordArrayManager {
4407
4430
  let tag = array[IDENTIFIER_ARRAY_TAG];
4408
4431
  if (!tag.shouldReset) {
4409
4432
  tag.shouldReset = true;
4410
- addToTransaction(tag);
4411
- } else if (delta > 0 && tag.t) {
4412
- addToTransaction(tag);
4433
+ addTransactionCB(array[NOTIFY]);
4434
+ } else if (delta > 0 && !tag.t) {
4435
+ addTransactionCB(array[NOTIFY]);
4413
4436
  }
4414
4437
  }
4415
4438
  _getPendingFor(identifier, includeManaged, isRemove) {
@@ -4466,7 +4489,7 @@ class RecordArrayManager {
4466
4489
  const old = source.slice();
4467
4490
  source.length = 0;
4468
4491
  fastPush(source, identifiers);
4469
- array[IDENTIFIER_ARRAY_TAG].ref = null;
4492
+ notifyArray(array);
4470
4493
  array.meta = payload.meta || null;
4471
4494
  array.links = payload.links || null;
4472
4495
  array.isLoaded = true;
@@ -4950,12 +4973,14 @@ class FetchManager {
4950
4973
  });
4951
4974
  if (!recordData || recordData.isEmpty(identifier) || isLoading) {
4952
4975
  let isReleasable = true;
4953
- if (!recordData && moduleExists("@ember-data/graph")) {
4954
- const graphFor = importSync('@ember-data/graph/-private').graphFor;
4955
- const graph = graphFor(store);
4956
- isReleasable = graph.isReleasable(identifier);
4957
- if (!isReleasable) {
4958
- graph.unload(identifier, true);
4976
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
4977
+ if (!recordData) {
4978
+ const graphFor = importSync('@ember-data/graph/-private').graphFor;
4979
+ const graph = graphFor(store);
4980
+ isReleasable = graph.isReleasable(identifier);
4981
+ if (!isReleasable) {
4982
+ graph.unload(identifier, true);
4983
+ }
4959
4984
  }
4960
4985
  }
4961
4986
  if (recordData || isReleasable) {
@@ -5642,7 +5667,7 @@ class Store {
5642
5667
  * @public
5643
5668
  */
5644
5669
  instantiateRecord(identifier, createRecordArgs, recordDataFor, notificationManager) {
5645
- if (moduleExists("@ember-data/model")) {
5670
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5646
5671
  let modelName = identifier.type;
5647
5672
  let recordData = this._instanceCache.getRecordData(identifier);
5648
5673
  // TODO deprecate allowing unknown args setting
@@ -5675,7 +5700,7 @@ class Store {
5675
5700
  * @param record
5676
5701
  */
5677
5702
  teardownRecord(record) {
5678
- if (moduleExists("@ember-data/model")) {
5703
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5679
5704
  assert(`expected to receive an instance of DSModel. If using a custom model make sure you implement teardownRecord`, 'destroy' in record);
5680
5705
  record.destroy();
5681
5706
  } else {
@@ -5694,10 +5719,12 @@ class Store {
5694
5719
  * @public
5695
5720
  */
5696
5721
  getSchemaDefinitionService() {
5697
- if (moduleExists("@ember-data/model") && !this._schemaDefinitionService) {
5698
- // it is potentially a mistake for the RFC to have not enabled chaining these services, though highlander rule is nice.
5699
- // what ember-m3 did via private API to allow both worlds to interop would be much much harder using this.
5700
- this._schemaDefinitionService = new DSModelSchemaDefinitionService(this);
5722
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5723
+ if (!this._schemaDefinitionService) {
5724
+ // it is potentially a mistake for the RFC to have not enabled chaining these services, though highlander rule is nice.
5725
+ // what ember-m3 did via private API to allow both worlds to interop would be much much harder using this.
5726
+ this._schemaDefinitionService = new DSModelSchemaDefinitionService(this);
5727
+ }
5701
5728
  }
5702
5729
  assert(`You must registerSchemaDefinitionService with the store to use custom model classes`, this._schemaDefinitionService);
5703
5730
  return this._schemaDefinitionService;
@@ -5784,7 +5811,7 @@ class Store {
5784
5811
  }
5785
5812
  assert(`You need to pass a model name to the store's modelFor method`, modelName);
5786
5813
  assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
5787
- if (moduleExists("@ember-data/model")) {
5814
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5788
5815
  let normalizedModelName = normalizeModelName$1(modelName);
5789
5816
  let maybeFactory = getModelFactory(this, this._modelFactoryCache, normalizedModelName);
5790
5817
 
@@ -6868,7 +6895,7 @@ class Store {
6868
6895
  // destroy the graph before unloadAll
6869
6896
  // since then we avoid churning relationships
6870
6897
  // during unload
6871
- if (moduleExists("@ember-data/graph")) {
6898
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
6872
6899
  const peekGraph = importSync('@ember-data/graph/-private').peekGraph;
6873
6900
  let graph = peekGraph(this);
6874
6901
  if (graph) {
@@ -7266,7 +7293,7 @@ class Store {
7266
7293
  * @param storeWrapper
7267
7294
  */
7268
7295
  createRecordDataFor(identifier, storeWrapper) {
7269
- if (moduleExists("@ember-data/json-api")) {
7296
+ if (macroCondition(dependencySatisfies("@ember-data/json-api", "*"))) {
7270
7297
  // we can't greedily use require as this causes
7271
7298
  // a cycle we can't easily fix (or clearly pin point) at present.
7272
7299
  //
@@ -7461,7 +7488,7 @@ class Store {
7461
7488
  serializer.destroy();
7462
7489
  }
7463
7490
  }
7464
- if (moduleExists("@ember-data/graph")) {
7491
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
7465
7492
  const peekGraph = importSync('@ember-data/graph/-private').peekGraph;
7466
7493
  let graph = peekGraph(this);
7467
7494
  if (graph) {
@@ -7499,7 +7526,10 @@ function isMaybeIdentifier(maybeIdentifier) {
7499
7526
  return Boolean(maybeIdentifier !== null && typeof maybeIdentifier === 'object' && ('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type || maybeIdentifier.lid));
7500
7527
  }
7501
7528
  function isDSModel(record) {
7502
- return moduleExists("@ember-data/model") && !!record && 'constructor' in record && 'isModel' in record.constructor && record.constructor.isModel === true;
7529
+ if (macroCondition(!dependencySatisfies("@ember-data/model", "*"))) {
7530
+ return false;
7531
+ }
7532
+ return !!record && 'constructor' in record && 'isModel' in record.constructor && record.constructor.isModel === true;
7503
7533
  }
7504
7534
  function adapterDidInvalidate(store, identifier, error) {
7505
7535
  if (error && error.isAdapterError === true && error.code === 'InvalidError') {
@@ -7657,4 +7687,4 @@ function normalizeModelName(modelName) {
7657
7687
  }
7658
7688
  assert(`normalizeModelName support has been removed`);
7659
7689
  }
7660
- export { Collection as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, Snapshot as a, setIdentifierGenerationMethod as b, setIdentifierUpdateMethod as c, setIdentifierForgetMethod as d, setIdentifierResetMethod as e, coerceId as f, SOURCE as g, IDENTIFIER_ARRAY_TAG as h, isStableIdentifier as i, fastPush as j, SnapshotRecordArray as k, recordDataFor as l, removeRecordDataFor as m, normalizeModelName as n, recordIdentifierFor as r, storeFor as s };
7690
+ export { Collection as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, Snapshot as a, setIdentifierGenerationMethod as b, setIdentifierUpdateMethod as c, setIdentifierForgetMethod as d, setIdentifierResetMethod as e, coerceId as f, notifyArray as g, SOURCE as h, isStableIdentifier as i, IDENTIFIER_ARRAY_TAG as j, fastPush as k, SnapshotRecordArray as l, recordDataFor as m, normalizeModelName as n, removeRecordDataFor as o, recordIdentifierFor as r, storeFor as s };