@ember-data/store 4.12.0-beta.0 → 4.12.0-beta.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.
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, 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-62be6fd3";
@@ -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';
@@ -2433,7 +2433,7 @@ class Snapshot {
2433
2433
  // function without access to intimate API contracts between RecordData and Model.
2434
2434
  // This is a requirement we should fix as soon as the relationship layer does not require
2435
2435
  // this intimate API usage.
2436
- if (!moduleExists("@ember-data/json-api")) {
2436
+ if (macroCondition(!dependencySatisfies("@ember-data/json-api", "*"))) {
2437
2437
  assert(`snapshot.belongsTo only supported when using the package @ember-data/json-api`);
2438
2438
  }
2439
2439
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
@@ -2510,7 +2510,7 @@ class Snapshot {
2510
2510
  // function without access to intimate API contracts between RecordData and Model.
2511
2511
  // This is a requirement we should fix as soon as the relationship layer does not require
2512
2512
  // this intimate API usage.
2513
- if (!moduleExists("@ember-data/json-api")) {
2513
+ if (macroCondition(!dependencySatisfies("@ember-data/json-api", "*"))) {
2514
2514
  assert(`snapshot.hasMany only supported when using the package @ember-data/json-api`);
2515
2515
  }
2516
2516
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
@@ -2654,7 +2654,7 @@ function recordDataFor(instance) {
2654
2654
  return null;
2655
2655
  }
2656
2656
  let _peekGraph;
2657
- if (moduleExists("@ember-data/graph")) {
2657
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
2658
2658
  let __peekGraph;
2659
2659
  _peekGraph = wrapper => {
2660
2660
  let a = importSync('@ember-data/graph/-private').peekGraph;
@@ -2766,7 +2766,7 @@ class InstanceCache {
2766
2766
  record: staleIdentifier,
2767
2767
  value: keptIdentifier
2768
2768
  });
2769
- } else if (moduleExists("@ember-data/json-api")) {
2769
+ } else if (macroCondition(dependencySatisfies("@ember-data/json-api", "*"))) {
2770
2770
  // TODO notify cache always, this requires it always being a singleton
2771
2771
  // and not ever specific to one record-data
2772
2772
  this.store.__private_singleton_recordData?.sync({
@@ -2910,7 +2910,7 @@ class InstanceCache {
2910
2910
  disconnect(identifier) {
2911
2911
  const record = this.__instances.record.get(identifier);
2912
2912
  assert('Cannot destroy record while it is still materialized', !record || record.isDestroyed || record.isDestroying);
2913
- if (moduleExists("@ember-data/graph")) {
2913
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
2914
2914
  let graph = _peekGraph(this.store);
2915
2915
  if (graph) {
2916
2916
  graph.remove(identifier);
@@ -3180,7 +3180,7 @@ function _isLoading(cache, identifier) {
3180
3180
  req.getPendingRequestsForRecord(identifier).some(req => req.type === 'query');
3181
3181
  }
3182
3182
  let _modelForMixin;
3183
- if (moduleExists("@ember-data/model")) {
3183
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
3184
3184
  let _found;
3185
3185
  _modelForMixin = function () {
3186
3186
  if (!_found) {
@@ -3268,9 +3268,11 @@ function getModelFactory(store, cache, normalizedModelName) {
3268
3268
  if (!factory) {
3269
3269
  let owner = getOwner(store);
3270
3270
  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);
3271
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
3272
+ if (!factory) {
3273
+ //Support looking up mixins as base types for polymorphic relationships
3274
+ factory = _modelForMixin(store, normalizedModelName);
3275
+ }
3274
3276
  }
3275
3277
  if (!factory) {
3276
3278
  // we don't cache misses in case someone wants to register a missing model
@@ -4178,28 +4180,22 @@ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_ARRAY_LIKE)) {
4178
4180
  IdentifierArray.prototype.arrayContentDidChange = function () {
4179
4181
  deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'arrayContentDidChange', 'derived state or reacting at the change source.');
4180
4182
  };
4181
-
4182
- // @ts-expect-error
4183
- IdentifierArray.prototype.reject = function (key, value) {
4183
+ IdentifierArray.prototype.reject = function (callback, target) {
4184
4184
  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);
4185
+ assert('`reject` expects a function as first argument.', typeof callback === 'function');
4186
+ return this.filter((...args) => {
4187
+ return !callback.apply(target, args);
4192
4188
  });
4193
4189
  };
4194
4190
  IdentifierArray.prototype.rejectBy = function (key, value) {
4195
4191
  deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'rejectBy', 'filter');
4196
4192
  if (arguments.length === 2) {
4197
- return this.filter(value => {
4198
- return !get(value, key);
4193
+ return this.filter(record => {
4194
+ return get(record, key) !== value;
4199
4195
  });
4200
4196
  }
4201
- return this.filter(value => {
4202
- return !get(value, key);
4197
+ return this.filter(record => {
4198
+ return !get(record, key);
4203
4199
  });
4204
4200
  };
4205
4201
  IdentifierArray.prototype.setEach = function (key, value) {
@@ -4950,12 +4946,14 @@ class FetchManager {
4950
4946
  });
4951
4947
  if (!recordData || recordData.isEmpty(identifier) || isLoading) {
4952
4948
  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);
4949
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
4950
+ if (!recordData) {
4951
+ const graphFor = importSync('@ember-data/graph/-private').graphFor;
4952
+ const graph = graphFor(store);
4953
+ isReleasable = graph.isReleasable(identifier);
4954
+ if (!isReleasable) {
4955
+ graph.unload(identifier, true);
4956
+ }
4959
4957
  }
4960
4958
  }
4961
4959
  if (recordData || isReleasable) {
@@ -5642,7 +5640,7 @@ class Store {
5642
5640
  * @public
5643
5641
  */
5644
5642
  instantiateRecord(identifier, createRecordArgs, recordDataFor, notificationManager) {
5645
- if (moduleExists("@ember-data/model")) {
5643
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5646
5644
  let modelName = identifier.type;
5647
5645
  let recordData = this._instanceCache.getRecordData(identifier);
5648
5646
  // TODO deprecate allowing unknown args setting
@@ -5675,7 +5673,7 @@ class Store {
5675
5673
  * @param record
5676
5674
  */
5677
5675
  teardownRecord(record) {
5678
- if (moduleExists("@ember-data/model")) {
5676
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5679
5677
  assert(`expected to receive an instance of DSModel. If using a custom model make sure you implement teardownRecord`, 'destroy' in record);
5680
5678
  record.destroy();
5681
5679
  } else {
@@ -5694,10 +5692,12 @@ class Store {
5694
5692
  * @public
5695
5693
  */
5696
5694
  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);
5695
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5696
+ if (!this._schemaDefinitionService) {
5697
+ // it is potentially a mistake for the RFC to have not enabled chaining these services, though highlander rule is nice.
5698
+ // what ember-m3 did via private API to allow both worlds to interop would be much much harder using this.
5699
+ this._schemaDefinitionService = new DSModelSchemaDefinitionService(this);
5700
+ }
5701
5701
  }
5702
5702
  assert(`You must registerSchemaDefinitionService with the store to use custom model classes`, this._schemaDefinitionService);
5703
5703
  return this._schemaDefinitionService;
@@ -5784,7 +5784,7 @@ class Store {
5784
5784
  }
5785
5785
  assert(`You need to pass a model name to the store's modelFor method`, modelName);
5786
5786
  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")) {
5787
+ if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5788
5788
  let normalizedModelName = normalizeModelName$1(modelName);
5789
5789
  let maybeFactory = getModelFactory(this, this._modelFactoryCache, normalizedModelName);
5790
5790
 
@@ -6868,7 +6868,7 @@ class Store {
6868
6868
  // destroy the graph before unloadAll
6869
6869
  // since then we avoid churning relationships
6870
6870
  // during unload
6871
- if (moduleExists("@ember-data/graph")) {
6871
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
6872
6872
  const peekGraph = importSync('@ember-data/graph/-private').peekGraph;
6873
6873
  let graph = peekGraph(this);
6874
6874
  if (graph) {
@@ -7266,7 +7266,7 @@ class Store {
7266
7266
  * @param storeWrapper
7267
7267
  */
7268
7268
  createRecordDataFor(identifier, storeWrapper) {
7269
- if (moduleExists("@ember-data/json-api")) {
7269
+ if (macroCondition(dependencySatisfies("@ember-data/json-api", "*"))) {
7270
7270
  // we can't greedily use require as this causes
7271
7271
  // a cycle we can't easily fix (or clearly pin point) at present.
7272
7272
  //
@@ -7461,7 +7461,7 @@ class Store {
7461
7461
  serializer.destroy();
7462
7462
  }
7463
7463
  }
7464
- if (moduleExists("@ember-data/graph")) {
7464
+ if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
7465
7465
  const peekGraph = importSync('@ember-data/graph/-private').peekGraph;
7466
7466
  let graph = peekGraph(this);
7467
7467
  if (graph) {
@@ -7499,7 +7499,10 @@ function isMaybeIdentifier(maybeIdentifier) {
7499
7499
  return Boolean(maybeIdentifier !== null && typeof maybeIdentifier === 'object' && ('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type || maybeIdentifier.lid));
7500
7500
  }
7501
7501
  function isDSModel(record) {
7502
- return moduleExists("@ember-data/model") && !!record && 'constructor' in record && 'isModel' in record.constructor && record.constructor.isModel === true;
7502
+ if (macroCondition(!dependencySatisfies("@ember-data/model", "*"))) {
7503
+ return false;
7504
+ }
7505
+ return !!record && 'constructor' in record && 'isModel' in record.constructor && record.constructor.isModel === true;
7503
7506
  }
7504
7507
  function adapterDidInvalidate(store, identifier, error) {
7505
7508
  if (error && error.isAdapterError === true && error.code === 'InvalidError') {