@ember-data/store 5.4.0-alpha.28 → 5.4.0-alpha.29

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 { A as ARRAY_SIGNAL, f as AdapterPopulatedRecordArray, C as CacheHandler, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, S as Store, l as StoreMap, _ as _clearCaches, o as _deprecatingNormalize, e as coerceId, h as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, j as removeRecordDataFor, m as setCacheFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, k as setRecordIdentifier, s as storeFor } from "./cache-handler-XLbbNJdo";
1
+ export { A as ARRAY_SIGNAL, f as AdapterPopulatedRecordArray, C as CacheHandler, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, S as Store, l as StoreMap, _ as _clearCaches, o as _deprecatingNormalize, e as coerceId, h as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, j as removeRecordDataFor, m as setCacheFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, k as setRecordIdentifier, s as storeFor } from "./cache-handler-oB00-31L";
@@ -1077,6 +1077,7 @@ function peekRecordIdentifier(record) {
1077
1077
  @param {Object} record a record instance previously obstained from the store.
1078
1078
  @return {StableRecordIdentifier}
1079
1079
  */
1080
+
1080
1081
  function recordIdentifierFor(record) {
1081
1082
  assert(`${String(record)} is not a record instantiated by @ember-data/store`, RecordCache.has(record));
1082
1083
  return RecordCache.get(record);
@@ -2528,6 +2529,7 @@ let IdentifierArray = (_class = class IdentifierArray {
2528
2529
  target[index] = identifier;
2529
2530
  return true;
2530
2531
  } else if (isSelfProp(self, prop)) {
2532
+ // @ts-expect-error not all properties are indeces and we can't safely cast
2531
2533
  self[prop] = value;
2532
2534
  return true;
2533
2535
  }
@@ -2618,6 +2620,10 @@ let IdentifierArray = (_class = class IdentifierArray {
2618
2620
  */
2619
2621
  _update() {
2620
2622
  assert(`_update cannot be used with this array`, this.modelName);
2623
+ // @ts-expect-error typescript is unable to handle the complexity of
2624
+ // T = unknown, modelName = string
2625
+ // T extends TypedRecordInstance, modelName = TypeFromInstance<T>
2626
+ // both being valid options to pass through here.
2621
2627
  return this.store.findAll(this.modelName, {
2622
2628
  reload: true
2623
2629
  });
@@ -2672,6 +2678,10 @@ class Collection extends IdentifierArray {
2672
2678
  // TODO save options from initial request?
2673
2679
  assert(`update cannot be used with this array`, this.modelName);
2674
2680
  assert(`update cannot be used with no query`, query);
2681
+ // @ts-expect-error typescript is unable to handle the complexity of
2682
+ // T = unknown, modelName = string
2683
+ // T extends TypedRecordInstance, modelName = TypeFromInstance<T>
2684
+ // both being valid options to pass through here.
2675
2685
  const promise = store.query(this.modelName, query, {
2676
2686
  _recordArray: this
2677
2687
  });
@@ -3297,6 +3307,24 @@ function constructResource(type, id, lid) {
3297
3307
  */
3298
3308
  // this import location is deprecated but breaks in 4.8 and older
3299
3309
 
3310
+ /**
3311
+ * Currently only records that extend object can be created via
3312
+ * store.createRecord. This is a limitation of the current API,
3313
+ * but can be worked around by creating a new identifier, running
3314
+ * the cache.clientDidCreate method, and then peeking the record
3315
+ * for the identifier.
3316
+ *
3317
+ * To assign primary key to a record during creation, only `id` will
3318
+ * work correctly for `store.createRecord`, other primary key may be
3319
+ * handled by updating the record after creation or using the flow
3320
+ * described above.
3321
+ *
3322
+ * TODO: These are limitations we want to (and can) address. If you
3323
+ * have need of lifting these limitations, please open an issue.
3324
+ *
3325
+ * @typedoc
3326
+ */
3327
+
3300
3328
  /**
3301
3329
  * A Store coordinates interaction between your application, a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache),
3302
3330
  * and sources of data (such as your API or a local persistence layer)
@@ -3779,7 +3807,7 @@ class Store extends EmberObject {
3779
3807
  }
3780
3808
 
3781
3809
  /**
3782
- Returns the schema for a particular `modelName`.
3810
+ Returns the schema for a particular resource type (modelName).
3783
3811
  When used with Model from @ember-data/model the return is the model class,
3784
3812
  but this is not guaranteed.
3785
3813
  If looking to query attribute or relationship information it is
@@ -3793,7 +3821,7 @@ class Store extends EmberObject {
3793
3821
  for example.
3794
3822
  @method modelFor
3795
3823
  @public
3796
- @param {String} type
3824
+ @param {string} type
3797
3825
  @return {ModelSchema}
3798
3826
  */
3799
3827
  // TODO @deprecate in favor of schema APIs, requires adapter/serializer overhaul or replacement
@@ -3826,17 +3854,18 @@ class Store extends EmberObject {
3826
3854
  ```
3827
3855
  @method createRecord
3828
3856
  @public
3829
- @param {String} modelName
3857
+ @param {String} type the name of the resource
3830
3858
  @param {Object} inputProperties a hash of properties to set on the
3831
3859
  newly created record.
3832
3860
  @return {Model} record
3833
3861
  */
3834
- createRecord(modelName, inputProperties) {
3862
+
3863
+ createRecord(type, inputProperties) {
3835
3864
  if (macroCondition(getOwnConfig().env.DEBUG)) {
3836
3865
  assertDestroyingStore(this, 'createRecord');
3837
3866
  }
3838
- assert(`You need to pass a model name to the store's createRecord method`, modelName);
3839
- assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
3867
+ assert(`You need to pass a model name to the store's createRecord method`, type);
3868
+ assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`, typeof type === 'string');
3840
3869
 
3841
3870
  // This is wrapped in a `run.join` so that in test environments users do not need to manually wrap
3842
3871
  // calls to `createRecord`. The run loop usage here is because we batch the joining and updating
@@ -3845,7 +3874,7 @@ class Store extends EmberObject {
3845
3874
  // to remove this, we would need to move to a new `async` API.
3846
3875
  let record;
3847
3876
  this._join(() => {
3848
- const normalizedModelName = normalizeModelName(modelName);
3877
+ const normalizedModelName = normalizeModelName(type);
3849
3878
  const properties = {
3850
3879
  ...inputProperties
3851
3880
  };
@@ -3854,21 +3883,20 @@ class Store extends EmberObject {
3854
3883
  // give the adapter an opportunity to generate one. Typically,
3855
3884
  // client-side ID generators will use something like uuid.js
3856
3885
  // to avoid conflicts.
3857
-
3886
+ let id = null;
3858
3887
  if (properties.id === null || properties.id === undefined) {
3859
- const adapter = this.adapterFor?.(modelName, true);
3888
+ const adapter = this.adapterFor?.(normalizedModelName, true);
3860
3889
  if (adapter && adapter.generateIdForRecord) {
3861
- properties.id = adapter.generateIdForRecord(this, modelName, properties);
3890
+ id = properties.id = coerceId(adapter.generateIdForRecord(this, normalizedModelName, properties));
3862
3891
  } else {
3863
- properties.id = null;
3892
+ id = properties.id = null;
3864
3893
  }
3894
+ } else {
3895
+ id = properties.id = coerceId(properties.id);
3865
3896
  }
3866
-
3867
- // Coerce ID to a string
3868
- properties.id = coerceId(properties.id);
3869
3897
  const resource = {
3870
3898
  type: normalizedModelName,
3871
- id: properties.id
3899
+ id
3872
3900
  };
3873
3901
  if (resource.id) {
3874
3902
  const identifier = this.identifierCache.peekRecordIdentifier(resource);
@@ -3894,7 +3922,7 @@ class Store extends EmberObject {
3894
3922
  ```
3895
3923
  @method deleteRecord
3896
3924
  @public
3897
- @param {Model} record
3925
+ @param {unknown} record
3898
3926
  */
3899
3927
  deleteRecord(record) {
3900
3928
  if (macroCondition(getOwnConfig().env.DEBUG)) {
@@ -4216,7 +4244,7 @@ class Store extends EmberObject {
4216
4244
  @since 1.13.0
4217
4245
  @method findRecord
4218
4246
  @public
4219
- @param {String|object} modelName - either a string representing the modelName or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
4247
+ @param {String|object} type - either a string representing the name of the resource or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
4220
4248
  @param {(String|Integer|Object)} id - optional object with options for the request only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved
4221
4249
  @param {Object} [options] - if the first param is a string this will be the optional options for the request. See examples for available options.
4222
4250
  @return {Promise} promise
@@ -4401,24 +4429,25 @@ class Store extends EmberObject {
4401
4429
  @since 1.13.0
4402
4430
  @method query
4403
4431
  @public
4404
- @param {String} modelName
4405
- @param {any} query an opaque query to be used by the adapter
4432
+ @param {String} type the name of the resource
4433
+ @param {object} query a query to be used by the adapter
4406
4434
  @param {Object} options optional, may include `adapterOptions` hash which will be passed to adapter.query
4407
4435
  @return {Promise} promise
4408
4436
  */
4409
- query(modelName, query, options) {
4437
+
4438
+ query(type, query, options = {}) {
4410
4439
  if (macroCondition(getOwnConfig().env.DEBUG)) {
4411
4440
  assertDestroyingStore(this, 'query');
4412
4441
  }
4413
- assert(`You need to pass a model name to the store's query method`, modelName);
4442
+ assert(`You need to pass a model name to the store's query method`, type);
4414
4443
  assert(`You need to pass a query hash to the store's query method`, query);
4415
- assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
4444
+ assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`, typeof type === 'string');
4416
4445
  const promise = this.request({
4417
4446
  op: 'query',
4418
4447
  data: {
4419
- type: normalizeModelName(modelName),
4448
+ type: normalizeModelName(type),
4420
4449
  query,
4421
- options: options || {}
4450
+ options: options
4422
4451
  },
4423
4452
  cacheOptions: {
4424
4453
  [SkipCache]: true
@@ -4676,20 +4705,21 @@ class Store extends EmberObject {
4676
4705
  @since 1.13.0
4677
4706
  @method findAll
4678
4707
  @public
4679
- @param {String} modelName
4680
- @param {Object} options
4708
+ @param {string} type the name of the resource
4709
+ @param {object} options
4681
4710
  @return {Promise} promise
4682
4711
  */
4683
- findAll(modelName, options = {}) {
4712
+
4713
+ findAll(type, options = {}) {
4684
4714
  if (macroCondition(getOwnConfig().env.DEBUG)) {
4685
4715
  assertDestroyingStore(this, 'findAll');
4686
4716
  }
4687
- assert(`You need to pass a model name to the store's findAll method`, modelName);
4688
- assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
4717
+ assert(`You need to pass a model name to the store's findAll method`, type);
4718
+ assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`, typeof type === 'string');
4689
4719
  const promise = this.request({
4690
4720
  op: 'findAll',
4691
4721
  data: {
4692
- type: normalizeModelName(modelName),
4722
+ type: normalizeModelName(type),
4693
4723
  options: options || {}
4694
4724
  },
4695
4725
  cacheOptions: {
@@ -4716,17 +4746,17 @@ class Store extends EmberObject {
4716
4746
  @since 1.13.0
4717
4747
  @method peekAll
4718
4748
  @public
4719
- @param {String} modelName
4749
+ @param {string} type the name of the resource
4720
4750
  @return {RecordArray}
4721
4751
  */
4722
- peekAll(modelName) {
4752
+
4753
+ peekAll(type) {
4723
4754
  if (macroCondition(getOwnConfig().env.DEBUG)) {
4724
4755
  assertDestroyingStore(this, 'peekAll');
4725
4756
  }
4726
- assert(`You need to pass a model name to the store's peekAll method`, modelName);
4727
- assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
4728
- const type = normalizeModelName(modelName);
4729
- return this.recordArrayManager.liveArrayFor(type);
4757
+ assert(`You need to pass a model name to the store's peekAll method`, type);
4758
+ assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`, typeof type === 'string');
4759
+ return this.recordArrayManager.liveArrayFor(normalizeModelName(type));
4730
4760
  }
4731
4761
 
4732
4762
  /**
@@ -4738,16 +4768,17 @@ class Store extends EmberObject {
4738
4768
  store.unloadAll('post');
4739
4769
  ```
4740
4770
  @method unloadAll
4771
+ @param {string} type the name of the resource
4741
4772
  @public
4742
- @param {String} modelName
4743
4773
  */
4744
- unloadAll(modelName) {
4774
+
4775
+ unloadAll(type) {
4745
4776
  if (macroCondition(getOwnConfig().env.DEBUG)) {
4746
4777
  assertDestroyedStoreOnly(this, 'unloadAll');
4747
4778
  }
4748
- assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${String(modelName)}`, !modelName || typeof modelName === 'string');
4779
+ assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${String(type)}`, !type || typeof type === 'string');
4749
4780
  this._join(() => {
4750
- if (modelName === undefined) {
4781
+ if (type === undefined) {
4751
4782
  // destroy the graph before unloadAll
4752
4783
  // since then we avoid churning relationships
4753
4784
  // during unload
@@ -4755,8 +4786,7 @@ class Store extends EmberObject {
4755
4786
  this.recordArrayManager.clear();
4756
4787
  this._instanceCache.clear();
4757
4788
  } else {
4758
- const normalizedModelName = normalizeModelName(modelName);
4759
- this._instanceCache.clear(normalizedModelName);
4789
+ this._instanceCache.clear(normalizeModelName(type));
4760
4790
  }
4761
4791
  });
4762
4792
  }
@@ -4944,11 +4974,13 @@ class Store extends EmberObject {
4944
4974
  /**
4945
4975
  * Trigger a save for a Record.
4946
4976
  *
4977
+ * Returns a promise resolving with the same record when the save is complete.
4978
+ *
4947
4979
  * @method saveRecord
4948
4980
  * @public
4949
- * @param {RecordInstance} record
4981
+ * @param {unknown} record
4950
4982
  * @param options
4951
- * @return {Promise<RecordInstance>}
4983
+ * @return {Promise<record>}
4952
4984
  */
4953
4985
  saveRecord(record, options = {}) {
4954
4986
  if (macroCondition(getOwnConfig().env.DEBUG)) {