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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (476) hide show
  1. package/dist/-private-BYn1Vh-L.js +22 -0
  2. package/dist/-private-BYn1Vh-L.js.map +1 -0
  3. package/dist/-private-CyhhcK1a.js +120 -0
  4. package/dist/-private-CyhhcK1a.js.map +1 -0
  5. package/dist/-private-zrP4VGAf.js +3530 -0
  6. package/dist/-private-zrP4VGAf.js.map +1 -0
  7. package/dist/aliases-BWYW5EhX.d.ts +17 -0
  8. package/dist/aliases-BWYW5EhX.d.ts.map +1 -0
  9. package/dist/build-config/babel-macros.d.ts +2 -0
  10. package/dist/build-config/babel-macros.js +3 -1
  11. package/dist/build-config/canary-features.d.ts +1 -0
  12. package/dist/build-config/canary-features.js +1 -1
  13. package/dist/build-config/debugging.d.ts +1 -0
  14. package/dist/build-config/debugging.js +1 -1
  15. package/dist/build-config/deprecations.d.ts +1 -0
  16. package/dist/build-config/deprecations.js +1 -1
  17. package/dist/build-config/env.d.ts +2 -0
  18. package/dist/build-config/env.js +3 -1
  19. package/dist/build-config/macros.d.ts +2 -0
  20. package/dist/build-config/macros.js +3 -1
  21. package/dist/build-config.d.ts +2 -0
  22. package/dist/build-config.js +3 -1
  23. package/dist/change-C7kqv2kW.d.ts +41 -0
  24. package/dist/change-C7kqv2kW.d.ts.map +1 -0
  25. package/dist/concepts-DFldVwEM.d.ts +77 -0
  26. package/dist/concepts-DFldVwEM.d.ts.map +1 -0
  27. package/dist/configure-B_F639tN.d.ts +134 -0
  28. package/dist/configure-B_F639tN.d.ts.map +1 -0
  29. package/dist/configure.d.ts +2 -0
  30. package/dist/configure.js +3 -2
  31. package/dist/document-BEn91SwT.d.ts +129 -0
  32. package/dist/document-BEn91SwT.d.ts.map +1 -0
  33. package/dist/error-50OSEhsF.d.ts +77 -0
  34. package/dist/error-50OSEhsF.d.ts.map +1 -0
  35. package/dist/fields-FM7peCiM.d.ts +2327 -0
  36. package/dist/fields-FM7peCiM.d.ts.map +1 -0
  37. package/dist/graph/-private.d.ts +2 -0
  38. package/dist/graph/-private.js +2200 -3196
  39. package/dist/graph/-private.js.map +1 -0
  40. package/dist/graph-DLqYXP2z.d.ts +186 -0
  41. package/dist/graph-DLqYXP2z.d.ts.map +1 -0
  42. package/dist/identifier-DQnqOSJK.d.ts +112 -0
  43. package/dist/identifier-DQnqOSJK.d.ts.map +1 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.js +3 -8
  46. package/dist/internal-DtWOpxrR.d.ts +9182 -0
  47. package/dist/internal-DtWOpxrR.d.ts.map +1 -0
  48. package/dist/json-api-raw-C5APJHHB.d.ts +378 -0
  49. package/dist/json-api-raw-C5APJHHB.d.ts.map +1 -0
  50. package/dist/mutations-CqtoGB4t.d.ts +165 -0
  51. package/dist/mutations-CqtoGB4t.d.ts.map +1 -0
  52. package/dist/operations-D1qA6r0_.d.ts +244 -0
  53. package/dist/operations-D1qA6r0_.d.ts.map +1 -0
  54. package/dist/params-DrEx3bf8.d.ts +41 -0
  55. package/dist/params-DrEx3bf8.d.ts.map +1 -0
  56. package/dist/raw-D5hnjiq7.d.ts +31 -0
  57. package/dist/raw-D5hnjiq7.d.ts.map +1 -0
  58. package/dist/reactive/-private.d.ts +2 -0
  59. package/dist/reactive/-private.js +3 -1
  60. package/dist/reactive.d.ts +2 -0
  61. package/dist/reactive.js +5 -4
  62. package/dist/record-D3QQcaIR.d.ts +254 -0
  63. package/dist/record-D3QQcaIR.d.ts.map +1 -0
  64. package/dist/relationship-CmHzMPKf.d.ts +65 -0
  65. package/dist/relationship-CmHzMPKf.d.ts.map +1 -0
  66. package/dist/request-7BJFgSu_.js +766 -0
  67. package/dist/request-7BJFgSu_.js.map +1 -0
  68. package/dist/request.d.ts +2 -0
  69. package/dist/request.js +2 -48
  70. package/dist/signals/-leaked.d.ts +1060 -0
  71. package/dist/signals/-leaked.d.ts.map +1 -0
  72. package/dist/signals/-leaked.js +3 -1
  73. package/dist/src-BOAWJH_S.js +9227 -0
  74. package/dist/src-BOAWJH_S.js.map +1 -0
  75. package/dist/store/-private.d.ts +2 -0
  76. package/dist/store/-private.js +3 -1
  77. package/dist/store-DNF9Rgoh.js +462 -0
  78. package/dist/store-DNF9Rgoh.js.map +1 -0
  79. package/dist/store.d.ts +2 -0
  80. package/dist/store.js +3 -1
  81. package/dist/symbols-DjRDCeX0.d.ts +88 -0
  82. package/dist/symbols-DjRDCeX0.d.ts.map +1 -0
  83. package/dist/types/-private.d.ts +76 -0
  84. package/dist/types/-private.d.ts.map +1 -0
  85. package/dist/types/-private.js +1 -77
  86. package/dist/types/cache/aliases.d.ts +2 -0
  87. package/dist/types/cache/change.d.ts +2 -0
  88. package/dist/types/cache/mutations.d.ts +2 -0
  89. package/dist/types/cache/operations.d.ts +2 -0
  90. package/dist/types/cache/relationship.d.ts +2 -0
  91. package/dist/types/cache.d.ts +2 -0
  92. package/dist/types/graph.d.ts +2 -0
  93. package/dist/types/identifier.d.ts +2 -0
  94. package/dist/types/identifier.js +60 -52
  95. package/dist/types/identifier.js.map +1 -0
  96. package/dist/types/json/raw.d.ts +2 -0
  97. package/dist/types/params.d.ts +2 -0
  98. package/dist/types/record.d.ts +2 -0
  99. package/dist/types/record.js +211 -181
  100. package/dist/types/record.js.map +1 -0
  101. package/dist/types/request.d.ts +2 -0
  102. package/dist/types/request.js +138 -69
  103. package/dist/types/request.js.map +1 -0
  104. package/dist/types/runtime.d.ts +55 -0
  105. package/dist/types/runtime.d.ts.map +1 -0
  106. package/dist/types/runtime.js +54 -26
  107. package/dist/types/runtime.js.map +1 -0
  108. package/dist/types/schema/concepts.d.ts +2 -0
  109. package/dist/types/schema/fields.d.ts +2 -0
  110. package/dist/types/schema/fields.js +501 -495
  111. package/dist/types/schema/fields.js.map +1 -0
  112. package/dist/types/schema/fields.type-test.d.ts +1 -0
  113. package/dist/types/schema/fields.type-test.js +79 -0
  114. package/dist/types/schema/fields.type-test.js.map +1 -0
  115. package/dist/types/schema/schema-service.d.ts +2 -0
  116. package/dist/types/spec/document.d.ts +2 -0
  117. package/dist/types/spec/error.d.ts +2 -0
  118. package/dist/types/spec/json-api-raw.d.ts +2 -0
  119. package/dist/types/symbols.d.ts +2 -0
  120. package/dist/types/symbols.js +84 -77
  121. package/dist/types/symbols.js.map +1 -0
  122. package/dist/types/utils.d.ts +2 -0
  123. package/dist/types.d.ts +3 -0
  124. package/dist/unpkg/dev/-private-BoSTJwp9.js +3519 -0
  125. package/dist/unpkg/dev/-private-BoSTJwp9.js.map +1 -0
  126. package/dist/unpkg/dev/-private-CUkeqUhO.js +22 -0
  127. package/dist/unpkg/dev/-private-CUkeqUhO.js.map +1 -0
  128. package/dist/unpkg/dev/-private-D6Tw25AD.js +111 -0
  129. package/dist/unpkg/dev/-private-D6Tw25AD.js.map +1 -0
  130. package/dist/unpkg/dev/build-config/babel-macros.js +3 -1
  131. package/dist/unpkg/dev/build-config/canary-features.js +1 -1
  132. package/dist/unpkg/dev/build-config/debugging.js +1 -1
  133. package/dist/unpkg/dev/build-config/deprecations.js +1 -1
  134. package/dist/unpkg/dev/build-config/env.js +3 -1
  135. package/dist/unpkg/dev/build-config/macros.js +3 -1
  136. package/dist/unpkg/dev/build-config.js +3 -1
  137. package/dist/unpkg/dev/configure.js +3 -1
  138. package/dist/unpkg/dev/graph/-private.js +1958 -2953
  139. package/dist/unpkg/dev/graph/-private.js.map +1 -0
  140. package/dist/unpkg/dev/index.js +3 -6
  141. package/dist/unpkg/dev/reactive/-private.js +3 -1
  142. package/dist/unpkg/dev/reactive.js +5 -3
  143. package/dist/unpkg/dev/request-CwjpJB3r.js +756 -0
  144. package/dist/unpkg/dev/request-CwjpJB3r.js.map +1 -0
  145. package/dist/unpkg/dev/request.js +2 -48
  146. package/dist/unpkg/dev/runtime-DoDtzXJb.js +110 -0
  147. package/dist/unpkg/dev/runtime-DoDtzXJb.js.map +1 -0
  148. package/dist/unpkg/dev/signals/-leaked.js +3 -1
  149. package/dist/unpkg/dev/src-CP6e_ozt.js +8331 -0
  150. package/dist/unpkg/dev/src-CP6e_ozt.js.map +1 -0
  151. package/dist/unpkg/dev/store/-private.js +3 -55
  152. package/dist/unpkg/dev/store-DamE3C4y.js +427 -0
  153. package/dist/unpkg/dev/store-DamE3C4y.js.map +1 -0
  154. package/dist/unpkg/dev/store.js +1 -556
  155. package/dist/unpkg/dev/types/-private.js +1 -67
  156. package/dist/unpkg/dev/types/identifier.js +63 -56
  157. package/dist/unpkg/dev/types/identifier.js.map +1 -0
  158. package/dist/unpkg/dev/types/record.js +211 -181
  159. package/dist/unpkg/dev/types/record.js.map +1 -0
  160. package/dist/unpkg/dev/types/request.js +138 -69
  161. package/dist/unpkg/dev/types/request.js.map +1 -0
  162. package/dist/unpkg/dev/types/runtime.js +54 -26
  163. package/dist/unpkg/dev/types/runtime.js.map +1 -0
  164. package/dist/unpkg/dev/types/schema/fields.js +501 -495
  165. package/dist/unpkg/dev/types/schema/fields.js.map +1 -0
  166. package/dist/unpkg/dev/types/schema/fields.type-test.js +79 -0
  167. package/dist/unpkg/dev/types/schema/fields.type-test.js.map +1 -0
  168. package/dist/unpkg/dev/types/symbols.js +84 -77
  169. package/dist/unpkg/dev/types/symbols.js.map +1 -0
  170. package/dist/unpkg/dev/utils/string.js +79 -85
  171. package/dist/unpkg/dev/utils/string.js.map +1 -0
  172. package/dist/unpkg/dev-deprecated/-private-BoSTJwp9.js +3519 -0
  173. package/dist/unpkg/dev-deprecated/-private-BoSTJwp9.js.map +1 -0
  174. package/dist/unpkg/dev-deprecated/-private-CUkeqUhO.js +22 -0
  175. package/dist/unpkg/dev-deprecated/-private-CUkeqUhO.js.map +1 -0
  176. package/dist/unpkg/dev-deprecated/-private-D6Tw25AD.js +111 -0
  177. package/dist/unpkg/dev-deprecated/-private-D6Tw25AD.js.map +1 -0
  178. package/dist/unpkg/dev-deprecated/build-config/babel-macros.js +3 -1
  179. package/dist/unpkg/dev-deprecated/build-config/canary-features.js +1 -1
  180. package/dist/unpkg/dev-deprecated/build-config/debugging.js +1 -1
  181. package/dist/unpkg/dev-deprecated/build-config/deprecations.js +1 -1
  182. package/dist/unpkg/dev-deprecated/build-config/env.js +3 -1
  183. package/dist/unpkg/dev-deprecated/build-config/macros.js +3 -1
  184. package/dist/unpkg/dev-deprecated/build-config.js +3 -1
  185. package/dist/unpkg/dev-deprecated/configure.js +3 -1
  186. package/dist/unpkg/dev-deprecated/graph/-private.js +2077 -3147
  187. package/dist/unpkg/dev-deprecated/graph/-private.js.map +1 -0
  188. package/dist/unpkg/dev-deprecated/index.js +3 -5
  189. package/dist/unpkg/dev-deprecated/reactive/-private.js +3 -1
  190. package/dist/unpkg/dev-deprecated/reactive.js +5 -3
  191. package/dist/unpkg/dev-deprecated/request-CwjpJB3r.js +756 -0
  192. package/dist/unpkg/dev-deprecated/request-CwjpJB3r.js.map +1 -0
  193. package/dist/unpkg/dev-deprecated/request.js +2 -48
  194. package/dist/unpkg/dev-deprecated/runtime-CPL2BGgT.js +110 -0
  195. package/dist/unpkg/dev-deprecated/runtime-CPL2BGgT.js.map +1 -0
  196. package/dist/unpkg/dev-deprecated/signals/-leaked.js +3 -1
  197. package/dist/unpkg/dev-deprecated/src-De8OV58h.js +8884 -0
  198. package/dist/unpkg/dev-deprecated/src-De8OV58h.js.map +1 -0
  199. package/dist/unpkg/dev-deprecated/store/-private.js +3 -1
  200. package/dist/unpkg/dev-deprecated/store-Bsdz5mRe.js +427 -0
  201. package/dist/unpkg/dev-deprecated/store-Bsdz5mRe.js.map +1 -0
  202. package/dist/unpkg/dev-deprecated/store.js +1 -556
  203. package/dist/unpkg/dev-deprecated/types/-private.js +1 -67
  204. package/dist/unpkg/dev-deprecated/types/identifier.js +63 -56
  205. package/dist/unpkg/dev-deprecated/types/identifier.js.map +1 -0
  206. package/dist/unpkg/dev-deprecated/types/record.js +211 -181
  207. package/dist/unpkg/dev-deprecated/types/record.js.map +1 -0
  208. package/dist/unpkg/dev-deprecated/types/request.js +138 -69
  209. package/dist/unpkg/dev-deprecated/types/request.js.map +1 -0
  210. package/dist/unpkg/dev-deprecated/types/runtime.js +54 -26
  211. package/dist/unpkg/dev-deprecated/types/runtime.js.map +1 -0
  212. package/dist/unpkg/dev-deprecated/types/schema/fields.js +501 -495
  213. package/dist/unpkg/dev-deprecated/types/schema/fields.js.map +1 -0
  214. package/dist/unpkg/dev-deprecated/types/schema/fields.type-test.js +79 -0
  215. package/dist/unpkg/dev-deprecated/types/schema/fields.type-test.js.map +1 -0
  216. package/dist/unpkg/dev-deprecated/types/symbols.js +84 -77
  217. package/dist/unpkg/dev-deprecated/types/symbols.js.map +1 -0
  218. package/dist/unpkg/dev-deprecated/utils/string.js +79 -85
  219. package/dist/unpkg/dev-deprecated/utils/string.js.map +1 -0
  220. package/dist/unpkg/prod/-private-B36B1ztP.js +22 -0
  221. package/dist/unpkg/prod/-private-B36B1ztP.js.map +1 -0
  222. package/dist/unpkg/prod/-private-DHco-h0q.js +3294 -0
  223. package/dist/unpkg/prod/-private-DHco-h0q.js.map +1 -0
  224. package/dist/unpkg/prod/-private-Dhl123OI.js +99 -0
  225. package/dist/unpkg/prod/-private-Dhl123OI.js.map +1 -0
  226. package/dist/unpkg/prod/build-config/babel-macros.js +3 -1
  227. package/dist/unpkg/prod/build-config/canary-features.js +1 -1
  228. package/dist/unpkg/prod/build-config/debugging.js +1 -1
  229. package/dist/unpkg/prod/build-config/deprecations.js +1 -1
  230. package/dist/unpkg/prod/build-config/env.js +3 -1
  231. package/dist/unpkg/prod/build-config/macros.js +3 -1
  232. package/dist/unpkg/prod/build-config.js +3 -1
  233. package/dist/unpkg/prod/configure.js +3 -2
  234. package/dist/unpkg/prod/graph/-private.js +1494 -2101
  235. package/dist/unpkg/prod/graph/-private.js.map +1 -0
  236. package/dist/unpkg/prod/index.js +2 -482
  237. package/dist/unpkg/prod/reactive/-private.js +3 -1
  238. package/dist/unpkg/prod/reactive.js +5 -30
  239. package/dist/unpkg/prod/request-BBdC1Sz7.js +480 -0
  240. package/dist/unpkg/prod/request-BBdC1Sz7.js.map +1 -0
  241. package/dist/unpkg/prod/request.js +3 -2
  242. package/dist/unpkg/prod/signals/-leaked.js +3 -1
  243. package/dist/unpkg/prod/src-nFHlZgKa.js +6942 -0
  244. package/dist/unpkg/prod/src-nFHlZgKa.js.map +1 -0
  245. package/dist/unpkg/prod/store/-private.js +3 -126
  246. package/dist/unpkg/prod/store-BWhmb7Ob.js +359 -0
  247. package/dist/unpkg/prod/store-BWhmb7Ob.js.map +1 -0
  248. package/dist/unpkg/prod/store.js +1 -435
  249. package/dist/unpkg/prod/types/-private.js +1 -47
  250. package/dist/unpkg/prod/types/identifier.js +63 -56
  251. package/dist/unpkg/prod/types/identifier.js.map +1 -0
  252. package/dist/unpkg/prod/types/record.js +211 -181
  253. package/dist/unpkg/prod/types/record.js.map +1 -0
  254. package/dist/unpkg/prod/types/request.js +138 -69
  255. package/dist/unpkg/prod/types/request.js.map +1 -0
  256. package/dist/unpkg/prod/types/runtime.js +54 -26
  257. package/dist/unpkg/prod/types/runtime.js.map +1 -0
  258. package/dist/unpkg/prod/types/schema/fields.js +501 -495
  259. package/dist/unpkg/prod/types/schema/fields.js.map +1 -0
  260. package/dist/unpkg/prod/types/schema/fields.type-test.js +79 -0
  261. package/dist/unpkg/prod/types/schema/fields.type-test.js.map +1 -0
  262. package/dist/unpkg/prod/types/symbols.js +84 -77
  263. package/dist/unpkg/prod/types/symbols.js.map +1 -0
  264. package/dist/unpkg/prod/utils/string.js +70 -66
  265. package/dist/unpkg/prod/utils/string.js.map +1 -0
  266. package/dist/unpkg/prod-deprecated/-private-B36B1ztP.js +22 -0
  267. package/dist/unpkg/prod-deprecated/-private-B36B1ztP.js.map +1 -0
  268. package/dist/unpkg/prod-deprecated/-private-DHco-h0q.js +3294 -0
  269. package/dist/unpkg/prod-deprecated/-private-DHco-h0q.js.map +1 -0
  270. package/dist/unpkg/prod-deprecated/-private-Dhl123OI.js +99 -0
  271. package/dist/unpkg/prod-deprecated/-private-Dhl123OI.js.map +1 -0
  272. package/dist/unpkg/prod-deprecated/build-config/babel-macros.js +3 -1
  273. package/dist/unpkg/prod-deprecated/build-config/canary-features.js +1 -1
  274. package/dist/unpkg/prod-deprecated/build-config/debugging.js +1 -1
  275. package/dist/unpkg/prod-deprecated/build-config/deprecations.js +1 -1
  276. package/dist/unpkg/prod-deprecated/build-config/env.js +3 -1
  277. package/dist/unpkg/prod-deprecated/build-config/macros.js +3 -1
  278. package/dist/unpkg/prod-deprecated/build-config.js +3 -1
  279. package/dist/unpkg/prod-deprecated/configure.js +3 -2
  280. package/dist/unpkg/prod-deprecated/graph/-private.js +1603 -2272
  281. package/dist/unpkg/prod-deprecated/graph/-private.js.map +1 -0
  282. package/dist/unpkg/prod-deprecated/index.js +2 -482
  283. package/dist/unpkg/prod-deprecated/reactive/-private.js +3 -1
  284. package/dist/unpkg/prod-deprecated/reactive.js +5 -5
  285. package/dist/unpkg/prod-deprecated/request-BBdC1Sz7.js +480 -0
  286. package/dist/unpkg/prod-deprecated/request-BBdC1Sz7.js.map +1 -0
  287. package/dist/unpkg/prod-deprecated/request.js +3 -2
  288. package/dist/unpkg/prod-deprecated/signals/-leaked.js +3 -1
  289. package/dist/unpkg/prod-deprecated/src-Cku5ymUJ.js +7375 -0
  290. package/dist/unpkg/prod-deprecated/src-Cku5ymUJ.js.map +1 -0
  291. package/dist/unpkg/prod-deprecated/store/-private.js +3 -88
  292. package/dist/unpkg/prod-deprecated/store-BWhmb7Ob.js +359 -0
  293. package/dist/unpkg/prod-deprecated/store-BWhmb7Ob.js.map +1 -0
  294. package/dist/unpkg/prod-deprecated/store.js +1 -435
  295. package/dist/unpkg/prod-deprecated/types/-private.js +1 -47
  296. package/dist/unpkg/prod-deprecated/types/identifier.js +63 -56
  297. package/dist/unpkg/prod-deprecated/types/identifier.js.map +1 -0
  298. package/dist/unpkg/prod-deprecated/types/record.js +211 -181
  299. package/dist/unpkg/prod-deprecated/types/record.js.map +1 -0
  300. package/dist/unpkg/prod-deprecated/types/request.js +138 -69
  301. package/dist/unpkg/prod-deprecated/types/request.js.map +1 -0
  302. package/dist/unpkg/prod-deprecated/types/runtime.js +54 -26
  303. package/dist/unpkg/prod-deprecated/types/runtime.js.map +1 -0
  304. package/dist/unpkg/prod-deprecated/types/schema/fields.js +501 -495
  305. package/dist/unpkg/prod-deprecated/types/schema/fields.js.map +1 -0
  306. package/dist/unpkg/prod-deprecated/types/schema/fields.type-test.js +79 -0
  307. package/dist/unpkg/prod-deprecated/types/schema/fields.type-test.js.map +1 -0
  308. package/dist/unpkg/prod-deprecated/types/symbols.js +84 -77
  309. package/dist/unpkg/prod-deprecated/types/symbols.js.map +1 -0
  310. package/dist/unpkg/prod-deprecated/utils/string.js +70 -66
  311. package/dist/unpkg/prod-deprecated/utils/string.js.map +1 -0
  312. package/dist/utils/string.d.ts +54 -0
  313. package/dist/utils/string.d.ts.map +1 -0
  314. package/dist/utils/string.js +84 -85
  315. package/dist/utils/string.js.map +1 -0
  316. package/dist/utils-BtURiy8l.d.ts +24 -0
  317. package/dist/utils-BtURiy8l.d.ts.map +1 -0
  318. package/package.json +17 -21
  319. package/declarations/build-config/babel-macros.d.ts +0 -1
  320. package/declarations/build-config/canary-features.d.ts +0 -1
  321. package/declarations/build-config/debugging.d.ts +0 -1
  322. package/declarations/build-config/deprecations.d.ts +0 -1
  323. package/declarations/build-config/env.d.ts +0 -1
  324. package/declarations/build-config/macros.d.ts +0 -1
  325. package/declarations/build-config.d.ts +0 -18
  326. package/declarations/configure.d.ts +0 -7
  327. package/declarations/graph/-private/-diff.d.ts +0 -19
  328. package/declarations/graph/-private/-edge-definition.d.ts +0 -149
  329. package/declarations/graph/-private/-state.d.ts +0 -9
  330. package/declarations/graph/-private/-utils.d.ts +0 -25
  331. package/declarations/graph/-private/coerce-id.d.ts +0 -4
  332. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +0 -6
  333. package/declarations/graph/-private/edges/collection.d.ts +0 -39
  334. package/declarations/graph/-private/edges/implicit.d.ts +0 -43
  335. package/declarations/graph/-private/edges/resource.d.ts +0 -23
  336. package/declarations/graph/-private/graph.d.ts +0 -56
  337. package/declarations/graph/-private/normalize-link.d.ts +0 -2
  338. package/declarations/graph/-private/operations/add-to-related-records.d.ts +0 -4
  339. package/declarations/graph/-private/operations/merge-identifier.d.ts +0 -3
  340. package/declarations/graph/-private/operations/remove-from-related-records.d.ts +0 -4
  341. package/declarations/graph/-private/operations/replace-related-record.d.ts +0 -3
  342. package/declarations/graph/-private/operations/replace-related-records.d.ts +0 -7
  343. package/declarations/graph/-private/operations/update-relationship.d.ts +0 -9
  344. package/declarations/graph/-private.d.ts +0 -13
  345. package/declarations/index.d.ts +0 -96
  346. package/declarations/reactive/-private/default-mode.d.ts +0 -73
  347. package/declarations/reactive/-private/document.d.ts +0 -142
  348. package/declarations/reactive/-private/fields/extension.d.ts +0 -8
  349. package/declarations/reactive/-private/fields/get-field-key.d.ts +0 -8
  350. package/declarations/reactive/-private/fields/managed-array.d.ts +0 -18
  351. package/declarations/reactive/-private/fields/managed-object.d.ts +0 -17
  352. package/declarations/reactive/-private/fields/many-array-manager.d.ts +0 -19
  353. package/declarations/reactive/-private/hooks.d.ts +0 -5
  354. package/declarations/reactive/-private/kind/alias-field.d.ts +0 -4
  355. package/declarations/reactive/-private/kind/array-field.d.ts +0 -4
  356. package/declarations/reactive/-private/kind/attribute-field.d.ts +0 -4
  357. package/declarations/reactive/-private/kind/belongs-to-field.d.ts +0 -4
  358. package/declarations/reactive/-private/kind/collection-field.d.ts +0 -4
  359. package/declarations/reactive/-private/kind/derived-field.d.ts +0 -4
  360. package/declarations/reactive/-private/kind/generic-field.d.ts +0 -4
  361. package/declarations/reactive/-private/kind/has-many-field.d.ts +0 -4
  362. package/declarations/reactive/-private/kind/hash-field.d.ts +0 -4
  363. package/declarations/reactive/-private/kind/identity-field.d.ts +0 -4
  364. package/declarations/reactive/-private/kind/local-field.d.ts +0 -4
  365. package/declarations/reactive/-private/kind/object-field.d.ts +0 -4
  366. package/declarations/reactive/-private/kind/resource-field.d.ts +0 -4
  367. package/declarations/reactive/-private/kind/schema-array-field.d.ts +0 -4
  368. package/declarations/reactive/-private/kind/schema-object-field.d.ts +0 -4
  369. package/declarations/reactive/-private/record.d.ts +0 -83
  370. package/declarations/reactive/-private/schema.d.ts +0 -326
  371. package/declarations/reactive/-private/symbols.d.ts +0 -5
  372. package/declarations/reactive/-private.d.ts +0 -2
  373. package/declarations/reactive.d.ts +0 -286
  374. package/declarations/request/-private/context.d.ts +0 -39
  375. package/declarations/request/-private/debug.d.ts +0 -4
  376. package/declarations/request/-private/fetch.d.ts +0 -33
  377. package/declarations/request/-private/future.d.ts +0 -7
  378. package/declarations/request/-private/manager.d.ts +0 -158
  379. package/declarations/request/-private/promise-cache.d.ts +0 -28
  380. package/declarations/request/-private/types.d.ts +0 -234
  381. package/declarations/request/-private/utils.d.ts +0 -57
  382. package/declarations/request.d.ts +0 -52
  383. package/declarations/signals/-leaked.d.ts +0 -2
  384. package/declarations/signals/-private.d.ts +0 -6
  385. package/declarations/signals/promise-state.d.ts +0 -264
  386. package/declarations/signals/reactivity/configure.d.ts +0 -138
  387. package/declarations/signals/reactivity/internal.d.ts +0 -154
  388. package/declarations/signals/reactivity/signal.d.ts +0 -56
  389. package/declarations/signals/request-state.d.ts +0 -372
  390. package/declarations/signals/request-subscription.d.ts +0 -177
  391. package/declarations/store/-private/cache-handler/handler.d.ts +0 -56
  392. package/declarations/store/-private/cache-handler/types.d.ts +0 -84
  393. package/declarations/store/-private/cache-handler/utils.d.ts +0 -31
  394. package/declarations/store/-private/caches/instance-cache.d.ts +0 -58
  395. package/declarations/store/-private/caches/resource-utils.d.ts +0 -9
  396. package/declarations/store/-private/debug/utils.d.ts +0 -7
  397. package/declarations/store/-private/default-cache-policy.d.ts +0 -387
  398. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +0 -34
  399. package/declarations/store/-private/managers/cache-key-manager.d.ts +0 -304
  400. package/declarations/store/-private/managers/cache-manager.d.ts +0 -367
  401. package/declarations/store/-private/managers/notification-manager.d.ts +0 -83
  402. package/declarations/store/-private/managers/record-array-manager.d.ts +0 -100
  403. package/declarations/store/-private/network/request-cache.d.ts +0 -103
  404. package/declarations/store/-private/record-arrays/-utils.d.ts +0 -80
  405. package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +0 -81
  406. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +0 -133
  407. package/declarations/store/-private/record-arrays/legacy-query.d.ts +0 -81
  408. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +0 -3
  409. package/declarations/store/-private/record-arrays/resource-array.d.ts +0 -67
  410. package/declarations/store/-private/store-service.d.ts +0 -874
  411. package/declarations/store/-private/utils/coerce-id.d.ts +0 -4
  412. package/declarations/store/-private/utils/construct-resource.d.ts +0 -6
  413. package/declarations/store/-private/utils/is-non-empty-string.d.ts +0 -1
  414. package/declarations/store/-private/utils/normalize-model-name.d.ts +0 -1
  415. package/declarations/store/-private/utils/uuid-polyfill.d.ts +0 -1
  416. package/declarations/store/-private.d.ts +0 -24
  417. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +0 -90
  418. package/declarations/store/-types/q/identifier.d.ts +0 -23
  419. package/declarations/store/-types/q/record-instance.d.ts +0 -22
  420. package/declarations/store/-types/q/store.d.ts +0 -31
  421. package/declarations/store/deprecated/-private.d.ts +0 -223
  422. package/declarations/store/deprecated/store.d.ts +0 -784
  423. package/declarations/store.d.ts +0 -2
  424. package/declarations/types/-private.d.ts +0 -22
  425. package/declarations/types/cache/aliases.d.ts +0 -1
  426. package/declarations/types/cache/change.d.ts +0 -6
  427. package/declarations/types/cache/mutations.d.ts +0 -38
  428. package/declarations/types/cache/operations.d.ts +0 -168
  429. package/declarations/types/cache/relationship.d.ts +0 -13
  430. package/declarations/types/cache.d.ts +0 -429
  431. package/declarations/types/graph.d.ts +0 -47
  432. package/declarations/types/identifier.d.ts +0 -86
  433. package/declarations/types/json/raw.d.ts +0 -6
  434. package/declarations/types/params.d.ts +0 -8
  435. package/declarations/types/record.d.ts +0 -269
  436. package/declarations/types/request.d.ts +0 -367
  437. package/declarations/types/runtime.d.ts +0 -14
  438. package/declarations/types/schema/concepts.d.ts +0 -23
  439. package/declarations/types/schema/fields.d.ts +0 -2200
  440. package/declarations/types/schema/fields.type-test.d.ts +0 -1
  441. package/declarations/types/schema/schema-service.d.ts +0 -380
  442. package/declarations/types/spec/document.d.ts +0 -67
  443. package/declarations/types/spec/error.d.ts +0 -18
  444. package/declarations/types/spec/json-api-raw.d.ts +0 -139
  445. package/declarations/types/symbols.d.ts +0 -78
  446. package/declarations/types/utils.d.ts +0 -5
  447. package/declarations/types.d.ts +0 -11
  448. package/declarations/utils/string.d.ts +0 -47
  449. package/dist/configure-DPUFCemT.js +0 -1940
  450. package/dist/default-cache-policy-D7_u4YRH.js +0 -572
  451. package/dist/future-BKkJJkj7.js +0 -678
  452. package/dist/index-CQP2NSqg.js +0 -9982
  453. package/dist/symbols-3C1OkYtZ.js +0 -39
  454. package/dist/unpkg/dev/-leaked-Co0EI6Go.js +0 -1939
  455. package/dist/unpkg/dev/-private-sql1_mdx.js +0 -39
  456. package/dist/unpkg/dev/future-DFfOzSoe.js +0 -672
  457. package/dist/unpkg/dev/index-BzcBOnw9.js +0 -9392
  458. package/dist/unpkg/dev/runtime-E1M51_-O.js +0 -135
  459. package/dist/unpkg/dev-deprecated/-leaked-DjMeRqdU.js +0 -1939
  460. package/dist/unpkg/dev-deprecated/-private-3C1OkYtZ.js +0 -39
  461. package/dist/unpkg/dev-deprecated/future-DFfOzSoe.js +0 -672
  462. package/dist/unpkg/dev-deprecated/index-6TnTv-WG.js +0 -10007
  463. package/dist/unpkg/dev-deprecated/runtime-DAu5b0IR.js +0 -135
  464. package/dist/unpkg/prod/-leaked-DUONXQDB.js +0 -1676
  465. package/dist/unpkg/prod/-private-sql1_mdx.js +0 -39
  466. package/dist/unpkg/prod/handler-EU_8ncB2.js +0 -1619
  467. package/dist/unpkg/prod/promise-cache-DIT8Ypjq.js +0 -19
  468. package/dist/unpkg/prod/request-BrJSCG6r.js +0 -421
  469. package/dist/unpkg/prod/schema-BSkHyoWz.js +0 -5219
  470. package/dist/unpkg/prod-deprecated/-leaked-DRNv9VIX.js +0 -1676
  471. package/dist/unpkg/prod-deprecated/-private-3C1OkYtZ.js +0 -39
  472. package/dist/unpkg/prod-deprecated/handler-CCIu4sQ3.js +0 -334
  473. package/dist/unpkg/prod-deprecated/hooks-Dv4Np0MY.js +0 -26
  474. package/dist/unpkg/prod-deprecated/promise-cache-DIT8Ypjq.js +0 -19
  475. package/dist/unpkg/prod-deprecated/request-BrJSCG6r.js +0 -421
  476. package/dist/unpkg/prod-deprecated/schema-CJcjHv0E.js +0 -6939
@@ -0,0 +1 @@
1
+ {"version":3,"file":"-private.js","names":["deprecate","getGlobalConfig","macroCondition","coerceId","id","WarpDrive","deprecations","DEPRECATE_NON_STRICT_ID","normalized","undefined","String","JSON","stringify","until","for","since","available","enabled","env","DEBUG","test","Error","length","ensureStringId","isNaN","warn","coerceId","getGlobalConfig","macroCondition","getStore","wrapper","WarpDrive","env","DEBUG","test","Error","_store","expandingGet","cache","key1","key2","mainCache","Object","create","expandingSet","value","assertValidRelationshipPayload","graph","op","relationship","get","record","field","isHasMany","isBelongsTo","payload","definition","identifier","state","type","isAsync","kind","links","features","JSON_API_CACHE_VALIDATION_ERRORS","data","hasReceivedData","id","inspect","Array","isArray","assertRelationshipData","store","i","length","Date","RegExp","Map","Set","checkIfNew","resourceKey","isNew","isImplicit","forAllRelatedIdentifiers","rel","cb","remoteState","localState","inverseIdentifier","additions","forEach","localMembers","remoteMembers","has","removeIdentifierCompletelyFromRelationship","silenceNotifications","notifyChange","delete","wasInRemovals","removals","canonicalIndex","indexOf","splice","currentIndex","undefined","channel","accessed","key","_removing","activeLogging","LOG_GRAPH","debug","globalThis","getWarpDriveRuntimeConfig","console","log","String","meta","JSON","stringify","schema","hasResource","expandingGet","expandingSet","getStore","assertInheritedSchema","getGlobalConfig","macroCondition","RELATIONSHIP_KINDS","isLegacyField","field","kind","isRelationshipField","includes","temporaryConvertToLegacy","name","type","options","Object","assign","async","inverse","resetOnRemoteUpdate","BOOL_LATER","STR_LATER","IMPLICIT_KEY_RAND","Date","now","implicitKeyFor","key","syncMeta","definition","inverseDefinition","inverseKind","inverseKey","inverseName","inverseType","inverseIsAsync","isAsync","inverseIsCollection","isCollection","inverseIsPolymorphic","isPolymorphic","inverseIsImplicit","isImplicit","inverseIsLinksMode","isLinksMode","upgradeMeta","meta","niceMeta","sourceKey","WarpDrive","env","DEBUG","test","Error","polymorphic","linksMode","assertConfiguration","info","isSelfReferential","_isRHS","rhs_relationshipName","rhs_baseModelName","lhs_isPolymorphic","rhs_modelNames","_isLHS","lhs_relationshipName","lhs_baseModelName","rhs_isPolymorphic","lhs_modelNames","lhs_definition","isLHS","isRelationship","isRHS","upgradeDefinition","graph","propertyName","cache","_definitionCache","storeWrapper","store","polymorphicLookup","_potentialPolymorphicTypes","cached","undefined","relationships","schema","fields","relationshipsBySourceKey","cacheFields","get","altTypes","keys","i","length","_cached","push","hasResource","inverseForRelationship","inverseDefinitions","metaFromInverse","lhs_key","rhs_key","rhs_definition","hasInverse","isReflexive","baseType","claimedRelationshipName","isKnownSide","JSON","stringify","modelNames","resourceKey","isLegacyField","isRelationshipField","temporaryConvertToLegacy","getGlobalConfig","macroCondition","assertPolymorphicType","assertInheritedSchema","WarpDrive","env","DEBUG","validateSchema","definition","meta","errors","Map","inverseKey","name","set","inverseType","type","inverseKind","kind","inverseIsAsync","options","async","inverseIsPolymorphic","polymorphic","key","inverse","isPolymorphic","as","expectedSchema","printSchema","config","get","inverseMetaFrom","undefined","inverseDefinition","inverseName","isAsync","isLinksMode","isCollection","inverseIsCollection","isImplicit","inverseIsImplicit","inverseIsLinksMode","resetOnRemoteUpdate","definitionWithPolymorphic","Object","assign","meta2","errors2","size","Error","parentIdentifier","parentDefinition","addedIdentifier","store","schema","fields","test","length","deprecate","_add","_removeLocal","_removeRemote","diffCollection","checkIfNew","isBelongsTo","isHasMany","notifyChange","assertPolymorphicType","getGlobalConfig","macroCondition","count","label","globalThis","__WarpDriveMetricCountData","replaceRelatedRecords","graph","op","isRemote","replaceRelatedRecordsRemote","replaceRelatedRecordsLocal","resourceKeys","value","relationship","get","record","field","WarpDrive","env","DEBUG","test","Error","state","hasReceivedData","additions","removals","inverseKey","type","definition","wasDirty","isDirty","localBecameDirty","activeLogging","LOG_METRIC_COUNTS","debug","getWarpDriveRuntimeConfig","onAdd","resourceKey","removalsHas","has","identifier","store","registerPolymorphicType","addToInverse","delete","onRemove","additionsHas","removeFromInverse","diff","size","forEach","add","del","becameDirty","changed","localState","finalState","kind","_addToTransaction","DEBUG_RELATIONSHIP_NOTIFICATIONS","console","log","remoteMembers","finalSet","remoteState","_diff","deprecations","DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE","resetOnRemoteUpdate","deprecationInfo","triggered","push","_realStore","key","map","i","lid","join","id","for","since","enabled","available","until","url","remoteOrderChanged","flushCanonical","isEmpty","localMembers","notifyInverseOfPotentialMaterialization","rel","channel","accessed","_scheduleLocalSync","deprecate","checkIfNew","isBelongsTo","notifyChange","assertPolymorphicType","addToInverse","notifyInverseOfPotentialMaterialization","removeFromInverse","getGlobalConfig","macroCondition","replaceRelatedRecord","graph","op","isRemote","relationship","get","record","field","WarpDrive","env","DEBUG","test","Error","type","definition","kind","_addToTransaction","state","prop","existingState","value","hasReceivedData","hasReceivedRemoteData","localState","_realStore","inverseKey","deprecations","DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE","resetOnRemoteUpdate","identifier","key","lid","id","for","since","enabled","available","until","url","isEmpty","isStale","hasFailedLoadAttempt","store","registerPolymorphicType","remoteState","deprecate","isBelongsTo","notifyChange","assertPolymorphicType","replaceRelatedRecord","replaceRelatedRecords","getGlobalConfig","macroCondition","_deprecatedCompare","priorLocalState","newState","newMembers","prevState","prevSet","onAdd","onDel","remoteClearsLocal","newLength","length","prevLength","iterationLength","Math","max","changed","size","remoteOrderChanged","added","Set","removed","duplicates","Map","finalSet","finalState","priorLocalLength","i","j","adv","member","has","add","priorLocalMember","list","get","undefined","set","push","prevMember","WarpDrive","deprecations","DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE","diff","del","_compare","finalLength","equalLength","activeLogging","DEBUG_RELATIONSHIP_NOTIFICATIONS","debug","globalThis","getWarpDriveRuntimeConfig","console","log","diffCollection","relationship","localState","remoteState","remoteMembers","DEPRECATE_NON_UNIQUE_PAYLOADS","definition","resetOnRemoteUpdate","env","DEBUG","type","key","id","for","until","since","available","enabled","test","Error","computeLocalState","storage","isDirty","state","slice","removals","forEach","v","index","indexOf","splice","additions","_add","graph","record","value","isRemote","_addLocal","_addRemote","hasValidIndex","delete","unshift","hasPresence","lid","identifier","hasReceivedData","store","registerPolymorphicType","_remove","_removeLocal","_removeRemote","rollbackRelationship","field","op","createState","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","activeLogging","LOG_GRAPH","debug","globalThis","getWarpDriveRuntimeConfig","hasReceivedData","value","hasReceivedRemoteData","isEmpty","isStale","hasFailedLoadAttempt","shouldForceReload","hasDematerializedInverse","computeLocalState","createState","createCollectionEdge","definition","identifier","state","remoteMembers","Set","remoteState","additions","removals","meta","links","localState","isDirty","transactionRef","accessed","_diff","undefined","cp","structuredClone","legacyGetCollectionRelationshipData","source","getRemoteState","payload","hasReceivedData","data","slice","createImplicitEdge","definition","identifier","localMembers","Set","remoteMembers","_add","isBelongsTo","isHasMany","notifyChange","replaceRelatedRecord","addToInverse","macroCondition","getGlobalConfig","addToRelatedRecords","graph","op","isRemote","record","value","index","relationship","get","field","_isBelongsTo","remoteState","newOp","WarpDrive","env","DEBUG","test","Error","lid","type","definition","kind","isDirty","localState","Array","isArray","i","length","addRelatedRecord","undefined","inverseKey","_remove","isBelongsTo","isHasMany","notifyChange","replaceRelatedRecord","removeFromInverse","macroCondition","getGlobalConfig","removeFromRelatedRecords","graph","op","isRemote","record","value","relationship","get","field","_isBelongsTo","remoteState","newOp","WarpDrive","env","DEBUG","test","Error","lid","type","definition","kind","Array","isArray","i","length","removeRelatedRecord","index","undefined","inverseKey","isBelongsTo","isHasMany","notifyChange","_normalizeLink","macroCondition","getGlobalConfig","updateRelationshipOperation","graph","op","relationship","get","record","field","WarpDrive","env","DEBUG","test","Error","definition","identifier","isCollection","payload","value","hasRelationshipDataProperty","hasUpdatedLink","meta","data","undefined","Array","isArray","cache","store","cacheKeyManager","update","upgradeIdentifiers","upgradeIdentifier","links","originalLinks","related","relatedLink","currentLink","currentLinkHref","href","type","key","state","hasFailedLoadAttempt","relationshipIsEmpty","length","hasReceivedData","hasReceivedRemoteData","isStale","hasDematerializedInverse","isEmpty","isStaleTransaction","transactionRef","_transaction","relationshipTransactionId","graphTransactionId","arr","i","getOrSetGlobal","peekTransient","setTransient","rollbackRelationship","isLHS","upgradeDefinition","assertValidRelationshipPayload","checkIfNew","forAllRelatedIdentifiers","getStore","isBelongsTo","isHasMany","isImplicit","notifyChange","removeIdentifierCompletelyFromRelationship","createCollectionEdge","legacyGetCollectionRelationshipData","createImplicitEdge","createResourceEdge","legacyGetResourceRelationshipData","addToRelatedRecords","mergeIdentifier","removeFromRelatedRecords","replaceRelatedRecord","replaceRelatedRecords","updateRelationshipOperation","getGlobalConfig","macroCondition","Graphs","Map","Graph","constructor","store","_definitionCache","Object","create","_metaCache","_potentialPolymorphicTypes","identifiers","_realStore","_store","isDestroyed","_willSyncRemote","_willSyncLocal","_pushedUpdates","belongsTo","undefined","hasMany","deletions","_updatedRelationships","_transaction","_removing","silenceNotifications","has","resourceKey","propertyName","relationships","get","getDefinition","defs","type","meta","info","WarpDrive","env","DEBUG","test","Error","lhs_definition","rhs_definition","set","relationship","kind","getData","getRemoteData","registerPolymorphicType","type1","type2","typeCache","t1","t2","isReleasable","activeLogging","LOG_GRAPH","debug","globalThis","getWarpDriveRuntimeConfig","console","log","String","keys","i","length","definition","inverseIsAsync","unload","forEach","key","rel","destroyRelationship","_isDirty","field","localState","remoteState","hasAdditions","additions","size","hasRemovals","removals","isReordered","getChanged","changed","reordered","Set","data","hasChanged","rollback","push","remove","delete","op","record","addPending","_cbs","_run","_flushRemoteQueue","_schedule","update","isRemote","identifier","removeCompletelyFromInverse","_scheduleLocalSync","channel","pending","_flushLocalQueue","groupCollapsed","transactionRef","updates","flushPending","groupEnd","_addToTransaction","updated","destroy","_","isDestroying","clear","graph","ops","values","opList","flushPendingList","inverseKey","inverseIsImplicit","inverseIdentifer","notifyInverseOfDematerialization","state","isStale","clearRelationship","isAsync","inverseIdentifier","removeDematerializedInverse","hasReceivedData","isEmpty","remoteMembers","localInverse","hasDematerializedInverse","localMembers","cache","cacheForKind","cacheForType","inverseType","cacheForField","isDirty","j","member","localMember","getStore","Graph","Graphs","getGlobalConfig","macroCondition","isBelongsTo","isStore","maybeStore","_instanceCache","undefined","getWrapper","store","_storeWrapper","peekGraph","get","graphFor","wrapper","graph","set","_graph","WarpDrive","env","DEBUG","isDestroying","Error"],"sources":["../../src/graph/-private/coerce-id.ts","../../src/graph/-private/-utils.ts","../../src/graph/-private/-edge-definition.ts","../../src/graph/-private/debug/assert-polymorphic-type.ts","../../src/graph/-private/operations/replace-related-records.ts","../../src/graph/-private/operations/replace-related-record.ts","../../src/graph/-private/-diff.ts","../../src/graph/-private/-state.ts","../../src/graph/-private/edges/collection.ts","../../src/graph/-private/edges/implicit.ts","../../src/graph/-private/edges/resource.ts","../../src/graph/-private/operations/add-to-related-records.ts","../../src/graph/-private/operations/merge-identifier.ts","../../src/graph/-private/operations/remove-from-related-records.ts","../../src/graph/-private/normalize-link.ts","../../src/graph/-private/operations/update-relationship.ts","../../src/graph/-private/graph.ts","../../src/graph/-private.ts"],"sourcesContent":["import { deprecate } from '@ember/debug';\n\nimport { DEPRECATE_NON_STRICT_ID } from '@warp-drive/core/build-config/deprecations';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\n// Used by the store to normalize IDs entering the store. Despite the fact\n// that developers may provide IDs as numbers (e.g., `store.findRecord('person', 1)`),\n// it is important that internally we use strings, since IDs may be serialized\n// and lose type information. For example, Ember's router may put a record's\n// ID into the URL, and if we later try to deserialize that URL and find the\n// corresponding record, we will not know if it is a string or a number.\ntype Coercable = string | number | boolean | null | undefined | symbol;\n\nexport function coerceId(id: Coercable): string | null {\n if (DEPRECATE_NON_STRICT_ID) {\n let normalized: string | null;\n if (id === null || id === undefined || id === '') {\n normalized = null;\n } else {\n normalized = String(id);\n }\n\n deprecate(\n `The resource id '<${typeof id}> ${String(\n id\n )} ' is not normalized. Update your application code to use '${JSON.stringify(normalized)}' instead.`,\n normalized === id,\n {\n id: 'ember-data:deprecate-non-strict-id',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '4.13',\n enabled: '5.3',\n },\n }\n );\n\n return normalized;\n }\n\n assert(\n `Resource IDs must be a non-empty string or null. Received '${String(id)}'.`,\n id === null || (typeof id === 'string' && id.length > 0)\n );\n\n return id;\n}\n\nexport function ensureStringId(id: Coercable): string {\n let normalized: string | null = null;\n if (typeof id === 'string') {\n normalized = id.length > 0 ? id : null;\n } else if (typeof id === 'number' && !isNaN(id)) {\n normalized = String(id);\n }\n\n assert(`Expected id to be a string or number, received ${String(id)}`, normalized !== null);\n\n return normalized;\n}\n","import { warn } from '@ember/debug';\n\nimport { JSON_API_CACHE_VALIDATION_ERRORS } from '@warp-drive/core/build-config/canary-features';\nimport { LOG_GRAPH } from '@warp-drive/core/build-config/debugging';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport type { Store } from '../../store/-private.ts';\nimport type { NotificationChannel } from '../../store/-private/managers/notification-manager.ts';\nimport type { CacheCapabilitiesManager } from '../../types.ts';\nimport type { UpdateResourceRelationshipOperation } from '../../types/cache/operations.ts';\nimport type { UpdateRelationshipOperation } from '../../types/graph.ts';\nimport type { ResourceKey } from '../../types/identifier.ts';\nimport type { ResourceIdentifierObject } from '../../types/spec/json-api-raw.ts';\nimport type { UpgradedMeta } from './-edge-definition.ts';\nimport { coerceId } from './coerce-id.ts';\nimport type { CollectionEdge } from './edges/collection.ts';\nimport type { ImplicitEdge } from './edges/implicit.ts';\nimport type { ResourceEdge } from './edges/resource.ts';\nimport type { Graph, GraphEdge } from './graph.ts';\n\n/** Retrieves the private {@link Store} instance from a capabilities manager (or any object exposing `_store`). */\nexport function getStore(wrapper: CacheCapabilitiesManager | { _store: Store }): Store {\n assert(`expected a private _store property`, '_store' in wrapper);\n return wrapper._store;\n}\n\n/** Reads a value from a two-level keyed cache, without creating the first-level entry if it is missing. */\nexport function expandingGet<T>(cache: Record<string, Record<string, T>>, key1: string, key2: string): T | undefined {\n const mainCache = (cache[key1] = cache[key1] || Object.create(null));\n return mainCache[key2];\n}\n\n/** Writes a value into a two-level keyed cache, lazily creating the first-level entry if it does not yet exist. */\nexport function expandingSet<T>(cache: Record<string, Record<string, T>>, key1: string, key2: string, value: T): void {\n const mainCache = (cache[key1] = cache[key1] || Object.create(null));\n mainCache[key2] = value;\n}\n\n/**\n * Asserts (dev-only) that a relationship update operation's payload is well-formed for the\n * relationship's kind (`belongsTo` vs `hasMany`), warning or asserting on common payload mistakes\n * such as a missing `data` alongside `links`, or `data` of the wrong shape.\n */\nexport function assertValidRelationshipPayload(\n graph: Graph,\n op: UpdateRelationshipOperation | UpdateResourceRelationshipOperation\n): void {\n const relationship = graph.get(op.record, op.field);\n assert(`Cannot update an implicit relationship`, isHasMany(relationship) || isBelongsTo(relationship));\n const payload = op.value;\n const { definition, identifier, state } = relationship;\n const { type } = identifier;\n const { field } = op;\n const { isAsync, kind } = definition;\n\n if (payload.links) {\n // once JSON_API_CACHE_VALIDATION_ERRORS is active, this warning is instead\n // the responsibility of the new document validator (see validateResourceRelationships\n // in warp-drive-packages/json-api/src/-private/validator/1.1/7.2_resource-objects.ts)\n if (!JSON_API_CACHE_VALIDATION_ERRORS) {\n warn(\n `You pushed a record of type '${type}' with a relationship '${field}' configured as 'async: false'. You've included a link but no primary data, this may be an error in your payload. WarpDrive will treat this relationship as known-to-be-empty.`,\n isAsync || payload.data === null || !!payload.data || state.hasReceivedData,\n {\n id: 'ds.store.push-link-for-sync-relationship',\n }\n );\n }\n } else if (payload.data) {\n if (kind === 'belongsTo') {\n assert(\n `A ${type} record was pushed into the store with the value of ${field} being ${inspect(\n payload.data\n )}, but ${field} is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`,\n !Array.isArray(payload.data)\n );\n assertRelationshipData(getStore(graph.store), identifier, payload.data, definition);\n } else if (kind === 'hasMany') {\n assert(\n `A ${type} record was pushed into the store with the value of ${field} being '${inspect(\n payload.data\n )}', but ${field} is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.`,\n Array.isArray(payload.data)\n );\n if (Array.isArray(payload.data)) {\n for (let i = 0; i < payload.data.length; i++) {\n assertRelationshipData(getStore(graph.store), identifier, payload.data[i], definition);\n }\n }\n }\n }\n}\n\nfunction inspect(value: unknown) {\n const type = typeof value;\n if (value === null) {\n return 'null';\n }\n if (type !== 'object') {\n return type;\n }\n if (Array.isArray(value)) {\n return 'Array';\n }\n if (value instanceof Date) {\n return 'Date';\n }\n if (value instanceof RegExp) {\n return 'RegExp';\n }\n if (value instanceof Map) {\n return 'Map';\n }\n if (value instanceof Set) {\n return 'Set';\n }\n return 'object';\n}\n\n/** Returns whether the given resource is new, i.e. it has no `id` or is flagged as new by the cache. */\nexport function checkIfNew(store: Store, resourceKey: ResourceKey): boolean {\n if (!resourceKey.id) {\n return true;\n }\n return store.cache.isNew(resourceKey);\n}\n\n/** A type-guard returning whether the given edge is a `belongsTo` {@link ResourceEdge}. */\nexport function isBelongsTo(relationship: GraphEdge): relationship is ResourceEdge {\n return relationship.definition.kind === 'belongsTo';\n}\n\n/** A type-guard returning whether the given edge is an {@link ImplicitEdge}. */\nexport function isImplicit(relationship: GraphEdge): relationship is ImplicitEdge {\n return relationship.definition.isImplicit;\n}\n\n/** A type-guard returning whether the given edge is a `hasMany` {@link CollectionEdge}. */\nexport function isHasMany(relationship: GraphEdge): relationship is CollectionEdge {\n return relationship.definition.kind === 'hasMany';\n}\n\n/** Invokes `cb` for every resource identifier currently related through `rel`, covering both local and remote membership regardless of the edge's kind. */\nexport function forAllRelatedIdentifiers(rel: GraphEdge, cb: (resourceKey: ResourceKey) => void): void {\n if (isBelongsTo(rel)) {\n if (rel.remoteState) {\n cb(rel.remoteState);\n }\n if (rel.localState && rel.localState !== rel.remoteState) {\n cb(rel.localState);\n }\n } else if (isHasMany(rel)) {\n // TODO\n // rel.remoteMembers.forEach(cb);\n // might be simpler if performance is not a concern\n for (let i = 0; i < rel.remoteState.length; i++) {\n const inverseIdentifier = rel.remoteState[i];\n cb(inverseIdentifier);\n }\n rel.additions?.forEach(cb);\n } else {\n rel.localMembers.forEach(cb);\n rel.remoteMembers.forEach((inverseIdentifier) => {\n if (!rel.localMembers.has(inverseIdentifier)) {\n cb(inverseIdentifier);\n }\n });\n }\n}\n\n/**\n * Removes the given identifier from BOTH remote AND local state.\n *\n * This method is useful when either a deletion or a rollback on a new record\n * needs to entirely purge itself from an inverse relationship.\n */\nexport function removeIdentifierCompletelyFromRelationship(\n graph: Graph,\n relationship: GraphEdge,\n value: ResourceKey,\n silenceNotifications?: boolean\n): void {\n if (isBelongsTo(relationship)) {\n if (relationship.remoteState === value) {\n relationship.remoteState = null;\n }\n\n if (relationship.localState === value) {\n relationship.localState = null;\n // This allows dematerialized inverses to be rematerialized\n // we shouldn't be notifying here though, figure out where\n // a notification was missed elsewhere.\n if (!silenceNotifications) {\n notifyChange(graph, relationship);\n }\n }\n } else if (isHasMany(relationship)) {\n relationship.remoteMembers.delete(value);\n relationship.additions?.delete(value);\n const wasInRemovals = relationship.removals?.delete(value);\n\n const canonicalIndex = relationship.remoteState.indexOf(value);\n if (canonicalIndex !== -1) {\n relationship.remoteState.splice(canonicalIndex, 1);\n }\n\n if (!wasInRemovals) {\n const currentIndex = relationship.localState?.indexOf(value);\n if (currentIndex !== -1 && currentIndex !== undefined) {\n relationship.localState!.splice(currentIndex, 1);\n // This allows dematerialized inverses to be rematerialized\n // we shouldn't be notifying here though, figure out where\n // a notification was missed elsewhere.\n if (!silenceNotifications) {\n notifyChange(graph, relationship);\n }\n }\n }\n } else {\n relationship.remoteMembers.delete(value);\n relationship.localMembers.delete(value);\n }\n}\n\n/** Notifies the store that a relationship has changed, provided the relationship has been accessed and is not currently being removed. */\nexport function notifyChange(\n graph: Graph,\n relationship: CollectionEdge | ResourceEdge,\n channel?: NotificationChannel\n): void {\n if (!relationship.accessed) {\n return;\n }\n\n const resourceKey = relationship.identifier;\n const key = relationship.definition.key;\n\n if (resourceKey === graph._removing) {\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`Graph: ignoring relationship change for removed identifier ${String(resourceKey)} ${key}`);\n }\n return;\n }\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`Graph: notifying relationship change for ${String(resourceKey)} ${key}`);\n }\n\n graph.store.notifyChange(resourceKey, 'relationships', key, channel);\n}\n\n/**\n * Asserts (dev-only) that a pushed relationship data payload conforms to the JSON:API resource\n * identifier shape (correct `type`/`id`, correct array-ness for the relationship's kind) and\n * references a resource type known to the schema.\n */\nexport function assertRelationshipData(\n store: Store,\n resourceKey: ResourceKey,\n data: ResourceIdentifierObject,\n meta: UpgradedMeta\n): void {\n assert(\n `A ${resourceKey.type} record was pushed into the store with the value of ${meta.key} being '${JSON.stringify(\n data\n )}', but ${\n meta.key\n } is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`,\n !Array.isArray(data)\n );\n assert(\n `Encountered a relationship identifier without a type for the ${meta.kind} relationship '${meta.key}' on <${\n resourceKey.type\n }:${String(resourceKey.id)}>, expected an identifier with type '${meta.type}' but found\\n\\n'${JSON.stringify(\n data,\n null,\n 2\n )}'\\n\\nPlease check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,\n data === null || ('type' in data && typeof data.type === 'string' && data.type.length)\n );\n assert(\n `Encountered a relationship identifier without an id for the ${meta.kind} relationship '${meta.key}' on <${\n resourceKey.type\n }:${String(resourceKey.id)}>, expected an identifier but found\\n\\n'${JSON.stringify(\n data,\n null,\n 2\n )}'\\n\\nPlease check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,\n data === null || !!coerceId(data.id)\n );\n if (data?.type === meta.type) {\n assert(\n `Missing Schema: Encountered a relationship identifier { type: '${data.type}', id: '${String(\n data.id\n )}' } for the '${resourceKey.type}.${meta.key}' ${meta.kind} relationship on <${resourceKey.type}:${String(\n resourceKey.id\n )}>, but no schema exists for that type.`,\n store.schema.hasResource(data)\n );\n } else {\n assert(\n `Missing Schema: Encountered a relationship identifier with type '${data.type}' for the ${\n meta.kind\n } relationship '${meta.key}' on <${resourceKey.type}:${String(\n resourceKey.id\n )}>, Expected an identifier with type '${meta.type}'. No schema was found for '${data.type}'.`,\n data === null || !data.type || store.schema.hasResource(data)\n );\n }\n}\n","import { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport type { Store } from '../../index.ts';\nimport type { ResourceKey } from '../../types.ts';\nimport type {\n CollectionField,\n FieldSchema,\n LegacyBelongsToField,\n LegacyHasManyField,\n ResourceField,\n} from '../../types/schema/fields.ts';\nimport { expandingGet, expandingSet, getStore } from './-utils.ts';\nimport { assertInheritedSchema } from './debug/assert-polymorphic-type.ts';\nimport type { Graph } from './graph.ts';\n\nexport type EdgeCache = Record<string, Record<string, EdgeDefinition | null>>;\n\nexport type RelationshipField = LegacyBelongsToField | LegacyHasManyField | ResourceField | CollectionField;\nexport type RelationshipFieldKind = RelationshipField['kind'];\nexport type CollectionKind = 'hasMany' | 'collection';\nexport type ResourceKind = 'belongsTo' | 'resource';\nexport const RELATIONSHIP_KINDS: string[] = ['belongsTo', 'hasMany', 'resource', 'collection'];\n\nexport function isLegacyField(field: FieldSchema): field is LegacyBelongsToField | LegacyHasManyField {\n return field.kind === 'belongsTo' || field.kind === 'hasMany';\n}\n\nexport function isRelationshipField(field: FieldSchema): field is RelationshipField {\n return RELATIONSHIP_KINDS.includes(field.kind);\n}\n\nexport function temporaryConvertToLegacy(\n field: ResourceField | CollectionField\n): LegacyBelongsToField | LegacyHasManyField {\n return {\n kind: field.kind === 'resource' ? 'belongsTo' : 'hasMany',\n name: field.name,\n type: field.type,\n options: Object.assign({}, { async: false, inverse: null, resetOnRemoteUpdate: false as const }, field.options),\n };\n}\n\n/**\n *\n * Given RHS (Right Hand Side)\n *\n * ```ts\n * class User extends Model {\n * @hasMany('animal', { async: false, inverse: 'owner' }) pets;\n * }\n * ```\n *\n * Given LHS (Left Hand Side)\n *\n * ```ts\n * class Animal extends Model {\n * @belongsTo('user', { async: false, inverse: 'pets' }) owner;\n * }\n * ```\n *\n * The UpgradedMeta for the RHS would be:\n *\n * ```ts\n * {\n * kind: 'hasMany',\n * key: 'pets',\n * type: 'animal',\n * isAsync: false,\n * isImplicit: false,\n * isCollection: true,\n * isPolymorphic: false,\n * inverseKind: 'belongsTo',\n * inverseKey: 'owner',\n * inverseType: 'user',\n * inverseIsAsync: false,\n * inverseIsImplicit: false,\n * inverseIsCollection: false,\n * inverseIsPolymorphic: false,\n * }\n * ```\n *\n * The UpgradeMeta for the LHS would be:\n *\n * ```ts\n * {\n * kind: 'belongsTo',\n * key: 'owner',\n * type: 'user',\n * isAsync: false,\n * isImplicit: false,\n * isCollection: false,\n * isPolymorphic: false,\n * inverseKind: 'hasMany',\n * inverseKey: 'pets',\n * inverseType: 'animal',\n * inverseIsAsync: false,\n * inverseIsImplicit: false,\n * inverseIsCollection: true,\n * inverseIsPolymorphic: false,\n * }\n * ```\n *\n * @private\n */\nexport interface UpgradedMeta {\n kind: 'implicit' | RelationshipFieldKind;\n /**\n * The field sourceKey on `this` record,\n * name if sourceKey is not set.\n */\n key: string;\n /**\n * The field name on `this` record\n */\n name: string;\n /**\n * The `type` of the related record\n *\n */\n type: string;\n isAsync: boolean;\n isImplicit: boolean;\n isCollection: boolean;\n isPolymorphic: boolean;\n resetOnRemoteUpdate: boolean;\n isLinksMode: boolean;\n\n inverseKind: 'implicit' | RelationshipFieldKind;\n /**\n * The field sourceKey on the opposing record,\n * name if sourceKey is not set.\n */\n inverseKey: string;\n /**\n * The field name on the opposing record,\n */\n inverseName: string;\n /**\n * The `type` of `this` record\n */\n inverseType: string;\n inverseIsAsync: boolean;\n inverseIsImplicit: boolean;\n inverseIsCollection: boolean;\n inverseIsPolymorphic: boolean;\n inverseIsLinksMode: boolean;\n}\n\nexport interface EdgeDefinition {\n lhs_key: string;\n lhs_modelNames: string[];\n lhs_baseModelName: string;\n lhs_relationshipName: string;\n lhs_definition: UpgradedMeta;\n lhs_isPolymorphic: boolean;\n\n rhs_key: string;\n rhs_modelNames: string[];\n rhs_baseModelName: string;\n rhs_relationshipName: string;\n rhs_definition: UpgradedMeta | null;\n rhs_isPolymorphic: boolean;\n\n hasInverse: boolean;\n\n /**\n * Whether this relationship points back at the same type.\n *\n * If the relationship is polymorphic, this will be true if\n * it points back at the same abstract type.\n *\n */\n isSelfReferential: boolean;\n\n /**\n * If this is a reflexive relationship, this is true\n * if the relationship also points back at the same\n * field.\n *\n */\n isReflexive: boolean;\n}\n\nconst BOOL_LATER = null as unknown as boolean;\nconst STR_LATER = '';\nconst IMPLICIT_KEY_RAND = Date.now();\n\nfunction implicitKeyFor(type: string, key: string): string {\n return `implicit-${type}:${key}${IMPLICIT_KEY_RAND}`;\n}\n\nfunction syncMeta(definition: UpgradedMeta, inverseDefinition: UpgradedMeta) {\n definition.inverseKind = inverseDefinition.kind;\n definition.inverseKey = inverseDefinition.key;\n definition.inverseName = inverseDefinition.name;\n definition.inverseType = inverseDefinition.type;\n definition.inverseIsAsync = inverseDefinition.isAsync;\n definition.inverseIsCollection = inverseDefinition.isCollection;\n definition.inverseIsPolymorphic = inverseDefinition.isPolymorphic;\n definition.inverseIsImplicit = inverseDefinition.isImplicit;\n definition.inverseIsLinksMode = inverseDefinition.isLinksMode;\n const resetOnRemoteUpdate =\n definition.resetOnRemoteUpdate === false || inverseDefinition.resetOnRemoteUpdate === false ? false : true;\n definition.resetOnRemoteUpdate = resetOnRemoteUpdate;\n inverseDefinition.resetOnRemoteUpdate = resetOnRemoteUpdate;\n}\n\nfunction upgradeMeta(meta: RelationshipField): UpgradedMeta {\n if (!isLegacyField(meta)) {\n meta = temporaryConvertToLegacy(meta);\n }\n const niceMeta: UpgradedMeta = {} as UpgradedMeta;\n const options = meta.options;\n niceMeta.kind = meta.kind;\n niceMeta.key = meta.sourceKey ?? meta.name;\n niceMeta.name = meta.name;\n niceMeta.type = meta.type;\n assert(`Expected relationship definition to specify async`, typeof options?.async === 'boolean');\n niceMeta.isAsync = options.async;\n niceMeta.isImplicit = false;\n niceMeta.isCollection = meta.kind === 'hasMany';\n niceMeta.isPolymorphic = options && !!options.polymorphic;\n niceMeta.isLinksMode = options.linksMode ?? false;\n\n niceMeta.inverseKey = (options && options.inverse) || STR_LATER;\n niceMeta.inverseName = (options && options.inverse) || STR_LATER;\n niceMeta.inverseType = STR_LATER;\n niceMeta.inverseIsAsync = BOOL_LATER;\n niceMeta.inverseIsImplicit = (options && options.inverse === null) || BOOL_LATER;\n niceMeta.inverseIsCollection = BOOL_LATER;\n niceMeta.inverseIsLinksMode = BOOL_LATER;\n\n // prettier-ignore\n niceMeta.resetOnRemoteUpdate = !isLegacyField(meta) ? false\n : meta.options?.linksMode ? false\n : meta.options?.resetOnRemoteUpdate === false ? false\n : true;\n\n return niceMeta;\n}\n\nfunction assertConfiguration(info: EdgeDefinition, type: string, key: string) {\n if (DEBUG) {\n const isSelfReferential = info.isSelfReferential;\n\n if (isSelfReferential) {\n return true;\n }\n\n const _isRHS =\n key === info.rhs_relationshipName &&\n (type === info.rhs_baseModelName || // base or non-polymorphic\n // if the other side is polymorphic then we need to scan our modelNames\n (info.lhs_isPolymorphic && info.rhs_modelNames.includes(type))); // polymorphic\n const _isLHS =\n key === info.lhs_relationshipName &&\n (type === info.lhs_baseModelName || // base or non-polymorphic\n // if the other side is polymorphic then we need to scan our modelNames\n (info.rhs_isPolymorphic && info.lhs_modelNames.includes(type))); // polymorphic;\n\n if (!_isRHS && !_isLHS) {\n /*\n this occurs when we are likely polymorphic but not configured to be polymorphic\n most often due to extending a class that has a relationship definition on it.\n\n e.g.\n\n ```ts\n class Pet extends Model {\n @belongsTo('human', { async: false, inverse: 'pet' }) owner;\n }\n class Human extends Model {\n @belongsTo('pet', { async: false, inverse: 'owner' }) pet;\n }\n class Farmer extends Human {}\n ```\n\n In the above case, the following would trigger this error:\n\n ```ts\n let pet = store.createRecord('pet');\n let farmer = store.createRecord('farmer');\n farmer.pet = pet; // error\n ```\n\n The correct way to fix this is to specify the polymorphic option on Pet\n and to specify the abstract type 'human' on the Human base class.\n\n ```ts\n class Pet extends Model {\n @belongsTo('human', { async: false, inverse: 'pet', polymorphic: true }) owner;\n }\n class Human extends Model {\n @belongsTo('pet', { async: false, inverse: 'owner', as: 'human' }) pet;\n }\n class Farmer extends Human {}\n ```\n\n Alternatively both Human and Farmer could declare the relationship, because relationship\n definitions are \"structural\".\n\n ```ts\n class Pet extends Model {\n @belongsTo('human', { async: false, inverse: 'pet', polymorphic: true }) owner;\n }\n class Human extends Model {\n @belongsTo('pet', { async: false, inverse: 'owner', as: 'human' }) pet;\n }\n class Farmer extends Model {\n @belongsTo('pet', { async: false, inverse: 'owner', as: 'human' }) pet;\n }\n ```\n\n */\n if (key === info.lhs_relationshipName && info.lhs_modelNames.includes(type)) {\n // parentIdentifier, parentDefinition, addedIdentifier, store\n assertInheritedSchema(info.lhs_definition, type);\n } else if (key === info.rhs_relationshipName && info.rhs_modelNames.includes(type)) {\n assertInheritedSchema(info.lhs_definition, type);\n }\n // OPEN AN ISSUE :: we would like to improve our errors but need to understand what corner case got us here\n throw new Error(\n `PLEASE OPEN AN ISSUE :: Found a relationship that is neither the LHS nor RHS of the same edge. This is not supported. Please report this to the WarpDrive team.`\n );\n }\n\n if (_isRHS && _isLHS) {\n // not sure how we get here but it's probably the result of some form of inheritance\n // without having specified polymorphism correctly leading to it not being self-referential\n // OPEN AN ISSUE :: we would like to improve our errors but need to understand what corner case got us here\n throw new Error(\n `PLEASE OPEN AN ISSUE :: Found a relationship that is both the LHS and RHS of the same edge but is not self-referential. This is not supported. Please report this to the WarpDrive team.`\n );\n }\n }\n}\n\nexport function isLHS(info: EdgeDefinition, type: string, key: string): boolean {\n const isSelfReferential = info.isSelfReferential;\n const isRelationship = key === info.lhs_relationshipName;\n\n if (DEBUG) {\n assertConfiguration(info, type, key);\n }\n\n if (isRelationship === true) {\n return (\n isSelfReferential === true || // itself\n type === info.lhs_baseModelName || // base or non-polymorphic\n // if the other side is polymorphic then we need to scan our modelNames\n (info.rhs_isPolymorphic && info.lhs_modelNames.includes(type)) // polymorphic\n );\n }\n\n return false;\n}\n\nexport function isRHS(info: EdgeDefinition, type: string, key: string): boolean {\n const isSelfReferential = info.isSelfReferential;\n const isRelationship = key === info.rhs_relationshipName;\n\n if (DEBUG) {\n assertConfiguration(info, type, key);\n }\n\n if (isRelationship === true) {\n return (\n isSelfReferential === true || // itself\n type === info.rhs_baseModelName || // base or non-polymorphic\n // if the other side is polymorphic then we need to scan our modelNames\n (info.lhs_isPolymorphic && info.rhs_modelNames.includes(type)) // polymorphic\n );\n }\n\n return false;\n}\n\nexport function upgradeDefinition(\n graph: Graph,\n key: ResourceKey,\n propertyName: string,\n isImplicit = false\n): EdgeDefinition | null {\n const cache = graph._definitionCache;\n const storeWrapper = graph.store;\n const polymorphicLookup = graph._potentialPolymorphicTypes;\n\n const { type } = key;\n let cached = /*#__NOINLINE__*/ expandingGet<EdgeDefinition | null>(cache, type, propertyName);\n\n // CASE: We have a cached resolution (null if no relationship exists)\n if (cached !== undefined) {\n return cached;\n }\n\n assert(\n `Expected to find relationship definition in the cache for the implicit relationship ${propertyName}`,\n !isImplicit\n );\n\n const relationships = storeWrapper.schema.fields(key);\n const relationshipsBySourceKey = storeWrapper.schema.cacheFields?.(key) ?? relationships;\n assert(`Expected to have a relationship definition for ${type} but none was found.`, relationships);\n const meta = relationshipsBySourceKey.get(propertyName);\n\n if (!meta) {\n // TODO potentially we should just be permissive here since this is an implicit relationship\n // and not require the lookup table to be populated\n if (polymorphicLookup[type]) {\n const altTypes = Object.keys(polymorphicLookup[type]);\n for (let i = 0; i < altTypes.length; i++) {\n const _cached = expandingGet<EdgeDefinition | null>(cache, altTypes[i], propertyName);\n if (_cached) {\n /*#__NOINLINE__*/ expandingSet<EdgeDefinition | null>(cache, type, propertyName, _cached);\n _cached.rhs_modelNames.push(type);\n return _cached;\n }\n }\n }\n\n // CASE: We don't have a relationship at all\n // we should only hit this in prod\n assert(`Expected a relationship schema for '${type}.${propertyName}', but no relationship schema was found.`, meta);\n\n cache[type][propertyName] = null;\n return null;\n }\n\n assert(`Expected ${propertyName} to be a relationship`, isRelationshipField(meta));\n const definition = /*#__NOINLINE__*/ upgradeMeta(meta);\n\n let inverseDefinition: UpgradedMeta | null;\n let inverseKey: string | null;\n const inverseType = definition.type;\n\n // CASE: Inverse is explicitly null\n if (definition.inverseKey === null) {\n // TODO probably dont need this assertion if polymorphic\n assert(`Expected the inverse model to exist`, storeWrapper.schema.hasResource({ type: inverseType }));\n inverseDefinition = null;\n } else {\n inverseKey = /*#__NOINLINE__*/ inverseForRelationship(getStore(storeWrapper), key, propertyName);\n\n // CASE: If we are polymorphic, and we declared an inverse that is non-null\n // we must assume that the lack of inverseKey means that there is no\n // concrete type as the baseType, so we must construct and artificial\n // placeholder\n if (!inverseKey && definition.isPolymorphic && definition.inverseKey) {\n inverseDefinition = {\n kind: 'belongsTo', // this must be updated when we find the first belongsTo or hasMany definition that matches\n key: definition.inverseKey,\n name: definition.inverseName,\n type: type,\n isAsync: false, // this must be updated when we find the first belongsTo or hasMany definition that matches\n isImplicit: false,\n isCollection: false, // this must be updated when we find the first belongsTo or hasMany definition that matches\n isPolymorphic: false,\n } as UpgradedMeta; // the rest of the fields are populated by syncMeta\n\n // CASE: Inverse resolves to null\n } else if (!inverseKey) {\n inverseDefinition = null;\n } else {\n // CASE: We have an explicit inverse or were able to resolve one\n // for the inverse we use \"name\" for lookup not \"sourceKey\"\n const inverseDefinitions = storeWrapper.schema.fields({ type: inverseType });\n assert(`Expected to have a relationship definition for ${inverseType} but none was found.`, inverseDefinitions);\n const metaFromInverse = inverseDefinitions.get(inverseKey);\n assert(\n `Expected a relationship schema for '${inverseType}.${inverseKey}' to match the inverse of '${type}.${propertyName}', but no relationship schema was found.`,\n metaFromInverse\n );\n assert(`Expected ${inverseKey} to be a relationship`, isRelationshipField(metaFromInverse));\n\n inverseDefinition = upgradeMeta(metaFromInverse);\n }\n }\n\n // CASE: We have no inverse\n if (!inverseDefinition) {\n // polish off meta\n inverseKey = /*#__NOINLINE__*/ implicitKeyFor(type, propertyName);\n inverseDefinition = {\n kind: 'implicit',\n key: inverseKey,\n type: type,\n isAsync: false,\n isImplicit: true,\n isCollection: true, // with implicits any number of records could point at us\n isPolymorphic: false,\n } as UpgradedMeta; // the rest of the fields are populated by syncMeta\n\n syncMeta(definition, inverseDefinition);\n syncMeta(inverseDefinition, definition);\n\n const info = {\n lhs_key: `${type}:${propertyName}`,\n lhs_modelNames: [type],\n lhs_baseModelName: type,\n lhs_relationshipName: propertyName,\n lhs_definition: definition,\n lhs_isPolymorphic: definition.isPolymorphic,\n\n rhs_key: inverseDefinition.key,\n rhs_modelNames: [inverseType],\n rhs_baseModelName: inverseType,\n rhs_relationshipName: inverseDefinition.key,\n rhs_definition: inverseDefinition,\n rhs_isPolymorphic: false,\n\n hasInverse: false,\n isSelfReferential: type === inverseType, // this could be wrong if we are self-referential but also polymorphic\n isReflexive: false, // we can't be reflexive if we don't define an inverse\n };\n\n expandingSet<EdgeDefinition | null>(cache, inverseType, inverseKey, info);\n expandingSet<EdgeDefinition | null>(cache, type, propertyName, info);\n return info;\n }\n\n // CASE: We do have an inverse\n const baseType = inverseDefinition.type;\n\n // TODO we want to assert this but this breaks all of our shoddily written tests\n /*\n if (DEBUG) {\n let inverseDoubleCheck = inverseFor(inverseRelationshipName, store);\n\n assert(`The ${inverseBaseModelName}:${inverseRelationshipName} relationship declares 'inverse: null', but it was resolved as the inverse for ${baseModelName}:${relationshipName}.`, inverseDoubleCheck);\n }\n */\n // CASE: We may have already discovered the inverse for the baseModelName\n // CASE: We have already discovered the inverse\n assert(\n `We should have determined an inverseKey by now, open an issue if this is hit`,\n typeof inverseKey! === 'string' && inverseKey.length > 0\n );\n cached = expandingGet(cache, baseType, propertyName) || expandingGet(cache, inverseType, inverseKey);\n\n if (cached) {\n // TODO this assert can be removed if the above assert is enabled\n assert(\n `The ${inverseType}:${inverseKey} relationship declares 'inverse: null', but it was resolved as the inverse for ${type}:${propertyName}.`,\n cached.hasInverse !== false\n );\n\n const _isLHS = cached.lhs_baseModelName === baseType;\n const claimedRelationshipName = _isLHS ? cached.lhs_relationshipName : cached.rhs_relationshipName;\n\n // CASE: We already resolved an edge that terminates at this same inverse field, but it\n // was claimed by a different relationship than the one we're currently resolving. This\n // means two distinct fields both declared the same explicit `inverse`, which a single\n // foreign key cannot satisfy for both.\n //\n // For self-referential relationships both sides of `cached` share the same base model\n // type, so `_isLHS` above cannot tell us which side corresponds to `propertyName`: we\n // must accept a match against *either* side before concluding this is a real conflict.\n const isKnownSide =\n (cached.lhs_baseModelName === baseType && cached.lhs_relationshipName === propertyName) ||\n (cached.rhs_baseModelName === baseType && cached.rhs_relationshipName === propertyName);\n assert(\n `Both '${baseType}.${claimedRelationshipName}' and '${baseType}.${propertyName}' declare 'inverse: ${JSON.stringify(inverseKey)}', but '${inverseType}.${inverseKey}' can only be the inverse of one relationship. Update these relationships so that only one declares 'inverse: ${JSON.stringify(inverseKey)}' (the others should use a different inverse or 'inverse: null'), or introduce an intermediate/join model if multiple relationships legitimately need to reference '${inverseType}.${inverseKey}'.`,\n isKnownSide\n );\n\n const modelNames = _isLHS ? cached.lhs_modelNames : cached.rhs_modelNames;\n // make this lookup easier in the future by caching the key\n modelNames.push(type);\n expandingSet<EdgeDefinition | null>(cache, type, propertyName, cached);\n\n return cached;\n }\n\n // this is our first time so polish off the metas\n syncMeta(definition, inverseDefinition);\n syncMeta(inverseDefinition, definition);\n\n const lhs_modelNames = [type];\n if (type !== baseType) {\n lhs_modelNames.push(baseType);\n }\n const isSelfReferential = baseType === inverseType;\n const info = {\n lhs_key: `${baseType}:${propertyName}`,\n lhs_modelNames,\n lhs_baseModelName: baseType,\n lhs_relationshipName: propertyName,\n lhs_definition: definition,\n lhs_isPolymorphic: definition.isPolymorphic,\n\n rhs_key: `${inverseType}:${inverseKey}`,\n rhs_modelNames: [inverseType],\n rhs_baseModelName: inverseType,\n rhs_relationshipName: inverseKey,\n rhs_definition: inverseDefinition,\n rhs_isPolymorphic: inverseDefinition.isPolymorphic,\n hasInverse: true,\n isSelfReferential,\n isReflexive: isSelfReferential && propertyName === inverseKey,\n };\n\n // Create entries for the baseModelName as well as modelName to speed up\n // inverse lookups\n expandingSet<EdgeDefinition | null>(cache, baseType, propertyName, info);\n expandingSet<EdgeDefinition | null>(cache, type, propertyName, info);\n\n // Greedily populate the inverse\n expandingSet<EdgeDefinition | null>(cache, inverseType, inverseKey, info);\n\n return info;\n}\n\nfunction inverseForRelationship(store: Store, resourceKey: ResourceKey | { type: string }, key: string) {\n const fields = store.schema.fields(resourceKey);\n const definition = fields.get(key);\n if (!definition) {\n return null;\n }\n\n assert(`Expected ${key} to be a relationship`, isRelationshipField(definition));\n assert(\n `Expected the relationship defintion to specify the inverse type or null.`,\n definition.options?.inverse === null ||\n (typeof definition.options?.inverse === 'string' && definition.options.inverse.length > 0)\n );\n return definition.options.inverse;\n}\n","/* oxlint-disable no-shadow */\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport {\n isLegacyField,\n isRelationshipField,\n temporaryConvertToLegacy,\n type UpgradedMeta,\n} from '../-edge-definition.ts';\nimport type { CacheCapabilitiesManager } from '../../../types.ts';\nimport type { ResourceKey } from '../../../types/identifier.ts';\n\n/*\n Assert that `addedRecord` has a valid type so it can be added to the\n relationship of the `record`.\n\n The assert basically checks if the `addedRecord` can be added to the\n relationship (specified via `relationshipMeta`) of the `record`.\n\n This utility should only be used internally, as both record parameters must\n be ResourceKeys and the `relationshipMeta` needs to be the meta\n information about the relationship, retrieved via\n `record.relationshipFor(key)`.\n*/\nlet assertPolymorphicType: (\n parentIdentifier: ResourceKey,\n parentDefinition: UpgradedMeta,\n addedIdentifier: ResourceKey,\n store: CacheCapabilitiesManager\n) => void;\nlet assertInheritedSchema: (definition: UpgradedMeta, type: string) => void;\n\nif (DEBUG) {\n function validateSchema(definition: UpgradedMeta, meta: PrintConfig) {\n const errors = new Map();\n\n if (definition.inverseKey !== meta.name) {\n errors.set('name', ` <---- should be '${definition.inverseKey}'`);\n }\n if (definition.inverseType !== meta.type) {\n errors.set('type', ` <---- should be '${definition.inverseType}'`);\n }\n if (definition.inverseKind !== meta.kind) {\n errors.set('kind', ` <---- should be '${definition.inverseKind}'`);\n }\n if (definition.inverseIsAsync !== meta.options.async) {\n errors.set('async', ` <---- should be ${definition.inverseIsAsync}`);\n }\n if (definition.inverseIsPolymorphic && definition.inverseIsPolymorphic !== meta.options.polymorphic) {\n errors.set('polymorphic', ` <---- should be ${definition.inverseIsPolymorphic}`);\n }\n if (definition.key !== meta.options.inverse) {\n errors.set('inverse', ` <---- should be '${definition.key}'`);\n }\n // `as` is only meaningful when `definition` itself is polymorphic (i.e. it\n // points at an abstract type that `meta` is expected to implement). When\n // `definition` isn't polymorphic, there's no abstract type for `meta` to\n // declare `as` against, so `meta.options.as` is correctly absent - that's\n // not an error to report.\n if (definition.isPolymorphic && definition.type !== meta.options.as) {\n errors.set('as', ` <---- should be '${definition.type}'`);\n }\n\n return errors;\n }\n\n type PrintConfig = {\n name: string;\n type: string;\n kind: string;\n options: {\n as?: string;\n async: boolean;\n polymorphic?: boolean;\n inverse: string | null;\n };\n };\n type RelationshipSchemaError = 'name' | 'type' | 'kind' | 'as' | 'async' | 'polymorphic' | 'inverse';\n\n function expectedSchema(definition: UpgradedMeta) {\n return printSchema({\n name: definition.inverseKey,\n type: definition.inverseType,\n kind: definition.inverseKind,\n options: {\n as: definition.type,\n async: definition.inverseIsAsync,\n polymorphic: definition.inverseIsPolymorphic || false,\n inverse: definition.key,\n },\n });\n }\n\n function printSchema(config: PrintConfig, errors?: Map<RelationshipSchemaError, string>) {\n return `\n\n\\`\\`\\`\n{\n ${config.name}: {\n name: '${config.name}',${errors?.get('name') || ''}\n type: '${config.type}',${errors?.get('type') || ''}\n kind: '${config.kind}',${errors?.get('kind') || ''}\n options: {\n as: '${config.options.as}',${errors?.get('as') || ''}\n async: ${config.options.async},${errors?.get('async') || ''}\n polymorphic: ${config.options.polymorphic},${errors?.get('polymorphic') || ''}\n inverse: '${config.options.inverse}'${errors?.get('inverse') || ''}\n }\n }\n}\n\\`\\`\\`\n\n`;\n }\n\n function inverseMetaFrom(definition: UpgradedMeta) {\n return {\n name: definition.inverseKey,\n type: definition.inverseType,\n kind: definition.inverseKind,\n options: {\n as: definition.isPolymorphic ? definition.type : undefined,\n async: definition.inverseIsAsync,\n polymorphic: definition.inverseIsPolymorphic,\n inverse: definition.key,\n },\n };\n }\n function inverseDefinition(definition: UpgradedMeta): UpgradedMeta {\n return {\n key: definition.inverseKey,\n name: definition.inverseName,\n type: definition.inverseType,\n kind: definition.inverseKind,\n isAsync: definition.inverseIsAsync,\n isPolymorphic: true,\n isLinksMode: definition.isLinksMode,\n isCollection: definition.inverseIsCollection,\n isImplicit: definition.inverseIsImplicit,\n inverseKey: definition.key,\n inverseName: definition.name,\n inverseType: definition.type,\n inverseKind: definition.kind,\n inverseIsAsync: definition.isAsync,\n inverseIsPolymorphic: definition.isPolymorphic,\n inverseIsLinksMode: definition.inverseIsLinksMode,\n inverseIsImplicit: definition.isImplicit,\n inverseIsCollection: definition.isCollection,\n resetOnRemoteUpdate: definition.resetOnRemoteUpdate,\n };\n }\n function definitionWithPolymorphic(definition: UpgradedMeta) {\n return Object.assign({}, definition, { inverseIsPolymorphic: true });\n }\n\n assertInheritedSchema = function assertInheritedSchema(definition: UpgradedMeta, type: string) {\n // `definition` is the only source of truth we have here - there is no\n // second, independently-declared schema available to diff it against.\n // That means the only thing we can actually verify is internal: does\n // `definition`'s own resolved inverse agree that this relationship is\n // polymorphic? Every other field of `meta2` below (name/type/kind/async/\n // inverse) is derived directly from `definition` itself, so comparing\n // them back to `definition` can never disagree - only the polymorphic\n // flag is independently meaningful, because `definitionWithPolymorphic`\n // asserts what it *should* be rather than mirroring what it already is.\n const meta2 = inverseMetaFrom(definition);\n const errors2 = validateSchema(definitionWithPolymorphic(definition), meta2);\n\n if (errors2.size > 0) {\n throw new Error(\n `The schema for the relationship '${type}.${definition.key}' satisfies '${\n definition.inverseType\n }' but cannot utilize the '${definition.inverseType}.${definition.key}' relationship to connect with '${\n definition.type\n }.${\n definition.inverseKey\n }' because that relationship is not polymorphic.\\n\\nIf using this relationship in a polymorphic manner is desired, the relationships schema definition for '${\n definition.type\n }' should include:${printSchema(meta2, errors2)}`\n );\n }\n };\n\n assertPolymorphicType = function assertPolymorphicType(\n parentIdentifier: ResourceKey,\n parentDefinition: UpgradedMeta,\n addedIdentifier: ResourceKey,\n store: CacheCapabilitiesManager\n ) {\n if (parentDefinition.inverseIsImplicit) {\n return;\n }\n if (parentDefinition.isPolymorphic) {\n let meta = store.schema.fields(addedIdentifier).get(parentDefinition.inverseKey);\n assert(\n `No '${parentDefinition.inverseKey}' field exists on '${\n addedIdentifier.type\n }'. To use this type in the polymorphic relationship '${parentDefinition.inverseType}.${\n parentDefinition.key\n }' the relationships schema definition for ${addedIdentifier.type} should include:${expectedSchema(\n parentDefinition\n )}`,\n meta\n );\n assert(\n `Expected the field ${parentDefinition.inverseKey} to be a relationship`,\n meta && isRelationshipField(meta)\n );\n meta = isLegacyField(meta) ? meta : temporaryConvertToLegacy(meta);\n assert(\n `You should not specify both options.as and options.inverse as null on ${addedIdentifier.type}.${parentDefinition.inverseKey}, as if there is no inverse field there is no abstract type to conform to. You may have intended for this relationship to be polymorphic, or you may have mistakenly set inverse to null.`,\n !(meta.options.inverse === null && meta?.options.as?.length)\n );\n const errors = validateSchema(parentDefinition, meta);\n assert(\n `The schema for the relationship '${parentDefinition.inverseKey}' on '${\n addedIdentifier.type\n }' type does not correctly implement '${parentDefinition.type}' and thus cannot be assigned to the '${\n parentDefinition.key\n }' relationship in '${\n parentIdentifier.type\n }'. If using this record in this polymorphic relationship is desired, correct the errors in the schema shown below:${printSchema(\n meta,\n errors\n )}`,\n errors.size === 0\n );\n } else if (addedIdentifier.type !== parentDefinition.type) {\n // if we are not polymorphic\n // then the addedIdentifier.type must be the same as the parentDefinition.type\n let meta = store.schema.fields(addedIdentifier).get(parentDefinition.inverseKey);\n assert(\n `Expected the field ${parentDefinition.inverseKey} to be a relationship`,\n !meta || isRelationshipField(meta)\n );\n meta = meta && (isLegacyField(meta) ? meta : temporaryConvertToLegacy(meta));\n if (meta?.options.as === parentDefinition.type) {\n // inverse is likely polymorphic but missing the polymorphic flag\n let meta = store.schema.fields({ type: parentDefinition.inverseType }).get(parentDefinition.key);\n assert(`Expected the field ${parentDefinition.key} to be a relationship`, meta && isRelationshipField(meta));\n meta = isLegacyField(meta) ? meta : temporaryConvertToLegacy(meta);\n const errors = validateSchema(definitionWithPolymorphic(inverseDefinition(parentDefinition)), meta);\n assert(\n `The '<${addedIdentifier.type}>.${\n parentDefinition.inverseKey\n }' relationship cannot be used polymorphically because '<${parentDefinition.inverseType}>.${\n parentDefinition.key\n } is not a polymorphic relationship. To use this relationship in a polymorphic manner, fix the following schema issues on the relationships schema for '${\n parentDefinition.inverseType\n }':${printSchema(meta, errors)}`\n );\n } else {\n assert(\n `The '${addedIdentifier.type}' type does not implement '${parentDefinition.type}' and thus cannot be assigned to the '${parentDefinition.key}' relationship in '${parentIdentifier.type}'. If this relationship should be polymorphic, mark ${parentDefinition.inverseType}.${parentDefinition.key} as \\`polymorphic: true\\` and ${addedIdentifier.type}.${parentDefinition.inverseKey} as implementing it via \\`as: '${parentDefinition.type}'\\`.`\n );\n }\n }\n };\n}\n\nexport { assertPolymorphicType, assertInheritedSchema };\n","import { deprecate } from '@ember/debug';\n\nimport { DEBUG_RELATIONSHIP_NOTIFICATIONS, LOG_METRIC_COUNTS } from '@warp-drive/core/build-config/debugging';\nimport { DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE } from '@warp-drive/core/build-config/deprecations';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport { _add, _removeLocal, _removeRemote, diffCollection } from '../-diff.ts';\nimport { checkIfNew, isBelongsTo, isHasMany, notifyChange } from '../-utils.ts';\nimport type { NotificationChannel } from '../../../store/-private/managers/notification-manager.ts';\nimport type { ResourceKey } from '../../../types.ts';\nimport type { ReplaceRelatedRecordsOperation } from '../../../types/graph.ts';\nimport { assertPolymorphicType } from '../debug/assert-polymorphic-type.ts';\nimport type { CollectionEdge } from '../edges/collection.ts';\nimport type { Graph } from '../graph.ts';\n\nfunction count(label: string) {\n // @ts-expect-error\n // oxlint-disable-next-line\n globalThis.__WarpDriveMetricCountData[label] = (globalThis.__WarpDriveMetricCountData[label] || 0) + 1;\n}\n\n/*\n case many:1\n ========\n In a bi-directional graph with Many:1 edges, adding a value\n results in up-to 3 discrete value transitions, while removing\n a value is only 2 transitions.\n\n For adding C to A\n If: A <<-> B, C <->> D is the initial state,\n and: B <->> A <<-> C, D is the final state\n\n then we would undergo the following transitions.\n\n add C to A\n remove C from D\n add A to C\n\n For removing B from A\n If: A <<-> B, C <->> D is the initial state,\n and: A, B, C <->> D is the final state\n\n then we would undergo the following transitions.\n\n remove B from A\n remove A from B\n\n case many:many\n ===========\n In a bi-directional graph with Many:Many edges, adding or\n removing a value requires only 2 value transitions.\n\n For Adding\n If: A<<->>B, C<<->>D is the initial state (double arrows representing the many side)\n And: D<<->>C<<->>A<<->>B is the final state\n\n Then we would undergo two transitions.\n\n add C to A.\n add A to C\n\n For Removing\n If: A<<->>B, C<<->>D is the initial state (double arrows representing the many side)\n And: A, B, C<<->>D is the final state\n\n Then we would undergo two transitions.\n\n remove B from A\n remove A from B\n\n case many:?\n ========\n In a uni-directional graph with Many:? edges (modeled in WarpDrive with `inverse:null`) with\n artificial (implicit) inverses, replacing a value results in 2 discrete value transitions.\n This is because a Many:? relationship is effectively Many:Many.\n */\nexport default function replaceRelatedRecords(\n graph: Graph,\n op: ReplaceRelatedRecordsOperation,\n isRemote: boolean\n): void {\n if (isRemote) {\n replaceRelatedRecordsRemote(graph, op, isRemote);\n } else {\n replaceRelatedRecordsLocal(graph, op, isRemote);\n }\n}\n\nfunction replaceRelatedRecordsLocal(graph: Graph, op: ReplaceRelatedRecordsOperation, isRemote: boolean) {\n const resourceKeys = op.value;\n const relationship = graph.get(op.record, op.field);\n assert(`expected hasMany relationship`, isHasMany(relationship));\n\n relationship.state.hasReceivedData = true;\n const { additions, removals } = relationship;\n const { inverseKey, type } = relationship.definition;\n const { record } = op;\n const wasDirty = relationship.isDirty;\n let localBecameDirty = false;\n\n if (LOG_METRIC_COUNTS) {\n count(`replaceRelatedRecordsLocal ${'type' in record ? record.type : '<document>'} ${op.field}`);\n }\n\n const onAdd = (resourceKey: ResourceKey) => {\n // Since we are diffing against the remote state, we check\n // if our previous local state did not contain this ResourceKey\n const removalsHas = removals?.has(resourceKey);\n if (removalsHas || !additions?.has(resourceKey)) {\n if (type !== resourceKey.type) {\n if (DEBUG) {\n assertPolymorphicType(relationship.identifier, relationship.definition, resourceKey, graph.store);\n }\n graph.registerPolymorphicType(type, resourceKey.type);\n }\n\n // we've added a record locally that wasn't in the local state before\n localBecameDirty = true;\n addToInverse(graph, resourceKey, inverseKey, op.record, isRemote);\n\n if (removalsHas) {\n removals!.delete(resourceKey);\n }\n }\n };\n\n const onRemove = (resourceKey: ResourceKey) => {\n // Since we are diffing against the remote state, we check\n // if our previous local state had contained this ResourceKey\n const additionsHas = additions?.has(resourceKey);\n if (additionsHas || !removals?.has(resourceKey)) {\n // we've removed a record locally that was in the local state before\n localBecameDirty = true;\n removeFromInverse(graph, resourceKey, inverseKey, record, isRemote);\n\n if (additionsHas) {\n additions!.delete(resourceKey);\n }\n }\n };\n\n const diff = diffCollection(resourceKeys, relationship, onAdd, onRemove);\n\n // any additions no longer in the local state\n // also need to be removed from the inverse\n if (additions && additions.size > 0) {\n additions.forEach((resourceKey) => {\n if (!diff.add.has(resourceKey)) {\n localBecameDirty = true;\n onRemove(resourceKey);\n }\n });\n }\n\n // any removals no longer in the local state\n // also need to be added back to the inverse\n if (removals && removals.size > 0) {\n removals.forEach((resourceKey) => {\n if (!diff.del.has(resourceKey)) {\n localBecameDirty = true;\n onAdd(resourceKey);\n }\n });\n }\n\n const becameDirty = diff.changed || localBecameDirty;\n relationship.additions = diff.add;\n relationship.removals = diff.del;\n relationship.localState = diff.finalState;\n\n // we only notify if the localState changed and were not already dirty before\n // because if we were already dirty then we have already notified\n if (becameDirty && !wasDirty) {\n // this is a purely local mutation -- nothing about remote state changed,\n // so a remote-only reader has nothing to see here and shouldn't be woken.\n notifyChange(graph, relationship, 'local');\n }\n}\n\nfunction replaceRelatedRecordsRemote(graph: Graph, op: ReplaceRelatedRecordsOperation, isRemote: boolean) {\n const resourceKeys = op.value;\n const relationship = graph.get(op.record, op.field);\n\n if (LOG_METRIC_COUNTS) {\n count(`replaceRelatedRecordsRemote ${'type' in op.record ? op.record.type : '<document>'} ${op.field}`);\n }\n\n assert(\n `You can only '${op.op}' on a hasMany relationship. ${op.record.type}.${op.field} is a ${relationship.definition.kind}`,\n isHasMany(relationship)\n );\n if (isRemote) {\n graph._addToTransaction(relationship);\n }\n\n const wasDirty = relationship.isDirty;\n // if this is our first time receiving data\n // we need to mark the relationship as dirty\n // so that non-materializing APIs like `hasManyReference.value()`\n // will get notified and updated.\n if (!relationship.state.hasReceivedData) {\n relationship.isDirty = true;\n }\n relationship.state.hasReceivedData = true;\n\n // cache existing state\n const { definition } = relationship;\n\n const { type } = relationship.definition;\n\n const diff = diffCollection(\n resourceKeys,\n relationship,\n (resourceKey) => {\n if (type !== resourceKey.type) {\n if (DEBUG) {\n assertPolymorphicType(relationship.identifier, relationship.definition, resourceKey, graph.store);\n }\n graph.registerPolymorphicType(type, resourceKey.type);\n }\n // commit additions\n // TODO build this into the diff?\n // because we are not dirty if this was a committed local addition\n if (relationship.additions?.has(resourceKey)) {\n relationship.additions.delete(resourceKey);\n } else {\n if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {\n if (!relationship.isDirty) {\n // oxlint-disable-next-line no-console\n console.log(\n `setting relationship to dirty because the remote addition was not in our previous list of local additions`\n );\n }\n }\n }\n addToInverse(graph, resourceKey, definition.inverseKey, op.record, isRemote);\n },\n (resourceKey) => {\n // commit removals\n // TODO build this into the diff?\n // because we are not dirty if this was a committed local addition\n if (relationship.removals?.has(resourceKey)) {\n relationship.removals.delete(resourceKey);\n } else {\n if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {\n if (!relationship.isDirty) {\n // oxlint-disable-next-line no-console\n console.log(\n `setting relationship to dirty because the remote removal was not in our previous list of local removals`\n );\n }\n }\n }\n removeFromInverse(graph, resourceKey, definition.inverseKey, op.record, isRemote);\n }\n );\n\n // replace existing state\n relationship.remoteMembers = diff.finalSet;\n relationship.remoteState = diff.finalState;\n\n // changed also indicates a change in order\n if (diff.changed) {\n relationship.isDirty = true;\n }\n\n // TODO unsure if we need this but it\n // may allow us to more efficiently patch\n // the associated ManyArray\n relationship._diff = diff;\n\n if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) {\n // only do this for legacy hasMany, not collection\n // and provide a way to incrementally migrate\n if (\n // we do not guard by diff.changed here\n // because we want to clear local changes even if\n // no change has occurred to preserve the legacy behavior\n relationship.definition.kind === 'hasMany' &&\n relationship.definition.resetOnRemoteUpdate !== false &&\n (diff.changed || wasDirty)\n ) {\n const deprecationInfo: {\n removals: ResourceKey[];\n additions: ResourceKey[];\n triggered: boolean;\n } = {\n removals: [],\n additions: [],\n triggered: false,\n };\n if (relationship.removals) {\n relationship.isDirty = true;\n relationship.removals.forEach((resourceKey) => {\n deprecationInfo.triggered = true;\n deprecationInfo.removals.push(resourceKey);\n // reverse the removal\n // if we are still in removals at this point then\n // we were not \"committed\" which means we are present\n // in the remoteMembers. So we \"add back\" on the inverse.\n addToInverse(graph, resourceKey, definition.inverseKey, op.record, false);\n });\n relationship.removals = null;\n }\n if (relationship.additions) {\n relationship.additions.forEach((resourceKey) => {\n // reverse the addition\n // if we are still in additions at this point then\n // we were not \"committed\" which means we are not present\n // in the remoteMembers. So we \"remove\" from the inverse.\n // however we only do this if we are not a \"new\" record.\n if (!checkIfNew(graph._realStore, resourceKey)) {\n deprecationInfo.triggered = true;\n deprecationInfo.additions.push(resourceKey);\n relationship.isDirty = true;\n relationship.additions!.delete(resourceKey);\n removeFromInverse(graph, resourceKey, definition.inverseKey, op.record, false);\n }\n });\n if (relationship.additions.size === 0) {\n relationship.additions = null;\n }\n }\n\n if (deprecationInfo.triggered) {\n deprecate(\n `WarpDrive is changing the default semantics of updates to the remote state of relationships.\\n\\nThe following local state was cleared from the <${\n relationship.identifier.type\n }>.${\n relationship.definition.key\n } hasMany relationship but will not be once this deprecation is resolved by opting into the new behavior:\\n\\n\\tAdded: [${deprecationInfo.additions\n .map((i) => i.lid)\n .join(', ')}]\\n\\tRemoved: [${deprecationInfo.removals.map((i) => i.lid).join(', ')}]`,\n false,\n {\n id: 'ember-data:deprecate-relationship-remote-update-clearing-local-state',\n for: 'ember-data',\n since: { enabled: '5.3', available: '4.13' },\n until: '6.0',\n url: 'https://deprecations.emberjs.com/v5.x#ember-data-deprecate-relationship-remote-update-clearing-local-state',\n }\n );\n }\n }\n }\n\n // A remote update is notified per projection, on that projection's channel\n // (see NotificationChannel's delivery matrix):\n //\n // - `diff.remoteOrderChanged` is exactly \"did remoteState's membership or\n // order change\". Remote-only readers (e.g. a non-editable `linksMode`\n // ManyArray) re-pull remote state when notified, so they are notified on\n // the `'remote'` channel whenever it changes - including a push that\n // merely confirms an already-committed local mutation, since the remote\n // projection genuinely changes there too.\n // - `diff.changed` is exactly \"did this remote update, once reconciled\n // against whatever local currently shows, produce an observably different\n // local materialization\" (it already accounts for the deprecated\n // `resetOnRemoteUpdate` reconciliation rules - see `_compare` in\n // -diff.ts). Local-view readers re-pull reconciled local state when\n // notified, so they are notified on the `'local'` channel; a push that\n // only confirms a committed local mutation leaves their view unchanged\n // and correctly stays silent for them.\n //\n // When both change, the two schedules coalesce into a single unscoped\n // notification (see `Graph._scheduleLocalSync`).\n //\n // Neither gate consults `relationship.isDirty` or `localState` freshness\n // beyond what the diff itself computed: the old `isDirty`-transition gate\n // (`relationship.isDirty && !wasDirty`) latched `true` forever for readers\n // that never run `computeLocalState`, and a single ungated/unscoped\n // `diff.changed` notify let a stale `localState` snapshot (never refreshed\n // by remote-only readers) suppress genuine remote changes - both caught by\n // `tests/json-api`'s \"update hasMany with repeated patch\".\n if (diff.remoteOrderChanged) {\n flushCanonical(graph, relationship, 'remote');\n }\n if (diff.changed) {\n flushCanonical(graph, relationship, 'local');\n }\n}\n\nexport function addToInverse(\n graph: Graph,\n resourceKey: ResourceKey,\n key: string,\n value: ResourceKey,\n isRemote: boolean\n): void {\n const relationship = graph.get(resourceKey, key);\n const { type } = relationship.definition;\n\n if (type !== value.type) {\n if (DEBUG) {\n assertPolymorphicType(relationship.identifier, relationship.definition, value, graph.store);\n }\n graph.registerPolymorphicType(type, value.type);\n }\n\n if (isBelongsTo(relationship)) {\n relationship.state.hasReceivedData = true;\n relationship.state.isEmpty = false;\n\n if (isRemote) {\n graph._addToTransaction(relationship);\n if (relationship.remoteState !== null) {\n removeFromInverse(graph, relationship.remoteState, relationship.definition.inverseKey, resourceKey, isRemote);\n }\n relationship.remoteState = value;\n // remote state definitely changed here (we just assigned it), independent of\n // whether local also needs reconciling below -- notify unconditionally so a\n // remote-only reader isn't at the mercy of the localState check further down.\n notifyChange(graph, relationship);\n }\n\n if (relationship.localState !== value) {\n if (!isRemote && relationship.localState) {\n removeFromInverse(graph, relationship.localState, relationship.definition.inverseKey, resourceKey, isRemote);\n }\n relationship.localState = value;\n\n if (!isRemote) {\n // purely local mutation; already notified (unscoped) above for the remote case.\n notifyChange(graph, relationship, 'local');\n }\n }\n } else if (isHasMany(relationship)) {\n if (isRemote) {\n // TODO this needs to alert stuffs\n // And patch state better\n // This is almost definitely wrong\n // WARNING WARNING WARNING\n\n if (!relationship.remoteMembers.has(value)) {\n graph._addToTransaction(relationship);\n relationship.remoteState.push(value);\n relationship.remoteMembers.add(value);\n if (relationship.additions?.has(value)) {\n relationship.additions.delete(value);\n } else {\n relationship.isDirty = true;\n relationship.state.hasReceivedData = true;\n flushCanonical(graph, relationship);\n }\n }\n } else {\n // if we are not dirty but have a null localState then we\n // are mutating a relationship that has never been fetched\n // so we initialize localState to an empty array\n if (!relationship.isDirty && !relationship.localState) {\n relationship.localState = [];\n }\n\n if (_add(graph, resourceKey, relationship, value, null, isRemote)) {\n notifyChange(graph, relationship, 'local');\n }\n }\n } else {\n if (isRemote) {\n if (!relationship.remoteMembers.has(value)) {\n relationship.remoteMembers.add(value);\n relationship.localMembers.add(value);\n }\n } else {\n if (!relationship.localMembers.has(value)) {\n relationship.localMembers.add(value);\n }\n }\n }\n}\n\nexport function notifyInverseOfPotentialMaterialization(\n graph: Graph,\n resourceKey: ResourceKey,\n key: string,\n value: ResourceKey,\n isRemote: boolean\n): void {\n const relationship = graph.get(resourceKey, key);\n if (isHasMany(relationship) && isRemote && relationship.remoteMembers.has(value)) {\n notifyChange(graph, relationship);\n }\n}\n\nexport function removeFromInverse(\n graph: Graph,\n resourceKey: ResourceKey,\n key: string,\n value: ResourceKey,\n isRemote: boolean\n): void {\n const relationship = graph.get(resourceKey, key);\n\n if (isBelongsTo(relationship)) {\n relationship.state.isEmpty = true;\n if (isRemote) {\n graph._addToTransaction(relationship);\n relationship.remoteState = null;\n // remote state definitely changed here; see the equivalent comment in addToInverse.\n notifyChange(graph, relationship);\n }\n if (relationship.localState === value) {\n relationship.localState = null;\n\n if (!isRemote) {\n notifyChange(graph, relationship, 'local');\n }\n }\n } else if (isHasMany(relationship)) {\n if (isRemote) {\n graph._addToTransaction(relationship);\n if (_removeRemote(relationship, value)) {\n notifyChange(graph, relationship);\n }\n } else {\n if (_removeLocal(relationship, value)) {\n notifyChange(graph, relationship, 'local');\n }\n }\n } else {\n if (isRemote) {\n relationship.remoteMembers.delete(value);\n relationship.localMembers.delete(value);\n } else {\n if (value && relationship.localMembers.has(value)) {\n relationship.localMembers.delete(value);\n }\n }\n }\n}\n\nfunction flushCanonical(graph: Graph, rel: CollectionEdge, channel?: NotificationChannel) {\n if (rel.accessed) {\n graph._scheduleLocalSync(rel, channel);\n }\n}\n","import { deprecate } from '@ember/debug';\n\nimport { DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE } from '@warp-drive/core/build-config/deprecations';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport { checkIfNew, isBelongsTo, notifyChange } from '../-utils.ts';\nimport type { ResourceKey } from '../../../types.ts';\nimport type { ReplaceRelatedRecordOperation } from '../../../types/graph.ts';\nimport { assertPolymorphicType } from '../debug/assert-polymorphic-type.ts';\nimport type { Graph } from '../graph.ts';\nimport { addToInverse, notifyInverseOfPotentialMaterialization, removeFromInverse } from './replace-related-records.ts';\n\nexport default function replaceRelatedRecord(graph: Graph, op: ReplaceRelatedRecordOperation, isRemote = false): void {\n const relationship = graph.get(op.record, op.field);\n assert(\n `You can only '${op.op}' on a belongsTo relationship. ${op.record.type}.${op.field} is a ${relationship.definition.kind}`,\n isBelongsTo(relationship)\n );\n if (isRemote) {\n graph._addToTransaction(relationship);\n }\n const { definition, state } = relationship;\n const prop = isRemote ? 'remoteState' : 'localState';\n const existingState: ResourceKey | null = relationship[prop];\n\n /*\n case 1:1\n ========\n In a bi-directional graph with 1:1 edges, replacing a value\n results in up-to 4 discrete value transitions.\n\n If: A <-> B, C <-> D is the initial state,\n and: A <-> C, B, D is the final state\n\n then we would undergo the following 4 transitions.\n\n remove A from B\n add C to A\n remove C from D\n add A to C\n\n case 1:many\n ===========\n In a bi-directional graph with 1:Many edges, replacing a value\n results in up-to 3 discrete value transitions.\n\n If: A<->>B<<->D, C<<->D is the initial state (double arrows representing the many side)\n And: A<->>C<<->D, B<<->D is the final state\n\n Then we would undergo three transitions.\n\n remove A from B\n add C to A.\n add A to C\n\n case 1:?\n ========\n In a uni-directional graph with 1:? edges (modeled in WarpDrive with `inverse:null`) with\n artificial (implicit) inverses, replacing a value results in up-to 3 discrete value transitions.\n This is because a 1:? relationship is effectively 1:many.\n\n If: A->B, C->B is the initial state\n And: A->C, C->B is the final state\n\n Then we would undergo three transitions.\n\n Remove A from B\n Add C to A\n Add A to C\n */\n\n // nothing for us to do\n if (op.value === existingState) {\n // if we were empty before but now know we are empty this needs to be true\n state.hasReceivedData = true;\n\n // if this is a remote update we still sync\n if (isRemote) {\n state.hasReceivedRemoteData = true;\n\n const { localState } = relationship;\n // don't sync if localState is a new record and our remoteState is null\n if (localState && checkIfNew(graph._realStore, localState) && !existingState) {\n return;\n }\n if (existingState && localState === existingState) {\n notifyInverseOfPotentialMaterialization(graph, existingState, definition.inverseKey, op.record, isRemote);\n } else if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) {\n // if localState does not match existingState then we know\n // we have a local mutation that has not been persisted yet\n if (localState !== op.value && relationship.definition.resetOnRemoteUpdate !== false) {\n relationship.localState = existingState;\n\n deprecate(\n `WarpDrive is changing the default semantics of updates to the remote state of relationships.\\n\\nThe following local state was cleared from the <${\n relationship.identifier.type\n }>.${\n relationship.definition.key\n } belongsTo relationship but will not be once this deprecation is resolved:\\n\\n\\t${\n localState ? 'Added: ' + localState.lid + '\\n\\t' : ''\n }${existingState ? 'Removed: ' + existingState.lid : ''}`,\n false,\n {\n id: 'ember-data:deprecate-relationship-remote-update-clearing-local-state',\n for: 'ember-data',\n since: { enabled: '5.3', available: '4.13' },\n until: '6.0',\n url: 'https://deprecations.emberjs.com/v5.x#ember-data-deprecate-relationship-remote-update-clearing-local-state',\n }\n );\n\n // remote didn't change here (op.value === existingState); this is purely\n // clearing a stale local override, so remote-only readers don't need it.\n notifyChange(graph, relationship, 'local');\n }\n }\n }\n return;\n }\n\n // remove this value from the inverse if required\n if (existingState) {\n removeFromInverse(graph, existingState, definition.inverseKey, op.record, isRemote);\n }\n\n // update value to the new value\n relationship[prop] = op.value;\n\n state.hasReceivedData = true;\n /**\n * Local mutations never give us additional information about\n * whether the relationship has received *remote* data. This is\n * what `getRemoteRelationship` relies on to avoid reflecting\n * local-only edits.\n */\n if (isRemote) {\n state.hasReceivedRemoteData = true;\n }\n state.isEmpty = op.value === null;\n state.isStale = false;\n state.hasFailedLoadAttempt = false;\n\n if (op.value) {\n if (definition.type !== op.value.type) {\n // assert(\n // `The '<${definition.inverseType}>.${op.field}' relationship expects only '${definition.type}' records since it is not polymorphic. Received a Record of type '${op.value.type}'`,\n // definition.isPolymorphic\n // );\n\n // TODO this should now handle the deprecation warning if isPolymorphic is not set\n // but the record does turn out to be polymorphic\n // this should still assert if the user is relying on legacy inheritance/mixins to\n // provide polymorphic behavior and has not yet added the polymorphic flags\n if (DEBUG) {\n assertPolymorphicType(relationship.identifier, definition, op.value, graph.store);\n }\n\n graph.registerPolymorphicType(definition.type, op.value.type);\n }\n addToInverse(graph, op.value, definition.inverseKey, op.record, isRemote);\n }\n\n if (isRemote) {\n // Reaching here means `op.value !== existingState` (the prior remoteState),\n // so the remote value has definitely changed -- notify unconditionally,\n // regardless of how (or whether) local state below ends up reconciling.\n notifyChange(graph, relationship);\n\n const { localState, remoteState } = relationship;\n if (localState && checkIfNew(graph._realStore, localState) && !remoteState) {\n return;\n }\n // when localState does not match the new remoteState and\n // localState === existingState then we had no local mutation\n // and we can safely sync the new remoteState to local\n if (localState !== remoteState && localState === existingState) {\n relationship.localState = remoteState;\n // But when localState does not match the new remoteState and\n // and localState !== existingState then we know we have a local mutation\n // that has not been persisted yet.\n } else if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) {\n if (\n localState !== remoteState &&\n localState !== existingState &&\n relationship.definition.resetOnRemoteUpdate !== false\n ) {\n relationship.localState = remoteState;\n\n deprecate(\n `WarpDrive is changing the default semantics of updates to the remote state of relationships.\\n\\nThe following local state was cleared from the <${\n relationship.identifier.type\n }>.${\n relationship.definition.key\n } belongsTo relationship but will not be once this deprecation is resolved:\\n\\n\\t${\n localState ? 'Added: ' + localState.lid + '\\n\\t' : ''\n }${existingState ? 'Removed: ' + existingState.lid : ''}`,\n false,\n {\n id: 'ember-data:deprecate-relationship-remote-update-clearing-local-state',\n for: 'ember-data',\n since: { enabled: '5.3', available: '4.13' },\n until: '6.0',\n url: 'https://deprecations.emberjs.com/v5.x#ember-data-deprecate-relationship-remote-update-clearing-local-state',\n }\n );\n }\n }\n } else {\n // purely local mutation; remote-only readers have nothing to see here.\n notifyChange(graph, relationship, 'local');\n }\n}\n","import { deprecate } from '@ember/debug';\n\nimport { DEBUG_RELATIONSHIP_NOTIFICATIONS } from '@warp-drive/core/build-config/debugging';\nimport {\n DEPRECATE_NON_UNIQUE_PAYLOADS,\n DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE,\n} from '@warp-drive/core/build-config/deprecations';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport type { ResourceKey } from '../../types/identifier.ts';\nimport { isBelongsTo, notifyChange } from './-utils.ts';\nimport { assertPolymorphicType } from './debug/assert-polymorphic-type.ts';\nimport type { CollectionEdge } from './edges/collection.ts';\nimport type { ResourceEdge } from './edges/resource.ts';\nimport type { Graph } from './graph.ts';\nimport replaceRelatedRecord from './operations/replace-related-record.ts';\nimport replaceRelatedRecords from './operations/replace-related-records.ts';\n\nfunction _deprecatedCompare<T>(\n priorLocalState: T[] | null,\n newState: T[],\n newMembers: Set<T>,\n prevState: T[],\n prevSet: Set<T>,\n onAdd: (v: T) => void,\n onDel: (v: T) => void,\n remoteClearsLocal: boolean\n): { duplicates: Map<T, number[]>; diff: Diff<T> } {\n const newLength = newState.length;\n const prevLength = prevState.length;\n const iterationLength = Math.max(newLength, prevLength);\n let changed: boolean = newMembers.size !== prevSet.size;\n let remoteOrderChanged = false;\n const added = new Set<T>();\n const removed = new Set<T>();\n const duplicates = new Map<T, number[]>();\n const finalSet = new Set<T>();\n const finalState: T[] = [];\n const priorLocalLength = priorLocalState?.length ?? 0;\n\n for (let i = 0, j = 0; i < iterationLength; i++) {\n let adv = false;\n let member: T | undefined;\n\n // accumulate anything added\n if (i < newLength) {\n member = newState[i];\n\n if (!finalSet.has(member)) {\n finalState[j] = member;\n finalSet.add(member);\n adv = true;\n\n if (!prevSet.has(member)) {\n // Avoid unnecessarily notifying a change that already exists locally\n if (i < priorLocalLength) {\n const priorLocalMember = priorLocalState![i];\n if (priorLocalMember !== member) {\n changed = true;\n }\n }\n added.add(member);\n onAdd(member);\n }\n } else {\n let list = duplicates.get(member);\n\n if (list === undefined) {\n list = [];\n duplicates.set(member, list);\n }\n\n list.push(i);\n }\n }\n\n // accumulate anything removed\n if (i < prevLength) {\n const prevMember = prevState[i];\n\n // detect reordering, adjusting index for duplicates\n // j is always less than i and so if i < prevLength, j < prevLength\n if (member !== prevState[j]) {\n // the new remote order does not match the current remote order\n // indicating a change in membership or reordering\n remoteOrderChanged = true;\n // however: if the new remote order matches the current local order\n // we can disregard the change notification generation so long as\n // we are not configured to reset on remote update (which is deprecated)\n if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) {\n if (!remoteClearsLocal && i < priorLocalLength) {\n const priorLocalMember = priorLocalState![j];\n if (priorLocalMember !== member) {\n changed = true;\n }\n } else {\n changed = true;\n }\n } else {\n if (i < priorLocalLength) {\n const priorLocalMember = priorLocalState![j];\n if (priorLocalMember !== member) {\n changed = true;\n }\n } else {\n changed = true;\n }\n }\n\n // if remote order hasn't changed but local order differs\n // and we are configured to reset on remote update (which is deprecated)\n // then we still need to mark the relationship as changed\n } else if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) {\n if (remoteClearsLocal) {\n if (!changed && j < priorLocalLength) {\n const priorLocalMember = priorLocalState![j];\n if (priorLocalMember !== member) {\n changed = true;\n }\n }\n }\n }\n\n if (!newMembers.has(prevMember)) {\n changed = true;\n removed.add(prevMember);\n onDel(prevMember);\n }\n } else if (adv && j < prevLength && member !== prevState[j]) {\n changed = true;\n }\n\n if (adv) {\n j++;\n }\n }\n\n const diff = {\n add: added,\n del: removed,\n finalState,\n finalSet,\n changed,\n remoteOrderChanged,\n };\n\n return {\n diff,\n duplicates,\n };\n}\n\nfunction _compare<T>(\n priorLocalState: T[] | null,\n finalState: T[],\n finalSet: Set<T>,\n prevState: T[],\n prevSet: Set<T>,\n onAdd: (v: T) => void,\n onDel: (v: T) => void,\n remoteClearsLocal: boolean\n): Diff<T> {\n const finalLength = finalState.length;\n const prevLength = prevState.length;\n const iterationLength = Math.max(finalLength, prevLength);\n const equalLength = priorLocalState ? finalLength === priorLocalState.length : finalLength === prevLength;\n let remoteOrderChanged = finalSet.size !== prevSet.size;\n let changed: boolean = priorLocalState ? finalSet.size !== priorLocalState.length : remoteOrderChanged;\n const added = new Set<T>();\n const removed = new Set<T>();\n const priorLocalLength = priorLocalState?.length ?? 0;\n\n if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {\n if (changed) {\n // console.log({\n // priorState: priorLocalState?.slice(),\n // finalState: finalState.slice(),\n // prevState: prevState.slice(),\n // });\n }\n\n // oxlint-disable-next-line no-unused-expressions\n changed &&\n // oxlint-disable-next-line no-console\n console.log(\n `changed because ${priorLocalState ? 'finalSet.size !== priorLocalState.length' : 'finalSet.size !== prevSet.size'}`\n );\n }\n\n for (let i = 0; i < iterationLength; i++) {\n let member: T | undefined;\n\n // accumulate anything added\n if (i < finalLength) {\n member = finalState[i];\n if (!prevSet.has(member)) {\n // Avoid unnecessarily notifying a change that already exists locally\n if (i < priorLocalLength) {\n const priorLocalMember = priorLocalState![i];\n if (priorLocalMember !== member) {\n if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {\n if (!changed) {\n // console.log({\n // priorLocalMember,\n // member,\n // i,\n // priorState: priorLocalState?.slice(),\n // finalState: finalState.slice(),\n // prevState: prevState.slice(),\n // });\n }\n\n // oxlint-disable-next-line no-unused-expressions, no-console\n !changed && console.log(`changed because priorLocalMember !== member && !prevSet.has(member)`);\n }\n changed = true;\n }\n }\n added.add(member);\n onAdd(member);\n }\n }\n\n // accumulate anything removed\n if (i < prevLength) {\n const prevMember = prevState[i];\n\n // detect reordering\n if (equalLength && member !== prevMember) {\n // the new remote order does not match the current remote order\n // indicating a change in membership or reordering\n remoteOrderChanged = true;\n // however: if the new remote order matches the current local order\n // we can disregard the change notification generation so long as\n // we are not configured to reset on remote update (which is deprecated)\n\n if (i < priorLocalLength) {\n const priorLocalMember = priorLocalState![i];\n if (priorLocalMember !== member) {\n if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {\n // oxlint-disable-next-line no-unused-expressions, no-console\n !changed && console.log(`changed because priorLocalMember !== member && member !== prevMember`);\n }\n changed = true;\n }\n } else if (i < finalLength) {\n // if we have exceeded the length of priorLocalState and we are within the range\n // of the finalState then we must have changed\n if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {\n // oxlint-disable-next-line no-unused-expressions, no-console\n !changed && console.log(`changed because priorMember !== member && index >= priorLocalLength`);\n }\n changed = true;\n }\n\n // if remote order hasn't changed but local order differs\n // and we are configured to reset on remote update (which is deprecated)\n // then we still need to mark the relationship as changed\n } else if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) {\n if (remoteClearsLocal) {\n if (equalLength && !changed && i < priorLocalLength) {\n const priorLocalMember = priorLocalState![i];\n if (priorLocalMember !== prevMember) {\n if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {\n // oxlint-disable-next-line no-unused-expressions, no-console\n !changed && console.log(`changed because priorLocalMember !== prevMember && remoteClearsLocal`);\n }\n changed = true;\n }\n }\n }\n }\n\n if (!finalSet.has(prevMember)) {\n // if we are within finalLength, we can only be \"changed\" if we've already exceeded\n // the index range of priorLocalState, as otherwise the previous member may still\n // be removed.\n //\n // prior local: [1, 2, 3, 4]\n // final state: [1, 2, 3]\n // prev remote state: [1, 2, 5, 3, 4]\n // i === 2\n // prevMember === 5\n // !finalSet.has(prevMember) === true\n //\n // because we will become changed at i===3,\n // we do not need to worry about becoming changed at i===2\n // as the arrays until now are still the same\n //\n // prior local: [1, 2, 3]\n // final state: [1, 2, 3, 4]\n // prev remote state: [1, 2, 5, 3, 4]\n // i === 2\n // prevMember === 5\n // !finalSet.has(prevMember) === true\n //\n // because we will become changed at i===3\n // we do not need to worry about becoming changed at i===2\n //\n // prior local: [1, 2, 3]\n // final state: [1, 2, 3]\n // prev remote state: [1, 2, 5, 3, 4]\n // i === 2\n // prevMember === 5\n // !finalSet.has(prevMember) === true\n //\n // because we have same length and same membership order\n // we do not need to worry about becoming changed at i===2\n //\n // if you do not have a priorLocalState you can't be changed\n // ergo, we never need to set changed in this branch.\n // this log can still be useful for debugging.\n if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {\n // oxlint-disable-next-line no-unused-expressions\n !changed &&\n // oxlint-disable-next-line no-console\n console.log(`changed because i >= priorLocalLength && i < finalLength && !finalSet.has(prevMember)`);\n }\n //\n // we do still set remoteOrderChanged as it has\n remoteOrderChanged = true;\n removed.add(prevMember);\n onDel(prevMember);\n }\n }\n }\n\n return {\n add: added,\n del: removed,\n finalState,\n finalSet,\n changed,\n remoteOrderChanged,\n };\n}\n\ntype Diff<T> = {\n add: Set<T>;\n del: Set<T>;\n finalState: T[];\n finalSet: Set<T>;\n changed: boolean;\n remoteOrderChanged: boolean;\n};\n\nexport function diffCollection(\n finalState: ResourceKey[],\n relationship: CollectionEdge,\n onAdd: (v: ResourceKey) => void,\n onDel: (v: ResourceKey) => void\n): Diff<ResourceKey> {\n const finalSet = new Set(finalState);\n const { localState: priorLocalState, remoteState, remoteMembers } = relationship;\n\n if (DEPRECATE_NON_UNIQUE_PAYLOADS) {\n if (finalState.length !== finalSet.size) {\n const { diff, duplicates } = _deprecatedCompare(\n priorLocalState,\n finalState,\n finalSet,\n remoteState,\n remoteMembers,\n onAdd,\n onDel,\n relationship.definition.resetOnRemoteUpdate\n );\n\n if (DEBUG) {\n deprecate(\n `Expected all entries in the relationship ${relationship.definition.type}:${relationship.definition.key} to be unique, see log for a list of duplicate entry indeces`,\n false,\n {\n id: 'ember-data:deprecate-non-unique-relationship-entries',\n for: 'ember-data',\n until: '6.0',\n since: { available: '4.13', enabled: '5.3' },\n }\n );\n // oxlint-disable-next-line no-console\n console.log(duplicates);\n }\n\n return diff;\n }\n } else {\n assert(\n `Expected all entries in the relationship to be unique, found duplicates`,\n finalState.length === finalSet.size\n );\n }\n\n return _compare(\n priorLocalState,\n finalState,\n finalSet,\n remoteState,\n remoteMembers,\n onAdd,\n onDel,\n relationship.definition.resetOnRemoteUpdate\n );\n}\n\nexport function computeLocalState(storage: CollectionEdge): ResourceKey[] {\n // When the edge is clean and we already have a materialized localState we can\n // return it directly. A clean edge can still have a `null` localState though:\n // dematerializing an inverse member (e.g. when a route reloads its model)\n // nulls out localState without dirtying the edge. In that case we fall through\n // and recompute from remoteState rather than asserting.\n if (!storage.isDirty && storage.localState) {\n return storage.localState;\n }\n\n const state = storage.remoteState.slice();\n\n storage.removals?.forEach((v) => {\n const index = state.indexOf(v);\n state.splice(index, 1);\n });\n\n storage.additions?.forEach((v) => {\n state.push(v);\n });\n storage.localState = state;\n storage.isDirty = false;\n\n return state;\n}\n\n/**\n * A function which attempts to add a value to the local state of a collection\n * relationship, and returns true if the value was added, or false if it was\n * already present.\n *\n * It will not generate a notification, will not update the relationships to dirty,\n * and will not update the inverse relationships, making it suitable for use as\n * an internal util to perform the just the addition to a specific side of a\n * relationship.\n *\n * @internal\n */\nexport function _add(\n graph: Graph,\n record: ResourceKey,\n relationship: CollectionEdge,\n value: ResourceKey,\n index: number | null,\n isRemote: boolean\n): boolean {\n return !isRemote\n ? _addLocal(graph, record, relationship, value, index)\n : _addRemote(graph, record, relationship, value, index);\n}\n\nfunction _addRemote(\n graph: Graph,\n record: ResourceKey,\n relationship: CollectionEdge,\n value: ResourceKey,\n index: number | null\n): boolean {\n assert(`expected an identifier to add to the collection relationship`, value);\n const { remoteMembers, additions, removals, remoteState } = relationship;\n\n assert(`Cannot add a resource that is already present`, !remoteMembers.has(value));\n if (remoteMembers.has(value)) {\n return false;\n }\n\n // add to the remote state\n remoteMembers.add(value);\n assert(\n `Cannot insert at an index that is not in bounds`,\n index === null || (index >= 0 && index < remoteState.length)\n );\n const hasValidIndex = index !== null && index >= 0 && index < remoteState.length;\n if (hasValidIndex) {\n remoteState.splice(index, 0, value);\n } else {\n remoteState.push(value);\n }\n\n // remove from additions if present\n if (additions?.has(value)) {\n additions.delete(value);\n\n // nothing more to do this was our state already\n return false;\n }\n\n assert(\n `Remote state indicated addition of a resource that was present only as a local mutation`,\n !removals?.has(value)\n );\n\n // if the relationship already needs to recalc, we don't bother\n // attempting to patch the localState\n if (relationship.isDirty) {\n return true;\n }\n\n // if we have existing localState\n // we attempt to patch it without blowing it away\n // as this is more efficient than recomputing\n // it allows us to preserve local ordering\n // to a small extent. Local ordering should not\n // be relied upon as any remote change could blow it away\n if (relationship.localState) {\n if (!hasValidIndex) {\n relationship.localState.push(value);\n } else if (index === 0) {\n relationship.localState.unshift(value);\n } else if (!removals?.size) {\n relationship.localState.splice(index, 0, value);\n } else {\n relationship.isDirty = true;\n }\n }\n\n return true;\n}\n\nfunction _addLocal(\n graph: Graph,\n record: ResourceKey,\n relationship: CollectionEdge,\n value: ResourceKey,\n index: number | null\n): boolean {\n const { remoteMembers, removals } = relationship;\n let additions = relationship.additions;\n const hasPresence = remoteMembers.has(value) || additions?.has(value);\n\n if (hasPresence && !removals?.has(value)) {\n assert(\n `Attempted to add the resource '${value.lid}' to the collection <${relationship.identifier.type}>.${relationship.definition.key} it was already in`,\n hasPresence && !removals?.has(value)\n );\n return false;\n }\n\n if (removals?.has(value)) {\n removals.delete(value);\n } else {\n if (!additions) {\n additions = relationship.additions = new Set();\n }\n\n relationship.state.hasReceivedData = true;\n additions.add(value);\n\n const { type } = relationship.definition;\n if (type !== value.type) {\n if (DEBUG) {\n assertPolymorphicType(record, relationship.definition, value, graph.store);\n }\n graph.registerPolymorphicType(value.type, type);\n }\n }\n\n // if we have existing localState\n // and we have an index\n // apply the change, as this is more efficient\n // than recomputing localState and\n // it allows us to preserve local ordering\n // to a small extend. Local ordering should not\n // be relied upon as any remote change will blow it away\n if (relationship.localState) {\n if (index !== null) {\n relationship.localState.splice(index, 0, value);\n } else {\n relationship.localState.push(value);\n }\n }\n\n return true;\n}\n\nexport function _remove(\n graph: Graph,\n record: ResourceKey,\n relationship: CollectionEdge,\n value: ResourceKey,\n index: number | null,\n isRemote: boolean\n): boolean {\n return !isRemote ? _removeLocal(relationship, value) : _removeRemote(relationship, value);\n}\n\nexport function _removeLocal(relationship: CollectionEdge, value: ResourceKey): boolean {\n assert(`expected an identifier to remove from the collection relationship`, value);\n const { remoteMembers, additions } = relationship;\n let removals = relationship.removals;\n const hasPresence = remoteMembers.has(value) || additions?.has(value);\n\n if (!hasPresence || removals?.has(value)) {\n assert(\n `Attempted to remove the resource '${value.lid}' from the collection <${relationship.identifier.type}>.${relationship.definition.key} but it was not present`,\n !hasPresence || removals?.has(value)\n );\n return false;\n }\n\n if (additions?.has(value)) {\n additions.delete(value);\n } else {\n if (!removals) {\n removals = relationship.removals = new Set();\n }\n\n removals.add(value);\n }\n\n // if we have existing localState\n // apply the change, as this is more efficient\n // than recomputing localState and\n // it allows us to preserve local ordering\n // to a small extend. Local ordering should not\n // be relied upon as any remote change will blow it away\n if (relationship.localState) {\n const index = relationship.localState.indexOf(value);\n assert(`Cannot remove a resource that is not present`, index !== -1);\n relationship.localState.splice(index, 1);\n }\n assert(\n `Expected relationship to be dirty when performing a local mutation`,\n relationship.localState || relationship.isDirty\n );\n\n return true;\n}\n\nexport function _removeRemote(relationship: CollectionEdge, value: ResourceKey): boolean {\n assert(`expected an identifier to remove from the collection relationship`, value);\n const { remoteMembers, additions, removals, remoteState } = relationship;\n\n assert(`Cannot remove a resource that is not present`, remoteMembers.has(value));\n if (!remoteMembers.has(value)) {\n return false;\n }\n\n // remove from remote state\n remoteMembers.delete(value);\n let index = remoteState.indexOf(value);\n assert(`Cannot remove a resource that is not present`, index !== -1);\n remoteState.splice(index, 1);\n\n // remove from removals if present\n if (removals?.has(value)) {\n removals.delete(value);\n\n // nothing more to do this was our state already\n return false;\n }\n\n assert(\n `Remote state indicated removal of a resource that was present only as a local mutation`,\n !additions?.has(value)\n );\n\n // if we have existing localState\n // and we have an index\n // apply the change, as this is more efficient\n // than recomputing localState and\n // it allows us to preserve local ordering\n // to a small extend. Local ordering should not\n // be relied upon as any remote change will blow it away\n if (relationship.localState) {\n index = relationship.localState.indexOf(value);\n assert(`Cannot remove a resource that is not present`, index !== -1);\n relationship.localState.splice(index, 1);\n }\n assert(\n `Expected relationship to be dirty when performing a local mutation`,\n relationship.localState || relationship.isDirty\n );\n\n return true;\n}\n\nexport function rollbackRelationship(\n graph: Graph,\n key: ResourceKey,\n field: string,\n relationship: CollectionEdge | ResourceEdge\n): void {\n if (isBelongsTo(relationship)) {\n replaceRelatedRecord(\n graph,\n {\n op: 'replaceRelatedRecord',\n record: key,\n field,\n value: relationship.remoteState,\n },\n false\n );\n } else {\n replaceRelatedRecords(\n graph,\n {\n op: 'replaceRelatedRecords',\n record: key,\n field,\n value: relationship.remoteState.slice(),\n },\n false\n );\n\n // when the change was a \"reorder\" only we wont have generated\n // a notification yet.\n // if we give rollback a unique operation we can use the ability of\n // diff to report a separate `remoteOrderChanged` flag to trigger this\n // if needed to avoid the duplicate.\n notifyChange(graph, relationship);\n }\n}\n","import { LOG_GRAPH } from '@warp-drive/build-config/debugging';\nimport { DEBUG } from '@warp-drive/build-config/env';\n\nexport interface RelationshipState {\n /*\n This flag indicates whether we should consider the content\n of this relationship \"known\".\n\n If we have no relationship knowledge, and the relationship\n is `async`, we will attempt to fetch the relationship on\n access if it is also stale.\n\n Snapshot uses this to tell the difference between unknown\n (`undefined`) or empty (`null`). The reason for this is that\n we wouldn't want to serialize unknown relationships as `null`\n as that might overwrite remote state.\n\n All relationships for a newly created (`store.createRecord()`) are\n considered known (`hasReceivedData === true`).\n\n true when\n => we receive a push with either new data or explicit empty (`[]` or `null`)\n => the relationship is a belongsTo and we have received data from\n the other side.\n\n false when\n => we have received no signal about what data belongs in this relationship\n => the relationship is a hasMany and we have only received data from\n the other side.\n */\n hasReceivedData: boolean;\n /*\n Like `hasReceivedData`, but only ever set by *remote* updates\n (pushes from the cache/server), never by local mutations.\n\n This is what `getRemoteRelationship` uses to distinguish \"we have\n never been told anything about this relationship's remote state\"\n (stays `undefined`) from \"we were explicitly told the remote state\n is empty\" (`null` / `[]`) regardless of any local edits that may\n have occurred since.\n */\n hasReceivedRemoteData: boolean;\n /*\n Flag that indicates whether an empty relationship is explicitly empty\n (signaled by push giving us an empty array or null relationship)\n e.g. an API response has told us that this relationship is empty.\n\n Thus far, it does not appear that we actually need this flag; however,\n @runspired has found it invaluable when debugging relationship tests\n to determine whether (and why if so) we are in an incorrect state.\n\n true when\n => we receive a push with explicit empty (`[]` or `null`)\n => we have received no signal about what data belongs in this relationship\n => on initial create (as no signal is known yet)\n\n false at all other times\n */\n\n isEmpty: boolean;\n /*\n This flag indicates whether we should\n re-fetch the relationship the next time\n it is accessed.\n\n The difference between this flag and `shouldForceReload`\n is in how we treat the presence of partially missing data:\n - for a forced reload, we will reload the link or EVERY record\n - for a stale reload, we will reload the link (if present) else only MISSING records\n\n Ideally these flags could be merged, but because we don't give the\n request layer the option of deciding how to resolve the data being queried\n we are forced to differentiate for now.\n\n It is also possible for a relationship to remain stale after a forced reload; however,\n in this case `state.hasFailedLoadAttempt` ought to be `true`.\n\n false when\n => cache.isNew(resourceKey) on initial setup\n => a previously triggered request has resolved\n => we get relationship data via push\n\n true when\n => !cache.isNew(resourceKey) on initial setup\n => an inverse has been unloaded\n => we get a new link for the relationship\n\n TODO @runspired unskip the acceptance tests and fix these flags\n */\n isStale: boolean;\n\n hasFailedLoadAttempt: boolean;\n /*\n This flag forces fetch. `true` for a single request once `reload()`\n has been called `false` at all other times.\n */\n shouldForceReload: boolean;\n /*\n This flag indicates whether we should\n **partially** re-fetch the relationship the\n next time it is accessed.\n\n false when\n => initial setup\n => a previously triggered request has resolved\n\n true when\n => an inverse has been unloaded\n */\n hasDematerializedInverse: boolean;\n\n // TODO do we want this anymore? Seems somewhat useful\n // especially if we rename to `hasUpdatedLink`\n // which would tell us slightly more about why the\n // relationship is stale\n // updatedLink: boolean;\n}\n\nexport function createState(): RelationshipState {\n if (DEBUG) {\n if (LOG_GRAPH) {\n let hasReceivedData = false;\n return {\n get hasReceivedData() {\n return hasReceivedData;\n },\n set hasReceivedData(value: boolean) {\n hasReceivedData = value;\n },\n hasReceivedRemoteData: false,\n isEmpty: true,\n isStale: false,\n hasFailedLoadAttempt: false,\n shouldForceReload: false,\n hasDematerializedInverse: false,\n };\n }\n }\n\n return {\n hasReceivedData: false,\n hasReceivedRemoteData: false,\n isEmpty: true,\n isStale: false,\n hasFailedLoadAttempt: false,\n shouldForceReload: false,\n hasDematerializedInverse: false,\n };\n}\n","import { computeLocalState } from '../-diff.ts';\nimport type { UpgradedMeta } from '../-edge-definition.ts';\nimport type { RelationshipState } from '../-state.ts';\nimport { createState } from '../-state.ts';\nimport type { CollectionRelationship } from '../../../types/cache/relationship.ts';\nimport type { ResourceKey } from '../../../types/identifier.ts';\nimport type { Links, Meta, PaginationLinks } from '../../../types/spec/json-api-raw.ts';\n\n/**\n * Stores the graph's internal state for one side of a collection (`hasMany`) relationship.\n */\nexport interface CollectionEdge {\n /** The upgraded relationship definition (schema metadata) for this edge. */\n definition: UpgradedMeta;\n /** The resource this relationship belongs to. */\n identifier: ResourceKey;\n /** Bookkeeping flags describing what we know about this relationship's data. */\n state: RelationshipState;\n\n /** The set of members known to be part of the remote (server-provided) state, used for fast membership checks. */\n remoteMembers: Set<ResourceKey>;\n /** The ordered list of members that make up the remote (server-provided) state of the relationship. */\n remoteState: ResourceKey[];\n\n /** Members that have been locally added to the relationship but not yet reflected in remote state. */\n additions: Set<ResourceKey> | null;\n /** Members that have been locally removed from the relationship but not yet reflected in remote state. */\n removals: Set<ResourceKey> | null;\n\n /** The most recently received JSON:API `meta` for this relationship. */\n meta: Meta | null;\n /** The most recently received JSON:API `links` for this relationship. */\n links: Links | PaginationLinks | null;\n\n /** The computed local (client-side) ordering of members, incorporating any pending {@link CollectionEdge.additions} and {@link CollectionEdge.removals}. Cached until `isDirty` is set. */\n localState: ResourceKey[] | null;\n /**\n * Whether the localState for this edge is out-of-sync\n * with the remoteState.\n *\n * if state.hasReceivedData=false we are also\n * not dirty since there is nothing to sync with.\n *\n */\n isDirty: boolean;\n /** The transaction id of the last transaction that touched this relationship, used to detect stale/out-of-order remote updates. */\n transactionRef: number;\n /**\n * Whether data for this edge has been accessed at least once\n * via `graph.getData`\n *\n */\n accessed: boolean;\n\n /**\n * The most recently computed diff between the prior and new remote state, retained so that\n * consumers (e.g. a `ManyArray`) may patch themselves incrementally instead of recomputing\n * from scratch.\n */\n _diff?: {\n /** Members present in the new remote state that were not present previously. */\n add: Set<ResourceKey>;\n /** Members present in the previous remote state that are no longer present. */\n del: Set<ResourceKey>;\n };\n}\n\n/** Creates a new {@link CollectionEdge} for the given definition and identifier. */\nexport function createCollectionEdge(definition: UpgradedMeta, identifier: ResourceKey): CollectionEdge {\n return {\n definition,\n identifier,\n state: createState(),\n remoteMembers: new Set(),\n remoteState: [],\n additions: null,\n removals: null,\n\n meta: null,\n links: null,\n\n localState: null,\n isDirty: false,\n transactionRef: 0,\n accessed: false,\n _diff: undefined,\n };\n}\n\nconst cp = structuredClone;\n\n/**\n * Builds a legacy `{ data, links, meta }` {@link CollectionRelationship} payload for this edge,\n * using either the remote or the computed local state, and marks the edge as accessed.\n */\nexport function legacyGetCollectionRelationshipData(\n source: CollectionEdge,\n getRemoteState: boolean\n): CollectionRelationship {\n source.accessed = true;\n const payload: CollectionRelationship = {};\n\n if (source.state.hasReceivedData) {\n payload.data = getRemoteState ? source.remoteState.slice() : computeLocalState(source);\n }\n\n if (source.links) {\n payload.links = cp(source.links);\n }\n\n if (source.meta) {\n payload.meta = cp(source.meta);\n }\n\n return payload;\n}\n","import type { UpgradedMeta } from '../-edge-definition.ts';\nimport type { ResourceKey } from '../../../types/identifier.ts';\n\n/**\n * The relationship definition (schema metadata) backing an {@link ImplicitEdge}, tagging\n * the {@link UpgradedMeta} as belonging to an implicit inverse relationship.\n */\nexport type ImplicitMeta = UpgradedMeta & {\n /** Always `'implicit'` for the definition of an {@link ImplicitEdge}. */\n kind: 'implicit';\n /** Always `true`, allowing this definition to be discriminated from `hasMany`/`belongsTo` definitions. */\n isImplicit: true;\n};\n\n/**\n Implicit relationships are relationships which have not been declared but the inverse side exists on\n another record somewhere\n\n For example consider the following two models\n\n ::: code-group\n\n ```js [./models/comment.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @attr text;\n }\n ```\n\n ```js [./models/post.js]\n import { Model, attr, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @attr title;\n @hasMany('comment', { async: true, inverse: null }) comments;\n }\n ```\n\n :::\n\n Then we would have a implicit 'post' relationship for the comment record in order\n to be do things like remove the comment from the post if the comment were to be deleted.\n*/\nexport interface ImplicitEdge {\n /** The definition (schema metadata) for this implicit inverse relationship. */\n definition: ImplicitMeta;\n /** The resource this implicit relationship belongs to. */\n identifier: ResourceKey;\n /** Members added locally that have not yet been confirmed by a remote update. */\n localMembers: Set<ResourceKey>;\n /** Members known to be part of the relationship from remote (server-provided) state. */\n remoteMembers: Set<ResourceKey>;\n}\n\n/** Creates a new {@link ImplicitEdge} for the given definition and identifier. */\nexport function createImplicitEdge(definition: ImplicitMeta, identifier: ResourceKey): ImplicitEdge {\n return {\n definition,\n identifier,\n localMembers: new Set(),\n remoteMembers: new Set(),\n };\n}\n","import type { UpgradedMeta } from '../-edge-definition.ts';\nimport type { RelationshipState } from '../-state.ts';\nimport { createState } from '../-state.ts';\nimport type { ResourceRelationship } from '../../../types/cache/relationship.ts';\nimport type { ResourceKey } from '../../../types/identifier.ts';\nimport type { Links, Meta, PaginationLinks } from '../../../types/spec/json-api-raw.ts';\n\n/**\n * Stores the data for one side of a \"single\" resource relationship.\n *\n * @private\n */\nexport interface ResourceEdge {\n definition: UpgradedMeta;\n identifier: ResourceKey;\n state: RelationshipState;\n localState: ResourceKey | null;\n remoteState: ResourceKey | null;\n meta: Meta | null;\n links: Links | PaginationLinks | null;\n transactionRef: number;\n accessed: boolean;\n}\n\nexport function createResourceEdge(definition: UpgradedMeta, identifier: ResourceKey): ResourceEdge {\n return {\n definition,\n identifier,\n state: createState(),\n transactionRef: 0,\n localState: null,\n remoteState: null,\n meta: null,\n links: null,\n accessed: false,\n };\n}\n\nexport function legacyGetResourceRelationshipData(source: ResourceEdge, getRemoteState: boolean): ResourceRelationship {\n source.accessed = true;\n let data: ResourceKey | null | undefined;\n const payload: ResourceRelationship = {};\n if (getRemoteState && (source.remoteState || source.state.hasReceivedRemoteData)) {\n data = source.remoteState ?? null;\n } else if (!getRemoteState && (source.localState || source.state.hasReceivedData)) {\n data = source.localState ?? null;\n }\n\n if (source.links) {\n payload.links = source.links;\n }\n if (data !== undefined) {\n payload.data = data;\n }\n if (source.meta) {\n payload.meta = source.meta;\n }\n\n return payload;\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\n\nimport { _add } from '../-diff.ts';\nimport { isBelongsTo, isHasMany, notifyChange } from '../-utils.ts';\nimport type { AddToResourceRelationshipMutation } from '../../../types/cache/mutations.ts';\nimport type { AddToResourceRelationshipOperation } from '../../../types/cache/operations.ts';\nimport type { ReplaceRelatedRecordOperation } from '../../../types/graph.ts';\nimport type { ResourceKey } from '../../../types/identifier.ts';\nimport type { CollectionEdge } from '../edges/collection.ts';\nimport type { Graph } from '../graph.ts';\nimport replaceRelatedRecord from './replace-related-record.ts';\nimport { addToInverse } from './replace-related-records.ts';\n\nexport default function addToRelatedRecords(\n graph: Graph,\n op: AddToResourceRelationshipOperation | AddToResourceRelationshipMutation,\n isRemote: boolean\n): void {\n const { record, value, index } = op;\n const relationship = graph.get(record, op.field);\n\n const _isBelongsTo = isBelongsTo(relationship);\n if (isRemote && _isBelongsTo) {\n if (value !== relationship.remoteState) {\n const newOp: ReplaceRelatedRecordOperation = {\n op: 'replaceRelatedRecord',\n record,\n field: op.field,\n value: value as ResourceKey,\n };\n return replaceRelatedRecord(graph, newOp, isRemote);\n }\n assert(\n `Expected '${value?.lid}' (the value to add) to NOT be the same as the remote state '${relationship.remoteState?.lid ?? '<null>'}'`,\n value === relationship.remoteState\n );\n return;\n }\n\n assert(\n `You can only '${op.op}' on a hasMany relationship. ${record.type}.${op.field} is a ${relationship.definition.kind}`,\n isHasMany(relationship)\n );\n\n // if we are not dirty but have a null localState then we\n // are mutating a relationship that has never been fetched\n // so we initialize localState to an empty array\n if (!relationship.isDirty && !relationship.localState) {\n relationship.localState = [];\n }\n\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n addRelatedRecord(graph, relationship, record, value[i], index !== undefined ? index + i : null, isRemote);\n }\n } else {\n addRelatedRecord(graph, relationship, record, value, index ?? null, isRemote);\n }\n\n // a purely local mutation (isRemote=false) has no remote implication, so\n // remote-only readers don't need to be woken for it. A remote addition\n // changes remote state and the reconciled local view alike, so it is\n // notified unscoped, reaching every subscriber.\n notifyChange(graph, relationship, isRemote ? undefined : 'local');\n}\n\nfunction addRelatedRecord(\n graph: Graph,\n relationship: CollectionEdge,\n record: ResourceKey,\n value: ResourceKey,\n index: number | null,\n isRemote: boolean\n) {\n assert(`expected an identifier to add to the collection relationship`, value);\n\n if (_add(graph, record, relationship, value, index, isRemote)) {\n addToInverse(graph, value, relationship.definition.inverseKey, record, isRemote);\n }\n}\n","import { forAllRelatedIdentifiers, isBelongsTo, isHasMany, notifyChange } from '../-utils.ts';\nimport type { MergeOperation } from '../../../types/cache/operations.ts';\nimport type { CollectionEdge } from '../edges/collection.ts';\nimport type { ImplicitEdge } from '../edges/implicit.ts';\nimport type { ResourceEdge } from '../edges/resource.ts';\nimport type { Graph, GraphEdge } from '../graph.ts';\n\nexport function mergeIdentifier(graph: Graph, op: MergeOperation, relationships: Record<string, GraphEdge>): void {\n Object.keys(relationships).forEach((key) => {\n const rel = relationships[key];\n if (!rel) {\n return;\n }\n mergeIdentifierForRelationship(graph, op, rel);\n });\n}\n\nfunction mergeIdentifierForRelationship(graph: Graph, op: MergeOperation, rel: GraphEdge): void {\n rel.identifier = op.value;\n forAllRelatedIdentifiers(rel, (identifier) => {\n const inverse = graph.get(identifier, rel.definition.inverseKey);\n mergeInRelationship(graph, inverse, op);\n });\n}\n\nfunction mergeInRelationship(graph: Graph, rel: GraphEdge, op: MergeOperation): void {\n if (isBelongsTo(rel)) {\n mergeBelongsTo(graph, rel, op);\n } else if (isHasMany(rel)) {\n mergeHasMany(graph, rel, op);\n } else {\n mergeImplicit(graph, rel, op);\n }\n}\n\nfunction mergeBelongsTo(graph: Graph, rel: ResourceEdge, op: MergeOperation): void {\n // both branches below independently indicate a real change (remote identity\n // substitution, or a local mutation referencing the merged identifier), so a\n // single unconditional notify covers both without needing to reason about\n // which side triggered it.\n let changed = false;\n if (rel.remoteState === op.record) {\n rel.remoteState = op.value;\n changed = true;\n }\n if (rel.localState === op.record) {\n rel.localState = op.value;\n changed = true;\n }\n if (changed) {\n notifyChange(graph, rel);\n }\n}\n\nfunction mergeHasMany(graph: Graph, rel: CollectionEdge, op: MergeOperation): void {\n if (rel.remoteMembers.has(op.record)) {\n rel.remoteMembers.delete(op.record);\n rel.remoteMembers.add(op.value);\n const index = rel.remoteState.indexOf(op.record);\n rel.remoteState.splice(index, 1, op.value);\n rel.isDirty = true;\n }\n if (rel.additions?.has(op.record)) {\n rel.additions.delete(op.record);\n rel.additions.add(op.value);\n rel.isDirty = true;\n }\n if (rel.removals?.has(op.record)) {\n rel.removals.delete(op.record);\n rel.removals.add(op.value);\n rel.isDirty = true;\n }\n if (rel.isDirty) {\n notifyChange(graph, rel);\n }\n}\n\nfunction mergeImplicit(graph: Graph, rel: ImplicitEdge, op: MergeOperation): void {\n if (rel.remoteMembers.has(op.record)) {\n rel.remoteMembers.delete(op.record);\n rel.remoteMembers.add(op.value);\n }\n if (rel.localMembers.has(op.record)) {\n rel.localMembers.delete(op.record);\n rel.localMembers.add(op.value);\n }\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\n\nimport { _remove } from '../-diff.ts';\nimport { isBelongsTo, isHasMany, notifyChange } from '../-utils.ts';\nimport type { RemoveFromResourceRelationshipMutation } from '../../../types/cache/mutations.ts';\nimport type { RemoveFromResourceRelationshipOperation } from '../../../types/cache/operations.ts';\nimport type { ReplaceRelatedRecordOperation } from '../../../types/graph.ts';\nimport type { ResourceKey } from '../../../types/identifier.ts';\nimport type { CollectionEdge } from '../edges/collection.ts';\nimport type { Graph } from '../graph.ts';\nimport replaceRelatedRecord from './replace-related-record.ts';\nimport { removeFromInverse } from './replace-related-records.ts';\n\nexport default function removeFromRelatedRecords(\n graph: Graph,\n op: RemoveFromResourceRelationshipOperation | RemoveFromResourceRelationshipMutation,\n isRemote: boolean\n): void {\n const { record, value } = op;\n const relationship = graph.get(record, op.field);\n\n const _isBelongsTo = isBelongsTo(relationship);\n if (isRemote && _isBelongsTo) {\n if (value === relationship.remoteState) {\n const newOp: ReplaceRelatedRecordOperation = {\n op: 'replaceRelatedRecord',\n record,\n field: op.field,\n value: null,\n };\n return replaceRelatedRecord(graph, newOp, isRemote);\n }\n assert(\n `Expected '${(value as ResourceKey)?.lid}' (the value to remove) to be the same as the remote state '${relationship.remoteState?.lid ?? '<null>'}'`,\n value === relationship.remoteState\n );\n return;\n }\n\n assert(\n `You can only '${op.op}' on a hasMany relationship. ${record.type}.${op.field} is a ${relationship.definition.kind}`,\n isHasMany(relationship)\n );\n\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n removeRelatedRecord(graph, record, relationship, value[i], op.index ?? null, isRemote);\n }\n } else {\n removeRelatedRecord(graph, record, relationship, value, op.index ?? null, isRemote);\n }\n\n // a purely local mutation (isRemote=false) has no remote implication, so\n // remote-only readers don't need to be woken for it. A remote removal\n // changes remote state and the reconciled local view alike, so it is\n // notified unscoped, reaching every subscriber.\n notifyChange(graph, relationship, isRemote ? undefined : 'local');\n}\n\nfunction removeRelatedRecord(\n graph: Graph,\n record: ResourceKey,\n relationship: CollectionEdge,\n value: ResourceKey,\n index: number | null,\n isRemote: boolean\n) {\n assert(`expected an identifier to remove from the collection relationship`, value);\n if (_remove(graph, record, relationship, value, index, isRemote)) {\n removeFromInverse(graph, value, relationship.definition.inverseKey, record, isRemote);\n }\n}\n","import type { Link, LinkObject } from '../../types/spec/json-api-raw.ts';\n\n/*\n This method normalizes a link to an \"links object\". If the passed link is\n already an object it's returned without any modifications.\n\n See http://jsonapi.org/format/#document-links for more information.\n*/\nexport default function _normalizeLink(link: Link): LinkObject | null {\n switch (typeof link) {\n case 'object':\n return link;\n case 'string':\n return { href: link };\n }\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\n\nimport { isBelongsTo, isHasMany, notifyChange } from '../-utils.ts';\nimport type { Store } from '../../../index.ts';\nimport type { ResourceKey } from '../../../types.ts';\nimport type { UpdateResourceRelationshipOperation } from '../../../types/cache/operations.ts';\nimport type { UpdateRelationshipOperation } from '../../../types/graph.ts';\nimport type {\n ExistingResourceIdentifierObject,\n NewResourceIdentifierObject,\n} from '../../../types/spec/json-api-raw.ts';\nimport type { Graph } from '../graph.ts';\nimport _normalizeLink from '../normalize-link.ts';\n\ntype CacheKeyManager = Store['cacheKeyManager'];\n\n/*\n Updates the \"canonical\" or \"remote\" state of a relationship, replacing any existing\n state and blowing away any local changes (excepting new records).\n*/\nexport default function updateRelationshipOperation(\n graph: Graph,\n op: UpdateRelationshipOperation | UpdateResourceRelationshipOperation\n): void {\n const relationship = graph.get(op.record, op.field);\n assert(`Cannot update an implicit relationship`, isHasMany(relationship) || isBelongsTo(relationship));\n const { definition, identifier } = relationship;\n const { isCollection } = definition;\n\n const payload = op.value;\n\n let hasRelationshipDataProperty = false;\n let hasUpdatedLink = false;\n\n if (payload.meta) {\n relationship.meta = payload.meta;\n }\n\n if (payload.data !== undefined) {\n hasRelationshipDataProperty = true;\n if (isCollection) {\n // TODO deprecate this case. We\n // have tests saying we support it.\n if (payload.data === null) {\n payload.data = [];\n }\n assert(`Expected an array`, Array.isArray(payload.data));\n const cache = graph.store.cacheKeyManager;\n graph.update(\n {\n op: 'replaceRelatedRecords',\n record: identifier,\n field: op.field,\n value: upgradeIdentifiers(payload.data, cache),\n },\n true\n );\n } else {\n graph.update(\n {\n op: 'replaceRelatedRecord',\n record: identifier,\n field: op.field,\n value: payload.data\n ? graph.store.cacheKeyManager.upgradeIdentifier(payload.data as ExistingResourceIdentifierObject)\n : null,\n },\n true\n );\n }\n }\n\n if (payload.links) {\n const originalLinks = relationship.links;\n relationship.links = payload.links;\n if (payload.links.related) {\n const relatedLink = _normalizeLink(payload.links.related);\n const currentLink = originalLinks && originalLinks.related ? _normalizeLink(originalLinks.related) : null;\n const currentLinkHref = currentLink ? currentLink.href : null;\n\n if (relatedLink && relatedLink.href && relatedLink.href !== currentLinkHref) {\n // Note: the equivalent warning for this case is issued eagerly (and with a more\n // complete condition, since it also accounts for `payload.data` being present) by\n // `assertValidRelationshipPayload` in `-utils.ts`, which always runs immediately\n // before this operation in DEBUG builds. Warning here too would double-warn.\n assert(\n `You have pushed a record of type '${identifier.type}' with '${definition.key}' as a link, but the value of that link is not a string.`,\n typeof relatedLink.href === 'string' || relatedLink.href === null\n );\n hasUpdatedLink = true;\n }\n }\n }\n\n /*\n Data being pushed into the relationship might contain only data or links,\n or a combination of both.\n\n IF contains only data\n IF contains both links and data\n state.isEmpty -> true if is empty array (has-many) or is null (belongs-to)\n state.hasReceivedData -> true\n hasDematerializedInverse -> false\n state.isStale -> false\n allInverseRecordsAreLoaded -> run-check-to-determine\n\n IF contains only links\n state.isStale -> true\n */\n relationship.state.hasFailedLoadAttempt = false;\n if (hasRelationshipDataProperty) {\n const relationshipIsEmpty = payload.data === null || (Array.isArray(payload.data) && payload.data.length === 0);\n\n // we don't need to notify here as the update op we pushed in above will notify once\n // membership is in the correct state.\n relationship.state.hasReceivedData = true;\n relationship.state.hasReceivedRemoteData = true;\n relationship.state.isStale = false;\n relationship.state.hasDematerializedInverse = false;\n relationship.state.isEmpty = relationshipIsEmpty;\n } else if (hasUpdatedLink) {\n // only notify stale if we have not previously received membership data.\n // within this same transaction\n // this prevents refetching when only one side of the relationship in the\n // payload contains the info while the other side contains just a link\n // this only works when the side with just a link is a belongsTo, as we\n // don't know if a hasMany has full information or not.\n // see #7049 for context.\n if (\n isCollection ||\n !relationship.state.hasReceivedData ||\n isStaleTransaction(relationship.transactionRef, graph._transaction)\n ) {\n relationship.state.isStale = true;\n\n notifyChange(graph, relationship);\n } else {\n relationship.state.isStale = false;\n }\n }\n}\n\nfunction isStaleTransaction(relationshipTransactionId: number, graphTransactionId: number | null) {\n return (\n relationshipTransactionId === 0 || // relationship has never notified\n graphTransactionId === null || // we are not in a transaction\n relationshipTransactionId < graphTransactionId // we are not part of the current transaction\n );\n}\n\nexport function upgradeIdentifiers(\n arr: (ExistingResourceIdentifierObject | NewResourceIdentifierObject | ResourceKey)[],\n cache: CacheKeyManager\n): ResourceKey[] {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = cache.upgradeIdentifier(arr[i]);\n }\n return arr as ResourceKey[];\n}\n","import { LOG_GRAPH } from '@warp-drive/core/build-config/debugging';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport type { Store } from '../../store/-private.ts';\nimport type { NotificationChannel } from '../../store/-private/managers/notification-manager.ts';\nimport type { CacheCapabilitiesManager, ResourceKey } from '../../types.ts';\nimport { getOrSetGlobal, peekTransient, setTransient } from '../../types/-private.ts';\nimport type { RelationshipDiff } from '../../types/cache.ts';\nimport type { MergeOperation } from '../../types/cache/operations.ts';\nimport type { CollectionRelationship, ResourceRelationship } from '../../types/cache/relationship.ts';\nimport type {\n DeleteRecordOperation,\n LocalRelationshipOperation,\n RemoteRelationshipOperation,\n UnknownOperation,\n} from '../../types/graph.ts';\nimport { rollbackRelationship } from './-diff.ts';\nimport type { EdgeCache, UpgradedMeta } from './-edge-definition.ts';\nimport { isLHS, upgradeDefinition } from './-edge-definition.ts';\nimport {\n assertValidRelationshipPayload,\n checkIfNew,\n forAllRelatedIdentifiers,\n getStore,\n isBelongsTo,\n isHasMany,\n isImplicit,\n notifyChange,\n removeIdentifierCompletelyFromRelationship,\n} from './-utils.ts';\nimport { type CollectionEdge, createCollectionEdge, legacyGetCollectionRelationshipData } from './edges/collection.ts';\nimport type { ImplicitEdge, ImplicitMeta } from './edges/implicit.ts';\nimport { createImplicitEdge } from './edges/implicit.ts';\nimport { createResourceEdge, legacyGetResourceRelationshipData, type ResourceEdge } from './edges/resource.ts';\nimport addToRelatedRecords from './operations/add-to-related-records.ts';\nimport { mergeIdentifier } from './operations/merge-identifier.ts';\nimport removeFromRelatedRecords from './operations/remove-from-related-records.ts';\nimport replaceRelatedRecord from './operations/replace-related-record.ts';\nimport replaceRelatedRecords from './operations/replace-related-records.ts';\nimport updateRelationshipOperation from './operations/update-relationship.ts';\n\n/**\n * A single edge (relationship field) tracked by the {@link Graph} for a resource. Which kind of edge\n * a field is depends on its relationship definition:\n *\n * - {@link ResourceEdge}: the \"one\" side of a `belongsTo`/resource relationship\n * - {@link CollectionEdge}: the \"many\" side of a `hasMany`/collection relationship\n * - {@link ImplicitEdge}: a synthesized inverse used when a relationship has no field defined for its inverse\n */\nexport type GraphEdge = ImplicitEdge | CollectionEdge | ResourceEdge;\n\nexport const Graphs: Map<CacheCapabilitiesManager, Graph> = getOrSetGlobal(\n 'Graphs',\n new Map<CacheCapabilitiesManager, Graph>()\n);\n\ntype PendingOps = {\n belongsTo?: Map<string, Map<string, RemoteRelationshipOperation[]>>;\n hasMany?: Map<string, Map<string, RemoteRelationshipOperation[]>>;\n deletions: DeleteRecordOperation[];\n};\n\n/**\n * Graph is WarpDrive's internal, private cache of all resource relationships.\n *\n * It acts as the cache for relationship data, allowing us to ask about and update\n * relationships for a given Identifier without requiring other objects for that\n * Identifier to be instantiated (such as `RecordData` or a `Record`).\n *\n * This also allows for us to make more substantive changes to relationships\n * with increasingly minor alterations to other portions of the internals\n * over time.\n *\n * The graph is made up of nodes and edges. Each unique identifier gets\n * its own node, which is a dictionary with a list of that node's edges\n * (or connections) to other nodes. In `Model` terms, a node represents a\n * record instance, with each key (an edge) in the dictionary correlating\n * to either a `hasMany` or `belongsTo` field on that record instance.\n *\n * The value for each key, or `edge` is the identifier(s) the node relates\n * to in the graph from that key.\n */\nexport class Graph {\n /**\n * Cache of resolved {@link EdgeDefinition}s (the paired LHS/RHS relationship definitions\n * for a `type` + `key`), keyed by resource `type` and then field name. Populated lazily by\n * `upgradeDefinition` and consulted by {@link Graph.getDefinition}.\n */\n declare _definitionCache: EdgeCache;\n /**\n * Cache of the resolved {@link UpgradedMeta} for a given resource `type` and field name, as\n * returned by {@link Graph.getDefinition}. Derived from `_definitionCache` the first time a\n * field's definition is looked up.\n */\n declare _metaCache: Record<string, Record<string, UpgradedMeta>>;\n /**\n * Tracks pairs of resource types that have been discovered to be polymorphically related, so\n * that the graph can recognize this connection without needing to walk prototype/schema\n * inheritance chains. Populated by {@link Graph.registerPolymorphicType}.\n */\n declare _potentialPolymorphicTypes: Record<string, Record<string, boolean>>;\n /**\n * The nodes of the graph. Each {@link ResourceKey} maps to a dictionary of its relationship\n * fields (edges), keyed by field name.\n */\n declare identifiers: Map<ResourceKey, Record<string, GraphEdge>>;\n /**\n * The `CacheCapabilitiesManager` (store wrapper) this graph was created for. Used to schedule\n * work and to notify of relationship changes.\n */\n declare store: CacheCapabilitiesManager;\n /**\n * The real underlying `Store` instance backing {@link Graph.store}, used for capabilities\n * (such as checking whether a resource is a new/unsaved client-side record) that are not\n * exposed on `CacheCapabilitiesManager`.\n */\n declare _realStore: Store;\n /**\n * `true` once {@link Graph.destroy} has been called. After this point the graph should no\n * longer be used.\n */\n declare isDestroyed: boolean;\n /**\n * `true` when a flush of the remote-update queue has been scheduled but has not yet run.\n * Set by {@link Graph.push} and cleared by {@link Graph._flushRemoteQueue}.\n */\n declare _willSyncRemote: boolean;\n /**\n * `true` when a flush of the local-update notification queue has been scheduled but has not\n * yet run. Set by {@link Graph._scheduleLocalSync} and cleared by\n * {@link Graph._flushLocalQueue}.\n */\n declare _willSyncLocal: boolean;\n /**\n * When `true`, the next scheduled local sync will be dropped without notifying subscribers of\n * the relationships that changed. Consumed and reset by {@link Graph._flushLocalQueue}.\n */\n declare silenceNotifications: boolean;\n /**\n * Remote relationship operations and record deletions that have been pushed via\n * {@link Graph.push} but not yet flushed into the graph by {@link Graph._flushRemoteQueue}.\n */\n declare _pushedUpdates: PendingOps;\n /**\n * The {@link CollectionEdge}s that have changes pending notification, scheduled via\n * {@link Graph._scheduleLocalSync} and drained by {@link Graph._flushLocalQueue}, each\n * mapped to the {@link NotificationChannel} the notification should be scoped to —\n * `null` when it must reach every subscriber (scheduled unscoped, or scheduled for\n * both channels).\n */\n declare _updatedRelationships: Map<CollectionEdge, NotificationChannel | null>;\n /**\n * The identifier of the current remote-update transaction, or `null` when no transaction is\n * in progress. Set by {@link Graph._flushRemoteQueue} and stamped onto edges via\n * {@link Graph._addToTransaction}.\n */\n declare _transaction: number | null;\n /**\n * The {@link ResourceKey} currently being removed via {@link Graph.remove}, or `null`. Used to\n * guard against re-entrant removal of the same resource.\n */\n declare _removing: ResourceKey | null;\n\n constructor(store: CacheCapabilitiesManager) {\n this._definitionCache = Object.create(null) as EdgeCache;\n this._metaCache = Object.create(null) as Record<string, Record<string, UpgradedMeta>>;\n this._potentialPolymorphicTypes = Object.create(null) as Record<string, Record<string, boolean>>;\n this.identifiers = new Map();\n this.store = store;\n this._realStore = (store as unknown as { _store: Store })._store;\n this.isDestroyed = false;\n this._willSyncRemote = false;\n this._willSyncLocal = false;\n this._pushedUpdates = {\n belongsTo: undefined,\n hasMany: undefined,\n deletions: [],\n };\n this._updatedRelationships = new Map();\n this._transaction = null;\n this._removing = null;\n this.silenceNotifications = false;\n }\n\n /**\n * Returns `true` if an edge has already been created in the graph for the given resource and\n * field name, without creating one if it does not yet exist.\n */\n has(resourceKey: ResourceKey, propertyName: string): boolean {\n const relationships = this.identifiers.get(resourceKey);\n if (!relationships) {\n return false;\n }\n return relationships[propertyName] !== undefined;\n }\n\n /**\n * Returns the resolved {@link UpgradedMeta} (relationship definition) for the given resource\n * `type` and field name, computing and caching it via `upgradeDefinition` on first access.\n */\n getDefinition(resourceKey: ResourceKey, propertyName: string): UpgradedMeta {\n let defs = this._metaCache[resourceKey.type];\n let meta: UpgradedMeta | null | undefined = defs?.[propertyName];\n if (!meta) {\n const info = /*#__NOINLINE__*/ upgradeDefinition(this, resourceKey, propertyName);\n assert(`Could not determine relationship information for ${resourceKey.type}.${propertyName}`, info !== null);\n\n // if (info.rhs_definition?.kind === 'implicit') {\n // we should possibly also do this\n // but it would result in being extremely permissive for other relationships by accident\n // this.registerPolymorphicType(info.rhs_baseModelName, identifier.type);\n // }\n\n meta = /*#__NOINLINE__*/ isLHS(info, resourceKey.type, propertyName) ? info.lhs_definition : info.rhs_definition!;\n defs = this._metaCache[resourceKey.type] = defs || {};\n defs[propertyName] = meta;\n }\n return meta;\n }\n\n /**\n * Returns the {@link GraphEdge} for the given resource and field name, creating it (as a\n * {@link ResourceEdge}, {@link CollectionEdge}, or {@link ImplicitEdge} depending on the\n * field's kind) if it does not already exist.\n */\n get(resourceKey: ResourceKey, propertyName: string): GraphEdge {\n assert(`expected propertyName`, propertyName);\n let relationships = this.identifiers.get(resourceKey);\n if (!relationships) {\n relationships = Object.create(null) as Record<string, GraphEdge>;\n this.identifiers.set(resourceKey, relationships);\n }\n\n let relationship = relationships[propertyName];\n if (!relationship) {\n const meta = this.getDefinition(resourceKey, propertyName);\n\n if (meta.kind === 'belongsTo') {\n relationship = relationships[propertyName] = createResourceEdge(meta, resourceKey);\n } else if (meta.kind === 'hasMany') {\n relationship = relationships[propertyName] = createCollectionEdge(meta, resourceKey);\n } else {\n assert(`Expected kind to be implicit`, meta.kind === 'implicit' && meta.isImplicit === true);\n relationship = relationships[propertyName] = createImplicitEdge(meta as ImplicitMeta, resourceKey);\n }\n }\n\n return relationship;\n }\n\n /**\n * Returns the local (current, potentially dirty) JSON:API relationship data for a `belongsTo`\n * or `hasMany` field. Asserts if the field is an implicit relationship.\n */\n getData(resourceKey: ResourceKey, propertyName: string): ResourceRelationship | CollectionRelationship {\n const relationship = this.get(resourceKey, propertyName);\n\n assert(`Cannot getData() on an implicit relationship`, !isImplicit(relationship));\n\n if (isBelongsTo(relationship)) {\n return legacyGetResourceRelationshipData(relationship, false);\n }\n\n return legacyGetCollectionRelationshipData(relationship, false);\n }\n\n /**\n * Returns the remote (last known server-confirmed) JSON:API relationship data for a\n * `belongsTo` or `hasMany` field. Asserts if the field is an implicit relationship.\n */\n getRemoteData(resourceKey: ResourceKey, propertyName: string): ResourceRelationship | CollectionRelationship {\n const relationship = this.get(resourceKey, propertyName);\n\n assert(`Cannot getRemoteData() on an implicit relationship`, !isImplicit(relationship));\n\n if (isBelongsTo(relationship)) {\n return legacyGetResourceRelationshipData(relationship, true);\n }\n\n return legacyGetCollectionRelationshipData(relationship, true);\n }\n\n /**\n * Allows for the graph to dynamically discover polymorphic connections\n * without needing to walk prototype chains.\n *\n * Used by edges when an added `type` does not match the expected `type`\n * for that edge.\n *\n * Currently we assert before calling this. For a public API we will want\n * to call out to the schema manager to ask if we should consider these\n * types as equivalent for a given relationship.\n */\n registerPolymorphicType(type1: string, type2: string): void {\n const typeCache = this._potentialPolymorphicTypes;\n let t1 = typeCache[type1];\n if (!t1) {\n t1 = typeCache[type1] = Object.create(null) as Record<string, boolean>;\n }\n t1[type2] = true;\n\n let t2 = typeCache[type2];\n if (!t2) {\n t2 = typeCache[type2] = Object.create(null) as Record<string, boolean>;\n }\n t2[type1] = true;\n }\n\n /**\n * Determines whether a resource is safe to fully release from memory. A resource is not\n * releasable if it has a relationship whose inverse is async and the resource itself is not a\n * new (unsaved, client-only) record, since the inverse may still need to reference it.\n */\n isReleasable(resourceKey: ResourceKey): boolean {\n const relationships = this.identifiers.get(resourceKey);\n if (!relationships) {\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`graph: RELEASABLE ${String(resourceKey)}`);\n }\n return true;\n }\n const keys = Object.keys(relationships);\n for (let i = 0; i < keys.length; i++) {\n const relationship: GraphEdge = relationships[keys[i]];\n // account for previously unloaded relationships\n // typically from a prior deletion of a record that pointed to this one implicitly\n if (relationship === undefined) {\n continue;\n }\n assert(`Expected a relationship`, relationship);\n if (relationship.definition.inverseIsAsync && !checkIfNew(this._realStore, resourceKey)) {\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`graph: <<NOT>> RELEASABLE ${String(resourceKey)}`);\n }\n return false;\n }\n }\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`graph: RELEASABLE ${String(resourceKey)}`);\n }\n return true;\n }\n\n /**\n * Cleans up all relationships for a resource that is being dematerialized, notifying inverses\n * so they can update their own state. This retains the graph's node structure (so it can be\n * rematerialized later) except for implicit edges, which are discarded outright.\n */\n unload(resourceKey: ResourceKey, silenceNotifications?: boolean): void {\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`graph: unload ${String(resourceKey)}`);\n }\n const relationships = this.identifiers.get(resourceKey);\n\n if (relationships) {\n // cleans up the graph but retains some nodes\n // to allow for rematerialization\n Object.keys(relationships).forEach((key) => {\n const rel = relationships[key];\n if (!rel) {\n return;\n }\n /*#__NOINLINE__*/ destroyRelationship(this, rel, silenceNotifications);\n if (/*#__NOINLINE__*/ isImplicit(rel)) {\n // @ts-expect-error\n relationships[key] = undefined;\n }\n });\n }\n }\n\n /**\n * Returns `true` if the given field on a resource has uncommitted local changes: for a\n * `belongsTo` this means local and remote state differ; for a `hasMany` this means there are\n * pending additions, removals, or a reordering relative to remote state.\n */\n _isDirty(resourceKey: ResourceKey, field: string): boolean {\n const relationships = this.identifiers.get(resourceKey);\n if (!relationships) {\n return false;\n }\n const relationship = relationships[field];\n if (!relationship) {\n return false;\n }\n if (isBelongsTo(relationship)) {\n return relationship.localState !== relationship.remoteState;\n } else if (isHasMany(relationship)) {\n const hasAdditions = relationship.additions !== null && relationship.additions.size > 0;\n const hasRemovals = relationship.removals !== null && relationship.removals.size > 0;\n return hasAdditions || hasRemovals || isReordered(relationship);\n }\n return false;\n }\n\n /**\n * Builds a map, keyed by field name, of every relationship on a resource that has uncommitted\n * local changes, describing each change as a {@link RelationshipDiff}.\n */\n getChanged(resourceKey: ResourceKey): Map<string, RelationshipDiff> {\n const relationships = this.identifiers.get(resourceKey);\n const changed = new Map<string, RelationshipDiff>();\n\n if (!relationships) {\n return changed;\n }\n\n const keys = Object.keys(relationships);\n for (let i = 0; i < keys.length; i++) {\n const field = keys[i];\n const relationship = relationships[field];\n if (!relationship) {\n continue;\n }\n if (isBelongsTo(relationship)) {\n if (relationship.localState !== relationship.remoteState) {\n changed.set(field, {\n kind: 'resource',\n remoteState: relationship.remoteState,\n localState: relationship.localState,\n });\n }\n } else if (isHasMany(relationship)) {\n const hasAdditions = relationship.additions !== null && relationship.additions.size > 0;\n const hasRemovals = relationship.removals !== null && relationship.removals.size > 0;\n const reordered = isReordered(relationship);\n\n if (hasAdditions || hasRemovals || reordered) {\n changed.set(field, {\n kind: 'collection',\n additions: new Set(relationship.additions),\n removals: new Set(relationship.removals),\n remoteState: relationship.remoteState,\n localState: legacyGetCollectionRelationshipData(relationship, false).data || [],\n reordered,\n });\n }\n }\n }\n\n return changed;\n }\n\n /**\n * Returns `true` if any relationship field on the resource has uncommitted local changes.\n */\n hasChanged(resourceKey: ResourceKey): boolean {\n const relationships = this.identifiers.get(resourceKey);\n if (!relationships) {\n return false;\n }\n const keys = Object.keys(relationships);\n for (let i = 0; i < keys.length; i++) {\n if (this._isDirty(resourceKey, keys[i])) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Reverts all locally dirty relationships on a resource back to their remote state, returning\n * the list of field names that were rolled back.\n */\n rollback(resourceKey: ResourceKey): string[] {\n const relationships = this.identifiers.get(resourceKey);\n const changed: string[] = [];\n if (!relationships) {\n return changed;\n }\n const keys = Object.keys(relationships);\n for (let i = 0; i < keys.length; i++) {\n const field = keys[i];\n const relationship = relationships[field];\n if (!relationship) {\n continue;\n }\n\n if (this._isDirty(resourceKey, field)) {\n rollbackRelationship(this, resourceKey, field, relationship as CollectionEdge | ResourceEdge);\n changed.push(field);\n }\n }\n\n return changed;\n }\n\n /**\n * Fully removes a resource and all of its relationships from the graph, unloading its edges\n * first so inverses are properly notified/cleaned up.\n */\n remove(resourceKey: ResourceKey): void {\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`graph: remove ${String(resourceKey)}`);\n }\n assert(`Cannot remove ${String(resourceKey)} while still removing ${String(this._removing)}`, !this._removing);\n this._removing = resourceKey;\n this.unload(resourceKey);\n this.identifiers.delete(resourceKey);\n this._removing = null;\n }\n\n /**\n * Queues a remote relationship operation (or record deletion) to be applied to the graph.\n * Pushed operations are batched and flushed asynchronously (see {@link Graph._flushRemoteQueue})\n * rather than applied immediately.\n */\n push(op: RemoteRelationshipOperation): void {\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`graph: push ${String(op.record)}`, op);\n }\n if (op.op === 'deleteRecord') {\n this._pushedUpdates.deletions.push(op);\n } else {\n const definition = this.getDefinition(op.record, op.field);\n assert(`Cannot push a remote update for an implicit relationship`, definition.kind !== 'implicit');\n addPending(this._pushedUpdates, definition, op);\n }\n if (!this._willSyncRemote) {\n this._willSyncRemote = true;\n const store = getStore(this.store);\n if (!store._cbs) {\n store._run(() => this._flushRemoteQueue());\n } else {\n store._schedule('coalesce', () => this._flushRemoteQueue());\n }\n }\n }\n\n /**\n * Applies a remote relationship operation or identifier merge directly to the graph. Pass\n * `isRemote: true` to indicate the operation represents confirmed server state rather than a\n * local (client-side) change.\n */\n update(op: RemoteRelationshipOperation | MergeOperation, isRemote: true): void;\n /**\n * Applies a local (client-side) relationship operation directly to the graph, such as adding,\n * removing, or replacing related records before it has been confirmed by the server.\n */\n update(op: LocalRelationshipOperation, isRemote?: false): void;\n /**\n * Implementation for both the remote and local {@link Graph.update} overloads: dispatches the\n * given operation (`mergeIdentifiers`, `updateRelationship`, `deleteRecord`, `add`, `remove`,\n * `replaceRelatedRecord`, or `replaceRelatedRecords`) to the appropriate handler.\n */\n update(\n op: MergeOperation | LocalRelationshipOperation | RemoteRelationshipOperation | UnknownOperation,\n isRemote = false\n ): void {\n assert(\n `Cannot update an implicit relationship`,\n op.op === 'deleteRecord' || op.op === 'mergeIdentifiers' || !isImplicit(this.get(op.record, op.field))\n );\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`graph: update (${isRemote ? 'remote' : 'local'}) ${String(op.record)}`, op);\n }\n\n switch (op.op) {\n case 'mergeIdentifiers': {\n const relationships = this.identifiers.get(op.record);\n if (relationships) {\n /*#__NOINLINE__*/ mergeIdentifier(this, op, relationships);\n }\n break;\n }\n case 'update':\n case 'updateRelationship':\n assert(`Can only perform the operation updateRelationship on remote state`, isRemote);\n if (DEBUG) {\n // in debug, assert payload validity eagerly\n // TODO add deprecations/assertion here for duplicates\n assertValidRelationshipPayload(this, op);\n }\n /*#__NOINLINE__*/ updateRelationshipOperation(this, op);\n break;\n case 'deleteRecord': {\n assert(`Can only perform the operation deleteRelationship on remote state`, isRemote);\n const identifier = op.record;\n const relationships = this.identifiers.get(identifier);\n\n if (relationships) {\n Object.keys(relationships).forEach((key) => {\n const rel = relationships[key];\n if (!rel) {\n return;\n }\n // works together with the has check\n // @ts-expect-error\n relationships[key] = undefined;\n /*#__NOINLINE__*/ removeCompletelyFromInverse(this, rel);\n });\n this.identifiers.delete(identifier);\n }\n break;\n }\n case 'replaceRelatedRecord':\n /*#__NOINLINE__*/ replaceRelatedRecord(this, op, isRemote);\n break;\n case 'add':\n /*#__NOINLINE__*/ addToRelatedRecords(this, op, isRemote);\n break;\n case 'remove':\n /*#__NOINLINE__*/ removeFromRelatedRecords(this, op, isRemote);\n break;\n case 'replaceRelatedRecords':\n /*#__NOINLINE__*/ replaceRelatedRecords(this, op, isRemote);\n break;\n default:\n assert(`No local relationship update operation exists for '${op.op}'`);\n }\n }\n\n /**\n * Marks a {@link CollectionEdge} as having changes that need to be notified on the given\n * {@link NotificationChannel} (omitted = unscoped, reaching every subscriber), and schedules\n * a flush of the sync queue (see {@link Graph._flushLocalQueue}) if one is not already\n * pending. Scheduling the same edge for both channels (or once unscoped) coalesces into a\n * single unscoped notification.\n */\n _scheduleLocalSync(relationship: CollectionEdge, channel?: NotificationChannel): void {\n const pending = this._updatedRelationships;\n if (!pending.has(relationship)) {\n pending.set(relationship, channel ?? null);\n } else if (pending.get(relationship) !== (channel ?? null)) {\n // two different scopes (or a scope + unscoped) for the same edge merge\n // into one unscoped notification rather than notifying twice.\n pending.set(relationship, null);\n }\n if (!this._willSyncLocal) {\n this._willSyncLocal = true;\n getStore(this.store)._schedule('sync', () => this._flushLocalQueue());\n }\n }\n\n /**\n * Flushes all remote operations queued via {@link Graph.push}, applying them within a single\n * transaction (see {@link Graph._transaction} and {@link Graph._addToTransaction}) so that\n * dependent edges updated during the flush can be distinguished from those that were not.\n */\n _flushRemoteQueue(): void {\n if (!this._willSyncRemote) {\n return;\n }\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.groupCollapsed(`Graph: Initialized Transaction`);\n }\n let transactionRef = peekTransient<number>('transactionRef') ?? 0;\n this._transaction = ++transactionRef;\n setTransient('transactionRef', transactionRef);\n this._willSyncRemote = false;\n const updates = this._pushedUpdates;\n const { deletions, hasMany, belongsTo } = updates;\n updates.deletions = [];\n updates.hasMany = undefined;\n updates.belongsTo = undefined;\n\n for (let i = 0; i < deletions.length; i++) {\n this.update(deletions[i], true);\n }\n\n if (hasMany) {\n flushPending(this, hasMany);\n }\n if (belongsTo) {\n flushPending(this, belongsTo);\n }\n\n this._transaction = null;\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`Graph: transaction finalized`);\n // oxlint-disable-next-line no-console\n console.groupEnd();\n }\n }\n\n /**\n * Stamps the current remote-update transaction id onto an edge, marking it as having been\n * touched during the in-progress {@link Graph._flushRemoteQueue} run. Must only be called while\n * a transaction is active.\n */\n _addToTransaction(relationship: CollectionEdge | ResourceEdge): void {\n assert(`expected a transaction`, this._transaction !== null);\n if (LOG_GRAPH) {\n // oxlint-disable-next-line no-console\n console.log(`Graph: ${String(relationship.identifier)} ${relationship.definition.key} added to transaction`);\n }\n relationship.transactionRef = this._transaction;\n }\n\n /**\n * Flushes the queue of relationships scheduled via {@link Graph._scheduleLocalSync}, notifying\n * subscribers of each changed relationship — unless {@link Graph.silenceNotifications} is set,\n * in which case the queue is discarded without notifying.\n */\n _flushLocalQueue(): void {\n if (!this._willSyncLocal) {\n return;\n }\n\n if (this.silenceNotifications) {\n this.silenceNotifications = false;\n this._updatedRelationships = new Map();\n return;\n }\n\n this._willSyncLocal = false;\n const updated = this._updatedRelationships;\n this._updatedRelationships = new Map();\n updated.forEach((channel, rel) => notifyChange(this, rel, channel ?? undefined));\n }\n\n /**\n * Tears down the graph: clears all tracked identifiers/edges, removes it from the global\n * {@link Graphs} registry, and marks it as destroyed. In debug builds this also asserts that no\n * other live, non-destroying graphs remain registered, to help catch memory leaks from\n * improperly torn down store instances.\n */\n destroy(): void {\n Graphs.delete(this.store);\n\n if (DEBUG) {\n Graphs.delete(getStore(this.store) as unknown as CacheCapabilitiesManager);\n if (Graphs.size) {\n Graphs.forEach((_, key) => {\n assert(\n `Memory Leak Detected, likely the test or app instance previous to this was not torn down properly`,\n !(key as unknown as { isDestroyed: boolean }).isDestroyed &&\n !(key as unknown as { isDestroying: boolean }).isDestroying\n );\n });\n }\n }\n\n this.identifiers.clear();\n this.store = null as unknown as CacheCapabilitiesManager;\n this.isDestroyed = true;\n }\n}\n\nfunction flushPending(graph: Graph, ops: Map<string, Map<string, RemoteRelationshipOperation[]>>) {\n for (const type of ops.values()) {\n for (const opList of type.values()) {\n flushPendingList(graph, opList);\n }\n }\n}\nfunction flushPendingList(graph: Graph, opList: RemoteRelationshipOperation[]) {\n for (let i = 0; i < opList.length; i++) {\n graph.update(opList[i], true);\n }\n}\n\n// Handle dematerialization for relationship `rel`. In all cases, notify the\n// relationship of the dematerialization: this is done so the relationship can\n// notify its inverse which needs to update state\n//\n// If the inverse is sync, unloading this record is treated as a client-side\n// delete, so we remove the inverse records from this relationship to\n// disconnect the graph. Because it's not async, we don't need to keep around\n// the identifier as an id-wrapper for references\nfunction destroyRelationship(graph: Graph, rel: GraphEdge, silenceNotifications?: boolean) {\n if (isImplicit(rel)) {\n if (graph.isReleasable(rel.identifier)) {\n /*#__NOINLINE__*/ removeCompletelyFromInverse(graph, rel);\n }\n return;\n }\n\n const { identifier } = rel;\n const { inverseKey } = rel.definition;\n\n if (!rel.definition.inverseIsImplicit) {\n /*#__NOINLINE__*/ forAllRelatedIdentifiers(rel, (inverseIdentifer: ResourceKey) =>\n /*#__NOINLINE__*/ notifyInverseOfDematerialization(\n graph,\n inverseIdentifer,\n inverseKey,\n identifier,\n silenceNotifications\n )\n );\n }\n\n if (!rel.definition.inverseIsImplicit && !rel.definition.inverseIsAsync) {\n rel.state.isStale = true;\n /*#__NOINLINE__*/ clearRelationship(rel);\n\n // necessary to clear relationships in the ui from dematerialized records\n // hasMany is managed by Model which calls `retreiveLatest` after\n // dematerializing the resource-cache instance.\n // but sync belongsTo requires this since they don't have a proxy to update.\n // so we have to notify so it will \"update\" to null.\n // we should discuss whether we still care about this, probably fine to just\n // leave the ui relationship populated since the record is destroyed and\n // internally we've fully cleaned up.\n if (!rel.definition.isAsync && !silenceNotifications) {\n /*#__NOINLINE__*/ notifyChange(graph, rel);\n }\n }\n}\n\nfunction notifyInverseOfDematerialization(\n graph: Graph,\n inverseIdentifier: ResourceKey,\n inverseKey: string,\n resourceKey: ResourceKey,\n silenceNotifications?: boolean\n) {\n if (!graph.has(inverseIdentifier, inverseKey)) {\n return;\n }\n\n const relationship = graph.get(inverseIdentifier, inverseKey);\n assert(`expected no implicit`, !isImplicit(relationship));\n\n // For remote members, it is possible that inverseRecordData has already been associated to\n // to another record. For such cases, do not dematerialize the inverseRecordData\n if (!isBelongsTo(relationship) || !relationship.localState || resourceKey === relationship.localState) {\n /*#__NOINLINE__*/ removeDematerializedInverse(graph, relationship, resourceKey, silenceNotifications);\n }\n}\n\nfunction clearRelationship(relationship: CollectionEdge | ResourceEdge) {\n if (isBelongsTo(relationship)) {\n relationship.localState = null;\n relationship.remoteState = null;\n relationship.state.hasReceivedData = false;\n relationship.state.isEmpty = true;\n } else {\n relationship.remoteMembers.clear();\n relationship.remoteState = [];\n relationship.additions = null;\n relationship.removals = null;\n relationship.localState = null;\n }\n}\n\nfunction removeDematerializedInverse(\n graph: Graph,\n relationship: CollectionEdge | ResourceEdge,\n inverseIdentifier: ResourceKey,\n silenceNotifications?: boolean\n) {\n if (isBelongsTo(relationship)) {\n const localInverse = relationship.localState;\n if (!relationship.definition.isAsync || (localInverse && checkIfNew(graph._realStore, localInverse))) {\n // unloading inverse of a sync relationship is treated as a client-side\n // delete, so actually remove the models don't merely invalidate the cp\n // cache.\n // if the record being unloaded only exists on the client, we similarly\n // treat it as a client side delete\n if (relationship.localState === localInverse && localInverse !== null) {\n relationship.localState = null;\n }\n\n if (relationship.remoteState === localInverse && localInverse !== null) {\n relationship.remoteState = null;\n relationship.state.hasReceivedData = true;\n relationship.state.isEmpty = true;\n if (relationship.localState && !checkIfNew(graph._realStore, relationship.localState)) {\n relationship.localState = null;\n }\n }\n } else {\n relationship.state.hasDematerializedInverse = true;\n }\n\n if (!silenceNotifications) {\n notifyChange(graph, relationship);\n }\n } else {\n if (!relationship.definition.isAsync || (inverseIdentifier && checkIfNew(graph._realStore, inverseIdentifier))) {\n // unloading inverse of a sync relationship is treated as a client-side\n // delete, so actually remove the models don't merely invalidate the cp\n // cache.\n // if the record being unloaded only exists on the client, we similarly\n // treat it as a client side delete\n /*#__NOINLINE__*/ removeIdentifierCompletelyFromRelationship(graph, relationship, inverseIdentifier);\n } else {\n relationship.state.hasDematerializedInverse = true;\n }\n\n if (!silenceNotifications) {\n notifyChange(graph, relationship);\n }\n }\n}\n\nfunction removeCompletelyFromInverse(graph: Graph, relationship: GraphEdge) {\n const { identifier } = relationship;\n const { inverseKey } = relationship.definition;\n\n forAllRelatedIdentifiers(relationship, (inverseIdentifier: ResourceKey) => {\n if (graph.has(inverseIdentifier, inverseKey)) {\n removeIdentifierCompletelyFromRelationship(graph, graph.get(inverseIdentifier, inverseKey), identifier);\n }\n });\n\n if (isBelongsTo(relationship)) {\n if (!relationship.definition.isAsync) {\n clearRelationship(relationship);\n }\n\n relationship.localState = null;\n } else if (isHasMany(relationship)) {\n if (!relationship.definition.isAsync) {\n clearRelationship(relationship);\n\n notifyChange(graph, relationship);\n }\n } else {\n relationship.remoteMembers.clear();\n relationship.localMembers.clear();\n }\n}\n\nfunction addPending(\n cache: PendingOps,\n definition: UpgradedMeta,\n op: RemoteRelationshipOperation & { field: string }\n): void {\n const cacheForKind = (cache[definition.kind as 'hasMany' | 'belongsTo'] =\n cache[definition.kind as 'hasMany' | 'belongsTo'] || new Map<string, Map<string, RemoteRelationshipOperation[]>>());\n\n let cacheForType = cacheForKind.get(definition.inverseType);\n if (!cacheForType) {\n cacheForType = new Map<string, RemoteRelationshipOperation[]>();\n cacheForKind.set(definition.inverseType, cacheForType);\n }\n\n let cacheForField = cacheForType.get(op.field);\n if (!cacheForField) {\n cacheForField = [];\n cacheForType.set(op.field, cacheForField);\n }\n\n cacheForField.push(op);\n}\n\nfunction isReordered(relationship: CollectionEdge): boolean {\n // if we are dirty we are never re-ordered because accessing\n // the state would flush away any reordering.\n if (relationship.isDirty) {\n return false;\n }\n\n const { remoteState, localState, additions, removals } = relationship;\n\n if (localState === null) {\n // the relationship has never been accessed, so it hasn't been reordered either\n return false;\n }\n\n for (let i = 0, j = 0; i < remoteState.length; i++) {\n const member = remoteState[i];\n const localMember = localState[j];\n\n if (member !== localMember) {\n if (removals && removals.has(member)) {\n // dont increment j because we want to skip this\n continue;\n }\n if (additions && additions.has(localMember)) {\n // increment j to skip this localMember\n // decrement i to repeat this remoteMember\n j++;\n i--;\n continue;\n }\n return true;\n }\n\n // if we made it here, increment j\n j++;\n }\n\n return false;\n}\n","/**\nProvides a performance tuned normalized graph for intelligently managing relationships between resources based on identity\n\nWhile this Graph is abstract, it currently is a private implementation required as a peer-dependency by the {json:api} Cache Implementation.\n\nWe intend to make this Graph public API after some additional iteration during the 5.x timeframe, until then all APIs should be considered experimental and unstable, not fit for direct application or 3rd party library usage.\n\n @module\n*/\nimport { DEBUG } from '@warp-drive/core/build-config/env';\n\nimport type { Store } from '../index.ts';\nimport type { CacheCapabilitiesManager } from '../types.ts';\nimport { getStore } from './-private/-utils.ts';\nimport { Graph, Graphs } from './-private/graph.ts';\n\nexport { isBelongsTo } from './-private/-utils.ts';\nexport type { CollectionEdge } from './-private/edges/collection.ts';\nexport type { ResourceEdge } from './-private/edges/resource.ts';\nexport type { ImplicitEdge } from './-private/edges/implicit.ts';\nexport type { GraphEdge } from './-private/graph.ts';\nexport type { UpgradedMeta } from './-private/-edge-definition.ts';\nexport type { Graph };\n\nfunction isStore(maybeStore: unknown): maybeStore is Store {\n return (maybeStore as Store)._instanceCache !== undefined;\n}\n\nfunction getWrapper(store: CacheCapabilitiesManager | Store): CacheCapabilitiesManager {\n return isStore(store) ? store._instanceCache._storeWrapper : store;\n}\n\n/** Returns the {@link Graph} associated with the given store or capabilities manager, if one has been created. */\nexport function peekGraph(store: CacheCapabilitiesManager | Store): Graph | undefined {\n return Graphs.get(getWrapper(store));\n}\n/** The type of the {@link peekGraph} function. */\nexport type peekGraph = typeof peekGraph;\n\n/** Returns the {@link Graph} for the given store, creating (and caching) one first if it does not yet exist. */\nexport function graphFor(store: CacheCapabilitiesManager | Store): Graph {\n const wrapper = getWrapper(store);\n let graph = Graphs.get(wrapper);\n\n if (!graph) {\n graph = new Graph(wrapper);\n Graphs.set(wrapper, graph);\n getStore(wrapper)._graph = graph;\n\n if (DEBUG) {\n if (getStore(wrapper).isDestroying) {\n throw new Error(`Memory Leak Detected During Teardown`);\n }\n }\n }\n return graph;\n}\n"],"mappings":";;;;;AAaA,SAAgBG,SAASC,IAA8B;CACrD,IAAAF,eAAAD,gBAAA,CAAA,CAAAI,UAAAC,aAAAC,uBAAA,GAA6B;EAC3B,IAAIC;EACJ,IAAIJ,OAAO,QAAQA,OAAOK,UAAaL,OAAO,IAC5CI,aAAa;OAEbA,aAAaE,OAAON,EAAE;EAGxBJ,UACE,qBAAqB,OAAOI,GAAE,IAAKM,OACjCN,EACF,EAAC,6DAA8DO,KAAKC,UAAUJ,UAAU,EAAC,aACzFA,eAAeJ,IACf;GACEA,IAAI;GACJS,OAAO;GACPC,KAAK;GACLC,OAAO;IACLC,WAAW;IACXC,SAAS;GACX;EACF,CACF;EAEA,OAAOT;CACT;CAEAN,eAAAD,gBAAA,CAAA,CAAAI,UAAAa,IAAAC,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