@warp-drive/legacy 5.8.0-alpha.4 → 5.8.0-alpha.40

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.
Files changed (213) hide show
  1. package/README.md +14 -27
  2. package/declarations/adapter/error.d.ts +5 -5
  3. package/declarations/adapter/json-api.d.ts +6 -8
  4. package/declarations/adapter/rest.d.ts +5 -8
  5. package/declarations/adapter.d.ts +4 -6
  6. package/declarations/compat/-private.d.ts +1 -1
  7. package/declarations/compat/builders/find-all.d.ts +6 -6
  8. package/declarations/compat/builders/find-record.d.ts +8 -8
  9. package/declarations/compat/builders/query.d.ts +12 -12
  10. package/declarations/compat/extensions.d.ts +1 -1
  11. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +7 -9
  12. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +20 -30
  13. package/declarations/compat/utils.d.ts +17 -17
  14. package/declarations/compat.d.ts +35 -11
  15. package/declarations/index.d.ts +70 -0
  16. package/declarations/model/-private/attr.d.ts +5 -6
  17. package/declarations/model/-private/belongs-to.d.ts +4 -5
  18. package/declarations/model/-private/has-many.d.ts +4 -5
  19. package/declarations/model/-private/hooks.d.ts +1 -1
  20. package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
  21. package/declarations/model/-private/model.d.ts +8 -8
  22. package/declarations/model/-private/record-state.d.ts +1 -1
  23. package/declarations/model/-private/references/belongs-to.d.ts +5 -5
  24. package/declarations/model/-private/references/has-many.d.ts +3 -3
  25. package/declarations/model/migration-support.d.ts +46 -21
  26. package/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  27. package/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  28. package/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  29. package/declarations/model-fragments/index.d.ts +5 -0
  30. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  31. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  32. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  33. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  34. package/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  35. package/declarations/model-fragments.d.ts +9 -0
  36. package/declarations/model.d.ts +2 -2
  37. package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -6
  38. package/declarations/serializer/-private/transforms/boolean.d.ts +2 -2
  39. package/declarations/serializer/-private/transforms/date.d.ts +2 -2
  40. package/declarations/serializer/-private/transforms/number.d.ts +1 -1
  41. package/declarations/serializer/-private/transforms/string.d.ts +1 -1
  42. package/declarations/serializer/json-api.d.ts +7 -9
  43. package/declarations/serializer/json.d.ts +7 -9
  44. package/declarations/serializer/rest.d.ts +4 -6
  45. package/declarations/serializer.d.ts +9 -12
  46. package/dist/{-private-8UmnAf9J.js → -private-B1pSSN52.js} +1 -1
  47. package/dist/adapter/-private.js +1 -1
  48. package/dist/adapter/error.js +12 -13
  49. package/dist/adapter/json-api.js +4 -1
  50. package/dist/adapter/rest.js +6 -9
  51. package/dist/adapter.js +4 -6
  52. package/dist/compat/-private.js +1 -1
  53. package/dist/compat/builders.js +26 -26
  54. package/dist/compat/utils.js +17 -18
  55. package/dist/compat.js +58 -41
  56. package/dist/{errors-8kD2mSe_.js → errors-CIGPcDvd.js} +87 -65
  57. package/dist/hooks-QqRnX108.js +74 -0
  58. package/dist/index.js +195 -0
  59. package/dist/{json-DziiodPf.js → json-BNrV8EYG.js} +12 -16
  60. package/dist/model/-private.js +1 -1
  61. package/dist/model/migration-support.js +54 -24
  62. package/dist/model-for-CqXsIKws.js +221 -0
  63. package/dist/model-fragments.js +76 -0
  64. package/dist/model.js +18 -90
  65. package/dist/{schema-provider-DQu4Rjco.js → schema-provider-g5MfTj8n.js} +18 -20
  66. package/dist/{serialize-into-hash-CS0MIv4F.js → serialize-into-hash-BnYvPex3.js} +1 -1
  67. package/dist/serializer/json-api.js +17 -44
  68. package/dist/serializer/json.js +1 -1
  69. package/dist/serializer/rest.js +14 -21
  70. package/dist/serializer/transform.js +15 -6
  71. package/dist/serializer.js +9 -13
  72. package/dist/store.js +3 -0
  73. package/dist/unpkg/dev/-private-DbaSCSym.js +1205 -0
  74. package/dist/unpkg/dev/adapter/-private.js +1 -0
  75. package/dist/unpkg/dev/adapter/error.js +335 -0
  76. package/dist/unpkg/dev/adapter/json-api.js +271 -0
  77. package/dist/unpkg/dev/adapter/rest.js +1255 -0
  78. package/dist/unpkg/dev/adapter.js +1252 -0
  79. package/dist/unpkg/dev/compat/-private.js +1 -0
  80. package/dist/unpkg/dev/compat/builders.js +275 -0
  81. package/dist/unpkg/dev/compat/extensions.js +242 -0
  82. package/dist/unpkg/dev/compat/utils.js +223 -0
  83. package/dist/unpkg/dev/compat.js +1146 -0
  84. package/dist/unpkg/dev/errors-DD96TBEs.js +2591 -0
  85. package/dist/unpkg/dev/hooks-CqWjNWeL.js +73 -0
  86. package/dist/unpkg/dev/index.js +197 -0
  87. package/dist/unpkg/dev/json-CCU-ZQ4b.js +1269 -0
  88. package/dist/unpkg/dev/model/-private.js +1 -0
  89. package/dist/unpkg/dev/model/migration-support.js +551 -0
  90. package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
  91. package/dist/unpkg/dev/model-fragments.js +76 -0
  92. package/dist/unpkg/dev/model.js +678 -0
  93. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  94. package/dist/unpkg/dev/schema-provider-B8jiJOYC.js +2229 -0
  95. package/dist/unpkg/dev/serialize-into-hash-CPAZXrQU.js +259 -0
  96. package/dist/unpkg/dev/serializer/json-api.js +648 -0
  97. package/dist/unpkg/dev/serializer/json.js +4 -0
  98. package/dist/unpkg/dev/serializer/rest.js +1242 -0
  99. package/dist/unpkg/dev/serializer/transform.js +278 -0
  100. package/dist/unpkg/dev/serializer.js +248 -0
  101. package/dist/unpkg/dev/store.js +636 -0
  102. package/dist/unpkg/dev/util-DvanW33H.js +20 -0
  103. package/dist/unpkg/dev/utils-BhvS1iTS.js +8 -0
  104. package/dist/unpkg/dev-deprecated/-private-DbaSCSym.js +1205 -0
  105. package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
  106. package/dist/unpkg/dev-deprecated/adapter/error.js +335 -0
  107. package/dist/unpkg/dev-deprecated/adapter/json-api.js +271 -0
  108. package/dist/unpkg/dev-deprecated/adapter/rest.js +1255 -0
  109. package/dist/unpkg/dev-deprecated/adapter.js +1252 -0
  110. package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
  111. package/dist/unpkg/dev-deprecated/compat/builders.js +275 -0
  112. package/dist/unpkg/dev-deprecated/compat/extensions.js +242 -0
  113. package/dist/unpkg/dev-deprecated/compat/utils.js +223 -0
  114. package/dist/unpkg/dev-deprecated/compat.js +1146 -0
  115. package/dist/unpkg/dev-deprecated/errors-DEnabIZj.js +2594 -0
  116. package/dist/unpkg/dev-deprecated/hooks-CAll-Ets.js +73 -0
  117. package/dist/unpkg/dev-deprecated/index.js +196 -0
  118. package/dist/unpkg/dev-deprecated/json-CCU-ZQ4b.js +1269 -0
  119. package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
  120. package/dist/unpkg/dev-deprecated/model/migration-support.js +568 -0
  121. package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
  122. package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
  123. package/dist/unpkg/dev-deprecated/model.js +682 -0
  124. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  125. package/dist/unpkg/dev-deprecated/schema-provider-k2qXQTBg.js +2254 -0
  126. package/dist/unpkg/dev-deprecated/serialize-into-hash-CPAZXrQU.js +259 -0
  127. package/dist/unpkg/dev-deprecated/serializer/json-api.js +648 -0
  128. package/dist/unpkg/dev-deprecated/serializer/json.js +4 -0
  129. package/dist/unpkg/dev-deprecated/serializer/rest.js +1242 -0
  130. package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
  131. package/dist/unpkg/dev-deprecated/serializer.js +248 -0
  132. package/dist/unpkg/dev-deprecated/store.js +636 -0
  133. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +24 -0
  134. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +12 -0
  135. package/dist/unpkg/prod/-private-Cvf_97EG.js +970 -0
  136. package/dist/unpkg/prod/adapter/-private.js +1 -0
  137. package/dist/unpkg/prod/adapter/error.js +330 -0
  138. package/dist/unpkg/prod/adapter/json-api.js +266 -0
  139. package/dist/unpkg/prod/adapter/rest.js +1218 -0
  140. package/dist/unpkg/prod/adapter.js +1219 -0
  141. package/dist/unpkg/prod/compat/-private.js +1 -0
  142. package/dist/unpkg/prod/compat/builders.js +210 -0
  143. package/dist/unpkg/prod/compat/extensions.js +232 -0
  144. package/dist/unpkg/prod/compat/utils.js +218 -0
  145. package/dist/unpkg/prod/compat.js +726 -0
  146. package/dist/unpkg/prod/errors-CXnfnBfQ.js +2343 -0
  147. package/dist/unpkg/prod/hooks-DvyWhLNg.js +41 -0
  148. package/dist/unpkg/prod/index.js +151 -0
  149. package/dist/unpkg/prod/json-BYrUP8ao.js +1256 -0
  150. package/dist/unpkg/prod/model/-private.js +1 -0
  151. package/dist/unpkg/prod/model/migration-support.js +544 -0
  152. package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
  153. package/dist/unpkg/prod/model-fragments.js +76 -0
  154. package/dist/unpkg/prod/model.js +593 -0
  155. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  156. package/dist/unpkg/prod/schema-provider-CHujJvA9.js +1904 -0
  157. package/dist/unpkg/prod/serialize-into-hash-DYU2egXl.js +215 -0
  158. package/dist/unpkg/prod/serializer/json-api.js +591 -0
  159. package/dist/unpkg/prod/serializer/json.js +4 -0
  160. package/dist/unpkg/prod/serializer/rest.js +1210 -0
  161. package/dist/unpkg/prod/serializer/transform.js +278 -0
  162. package/dist/unpkg/prod/serializer.js +248 -0
  163. package/dist/unpkg/prod/store.js +504 -0
  164. package/dist/unpkg/prod/util-DvanW33H.js +20 -0
  165. package/dist/unpkg/prod/utils-BhvS1iTS.js +8 -0
  166. package/dist/unpkg/prod-deprecated/-private-Cvf_97EG.js +970 -0
  167. package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
  168. package/dist/unpkg/prod-deprecated/adapter/error.js +330 -0
  169. package/dist/unpkg/prod-deprecated/adapter/json-api.js +266 -0
  170. package/dist/unpkg/prod-deprecated/adapter/rest.js +1218 -0
  171. package/dist/unpkg/prod-deprecated/adapter.js +1219 -0
  172. package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
  173. package/dist/unpkg/prod-deprecated/compat/builders.js +210 -0
  174. package/dist/unpkg/prod-deprecated/compat/extensions.js +232 -0
  175. package/dist/unpkg/prod-deprecated/compat/utils.js +218 -0
  176. package/dist/unpkg/prod-deprecated/compat.js +726 -0
  177. package/dist/unpkg/prod-deprecated/errors-CG1SPYVg.js +2346 -0
  178. package/dist/unpkg/prod-deprecated/hooks-BIUBiNGR.js +41 -0
  179. package/dist/unpkg/prod-deprecated/index.js +150 -0
  180. package/dist/unpkg/prod-deprecated/json-BYrUP8ao.js +1256 -0
  181. package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
  182. package/dist/unpkg/prod-deprecated/model/migration-support.js +561 -0
  183. package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
  184. package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
  185. package/dist/unpkg/prod-deprecated/model.js +596 -0
  186. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  187. package/dist/unpkg/prod-deprecated/schema-provider-BJ4TWnZf.js +1947 -0
  188. package/dist/unpkg/prod-deprecated/serialize-into-hash-DYU2egXl.js +215 -0
  189. package/dist/unpkg/prod-deprecated/serializer/json-api.js +591 -0
  190. package/dist/unpkg/prod-deprecated/serializer/json.js +4 -0
  191. package/dist/unpkg/prod-deprecated/serializer/rest.js +1210 -0
  192. package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
  193. package/dist/unpkg/prod-deprecated/serializer.js +248 -0
  194. package/dist/unpkg/prod-deprecated/store.js +504 -0
  195. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +23 -0
  196. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +11 -0
  197. package/logos/README.md +2 -2
  198. package/logos/logo-yellow-slab.svg +1 -0
  199. package/logos/word-mark-black.svg +1 -0
  200. package/logos/word-mark-white.svg +1 -0
  201. package/package.json +14 -6
  202. package/logos/NCC-1701-a-blue.svg +0 -4
  203. package/logos/NCC-1701-a-gold.svg +0 -4
  204. package/logos/NCC-1701-a-gold_100.svg +0 -1
  205. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  206. package/logos/NCC-1701-a.svg +0 -4
  207. package/logos/docs-badge.svg +0 -2
  208. package/logos/ember-data-logo-dark.svg +0 -12
  209. package/logos/ember-data-logo-light.svg +0 -12
  210. package/logos/social1.png +0 -0
  211. package/logos/social2.png +0 -0
  212. package/logos/warp-drive-logo-dark.svg +0 -4
  213. package/logos/warp-drive-logo-gold.svg +0 -4
@@ -2,7 +2,7 @@ import { Context } from '@warp-drive/core/reactive/-private';
2
2
  import { memoized, defineSignal, assertPrivateStore, defineNonEnumerableSignal, isResourceKey, recordIdentifierFor, isPrivateStore, storeFor, fastPush, createLegacyManyArray, notifyInternalSignal } from '@warp-drive/core/store/-private';
3
3
  import { getOrSetGlobal } from '@warp-drive/core/types/-private';
4
4
  import { EnableHydration } from '@warp-drive/core/types/request';
5
- import { u as upgradeStore } from "./-private-8UmnAf9J.js";
5
+ import { u as upgradeStore } from "./-private-B1pSSN52.js";
6
6
  import { computed, get } from '@ember/object';
7
7
  import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
8
8
  import ObjectProxy from '@ember/object/proxy';
@@ -344,11 +344,11 @@ function isResourceIdentiferWithRelatedLinks$1(value) {
344
344
  and manipulation of a hasMany relationship.
345
345
 
346
346
  It is especially useful when you're dealing with `async` relationships
347
- from `@ember-data/model` as it allows synchronous access to
347
+ from `@warp-drive/legacy/model` as it allows synchronous access to
348
348
  the relationship data if loaded, as well as APIs for loading, reloading
349
349
  the data or accessing available information without triggering a load.
350
350
 
351
- It may also be useful when using `sync` relationships with `@ember-data/model`
351
+ It may also be useful when using `sync` relationships with `@warp-drive/legacy/model`
352
352
  that need to be loaded/reloaded with more precise timing than marking the
353
353
  relationship as `async` and relying on autofetch would have allowed.
354
354
 
@@ -632,7 +632,7 @@ class HasManyReference {
632
632
  }
633
633
 
634
634
  /**
635
- `push` can be used to update the data in the relationship and EmberData
635
+ `push` can be used to update the data in the relationship and WarpDrive
636
636
  will treat the new data as the canonical value of this relationship on
637
637
  the backend. An empty array will signify the canonical value should be
638
638
  empty.
@@ -951,11 +951,11 @@ function isResourceIdentiferWithRelatedLinks(value) {
951
951
  and manipulation of a belongsTo relationship.
952
952
 
953
953
  It is especially useful when you're dealing with `async` relationships
954
- from `@ember-data/model` as it allows synchronous access to
954
+ from `@warp-drive/legacy/model` as it allows synchronous access to
955
955
  the relationship data if loaded, as well as APIs for loading, reloading
956
956
  the data or accessing available information without triggering a load.
957
957
 
958
- It may also be useful when using `sync` relationships with `@ember-data/model`
958
+ It may also be useful when using `sync` relationships with `@warp-drive/legacy/model`
959
959
  that need to be loaded/reloaded with more precise timing than marking the
960
960
  relationship as `async` and relying on autofetch would have allowed.
961
961
 
@@ -1194,7 +1194,7 @@ class BelongsToReference {
1194
1194
  use the "link" otherwise it defaults to "id".
1195
1195
  Example
1196
1196
  ```js [app/models/post.js]
1197
- import Model, { hasMany } from '@ember-data/model';
1197
+ import Model, { hasMany } from '@warp-drive/legacy/model';
1198
1198
  export default class PostModel extends Model {
1199
1199
  @hasMany('comment', { async: true, inverse: null }) comments;
1200
1200
  }
@@ -1231,7 +1231,7 @@ class BelongsToReference {
1231
1231
  }
1232
1232
 
1233
1233
  /**
1234
- `push` can be used to update the data in the relationship and EmberData
1234
+ `push` can be used to update the data in the relationship and WarpDrive
1235
1235
  will treat the new data as the canonical value of this relationship on
1236
1236
  the backend. A value of `null` (e.g. `{ data: null }`) can be passed to
1237
1237
  clear the relationship.
@@ -1430,7 +1430,7 @@ class BelongsToReference {
1430
1430
  });
1431
1431
  ```
1432
1432
  ```js [app/adapters/user.js]
1433
- import Adapter from '@ember-data/adapter';
1433
+ import Adapter from '@warp-drive/legacy/adapter';
1434
1434
  export default class UserAdapter extends Adapter {
1435
1435
  findRecord(store, type, id, snapshot) {
1436
1436
  // In the adapter you will have access to adapterOptions.
@@ -1581,28 +1581,31 @@ class LegacySupport {
1581
1581
  this.cache.mutate(mutation);
1582
1582
  }
1583
1583
  _findBelongsTo(key, resource, relationship, options) {
1584
+ const name = getRealFieldName(this, key);
1585
+
1584
1586
  // TODO @runspired follow up if parent isNew then we should not be attempting load here
1585
1587
  // TODO @runspired follow up on whether this should be in the relationship requests cache
1586
- return this._findBelongsToByJsonApiResource(resource, this.identifier, relationship, options).then(identifier => handleCompletedRelationshipRequest(this, key, relationship, identifier), e => handleCompletedRelationshipRequest(this, key, relationship, null, e));
1588
+ return this._findBelongsToByJsonApiResource(resource, this.identifier, relationship, options).then(identifier => handleCompletedRelationshipRequest(this, name, relationship, identifier), e => handleCompletedRelationshipRequest(this, name, relationship, null, e));
1587
1589
  }
1588
1590
  reloadBelongsTo(key, options) {
1589
1591
  const loadingPromise = this._relationshipPromisesCache[key];
1590
1592
  if (loadingPromise) {
1591
1593
  return loadingPromise;
1592
1594
  }
1593
- const relationship = this.graph.get(this.identifier, key);
1595
+ const name = getRealFieldName(this, key);
1596
+ const resource = this.store.cache.getRelationship(this.identifier, name);
1597
+ const relationship = this.graph.get(this.identifier, name);
1594
1598
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1595
1599
  if (!test) {
1596
- throw new Error(`Expected ${key} to be a belongs-to relationship`);
1600
+ throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
1597
1601
  }
1598
1602
  })(isBelongsTo(relationship)) : {};
1599
- const resource = this.cache.getRelationship(this.identifier, key);
1600
1603
  relationship.state.hasFailedLoadAttempt = false;
1601
1604
  relationship.state.shouldForceReload = true;
1602
- const promise = this._findBelongsTo(key, resource, relationship, options);
1603
- if (this._relationshipProxyCache[key]) {
1605
+ const promise = this._findBelongsTo(name, resource, relationship, options);
1606
+ if (this._relationshipProxyCache[name]) {
1604
1607
  // @ts-expect-error
1605
- return this._updatePromiseProxyFor('belongsTo', key, {
1608
+ return this._updatePromiseProxyFor('belongsTo', name, {
1606
1609
  promise
1607
1610
  });
1608
1611
  }
@@ -1610,10 +1613,10 @@ class LegacySupport {
1610
1613
  }
1611
1614
  getBelongsTo(key, options) {
1612
1615
  const {
1613
- identifier,
1614
- cache
1616
+ identifier
1615
1617
  } = this;
1616
- const resource = cache.getRelationship(this.identifier, key);
1618
+ const name = getRealFieldName(this, key);
1619
+ const resource = this.store.cache.getRelationship(this.identifier, name);
1617
1620
  const relatedIdentifier = resource && resource.data ? resource.data : null;
1618
1621
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1619
1622
  if (!test) {
@@ -1621,10 +1624,10 @@ class LegacySupport {
1621
1624
  }
1622
1625
  })(!relatedIdentifier || isResourceKey(relatedIdentifier)) : {};
1623
1626
  const store = this.store;
1624
- const relationship = this.graph.get(this.identifier, key);
1627
+ const relationship = this.graph.get(this.identifier, name);
1625
1628
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1626
1629
  if (!test) {
1627
- throw new Error(`Expected ${key} to be a belongs-to relationship`);
1630
+ throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
1628
1631
  }
1629
1632
  })(isBelongsTo(relationship)) : {};
1630
1633
  const isAsync = relationship.definition.isAsync;
@@ -1636,11 +1639,11 @@ class LegacySupport {
1636
1639
  };
1637
1640
  if (isAsync) {
1638
1641
  if (relationship.state.hasFailedLoadAttempt) {
1639
- return this._relationshipProxyCache[key];
1642
+ return this._relationshipProxyCache[name];
1640
1643
  }
1641
- const promise = this._findBelongsTo(key, resource, relationship, options);
1644
+ const promise = this._findBelongsTo(name, resource, relationship, options);
1642
1645
  const isLoaded = relatedIdentifier && store._instanceCache.recordIsLoaded(relatedIdentifier);
1643
- return this._updatePromiseProxyFor('belongsTo', key, {
1646
+ return this._updatePromiseProxyFor('belongsTo', name, {
1644
1647
  promise,
1645
1648
  content: isLoaded ? store._instanceCache.getRecord(relatedIdentifier) : null,
1646
1649
  _belongsToState
@@ -1651,7 +1654,7 @@ class LegacySupport {
1651
1654
  } else {
1652
1655
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1653
1656
  if (!test) {
1654
- throw new Error(`You looked up the '${key}' relationship on a '${identifier.type}' with id ${identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (\`belongsTo(<type>, { async: true, inverse: <inverse> })\`)`);
1657
+ throw new Error(`You looked up the '${key === name ? name : `${key} (source: ${name})`}' relationship on a '${identifier.type}' with id ${identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (\`belongsTo(<type>, { async: true, inverse: <inverse> })\`)`);
1655
1658
  }
1656
1659
  })(store._instanceCache.recordIsLoaded(relatedIdentifier, true)) : {};
1657
1660
  return store._instanceCache.getRecord(relatedIdentifier);
@@ -1659,10 +1662,11 @@ class LegacySupport {
1659
1662
  }
1660
1663
  }
1661
1664
  setDirtyBelongsTo(key, value) {
1665
+ const name = getRealFieldName(this, key);
1662
1666
  return this.cache.mutate({
1663
1667
  op: 'replaceRelatedRecord',
1664
1668
  record: this.identifier,
1665
- field: key,
1669
+ field: name,
1666
1670
  value: extractIdentifierFromRecord(value)
1667
1671
  },
1668
1672
  // @ts-expect-error
@@ -1688,13 +1692,15 @@ class LegacySupport {
1688
1692
  return [identifiers, jsonApi];
1689
1693
  }
1690
1694
  getManyArray(key, definition) {
1695
+ const name = getRealFieldName(this, key);
1691
1696
  if (this.graph) {
1692
- let manyArray = this._manyArrayCache[key];
1697
+ let manyArray = this._manyArrayCache[name];
1693
1698
  if (!definition) {
1694
- definition = this.graph.get(this.identifier, key).definition;
1699
+ definition = this.graph.get(this.identifier, name).definition;
1695
1700
  }
1696
1701
  if (!manyArray) {
1697
- const [identifiers, doc] = this._getCurrentState(this.identifier, key);
1702
+ const [identifiers, doc] = this._getCurrentState(this.identifier, name);
1703
+ const field = getField(this, name);
1698
1704
  manyArray = createLegacyManyArray({
1699
1705
  store: this.store,
1700
1706
  // @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
@@ -1705,60 +1711,62 @@ class LegacySupport {
1705
1711
  editable: true,
1706
1712
  isAsync: definition.isAsync,
1707
1713
  isPolymorphic: definition.isPolymorphic,
1708
- field: this.store.schema.fields(this.identifier).get(key),
1714
+ field: field,
1709
1715
  identifier: this.identifier,
1710
1716
  links: doc.links || null,
1711
1717
  meta: doc.meta || null
1712
1718
  });
1713
- this._manyArrayCache[key] = manyArray;
1719
+ this._manyArrayCache[name] = manyArray;
1714
1720
  }
1715
1721
  return manyArray;
1716
1722
  }
1717
1723
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1718
1724
  {
1719
- throw new Error('hasMany only works with the @ember-data/json-api package');
1725
+ throw new Error('hasMany only works with the JSONAPICache');
1720
1726
  }
1721
1727
  })() : {};
1722
1728
  }
1723
1729
  fetchAsyncHasMany(key, relationship, manyArray, options) {
1730
+ const name = getRealFieldName(this, key);
1724
1731
  if (this.graph) {
1725
- let loadingPromise = this._relationshipPromisesCache[key];
1732
+ let loadingPromise = this._relationshipPromisesCache[name];
1726
1733
  if (loadingPromise) {
1727
1734
  return loadingPromise;
1728
1735
  }
1729
- const jsonApi = this.cache.getRelationship(this.identifier, key);
1736
+ const jsonApi = this.cache.getRelationship(this.identifier, name);
1730
1737
  const promise = this._findHasManyByJsonApiResource(jsonApi, this.identifier, relationship, options);
1731
1738
  if (!promise) {
1732
1739
  manyArray.isLoaded = true;
1733
1740
  return Promise.resolve(manyArray);
1734
1741
  }
1735
- loadingPromise = promise.then(() => handleCompletedRelationshipRequest(this, key, relationship, manyArray), e => handleCompletedRelationshipRequest(this, key, relationship, manyArray, e));
1736
- this._relationshipPromisesCache[key] = loadingPromise;
1742
+ loadingPromise = promise.then(() => handleCompletedRelationshipRequest(this, name, relationship, manyArray), e => handleCompletedRelationshipRequest(this, name, relationship, manyArray, e));
1743
+ this._relationshipPromisesCache[name] = loadingPromise;
1737
1744
  return loadingPromise;
1738
1745
  }
1739
1746
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1740
1747
  {
1741
- throw new Error('hasMany only works with the @ember-data/json-api package');
1748
+ throw new Error('hasMany only works with the JSONAPICache');
1742
1749
  }
1743
1750
  })() : {};
1744
1751
  }
1745
1752
  reloadHasMany(key, options) {
1753
+ const name = getRealFieldName(this, key);
1746
1754
  if (this.graph) {
1747
- const loadingPromise = this._relationshipPromisesCache[key];
1755
+ const loadingPromise = this._relationshipPromisesCache[name];
1748
1756
  if (loadingPromise) {
1749
1757
  return loadingPromise;
1750
1758
  }
1751
- const relationship = this.graph.get(this.identifier, key);
1759
+ const relationship = this.graph.get(this.identifier, name);
1752
1760
  const {
1753
1761
  definition,
1754
1762
  state
1755
1763
  } = relationship;
1756
1764
  state.hasFailedLoadAttempt = false;
1757
1765
  state.shouldForceReload = true;
1758
- const manyArray = this.getManyArray(key, definition);
1759
- const promise = this.fetchAsyncHasMany(key, relationship, manyArray, options);
1760
- if (this._relationshipProxyCache[key]) {
1761
- return this._updatePromiseProxyFor('hasMany', key, {
1766
+ const manyArray = this.getManyArray(name, definition);
1767
+ const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
1768
+ if (this._relationshipProxyCache[name]) {
1769
+ return this._updatePromiseProxyFor('hasMany', name, {
1762
1770
  promise
1763
1771
  });
1764
1772
  }
@@ -1766,31 +1774,32 @@ class LegacySupport {
1766
1774
  }
1767
1775
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1768
1776
  {
1769
- throw new Error(`hasMany only works with the @ember-data/json-api package`);
1777
+ throw new Error(`hasMany only works with the JSONAPICache`);
1770
1778
  }
1771
1779
  })() : {};
1772
1780
  }
1773
1781
  getHasMany(key, options) {
1782
+ const name = getRealFieldName(this, key);
1774
1783
  if (this.graph) {
1775
- const relationship = this.graph.get(this.identifier, key);
1784
+ const relationship = this.graph.get(this.identifier, name);
1776
1785
  const {
1777
1786
  definition,
1778
1787
  state
1779
1788
  } = relationship;
1780
- const manyArray = this.getManyArray(key, definition);
1789
+ const manyArray = this.getManyArray(name, definition);
1781
1790
  if (definition.isAsync) {
1782
1791
  if (state.hasFailedLoadAttempt) {
1783
- return this._relationshipProxyCache[key];
1792
+ return this._relationshipProxyCache[name];
1784
1793
  }
1785
- const promise = this.fetchAsyncHasMany(key, relationship, manyArray, options);
1786
- return this._updatePromiseProxyFor('hasMany', key, {
1794
+ const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
1795
+ return this._updatePromiseProxyFor('hasMany', name, {
1787
1796
  promise,
1788
1797
  content: manyArray
1789
1798
  });
1790
1799
  } else {
1791
1800
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1792
1801
  if (!test) {
1793
- throw new Error(`You looked up the '${key}' relationship on a '${this.identifier.type}' with id ${this.identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async ('hasMany(<type>, { async: true, inverse: <inverse> })')`);
1802
+ throw new Error(`You looked up the '${key === name ? name : `${key} (source: ${name})`}' relationship on a '${this.identifier.type}' with id ${this.identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async ('hasMany(<type>, { async: true, inverse: <inverse> })')`);
1794
1803
  }
1795
1804
  })(!anyUnloaded(this.store, relationship)) : {};
1796
1805
  return manyArray;
@@ -1798,7 +1807,7 @@ class LegacySupport {
1798
1807
  }
1799
1808
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1800
1809
  {
1801
- throw new Error(`hasMany only works with the @ember-data/json-api package`);
1810
+ throw new Error(`hasMany only works with the JSONAPICache`);
1802
1811
  }
1803
1812
  })() : {};
1804
1813
  }
@@ -1841,7 +1850,8 @@ class LegacySupport {
1841
1850
  }
1842
1851
  return promiseProxy;
1843
1852
  }
1844
- referenceFor(kind, name) {
1853
+ referenceFor(kind, key) {
1854
+ const name = getRealFieldName(this, key);
1845
1855
  let reference = this.references[name];
1846
1856
  if (!reference) {
1847
1857
  if (!this.graph) {
@@ -1850,7 +1860,7 @@ class LegacySupport {
1850
1860
  // because of the intimate API access involved. This is something we will need to redesign.
1851
1861
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1852
1862
  {
1853
- throw new Error(`snapshot.belongsTo only supported for @ember-data/json-api`);
1863
+ throw new Error(`snapshot.belongsTo only supported when using the JSONAPICache`);
1854
1864
  }
1855
1865
  })() : {};
1856
1866
  }
@@ -1865,16 +1875,16 @@ class LegacySupport {
1865
1875
  const actualRelationshipKind = relationship.definition.kind;
1866
1876
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1867
1877
  if (!test) {
1868
- throw new Error(`You tried to get the '${name}' relationship on a '${modelName}' via record.${kind}('${name}'), but the relationship is of kind '${actualRelationshipKind}'. Use record.${actualRelationshipKind}('${name}') instead.`);
1878
+ throw new Error(`You tried to get the '${key === name ? name : `${key} (source: ${name})`}' relationship on a '${modelName}' via record.${kind}('${key}'), but the relationship is of kind '${actualRelationshipKind}'. Use record.${actualRelationshipKind}('${key}') instead.`);
1869
1879
  }
1870
1880
  })(actualRelationshipKind === kind) : {};
1871
1881
  }
1872
1882
  }
1873
1883
  const relationshipKind = relationship.definition.kind;
1874
1884
  if (relationshipKind === 'belongsTo') {
1875
- reference = new BelongsToReference(this.store, graph, identifier, relationship, name);
1885
+ reference = new BelongsToReference(this.store, graph, identifier, relationship, key);
1876
1886
  } else if (relationshipKind === 'hasMany') {
1877
- reference = new HasManyReference(this.store, graph, identifier, relationship, name);
1887
+ reference = new HasManyReference(this.store, graph, identifier, relationship, key);
1878
1888
  }
1879
1889
  this.references[name] = reference;
1880
1890
  }
@@ -1982,7 +1992,7 @@ class LegacySupport {
1982
1992
  }
1983
1993
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1984
1994
  {
1985
- throw new Error(`hasMany only works with the @ember-data/json-api package`);
1995
+ throw new Error(`hasMany only works with the JSONAPICache`);
1986
1996
  }
1987
1997
  })() : {};
1988
1998
  }
@@ -1991,12 +2001,13 @@ class LegacySupport {
1991
2001
  return Promise.resolve(null);
1992
2002
  }
1993
2003
  const key = relationship.definition.key;
2004
+ const name = getRealFieldName(this, key);
1994
2005
 
1995
2006
  // interleaved promises mean that we MUST cache this here
1996
2007
  // in order to prevent infinite re-render if the request
1997
2008
  // fails.
1998
- if (this._pending[key]) {
1999
- return this._pending[key];
2009
+ if (this._pending[name]) {
2010
+ return this._pending[name];
2000
2011
  }
2001
2012
  const identifier = resource.data ? resource.data : null;
2002
2013
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
@@ -2046,10 +2057,10 @@ class LegacySupport {
2046
2057
  }
2047
2058
  };
2048
2059
  const future = this.store.request(req);
2049
- this._pending[key] = future.then(doc => field.options.linksMode ? doc.content.data : doc.content).finally(() => {
2050
- this._pending[key] = undefined;
2060
+ this._pending[name] = future.then(doc => field.options.linksMode ? doc.content.data : doc.content).finally(() => {
2061
+ this._pending[name] = undefined;
2051
2062
  });
2052
- return this._pending[key];
2063
+ return this._pending[name];
2053
2064
  }
2054
2065
  const preferLocalCache = hasReceivedData && allInverseRecordsAreLoaded && !isEmpty;
2055
2066
  const hasLocalPartialData = hasDematerializedInverse || isEmpty && resource.data;
@@ -2076,7 +2087,7 @@ class LegacySupport {
2076
2087
  }
2077
2088
  })(identifier) : {};
2078
2089
  options.reload = options.reload || !attemptLocalCache || undefined;
2079
- this._pending[key] = this.store.request({
2090
+ this._pending[name] = this.store.request({
2080
2091
  op: 'findBelongsTo',
2081
2092
  records: [identifier],
2082
2093
  data: request,
@@ -2084,9 +2095,9 @@ class LegacySupport {
2084
2095
  [Symbol.for('wd:skip-cache')]: true
2085
2096
  }
2086
2097
  }).then(doc => doc.content).finally(() => {
2087
- this._pending[key] = undefined;
2098
+ this._pending[name] = undefined;
2088
2099
  });
2089
- return this._pending[key];
2100
+ return this._pending[name];
2090
2101
  }
2091
2102
 
2092
2103
  // we were explicitly told we have no data and no links.
@@ -2213,6 +2224,17 @@ function areAllInverseRecordsLoaded(store, resource) {
2213
2224
  function isBelongsTo(relationship) {
2214
2225
  return relationship.definition.kind === 'belongsTo';
2215
2226
  }
2227
+ function getField(context, key) {
2228
+ const {
2229
+ identifier,
2230
+ store
2231
+ } = context;
2232
+ return store.schema.fields(identifier).get(key) ?? store.schema.cacheFields?.(identifier).get(key);
2233
+ }
2234
+ function getRealFieldName(context, key) {
2235
+ const field = getField(context, key);
2236
+ return field ? field.sourceKey ?? field.name : key;
2237
+ }
2216
2238
 
2217
2239
  // we force the type here to our own construct because mixin and extend patterns
2218
2240
  // lose generic signatures. We also do this because we need to Omit `clear` from
@@ -0,0 +1,74 @@
1
+ import { setOwner, getOwner } from '@ember/application';
2
+ import { assertPrivateStore, setRecordIdentifier, StoreMap } from '@warp-drive/core/store/-private';
3
+ import { g as getModelFactory } from "./schema-provider-g5MfTj8n.js";
4
+ import { n as normalizeModelName } from "./util-Dul6TZts.js";
5
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
+ function instantiateRecord(identifier, createRecordArgs) {
7
+ const type = identifier.type;
8
+
9
+ // TODO deprecate allowing unknown args setting
10
+ const createOptions = {
11
+ _createProps: createRecordArgs ?? {},
12
+ // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
13
+ _secretInit: {
14
+ identifier,
15
+ store: this,
16
+ cb: secretInit
17
+ }
18
+ };
19
+
20
+ // ensure that `getOwner(this)` works inside a model instance
21
+ setOwner(createOptions, getOwner(this));
22
+ const factory = getModelFactory(this, type);
23
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
24
+ if (!test) {
25
+ throw new Error(`No model was found for '${type}'`);
26
+ }
27
+ })(factory) : {};
28
+ return factory.class.create(createOptions);
29
+ }
30
+ function teardownRecord(record) {
31
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
32
+ if (!test) {
33
+ throw new Error(`expected to receive an instance of Model from @ember-data/model. If using a custom model make sure you implement teardownRecord`);
34
+ }
35
+ })('destroy' in record) : {};
36
+ record.destroy();
37
+ }
38
+ function modelFor(modelName) {
39
+ assertPrivateStore(this);
40
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
41
+ if (!test) {
42
+ throw new Error(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`);
43
+ }
44
+ })(!this.isDestroyed && !this.isDestroying) : {};
45
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
46
+ if (!test) {
47
+ throw new Error(`You need to pass a model name to the store's modelFor method`);
48
+ }
49
+ })(modelName) : {};
50
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
51
+ if (!test) {
52
+ throw new Error(`Please pass a proper model name to the store's modelFor method`);
53
+ }
54
+ })(typeof modelName === 'string' && modelName.length) : {};
55
+ const type = normalizeModelName(modelName);
56
+ const maybeFactory = getModelFactory(this, type);
57
+ const klass = maybeFactory && maybeFactory.class ? maybeFactory.class : null;
58
+ const ignoreType = !klass || !klass.isModel || this._forceShim;
59
+ if (!ignoreType) {
60
+ return klass;
61
+ }
62
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
63
+ if (!test) {
64
+ throw new Error(`No model was found for '${type}' and no schema handles the type`);
65
+ }
66
+ })(this.schema.hasResource({
67
+ type
68
+ })) : {};
69
+ }
70
+ function secretInit(record, identifier, store) {
71
+ setRecordIdentifier(record, identifier);
72
+ StoreMap.set(record, store);
73
+ }
74
+ export { instantiateRecord as i, modelFor as m, teardownRecord as t };