@warp-drive/legacy 5.9.0-beta.0 → 5.9.0-beta.2

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