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

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