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