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

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