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

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