@apollo/client 3.8.7 → 3.8.8

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 (609) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +14 -0
  3. package/CHANGELOG.md +3357 -0
  4. package/apollo-client.cjs +314 -316
  5. package/apollo-client.cjs.map +1 -1
  6. package/apollo-client.min.cjs +1 -1
  7. package/cache/cache.cjs +133 -152
  8. package/cache/cache.cjs.map +1 -1
  9. package/cache/cache.cjs.native.js +133 -152
  10. package/cache/core/cache.d.ts +10 -0
  11. package/cache/core/cache.js +17 -5
  12. package/cache/core/cache.js.map +1 -1
  13. package/cache/core/types/Cache.d.ts +1 -1
  14. package/cache/core/types/Cache.js.map +1 -1
  15. package/cache/core/types/DataProxy.d.ts +92 -0
  16. package/cache/core/types/common.js +4 -1
  17. package/cache/core/types/common.js.map +1 -1
  18. package/cache/inmemory/entityStore.d.ts +1 -1
  19. package/cache/inmemory/entityStore.js +190 -29
  20. package/cache/inmemory/entityStore.js.map +1 -1
  21. package/cache/inmemory/fixPolyfills.js +9 -0
  22. package/cache/inmemory/fixPolyfills.js.map +1 -1
  23. package/cache/inmemory/fixPolyfills.native.js +12 -0
  24. package/cache/inmemory/fixPolyfills.native.js.map +1 -1
  25. package/cache/inmemory/fragmentRegistry.js +23 -12
  26. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  27. package/cache/inmemory/helpers.js +20 -11
  28. package/cache/inmemory/helpers.js.map +1 -1
  29. package/cache/inmemory/inMemoryCache.js +161 -8
  30. package/cache/inmemory/inMemoryCache.js.map +1 -1
  31. package/cache/inmemory/key-extractor.js +72 -4
  32. package/cache/inmemory/key-extractor.js.map +1 -1
  33. package/cache/inmemory/object-canon.js +91 -3
  34. package/cache/inmemory/object-canon.js.map +1 -1
  35. package/cache/inmemory/policies.js +193 -43
  36. package/cache/inmemory/policies.js.map +1 -1
  37. package/cache/inmemory/reactiveVars.js +20 -2
  38. package/cache/inmemory/reactiveVars.js.map +1 -1
  39. package/cache/inmemory/readFromStore.d.ts +4 -0
  40. package/cache/inmemory/readFromStore.js +54 -9
  41. package/cache/inmemory/readFromStore.js.map +1 -1
  42. package/cache/inmemory/types.d.ts +28 -0
  43. package/cache/inmemory/types.js.map +1 -1
  44. package/cache/inmemory/writeToStore.js +152 -25
  45. package/cache/inmemory/writeToStore.js.map +1 -1
  46. package/config/jest/setup.js +2 -0
  47. package/config/jest/setup.js.map +1 -1
  48. package/core/ApolloClient.d.ts +264 -3
  49. package/core/ApolloClient.js +235 -7
  50. package/core/ApolloClient.js.map +1 -1
  51. package/core/LocalState.d.ts +4 -6
  52. package/core/LocalState.js +56 -18
  53. package/core/LocalState.js.map +1 -1
  54. package/core/ObservableQuery.d.ts +25 -0
  55. package/core/ObservableQuery.js +239 -30
  56. package/core/ObservableQuery.js.map +1 -1
  57. package/core/QueryInfo.d.ts +3 -3
  58. package/core/QueryInfo.js +116 -13
  59. package/core/QueryInfo.js.map +1 -1
  60. package/core/QueryManager.d.ts +4 -0
  61. package/core/QueryManager.js +229 -33
  62. package/core/QueryManager.js.map +1 -1
  63. package/core/core.cjs +112 -103
  64. package/core/core.cjs.map +1 -1
  65. package/core/core.cjs.native.js +112 -103
  66. package/core/equalByQuery.js +20 -1
  67. package/core/equalByQuery.js.map +1 -1
  68. package/core/index.d.ts +1 -1
  69. package/core/index.js +19 -0
  70. package/core/index.js.map +1 -1
  71. package/core/networkStatus.d.ts +39 -0
  72. package/core/networkStatus.js +39 -0
  73. package/core/networkStatus.js.map +1 -1
  74. package/core/types.d.ts +9 -0
  75. package/core/types.js.map +1 -1
  76. package/core/watchQueryOptions.d.ts +225 -1
  77. package/core/watchQueryOptions.js.map +1 -1
  78. package/dev/dev.cjs +5 -111
  79. package/dev/dev.cjs.map +1 -1
  80. package/dev/dev.cjs.native.js +5 -111
  81. package/dev/loadErrorMessageHandler.js.map +1 -1
  82. package/errors/errors.cjs +1 -1
  83. package/errors/errors.cjs.map +1 -1
  84. package/errors/errors.cjs.native.js +1 -1
  85. package/errors/index.js +14 -1
  86. package/errors/index.js.map +1 -1
  87. package/invariantErrorCodes.js +1 -0
  88. package/link/batch/batch.cjs +2 -2
  89. package/link/batch/batch.cjs.map +1 -1
  90. package/link/batch/batch.cjs.native.js +2 -2
  91. package/link/batch/batchLink.d.ts +21 -0
  92. package/link/batch/batchLink.js +2 -1
  93. package/link/batch/batchLink.js.map +1 -1
  94. package/link/batch/batching.js +24 -1
  95. package/link/batch/batching.js.map +1 -1
  96. package/link/batch-http/batch-http.cjs +3 -2
  97. package/link/batch-http/batch-http.cjs.map +1 -1
  98. package/link/batch-http/batch-http.cjs.native.js +3 -2
  99. package/link/batch-http/batchHttpLink.d.ts +4 -0
  100. package/link/batch-http/batchHttpLink.js +53 -2
  101. package/link/batch-http/batchHttpLink.js.map +1 -1
  102. package/link/context/context.cjs.map +1 -1
  103. package/link/context/index.js +1 -0
  104. package/link/context/index.js.map +1 -1
  105. package/link/core/ApolloLink.js +12 -5
  106. package/link/core/ApolloLink.js.map +1 -1
  107. package/link/core/core.cjs +5 -5
  108. package/link/core/core.cjs.map +1 -1
  109. package/link/core/core.cjs.native.js +5 -5
  110. package/link/error/error.cjs +1 -1
  111. package/link/error/error.cjs.map +1 -1
  112. package/link/error/error.cjs.native.js +1 -1
  113. package/link/error/index.d.ts +3 -0
  114. package/link/error/index.js +4 -1
  115. package/link/error/index.js.map +1 -1
  116. package/link/http/HttpLink.d.ts +0 -2
  117. package/link/http/HttpLink.js +1 -1
  118. package/link/http/HttpLink.js.map +1 -1
  119. package/link/http/checkFetcher.js.map +1 -1
  120. package/link/http/createHttpLink.js +23 -1
  121. package/link/http/createHttpLink.js.map +1 -1
  122. package/link/http/createSignalIfSupported.d.ts +5 -0
  123. package/link/http/createSignalIfSupported.js +5 -0
  124. package/link/http/createSignalIfSupported.js.map +1 -1
  125. package/link/http/http.cjs +14 -12
  126. package/link/http/http.cjs.map +1 -1
  127. package/link/http/http.cjs.native.js +14 -12
  128. package/link/http/index.js +2 -1
  129. package/link/http/index.js.map +1 -1
  130. package/link/http/iterators/async.d.ts +4 -0
  131. package/link/http/iterators/async.js +4 -0
  132. package/link/http/iterators/async.js.map +1 -1
  133. package/link/http/iterators/nodeStream.d.ts +4 -0
  134. package/link/http/iterators/nodeStream.js +4 -0
  135. package/link/http/iterators/nodeStream.js.map +1 -1
  136. package/link/http/iterators/promise.d.ts +4 -0
  137. package/link/http/iterators/promise.js +4 -0
  138. package/link/http/iterators/promise.js.map +1 -1
  139. package/link/http/iterators/reader.d.ts +4 -0
  140. package/link/http/iterators/reader.js +4 -0
  141. package/link/http/iterators/reader.js.map +1 -1
  142. package/link/http/parseAndCheckHttpResponse.js +51 -10
  143. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  144. package/link/http/responseIterator.d.ts +4 -0
  145. package/link/http/responseIterator.js +6 -0
  146. package/link/http/responseIterator.js.map +1 -1
  147. package/link/http/rewriteURIForGET.d.ts +1 -1
  148. package/link/http/rewriteURIForGET.js +10 -0
  149. package/link/http/rewriteURIForGET.js.map +1 -1
  150. package/link/http/selectHttpOptionsAndBody.d.ts +45 -0
  151. package/link/http/selectHttpOptionsAndBody.js +23 -0
  152. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  153. package/link/http/selectURI.js.map +1 -1
  154. package/link/http/serializeFetchParameter.js.map +1 -1
  155. package/link/persisted-queries/index.js +34 -4
  156. package/link/persisted-queries/index.js.map +1 -1
  157. package/link/persisted-queries/persisted-queries.cjs +4 -4
  158. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  159. package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
  160. package/link/remove-typename/remove-typename.cjs +12 -9
  161. package/link/remove-typename/remove-typename.cjs.map +1 -1
  162. package/link/remove-typename/remove-typename.cjs.native.js +12 -9
  163. package/link/remove-typename/removeTypenameFromVariables.js +12 -9
  164. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  165. package/link/retry/delayFunction.d.ts +29 -0
  166. package/link/retry/delayFunction.js +6 -0
  167. package/link/retry/delayFunction.js.map +1 -1
  168. package/link/retry/retry.cjs +5 -5
  169. package/link/retry/retry.cjs.map +1 -1
  170. package/link/retry/retry.cjs.native.js +5 -5
  171. package/link/retry/retryFunction.d.ts +20 -0
  172. package/link/retry/retryLink.d.ts +6 -0
  173. package/link/retry/retryLink.js +31 -6
  174. package/link/retry/retryLink.js.map +1 -1
  175. package/link/schema/index.d.ts +13 -0
  176. package/link/schema/index.js +3 -3
  177. package/link/schema/index.js.map +1 -1
  178. package/link/schema/schema.cjs +3 -3
  179. package/link/schema/schema.cjs.map +1 -1
  180. package/link/schema/schema.cjs.native.js +3 -3
  181. package/link/subscriptions/index.js +35 -2
  182. package/link/subscriptions/index.js.map +1 -1
  183. package/link/subscriptions/subscriptions.cjs +3 -2
  184. package/link/subscriptions/subscriptions.cjs.map +1 -1
  185. package/link/subscriptions/subscriptions.cjs.native.js +3 -2
  186. package/link/utils/createOperation.js.map +1 -1
  187. package/link/utils/filterOperationVariables.js +4 -0
  188. package/link/utils/filterOperationVariables.js.map +1 -1
  189. package/link/utils/toPromise.js.map +1 -1
  190. package/link/utils/transformOperation.js +3 -2
  191. package/link/utils/transformOperation.js.map +1 -1
  192. package/link/utils/utils.cjs +2 -2
  193. package/link/utils/utils.cjs.map +1 -1
  194. package/link/utils/utils.cjs.native.js +2 -2
  195. package/link/utils/validateOperation.js.map +1 -1
  196. package/link/ws/index.d.ts +12 -0
  197. package/link/ws/index.js +1 -1
  198. package/link/ws/index.js.map +1 -1
  199. package/link/ws/ws.cjs +1 -1
  200. package/link/ws/ws.cjs.map +1 -1
  201. package/link/ws/ws.cjs.native.js +1 -1
  202. package/package.json +49 -38
  203. package/react/cache/QueryReference.d.ts +6 -1
  204. package/react/cache/QueryReference.js +26 -1
  205. package/react/cache/QueryReference.js.map +1 -1
  206. package/react/cache/SuspenseCache.d.ts +10 -0
  207. package/react/cache/SuspenseCache.js +1 -1
  208. package/react/cache/SuspenseCache.js.map +1 -1
  209. package/react/cache/getSuspenseCache.js.map +1 -1
  210. package/react/context/ApolloContext.d.ts +5 -0
  211. package/react/context/ApolloContext.js +10 -3
  212. package/react/context/ApolloContext.js.map +1 -1
  213. package/react/context/context.cjs +1 -3
  214. package/react/context/context.cjs.map +1 -1
  215. package/react/context/context.cjs.native.js +1 -3
  216. package/react/hoc/graphql.js.map +1 -1
  217. package/react/hoc/hoc-utils.js +3 -1
  218. package/react/hoc/hoc-utils.js.map +1 -1
  219. package/react/hoc/hoc.cjs +9 -17
  220. package/react/hoc/hoc.cjs.map +1 -1
  221. package/react/hoc/hoc.cjs.native.js +9 -17
  222. package/react/hoc/mutation-hoc.js +9 -4
  223. package/react/hoc/mutation-hoc.js.map +1 -1
  224. package/react/hoc/query-hoc.js +10 -4
  225. package/react/hoc/query-hoc.js.map +1 -1
  226. package/react/hoc/subscription-hoc.js +10 -4
  227. package/react/hoc/subscription-hoc.js.map +1 -1
  228. package/react/hoc/withApollo.js +3 -4
  229. package/react/hoc/withApollo.js.map +1 -1
  230. package/react/hooks/hooks.cjs +30 -22
  231. package/react/hooks/hooks.cjs.map +1 -1
  232. package/react/hooks/hooks.cjs.native.js +30 -22
  233. package/react/hooks/internal/__use.js +5 -0
  234. package/react/hooks/internal/__use.js.map +1 -1
  235. package/react/hooks/internal/index.js +1 -0
  236. package/react/hooks/internal/index.js.map +1 -1
  237. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  238. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
  239. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  240. package/react/hooks/useBackgroundQuery.js +6 -0
  241. package/react/hooks/useBackgroundQuery.js.map +1 -1
  242. package/react/hooks/useFragment.js +4 -3
  243. package/react/hooks/useFragment.js.map +1 -1
  244. package/react/hooks/useLazyQuery.js +13 -4
  245. package/react/hooks/useLazyQuery.js.map +1 -1
  246. package/react/hooks/useMutation.js +8 -3
  247. package/react/hooks/useMutation.js.map +1 -1
  248. package/react/hooks/useQuery.d.ts +11 -0
  249. package/react/hooks/useQuery.js +137 -5
  250. package/react/hooks/useQuery.js.map +1 -1
  251. package/react/hooks/useReactiveVar.js +5 -0
  252. package/react/hooks/useReactiveVar.js.map +1 -1
  253. package/react/hooks/useReadQuery.d.ts +19 -0
  254. package/react/hooks/useReadQuery.js.map +1 -1
  255. package/react/hooks/useSubscription.js +5 -0
  256. package/react/hooks/useSubscription.js.map +1 -1
  257. package/react/hooks/useSuspenseQuery.js +11 -5
  258. package/react/hooks/useSuspenseQuery.js.map +1 -1
  259. package/react/hooks/useSyncExternalStore.js +53 -1
  260. package/react/hooks/useSyncExternalStore.js.map +1 -1
  261. package/react/parser/index.js +4 -5
  262. package/react/parser/index.js.map +1 -1
  263. package/react/parser/parser.cjs +2 -4
  264. package/react/parser/parser.cjs.map +1 -1
  265. package/react/parser/parser.cjs.native.js +2 -4
  266. package/react/ssr/RenderPromises.js +21 -1
  267. package/react/ssr/RenderPromises.js.map +1 -1
  268. package/react/ssr/getDataFromTree.js +18 -3
  269. package/react/ssr/getDataFromTree.js.map +1 -1
  270. package/react/ssr/ssr.cjs +6 -4
  271. package/react/ssr/ssr.cjs.map +1 -1
  272. package/react/ssr/ssr.cjs.native.js +6 -4
  273. package/react/types/types.d.ts +66 -0
  274. package/testing/core/core.cjs +14 -11
  275. package/testing/core/core.cjs.map +1 -1
  276. package/testing/core/core.cjs.native.js +14 -11
  277. package/testing/core/itAsync.d.ts +1 -1
  278. package/testing/core/itAsync.js.map +1 -1
  279. package/testing/core/mocking/mockFetch.d.ts +2 -2
  280. package/testing/core/mocking/mockFetch.js +8 -4
  281. package/testing/core/mocking/mockFetch.js.map +1 -1
  282. package/testing/core/mocking/mockLink.js +17 -7
  283. package/testing/core/mocking/mockLink.js.map +1 -1
  284. package/testing/core/mocking/mockQueryManager.js +2 -0
  285. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  286. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  287. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  288. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  289. package/testing/core/mocking/mockWatchQuery.js +1 -1
  290. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  291. package/testing/core/observableToPromise.d.ts +17 -3
  292. package/testing/core/observableToPromise.js +5 -0
  293. package/testing/core/observableToPromise.js.map +1 -1
  294. package/testing/core/subscribeAndCount.js +3 -0
  295. package/testing/core/subscribeAndCount.js.map +1 -1
  296. package/testing/core/wait.js +2 -2
  297. package/testing/core/wait.js.map +1 -1
  298. package/testing/core/withConsoleSpy.d.ts +3 -0
  299. package/testing/core/withConsoleSpy.js +7 -1
  300. package/testing/core/withConsoleSpy.js.map +1 -1
  301. package/testing/core/wrap.js +2 -0
  302. package/testing/core/wrap.js.map +1 -1
  303. package/testing/internal/ObservableStream.js +14 -14
  304. package/testing/internal/ObservableStream.js.map +1 -1
  305. package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
  306. package/testing/internal/disposables/spyOnConsole.js +2 -0
  307. package/testing/internal/disposables/spyOnConsole.js.map +1 -1
  308. package/testing/internal/disposables/withCleanup.d.ts +1 -0
  309. package/testing/internal/disposables/withCleanup.js +3 -0
  310. package/testing/internal/disposables/withCleanup.js.map +1 -1
  311. package/testing/internal/profile/Render.d.ts +28 -0
  312. package/testing/internal/profile/Render.js +12 -1
  313. package/testing/internal/profile/Render.js.map +1 -1
  314. package/testing/internal/profile/profile.d.ts +44 -7
  315. package/testing/internal/profile/profile.js +63 -51
  316. package/testing/internal/profile/profile.js.map +1 -1
  317. package/testing/internal/profile/traces.d.ts +4 -0
  318. package/testing/internal/profile/traces.js +9 -5
  319. package/testing/internal/profile/traces.js.map +1 -1
  320. package/testing/matchers/ProfiledComponent.js +27 -22
  321. package/testing/matchers/ProfiledComponent.js.map +1 -1
  322. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  323. package/testing/matchers/toMatchDocument.js.map +1 -1
  324. package/testing/react/MockedProvider.d.ts +4 -0
  325. package/testing/react/MockedProvider.js +6 -2
  326. package/testing/react/MockedProvider.js.map +1 -1
  327. package/testing/testing.cjs +4 -2
  328. package/testing/testing.cjs.map +1 -1
  329. package/testing/testing.cjs.native.js +4 -2
  330. package/utilities/common/arrays.js +1 -0
  331. package/utilities/common/arrays.js.map +1 -1
  332. package/utilities/common/canUse.js +16 -1
  333. package/utilities/common/canUse.js.map +1 -1
  334. package/utilities/common/cloneDeep.d.ts +3 -0
  335. package/utilities/common/cloneDeep.js +5 -0
  336. package/utilities/common/cloneDeep.js.map +1 -1
  337. package/utilities/common/compact.d.ts +4 -0
  338. package/utilities/common/compact.js +4 -0
  339. package/utilities/common/compact.js.map +1 -1
  340. package/utilities/common/errorHandling.js +1 -3
  341. package/utilities/common/errorHandling.js.map +1 -1
  342. package/utilities/common/incrementalResult.js +3 -0
  343. package/utilities/common/incrementalResult.js.map +1 -1
  344. package/utilities/common/makeUniqueId.js +2 -0
  345. package/utilities/common/makeUniqueId.js.map +1 -1
  346. package/utilities/common/maybeDeepFreeze.js +3 -0
  347. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  348. package/utilities/common/mergeDeep.js +12 -1
  349. package/utilities/common/mergeDeep.js.map +1 -1
  350. package/utilities/common/mergeOptions.d.ts +1 -1
  351. package/utilities/common/mergeOptions.js.map +1 -1
  352. package/utilities/common/omitDeep.js.map +1 -1
  353. package/utilities/globals/global.js +7 -1
  354. package/utilities/globals/global.js.map +1 -1
  355. package/utilities/globals/globals.cjs +4 -5
  356. package/utilities/globals/globals.cjs.map +1 -1
  357. package/utilities/globals/globals.cjs.native.js +4 -5
  358. package/utilities/globals/index.d.ts +4 -0
  359. package/utilities/globals/index.js +7 -0
  360. package/utilities/globals/index.js.map +1 -1
  361. package/utilities/globals/invariantWrappers.d.ts +40 -0
  362. package/utilities/globals/invariantWrappers.js +11 -3
  363. package/utilities/globals/invariantWrappers.js.map +1 -1
  364. package/utilities/globals/maybe.js.map +1 -1
  365. package/utilities/graphql/DocumentTransform.js +19 -6
  366. package/utilities/graphql/DocumentTransform.js.map +1 -1
  367. package/utilities/graphql/directives.js +3 -0
  368. package/utilities/graphql/directives.js.map +1 -1
  369. package/utilities/graphql/fragments.d.ts +25 -0
  370. package/utilities/graphql/fragments.js +36 -0
  371. package/utilities/graphql/fragments.js.map +1 -1
  372. package/utilities/graphql/getFromAST.d.ts +5 -0
  373. package/utilities/graphql/getFromAST.js +9 -0
  374. package/utilities/graphql/getFromAST.js.map +1 -1
  375. package/utilities/graphql/print.js.map +1 -1
  376. package/utilities/graphql/storeUtils.d.ts +14 -0
  377. package/utilities/graphql/storeUtils.js +7 -2
  378. package/utilities/graphql/storeUtils.js.map +1 -1
  379. package/utilities/graphql/transform.js +106 -7
  380. package/utilities/graphql/transform.js.map +1 -1
  381. package/utilities/observables/Concast.d.ts +1 -1
  382. package/utilities/observables/Concast.js +84 -1
  383. package/utilities/observables/Concast.js.map +1 -1
  384. package/utilities/observables/Observable.js +6 -0
  385. package/utilities/observables/Observable.js.map +1 -1
  386. package/utilities/observables/asyncMap.js +12 -3
  387. package/utilities/observables/asyncMap.js.map +1 -1
  388. package/utilities/observables/iteration.js +3 -0
  389. package/utilities/observables/iteration.js.map +1 -1
  390. package/utilities/observables/subclassing.js +14 -0
  391. package/utilities/observables/subclassing.js.map +1 -1
  392. package/utilities/policies/pagination.js +47 -3
  393. package/utilities/policies/pagination.js.map +1 -1
  394. package/utilities/promises/decoration.js +1 -0
  395. package/utilities/promises/decoration.js.map +1 -1
  396. package/utilities/types/DeepOmit.js.map +1 -1
  397. package/utilities/types/DeepPartial.d.ts +1 -1
  398. package/utilities/types/DeepPartial.js +4 -0
  399. package/utilities/types/DeepPartial.js.map +1 -1
  400. package/utilities/types/IsStrictlyAny.js.map +1 -1
  401. package/utilities/types/TODO.d.ts +3 -0
  402. package/utilities/types/TODO.js +2 -0
  403. package/utilities/types/TODO.js.map +1 -0
  404. package/utilities/utilities.cjs +31 -27
  405. package/utilities/utilities.cjs.map +1 -1
  406. package/utilities/utilities.cjs.native.js +31 -27
  407. package/version.js +1 -1
  408. package/cache/core/cache.d.ts.map +0 -1
  409. package/cache/core/types/Cache.d.ts.map +0 -1
  410. package/cache/core/types/DataProxy.d.ts.map +0 -1
  411. package/cache/core/types/common.d.ts.map +0 -1
  412. package/cache/index.d.ts.map +0 -1
  413. package/cache/inmemory/entityStore.d.ts.map +0 -1
  414. package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
  415. package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
  416. package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
  417. package/cache/inmemory/helpers.d.ts.map +0 -1
  418. package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
  419. package/cache/inmemory/key-extractor.d.ts.map +0 -1
  420. package/cache/inmemory/object-canon.d.ts.map +0 -1
  421. package/cache/inmemory/policies.d.ts.map +0 -1
  422. package/cache/inmemory/reactiveVars.d.ts.map +0 -1
  423. package/cache/inmemory/readFromStore.d.ts.map +0 -1
  424. package/cache/inmemory/types.d.ts.map +0 -1
  425. package/cache/inmemory/writeToStore.d.ts.map +0 -1
  426. package/config/jest/setup.d.ts.map +0 -1
  427. package/core/ApolloClient.d.ts.map +0 -1
  428. package/core/LocalState.d.ts.map +0 -1
  429. package/core/ObservableQuery.d.ts.map +0 -1
  430. package/core/QueryInfo.d.ts.map +0 -1
  431. package/core/QueryManager.d.ts.map +0 -1
  432. package/core/equalByQuery.d.ts.map +0 -1
  433. package/core/index.d.ts.map +0 -1
  434. package/core/networkStatus.d.ts.map +0 -1
  435. package/core/types.d.ts.map +0 -1
  436. package/core/watchQueryOptions.d.ts.map +0 -1
  437. package/dev/index.d.ts.map +0 -1
  438. package/dev/loadDevMessages.d.ts.map +0 -1
  439. package/dev/loadErrorMessageHandler.d.ts.map +0 -1
  440. package/dev/loadErrorMessages.d.ts.map +0 -1
  441. package/errors/index.d.ts.map +0 -1
  442. package/index.d.ts.map +0 -1
  443. package/invariantErrorCodes.d.ts.map +0 -1
  444. package/link/batch/batchLink.d.ts.map +0 -1
  445. package/link/batch/batching.d.ts.map +0 -1
  446. package/link/batch/index.d.ts.map +0 -1
  447. package/link/batch-http/batchHttpLink.d.ts.map +0 -1
  448. package/link/batch-http/index.d.ts.map +0 -1
  449. package/link/context/index.d.ts.map +0 -1
  450. package/link/core/ApolloLink.d.ts.map +0 -1
  451. package/link/core/concat.d.ts.map +0 -1
  452. package/link/core/empty.d.ts.map +0 -1
  453. package/link/core/execute.d.ts.map +0 -1
  454. package/link/core/from.d.ts.map +0 -1
  455. package/link/core/index.d.ts.map +0 -1
  456. package/link/core/split.d.ts.map +0 -1
  457. package/link/core/types.d.ts.map +0 -1
  458. package/link/error/index.d.ts.map +0 -1
  459. package/link/http/HttpLink.d.ts.map +0 -1
  460. package/link/http/checkFetcher.d.ts.map +0 -1
  461. package/link/http/createHttpLink.d.ts.map +0 -1
  462. package/link/http/createSignalIfSupported.d.ts.map +0 -1
  463. package/link/http/index.d.ts.map +0 -1
  464. package/link/http/iterators/async.d.ts.map +0 -1
  465. package/link/http/iterators/nodeStream.d.ts.map +0 -1
  466. package/link/http/iterators/promise.d.ts.map +0 -1
  467. package/link/http/iterators/reader.d.ts.map +0 -1
  468. package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
  469. package/link/http/responseIterator.d.ts.map +0 -1
  470. package/link/http/rewriteURIForGET.d.ts.map +0 -1
  471. package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
  472. package/link/http/selectURI.d.ts.map +0 -1
  473. package/link/http/serializeFetchParameter.d.ts.map +0 -1
  474. package/link/persisted-queries/index.d.ts.map +0 -1
  475. package/link/remove-typename/index.d.ts.map +0 -1
  476. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
  477. package/link/retry/delayFunction.d.ts.map +0 -1
  478. package/link/retry/index.d.ts.map +0 -1
  479. package/link/retry/retryFunction.d.ts.map +0 -1
  480. package/link/retry/retryLink.d.ts.map +0 -1
  481. package/link/schema/index.d.ts.map +0 -1
  482. package/link/subscriptions/index.d.ts.map +0 -1
  483. package/link/utils/createOperation.d.ts.map +0 -1
  484. package/link/utils/filterOperationVariables.d.ts.map +0 -1
  485. package/link/utils/fromError.d.ts.map +0 -1
  486. package/link/utils/fromPromise.d.ts.map +0 -1
  487. package/link/utils/index.d.ts.map +0 -1
  488. package/link/utils/throwServerError.d.ts.map +0 -1
  489. package/link/utils/toPromise.d.ts.map +0 -1
  490. package/link/utils/transformOperation.d.ts.map +0 -1
  491. package/link/utils/validateOperation.d.ts.map +0 -1
  492. package/link/ws/index.d.ts.map +0 -1
  493. package/react/cache/QueryReference.d.ts.map +0 -1
  494. package/react/cache/SuspenseCache.d.ts.map +0 -1
  495. package/react/cache/getSuspenseCache.d.ts.map +0 -1
  496. package/react/cache/index.d.ts.map +0 -1
  497. package/react/cache/types.d.ts.map +0 -1
  498. package/react/components/Mutation.d.ts.map +0 -1
  499. package/react/components/Query.d.ts.map +0 -1
  500. package/react/components/Subscription.d.ts.map +0 -1
  501. package/react/components/index.d.ts.map +0 -1
  502. package/react/components/types.d.ts.map +0 -1
  503. package/react/context/ApolloConsumer.d.ts.map +0 -1
  504. package/react/context/ApolloContext.d.ts.map +0 -1
  505. package/react/context/ApolloProvider.d.ts.map +0 -1
  506. package/react/context/index.d.ts.map +0 -1
  507. package/react/hoc/graphql.d.ts.map +0 -1
  508. package/react/hoc/hoc-utils.d.ts.map +0 -1
  509. package/react/hoc/index.d.ts.map +0 -1
  510. package/react/hoc/mutation-hoc.d.ts.map +0 -1
  511. package/react/hoc/query-hoc.d.ts.map +0 -1
  512. package/react/hoc/subscription-hoc.d.ts.map +0 -1
  513. package/react/hoc/types.d.ts.map +0 -1
  514. package/react/hoc/withApollo.d.ts.map +0 -1
  515. package/react/hooks/constants.d.ts.map +0 -1
  516. package/react/hooks/index.d.ts.map +0 -1
  517. package/react/hooks/internal/__use.d.ts.map +0 -1
  518. package/react/hooks/internal/index.d.ts.map +0 -1
  519. package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
  520. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
  521. package/react/hooks/useApolloClient.d.ts.map +0 -1
  522. package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
  523. package/react/hooks/useFragment.d.ts.map +0 -1
  524. package/react/hooks/useLazyQuery.d.ts.map +0 -1
  525. package/react/hooks/useMutation.d.ts.map +0 -1
  526. package/react/hooks/useQuery.d.ts.map +0 -1
  527. package/react/hooks/useReactiveVar.d.ts.map +0 -1
  528. package/react/hooks/useReadQuery.d.ts.map +0 -1
  529. package/react/hooks/useSubscription.d.ts.map +0 -1
  530. package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
  531. package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
  532. package/react/index.d.ts.map +0 -1
  533. package/react/parser/index.d.ts.map +0 -1
  534. package/react/ssr/RenderPromises.d.ts.map +0 -1
  535. package/react/ssr/getDataFromTree.d.ts.map +0 -1
  536. package/react/ssr/index.d.ts.map +0 -1
  537. package/react/ssr/renderToStringWithData.d.ts.map +0 -1
  538. package/react/types/types.d.ts.map +0 -1
  539. package/testing/core/index.d.ts.map +0 -1
  540. package/testing/core/itAsync.d.ts.map +0 -1
  541. package/testing/core/mocking/mockClient.d.ts.map +0 -1
  542. package/testing/core/mocking/mockFetch.d.ts.map +0 -1
  543. package/testing/core/mocking/mockLink.d.ts.map +0 -1
  544. package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
  545. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
  546. package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
  547. package/testing/core/observableToPromise.d.ts.map +0 -1
  548. package/testing/core/subscribeAndCount.d.ts.map +0 -1
  549. package/testing/core/wait.d.ts.map +0 -1
  550. package/testing/core/withConsoleSpy.d.ts.map +0 -1
  551. package/testing/core/wrap.d.ts.map +0 -1
  552. package/testing/index.d.ts.map +0 -1
  553. package/testing/internal/ObservableStream.d.ts.map +0 -1
  554. package/testing/internal/disposables/index.d.ts.map +0 -1
  555. package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
  556. package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
  557. package/testing/internal/index.d.ts.map +0 -1
  558. package/testing/internal/profile/Render.d.ts.map +0 -1
  559. package/testing/internal/profile/index.d.ts.map +0 -1
  560. package/testing/internal/profile/profile.d.ts.map +0 -1
  561. package/testing/internal/profile/traces.d.ts.map +0 -1
  562. package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
  563. package/testing/matchers/index.d.ts.map +0 -1
  564. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
  565. package/testing/matchers/toMatchDocument.d.ts.map +0 -1
  566. package/testing/react/MockedProvider.d.ts.map +0 -1
  567. package/utilities/common/arrays.d.ts.map +0 -1
  568. package/utilities/common/canUse.d.ts.map +0 -1
  569. package/utilities/common/cloneDeep.d.ts.map +0 -1
  570. package/utilities/common/compact.d.ts.map +0 -1
  571. package/utilities/common/errorHandling.d.ts.map +0 -1
  572. package/utilities/common/filterInPlace.d.ts +0 -2
  573. package/utilities/common/filterInPlace.d.ts.map +0 -1
  574. package/utilities/common/filterInPlace.js +0 -11
  575. package/utilities/common/filterInPlace.js.map +0 -1
  576. package/utilities/common/incrementalResult.d.ts.map +0 -1
  577. package/utilities/common/makeUniqueId.d.ts.map +0 -1
  578. package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
  579. package/utilities/common/mergeDeep.d.ts.map +0 -1
  580. package/utilities/common/mergeOptions.d.ts.map +0 -1
  581. package/utilities/common/objects.d.ts.map +0 -1
  582. package/utilities/common/omitDeep.d.ts.map +0 -1
  583. package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
  584. package/utilities/common/stripTypename.d.ts.map +0 -1
  585. package/utilities/globals/global.d.ts.map +0 -1
  586. package/utilities/globals/index.d.ts.map +0 -1
  587. package/utilities/globals/invariantWrappers.d.ts.map +0 -1
  588. package/utilities/globals/maybe.d.ts.map +0 -1
  589. package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
  590. package/utilities/graphql/directives.d.ts.map +0 -1
  591. package/utilities/graphql/fragments.d.ts.map +0 -1
  592. package/utilities/graphql/getFromAST.d.ts.map +0 -1
  593. package/utilities/graphql/operations.d.ts.map +0 -1
  594. package/utilities/graphql/print.d.ts.map +0 -1
  595. package/utilities/graphql/storeUtils.d.ts.map +0 -1
  596. package/utilities/graphql/transform.d.ts.map +0 -1
  597. package/utilities/index.d.ts.map +0 -1
  598. package/utilities/observables/Concast.d.ts.map +0 -1
  599. package/utilities/observables/Observable.d.ts.map +0 -1
  600. package/utilities/observables/asyncMap.d.ts.map +0 -1
  601. package/utilities/observables/iteration.d.ts.map +0 -1
  602. package/utilities/observables/subclassing.d.ts.map +0 -1
  603. package/utilities/policies/pagination.d.ts.map +0 -1
  604. package/utilities/promises/decoration.d.ts.map +0 -1
  605. package/utilities/types/DeepOmit.d.ts.map +0 -1
  606. package/utilities/types/DeepPartial.d.ts.map +0 -1
  607. package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
  608. package/utilities/types/Primitive.d.ts.map +0 -1
  609. package/version.d.ts.map +0 -1
@@ -8,24 +8,37 @@ import { hasOwn, fieldNameFromStoreName } from "./helpers.js";
8
8
  var DELETE = Object.create(null);
9
9
  var delModifier = function () { return DELETE; };
10
10
  var INVALIDATE = Object.create(null);
11
- var EntityStore = (function () {
11
+ var EntityStore = /** @class */ (function () {
12
12
  function EntityStore(policies, group) {
13
13
  var _this = this;
14
14
  this.policies = policies;
15
15
  this.group = group;
16
16
  this.data = Object.create(null);
17
+ // Maps root entity IDs to the number of times they have been retained, minus
18
+ // the number of times they have been released. Retained entities keep other
19
+ // entities they reference (even indirectly) from being garbage collected.
17
20
  this.rootIds = Object.create(null);
21
+ // Lazily tracks { __ref: <dataId> } strings contained by this.data[dataId].
18
22
  this.refs = Object.create(null);
23
+ // Bound function that can be passed around to provide easy access to fields
24
+ // of Reference objects as well as ordinary objects.
19
25
  this.getFieldValue = function (objectOrReference, storeFieldName) {
20
- return maybeDeepFreeze(isReference(objectOrReference)
21
- ? _this.get(objectOrReference.__ref, storeFieldName)
26
+ return maybeDeepFreeze(isReference(objectOrReference) ?
27
+ _this.get(objectOrReference.__ref, storeFieldName)
22
28
  : objectOrReference && objectOrReference[storeFieldName]);
23
29
  };
30
+ // Returns true for non-normalized StoreObjects and non-dangling
31
+ // References, indicating that readField(name, objOrRef) has a chance of
32
+ // working. Useful for filtering out dangling references from lists.
24
33
  this.canRead = function (objOrRef) {
25
- return isReference(objOrRef)
26
- ? _this.has(objOrRef.__ref)
34
+ return isReference(objOrRef) ?
35
+ _this.has(objOrRef.__ref)
27
36
  : typeof objOrRef === "object";
28
37
  };
38
+ // Bound function that converts an id or an object with a __typename and
39
+ // primary key fields to a Reference object. If called with a Reference object,
40
+ // that same Reference object is returned. Pass true for mergeIntoStore to persist
41
+ // an object into the store.
29
42
  this.toReference = function (objOrIdOrRef, mergeIntoStore) {
30
43
  if (typeof objOrIdOrRef === "string") {
31
44
  return makeReference(objOrIdOrRef);
@@ -43,6 +56,9 @@ var EntityStore = (function () {
43
56
  }
44
57
  };
45
58
  }
59
+ // Although the EntityStore class is abstract, it contains concrete
60
+ // implementations of the various NormalizedCache interface methods that
61
+ // are inherited by the Root and Layer subclasses.
46
62
  EntityStore.prototype.toObject = function () {
47
63
  return __assign({}, this.data);
48
64
  };
@@ -66,6 +82,11 @@ var EntityStore = (function () {
66
82
  }
67
83
  };
68
84
  EntityStore.prototype.lookup = function (dataId, dependOnExistence) {
85
+ // The has method (above) calls lookup with dependOnExistence = true, so
86
+ // that it can later be invalidated when we add or remove a StoreObject for
87
+ // this dataId. Any consumer who cares about the contents of the StoreObject
88
+ // should not rely on this dependency, since the contents could change
89
+ // without the object being added or removed.
69
90
  if (dependOnExistence)
70
91
  this.group.depend(dataId, "__exists");
71
92
  if (hasOwn.call(this.data, dataId)) {
@@ -81,32 +102,54 @@ var EntityStore = (function () {
81
102
  EntityStore.prototype.merge = function (older, newer) {
82
103
  var _this = this;
83
104
  var dataId;
105
+ // Convert unexpected references to ID strings.
84
106
  if (isReference(older))
85
107
  older = older.__ref;
86
108
  if (isReference(newer))
87
109
  newer = newer.__ref;
88
110
  var existing = typeof older === "string" ? this.lookup((dataId = older)) : older;
89
111
  var incoming = typeof newer === "string" ? this.lookup((dataId = newer)) : newer;
112
+ // If newer was a string ID, but that ID was not defined in this store,
113
+ // then there are no fields to be merged, so we're done.
90
114
  if (!incoming)
91
115
  return;
92
116
  invariant(typeof dataId === "string", 1);
93
117
  var merged = new DeepMerger(storeObjectReconciler).merge(existing, incoming);
118
+ // Even if merged === existing, existing may have come from a lower
119
+ // layer, so we always need to set this.data[dataId] on this level.
94
120
  this.data[dataId] = merged;
95
121
  if (merged !== existing) {
96
122
  delete this.refs[dataId];
97
123
  if (this.group.caching) {
98
124
  var fieldsToDirty_1 = Object.create(null);
125
+ // If we added a new StoreObject where there was previously none, dirty
126
+ // anything that depended on the existence of this dataId, such as the
127
+ // EntityStore#has method.
99
128
  if (!existing)
100
129
  fieldsToDirty_1.__exists = 1;
130
+ // Now invalidate dependents who called getFieldValue for any fields
131
+ // that are changing as a result of this merge.
101
132
  Object.keys(incoming).forEach(function (storeFieldName) {
102
133
  if (!existing ||
103
134
  existing[storeFieldName] !== merged[storeFieldName]) {
135
+ // Always dirty the full storeFieldName, which may include
136
+ // serialized arguments following the fieldName prefix.
104
137
  fieldsToDirty_1[storeFieldName] = 1;
138
+ // Also dirty fieldNameFromStoreName(storeFieldName) if it's
139
+ // different from storeFieldName and this field does not have
140
+ // keyArgs configured, because that means the cache can't make
141
+ // any assumptions about how field values with the same field
142
+ // name but different arguments might be interrelated, so it
143
+ // must err on the side of invalidating all field values that
144
+ // share the same short fieldName, regardless of arguments.
105
145
  var fieldName = fieldNameFromStoreName(storeFieldName);
106
146
  if (fieldName !== storeFieldName &&
107
147
  !_this.policies.hasKeyArgs(merged.__typename, fieldName)) {
108
148
  fieldsToDirty_1[fieldName] = 1;
109
149
  }
150
+ // If merged[storeFieldName] has become undefined, and this is the
151
+ // Root layer, actually delete the property from the merged object,
152
+ // which is guaranteed to have been created fresh in this method.
110
153
  if (merged[storeFieldName] === void 0 && !(_this instanceof Layer)) {
111
154
  delete merged[storeFieldName];
112
155
  }
@@ -114,6 +157,10 @@ var EntityStore = (function () {
114
157
  });
115
158
  if (fieldsToDirty_1.__typename &&
116
159
  !(existing && existing.__typename) &&
160
+ // Since we return default root __typename strings
161
+ // automatically from store.get, we don't need to dirty the
162
+ // ROOT_QUERY.__typename field if merged.__typename is equal
163
+ // to the default string (usually "Query").
117
164
  this.policies.rootTypenamesById[dataId] === merged.__typename) {
118
165
  delete fieldsToDirty_1.__typename;
119
166
  }
@@ -137,8 +184,8 @@ var EntityStore = (function () {
137
184
  toReference: this.toReference,
138
185
  canRead: this.canRead,
139
186
  readField: function (fieldNameOrOptions, from) {
140
- return _this.policies.readField(typeof fieldNameOrOptions === "string"
141
- ? {
187
+ return _this.policies.readField(typeof fieldNameOrOptions === "string" ?
188
+ {
142
189
  fieldName: fieldNameOrOptions,
143
190
  from: from || makeReference(dataId),
144
191
  }
@@ -150,13 +197,9 @@ var EntityStore = (function () {
150
197
  var fieldValue = storeObject[storeFieldName];
151
198
  if (fieldValue === void 0)
152
199
  return;
153
- var modify = typeof fields === "function"
154
- ? fields
155
- : fields[storeFieldName] || fields[fieldName];
200
+ var modify = typeof fields === "function" ? fields : (fields[storeFieldName] || fields[fieldName]);
156
201
  if (modify) {
157
- var newValue = modify === delModifier
158
- ? DELETE
159
- : modify(maybeDeepFreeze(fieldValue), __assign(__assign({}, sharedDetails_1), { fieldName: fieldName, storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) }));
202
+ var newValue = modify === delModifier ? DELETE : (modify(maybeDeepFreeze(fieldValue), __assign(__assign({}, sharedDetails_1), { fieldName: fieldName, storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) })));
160
203
  if (newValue === INVALIDATE) {
161
204
  _this.group.dirty(dataId, storeFieldName);
162
205
  }
@@ -178,6 +221,7 @@ var EntityStore = (function () {
178
221
  checkReference(newValue);
179
222
  }
180
223
  else if (Array.isArray(newValue)) {
224
+ // Warn about writing "mixed" arrays of Reference and non-Reference objects
181
225
  var seenReference = false;
182
226
  var someNonReference = void 0;
183
227
  for (var _i = 0, newValue_1 = newValue; _i < newValue_1.length; _i++) {
@@ -188,8 +232,11 @@ var EntityStore = (function () {
188
232
  break;
189
233
  }
190
234
  else {
235
+ // Do not warn on primitive values, since those could never be represented
236
+ // by a reference. This is a valid (albeit uncommon) use case.
191
237
  if (typeof value === "object" && !!value) {
192
238
  var id = _this.policies.identify(value)[0];
239
+ // check if object could even be referenced, otherwise we are not interested in it for this warning
193
240
  if (id) {
194
241
  someNonReference = value;
195
242
  }
@@ -225,18 +272,23 @@ var EntityStore = (function () {
225
272
  }
226
273
  return false;
227
274
  };
275
+ // If called with only one argument, removes the entire entity
276
+ // identified by dataId. If called with a fieldName as well, removes all
277
+ // fields of that entity whose names match fieldName according to the
278
+ // fieldNameFromStoreName helper function. If called with a fieldName
279
+ // and variables, removes all fields of that entity whose names match fieldName
280
+ // and whose arguments when cached exactly match the variables passed.
228
281
  EntityStore.prototype.delete = function (dataId, fieldName, args) {
229
282
  var _a;
230
283
  var storeObject = this.lookup(dataId);
231
284
  if (storeObject) {
232
285
  var typename = this.getFieldValue(storeObject, "__typename");
233
- var storeFieldName = fieldName && args
234
- ? this.policies.getStoreFieldName({ typename: typename, fieldName: fieldName, args: args })
286
+ var storeFieldName = fieldName && args ?
287
+ this.policies.getStoreFieldName({ typename: typename, fieldName: fieldName, args: args })
235
288
  : fieldName;
236
- return this.modify(dataId, storeFieldName
237
- ? (_a = {},
238
- _a[storeFieldName] = delModifier,
239
- _a) : delModifier);
289
+ return this.modify(dataId, storeFieldName ? (_a = {},
290
+ _a[storeFieldName] = delModifier,
291
+ _a) : delModifier);
240
292
  }
241
293
  return false;
242
294
  };
@@ -249,6 +301,10 @@ var EntityStore = (function () {
249
301
  if (this instanceof Layer && this !== limit) {
250
302
  evicted = this.parent.evict(options, limit) || evicted;
251
303
  }
304
+ // Always invalidate the field to trigger rereading of watched
305
+ // queries, even if no cache data was modified by the eviction,
306
+ // because queries may depend on computed fields with custom read
307
+ // functions, whose values are not stored in the EntityStore.
252
308
  if (options.fieldName || evicted) {
253
309
  this.group.dirty(options.id, options.fieldName || "__exists");
254
310
  }
@@ -301,6 +357,8 @@ var EntityStore = (function () {
301
357
  }
302
358
  return 0;
303
359
  };
360
+ // Return a Set<string> of all the ID strings that have been retained by
361
+ // this layer/root *and* any layers/roots beneath it.
304
362
  EntityStore.prototype.getRootIdSet = function (ids) {
305
363
  if (ids === void 0) { ids = new Set(); }
306
364
  Object.keys(this.rootIds).forEach(ids.add, ids);
@@ -308,17 +366,29 @@ var EntityStore = (function () {
308
366
  this.parent.getRootIdSet(ids);
309
367
  }
310
368
  else {
369
+ // Official singleton IDs like ROOT_QUERY and ROOT_MUTATION are
370
+ // always considered roots for garbage collection, regardless of
371
+ // their retainment counts in this.rootIds.
311
372
  Object.keys(this.policies.rootTypenamesById).forEach(ids.add, ids);
312
373
  }
313
374
  return ids;
314
375
  };
376
+ // The goal of garbage collection is to remove IDs from the Root layer of the
377
+ // store that are no longer reachable starting from any IDs that have been
378
+ // explicitly retained (see retain and release, above). Returns an array of
379
+ // dataId strings that were removed from the store.
315
380
  EntityStore.prototype.gc = function () {
316
381
  var _this = this;
317
382
  var ids = this.getRootIdSet();
318
383
  var snapshot = this.toObject();
319
384
  ids.forEach(function (id) {
320
385
  if (hasOwn.call(snapshot, id)) {
386
+ // Because we are iterating over an ECMAScript Set, the IDs we add here
387
+ // will be visited in later iterations of the forEach loop only if they
388
+ // were not previously contained by the Set.
321
389
  Object.keys(_this.findChildRefIds(id)).forEach(ids.add, ids);
390
+ // By removing IDs from the snapshot object here, we protect them from
391
+ // getting removed from the root store layer below.
322
392
  delete snapshot[id];
323
393
  }
324
394
  });
@@ -338,13 +408,24 @@ var EntityStore = (function () {
338
408
  if (!root)
339
409
  return found_1;
340
410
  var workSet_1 = new Set([root]);
411
+ // Within the store, only arrays and objects can contain child entity
412
+ // references, so we can prune the traversal using this predicate:
341
413
  workSet_1.forEach(function (obj) {
342
414
  if (isReference(obj)) {
343
415
  found_1[obj.__ref] = true;
416
+ // In rare cases, a { __ref } Reference object may have other fields.
417
+ // This often indicates a mismerging of References with StoreObjects,
418
+ // but garbage collection should not be fooled by a stray __ref
419
+ // property in a StoreObject (ignoring all the other fields just
420
+ // because the StoreObject looks like a Reference). To avoid this
421
+ // premature termination of findChildRefIds recursion, we fall through
422
+ // to the code below, which will handle any other properties of obj.
344
423
  }
345
424
  if (isNonNullObject(obj)) {
346
425
  Object.keys(obj).forEach(function (key) {
347
426
  var child = obj[key];
427
+ // No need to add primitive values to the workSet, since they cannot
428
+ // contain reference objects.
348
429
  if (isNonNullObject(child)) {
349
430
  workSet_1.add(child);
350
431
  }
@@ -360,7 +441,20 @@ var EntityStore = (function () {
360
441
  return EntityStore;
361
442
  }());
362
443
  export { EntityStore };
363
- var CacheGroup = (function () {
444
+ // A single CacheGroup represents a set of one or more EntityStore objects,
445
+ // typically the Root store in a CacheGroup by itself, and all active Layer
446
+ // stores in a group together. A single EntityStore object belongs to only
447
+ // one CacheGroup, store.group. The CacheGroup is responsible for tracking
448
+ // dependencies, so store.group is helpful for generating unique keys for
449
+ // cached results that need to be invalidated when/if those dependencies
450
+ // change. If we used the EntityStore objects themselves as cache keys (that
451
+ // is, store rather than store.group), the cache would become unnecessarily
452
+ // fragmented by all the different Layer objects. Instead, the CacheGroup
453
+ // approach allows all optimistic Layer objects in the same linked list to
454
+ // belong to one CacheGroup, with the non-optimistic Root object belonging
455
+ // to another CacheGroup, allowing resultCaching dependencies to be tracked
456
+ // separately for optimistic and non-optimistic entity data.
457
+ var CacheGroup = /** @class */ (function () {
364
458
  function CacheGroup(caching, parent) {
365
459
  if (parent === void 0) { parent = null; }
366
460
  this.caching = caching;
@@ -377,6 +471,11 @@ var CacheGroup = (function () {
377
471
  this.d(makeDepKey(dataId, storeFieldName));
378
472
  var fieldName = fieldNameFromStoreName(storeFieldName);
379
473
  if (fieldName !== storeFieldName) {
474
+ // Fields with arguments that contribute extra identifying
475
+ // information to the fieldName (thus forming the storeFieldName)
476
+ // depend not only on the full storeFieldName but also on the
477
+ // short fieldName, so the field can be invalidated using either
478
+ // level of specificity.
380
479
  this.d(makeDepKey(dataId, fieldName));
381
480
  }
382
481
  if (this.parent) {
@@ -386,21 +485,41 @@ var CacheGroup = (function () {
386
485
  };
387
486
  CacheGroup.prototype.dirty = function (dataId, storeFieldName) {
388
487
  if (this.d) {
389
- this.d.dirty(makeDepKey(dataId, storeFieldName), storeFieldName === "__exists" ? "forget" : "setDirty");
488
+ this.d.dirty(makeDepKey(dataId, storeFieldName),
489
+ // When storeFieldName === "__exists", that means the entity identified
490
+ // by dataId has either disappeared from the cache or was newly added,
491
+ // so the result caching system would do well to "forget everything it
492
+ // knows" about that object. To achieve that kind of invalidation, we
493
+ // not only dirty the associated result cache entry, but also remove it
494
+ // completely from the dependency graph. For the optimism implementation
495
+ // details, see https://github.com/benjamn/optimism/pull/195.
496
+ storeFieldName === "__exists" ? "forget" : "setDirty");
390
497
  }
391
498
  };
392
499
  return CacheGroup;
393
500
  }());
394
501
  function makeDepKey(dataId, storeFieldName) {
502
+ // Since field names cannot have '#' characters in them, this method
503
+ // of joining the field name and the ID should be unambiguous, and much
504
+ // cheaper than JSON.stringify([dataId, fieldName]).
395
505
  return storeFieldName + "#" + dataId;
396
506
  }
397
507
  export function maybeDependOnExistenceOfEntity(store, entityId) {
398
508
  if (supportsResultCaching(store)) {
509
+ // We use this pseudo-field __exists elsewhere in the EntityStore code to
510
+ // represent changes in the existence of the entity object identified by
511
+ // entityId. This dependency gets reliably dirtied whenever an object with
512
+ // this ID is deleted (or newly created) within this group, so any result
513
+ // cache entries (for example, StoreReader#executeSelectionSet results) that
514
+ // depend on __exists for this entityId will get dirtied as well, leading to
515
+ // the eventual recomputation (instead of reuse) of those result objects the
516
+ // next time someone reads them from the cache.
399
517
  store.group.depend(entityId, "__exists");
400
518
  }
401
519
  }
402
520
  (function (EntityStore) {
403
- var Root = (function (_super) {
521
+ // Refer to this class as EntityStore.Root outside this namespace.
522
+ var Root = /** @class */ (function (_super) {
404
523
  __extends(Root, _super);
405
524
  function Root(_a) {
406
525
  var policies = _a.policies, _b = _a.resultCaching, resultCaching = _b === void 0 ? true : _b, seed = _a.seed;
@@ -412,9 +531,13 @@ export function maybeDependOnExistenceOfEntity(store, entityId) {
412
531
  return _this;
413
532
  }
414
533
  Root.prototype.addLayer = function (layerId, replay) {
534
+ // Adding an optimistic Layer on top of the Root actually adds the Layer
535
+ // on top of the Stump, so the Stump always comes between the Root and
536
+ // any Layer objects that we've added.
415
537
  return this.stump.addLayer(layerId, replay);
416
538
  };
417
539
  Root.prototype.removeLayer = function () {
540
+ // Never remove the root layer.
418
541
  return this;
419
542
  };
420
543
  Root.prototype.getStorage = function () {
@@ -424,7 +547,9 @@ export function maybeDependOnExistenceOfEntity(store, entityId) {
424
547
  }(EntityStore));
425
548
  EntityStore.Root = Root;
426
549
  })(EntityStore || (EntityStore = {}));
427
- var Layer = (function (_super) {
550
+ // Not exported, since all Layer instances are created by the addLayer method
551
+ // of the EntityStore.Root class.
552
+ var Layer = /** @class */ (function (_super) {
428
553
  __extends(Layer, _super);
429
554
  function Layer(id, parent, replay, group) {
430
555
  var _this = _super.call(this, parent.policies, group) || this;
@@ -440,22 +565,39 @@ var Layer = (function (_super) {
440
565
  };
441
566
  Layer.prototype.removeLayer = function (layerId) {
442
567
  var _this = this;
568
+ // Remove all instances of the given id, not just the first one.
443
569
  var parent = this.parent.removeLayer(layerId);
444
570
  if (layerId === this.id) {
445
571
  if (this.group.caching) {
572
+ // Dirty every ID we're removing. Technically we might be able to avoid
573
+ // dirtying fields that have values in higher layers, but we don't have
574
+ // easy access to higher layers here, and we're about to recreate those
575
+ // layers anyway (see parent.addLayer below).
446
576
  Object.keys(this.data).forEach(function (dataId) {
447
577
  var ownStoreObject = _this.data[dataId];
448
578
  var parentStoreObject = parent["lookup"](dataId);
449
579
  if (!parentStoreObject) {
580
+ // The StoreObject identified by dataId was defined in this layer
581
+ // but will be undefined in the parent layer, so we can delete the
582
+ // whole entity using this.delete(dataId). Since we're about to
583
+ // throw this layer away, the only goal of this deletion is to dirty
584
+ // the removed fields.
450
585
  _this.delete(dataId);
451
586
  }
452
587
  else if (!ownStoreObject) {
588
+ // This layer had an entry for dataId but it was undefined, which
589
+ // means the entity was deleted in this layer, and it's about to
590
+ // become undeleted when we remove this layer, so we need to dirty
591
+ // all fields that are about to be reexposed.
453
592
  _this.group.dirty(dataId, "__exists");
454
593
  Object.keys(parentStoreObject).forEach(function (storeFieldName) {
455
594
  _this.group.dirty(dataId, storeFieldName);
456
595
  });
457
596
  }
458
597
  else if (ownStoreObject !== parentStoreObject) {
598
+ // If ownStoreObject is not exactly the same as parentStoreObject,
599
+ // dirty any fields whose values will change as a result of this
600
+ // removal.
459
601
  Object.keys(ownStoreObject).forEach(function (storeFieldName) {
460
602
  if (!equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
461
603
  _this.group.dirty(dataId, storeFieldName);
@@ -466,8 +608,10 @@ var Layer = (function (_super) {
466
608
  }
467
609
  return parent;
468
610
  }
611
+ // No changes are necessary if the parent chain remains identical.
469
612
  if (parent === this.parent)
470
613
  return this;
614
+ // Recreate this layer on top of the new parent.
471
615
  return parent.addLayer(this.id, this.replay);
472
616
  };
473
617
  Layer.prototype.toObject = function () {
@@ -475,36 +619,53 @@ var Layer = (function (_super) {
475
619
  };
476
620
  Layer.prototype.findChildRefIds = function (dataId) {
477
621
  var fromParent = this.parent.findChildRefIds(dataId);
478
- return hasOwn.call(this.data, dataId)
479
- ? __assign(__assign({}, fromParent), _super.prototype.findChildRefIds.call(this, dataId)) : fromParent;
622
+ return hasOwn.call(this.data, dataId) ? __assign(__assign({}, fromParent), _super.prototype.findChildRefIds.call(this, dataId)) : fromParent;
480
623
  };
481
624
  Layer.prototype.getStorage = function () {
482
625
  var p = this.parent;
483
626
  while (p.parent)
484
627
  p = p.parent;
485
- return p.getStorage.apply(p, arguments);
628
+ return p.getStorage.apply(p,
629
+ // @ts-expect-error
630
+ arguments);
486
631
  };
487
632
  return Layer;
488
633
  }(EntityStore));
489
- var Stump = (function (_super) {
634
+ // Represents a Layer permanently installed just above the Root, which allows
635
+ // reading optimistically (and registering optimistic dependencies) even when
636
+ // no optimistic layers are currently active. The stump.group CacheGroup object
637
+ // is shared by any/all Layer objects added on top of the Stump.
638
+ var Stump = /** @class */ (function (_super) {
490
639
  __extends(Stump, _super);
491
640
  function Stump(root) {
492
641
  return _super.call(this, "EntityStore.Stump", root, function () { }, new CacheGroup(root.group.caching, root.group)) || this;
493
642
  }
494
643
  Stump.prototype.removeLayer = function () {
644
+ // Never remove the Stump layer.
495
645
  return this;
496
646
  };
497
- Stump.prototype.merge = function () {
498
- return this.parent.merge.apply(this.parent, arguments);
647
+ Stump.prototype.merge = function (older, newer) {
648
+ // We never want to write any data into the Stump, so we forward any merge
649
+ // calls to the Root instead. Another option here would be to throw an
650
+ // exception, but the toReference(object, true) function can sometimes
651
+ // trigger Stump writes (which used to be Root writes, before the Stump
652
+ // concept was introduced).
653
+ return this.parent.merge(older, newer);
499
654
  };
500
655
  return Stump;
501
656
  }(Layer));
502
657
  function storeObjectReconciler(existingObject, incomingObject, property) {
503
658
  var existingValue = existingObject[property];
504
659
  var incomingValue = incomingObject[property];
660
+ // Wherever there is a key collision, prefer the incoming value, unless
661
+ // it is deeply equal to the existing value. It's worth checking deep
662
+ // equality here (even though blindly returning incoming would be
663
+ // logically correct) because preserving the referential identity of
664
+ // existing data can prevent needless rereading and rerendering.
505
665
  return equal(existingValue, incomingValue) ? existingValue : incomingValue;
506
666
  }
507
667
  export function supportsResultCaching(store) {
668
+ // When result caching is disabled, store.depend will be null.
508
669
  return !!(store instanceof EntityStore && store.group.caching);
509
670
  }
510
671
  //# sourceMappingURL=entityStore.js.map