@warp-drive/legacy 5.8.0-alpha.30 → 5.8.0-alpha.34

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 (477) hide show
  1. package/declarations/adapter/error.d.ts +5 -5
  2. package/declarations/adapter/json-api.d.ts +2 -2
  3. package/declarations/compat/builders/find-all.d.ts +6 -6
  4. package/declarations/compat/builders/find-record.d.ts +8 -8
  5. package/declarations/compat/builders/query.d.ts +12 -12
  6. package/declarations/compat.d.ts +3 -3
  7. package/declarations/model/-private/references/belongs-to.d.ts +4 -4
  8. package/declarations/model/-private/references/has-many.d.ts +2 -2
  9. package/declarations/model/migration-support.d.ts +34 -18
  10. package/declarations/model.d.ts +2 -2
  11. package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -1
  12. package/declarations/serializer/json-api.d.ts +3 -3
  13. package/declarations/serializer/json.d.ts +1 -1
  14. package/declarations/serializer.d.ts +1 -1
  15. package/dist/adapter/error.js +7 -7
  16. package/dist/compat/builders.js +26 -26
  17. package/dist/compat/utils.js +0 -1
  18. package/dist/compat.js +3 -3
  19. package/dist/{errors-B9CDPh3R.js → errors-CIGPcDvd.js} +12 -12
  20. package/dist/{hooks-CQXyievu.js → hooks-QqRnX108.js} +1 -1
  21. package/dist/index.js +4 -4
  22. package/dist/{json-BHxlccxF.js → json-BNrV8EYG.js} +4 -4
  23. package/dist/model/-private.js +1 -1
  24. package/dist/model/migration-support.js +41 -24
  25. package/dist/{model-for-B0TSd9HU.js → model-for-CqXsIKws.js} +1 -1
  26. package/dist/model-fragments.js +2 -2
  27. package/dist/model.js +3 -3
  28. package/dist/{schema-provider-BnVr_CnJ.js → schema-provider-g5MfTj8n.js} +11 -11
  29. package/dist/serializer/json-api.js +7 -7
  30. package/dist/serializer/json.js +1 -1
  31. package/dist/serializer/rest.js +10 -10
  32. package/dist/serializer.js +1 -1
  33. package/dist/unpkg/dev/-private-B1pSSN52.js +1210 -0
  34. package/dist/unpkg/dev/adapter/-private.js +1 -0
  35. package/dist/unpkg/dev/adapter/error.js +336 -0
  36. package/dist/unpkg/dev/adapter/json-api.js +132 -0
  37. package/dist/unpkg/dev/adapter/rest.js +1257 -0
  38. package/dist/unpkg/dev/adapter.js +1253 -0
  39. package/dist/unpkg/dev/compat/-private.js +1 -0
  40. package/dist/unpkg/dev/compat/builders.js +273 -0
  41. package/dist/unpkg/dev/compat/extensions.js +243 -0
  42. package/dist/unpkg/dev/compat/utils.js +224 -0
  43. package/dist/unpkg/dev/compat.js +1020 -0
  44. package/dist/unpkg/dev/declarations/adapter/-private/build-url-mixin.d.ts +33 -0
  45. package/dist/unpkg/dev/declarations/adapter/-private/fastboot-interface.d.ts +8 -0
  46. package/dist/unpkg/dev/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -0
  47. package/dist/unpkg/dev/declarations/adapter/-private/utils/determine-body-promise.d.ts +4 -0
  48. package/dist/unpkg/dev/declarations/adapter/-private/utils/fetch.d.ts +8 -0
  49. package/dist/unpkg/dev/declarations/adapter/-private/utils/parse-response-headers.d.ts +1 -0
  50. package/dist/unpkg/dev/declarations/adapter/-private/utils/serialize-into-hash.d.ts +6 -0
  51. package/dist/unpkg/dev/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -0
  52. package/dist/unpkg/dev/declarations/adapter/-private.d.ts +5 -0
  53. package/dist/unpkg/dev/declarations/adapter/error.d.ts +215 -0
  54. package/dist/unpkg/dev/declarations/adapter/json-api.d.ts +231 -0
  55. package/dist/unpkg/dev/declarations/adapter/rest.d.ts +815 -0
  56. package/dist/unpkg/dev/declarations/adapter.d.ts +770 -0
  57. package/dist/unpkg/dev/declarations/compat/-private.d.ts +13 -0
  58. package/dist/unpkg/dev/declarations/compat/builders/find-all.d.ts +35 -0
  59. package/dist/unpkg/dev/declarations/compat/builders/find-record.d.ts +56 -0
  60. package/dist/unpkg/dev/declarations/compat/builders/query.d.ts +66 -0
  61. package/dist/unpkg/dev/declarations/compat/builders/save-record.d.ts +34 -0
  62. package/dist/unpkg/dev/declarations/compat/builders/utils.d.ts +3 -0
  63. package/dist/unpkg/dev/declarations/compat/builders.d.ts +14 -0
  64. package/dist/unpkg/dev/declarations/compat/extensions.d.ts +59 -0
  65. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/fetch-manager.d.ts +55 -0
  66. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -0
  67. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +11 -0
  68. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +5 -0
  69. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +2 -0
  70. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +524 -0
  71. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +213 -0
  72. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/serializer-response.d.ts +6 -0
  73. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +110 -0
  74. package/dist/unpkg/dev/declarations/compat/legacy-network-handler/snapshot.d.ts +255 -0
  75. package/dist/unpkg/dev/declarations/compat/utils.d.ts +137 -0
  76. package/dist/unpkg/dev/declarations/compat.d.ts +157 -0
  77. package/dist/unpkg/dev/declarations/index.d.ts +70 -0
  78. package/dist/unpkg/dev/declarations/model/-private/attr.d.ts +170 -0
  79. package/dist/unpkg/dev/declarations/model/-private/belongs-to.d.ts +174 -0
  80. package/dist/unpkg/dev/declarations/model/-private/debug/assert-polymorphic-type.d.ts +5 -0
  81. package/dist/unpkg/dev/declarations/model/-private/errors.d.ts +289 -0
  82. package/dist/unpkg/dev/declarations/model/-private/has-many.d.ts +162 -0
  83. package/dist/unpkg/dev/declarations/model/-private/hooks.d.ts +10 -0
  84. package/dist/unpkg/dev/declarations/model/-private/legacy-relationships-support.d.ts +47 -0
  85. package/dist/unpkg/dev/declarations/model/-private/model-for-mixin.d.ts +3 -0
  86. package/dist/unpkg/dev/declarations/model/-private/model-methods.d.ts +39 -0
  87. package/dist/unpkg/dev/declarations/model/-private/model.d.ts +1269 -0
  88. package/dist/unpkg/dev/declarations/model/-private/notify-changes.d.ts +4 -0
  89. package/dist/unpkg/dev/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  90. package/dist/unpkg/dev/declarations/model/-private/promise-many-array.d.ts +124 -0
  91. package/dist/unpkg/dev/declarations/model/-private/record-state.d.ts +58 -0
  92. package/dist/unpkg/dev/declarations/model/-private/references/belongs-to.d.ts +498 -0
  93. package/dist/unpkg/dev/declarations/model/-private/references/has-many.d.ts +500 -0
  94. package/dist/unpkg/dev/declarations/model/-private/schema-provider.d.ts +56 -0
  95. package/dist/unpkg/dev/declarations/model/-private/type-utils.d.ts +57 -0
  96. package/dist/unpkg/dev/declarations/model/-private/util.d.ts +5 -0
  97. package/dist/unpkg/dev/declarations/model/-private.d.ts +8 -0
  98. package/dist/unpkg/dev/declarations/model/migration-support.d.ts +280 -0
  99. package/dist/unpkg/dev/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  100. package/dist/unpkg/dev/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  101. package/dist/unpkg/dev/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  102. package/dist/unpkg/dev/declarations/model-fragments/index.d.ts +5 -0
  103. package/dist/unpkg/dev/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  104. package/dist/unpkg/dev/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  105. package/dist/unpkg/dev/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  106. package/dist/unpkg/dev/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  107. package/dist/unpkg/dev/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  108. package/dist/unpkg/dev/declarations/model-fragments.d.ts +9 -0
  109. package/dist/unpkg/dev/declarations/model.d.ts +49 -0
  110. package/dist/unpkg/dev/declarations/serializer/-private/embedded-records-mixin.d.ts +91 -0
  111. package/dist/unpkg/dev/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  112. package/dist/unpkg/dev/declarations/serializer/-private/transforms/date.d.ts +28 -0
  113. package/dist/unpkg/dev/declarations/serializer/-private/transforms/number.d.ts +29 -0
  114. package/dist/unpkg/dev/declarations/serializer/-private/transforms/string.d.ts +29 -0
  115. package/dist/unpkg/dev/declarations/serializer/-private/transforms/transform.d.ts +118 -0
  116. package/dist/unpkg/dev/declarations/serializer/-private/utils.d.ts +3 -0
  117. package/dist/unpkg/dev/declarations/serializer/json-api.d.ts +123 -0
  118. package/dist/unpkg/dev/declarations/serializer/json.d.ts +75 -0
  119. package/dist/unpkg/dev/declarations/serializer/rest.d.ts +51 -0
  120. package/dist/unpkg/dev/declarations/serializer/transform.d.ts +5 -0
  121. package/dist/unpkg/dev/declarations/serializer.d.ts +254 -0
  122. package/dist/unpkg/dev/declarations/store/-private.d.ts +223 -0
  123. package/dist/unpkg/dev/declarations/store.d.ts +3 -0
  124. package/dist/unpkg/dev/errors-CIGPcDvd.js +2595 -0
  125. package/dist/unpkg/dev/hooks-QqRnX108.js +74 -0
  126. package/dist/unpkg/dev/index.js +195 -0
  127. package/dist/unpkg/dev/json-BNrV8EYG.js +1272 -0
  128. package/dist/unpkg/dev/model/-private.js +1 -0
  129. package/dist/unpkg/dev/model/migration-support.js +579 -0
  130. package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
  131. package/dist/unpkg/dev/model-fragments.js +76 -0
  132. package/dist/unpkg/dev/model.js +667 -0
  133. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  134. package/dist/unpkg/dev/schema-provider-g5MfTj8n.js +2338 -0
  135. package/dist/unpkg/dev/serialize-into-hash-BnYvPex3.js +261 -0
  136. package/dist/unpkg/dev/serializer/json-api.js +527 -0
  137. package/dist/unpkg/dev/serializer/json.js +6 -0
  138. package/dist/unpkg/dev/serializer/rest.js +1243 -0
  139. package/dist/unpkg/dev/serializer/transform.js +278 -0
  140. package/dist/unpkg/dev/serializer.js +248 -0
  141. package/dist/unpkg/dev/store.js +636 -0
  142. package/dist/unpkg/dev/util-Dul6TZts.js +35 -0
  143. package/dist/unpkg/dev/utils-Cqw9eRj5.js +23 -0
  144. package/dist/unpkg/dev-deprecated/-private-B1pSSN52.js +1210 -0
  145. package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
  146. package/dist/unpkg/dev-deprecated/adapter/error.js +336 -0
  147. package/dist/unpkg/dev-deprecated/adapter/json-api.js +132 -0
  148. package/dist/unpkg/dev-deprecated/adapter/rest.js +1257 -0
  149. package/dist/unpkg/dev-deprecated/adapter.js +1253 -0
  150. package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
  151. package/dist/unpkg/dev-deprecated/compat/builders.js +273 -0
  152. package/dist/unpkg/dev-deprecated/compat/extensions.js +243 -0
  153. package/dist/unpkg/dev-deprecated/compat/utils.js +224 -0
  154. package/dist/unpkg/dev-deprecated/compat.js +1020 -0
  155. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/build-url-mixin.d.ts +33 -0
  156. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/fastboot-interface.d.ts +8 -0
  157. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -0
  158. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/determine-body-promise.d.ts +4 -0
  159. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/fetch.d.ts +8 -0
  160. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/parse-response-headers.d.ts +1 -0
  161. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/serialize-into-hash.d.ts +6 -0
  162. package/dist/unpkg/dev-deprecated/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -0
  163. package/dist/unpkg/dev-deprecated/declarations/adapter/-private.d.ts +5 -0
  164. package/dist/unpkg/dev-deprecated/declarations/adapter/error.d.ts +215 -0
  165. package/dist/unpkg/dev-deprecated/declarations/adapter/json-api.d.ts +231 -0
  166. package/dist/unpkg/dev-deprecated/declarations/adapter/rest.d.ts +815 -0
  167. package/dist/unpkg/dev-deprecated/declarations/adapter.d.ts +770 -0
  168. package/dist/unpkg/dev-deprecated/declarations/compat/-private.d.ts +13 -0
  169. package/dist/unpkg/dev-deprecated/declarations/compat/builders/find-all.d.ts +35 -0
  170. package/dist/unpkg/dev-deprecated/declarations/compat/builders/find-record.d.ts +56 -0
  171. package/dist/unpkg/dev-deprecated/declarations/compat/builders/query.d.ts +66 -0
  172. package/dist/unpkg/dev-deprecated/declarations/compat/builders/save-record.d.ts +34 -0
  173. package/dist/unpkg/dev-deprecated/declarations/compat/builders/utils.d.ts +3 -0
  174. package/dist/unpkg/dev-deprecated/declarations/compat/builders.d.ts +14 -0
  175. package/dist/unpkg/dev-deprecated/declarations/compat/extensions.d.ts +59 -0
  176. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/fetch-manager.d.ts +55 -0
  177. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -0
  178. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +11 -0
  179. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +5 -0
  180. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +2 -0
  181. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +524 -0
  182. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +213 -0
  183. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/serializer-response.d.ts +6 -0
  184. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +110 -0
  185. package/dist/unpkg/dev-deprecated/declarations/compat/legacy-network-handler/snapshot.d.ts +255 -0
  186. package/dist/unpkg/dev-deprecated/declarations/compat/utils.d.ts +137 -0
  187. package/dist/unpkg/dev-deprecated/declarations/compat.d.ts +157 -0
  188. package/dist/unpkg/dev-deprecated/declarations/index.d.ts +70 -0
  189. package/dist/unpkg/dev-deprecated/declarations/model/-private/attr.d.ts +170 -0
  190. package/dist/unpkg/dev-deprecated/declarations/model/-private/belongs-to.d.ts +174 -0
  191. package/dist/unpkg/dev-deprecated/declarations/model/-private/debug/assert-polymorphic-type.d.ts +5 -0
  192. package/dist/unpkg/dev-deprecated/declarations/model/-private/errors.d.ts +289 -0
  193. package/dist/unpkg/dev-deprecated/declarations/model/-private/has-many.d.ts +162 -0
  194. package/dist/unpkg/dev-deprecated/declarations/model/-private/hooks.d.ts +10 -0
  195. package/dist/unpkg/dev-deprecated/declarations/model/-private/legacy-relationships-support.d.ts +47 -0
  196. package/dist/unpkg/dev-deprecated/declarations/model/-private/model-for-mixin.d.ts +3 -0
  197. package/dist/unpkg/dev-deprecated/declarations/model/-private/model-methods.d.ts +39 -0
  198. package/dist/unpkg/dev-deprecated/declarations/model/-private/model.d.ts +1269 -0
  199. package/dist/unpkg/dev-deprecated/declarations/model/-private/notify-changes.d.ts +4 -0
  200. package/dist/unpkg/dev-deprecated/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  201. package/dist/unpkg/dev-deprecated/declarations/model/-private/promise-many-array.d.ts +124 -0
  202. package/dist/unpkg/dev-deprecated/declarations/model/-private/record-state.d.ts +58 -0
  203. package/dist/unpkg/dev-deprecated/declarations/model/-private/references/belongs-to.d.ts +498 -0
  204. package/dist/unpkg/dev-deprecated/declarations/model/-private/references/has-many.d.ts +500 -0
  205. package/dist/unpkg/dev-deprecated/declarations/model/-private/schema-provider.d.ts +56 -0
  206. package/dist/unpkg/dev-deprecated/declarations/model/-private/type-utils.d.ts +57 -0
  207. package/dist/unpkg/dev-deprecated/declarations/model/-private/util.d.ts +5 -0
  208. package/dist/unpkg/dev-deprecated/declarations/model/-private.d.ts +8 -0
  209. package/dist/unpkg/dev-deprecated/declarations/model/migration-support.d.ts +280 -0
  210. package/dist/unpkg/dev-deprecated/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  211. package/dist/unpkg/dev-deprecated/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  212. package/dist/unpkg/dev-deprecated/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  213. package/dist/unpkg/dev-deprecated/declarations/model-fragments/index.d.ts +5 -0
  214. package/dist/unpkg/dev-deprecated/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  215. package/dist/unpkg/dev-deprecated/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  216. package/dist/unpkg/dev-deprecated/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  217. package/dist/unpkg/dev-deprecated/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  218. package/dist/unpkg/dev-deprecated/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  219. package/dist/unpkg/dev-deprecated/declarations/model-fragments.d.ts +9 -0
  220. package/dist/unpkg/dev-deprecated/declarations/model.d.ts +49 -0
  221. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/embedded-records-mixin.d.ts +91 -0
  222. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  223. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/date.d.ts +28 -0
  224. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/number.d.ts +29 -0
  225. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/string.d.ts +29 -0
  226. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/transforms/transform.d.ts +118 -0
  227. package/dist/unpkg/dev-deprecated/declarations/serializer/-private/utils.d.ts +3 -0
  228. package/dist/unpkg/dev-deprecated/declarations/serializer/json-api.d.ts +123 -0
  229. package/dist/unpkg/dev-deprecated/declarations/serializer/json.d.ts +75 -0
  230. package/dist/unpkg/dev-deprecated/declarations/serializer/rest.d.ts +51 -0
  231. package/dist/unpkg/dev-deprecated/declarations/serializer/transform.d.ts +5 -0
  232. package/dist/unpkg/dev-deprecated/declarations/serializer.d.ts +254 -0
  233. package/dist/unpkg/dev-deprecated/declarations/store/-private.d.ts +223 -0
  234. package/dist/unpkg/dev-deprecated/declarations/store.d.ts +3 -0
  235. package/dist/unpkg/dev-deprecated/errors-CIGPcDvd.js +2595 -0
  236. package/dist/unpkg/dev-deprecated/hooks-QqRnX108.js +74 -0
  237. package/dist/unpkg/dev-deprecated/index.js +195 -0
  238. package/dist/unpkg/dev-deprecated/json-BNrV8EYG.js +1272 -0
  239. package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
  240. package/dist/unpkg/dev-deprecated/model/migration-support.js +579 -0
  241. package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
  242. package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
  243. package/dist/unpkg/dev-deprecated/model.js +667 -0
  244. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  245. package/dist/unpkg/dev-deprecated/schema-provider-g5MfTj8n.js +2338 -0
  246. package/dist/unpkg/dev-deprecated/serialize-into-hash-BnYvPex3.js +261 -0
  247. package/dist/unpkg/dev-deprecated/serializer/json-api.js +527 -0
  248. package/dist/unpkg/dev-deprecated/serializer/json.js +6 -0
  249. package/dist/unpkg/dev-deprecated/serializer/rest.js +1243 -0
  250. package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
  251. package/dist/unpkg/dev-deprecated/serializer.js +248 -0
  252. package/dist/unpkg/dev-deprecated/store.js +636 -0
  253. package/dist/unpkg/dev-deprecated/util-Dul6TZts.js +35 -0
  254. package/dist/unpkg/dev-deprecated/utils-Cqw9eRj5.js +23 -0
  255. package/dist/unpkg/prod/-private-B1pSSN52.js +1210 -0
  256. package/dist/unpkg/prod/adapter/-private.js +1 -0
  257. package/dist/unpkg/prod/adapter/error.js +336 -0
  258. package/dist/unpkg/prod/adapter/json-api.js +132 -0
  259. package/dist/unpkg/prod/adapter/rest.js +1257 -0
  260. package/dist/unpkg/prod/adapter.js +1253 -0
  261. package/dist/unpkg/prod/compat/-private.js +1 -0
  262. package/dist/unpkg/prod/compat/builders.js +273 -0
  263. package/dist/unpkg/prod/compat/extensions.js +243 -0
  264. package/dist/unpkg/prod/compat/utils.js +224 -0
  265. package/dist/unpkg/prod/compat.js +1020 -0
  266. package/dist/unpkg/prod/declarations/adapter/-private/build-url-mixin.d.ts +33 -0
  267. package/dist/unpkg/prod/declarations/adapter/-private/fastboot-interface.d.ts +8 -0
  268. package/dist/unpkg/prod/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -0
  269. package/dist/unpkg/prod/declarations/adapter/-private/utils/determine-body-promise.d.ts +4 -0
  270. package/dist/unpkg/prod/declarations/adapter/-private/utils/fetch.d.ts +8 -0
  271. package/dist/unpkg/prod/declarations/adapter/-private/utils/parse-response-headers.d.ts +1 -0
  272. package/dist/unpkg/prod/declarations/adapter/-private/utils/serialize-into-hash.d.ts +6 -0
  273. package/dist/unpkg/prod/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -0
  274. package/dist/unpkg/prod/declarations/adapter/-private.d.ts +5 -0
  275. package/dist/unpkg/prod/declarations/adapter/error.d.ts +215 -0
  276. package/dist/unpkg/prod/declarations/adapter/json-api.d.ts +231 -0
  277. package/dist/unpkg/prod/declarations/adapter/rest.d.ts +815 -0
  278. package/dist/unpkg/prod/declarations/adapter.d.ts +770 -0
  279. package/dist/unpkg/prod/declarations/compat/-private.d.ts +13 -0
  280. package/dist/unpkg/prod/declarations/compat/builders/find-all.d.ts +35 -0
  281. package/dist/unpkg/prod/declarations/compat/builders/find-record.d.ts +56 -0
  282. package/dist/unpkg/prod/declarations/compat/builders/query.d.ts +66 -0
  283. package/dist/unpkg/prod/declarations/compat/builders/save-record.d.ts +34 -0
  284. package/dist/unpkg/prod/declarations/compat/builders/utils.d.ts +3 -0
  285. package/dist/unpkg/prod/declarations/compat/builders.d.ts +14 -0
  286. package/dist/unpkg/prod/declarations/compat/extensions.d.ts +59 -0
  287. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/fetch-manager.d.ts +55 -0
  288. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -0
  289. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +11 -0
  290. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +5 -0
  291. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +2 -0
  292. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +524 -0
  293. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +213 -0
  294. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/serializer-response.d.ts +6 -0
  295. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +110 -0
  296. package/dist/unpkg/prod/declarations/compat/legacy-network-handler/snapshot.d.ts +255 -0
  297. package/dist/unpkg/prod/declarations/compat/utils.d.ts +137 -0
  298. package/dist/unpkg/prod/declarations/compat.d.ts +157 -0
  299. package/dist/unpkg/prod/declarations/index.d.ts +70 -0
  300. package/dist/unpkg/prod/declarations/model/-private/attr.d.ts +170 -0
  301. package/dist/unpkg/prod/declarations/model/-private/belongs-to.d.ts +174 -0
  302. package/dist/unpkg/prod/declarations/model/-private/debug/assert-polymorphic-type.d.ts +5 -0
  303. package/dist/unpkg/prod/declarations/model/-private/errors.d.ts +289 -0
  304. package/dist/unpkg/prod/declarations/model/-private/has-many.d.ts +162 -0
  305. package/dist/unpkg/prod/declarations/model/-private/hooks.d.ts +10 -0
  306. package/dist/unpkg/prod/declarations/model/-private/legacy-relationships-support.d.ts +47 -0
  307. package/dist/unpkg/prod/declarations/model/-private/model-for-mixin.d.ts +3 -0
  308. package/dist/unpkg/prod/declarations/model/-private/model-methods.d.ts +39 -0
  309. package/dist/unpkg/prod/declarations/model/-private/model.d.ts +1269 -0
  310. package/dist/unpkg/prod/declarations/model/-private/notify-changes.d.ts +4 -0
  311. package/dist/unpkg/prod/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  312. package/dist/unpkg/prod/declarations/model/-private/promise-many-array.d.ts +124 -0
  313. package/dist/unpkg/prod/declarations/model/-private/record-state.d.ts +58 -0
  314. package/dist/unpkg/prod/declarations/model/-private/references/belongs-to.d.ts +498 -0
  315. package/dist/unpkg/prod/declarations/model/-private/references/has-many.d.ts +500 -0
  316. package/dist/unpkg/prod/declarations/model/-private/schema-provider.d.ts +56 -0
  317. package/dist/unpkg/prod/declarations/model/-private/type-utils.d.ts +57 -0
  318. package/dist/unpkg/prod/declarations/model/-private/util.d.ts +5 -0
  319. package/dist/unpkg/prod/declarations/model/-private.d.ts +8 -0
  320. package/dist/unpkg/prod/declarations/model/migration-support.d.ts +280 -0
  321. package/dist/unpkg/prod/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  322. package/dist/unpkg/prod/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  323. package/dist/unpkg/prod/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  324. package/dist/unpkg/prod/declarations/model-fragments/index.d.ts +5 -0
  325. package/dist/unpkg/prod/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  326. package/dist/unpkg/prod/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  327. package/dist/unpkg/prod/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  328. package/dist/unpkg/prod/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  329. package/dist/unpkg/prod/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  330. package/dist/unpkg/prod/declarations/model-fragments.d.ts +9 -0
  331. package/dist/unpkg/prod/declarations/model.d.ts +49 -0
  332. package/dist/unpkg/prod/declarations/serializer/-private/embedded-records-mixin.d.ts +91 -0
  333. package/dist/unpkg/prod/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  334. package/dist/unpkg/prod/declarations/serializer/-private/transforms/date.d.ts +28 -0
  335. package/dist/unpkg/prod/declarations/serializer/-private/transforms/number.d.ts +29 -0
  336. package/dist/unpkg/prod/declarations/serializer/-private/transforms/string.d.ts +29 -0
  337. package/dist/unpkg/prod/declarations/serializer/-private/transforms/transform.d.ts +118 -0
  338. package/dist/unpkg/prod/declarations/serializer/-private/utils.d.ts +3 -0
  339. package/dist/unpkg/prod/declarations/serializer/json-api.d.ts +123 -0
  340. package/dist/unpkg/prod/declarations/serializer/json.d.ts +75 -0
  341. package/dist/unpkg/prod/declarations/serializer/rest.d.ts +51 -0
  342. package/dist/unpkg/prod/declarations/serializer/transform.d.ts +5 -0
  343. package/dist/unpkg/prod/declarations/serializer.d.ts +254 -0
  344. package/dist/unpkg/prod/declarations/store/-private.d.ts +223 -0
  345. package/dist/unpkg/prod/declarations/store.d.ts +3 -0
  346. package/dist/unpkg/prod/errors-CIGPcDvd.js +2595 -0
  347. package/dist/unpkg/prod/hooks-QqRnX108.js +74 -0
  348. package/dist/unpkg/prod/index.js +195 -0
  349. package/dist/unpkg/prod/json-BNrV8EYG.js +1272 -0
  350. package/dist/unpkg/prod/model/-private.js +1 -0
  351. package/dist/unpkg/prod/model/migration-support.js +579 -0
  352. package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
  353. package/dist/unpkg/prod/model-fragments.js +76 -0
  354. package/dist/unpkg/prod/model.js +667 -0
  355. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  356. package/dist/unpkg/prod/schema-provider-g5MfTj8n.js +2338 -0
  357. package/dist/unpkg/prod/serialize-into-hash-BnYvPex3.js +261 -0
  358. package/dist/unpkg/prod/serializer/json-api.js +527 -0
  359. package/dist/unpkg/prod/serializer/json.js +6 -0
  360. package/dist/unpkg/prod/serializer/rest.js +1243 -0
  361. package/dist/unpkg/prod/serializer/transform.js +278 -0
  362. package/dist/unpkg/prod/serializer.js +248 -0
  363. package/dist/unpkg/prod/store.js +636 -0
  364. package/dist/unpkg/prod/util-Dul6TZts.js +35 -0
  365. package/dist/unpkg/prod/utils-Cqw9eRj5.js +23 -0
  366. package/dist/unpkg/prod-deprecated/-private-B1pSSN52.js +1210 -0
  367. package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
  368. package/dist/unpkg/prod-deprecated/adapter/error.js +336 -0
  369. package/dist/unpkg/prod-deprecated/adapter/json-api.js +132 -0
  370. package/dist/unpkg/prod-deprecated/adapter/rest.js +1257 -0
  371. package/dist/unpkg/prod-deprecated/adapter.js +1253 -0
  372. package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
  373. package/dist/unpkg/prod-deprecated/compat/builders.js +273 -0
  374. package/dist/unpkg/prod-deprecated/compat/extensions.js +243 -0
  375. package/dist/unpkg/prod-deprecated/compat/utils.js +224 -0
  376. package/dist/unpkg/prod-deprecated/compat.js +1020 -0
  377. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/build-url-mixin.d.ts +33 -0
  378. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/fastboot-interface.d.ts +8 -0
  379. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -0
  380. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/determine-body-promise.d.ts +4 -0
  381. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/fetch.d.ts +8 -0
  382. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/parse-response-headers.d.ts +1 -0
  383. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/serialize-into-hash.d.ts +6 -0
  384. package/dist/unpkg/prod-deprecated/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -0
  385. package/dist/unpkg/prod-deprecated/declarations/adapter/-private.d.ts +5 -0
  386. package/dist/unpkg/prod-deprecated/declarations/adapter/error.d.ts +215 -0
  387. package/dist/unpkg/prod-deprecated/declarations/adapter/json-api.d.ts +231 -0
  388. package/dist/unpkg/prod-deprecated/declarations/adapter/rest.d.ts +815 -0
  389. package/dist/unpkg/prod-deprecated/declarations/adapter.d.ts +770 -0
  390. package/dist/unpkg/prod-deprecated/declarations/compat/-private.d.ts +13 -0
  391. package/dist/unpkg/prod-deprecated/declarations/compat/builders/find-all.d.ts +35 -0
  392. package/dist/unpkg/prod-deprecated/declarations/compat/builders/find-record.d.ts +56 -0
  393. package/dist/unpkg/prod-deprecated/declarations/compat/builders/query.d.ts +66 -0
  394. package/dist/unpkg/prod-deprecated/declarations/compat/builders/save-record.d.ts +34 -0
  395. package/dist/unpkg/prod-deprecated/declarations/compat/builders/utils.d.ts +3 -0
  396. package/dist/unpkg/prod-deprecated/declarations/compat/builders.d.ts +14 -0
  397. package/dist/unpkg/prod-deprecated/declarations/compat/extensions.d.ts +59 -0
  398. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/fetch-manager.d.ts +55 -0
  399. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -0
  400. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +11 -0
  401. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +5 -0
  402. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +2 -0
  403. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +524 -0
  404. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +213 -0
  405. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/serializer-response.d.ts +6 -0
  406. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +110 -0
  407. package/dist/unpkg/prod-deprecated/declarations/compat/legacy-network-handler/snapshot.d.ts +255 -0
  408. package/dist/unpkg/prod-deprecated/declarations/compat/utils.d.ts +137 -0
  409. package/dist/unpkg/prod-deprecated/declarations/compat.d.ts +157 -0
  410. package/dist/unpkg/prod-deprecated/declarations/index.d.ts +70 -0
  411. package/dist/unpkg/prod-deprecated/declarations/model/-private/attr.d.ts +170 -0
  412. package/dist/unpkg/prod-deprecated/declarations/model/-private/belongs-to.d.ts +174 -0
  413. package/dist/unpkg/prod-deprecated/declarations/model/-private/debug/assert-polymorphic-type.d.ts +5 -0
  414. package/dist/unpkg/prod-deprecated/declarations/model/-private/errors.d.ts +289 -0
  415. package/dist/unpkg/prod-deprecated/declarations/model/-private/has-many.d.ts +162 -0
  416. package/dist/unpkg/prod-deprecated/declarations/model/-private/hooks.d.ts +10 -0
  417. package/dist/unpkg/prod-deprecated/declarations/model/-private/legacy-relationships-support.d.ts +47 -0
  418. package/dist/unpkg/prod-deprecated/declarations/model/-private/model-for-mixin.d.ts +3 -0
  419. package/dist/unpkg/prod-deprecated/declarations/model/-private/model-methods.d.ts +39 -0
  420. package/dist/unpkg/prod-deprecated/declarations/model/-private/model.d.ts +1269 -0
  421. package/dist/unpkg/prod-deprecated/declarations/model/-private/notify-changes.d.ts +4 -0
  422. package/dist/unpkg/prod-deprecated/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  423. package/dist/unpkg/prod-deprecated/declarations/model/-private/promise-many-array.d.ts +124 -0
  424. package/dist/unpkg/prod-deprecated/declarations/model/-private/record-state.d.ts +58 -0
  425. package/dist/unpkg/prod-deprecated/declarations/model/-private/references/belongs-to.d.ts +498 -0
  426. package/dist/unpkg/prod-deprecated/declarations/model/-private/references/has-many.d.ts +500 -0
  427. package/dist/unpkg/prod-deprecated/declarations/model/-private/schema-provider.d.ts +56 -0
  428. package/dist/unpkg/prod-deprecated/declarations/model/-private/type-utils.d.ts +57 -0
  429. package/dist/unpkg/prod-deprecated/declarations/model/-private/util.d.ts +5 -0
  430. package/dist/unpkg/prod-deprecated/declarations/model/-private.d.ts +8 -0
  431. package/dist/unpkg/prod-deprecated/declarations/model/migration-support.d.ts +280 -0
  432. package/dist/unpkg/prod-deprecated/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  433. package/dist/unpkg/prod-deprecated/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  434. package/dist/unpkg/prod-deprecated/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  435. package/dist/unpkg/prod-deprecated/declarations/model-fragments/index.d.ts +5 -0
  436. package/dist/unpkg/prod-deprecated/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  437. package/dist/unpkg/prod-deprecated/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  438. package/dist/unpkg/prod-deprecated/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  439. package/dist/unpkg/prod-deprecated/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  440. package/dist/unpkg/prod-deprecated/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  441. package/dist/unpkg/prod-deprecated/declarations/model-fragments.d.ts +9 -0
  442. package/dist/unpkg/prod-deprecated/declarations/model.d.ts +49 -0
  443. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/embedded-records-mixin.d.ts +91 -0
  444. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  445. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/date.d.ts +28 -0
  446. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/number.d.ts +29 -0
  447. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/string.d.ts +29 -0
  448. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/transforms/transform.d.ts +118 -0
  449. package/dist/unpkg/prod-deprecated/declarations/serializer/-private/utils.d.ts +3 -0
  450. package/dist/unpkg/prod-deprecated/declarations/serializer/json-api.d.ts +123 -0
  451. package/dist/unpkg/prod-deprecated/declarations/serializer/json.d.ts +75 -0
  452. package/dist/unpkg/prod-deprecated/declarations/serializer/rest.d.ts +51 -0
  453. package/dist/unpkg/prod-deprecated/declarations/serializer/transform.d.ts +5 -0
  454. package/dist/unpkg/prod-deprecated/declarations/serializer.d.ts +254 -0
  455. package/dist/unpkg/prod-deprecated/declarations/store/-private.d.ts +223 -0
  456. package/dist/unpkg/prod-deprecated/declarations/store.d.ts +3 -0
  457. package/dist/unpkg/prod-deprecated/errors-CIGPcDvd.js +2595 -0
  458. package/dist/unpkg/prod-deprecated/hooks-QqRnX108.js +74 -0
  459. package/dist/unpkg/prod-deprecated/index.js +195 -0
  460. package/dist/unpkg/prod-deprecated/json-BNrV8EYG.js +1272 -0
  461. package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
  462. package/dist/unpkg/prod-deprecated/model/migration-support.js +579 -0
  463. package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
  464. package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
  465. package/dist/unpkg/prod-deprecated/model.js +667 -0
  466. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  467. package/dist/unpkg/prod-deprecated/schema-provider-g5MfTj8n.js +2338 -0
  468. package/dist/unpkg/prod-deprecated/serialize-into-hash-BnYvPex3.js +261 -0
  469. package/dist/unpkg/prod-deprecated/serializer/json-api.js +527 -0
  470. package/dist/unpkg/prod-deprecated/serializer/json.js +6 -0
  471. package/dist/unpkg/prod-deprecated/serializer/rest.js +1243 -0
  472. package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
  473. package/dist/unpkg/prod-deprecated/serializer.js +248 -0
  474. package/dist/unpkg/prod-deprecated/store.js +636 -0
  475. package/dist/unpkg/prod-deprecated/util-Dul6TZts.js +35 -0
  476. package/dist/unpkg/prod-deprecated/utils-Cqw9eRj5.js +23 -0
  477. package/package.json +30 -6
@@ -0,0 +1,2595 @@
1
+ import { Context } from '@warp-drive/core/reactive/-private';
2
+ import { memoized, defineSignal, assertPrivateStore, defineNonEnumerableSignal, isResourceKey, recordIdentifierFor, isPrivateStore, storeFor, fastPush, createLegacyManyArray, notifyInternalSignal } from '@warp-drive/core/store/-private';
3
+ import { getOrSetGlobal } from '@warp-drive/core/types/-private';
4
+ import { EnableHydration } from '@warp-drive/core/types/request';
5
+ import { u as upgradeStore } from "./-private-B1pSSN52.js";
6
+ import { computed, get } from '@ember/object';
7
+ import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
8
+ import ObjectProxy from '@ember/object/proxy';
9
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
10
+ import { d as decorateMethodV2, a as decorateFieldV2, i as initializeDeferredDecorator } from "./runtime-BPCpkOf1-BKOwiRJp.js";
11
+ import { A } from '@ember/array';
12
+ import ArrayProxy from '@ember/array/proxy';
13
+ import { mapBy, not } from '@ember/object/computed';
14
+ const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
15
+ const LegacyPromiseProxy = Symbol.for('LegacyPromiseProxy');
16
+
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-extraneous-class
18
+
19
+ const Extended = PromiseObject;
20
+
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+
23
+ /**
24
+ A PromiseBelongsTo is a PromiseObject that also proxies certain method calls
25
+ to the underlying belongsTo model.
26
+ Right now we proxy:
27
+ * `reload()`
28
+ @class PromiseBelongsTo
29
+ @private
30
+ */
31
+ class PromiseBelongsTo extends Extended {
32
+ get id() {
33
+ const {
34
+ key,
35
+ legacySupport
36
+ } = this._belongsToState;
37
+ const ref = legacySupport.referenceFor('belongsTo', key);
38
+ return ref.id();
39
+ }
40
+
41
+ // we don't proxy meta because we would need to proxy it to the relationship state container
42
+ // however, meta on relationships does not trigger change notifications.
43
+ // if you need relationship meta, you should do `record.belongsTo(relationshipName).meta()`
44
+ static {
45
+ decorateMethodV2(this.prototype, "id", [memoized]);
46
+ }
47
+ get meta() {
48
+ // eslint-disable-next-line no-constant-condition
49
+ {
50
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
51
+ {
52
+ throw new Error('You attempted to access meta on the promise for the async belongsTo relationship ' + `${this._belongsToState.modelName}:${this._belongsToState.key}'.` + '\nUse `record.belongsTo(relationshipName).meta()` instead.');
53
+ }
54
+ })() : {};
55
+ }
56
+ return;
57
+ }
58
+ static {
59
+ decorateMethodV2(this.prototype, "meta", [computed()]);
60
+ }
61
+ async reload(options) {
62
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
63
+ if (!test) {
64
+ throw new Error('You are trying to reload an async belongsTo before it has been created');
65
+ }
66
+ })(this.content !== undefined) : {};
67
+ const {
68
+ key,
69
+ legacySupport
70
+ } = this._belongsToState;
71
+ await legacySupport.reloadBelongsTo(key, options);
72
+ return this;
73
+ }
74
+ }
75
+ PromiseBelongsTo.prototype[LegacyPromiseProxy] = true;
76
+
77
+ /**
78
+ This class is returned as the result of accessing an async hasMany relationship
79
+ on an instance of a Model extending from `@ember-data/model`.
80
+
81
+ A PromiseManyArray is an iterable proxy that allows templates to consume related
82
+ ManyArrays and update once their contents are no longer pending.
83
+
84
+ In your JS code you should resolve the promise first.
85
+
86
+ ```js
87
+ const comments = await post.comments;
88
+ ```
89
+
90
+ @class PromiseManyArray
91
+ @public
92
+ */
93
+ class PromiseManyArray {
94
+ constructor(promise, content) {
95
+ this._update(promise, content);
96
+ this.isDestroyed = false;
97
+ this[LegacyPromiseProxy] = true;
98
+ }
99
+
100
+ /**
101
+ * Retrieve the length of the content
102
+ * @property length
103
+ * @public
104
+ */
105
+ get length() {
106
+ // shouldn't be needed, but ends up being needed
107
+ // for computed chains even in 4.x
108
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_COMPUTED_CHAINS)) {
109
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
110
+ this['[]'];
111
+ }
112
+ return this.content ? this.content.length : 0;
113
+ }
114
+
115
+ // this will error if someone tries to call
116
+ // A(identifierArray) since it is not configurable
117
+ // which is preferrable to the `meta` override we used
118
+ // before which required importing all of Ember
119
+ static {
120
+ decorateMethodV2(this.prototype, "length", [memoized]);
121
+ }
122
+ get '[]'() {
123
+ // ember-source < 3.23 (e.g. 3.20 lts)
124
+ // requires that the tag `'[]'` be notified
125
+ // on the ArrayProxy in order for `{{#each}}`
126
+ // to recompute. We entangle content.
127
+ return this.content?.length && this.content;
128
+ }
129
+
130
+ /**
131
+ * Iterate the proxied content. Called by the glimmer iterator in #each
132
+ * We do not guarantee that forEach will always be available. This
133
+ * may eventually be made to use Symbol.Iterator once glimmer supports it.
134
+ *
135
+ * @param cb
136
+ * @return
137
+ * @private
138
+ */
139
+ static {
140
+ decorateMethodV2(this.prototype, '[]', [memoized]);
141
+ }
142
+ forEach(cb) {
143
+ if (this.content && this.length) {
144
+ this.content.forEach(cb);
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Reload the relationship
150
+ * @public
151
+ * @param options
152
+ * @return
153
+ */
154
+ reload(options) {
155
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
156
+ if (!test) {
157
+ throw new Error('You are trying to reload an async manyArray before it has been created');
158
+ }
159
+ })(this.content) : {};
160
+ void this.content.reload(options);
161
+ return this;
162
+ }
163
+
164
+ //---- Properties/Methods from the PromiseProxyMixin that we will keep as our API
165
+
166
+ /**
167
+ * Whether the loading promise is still pending
168
+ *
169
+ * @property isPending
170
+ * @type {Boolean}
171
+ * @public
172
+ */
173
+
174
+ /**
175
+ * Whether the loading promise rejected
176
+ *
177
+ * @property isRejected
178
+ * @type {Boolean}
179
+ * @public
180
+ */
181
+
182
+ /**
183
+ * Whether the loading promise succeeded
184
+ *
185
+ * @property isFulfilled
186
+ * @type {Boolean}
187
+ * @public
188
+ */
189
+
190
+ /**
191
+ * Whether the loading promise completed (resolved or rejected)
192
+ *
193
+ * @property isSettled
194
+ * @type {Boolean}
195
+ * @public
196
+ */
197
+
198
+ /**
199
+ * chain this promise
200
+ *
201
+ * @public
202
+ */
203
+ then(success, rejected) {
204
+ return this.promise.then(success, rejected);
205
+ }
206
+
207
+ /**
208
+ * catch errors thrown by this promise
209
+ * @public
210
+ * @param callback
211
+ * @return {Promise}
212
+ */
213
+ catch(cb) {
214
+ return this.promise.catch(cb);
215
+ }
216
+
217
+ /**
218
+ * run cleanup after this promise completes
219
+ *
220
+ * @public
221
+ * @param callback
222
+ * @return {Promise}
223
+ */
224
+ finally(cb) {
225
+ return this.promise.finally(cb);
226
+ }
227
+
228
+ //---- Methods on EmberObject that we should keep
229
+
230
+ destroy() {
231
+ this.isDestroyed = true;
232
+ this.content = null;
233
+ this.promise = null;
234
+ }
235
+
236
+ //---- Methods/Properties on ManyArray that we own and proxy to
237
+
238
+ /**
239
+ * Retrieve the links for this relationship
240
+ * @property links
241
+ * @public
242
+ */
243
+ get links() {
244
+ return this.content ? this.content.links : undefined;
245
+ }
246
+
247
+ /**
248
+ * Retrieve the meta for this relationship
249
+ * @property meta
250
+ * @public
251
+ */
252
+ static {
253
+ decorateMethodV2(this.prototype, "links", [memoized]);
254
+ }
255
+ get meta() {
256
+ return this.content ? this.content.meta : undefined;
257
+ }
258
+
259
+ //---- Our own stuff
260
+
261
+ /** @internal */
262
+ static {
263
+ decorateMethodV2(this.prototype, "meta", [memoized]);
264
+ }
265
+ _update(promise, content) {
266
+ if (content !== undefined) {
267
+ this.content = content;
268
+ }
269
+ this.promise = tapPromise(this, promise);
270
+ }
271
+ static create({
272
+ promise,
273
+ content
274
+ }) {
275
+ return new this(promise, content);
276
+ }
277
+ }
278
+ defineSignal(PromiseManyArray.prototype, 'content', null);
279
+ defineSignal(PromiseManyArray.prototype, 'isPending', false);
280
+ defineSignal(PromiseManyArray.prototype, 'isRejected', false);
281
+ defineSignal(PromiseManyArray.prototype, 'isFulfilled', false);
282
+ defineSignal(PromiseManyArray.prototype, 'isSettled', false);
283
+ function tapPromise(proxy, promise) {
284
+ proxy.isPending = true;
285
+ proxy.isSettled = false;
286
+ proxy.isFulfilled = false;
287
+ proxy.isRejected = false;
288
+ return Promise.resolve(promise).then(content => {
289
+ proxy.isPending = false;
290
+ proxy.isFulfilled = true;
291
+ proxy.isSettled = true;
292
+ proxy.content = content;
293
+ return content;
294
+ }, error => {
295
+ proxy.isPending = false;
296
+ proxy.isFulfilled = false;
297
+ proxy.isRejected = true;
298
+ proxy.isSettled = true;
299
+ throw error;
300
+ });
301
+ }
302
+
303
+ /*
304
+ Assert that `addedRecord` has a valid type so it can be added to the
305
+ relationship of the `record`.
306
+
307
+ The assert basically checks if the `addedRecord` can be added to the
308
+ relationship (specified via `relationshipMeta`) of the `record`.
309
+
310
+ This utility should only be used internally, as both record parameters must
311
+ be stable record identifiers and the `relationshipMeta` needs to be the meta
312
+ information about the relationship, retrieved via
313
+ `record.relationshipFor(key)`.
314
+ */
315
+ let assertPolymorphicType;
316
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
317
+ // eslint-disable-next-line @typescript-eslint/no-shadow
318
+ assertPolymorphicType = function assertPolymorphicType(parentIdentifier, parentDefinition, addedIdentifier, store) {
319
+ if (parentDefinition.inverseIsImplicit) {
320
+ return;
321
+ }
322
+ if (parentDefinition.isPolymorphic) {
323
+ const meta = store.schema.fields(addedIdentifier)?.get(parentDefinition.inverseKey);
324
+ if (meta) {
325
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
326
+ if (!test) {
327
+ throw new Error(`Expected the schema for the field ${parentDefinition.inverseKey} on ${addedIdentifier.type} to be for a legacy relationship`);
328
+ }
329
+ })(meta.kind === 'belongsTo' || meta.kind === 'hasMany') : {};
330
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
331
+ if (!test) {
332
+ throw new Error(`The schema for the relationship '${parentDefinition.inverseKey}' on '${addedIdentifier.type}' type does not implement '${parentDefinition.type}' and thus cannot be assigned to the '${parentDefinition.key}' relationship in '${parentIdentifier.type}'. The definition should specify 'as: "${parentDefinition.type}"' in options.`);
333
+ }
334
+ })(meta?.options?.as === parentDefinition.type) : {};
335
+ }
336
+ }
337
+ };
338
+ }
339
+ function isResourceIdentiferWithRelatedLinks$1(value) {
340
+ return Boolean(value && value.links && value.links.related);
341
+ }
342
+ /**
343
+ A `HasManyReference` is a low-level API that allows access
344
+ and manipulation of a hasMany relationship.
345
+
346
+ It is especially useful when you're dealing with `async` relationships
347
+ from `@warp-drive/legacy/model` as it allows synchronous access to
348
+ the relationship data if loaded, as well as APIs for loading, reloading
349
+ the data or accessing available information without triggering a load.
350
+
351
+ It may also be useful when using `sync` relationships with `@warp-drive/legacy/model`
352
+ that need to be loaded/reloaded with more precise timing than marking the
353
+ relationship as `async` and relying on autofetch would have allowed.
354
+
355
+ However,keep in mind that marking a relationship as `async: false` will introduce
356
+ bugs into your application if the data is not always guaranteed to be available
357
+ by the time the relationship is accessed. Ergo, it is recommended when using this
358
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
359
+
360
+ Reference APIs are entangled with the relationship's underlying state,
361
+ thus any getters or cached properties that utilize these will properly
362
+ invalidate if the relationship state changes.
363
+
364
+ References are "stable", meaning that multiple calls to retrieve the reference
365
+ for a given relationship will always return the same HasManyReference.
366
+
367
+ @class HasManyReference
368
+ @public
369
+ */
370
+ class HasManyReference {
371
+ /**
372
+ * The field name on the parent record for this has-many relationship.
373
+ *
374
+ * @property key
375
+ * @type {String}
376
+ * @public
377
+ */
378
+
379
+ /**
380
+ * The type of resource this relationship will contain.
381
+ *
382
+ * @property type
383
+ * @type {String}
384
+ * @public
385
+ */
386
+
387
+ // unsubscribe tokens given to us by the notification manager
388
+ ___token;
389
+ ___identifier;
390
+ ___relatedTokenMap;
391
+ constructor(store, graph, parentIdentifier, hasManyRelationship, key) {
392
+ this.graph = graph;
393
+ this.key = key;
394
+ this.hasManyRelationship = hasManyRelationship;
395
+ this.type = hasManyRelationship.definition.type;
396
+ this.store = store;
397
+ this.___identifier = parentIdentifier;
398
+ this.___token = store.notifications.subscribe(parentIdentifier, (_, bucket, notifiedKey) => {
399
+ if (bucket === 'relationships' && notifiedKey === key) {
400
+ this._ref++;
401
+ }
402
+ });
403
+ this.___relatedTokenMap = new Map();
404
+ // TODO inverse
405
+ }
406
+
407
+ /**
408
+ * This method should never be called by user code.
409
+ *
410
+ * @internal
411
+ */
412
+ destroy() {
413
+ this.store.notifications.unsubscribe(this.___token);
414
+ this.___relatedTokenMap.forEach(token => {
415
+ this.store.notifications.unsubscribe(token);
416
+ });
417
+ this.___relatedTokenMap.clear();
418
+ }
419
+
420
+ /**
421
+ * An array of identifiers for the records that this reference refers to.
422
+ *
423
+ * @property identifiers
424
+ * @type {ResourceKey[]}
425
+ * @public
426
+ */
427
+ get identifiers() {
428
+ ensureRefCanSubscribe(this);
429
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
430
+ this._ref;
431
+ const resource = this._resource();
432
+ const map = this.___relatedTokenMap;
433
+ this.___relatedTokenMap = new Map();
434
+ if (resource && resource.data) {
435
+ return resource.data.map(resourceIdentifier => {
436
+ const identifier = this.store.cacheKeyManager.getOrCreateRecordIdentifier(resourceIdentifier);
437
+ let token = map.get(identifier);
438
+ if (token) {
439
+ map.delete(identifier);
440
+ } else {
441
+ token = this.store.notifications.subscribe(identifier, (_, bucket, notifiedKey) => {
442
+ if (bucket === 'identity' || bucket === 'attributes' && notifiedKey === 'id') {
443
+ this._ref++;
444
+ }
445
+ });
446
+ }
447
+ this.___relatedTokenMap.set(identifier, token);
448
+ return identifier;
449
+ });
450
+ }
451
+ map.forEach(token => {
452
+ this.store.notifications.unsubscribe(token);
453
+ });
454
+ map.clear();
455
+ return [];
456
+ }
457
+ static {
458
+ decorateMethodV2(this.prototype, "identifiers", [memoized]);
459
+ }
460
+ _resource() {
461
+ const cache = this.store.cache;
462
+ return cache.getRelationship(this.___identifier, this.key);
463
+ }
464
+
465
+ /**
466
+ This returns a string that represents how the reference will be
467
+ looked up when it is loaded. If the relationship has a link it will
468
+ use the "link" otherwise it defaults to "id".
469
+ Example
470
+ ```js [app/models/post.js]
471
+ import { Model, hasMany } from '@warp-drive/legacy/model';
472
+ export default class PostModel extends Model {
473
+ @hasMany('comment', { async: true, inverse: null }) comments;
474
+ }
475
+ ```
476
+ ```javascript
477
+ let post = store.push({
478
+ data: {
479
+ type: 'post',
480
+ id: 1,
481
+ relationships: {
482
+ comments: {
483
+ data: [{ type: 'comment', id: 1 }]
484
+ }
485
+ }
486
+ }
487
+ });
488
+ let commentsRef = post.hasMany('comments');
489
+ // get the identifier of the reference
490
+ if (commentsRef.remoteType() === "ids") {
491
+ let ids = commentsRef.ids();
492
+ } else if (commentsRef.remoteType() === "link") {
493
+ let link = commentsRef.link();
494
+ }
495
+ ```
496
+ @public
497
+ @return {String} The name of the remote type. This should either be `link` or `ids`
498
+ */
499
+ remoteType() {
500
+ const value = this._resource();
501
+ if (value && value.links && value.links.related) {
502
+ return 'link';
503
+ }
504
+ return 'ids';
505
+ }
506
+
507
+ /**
508
+ `ids()` returns an array of the record IDs in this relationship.
509
+ Example
510
+ ```js [app/models/post.js]
511
+ import { Model, hasMany } from '@warp-drive/legacy/model';
512
+ export default class PostModel extends Model {
513
+ @hasMany('comment', { async: true, inverse: null }) comments;
514
+ }
515
+ ```
516
+ ```javascript
517
+ let post = store.push({
518
+ data: {
519
+ type: 'post',
520
+ id: 1,
521
+ relationships: {
522
+ comments: {
523
+ data: [{ type: 'comment', id: 1 }]
524
+ }
525
+ }
526
+ }
527
+ });
528
+ let commentsRef = post.hasMany('comments');
529
+ commentsRef.ids(); // ['1']
530
+ ```
531
+ @public
532
+ @return {Array} The ids in this has-many relationship
533
+ */
534
+ ids() {
535
+ return this.identifiers.map(identifier => identifier.id);
536
+ }
537
+
538
+ /**
539
+ The link Ember Data will use to fetch or reload this belongs-to
540
+ relationship. By default it uses only the "related" resource linkage.
541
+ Example
542
+ ```javascript
543
+ // models/blog.js
544
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
545
+ export default Model.extend({
546
+ user: belongsTo('user', { async: true, inverse: null })
547
+ });
548
+ let blog = store.push({
549
+ data: {
550
+ type: 'blog',
551
+ id: 1,
552
+ relationships: {
553
+ user: {
554
+ links: {
555
+ related: '/articles/1/author'
556
+ }
557
+ }
558
+ }
559
+ }
560
+ });
561
+ let userRef = blog.belongsTo('user');
562
+ // get the identifier of the reference
563
+ if (userRef.remoteType() === "link") {
564
+ let link = userRef.link();
565
+ }
566
+ ```
567
+ @public
568
+ @return {String} The link Ember Data will use to fetch or reload this belongs-to relationship.
569
+ */
570
+ link() {
571
+ const resource = this._resource();
572
+ if (isResourceIdentiferWithRelatedLinks$1(resource)) {
573
+ if (resource.links) {
574
+ const related = resource.links.related;
575
+ return !related || typeof related === 'string' ? related : related.href;
576
+ }
577
+ }
578
+ return null;
579
+ }
580
+
581
+ /**
582
+ * any links that have been received for this relationship
583
+ *
584
+ * @public
585
+ * @return
586
+ */
587
+ links() {
588
+ const resource = this._resource();
589
+ return resource && resource.links ? resource.links : null;
590
+ }
591
+
592
+ /**
593
+ The meta data for the has-many relationship.
594
+ Example
595
+ ```javascript
596
+ // models/blog.js
597
+ import { Model, hasMany } from '@warp-drive/legacy/model';
598
+ export default Model.extend({
599
+ users: hasMany('user', { async: true, inverse: null })
600
+ });
601
+ let blog = store.push({
602
+ data: {
603
+ type: 'blog',
604
+ id: 1,
605
+ relationships: {
606
+ users: {
607
+ links: {
608
+ related: {
609
+ href: '/articles/1/authors'
610
+ },
611
+ },
612
+ meta: {
613
+ lastUpdated: 1458014400000
614
+ }
615
+ }
616
+ }
617
+ }
618
+ });
619
+ let usersRef = blog.hasMany('user');
620
+ usersRef.meta() // { lastUpdated: 1458014400000 }
621
+ ```
622
+ @public
623
+ @return {Object|null} The meta information for the belongs-to relationship.
624
+ */
625
+ meta() {
626
+ let meta = null;
627
+ const resource = this._resource();
628
+ if (resource && resource.meta && typeof resource.meta === 'object') {
629
+ meta = resource.meta;
630
+ }
631
+ return meta;
632
+ }
633
+
634
+ /**
635
+ `push` can be used to update the data in the relationship and WarpDrive
636
+ will treat the new data as the canonical value of this relationship on
637
+ the backend. An empty array will signify the canonical value should be
638
+ empty.
639
+ Example model
640
+ ```js [app/models/post.js]
641
+ import { Model, hasMany } from '@warp-drive/legacy/model';
642
+ export default class PostModel extends Model {
643
+ @hasMany('comment', { async: true, inverse: null }) comments;
644
+ }
645
+ ```
646
+ Setup some initial state, note we haven't loaded the comments yet:
647
+ ```js
648
+ const post = store.push({
649
+ data: {
650
+ type: 'post',
651
+ id: '1',
652
+ relationships: {
653
+ comments: {
654
+ data: [{ type: 'comment', id: '1' }]
655
+ }
656
+ }
657
+ }
658
+ });
659
+ const commentsRef = post.hasMany('comments');
660
+ commentsRef.ids(); // ['1']
661
+ ```
662
+ Update the state using `push`, note we can do this even without
663
+ having loaded these comments yet by providing resource identifiers.
664
+ Both full resources and resource identifiers are supported.
665
+ ```js
666
+ await commentsRef.push({
667
+ data: [
668
+ { type: 'comment', id: '2' },
669
+ { type: 'comment', id: '3' },
670
+ ]
671
+ });
672
+ commentsRef.ids(); // ['2', '3']
673
+ ```
674
+ For convenience, you can also pass in an array of resources or resource identifiers
675
+ without wrapping them in the `data` property:
676
+ ```js
677
+ await commentsRef.push([
678
+ { type: 'comment', id: '4' },
679
+ { type: 'comment', id: '5' },
680
+ ]);
681
+ commentsRef.ids(); // ['4', '5']
682
+ ```
683
+ When using the `data` property, you may also include other resource data via included,
684
+ as well as provide new links and meta to the relationship.
685
+ ```js
686
+ await commentsRef.push({
687
+ links: {
688
+ related: '/posts/1/comments'
689
+ },
690
+ meta: {
691
+ total: 2
692
+ },
693
+ data: [
694
+ { type: 'comment', id: '4' },
695
+ { type: 'comment', id: '5' },
696
+ ],
697
+ included: [
698
+ { type: 'other-thing', id: '1', attributes: { foo: 'bar' },
699
+ ]
700
+ });
701
+ ```
702
+ By default, the store will attempt to fetch any unloaded records before resolving
703
+ the returned promise with the ManyArray.
704
+ Alternatively, pass `true` as the second argument to avoid fetching unloaded records
705
+ and instead the promise will resolve with void without attempting to fetch. This is
706
+ particularly useful if you want to update the state of the relationship without
707
+ forcing the load of all of the associated records.
708
+ @public
709
+ @param {Array|Object} doc a JSONAPI document object describing the new value of this relationship.
710
+ @param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
711
+ @return {Promise<ManyArray | void>}
712
+ */
713
+ async push(doc, skipFetch) {
714
+ const {
715
+ store
716
+ } = this;
717
+ const dataDoc = Array.isArray(doc) ? {
718
+ data: doc
719
+ } : doc;
720
+ const isResourceData = Array.isArray(dataDoc.data) && dataDoc.data.length > 0 && isMaybeResource(dataDoc.data[0]);
721
+
722
+ // enforce that one of links, meta or data is present
723
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
724
+ if (!test) {
725
+ throw new Error(`You must provide at least one of 'links', 'meta' or 'data' when calling hasManyReference.push`);
726
+ }
727
+ })('links' in dataDoc || 'meta' in dataDoc || 'data' in dataDoc) : {};
728
+ const identifiers = !Array.isArray(dataDoc.data) ? [] : isResourceData ? store._push(dataDoc, true) : dataDoc.data.map(i => store.cacheKeyManager.getOrCreateRecordIdentifier(i));
729
+ const {
730
+ identifier
731
+ } = this.hasManyRelationship;
732
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
733
+ const relationshipMeta = this.hasManyRelationship.definition;
734
+ identifiers.forEach(added => {
735
+ assertPolymorphicType(identifier, relationshipMeta, added, store);
736
+ });
737
+ }
738
+ const newData = {};
739
+ // only set data if it was passed in
740
+ if (Array.isArray(dataDoc.data)) {
741
+ newData.data = identifiers;
742
+ }
743
+ if ('links' in dataDoc) {
744
+ newData.links = dataDoc.links;
745
+ }
746
+ if ('meta' in dataDoc) {
747
+ newData.meta = dataDoc.meta;
748
+ }
749
+ assertPrivateStore(store);
750
+ store._join(() => {
751
+ this.graph.push({
752
+ op: 'updateRelationship',
753
+ record: identifier,
754
+ field: this.key,
755
+ value: newData
756
+ });
757
+ });
758
+ if (!skipFetch) return this.load();
759
+ }
760
+ _isLoaded() {
761
+ const hasRelationshipDataProperty = this.hasManyRelationship.state.hasReceivedData;
762
+ if (!hasRelationshipDataProperty) {
763
+ return false;
764
+ }
765
+ const relationship = this.graph.getData(this.hasManyRelationship.identifier, this.key);
766
+ return relationship.data ? relationship.data.every(identifier => {
767
+ assertPrivateStore(this.store);
768
+ return this.store._instanceCache.recordIsLoaded(identifier, true) === true;
769
+ }) : false;
770
+ }
771
+
772
+ /**
773
+ `value()` synchronously returns the current value of the has-many
774
+ relationship. Unlike `record.relationshipName`, calling
775
+ `value()` on a reference does not trigger a fetch if the async
776
+ relationship is not yet loaded. If the relationship is not loaded
777
+ it will always return `null`.
778
+ Example
779
+ ```js [app/models/post.js]
780
+ import { Model, hasMany } from '@warp-drive/legacy/model';
781
+ export default class PostModel extends Model {
782
+ @hasMany('comment', { async: true, inverse: null }) comments;
783
+ }
784
+ ```
785
+ ```javascript
786
+ let post = store.push({
787
+ data: {
788
+ type: 'post',
789
+ id: 1,
790
+ relationships: {
791
+ comments: {
792
+ data: [{ type: 'comment', id: 1 }]
793
+ }
794
+ }
795
+ }
796
+ });
797
+ let commentsRef = post.hasMany('comments');
798
+ post.comments.then(function(comments) {
799
+ commentsRef.value() === comments
800
+ })
801
+ ```
802
+ @public
803
+ @return {ManyArray}
804
+ */
805
+ value() {
806
+ const support = LEGACY_SUPPORT.get(this.___identifier);
807
+ if (!ensureRefCanSubscribe(this)) {
808
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
809
+ this._ref;
810
+ return null;
811
+ }
812
+ return support.getManyArray(this.key);
813
+ }
814
+
815
+ /**
816
+ Loads the relationship if it is not already loaded. If the
817
+ relationship is already loaded this method does not trigger a new
818
+ load. This causes a request to the specified
819
+ relationship link or reloads all items currently in the relationship.
820
+ Example
821
+ ```js [app/models/post.js]
822
+ import { Model, hasMany } from '@warp-drive/legacy/model';
823
+ export default class PostModel extends Model {
824
+ @hasMany('comment', { async: true, inverse: null }) comments;
825
+ }
826
+ ```
827
+ ```javascript
828
+ let post = store.push({
829
+ data: {
830
+ type: 'post',
831
+ id: 1,
832
+ relationships: {
833
+ comments: {
834
+ data: [{ type: 'comment', id: 1 }]
835
+ }
836
+ }
837
+ }
838
+ });
839
+ let commentsRef = post.hasMany('comments');
840
+ commentsRef.load().then(function(comments) {
841
+ //...
842
+ });
843
+ ```
844
+ You may also pass in an options object whose properties will be
845
+ fed forward. This enables you to pass `adapterOptions` into the
846
+ request given to the adapter via the reference.
847
+ Example
848
+ ```javascript
849
+ commentsRef.load({ adapterOptions: { isPrivate: true } })
850
+ .then(function(comments) {
851
+ //...
852
+ });
853
+ ```
854
+ ```js [app/adapters/comment.js]
855
+ export default ApplicationAdapter.extend({
856
+ findMany(store, type, id, snapshots) {
857
+ // In the adapter you will have access to adapterOptions.
858
+ let adapterOptions = snapshots[0].adapterOptions;
859
+ }
860
+ });
861
+ ```
862
+ @public
863
+ @param {Object} options the options to pass in.
864
+ @return {Promise} a promise that resolves with the ManyArray in
865
+ this has-many relationship.
866
+ */
867
+ async load(options) {
868
+ const support = LEGACY_SUPPORT.get(this.___identifier);
869
+ const fetchSyncRel = !this.hasManyRelationship.definition.isAsync && !areAllInverseRecordsLoaded(this.store, this._resource());
870
+ return fetchSyncRel ? support.reloadHasMany(this.key, options) :
871
+ // we cast to fix the return type since typescript and eslint don't understand async functions
872
+ // properly
873
+ support.getHasMany(this.key, options);
874
+ }
875
+
876
+ /**
877
+ Reloads this has-many relationship. This causes a request to the specified
878
+ relationship link or reloads all items currently in the relationship.
879
+ Example
880
+ ```js [app/models/post.js]
881
+ import { Model, hasMany } from '@warp-drive/legacy/model';
882
+ export default class PostModel extends Model {
883
+ @hasMany('comment', { async: true, inverse: null }) comments;
884
+ }
885
+ ```
886
+ ```javascript
887
+ let post = store.push({
888
+ data: {
889
+ type: 'post',
890
+ id: 1,
891
+ relationships: {
892
+ comments: {
893
+ data: [{ type: 'comment', id: 1 }]
894
+ }
895
+ }
896
+ }
897
+ });
898
+ let commentsRef = post.hasMany('comments');
899
+ commentsRef.reload().then(function(comments) {
900
+ //...
901
+ });
902
+ ```
903
+ You may also pass in an options object whose properties will be
904
+ fed forward. This enables you to pass `adapterOptions` into the
905
+ request given to the adapter via the reference. A full example
906
+ can be found in the `load` method.
907
+ Example
908
+ ```javascript
909
+ commentsRef.reload({ adapterOptions: { isPrivate: true } })
910
+ ```
911
+ @public
912
+ @param {Object} options the options to pass in.
913
+ @return {Promise} a promise that resolves with the ManyArray in this has-many relationship.
914
+ */
915
+ reload(options) {
916
+ const support = LEGACY_SUPPORT.get(this.___identifier);
917
+ return support.reloadHasMany(this.key, options);
918
+ }
919
+ }
920
+ defineNonEnumerableSignal(HasManyReference.prototype, '_ref', 0);
921
+ function isMaybeResource(object) {
922
+ const keys = Object.keys(object).filter(k => k !== 'id' && k !== 'type' && k !== 'lid');
923
+ return keys.length > 0;
924
+ }
925
+ function ensureRefCanSubscribe(rel) {
926
+ const loaded = rel._isLoaded();
927
+ if (!loaded) {
928
+ // subscribe to changes
929
+ // for when we are not loaded yet
930
+ //
931
+ // because the graph optimizes the case where a relationship has never been subscribed,
932
+ // we force accessed to be true here. When we make the graph public we should create a
933
+ // subscribe/unsubscribe API
934
+ const edge = rel.graph.get(rel.___identifier, rel.key);
935
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
936
+ if (!test) {
937
+ throw new Error(`Expected a hasMany relationship for ${rel.___identifier.type}:${rel.key}`);
938
+ }
939
+ })('accessed' in edge) : {};
940
+ edge.accessed = true;
941
+ return false;
942
+ }
943
+ return true;
944
+ }
945
+ function isResourceIdentiferWithRelatedLinks(value) {
946
+ return Boolean(value && value.links && value.links.related);
947
+ }
948
+
949
+ /**
950
+ A `BelongsToReference` is a low-level API that allows access
951
+ and manipulation of a belongsTo relationship.
952
+
953
+ It is especially useful when you're dealing with `async` relationships
954
+ from `@warp-drive/legacy/model` as it allows synchronous access to
955
+ the relationship data if loaded, as well as APIs for loading, reloading
956
+ the data or accessing available information without triggering a load.
957
+
958
+ It may also be useful when using `sync` relationships with `@warp-drive/legacy/model`
959
+ that need to be loaded/reloaded with more precise timing than marking the
960
+ relationship as `async` and relying on autofetch would have allowed.
961
+
962
+ However,keep in mind that marking a relationship as `async: false` will introduce
963
+ bugs into your application if the data is not always guaranteed to be available
964
+ by the time the relationship is accessed. Ergo, it is recommended when using this
965
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
966
+
967
+ Reference APIs are entangled with the relationship's underlying state,
968
+ thus any getters or cached properties that utilize these will properly
969
+ invalidate if the relationship state changes.
970
+
971
+ References are "stable", meaning that multiple calls to retrieve the reference
972
+ for a given relationship will always return the same HasManyReference.
973
+
974
+ @class BelongsToReference
975
+ @public
976
+ */
977
+ class BelongsToReference {
978
+ /**
979
+ * The field name on the parent record for this has-many relationship.
980
+ *
981
+ * @property key
982
+ * @type {String}
983
+ * @public
984
+ */
985
+
986
+ /**
987
+ * The type of resource this relationship will contain.
988
+ *
989
+ * @property type
990
+ * @type {String}
991
+ * @public
992
+ */
993
+
994
+ // unsubscribe tokens given to us by the notification manager
995
+
996
+ constructor(store, graph, parentIdentifier, belongsToRelationship, key) {
997
+ this.graph = graph;
998
+ this.key = key;
999
+ this.belongsToRelationship = belongsToRelationship;
1000
+ this.type = belongsToRelationship.definition.type;
1001
+ this.store = store;
1002
+ this.___identifier = parentIdentifier;
1003
+ this.___relatedToken = null;
1004
+ this.___token = store.notifications.subscribe(parentIdentifier, (_, bucket, notifiedKey) => {
1005
+ if (bucket === 'relationships' && notifiedKey === key) {
1006
+ this._ref++;
1007
+ }
1008
+ });
1009
+
1010
+ // TODO inverse
1011
+ }
1012
+ destroy() {
1013
+ // TODO @feature we need the notification manager often enough
1014
+ // we should potentially just expose it fully public
1015
+ this.store.notifications.unsubscribe(this.___token);
1016
+ this.___token = null;
1017
+ if (this.___relatedToken) {
1018
+ this.store.notifications.unsubscribe(this.___relatedToken);
1019
+ this.___relatedToken = null;
1020
+ }
1021
+ }
1022
+
1023
+ /**
1024
+ * The identifier of the record that this reference refers to.
1025
+ * `null` if no related record is known.
1026
+ *
1027
+ * @property identifier
1028
+ * @type {ResourceKey | null}
1029
+ * @public
1030
+ */
1031
+ get identifier() {
1032
+ if (this.___relatedToken) {
1033
+ this.store.notifications.unsubscribe(this.___relatedToken);
1034
+ this.___relatedToken = null;
1035
+ }
1036
+ const resource = this._resource();
1037
+ if (resource && resource.data) {
1038
+ const identifier = this.store.cacheKeyManager.getOrCreateRecordIdentifier(resource.data);
1039
+ this.___relatedToken = this.store.notifications.subscribe(identifier, (_, bucket, notifiedKey) => {
1040
+ if (bucket === 'identity' || bucket === 'attributes' && notifiedKey === 'id') {
1041
+ this._ref++;
1042
+ }
1043
+ });
1044
+ return identifier;
1045
+ }
1046
+ return null;
1047
+ }
1048
+
1049
+ /**
1050
+ The `id` of the record that this reference refers to. Together, the
1051
+ `type()` and `id()` methods form a composite key for the identity
1052
+ map. This can be used to access the id of an async relationship
1053
+ without triggering a fetch that would normally happen if you
1054
+ attempted to use `record.relationship.id`.
1055
+ Example
1056
+ ```javascript
1057
+ // models/blog.js
1058
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1059
+ export default class BlogModel extends Model {
1060
+ @belongsTo('user', { async: true, inverse: null }) user;
1061
+ }
1062
+ let blog = store.push({
1063
+ data: {
1064
+ type: 'blog',
1065
+ id: 1,
1066
+ relationships: {
1067
+ user: {
1068
+ data: { type: 'user', id: 1 }
1069
+ }
1070
+ }
1071
+ }
1072
+ });
1073
+ let userRef = blog.belongsTo('user');
1074
+ // get the identifier of the reference
1075
+ if (userRef.remoteType() === "id") {
1076
+ let id = userRef.id();
1077
+ }
1078
+ ```
1079
+ @public
1080
+ @return {String} The id of the record in this belongsTo relationship.
1081
+ */
1082
+ static {
1083
+ decorateMethodV2(this.prototype, "identifier", [memoized]);
1084
+ }
1085
+ id() {
1086
+ return this.identifier?.id || null;
1087
+ }
1088
+
1089
+ /**
1090
+ The link Ember Data will use to fetch or reload this belongs-to
1091
+ relationship. By default it uses only the "related" resource linkage.
1092
+ Example
1093
+ ```javascript
1094
+ // models/blog.js
1095
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1096
+ export default Model.extend({
1097
+ user: belongsTo('user', { async: true, inverse: null })
1098
+ });
1099
+ let blog = store.push({
1100
+ data: {
1101
+ type: 'blog',
1102
+ id: 1,
1103
+ relationships: {
1104
+ user: {
1105
+ links: {
1106
+ related: '/articles/1/author'
1107
+ }
1108
+ }
1109
+ }
1110
+ }
1111
+ });
1112
+ let userRef = blog.belongsTo('user');
1113
+ // get the identifier of the reference
1114
+ if (userRef.remoteType() === "link") {
1115
+ let link = userRef.link();
1116
+ }
1117
+ ```
1118
+ @public
1119
+ @return {String} The link Ember Data will use to fetch or reload this belongs-to relationship.
1120
+ */
1121
+ link() {
1122
+ const resource = this._resource();
1123
+ if (isResourceIdentiferWithRelatedLinks(resource)) {
1124
+ if (resource.links) {
1125
+ const related = resource.links.related;
1126
+ return !related || typeof related === 'string' ? related : related.href;
1127
+ }
1128
+ }
1129
+ return null;
1130
+ }
1131
+
1132
+ /**
1133
+ * any links that have been received for this relationship
1134
+ *
1135
+ * @public
1136
+ * @return
1137
+ */
1138
+ links() {
1139
+ const resource = this._resource();
1140
+ return resource && resource.links ? resource.links : null;
1141
+ }
1142
+
1143
+ /**
1144
+ The meta data for the belongs-to relationship.
1145
+ Example
1146
+ ```javascript
1147
+ // models/blog.js
1148
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1149
+ export default Model.extend({
1150
+ user: belongsTo('user', { async: true, inverse: null })
1151
+ });
1152
+ let blog = store.push({
1153
+ data: {
1154
+ type: 'blog',
1155
+ id: 1,
1156
+ relationships: {
1157
+ user: {
1158
+ links: {
1159
+ related: {
1160
+ href: '/articles/1/author'
1161
+ },
1162
+ },
1163
+ meta: {
1164
+ lastUpdated: 1458014400000
1165
+ }
1166
+ }
1167
+ }
1168
+ }
1169
+ });
1170
+ let userRef = blog.belongsTo('user');
1171
+ userRef.meta() // { lastUpdated: 1458014400000 }
1172
+ ```
1173
+ @public
1174
+ @return {Object} The meta information for the belongs-to relationship.
1175
+ */
1176
+ meta() {
1177
+ let meta = null;
1178
+ const resource = this._resource();
1179
+ if (resource && resource.meta && typeof resource.meta === 'object') {
1180
+ meta = resource.meta;
1181
+ }
1182
+ return meta;
1183
+ }
1184
+ _resource() {
1185
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
1186
+ this._ref; // subscribe
1187
+ const cache = this.store.cache;
1188
+ return cache.getRelationship(this.___identifier, this.key);
1189
+ }
1190
+
1191
+ /**
1192
+ This returns a string that represents how the reference will be
1193
+ looked up when it is loaded. If the relationship has a link it will
1194
+ use the "link" otherwise it defaults to "id".
1195
+ Example
1196
+ ```js [app/models/post.js]
1197
+ import Model, { hasMany } from '@warp-drive/legacy/model';
1198
+ export default class PostModel extends Model {
1199
+ @hasMany('comment', { async: true, inverse: null }) comments;
1200
+ }
1201
+ ```
1202
+ ```javascript
1203
+ let post = store.push({
1204
+ data: {
1205
+ type: 'post',
1206
+ id: 1,
1207
+ relationships: {
1208
+ comments: {
1209
+ data: [{ type: 'comment', id: 1 }]
1210
+ }
1211
+ }
1212
+ }
1213
+ });
1214
+ let commentsRef = post.hasMany('comments');
1215
+ // get the identifier of the reference
1216
+ if (commentsRef.remoteType() === "ids") {
1217
+ let ids = commentsRef.ids();
1218
+ } else if (commentsRef.remoteType() === "link") {
1219
+ let link = commentsRef.link();
1220
+ }
1221
+ ```
1222
+ @public
1223
+ @return {String} The name of the remote type. This should either be `link` or `id`
1224
+ */
1225
+ remoteType() {
1226
+ const value = this._resource();
1227
+ if (isResourceIdentiferWithRelatedLinks(value)) {
1228
+ return 'link';
1229
+ }
1230
+ return 'id';
1231
+ }
1232
+
1233
+ /**
1234
+ `push` can be used to update the data in the relationship and WarpDrive
1235
+ will treat the new data as the canonical value of this relationship on
1236
+ the backend. A value of `null` (e.g. `{ data: null }`) can be passed to
1237
+ clear the relationship.
1238
+ Example model
1239
+ ```js [app/models/blog.js]
1240
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1241
+ export default class BlogModel extends Model {
1242
+ @belongsTo('user', { async: true, inverse: null }) user;
1243
+ }
1244
+ ```
1245
+ Setup some initial state, note we haven't loaded the user yet:
1246
+ ```js
1247
+ const blog = store.push({
1248
+ data: {
1249
+ type: 'blog',
1250
+ id: '1',
1251
+ relationships: {
1252
+ user: {
1253
+ data: { type: 'user', id: '1' }
1254
+ }
1255
+ }
1256
+ }
1257
+ });
1258
+ const userRef = blog.belongsTo('user');
1259
+ userRef.id(); // '1'
1260
+ ```
1261
+ Update the state using `push`, note we can do this even without
1262
+ having loaded the user yet by providing a resource-identifier.
1263
+ Both full a resource and a resource-identifier are supported.
1264
+ ```js
1265
+ await userRef.push({
1266
+ data: {
1267
+ type: 'user',
1268
+ id: '2',
1269
+ }
1270
+ });
1271
+ userRef.id(); // '2'
1272
+ ```
1273
+ You may also pass in links and meta fore the relationship, and sideload
1274
+ additional resources that might be required.
1275
+ ```js
1276
+ await userRef.push({
1277
+ data: {
1278
+ type: 'user',
1279
+ id: '2',
1280
+ },
1281
+ links: {
1282
+ related: '/articles/1/author'
1283
+ },
1284
+ meta: {
1285
+ lastUpdated: Date.now()
1286
+ },
1287
+ included: [
1288
+ {
1289
+ type: 'user-preview',
1290
+ id: '2',
1291
+ attributes: {
1292
+ username: '@runspired'
1293
+ }
1294
+ }
1295
+ ]
1296
+ });
1297
+ ```
1298
+ By default, the store will attempt to fetch the record if it is not loaded or its
1299
+ resource data is not included in the call to `push` before resolving the returned
1300
+ promise with the new state..
1301
+ Alternatively, pass `true` as the second argument to avoid fetching unloaded records
1302
+ and instead the promise will resolve with void without attempting to fetch. This is
1303
+ particularly useful if you want to update the state of the relationship without
1304
+ forcing the load of all of the associated record.
1305
+ @public
1306
+ @param {Object} doc a JSONAPI document object describing the new value of this relationship.
1307
+ @param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
1308
+ @return {Promise<OpaqueRecordInstance | null | void>}
1309
+ */
1310
+ async push(doc, skipFetch) {
1311
+ const {
1312
+ store
1313
+ } = this;
1314
+ const isResourceData = doc.data && isMaybeResource(doc.data);
1315
+ const added = isResourceData ? store._push(doc, true) : doc.data ? store.cacheKeyManager.getOrCreateRecordIdentifier(doc.data) : null;
1316
+ const {
1317
+ identifier
1318
+ } = this.belongsToRelationship;
1319
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1320
+ if (added) {
1321
+ assertPolymorphicType(identifier, this.belongsToRelationship.definition, added, store);
1322
+ }
1323
+ }
1324
+ const newData = {};
1325
+
1326
+ // only set data if it was passed in
1327
+ if (doc.data || doc.data === null) {
1328
+ newData.data = added;
1329
+ }
1330
+ if ('links' in doc) {
1331
+ newData.links = doc.links;
1332
+ }
1333
+ if ('meta' in doc) {
1334
+ newData.meta = doc.meta;
1335
+ }
1336
+ assertPrivateStore(store);
1337
+ store._join(() => {
1338
+ this.graph.push({
1339
+ op: 'updateRelationship',
1340
+ record: identifier,
1341
+ field: this.key,
1342
+ value: newData
1343
+ });
1344
+ });
1345
+ if (!skipFetch) return this.load();
1346
+ }
1347
+
1348
+ /**
1349
+ `value()` synchronously returns the current value of the belongs-to
1350
+ relationship. Unlike `record.relationshipName`, calling
1351
+ `value()` on a reference does not trigger a fetch if the async
1352
+ relationship is not yet loaded. If the relationship is not loaded
1353
+ it will always return `null`.
1354
+ Example
1355
+ ```javascript
1356
+ // models/blog.js
1357
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1358
+ export default class BlogModel extends Model {
1359
+ @belongsTo('user', { async: true, inverse: null }) user;
1360
+ }
1361
+ let blog = store.push({
1362
+ data: {
1363
+ type: 'blog',
1364
+ id: 1,
1365
+ relationships: {
1366
+ user: {
1367
+ data: { type: 'user', id: 1 }
1368
+ }
1369
+ }
1370
+ }
1371
+ });
1372
+ let userRef = blog.belongsTo('user');
1373
+ userRef.value(); // null
1374
+ // provide data for reference
1375
+ userRef.push({
1376
+ data: {
1377
+ type: 'user',
1378
+ id: 1,
1379
+ attributes: {
1380
+ username: "@user"
1381
+ }
1382
+ }
1383
+ }).then(function(user) {
1384
+ userRef.value(); // user
1385
+ });
1386
+ ```
1387
+ @public
1388
+ @return {Model} the record in this relationship
1389
+ */
1390
+ value() {
1391
+ const resource = this._resource();
1392
+ return resource && resource.data ? this.store.peekRecord(resource.data) : null;
1393
+ }
1394
+
1395
+ /**
1396
+ Loads a record in a belongs-to relationship if it is not already
1397
+ loaded. If the relationship is already loaded this method does not
1398
+ trigger a new load.
1399
+ Example
1400
+ ```javascript
1401
+ // models/blog.js
1402
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1403
+ export default class BlogModel extends Model {
1404
+ @belongsTo('user', { async: true, inverse: null }) user;
1405
+ }
1406
+ let blog = store.push({
1407
+ data: {
1408
+ type: 'blog',
1409
+ id: 1,
1410
+ relationships: {
1411
+ user: {
1412
+ data: { type: 'user', id: 1 }
1413
+ }
1414
+ }
1415
+ }
1416
+ });
1417
+ let userRef = blog.belongsTo('user');
1418
+ userRef.value(); // null
1419
+ userRef.load().then(function(user) {
1420
+ userRef.value() === user
1421
+ });
1422
+ ```
1423
+ You may also pass in an options object whose properties will be
1424
+ fed forward. This enables you to pass `adapterOptions` into the
1425
+ request given to the adapter via the reference.
1426
+ Example
1427
+ ```javascript
1428
+ userRef.load({ adapterOptions: { isPrivate: true } }).then(function(user) {
1429
+ userRef.value() === user;
1430
+ });
1431
+ ```
1432
+ ```js [app/adapters/user.js]
1433
+ import Adapter from '@warp-drive/legacy/adapter';
1434
+ export default class UserAdapter extends Adapter {
1435
+ findRecord(store, type, id, snapshot) {
1436
+ // In the adapter you will have access to adapterOptions.
1437
+ let adapterOptions = snapshot.adapterOptions;
1438
+ }
1439
+ });
1440
+ ```
1441
+ @public
1442
+ @param {Object} options the options to pass in.
1443
+ @return {Promise} a promise that resolves with the record in this belongs-to relationship.
1444
+ */
1445
+ async load(options) {
1446
+ const support = LEGACY_SUPPORT.get(this.___identifier);
1447
+ const fetchSyncRel = !this.belongsToRelationship.definition.isAsync && !areAllInverseRecordsLoaded(this.store, this._resource());
1448
+ return fetchSyncRel ? support.reloadBelongsTo(this.key, options).then(() => this.value()) :
1449
+ // we cast to fix the return type since typescript and eslint don't understand async functions
1450
+ // properly
1451
+ support.getBelongsTo(this.key, options);
1452
+ }
1453
+
1454
+ /**
1455
+ Triggers a reload of the value in this relationship. If the
1456
+ remoteType is `"link"` Ember Data will use the relationship link to
1457
+ reload the relationship. Otherwise it will reload the record by its
1458
+ id.
1459
+ Example
1460
+ ```javascript
1461
+ // models/blog.js
1462
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1463
+ export default class BlogModel extends Model {
1464
+ @belongsTo('user', { async: true, inverse: null }) user;
1465
+ }
1466
+ let blog = store.push({
1467
+ data: {
1468
+ type: 'blog',
1469
+ id: 1,
1470
+ relationships: {
1471
+ user: {
1472
+ data: { type: 'user', id: 1 }
1473
+ }
1474
+ }
1475
+ }
1476
+ });
1477
+ let userRef = blog.belongsTo('user');
1478
+ userRef.reload().then(function(user) {
1479
+ userRef.value() === user
1480
+ });
1481
+ ```
1482
+ You may also pass in an options object whose properties will be
1483
+ fed forward. This enables you to pass `adapterOptions` into the
1484
+ request given to the adapter via the reference. A full example
1485
+ can be found in the `load` method.
1486
+ Example
1487
+ ```javascript
1488
+ userRef.reload({ adapterOptions: { isPrivate: true } })
1489
+ ```
1490
+ @public
1491
+ @param {Object} options the options to pass in.
1492
+ @return {Promise} a promise that resolves with the record in this belongs-to relationship after the reload has completed.
1493
+ */
1494
+ reload(options) {
1495
+ const support = LEGACY_SUPPORT.get(this.___identifier);
1496
+ return support.reloadBelongsTo(this.key, options).then(() => this.value());
1497
+ }
1498
+ }
1499
+ defineNonEnumerableSignal(BelongsToReference.prototype, '_ref', 0);
1500
+ const LEGACY_SUPPORT = getOrSetGlobal('LEGACY_SUPPORT', new Map());
1501
+ function lookupLegacySupport(record) {
1502
+ const identifier = recordIdentifierFor(record);
1503
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1504
+ if (!test) {
1505
+ throw new Error(`Expected a record`);
1506
+ }
1507
+ })(identifier) : {};
1508
+ let support = LEGACY_SUPPORT.get(identifier);
1509
+ if (!support) {
1510
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1511
+ if (!test) {
1512
+ throw new Error(`Memory Leak Detected`);
1513
+ }
1514
+ })(!record.isDestroyed && !record.isDestroying) : {};
1515
+ support = new LegacySupport(record, identifier);
1516
+ LEGACY_SUPPORT.set(identifier, support);
1517
+ }
1518
+ return support;
1519
+ }
1520
+
1521
+ /**
1522
+ * @hideconstructor
1523
+ */
1524
+ class LegacySupport {
1525
+ /** @internal */
1526
+
1527
+ /** @internal */
1528
+
1529
+ /** @internal */
1530
+
1531
+ /** @internal */
1532
+
1533
+ /** @internal */
1534
+
1535
+ /** @internal */
1536
+
1537
+ /** @internal */
1538
+
1539
+ /** @internal */
1540
+
1541
+ /** @internal */
1542
+
1543
+ /** @internal */
1544
+
1545
+ /** @internal */
1546
+
1547
+ constructor(record, identifier) {
1548
+ this.record = record;
1549
+ this.store = isPrivateStore(storeFor(record, false));
1550
+ this.identifier = identifier;
1551
+ this.cache = this.store.cache;
1552
+ if (this.store._graph) {
1553
+ this.graph = this.store._graph;
1554
+ }
1555
+ this._manyArrayCache = Object.create(null);
1556
+ this._relationshipPromisesCache = Object.create(null);
1557
+ this._relationshipProxyCache = Object.create(null);
1558
+ this._pending = Object.create(null);
1559
+ this.references = Object.create(null);
1560
+ }
1561
+
1562
+ /** @private */
1563
+ _syncArray(array) {
1564
+ // It’s possible the parent side of the relationship may have been destroyed by this point
1565
+ if (this.isDestroyed || this.isDestroying) {
1566
+ return;
1567
+ }
1568
+ const currentState = array[Context].source;
1569
+ const identifier = this.identifier;
1570
+ const [identifiers, jsonApi] = this._getCurrentState(identifier, array.key);
1571
+ if (jsonApi.meta) {
1572
+ array.meta = jsonApi.meta;
1573
+ }
1574
+ if (jsonApi.links) {
1575
+ array.links = jsonApi.links;
1576
+ }
1577
+ currentState.length = 0;
1578
+ fastPush(currentState, identifiers);
1579
+ }
1580
+ mutate(mutation) {
1581
+ this.cache.mutate(mutation);
1582
+ }
1583
+ _findBelongsTo(key, resource, relationship, options) {
1584
+ const name = getRealFieldName(this, key);
1585
+
1586
+ // TODO @runspired follow up if parent isNew then we should not be attempting load here
1587
+ // TODO @runspired follow up on whether this should be in the relationship requests cache
1588
+ return this._findBelongsToByJsonApiResource(resource, this.identifier, relationship, options).then(identifier => handleCompletedRelationshipRequest(this, name, relationship, identifier), e => handleCompletedRelationshipRequest(this, name, relationship, null, e));
1589
+ }
1590
+ reloadBelongsTo(key, options) {
1591
+ const loadingPromise = this._relationshipPromisesCache[key];
1592
+ if (loadingPromise) {
1593
+ return loadingPromise;
1594
+ }
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);
1598
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1599
+ if (!test) {
1600
+ throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
1601
+ }
1602
+ })(isBelongsTo(relationship)) : {};
1603
+ relationship.state.hasFailedLoadAttempt = false;
1604
+ relationship.state.shouldForceReload = true;
1605
+ const promise = this._findBelongsTo(name, resource, relationship, options);
1606
+ if (this._relationshipProxyCache[name]) {
1607
+ // @ts-expect-error
1608
+ return this._updatePromiseProxyFor('belongsTo', name, {
1609
+ promise
1610
+ });
1611
+ }
1612
+ return promise;
1613
+ }
1614
+ getBelongsTo(key, options) {
1615
+ const {
1616
+ identifier
1617
+ } = this;
1618
+ const name = getRealFieldName(this, key);
1619
+ const resource = this.store.cache.getRelationship(this.identifier, name);
1620
+ const relatedIdentifier = resource && resource.data ? resource.data : null;
1621
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1622
+ if (!test) {
1623
+ throw new Error(`Expected a stable identifier`);
1624
+ }
1625
+ })(!relatedIdentifier || isResourceKey(relatedIdentifier)) : {};
1626
+ const store = this.store;
1627
+ const relationship = this.graph.get(this.identifier, name);
1628
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1629
+ if (!test) {
1630
+ throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
1631
+ }
1632
+ })(isBelongsTo(relationship)) : {};
1633
+ const isAsync = relationship.definition.isAsync;
1634
+ const _belongsToState = {
1635
+ key,
1636
+ store,
1637
+ legacySupport: this,
1638
+ modelName: relationship.definition.type
1639
+ };
1640
+ if (isAsync) {
1641
+ if (relationship.state.hasFailedLoadAttempt) {
1642
+ return this._relationshipProxyCache[name];
1643
+ }
1644
+ const promise = this._findBelongsTo(name, resource, relationship, options);
1645
+ const isLoaded = relatedIdentifier && store._instanceCache.recordIsLoaded(relatedIdentifier);
1646
+ return this._updatePromiseProxyFor('belongsTo', name, {
1647
+ promise,
1648
+ content: isLoaded ? store._instanceCache.getRecord(relatedIdentifier) : null,
1649
+ _belongsToState
1650
+ });
1651
+ } else {
1652
+ if (relatedIdentifier === null) {
1653
+ return null;
1654
+ } else {
1655
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1656
+ if (!test) {
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> })\`)`);
1658
+ }
1659
+ })(store._instanceCache.recordIsLoaded(relatedIdentifier, true)) : {};
1660
+ return store._instanceCache.getRecord(relatedIdentifier);
1661
+ }
1662
+ }
1663
+ }
1664
+ setDirtyBelongsTo(key, value) {
1665
+ const name = getRealFieldName(this, key);
1666
+ return this.cache.mutate({
1667
+ op: 'replaceRelatedRecord',
1668
+ record: this.identifier,
1669
+ field: name,
1670
+ value: extractIdentifierFromRecord(value)
1671
+ },
1672
+ // @ts-expect-error
1673
+ true);
1674
+ }
1675
+ _getCurrentState(identifier, field) {
1676
+ const jsonApi = this.cache.getRelationship(identifier, field);
1677
+ const cache = this.store._instanceCache;
1678
+ const identifiers = [];
1679
+ if (jsonApi.data) {
1680
+ for (let i = 0; i < jsonApi.data.length; i++) {
1681
+ const relatedIdentifier = jsonApi.data[i];
1682
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1683
+ if (!test) {
1684
+ throw new Error(`Expected a stable identifier`);
1685
+ }
1686
+ })(isResourceKey(relatedIdentifier)) : {};
1687
+ if (cache.recordIsLoaded(relatedIdentifier, true)) {
1688
+ identifiers.push(relatedIdentifier);
1689
+ }
1690
+ }
1691
+ }
1692
+ return [identifiers, jsonApi];
1693
+ }
1694
+ getManyArray(key, definition) {
1695
+ const name = getRealFieldName(this, key);
1696
+ if (this.graph) {
1697
+ let manyArray = this._manyArrayCache[name];
1698
+ if (!definition) {
1699
+ definition = this.graph.get(this.identifier, name).definition;
1700
+ }
1701
+ if (!manyArray) {
1702
+ const [identifiers, doc] = this._getCurrentState(this.identifier, name);
1703
+ const field = getField(this, name);
1704
+ manyArray = createLegacyManyArray({
1705
+ store: this.store,
1706
+ // @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
1707
+ manager: this,
1708
+ source: identifiers,
1709
+ type: definition.type,
1710
+ isLoaded: !definition.isAsync,
1711
+ editable: true,
1712
+ isAsync: definition.isAsync,
1713
+ isPolymorphic: definition.isPolymorphic,
1714
+ field: field,
1715
+ identifier: this.identifier,
1716
+ links: doc.links || null,
1717
+ meta: doc.meta || null
1718
+ });
1719
+ this._manyArrayCache[name] = manyArray;
1720
+ }
1721
+ return manyArray;
1722
+ }
1723
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1724
+ {
1725
+ throw new Error('hasMany only works with the JSONAPICache');
1726
+ }
1727
+ })() : {};
1728
+ }
1729
+ fetchAsyncHasMany(key, relationship, manyArray, options) {
1730
+ const name = getRealFieldName(this, key);
1731
+ if (this.graph) {
1732
+ let loadingPromise = this._relationshipPromisesCache[name];
1733
+ if (loadingPromise) {
1734
+ return loadingPromise;
1735
+ }
1736
+ const jsonApi = this.cache.getRelationship(this.identifier, name);
1737
+ const promise = this._findHasManyByJsonApiResource(jsonApi, this.identifier, relationship, options);
1738
+ if (!promise) {
1739
+ manyArray.isLoaded = true;
1740
+ return Promise.resolve(manyArray);
1741
+ }
1742
+ loadingPromise = promise.then(() => handleCompletedRelationshipRequest(this, name, relationship, manyArray), e => handleCompletedRelationshipRequest(this, name, relationship, manyArray, e));
1743
+ this._relationshipPromisesCache[name] = loadingPromise;
1744
+ return loadingPromise;
1745
+ }
1746
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1747
+ {
1748
+ throw new Error('hasMany only works with the JSONAPICache');
1749
+ }
1750
+ })() : {};
1751
+ }
1752
+ reloadHasMany(key, options) {
1753
+ const name = getRealFieldName(this, key);
1754
+ if (this.graph) {
1755
+ const loadingPromise = this._relationshipPromisesCache[name];
1756
+ if (loadingPromise) {
1757
+ return loadingPromise;
1758
+ }
1759
+ const relationship = this.graph.get(this.identifier, name);
1760
+ const {
1761
+ definition,
1762
+ state
1763
+ } = relationship;
1764
+ state.hasFailedLoadAttempt = false;
1765
+ state.shouldForceReload = true;
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, {
1770
+ promise
1771
+ });
1772
+ }
1773
+ return promise;
1774
+ }
1775
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1776
+ {
1777
+ throw new Error(`hasMany only works with the JSONAPICache`);
1778
+ }
1779
+ })() : {};
1780
+ }
1781
+ getHasMany(key, options) {
1782
+ const name = getRealFieldName(this, key);
1783
+ if (this.graph) {
1784
+ const relationship = this.graph.get(this.identifier, name);
1785
+ const {
1786
+ definition,
1787
+ state
1788
+ } = relationship;
1789
+ const manyArray = this.getManyArray(name, definition);
1790
+ if (definition.isAsync) {
1791
+ if (state.hasFailedLoadAttempt) {
1792
+ return this._relationshipProxyCache[name];
1793
+ }
1794
+ const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
1795
+ return this._updatePromiseProxyFor('hasMany', name, {
1796
+ promise,
1797
+ content: manyArray
1798
+ });
1799
+ } else {
1800
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1801
+ if (!test) {
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> })')`);
1803
+ }
1804
+ })(!anyUnloaded(this.store, relationship)) : {};
1805
+ return manyArray;
1806
+ }
1807
+ }
1808
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1809
+ {
1810
+ throw new Error(`hasMany only works with the JSONAPICache`);
1811
+ }
1812
+ })() : {};
1813
+ }
1814
+ _updatePromiseProxyFor(kind, key, args) {
1815
+ let promiseProxy = this._relationshipProxyCache[key];
1816
+ if (kind === 'hasMany') {
1817
+ const {
1818
+ promise,
1819
+ content
1820
+ } = args;
1821
+ if (promiseProxy) {
1822
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1823
+ if (!test) {
1824
+ throw new Error(`Expected a PromiseManyArray`);
1825
+ }
1826
+ })('_update' in promiseProxy) : {};
1827
+ promiseProxy._update(promise, content);
1828
+ } else {
1829
+ promiseProxy = this._relationshipProxyCache[key] = new PromiseManyArray(promise, content);
1830
+ }
1831
+ return promiseProxy;
1832
+ }
1833
+ if (promiseProxy) {
1834
+ const {
1835
+ promise,
1836
+ content
1837
+ } = args;
1838
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1839
+ if (!test) {
1840
+ throw new Error(`Expected a PromiseBelongsTo`);
1841
+ }
1842
+ })('_belongsToState' in promiseProxy) : {};
1843
+ if (content !== undefined) {
1844
+ promiseProxy.set('content', content);
1845
+ }
1846
+ void promiseProxy.set('promise', promise);
1847
+ } else {
1848
+ promiseProxy = PromiseBelongsTo.create(args);
1849
+ this._relationshipProxyCache[key] = promiseProxy;
1850
+ }
1851
+ return promiseProxy;
1852
+ }
1853
+ referenceFor(kind, key) {
1854
+ const name = getRealFieldName(this, key);
1855
+ let reference = this.references[name];
1856
+ if (!reference) {
1857
+ if (!this.graph) {
1858
+ // TODO @runspired while this feels odd, it is not a regression in capability because we do
1859
+ // not today support references pulling from RecordDatas other than our own
1860
+ // because of the intimate API access involved. This is something we will need to redesign.
1861
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1862
+ {
1863
+ throw new Error(`snapshot.belongsTo only supported when using the JSONAPICache`);
1864
+ }
1865
+ })() : {};
1866
+ }
1867
+ const {
1868
+ graph,
1869
+ identifier
1870
+ } = this;
1871
+ const relationship = graph.get(identifier, name);
1872
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1873
+ if (kind) {
1874
+ const modelName = identifier.type;
1875
+ const actualRelationshipKind = relationship.definition.kind;
1876
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1877
+ if (!test) {
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.`);
1879
+ }
1880
+ })(actualRelationshipKind === kind) : {};
1881
+ }
1882
+ }
1883
+ const relationshipKind = relationship.definition.kind;
1884
+ if (relationshipKind === 'belongsTo') {
1885
+ reference = new BelongsToReference(this.store, graph, identifier, relationship, key);
1886
+ } else if (relationshipKind === 'hasMany') {
1887
+ reference = new HasManyReference(this.store, graph, identifier, relationship, key);
1888
+ }
1889
+ this.references[name] = reference;
1890
+ }
1891
+ return reference;
1892
+ }
1893
+ _findHasManyByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
1894
+ if (this.graph) {
1895
+ if (!resource) {
1896
+ return;
1897
+ }
1898
+ const {
1899
+ definition,
1900
+ state
1901
+ } = relationship;
1902
+ upgradeStore(this.store);
1903
+ const adapter = this.store.adapterFor?.(definition.type);
1904
+ const {
1905
+ isStale,
1906
+ hasDematerializedInverse,
1907
+ hasReceivedData,
1908
+ isEmpty,
1909
+ shouldForceReload
1910
+ } = state;
1911
+ const allInverseRecordsAreLoaded = areAllInverseRecordsLoaded(this.store, resource);
1912
+ const identifiers = resource.data;
1913
+ const shouldFindViaLink = resource.links && resource.links.related && (typeof adapter?.findHasMany === 'function' || typeof identifiers === 'undefined') && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
1914
+ const field = this.store.schema.fields({
1915
+ type: definition.inverseType
1916
+ }).get(definition.key);
1917
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1918
+ if (!test) {
1919
+ throw new Error(`Expected a hasMany field definition for ${definition.inverseType}.${definition.key}`);
1920
+ }
1921
+ })(field && field.kind === 'hasMany') : {};
1922
+ const request = {
1923
+ useLink: shouldFindViaLink,
1924
+ field,
1925
+ links: resource.links,
1926
+ meta: resource.meta,
1927
+ options,
1928
+ record: parentIdentifier
1929
+ };
1930
+
1931
+ // fetch via link
1932
+ if (shouldFindViaLink) {
1933
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1934
+ if (!test) {
1935
+ throw new Error(`Expected collection to be an array`);
1936
+ }
1937
+ })(!identifiers || Array.isArray(identifiers)) : {};
1938
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1939
+ if (!test) {
1940
+ throw new Error(`Expected stable identifiers`);
1941
+ }
1942
+ })(!identifiers || identifiers.every(isResourceKey)) : {};
1943
+ const req = field.options.linksMode ? {
1944
+ url: getRelatedLink(resource),
1945
+ op: 'findHasMany',
1946
+ method: 'GET',
1947
+ records: identifiers || [],
1948
+ data: request,
1949
+ [EnableHydration]: false
1950
+ } : {
1951
+ op: 'findHasMany',
1952
+ records: identifiers || [],
1953
+ data: request,
1954
+ cacheOptions: {
1955
+ [Symbol.for('wd:skip-cache')]: true
1956
+ }
1957
+ };
1958
+ return this.store.request(req);
1959
+ }
1960
+ const preferLocalCache = hasReceivedData && !isEmpty;
1961
+ const hasLocalPartialData = hasDematerializedInverse || isEmpty && Array.isArray(identifiers) && identifiers.length > 0;
1962
+ const attemptLocalCache = !shouldForceReload && !isStale && (preferLocalCache || hasLocalPartialData);
1963
+ if (attemptLocalCache && allInverseRecordsAreLoaded) {
1964
+ return;
1965
+ }
1966
+ const hasData = hasReceivedData && !isEmpty;
1967
+ if (attemptLocalCache || hasData || hasLocalPartialData) {
1968
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1969
+ if (!test) {
1970
+ throw new Error(`Expected collection to be an array`);
1971
+ }
1972
+ })(Array.isArray(identifiers)) : {};
1973
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1974
+ if (!test) {
1975
+ throw new Error(`Expected stable identifiers`);
1976
+ }
1977
+ })(identifiers.every(isResourceKey)) : {};
1978
+ options.reload = options.reload || !attemptLocalCache || undefined;
1979
+ return this.store.request({
1980
+ op: 'findHasMany',
1981
+ records: identifiers,
1982
+ data: request,
1983
+ cacheOptions: {
1984
+ [Symbol.for('wd:skip-cache')]: true
1985
+ }
1986
+ });
1987
+ }
1988
+
1989
+ // we were explicitly told we have no data and no links.
1990
+ // TODO if the relationshipIsStale, should we hit the adapter anyway?
1991
+ return;
1992
+ }
1993
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1994
+ {
1995
+ throw new Error(`hasMany only works with the JSONAPICache`);
1996
+ }
1997
+ })() : {};
1998
+ }
1999
+ _findBelongsToByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
2000
+ if (!resource) {
2001
+ return Promise.resolve(null);
2002
+ }
2003
+ const key = relationship.definition.key;
2004
+ const name = getRealFieldName(this, key);
2005
+
2006
+ // interleaved promises mean that we MUST cache this here
2007
+ // in order to prevent infinite re-render if the request
2008
+ // fails.
2009
+ if (this._pending[name]) {
2010
+ return this._pending[name];
2011
+ }
2012
+ const identifier = resource.data ? resource.data : null;
2013
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2014
+ if (!test) {
2015
+ throw new Error(`Expected a stable identifier`);
2016
+ }
2017
+ })(!identifier || isResourceKey(identifier)) : {};
2018
+ const {
2019
+ isStale,
2020
+ hasDematerializedInverse,
2021
+ hasReceivedData,
2022
+ isEmpty,
2023
+ shouldForceReload
2024
+ } = relationship.state;
2025
+ const allInverseRecordsAreLoaded = areAllInverseRecordsLoaded(this.store, resource);
2026
+ const shouldFindViaLink = resource.links?.related && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
2027
+ const field = this.store.schema.fields(this.identifier).get(relationship.definition.key);
2028
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2029
+ if (!test) {
2030
+ throw new Error(`Attempted to access a belongsTo relationship but no definition exists for it`);
2031
+ }
2032
+ })(field && field.kind === 'belongsTo') : {};
2033
+ const request = {
2034
+ useLink: shouldFindViaLink,
2035
+ field,
2036
+ links: resource.links,
2037
+ meta: resource.meta,
2038
+ options,
2039
+ record: parentIdentifier
2040
+ };
2041
+
2042
+ // fetch via link
2043
+ if (shouldFindViaLink) {
2044
+ const req = field.options.linksMode ? {
2045
+ url: getRelatedLink(resource),
2046
+ op: 'findBelongsTo',
2047
+ method: 'GET',
2048
+ records: identifier ? [identifier] : [],
2049
+ data: request,
2050
+ [EnableHydration]: false
2051
+ } : {
2052
+ op: 'findBelongsTo',
2053
+ records: identifier ? [identifier] : [],
2054
+ data: request,
2055
+ cacheOptions: {
2056
+ [Symbol.for('wd:skip-cache')]: true
2057
+ }
2058
+ };
2059
+ const future = this.store.request(req);
2060
+ this._pending[name] = future.then(doc => field.options.linksMode ? doc.content.data : doc.content).finally(() => {
2061
+ this._pending[name] = undefined;
2062
+ });
2063
+ return this._pending[name];
2064
+ }
2065
+ const preferLocalCache = hasReceivedData && allInverseRecordsAreLoaded && !isEmpty;
2066
+ const hasLocalPartialData = hasDematerializedInverse || isEmpty && resource.data;
2067
+ // null is explicit empty, undefined is "we don't know anything"
2068
+ const localDataIsEmpty = !identifier;
2069
+ const attemptLocalCache = !shouldForceReload && !isStale && (preferLocalCache || hasLocalPartialData);
2070
+
2071
+ // we dont need to fetch and are empty
2072
+ if (attemptLocalCache && localDataIsEmpty) {
2073
+ return Promise.resolve(null);
2074
+ }
2075
+
2076
+ // we dont need to fetch because we are local state
2077
+ const resourceIsLocal = identifier?.id === null;
2078
+ if (attemptLocalCache && allInverseRecordsAreLoaded || resourceIsLocal) {
2079
+ return Promise.resolve(identifier);
2080
+ }
2081
+
2082
+ // we may need to fetch
2083
+ if (identifier) {
2084
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2085
+ if (!test) {
2086
+ throw new Error(`Cannot fetch belongs-to relationship with no information`);
2087
+ }
2088
+ })(identifier) : {};
2089
+ options.reload = options.reload || !attemptLocalCache || undefined;
2090
+ this._pending[name] = this.store.request({
2091
+ op: 'findBelongsTo',
2092
+ records: [identifier],
2093
+ data: request,
2094
+ cacheOptions: {
2095
+ [Symbol.for('wd:skip-cache')]: true
2096
+ }
2097
+ }).then(doc => doc.content).finally(() => {
2098
+ this._pending[name] = undefined;
2099
+ });
2100
+ return this._pending[name];
2101
+ }
2102
+
2103
+ // we were explicitly told we have no data and no links.
2104
+ // TODO if the relationshipIsStale, should we hit the adapter anyway?
2105
+ return Promise.resolve(null);
2106
+ }
2107
+ destroy() {
2108
+ this.isDestroying = true;
2109
+ let cache = this._manyArrayCache;
2110
+ this._manyArrayCache = Object.create(null);
2111
+ Object.keys(cache).forEach(key => {
2112
+ cache[key].destroy();
2113
+ });
2114
+ cache = this._relationshipProxyCache;
2115
+ this._relationshipProxyCache = Object.create(null);
2116
+ Object.keys(cache).forEach(key => {
2117
+ const proxy = cache[key];
2118
+ if (proxy.destroy) {
2119
+ proxy.destroy();
2120
+ }
2121
+ });
2122
+ cache = this.references;
2123
+ this.references = Object.create(null);
2124
+ Object.keys(cache).forEach(key => {
2125
+ cache[key].destroy();
2126
+ });
2127
+ this.isDestroyed = true;
2128
+ }
2129
+ }
2130
+ function getRelatedLink(resource) {
2131
+ const related = resource.links?.related;
2132
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2133
+ if (!test) {
2134
+ throw new Error(`Expected a related link`);
2135
+ }
2136
+ })(related) : {};
2137
+ return typeof related === 'object' ? related.href : related;
2138
+ }
2139
+ function handleCompletedRelationshipRequest(recordExt, key, relationship, value, error) {
2140
+ delete recordExt._relationshipPromisesCache[key];
2141
+ relationship.state.shouldForceReload = false;
2142
+ const isHasMany = relationship.definition.kind === 'hasMany';
2143
+ if (isHasMany) {
2144
+ // we don't notify the record property here to avoid refetch
2145
+ // only the many array
2146
+ notifyInternalSignal(value[Context].signal);
2147
+ }
2148
+ if (error) {
2149
+ relationship.state.hasFailedLoadAttempt = true;
2150
+ const proxy = recordExt._relationshipProxyCache[key];
2151
+ // belongsTo relationships are sometimes unloaded
2152
+ // when a load fails, in this case we need
2153
+ // to make sure that we aren't proxying
2154
+ // to destroyed content
2155
+ // for the sync belongsTo reload case there will be no proxy
2156
+ // for the async reload case there will be no proxy if the ui
2157
+ // has never been accessed
2158
+ if (proxy && !isHasMany) {
2159
+ // @ts-expect-error unsure why this is not resolving the boolean but async belongsTo is weird
2160
+ if (proxy.content && proxy.content.isDestroying) {
2161
+ proxy.set('content', null);
2162
+ }
2163
+ recordExt.store.notifications._flush();
2164
+ }
2165
+ throw error;
2166
+ }
2167
+ if (isHasMany) {
2168
+ value.isLoaded = true;
2169
+ } else {
2170
+ recordExt.store.notifications._flush();
2171
+ }
2172
+ relationship.state.hasFailedLoadAttempt = false;
2173
+ // only set to not stale if no error is thrown
2174
+ relationship.state.isStale = false;
2175
+ return isHasMany || !value ? value : recordExt.store.peekRecord(value);
2176
+ }
2177
+ function extractIdentifierFromRecord(record) {
2178
+ if (!record) {
2179
+ return null;
2180
+ }
2181
+ return recordIdentifierFor(record);
2182
+ }
2183
+ function anyUnloaded(store, relationship) {
2184
+ assertPrivateStore(store);
2185
+ const graph = store._graph;
2186
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2187
+ if (!test) {
2188
+ throw new Error(`Expected a Graph instance to be available`);
2189
+ }
2190
+ })(graph) : {};
2191
+ const relationshipData = graph.getData(relationship.identifier, relationship.definition.key);
2192
+ const state = relationshipData.data;
2193
+ const cache = store._instanceCache;
2194
+ const unloaded = state?.find(s => {
2195
+ const isLoaded = cache.recordIsLoaded(s, true);
2196
+ return !isLoaded;
2197
+ });
2198
+ return unloaded || false;
2199
+ }
2200
+ function areAllInverseRecordsLoaded(store, resource) {
2201
+ assertPrivateStore(store);
2202
+ const instanceCache = store._instanceCache;
2203
+ const identifiers = resource.data;
2204
+ if (Array.isArray(identifiers)) {
2205
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2206
+ if (!test) {
2207
+ throw new Error(`Expected stable identifiers`);
2208
+ }
2209
+ })(identifiers.every(isResourceKey)) : {};
2210
+ // treat as collection
2211
+ // check for unloaded records
2212
+ return identifiers.every(identifier => instanceCache.recordIsLoaded(identifier));
2213
+ }
2214
+
2215
+ // treat as single resource
2216
+ if (!identifiers) return true;
2217
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2218
+ if (!test) {
2219
+ throw new Error(`Expected stable identifiers`);
2220
+ }
2221
+ })(isResourceKey(identifiers)) : {};
2222
+ return instanceCache.recordIsLoaded(identifiers);
2223
+ }
2224
+ function isBelongsTo(relationship) {
2225
+ return relationship.definition.kind === 'belongsTo';
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
+ }
2238
+
2239
+ // we force the type here to our own construct because mixin and extend patterns
2240
+ // lose generic signatures. We also do this because we need to Omit `clear` from
2241
+ // the type of ArrayProxy as we override it's signature.
2242
+ const ArrayProxyWithCustomOverrides = ArrayProxy;
2243
+
2244
+ /**
2245
+ Holds validation errors for a given record, organized by attribute names.
2246
+
2247
+ This class is not directly instantiable.
2248
+
2249
+ Every `Model` has an `errors` property that is an instance of
2250
+ `Errors`. This can be used to display validation error
2251
+ messages returned from the server when a `record.save()` rejects.
2252
+
2253
+ For Example, if you had a `User` model that looked like this:
2254
+
2255
+ ```js [app/models/user.js]
2256
+ import { Model, attr } from '@warp-drive/legacy/model';
2257
+
2258
+ export default class UserModel extends Model {
2259
+ @attr('string') username;
2260
+ @attr('string') email;
2261
+ }
2262
+ ```
2263
+ And you attempted to save a record that did not validate on the backend:
2264
+
2265
+ ```javascript
2266
+ let user = store.createRecord('user', {
2267
+ username: 'tomster',
2268
+ email: 'invalidEmail'
2269
+ });
2270
+ user.save();
2271
+ ```
2272
+
2273
+ Your backend would be expected to return an error response that described
2274
+ the problem, so that error messages can be generated on the app.
2275
+
2276
+ API responses will be translated into instances of `Errors` differently,
2277
+ depending on the specific combination of adapter and serializer used. You
2278
+ may want to check the documentation or the source code of the libraries
2279
+ that you are using, to know how they expect errors to be communicated.
2280
+
2281
+ Errors can be displayed to the user by accessing their property name
2282
+ to get an array of all the error objects for that property. Each
2283
+ error object is a JavaScript object with two keys:
2284
+
2285
+ - `message` A string containing the error message from the backend
2286
+ - `attribute` The name of the property associated with this error message
2287
+
2288
+ ```handlebars
2289
+ <label>Username: <Input @value={{@model.username}} /> </label>
2290
+ {{#each @model.errors.username as |error|}}
2291
+ <div class="error">
2292
+ {{error.message}}
2293
+ </div>
2294
+ {{/each}}
2295
+
2296
+ <label>Email: <Input @value={{@model.email}} /> </label>
2297
+ {{#each @model.errors.email as |error|}}
2298
+ <div class="error">
2299
+ {{error.message}}
2300
+ </div>
2301
+ {{/each}}
2302
+ ```
2303
+
2304
+ You can also access the special `messages` property on the error
2305
+ object to get an array of all the error strings.
2306
+
2307
+ ```handlebars
2308
+ {{#each @model.errors.messages as |message|}}
2309
+ <div class="error">
2310
+ {{message}}
2311
+ </div>
2312
+ {{/each}}
2313
+ ```
2314
+
2315
+ @class Errors
2316
+ @public
2317
+ */
2318
+ class Errors extends ArrayProxyWithCustomOverrides {
2319
+ /**
2320
+ @property errorsByAttributeName
2321
+ @type {MapWithDefault}
2322
+ @private
2323
+ */
2324
+ get errorsByAttributeName() {
2325
+ return new Map();
2326
+ }
2327
+
2328
+ /**
2329
+ Returns errors for a given attribute
2330
+ ```javascript
2331
+ let user = store.createRecord('user', {
2332
+ username: 'tomster',
2333
+ email: 'invalidEmail'
2334
+ });
2335
+ user.save().catch(function(){
2336
+ user.errors.errorsFor('email'); // returns:
2337
+ // [{attribute: "email", message: "Doesn't look like a valid email."}]
2338
+ });
2339
+ ```
2340
+ @public
2341
+ @param {String} attribute
2342
+ @return {Array}
2343
+ */
2344
+ static {
2345
+ decorateMethodV2(this.prototype, "errorsByAttributeName", [computed()]);
2346
+ }
2347
+ errorsFor(attribute) {
2348
+ const map = this.errorsByAttributeName;
2349
+ let errors = map.get(attribute);
2350
+ if (errors === undefined) {
2351
+ errors = A();
2352
+ map.set(attribute, errors);
2353
+ }
2354
+
2355
+ // Errors may be a native array with extensions turned on. Since we access
2356
+ // the array via a method, and not a computed or using `Ember.get`, it does
2357
+ // not entangle properly with autotracking, so we entangle manually by
2358
+ // getting the `[]` property.
2359
+ get(errors, '[]');
2360
+ return errors;
2361
+ }
2362
+
2363
+ /**
2364
+ An array containing all of the error messages for this
2365
+ record. This is useful for displaying all errors to the user.
2366
+ ```handlebars
2367
+ {{#each @model.errors.messages as |message|}}
2368
+ <div class="error">
2369
+ {{message}}
2370
+ </div>
2371
+ {{/each}}
2372
+ ```
2373
+ @property messages
2374
+ @public
2375
+ @type {Array}
2376
+ */
2377
+ static {
2378
+ decorateFieldV2(this.prototype, "messages", [mapBy('content', 'message')]);
2379
+ }
2380
+ #messages = (initializeDeferredDecorator(this, "messages"), void 0);
2381
+ /**
2382
+ @property content
2383
+ @type {Array}
2384
+ @private
2385
+ */
2386
+ get content() {
2387
+ return A();
2388
+ }
2389
+
2390
+ /**
2391
+ @private
2392
+ */
2393
+ static {
2394
+ decorateMethodV2(this.prototype, "content", [computed()]);
2395
+ }
2396
+ unknownProperty(attribute) {
2397
+ const errors = this.errorsFor(attribute);
2398
+ if (errors.length === 0) {
2399
+ return undefined;
2400
+ }
2401
+ return errors;
2402
+ }
2403
+
2404
+ /**
2405
+ Total number of errors.
2406
+ @property length
2407
+ @type {Number}
2408
+ @public
2409
+ @readonly
2410
+ */
2411
+
2412
+ /**
2413
+ `true` if we have no errors.
2414
+ @property isEmpty
2415
+ @type {Boolean}
2416
+ @public
2417
+ @readonly
2418
+ */
2419
+ static {
2420
+ decorateFieldV2(this.prototype, "isEmpty", [not('length')]);
2421
+ }
2422
+ #isEmpty = (initializeDeferredDecorator(this, "isEmpty"), void 0);
2423
+ /**
2424
+ Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
2425
+ the record and transition the record into an `invalid` state.
2426
+ Example
2427
+ ```javascript
2428
+ let errors = user.errors;
2429
+ // add multiple errors
2430
+ errors.add('password', [
2431
+ 'Must be at least 12 characters',
2432
+ 'Must contain at least one symbol',
2433
+ 'Cannot contain your name'
2434
+ ]);
2435
+ errors.errorsFor('password');
2436
+ // =>
2437
+ // [
2438
+ // { attribute: 'password', message: 'Must be at least 12 characters' },
2439
+ // { attribute: 'password', message: 'Must contain at least one symbol' },
2440
+ // { attribute: 'password', message: 'Cannot contain your name' },
2441
+ // ]
2442
+ // add a single error
2443
+ errors.add('username', 'This field is required');
2444
+ errors.errorsFor('username');
2445
+ // =>
2446
+ // [
2447
+ // { attribute: 'username', message: 'This field is required' },
2448
+ // ]
2449
+ ```
2450
+ @public
2451
+ @param {String} attribute - the property name of an attribute or relationship
2452
+ @param {string[]|string} messages - an error message or array of error messages for the attribute
2453
+ */
2454
+ add(attribute, messages) {
2455
+ const errors = this._findOrCreateMessages(attribute, messages);
2456
+ this.addObjects(errors);
2457
+ this.errorsFor(attribute).addObjects(errors);
2458
+ this.__record.currentState.notify('isValid');
2459
+ this.notifyPropertyChange(attribute);
2460
+ }
2461
+
2462
+ /**
2463
+ @private
2464
+ */
2465
+ _findOrCreateMessages(attribute, messages) {
2466
+ const errors = this.errorsFor(attribute);
2467
+ const messagesArray = Array.isArray(messages) ? messages : [messages];
2468
+ const _messages = new Array(messagesArray.length);
2469
+ for (let i = 0; i < messagesArray.length; i++) {
2470
+ const message = messagesArray[i];
2471
+ const err = errors.findBy('message', message);
2472
+ if (err) {
2473
+ _messages[i] = err;
2474
+ } else {
2475
+ _messages[i] = {
2476
+ attribute: attribute,
2477
+ message
2478
+ };
2479
+ }
2480
+ }
2481
+ return _messages;
2482
+ }
2483
+
2484
+ /**
2485
+ Manually removes all errors for a given member from the record.
2486
+ This will transition the record into a `valid` state, and
2487
+ triggers the `becameValid` event and lifecycle method.
2488
+ Example:
2489
+ ```javascript
2490
+ let errors = user.errors;
2491
+ errors.add('phone', ['error-1', 'error-2']);
2492
+ errors.errorsFor('phone');
2493
+ // =>
2494
+ // [
2495
+ // { attribute: 'phone', message: 'error-1' },
2496
+ // { attribute: 'phone', message: 'error-2' },
2497
+ // ]
2498
+ errors.remove('phone');
2499
+ errors.errorsFor('phone');
2500
+ // => undefined
2501
+ ```
2502
+ @public
2503
+ @param {String} member - the property name of an attribute or relationship
2504
+ */
2505
+ remove(attribute) {
2506
+ if (this.isEmpty) {
2507
+ return;
2508
+ }
2509
+ const content = this.rejectBy('attribute', attribute);
2510
+ this.content.setObjects(content);
2511
+
2512
+ // Although errorsByAttributeName.delete is technically enough to sync errors state, we also
2513
+ // must mutate the array as well for autotracking
2514
+ const errors = this.errorsFor(attribute);
2515
+ for (let i = 0; i < errors.length; i++) {
2516
+ if (errors[i].attribute === attribute) {
2517
+ // .replace from Ember.NativeArray is necessary. JS splice will not work.
2518
+ errors.replace(i, 1);
2519
+ }
2520
+ }
2521
+ this.errorsByAttributeName.delete(attribute);
2522
+ this.__record.currentState.notify('isValid');
2523
+ this.notifyPropertyChange(attribute);
2524
+ this.notifyPropertyChange('length');
2525
+ }
2526
+
2527
+ /**
2528
+ Manually clears all errors for the record.
2529
+ This will transition the record into a `valid` state, and
2530
+ will trigger the `becameValid` event and lifecycle method.
2531
+ Example:
2532
+ ```javascript
2533
+ let errors = user.errors;
2534
+ errors.add('username', ['error-a']);
2535
+ errors.add('phone', ['error-1', 'error-2']);
2536
+ errors.errorsFor('username');
2537
+ // =>
2538
+ // [
2539
+ // { attribute: 'username', message: 'error-a' },
2540
+ // ]
2541
+ errors.errorsFor('phone');
2542
+ // =>
2543
+ // [
2544
+ // { attribute: 'phone', message: 'error-1' },
2545
+ // { attribute: 'phone', message: 'error-2' },
2546
+ // ]
2547
+ errors.clear();
2548
+ errors.errorsFor('username');
2549
+ // => undefined
2550
+ errors.errorsFor('phone');
2551
+ // => undefined
2552
+ errors.messages
2553
+ // => []
2554
+ ```
2555
+ @public
2556
+ */
2557
+ clear() {
2558
+ if (this.isEmpty) {
2559
+ return;
2560
+ }
2561
+ const errorsByAttributeName = this.errorsByAttributeName;
2562
+ const attributes = [];
2563
+ errorsByAttributeName.forEach(function (_, attribute) {
2564
+ attributes.push(attribute);
2565
+ });
2566
+ errorsByAttributeName.clear();
2567
+ attributes.forEach(attribute => {
2568
+ this.notifyPropertyChange(attribute);
2569
+ });
2570
+ this.__record.currentState.notify('isValid');
2571
+ super.clear();
2572
+ }
2573
+
2574
+ /**
2575
+ Checks if there are error messages for the given attribute.
2576
+ ```js [app/controllers/user/edit.js]
2577
+ export default class UserEditController extends Controller {
2578
+ @action
2579
+ save(user) {
2580
+ if (user.errors.has('email')) {
2581
+ return alert('Please update your email before attempting to save.');
2582
+ }
2583
+ user.save();
2584
+ }
2585
+ }
2586
+ ```
2587
+ @public
2588
+ @param {String} attribute
2589
+ @return {Boolean} true if there some errors on given attribute
2590
+ */
2591
+ has(attribute) {
2592
+ return this.errorsFor(attribute).length > 0;
2593
+ }
2594
+ }
2595
+ export { Errors as E, LEGACY_SUPPORT as L, PromiseBelongsTo as P, PromiseManyArray as a, lookupLegacySupport as l };