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

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