@apollo/client 3.4.17 → 3.5.6

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 (421) hide show
  1. package/README.md +1 -1
  2. package/{apollo-client.cjs.js → apollo-client.cjs} +1219 -1280
  3. package/apollo-client.cjs.map +1 -0
  4. package/apollo-client.min.cjs +1 -0
  5. package/cache/{cache.cjs.js → cache.cjs} +757 -601
  6. package/cache/cache.cjs.map +1 -0
  7. package/cache/core/cache.d.ts +6 -4
  8. package/cache/core/cache.d.ts.map +1 -1
  9. package/cache/core/cache.js +28 -1
  10. package/cache/core/cache.js.map +1 -1
  11. package/cache/core/types/Cache.d.ts +12 -10
  12. package/cache/core/types/Cache.d.ts.map +1 -1
  13. package/cache/core/types/Cache.js.map +1 -1
  14. package/cache/core/types/DataProxy.d.ts +4 -0
  15. package/cache/core/types/DataProxy.d.ts.map +1 -1
  16. package/cache/core/types/DataProxy.js.map +1 -1
  17. package/cache/core/types/common.d.ts +8 -5
  18. package/cache/core/types/common.d.ts.map +1 -1
  19. package/cache/core/types/common.js +6 -11
  20. package/cache/core/types/common.js.map +1 -1
  21. package/cache/inmemory/helpers.js +1 -1
  22. package/cache/inmemory/helpers.js.map +1 -1
  23. package/cache/inmemory/inMemoryCache.d.ts +4 -4
  24. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  25. package/cache/inmemory/inMemoryCache.js +12 -3
  26. package/cache/inmemory/inMemoryCache.js.map +1 -1
  27. package/cache/inmemory/key-extractor.d.ts +9 -0
  28. package/cache/inmemory/key-extractor.d.ts.map +1 -0
  29. package/cache/inmemory/key-extractor.js +118 -0
  30. package/cache/inmemory/key-extractor.js.map +1 -0
  31. package/cache/inmemory/policies.d.ts +7 -3
  32. package/cache/inmemory/policies.d.ts.map +1 -1
  33. package/cache/inmemory/policies.js +47 -118
  34. package/cache/inmemory/policies.js.map +1 -1
  35. package/cache/inmemory/readFromStore.d.ts +2 -2
  36. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  37. package/cache/inmemory/readFromStore.js +54 -42
  38. package/cache/inmemory/readFromStore.js.map +1 -1
  39. package/cache/inmemory/writeToStore.d.ts +8 -3
  40. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  41. package/cache/inmemory/writeToStore.js +166 -95
  42. package/cache/inmemory/writeToStore.js.map +1 -1
  43. package/cache/package.json +2 -1
  44. package/core/ApolloClient.d.ts +0 -1
  45. package/core/ApolloClient.d.ts.map +1 -1
  46. package/core/ApolloClient.js +3 -3
  47. package/core/ApolloClient.js.map +1 -1
  48. package/core/LocalState.js +1 -1
  49. package/core/LocalState.js.map +1 -1
  50. package/core/ObservableQuery.d.ts +2 -2
  51. package/core/ObservableQuery.d.ts.map +1 -1
  52. package/core/ObservableQuery.js +19 -14
  53. package/core/ObservableQuery.js.map +1 -1
  54. package/core/QueryInfo.d.ts +2 -2
  55. package/core/QueryInfo.d.ts.map +1 -1
  56. package/core/QueryInfo.js.map +1 -1
  57. package/core/QueryManager.d.ts +0 -1
  58. package/core/QueryManager.d.ts.map +1 -1
  59. package/core/QueryManager.js +10 -10
  60. package/core/QueryManager.js.map +1 -1
  61. package/core/{core.cjs.js → core.cjs} +38 -34
  62. package/core/core.cjs.map +1 -0
  63. package/core/package.json +2 -1
  64. package/errors/{errors.cjs.js → errors.cjs} +3 -3
  65. package/errors/errors.cjs.map +1 -0
  66. package/errors/index.d.ts +3 -1
  67. package/errors/index.d.ts.map +1 -1
  68. package/errors/index.js +2 -2
  69. package/errors/index.js.map +1 -1
  70. package/errors/package.json +2 -1
  71. package/invariantErrorCodes.js +84 -104
  72. package/link/batch/{batch.cjs.js → batch.cjs} +2 -2
  73. package/link/batch/batch.cjs.map +1 -0
  74. package/link/batch/batchLink.d.ts +0 -1
  75. package/link/batch/batchLink.d.ts.map +1 -1
  76. package/link/batch/batching.d.ts +0 -1
  77. package/link/batch/batching.d.ts.map +1 -1
  78. package/link/batch/batching.js +1 -1
  79. package/link/batch/batching.js.map +1 -1
  80. package/link/batch/package.json +2 -1
  81. package/link/batch-http/{batch-http.cjs.js → batch-http.cjs} +3 -3
  82. package/link/batch-http/batch-http.cjs.map +1 -0
  83. package/link/batch-http/batchHttpLink.d.ts +0 -1
  84. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  85. package/link/batch-http/batchHttpLink.js +3 -3
  86. package/link/batch-http/batchHttpLink.js.map +1 -1
  87. package/link/batch-http/package.json +2 -1
  88. package/link/context/{context.cjs.js → context.cjs} +1 -1
  89. package/link/context/context.cjs.map +1 -0
  90. package/link/context/index.js.map +1 -1
  91. package/link/context/package.json +2 -1
  92. package/link/core/ApolloLink.d.ts +2 -3
  93. package/link/core/ApolloLink.d.ts.map +1 -1
  94. package/link/core/ApolloLink.js +1 -1
  95. package/link/core/ApolloLink.js.map +1 -1
  96. package/link/core/{core.cjs.js → core.cjs} +2 -2
  97. package/link/core/core.cjs.map +1 -0
  98. package/link/core/package.json +2 -1
  99. package/link/core/types.d.ts +4 -7
  100. package/link/core/types.d.ts.map +1 -1
  101. package/link/core/types.js.map +1 -1
  102. package/link/error/{error.cjs.js → error.cjs} +2 -2
  103. package/link/error/error.cjs.map +1 -0
  104. package/link/error/index.d.ts +5 -7
  105. package/link/error/index.d.ts.map +1 -1
  106. package/link/error/index.js +1 -1
  107. package/link/error/index.js.map +1 -1
  108. package/link/error/package.json +2 -1
  109. package/link/http/checkFetcher.js +1 -1
  110. package/link/http/createHttpLink.d.ts.map +1 -1
  111. package/link/http/createHttpLink.js +3 -3
  112. package/link/http/createHttpLink.js.map +1 -1
  113. package/link/http/{http.cjs.js → http.cjs} +28 -15
  114. package/link/http/http.cjs.map +1 -0
  115. package/link/http/index.d.ts +1 -1
  116. package/link/http/index.d.ts.map +1 -1
  117. package/link/http/index.js +1 -1
  118. package/link/http/index.js.map +1 -1
  119. package/link/http/package.json +2 -1
  120. package/link/http/parseAndCheckHttpResponse.js +3 -3
  121. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  122. package/link/http/rewriteURIForGET.js +1 -1
  123. package/link/http/rewriteURIForGET.js.map +1 -1
  124. package/link/http/selectHttpOptionsAndBody.d.ts +11 -1
  125. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  126. package/link/http/selectHttpOptionsAndBody.js +20 -7
  127. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  128. package/link/http/serializeFetchParameter.js +1 -1
  129. package/link/http/serializeFetchParameter.js.map +1 -1
  130. package/link/persisted-queries/index.d.ts.map +1 -1
  131. package/link/persisted-queries/index.js +3 -3
  132. package/link/persisted-queries/index.js.map +1 -1
  133. package/link/persisted-queries/package.json +2 -1
  134. package/link/persisted-queries/{persisted-queries.cjs.js → persisted-queries.cjs} +3 -3
  135. package/link/persisted-queries/persisted-queries.cjs.map +1 -0
  136. package/link/retry/package.json +2 -1
  137. package/link/retry/{retry.cjs.js → retry.cjs} +1 -1
  138. package/link/retry/retry.cjs.map +1 -0
  139. package/link/retry/retryLink.d.ts +0 -1
  140. package/link/retry/retryLink.d.ts.map +1 -1
  141. package/link/retry/retryLink.js.map +1 -1
  142. package/link/schema/index.d.ts +0 -1
  143. package/link/schema/index.d.ts.map +1 -1
  144. package/link/schema/index.js +8 -1
  145. package/link/schema/index.js.map +1 -1
  146. package/link/schema/package.json +2 -1
  147. package/link/schema/{schema.cjs.js → schema.cjs} +9 -2
  148. package/link/schema/schema.cjs.map +1 -0
  149. package/link/utils/fromError.d.ts +0 -1
  150. package/link/utils/fromError.d.ts.map +1 -1
  151. package/link/utils/fromPromise.d.ts +0 -1
  152. package/link/utils/fromPromise.d.ts.map +1 -1
  153. package/link/utils/package.json +2 -1
  154. package/link/utils/toPromise.d.ts +0 -1
  155. package/link/utils/toPromise.d.ts.map +1 -1
  156. package/link/utils/{utils.cjs.js → utils.cjs} +2 -2
  157. package/link/utils/utils.cjs.map +1 -0
  158. package/link/utils/validateOperation.js +1 -1
  159. package/link/utils/validateOperation.js.map +1 -1
  160. package/link/ws/index.d.ts +0 -1
  161. package/link/ws/index.d.ts.map +1 -1
  162. package/link/ws/package.json +2 -1
  163. package/link/ws/{ws.cjs.js → ws.cjs} +1 -1
  164. package/link/ws/ws.cjs.map +1 -0
  165. package/{main.cjs.js → main.cjs} +5 -5
  166. package/main.cjs.map +1 -0
  167. package/package.json +20 -19
  168. package/react/components/Query.js.map +1 -1
  169. package/react/components/{components.cjs.js → components.cjs} +4 -4
  170. package/react/components/components.cjs.map +1 -0
  171. package/react/components/package.json +2 -1
  172. package/react/context/ApolloConsumer.js +1 -1
  173. package/react/context/ApolloProvider.js +1 -1
  174. package/react/context/{context.cjs.js → context.cjs} +6 -6
  175. package/react/context/context.cjs.map +1 -0
  176. package/react/context/index.d.ts +3 -3
  177. package/react/context/index.d.ts.map +1 -1
  178. package/react/context/index.js +3 -3
  179. package/react/context/index.js.map +1 -1
  180. package/react/context/package.json +2 -1
  181. package/react/hoc/hoc-utils.js +1 -1
  182. package/react/hoc/{hoc.cjs.js → hoc.cjs} +12 -12
  183. package/react/hoc/hoc.cjs.map +1 -0
  184. package/react/hoc/mutation-hoc.js +2 -2
  185. package/react/hoc/mutation-hoc.js.map +1 -1
  186. package/react/hoc/package.json +2 -1
  187. package/react/hoc/query-hoc.js +1 -1
  188. package/react/hoc/query-hoc.js.map +1 -1
  189. package/react/hoc/subscription-hoc.js +1 -1
  190. package/react/hoc/subscription-hoc.js.map +1 -1
  191. package/react/hoc/withApollo.js +2 -2
  192. package/react/hoc/withApollo.js.map +1 -1
  193. package/react/hooks/hooks.cjs +502 -0
  194. package/react/hooks/hooks.cjs.map +1 -0
  195. package/react/hooks/package.json +2 -1
  196. package/react/hooks/useApolloClient.d.ts +1 -1
  197. package/react/hooks/useApolloClient.d.ts.map +1 -1
  198. package/react/hooks/useApolloClient.js +7 -5
  199. package/react/hooks/useApolloClient.js.map +1 -1
  200. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  201. package/react/hooks/useLazyQuery.js +56 -2
  202. package/react/hooks/useLazyQuery.js.map +1 -1
  203. package/react/hooks/useMutation.d.ts.map +1 -1
  204. package/react/hooks/useMutation.js +89 -21
  205. package/react/hooks/useMutation.js.map +1 -1
  206. package/react/hooks/useQuery.d.ts +2 -3
  207. package/react/hooks/useQuery.d.ts.map +1 -1
  208. package/react/hooks/useQuery.js +224 -2
  209. package/react/hooks/useQuery.js.map +1 -1
  210. package/react/hooks/useSubscription.d.ts +2 -7
  211. package/react/hooks/useSubscription.d.ts.map +1 -1
  212. package/react/hooks/useSubscription.js +89 -32
  213. package/react/hooks/useSubscription.js.map +1 -1
  214. package/react/package.json +2 -1
  215. package/react/parser/index.d.ts +1 -0
  216. package/react/parser/index.d.ts.map +1 -1
  217. package/react/parser/index.js +16 -9
  218. package/react/parser/index.js.map +1 -1
  219. package/react/parser/package.json +2 -1
  220. package/react/parser/{parser.cjs.js → parser.cjs} +18 -10
  221. package/react/parser/parser.cjs.map +1 -0
  222. package/react/{react.cjs.js → react.cjs} +3 -3
  223. package/react/react.cjs.map +1 -0
  224. package/react/ssr/RenderPromises.d.ts +7 -3
  225. package/react/ssr/RenderPromises.d.ts.map +1 -1
  226. package/react/ssr/RenderPromises.js.map +1 -1
  227. package/react/ssr/package.json +2 -1
  228. package/react/ssr/{ssr.cjs.js → ssr.cjs} +4 -4
  229. package/react/ssr/ssr.cjs.map +1 -0
  230. package/react/types/types.d.ts +7 -18
  231. package/react/types/types.d.ts.map +1 -1
  232. package/react/types/types.js.map +1 -1
  233. package/testing/{testing.cjs.js → core/core.cjs} +10 -104
  234. package/testing/core/core.cjs.map +1 -0
  235. package/{utilities/testing → testing/core}/index.d.ts +0 -1
  236. package/testing/core/index.d.ts.map +1 -0
  237. package/{utilities/testing → testing/core}/index.js +0 -1
  238. package/testing/core/index.js.map +1 -0
  239. package/{utilities/testing → testing/core}/itAsync.d.ts +0 -0
  240. package/testing/core/itAsync.d.ts.map +1 -0
  241. package/{utilities/testing → testing/core}/itAsync.js +0 -0
  242. package/testing/core/itAsync.js.map +1 -0
  243. package/{utilities/testing → testing/core}/mocking/mockClient.d.ts +0 -0
  244. package/testing/core/mocking/mockClient.d.ts.map +1 -0
  245. package/{utilities/testing → testing/core}/mocking/mockClient.js +0 -0
  246. package/testing/core/mocking/mockClient.js.map +1 -0
  247. package/{utilities/testing → testing/core}/mocking/mockFetch.d.ts +0 -0
  248. package/testing/core/mocking/mockFetch.d.ts.map +1 -0
  249. package/{utilities/testing → testing/core}/mocking/mockFetch.js +1 -1
  250. package/testing/core/mocking/mockFetch.js.map +1 -0
  251. package/{utilities/testing → testing/core}/mocking/mockLink.d.ts +0 -1
  252. package/testing/core/mocking/mockLink.d.ts.map +1 -0
  253. package/{utilities/testing → testing/core}/mocking/mockLink.js +5 -5
  254. package/testing/core/mocking/mockLink.js.map +1 -0
  255. package/{utilities/testing → testing/core}/mocking/mockQueryManager.d.ts +1 -1
  256. package/testing/core/mocking/mockQueryManager.d.ts.map +1 -0
  257. package/{utilities/testing → testing/core}/mocking/mockQueryManager.js +1 -1
  258. package/testing/core/mocking/mockQueryManager.js.map +1 -0
  259. package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.d.ts +1 -4
  260. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -0
  261. package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.js +1 -1
  262. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -0
  263. package/{utilities/testing → testing/core}/mocking/mockWatchQuery.d.ts +1 -1
  264. package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -0
  265. package/{utilities/testing → testing/core}/mocking/mockWatchQuery.js +0 -0
  266. package/testing/core/mocking/mockWatchQuery.js.map +1 -0
  267. package/{utilities/testing → testing/core}/observableToPromise.d.ts +2 -3
  268. package/testing/core/observableToPromise.d.ts.map +1 -0
  269. package/{utilities/testing → testing/core}/observableToPromise.js +1 -1
  270. package/testing/core/observableToPromise.js.map +1 -0
  271. package/testing/core/package.json +8 -0
  272. package/testing/core/subscribeAndCount.d.ts +4 -0
  273. package/testing/core/subscribeAndCount.d.ts.map +1 -0
  274. package/{utilities/testing → testing/core}/subscribeAndCount.js +1 -1
  275. package/testing/core/subscribeAndCount.js.map +1 -0
  276. package/{utilities/testing → testing/core}/withConsoleSpy.d.ts +0 -0
  277. package/testing/core/withConsoleSpy.d.ts.map +1 -0
  278. package/{utilities/testing → testing/core}/withConsoleSpy.js +0 -0
  279. package/testing/core/withConsoleSpy.js.map +1 -0
  280. package/{utilities/testing → testing/core}/wrap.d.ts +0 -0
  281. package/testing/core/wrap.d.ts.map +1 -0
  282. package/{utilities/testing → testing/core}/wrap.js +0 -0
  283. package/testing/core/wrap.js.map +1 -0
  284. package/testing/index.d.ts +2 -1
  285. package/testing/index.d.ts.map +1 -1
  286. package/testing/index.js +2 -1
  287. package/testing/index.js.map +1 -1
  288. package/testing/package.json +2 -1
  289. package/{utilities/testing/mocking → testing/react}/MockedProvider.d.ts +5 -5
  290. package/testing/react/MockedProvider.d.ts.map +1 -0
  291. package/{utilities/testing/mocking → testing/react}/MockedProvider.js +4 -4
  292. package/testing/react/MockedProvider.js.map +1 -0
  293. package/testing/testing.cjs +58 -0
  294. package/testing/testing.cjs.map +1 -0
  295. package/utilities/common/errorHandling.d.ts +1 -1
  296. package/utilities/common/errorHandling.d.ts.map +1 -1
  297. package/utilities/common/errorHandling.js.map +1 -1
  298. package/utilities/common/makeUniqueId.js +1 -1
  299. package/utilities/common/makeUniqueId.js.map +1 -1
  300. package/utilities/common/mergeDeep.d.ts.map +1 -1
  301. package/utilities/common/mergeDeep.js +6 -1
  302. package/utilities/common/mergeDeep.js.map +1 -1
  303. package/utilities/globals/fix-graphql.js +1 -1
  304. package/utilities/globals/global.d.ts.map +1 -1
  305. package/utilities/globals/global.js +1 -1
  306. package/utilities/globals/global.js.map +1 -1
  307. package/utilities/globals/{globals.cjs.js → globals.cjs} +3 -3
  308. package/utilities/globals/globals.cjs.map +1 -0
  309. package/utilities/globals/index.js +1 -1
  310. package/utilities/globals/package.json +2 -1
  311. package/utilities/graphql/directives.js +5 -5
  312. package/utilities/graphql/directives.js.map +1 -1
  313. package/utilities/graphql/fragments.d.ts.map +1 -1
  314. package/utilities/graphql/fragments.js +4 -4
  315. package/utilities/graphql/fragments.js.map +1 -1
  316. package/utilities/graphql/getFromAST.js +8 -8
  317. package/utilities/graphql/getFromAST.js.map +1 -1
  318. package/utilities/graphql/storeUtils.js +6 -6
  319. package/utilities/graphql/storeUtils.js.map +1 -1
  320. package/utilities/graphql/transform.d.ts.map +1 -1
  321. package/utilities/graphql/transform.js.map +1 -1
  322. package/utilities/observables/Concast.d.ts +0 -1
  323. package/utilities/observables/Concast.d.ts.map +1 -1
  324. package/utilities/observables/asyncMap.d.ts +0 -1
  325. package/utilities/observables/asyncMap.d.ts.map +1 -1
  326. package/utilities/observables/subclassing.d.ts +0 -1
  327. package/utilities/observables/subclassing.d.ts.map +1 -1
  328. package/utilities/package.json +2 -1
  329. package/utilities/{utilities.cjs.js → utilities.cjs} +31 -26
  330. package/utilities/utilities.cjs.map +1 -0
  331. package/version.js +1 -1
  332. package/apollo-client.cjs.js.map +0 -1
  333. package/apollo-client.cjs.min.js +0 -1
  334. package/cache/cache.cjs.js.map +0 -1
  335. package/core/core.cjs.js.map +0 -1
  336. package/errors/errors.cjs.js.map +0 -1
  337. package/link/batch/batch.cjs.js.map +0 -1
  338. package/link/batch-http/batch-http.cjs.js.map +0 -1
  339. package/link/context/context.cjs.js.map +0 -1
  340. package/link/core/core.cjs.js.map +0 -1
  341. package/link/error/error.cjs.js.map +0 -1
  342. package/link/http/http.cjs.js.map +0 -1
  343. package/link/persisted-queries/persisted-queries.cjs.js.map +0 -1
  344. package/link/retry/retry.cjs.js.map +0 -1
  345. package/link/schema/schema.cjs.js.map +0 -1
  346. package/link/utils/utils.cjs.js.map +0 -1
  347. package/link/ws/ws.cjs.js.map +0 -1
  348. package/main.cjs.js.map +0 -1
  349. package/react/components/components.cjs.js.map +0 -1
  350. package/react/context/context.cjs.js.map +0 -1
  351. package/react/data/MutationData.d.ts +0 -29
  352. package/react/data/MutationData.d.ts.map +0 -1
  353. package/react/data/MutationData.js +0 -115
  354. package/react/data/MutationData.js.map +0 -1
  355. package/react/data/OperationData.d.ts +0 -24
  356. package/react/data/OperationData.d.ts.map +0 -1
  357. package/react/data/OperationData.js +0 -53
  358. package/react/data/OperationData.js.map +0 -1
  359. package/react/data/QueryData.d.ts +0 -44
  360. package/react/data/QueryData.d.ts.map +0 -1
  361. package/react/data/QueryData.js +0 -298
  362. package/react/data/QueryData.js.map +0 -1
  363. package/react/data/SubscriptionData.d.ts +0 -28
  364. package/react/data/SubscriptionData.d.ts.map +0 -1
  365. package/react/data/SubscriptionData.js +0 -122
  366. package/react/data/SubscriptionData.js.map +0 -1
  367. package/react/data/data.cjs.js +0 -581
  368. package/react/data/data.cjs.js.map +0 -1
  369. package/react/data/index.d.ts +0 -6
  370. package/react/data/index.d.ts.map +0 -1
  371. package/react/data/index.js +0 -6
  372. package/react/data/index.js.map +0 -1
  373. package/react/data/package.json +0 -7
  374. package/react/hoc/hoc.cjs.js.map +0 -1
  375. package/react/hooks/hooks.cjs.js +0 -195
  376. package/react/hooks/hooks.cjs.js.map +0 -1
  377. package/react/hooks/utils/useAfterFastRefresh.d.ts +0 -3
  378. package/react/hooks/utils/useAfterFastRefresh.d.ts.map +0 -1
  379. package/react/hooks/utils/useAfterFastRefresh.js +0 -19
  380. package/react/hooks/utils/useAfterFastRefresh.js.map +0 -1
  381. package/react/hooks/utils/useBaseQuery.d.ts +0 -7
  382. package/react/hooks/utils/useBaseQuery.d.ts.map +0 -1
  383. package/react/hooks/utils/useBaseQuery.js +0 -55
  384. package/react/hooks/utils/useBaseQuery.js.map +0 -1
  385. package/react/hooks/utils/useDeepMemo.d.ts +0 -2
  386. package/react/hooks/utils/useDeepMemo.d.ts.map +0 -1
  387. package/react/hooks/utils/useDeepMemo.js +0 -10
  388. package/react/hooks/utils/useDeepMemo.js.map +0 -1
  389. package/react/parser/parser.cjs.js.map +0 -1
  390. package/react/react.cjs.js.map +0 -1
  391. package/react/ssr/ssr.cjs.js.map +0 -1
  392. package/testing/testing.cjs.js.map +0 -1
  393. package/utilities/globals/globals.cjs.js.map +0 -1
  394. package/utilities/testing/index.d.ts.map +0 -1
  395. package/utilities/testing/index.js.map +0 -1
  396. package/utilities/testing/itAsync.d.ts.map +0 -1
  397. package/utilities/testing/itAsync.js.map +0 -1
  398. package/utilities/testing/mocking/MockedProvider.d.ts.map +0 -1
  399. package/utilities/testing/mocking/MockedProvider.js.map +0 -1
  400. package/utilities/testing/mocking/mockClient.d.ts.map +0 -1
  401. package/utilities/testing/mocking/mockClient.js.map +0 -1
  402. package/utilities/testing/mocking/mockFetch.d.ts.map +0 -1
  403. package/utilities/testing/mocking/mockFetch.js.map +0 -1
  404. package/utilities/testing/mocking/mockLink.d.ts.map +0 -1
  405. package/utilities/testing/mocking/mockLink.js.map +0 -1
  406. package/utilities/testing/mocking/mockQueryManager.d.ts.map +0 -1
  407. package/utilities/testing/mocking/mockQueryManager.js.map +0 -1
  408. package/utilities/testing/mocking/mockSubscriptionLink.d.ts.map +0 -1
  409. package/utilities/testing/mocking/mockSubscriptionLink.js.map +0 -1
  410. package/utilities/testing/mocking/mockWatchQuery.d.ts.map +0 -1
  411. package/utilities/testing/mocking/mockWatchQuery.js.map +0 -1
  412. package/utilities/testing/observableToPromise.d.ts.map +0 -1
  413. package/utilities/testing/observableToPromise.js.map +0 -1
  414. package/utilities/testing/subscribeAndCount.d.ts +0 -5
  415. package/utilities/testing/subscribeAndCount.d.ts.map +0 -1
  416. package/utilities/testing/subscribeAndCount.js.map +0 -1
  417. package/utilities/testing/withConsoleSpy.d.ts.map +0 -1
  418. package/utilities/testing/withConsoleSpy.js.map +0 -1
  419. package/utilities/testing/wrap.d.ts.map +0 -1
  420. package/utilities/testing/wrap.js.map +0 -1
  421. package/utilities/utilities.cjs.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../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AAY,GAAnB,UACE,OAA4D,EAC5D,UAAiC;QAAjC,2BAAA,EAAA,cAAc,CAAC,OAAO,CAAC,UAAU;QAEjC,OAAO,IAAI,CAAC,IAAI,uBACX,OAAO,KACV,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,EAClE,MAAM,EAAE,OAAO,CAAC,EAAE,EAClB,UAAU,YAAA,IACV,CAAC;IACL,CAAC;IAEM,gCAAU,GAAjB,UAAiD,EAIJ;QAH3C,IAAA,EAAE,QAAA,EACF,IAAI,UAAA,EACD,OAAO,cAHqC,cAIhD,CADW;QAEV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;YACvC,MAAM,EAAE,EAAE,IAAI,YAAY;YAC1B,MAAM,EAAE,IAAI;SACb,CAAC,CAAC,CAAC;IACN,CAAC;IAEM,mCAAa,GAApB,UAAoD,EAMJ;QAL9C,IAAA,EAAE,QAAA,EACF,IAAI,UAAA,EACJ,QAAQ,cAAA,EACR,YAAY,kBAAA,EACT,OAAO,cALwC,0CAMnD,CADW;QAEV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;YACvC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,YAAY,CAAC;YAClD,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,IAAI;SACb,CAAC,CAAC,CAAC;IACN,CAAC;IACH,kBAAC;AAAD,CAAC,AA9JD,IA8JC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { wrap } from 'optimism';\n\nimport {\n StoreObject,\n Reference,\n getFragmentQueryDocument,\n} from '../../utilities';\nimport { DataProxy } from './types/DataProxy';\nimport { Cache } from './types/Cache';\n\nexport type Transaction<T> = (c: ApolloCache<T>) => void;\n\nexport abstract class ApolloCache<TSerialized> implements DataProxy {\n // required to implement\n // core API\n public abstract read<T, TVariables = any>(\n query: Cache.ReadOptions<TVariables, T>,\n ): T | null;\n public abstract write<TResult = any, TVariables = any>(\n write: Cache.WriteOptions<TResult, TVariables>,\n ): Reference | undefined;\n public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;\n public abstract watch(watch: Cache.WatchOptions): () => void;\n\n // Empty the cache and restart all current watches (unless\n // options.discardWatches is true).\n public abstract reset(options?: Cache.ResetOptions): Promise<void>;\n\n // Remove whole objects from the cache by passing just options.id, or\n // specific fields by passing options.field and/or options.args. If no\n // options.args are provided, all fields matching options.field (even\n // those with arguments) will be removed. Returns true iff any data was\n // removed from the cache.\n public abstract evict(options: Cache.EvictOptions): boolean;\n\n // initializer / offline / ssr API\n /**\n * Replaces existing state in the cache (if any) with the values expressed by\n * `serializedState`.\n *\n * Called when hydrating a cache (server side rendering, or offline storage),\n * and also (potentially) during hot reloads.\n */\n public abstract restore(\n serializedState: TSerialized,\n ): ApolloCache<TSerialized>;\n\n /**\n * Exposes the cache's complete state, in a serializable format for later restoration.\n */\n public abstract extract(optimistic?: boolean): TSerialized;\n\n // Optimistic API\n\n public abstract removeOptimistic(id: string): void;\n\n // Transactional API\n\n // The batch method is intended to replace/subsume both performTransaction\n // and recordOptimisticTransaction, but performTransaction came first, so we\n // provide a default batch implementation that's just another way of calling\n // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can\n // override the batch method to do more interesting things with its options.\n public batch(options: Cache.BatchOptions<this>) {\n const optimisticId =\n typeof options.optimistic === \"string\" ? options.optimistic :\n options.optimistic === false ? null : void 0;\n this.performTransaction(options.update, optimisticId);\n }\n\n public abstract performTransaction(\n transaction: Transaction<TSerialized>,\n // Although subclasses may implement recordOptimisticTransaction\n // however they choose, the default implementation simply calls\n // performTransaction with a string as the second argument, allowing\n // performTransaction to handle both optimistic and non-optimistic\n // (broadcast-batching) transactions. Passing null for optimisticId is\n // also allowed, and indicates that performTransaction should apply\n // the transaction non-optimistically (ignoring optimistic data).\n optimisticId?: string | null,\n ): void;\n\n public recordOptimisticTransaction(\n transaction: Transaction<TSerialized>,\n optimisticId: string,\n ) {\n this.performTransaction(transaction, optimisticId);\n }\n\n // Optional API\n\n public transformDocument(document: DocumentNode): DocumentNode {\n return document;\n }\n\n public identify(object: StoreObject | Reference): string | undefined {\n return;\n }\n\n public gc(): string[] {\n return [];\n }\n\n public modify(options: Cache.ModifyOptions): boolean {\n return false;\n }\n\n // Experimental API\n\n public transformForLink(document: DocumentNode): DocumentNode {\n return document;\n }\n\n // DataProxy API\n /**\n *\n * @param options\n * @param optimistic\n */\n public readQuery<QueryType, TVariables = any>(\n options: Cache.ReadQueryOptions<QueryType, TVariables>,\n optimistic = !!options.optimistic,\n ): QueryType | null {\n return this.read({\n ...options,\n rootId: options.id || 'ROOT_QUERY',\n optimistic,\n });\n }\n\n // Make sure we compute the same (===) fragment query document every\n // time we receive the same fragment in readFragment.\n private getFragmentDoc = wrap(getFragmentQueryDocument);\n\n public readFragment<FragmentType, TVariables = any>(\n options: Cache.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic = !!options.optimistic,\n ): FragmentType | null {\n return this.read({\n ...options,\n query: this.getFragmentDoc(options.fragment, options.fragmentName),\n rootId: options.id,\n optimistic,\n });\n }\n\n public writeQuery<TData = any, TVariables = any>({\n id,\n data,\n ...options\n }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined {\n return this.write(Object.assign(options, {\n dataId: id || 'ROOT_QUERY',\n result: data,\n }));\n }\n\n public writeFragment<TData = any, TVariables = any>({\n id,\n data,\n fragment,\n fragmentName,\n ...options\n }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined {\n return this.write(Object.assign(options, {\n query: this.getFragmentDoc(fragment, fragmentName),\n dataId: id,\n result: data,\n }));\n }\n}\n"]}
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/cache/core/cache.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAGL,wB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IAAI,KAAK,IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,UAAU,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC1D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAEM,oCAAc,GAArB,UACE,OAAuD,EACvD,MAAmD;QAEnD,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM,EAAN,UAAO,KAAK;gBACV,IAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAoB,OAAO,CAAC,CAAC;gBAC7D,IAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC3B,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI;oBAAE,OAAO,KAAK,CAAC;gBACnD,KAAK,CAAC,aAAa,uBAAyB,OAAO,KAAE,IAAI,MAAA,IAAG,CAAC;gBAC7D,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IACH,kBAAC;AAAD,CAAC,AAnMD,IAmMC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { wrap } from 'optimism';\n\nimport {\n StoreObject,\n Reference,\n getFragmentQueryDocument,\n} from '../../utilities';\nimport { DataProxy } from './types/DataProxy';\nimport { Cache } from './types/Cache';\n\nexport type Transaction<T> = (c: ApolloCache<T>) => void;\n\nexport abstract class ApolloCache<TSerialized> implements DataProxy {\n // required to implement\n // core API\n public abstract read<TData = any, TVariables = any>(\n query: Cache.ReadOptions<TVariables, TData>,\n ): TData | null;\n public abstract write<TData = any, TVariables = any>(\n write: Cache.WriteOptions<TData, TVariables>,\n ): Reference | undefined;\n public abstract diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T>;\n public abstract watch<TData = any, TVariables = any>(\n watch: Cache.WatchOptions<TData, TVariables>,\n ): () => void;\n\n // Empty the cache and restart all current watches (unless\n // options.discardWatches is true).\n public abstract reset(options?: Cache.ResetOptions): Promise<void>;\n\n // Remove whole objects from the cache by passing just options.id, or\n // specific fields by passing options.field and/or options.args. If no\n // options.args are provided, all fields matching options.field (even\n // those with arguments) will be removed. Returns true iff any data was\n // removed from the cache.\n public abstract evict(options: Cache.EvictOptions): boolean;\n\n // initializer / offline / ssr API\n /**\n * Replaces existing state in the cache (if any) with the values expressed by\n * `serializedState`.\n *\n * Called when hydrating a cache (server side rendering, or offline storage),\n * and also (potentially) during hot reloads.\n */\n public abstract restore(\n serializedState: TSerialized,\n ): ApolloCache<TSerialized>;\n\n /**\n * Exposes the cache's complete state, in a serializable format for later restoration.\n */\n public abstract extract(optimistic?: boolean): TSerialized;\n\n // Optimistic API\n\n public abstract removeOptimistic(id: string): void;\n\n // Transactional API\n\n // The batch method is intended to replace/subsume both performTransaction\n // and recordOptimisticTransaction, but performTransaction came first, so we\n // provide a default batch implementation that's just another way of calling\n // performTransaction. Subclasses of ApolloCache (such as InMemoryCache) can\n // override the batch method to do more interesting things with its options.\n public batch<U>(options: Cache.BatchOptions<this, U>): U {\n const optimisticId =\n typeof options.optimistic === \"string\" ? options.optimistic :\n options.optimistic === false ? null : void 0;\n let updateResult: U;\n this.performTransaction(\n () => updateResult = options.update(this),\n optimisticId,\n );\n return updateResult!;\n }\n\n public abstract performTransaction(\n transaction: Transaction<TSerialized>,\n // Although subclasses may implement recordOptimisticTransaction\n // however they choose, the default implementation simply calls\n // performTransaction with a string as the second argument, allowing\n // performTransaction to handle both optimistic and non-optimistic\n // (broadcast-batching) transactions. Passing null for optimisticId is\n // also allowed, and indicates that performTransaction should apply\n // the transaction non-optimistically (ignoring optimistic data).\n optimisticId?: string | null,\n ): void;\n\n public recordOptimisticTransaction(\n transaction: Transaction<TSerialized>,\n optimisticId: string,\n ) {\n this.performTransaction(transaction, optimisticId);\n }\n\n // Optional API\n\n public transformDocument(document: DocumentNode): DocumentNode {\n return document;\n }\n\n public identify(object: StoreObject | Reference): string | undefined {\n return;\n }\n\n public gc(): string[] {\n return [];\n }\n\n public modify(options: Cache.ModifyOptions): boolean {\n return false;\n }\n\n // Experimental API\n\n public transformForLink(document: DocumentNode): DocumentNode {\n return document;\n }\n\n // DataProxy API\n /**\n *\n * @param options\n * @param optimistic\n */\n public readQuery<QueryType, TVariables = any>(\n options: Cache.ReadQueryOptions<QueryType, TVariables>,\n optimistic = !!options.optimistic,\n ): QueryType | null {\n return this.read({\n ...options,\n rootId: options.id || 'ROOT_QUERY',\n optimistic,\n });\n }\n\n // Make sure we compute the same (===) fragment query document every\n // time we receive the same fragment in readFragment.\n private getFragmentDoc = wrap(getFragmentQueryDocument);\n\n public readFragment<FragmentType, TVariables = any>(\n options: Cache.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic = !!options.optimistic,\n ): FragmentType | null {\n return this.read({\n ...options,\n query: this.getFragmentDoc(options.fragment, options.fragmentName),\n rootId: options.id,\n optimistic,\n });\n }\n\n public writeQuery<TData = any, TVariables = any>({\n id,\n data,\n ...options\n }: Cache.WriteQueryOptions<TData, TVariables>): Reference | undefined {\n return this.write(Object.assign(options, {\n dataId: id || 'ROOT_QUERY',\n result: data,\n }));\n }\n\n public writeFragment<TData = any, TVariables = any>({\n id,\n data,\n fragment,\n fragmentName,\n ...options\n }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined {\n return this.write(Object.assign(options, {\n query: this.getFragmentDoc(fragment, fragmentName),\n dataId: id,\n result: data,\n }));\n }\n\n public updateQuery<TData = any, TVariables = any>(\n options: Cache.UpdateQueryOptions<TData, TVariables>,\n update: (data: TData | null) => TData | null | void,\n ): TData | null {\n return this.batch({\n update(cache) {\n const value = cache.readQuery<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeQuery<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n\n public updateFragment<TData = any, TVariables = any>(\n options: Cache.UpdateFragmentOptions<TData, TVariables>,\n update: (data: TData | null) => TData | null | void,\n ): TData | null {\n return this.batch({\n update(cache) {\n const value = cache.readFragment<TData, TVariables>(options);\n const data = update(value);\n if (data === void 0 || data === null) return value;\n cache.writeFragment<TData, TVariables>({ ...options, data });\n return data;\n },\n });\n }\n}\n"]}
@@ -2,7 +2,7 @@ import { DataProxy } from './DataProxy';
2
2
  import { Modifier, Modifiers } from './common';
3
3
  import { ApolloCache } from '../cache';
4
4
  export declare namespace Cache {
5
- type WatchCallback = (diff: Cache.DiffResult<any>, lastDiff?: Cache.DiffResult<any>) => void;
5
+ type WatchCallback<TData = any> = (diff: Cache.DiffResult<TData>, lastDiff?: Cache.DiffResult<TData>) => void;
6
6
  interface ReadOptions<TVariables = any, TData = any> extends DataProxy.Query<TVariables, TData> {
7
7
  rootId?: string;
8
8
  previousResult?: any;
@@ -14,13 +14,13 @@ export declare namespace Cache {
14
14
  dataId?: string;
15
15
  result: TResult;
16
16
  }
17
- interface DiffOptions extends ReadOptions {
17
+ interface DiffOptions<TData = any, TVariables = any> extends ReadOptions<TVariables, TData> {
18
18
  }
19
- interface WatchOptions<Watcher extends object = Record<string, any>> extends ReadOptions {
20
- watcher?: Watcher;
19
+ interface WatchOptions<TData = any, TVariables = any> extends ReadOptions<TVariables, TData> {
20
+ watcher?: object;
21
21
  immediate?: boolean;
22
- callback: WatchCallback;
23
- lastDiff?: DiffResult<any>;
22
+ callback: WatchCallback<TData>;
23
+ lastDiff?: DiffResult<TData>;
24
24
  }
25
25
  interface EvictOptions {
26
26
  id?: string;
@@ -37,17 +37,19 @@ export declare namespace Cache {
37
37
  optimistic?: boolean;
38
38
  broadcast?: boolean;
39
39
  }
40
- interface BatchOptions<C extends ApolloCache<any>> {
41
- update(cache: C): void;
42
- optimistic: string | boolean;
40
+ interface BatchOptions<TCache extends ApolloCache<any>, TUpdateResult = void> {
41
+ update(cache: TCache): TUpdateResult;
42
+ optimistic?: string | boolean;
43
43
  removeOptimistic?: string;
44
- onWatchUpdated?: (this: C, watch: Cache.WatchOptions, diff: Cache.DiffResult<any>, lastDiff: Cache.DiffResult<any> | undefined) => any;
44
+ onWatchUpdated?: (this: TCache, watch: Cache.WatchOptions, diff: Cache.DiffResult<any>, lastDiff: Cache.DiffResult<any> | undefined) => any;
45
45
  }
46
46
  export import DiffResult = DataProxy.DiffResult;
47
47
  export import ReadQueryOptions = DataProxy.ReadQueryOptions;
48
48
  export import ReadFragmentOptions = DataProxy.ReadFragmentOptions;
49
49
  export import WriteQueryOptions = DataProxy.WriteQueryOptions;
50
50
  export import WriteFragmentOptions = DataProxy.WriteFragmentOptions;
51
+ export import UpdateQueryOptions = DataProxy.UpdateQueryOptions;
52
+ export import UpdateFragmentOptions = DataProxy.UpdateFragmentOptions;
51
53
  export import Fragment = DataProxy.Fragment;
52
54
  }
53
55
  //# sourceMappingURL=Cache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,yBAAiB,KAAK,CAAC;IACrB,KAAY,aAAa,GAAG,CAC1B,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAC7B,IAAI,CAAC;IAEV,UAAiB,WAAW,CAAC,UAAU,GAAG,GAAG,EAAE,KAAK,GAAG,GAAG,CACxD,SAAQ,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC;QAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,cAAc,CAAC,EAAE,GAAG,CAAC;QACrB,UAAU,EAAE,OAAO,CAAC;QACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;IAED,UAAiB,YAAY,CAA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iGrB","sourcesContent":["import { DataProxy } from './DataProxy';\nimport { Modifier, Modifiers } from './common';\nimport { ApolloCache } from '../cache';\n\nexport namespace Cache {\n export type WatchCallback = (\n diff: Cache.DiffResult<any>,\n lastDiff?: Cache.DiffResult<any>,\n ) => void;\n\n export interface ReadOptions<TVariables = any, TData = any>\n extends DataProxy.Query<TVariables, TData> {\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n canonizeResults?: boolean;\n }\n\n export interface WriteOptions<TResult = any, TVariables = any>\n extends Omit<DataProxy.Query<TVariables, TResult>, \"id\">,\n Omit<DataProxy.WriteOptions<TResult>, \"data\">\n {\n dataId?: string;\n result: TResult;\n }\n\n export interface DiffOptions extends ReadOptions {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<\n Watcher extends object = Record<string, any>\n > extends ReadOptions {\n watcher?: Watcher;\n immediate?: boolean;\n callback: WatchCallback;\n lastDiff?: DiffResult<any>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions {\n id?: string;\n fields: Modifiers | Modifier<any>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<C extends ApolloCache<any>> {\n // Same as the first parameter of performTransaction, except the cache\n // argument will have the subclass type rather than ApolloCache.\n update(cache: C): void;\n\n // Passing a string for this option creates a new optimistic layer, with the\n // given string as its layer.id, just like passing a string for the\n // optimisticId parameter of performTransaction. Passing true is the same as\n // passing undefined to performTransaction (running the batch operation\n // against the current top layer of the cache), and passing false is the\n // same as passing null (running the operation against root/non-optimistic\n // cache data).\n optimistic: string | boolean;\n\n // If you specify the ID of an optimistic layer using this option, that\n // layer will be removed as part of the batch transaction, triggering at\n // most one broadcast for both the transaction and the removal of the layer.\n // Note: this option is needed because calling cache.removeOptimistic during\n // the transaction function may not be not safe, since any modifications to\n // cache layers may be discarded after the transaction finishes.\n removeOptimistic?: string;\n\n // If you want to find out which watched queries were invalidated during\n // this batch operation, pass this optional callback function. Returning\n // false from the callback will prevent broadcasting this result.\n onWatchUpdated?: (\n this: C,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff: Cache.DiffResult<any> | undefined,\n ) => any;\n }\n\n export import DiffResult = DataProxy.DiffResult;\n export import ReadQueryOptions = DataProxy.ReadQueryOptions;\n export import ReadFragmentOptions = DataProxy.ReadFragmentOptions;\n export import WriteQueryOptions = DataProxy.WriteQueryOptions;\n export import WriteFragmentOptions = DataProxy.WriteFragmentOptions;\n export import Fragment = DataProxy.Fragment;\n}\n"]}
1
+ {"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../../../src/cache/core/types/Cache.ts"],"names":[],"mappings":"AAIA,MAAM,KAAW,KAAK,CA0GrB;AA1GD,WAAiB,KAAK;AA0GtB,CAAC,EA1GgB,KAAK,KAAL,KAAK,QA0GrB","sourcesContent":["import { DataProxy } from './DataProxy';\nimport { Modifier, Modifiers } from './common';\nimport { ApolloCache } from '../cache';\n\nexport namespace Cache {\n export type WatchCallback<TData = any> = (\n diff: Cache.DiffResult<TData>,\n lastDiff?: Cache.DiffResult<TData>,\n ) => void;\n\n export interface ReadOptions<TVariables = any, TData = any>\n extends DataProxy.Query<TVariables, TData> {\n rootId?: string;\n previousResult?: any;\n optimistic: boolean;\n returnPartialData?: boolean;\n canonizeResults?: boolean;\n }\n\n export interface WriteOptions<TResult = any, TVariables = any>\n extends Omit<DataProxy.Query<TVariables, TResult>, \"id\">,\n Omit<DataProxy.WriteOptions<TResult>, \"data\">\n {\n dataId?: string;\n result: TResult;\n }\n\n export interface DiffOptions<\n TData = any,\n TVariables = any,\n > extends ReadOptions<TVariables, TData> {\n // The DiffOptions interface is currently just an alias for\n // ReadOptions, though DiffOptions used to be responsible for\n // declaring the returnPartialData option.\n }\n\n export interface WatchOptions<\n TData = any,\n TVariables = any,\n > extends ReadOptions<TVariables, TData> {\n watcher?: object;\n immediate?: boolean;\n callback: WatchCallback<TData>;\n lastDiff?: DiffResult<TData>;\n }\n\n export interface EvictOptions {\n id?: string;\n fieldName?: string;\n args?: Record<string, any>;\n broadcast?: boolean;\n }\n\n // Although you can call cache.reset() without options, its behavior can be\n // configured by passing a Cache.ResetOptions object.\n export interface ResetOptions {\n discardWatches?: boolean;\n }\n\n export interface ModifyOptions {\n id?: string;\n fields: Modifiers | Modifier<any>;\n optimistic?: boolean;\n broadcast?: boolean;\n }\n\n export interface BatchOptions<\n TCache extends ApolloCache<any>,\n TUpdateResult = void,\n > {\n // Same as the first parameter of performTransaction, except the cache\n // argument will have the subclass type rather than ApolloCache.\n update(cache: TCache): TUpdateResult;\n\n // Passing a string for this option creates a new optimistic layer, with the\n // given string as its layer.id, just like passing a string for the\n // optimisticId parameter of performTransaction. Passing true is the same as\n // passing undefined to performTransaction (running the batch operation\n // against the current top layer of the cache), and passing false is the\n // same as passing null (running the operation against root/non-optimistic\n // cache data).\n optimistic?: string | boolean;\n\n // If you specify the ID of an optimistic layer using this option, that\n // layer will be removed as part of the batch transaction, triggering at\n // most one broadcast for both the transaction and the removal of the layer.\n // Note: this option is needed because calling cache.removeOptimistic during\n // the transaction function may not be not safe, since any modifications to\n // cache layers may be discarded after the transaction finishes.\n removeOptimistic?: string;\n\n // If you want to find out which watched queries were invalidated during\n // this batch operation, pass this optional callback function. Returning\n // false from the callback will prevent broadcasting this result.\n onWatchUpdated?: (\n this: TCache,\n watch: Cache.WatchOptions,\n diff: Cache.DiffResult<any>,\n lastDiff: Cache.DiffResult<any> | undefined,\n ) => any;\n }\n\n export import DiffResult = DataProxy.DiffResult;\n export import ReadQueryOptions = DataProxy.ReadQueryOptions;\n export import ReadFragmentOptions = DataProxy.ReadFragmentOptions;\n export import WriteQueryOptions = DataProxy.WriteQueryOptions;\n export import WriteFragmentOptions = DataProxy.WriteFragmentOptions;\n export import UpdateQueryOptions = DataProxy.UpdateQueryOptions;\n export import UpdateFragmentOptions = DataProxy.UpdateFragmentOptions;\n export import Fragment = DataProxy.Fragment;\n}\n"]}
@@ -32,6 +32,10 @@ export declare namespace DataProxy {
32
32
  }
33
33
  interface WriteFragmentOptions<TData, TVariables> extends Fragment<TVariables, TData>, WriteOptions<TData> {
34
34
  }
35
+ interface UpdateQueryOptions<TData, TVariables> extends Omit<(ReadQueryOptions<TData, TVariables> & WriteQueryOptions<TData, TVariables>), 'data'> {
36
+ }
37
+ interface UpdateFragmentOptions<TData, TVariables> extends Omit<(ReadFragmentOptions<TData, TVariables> & WriteFragmentOptions<TData, TVariables>), 'data'> {
38
+ }
35
39
  type DiffResult<T> = {
36
40
  result?: T;
37
41
  complete?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"DataProxy.d.ts","sourceRoot":"","sources":["../../../../src/cache/core/types/DataProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,yBAAiB,SAAS,CAAC;IACzB,UAAiB,KAAK,CAAC,UAAU,EAAE,KAAK;QAMtC,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAK3D,SAAS,CAAC,EAAE,UAAU,CAAC;QAOvB,EAAE,CAAC,EAAE,MAAM,CAAC;KACb;IAED,UAAiB,QAAQ,CAAC,UAAU,EAAE,KAAK;QAMzC,EAAE,CAAC,EAAE,MAAM,CAAC;QAQZ,QAAQ,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAO9D,YAAY,CAAC,EAAE,MAAM,CAAC;QAKtB,SAAS,CAAC,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AAC,CAAC,IAAI;QAC1B,MAAM,CAAC,EAAE,CAAC,CAAC;QACX,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;QAC9B,yBAAyB,CAAC,EAAE,OAAO,CAAC;KACrC,CAAA;CACF;AAQD,MAAM,WAAW,SAAS;IAIxB,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,GAAG,EACnC,OAAO,EAAE,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,UAAU,CAAC,EAC1D,UAAU,CAAC,EAAE,OAAO,GACnB,SAAS,GAAG,IAAI,CAAC;IAOpB,YAAY,CAAC,YAAY,EAAE,UAAU,GAAG,GAAG,EACzC,OAAO,EAAE,SAAS,CAAC,mBAAmB,CAAC,YAAY,EAAE,UAAU,CAAC,EAChE,UAAU,CAAC,EAAE,OAAO,GACnB,YAAY,GAAG,IAAI,CAAC;IAKvB,UAAU,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,GAAG,EACtC,OAAO,EAAE,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,GACtD,IAAI,CAAC;IAOR,aAAa,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,GAAG,EACzC,OAAO,EAAE,SAAS,CAAC,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,GACzD,IAAI,CAAC;CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"DataProxy.js","sourceRoot":"","sources":["../../../../src/cache/core/types/DataProxy.ts"],"names":[],"mappings":"","sourcesContent":["import { DocumentNode } from 'graphql'; // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\n\nimport { MissingFieldError } from './common';\n\nexport namespace DataProxy {\n export interface Query<TVariables, TData> {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n }\n\n export interface Fragment<TVariables, TData> {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by your `dataIdFromObject` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: string;\n\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n }\n\n export interface ReadQueryOptions<TData, TVariables>\n extends Query<TVariables, TData> {\n /**\n * Whether to return incomplete data rather than null.\n * Defaults to false.\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted. Defaults to false.\n */\n optimistic?: boolean;\n /**\n * Whether to canonize cache results before returning them. Canonization\n * takes some extra time, but it speeds up future deep equality comparisons.\n * Defaults to false.\n */\n canonizeResults?: boolean;\n }\n\n export interface ReadFragmentOptions<TData, TVariables>\n extends Fragment<TVariables, TData> {\n /**\n * Whether to return incomplete data rather than null.\n * Defaults to false.\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted. Defaults to false.\n */\n optimistic?: boolean;\n /**\n * Whether to canonize cache results before returning them. Canonization\n * takes some extra time, but it speeds up future deep equality comparisons.\n * Defaults to false.\n */\n canonizeResults?: boolean;\n }\n\n export interface WriteOptions<TData> {\n /**\n * The data you will be writing to the store.\n */\n data: TData;\n /**\n * Whether to notify query watchers (default: true).\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data (default: false).\n */\n overwrite?: boolean;\n }\n\n export interface WriteQueryOptions<TData, TVariables>\n extends Query<TVariables, TData>, WriteOptions<TData> {}\n\n export interface WriteFragmentOptions<TData, TVariables>\n extends Fragment<TVariables, TData>, WriteOptions<TData> {}\n\n export type DiffResult<T> = {\n result?: T;\n complete?: boolean;\n missing?: MissingFieldError[];\n fromOptimisticTransaction?: boolean;\n }\n}\n\n/**\n * A proxy to the normalized data living in our store. This interface allows a\n * user to read and write denormalized data which feels natural to the user\n * whilst in the background this data is being converted into the normalized\n * store format.\n */\nexport interface DataProxy {\n /**\n * Reads a GraphQL query from the root query id.\n */\n readQuery<QueryType, TVariables = any>(\n options: DataProxy.ReadQueryOptions<QueryType, TVariables>,\n optimistic?: boolean,\n ): QueryType | null;\n\n /**\n * Reads a GraphQL fragment from any arbitrary id. If there is more than\n * one fragment in the provided document then a `fragmentName` must be\n * provided to select the correct fragment.\n */\n readFragment<FragmentType, TVariables = any>(\n options: DataProxy.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic?: boolean,\n ): FragmentType | null;\n\n /**\n * Writes a GraphQL query to the root query id.\n */\n writeQuery<TData = any, TVariables = any>(\n options: DataProxy.WriteQueryOptions<TData, TVariables>,\n ): void;\n\n /**\n * Writes a GraphQL fragment to any arbitrary id. If there is more than\n * one fragment in the provided document then a `fragmentName` must be\n * provided to select the correct fragment.\n */\n writeFragment<TData = any, TVariables = any>(\n options: DataProxy.WriteFragmentOptions<TData, TVariables>,\n ): void;\n}\n"]}
1
+ {"version":3,"file":"DataProxy.js","sourceRoot":"","sources":["../../../../src/cache/core/types/DataProxy.ts"],"names":[],"mappings":"","sourcesContent":["import { DocumentNode } from 'graphql'; // eslint-disable-line import/no-extraneous-dependencies, import/no-unresolved\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\n\nimport { MissingFieldError } from './common';\n\nexport namespace DataProxy {\n export interface Query<TVariables, TData> {\n /**\n * The GraphQL query shape to be used constructed using the `gql` template\n * string tag from `graphql-tag`. The query will be used to determine the\n * shape of the data to be read.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: TVariables;\n\n /**\n * The root id to be used. Defaults to \"ROOT_QUERY\", which is the ID of the\n * root query object. This property makes writeQuery capable of writing data\n * to any object in the cache.\n */\n id?: string;\n }\n\n export interface Fragment<TVariables, TData> {\n /**\n * The root id to be used. This id should take the same form as the\n * value returned by your `dataIdFromObject` function. If a value with your\n * id does not exist in the store, `null` will be returned.\n */\n id?: string;\n\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that your GraphQL fragments depend on.\n */\n variables?: TVariables;\n }\n\n export interface ReadQueryOptions<TData, TVariables>\n extends Query<TVariables, TData> {\n /**\n * Whether to return incomplete data rather than null.\n * Defaults to false.\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted. Defaults to false.\n */\n optimistic?: boolean;\n /**\n * Whether to canonize cache results before returning them. Canonization\n * takes some extra time, but it speeds up future deep equality comparisons.\n * Defaults to false.\n */\n canonizeResults?: boolean;\n }\n\n export interface ReadFragmentOptions<TData, TVariables>\n extends Fragment<TVariables, TData> {\n /**\n * Whether to return incomplete data rather than null.\n * Defaults to false.\n */\n returnPartialData?: boolean;\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted. Defaults to false.\n */\n optimistic?: boolean;\n /**\n * Whether to canonize cache results before returning them. Canonization\n * takes some extra time, but it speeds up future deep equality comparisons.\n * Defaults to false.\n */\n canonizeResults?: boolean;\n }\n\n export interface WriteOptions<TData> {\n /**\n * The data you will be writing to the store.\n */\n data: TData;\n /**\n * Whether to notify query watchers (default: true).\n */\n broadcast?: boolean;\n /**\n * When true, ignore existing field data rather than merging it with\n * incoming data (default: false).\n */\n overwrite?: boolean;\n }\n\n export interface WriteQueryOptions<TData, TVariables>\n extends Query<TVariables, TData>, WriteOptions<TData> {}\n\n export interface WriteFragmentOptions<TData, TVariables>\n extends Fragment<TVariables, TData>, WriteOptions<TData> {}\n\n export interface UpdateQueryOptions<TData, TVariables>\n extends Omit<(\n ReadQueryOptions<TData, TVariables> &\n WriteQueryOptions<TData, TVariables>\n ), 'data'> {}\n\n export interface UpdateFragmentOptions<TData, TVariables>\n extends Omit<(\n ReadFragmentOptions<TData, TVariables> &\n WriteFragmentOptions<TData, TVariables>\n ), 'data'> {}\n\n export type DiffResult<T> = {\n result?: T;\n complete?: boolean;\n missing?: MissingFieldError[];\n fromOptimisticTransaction?: boolean;\n }\n}\n\n/**\n * A proxy to the normalized data living in our store. This interface allows a\n * user to read and write denormalized data which feels natural to the user\n * whilst in the background this data is being converted into the normalized\n * store format.\n */\nexport interface DataProxy {\n /**\n * Reads a GraphQL query from the root query id.\n */\n readQuery<QueryType, TVariables = any>(\n options: DataProxy.ReadQueryOptions<QueryType, TVariables>,\n optimistic?: boolean,\n ): QueryType | null;\n\n /**\n * Reads a GraphQL fragment from any arbitrary id. If there is more than\n * one fragment in the provided document then a `fragmentName` must be\n * provided to select the correct fragment.\n */\n readFragment<FragmentType, TVariables = any>(\n options: DataProxy.ReadFragmentOptions<FragmentType, TVariables>,\n optimistic?: boolean,\n ): FragmentType | null;\n\n /**\n * Writes a GraphQL query to the root query id.\n */\n writeQuery<TData = any, TVariables = any>(\n options: DataProxy.WriteQueryOptions<TData, TVariables>,\n ): void;\n\n /**\n * Writes a GraphQL fragment to any arbitrary id. If there is more than\n * one fragment in the provided document then a `fragmentName` must be\n * provided to select the correct fragment.\n */\n writeFragment<TData = any, TVariables = any>(\n options: DataProxy.WriteFragmentOptions<TData, TVariables>,\n ): void;\n}\n"]}
@@ -1,13 +1,16 @@
1
- import { FieldNode } from 'graphql';
1
+ import { DocumentNode, FieldNode } from 'graphql';
2
2
  import { Reference, StoreObject, StoreValue, isReference } from '../../../utilities';
3
3
  import { StorageType } from '../../inmemory/policies';
4
4
  export declare type SafeReadonly<T> = T extends object ? Readonly<T> : T;
5
- export declare class MissingFieldError extends Error {
5
+ export declare type MissingTree = string | {
6
+ readonly [key: string]: MissingTree;
7
+ };
8
+ export declare class MissingFieldError {
6
9
  readonly message: string;
7
- readonly path: (string | number)[];
8
- readonly query: import('graphql').DocumentNode;
10
+ readonly path: MissingTree | Array<string | number>;
11
+ readonly query: DocumentNode;
9
12
  readonly variables?: Record<string, any> | undefined;
10
- constructor(message: string, path: (string | number)[], query: import('graphql').DocumentNode, variables?: Record<string, any> | undefined);
13
+ constructor(message: string, path: MissingTree | Array<string | number>, query: DocumentNode, variables?: Record<string, any> | undefined);
11
14
  }
12
15
  export interface FieldSpecifier {
13
16
  typename?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/cache/core/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAStD,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEjE,q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AAG;IACtB,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;CACpC,CAAC"}
@@ -1,16 +1,11 @@
1
- import { __extends } from "tslib";
2
- var MissingFieldError = (function (_super) {
3
- __extends(MissingFieldError, _super);
1
+ var MissingFieldError = (function () {
4
2
  function MissingFieldError(message, path, query, variables) {
5
- var _this = _super.call(this, message) || this;
6
- _this.message = message;
7
- _this.path = path;
8
- _this.query = query;
9
- _this.variables = variables;
10
- _this.__proto__ = MissingFieldError.prototype;
11
- return _this;
3
+ this.message = message;
4
+ this.path = path;
5
+ this.query = query;
6
+ this.variables = variables;
12
7
  }
13
8
  return MissingFieldError;
14
- }(Error));
9
+ }());
15
10
  export { MissingFieldError };
16
11
  //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/cache/core/types/common.ts"],"names":[],"mappings":";AAoBA;IAAuC,qCAAK;IAC1C,2BACkB,OAAe,EACf,IAAyB,EACzB,KAAqC,EACrC,SAA+B;QAJjD,YAME,kBAAM,OAAO,CAAC,SAIf;QATiB,aAAO,GAAP,OAAO,CAAQ;QACf,UAAI,GAAJ,IAAI,CAAqB;QACzB,WAAK,GAAL,KAAK,CAAgC;QACrC,eAAS,GAAT,SAAS,CAAsB;QAK9C,KAAY,CAAC,SAAS,GAAG,iBAAiB,CAAC,SAAS,CAAC;;IACxD,CAAC;IACH,wBAAC;AAAD,CAAC,AAZD,CAAuC,KAAK,GAY3C","sourcesContent":["import { FieldNode } from 'graphql';\n\nimport {\n Reference,\n StoreObject,\n StoreValue,\n isReference,\n} from '../../../utilities';\n\nimport { StorageType } from '../../inmemory/policies';\n\n// The Readonly<T> type only really works for object types, since it marks\n// all of the object's properties as readonly, but there are many cases when\n// a generic type parameter like TExisting might be a string or some other\n// primitive type, in which case we need to avoid wrapping it with Readonly.\n// SafeReadonly<string> collapses to just string, which makes string\n// assignable to SafeReadonly<any>, whereas string is not assignable to\n// Readonly<any>, somewhat surprisingly.\nexport type SafeReadonly<T> = T extends object ? Readonly<T> : T;\n\nexport class MissingFieldError extends Error {\n constructor(\n public readonly message: string,\n public readonly path: (string | number)[],\n public readonly query: import('graphql').DocumentNode,\n public readonly variables?: Record<string, any>,\n ) {\n super(message);\n // We're not using `Object.setPrototypeOf` here as it isn't fully\n // supported on Android (see issue #3236).\n (this as any).__proto__ = MissingFieldError.prototype;\n }\n}\n\nexport interface FieldSpecifier {\n typename?: string;\n fieldName: string;\n field?: FieldNode;\n args?: Record<string, any>;\n variables?: Record<string, any>;\n}\n\nexport interface ReadFieldOptions extends FieldSpecifier {\n from?: StoreObject | Reference;\n}\n\nexport interface ReadFieldFunction {\n <V = StoreValue>(options: ReadFieldOptions): SafeReadonly<V> | undefined;\n <V = StoreValue>(\n fieldName: string,\n from?: StoreObject | Reference,\n ): SafeReadonly<V> | undefined;\n}\n\nexport type ToReferenceFunction = (\n objOrIdOrRef: StoreObject | string | Reference,\n mergeIntoStore?: boolean,\n) => Reference | undefined;\n\nexport type CanReadFunction = (value: StoreValue) => boolean;\n\nexport type Modifier<T> = (value: T, details: {\n DELETE: any;\n INVALIDATE: any;\n fieldName: string;\n storeFieldName: string;\n readField: ReadFieldFunction;\n canRead: CanReadFunction;\n isReference: typeof isReference;\n toReference: ToReferenceFunction;\n storage: StorageType;\n}) => T;\n\nexport type Modifiers = {\n [fieldName: string]: Modifier<any>;\n};\n"]}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/cache/core/types/common.ts"],"names":[],"mappings":"AAwBA;IACE,2BACkB,OAAe,EACf,IAA0C,EAC1C,KAAmB,EACnB,SAA+B;QAH/B,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAsC;QAC1C,UAAK,GAAL,KAAK,CAAc;QACnB,cAAS,GAAT,SAAS,CAAsB;IAC9C,CAAC;IACN,wBAAC;AAAD,CAAC,AAPD,IAOC","sourcesContent":["import { DocumentNode, FieldNode } from 'graphql';\n\nimport {\n Reference,\n StoreObject,\n StoreValue,\n isReference,\n} from '../../../utilities';\n\nimport { StorageType } from '../../inmemory/policies';\n\n// The Readonly<T> type only really works for object types, since it marks\n// all of the object's properties as readonly, but there are many cases when\n// a generic type parameter like TExisting might be a string or some other\n// primitive type, in which case we need to avoid wrapping it with Readonly.\n// SafeReadonly<string> collapses to just string, which makes string\n// assignable to SafeReadonly<any>, whereas string is not assignable to\n// Readonly<any>, somewhat surprisingly.\nexport type SafeReadonly<T> = T extends object ? Readonly<T> : T;\n\nexport type MissingTree = string | {\n readonly [key: string]: MissingTree;\n};\n\nexport class MissingFieldError {\n constructor(\n public readonly message: string,\n public readonly path: MissingTree | Array<string | number>,\n public readonly query: DocumentNode,\n public readonly variables?: Record<string, any>,\n ) {}\n}\n\nexport interface FieldSpecifier {\n typename?: string;\n fieldName: string;\n field?: FieldNode;\n args?: Record<string, any>;\n variables?: Record<string, any>;\n}\n\nexport interface ReadFieldOptions extends FieldSpecifier {\n from?: StoreObject | Reference;\n}\n\nexport interface ReadFieldFunction {\n <V = StoreValue>(options: ReadFieldOptions): SafeReadonly<V> | undefined;\n <V = StoreValue>(\n fieldName: string,\n from?: StoreObject | Reference,\n ): SafeReadonly<V> | undefined;\n}\n\nexport type ToReferenceFunction = (\n objOrIdOrRef: StoreObject | string | Reference,\n mergeIntoStore?: boolean,\n) => Reference | undefined;\n\nexport type CanReadFunction = (value: StoreValue) => boolean;\n\nexport type Modifier<T> = (value: T, details: {\n DELETE: any;\n INVALIDATE: any;\n fieldName: string;\n storeFieldName: string;\n readField: ReadFieldFunction;\n canRead: CanReadFunction;\n isReference: typeof isReference;\n toReference: ToReferenceFunction;\n storage: StorageType;\n}) => T;\n\nexport type Modifiers = {\n [fieldName: string]: Modifier<any>;\n};\n"]}
@@ -12,7 +12,7 @@ export function defaultDataIdFromObject(_a, context) {
12
12
  if (id === void 0)
13
13
  id = _id;
14
14
  if (id !== void 0) {
15
- return __typename + ":" + ((typeof id === "number" ||
15
+ return "".concat(__typename, ":").concat((typeof id === "number" ||
16
16
  typeof id === "string") ? id : JSON.stringify(id));
17
17
  }
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/cache/inmemory/helpers.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,WAAW,EAGX,OAAO,EACP,UAAU,EACV,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,OAAO,GACR,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CACJ,IAAgB,MAAM,GACpB,MAAM,CAAC,SAAS,eADI,CACH;AAErB,MAAM,UAAU,uBAAuB,CACrC,EAA8C,EAC9C,OAA0B;QADxB,UAAU,gBAAA,EAAE,EAAE,QAAA,EAAE,GAAG,SAAA;IAGrB,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAClC,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,SAAS;gBACd,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAG,EAAE,IAAA,EAAE,CAAC,CAAC;oBAC1B,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAA,EAAE,CAAC,CAAC;wBAC1B,KAAK,CAAC,CAAC;SACV;QAED,IAAI,EAAE,KAAK,KAAK,CAAC;YAAE,EAAE,GAAG,GAAG,CAAC;QAC5B,IAAI,EAAE,KAAK,KAAK,CAAC,EAAE;YACjB,OAAU,UAAU,UAAI,CACtB,OAAO,EAAE,KAAK,QAAQ;gBACtB,OAAO,EAAE,KAAK,QAAQ,CACvB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAE,CAAC;SAC/B;KACF;AACH,CAAC;AAED,IAAM,aAAa,GAAG;IACpB,gBAAgB,EAAE,uBAAuB;IACzC,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,IAAI;IAGnB,eAAe,EAAE,KAAK;CACvB,CAAC;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CAAC,KAAK,EAAE,SAAS,CAAC,EAAE;oBACrD,IAAM,GAAG,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;oBAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC;wBAC7B,CAAC,CAAC,KAAK,CAAC,YAAY;4BACnB,yBAAyB,CAAC,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;iBAC3E;gBAMD,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;KACN;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,KAAiB;IAEjB,OAAO,eAAe,CAAC,KAAK,CAAC;QAC3B,CAAC,WAAW,CAAC,KAAK,CAAC;QACnB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO,IAAI,UAAU,CAAC;AACxB,CAAC","sourcesContent":["import { SelectionSetNode } from 'graphql';\n\nimport {\n NormalizedCache,\n InMemoryCacheConfig,\n} from './types';\n\nimport { KeyFieldsContext } from './policies';\n\nimport {\n Reference,\n isReference,\n StoreValue,\n StoreObject,\n isField,\n DeepMerger,\n resultKeyNameFromField,\n shouldInclude,\n isNonNullObject,\n compact,\n} from '../../utilities';\n\nexport const {\n hasOwnProperty: hasOwn,\n} = Object.prototype;\n\nexport function defaultDataIdFromObject(\n { __typename, id, _id }: Readonly<StoreObject>,\n context?: KeyFieldsContext,\n): string | undefined {\n if (typeof __typename === \"string\") {\n if (context) {\n context.keyObject =\n id !== void 0 ? { id } :\n _id !== void 0 ? { _id } :\n void 0;\n }\n // If there is no object.id, fall back to object._id.\n if (id === void 0) id = _id;\n if (id !== void 0) {\n return `${__typename}:${(\n typeof id === \"number\" ||\n typeof id === \"string\"\n ) ? id : JSON.stringify(id)}`;\n }\n }\n}\n\nconst defaultConfig = {\n dataIdFromObject: defaultDataIdFromObject,\n addTypename: true,\n resultCaching: true,\n // Thanks to the shouldCanonizeResults helper, this should be the only line\n // you have to change to reenable canonization by default in the future.\n canonizeResults: false,\n};\n\nexport function normalizeConfig(config: InMemoryCacheConfig) {\n return compact(defaultConfig, config);\n}\n\nexport function shouldCanonizeResults(\n config: Pick<InMemoryCacheConfig, \"canonizeResults\">,\n): boolean {\n const value = config.canonizeResults;\n return value === void 0 ? defaultConfig.canonizeResults : value;\n}\n\nexport function getTypenameFromStoreObject(\n store: NormalizedCache,\n objectOrReference: StoreObject | Reference,\n): string | undefined {\n return isReference(objectOrReference)\n ? store.get(objectOrReference.__ref, \"__typename\") as string\n : objectOrReference && objectOrReference.__typename;\n}\n\nexport const TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i;\n\nexport function fieldNameFromStoreName(storeFieldName: string): string {\n const match = storeFieldName.match(TypeOrFieldNameRegExp);\n return match ? match[0] : storeFieldName;\n}\n\nexport function selectionSetMatchesResult(\n selectionSet: SelectionSetNode,\n result: Record<string, any>,\n variables?: Record<string, any>,\n): boolean {\n if (isNonNullObject(result)) {\n return Array.isArray(result)\n ? result.every(item => selectionSetMatchesResult(selectionSet, item, variables))\n : selectionSet.selections.every(field => {\n if (isField(field) && shouldInclude(field, variables)) {\n const key = resultKeyNameFromField(field);\n return hasOwn.call(result, key) &&\n (!field.selectionSet ||\n selectionSetMatchesResult(field.selectionSet, result[key], variables));\n }\n // If the selection has been skipped with @skip(true) or\n // @include(false), it should not count against the matching. If\n // the selection is not a field, it must be a fragment (inline or\n // named). We will determine if selectionSetMatchesResult for that\n // fragment when we get to it, so for now we return true.\n return true;\n });\n }\n return false;\n}\n\nexport function storeValueIsStoreObject(\n value: StoreValue,\n): value is StoreObject {\n return isNonNullObject(value) &&\n !isReference(value) &&\n !Array.isArray(value);\n}\n\nexport function makeProcessedFieldsMerger() {\n return new DeepMerger;\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../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,CAAC;wBAC7B,CAAC,CAAC,KAAK,CAAC,YAAY;4BACnB,yBAAyB,CAAC,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;iBAC3E;gBAMD,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;KACN;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,KAAiB;IAEjB,OAAO,eAAe,CAAC,KAAK,CAAC;QAC3B,CAAC,WAAW,CAAC,KAAK,CAAC;QACnB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO,IAAI,UAAU,CAAC;AACxB,CAAC","sourcesContent":["import { SelectionSetNode } from 'graphql';\n\nimport {\n NormalizedCache,\n InMemoryCacheConfig,\n} from './types';\n\nimport { KeyFieldsContext } from './policies';\n\nimport {\n Reference,\n isReference,\n StoreValue,\n StoreObject,\n isField,\n DeepMerger,\n resultKeyNameFromField,\n shouldInclude,\n isNonNullObject,\n compact,\n} from '../../utilities';\n\nexport const {\n hasOwnProperty: hasOwn,\n} = Object.prototype;\n\nexport function defaultDataIdFromObject(\n { __typename, id, _id }: Readonly<StoreObject>,\n context?: KeyFieldsContext,\n): string | undefined {\n if (typeof __typename === \"string\") {\n if (context) {\n context.keyObject =\n id !== void 0 ? { id } :\n _id !== void 0 ? { _id } :\n void 0;\n }\n // If there is no object.id, fall back to object._id.\n if (id === void 0) id = _id;\n if (id !== void 0) {\n return `${__typename}:${(\n typeof id === \"number\" ||\n typeof id === \"string\"\n ) ? id : JSON.stringify(id)}`;\n }\n }\n}\n\nconst defaultConfig = {\n dataIdFromObject: defaultDataIdFromObject,\n addTypename: true,\n resultCaching: true,\n // Thanks to the shouldCanonizeResults helper, this should be the only line\n // you have to change to reenable canonization by default in the future.\n canonizeResults: false,\n};\n\nexport function normalizeConfig(config: InMemoryCacheConfig) {\n return compact(defaultConfig, config);\n}\n\nexport function shouldCanonizeResults(\n config: Pick<InMemoryCacheConfig, \"canonizeResults\">,\n): boolean {\n const value = config.canonizeResults;\n return value === void 0 ? defaultConfig.canonizeResults : value;\n}\n\nexport function getTypenameFromStoreObject(\n store: NormalizedCache,\n objectOrReference: StoreObject | Reference,\n): string | undefined {\n return isReference(objectOrReference)\n ? store.get(objectOrReference.__ref, \"__typename\") as string\n : objectOrReference && objectOrReference.__typename;\n}\n\nexport const TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i;\n\nexport function fieldNameFromStoreName(storeFieldName: string): string {\n const match = storeFieldName.match(TypeOrFieldNameRegExp);\n return match ? match[0] : storeFieldName;\n}\n\nexport function selectionSetMatchesResult(\n selectionSet: SelectionSetNode,\n result: Record<string, any>,\n variables?: Record<string, any>,\n): boolean {\n if (isNonNullObject(result)) {\n return Array.isArray(result)\n ? result.every(item => selectionSetMatchesResult(selectionSet, item, variables))\n : selectionSet.selections.every(field => {\n if (isField(field) && shouldInclude(field, variables)) {\n const key = resultKeyNameFromField(field);\n return hasOwn.call(result, key) &&\n (!field.selectionSet ||\n selectionSetMatchesResult(field.selectionSet, result[key], variables));\n }\n // If the selection has been skipped with @skip(true) or\n // @include(false), it should not count against the matching. If\n // the selection is not a field, it must be a fragment (inline or\n // named). We will determine if selectionSetMatchesResult for that\n // fragment when we get to it, so for now we return true.\n return true;\n });\n }\n return false;\n}\n\nexport function storeValueIsStoreObject(\n value: StoreValue,\n): value is StoreObject {\n return isNonNullObject(value) &&\n !isReference(value) &&\n !Array.isArray(value);\n}\n\nexport function makeProcessedFieldsMerger() {\n return new DeepMerger;\n}\n"]}
@@ -27,8 +27,8 @@ export declare class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
27
27
  read<T>(options: Cache.ReadOptions): T | null;
28
28
  write(options: Cache.WriteOptions): Reference | undefined;
29
29
  modify(options: Cache.ModifyOptions): boolean;
30
- diff<T>(options: Cache.DiffOptions): Cache.DiffResult<T>;
31
- watch(watch: Cache.WatchOptions): () => void;
30
+ diff<TData, TVariables = any>(options: Cache.DiffOptions<TData, TVariables>): Cache.DiffResult<TData>;
31
+ watch<TData = any, TVariables = any>(watch: Cache.WatchOptions<TData, TVariables>): () => void;
32
32
  gc(options?: {
33
33
  resetResultCache?: boolean;
34
34
  resetResultIdentities?: boolean;
@@ -40,8 +40,8 @@ export declare class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
40
40
  reset(options?: Cache.ResetOptions): Promise<void>;
41
41
  removeOptimistic(idToRemove: string): void;
42
42
  private txCount;
43
- batch(options: Cache.BatchOptions<InMemoryCache>): void;
44
- performTransaction(update: (cache: InMemoryCache) => any, optimisticId?: string | null): void;
43
+ batch<TUpdateResult>(options: Cache.BatchOptions<InMemoryCache, TUpdateResult>): TUpdateResult;
44
+ performTransaction(update: (cache: InMemoryCache) => any, optimisticId?: string | null): any;
45
45
  transformDocument(document: DocumentNode): DocumentNode;
46
46
  protected broadcastWatches(options?: BroadcastOptions): void;
47
47
  private broadcastWatch;
@@ -1 +1 @@
1
- {"version":3,"file":"inMemoryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/inMemoryCache.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAEL,WAAW,EACX,SAAS,EAEV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAIrE,OAAO,EAAE,OAAO,EAA4B,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,aAAK,gBAAgB,GAAG,IAAI,CAC1B,KAAK,CAAC,YAAY,CAAC,aAAa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IAgCN,EAAE,CAAC,OAAO,CAAC,EAAE;QAGlB,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAI3B,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC;IAoBM,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM;IASpD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM;IAUrD,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS;IAS7D,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,GAAG,OAAO;IA0B3C,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBlD,gBAAgB,CAAC,UAAU,EAAE,MAAM;IAQ1C,OAAO,CAAC,OAAO,CAAK;IAEb,KAAK,CAAC,aAAa,EACxB,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,aAAa,CAAC,GACxD,aAAa;IAmGT,kBAAkB,CACvB,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,GAAG,EACrC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAQvB,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY;IAgB9D,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB;IAYrD,OAAO,CAAC,cAAc;CAgCvB"}
@@ -1,4 +1,5 @@
1
1
  import { __assign, __extends } from "tslib";
2
+ import { invariant } from "../../utilities/globals/index.js";
2
3
  import "./fixPolyfills.js";
3
4
  import { wrap } from 'optimism';
4
5
  import { equal } from '@wry/equality';
@@ -158,8 +159,14 @@ var InMemoryCache = (function (_super) {
158
159
  return (optimistic ? this.optimisticData : this.data).release(rootId);
159
160
  };
160
161
  InMemoryCache.prototype.identify = function (object) {
161
- return isReference(object) ? object.__ref :
162
- this.policies.identify(object)[0];
162
+ if (isReference(object))
163
+ return object.__ref;
164
+ try {
165
+ return this.policies.identify(object)[0];
166
+ }
167
+ catch (e) {
168
+ __DEV__ && invariant.warn(e);
169
+ }
163
170
  };
164
171
  InMemoryCache.prototype.evict = function (options) {
165
172
  if (!options.id) {
@@ -202,6 +209,7 @@ var InMemoryCache = (function (_super) {
202
209
  InMemoryCache.prototype.batch = function (options) {
203
210
  var _this = this;
204
211
  var update = options.update, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, removeOptimistic = options.removeOptimistic, onWatchUpdated = options.onWatchUpdated;
212
+ var updateResult;
205
213
  var perform = function (layer) {
206
214
  var _a = _this, data = _a.data, optimisticData = _a.optimisticData;
207
215
  ++_this.txCount;
@@ -209,7 +217,7 @@ var InMemoryCache = (function (_super) {
209
217
  _this.data = _this.optimisticData = layer;
210
218
  }
211
219
  try {
212
- update(_this);
220
+ return updateResult = update(_this);
213
221
  }
214
222
  finally {
215
223
  --_this.txCount;
@@ -251,6 +259,7 @@ var InMemoryCache = (function (_super) {
251
259
  else {
252
260
  this.broadcastWatches(options);
253
261
  }
262
+ return updateResult;
254
263
  };
255
264
  InMemoryCache.prototype.performTransaction = function (update, optimisticId) {
256
265
  return this.batch({
@@ -1 +1 @@
1
- {"version":3,"file":"inMemoryCache.js","sourceRoot":"","sources":["../../../src/cache/inmemory/inMemoryCache.ts"],"names":[],"mappings":";AACA,OAAO,gBAAgB,CAAC;AAGxB,OAAO,EAA6B,IAAI,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACL,qBAAqB,EAGrB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,E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AAQ,CAAC,KAAK,KAAK,EAAE;gBAGlE,OAAO;aACR;SACF;QAED,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;YACrD,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC;SACzC;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AAlgBD,CAAmC,WAAW,GAkgB7C","sourcesContent":["// Make builtins like Map and Set safe to use with non-extensible objects.\nimport './fixPolyfills';\n\nimport { DocumentNode } from 'graphql';\nimport { OptimisticWrapperFunction, wrap } from 'optimism';\nimport { equal } from '@wry/equality';\n\nimport { ApolloCache } from '../core/cache';\nimport { Cache } from '../core/types/Cache';\nimport { MissingFieldError } from '../core/types/common';\nimport {\n addTypenameToDocument,\n StoreObject,\n Reference,\n isReference,\n} from '../../utilities';\nimport { InMemoryCacheConfig, NormalizedCacheObject } from './types';\nimport { StoreReader } from './readFromStore';\nimport { StoreWriter } from './writeToStore';\nimport { EntityStore, supportsResultCaching } from './entityStore';\nimport { makeVar, forgetCache, recallCache } from './reactiveVars';\nimport { Policies } from './policies';\nimport { hasOwn, normalizeConfig, shouldCanonizeResults } from './helpers';\nimport { canonicalStringify } from './object-canon';\n\ntype BroadcastOptions = Pick<\n Cache.BatchOptions<InMemoryCache>,\n | \"optimistic\"\n | \"onWatchUpdated\"\n>\n\nexport class InMemoryCache extends ApolloCache<NormalizedCacheObject> {\n private data: EntityStore;\n private optimisticData: EntityStore;\n\n protected config: InMemoryCacheConfig;\n private watches = new Set<Cache.WatchOptions>();\n private addTypename: boolean;\n\n private typenameDocumentCache = new Map<DocumentNode, DocumentNode>();\n private storeReader: StoreReader;\n private storeWriter: StoreWriter;\n\n private maybeBroadcastWatch: OptimisticWrapperFunction<\n [Cache.WatchOptions, BroadcastOptions?],\n any,\n [Cache.WatchOptions]>;\n\n // Dynamically imported code can augment existing typePolicies or\n // possibleTypes by calling cache.policies.addTypePolicies or\n // cache.policies.addPossibletypes.\n public readonly policies: Policies;\n\n public readonly makeVar = makeVar;\n\n constructor(config: InMemoryCacheConfig = {}) {\n super();\n this.config = normalizeConfig(config);\n this.addTypename = !!this.config.addTypename;\n\n this.policies = new Policies({\n cache: this,\n dataIdFromObject: this.config.dataIdFromObject,\n possibleTypes: this.config.possibleTypes,\n typePolicies: this.config.typePolicies,\n });\n\n this.init();\n }\n\n private init() {\n // Passing { resultCaching: false } in the InMemoryCache constructor options\n // will completely disable dependency tracking, which will improve memory\n // usage but worsen the performance of repeated reads.\n const rootStore = this.data = new EntityStore.Root({\n policies: this.policies,\n resultCaching: this.config.resultCaching,\n });\n\n // When no optimistic writes are currently active, cache.optimisticData ===\n // cache.data, so there are no additional layers on top of the actual data.\n // When an optimistic update happens, this.optimisticData will become a\n // linked list of EntityStore Layer objects that terminates with the\n // original this.data cache object.\n this.optimisticData = rootStore.stump;\n\n this.resetResultCache();\n }\n\n private resetResultCache(resetResultIdentities?: boolean) {\n const previousReader = this.storeReader;\n\n // The StoreWriter is mostly stateless and so doesn't really need to be\n // reset, but it does need to have its writer.storeReader reference updated,\n // so it's simpler to update this.storeWriter as well.\n this.storeWriter = new StoreWriter(\n this,\n this.storeReader = new StoreReader({\n cache: this,\n addTypename: this.addTypename,\n resultCacheMaxSize: this.config.resultCacheMaxSize,\n canonizeResults: shouldCanonizeResults(this.config),\n canon: resetResultIdentities\n ? void 0\n : previousReader && previousReader.canon,\n }),\n );\n\n this.maybeBroadcastWatch = wrap((\n c: Cache.WatchOptions,\n options?: BroadcastOptions,\n ) => {\n return this.broadcastWatch(c, options);\n }, {\n max: this.config.resultCacheMaxSize,\n makeCacheKey: (c: Cache.WatchOptions) => {\n // Return a cache key (thus enabling result caching) only if we're\n // currently using a data store that can track cache dependencies.\n const store = c.optimistic ? this.optimisticData : this.data;\n if (supportsResultCaching(store)) {\n const { optimistic, rootId, variables } = c;\n return store.makeCacheKey(\n c.query,\n // Different watches can have the same query, optimistic\n // status, rootId, and variables, but if their callbacks are\n // different, the (identical) result needs to be delivered to\n // each distinct callback. The easiest way to achieve that\n // separation is to include c.callback in the cache key for\n // maybeBroadcastWatch calls. See issue #5733.\n c.callback,\n canonicalStringify({ optimistic, rootId, variables }),\n );\n }\n }\n });\n\n // Since we have thrown away all the cached functions that depend on the\n // CacheGroup dependencies maintained by EntityStore, we should also reset\n // all CacheGroup dependency information.\n new Set([\n this.data.group,\n this.optimisticData.group,\n ]).forEach(group => group.resetCaching());\n }\n\n public restore(data: NormalizedCacheObject): this {\n this.init();\n // Since calling this.init() discards/replaces the entire StoreReader, along\n // with the result caches it maintains, this.data.replace(data) won't have\n // to bother deleting the old data.\n if (data) this.data.replace(data);\n return this;\n }\n\n public extract(optimistic: boolean = false): NormalizedCacheObject {\n return (optimistic ? this.optimisticData : this.data).extract();\n }\n\n public read<T>(options: Cache.ReadOptions): T | null {\n const {\n // Since read returns data or null, without any additional metadata\n // about whether/where there might have been missing fields, the\n // default behavior cannot be returnPartialData = true (like it is\n // for the diff method), since defaulting to true would violate the\n // integrity of the T in the return type. However, partial data may\n // be useful in some cases, so returnPartialData:true may be\n // specified explicitly.\n returnPartialData = false,\n } = options;\n try {\n return this.storeReader.diffQueryAgainstStore<T>({\n ...options,\n store: options.optimistic ? this.optimisticData : this.data,\n config: this.config,\n returnPartialData,\n }).result || null;\n } catch (e) {\n if (e instanceof MissingFieldError) {\n // Swallow MissingFieldError and return null, so callers do not\n // need to worry about catching \"normal\" exceptions resulting from\n // incomplete cache data. Unexpected errors will be re-thrown. If\n // you need more information about which fields were missing, use\n // cache.diff instead, and examine diffResult.missing.\n return null;\n }\n throw e;\n }\n }\n\n public write(options: Cache.WriteOptions): Reference | undefined {\n try {\n ++this.txCount;\n return this.storeWriter.writeToStore(this.data, options);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public modify(options: Cache.ModifyOptions): boolean {\n if (hasOwn.call(options, \"id\") && !options.id) {\n // To my knowledge, TypeScript does not currently provide a way to\n // enforce that an optional property?:type must *not* be undefined\n // when present. That ability would be useful here, because we want\n // options.id to default to ROOT_QUERY only when no options.id was\n // provided. If the caller attempts to pass options.id with a\n // falsy/undefined value (perhaps because cache.identify failed), we\n // should not assume the goal was to modify the ROOT_QUERY object.\n // We could throw, but it seems natural to return false to indicate\n // that nothing was modified.\n return false;\n }\n const store = options.optimistic // Defaults to false.\n ? this.optimisticData\n : this.data;\n try {\n ++this.txCount;\n return store.modify(options.id || \"ROOT_QUERY\", options.fields);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public diff<T>(options: Cache.DiffOptions): Cache.DiffResult<T> {\n return this.storeReader.diffQueryAgainstStore({\n ...options,\n store: options.optimistic ? this.optimisticData : this.data,\n rootId: options.id || \"ROOT_QUERY\",\n config: this.config,\n });\n }\n\n public watch(watch: Cache.WatchOptions): () => void {\n if (!this.watches.size) {\n // In case we previously called forgetCache(this) because\n // this.watches became empty (see below), reattach this cache to any\n // reactive variables on which it previously depended. It might seem\n // paradoxical that we're able to recall something we supposedly\n // forgot, but the point of calling forgetCache(this) is to silence\n // useless broadcasts while this.watches is empty, and to allow the\n // cache to be garbage collected. If, however, we manage to call\n // recallCache(this) here, this cache object must not have been\n // garbage collected yet, and should resume receiving updates from\n // reactive variables, now that it has a watcher to notify.\n recallCache(this);\n }\n this.watches.add(watch);\n if (watch.immediate) {\n this.maybeBroadcastWatch(watch);\n }\n return () => {\n // Once we remove the last watch from this.watches, cache.broadcastWatches\n // no longer does anything, so we preemptively tell the reactive variable\n // system to exclude this cache from future broadcasts.\n if (this.watches.delete(watch) && !this.watches.size) {\n forgetCache(this);\n }\n // Remove this watch from the LRU cache managed by the\n // maybeBroadcastWatch OptimisticWrapperFunction, to prevent memory\n // leaks involving the closure of watch.callback.\n this.maybeBroadcastWatch.forget(watch);\n };\n }\n\n public gc(options?: {\n // If true, also free non-essential result cache memory by bulk-releasing\n // this.{store{Reader,Writer},maybeBroadcastWatch}. Defaults to false.\n resetResultCache?: boolean;\n // If resetResultCache is true, this.storeReader.canon will be preserved by\n // default, but can also be discarded by passing resetResultIdentities:true.\n // Defaults to false.\n resetResultIdentities?: boolean;\n }) {\n canonicalStringify.reset();\n const ids = this.optimisticData.gc();\n if (options && !this.txCount) {\n if (options.resetResultCache) {\n this.resetResultCache(options.resetResultIdentities);\n } else if (options.resetResultIdentities) {\n this.storeReader.resetCanon();\n }\n }\n return ids;\n }\n\n // Call this method to ensure the given root ID remains in the cache after\n // garbage collection, along with its transitive child entities. Note that\n // the cache automatically retains all directly written entities. By default,\n // the retainment persists after optimistic updates are removed. Pass true\n // for the optimistic argument if you would prefer for the retainment to be\n // discarded when the top-most optimistic layer is removed. Returns the\n // resulting (non-negative) retainment count.\n public retain(rootId: string, optimistic?: boolean): number {\n return (optimistic ? this.optimisticData : this.data).retain(rootId);\n }\n\n // Call this method to undo the effect of the retain method, above. Once the\n // retainment count falls to zero, the given ID will no longer be preserved\n // during garbage collection, though it may still be preserved by other safe\n // entities that refer to it. Returns the resulting (non-negative) retainment\n // count, in case that's useful.\n public release(rootId: string, optimistic?: boolean): number {\n return (optimistic ? this.optimisticData : this.data).release(rootId);\n }\n\n // Returns the canonical ID for a given StoreObject, obeying typePolicies\n // and keyFields (and dataIdFromObject, if you still use that). At minimum,\n // the object must contain a __typename and any primary key fields required\n // to identify entities of that type. If you pass a query result object, be\n // sure that none of the primary key fields have been renamed by aliasing.\n // If you pass a Reference object, its __ref ID string will be returned.\n public identify(object: StoreObject | Reference): string | undefined {\n return isReference(object) ? object.__ref :\n this.policies.identify(object)[0];\n }\n\n public evict(options: Cache.EvictOptions): boolean {\n if (!options.id) {\n if (hasOwn.call(options, \"id\")) {\n // See comment in modify method about why we return false when\n // options.id exists but is falsy/undefined.\n return false;\n }\n options = { ...options, id: \"ROOT_QUERY\" };\n }\n try {\n // It's unlikely that the eviction will end up invoking any other\n // cache update operations while it's running, but {in,de}crementing\n // this.txCount still seems like a good idea, for uniformity with\n // the other update methods.\n ++this.txCount;\n // Pass this.data as a limit on the depth of the eviction, so evictions\n // during optimistic updates (when this.data is temporarily set equal to\n // this.optimisticData) do not escape their optimistic Layer.\n return this.optimisticData.evict(options, this.data);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public reset(options?: Cache.ResetOptions): Promise<void> {\n this.init();\n\n canonicalStringify.reset();\n\n if (options && options.discardWatches) {\n // Similar to what happens in the unsubscribe function returned by\n // cache.watch, applied to all current watches.\n this.watches.forEach(watch => this.maybeBroadcastWatch.forget(watch));\n this.watches.clear();\n forgetCache(this);\n } else {\n // Calling this.init() above unblocks all maybeBroadcastWatch caching, so\n // this.broadcastWatches() triggers a broadcast to every current watcher\n // (letting them know their data is now missing). This default behavior is\n // convenient because it means the watches do not have to be manually\n // reestablished after resetting the cache. To prevent this broadcast and\n // cancel all watches, pass true for options.discardWatches.\n this.broadcastWatches();\n }\n\n return Promise.resolve();\n }\n\n public removeOptimistic(idToRemove: string) {\n const newOptimisticData = this.optimisticData.removeLayer(idToRemove);\n if (newOptimisticData !== this.optimisticData) {\n this.optimisticData = newOptimisticData;\n this.broadcastWatches();\n }\n }\n\n private txCount = 0;\n\n public batch(options: Cache.BatchOptions<InMemoryCache>) {\n const {\n update,\n optimistic = true,\n removeOptimistic,\n onWatchUpdated,\n } = options;\n\n const perform = (layer?: EntityStore) => {\n const { data, optimisticData } = this;\n ++this.txCount;\n if (layer) {\n this.data = this.optimisticData = layer;\n }\n try {\n update(this);\n } finally {\n --this.txCount;\n this.data = data;\n this.optimisticData = optimisticData;\n }\n };\n\n const alreadyDirty = new Set<Cache.WatchOptions>();\n\n if (onWatchUpdated && !this.txCount) {\n // If an options.onWatchUpdated callback is provided, we want to call it\n // with only the Cache.WatchOptions objects affected by options.update,\n // but there might be dirty watchers already waiting to be broadcast that\n // have nothing to do with the update. To prevent including those watchers\n // in the post-update broadcast, we perform this initial broadcast to\n // collect the dirty watchers, so we can re-dirty them later, after the\n // post-update broadcast, allowing them to receive their pending\n // broadcasts the next time broadcastWatches is called, just as they would\n // if we never called cache.batch.\n this.broadcastWatches({\n ...options,\n onWatchUpdated(watch) {\n alreadyDirty.add(watch);\n return false;\n },\n });\n }\n\n if (typeof optimistic === 'string') {\n // Note that there can be multiple layers with the same optimistic ID.\n // When removeOptimistic(id) is called for that id, all matching layers\n // will be removed, and the remaining layers will be reapplied.\n this.optimisticData = this.optimisticData.addLayer(optimistic, perform);\n } else if (optimistic === false) {\n // Ensure both this.data and this.optimisticData refer to the root\n // (non-optimistic) layer of the cache during the update. Note that\n // this.data could be a Layer if we are currently executing an optimistic\n // update function, but otherwise will always be an EntityStore.Root\n // instance.\n perform(this.data);\n } else {\n // Otherwise, leave this.data and this.optimisticData unchanged and run\n // the update with broadcast batching.\n perform();\n }\n\n if (typeof removeOptimistic === \"string\") {\n this.optimisticData = this.optimisticData.removeLayer(removeOptimistic);\n }\n\n // Note: if this.txCount > 0, then alreadyDirty.size === 0, so this code\n // takes the else branch and calls this.broadcastWatches(options), which\n // does nothing when this.txCount > 0.\n if (onWatchUpdated && alreadyDirty.size) {\n this.broadcastWatches({\n ...options,\n onWatchUpdated(watch, diff) {\n const result = onWatchUpdated.call(this, watch, diff);\n if (result !== false) {\n // Since onWatchUpdated did not return false, this diff is\n // about to be broadcast to watch.callback, so we don't need\n // to re-dirty it with the other alreadyDirty watches below.\n alreadyDirty.delete(watch);\n }\n return result;\n }\n });\n // Silently re-dirty any watches that were already dirty before the update\n // was performed, and were not broadcast just now.\n if (alreadyDirty.size) {\n alreadyDirty.forEach(watch => this.maybeBroadcastWatch.dirty(watch));\n }\n } else {\n // If alreadyDirty is empty or we don't have an onWatchUpdated\n // function, we don't need to go to the trouble of wrapping\n // options.onWatchUpdated.\n this.broadcastWatches(options);\n }\n }\n\n public performTransaction(\n update: (cache: InMemoryCache) => any,\n optimisticId?: string | null,\n ) {\n return this.batch({\n update,\n optimistic: optimisticId || (optimisticId !== null),\n });\n }\n\n public transformDocument(document: DocumentNode): DocumentNode {\n if (this.addTypename) {\n let result = this.typenameDocumentCache.get(document);\n if (!result) {\n result = addTypenameToDocument(document);\n this.typenameDocumentCache.set(document, result);\n // If someone calls transformDocument and then mistakenly passes the\n // result back into an API that also calls transformDocument, make sure\n // we don't keep creating new query documents.\n this.typenameDocumentCache.set(result, result);\n }\n return result;\n }\n return document;\n }\n\n protected broadcastWatches(options?: BroadcastOptions) {\n if (!this.txCount) {\n this.watches.forEach(c => this.maybeBroadcastWatch(c, options));\n }\n }\n\n // This method is wrapped by maybeBroadcastWatch, which is called by\n // broadcastWatches, so that we compute and broadcast results only when\n // the data that would be broadcast might have changed. It would be\n // simpler to check for changes after recomputing a result but before\n // broadcasting it, but this wrapping approach allows us to skip both\n // the recomputation and the broadcast, in most cases.\n private broadcastWatch(\n c: Cache.WatchOptions,\n options?: BroadcastOptions,\n ) {\n const { lastDiff } = c;\n\n // Both WatchOptions and DiffOptions extend ReadOptions, and DiffOptions\n // currently requires no additional properties, so we can use c (a\n // WatchOptions object) as DiffOptions, without having to allocate a new\n // object, and without having to enumerate the relevant properties (query,\n // variables, etc.) explicitly. There will be some additional properties\n // (lastDiff, callback, etc.), but cache.diff ignores them.\n const diff = this.diff<any>(c);\n\n if (options) {\n if (c.optimistic &&\n typeof options.optimistic === \"string\") {\n diff.fromOptimisticTransaction = true;\n }\n\n if (options.onWatchUpdated &&\n options.onWatchUpdated.call(this, c, diff, lastDiff) === false) {\n // Returning false from the onWatchUpdated callback will prevent\n // calling c.callback(diff) for this watcher.\n return;\n }\n }\n\n if (!lastDiff || !equal(lastDiff.result, diff.result)) {\n c.callback(c.lastDiff = diff, lastDiff);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"inMemoryCache.js","sourceRoot":"","sources":["../../../src/cache/inmemory/inMemoryCache.ts"],"names":[],"mappings":";AAAA,OAAO,EAA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OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,KAAI,CAAC,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC,EAApC,CAAoC,CAAC,CAAC;SACjE;IACH,CAAC;IAQO,sCAAc,GAAtB,UACE,CAAqB,EACrB,OAA0B;QAElB,IAAA,QAAQ,GAAK,CAAC,SAAN,CAAO;QAQvB,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAM,CAAC,CAAC,CAAC;QAE/B,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,CAAC,UAAU;gBACZ,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,EAAE;gBAC1C,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;aACvC;YAED,IAAI,OAAO,CAAC,cAAc;gBACtB,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,KAAK,EAAE;gBAGlE,OAAO;aACR;SACF;QAED,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;YACrD,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC;SACzC;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AA/gBD,CAAmC,WAAW,GA+gB7C","sourcesContent":["import { invariant } from '../../utilities/globals';\n\n// Make builtins like Map and Set safe to use with non-extensible objects.\nimport './fixPolyfills';\n\nimport { DocumentNode } from 'graphql';\nimport { OptimisticWrapperFunction, wrap } from 'optimism';\nimport { equal } from '@wry/equality';\n\nimport { ApolloCache } from '../core/cache';\nimport { Cache } from '../core/types/Cache';\nimport { MissingFieldError } from '../core/types/common';\nimport {\n addTypenameToDocument,\n StoreObject,\n Reference,\n isReference,\n} from '../../utilities';\nimport { InMemoryCacheConfig, NormalizedCacheObject } from './types';\nimport { StoreReader } from './readFromStore';\nimport { StoreWriter } from './writeToStore';\nimport { EntityStore, supportsResultCaching } from './entityStore';\nimport { makeVar, forgetCache, recallCache } from './reactiveVars';\nimport { Policies } from './policies';\nimport { hasOwn, normalizeConfig, shouldCanonizeResults } from './helpers';\nimport { canonicalStringify } from './object-canon';\n\ntype BroadcastOptions = Pick<\n Cache.BatchOptions<InMemoryCache>,\n | \"optimistic\"\n | \"onWatchUpdated\"\n>\n\nexport class InMemoryCache extends ApolloCache<NormalizedCacheObject> {\n private data: EntityStore;\n private optimisticData: EntityStore;\n\n protected config: InMemoryCacheConfig;\n private watches = new Set<Cache.WatchOptions>();\n private addTypename: boolean;\n\n private typenameDocumentCache = new Map<DocumentNode, DocumentNode>();\n private storeReader: StoreReader;\n private storeWriter: StoreWriter;\n\n private maybeBroadcastWatch: OptimisticWrapperFunction<\n [Cache.WatchOptions, BroadcastOptions?],\n any,\n [Cache.WatchOptions]>;\n\n // Dynamically imported code can augment existing typePolicies or\n // possibleTypes by calling cache.policies.addTypePolicies or\n // cache.policies.addPossibletypes.\n public readonly policies: Policies;\n\n public readonly makeVar = makeVar;\n\n constructor(config: InMemoryCacheConfig = {}) {\n super();\n this.config = normalizeConfig(config);\n this.addTypename = !!this.config.addTypename;\n\n this.policies = new Policies({\n cache: this,\n dataIdFromObject: this.config.dataIdFromObject,\n possibleTypes: this.config.possibleTypes,\n typePolicies: this.config.typePolicies,\n });\n\n this.init();\n }\n\n private init() {\n // Passing { resultCaching: false } in the InMemoryCache constructor options\n // will completely disable dependency tracking, which will improve memory\n // usage but worsen the performance of repeated reads.\n const rootStore = this.data = new EntityStore.Root({\n policies: this.policies,\n resultCaching: this.config.resultCaching,\n });\n\n // When no optimistic writes are currently active, cache.optimisticData ===\n // cache.data, so there are no additional layers on top of the actual data.\n // When an optimistic update happens, this.optimisticData will become a\n // linked list of EntityStore Layer objects that terminates with the\n // original this.data cache object.\n this.optimisticData = rootStore.stump;\n\n this.resetResultCache();\n }\n\n private resetResultCache(resetResultIdentities?: boolean) {\n const previousReader = this.storeReader;\n\n // The StoreWriter is mostly stateless and so doesn't really need to be\n // reset, but it does need to have its writer.storeReader reference updated,\n // so it's simpler to update this.storeWriter as well.\n this.storeWriter = new StoreWriter(\n this,\n this.storeReader = new StoreReader({\n cache: this,\n addTypename: this.addTypename,\n resultCacheMaxSize: this.config.resultCacheMaxSize,\n canonizeResults: shouldCanonizeResults(this.config),\n canon: resetResultIdentities\n ? void 0\n : previousReader && previousReader.canon,\n }),\n );\n\n this.maybeBroadcastWatch = wrap((\n c: Cache.WatchOptions,\n options?: BroadcastOptions,\n ) => {\n return this.broadcastWatch(c, options);\n }, {\n max: this.config.resultCacheMaxSize,\n makeCacheKey: (c: Cache.WatchOptions) => {\n // Return a cache key (thus enabling result caching) only if we're\n // currently using a data store that can track cache dependencies.\n const store = c.optimistic ? this.optimisticData : this.data;\n if (supportsResultCaching(store)) {\n const { optimistic, rootId, variables } = c;\n return store.makeCacheKey(\n c.query,\n // Different watches can have the same query, optimistic\n // status, rootId, and variables, but if their callbacks are\n // different, the (identical) result needs to be delivered to\n // each distinct callback. The easiest way to achieve that\n // separation is to include c.callback in the cache key for\n // maybeBroadcastWatch calls. See issue #5733.\n c.callback,\n canonicalStringify({ optimistic, rootId, variables }),\n );\n }\n }\n });\n\n // Since we have thrown away all the cached functions that depend on the\n // CacheGroup dependencies maintained by EntityStore, we should also reset\n // all CacheGroup dependency information.\n new Set([\n this.data.group,\n this.optimisticData.group,\n ]).forEach(group => group.resetCaching());\n }\n\n public restore(data: NormalizedCacheObject): this {\n this.init();\n // Since calling this.init() discards/replaces the entire StoreReader, along\n // with the result caches it maintains, this.data.replace(data) won't have\n // to bother deleting the old data.\n if (data) this.data.replace(data);\n return this;\n }\n\n public extract(optimistic: boolean = false): NormalizedCacheObject {\n return (optimistic ? this.optimisticData : this.data).extract();\n }\n\n public read<T>(options: Cache.ReadOptions): T | null {\n const {\n // Since read returns data or null, without any additional metadata\n // about whether/where there might have been missing fields, the\n // default behavior cannot be returnPartialData = true (like it is\n // for the diff method), since defaulting to true would violate the\n // integrity of the T in the return type. However, partial data may\n // be useful in some cases, so returnPartialData:true may be\n // specified explicitly.\n returnPartialData = false,\n } = options;\n try {\n return this.storeReader.diffQueryAgainstStore<T>({\n ...options,\n store: options.optimistic ? this.optimisticData : this.data,\n config: this.config,\n returnPartialData,\n }).result || null;\n } catch (e) {\n if (e instanceof MissingFieldError) {\n // Swallow MissingFieldError and return null, so callers do not\n // need to worry about catching \"normal\" exceptions resulting from\n // incomplete cache data. Unexpected errors will be re-thrown. If\n // you need more information about which fields were missing, use\n // cache.diff instead, and examine diffResult.missing.\n return null;\n }\n throw e;\n }\n }\n\n public write(options: Cache.WriteOptions): Reference | undefined {\n try {\n ++this.txCount;\n return this.storeWriter.writeToStore(this.data, options);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public modify(options: Cache.ModifyOptions): boolean {\n if (hasOwn.call(options, \"id\") && !options.id) {\n // To my knowledge, TypeScript does not currently provide a way to\n // enforce that an optional property?:type must *not* be undefined\n // when present. That ability would be useful here, because we want\n // options.id to default to ROOT_QUERY only when no options.id was\n // provided. If the caller attempts to pass options.id with a\n // falsy/undefined value (perhaps because cache.identify failed), we\n // should not assume the goal was to modify the ROOT_QUERY object.\n // We could throw, but it seems natural to return false to indicate\n // that nothing was modified.\n return false;\n }\n const store = options.optimistic // Defaults to false.\n ? this.optimisticData\n : this.data;\n try {\n ++this.txCount;\n return store.modify(options.id || \"ROOT_QUERY\", options.fields);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public diff<TData, TVariables = any>(\n options: Cache.DiffOptions<TData, TVariables>,\n ): Cache.DiffResult<TData> {\n return this.storeReader.diffQueryAgainstStore({\n ...options,\n store: options.optimistic ? this.optimisticData : this.data,\n rootId: options.id || \"ROOT_QUERY\",\n config: this.config,\n });\n }\n\n public watch<TData = any, TVariables = any>(\n watch: Cache.WatchOptions<TData, TVariables>,\n ): () => void {\n if (!this.watches.size) {\n // In case we previously called forgetCache(this) because\n // this.watches became empty (see below), reattach this cache to any\n // reactive variables on which it previously depended. It might seem\n // paradoxical that we're able to recall something we supposedly\n // forgot, but the point of calling forgetCache(this) is to silence\n // useless broadcasts while this.watches is empty, and to allow the\n // cache to be garbage collected. If, however, we manage to call\n // recallCache(this) here, this cache object must not have been\n // garbage collected yet, and should resume receiving updates from\n // reactive variables, now that it has a watcher to notify.\n recallCache(this);\n }\n this.watches.add(watch);\n if (watch.immediate) {\n this.maybeBroadcastWatch(watch);\n }\n return () => {\n // Once we remove the last watch from this.watches, cache.broadcastWatches\n // no longer does anything, so we preemptively tell the reactive variable\n // system to exclude this cache from future broadcasts.\n if (this.watches.delete(watch) && !this.watches.size) {\n forgetCache(this);\n }\n // Remove this watch from the LRU cache managed by the\n // maybeBroadcastWatch OptimisticWrapperFunction, to prevent memory\n // leaks involving the closure of watch.callback.\n this.maybeBroadcastWatch.forget(watch);\n };\n }\n\n public gc(options?: {\n // If true, also free non-essential result cache memory by bulk-releasing\n // this.{store{Reader,Writer},maybeBroadcastWatch}. Defaults to false.\n resetResultCache?: boolean;\n // If resetResultCache is true, this.storeReader.canon will be preserved by\n // default, but can also be discarded by passing resetResultIdentities:true.\n // Defaults to false.\n resetResultIdentities?: boolean;\n }) {\n canonicalStringify.reset();\n const ids = this.optimisticData.gc();\n if (options && !this.txCount) {\n if (options.resetResultCache) {\n this.resetResultCache(options.resetResultIdentities);\n } else if (options.resetResultIdentities) {\n this.storeReader.resetCanon();\n }\n }\n return ids;\n }\n\n // Call this method to ensure the given root ID remains in the cache after\n // garbage collection, along with its transitive child entities. Note that\n // the cache automatically retains all directly written entities. By default,\n // the retainment persists after optimistic updates are removed. Pass true\n // for the optimistic argument if you would prefer for the retainment to be\n // discarded when the top-most optimistic layer is removed. Returns the\n // resulting (non-negative) retainment count.\n public retain(rootId: string, optimistic?: boolean): number {\n return (optimistic ? this.optimisticData : this.data).retain(rootId);\n }\n\n // Call this method to undo the effect of the retain method, above. Once the\n // retainment count falls to zero, the given ID will no longer be preserved\n // during garbage collection, though it may still be preserved by other safe\n // entities that refer to it. Returns the resulting (non-negative) retainment\n // count, in case that's useful.\n public release(rootId: string, optimistic?: boolean): number {\n return (optimistic ? this.optimisticData : this.data).release(rootId);\n }\n\n // Returns the canonical ID for a given StoreObject, obeying typePolicies\n // and keyFields (and dataIdFromObject, if you still use that). At minimum,\n // the object must contain a __typename and any primary key fields required\n // to identify entities of that type. If you pass a query result object, be\n // sure that none of the primary key fields have been renamed by aliasing.\n // If you pass a Reference object, its __ref ID string will be returned.\n public identify(object: StoreObject | Reference): string | undefined {\n if (isReference(object)) return object.__ref;\n try {\n return this.policies.identify(object)[0];\n } catch (e) {\n invariant.warn(e);\n }\n }\n\n public evict(options: Cache.EvictOptions): boolean {\n if (!options.id) {\n if (hasOwn.call(options, \"id\")) {\n // See comment in modify method about why we return false when\n // options.id exists but is falsy/undefined.\n return false;\n }\n options = { ...options, id: \"ROOT_QUERY\" };\n }\n try {\n // It's unlikely that the eviction will end up invoking any other\n // cache update operations while it's running, but {in,de}crementing\n // this.txCount still seems like a good idea, for uniformity with\n // the other update methods.\n ++this.txCount;\n // Pass this.data as a limit on the depth of the eviction, so evictions\n // during optimistic updates (when this.data is temporarily set equal to\n // this.optimisticData) do not escape their optimistic Layer.\n return this.optimisticData.evict(options, this.data);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public reset(options?: Cache.ResetOptions): Promise<void> {\n this.init();\n\n canonicalStringify.reset();\n\n if (options && options.discardWatches) {\n // Similar to what happens in the unsubscribe function returned by\n // cache.watch, applied to all current watches.\n this.watches.forEach(watch => this.maybeBroadcastWatch.forget(watch));\n this.watches.clear();\n forgetCache(this);\n } else {\n // Calling this.init() above unblocks all maybeBroadcastWatch caching, so\n // this.broadcastWatches() triggers a broadcast to every current watcher\n // (letting them know their data is now missing). This default behavior is\n // convenient because it means the watches do not have to be manually\n // reestablished after resetting the cache. To prevent this broadcast and\n // cancel all watches, pass true for options.discardWatches.\n this.broadcastWatches();\n }\n\n return Promise.resolve();\n }\n\n public removeOptimistic(idToRemove: string) {\n const newOptimisticData = this.optimisticData.removeLayer(idToRemove);\n if (newOptimisticData !== this.optimisticData) {\n this.optimisticData = newOptimisticData;\n this.broadcastWatches();\n }\n }\n\n private txCount = 0;\n\n public batch<TUpdateResult>(\n options: Cache.BatchOptions<InMemoryCache, TUpdateResult>,\n ): TUpdateResult {\n const {\n update,\n optimistic = true,\n removeOptimistic,\n onWatchUpdated,\n } = options;\n\n let updateResult: TUpdateResult;\n const perform = (layer?: EntityStore): TUpdateResult => {\n const { data, optimisticData } = this;\n ++this.txCount;\n if (layer) {\n this.data = this.optimisticData = layer;\n }\n try {\n return updateResult = update(this);\n } finally {\n --this.txCount;\n this.data = data;\n this.optimisticData = optimisticData;\n }\n };\n\n const alreadyDirty = new Set<Cache.WatchOptions>();\n\n if (onWatchUpdated && !this.txCount) {\n // If an options.onWatchUpdated callback is provided, we want to call it\n // with only the Cache.WatchOptions objects affected by options.update,\n // but there might be dirty watchers already waiting to be broadcast that\n // have nothing to do with the update. To prevent including those watchers\n // in the post-update broadcast, we perform this initial broadcast to\n // collect the dirty watchers, so we can re-dirty them later, after the\n // post-update broadcast, allowing them to receive their pending\n // broadcasts the next time broadcastWatches is called, just as they would\n // if we never called cache.batch.\n this.broadcastWatches({\n ...options,\n onWatchUpdated(watch) {\n alreadyDirty.add(watch);\n return false;\n },\n });\n }\n\n if (typeof optimistic === 'string') {\n // Note that there can be multiple layers with the same optimistic ID.\n // When removeOptimistic(id) is called for that id, all matching layers\n // will be removed, and the remaining layers will be reapplied.\n this.optimisticData = this.optimisticData.addLayer(optimistic, perform);\n } else if (optimistic === false) {\n // Ensure both this.data and this.optimisticData refer to the root\n // (non-optimistic) layer of the cache during the update. Note that\n // this.data could be a Layer if we are currently executing an optimistic\n // update function, but otherwise will always be an EntityStore.Root\n // instance.\n perform(this.data);\n } else {\n // Otherwise, leave this.data and this.optimisticData unchanged and run\n // the update with broadcast batching.\n perform();\n }\n\n if (typeof removeOptimistic === \"string\") {\n this.optimisticData = this.optimisticData.removeLayer(removeOptimistic);\n }\n\n // Note: if this.txCount > 0, then alreadyDirty.size === 0, so this code\n // takes the else branch and calls this.broadcastWatches(options), which\n // does nothing when this.txCount > 0.\n if (onWatchUpdated && alreadyDirty.size) {\n this.broadcastWatches({\n ...options,\n onWatchUpdated(watch, diff) {\n const result = onWatchUpdated.call(this, watch, diff);\n if (result !== false) {\n // Since onWatchUpdated did not return false, this diff is\n // about to be broadcast to watch.callback, so we don't need\n // to re-dirty it with the other alreadyDirty watches below.\n alreadyDirty.delete(watch);\n }\n return result;\n }\n });\n // Silently re-dirty any watches that were already dirty before the update\n // was performed, and were not broadcast just now.\n if (alreadyDirty.size) {\n alreadyDirty.forEach(watch => this.maybeBroadcastWatch.dirty(watch));\n }\n } else {\n // If alreadyDirty is empty or we don't have an onWatchUpdated\n // function, we don't need to go to the trouble of wrapping\n // options.onWatchUpdated.\n this.broadcastWatches(options);\n }\n\n return updateResult!;\n }\n\n public performTransaction(\n update: (cache: InMemoryCache) => any,\n optimisticId?: string | null,\n ) {\n return this.batch({\n update,\n optimistic: optimisticId || (optimisticId !== null),\n });\n }\n\n public transformDocument(document: DocumentNode): DocumentNode {\n if (this.addTypename) {\n let result = this.typenameDocumentCache.get(document);\n if (!result) {\n result = addTypenameToDocument(document);\n this.typenameDocumentCache.set(document, result);\n // If someone calls transformDocument and then mistakenly passes the\n // result back into an API that also calls transformDocument, make sure\n // we don't keep creating new query documents.\n this.typenameDocumentCache.set(result, result);\n }\n return result;\n }\n return document;\n }\n\n protected broadcastWatches(options?: BroadcastOptions) {\n if (!this.txCount) {\n this.watches.forEach(c => this.maybeBroadcastWatch(c, options));\n }\n }\n\n // This method is wrapped by maybeBroadcastWatch, which is called by\n // broadcastWatches, so that we compute and broadcast results only when\n // the data that would be broadcast might have changed. It would be\n // simpler to check for changes after recomputing a result but before\n // broadcasting it, but this wrapping approach allows us to skip both\n // the recomputation and the broadcast, in most cases.\n private broadcastWatch(\n c: Cache.WatchOptions,\n options?: BroadcastOptions,\n ) {\n const { lastDiff } = c;\n\n // Both WatchOptions and DiffOptions extend ReadOptions, and DiffOptions\n // currently requires no additional properties, so we can use c (a\n // WatchOptions object) as DiffOptions, without having to allocate a new\n // object, and without having to enumerate the relevant properties (query,\n // variables, etc.) explicitly. There will be some additional properties\n // (lastDiff, callback, etc.), but cache.diff ignores them.\n const diff = this.diff<any>(c);\n\n if (options) {\n if (c.optimistic &&\n typeof options.optimistic === \"string\") {\n diff.fromOptimisticTransaction = true;\n }\n\n if (options.onWatchUpdated &&\n options.onWatchUpdated.call(this, c, diff, lastDiff) === false) {\n // Returning false from the onWatchUpdated callback will prevent\n // calling c.callback(diff) for this watcher.\n return;\n }\n }\n\n if (!lastDiff || !equal(lastDiff.result, diff.result)) {\n c.callback(c.lastDiff = diff, lastDiff);\n }\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { KeySpecifier, KeyFieldsFunction, KeyArgsFunction } from "./policies";
2
+ export declare function keyFieldsFnFromSpecifier(specifier: KeySpecifier): KeyFieldsFunction;
3
+ export declare function keyArgsFnFromSpecifier(specifier: KeySpecifier): KeyArgsFunction;
4
+ export declare function collectSpecifierPaths(specifier: KeySpecifier, extractor: (path: string[]) => any): Record<string, any>;
5
+ export declare function getSpecifierPaths(spec: KeySpecifier): string[][];
6
+ declare function extractKey<TObj extends Record<string, any>, TKey extends string>(object: TObj, key: TKey): TObj[TKey] | undefined;
7
+ export declare function extractKeyPath(object: Record<string, any>, path: string[], extract?: typeof extractKey): any;
8
+ export {};
9
+ //# sourceMappingURL=key-extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-extractor.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/key-extractor.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,eAAe,EAChB,MAAM,YAAY,CAAC;AAkBpB,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,YAAY,GACtB,iBAAiB,CAoDnB;AASD,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,YAAY,GAAG,eAAe,CAyE/E;AAED,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,YAAY,EACvB,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAG,GACjC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAgBrB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,EAAE,EAAE,CAsBhE;AAED,iBAAS,UAAU,CACjB,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,IAAI,SAAS,MAAM,EACnB,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,CAEjD;AAED,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,CAAC,EAAE,OAAO,UAAU,GAC1B,GAAG,CAkBL"}