@warp-drive/legacy 5.9.0-alpha.21 → 5.9.0-alpha.23

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