@graphql-box/cache-manager 4.1.4 → 5.0.0

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 (334) hide show
  1. package/README.md +1 -5
  2. package/dist/cjs/index.cjs +1477 -0
  3. package/dist/cjs/index.cjs.map +1 -0
  4. package/{lib/module/main/index.js → dist/esm/index.mjs} +734 -331
  5. package/dist/esm/index.mjs.map +1 -0
  6. package/dist/types/cjs/constants.d.cts +6 -0
  7. package/dist/types/cjs/constants.d.cts.map +1 -0
  8. package/dist/types/cjs/debug/index.d.cts +4 -0
  9. package/dist/types/cjs/debug/index.d.cts.map +1 -0
  10. package/dist/types/cjs/debug/logCacheEntry.d.cts +8 -0
  11. package/dist/types/cjs/debug/logCacheEntry.d.cts.map +1 -0
  12. package/dist/types/cjs/debug/logCacheQuery.d.cts +8 -0
  13. package/dist/types/cjs/debug/logCacheQuery.d.cts.map +1 -0
  14. package/dist/types/cjs/debug/logPartialCompiled.d.cts +6 -0
  15. package/dist/types/cjs/debug/logPartialCompiled.d.cts.map +1 -0
  16. package/dist/types/cjs/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.cts +3 -0
  17. package/dist/types/cjs/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.cts.map +1 -0
  18. package/dist/types/cjs/helpers/checkFieldPathChecklist.d.cts +3 -0
  19. package/dist/types/cjs/helpers/checkFieldPathChecklist.d.cts.map +1 -0
  20. package/dist/types/cjs/helpers/combineData.d.cts +2 -0
  21. package/dist/types/cjs/helpers/combineData.d.cts.map +1 -0
  22. package/dist/types/cjs/helpers/createFragmentSpreadChecklist.d.cts +9 -0
  23. package/dist/types/cjs/helpers/createFragmentSpreadChecklist.d.cts.map +1 -0
  24. package/dist/types/cjs/helpers/deriveOpCacheability.d.cts +9 -0
  25. package/dist/types/cjs/helpers/deriveOpCacheability.d.cts.map +1 -0
  26. package/dist/types/cjs/helpers/filterField.d.cts +5 -0
  27. package/dist/types/cjs/helpers/filterField.d.cts.map +1 -0
  28. package/dist/types/cjs/helpers/filterFragmentDefinitions.d.cts +5 -0
  29. package/dist/types/cjs/helpers/filterFragmentDefinitions.d.cts.map +1 -0
  30. package/dist/types/cjs/helpers/filterFragmentSpreads.d.cts +5 -0
  31. package/dist/types/cjs/helpers/filterFragmentSpreads.d.cts.map +1 -0
  32. package/dist/types/cjs/helpers/filterIDsAndTypeNames.d.cts +4 -0
  33. package/dist/types/cjs/helpers/filterIDsAndTypeNames.d.cts.map +1 -0
  34. package/dist/types/cjs/helpers/filterInlineFragments.d.cts +4 -0
  35. package/dist/types/cjs/helpers/filterInlineFragments.d.cts.map +1 -0
  36. package/dist/types/cjs/helpers/filterOperationAndFragmentDefinitions.d.cts +3 -0
  37. package/dist/types/cjs/helpers/filterOperationAndFragmentDefinitions.d.cts.map +1 -0
  38. package/dist/types/cjs/helpers/filterOutPropsWithArgsOrDirectives.d.cts +6 -0
  39. package/dist/types/cjs/helpers/filterOutPropsWithArgsOrDirectives.d.cts.map +1 -0
  40. package/dist/types/cjs/helpers/filterQuery.d.cts +4 -0
  41. package/dist/types/cjs/helpers/filterQuery.d.cts.map +1 -0
  42. package/dist/types/cjs/helpers/getDataValue.d.cts +2 -0
  43. package/dist/types/cjs/helpers/getDataValue.d.cts.map +1 -0
  44. package/dist/types/cjs/helpers/hasTypename.d.cts +3 -0
  45. package/dist/types/cjs/helpers/hasTypename.d.cts.map +1 -0
  46. package/dist/types/cjs/helpers/isFirstResponseChunk.d.cts +4 -0
  47. package/dist/types/cjs/helpers/isFirstResponseChunk.d.cts.map +1 -0
  48. package/dist/types/cjs/helpers/isLastResponseChunk.d.cts +4 -0
  49. package/dist/types/cjs/helpers/isLastResponseChunk.d.cts.map +1 -0
  50. package/dist/types/cjs/helpers/isNotLastResponseChunk.d.cts +4 -0
  51. package/dist/types/cjs/helpers/isNotLastResponseChunk.d.cts.map +1 -0
  52. package/dist/types/cjs/helpers/isNotResponseChunk.d.cts +4 -0
  53. package/dist/types/cjs/helpers/isNotResponseChunk.d.cts.map +1 -0
  54. package/dist/types/cjs/helpers/mergeObjects.d.cts +2 -0
  55. package/dist/types/cjs/helpers/mergeObjects.d.cts.map +1 -0
  56. package/dist/types/cjs/helpers/mergeResponseDataSets.d.cts +3 -0
  57. package/dist/types/cjs/helpers/mergeResponseDataSets.d.cts.map +1 -0
  58. package/dist/types/cjs/helpers/normalizePatchResponseData.d.cts +11 -0
  59. package/dist/types/cjs/helpers/normalizePatchResponseData.d.cts.map +1 -0
  60. package/dist/types/cjs/helpers/validTypeIdValue.d.cts +3 -0
  61. package/dist/types/cjs/helpers/validTypeIdValue.d.cts.map +1 -0
  62. package/dist/types/cjs/index.d.cts +3 -0
  63. package/dist/types/cjs/index.d.cts.map +1 -0
  64. package/dist/types/cjs/main.d.cts +63 -0
  65. package/dist/types/cjs/main.d.cts.map +1 -0
  66. package/dist/types/cjs/types.d.cts +131 -0
  67. package/dist/types/cjs/types.d.cts.map +1 -0
  68. package/dist/types/esm/constants.d.ts +6 -0
  69. package/dist/types/esm/constants.d.ts.map +1 -0
  70. package/dist/types/esm/debug/index.d.ts +4 -0
  71. package/dist/types/esm/debug/index.d.ts.map +1 -0
  72. package/dist/types/esm/debug/logCacheEntry.d.ts +8 -0
  73. package/dist/types/esm/debug/logCacheEntry.d.ts.map +1 -0
  74. package/dist/types/esm/debug/logCacheQuery.d.ts +8 -0
  75. package/dist/types/esm/debug/logCacheQuery.d.ts.map +1 -0
  76. package/dist/types/esm/debug/logPartialCompiled.d.ts +6 -0
  77. package/dist/types/esm/debug/logPartialCompiled.d.ts.map +1 -0
  78. package/dist/types/esm/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts +3 -0
  79. package/dist/types/esm/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts.map +1 -0
  80. package/dist/types/esm/helpers/checkFieldPathChecklist.d.ts +3 -0
  81. package/dist/types/esm/helpers/checkFieldPathChecklist.d.ts.map +1 -0
  82. package/dist/types/esm/helpers/combineData.d.ts +2 -0
  83. package/dist/types/esm/helpers/combineData.d.ts.map +1 -0
  84. package/dist/types/esm/helpers/createFragmentSpreadChecklist.d.ts +9 -0
  85. package/dist/types/esm/helpers/createFragmentSpreadChecklist.d.ts.map +1 -0
  86. package/dist/types/esm/helpers/deriveOpCacheability.d.ts +9 -0
  87. package/dist/types/esm/helpers/deriveOpCacheability.d.ts.map +1 -0
  88. package/dist/types/esm/helpers/filterField.d.ts +5 -0
  89. package/dist/types/esm/helpers/filterField.d.ts.map +1 -0
  90. package/dist/types/esm/helpers/filterFragmentDefinitions.d.ts +5 -0
  91. package/dist/types/esm/helpers/filterFragmentDefinitions.d.ts.map +1 -0
  92. package/dist/types/esm/helpers/filterFragmentSpreads.d.ts +5 -0
  93. package/dist/types/esm/helpers/filterFragmentSpreads.d.ts.map +1 -0
  94. package/dist/types/esm/helpers/filterIDsAndTypeNames.d.ts +4 -0
  95. package/dist/types/esm/helpers/filterIDsAndTypeNames.d.ts.map +1 -0
  96. package/dist/types/esm/helpers/filterInlineFragments.d.ts +4 -0
  97. package/dist/types/esm/helpers/filterInlineFragments.d.ts.map +1 -0
  98. package/dist/types/esm/helpers/filterOperationAndFragmentDefinitions.d.ts +3 -0
  99. package/dist/types/esm/helpers/filterOperationAndFragmentDefinitions.d.ts.map +1 -0
  100. package/dist/types/esm/helpers/filterOutPropsWithArgsOrDirectives.d.ts +6 -0
  101. package/dist/types/esm/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +1 -0
  102. package/dist/types/esm/helpers/filterQuery.d.ts +4 -0
  103. package/dist/types/esm/helpers/filterQuery.d.ts.map +1 -0
  104. package/dist/types/esm/helpers/getDataValue.d.ts +2 -0
  105. package/dist/types/esm/helpers/getDataValue.d.ts.map +1 -0
  106. package/dist/types/esm/helpers/hasTypename.d.ts +3 -0
  107. package/dist/types/esm/helpers/hasTypename.d.ts.map +1 -0
  108. package/dist/types/esm/helpers/isFirstResponseChunk.d.ts +4 -0
  109. package/dist/types/esm/helpers/isFirstResponseChunk.d.ts.map +1 -0
  110. package/dist/types/esm/helpers/isLastResponseChunk.d.ts +4 -0
  111. package/dist/types/esm/helpers/isLastResponseChunk.d.ts.map +1 -0
  112. package/dist/types/esm/helpers/isNotLastResponseChunk.d.ts +4 -0
  113. package/dist/types/esm/helpers/isNotLastResponseChunk.d.ts.map +1 -0
  114. package/dist/types/esm/helpers/isNotResponseChunk.d.ts +4 -0
  115. package/dist/types/esm/helpers/isNotResponseChunk.d.ts.map +1 -0
  116. package/dist/types/esm/helpers/mergeObjects.d.ts +2 -0
  117. package/dist/types/esm/helpers/mergeObjects.d.ts.map +1 -0
  118. package/dist/types/esm/helpers/mergeResponseDataSets.d.ts +3 -0
  119. package/dist/types/esm/helpers/mergeResponseDataSets.d.ts.map +1 -0
  120. package/dist/types/esm/helpers/normalizePatchResponseData.d.ts +11 -0
  121. package/dist/types/esm/helpers/normalizePatchResponseData.d.ts.map +1 -0
  122. package/dist/types/esm/helpers/validTypeIdValue.d.ts +3 -0
  123. package/dist/types/esm/helpers/validTypeIdValue.d.ts.map +1 -0
  124. package/dist/types/esm/index.d.ts +3 -0
  125. package/dist/types/esm/index.d.ts.map +1 -0
  126. package/{lib/types/main/index.d.ts → dist/types/esm/main.d.ts} +6 -7
  127. package/dist/types/esm/main.d.ts.map +1 -0
  128. package/{lib/types/defs/index.d.ts → dist/types/esm/types.d.ts} +26 -26
  129. package/dist/types/esm/types.d.ts.map +1 -0
  130. package/dist/types/tsconfig.build.tsbuildinfo +1 -0
  131. package/package.json +54 -39
  132. package/src/__snapshots__/index.test.ts.snap +16531 -16531
  133. package/src/constants.ts +6 -0
  134. package/src/debug/index.ts +3 -3
  135. package/src/debug/logCacheEntry.ts +54 -0
  136. package/src/debug/{log-cache-query/index.ts → logCacheQuery.ts} +23 -20
  137. package/src/debug/logPartialCompiled.ts +41 -0
  138. package/src/helpers/areOnlyPopulatedFieldsTypeIdKeys.ts +19 -12
  139. package/src/helpers/checkFieldPathChecklist.ts +9 -7
  140. package/src/helpers/combineData.ts +14 -0
  141. package/src/helpers/createFragmentSpreadChecklist.ts +11 -10
  142. package/src/helpers/deriveOpCacheability.ts +10 -6
  143. package/src/helpers/filterField.ts +28 -21
  144. package/src/helpers/filterFragmentDefinitions.ts +35 -21
  145. package/src/helpers/filterFragmentSpreads.ts +17 -12
  146. package/src/helpers/filterIDsAndTypeNames.ts +15 -11
  147. package/src/helpers/filterInlineFragments.ts +13 -11
  148. package/src/helpers/filterOperationAndFragmentDefinitions.ts +5 -5
  149. package/src/helpers/filterOutPropsWithArgsOrDirectives.ts +10 -10
  150. package/src/helpers/filterQuery.ts +21 -12
  151. package/src/helpers/getDataValue.ts +14 -0
  152. package/src/helpers/hasTypename.ts +11 -0
  153. package/src/helpers/isFirstResponseChunk.ts +6 -4
  154. package/src/helpers/isLastResponseChunk.ts +6 -4
  155. package/src/helpers/isNotLastResponseChunk.ts +6 -4
  156. package/src/helpers/isNotResponseChunk.ts +6 -4
  157. package/src/helpers/mergeObjects.ts +7 -0
  158. package/src/helpers/mergeResponseDataSets.ts +8 -8
  159. package/src/helpers/normalizePatchResponseData.ts +12 -5
  160. package/src/helpers/validTypeIdValue.ts +18 -0
  161. package/src/index.test.ts +479 -450
  162. package/src/index.ts +2 -2
  163. package/src/{main/index.ts → main.ts} +287 -260
  164. package/src/{defs/index.ts → types.ts} +38 -43
  165. package/tsconfig.build.json +10 -0
  166. package/tsconfig.json +17 -0
  167. package/lib/browser/index.js +0 -2
  168. package/lib/browser/index.js.map +0 -1
  169. package/lib/browser/production.analysis.txt +0 -234
  170. package/lib/main/consts/index.js +0 -17
  171. package/lib/main/consts/index.js.map +0 -1
  172. package/lib/main/debug/index.js +0 -32
  173. package/lib/main/debug/index.js.map +0 -1
  174. package/lib/main/debug/log-cache-entry/index.js +0 -57
  175. package/lib/main/debug/log-cache-entry/index.js.map +0 -1
  176. package/lib/main/debug/log-cache-query/index.js +0 -59
  177. package/lib/main/debug/log-cache-query/index.js.map +0 -1
  178. package/lib/main/debug/log-partial-compiled/index.js +0 -50
  179. package/lib/main/debug/log-partial-compiled/index.js.map +0 -1
  180. package/lib/main/defs/index.js +0 -2
  181. package/lib/main/defs/index.js.map +0 -1
  182. package/lib/main/helpers/areOnlyPopulatedFieldsTypeIdKeys.js +0 -53
  183. package/lib/main/helpers/areOnlyPopulatedFieldsTypeIdKeys.js.map +0 -1
  184. package/lib/main/helpers/checkFieldPathChecklist.js +0 -40
  185. package/lib/main/helpers/checkFieldPathChecklist.js.map +0 -1
  186. package/lib/main/helpers/createFragmentSpreadChecklist.js +0 -26
  187. package/lib/main/helpers/createFragmentSpreadChecklist.js.map +0 -1
  188. package/lib/main/helpers/deriveOpCacheability.js +0 -46
  189. package/lib/main/helpers/deriveOpCacheability.js.map +0 -1
  190. package/lib/main/helpers/filterField.js +0 -95
  191. package/lib/main/helpers/filterField.js.map +0 -1
  192. package/lib/main/helpers/filterFragmentDefinitions.js +0 -55
  193. package/lib/main/helpers/filterFragmentDefinitions.js.map +0 -1
  194. package/lib/main/helpers/filterFragmentSpreads.js +0 -36
  195. package/lib/main/helpers/filterFragmentSpreads.js.map +0 -1
  196. package/lib/main/helpers/filterIDsAndTypeNames.js +0 -47
  197. package/lib/main/helpers/filterIDsAndTypeNames.js.map +0 -1
  198. package/lib/main/helpers/filterInlineFragments.js +0 -42
  199. package/lib/main/helpers/filterInlineFragments.js.map +0 -1
  200. package/lib/main/helpers/filterOperationAndFragmentDefinitions.js +0 -15
  201. package/lib/main/helpers/filterOperationAndFragmentDefinitions.js.map +0 -1
  202. package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js +0 -37
  203. package/lib/main/helpers/filterOutPropsWithArgsOrDirectives.js.map +0 -1
  204. package/lib/main/helpers/filterQuery.js +0 -58
  205. package/lib/main/helpers/filterQuery.js.map +0 -1
  206. package/lib/main/helpers/isFirstResponseChunk.js +0 -11
  207. package/lib/main/helpers/isFirstResponseChunk.js.map +0 -1
  208. package/lib/main/helpers/isLastResponseChunk.js +0 -11
  209. package/lib/main/helpers/isLastResponseChunk.js.map +0 -1
  210. package/lib/main/helpers/isNotLastResponseChunk.js +0 -11
  211. package/lib/main/helpers/isNotLastResponseChunk.js.map +0 -1
  212. package/lib/main/helpers/isNotResponseChunk.js +0 -11
  213. package/lib/main/helpers/isNotResponseChunk.js.map +0 -1
  214. package/lib/main/helpers/mergeResponseDataSets.js +0 -53
  215. package/lib/main/helpers/mergeResponseDataSets.js.map +0 -1
  216. package/lib/main/helpers/normalizePatchResponseData.js +0 -29
  217. package/lib/main/helpers/normalizePatchResponseData.js.map +0 -1
  218. package/lib/main/helpers/validTypeIDValue.js +0 -20
  219. package/lib/main/helpers/validTypeIDValue.js.map +0 -1
  220. package/lib/main/index.js +0 -31
  221. package/lib/main/index.js.map +0 -1
  222. package/lib/main/main/index.js +0 -1090
  223. package/lib/main/main/index.js.map +0 -1
  224. package/lib/module/consts/index.js +0 -6
  225. package/lib/module/consts/index.js.map +0 -1
  226. package/lib/module/debug/index.js +0 -4
  227. package/lib/module/debug/index.js.map +0 -1
  228. package/lib/module/debug/log-cache-entry/index.js +0 -48
  229. package/lib/module/debug/log-cache-entry/index.js.map +0 -1
  230. package/lib/module/debug/log-cache-query/index.js +0 -50
  231. package/lib/module/debug/log-cache-query/index.js.map +0 -1
  232. package/lib/module/debug/log-partial-compiled/index.js +0 -41
  233. package/lib/module/debug/log-partial-compiled/index.js.map +0 -1
  234. package/lib/module/defs/index.js +0 -2
  235. package/lib/module/defs/index.js.map +0 -1
  236. package/lib/module/helpers/areOnlyPopulatedFieldsTypeIdKeys.js +0 -41
  237. package/lib/module/helpers/areOnlyPopulatedFieldsTypeIdKeys.js.map +0 -1
  238. package/lib/module/helpers/checkFieldPathChecklist.js +0 -31
  239. package/lib/module/helpers/checkFieldPathChecklist.js.map +0 -1
  240. package/lib/module/helpers/createFragmentSpreadChecklist.js +0 -14
  241. package/lib/module/helpers/createFragmentSpreadChecklist.js.map +0 -1
  242. package/lib/module/helpers/deriveOpCacheability.js +0 -32
  243. package/lib/module/helpers/deriveOpCacheability.js.map +0 -1
  244. package/lib/module/helpers/filterField.js +0 -80
  245. package/lib/module/helpers/filterField.js.map +0 -1
  246. package/lib/module/helpers/filterFragmentDefinitions.js +0 -43
  247. package/lib/module/helpers/filterFragmentDefinitions.js.map +0 -1
  248. package/lib/module/helpers/filterFragmentSpreads.js +0 -22
  249. package/lib/module/helpers/filterFragmentSpreads.js.map +0 -1
  250. package/lib/module/helpers/filterIDsAndTypeNames.js +0 -36
  251. package/lib/module/helpers/filterIDsAndTypeNames.js.map +0 -1
  252. package/lib/module/helpers/filterInlineFragments.js +0 -32
  253. package/lib/module/helpers/filterInlineFragments.js.map +0 -1
  254. package/lib/module/helpers/filterOperationAndFragmentDefinitions.js +0 -5
  255. package/lib/module/helpers/filterOperationAndFragmentDefinitions.js.map +0 -1
  256. package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js +0 -24
  257. package/lib/module/helpers/filterOutPropsWithArgsOrDirectives.js.map +0 -1
  258. package/lib/module/helpers/filterQuery.js +0 -43
  259. package/lib/module/helpers/filterQuery.js.map +0 -1
  260. package/lib/module/helpers/isFirstResponseChunk.js +0 -2
  261. package/lib/module/helpers/isFirstResponseChunk.js.map +0 -1
  262. package/lib/module/helpers/isLastResponseChunk.js +0 -2
  263. package/lib/module/helpers/isLastResponseChunk.js.map +0 -1
  264. package/lib/module/helpers/isNotLastResponseChunk.js +0 -2
  265. package/lib/module/helpers/isNotLastResponseChunk.js.map +0 -1
  266. package/lib/module/helpers/isNotResponseChunk.js +0 -2
  267. package/lib/module/helpers/isNotResponseChunk.js.map +0 -1
  268. package/lib/module/helpers/mergeResponseDataSets.js +0 -41
  269. package/lib/module/helpers/mergeResponseDataSets.js.map +0 -1
  270. package/lib/module/helpers/normalizePatchResponseData.js +0 -17
  271. package/lib/module/helpers/normalizePatchResponseData.js.map +0 -1
  272. package/lib/module/helpers/validTypeIDValue.js +0 -8
  273. package/lib/module/helpers/validTypeIDValue.js.map +0 -1
  274. package/lib/module/index.js +0 -3
  275. package/lib/module/index.js.map +0 -1
  276. package/lib/module/main/index.js.map +0 -1
  277. package/lib/types/consts/index.d.ts +0 -6
  278. package/lib/types/consts/index.d.ts.map +0 -1
  279. package/lib/types/debug/index.d.ts +0 -4
  280. package/lib/types/debug/index.d.ts.map +0 -1
  281. package/lib/types/debug/log-cache-entry/index.d.ts +0 -2
  282. package/lib/types/debug/log-cache-entry/index.d.ts.map +0 -1
  283. package/lib/types/debug/log-cache-query/index.d.ts +0 -2
  284. package/lib/types/debug/log-cache-query/index.d.ts.map +0 -1
  285. package/lib/types/debug/log-partial-compiled/index.d.ts +0 -2
  286. package/lib/types/debug/log-partial-compiled/index.d.ts.map +0 -1
  287. package/lib/types/defs/index.d.ts.map +0 -1
  288. package/lib/types/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts +0 -4
  289. package/lib/types/helpers/areOnlyPopulatedFieldsTypeIdKeys.d.ts.map +0 -1
  290. package/lib/types/helpers/checkFieldPathChecklist.d.ts +0 -4
  291. package/lib/types/helpers/checkFieldPathChecklist.d.ts.map +0 -1
  292. package/lib/types/helpers/createFragmentSpreadChecklist.d.ts +0 -12
  293. package/lib/types/helpers/createFragmentSpreadChecklist.d.ts.map +0 -1
  294. package/lib/types/helpers/deriveOpCacheability.d.ts +0 -10
  295. package/lib/types/helpers/deriveOpCacheability.d.ts.map +0 -1
  296. package/lib/types/helpers/filterField.d.ts +0 -6
  297. package/lib/types/helpers/filterField.d.ts.map +0 -1
  298. package/lib/types/helpers/filterFragmentDefinitions.d.ts +0 -6
  299. package/lib/types/helpers/filterFragmentDefinitions.d.ts.map +0 -1
  300. package/lib/types/helpers/filterFragmentSpreads.d.ts +0 -6
  301. package/lib/types/helpers/filterFragmentSpreads.d.ts.map +0 -1
  302. package/lib/types/helpers/filterIDsAndTypeNames.d.ts +0 -5
  303. package/lib/types/helpers/filterIDsAndTypeNames.d.ts.map +0 -1
  304. package/lib/types/helpers/filterInlineFragments.d.ts +0 -5
  305. package/lib/types/helpers/filterInlineFragments.d.ts.map +0 -1
  306. package/lib/types/helpers/filterOperationAndFragmentDefinitions.d.ts +0 -4
  307. package/lib/types/helpers/filterOperationAndFragmentDefinitions.d.ts.map +0 -1
  308. package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts +0 -7
  309. package/lib/types/helpers/filterOutPropsWithArgsOrDirectives.d.ts.map +0 -1
  310. package/lib/types/helpers/filterQuery.d.ts +0 -5
  311. package/lib/types/helpers/filterQuery.d.ts.map +0 -1
  312. package/lib/types/helpers/isFirstResponseChunk.d.ts +0 -5
  313. package/lib/types/helpers/isFirstResponseChunk.d.ts.map +0 -1
  314. package/lib/types/helpers/isLastResponseChunk.d.ts +0 -5
  315. package/lib/types/helpers/isLastResponseChunk.d.ts.map +0 -1
  316. package/lib/types/helpers/isNotLastResponseChunk.d.ts +0 -5
  317. package/lib/types/helpers/isNotLastResponseChunk.d.ts.map +0 -1
  318. package/lib/types/helpers/isNotResponseChunk.d.ts +0 -5
  319. package/lib/types/helpers/isNotResponseChunk.d.ts.map +0 -1
  320. package/lib/types/helpers/mergeResponseDataSets.d.ts +0 -4
  321. package/lib/types/helpers/mergeResponseDataSets.d.ts.map +0 -1
  322. package/lib/types/helpers/normalizePatchResponseData.d.ts +0 -5
  323. package/lib/types/helpers/normalizePatchResponseData.d.ts.map +0 -1
  324. package/lib/types/helpers/validTypeIDValue.d.ts +0 -3
  325. package/lib/types/helpers/validTypeIDValue.d.ts.map +0 -1
  326. package/lib/types/index.d.ts +0 -3
  327. package/lib/types/index.d.ts.map +0 -1
  328. package/lib/types/index.test.d.ts +0 -2
  329. package/lib/types/index.test.d.ts.map +0 -1
  330. package/lib/types/main/index.d.ts.map +0 -1
  331. package/src/consts/index.ts +0 -6
  332. package/src/debug/log-cache-entry/index.ts +0 -45
  333. package/src/debug/log-partial-compiled/index.ts +0 -38
  334. package/src/helpers/validTypeIDValue.ts +0 -11
@@ -1,26 +1,26 @@
1
- import Cachemap from "@cachemap/core";
1
+ import { type Core } from '@cachemap/core';
2
2
  import {
3
- CacheMetadata,
4
- CacheTypes,
5
- CachemapOptions,
3
+ type CacheMetadata,
4
+ type CacheTypes,
5
+ type CachemapOptions,
6
6
  DATA_ENTITIES,
7
7
  DEFAULT_TYPE_ID_KEY,
8
- FieldTypeInfo,
9
- PlainObjectMap,
10
- PlainObjectStringMap,
11
- QUERY,
8
+ type EntityData,
9
+ type FieldTypeInfo,
10
+ type PlainData,
12
11
  QUERY_RESPONSES,
13
12
  REQUEST_FIELD_PATHS,
14
- RawResponseDataWithMaybeCacheMetadata,
15
- RequestContext,
16
- RequestData,
17
- RequestOptions,
18
- ResponseData,
13
+ type RawResponseDataWithMaybeCacheMetadata,
14
+ type RequestContext,
15
+ type RequestData,
16
+ type RequestOptions,
17
+ type ResponseData,
19
18
  TYPE_NAME_KEY,
20
- } from "@graphql-box/core";
19
+ } from '@graphql-box/core';
21
20
  import {
22
- FRAGMENT_SPREAD,
23
- KeysAndPaths,
21
+ ArgsError,
22
+ GroupedError,
23
+ type KeysAndPaths,
24
24
  buildFieldKeysAndPaths,
25
25
  dehydrateCacheMetadata,
26
26
  getChildFields,
@@ -28,61 +28,67 @@ import {
28
28
  getOperationDefinitions,
29
29
  hasChildFields,
30
30
  hashRequest,
31
+ isArray,
32
+ isObjectLike,
33
+ isPlainObject,
31
34
  iterateChildFields,
32
- mergeObjects,
33
35
  rehydrateCacheMetadata,
34
- } from "@graphql-box/helpers";
35
- import Cacheability from "cacheability";
36
- import { FieldNode, print } from "graphql";
37
- import { assign, cloneDeep, get, isArray, isObjectLike, isPlainObject, isUndefined, set, unset } from "lodash";
38
- import { CACHE_CONTROL, HEADER_NO_CACHE, METADATA, NO_CACHE } from "../consts";
39
- import { logCacheEntry, logCacheQuery, logPartialCompiled } from "../debug";
36
+ } from '@graphql-box/helpers';
37
+ import { Cacheability } from 'cacheability';
38
+ import { type FieldNode, Kind, OperationTypeNode, print } from 'graphql';
39
+ import { assign, cloneDeep, get, isEqual, isNumber, isUndefined, set, unset } from 'lodash-es';
40
+ import { CACHE_CONTROL, HEADER_NO_CACHE, METADATA, NO_CACHE } from './constants.ts';
41
+ import { logCacheEntry, logCacheQuery, logPartialCompiled } from './debug/index.ts';
42
+ import { areOnlyPopulatedFieldsTypeIdKeys } from './helpers/areOnlyPopulatedFieldsTypeIdKeys.ts';
43
+ import { combineDataSets } from './helpers/combineData.ts';
44
+ import { deriveOpCacheability } from './helpers/deriveOpCacheability.ts';
45
+ import { filterOutPropsWithArgsOrDirectives } from './helpers/filterOutPropsWithArgsOrDirectives.ts';
46
+ import { filterQuery } from './helpers/filterQuery.ts';
47
+ import { getDataValue } from './helpers/getDataValue.ts';
48
+ import { hasTypename } from './helpers/hasTypename.ts';
49
+ import { isLastResponseChunk } from './helpers/isLastResponseChunk.ts';
50
+ import { isNotLastResponseChunk } from './helpers/isNotLastResponseChunk.ts';
51
+ import { isNotResponseChunk } from './helpers/isNotResponseChunk.ts';
52
+ import { mergeDataSets } from './helpers/mergeObjects.ts';
53
+ import { mergeResponseDataSets } from './helpers/mergeResponseDataSets.ts';
54
+ import { normalizePatchResponseData } from './helpers/normalizePatchResponseData.ts';
55
+ import { getValidTypeIdValue } from './helpers/validTypeIdValue.ts';
40
56
  import {
41
- AnalyzeQueryResult,
42
- AncestorKeysAndPaths,
43
- CacheManagerContext,
44
- CacheManagerDef,
45
- CachedAncestorFieldData,
46
- CachedResponseData,
47
- CheckCacheEntryResult,
48
- DataForCachingEntry,
49
- FieldCount,
50
- FieldPathChecklist,
51
- FieldPathChecklistValue,
52
- MergedCachedFieldData,
53
- PartialQueryResponse,
54
- PartialQueryResponses,
55
- QueryResponseCacheEntry,
56
- ResponseDataForCaching,
57
- TypeNamesAndKind,
58
- UserOptions,
59
- } from "../defs";
60
- import areOnlyPopulatedFieldsTypeIdKeys from "../helpers/areOnlyPopulatedFieldsTypeIdKeys";
61
- import deriveOpCacheability from "../helpers/deriveOpCacheability";
62
- import filterOutPropsWithArgsOrDirectives from "../helpers/filterOutPropsWithArgsOrDirectives";
63
- import filterQuery from "../helpers/filterQuery";
64
- import isLastResponseChunk from "../helpers/isLastResponseChunk";
65
- import isNotLastResponseChunk from "../helpers/isNotLastResponseChunk";
66
- import isNotResponseChunk from "../helpers/isNotResponseChunk";
67
- import mergeResponseDataSets from "../helpers/mergeResponseDataSets";
68
- import normalizePatchResponseData from "../helpers/normalizePatchResponseData";
69
- import { getValidTypeIDValue } from "../helpers/validTypeIDValue";
70
-
71
- export default class CacheManager implements CacheManagerDef {
57
+ type AnalyzeQueryResult,
58
+ type AncestorKeysAndPaths,
59
+ type CacheManagerContext,
60
+ type CacheManagerDef,
61
+ type CachedAncestorFieldData,
62
+ type CachedResponseData,
63
+ type CheckCacheEntryResult,
64
+ type DataForCachingEntry,
65
+ type FieldCount,
66
+ type FieldPathChecklist,
67
+ type MergedCachedFieldData,
68
+ type PartialQueryResponse,
69
+ type PartialQueryResponses,
70
+ type QueryResponseCacheEntry,
71
+ type ResponseDataForCaching,
72
+ type TypenamesAndKind,
73
+ type UserOptions,
74
+ } from './types.ts';
75
+
76
+ export class CacheManager implements CacheManagerDef {
72
77
  private static _countFieldPathChecklist(fieldPathChecklist: FieldPathChecklist): FieldCount {
73
78
  const fieldCount: FieldCount = { missing: 0, total: 0 };
74
79
 
75
- fieldPathChecklist.forEach(checklistValues => {
80
+ for (const [, checklistValues] of fieldPathChecklist) {
76
81
  fieldCount.total += checklistValues.length;
77
82
  const missing = checklistValues.filter(({ hasData }) => !hasData);
78
83
  fieldCount.missing += missing.length;
79
- });
84
+ }
80
85
 
81
86
  return fieldCount;
82
87
  }
83
88
 
84
- private static _getFieldDataFromAncestor(ancestorFieldData: any, propNameOrIndex: string | number): any {
85
- return isObjectLike(ancestorFieldData) ? cloneDeep(ancestorFieldData[propNameOrIndex]) : undefined;
89
+ private static _getFieldDataFromAncestor<T>(ancestorFieldData: unknown, propNameOrIndex: string | number) {
90
+ const dataValue = getDataValue<T>(ancestorFieldData, propNameOrIndex);
91
+ return isObjectLike(dataValue) ? cloneDeep(dataValue) : dataValue;
86
92
  }
87
93
 
88
94
  private static _getOperationCacheControl(cacheMetadata: CacheMetadata | undefined, operation: string): string {
@@ -119,7 +125,7 @@ export default class CacheManager implements CacheManagerDef {
119
125
 
120
126
  private static _mergeResponseCacheMetadata(
121
127
  cacheMetadata: CacheMetadata,
122
- partialQueryResponse?: PartialQueryResponse,
128
+ partialQueryResponse?: PartialQueryResponse
123
129
  ): CacheMetadata {
124
130
  if (!partialQueryResponse) {
125
131
  return cacheMetadata;
@@ -129,15 +135,24 @@ export default class CacheManager implements CacheManagerDef {
129
135
  }
130
136
 
131
137
  private static _setCachedData(
132
- requestData: PlainObjectMap,
138
+ responseData: unknown,
133
139
  { data }: MergedCachedFieldData,
134
- propNameOrIndex: string | number,
140
+ propNameOrIndex: string | number
135
141
  ): void {
142
+ const setData = (value: unknown) => {
143
+ if (isArray(responseData) && isNumber(propNameOrIndex)) {
144
+ responseData[propNameOrIndex] = value;
145
+ } else if (isPlainObject(responseData)) {
146
+ responseData[propNameOrIndex] = value;
147
+ }
148
+ };
149
+
136
150
  if (!isObjectLike(data) && !isUndefined(data)) {
137
- requestData[propNameOrIndex] = data as string | number | boolean | null;
138
- } else if (isObjectLike(data)) {
139
- const objectLikeData = data as PlainObjectMap | any[];
140
- requestData[propNameOrIndex] = isArray(objectLikeData) ? [] : {};
151
+ setData(data);
152
+ } else if (isArray(data)) {
153
+ setData([]);
154
+ } else if (isPlainObject(data)) {
155
+ setData({});
141
156
  }
142
157
  }
143
158
 
@@ -145,9 +160,9 @@ export default class CacheManager implements CacheManagerDef {
145
160
  cachedFieldData: MergedCachedFieldData,
146
161
  { cacheMetadata, data, fieldPathChecklist }: CachedResponseData,
147
162
  { propNameOrIndex, requestFieldPath }: KeysAndPaths,
148
- typeNamesAndKind: TypeNamesAndKind,
163
+ typeNamesAndKind: TypenamesAndKind,
149
164
  _options: RequestOptions,
150
- { operation }: CacheManagerContext,
165
+ { operation }: CacheManagerContext
151
166
  ) {
152
167
  CacheManager._setCacheMetadata(cacheMetadata, cachedFieldData.cacheability, requestFieldPath, operation);
153
168
  CacheManager._setFieldPathChecklist(fieldPathChecklist, cachedFieldData, requestFieldPath, typeNamesAndKind);
@@ -158,7 +173,7 @@ export default class CacheManager implements CacheManagerDef {
158
173
  cacheMetadata: CacheMetadata,
159
174
  cacheability: Cacheability | undefined,
160
175
  requestFieldPath: string,
161
- operation: string,
176
+ operation: string
162
177
  ): void {
163
178
  if (!cacheability) {
164
179
  return;
@@ -176,9 +191,9 @@ export default class CacheManager implements CacheManagerDef {
176
191
  fieldPathChecklist: FieldPathChecklist,
177
192
  { data }: MergedCachedFieldData,
178
193
  requestFieldPath: string,
179
- { dataTypeName, fieldTypeName, fragmentKind, fragmentName }: TypeNamesAndKind,
194
+ { dataTypename: dataTypeName, fieldTypename: fieldTypeName, fragmentKind, fragmentName }: TypenamesAndKind
180
195
  ): void {
181
- if (isUndefined(fieldTypeName) || fragmentKind === FRAGMENT_SPREAD) {
196
+ if (isUndefined(fieldTypeName) || fragmentKind === Kind.FRAGMENT_SPREAD) {
182
197
  if (fieldPathChecklist.has(requestFieldPath)) {
183
198
  return;
184
199
  }
@@ -192,7 +207,7 @@ export default class CacheManager implements CacheManagerDef {
192
207
  }
193
208
 
194
209
  const entry = fieldPathChecklist.get(requestFieldPath);
195
- const checklistValues = entry ? (entry as FieldPathChecklistValue[]) : [];
210
+ const checklistValues = entry ?? [];
196
211
 
197
212
  if (checklistValues.some(({ typeName }) => typeName === dataTypeName)) {
198
213
  return;
@@ -200,56 +215,48 @@ export default class CacheManager implements CacheManagerDef {
200
215
 
201
216
  fieldPathChecklist.set(requestFieldPath, [
202
217
  ...checklistValues,
203
- { fragmentKind, fragmentName, hasData: !isUndefined(data), typeName: dataTypeName as string },
218
+ { fragmentKind, fragmentName, hasData: !isUndefined(data), typeName: dataTypeName },
204
219
  ]);
205
220
  }
206
221
 
207
- private _cache: Cachemap;
222
+ private _cache: Core;
208
223
  private _cascadeCacheControl: boolean;
209
224
  private _fallbackOperationCacheability: string;
210
225
  private _partialQueryResponses: PartialQueryResponses = new Map();
211
- private _responseChunksAwaitingCaching: Map<string, RawResponseDataWithMaybeCacheMetadata[]> = new Map();
212
- private _typeCacheDirectives: PlainObjectStringMap;
226
+ private _responseChunksAwaitingCaching = new Map<string, RawResponseDataWithMaybeCacheMetadata[]>();
227
+ private _typeCacheDirectives: Record<string, string>;
213
228
  private _typeIDKey: string;
214
229
 
215
230
  constructor(options: UserOptions) {
216
- const errors: TypeError[] = [];
231
+ const errors: ArgsError[] = [];
217
232
 
218
- if (!options.cache) {
219
- errors.push(new TypeError("@graphql-box/cache-manager expected options.cache."));
233
+ if (!('cache' in options)) {
234
+ errors.push(new ArgsError('@graphql-box/cache-manager expected cache to be in options.'));
220
235
  }
221
236
 
222
237
  if (!!options.typeCacheDirectives && !isPlainObject(options.typeCacheDirectives)) {
223
- const message = "@graphql-box/cache-manager expected options.typeCacheDirectives to be a plain object.";
224
- errors.push(new TypeError(message));
238
+ const message = '@graphql-box/cache-manager expected options.typeCacheDirectives to be a plain object.';
239
+ errors.push(new ArgsError(message));
225
240
  }
226
241
 
227
- if (errors.length) {
228
- throw errors;
242
+ if (errors.length > 0) {
243
+ throw new GroupedError('@graphql-box/cache-manager argument validation errors.', errors);
229
244
  }
230
245
 
231
246
  this._cache = options.cache;
232
- this._cascadeCacheControl = options.cascadeCacheControl || false;
233
- this._fallbackOperationCacheability = options.fallbackOperationCacheability || NO_CACHE;
234
- this._typeCacheDirectives = options.typeCacheDirectives || {};
247
+ this._cascadeCacheControl = options.cascadeCacheControl ?? false;
248
+ this._fallbackOperationCacheability = options.fallbackOperationCacheability ?? NO_CACHE;
249
+ this._typeCacheDirectives = options.typeCacheDirectives ?? {};
235
250
  this._typeIDKey = options.typeIDKey ?? DEFAULT_TYPE_ID_KEY;
236
251
  }
237
252
 
238
- get cache(): Cachemap {
239
- return this._cache;
240
- }
241
-
242
253
  public async analyzeQuery(
243
254
  requestData: RequestData,
244
255
  options: RequestOptions,
245
- context: RequestContext,
256
+ context: RequestContext
246
257
  ): Promise<AnalyzeQueryResult> {
247
258
  const { ast, hash } = requestData;
248
259
 
249
- if (!ast) {
250
- return Promise.reject(new TypeError("@graphql-box/cache-manager expected an AST."));
251
- }
252
-
253
260
  const cacheManagerContext: CacheManagerContext = {
254
261
  ...context,
255
262
  fragmentDefinitions: getFragmentDefinitions(ast),
@@ -259,9 +266,11 @@ export default class CacheManager implements CacheManagerDef {
259
266
  const cachedResponseData = await this._retrieveCachedResponseData(requestData, options, cacheManagerContext);
260
267
  const { cacheMetadata, data, fieldCount } = cachedResponseData;
261
268
 
262
- // Second half of check is required for the scenario where the only matching data is
263
- // the typeIDKey field, i.e. "id", in which case there is no point settings a partial
264
- // query reponse because we request the typeIDKey field with every request.
269
+ /**
270
+ * Second half of check is required for the scenario where the only matching data is
271
+ * the typeIDKey field, i.e. "id", in which case there is no point settings a partial
272
+ * query reponse because we request the typeIDKey field with every request.
273
+ */
265
274
  if (fieldCount.missing === fieldCount.total || areOnlyPopulatedFieldsTypeIdKeys(data, this._typeIDKey)) {
266
275
  return { updated: requestData };
267
276
  }
@@ -281,7 +290,14 @@ export default class CacheManager implements CacheManagerDef {
281
290
  const { fragmentDefinitions, typeIDKey, ...rest } = cacheManagerContext;
282
291
  assign(context, { ...rest, filteredRequest });
283
292
  this._setPartialQueryResponse(hash, { cacheMetadata, data }, options, context);
284
- return { updated: { ast: filteredAST, hash: hashRequest(filteredRequest), request: filteredRequest } };
293
+
294
+ return {
295
+ updated: { ast: filteredAST, hash: hashRequest(filteredRequest), request: filteredRequest },
296
+ };
297
+ }
298
+
299
+ get cache(): Core {
300
+ return this._cache;
285
301
  }
286
302
 
287
303
  public async cacheQuery(
@@ -289,7 +305,7 @@ export default class CacheManager implements CacheManagerDef {
289
305
  updatedRequestData: RequestData | undefined,
290
306
  rawResponseData: RawResponseDataWithMaybeCacheMetadata,
291
307
  options: RequestOptions,
292
- context: RequestContext,
308
+ context: RequestContext
293
309
  ): Promise<ResponseData> {
294
310
  const cacheManagerContext: CacheManagerContext = {
295
311
  ...context,
@@ -304,7 +320,7 @@ export default class CacheManager implements CacheManagerDef {
304
320
  requestData: RequestData,
305
321
  rawResponseData: RawResponseDataWithMaybeCacheMetadata,
306
322
  options: RequestOptions,
307
- context: RequestContext,
323
+ context: RequestContext
308
324
  ): Promise<ResponseData> {
309
325
  const cacheManagerContext: CacheManagerContext = {
310
326
  ...context,
@@ -319,7 +335,7 @@ export default class CacheManager implements CacheManagerDef {
319
335
  cacheType: CacheTypes,
320
336
  hash: string,
321
337
  options: RequestOptions,
322
- context: RequestContext & { requestFieldCacheKey?: string },
338
+ context: RequestContext & { requestFieldCacheKey?: string }
323
339
  ): Promise<CheckCacheEntryResult | false> {
324
340
  return this._checkCacheEntry(cacheType, hash, options, context);
325
341
  }
@@ -327,7 +343,7 @@ export default class CacheManager implements CacheManagerDef {
327
343
  public async checkQueryResponseCacheEntry(
328
344
  hash: string,
329
345
  options: RequestOptions,
330
- context: RequestContext,
346
+ context: RequestContext
331
347
  ): Promise<ResponseData | false> {
332
348
  const result = await this._checkCacheEntry(QUERY_RESPONSES, hash, options, context);
333
349
 
@@ -351,7 +367,7 @@ export default class CacheManager implements CacheManagerDef {
351
367
  requestData: RequestData,
352
368
  responseData: ResponseData,
353
369
  options: RequestOptions,
354
- context: CacheManagerContext,
370
+ context: CacheManagerContext
355
371
  ): Promise<void> {
356
372
  return this._setQueryResponseCacheEntry(requestData.hash, responseData, options, context);
357
373
  }
@@ -359,32 +375,36 @@ export default class CacheManager implements CacheManagerDef {
359
375
  private async _analyzeFieldNode(
360
376
  fieldNode: FieldNode,
361
377
  cachedAncestorFieldData: CachedAncestorFieldData,
362
- cachedResponseData: CachedResponseData,
378
+ cachedResponseData: CachedResponseData & { data: unknown },
363
379
  options: RequestOptions,
364
- context: CacheManagerContext,
380
+ context: CacheManagerContext
365
381
  ): Promise<void> {
366
- if (hasChildFields(fieldNode, { fragmentDefinitions: context.fragmentDefinitions })) {
367
- await this._analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context);
368
- } else {
369
- await this._analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context);
370
- }
382
+ await (hasChildFields(fieldNode, { fragmentDefinitions: context.fragmentDefinitions })
383
+ ? this._analyzeParentFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context)
384
+ : this._analyzeLeafFieldNode(fieldNode, cachedAncestorFieldData, cachedResponseData, options, context));
371
385
  }
372
386
 
373
387
  private async _analyzeLeafFieldNode(
374
388
  fieldNode: FieldNode,
375
389
  cachedAncestorFieldData: CachedAncestorFieldData,
376
- cachedResponseData: CachedResponseData,
390
+ cachedResponseData: CachedResponseData & { data: unknown },
377
391
  options: RequestOptions,
378
- context: CacheManagerContext,
392
+ context: CacheManagerContext
379
393
  ): Promise<void> {
380
394
  const keysAndPaths = buildFieldKeysAndPaths(fieldNode, cachedAncestorFieldData, context);
381
395
  const { hashedRequestFieldCacheKey, propNameOrIndex, requestFieldCacheKey, requestFieldPath } = keysAndPaths;
382
396
  const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
383
397
  const { entityData, fragmentKind, fragmentName, requestFieldPathData, typeName } = cachedAncestorFieldData;
384
398
 
385
- const typeNamesAndKind = {
386
- dataTypeName: entityData?.__typename || requestFieldPathData?.__typename,
387
- fieldTypeName: typeName,
399
+ const dataTypename = hasTypename(entityData)
400
+ ? entityData.__typename
401
+ : hasTypename(requestFieldPathData)
402
+ ? requestFieldPathData.__typename
403
+ : undefined;
404
+
405
+ const typenamesAndKind = {
406
+ dataTypename,
407
+ fieldTypename: typeName,
388
408
  fragmentKind,
389
409
  fragmentName,
390
410
  };
@@ -394,27 +414,27 @@ export default class CacheManager implements CacheManagerDef {
394
414
  hashedRequestFieldCacheKey,
395
415
  requestFieldCacheKey,
396
416
  options,
397
- context,
417
+ context
398
418
  );
399
419
 
400
420
  CacheManager._setCachedResponseData(
401
421
  { cacheability, data: entry },
402
422
  cachedResponseData,
403
423
  keysAndPaths,
404
- typeNamesAndKind,
424
+ typenamesAndKind,
405
425
  options,
406
- context,
426
+ context
407
427
  );
408
428
  } else {
409
429
  const cachedFieldData =
410
- CacheManager._getFieldDataFromAncestor(entityData, propNameOrIndex) ||
430
+ CacheManager._getFieldDataFromAncestor(entityData, propNameOrIndex) ??
411
431
  CacheManager._getFieldDataFromAncestor(requestFieldPathData, propNameOrIndex);
412
432
 
413
433
  CacheManager._setFieldPathChecklist(
414
434
  cachedResponseData.fieldPathChecklist,
415
435
  { data: cachedFieldData },
416
436
  requestFieldPath,
417
- typeNamesAndKind,
437
+ typenamesAndKind
418
438
  );
419
439
 
420
440
  CacheManager._setCachedData(cachedResponseData.data, { data: cachedFieldData }, propNameOrIndex);
@@ -426,18 +446,18 @@ export default class CacheManager implements CacheManagerDef {
426
446
  cachedAncestorFieldData: CachedAncestorFieldData,
427
447
  cachedResponseData: CachedResponseData,
428
448
  options: RequestOptions,
429
- context: CacheManagerContext,
449
+ context: CacheManagerContext
430
450
  ): Promise<void> {
431
451
  const keysAndPaths = buildFieldKeysAndPaths(fieldNode, cachedAncestorFieldData, context);
432
452
  const { propNameOrIndex, requestFieldCacheKey, requestFieldPath } = keysAndPaths;
433
- const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath) as FieldTypeInfo;
453
+ const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath)!;
434
454
 
435
455
  const { cacheability, data, entityData, requestFieldPathData } = await this._retrieveCachedParentNodeData(
436
456
  cachedAncestorFieldData,
437
457
  keysAndPaths,
438
458
  fieldTypeInfo,
439
459
  options,
440
- context,
460
+ context
441
461
  );
442
462
 
443
463
  const { fragmentKind, fragmentName, typeName } = cachedAncestorFieldData;
@@ -446,28 +466,27 @@ export default class CacheManager implements CacheManagerDef {
446
466
  { cacheability, data },
447
467
  cachedResponseData,
448
468
  keysAndPaths,
449
- { dataTypeName: get(data, TYPE_NAME_KEY), fieldTypeName: typeName, fragmentKind, fragmentName },
469
+ { dataTypename: get(data, TYPE_NAME_KEY), fieldTypename: typeName, fragmentKind, fragmentName },
450
470
  options,
451
- context,
471
+ context
452
472
  );
453
473
 
454
474
  if (!isObjectLike(data)) {
455
475
  return;
456
476
  }
457
477
 
458
- const objectLikeData = data as PlainObjectMap | any[];
459
478
  const promises: Promise<void>[] = [];
460
479
 
461
480
  iterateChildFields(
462
481
  fieldNode,
463
- objectLikeData,
482
+ data,
464
483
  context.fragmentDefinitions,
465
484
  (
466
485
  childField: FieldNode,
467
486
  childTypeName: string | undefined,
468
487
  childFragmentKind: string | undefined,
469
488
  childFragmentName: string | undefined,
470
- childIndex?: number,
489
+ childIndex?: number
471
490
  ) => {
472
491
  promises.push(
473
492
  this._analyzeFieldNode(
@@ -483,12 +502,21 @@ export default class CacheManager implements CacheManagerDef {
483
502
  requestFieldPathData,
484
503
  typeName: childTypeName,
485
504
  },
486
- { ...cachedResponseData, data: cachedResponseData.data[propNameOrIndex] },
505
+ {
506
+ ...cachedResponseData,
507
+ /**
508
+ * `cachedResponseData.data[propNameOrIndex]` will always be either an empty array
509
+ * or an empty object at this point as based on whether `data` is object-like
510
+ * `cachedResponseData.data[propNameOrIndex]` is set accordingly in
511
+ * _setCachedResponseData > _setCachedData
512
+ */
513
+ data: getDataValue<PlainData>(cachedResponseData.data, propNameOrIndex)!,
514
+ },
487
515
  options,
488
- context,
489
- ),
516
+ context
517
+ )
490
518
  );
491
- },
519
+ }
492
520
  );
493
521
 
494
522
  await Promise.all(promises);
@@ -498,25 +526,29 @@ export default class CacheManager implements CacheManagerDef {
498
526
  { ast }: RequestData,
499
527
  { data, ...otherProps }: RawResponseDataWithMaybeCacheMetadata,
500
528
  options: RequestOptions,
501
- context: CacheManagerContext,
529
+ context: CacheManagerContext
502
530
  ): CacheMetadata {
503
531
  const cacheMetadata = this._createCacheMetadata({ data, ...otherProps }, context);
504
532
  const queryNode = getOperationDefinitions(ast, context.operation)[0];
533
+
534
+ if (!queryNode) {
535
+ return cacheMetadata;
536
+ }
537
+
505
538
  const fieldsAndTypeNames = getChildFields(queryNode);
506
539
 
507
540
  if (!fieldsAndTypeNames) {
508
541
  return cacheMetadata;
509
542
  }
510
543
 
511
- fieldsAndTypeNames.forEach(({ fieldNode }) =>
544
+ for (const { fieldNode } of fieldsAndTypeNames)
512
545
  this._setFieldCacheability(
513
546
  fieldNode,
514
547
  { requestFieldPath: context.operation },
515
548
  { cacheMetadata, data },
516
549
  options,
517
- context,
518
- ),
519
- );
550
+ context
551
+ );
520
552
 
521
553
  return cacheMetadata;
522
554
  }
@@ -526,7 +558,7 @@ export default class CacheManager implements CacheManagerDef {
526
558
  updatedRequestData: RequestData | undefined,
527
559
  rawResponseData: RawResponseDataWithMaybeCacheMetadata,
528
560
  options: RequestOptions,
529
- context: CacheManagerContext,
561
+ context: CacheManagerContext
530
562
  ): Promise<ResponseData> {
531
563
  const normalizedResponseData = normalizePatchResponseData(rawResponseData, context);
532
564
  let responseDataForCaching: RawResponseDataWithMaybeCacheMetadata | undefined = normalizedResponseData;
@@ -555,19 +587,19 @@ export default class CacheManager implements CacheManagerDef {
555
587
  requestFieldPathData: cloneDeep(data),
556
588
  },
557
589
  options,
558
- context,
559
- ),
590
+ context
591
+ )
560
592
  );
561
593
 
562
594
  let queryCacheMetadata: CacheMetadata | undefined;
563
- let queryData: PlainObjectMap | undefined;
595
+ let queryData: PlainData | undefined;
564
596
 
565
- if (context.operation === QUERY) {
597
+ if (context.operation === OperationTypeNode.QUERY) {
566
598
  let partialQueryResponse: PartialQueryResponse | undefined;
567
599
 
568
600
  if (context.queryFiltered && updatedRequestData) {
569
601
  dataCaching.push(
570
- this._setQueryResponseCacheEntry(updatedRequestData.hash, { cacheMetadata, data }, options, context),
602
+ this._setQueryResponseCacheEntry(updatedRequestData.hash, { cacheMetadata, data }, options, context)
571
603
  );
572
604
 
573
605
  partialQueryResponse = this._getPartialQueryResponse(requestData.hash);
@@ -581,8 +613,8 @@ export default class CacheManager implements CacheManagerDef {
581
613
  requestData.hash,
582
614
  { cacheMetadata: queryCacheMetadata, data: queryData },
583
615
  options,
584
- context,
585
- ),
616
+ context
617
+ )
586
618
  );
587
619
  }
588
620
 
@@ -608,12 +640,12 @@ export default class CacheManager implements CacheManagerDef {
608
640
  };
609
641
  }
610
642
 
611
- private async _checkCacheEntry(
643
+ private async _checkCacheEntry<T>(
612
644
  cacheType: CacheTypes,
613
645
  hash: string,
614
646
  options: RequestOptions,
615
- context: CacheManagerContext & { requestFieldCacheKey?: string },
616
- ): Promise<CheckCacheEntryResult | false> {
647
+ context: CacheManagerContext & { requestFieldCacheKey?: string }
648
+ ): Promise<CheckCacheEntryResult<T> | false> {
617
649
  try {
618
650
  const cacheability = await this._hasCacheEntry(cacheType, hash);
619
651
 
@@ -621,23 +653,23 @@ export default class CacheManager implements CacheManagerDef {
621
653
  return false;
622
654
  }
623
655
 
624
- const entry = await this._getCacheEntry(cacheType, hash, options, context);
656
+ const entry = await this._getCacheEntry<T>(cacheType, hash, options, context);
625
657
 
626
658
  if (isUndefined(entry)) {
627
659
  return false;
628
660
  }
629
661
 
630
662
  return { cacheability, entry };
631
- } catch (error) {
663
+ } catch {
632
664
  return false;
633
665
  }
634
666
  }
635
667
 
636
668
  private _createCacheMetadata(
637
669
  { _cacheMetadata, headers }: RawResponseDataWithMaybeCacheMetadata,
638
- { operation }: CacheManagerContext,
670
+ { operation }: CacheManagerContext
639
671
  ): CacheMetadata {
640
- const cacheMetadata = new Map();
672
+ const cacheMetadata = new Map<string, Cacheability>();
641
673
 
642
674
  const cacheability = deriveOpCacheability({
643
675
  _cacheMetadata,
@@ -655,17 +687,13 @@ export default class CacheManager implements CacheManagerDef {
655
687
  }
656
688
 
657
689
  @logCacheQuery()
658
- private async _getCacheEntry(
690
+ private async _getCacheEntry<T>(
659
691
  cacheType: CacheTypes,
660
692
  hash: string,
661
693
  _options: RequestOptions,
662
- _context: CacheManagerContext & { requestFieldCacheKey?: string },
663
- ): Promise<any> {
664
- try {
665
- return await this._cache.get(`${cacheType}::${hash}`);
666
- } catch (errors) {
667
- return Promise.reject(errors);
668
- }
694
+ _context: CacheManagerContext & { requestFieldCacheKey?: string }
695
+ ): Promise<T | undefined> {
696
+ return this._cache.get<T>(`${cacheType}::${hash}`);
669
697
  }
670
698
 
671
699
  private _getPartialQueryResponse(hash: string): PartialQueryResponse | undefined {
@@ -677,13 +705,13 @@ export default class CacheManager implements CacheManagerDef {
677
705
  private async _hasCacheEntry(cacheType: CacheTypes, hash: string): Promise<Cacheability | false> {
678
706
  try {
679
707
  return await this._cache.has(`${cacheType}::${hash}`);
680
- } catch (error) {
708
+ } catch {
681
709
  return false;
682
710
  }
683
711
  }
684
712
 
685
- private _isFieldEntity(fieldData: any, { isEntity, possibleTypes }: FieldTypeInfo): boolean {
686
- if (!get(fieldData, this._typeIDKey, null)) {
713
+ private _isFieldEntity(fieldData: unknown, { isEntity, possibleTypes }: FieldTypeInfo): boolean {
714
+ if (!isPlainObject(fieldData) || !(this._typeIDKey in fieldData)) {
687
715
  return false;
688
716
  }
689
717
 
@@ -691,28 +719,19 @@ export default class CacheManager implements CacheManagerDef {
691
719
  return true;
692
720
  }
693
721
 
694
- if (!possibleTypes.length) {
722
+ if (possibleTypes.length === 0) {
695
723
  return false;
696
724
  }
697
725
 
698
726
  return possibleTypes.some(type => type.typeName === fieldData.__typename);
699
727
  }
700
728
 
701
- private _mergeObjects<T>(obj: T, src: T): T {
702
- return mergeObjects(obj, src, (_key: string, val: any): string | number | undefined => {
703
- return isPlainObject(val) && val[this._typeIDKey] ? val[this._typeIDKey] : undefined;
704
- });
705
- }
706
-
707
- private _mergeResponseData(
708
- responseData: PlainObjectMap,
709
- partialQueryResponse?: PartialQueryResponse,
710
- ): PlainObjectMap {
729
+ private _mergeResponseData(responseData: PlainData, partialQueryResponse?: PartialQueryResponse): PlainData {
711
730
  if (!partialQueryResponse) {
712
731
  return responseData;
713
732
  }
714
733
 
715
- return this._mergeObjects(partialQueryResponse.data, responseData);
734
+ return mergeDataSets(partialQueryResponse.data, responseData, this._typeIDKey);
716
735
  }
717
736
 
718
737
  private async _parseEntityAndRequestFieldPathCacheEntryData(
@@ -720,11 +739,11 @@ export default class CacheManager implements CacheManagerDef {
720
739
  ancestorKeysAndPaths: AncestorKeysAndPaths,
721
740
  { cacheMetadata, entityData, requestFieldPathData }: ResponseDataForCaching,
722
741
  options: RequestOptions,
723
- context: CacheManagerContext,
742
+ context: CacheManagerContext
724
743
  ): Promise<void> {
725
744
  const keysAndPaths = buildFieldKeysAndPaths(field, ancestorKeysAndPaths, context);
726
745
  const { requestFieldCacheKey, requestFieldPath, responseDataPath } = keysAndPaths;
727
- const fieldData = get(requestFieldPathData, responseDataPath);
746
+ const fieldData = get(requestFieldPathData, responseDataPath) as unknown;
728
747
  const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
729
748
 
730
749
  if (!isObjectLike(fieldData) && !fieldTypeInfo?.hasDirectives) {
@@ -736,14 +755,14 @@ export default class CacheManager implements CacheManagerDef {
736
755
 
737
756
  iterateChildFields(
738
757
  field,
739
- fieldData as PlainObjectMap | any[],
758
+ fieldData,
740
759
  context.fragmentDefinitions,
741
760
  (
742
761
  childField: FieldNode,
743
762
  _typeName: string | undefined,
744
763
  _fragmentKind: string | undefined,
745
764
  _fragmentName: string | undefined,
746
- childIndex?: number,
765
+ childIndex?: number
747
766
  ) => {
748
767
  promises.push(
749
768
  this._parseEntityAndRequestFieldPathCacheEntryData(
@@ -751,10 +770,10 @@ export default class CacheManager implements CacheManagerDef {
751
770
  { index: childIndex, requestFieldCacheKey, requestFieldPath, responseDataPath },
752
771
  { cacheMetadata, entityData, requestFieldPathData },
753
772
  options,
754
- context,
755
- ),
773
+ context
774
+ )
756
775
  );
757
- },
776
+ }
758
777
  );
759
778
 
760
779
  await Promise.all(promises);
@@ -765,7 +784,7 @@ export default class CacheManager implements CacheManagerDef {
765
784
  keysAndPaths,
766
785
  { cacheMetadata, entityData, requestFieldPathData },
767
786
  options,
768
- context,
787
+ context
769
788
  );
770
789
  }
771
790
 
@@ -773,16 +792,18 @@ export default class CacheManager implements CacheManagerDef {
773
792
  validTypeIDValue: string | number,
774
793
  { possibleTypes, typeName }: FieldTypeInfo,
775
794
  options: RequestOptions,
776
- context: CacheManagerContext,
777
- ) {
795
+ context: CacheManagerContext
796
+ ): Promise<Partial<CheckCacheEntryResult<EntityData>>> {
778
797
  const typeNames = [...possibleTypes.map(type => type.typeName), typeName];
779
798
 
780
799
  const checkResults = await Promise.all(
781
- typeNames.map(name => this._checkCacheEntry(DATA_ENTITIES, `${name}::${validTypeIDValue}`, options, context)),
800
+ typeNames.map(name =>
801
+ this._checkCacheEntry<EntityData>(DATA_ENTITIES, `${name}::${validTypeIDValue}`, options, context)
802
+ )
782
803
  );
783
804
 
784
- const validResults = checkResults.filter(result => !!result) as CheckCacheEntryResult[];
785
- let validResult: CheckCacheEntryResult | undefined;
805
+ const validResults = checkResults.filter(result => !!result) as CheckCacheEntryResult<EntityData>[];
806
+ let validResult: CheckCacheEntryResult<EntityData> | undefined;
786
807
 
787
808
  if (validResults.length === 1) {
788
809
  validResult = validResults[0];
@@ -790,12 +811,15 @@ export default class CacheManager implements CacheManagerDef {
790
811
  validResults.sort(({ cacheability: a }, { cacheability: b }) => a.metadata.ttl - b.metadata.ttl);
791
812
 
792
813
  validResult = {
793
- cacheability: validResults[0].cacheability,
794
- entry: validResults.reduce((obj, { entry }) => this._mergeObjects(obj, entry), {}),
814
+ cacheability: validResults[0]!.cacheability,
815
+ entry: validResults.reduce<Partial<EntityData>>(
816
+ (obj, { entry }) => mergeDataSets(obj, entry, this._typeIDKey),
817
+ {}
818
+ ) as EntityData,
795
819
  };
796
820
  }
797
821
 
798
- return (validResult || {}) as Partial<CheckCacheEntryResult>;
822
+ return validResult ?? {};
799
823
  }
800
824
 
801
825
  private async _retrieveCachedParentNodeData(
@@ -803,7 +827,7 @@ export default class CacheManager implements CacheManagerDef {
803
827
  { hashedRequestFieldCacheKey, propNameOrIndex, requestFieldCacheKey }: KeysAndPaths,
804
828
  fieldTypeInfo: FieldTypeInfo,
805
829
  options: RequestOptions,
806
- context: CacheManagerContext,
830
+ context: CacheManagerContext
807
831
  ) {
808
832
  let entityData = CacheManager._getFieldDataFromAncestor(ancestorEntityData, propNameOrIndex);
809
833
  let requestFieldPathData = CacheManager._getFieldDataFromAncestor(ancestorRequestFieldPathData, propNameOrIndex);
@@ -814,41 +838,36 @@ export default class CacheManager implements CacheManagerDef {
814
838
  hashedRequestFieldCacheKey,
815
839
  requestFieldCacheKey,
816
840
  options,
817
- context,
841
+ context
818
842
  );
819
843
 
820
- if (entry) {
821
- requestFieldPathData = this._mergeObjects(requestFieldPathData, entry);
822
- }
844
+ requestFieldPathData = combineDataSets(requestFieldPathData, entry, this._typeIDKey);
823
845
 
824
846
  if (entryCacheability) {
825
847
  cacheability = entryCacheability;
826
848
  }
827
849
  }
828
850
 
829
- const validTypeIDValue = getValidTypeIDValue(requestFieldPathData, fieldTypeInfo, this._typeIDKey);
851
+ const validTypeIDValue = getValidTypeIdValue(requestFieldPathData, fieldTypeInfo, this._typeIDKey);
830
852
 
831
853
  if (CacheManager._isNodeEntity(fieldTypeInfo) && validTypeIDValue) {
832
854
  const { cacheability: entryCacheability, entry } = await this._retrieveCachedEntityData(
833
855
  validTypeIDValue,
834
856
  fieldTypeInfo,
835
857
  options,
836
- context,
858
+ context
837
859
  );
838
860
 
839
- if (entry) {
840
- entityData = this._mergeObjects(entityData, entry);
841
- }
861
+ entityData = combineDataSets(entityData, entry, this._typeIDKey);
842
862
 
843
- if (entryCacheability && (!cacheability || entryCacheability.metadata.ttl > cacheability?.metadata.ttl)) {
863
+ if (entryCacheability && (!cacheability || entryCacheability.metadata.ttl > cacheability.metadata.ttl)) {
844
864
  cacheability = entryCacheability;
845
865
  }
846
866
  }
847
867
 
848
- const data =
849
- !isUndefined(requestFieldPathData) || !isUndefined(entityData)
850
- ? this._mergeObjects(requestFieldPathData, entityData)
851
- : entityData ?? requestFieldPathData;
868
+ const data = isEqual(entityData, requestFieldPathData)
869
+ ? entityData
870
+ : combineDataSets(entityData, requestFieldPathData, this._typeIDKey);
852
871
 
853
872
  return {
854
873
  cacheability,
@@ -862,16 +881,17 @@ export default class CacheManager implements CacheManagerDef {
862
881
  hash: string,
863
882
  requestFieldCacheKey: string,
864
883
  options: RequestOptions,
865
- context: CacheManagerContext,
866
- ) {
867
- return (this._checkCacheEntry(REQUEST_FIELD_PATHS, hash, options, { ...context, requestFieldCacheKey }) ||
868
- {}) as Partial<CheckCacheEntryResult>;
884
+ context: CacheManagerContext
885
+ ): Promise<Partial<CheckCacheEntryResult>> {
886
+ return (
887
+ (await this._checkCacheEntry(REQUEST_FIELD_PATHS, hash, options, { ...context, requestFieldCacheKey })) || {}
888
+ );
869
889
  }
870
890
 
871
891
  private async _retrieveCachedResponseData(
872
892
  { ast }: RequestData,
873
893
  options: RequestOptions,
874
- context: CacheManagerContext,
894
+ context: CacheManagerContext
875
895
  ): Promise<CachedResponseData> {
876
896
  const cachedResponseData: CachedResponseData = {
877
897
  cacheMetadata: new Map(),
@@ -881,6 +901,11 @@ export default class CacheManager implements CacheManagerDef {
881
901
  };
882
902
 
883
903
  const queryNode = getOperationDefinitions(ast, context.operation)[0];
904
+
905
+ if (!queryNode) {
906
+ return cachedResponseData;
907
+ }
908
+
884
909
  const fieldsAndTypeNames = getChildFields(queryNode);
885
910
 
886
911
  if (!fieldsAndTypeNames) {
@@ -889,14 +914,8 @@ export default class CacheManager implements CacheManagerDef {
889
914
 
890
915
  await Promise.all(
891
916
  fieldsAndTypeNames.map(({ fieldNode }) =>
892
- this._analyzeFieldNode(
893
- fieldNode,
894
- { requestFieldPath: context.operation },
895
- cachedResponseData,
896
- options,
897
- context,
898
- ),
899
- ),
917
+ this._analyzeFieldNode(fieldNode, { requestFieldPath: context.operation }, cachedResponseData, options, context)
918
+ )
900
919
  );
901
920
 
902
921
  cachedResponseData.fieldCount = CacheManager._countFieldPathChecklist(cachedResponseData.fieldPathChecklist);
@@ -905,11 +924,9 @@ export default class CacheManager implements CacheManagerDef {
905
924
 
906
925
  private _retrieveResponseDataForCaching(
907
926
  normalizedResponseData: RawResponseDataWithMaybeCacheMetadata,
908
- context: CacheManagerContext,
927
+ context: CacheManagerContext
909
928
  ) {
910
- const responseChunks = this._responseChunksAwaitingCaching.get(
911
- context.requestID,
912
- ) as RawResponseDataWithMaybeCacheMetadata[];
929
+ const responseChunks = this._responseChunksAwaitingCaching.get(context.requestID)!;
913
930
 
914
931
  this._responseChunksAwaitingCaching.delete(context.requestID);
915
932
  return mergeResponseDataSets([...responseChunks, normalizedResponseData]);
@@ -919,14 +936,14 @@ export default class CacheManager implements CacheManagerDef {
919
936
  private async _setCacheEntry(
920
937
  cacheType: CacheTypes,
921
938
  hash: string,
922
- value: any,
939
+ value: unknown,
923
940
  cachemapOptions: CachemapOptions,
924
941
  _options: RequestOptions,
925
- _context: CacheManagerContext & { requestFieldCacheKey?: string },
942
+ _context: CacheManagerContext & { requestFieldCacheKey?: string }
926
943
  ): Promise<void> {
927
944
  try {
928
945
  await this._cache.set(`${cacheType}::${hash}`, cloneDeep(value), cachemapOptions);
929
- } catch (error) {
946
+ } catch {
930
947
  // no catch
931
948
  }
932
949
  }
@@ -935,9 +952,14 @@ export default class CacheManager implements CacheManagerDef {
935
952
  requestData: RequestData,
936
953
  responseData: ResponseDataForCaching,
937
954
  options: RequestOptions,
938
- context: CacheManagerContext,
955
+ context: CacheManagerContext
939
956
  ): Promise<void> {
940
957
  const operationNode = getOperationDefinitions(requestData.ast, context.operation)[0];
958
+
959
+ if (!operationNode) {
960
+ return;
961
+ }
962
+
941
963
  const fieldsAndTypeNames = getChildFields(operationNode);
942
964
 
943
965
  if (!fieldsAndTypeNames) {
@@ -951,9 +973,9 @@ export default class CacheManager implements CacheManagerDef {
951
973
  { requestFieldPath: context.operation },
952
974
  responseData,
953
975
  options,
954
- context,
976
+ context
955
977
  );
956
- }),
978
+ })
957
979
  );
958
980
  }
959
981
 
@@ -962,10 +984,10 @@ export default class CacheManager implements CacheManagerDef {
962
984
  keysAndPaths: KeysAndPaths,
963
985
  { cacheMetadata, entityData, requestFieldPathData }: ResponseDataForCaching,
964
986
  options: RequestOptions,
965
- context: CacheManagerContext,
987
+ context: CacheManagerContext
966
988
  ) {
967
989
  const { requestFieldPath, responseDataPath } = keysAndPaths;
968
- const fieldData = get(entityData, responseDataPath);
990
+ const fieldData = get(entityData, responseDataPath) as unknown;
969
991
  const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
970
992
  const cacheability = cacheMetadata.get(requestFieldPath);
971
993
 
@@ -981,8 +1003,8 @@ export default class CacheManager implements CacheManagerDef {
981
1003
  keysAndPaths,
982
1004
  { cacheability, data: requestFieldPathData, fieldTypeInfo },
983
1005
  options,
984
- context,
985
- ),
1006
+ context
1007
+ )
986
1008
  );
987
1009
 
988
1010
  const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
@@ -993,7 +1015,7 @@ export default class CacheManager implements CacheManagerDef {
993
1015
 
994
1016
  if (isEntity) {
995
1017
  promises.push(
996
- this._setEntityCacheEntry(keysAndPaths, { cacheability, data: entityData, fieldTypeInfo }, options, context),
1018
+ this._setEntityCacheEntry(keysAndPaths, { cacheability, data: entityData, fieldTypeInfo }, options, context)
997
1019
  );
998
1020
  }
999
1021
 
@@ -1004,15 +1026,15 @@ export default class CacheManager implements CacheManagerDef {
1004
1026
  { responseDataPath }: KeysAndPaths,
1005
1027
  { cacheability, data, fieldTypeInfo }: DataForCachingEntry,
1006
1028
  options: RequestOptions,
1007
- context: CacheManagerContext,
1029
+ context: CacheManagerContext
1008
1030
  ) {
1009
- let fieldData = get(data, responseDataPath);
1031
+ let fieldData = get(data, responseDataPath) as EntityData;
1010
1032
  const fieldTypeName = fieldTypeInfo.isEntity ? fieldTypeInfo.typeName : fieldData.__typename;
1011
- const entityDataKey = `${fieldTypeName}::${fieldData[this._typeIDKey]}`;
1012
- const result = await this._checkCacheEntry(DATA_ENTITIES, entityDataKey, options, context);
1033
+ const entityDataKey = `${fieldTypeName}::${String(fieldData[this._typeIDKey])}`;
1034
+ const result = await this._checkCacheEntry<EntityData>(DATA_ENTITIES, entityDataKey, options, context);
1013
1035
 
1014
1036
  if (result) {
1015
- fieldData = this._mergeObjects(result.entry, fieldData);
1037
+ fieldData = mergeDataSets(result.entry, fieldData, this._typeIDKey);
1016
1038
  }
1017
1039
 
1018
1040
  await this._setCacheEntry(
@@ -1021,7 +1043,7 @@ export default class CacheManager implements CacheManagerDef {
1021
1043
  fieldData,
1022
1044
  { cacheHeaders: { cacheControl: cacheability.printCacheControl() }, tag: options.tag },
1023
1045
  options,
1024
- context,
1046
+ context
1025
1047
  );
1026
1048
 
1027
1049
  set(data, responseDataPath, { __cacheKey: `${DATA_ENTITIES}::${entityDataKey}` });
@@ -1032,12 +1054,17 @@ export default class CacheManager implements CacheManagerDef {
1032
1054
  ancestorKeysAndPaths: AncestorKeysAndPaths,
1033
1055
  { cacheMetadata, data }: ResponseData,
1034
1056
  options: RequestOptions,
1035
- context: CacheManagerContext,
1057
+ context: CacheManagerContext
1036
1058
  ): void {
1037
1059
  const { requestFieldPath: ancestorRequestFieldPath } = ancestorKeysAndPaths;
1038
1060
  const keysAndPaths = buildFieldKeysAndPaths(field, ancestorKeysAndPaths, context);
1039
1061
  const { requestFieldPath, responseDataPath } = keysAndPaths;
1040
- const fieldData = get(data, responseDataPath);
1062
+
1063
+ if (!isObjectLike(data)) {
1064
+ return;
1065
+ }
1066
+
1067
+ const fieldData = get(data, responseDataPath) as unknown;
1041
1068
  const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
1042
1069
 
1043
1070
  if (!isObjectLike(fieldData) && !fieldTypeInfo?.hasDirectives) {
@@ -1049,23 +1076,23 @@ export default class CacheManager implements CacheManagerDef {
1049
1076
  if (isObjectLike(fieldData)) {
1050
1077
  iterateChildFields(
1051
1078
  field,
1052
- fieldData as PlainObjectMap | any[],
1079
+ fieldData,
1053
1080
  context.fragmentDefinitions,
1054
1081
  (
1055
1082
  childField: FieldNode,
1056
1083
  _typeName: string | undefined,
1057
1084
  _fragmentKind: string | undefined,
1058
1085
  _fragmentName: string | undefined,
1059
- childIndex?: number,
1086
+ childIndex?: number
1060
1087
  ) => {
1061
1088
  this._setFieldCacheability(
1062
1089
  childField,
1063
1090
  { index: childIndex, requestFieldPath, responseDataPath },
1064
1091
  { cacheMetadata, data },
1065
1092
  options,
1066
- context,
1093
+ context
1067
1094
  );
1068
- },
1095
+ }
1069
1096
  );
1070
1097
  }
1071
1098
  }
@@ -1073,7 +1100,7 @@ export default class CacheManager implements CacheManagerDef {
1073
1100
  private _setFieldTypeCacheDirective(
1074
1101
  cacheMetadata: CacheMetadata,
1075
1102
  { ancestorRequestFieldPath, requestFieldPath }: { ancestorRequestFieldPath?: string; requestFieldPath: string },
1076
- { fieldTypeMap, operation }: CacheManagerContext,
1103
+ { fieldTypeMap, operation }: CacheManagerContext
1077
1104
  ): void {
1078
1105
  if (cacheMetadata.has(requestFieldPath)) {
1079
1106
  return;
@@ -1089,18 +1116,18 @@ export default class CacheManager implements CacheManagerDef {
1089
1116
  cacheMetadata,
1090
1117
  cacheMetadata.get(ancestorRequestFieldPath),
1091
1118
  requestFieldPath,
1092
- operation,
1119
+ operation
1093
1120
  );
1094
1121
  }
1095
1122
  }
1096
1123
 
1097
1124
  @logPartialCompiled()
1098
- private async _setPartialQueryResponse(
1125
+ private _setPartialQueryResponse(
1099
1126
  hash: string,
1100
1127
  partialQueryResponse: PartialQueryResponse,
1101
1128
  _options: RequestOptions,
1102
- _context: CacheManagerContext,
1103
- ): Promise<void> {
1129
+ _context: CacheManagerContext
1130
+ ): void {
1104
1131
  this._partialQueryResponses.set(hash, partialQueryResponse);
1105
1132
  }
1106
1133
 
@@ -1108,7 +1135,7 @@ export default class CacheManager implements CacheManagerDef {
1108
1135
  hash: string,
1109
1136
  { cacheMetadata, data }: ResponseData,
1110
1137
  options: RequestOptions,
1111
- context: CacheManagerContext,
1138
+ context: CacheManagerContext
1112
1139
  ): Promise<void> {
1113
1140
  const dehydratedCacheMetadata = dehydrateCacheMetadata(cacheMetadata);
1114
1141
  const cacheControl = CacheManager._getOperationCacheControl(cacheMetadata, context.operation);
@@ -1119,7 +1146,7 @@ export default class CacheManager implements CacheManagerDef {
1119
1146
  { cacheMetadata: dehydratedCacheMetadata, data },
1120
1147
  { cacheHeaders: { cacheControl }, tag: options.tag },
1121
1148
  options,
1122
- context,
1149
+ context
1123
1150
  );
1124
1151
  }
1125
1152
 
@@ -1128,14 +1155,14 @@ export default class CacheManager implements CacheManagerDef {
1128
1155
  keysAndPaths: KeysAndPaths,
1129
1156
  { cacheability, data, fieldTypeInfo }: DataForCachingEntry,
1130
1157
  options: RequestOptions,
1131
- context: CacheManagerContext,
1158
+ context: CacheManagerContext
1132
1159
  ): Promise<void> {
1133
1160
  const { hashedRequestFieldCacheKey, requestFieldCacheKey, responseDataPath } = keysAndPaths;
1134
- let fieldData = get(data, responseDataPath);
1161
+ let fieldData = get(data, responseDataPath) as unknown;
1135
1162
  const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
1136
1163
  const hasArgsOrDirectives = fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives;
1137
1164
 
1138
- if (context.operation === QUERY && (isEntity || hasArgsOrDirectives)) {
1165
+ if (context.operation === OperationTypeNode.QUERY && (isEntity || hasArgsOrDirectives)) {
1139
1166
  if (isPlainObject(fieldData) && field.selectionSet?.selections) {
1140
1167
  fieldData = filterOutPropsWithArgsOrDirectives(fieldData, field.selectionSet.selections, keysAndPaths, context);
1141
1168
  }
@@ -1145,8 +1172,8 @@ export default class CacheManager implements CacheManagerDef {
1145
1172
  requestFieldCacheKey,
1146
1173
  });
1147
1174
 
1148
- if (result && isObjectLike(fieldData)) {
1149
- fieldData = this._mergeObjects(result.entry, fieldData);
1175
+ if (result && isObjectLike(result.entry) && isObjectLike(fieldData)) {
1176
+ fieldData = mergeDataSets(result.entry, fieldData, this._typeIDKey);
1150
1177
  }
1151
1178
 
1152
1179
  await this._setCacheEntry(
@@ -1155,7 +1182,7 @@ export default class CacheManager implements CacheManagerDef {
1155
1182
  fieldData,
1156
1183
  { cacheHeaders: { cacheControl: cacheability.printCacheControl() }, tag: options.tag },
1157
1184
  options,
1158
- { ...context, requestFieldCacheKey },
1185
+ { ...context, requestFieldCacheKey }
1159
1186
  );
1160
1187
 
1161
1188
  if (hasChildFields(field, { fragmentDefinitions: context.fragmentDefinitions })) {
@@ -1170,7 +1197,7 @@ export default class CacheManager implements CacheManagerDef {
1170
1197
 
1171
1198
  private _setResponseChunksAwaitingCaching(
1172
1199
  normalizedResponseData: RawResponseDataWithMaybeCacheMetadata,
1173
- context: CacheManagerContext,
1200
+ context: CacheManagerContext
1174
1201
  ) {
1175
1202
  const responseChunks = this._responseChunksAwaitingCaching.get(context.requestID);
1176
1203