@ember-data/store 5.3.0-alpha.4 → 5.3.0-alpha.6

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 { f as AdapterPopulatedRecordArray, C as CacheHandler, h as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, S as Store, _ as _clearCaches, e as coerceId, j as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, k as removeRecordDataFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./store-service-4e1e7840";
1
+ export { f as AdapterPopulatedRecordArray, C as CacheHandler, h as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, S as Store, m as StoreMap, _ as _clearCaches, e as coerceId, j as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, k as removeRecordDataFor, o as setCacheFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, l as setRecordIdentifier, s as storeFor } from "./store-service-7750e2f0";
package/addon/index.js CHANGED
@@ -1 +1 @@
1
- export { C as CacheHandler, S as default, r as recordIdentifierFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./store-service-4e1e7840";
1
+ export { C as CacheHandler, S as default, r as recordIdentifierFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./store-service-7750e2f0";
@@ -1,8 +1,8 @@
1
- import { getOwner, setOwner } from '@ember/application';
1
+ import { macroCondition, getOwnConfig } from '@embroider/macros';
2
+ import { getOwner } from '@ember/application';
2
3
  import { assert, warn } from '@ember/debug';
3
4
  import EmberObject from '@ember/object';
4
5
  import { _backburner } from '@ember/runloop';
5
- import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';
6
6
  import { tracked } from '@glimmer/tracking';
7
7
  import { dasherize } from '@ember/string';
8
8
  import { addToTransaction, subscribe, addTransactionCB } from '@ember-data/tracking/-private';
@@ -354,26 +354,6 @@ function copyDocumentProperties(target, source) {
354
354
  }
355
355
  }
356
356
 
357
- /*
358
- * Returns the Cache instance associated with a given
359
- * Model or Identifier
360
- */
361
-
362
- const CacheForIdentifierCache = new Map();
363
- function setCacheFor(identifier, cache) {
364
- assert(`Illegal set of identifier`, !CacheForIdentifierCache.has(identifier) || CacheForIdentifierCache.get(identifier) === cache);
365
- CacheForIdentifierCache.set(identifier, cache);
366
- }
367
- function removeRecordDataFor(identifier) {
368
- CacheForIdentifierCache.delete(identifier);
369
- }
370
- function peekCache(instance) {
371
- if (CacheForIdentifierCache.has(instance)) {
372
- return CacheForIdentifierCache.get(instance);
373
- }
374
- return null;
375
- }
376
-
377
357
  /**
378
358
  @module @ember-data/store
379
359
  */
@@ -1335,14 +1315,25 @@ class CacheStoreWrapper {
1335
1315
  this._pendingNotifies.delete(identifier);
1336
1316
  }
1337
1317
  }
1338
- let _peekGraph;
1339
- if (macroCondition(getOwnConfig().packages.HAS_GRAPH_PACKAGE)) {
1340
- let __peekGraph;
1341
- _peekGraph = wrapper => {
1342
- let a = importSync('@ember-data/graph/-private').peekGraph;
1343
- __peekGraph = __peekGraph || a;
1344
- return __peekGraph(wrapper);
1345
- };
1318
+
1319
+ /*
1320
+ * Returns the Cache instance associated with a given
1321
+ * Model or Identifier
1322
+ */
1323
+
1324
+ const CacheForIdentifierCache = new Map();
1325
+ function setCacheFor(identifier, cache) {
1326
+ assert(`Illegal set of identifier`, !CacheForIdentifierCache.has(identifier) || CacheForIdentifierCache.get(identifier) === cache);
1327
+ CacheForIdentifierCache.set(identifier, cache);
1328
+ }
1329
+ function removeRecordDataFor(identifier) {
1330
+ CacheForIdentifierCache.delete(identifier);
1331
+ }
1332
+ function peekCache(instance) {
1333
+ if (CacheForIdentifierCache.has(instance)) {
1334
+ return CacheForIdentifierCache.get(instance);
1335
+ }
1336
+ return null;
1346
1337
  }
1347
1338
 
1348
1339
  /**
@@ -1441,11 +1432,8 @@ class InstanceCache {
1441
1432
 
1442
1433
  /*
1443
1434
  TODO @runspired consider adding this to make polymorphism even nicer
1444
- if (HAS_GRAPH_PACKAGE) {
1445
1435
  if (identifier.type !== matchedIdentifier.type) {
1446
- const graphFor = importSync('@ember-data/graph/-private').graphFor;
1447
- graphFor(this).registerPolymorphicType(identifier.type, matchedIdentifier.type);
1448
- }
1436
+ this.store._graph?.registerPolymorphicType(identifier.type, matchedIdentifier.type);
1449
1437
  }
1450
1438
  */
1451
1439
 
@@ -1507,12 +1495,7 @@ class InstanceCache {
1507
1495
  disconnect(identifier) {
1508
1496
  const record = this.__instances.record.get(identifier);
1509
1497
  assert('Cannot destroy record while it is still materialized', !record || record.isDestroyed || record.isDestroying);
1510
- if (macroCondition(getOwnConfig().packages.HAS_GRAPH_PACKAGE)) {
1511
- let graph = _peekGraph(this.store);
1512
- if (graph) {
1513
- graph.remove(identifier);
1514
- }
1515
- }
1498
+ this.store._graph?.remove(identifier);
1516
1499
  this.store.identifierCache.forgetRecordIdentifier(identifier);
1517
1500
  removeRecordDataFor(identifier);
1518
1501
  this.store._requestCache._clearEntries(identifier);
@@ -1712,84 +1695,6 @@ function _clearCaches() {
1712
1695
  StoreMap.clear();
1713
1696
  CacheForIdentifierCache.clear();
1714
1697
  }
1715
- let _modelForMixin;
1716
- if (macroCondition(getOwnConfig().packages.HAS_MODEL_PACKAGE)) {
1717
- let _found;
1718
- _modelForMixin = function () {
1719
- if (!_found) {
1720
- _found = importSync('@ember-data/model/-private')._modelForMixin;
1721
- }
1722
- return _found(...arguments);
1723
- };
1724
- }
1725
- class DSModelSchemaDefinitionService {
1726
- constructor(store) {
1727
- this.store = store;
1728
- this._relationshipsDefCache = Object.create(null);
1729
- this._attributesDefCache = Object.create(null);
1730
- }
1731
-
1732
- // Following the existing RD implementation
1733
- attributesDefinitionFor(identifier) {
1734
- let modelName, attributes;
1735
- modelName = identifier.type;
1736
- attributes = this._attributesDefCache[modelName];
1737
- if (attributes === undefined) {
1738
- let modelClass = this.store.modelFor(modelName);
1739
- let attributeMap = modelClass.attributes;
1740
- attributes = Object.create(null);
1741
- attributeMap.forEach((meta, name) => attributes[name] = meta);
1742
- this._attributesDefCache[modelName] = attributes;
1743
- }
1744
- return attributes;
1745
- }
1746
-
1747
- // Following the existing RD implementation
1748
- relationshipsDefinitionFor(identifier) {
1749
- let modelName, relationships;
1750
- modelName = identifier.type;
1751
- relationships = this._relationshipsDefCache[modelName];
1752
- if (relationships === undefined) {
1753
- let modelClass = this.store.modelFor(modelName);
1754
- relationships = modelClass.relationshipsObject || null;
1755
- this._relationshipsDefCache[modelName] = relationships;
1756
- }
1757
- return relationships;
1758
- }
1759
- doesTypeExist(modelName) {
1760
- let normalizedModelName = normalizeModelName(modelName);
1761
- let factory = getModelFactory(this.store, this.store._modelFactoryCache, normalizedModelName);
1762
- return factory !== null;
1763
- }
1764
- }
1765
- function getModelFactory(store, cache, normalizedModelName) {
1766
- let factory = cache[normalizedModelName];
1767
- if (!factory) {
1768
- let owner = getOwner(store);
1769
- factory = owner.factoryFor(`model:${normalizedModelName}`);
1770
- if (macroCondition(getOwnConfig().packages.HAS_MODEL_PACKAGE)) {
1771
- if (!factory) {
1772
- //Support looking up mixins as base types for polymorphic relationships
1773
- factory = _modelForMixin(store, normalizedModelName);
1774
- }
1775
- }
1776
- if (!factory) {
1777
- // we don't cache misses in case someone wants to register a missing model
1778
- return null;
1779
- }
1780
- let klass = factory.class;
1781
- if (klass.isModel) {
1782
- let hasOwnModelNameSet = klass.modelName && Object.prototype.hasOwnProperty.call(klass, 'modelName');
1783
- if (!hasOwnModelNameSet) {
1784
- Object.defineProperty(klass, 'modelName', {
1785
- value: normalizedModelName
1786
- });
1787
- }
1788
- }
1789
- cache[normalizedModelName] = factory;
1790
- }
1791
- return factory;
1792
- }
1793
1698
 
1794
1699
  // if modelFor turns out to be a bottleneck we should replace with a Map
1795
1700
  // and clear it during store teardown.
@@ -3559,14 +3464,6 @@ function constructResource(type, id, lid) {
3559
3464
  }
3560
3465
  }
3561
3466
 
3562
- /**
3563
- @module @ember-data/store
3564
- */
3565
-
3566
- // hello world
3567
-
3568
- let _Cache;
3569
-
3570
3467
  /**
3571
3468
  * A Store coordinates interaction between your application, a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache),
3572
3469
  * and sources of data (such as your API or a local persistence layer)
@@ -3720,7 +3617,6 @@ class Store extends EmberObject {
3720
3617
  this._instanceCache = new InstanceCache(this);
3721
3618
  this._adapterCache = Object.create(null);
3722
3619
  this._serializerCache = Object.create(null);
3723
- this._modelFactoryCache = Object.create(null);
3724
3620
  this._documentCache = new Map();
3725
3621
  this.isDestroying = false;
3726
3622
  this.isDestroyed = false;
@@ -3865,28 +3761,6 @@ class Store extends EmberObject {
3865
3761
  * @returns A record instance
3866
3762
  * @public
3867
3763
  */
3868
- instantiateRecord(identifier, createRecordArgs) {
3869
- if (macroCondition(getOwnConfig().packages.HAS_MODEL_PACKAGE)) {
3870
- let modelName = identifier.type;
3871
- const cache = this.cache;
3872
- // TODO deprecate allowing unknown args setting
3873
- let createOptions = {
3874
- _createProps: createRecordArgs,
3875
- // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
3876
- _secretInit: {
3877
- identifier,
3878
- cache,
3879
- store: this,
3880
- cb: secretInit
3881
- }
3882
- };
3883
-
3884
- // ensure that `getOwner(this)` works inside a model instance
3885
- setOwner(createOptions, getOwner(this));
3886
- return getModelFactory(this, this._modelFactoryCache, modelName).class.create(createOptions);
3887
- }
3888
- assert(`You must implement the store's instantiateRecord hook for your custom model class.`);
3889
- }
3890
3764
 
3891
3765
  /**
3892
3766
  * A hook which an app or addon may implement. Called when
@@ -3898,14 +3772,6 @@ class Store extends EmberObject {
3898
3772
  * @public
3899
3773
  * @param record
3900
3774
  */
3901
- teardownRecord(record) {
3902
- if (macroCondition(getOwnConfig().packages.HAS_MODEL_PACKAGE)) {
3903
- assert(`expected to receive an instance of DSModel. If using a custom model make sure you implement teardownRecord`, 'destroy' in record);
3904
- record.destroy();
3905
- } else {
3906
- assert(`You must implement the store's teardownRecord hook for your custom models`);
3907
- }
3908
- }
3909
3775
 
3910
3776
  /**
3911
3777
  * Provides access to the SchemaDefinitionService instance
@@ -3918,13 +3784,6 @@ class Store extends EmberObject {
3918
3784
  * @public
3919
3785
  */
3920
3786
  getSchemaDefinitionService() {
3921
- if (macroCondition(getOwnConfig().packages.HAS_MODEL_PACKAGE)) {
3922
- if (!this._schema) {
3923
- // it is potentially a mistake for the RFC to have not enabled chaining these services, though highlander rule is nice.
3924
- // what ember-m3 did via private API to allow both worlds to interop would be much much harder using this.
3925
- this._schema = new DSModelSchemaDefinitionService(this);
3926
- }
3927
- }
3928
3787
  assert(`You must registerSchemaDefinitionService with the store to use custom model classes`, this._schema);
3929
3788
  return this._schema;
3930
3789
  }
@@ -4056,33 +3915,18 @@ class Store extends EmberObject {
4056
3915
  for example.
4057
3916
  @method modelFor
4058
3917
  @public
4059
- @param {String} modelName
4060
- @return {subclass of Model | ShimModelClass}
3918
+ @param {String} type
3919
+ @return {ModelSchema}
4061
3920
  */
4062
3921
  // TODO @deprecate in favor of schema APIs, requires adapter/serializer overhaul or replacement
4063
3922
 
4064
- modelFor(modelName) {
3923
+ modelFor(type) {
4065
3924
  if (macroCondition(getOwnConfig().env.DEBUG)) {
4066
3925
  assertDestroyedStoreOnly(this, 'modelFor');
4067
3926
  }
4068
- assert(`You need to pass a model name to the store's modelFor method`, modelName);
4069
- assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
4070
- if (macroCondition(getOwnConfig().packages.HAS_MODEL_PACKAGE)) {
4071
- let normalizedModelName = normalizeModelName(modelName);
4072
- let maybeFactory = getModelFactory(this, this._modelFactoryCache, normalizedModelName);
4073
-
4074
- // for factorFor factory/class split
4075
- let klass = maybeFactory && maybeFactory.class ? maybeFactory.class : maybeFactory;
4076
- if (!klass || !klass.isModel || this._forceShim) {
4077
- assert(`No model was found for '${modelName}' and no schema handles the type`, this.getSchemaDefinitionService().doesTypeExist(modelName));
4078
- return getShimClass(this, modelName);
4079
- } else {
4080
- // TODO @deprecate ever returning the klass, always return the shim
4081
- return klass;
4082
- }
4083
- }
4084
- assert(`No model was found for '${modelName}' and no schema handles the type`, this.getSchemaDefinitionService().doesTypeExist(modelName));
4085
- return getShimClass(this, modelName);
3927
+ assert(`You need to pass <type> to the store's modelFor method`, typeof type === 'string' && type.length);
3928
+ assert(`No model was found for '${type}' and no schema handles the type`, this.getSchemaDefinitionService().doesTypeExist(type));
3929
+ return getShimClass(this, type);
4086
3930
  }
4087
3931
 
4088
3932
  /**
@@ -5027,13 +4871,7 @@ class Store extends EmberObject {
5027
4871
  // destroy the graph before unloadAll
5028
4872
  // since then we avoid churning relationships
5029
4873
  // during unload
5030
- if (macroCondition(getOwnConfig().packages.HAS_GRAPH_PACKAGE)) {
5031
- const peekGraph = importSync('@ember-data/graph/-private').peekGraph;
5032
- const graph = peekGraph(this);
5033
- if (graph) {
5034
- graph.identifiers.clear();
5035
- }
5036
- }
4874
+ this._graph?.identifiers.clear();
5037
4875
  this.recordArrayManager.clear();
5038
4876
  this._instanceCache.clear();
5039
4877
  } else {
@@ -5288,19 +5126,6 @@ class Store extends EmberObject {
5288
5126
  serializer.pushPayload(this, payload);
5289
5127
  }
5290
5128
 
5291
- // TODO @runspired @deprecate records should implement their own serialization if desired
5292
- serializeRecord(record, options) {
5293
- // TODO we used to check if the record was destroyed here
5294
- if (macroCondition(getOwnConfig().packages.HAS_COMPAT_PACKAGE)) {
5295
- if (!this._fetchManager) {
5296
- const FetchManager = importSync('@ember-data/legacy-compat/-private').FetchManager;
5297
- this._fetchManager = new FetchManager(this);
5298
- }
5299
- return this._fetchManager.createSnapshot(recordIdentifierFor(record)).serialize(options);
5300
- }
5301
- assert(`Store.serializeRecord is only available when utilizing @ember-data/legacy-compat for legacy compatibility`);
5302
- }
5303
-
5304
5129
  /**
5305
5130
  * Trigger a save for a Record.
5306
5131
  *
@@ -5327,9 +5152,6 @@ class Store extends EmberObject {
5327
5152
  if (resourceIsFullyDeleted(this._instanceCache, identifier)) {
5328
5153
  return Promise.resolve(record);
5329
5154
  }
5330
- if (isDSModel(record)) {
5331
- record.errors.clear();
5332
- }
5333
5155
  if (!options) {
5334
5156
  options = {};
5335
5157
  }
@@ -5369,15 +5191,6 @@ class Store extends EmberObject {
5369
5191
  * @param storeWrapper
5370
5192
  * @returns {Cache}
5371
5193
  */
5372
- createCache(storeWrapper) {
5373
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
5374
- if (_Cache === undefined) {
5375
- _Cache = importSync('@ember-data/json-api').default;
5376
- }
5377
- return new _Cache(storeWrapper);
5378
- }
5379
- assert(`Expected store.createCache to be implemented but it wasn't`);
5380
- }
5381
5194
 
5382
5195
  /**
5383
5196
  * Returns the cache instance associated to this Store, instantiates the Cache
@@ -5542,13 +5355,8 @@ class Store extends EmberObject {
5542
5355
  serializer.destroy();
5543
5356
  }
5544
5357
  }
5545
- if (macroCondition(getOwnConfig().packages.HAS_GRAPH_PACKAGE)) {
5546
- const peekGraph = importSync('@ember-data/graph/-private').peekGraph;
5547
- let graph = peekGraph(this);
5548
- if (graph) {
5549
- graph.destroy();
5550
- }
5551
- }
5358
+ this._graph?.destroy();
5359
+ this._graph = undefined;
5552
5360
  this.notifications.destroy();
5553
5361
  this.recordArrayManager.destroy();
5554
5362
  this.identifierCache.destroy();
@@ -5572,12 +5380,6 @@ if (macroCondition(getOwnConfig().env.DEBUG)) {
5572
5380
  function isMaybeIdentifier(maybeIdentifier) {
5573
5381
  return Boolean(maybeIdentifier !== null && typeof maybeIdentifier === 'object' && ('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type || maybeIdentifier.lid));
5574
5382
  }
5575
- function isDSModel(record) {
5576
- if (macroCondition(!getOwnConfig().packages.HAS_MODEL_PACKAGE)) {
5577
- return false;
5578
- }
5579
- return !!record && 'constructor' in record && 'isModel' in record.constructor && record.constructor.isModel === true;
5580
- }
5581
5383
  function normalizeProperties(store, identifier, properties) {
5582
5384
  // assert here
5583
5385
  if (properties !== undefined) {
@@ -5638,9 +5440,4 @@ function extractIdentifierFromRecord(recordOrPromiseRecord) {
5638
5440
  const extract = recordIdentifierFor;
5639
5441
  return extract(recordOrPromiseRecord);
5640
5442
  }
5641
- function secretInit(record, cache, identifier, store) {
5642
- setRecordIdentifier(record, identifier);
5643
- StoreMap.set(record, store);
5644
- setCacheFor(record, cache);
5645
- }
5646
- export { CacheHandler as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, coerceId as e, Collection as f, SOURCE as g, IDENTIFIER_ARRAY_TAG as h, isStableIdentifier as i, fastPush as j, removeRecordDataFor as k, notifyArray as n, peekCache as p, recordIdentifierFor as r, storeFor as s };
5443
+ export { CacheHandler as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, coerceId as e, Collection as f, SOURCE as g, IDENTIFIER_ARRAY_TAG as h, isStableIdentifier as i, fastPush as j, removeRecordDataFor as k, setRecordIdentifier as l, StoreMap as m, notifyArray as n, setCacheFor as o, peekCache as p, recordIdentifierFor as r, storeFor as s };