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

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-XgLAkYVs.js +1130 -0
  21. package/dist/adapter-XgLAkYVs.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-LQhmDVdd.js +2134 -0
  46. package/dist/errors-LQhmDVdd.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-BtIEHqYZ.js +683 -0
  64. package/dist/model-BtIEHqYZ.js.map +1 -0
  65. package/dist/model-fragments-Dpn9285r.js +334 -0
  66. package/dist/model-fragments-Dpn9285r.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-BgO3Lyjx.js +53 -0
  76. package/dist/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  77. package/dist/schema-provider-DsKuB5Wb.js +1929 -0
  78. package/dist/schema-provider-DsKuB5Wb.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-Cw0uSl8d.js +1129 -0
  115. package/dist/unpkg/dev/adapter-Cw0uSl8d.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-CeyxXB7K.js +825 -0
  125. package/dist/unpkg/dev/compat-CeyxXB7K.js.map +1 -0
  126. package/dist/unpkg/dev/compat.js +1 -1178
  127. package/dist/unpkg/dev/errors-1javxsPo.js +2127 -0
  128. package/dist/unpkg/dev/errors-1javxsPo.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-C9Xb1R1x.js +655 -0
  137. package/dist/unpkg/dev/model-C9Xb1R1x.js.map +1 -0
  138. package/dist/unpkg/dev/model-fragments-Dpn9285r.js +334 -0
  139. package/dist/unpkg/dev/model-fragments-Dpn9285r.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-BgO3Lyjx.js +53 -0
  143. package/dist/unpkg/dev/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  144. package/dist/unpkg/dev/schema-provider-Dy6c1J5f.js +1834 -0
  145. package/dist/unpkg/dev/schema-provider-Dy6c1J5f.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-Cw0uSl8d.js +1129 -0
  174. package/dist/unpkg/dev-deprecated/adapter-Cw0uSl8d.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-DmAgB2NS.js +825 -0
  184. package/dist/unpkg/dev-deprecated/compat-DmAgB2NS.js.map +1 -0
  185. package/dist/unpkg/dev-deprecated/compat.js +1 -1178
  186. package/dist/unpkg/dev-deprecated/errors-C4_aOhY5.js +2128 -0
  187. package/dist/unpkg/dev-deprecated/errors-C4_aOhY5.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-CvSMYkgs.js +660 -0
  196. package/dist/unpkg/dev-deprecated/model-CvSMYkgs.js.map +1 -0
  197. package/dist/unpkg/dev-deprecated/model-fragments-Dpn9285r.js +334 -0
  198. package/dist/unpkg/dev-deprecated/model-fragments-Dpn9285r.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-BgO3Lyjx.js +53 -0
  202. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  203. package/dist/unpkg/dev-deprecated/schema-provider-Cqttza94.js +1835 -0
  204. package/dist/unpkg/dev-deprecated/schema-provider-Cqttza94.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-Wnk7jizX.js +1111 -0
  233. package/dist/unpkg/prod/adapter-Wnk7jizX.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-Co7YWHoA.js +1977 -0
  246. package/dist/unpkg/prod/errors-Co7YWHoA.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-BzoOmtka.js +603 -0
  255. package/dist/unpkg/prod/model-BzoOmtka.js.map +1 -0
  256. package/dist/unpkg/prod/model-fragments-Dpn9285r.js +334 -0
  257. package/dist/unpkg/prod/model-fragments-Dpn9285r.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-BgO3Lyjx.js +53 -0
  261. package/dist/unpkg/prod/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  262. package/dist/unpkg/prod/schema-provider-CKZcqWyP.js +1622 -0
  263. package/dist/unpkg/prod/schema-provider-CKZcqWyP.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-Wnk7jizX.js} +445 -110
  292. package/dist/unpkg/prod-deprecated/adapter-Wnk7jizX.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-C-opde61.js +1978 -0
  305. package/dist/unpkg/prod-deprecated/errors-C-opde61.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-C0bTXzGn.js +604 -0
  314. package/dist/unpkg/prod-deprecated/model-C0bTXzGn.js.map +1 -0
  315. package/dist/unpkg/prod-deprecated/model-fragments-Dpn9285r.js +334 -0
  316. package/dist/unpkg/prod-deprecated/model-fragments-Dpn9285r.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-BgO3Lyjx.js +53 -0
  320. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BgO3Lyjx.js.map +1 -0
  321. package/dist/unpkg/prod-deprecated/schema-provider-lH3qP5tw.js +1635 -0
  322. package/dist/unpkg/prod-deprecated/schema-provider-lH3qP5tw.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 +13 -13
  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
@@ -0,0 +1,2134 @@
1
+ import { t as upgradeStore } from "./-private-DccRZQsm.js";
2
+ import { n as decorateMethodV2, r as initializeDeferredDecorator, t as decorateFieldV2 } from "./runtime-BPCpkOf1-BgO3Lyjx.js";
3
+ import { assertPrivateStore, createLegacyManyArray, fastPush, isPrivateStore, isResourceKey, recordIdentifierFor, storeFor } from "@warp-drive/core/store/-private";
4
+ import { Context } from "@warp-drive/core/reactive/-private";
5
+ import { defineNonEnumerableSignal, defineSignal, memoized, notifyInternalSignal } from "@warp-drive/core/signals/-leaked";
6
+ import { getOrSetGlobal } from "@warp-drive/core/types/-private";
7
+ import { getGlobalConfig, macroCondition } from "@embroider/macros";
8
+ import { computed, get } from "@ember/object";
9
+ import { EnableHydration } from "@warp-drive/core/types/request";
10
+ import PromiseProxyMixin from "@ember/object/promise-proxy-mixin";
11
+ import ObjectProxy from "@ember/object/proxy";
12
+ import { A } from "@ember/array";
13
+ import ArrayProxy from "@ember/array/proxy";
14
+ import { mapBy, not } from "@ember/object/computed";
15
+
16
+ //#region src/model/-private/promise-proxy-base.js
17
+ const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
18
+
19
+ //#endregion
20
+ //#region src/model/-private/promise-belongs-to.ts
21
+ const LegacyPromiseProxy = Symbol.for("LegacyPromiseProxy");
22
+ const Extended = PromiseObject;
23
+ /**
24
+ A PromiseBelongsTo is a PromiseObject that also proxies certain method calls
25
+ to the underlying belongsTo model.
26
+ Right now we proxy:
27
+ * `reload()`
28
+ @class PromiseBelongsTo
29
+ @private
30
+ */
31
+ var PromiseBelongsTo = class extends Extended {
32
+ get id() {
33
+ const { key, legacySupport } = this._belongsToState;
34
+ return legacySupport.referenceFor("belongsTo", key).id();
35
+ }
36
+ static {
37
+ decorateMethodV2(this.prototype, "id", [memoized]);
38
+ }
39
+ get meta() {
40
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
41
+ if (!test) throw new Error(`You attempted to access meta on the promise for the async belongsTo relationship ${this._belongsToState.modelName}:${this._belongsToState.key}'.
42
+ Use \`record.belongsTo(relationshipName).meta()\` instead.`);
43
+ })(false);
44
+ }
45
+ static {
46
+ decorateMethodV2(this.prototype, "meta", [computed()]);
47
+ }
48
+ async reload(options) {
49
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
50
+ if (!test) throw new Error("You are trying to reload an async belongsTo before it has been created");
51
+ })(this.content !== void 0);
52
+ const { key, legacySupport } = this._belongsToState;
53
+ await legacySupport.reloadBelongsTo(key, options);
54
+ return this;
55
+ }
56
+ };
57
+ PromiseBelongsTo.prototype[LegacyPromiseProxy] = true;
58
+
59
+ //#endregion
60
+ //#region src/model/-private/promise-many-array.ts
61
+ /**
62
+ This class is returned as the result of accessing an async hasMany relationship
63
+ on an instance of a Model extending from `@warp-drive/legacy/model`.
64
+
65
+ A PromiseManyArray is an iterable proxy that allows templates to consume related
66
+ ManyArrays and update once their contents are no longer pending.
67
+
68
+ In your JS code you should resolve the promise first.
69
+
70
+ ```js
71
+ const comments = await post.comments;
72
+ ```
73
+
74
+ @public
75
+ */
76
+ var PromiseManyArray = class {
77
+ /**
78
+ * The promise for the relationship's content, or `null` once
79
+ * {@link PromiseManyArray.destroy | destroy} has been called.
80
+ */
81
+ /**
82
+ * Whether {@link PromiseManyArray.destroy | destroy} has been called.
83
+ */
84
+ /**
85
+ * The resolved `ManyArray` for the relationship, if the promise has
86
+ * resolved, else `null`.
87
+ */
88
+ constructor(promise, content) {
89
+ this._update(promise, content);
90
+ this.isDestroyed = false;
91
+ this[LegacyPromiseProxy] = true;
92
+ }
93
+ /**
94
+ * Retrieve the length of the content
95
+ * @public
96
+ */
97
+ get length() {
98
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_COMPUTED_CHAINS)) this["[]"];
99
+ return this.content ? this.content.length : 0;
100
+ }
101
+ /**
102
+ * @private
103
+ */
104
+ static {
105
+ decorateMethodV2(this.prototype, "length", [memoized]);
106
+ }
107
+ get "[]"() {
108
+ return this.content?.length && this.content;
109
+ }
110
+ /**
111
+ * Iterate the proxied content. Called by the glimmer iterator in #each
112
+ * We do not guarantee that forEach will always be available. This
113
+ * may eventually be made to use Symbol.Iterator once glimmer supports it.
114
+ *
115
+ * @param cb
116
+ * @return
117
+ * @private
118
+ */
119
+ static {
120
+ decorateMethodV2(this.prototype, "[]", [memoized]);
121
+ }
122
+ forEach(cb) {
123
+ if (this.content && this.length) this.content.forEach(cb);
124
+ }
125
+ /**
126
+ * Reload the relationship
127
+ * @public
128
+ */
129
+ reload(options) {
130
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
131
+ if (!test) throw new Error("You are trying to reload an async manyArray before it has been created");
132
+ })(this.content);
133
+ this.content.reload(options);
134
+ return this;
135
+ }
136
+ /**
137
+ * Whether the loading promise is still pending
138
+ *
139
+ * @public
140
+ */
141
+ /**
142
+ * Whether the loading promise rejected
143
+ *
144
+ * @public
145
+ */
146
+ /**
147
+ * Whether the loading promise succeeded
148
+ *
149
+ * @public
150
+ */
151
+ /**
152
+ * Whether the loading promise completed (resolved or rejected)
153
+ *
154
+ * @public
155
+ */
156
+ /**
157
+ * chain this promise
158
+ *
159
+ * @public
160
+ */
161
+ then(success, rejected) {
162
+ return this.promise.then(success, rejected);
163
+ }
164
+ /**
165
+ * catch errors thrown by this promise
166
+ * @public
167
+ */
168
+ catch(cb) {
169
+ return this.promise.catch(cb);
170
+ }
171
+ /**
172
+ * run cleanup after this promise completes
173
+ *
174
+ * @public
175
+ */
176
+ finally(cb) {
177
+ return this.promise.finally(cb);
178
+ }
179
+ /**
180
+ * Tears down this proxy, releasing its {@link PromiseManyArray.content | content} and
181
+ * {@link PromiseManyArray.promise | promise} and marking it as {@link PromiseManyArray.isDestroyed | destroyed}.
182
+ *
183
+ * @public
184
+ */
185
+ destroy() {
186
+ this.isDestroyed = true;
187
+ this.content = null;
188
+ this.promise = null;
189
+ }
190
+ /**
191
+ * Retrieve the links for this relationship
192
+ * @public
193
+ */
194
+ get links() {
195
+ return this.content ? this.content.links : void 0;
196
+ }
197
+ /**
198
+ * Retrieve the meta for this relationship
199
+ * @public
200
+ */
201
+ static {
202
+ decorateMethodV2(this.prototype, "links", [memoized]);
203
+ }
204
+ get meta() {
205
+ return this.content ? this.content.meta : void 0;
206
+ }
207
+ /** @internal */
208
+ static {
209
+ decorateMethodV2(this.prototype, "meta", [memoized]);
210
+ }
211
+ _update(promise, content) {
212
+ if (content !== void 0) this.content = content;
213
+ this.promise = tapPromise(this, promise);
214
+ }
215
+ static create({ promise, content }) {
216
+ return new this(promise, content);
217
+ }
218
+ };
219
+ defineSignal(PromiseManyArray.prototype, "content", null);
220
+ defineSignal(PromiseManyArray.prototype, "isPending", false);
221
+ defineSignal(PromiseManyArray.prototype, "isRejected", false);
222
+ defineSignal(PromiseManyArray.prototype, "isFulfilled", false);
223
+ defineSignal(PromiseManyArray.prototype, "isSettled", false);
224
+ function tapPromise(proxy, promise) {
225
+ proxy.isPending = true;
226
+ proxy.isSettled = false;
227
+ proxy.isFulfilled = false;
228
+ proxy.isRejected = false;
229
+ return Promise.resolve(promise).then((content) => {
230
+ proxy.isPending = false;
231
+ proxy.isFulfilled = true;
232
+ proxy.isSettled = true;
233
+ proxy.content = content;
234
+ return content;
235
+ }, (error) => {
236
+ proxy.isPending = false;
237
+ proxy.isFulfilled = false;
238
+ proxy.isRejected = true;
239
+ proxy.isSettled = true;
240
+ throw error;
241
+ });
242
+ }
243
+
244
+ //#endregion
245
+ //#region src/model/-private/debug/assert-polymorphic-type.ts
246
+ let assertPolymorphicType;
247
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) assertPolymorphicType = function assertPolymorphicType(parentIdentifier, parentDefinition, addedIdentifier, store) {
248
+ if (parentDefinition.inverseIsImplicit) return;
249
+ if (parentDefinition.isPolymorphic) {
250
+ const meta = store.schema.fields(addedIdentifier)?.get(parentDefinition.inverseKey);
251
+ if (meta) {
252
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
253
+ if (!test) throw new Error(`Expected the schema for the field ${parentDefinition.inverseKey} on ${addedIdentifier.type} to be for a legacy relationship`);
254
+ })(meta.kind === "belongsTo" || meta.kind === "hasMany");
255
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
256
+ if (!test) 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.`);
257
+ })(meta?.options?.as === parentDefinition.type);
258
+ }
259
+ }
260
+ };
261
+
262
+ //#endregion
263
+ //#region src/model/-private/references/has-many.ts
264
+ function isResourceIdentiferWithRelatedLinks$1(value) {
265
+ return Boolean(value && value.links && value.links.related);
266
+ }
267
+ /**
268
+ A `HasManyReference` is a low-level API that allows access
269
+ and manipulation of a hasMany relationship.
270
+
271
+ It is especially useful when you're dealing with `async` relationships
272
+ from `@warp-drive/legacy/model` as it allows synchronous access to
273
+ the relationship data if loaded, as well as APIs for loading, reloading
274
+ the data or accessing available information without triggering a load.
275
+
276
+ It may also be useful when using `sync` relationships with `@warp-drive/legacy/model`
277
+ that need to be loaded/reloaded with more precise timing than marking the
278
+ relationship as `async` and relying on autofetch would have allowed.
279
+
280
+ However,keep in mind that marking a relationship as `async: false` will introduce
281
+ bugs into your application if the data is not always guaranteed to be available
282
+ by the time the relationship is accessed. Ergo, it is recommended when using this
283
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
284
+
285
+ Reference APIs are entangled with the relationship's underlying state,
286
+ thus any getters or cached properties that utilize these will properly
287
+ invalidate if the relationship state changes.
288
+
289
+ References are "stable", meaning that multiple calls to retrieve the reference
290
+ for a given relationship will always return the same HasManyReference.
291
+
292
+ @class HasManyReference
293
+ @public
294
+ */
295
+ var HasManyReference = class {
296
+ /**
297
+ * The field name on the parent record for this has-many relationship.
298
+ *
299
+ * @property key
300
+ * @type {String}
301
+ * @public
302
+ */
303
+ /**
304
+ * The type of resource this relationship will contain.
305
+ *
306
+ * @property type
307
+ * @type {String}
308
+ * @public
309
+ */
310
+ ___token;
311
+ ___identifier;
312
+ ___relatedTokenMap;
313
+ constructor(store, graph, parentIdentifier, hasManyRelationship, key) {
314
+ this.graph = graph;
315
+ this.key = key;
316
+ this.hasManyRelationship = hasManyRelationship;
317
+ this.type = hasManyRelationship.definition.type;
318
+ this.store = store;
319
+ this.___identifier = parentIdentifier;
320
+ this.___token = store.notifications.subscribe(parentIdentifier, (_, bucket, notifiedKey) => {
321
+ if (bucket === "relationships" && notifiedKey === key) this._ref++;
322
+ });
323
+ this.___relatedTokenMap = /* @__PURE__ */ new Map();
324
+ }
325
+ /**
326
+ * This method should never be called by user code.
327
+ *
328
+ * @internal
329
+ */
330
+ destroy() {
331
+ this.store.notifications.unsubscribe(this.___token);
332
+ this.___relatedTokenMap.forEach((token) => {
333
+ this.store.notifications.unsubscribe(token);
334
+ });
335
+ this.___relatedTokenMap.clear();
336
+ }
337
+ /**
338
+ * An array of identifiers for the records that this reference refers to.
339
+ *
340
+ * @property identifiers
341
+ * @type {ResourceKey[]}
342
+ * @public
343
+ */
344
+ get identifiers() {
345
+ ensureRefCanSubscribe(this);
346
+ this._ref;
347
+ const resource = this._resource();
348
+ const map = this.___relatedTokenMap;
349
+ this.___relatedTokenMap = /* @__PURE__ */ new Map();
350
+ if (resource && resource.data) return resource.data.map((resourceIdentifier) => {
351
+ const identifier = this.store.cacheKeyManager.getOrCreateRecordIdentifier(resourceIdentifier);
352
+ let token = map.get(identifier);
353
+ if (token) map.delete(identifier);
354
+ else token = this.store.notifications.subscribe(identifier, (_, bucket, notifiedKey) => {
355
+ if (bucket === "identity" || bucket === "attributes" && notifiedKey === "id") this._ref++;
356
+ });
357
+ this.___relatedTokenMap.set(identifier, token);
358
+ return identifier;
359
+ });
360
+ map.forEach((token) => {
361
+ this.store.notifications.unsubscribe(token);
362
+ });
363
+ map.clear();
364
+ return [];
365
+ }
366
+ static {
367
+ decorateMethodV2(this.prototype, "identifiers", [memoized]);
368
+ }
369
+ _resource() {
370
+ return this.store.cache.getRelationship(this.___identifier, this.key);
371
+ }
372
+ /**
373
+ This returns a string that represents how the reference will be
374
+ looked up when it is loaded. If the relationship has a link it will
375
+ use the "link" otherwise it defaults to "id".
376
+ Example
377
+ ```js [app/models/post.js]
378
+ import { Model, hasMany } from '@warp-drive/legacy/model';
379
+ export default class PostModel extends Model {
380
+ @hasMany('comment', { async: true, inverse: null }) comments;
381
+ }
382
+ ```
383
+ ```javascript
384
+ let post = store.push({
385
+ data: {
386
+ type: 'post',
387
+ id: 1,
388
+ relationships: {
389
+ comments: {
390
+ data: [{ type: 'comment', id: 1 }]
391
+ }
392
+ }
393
+ }
394
+ });
395
+ let commentsRef = post.hasMany('comments');
396
+ // get the identifier of the reference
397
+ if (commentsRef.remoteType() === "ids") {
398
+ let ids = commentsRef.ids();
399
+ } else if (commentsRef.remoteType() === "link") {
400
+ let link = commentsRef.link();
401
+ }
402
+ ```
403
+ @public
404
+ @return The name of the remote type. This should either be `link` or `ids`
405
+ */
406
+ remoteType() {
407
+ const value = this._resource();
408
+ if (value && value.links && value.links.related) return "link";
409
+ return "ids";
410
+ }
411
+ /**
412
+ `ids()` returns an array of the record IDs in this relationship.
413
+ Example
414
+ ```js [app/models/post.js]
415
+ import { Model, hasMany } from '@warp-drive/legacy/model';
416
+ export default class PostModel extends Model {
417
+ @hasMany('comment', { async: true, inverse: null }) comments;
418
+ }
419
+ ```
420
+ ```javascript
421
+ let post = store.push({
422
+ data: {
423
+ type: 'post',
424
+ id: 1,
425
+ relationships: {
426
+ comments: {
427
+ data: [{ type: 'comment', id: 1 }]
428
+ }
429
+ }
430
+ }
431
+ });
432
+ let commentsRef = post.hasMany('comments');
433
+ commentsRef.ids(); // ['1']
434
+ ```
435
+ @public
436
+ @return The ids in this has-many relationship
437
+ */
438
+ ids() {
439
+ return this.identifiers.map((identifier) => identifier.id);
440
+ }
441
+ /**
442
+ The link WarpDrive will use to fetch or reload this belongs-to
443
+ relationship. By default it uses only the "related" resource linkage.
444
+ Example
445
+ ```javascript
446
+ // models/blog.js
447
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
448
+ export default Model.extend({
449
+ user: belongsTo('user', { async: true, inverse: null })
450
+ });
451
+ let blog = store.push({
452
+ data: {
453
+ type: 'blog',
454
+ id: 1,
455
+ relationships: {
456
+ user: {
457
+ links: {
458
+ related: '/articles/1/author'
459
+ }
460
+ }
461
+ }
462
+ }
463
+ });
464
+ let userRef = blog.belongsTo('user');
465
+ // get the identifier of the reference
466
+ if (userRef.remoteType() === "link") {
467
+ let link = userRef.link();
468
+ }
469
+ ```
470
+ @public
471
+ @return The link WarpDrive will use to fetch or reload this belongs-to relationship.
472
+ */
473
+ link() {
474
+ const resource = this._resource();
475
+ if (isResourceIdentiferWithRelatedLinks$1(resource)) {
476
+ if (resource.links) {
477
+ const related = resource.links.related;
478
+ return !related || typeof related === "string" ? related : related.href;
479
+ }
480
+ }
481
+ return null;
482
+ }
483
+ /**
484
+ * any links that have been received for this relationship
485
+ *
486
+ * @public
487
+ * @return
488
+ */
489
+ links() {
490
+ const resource = this._resource();
491
+ return resource && resource.links ? resource.links : null;
492
+ }
493
+ /**
494
+ The meta data for the has-many relationship.
495
+ Example
496
+ ```javascript
497
+ // models/blog.js
498
+ import { Model, hasMany } from '@warp-drive/legacy/model';
499
+ export default Model.extend({
500
+ users: hasMany('user', { async: true, inverse: null })
501
+ });
502
+ let blog = store.push({
503
+ data: {
504
+ type: 'blog',
505
+ id: 1,
506
+ relationships: {
507
+ users: {
508
+ links: {
509
+ related: {
510
+ href: '/articles/1/authors'
511
+ },
512
+ },
513
+ meta: {
514
+ lastUpdated: 1458014400000
515
+ }
516
+ }
517
+ }
518
+ }
519
+ });
520
+ let usersRef = blog.hasMany('user');
521
+ usersRef.meta() // { lastUpdated: 1458014400000 }
522
+ ```
523
+ @public
524
+ @return The meta information for the belongs-to relationship.
525
+ */
526
+ meta() {
527
+ let meta = null;
528
+ const resource = this._resource();
529
+ if (resource && resource.meta && typeof resource.meta === "object") meta = resource.meta;
530
+ return meta;
531
+ }
532
+ /**
533
+ `push` can be used to update the data in the relationship and WarpDrive
534
+ will treat the new data as the canonical value of this relationship on
535
+ the backend. An empty array will signify the canonical value should be
536
+ empty.
537
+ Example model
538
+ ```js [app/models/post.js]
539
+ import { Model, hasMany } from '@warp-drive/legacy/model';
540
+ export default class PostModel extends Model {
541
+ @hasMany('comment', { async: true, inverse: null }) comments;
542
+ }
543
+ ```
544
+ Setup some initial state, note we haven't loaded the comments yet:
545
+ ```js
546
+ const post = store.push({
547
+ data: {
548
+ type: 'post',
549
+ id: '1',
550
+ relationships: {
551
+ comments: {
552
+ data: [{ type: 'comment', id: '1' }]
553
+ }
554
+ }
555
+ }
556
+ });
557
+ const commentsRef = post.hasMany('comments');
558
+ commentsRef.ids(); // ['1']
559
+ ```
560
+ Update the state using `push`, note we can do this even without
561
+ having loaded these comments yet by providing resource identifiers.
562
+ Both full resources and resource identifiers are supported.
563
+ ```js
564
+ await commentsRef.push({
565
+ data: [
566
+ { type: 'comment', id: '2' },
567
+ { type: 'comment', id: '3' },
568
+ ]
569
+ });
570
+ commentsRef.ids(); // ['2', '3']
571
+ ```
572
+ For convenience, you can also pass in an array of resources or resource identifiers
573
+ without wrapping them in the `data` property:
574
+ ```js
575
+ await commentsRef.push([
576
+ { type: 'comment', id: '4' },
577
+ { type: 'comment', id: '5' },
578
+ ]);
579
+ commentsRef.ids(); // ['4', '5']
580
+ ```
581
+ When using the `data` property, you may also include other resource data via included,
582
+ as well as provide new links and meta to the relationship.
583
+ ```js
584
+ await commentsRef.push({
585
+ links: {
586
+ related: '/posts/1/comments'
587
+ },
588
+ meta: {
589
+ total: 2
590
+ },
591
+ data: [
592
+ { type: 'comment', id: '4' },
593
+ { type: 'comment', id: '5' },
594
+ ],
595
+ included: [
596
+ { type: 'other-thing', id: '1', attributes: { foo: 'bar' },
597
+ ]
598
+ });
599
+ ```
600
+ By default, the store will attempt to fetch any unloaded records before resolving
601
+ the returned promise with the ManyArray.
602
+ Alternatively, pass `true` as the second argument to avoid fetching unloaded records
603
+ and instead the promise will resolve with void without attempting to fetch. This is
604
+ particularly useful if you want to update the state of the relationship without
605
+ forcing the load of all of the associated records.
606
+ @public
607
+ @param doc a JSONAPI document object describing the new value of this relationship.
608
+ @param skipFetch [optional] if `true`, do not attempt to fetch unloaded records
609
+ */
610
+ async push(doc, skipFetch) {
611
+ const { store } = this;
612
+ const dataDoc = Array.isArray(doc) ? { data: doc } : doc;
613
+ const isResourceData = Array.isArray(dataDoc.data) && dataDoc.data.length > 0 && isMaybeResource(dataDoc.data[0]);
614
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
615
+ if (!test) throw new Error(`You must provide at least one of 'links', 'meta' or 'data' when calling hasManyReference.push`);
616
+ })("links" in dataDoc || "meta" in dataDoc || "data" in dataDoc);
617
+ const identifiers = !Array.isArray(dataDoc.data) ? [] : isResourceData ? store._push(dataDoc, true) : dataDoc.data.map((i) => store.cacheKeyManager.getOrCreateRecordIdentifier(i));
618
+ const { identifier } = this.hasManyRelationship;
619
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
620
+ const relationshipMeta = this.hasManyRelationship.definition;
621
+ identifiers.forEach((added) => {
622
+ assertPolymorphicType(identifier, relationshipMeta, added, store);
623
+ });
624
+ }
625
+ const newData = {};
626
+ if (Array.isArray(dataDoc.data)) newData.data = identifiers;
627
+ if ("links" in dataDoc) newData.links = dataDoc.links;
628
+ if ("meta" in dataDoc) newData.meta = dataDoc.meta;
629
+ assertPrivateStore(store);
630
+ store._join(() => {
631
+ this.graph.push({
632
+ op: "updateRelationship",
633
+ record: identifier,
634
+ field: this.key,
635
+ value: newData
636
+ });
637
+ });
638
+ if (!skipFetch) return this.load();
639
+ }
640
+ _isLoaded() {
641
+ if (!this.hasManyRelationship.state.hasReceivedData) return false;
642
+ const relationship = this.graph.getData(this.hasManyRelationship.identifier, this.key);
643
+ return relationship.data ? relationship.data.every((identifier) => {
644
+ assertPrivateStore(this.store);
645
+ return this.store._instanceCache.recordIsLoaded(identifier, true) === true;
646
+ }) : false;
647
+ }
648
+ /**
649
+ `value()` synchronously returns the current value of the has-many
650
+ relationship. Unlike `record.relationshipName`, calling
651
+ `value()` on a reference does not trigger a fetch if the async
652
+ relationship is not yet loaded. If the relationship is not loaded
653
+ it will always return `null`.
654
+ Example
655
+ ```js [app/models/post.js]
656
+ import { Model, hasMany } from '@warp-drive/legacy/model';
657
+ export default class PostModel extends Model {
658
+ @hasMany('comment', { async: true, inverse: null }) comments;
659
+ }
660
+ ```
661
+ ```javascript
662
+ let post = store.push({
663
+ data: {
664
+ type: 'post',
665
+ id: 1,
666
+ relationships: {
667
+ comments: {
668
+ data: [{ type: 'comment', id: 1 }]
669
+ }
670
+ }
671
+ }
672
+ });
673
+ let commentsRef = post.hasMany('comments');
674
+ post.comments.then(function(comments) {
675
+ commentsRef.value() === comments
676
+ })
677
+ ```
678
+ @public
679
+ */
680
+ value() {
681
+ const support = LEGACY_SUPPORT.get(this.___identifier);
682
+ if (!ensureRefCanSubscribe(this)) {
683
+ this._ref;
684
+ return null;
685
+ }
686
+ return support.getManyArray(this.key);
687
+ }
688
+ /**
689
+ Loads the relationship if it is not already loaded. If the
690
+ relationship is already loaded this method does not trigger a new
691
+ load. This causes a request to the specified
692
+ relationship link or reloads all items currently in the relationship.
693
+ Example
694
+ ```js [app/models/post.js]
695
+ import { Model, hasMany } from '@warp-drive/legacy/model';
696
+ export default class PostModel extends Model {
697
+ @hasMany('comment', { async: true, inverse: null }) comments;
698
+ }
699
+ ```
700
+ ```javascript
701
+ let post = store.push({
702
+ data: {
703
+ type: 'post',
704
+ id: 1,
705
+ relationships: {
706
+ comments: {
707
+ data: [{ type: 'comment', id: 1 }]
708
+ }
709
+ }
710
+ }
711
+ });
712
+ let commentsRef = post.hasMany('comments');
713
+ commentsRef.load().then(function(comments) {
714
+ //...
715
+ });
716
+ ```
717
+ You may also pass in an options object whose properties will be
718
+ fed forward. This enables you to pass `adapterOptions` into the
719
+ request given to the adapter via the reference.
720
+ Example
721
+ ```javascript
722
+ commentsRef.load({ adapterOptions: { isPrivate: true } })
723
+ .then(function(comments) {
724
+ //...
725
+ });
726
+ ```
727
+ ```js [app/adapters/comment.js]
728
+ export default ApplicationAdapter.extend({
729
+ findMany(store, type, id, snapshots) {
730
+ // In the adapter you will have access to adapterOptions.
731
+ let adapterOptions = snapshots[0].adapterOptions;
732
+ }
733
+ });
734
+ ```
735
+ @public
736
+ @param options the options to pass in.
737
+ @return a promise that resolves with the ManyArray in
738
+ this has-many relationship.
739
+ */
740
+ async load(options) {
741
+ const support = LEGACY_SUPPORT.get(this.___identifier);
742
+ return !this.hasManyRelationship.definition.isAsync && !areAllInverseRecordsLoaded(this.store, this._resource()) ? support.reloadHasMany(this.key, options) : support.getHasMany(this.key, options);
743
+ }
744
+ /**
745
+ Reloads this has-many relationship. This causes a request to the specified
746
+ relationship link or reloads all items currently in the relationship.
747
+ Example
748
+ ```js [app/models/post.js]
749
+ import { Model, hasMany } from '@warp-drive/legacy/model';
750
+ export default class PostModel extends Model {
751
+ @hasMany('comment', { async: true, inverse: null }) comments;
752
+ }
753
+ ```
754
+ ```javascript
755
+ let post = store.push({
756
+ data: {
757
+ type: 'post',
758
+ id: 1,
759
+ relationships: {
760
+ comments: {
761
+ data: [{ type: 'comment', id: 1 }]
762
+ }
763
+ }
764
+ }
765
+ });
766
+ let commentsRef = post.hasMany('comments');
767
+ commentsRef.reload().then(function(comments) {
768
+ //...
769
+ });
770
+ ```
771
+ You may also pass in an options object whose properties will be
772
+ fed forward. This enables you to pass `adapterOptions` into the
773
+ request given to the adapter via the reference. A full example
774
+ can be found in the `load` method.
775
+ Example
776
+ ```javascript
777
+ commentsRef.reload({ adapterOptions: { isPrivate: true } })
778
+ ```
779
+ @public
780
+ @param options the options to pass in.
781
+ @return a promise that resolves with the ManyArray in this has-many relationship.
782
+ */
783
+ reload(options) {
784
+ return LEGACY_SUPPORT.get(this.___identifier).reloadHasMany(this.key, options);
785
+ }
786
+ };
787
+ defineNonEnumerableSignal(HasManyReference.prototype, "_ref", 0);
788
+ function isMaybeResource(object) {
789
+ return Object.keys(object).filter((k) => k !== "id" && k !== "type" && k !== "lid").length > 0;
790
+ }
791
+ function ensureRefCanSubscribe(rel) {
792
+ if (!rel._isLoaded()) {
793
+ const edge = rel.graph.get(rel.___identifier, rel.key);
794
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
795
+ if (!test) throw new Error(`Expected a hasMany relationship for ${rel.___identifier.type}:${rel.key}`);
796
+ })("accessed" in edge);
797
+ edge.accessed = true;
798
+ return false;
799
+ }
800
+ return true;
801
+ }
802
+
803
+ //#endregion
804
+ //#region src/model/-private/references/belongs-to.ts
805
+ function isResourceIdentiferWithRelatedLinks(value) {
806
+ return Boolean(value && value.links && value.links.related);
807
+ }
808
+ /**
809
+ A `BelongsToReference` is a low-level API that allows access
810
+ and manipulation of a belongsTo relationship.
811
+
812
+ It is especially useful when you're dealing with `async` relationships
813
+ from `@warp-drive/legacy/model` as it allows synchronous access to
814
+ the relationship data if loaded, as well as APIs for loading, reloading
815
+ the data or accessing available information without triggering a load.
816
+
817
+ It may also be useful when using `sync` relationships with `@warp-drive/legacy/model`
818
+ that need to be loaded/reloaded with more precise timing than marking the
819
+ relationship as `async` and relying on autofetch would have allowed.
820
+
821
+ However,keep in mind that marking a relationship as `async: false` will introduce
822
+ bugs into your application if the data is not always guaranteed to be available
823
+ by the time the relationship is accessed. Ergo, it is recommended when using this
824
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
825
+
826
+ Reference APIs are entangled with the relationship's underlying state,
827
+ thus any getters or cached properties that utilize these will properly
828
+ invalidate if the relationship state changes.
829
+
830
+ References are "stable", meaning that multiple calls to retrieve the reference
831
+ for a given relationship will always return the same HasManyReference.
832
+
833
+ @public
834
+ */
835
+ var BelongsToReference = class {
836
+ /**
837
+ * The field name on the parent record for this has-many relationship.
838
+ *
839
+ */
840
+ /**
841
+ * The type of resource this relationship will contain.
842
+ *
843
+ */
844
+ constructor(store, graph, parentIdentifier, belongsToRelationship, key) {
845
+ this.graph = graph;
846
+ this.key = key;
847
+ this.belongsToRelationship = belongsToRelationship;
848
+ this.type = belongsToRelationship.definition.type;
849
+ this.store = store;
850
+ this.___identifier = parentIdentifier;
851
+ this.___relatedToken = null;
852
+ this.___token = store.notifications.subscribe(parentIdentifier, (_, bucket, notifiedKey) => {
853
+ if (bucket === "relationships" && notifiedKey === key) this._ref++;
854
+ });
855
+ }
856
+ destroy() {
857
+ this.store.notifications.unsubscribe(this.___token);
858
+ this.___token = null;
859
+ if (this.___relatedToken) {
860
+ this.store.notifications.unsubscribe(this.___relatedToken);
861
+ this.___relatedToken = null;
862
+ }
863
+ }
864
+ /**
865
+ * The identifier of the record that this reference refers to.
866
+ * `null` if no related record is known.
867
+ *
868
+ */
869
+ get identifier() {
870
+ if (this.___relatedToken) {
871
+ this.store.notifications.unsubscribe(this.___relatedToken);
872
+ this.___relatedToken = null;
873
+ }
874
+ const resource = this._resource();
875
+ if (resource && resource.data) {
876
+ const identifier = this.store.cacheKeyManager.getOrCreateRecordIdentifier(resource.data);
877
+ this.___relatedToken = this.store.notifications.subscribe(identifier, (_, bucket, notifiedKey) => {
878
+ if (bucket === "identity" || bucket === "attributes" && notifiedKey === "id") this._ref++;
879
+ });
880
+ return identifier;
881
+ }
882
+ return null;
883
+ }
884
+ /**
885
+ The `id` of the record that this reference refers to. Together, the
886
+ `type()` and `id()` methods form a composite key for the identity
887
+ map. This can be used to access the id of an async relationship
888
+ without triggering a fetch that would normally happen if you
889
+ attempted to use `record.relationship.id`.
890
+ Example
891
+ ```javascript
892
+ // models/blog.js
893
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
894
+ export default class BlogModel extends Model {
895
+ @belongsTo('user', { async: true, inverse: null }) user;
896
+ }
897
+ let blog = store.push({
898
+ data: {
899
+ type: 'blog',
900
+ id: 1,
901
+ relationships: {
902
+ user: {
903
+ data: { type: 'user', id: 1 }
904
+ }
905
+ }
906
+ }
907
+ });
908
+ let userRef = blog.belongsTo('user');
909
+ // get the identifier of the reference
910
+ if (userRef.remoteType() === "id") {
911
+ let id = userRef.id();
912
+ }
913
+ ```
914
+ @public
915
+ @return The id of the record in this belongsTo relationship.
916
+ */
917
+ static {
918
+ decorateMethodV2(this.prototype, "identifier", [memoized]);
919
+ }
920
+ id() {
921
+ return this.identifier?.id || null;
922
+ }
923
+ /**
924
+ The link WarpDrive will use to fetch or reload this belongs-to
925
+ relationship. By default it uses only the "related" resource linkage.
926
+ Example
927
+ ```javascript
928
+ // models/blog.js
929
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
930
+ export default Model.extend({
931
+ user: belongsTo('user', { async: true, inverse: null })
932
+ });
933
+ let blog = store.push({
934
+ data: {
935
+ type: 'blog',
936
+ id: 1,
937
+ relationships: {
938
+ user: {
939
+ links: {
940
+ related: '/articles/1/author'
941
+ }
942
+ }
943
+ }
944
+ }
945
+ });
946
+ let userRef = blog.belongsTo('user');
947
+ // get the identifier of the reference
948
+ if (userRef.remoteType() === "link") {
949
+ let link = userRef.link();
950
+ }
951
+ ```
952
+ @public
953
+ @return The link WarpDrive will use to fetch or reload this belongs-to relationship.
954
+ */
955
+ link() {
956
+ const resource = this._resource();
957
+ if (isResourceIdentiferWithRelatedLinks(resource)) {
958
+ if (resource.links) {
959
+ const related = resource.links.related;
960
+ return !related || typeof related === "string" ? related : related.href;
961
+ }
962
+ }
963
+ return null;
964
+ }
965
+ /**
966
+ * any links that have been received for this relationship
967
+ *
968
+ * @public
969
+ * @return
970
+ */
971
+ links() {
972
+ const resource = this._resource();
973
+ return resource && resource.links ? resource.links : null;
974
+ }
975
+ /**
976
+ The meta data for the belongs-to relationship.
977
+ Example
978
+ ```javascript
979
+ // models/blog.js
980
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
981
+ export default Model.extend({
982
+ user: belongsTo('user', { async: true, inverse: null })
983
+ });
984
+ let blog = store.push({
985
+ data: {
986
+ type: 'blog',
987
+ id: 1,
988
+ relationships: {
989
+ user: {
990
+ links: {
991
+ related: {
992
+ href: '/articles/1/author'
993
+ },
994
+ },
995
+ meta: {
996
+ lastUpdated: 1458014400000
997
+ }
998
+ }
999
+ }
1000
+ }
1001
+ });
1002
+ let userRef = blog.belongsTo('user');
1003
+ userRef.meta() // { lastUpdated: 1458014400000 }
1004
+ ```
1005
+ @public
1006
+ @return The meta information for the belongs-to relationship.
1007
+ */
1008
+ meta() {
1009
+ let meta = null;
1010
+ const resource = this._resource();
1011
+ if (resource && resource.meta && typeof resource.meta === "object") meta = resource.meta;
1012
+ return meta;
1013
+ }
1014
+ _resource() {
1015
+ this._ref;
1016
+ return this.store.cache.getRelationship(this.___identifier, this.key);
1017
+ }
1018
+ /**
1019
+ This returns a string that represents how the reference will be
1020
+ looked up when it is loaded. If the relationship has a link it will
1021
+ use the "link" otherwise it defaults to "id".
1022
+ Example
1023
+ ```js [app/models/post.js]
1024
+ import Model, { hasMany } from '@warp-drive/legacy/model';
1025
+ export default class PostModel extends Model {
1026
+ @hasMany('comment', { async: true, inverse: null }) comments;
1027
+ }
1028
+ ```
1029
+ ```javascript
1030
+ let post = store.push({
1031
+ data: {
1032
+ type: 'post',
1033
+ id: 1,
1034
+ relationships: {
1035
+ comments: {
1036
+ data: [{ type: 'comment', id: 1 }]
1037
+ }
1038
+ }
1039
+ }
1040
+ });
1041
+ let commentsRef = post.hasMany('comments');
1042
+ // get the identifier of the reference
1043
+ if (commentsRef.remoteType() === "ids") {
1044
+ let ids = commentsRef.ids();
1045
+ } else if (commentsRef.remoteType() === "link") {
1046
+ let link = commentsRef.link();
1047
+ }
1048
+ ```
1049
+ @public
1050
+ @return The name of the remote type. This should either be `link` or `id`
1051
+ */
1052
+ remoteType() {
1053
+ if (isResourceIdentiferWithRelatedLinks(this._resource())) return "link";
1054
+ return "id";
1055
+ }
1056
+ /**
1057
+ `push` can be used to update the data in the relationship and WarpDrive
1058
+ will treat the new data as the canonical value of this relationship on
1059
+ the backend. A value of `null` (e.g. `{ data: null }`) can be passed to
1060
+ clear the relationship.
1061
+ Example model
1062
+ ```js [app/models/blog.js]
1063
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1064
+ export default class BlogModel extends Model {
1065
+ @belongsTo('user', { async: true, inverse: null }) user;
1066
+ }
1067
+ ```
1068
+ Setup some initial state, note we haven't loaded the user yet:
1069
+ ```js
1070
+ const blog = store.push({
1071
+ data: {
1072
+ type: 'blog',
1073
+ id: '1',
1074
+ relationships: {
1075
+ user: {
1076
+ data: { type: 'user', id: '1' }
1077
+ }
1078
+ }
1079
+ }
1080
+ });
1081
+ const userRef = blog.belongsTo('user');
1082
+ userRef.id(); // '1'
1083
+ ```
1084
+ Update the state using `push`, note we can do this even without
1085
+ having loaded the user yet by providing a resource-identifier.
1086
+ Both full a resource and a resource-identifier are supported.
1087
+ ```js
1088
+ await userRef.push({
1089
+ data: {
1090
+ type: 'user',
1091
+ id: '2',
1092
+ }
1093
+ });
1094
+ userRef.id(); // '2'
1095
+ ```
1096
+ You may also pass in links and meta fore the relationship, and sideload
1097
+ additional resources that might be required.
1098
+ ```js
1099
+ await userRef.push({
1100
+ data: {
1101
+ type: 'user',
1102
+ id: '2',
1103
+ },
1104
+ links: {
1105
+ related: '/articles/1/author'
1106
+ },
1107
+ meta: {
1108
+ lastUpdated: Date.now()
1109
+ },
1110
+ included: [
1111
+ {
1112
+ type: 'user-preview',
1113
+ id: '2',
1114
+ attributes: {
1115
+ username: '@runspired'
1116
+ }
1117
+ }
1118
+ ]
1119
+ });
1120
+ ```
1121
+ By default, the store will attempt to fetch the record if it is not loaded or its
1122
+ resource data is not included in the call to `push` before resolving the returned
1123
+ promise with the new state..
1124
+ Alternatively, pass `true` as the second argument to avoid fetching unloaded records
1125
+ and instead the promise will resolve with void without attempting to fetch. This is
1126
+ particularly useful if you want to update the state of the relationship without
1127
+ forcing the load of all of the associated record.
1128
+ @public
1129
+ @param doc a JSONAPI document object describing the new value of this relationship.
1130
+ @param skipFetch [optional] if `true`, do not attempt to fetch unloaded records
1131
+ @return a promise that resolves with the record in this belongs-to relationship after the push has completed.
1132
+ */
1133
+ async push(doc, skipFetch) {
1134
+ const { store } = this;
1135
+ const added = doc.data && isMaybeResource(doc.data) ? store._push(doc, true) : doc.data ? store.cacheKeyManager.getOrCreateRecordIdentifier(doc.data) : null;
1136
+ const { identifier } = this.belongsToRelationship;
1137
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1138
+ if (added) assertPolymorphicType(identifier, this.belongsToRelationship.definition, added, store);
1139
+ }
1140
+ const newData = {};
1141
+ if (doc.data || doc.data === null) newData.data = added;
1142
+ if ("links" in doc) newData.links = doc.links;
1143
+ if ("meta" in doc) newData.meta = doc.meta;
1144
+ assertPrivateStore(store);
1145
+ store._join(() => {
1146
+ this.graph.push({
1147
+ op: "updateRelationship",
1148
+ record: identifier,
1149
+ field: this.key,
1150
+ value: newData
1151
+ });
1152
+ });
1153
+ if (!skipFetch) return this.load();
1154
+ }
1155
+ /**
1156
+ `value()` synchronously returns the current value of the belongs-to
1157
+ relationship. Unlike `record.relationshipName`, calling
1158
+ `value()` on a reference does not trigger a fetch if the async
1159
+ relationship is not yet loaded. If the relationship is not loaded
1160
+ it will always return `null`.
1161
+ Example
1162
+ ```javascript
1163
+ // models/blog.js
1164
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1165
+ export default class BlogModel extends Model {
1166
+ @belongsTo('user', { async: true, inverse: null }) user;
1167
+ }
1168
+ let blog = store.push({
1169
+ data: {
1170
+ type: 'blog',
1171
+ id: 1,
1172
+ relationships: {
1173
+ user: {
1174
+ data: { type: 'user', id: 1 }
1175
+ }
1176
+ }
1177
+ }
1178
+ });
1179
+ let userRef = blog.belongsTo('user');
1180
+ userRef.value(); // null
1181
+ // provide data for reference
1182
+ userRef.push({
1183
+ data: {
1184
+ type: 'user',
1185
+ id: 1,
1186
+ attributes: {
1187
+ username: "@user"
1188
+ }
1189
+ }
1190
+ }).then(function(user) {
1191
+ userRef.value(); // user
1192
+ });
1193
+ ```
1194
+ @public
1195
+ @return the record in this relationship
1196
+ */
1197
+ value() {
1198
+ const resource = this._resource();
1199
+ return resource && resource.data ? this.store.peekRecord(resource.data) : null;
1200
+ }
1201
+ /**
1202
+ Loads a record in a belongs-to relationship if it is not already
1203
+ loaded. If the relationship is already loaded this method does not
1204
+ trigger a new load.
1205
+ Example
1206
+ ```javascript
1207
+ // models/blog.js
1208
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1209
+ export default class BlogModel extends Model {
1210
+ @belongsTo('user', { async: true, inverse: null }) user;
1211
+ }
1212
+ let blog = store.push({
1213
+ data: {
1214
+ type: 'blog',
1215
+ id: 1,
1216
+ relationships: {
1217
+ user: {
1218
+ data: { type: 'user', id: 1 }
1219
+ }
1220
+ }
1221
+ }
1222
+ });
1223
+ let userRef = blog.belongsTo('user');
1224
+ userRef.value(); // null
1225
+ userRef.load().then(function(user) {
1226
+ userRef.value() === user
1227
+ });
1228
+ ```
1229
+ You may also pass in an options object whose properties will be
1230
+ fed forward. This enables you to pass `adapterOptions` into the
1231
+ request given to the adapter via the reference.
1232
+ Example
1233
+ ```javascript
1234
+ userRef.load({ adapterOptions: { isPrivate: true } }).then(function(user) {
1235
+ userRef.value() === user;
1236
+ });
1237
+ ```
1238
+ ```js [app/adapters/user.js]
1239
+ import Adapter from '@warp-drive/legacy/adapter';
1240
+ export default class UserAdapter extends Adapter {
1241
+ findRecord(store, type, id, snapshot) {
1242
+ // In the adapter you will have access to adapterOptions.
1243
+ let adapterOptions = snapshot.adapterOptions;
1244
+ }
1245
+ });
1246
+ ```
1247
+ @public
1248
+ @param options the options to pass in.
1249
+ @return a promise that resolves with the record in this belongs-to relationship.
1250
+ */
1251
+ async load(options) {
1252
+ const support = LEGACY_SUPPORT.get(this.___identifier);
1253
+ return !this.belongsToRelationship.definition.isAsync && !areAllInverseRecordsLoaded(this.store, this._resource()) ? support.reloadBelongsTo(this.key, options).then(() => this.value()) : support.getBelongsTo(this.key, options);
1254
+ }
1255
+ /**
1256
+ Triggers a reload of the value in this relationship. If the
1257
+ remoteType is `"link"` WarpDrive will use the relationship link to
1258
+ reload the relationship. Otherwise it will reload the record by its
1259
+ id.
1260
+ Example
1261
+ ```javascript
1262
+ // models/blog.js
1263
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
1264
+ export default class BlogModel extends Model {
1265
+ @belongsTo('user', { async: true, inverse: null }) user;
1266
+ }
1267
+ let blog = store.push({
1268
+ data: {
1269
+ type: 'blog',
1270
+ id: 1,
1271
+ relationships: {
1272
+ user: {
1273
+ data: { type: 'user', id: 1 }
1274
+ }
1275
+ }
1276
+ }
1277
+ });
1278
+ let userRef = blog.belongsTo('user');
1279
+ userRef.reload().then(function(user) {
1280
+ userRef.value() === user
1281
+ });
1282
+ ```
1283
+ You may also pass in an options object whose properties will be
1284
+ fed forward. This enables you to pass `adapterOptions` into the
1285
+ request given to the adapter via the reference. A full example
1286
+ can be found in the `load` method.
1287
+ Example
1288
+ ```javascript
1289
+ userRef.reload({ adapterOptions: { isPrivate: true } })
1290
+ ```
1291
+ @public
1292
+ @param options the options to pass in.
1293
+ @return a promise that resolves with the record in this belongs-to relationship after the reload has completed.
1294
+ */
1295
+ reload(options) {
1296
+ return LEGACY_SUPPORT.get(this.___identifier).reloadBelongsTo(this.key, options).then(() => this.value());
1297
+ }
1298
+ };
1299
+ defineNonEnumerableSignal(BelongsToReference.prototype, "_ref", 0);
1300
+
1301
+ //#endregion
1302
+ //#region src/model/-private/legacy-relationships-support.ts
1303
+ const LEGACY_SUPPORT = getOrSetGlobal("LEGACY_SUPPORT", /* @__PURE__ */ new Map());
1304
+ function lookupLegacySupport(record) {
1305
+ const identifier = recordIdentifierFor(record);
1306
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1307
+ if (!test) throw new Error(`Expected a record`);
1308
+ })(identifier);
1309
+ let support = LEGACY_SUPPORT.get(identifier);
1310
+ if (!support) {
1311
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1312
+ if (!test) throw new Error(`Memory Leak Detected`);
1313
+ })(!record.isDestroyed && !record.isDestroying);
1314
+ support = new LegacySupport(record, identifier);
1315
+ LEGACY_SUPPORT.set(identifier, support);
1316
+ }
1317
+ return support;
1318
+ }
1319
+ /**
1320
+ * @hideconstructor
1321
+ */
1322
+ var LegacySupport = class {
1323
+ /** @internal */
1324
+ /** @internal */
1325
+ /** @internal */
1326
+ /** @internal */
1327
+ /** @internal */
1328
+ /** @internal */
1329
+ /** @internal */
1330
+ /** @internal */
1331
+ /** @internal */
1332
+ /** @internal */
1333
+ /** @internal */
1334
+ constructor(record, identifier) {
1335
+ this.record = record;
1336
+ this.store = isPrivateStore(storeFor(record, false));
1337
+ this.identifier = identifier;
1338
+ this.cache = this.store.cache;
1339
+ if (this.store._graph) this.graph = this.store._graph;
1340
+ this._manyArrayCache = Object.create(null);
1341
+ this._relationshipPromisesCache = Object.create(null);
1342
+ this._relationshipProxyCache = Object.create(null);
1343
+ this._pending = Object.create(null);
1344
+ this.references = Object.create(null);
1345
+ }
1346
+ /** @private */
1347
+ _syncArray(array) {
1348
+ if (this.isDestroyed || this.isDestroying) return;
1349
+ const currentState = array[Context].source;
1350
+ const identifier = this.identifier;
1351
+ const [identifiers, jsonApi] = this._getCurrentState(identifier, array.key);
1352
+ if (jsonApi.meta) array.meta = jsonApi.meta;
1353
+ if (jsonApi.links) array.links = jsonApi.links;
1354
+ currentState.length = 0;
1355
+ fastPush(currentState, identifiers);
1356
+ }
1357
+ mutate(mutation) {
1358
+ this.cache.mutate(mutation);
1359
+ }
1360
+ _findBelongsTo(key, resource, relationship, options) {
1361
+ const name = getRealFieldName(this, key);
1362
+ return this._findBelongsToByJsonApiResource(resource, this.identifier, relationship, options).then((identifier) => handleCompletedRelationshipRequest(this, name, relationship, identifier), (e) => handleCompletedRelationshipRequest(this, name, relationship, null, e));
1363
+ }
1364
+ reloadBelongsTo(key, options) {
1365
+ const loadingPromise = this._relationshipPromisesCache[key];
1366
+ if (loadingPromise) return loadingPromise;
1367
+ const name = getRealFieldName(this, key);
1368
+ const resource = this.store.cache.getRelationship(this.identifier, name);
1369
+ const relationship = this.graph.get(this.identifier, name);
1370
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1371
+ if (!test) throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
1372
+ })(isBelongsTo(relationship));
1373
+ relationship.state.hasFailedLoadAttempt = false;
1374
+ relationship.state.shouldForceReload = true;
1375
+ const promise = this._findBelongsTo(name, resource, relationship, options);
1376
+ if (this._relationshipProxyCache[name]) return this._updatePromiseProxyFor("belongsTo", name, { promise });
1377
+ return promise;
1378
+ }
1379
+ getBelongsTo(key, options) {
1380
+ const { identifier } = this;
1381
+ const name = getRealFieldName(this, key);
1382
+ const resource = this.store.cache.getRelationship(this.identifier, name);
1383
+ const relatedIdentifier = resource && resource.data ? resource.data : null;
1384
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1385
+ if (!test) throw new Error(`Expected a stable identifier`);
1386
+ })(!relatedIdentifier || isResourceKey(relatedIdentifier));
1387
+ const store = this.store;
1388
+ const relationship = this.graph.get(this.identifier, name);
1389
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1390
+ if (!test) throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
1391
+ })(isBelongsTo(relationship));
1392
+ const isAsync = relationship.definition.isAsync;
1393
+ const _belongsToState = {
1394
+ key,
1395
+ store,
1396
+ legacySupport: this,
1397
+ modelName: relationship.definition.type
1398
+ };
1399
+ if (isAsync) {
1400
+ if (relationship.state.hasFailedLoadAttempt) return this._relationshipProxyCache[name];
1401
+ const promise = this._findBelongsTo(name, resource, relationship, options);
1402
+ const isLoaded = relatedIdentifier && store._instanceCache.recordIsLoaded(relatedIdentifier);
1403
+ return this._updatePromiseProxyFor("belongsTo", name, {
1404
+ promise,
1405
+ content: isLoaded ? store._instanceCache.getRecord(relatedIdentifier) : null,
1406
+ _belongsToState
1407
+ });
1408
+ } else if (relatedIdentifier === null) return null;
1409
+ else {
1410
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1411
+ if (!test) 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> })\`)`);
1412
+ })(store._instanceCache.recordIsLoaded(relatedIdentifier, true));
1413
+ return store._instanceCache.getRecord(relatedIdentifier);
1414
+ }
1415
+ }
1416
+ setDirtyBelongsTo(key, value) {
1417
+ const name = getRealFieldName(this, key);
1418
+ return this.cache.mutate({
1419
+ op: "replaceRelatedRecord",
1420
+ record: this.identifier,
1421
+ field: name,
1422
+ value: extractIdentifierFromRecord(value)
1423
+ }, true);
1424
+ }
1425
+ _getCurrentState(identifier, field) {
1426
+ const jsonApi = this.cache.getRelationship(identifier, field);
1427
+ const cache = this.store._instanceCache;
1428
+ const identifiers = [];
1429
+ if (jsonApi.data) for (let i = 0; i < jsonApi.data.length; i++) {
1430
+ const relatedIdentifier = jsonApi.data[i];
1431
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1432
+ if (!test) throw new Error(`Expected a stable identifier`);
1433
+ })(isResourceKey(relatedIdentifier));
1434
+ if (cache.recordIsLoaded(relatedIdentifier, true)) identifiers.push(relatedIdentifier);
1435
+ }
1436
+ return [identifiers, jsonApi];
1437
+ }
1438
+ getManyArray(key, definition) {
1439
+ const name = getRealFieldName(this, key);
1440
+ if (this.graph) {
1441
+ let manyArray = this._manyArrayCache[name];
1442
+ if (!definition) definition = this.graph.get(this.identifier, name).definition;
1443
+ if (!manyArray) {
1444
+ const [identifiers, doc] = this._getCurrentState(this.identifier, name);
1445
+ const field = getField(this, name);
1446
+ manyArray = createLegacyManyArray({
1447
+ store: this.store,
1448
+ manager: this,
1449
+ source: identifiers,
1450
+ type: definition.type,
1451
+ isLoaded: !definition.isAsync,
1452
+ editable: true,
1453
+ isAsync: definition.isAsync,
1454
+ isPolymorphic: definition.isPolymorphic,
1455
+ field,
1456
+ identifier: this.identifier,
1457
+ links: doc.links || null,
1458
+ meta: doc.meta || null
1459
+ });
1460
+ this._manyArrayCache[name] = manyArray;
1461
+ }
1462
+ return manyArray;
1463
+ }
1464
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1465
+ if (!test) throw new Error("hasMany only works with the JSONAPICache");
1466
+ })(false);
1467
+ }
1468
+ fetchAsyncHasMany(key, relationship, manyArray, options) {
1469
+ const name = getRealFieldName(this, key);
1470
+ if (this.graph) {
1471
+ let loadingPromise = this._relationshipPromisesCache[name];
1472
+ if (loadingPromise) return loadingPromise;
1473
+ const jsonApi = this.cache.getRelationship(this.identifier, name);
1474
+ const promise = this._findHasManyByJsonApiResource(jsonApi, this.identifier, relationship, options);
1475
+ if (!promise) {
1476
+ manyArray.isLoaded = true;
1477
+ return Promise.resolve(manyArray);
1478
+ }
1479
+ loadingPromise = promise.then(() => handleCompletedRelationshipRequest(this, name, relationship, manyArray), (e) => handleCompletedRelationshipRequest(this, name, relationship, manyArray, e));
1480
+ this._relationshipPromisesCache[name] = loadingPromise;
1481
+ return loadingPromise;
1482
+ }
1483
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1484
+ if (!test) throw new Error("hasMany only works with the JSONAPICache");
1485
+ })(false);
1486
+ }
1487
+ reloadHasMany(key, options) {
1488
+ const name = getRealFieldName(this, key);
1489
+ if (this.graph) {
1490
+ const loadingPromise = this._relationshipPromisesCache[name];
1491
+ if (loadingPromise) return loadingPromise;
1492
+ const relationship = this.graph.get(this.identifier, name);
1493
+ const { definition, state } = relationship;
1494
+ state.hasFailedLoadAttempt = false;
1495
+ state.shouldForceReload = true;
1496
+ const manyArray = this.getManyArray(name, definition);
1497
+ const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
1498
+ if (this._relationshipProxyCache[name]) return this._updatePromiseProxyFor("hasMany", name, { promise });
1499
+ return promise;
1500
+ }
1501
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1502
+ if (!test) throw new Error(`hasMany only works with the JSONAPICache`);
1503
+ })(false);
1504
+ }
1505
+ getHasMany(key, options) {
1506
+ const name = getRealFieldName(this, key);
1507
+ if (this.graph) {
1508
+ const relationship = this.graph.get(this.identifier, name);
1509
+ const { definition, state } = relationship;
1510
+ const manyArray = this.getManyArray(name, definition);
1511
+ if (definition.isAsync) {
1512
+ if (state.hasFailedLoadAttempt) return this._relationshipProxyCache[name];
1513
+ const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
1514
+ return this._updatePromiseProxyFor("hasMany", name, {
1515
+ promise,
1516
+ content: manyArray
1517
+ });
1518
+ } else {
1519
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1520
+ if (!test) 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> })')`);
1521
+ })(!anyUnloaded(this.store, relationship));
1522
+ return manyArray;
1523
+ }
1524
+ }
1525
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1526
+ if (!test) throw new Error(`hasMany only works with the JSONAPICache`);
1527
+ })(false);
1528
+ }
1529
+ _updatePromiseProxyFor(kind, key, args) {
1530
+ let promiseProxy = this._relationshipProxyCache[key];
1531
+ if (kind === "hasMany") {
1532
+ const { promise, content } = args;
1533
+ if (promiseProxy) {
1534
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1535
+ if (!test) throw new Error(`Expected a PromiseManyArray`);
1536
+ })("_update" in promiseProxy);
1537
+ promiseProxy._update(promise, content);
1538
+ } else promiseProxy = this._relationshipProxyCache[key] = new PromiseManyArray(promise, content);
1539
+ return promiseProxy;
1540
+ }
1541
+ if (promiseProxy) {
1542
+ const { promise, content } = args;
1543
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1544
+ if (!test) throw new Error(`Expected a PromiseBelongsTo`);
1545
+ })("_belongsToState" in promiseProxy);
1546
+ if (content !== void 0) promiseProxy.set("content", content);
1547
+ promiseProxy.set("promise", promise);
1548
+ } else {
1549
+ promiseProxy = PromiseBelongsTo.create(args);
1550
+ this._relationshipProxyCache[key] = promiseProxy;
1551
+ }
1552
+ return promiseProxy;
1553
+ }
1554
+ referenceFor(kind, key) {
1555
+ const name = getRealFieldName(this, key);
1556
+ let reference = this.references[name];
1557
+ if (!reference) {
1558
+ if (!this.graph) macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1559
+ if (!test) throw new Error(`snapshot.belongsTo only supported when using the JSONAPICache`);
1560
+ })(false);
1561
+ const { graph, identifier } = this;
1562
+ const relationship = graph.get(identifier, name);
1563
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1564
+ if (kind) {
1565
+ const modelName = identifier.type;
1566
+ const actualRelationshipKind = relationship.definition.kind;
1567
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1568
+ if (!test) 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.`);
1569
+ })(actualRelationshipKind === kind);
1570
+ }
1571
+ }
1572
+ const relationshipKind = relationship.definition.kind;
1573
+ if (relationshipKind === "belongsTo") reference = new BelongsToReference(this.store, graph, identifier, relationship, key);
1574
+ else if (relationshipKind === "hasMany") reference = new HasManyReference(this.store, graph, identifier, relationship, key);
1575
+ this.references[name] = reference;
1576
+ }
1577
+ return reference;
1578
+ }
1579
+ _findHasManyByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
1580
+ if (this.graph) {
1581
+ if (!resource) return;
1582
+ const { definition, state } = relationship;
1583
+ /* @__PURE__ */ upgradeStore(this.store);
1584
+ const adapter = this.store.adapterFor?.(definition.type);
1585
+ const { isStale, hasDematerializedInverse, hasReceivedData, isEmpty, shouldForceReload } = state;
1586
+ const allInverseRecordsAreLoaded = areAllInverseRecordsLoaded(this.store, resource);
1587
+ const identifiers = resource.data;
1588
+ const shouldFindViaLink = resource.links && resource.links.related && (typeof adapter?.findHasMany === "function" || typeof identifiers === "undefined") && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
1589
+ const field = this.store.schema.fields({ type: definition.inverseType }).get(definition.key);
1590
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1591
+ if (!test) throw new Error(`Expected a hasMany field definition for ${definition.inverseType}.${definition.key}`);
1592
+ })(field && field.kind === "hasMany");
1593
+ const request = {
1594
+ useLink: shouldFindViaLink,
1595
+ field,
1596
+ links: resource.links,
1597
+ meta: resource.meta,
1598
+ options,
1599
+ record: parentIdentifier
1600
+ };
1601
+ if (shouldFindViaLink) {
1602
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1603
+ if (!test) throw new Error(`Expected collection to be an array`);
1604
+ })(!identifiers || Array.isArray(identifiers));
1605
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1606
+ if (!test) throw new Error(`Expected stable identifiers`);
1607
+ })(!identifiers || identifiers.every(isResourceKey));
1608
+ const req = field.options.linksMode ? {
1609
+ url: getRelatedLink(resource),
1610
+ op: "findHasMany",
1611
+ method: "GET",
1612
+ records: identifiers || [],
1613
+ data: request,
1614
+ [EnableHydration]: false
1615
+ } : {
1616
+ op: "findHasMany",
1617
+ records: identifiers || [],
1618
+ data: request,
1619
+ cacheOptions: { [Symbol.for("wd:skip-cache")]: true }
1620
+ };
1621
+ return this.store.request(req);
1622
+ }
1623
+ const preferLocalCache = hasReceivedData && !isEmpty;
1624
+ const hasLocalPartialData = hasDematerializedInverse || isEmpty && Array.isArray(identifiers) && identifiers.length > 0;
1625
+ const attemptLocalCache = !shouldForceReload && !isStale && (preferLocalCache || hasLocalPartialData);
1626
+ if (attemptLocalCache && allInverseRecordsAreLoaded) return;
1627
+ if (attemptLocalCache || hasReceivedData && !isEmpty || hasLocalPartialData) {
1628
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1629
+ if (!test) throw new Error(`Expected collection to be an array`);
1630
+ })(Array.isArray(identifiers));
1631
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1632
+ if (!test) throw new Error(`Expected stable identifiers`);
1633
+ })(identifiers.every(isResourceKey));
1634
+ options.reload = options.reload || !attemptLocalCache || void 0;
1635
+ return this.store.request({
1636
+ op: "findHasMany",
1637
+ records: identifiers,
1638
+ data: request,
1639
+ cacheOptions: { [Symbol.for("wd:skip-cache")]: true }
1640
+ });
1641
+ }
1642
+ return;
1643
+ }
1644
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1645
+ if (!test) throw new Error(`hasMany only works with the JSONAPICache`);
1646
+ })(false);
1647
+ }
1648
+ _findBelongsToByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
1649
+ if (!resource) return Promise.resolve(null);
1650
+ const key = relationship.definition.key;
1651
+ const name = getRealFieldName(this, key);
1652
+ if (this._pending[name]) return this._pending[name];
1653
+ const identifier = resource.data ? resource.data : null;
1654
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1655
+ if (!test) throw new Error(`Expected a stable identifier`);
1656
+ })(!identifier || isResourceKey(identifier));
1657
+ const { isStale, hasDematerializedInverse, hasReceivedData, isEmpty, shouldForceReload } = relationship.state;
1658
+ const allInverseRecordsAreLoaded = areAllInverseRecordsLoaded(this.store, resource);
1659
+ const shouldFindViaLink = resource.links?.related && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
1660
+ const field = this.store.schema.fields(this.identifier).get(relationship.definition.key);
1661
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1662
+ if (!test) throw new Error(`Attempted to access a belongsTo relationship but no definition exists for it`);
1663
+ })(field && field.kind === "belongsTo");
1664
+ const request = {
1665
+ useLink: shouldFindViaLink,
1666
+ field,
1667
+ links: resource.links,
1668
+ meta: resource.meta,
1669
+ options,
1670
+ record: parentIdentifier
1671
+ };
1672
+ if (shouldFindViaLink) {
1673
+ const req = field.options.linksMode ? {
1674
+ url: getRelatedLink(resource),
1675
+ op: "findBelongsTo",
1676
+ method: "GET",
1677
+ records: identifier ? [identifier] : [],
1678
+ data: request,
1679
+ [EnableHydration]: false
1680
+ } : {
1681
+ op: "findBelongsTo",
1682
+ records: identifier ? [identifier] : [],
1683
+ data: request,
1684
+ cacheOptions: { [Symbol.for("wd:skip-cache")]: true }
1685
+ };
1686
+ const future = this.store.request(req);
1687
+ this._pending[name] = future.then((doc) => field.options.linksMode ? doc.content.data : doc.content).finally(() => {
1688
+ this._pending[name] = void 0;
1689
+ });
1690
+ return this._pending[name];
1691
+ }
1692
+ const preferLocalCache = hasReceivedData && allInverseRecordsAreLoaded && !isEmpty;
1693
+ const hasLocalPartialData = hasDematerializedInverse || isEmpty && resource.data;
1694
+ const localDataIsEmpty = !identifier;
1695
+ const attemptLocalCache = !shouldForceReload && !isStale && (preferLocalCache || hasLocalPartialData);
1696
+ if (attemptLocalCache && localDataIsEmpty) return Promise.resolve(null);
1697
+ const resourceIsLocal = identifier?.id === null;
1698
+ if (attemptLocalCache && allInverseRecordsAreLoaded || resourceIsLocal) return Promise.resolve(identifier);
1699
+ if (identifier) {
1700
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1701
+ if (!test) throw new Error(`Cannot fetch belongs-to relationship with no information`);
1702
+ })(identifier);
1703
+ options.reload = options.reload || !attemptLocalCache || void 0;
1704
+ this._pending[name] = this.store.request({
1705
+ op: "findBelongsTo",
1706
+ records: [identifier],
1707
+ data: request,
1708
+ cacheOptions: { [Symbol.for("wd:skip-cache")]: true }
1709
+ }).then((doc) => doc.content).finally(() => {
1710
+ this._pending[name] = void 0;
1711
+ });
1712
+ return this._pending[name];
1713
+ }
1714
+ return Promise.resolve(null);
1715
+ }
1716
+ destroy() {
1717
+ this.isDestroying = true;
1718
+ let cache = this._manyArrayCache;
1719
+ this._manyArrayCache = Object.create(null);
1720
+ Object.keys(cache).forEach((key) => {
1721
+ cache[key].destroy();
1722
+ });
1723
+ cache = this._relationshipProxyCache;
1724
+ this._relationshipProxyCache = Object.create(null);
1725
+ Object.keys(cache).forEach((key) => {
1726
+ const proxy = cache[key];
1727
+ if (proxy.destroy) proxy.destroy();
1728
+ });
1729
+ cache = this.references;
1730
+ this.references = Object.create(null);
1731
+ Object.keys(cache).forEach((key) => {
1732
+ cache[key].destroy();
1733
+ });
1734
+ this.isDestroyed = true;
1735
+ }
1736
+ };
1737
+ function getRelatedLink(resource) {
1738
+ const related = resource.links?.related;
1739
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1740
+ if (!test) throw new Error(`Expected a related link`);
1741
+ })(related);
1742
+ return typeof related === "object" ? related.href : related;
1743
+ }
1744
+ function handleCompletedRelationshipRequest(recordExt, key, relationship, value, error) {
1745
+ delete recordExt._relationshipPromisesCache[key];
1746
+ relationship.state.shouldForceReload = false;
1747
+ const isHasMany = relationship.definition.kind === "hasMany";
1748
+ if (isHasMany) notifyInternalSignal(value[Context].signal);
1749
+ if (error) {
1750
+ relationship.state.hasFailedLoadAttempt = true;
1751
+ const proxy = recordExt._relationshipProxyCache[key];
1752
+ if (proxy && !isHasMany) {
1753
+ if (proxy.content && proxy.content.isDestroying) proxy.set("content", null);
1754
+ recordExt.store.notifications._flush();
1755
+ }
1756
+ throw error;
1757
+ }
1758
+ if (isHasMany) value.isLoaded = true;
1759
+ else recordExt.store.notifications._flush();
1760
+ relationship.state.hasFailedLoadAttempt = false;
1761
+ relationship.state.isStale = false;
1762
+ return isHasMany || !value ? value : recordExt.store.peekRecord(value);
1763
+ }
1764
+ function extractIdentifierFromRecord(record) {
1765
+ if (!record) return null;
1766
+ return recordIdentifierFor(record);
1767
+ }
1768
+ function anyUnloaded(store, relationship) {
1769
+ assertPrivateStore(store);
1770
+ const graph = store._graph;
1771
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1772
+ if (!test) throw new Error(`Expected a Graph instance to be available`);
1773
+ })(graph);
1774
+ const state = graph.getData(relationship.identifier, relationship.definition.key).data;
1775
+ const cache = store._instanceCache;
1776
+ return state?.find((s) => {
1777
+ return !cache.recordIsLoaded(s, true);
1778
+ }) || false;
1779
+ }
1780
+ function areAllInverseRecordsLoaded(store, resource) {
1781
+ assertPrivateStore(store);
1782
+ const instanceCache = store._instanceCache;
1783
+ const identifiers = resource.data;
1784
+ if (Array.isArray(identifiers)) {
1785
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1786
+ if (!test) throw new Error(`Expected stable identifiers`);
1787
+ })(identifiers.every(isResourceKey));
1788
+ return identifiers.every((identifier) => instanceCache.recordIsLoaded(identifier));
1789
+ }
1790
+ if (!identifiers) return true;
1791
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1792
+ if (!test) throw new Error(`Expected stable identifiers`);
1793
+ })(isResourceKey(identifiers));
1794
+ return instanceCache.recordIsLoaded(identifiers);
1795
+ }
1796
+ function isBelongsTo(relationship) {
1797
+ return relationship.definition.kind === "belongsTo";
1798
+ }
1799
+ function getField(context, key) {
1800
+ const { identifier, store } = context;
1801
+ return store.schema.fields(identifier).get(key) ?? store.schema.cacheFields?.(identifier).get(key);
1802
+ }
1803
+ function getRealFieldName(context, key) {
1804
+ const field = getField(context, key);
1805
+ return field ? field.sourceKey ?? field.name : key;
1806
+ }
1807
+
1808
+ //#endregion
1809
+ //#region src/model/-private/errors.ts
1810
+ const ArrayProxyWithCustomOverrides = ArrayProxy;
1811
+ /**
1812
+ Holds validation errors for a given record, organized by attribute names.
1813
+
1814
+ This class is not directly instantiable.
1815
+
1816
+ Every `Model` has an `errors` property that is an instance of
1817
+ `Errors`. This can be used to display validation error
1818
+ messages returned from the server when a `record.save()` rejects.
1819
+
1820
+ For Example, if you had a `User` model that looked like this:
1821
+
1822
+ ```js [app/models/user.js]
1823
+ import { Model, attr } from '@warp-drive/legacy/model';
1824
+
1825
+ export default class UserModel extends Model {
1826
+ @attr('string') username;
1827
+ @attr('string') email;
1828
+ }
1829
+ ```
1830
+ And you attempted to save a record that did not validate on the backend:
1831
+
1832
+ ```javascript
1833
+ let user = store.createRecord('user', {
1834
+ username: 'tomster',
1835
+ email: 'invalidEmail'
1836
+ });
1837
+ user.save();
1838
+ ```
1839
+
1840
+ Your backend would be expected to return an error response that described
1841
+ the problem, so that error messages can be generated on the app.
1842
+
1843
+ API responses will be translated into instances of `Errors` differently,
1844
+ depending on the specific combination of adapter and serializer used. You
1845
+ may want to check the documentation or the source code of the libraries
1846
+ that you are using, to know how they expect errors to be communicated.
1847
+
1848
+ Errors can be displayed to the user by accessing their property name
1849
+ to get an array of all the error objects for that property. Each
1850
+ error object is a JavaScript object with two keys:
1851
+
1852
+ - `message` A string containing the error message from the backend
1853
+ - `attribute` The name of the property associated with this error message
1854
+
1855
+ ```handlebars
1856
+ <label>Username: <Input @value={{@model.username}} /> </label>
1857
+ {{#each @model.errors.username as |error|}}
1858
+ <div class="error">
1859
+ {{error.message}}
1860
+ </div>
1861
+ {{/each}}
1862
+
1863
+ <label>Email: <Input @value={{@model.email}} /> </label>
1864
+ {{#each @model.errors.email as |error|}}
1865
+ <div class="error">
1866
+ {{error.message}}
1867
+ </div>
1868
+ {{/each}}
1869
+ ```
1870
+
1871
+ You can also access the special `messages` property on the error
1872
+ object to get an array of all the error strings.
1873
+
1874
+ ```handlebars
1875
+ {{#each @model.errors.messages as |message|}}
1876
+ <div class="error">
1877
+ {{message}}
1878
+ </div>
1879
+ {{/each}}
1880
+ ```
1881
+
1882
+ @class Errors
1883
+ @public
1884
+ */
1885
+ var Errors = class extends ArrayProxyWithCustomOverrides {
1886
+ /**
1887
+ @property errorsByAttributeName
1888
+ @type {MapWithDefault}
1889
+ @private
1890
+ */
1891
+ get errorsByAttributeName() {
1892
+ return /* @__PURE__ */ new Map();
1893
+ }
1894
+ /**
1895
+ Returns errors for a given attribute
1896
+ ```javascript
1897
+ let user = store.createRecord('user', {
1898
+ username: 'tomster',
1899
+ email: 'invalidEmail'
1900
+ });
1901
+ user.save().catch(function(){
1902
+ user.errors.errorsFor('email'); // returns:
1903
+ // [{attribute: "email", message: "Doesn't look like a valid email."}]
1904
+ });
1905
+ ```
1906
+ @public
1907
+ @param {String} attribute
1908
+ @return {Array}
1909
+ */
1910
+ static {
1911
+ decorateMethodV2(this.prototype, "errorsByAttributeName", [computed()]);
1912
+ }
1913
+ errorsFor(attribute) {
1914
+ const map = this.errorsByAttributeName;
1915
+ let errors = map.get(attribute);
1916
+ if (errors === void 0) {
1917
+ errors = A();
1918
+ map.set(attribute, errors);
1919
+ }
1920
+ get(errors, "[]");
1921
+ return errors;
1922
+ }
1923
+ /**
1924
+ An array containing all of the error messages for this
1925
+ record. This is useful for displaying all errors to the user.
1926
+ ```handlebars
1927
+ {{#each @model.errors.messages as |message|}}
1928
+ <div class="error">
1929
+ {{message}}
1930
+ </div>
1931
+ {{/each}}
1932
+ ```
1933
+ @property messages
1934
+ @public
1935
+ @type {Array}
1936
+ */
1937
+ static {
1938
+ decorateFieldV2(this.prototype, "messages", [mapBy("content", "message")]);
1939
+ }
1940
+ #messages = (initializeDeferredDecorator(this, "messages"), void 0);
1941
+ /**
1942
+ @property content
1943
+ @type {Array}
1944
+ @private
1945
+ */
1946
+ get content() {
1947
+ return A();
1948
+ }
1949
+ /**
1950
+ @private
1951
+ */
1952
+ static {
1953
+ decorateMethodV2(this.prototype, "content", [computed()]);
1954
+ }
1955
+ unknownProperty(attribute) {
1956
+ const errors = this.errorsFor(attribute);
1957
+ if (errors.length === 0) return;
1958
+ return errors;
1959
+ }
1960
+ /**
1961
+ Total number of errors.
1962
+ @property length
1963
+ @type {Number}
1964
+ @public
1965
+ @readonly
1966
+ */
1967
+ /**
1968
+ `true` if we have no errors.
1969
+ @property isEmpty
1970
+ @type {Boolean}
1971
+ @public
1972
+ @readonly
1973
+ */
1974
+ static {
1975
+ decorateFieldV2(this.prototype, "isEmpty", [not("length")]);
1976
+ }
1977
+ #isEmpty = (initializeDeferredDecorator(this, "isEmpty"), void 0);
1978
+ /**
1979
+ Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
1980
+ the record and transition the record into an `invalid` state.
1981
+ Example
1982
+ ```javascript
1983
+ let errors = user.errors;
1984
+ // add multiple errors
1985
+ errors.add('password', [
1986
+ 'Must be at least 12 characters',
1987
+ 'Must contain at least one symbol',
1988
+ 'Cannot contain your name'
1989
+ ]);
1990
+ errors.errorsFor('password');
1991
+ // =>
1992
+ // [
1993
+ // { attribute: 'password', message: 'Must be at least 12 characters' },
1994
+ // { attribute: 'password', message: 'Must contain at least one symbol' },
1995
+ // { attribute: 'password', message: 'Cannot contain your name' },
1996
+ // ]
1997
+ // add a single error
1998
+ errors.add('username', 'This field is required');
1999
+ errors.errorsFor('username');
2000
+ // =>
2001
+ // [
2002
+ // { attribute: 'username', message: 'This field is required' },
2003
+ // ]
2004
+ ```
2005
+ @public
2006
+ @param {String} attribute - the property name of an attribute or relationship
2007
+ @param {string[]|string} messages - an error message or array of error messages for the attribute
2008
+ */
2009
+ add(attribute, messages) {
2010
+ const errors = this._findOrCreateMessages(attribute, messages);
2011
+ this.addObjects(errors);
2012
+ this.errorsFor(attribute).addObjects(errors);
2013
+ this.__record.currentState.notify("isValid");
2014
+ this.notifyPropertyChange(attribute);
2015
+ }
2016
+ /**
2017
+ @private
2018
+ */
2019
+ _findOrCreateMessages(attribute, messages) {
2020
+ const errors = this.errorsFor(attribute);
2021
+ const messagesArray = Array.isArray(messages) ? messages : [messages];
2022
+ const _messages = new Array(messagesArray.length);
2023
+ for (let i = 0; i < messagesArray.length; i++) {
2024
+ const message = messagesArray[i];
2025
+ const err = errors.findBy("message", message);
2026
+ if (err) _messages[i] = err;
2027
+ else _messages[i] = {
2028
+ attribute,
2029
+ message
2030
+ };
2031
+ }
2032
+ return _messages;
2033
+ }
2034
+ /**
2035
+ Manually removes all errors for a given member from the record.
2036
+ This will transition the record into a `valid` state, and
2037
+ triggers the `becameValid` event and lifecycle method.
2038
+ Example:
2039
+ ```javascript
2040
+ let errors = user.errors;
2041
+ errors.add('phone', ['error-1', 'error-2']);
2042
+ errors.errorsFor('phone');
2043
+ // =>
2044
+ // [
2045
+ // { attribute: 'phone', message: 'error-1' },
2046
+ // { attribute: 'phone', message: 'error-2' },
2047
+ // ]
2048
+ errors.remove('phone');
2049
+ errors.errorsFor('phone');
2050
+ // => undefined
2051
+ ```
2052
+ @public
2053
+ @param {String} member - the property name of an attribute or relationship
2054
+ */
2055
+ remove(attribute) {
2056
+ if (this.isEmpty) return;
2057
+ const content = this.rejectBy("attribute", attribute);
2058
+ this.content.setObjects(content);
2059
+ const errors = this.errorsFor(attribute);
2060
+ for (let i = 0; i < errors.length; i++) if (errors[i].attribute === attribute) errors.replace(i, 1);
2061
+ this.errorsByAttributeName.delete(attribute);
2062
+ this.__record.currentState.notify("isValid");
2063
+ this.notifyPropertyChange(attribute);
2064
+ this.notifyPropertyChange("length");
2065
+ }
2066
+ /**
2067
+ Manually clears all errors for the record.
2068
+ This will transition the record into a `valid` state, and
2069
+ will trigger the `becameValid` event and lifecycle method.
2070
+ Example:
2071
+ ```javascript
2072
+ let errors = user.errors;
2073
+ errors.add('username', ['error-a']);
2074
+ errors.add('phone', ['error-1', 'error-2']);
2075
+ errors.errorsFor('username');
2076
+ // =>
2077
+ // [
2078
+ // { attribute: 'username', message: 'error-a' },
2079
+ // ]
2080
+ errors.errorsFor('phone');
2081
+ // =>
2082
+ // [
2083
+ // { attribute: 'phone', message: 'error-1' },
2084
+ // { attribute: 'phone', message: 'error-2' },
2085
+ // ]
2086
+ errors.clear();
2087
+ errors.errorsFor('username');
2088
+ // => undefined
2089
+ errors.errorsFor('phone');
2090
+ // => undefined
2091
+ errors.messages
2092
+ // => []
2093
+ ```
2094
+ @public
2095
+ */
2096
+ clear() {
2097
+ if (this.isEmpty) return;
2098
+ const errorsByAttributeName = this.errorsByAttributeName;
2099
+ const attributes = [];
2100
+ errorsByAttributeName.forEach(function(_, attribute) {
2101
+ attributes.push(attribute);
2102
+ });
2103
+ errorsByAttributeName.clear();
2104
+ attributes.forEach((attribute) => {
2105
+ this.notifyPropertyChange(attribute);
2106
+ });
2107
+ this.__record.currentState.notify("isValid");
2108
+ super.clear();
2109
+ }
2110
+ /**
2111
+ Checks if there are error messages for the given attribute.
2112
+ ```js [app/controllers/user/edit.js]
2113
+ export default class UserEditController extends Controller {
2114
+ @action
2115
+ save(user) {
2116
+ if (user.errors.has('email')) {
2117
+ return alert('Please update your email before attempting to save.');
2118
+ }
2119
+ user.save();
2120
+ }
2121
+ }
2122
+ ```
2123
+ @public
2124
+ @param {String} attribute
2125
+ @return {Boolean} true if there some errors on given attribute
2126
+ */
2127
+ has(attribute) {
2128
+ return this.errorsFor(attribute).length > 0;
2129
+ }
2130
+ };
2131
+
2132
+ //#endregion
2133
+ export { PromiseBelongsTo as a, PromiseManyArray as i, LEGACY_SUPPORT as n, lookupLegacySupport as r, Errors as t };
2134
+ //# sourceMappingURL=errors-LQhmDVdd.js.map