@apollo/client 0.0.0-pr-10521-20230206180228

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 (778) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +45 -0
  3. package/apollo-client.cjs +7614 -0
  4. package/apollo-client.cjs.map +1 -0
  5. package/apollo-client.min.cjs +1 -0
  6. package/cache/cache.cjs +2425 -0
  7. package/cache/cache.cjs.map +1 -0
  8. package/cache/cache.cjs.native.js +2425 -0
  9. package/cache/core/cache.d.ts +32 -0
  10. package/cache/core/cache.d.ts.map +1 -0
  11. package/cache/core/cache.js +84 -0
  12. package/cache/core/cache.js.map +1 -0
  13. package/cache/core/types/Cache.d.ts +55 -0
  14. package/cache/core/types/Cache.d.ts.map +1 -0
  15. package/cache/core/types/Cache.js +4 -0
  16. package/cache/core/types/Cache.js.map +1 -0
  17. package/cache/core/types/DataProxy.d.ts +52 -0
  18. package/cache/core/types/DataProxy.d.ts.map +1 -0
  19. package/cache/core/types/DataProxy.js +2 -0
  20. package/cache/core/types/DataProxy.js.map +1 -0
  21. package/cache/core/types/common.d.ts +47 -0
  22. package/cache/core/types/common.d.ts.map +1 -0
  23. package/cache/core/types/common.js +26 -0
  24. package/cache/core/types/common.js.map +1 -0
  25. package/cache/index.d.ts +15 -0
  26. package/cache/index.d.ts.map +1 -0
  27. package/cache/index.js +14 -0
  28. package/cache/index.js.map +1 -0
  29. package/cache/inmemory/__mocks__/optimism.d.ts +2 -0
  30. package/cache/inmemory/__mocks__/optimism.d.ts.map +1 -0
  31. package/cache/inmemory/__mocks__/optimism.js +14 -0
  32. package/cache/inmemory/__mocks__/optimism.js.map +1 -0
  33. package/cache/inmemory/entityStore.d.ts +83 -0
  34. package/cache/inmemory/entityStore.d.ts.map +1 -0
  35. package/cache/inmemory/entityStore.js +467 -0
  36. package/cache/inmemory/entityStore.js.map +1 -0
  37. package/cache/inmemory/fixPolyfills.d.ts +1 -0
  38. package/cache/inmemory/fixPolyfills.d.ts.map +1 -0
  39. package/cache/inmemory/fixPolyfills.js +1 -0
  40. package/cache/inmemory/fixPolyfills.js.map +1 -0
  41. package/cache/inmemory/fixPolyfills.native.d.ts +2 -0
  42. package/cache/inmemory/fixPolyfills.native.d.ts.map +1 -0
  43. package/cache/inmemory/fixPolyfills.native.js +48 -0
  44. package/cache/inmemory/fixPolyfills.native.js.map +1 -0
  45. package/cache/inmemory/fragmentRegistry.d.ts +8 -0
  46. package/cache/inmemory/fragmentRegistry.d.ts.map +1 -0
  47. package/cache/inmemory/fragmentRegistry.js +113 -0
  48. package/cache/inmemory/fragmentRegistry.js.map +1 -0
  49. package/cache/inmemory/helpers.d.ts +27 -0
  50. package/cache/inmemory/helpers.d.ts.map +1 -0
  51. package/cache/inmemory/helpers.js +85 -0
  52. package/cache/inmemory/helpers.js.map +1 -0
  53. package/cache/inmemory/inMemoryCache.d.ts +52 -0
  54. package/cache/inmemory/inMemoryCache.d.ts.map +1 -0
  55. package/cache/inmemory/inMemoryCache.js +316 -0
  56. package/cache/inmemory/inMemoryCache.js.map +1 -0
  57. package/cache/inmemory/key-extractor.d.ts +9 -0
  58. package/cache/inmemory/key-extractor.d.ts.map +1 -0
  59. package/cache/inmemory/key-extractor.js +118 -0
  60. package/cache/inmemory/key-extractor.js.map +1 -0
  61. package/cache/inmemory/object-canon.d.ts +17 -0
  62. package/cache/inmemory/object-canon.d.ts.map +1 -0
  63. package/cache/inmemory/object-canon.js +120 -0
  64. package/cache/inmemory/object-canon.js.map +1 -0
  65. package/cache/inmemory/policies.d.ts +96 -0
  66. package/cache/inmemory/policies.d.ts.map +1 -0
  67. package/cache/inmemory/policies.js +416 -0
  68. package/cache/inmemory/policies.js.map +1 -0
  69. package/cache/inmemory/reactiveVars.d.ts +18 -0
  70. package/cache/inmemory/reactiveVars.d.ts.map +1 -0
  71. package/cache/inmemory/reactiveVars.js +65 -0
  72. package/cache/inmemory/reactiveVars.js.map +1 -0
  73. package/cache/inmemory/readFromStore.d.ts +36 -0
  74. package/cache/inmemory/readFromStore.d.ts.map +1 -0
  75. package/cache/inmemory/readFromStore.js +267 -0
  76. package/cache/inmemory/readFromStore.js.map +1 -0
  77. package/cache/inmemory/types.d.ts +81 -0
  78. package/cache/inmemory/types.d.ts.map +1 -0
  79. package/cache/inmemory/types.js +4 -0
  80. package/cache/inmemory/types.js.map +1 -0
  81. package/cache/inmemory/writeToStore.d.ts +37 -0
  82. package/cache/inmemory/writeToStore.d.ts.map +1 -0
  83. package/cache/inmemory/writeToStore.js +394 -0
  84. package/cache/inmemory/writeToStore.js.map +1 -0
  85. package/cache/package.json +8 -0
  86. package/config/jest/setup.d.ts +2 -0
  87. package/config/jest/setup.d.ts.map +1 -0
  88. package/config/jest/setup.js +5 -0
  89. package/config/jest/setup.js.map +1 -0
  90. package/core/ApolloClient.d.ts +76 -0
  91. package/core/ApolloClient.d.ts.map +1 -0
  92. package/core/ApolloClient.js +240 -0
  93. package/core/ApolloClient.js.map +1 -0
  94. package/core/LocalState.d.ts +69 -0
  95. package/core/LocalState.d.ts.map +1 -0
  96. package/core/LocalState.js +321 -0
  97. package/core/LocalState.js.map +1 -0
  98. package/core/ObservableQuery.d.ts +74 -0
  99. package/core/ObservableQuery.d.ts.map +1 -0
  100. package/core/ObservableQuery.js +507 -0
  101. package/core/ObservableQuery.js.map +1 -0
  102. package/core/QueryInfo.d.ts +62 -0
  103. package/core/QueryInfo.d.ts.map +1 -0
  104. package/core/QueryInfo.js +287 -0
  105. package/core/QueryInfo.js.map +1 -0
  106. package/core/QueryManager.d.ts +120 -0
  107. package/core/QueryManager.d.ts.map +1 -0
  108. package/core/QueryManager.js +890 -0
  109. package/core/QueryManager.js.map +1 -0
  110. package/core/core.cjs +2349 -0
  111. package/core/core.cjs.map +1 -0
  112. package/core/core.cjs.native.js +2349 -0
  113. package/core/index.d.ts +17 -0
  114. package/core/index.d.ts.map +1 -0
  115. package/core/index.js +17 -0
  116. package/core/index.js.map +1 -0
  117. package/core/networkStatus.d.ts +11 -0
  118. package/core/networkStatus.d.ts.map +1 -0
  119. package/core/networkStatus.js +14 -0
  120. package/core/networkStatus.js.map +1 -0
  121. package/core/package.json +8 -0
  122. package/core/types.d.ts +74 -0
  123. package/core/types.d.ts.map +1 -0
  124. package/core/types.js +3 -0
  125. package/core/types.js.map +1 -0
  126. package/core/watchQueryOptions.d.ts +78 -0
  127. package/core/watchQueryOptions.d.ts.map +1 -0
  128. package/core/watchQueryOptions.js +2 -0
  129. package/core/watchQueryOptions.js.map +1 -0
  130. package/errors/errors.cjs +49 -0
  131. package/errors/errors.cjs.map +1 -0
  132. package/errors/errors.cjs.native.js +49 -0
  133. package/errors/index.d.ts +23 -0
  134. package/errors/index.d.ts.map +1 -0
  135. package/errors/index.js +42 -0
  136. package/errors/index.js.map +1 -0
  137. package/errors/package.json +8 -0
  138. package/index.d.ts +3 -0
  139. package/index.d.ts.map +1 -0
  140. package/index.js +3 -0
  141. package/index.js.map +1 -0
  142. package/invariantErrorCodes.js +339 -0
  143. package/link/batch/batch.cjs +159 -0
  144. package/link/batch/batch.cjs.map +1 -0
  145. package/link/batch/batch.cjs.native.js +159 -0
  146. package/link/batch/batchLink.d.ts +19 -0
  147. package/link/batch/batchLink.d.ts.map +1 -0
  148. package/link/batch/batchLink.js +31 -0
  149. package/link/batch/batchLink.js.map +1 -0
  150. package/link/batch/batching.d.ts +27 -0
  151. package/link/batch/batching.d.ts.map +1 -0
  152. package/link/batch/batching.js +125 -0
  153. package/link/batch/batching.js.map +1 -0
  154. package/link/batch/index.d.ts +2 -0
  155. package/link/batch/index.d.ts.map +1 -0
  156. package/link/batch/index.js +2 -0
  157. package/link/batch/index.js.map +1 -0
  158. package/link/batch/package.json +8 -0
  159. package/link/batch-http/batch-http.cjs +137 -0
  160. package/link/batch-http/batch-http.cjs.map +1 -0
  161. package/link/batch-http/batch-http.cjs.native.js +137 -0
  162. package/link/batch-http/batchHttpLink.d.ts +16 -0
  163. package/link/batch-http/batchHttpLink.d.ts.map +1 -0
  164. package/link/batch-http/batchHttpLink.js +131 -0
  165. package/link/batch-http/batchHttpLink.js.map +1 -0
  166. package/link/batch-http/index.d.ts +2 -0
  167. package/link/batch-http/index.d.ts.map +1 -0
  168. package/link/batch-http/index.js +2 -0
  169. package/link/batch-http/index.js.map +1 -0
  170. package/link/batch-http/package.json +8 -0
  171. package/link/context/context.cjs +38 -0
  172. package/link/context/context.cjs.map +1 -0
  173. package/link/context/context.cjs.native.js +38 -0
  174. package/link/context/index.d.ts +5 -0
  175. package/link/context/index.d.ts.map +1 -0
  176. package/link/context/index.js +31 -0
  177. package/link/context/index.js.map +1 -0
  178. package/link/context/package.json +8 -0
  179. package/link/core/ApolloLink.d.ts +16 -0
  180. package/link/core/ApolloLink.d.ts.map +1 -0
  181. package/link/core/ApolloLink.js +100 -0
  182. package/link/core/ApolloLink.js.map +1 -0
  183. package/link/core/concat.d.ts +3 -0
  184. package/link/core/concat.d.ts.map +1 -0
  185. package/link/core/concat.js +3 -0
  186. package/link/core/concat.js.map +1 -0
  187. package/link/core/core.cjs +121 -0
  188. package/link/core/core.cjs.map +1 -0
  189. package/link/core/core.cjs.native.js +121 -0
  190. package/link/core/empty.d.ts +3 -0
  191. package/link/core/empty.d.ts.map +1 -0
  192. package/link/core/empty.js +3 -0
  193. package/link/core/empty.js.map +1 -0
  194. package/link/core/execute.d.ts +3 -0
  195. package/link/core/execute.d.ts.map +1 -0
  196. package/link/core/execute.js +3 -0
  197. package/link/core/execute.js.map +1 -0
  198. package/link/core/from.d.ts +3 -0
  199. package/link/core/from.d.ts.map +1 -0
  200. package/link/core/from.js +3 -0
  201. package/link/core/from.js.map +1 -0
  202. package/link/core/index.d.ts +9 -0
  203. package/link/core/index.d.ts.map +1 -0
  204. package/link/core/index.js +9 -0
  205. package/link/core/index.js.map +1 -0
  206. package/link/core/package.json +8 -0
  207. package/link/core/split.d.ts +3 -0
  208. package/link/core/split.d.ts.map +1 -0
  209. package/link/core/split.js +3 -0
  210. package/link/core/split.js.map +1 -0
  211. package/link/core/types.d.ts +52 -0
  212. package/link/core/types.d.ts.map +1 -0
  213. package/link/core/types.js +2 -0
  214. package/link/core/types.js.map +1 -0
  215. package/link/error/error.cjs +90 -0
  216. package/link/error/error.cjs.map +1 -0
  217. package/link/error/error.cjs.native.js +90 -0
  218. package/link/error/index.d.ts +24 -0
  219. package/link/error/index.d.ts.map +1 -0
  220. package/link/error/index.js +83 -0
  221. package/link/error/index.js.map +1 -0
  222. package/link/error/package.json +8 -0
  223. package/link/http/HttpLink.d.ts +8 -0
  224. package/link/http/HttpLink.d.ts.map +1 -0
  225. package/link/http/HttpLink.js +15 -0
  226. package/link/http/HttpLink.js.map +1 -0
  227. package/link/http/checkFetcher.d.ts +2 -0
  228. package/link/http/checkFetcher.d.ts.map +1 -0
  229. package/link/http/checkFetcher.js +7 -0
  230. package/link/http/checkFetcher.js.map +1 -0
  231. package/link/http/createHttpLink.d.ts +4 -0
  232. package/link/http/createHttpLink.d.ts.map +1 -0
  233. package/link/http/createHttpLink.js +127 -0
  234. package/link/http/createHttpLink.js.map +1 -0
  235. package/link/http/createSignalIfSupported.d.ts +8 -0
  236. package/link/http/createSignalIfSupported.d.ts.map +1 -0
  237. package/link/http/createSignalIfSupported.js +8 -0
  238. package/link/http/createSignalIfSupported.js.map +1 -0
  239. package/link/http/http.cjs +593 -0
  240. package/link/http/http.cjs.map +1 -0
  241. package/link/http/http.cjs.native.js +593 -0
  242. package/link/http/index.d.ts +11 -0
  243. package/link/http/index.d.ts.map +1 -0
  244. package/link/http/index.js +11 -0
  245. package/link/http/index.js.map +1 -0
  246. package/link/http/iterators/async.d.ts +2 -0
  247. package/link/http/iterators/async.d.ts.map +1 -0
  248. package/link/http/iterators/async.js +14 -0
  249. package/link/http/iterators/async.js.map +1 -0
  250. package/link/http/iterators/nodeStream.d.ts +4 -0
  251. package/link/http/iterators/nodeStream.d.ts.map +1 -0
  252. package/link/http/iterators/nodeStream.js +71 -0
  253. package/link/http/iterators/nodeStream.js.map +1 -0
  254. package/link/http/iterators/promise.d.ts +2 -0
  255. package/link/http/iterators/promise.d.ts.map +1 -0
  256. package/link/http/iterators/promise.js +28 -0
  257. package/link/http/iterators/promise.js.map +1 -0
  258. package/link/http/iterators/reader.d.ts +2 -0
  259. package/link/http/iterators/reader.d.ts.map +1 -0
  260. package/link/http/iterators/reader.js +15 -0
  261. package/link/http/iterators/reader.js.map +1 -0
  262. package/link/http/package.json +8 -0
  263. package/link/http/parseAndCheckHttpResponse.d.ts +14 -0
  264. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -0
  265. package/link/http/parseAndCheckHttpResponse.js +148 -0
  266. package/link/http/parseAndCheckHttpResponse.js.map +1 -0
  267. package/link/http/responseIterator.d.ts +3 -0
  268. package/link/http/responseIterator.d.ts.map +1 -0
  269. package/link/http/responseIterator.js +23 -0
  270. package/link/http/responseIterator.js.map +1 -0
  271. package/link/http/rewriteURIForGET.d.ts +9 -0
  272. package/link/http/rewriteURIForGET.d.ts.map +1 -0
  273. package/link/http/rewriteURIForGET.js +43 -0
  274. package/link/http/rewriteURIForGET.js.map +1 -0
  275. package/link/http/selectHttpOptionsAndBody.d.ts +57 -0
  276. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -0
  277. package/link/http/selectHttpOptionsAndBody.js +78 -0
  278. package/link/http/selectHttpOptionsAndBody.js.map +1 -0
  279. package/link/http/selectURI.d.ts +3 -0
  280. package/link/http/selectURI.d.ts.map +1 -0
  281. package/link/http/selectURI.js +14 -0
  282. package/link/http/selectURI.js.map +1 -0
  283. package/link/http/serializeFetchParameter.d.ts +6 -0
  284. package/link/http/serializeFetchParameter.d.ts.map +1 -0
  285. package/link/http/serializeFetchParameter.js +14 -0
  286. package/link/http/serializeFetchParameter.js.map +1 -0
  287. package/link/persisted-queries/index.d.ts +31 -0
  288. package/link/persisted-queries/index.d.ts.map +1 -0
  289. package/link/persisted-queries/index.js +170 -0
  290. package/link/persisted-queries/index.js.map +1 -0
  291. package/link/persisted-queries/package.json +8 -0
  292. package/link/persisted-queries/persisted-queries.cjs +174 -0
  293. package/link/persisted-queries/persisted-queries.cjs.map +1 -0
  294. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  295. package/link/retry/delayFunction.d.ts +11 -0
  296. package/link/retry/delayFunction.d.ts.map +1 -0
  297. package/link/retry/delayFunction.js +12 -0
  298. package/link/retry/delayFunction.js.map +1 -0
  299. package/link/retry/index.d.ts +2 -0
  300. package/link/retry/index.d.ts.map +1 -0
  301. package/link/retry/index.js +2 -0
  302. package/link/retry/index.js.map +1 -0
  303. package/link/retry/package.json +8 -0
  304. package/link/retry/retry.cjs +170 -0
  305. package/link/retry/retry.cjs.map +1 -0
  306. package/link/retry/retry.cjs.native.js +170 -0
  307. package/link/retry/retryFunction.d.ts +10 -0
  308. package/link/retry/retryFunction.d.ts.map +1 -0
  309. package/link/retry/retryFunction.js +9 -0
  310. package/link/retry/retryFunction.js.map +1 -0
  311. package/link/retry/retryLink.d.ts +17 -0
  312. package/link/retry/retryLink.d.ts.map +1 -0
  313. package/link/retry/retryLink.js +145 -0
  314. package/link/retry/retryLink.js.map +1 -0
  315. package/link/schema/index.d.ts +22 -0
  316. package/link/schema/index.d.ts.map +1 -0
  317. package/link/schema/index.js +50 -0
  318. package/link/schema/index.js.map +1 -0
  319. package/link/schema/package.json +8 -0
  320. package/link/schema/schema.cjs +56 -0
  321. package/link/schema/schema.cjs.map +1 -0
  322. package/link/schema/schema.cjs.native.js +56 -0
  323. package/link/subscriptions/index.d.ts +9 -0
  324. package/link/subscriptions/index.d.ts.map +1 -0
  325. package/link/subscriptions/index.js +39 -0
  326. package/link/subscriptions/index.js.map +1 -0
  327. package/link/subscriptions/package.json +8 -0
  328. package/link/subscriptions/subscriptions.cjs +45 -0
  329. package/link/subscriptions/subscriptions.cjs.map +1 -0
  330. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  331. package/link/utils/createOperation.d.ts +3 -0
  332. package/link/utils/createOperation.d.ts.map +1 -0
  333. package/link/utils/createOperation.js +23 -0
  334. package/link/utils/createOperation.js.map +1 -0
  335. package/link/utils/fromError.d.ts +3 -0
  336. package/link/utils/fromError.d.ts.map +1 -0
  337. package/link/utils/fromError.js +7 -0
  338. package/link/utils/fromError.js.map +1 -0
  339. package/link/utils/fromPromise.d.ts +3 -0
  340. package/link/utils/fromPromise.d.ts.map +1 -0
  341. package/link/utils/fromPromise.js +12 -0
  342. package/link/utils/fromPromise.js.map +1 -0
  343. package/link/utils/index.d.ts +9 -0
  344. package/link/utils/index.d.ts.map +1 -0
  345. package/link/utils/index.js +9 -0
  346. package/link/utils/index.js.map +1 -0
  347. package/link/utils/package.json +8 -0
  348. package/link/utils/throwServerError.d.ts +7 -0
  349. package/link/utils/throwServerError.d.ts.map +1 -0
  350. package/link/utils/throwServerError.js +9 -0
  351. package/link/utils/throwServerError.js.map +1 -0
  352. package/link/utils/toPromise.d.ts +3 -0
  353. package/link/utils/toPromise.d.ts.map +1 -0
  354. package/link/utils/toPromise.js +19 -0
  355. package/link/utils/toPromise.js.map +1 -0
  356. package/link/utils/transformOperation.d.ts +3 -0
  357. package/link/utils/transformOperation.d.ts.map +1 -0
  358. package/link/utils/transformOperation.js +17 -0
  359. package/link/utils/transformOperation.js.map +1 -0
  360. package/link/utils/utils.cjs +115 -0
  361. package/link/utils/utils.cjs.map +1 -0
  362. package/link/utils/utils.cjs.native.js +115 -0
  363. package/link/utils/validateOperation.d.ts +3 -0
  364. package/link/utils/validateOperation.d.ts.map +1 -0
  365. package/link/utils/validateOperation.js +18 -0
  366. package/link/utils/validateOperation.js.map +1 -0
  367. package/link/ws/index.d.ts +17 -0
  368. package/link/ws/index.d.ts.map +1 -0
  369. package/link/ws/index.js +22 -0
  370. package/link/ws/index.js.map +1 -0
  371. package/link/ws/package.json +8 -0
  372. package/link/ws/ws.cjs +28 -0
  373. package/link/ws/ws.cjs.map +1 -0
  374. package/link/ws/ws.cjs.native.js +28 -0
  375. package/main.cjs +16 -0
  376. package/main.cjs.map +1 -0
  377. package/main.cjs.native.js +16 -0
  378. package/package.json +141 -0
  379. package/react/cache/SuspenseCache.d.ts +18 -0
  380. package/react/cache/SuspenseCache.d.ts.map +1 -0
  381. package/react/cache/SuspenseCache.js +49 -0
  382. package/react/cache/SuspenseCache.js.map +1 -0
  383. package/react/cache/index.d.ts +2 -0
  384. package/react/cache/index.d.ts.map +1 -0
  385. package/react/cache/index.js +2 -0
  386. package/react/cache/index.js.map +1 -0
  387. package/react/components/Mutation.d.ts +12 -0
  388. package/react/components/Mutation.d.ts.map +1 -0
  389. package/react/components/Mutation.js +22 -0
  390. package/react/components/Mutation.js.map +1 -0
  391. package/react/components/Query.d.ts +12 -0
  392. package/react/components/Query.d.ts.map +1 -0
  393. package/react/components/Query.js +23 -0
  394. package/react/components/Query.js.map +1 -0
  395. package/react/components/Subscription.d.ts +12 -0
  396. package/react/components/Subscription.d.ts.map +1 -0
  397. package/react/components/Subscription.js +17 -0
  398. package/react/components/Subscription.js.map +1 -0
  399. package/react/components/components.cjs +81 -0
  400. package/react/components/components.cjs.map +1 -0
  401. package/react/components/components.cjs.native.js +81 -0
  402. package/react/components/index.d.ts +5 -0
  403. package/react/components/index.d.ts.map +1 -0
  404. package/react/components/index.js +5 -0
  405. package/react/components/index.js.map +1 -0
  406. package/react/components/package.json +8 -0
  407. package/react/components/types.d.ts +18 -0
  408. package/react/components/types.d.ts.map +1 -0
  409. package/react/components/types.js +2 -0
  410. package/react/components/types.js.map +1 -0
  411. package/react/context/ApolloConsumer.d.ts +7 -0
  412. package/react/context/ApolloConsumer.d.ts.map +1 -0
  413. package/react/context/ApolloConsumer.js +12 -0
  414. package/react/context/ApolloConsumer.js.map +1 -0
  415. package/react/context/ApolloContext.d.ts +12 -0
  416. package/react/context/ApolloContext.d.ts.map +1 -0
  417. package/react/context/ApolloContext.js +20 -0
  418. package/react/context/ApolloContext.js.map +1 -0
  419. package/react/context/ApolloProvider.d.ts +10 -0
  420. package/react/context/ApolloProvider.d.ts.map +1 -0
  421. package/react/context/ApolloProvider.js +20 -0
  422. package/react/context/ApolloProvider.js.map +1 -0
  423. package/react/context/context.cjs +70 -0
  424. package/react/context/context.cjs.map +1 -0
  425. package/react/context/context.cjs.native.js +70 -0
  426. package/react/context/index.d.ts +5 -0
  427. package/react/context/index.d.ts.map +1 -0
  428. package/react/context/index.js +5 -0
  429. package/react/context/index.js.map +1 -0
  430. package/react/context/package.json +8 -0
  431. package/react/hoc/graphql.d.ts +6 -0
  432. package/react/hoc/graphql.d.ts.map +1 -0
  433. package/react/hoc/graphql.js +17 -0
  434. package/react/hoc/graphql.js.map +1 -0
  435. package/react/hoc/hoc-utils.d.ts +17 -0
  436. package/react/hoc/hoc-utils.d.ts.map +1 -0
  437. package/react/hoc/hoc-utils.js +47 -0
  438. package/react/hoc/hoc-utils.js.map +1 -0
  439. package/react/hoc/hoc.cjs +325 -0
  440. package/react/hoc/hoc.cjs.map +1 -0
  441. package/react/hoc/hoc.cjs.native.js +325 -0
  442. package/react/hoc/index.d.ts +8 -0
  443. package/react/hoc/index.d.ts.map +1 -0
  444. package/react/hoc/index.js +8 -0
  445. package/react/hoc/index.js.map +1 -0
  446. package/react/hoc/mutation-hoc.d.ts +7 -0
  447. package/react/hoc/mutation-hoc.d.ts.map +1 -0
  448. package/react/hoc/mutation-hoc.js +63 -0
  449. package/react/hoc/mutation-hoc.js.map +1 -0
  450. package/react/hoc/package.json +8 -0
  451. package/react/hoc/query-hoc.d.ts +5 -0
  452. package/react/hoc/query-hoc.d.ts.map +1 -0
  453. package/react/hoc/query-hoc.js +70 -0
  454. package/react/hoc/query-hoc.js.map +1 -0
  455. package/react/hoc/subscription-hoc.d.ts +5 -0
  456. package/react/hoc/subscription-hoc.d.ts.map +1 -0
  457. package/react/hoc/subscription-hoc.js +80 -0
  458. package/react/hoc/subscription-hoc.js.map +1 -0
  459. package/react/hoc/types.d.ts +43 -0
  460. package/react/hoc/types.d.ts.map +1 -0
  461. package/react/hoc/types.js +2 -0
  462. package/react/hoc/types.js.map +1 -0
  463. package/react/hoc/withApollo.d.ts +4 -0
  464. package/react/hoc/withApollo.d.ts.map +1 -0
  465. package/react/hoc/withApollo.js +45 -0
  466. package/react/hoc/withApollo.js.map +1 -0
  467. package/react/hooks/compareResults.d.ts +3 -0
  468. package/react/hooks/compareResults.d.ts.map +1 -0
  469. package/react/hooks/compareResults.js +63 -0
  470. package/react/hooks/compareResults.js.map +1 -0
  471. package/react/hooks/hooks.cjs +913 -0
  472. package/react/hooks/hooks.cjs.map +1 -0
  473. package/react/hooks/hooks.cjs.native.js +913 -0
  474. package/react/hooks/index.d.ts +10 -0
  475. package/react/hooks/index.d.ts.map +1 -0
  476. package/react/hooks/index.js +10 -0
  477. package/react/hooks/index.js.map +1 -0
  478. package/react/hooks/internal/index.d.ts +3 -0
  479. package/react/hooks/internal/index.d.ts.map +1 -0
  480. package/react/hooks/internal/index.js +3 -0
  481. package/react/hooks/internal/index.js.map +1 -0
  482. package/react/hooks/internal/useDeepMemo.d.ts +3 -0
  483. package/react/hooks/internal/useDeepMemo.d.ts.map +1 -0
  484. package/react/hooks/internal/useDeepMemo.js +10 -0
  485. package/react/hooks/internal/useDeepMemo.js.map +1 -0
  486. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts +3 -0
  487. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -0
  488. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -0
  489. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -0
  490. package/react/hooks/package.json +8 -0
  491. package/react/hooks/useApolloClient.d.ts +3 -0
  492. package/react/hooks/useApolloClient.d.ts.map +1 -0
  493. package/react/hooks/useApolloClient.js +12 -0
  494. package/react/hooks/useApolloClient.js.map +1 -0
  495. package/react/hooks/useFragment.d.ts +13 -0
  496. package/react/hooks/useFragment.d.ts.map +1 -0
  497. package/react/hooks/useFragment.js +39 -0
  498. package/react/hooks/useFragment.js.map +1 -0
  499. package/react/hooks/useLazyQuery.d.ts +6 -0
  500. package/react/hooks/useLazyQuery.d.ts.map +1 -0
  501. package/react/hooks/useLazyQuery.js +71 -0
  502. package/react/hooks/useLazyQuery.js.map +1 -0
  503. package/react/hooks/useMutation.d.ts +6 -0
  504. package/react/hooks/useMutation.d.ts.map +1 -0
  505. package/react/hooks/useMutation.js +100 -0
  506. package/react/hooks/useMutation.js.map +1 -0
  507. package/react/hooks/useQuery.d.ts +41 -0
  508. package/react/hooks/useQuery.d.ts.map +1 -0
  509. package/react/hooks/useQuery.js +302 -0
  510. package/react/hooks/useQuery.js.map +1 -0
  511. package/react/hooks/useReactiveVar.d.ts +3 -0
  512. package/react/hooks/useReactiveVar.d.ts.map +1 -0
  513. package/react/hooks/useReactiveVar.js +16 -0
  514. package/react/hooks/useReactiveVar.js.map +1 -0
  515. package/react/hooks/useSubscription.d.ts +6 -0
  516. package/react/hooks/useSubscription.d.ts.map +1 -0
  517. package/react/hooks/useSubscription.js +141 -0
  518. package/react/hooks/useSubscription.js.map +1 -0
  519. package/react/hooks/useSuspenseCache.d.ts +2 -0
  520. package/react/hooks/useSuspenseCache.d.ts.map +1 -0
  521. package/react/hooks/useSuspenseCache.js +10 -0
  522. package/react/hooks/useSuspenseCache.js.map +1 -0
  523. package/react/hooks/useSuspenseQuery.d.ts +12 -0
  524. package/react/hooks/useSuspenseQuery.d.ts.map +1 -0
  525. package/react/hooks/useSuspenseQuery.js +181 -0
  526. package/react/hooks/useSuspenseQuery.js.map +1 -0
  527. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  528. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  529. package/react/hooks/useSyncExternalStore.js +48 -0
  530. package/react/hooks/useSyncExternalStore.js.map +1 -0
  531. package/react/index.d.ts +7 -0
  532. package/react/index.d.ts.map +1 -0
  533. package/react/index.js +7 -0
  534. package/react/index.js.map +1 -0
  535. package/react/package.json +8 -0
  536. package/react/parser/index.d.ts +15 -0
  537. package/react/parser/index.d.ts.map +1 -0
  538. package/react/parser/index.js +94 -0
  539. package/react/parser/index.js.map +1 -0
  540. package/react/parser/package.json +8 -0
  541. package/react/parser/parser.cjs +103 -0
  542. package/react/parser/parser.cjs.map +1 -0
  543. package/react/parser/parser.cjs.native.js +103 -0
  544. package/react/react.cjs +69 -0
  545. package/react/react.cjs.map +1 -0
  546. package/react/react.cjs.native.js +69 -0
  547. package/react/ssr/RenderPromises.d.ts +22 -0
  548. package/react/ssr/RenderPromises.d.ts.map +1 -0
  549. package/react/ssr/RenderPromises.js +90 -0
  550. package/react/ssr/RenderPromises.js.map +1 -0
  551. package/react/ssr/getDataFromTree.d.ts +13 -0
  552. package/react/ssr/getDataFromTree.d.ts.map +1 -0
  553. package/react/ssr/getDataFromTree.js +32 -0
  554. package/react/ssr/getDataFromTree.js.map +1 -0
  555. package/react/ssr/index.d.ts +4 -0
  556. package/react/ssr/index.d.ts.map +1 -0
  557. package/react/ssr/index.js +4 -0
  558. package/react/ssr/index.js.map +1 -0
  559. package/react/ssr/package.json +8 -0
  560. package/react/ssr/renderToStringWithData.d.ts +3 -0
  561. package/react/ssr/renderToStringWithData.d.ts.map +1 -0
  562. package/react/ssr/renderToStringWithData.js +9 -0
  563. package/react/ssr/renderToStringWithData.js.map +1 -0
  564. package/react/ssr/ssr.cjs +151 -0
  565. package/react/ssr/ssr.cjs.map +1 -0
  566. package/react/ssr/ssr.cjs.native.js +151 -0
  567. package/react/types/types.d.ts +130 -0
  568. package/react/types/types.d.ts.map +1 -0
  569. package/react/types/types.js +2 -0
  570. package/react/types/types.js.map +1 -0
  571. package/testing/core/core.cjs +315 -0
  572. package/testing/core/core.cjs.map +1 -0
  573. package/testing/core/core.cjs.native.js +315 -0
  574. package/testing/core/index.d.ts +8 -0
  575. package/testing/core/index.d.ts.map +1 -0
  576. package/testing/core/index.js +8 -0
  577. package/testing/core/index.js.map +1 -0
  578. package/testing/core/itAsync.d.ts +6 -0
  579. package/testing/core/itAsync.d.ts.map +1 -0
  580. package/testing/core/itAsync.js +19 -0
  581. package/testing/core/itAsync.js.map +1 -0
  582. package/testing/core/mocking/mockClient.d.ts +5 -0
  583. package/testing/core/mocking/mockClient.d.ts.map +1 -0
  584. package/testing/core/mocking/mockClient.js +14 -0
  585. package/testing/core/mocking/mockClient.js.map +1 -0
  586. package/testing/core/mocking/mockFetch.d.ts +24 -0
  587. package/testing/core/mocking/mockFetch.d.ts.map +1 -0
  588. package/testing/core/mocking/mockFetch.js +83 -0
  589. package/testing/core/mocking/mockFetch.js.map +1 -0
  590. package/testing/core/mocking/mockLink.d.ts +28 -0
  591. package/testing/core/mocking/mockLink.d.ts.map +1 -0
  592. package/testing/core/mocking/mockLink.js +139 -0
  593. package/testing/core/mocking/mockLink.js.map +1 -0
  594. package/testing/core/mocking/mockQueryManager.d.ts +5 -0
  595. package/testing/core/mocking/mockQueryManager.d.ts.map +1 -0
  596. package/testing/core/mocking/mockQueryManager.js +14 -0
  597. package/testing/core/mocking/mockQueryManager.js.map +1 -0
  598. package/testing/core/mocking/mockSubscriptionLink.d.ts +24 -0
  599. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -0
  600. package/testing/core/mocking/mockSubscriptionLink.js +62 -0
  601. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -0
  602. package/testing/core/mocking/mockWatchQuery.d.ts +5 -0
  603. package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -0
  604. package/testing/core/mocking/mockWatchQuery.js +15 -0
  605. package/testing/core/mocking/mockWatchQuery.js.map +1 -0
  606. package/testing/core/observableToPromise.d.ts +15 -0
  607. package/testing/core/observableToPromise.d.ts.map +1 -0
  608. package/testing/core/observableToPromise.js +65 -0
  609. package/testing/core/observableToPromise.js.map +1 -0
  610. package/testing/core/package.json +8 -0
  611. package/testing/core/subscribeAndCount.d.ts +3 -0
  612. package/testing/core/subscribeAndCount.d.ts.map +1 -0
  613. package/testing/core/subscribeAndCount.js +16 -0
  614. package/testing/core/subscribeAndCount.js.map +1 -0
  615. package/testing/core/wait.d.ts +3 -0
  616. package/testing/core/wait.d.ts.map +1 -0
  617. package/testing/core/wait.js +16 -0
  618. package/testing/core/wait.js.map +1 -0
  619. package/testing/core/withConsoleSpy.d.ts +4 -0
  620. package/testing/core/withConsoleSpy.d.ts.map +1 -0
  621. package/testing/core/withConsoleSpy.js +39 -0
  622. package/testing/core/withConsoleSpy.js.map +1 -0
  623. package/testing/core/wrap.d.ts +4 -0
  624. package/testing/core/wrap.d.ts.map +1 -0
  625. package/testing/core/wrap.js +26 -0
  626. package/testing/core/wrap.js.map +1 -0
  627. package/testing/index.d.ts +4 -0
  628. package/testing/index.d.ts.map +1 -0
  629. package/testing/index.js +4 -0
  630. package/testing/index.js.map +1 -0
  631. package/testing/package.json +8 -0
  632. package/testing/react/MockedProvider.d.ts +30 -0
  633. package/testing/react/MockedProvider.d.ts.map +1 -0
  634. package/testing/react/MockedProvider.js +39 -0
  635. package/testing/react/MockedProvider.js.map +1 -0
  636. package/testing/testing.cjs +109 -0
  637. package/testing/testing.cjs.map +1 -0
  638. package/testing/testing.cjs.native.js +109 -0
  639. package/utilities/common/arrays.d.ts +2 -0
  640. package/utilities/common/arrays.d.ts.map +1 -0
  641. package/utilities/common/arrays.js +4 -0
  642. package/utilities/common/arrays.js.map +1 -0
  643. package/utilities/common/canUse.d.ts +7 -0
  644. package/utilities/common/canUse.d.ts.map +1 -0
  645. package/utilities/common/canUse.js +11 -0
  646. package/utilities/common/canUse.js.map +1 -0
  647. package/utilities/common/cloneDeep.d.ts +2 -0
  648. package/utilities/common/cloneDeep.d.ts.map +1 -0
  649. package/utilities/common/cloneDeep.js +33 -0
  650. package/utilities/common/cloneDeep.js.map +1 -0
  651. package/utilities/common/compact.d.ts +3 -0
  652. package/utilities/common/compact.d.ts.map +1 -0
  653. package/utilities/common/compact.js +19 -0
  654. package/utilities/common/compact.js.map +1 -0
  655. package/utilities/common/errorHandling.d.ts +4 -0
  656. package/utilities/common/errorHandling.d.ts.map +1 -0
  657. package/utilities/common/errorHandling.js +21 -0
  658. package/utilities/common/errorHandling.js.map +1 -0
  659. package/utilities/common/filterInPlace.d.ts +2 -0
  660. package/utilities/common/filterInPlace.d.ts.map +1 -0
  661. package/utilities/common/filterInPlace.js +11 -0
  662. package/utilities/common/filterInPlace.js.map +1 -0
  663. package/utilities/common/incrementalResult.d.ts +6 -0
  664. package/utilities/common/incrementalResult.d.ts.map +1 -0
  665. package/utilities/common/incrementalResult.js +32 -0
  666. package/utilities/common/incrementalResult.js.map +1 -0
  667. package/utilities/common/makeUniqueId.d.ts +2 -0
  668. package/utilities/common/makeUniqueId.d.ts.map +1 -0
  669. package/utilities/common/makeUniqueId.js +7 -0
  670. package/utilities/common/makeUniqueId.js.map +1 -0
  671. package/utilities/common/maybeDeepFreeze.d.ts +2 -0
  672. package/utilities/common/maybeDeepFreeze.d.ts.map +1 -0
  673. package/utilities/common/maybeDeepFreeze.js +34 -0
  674. package/utilities/common/maybeDeepFreeze.js.map +1 -0
  675. package/utilities/common/mergeDeep.d.ts +14 -0
  676. package/utilities/common/mergeDeep.d.ts.map +1 -0
  677. package/utilities/common/mergeDeep.js +76 -0
  678. package/utilities/common/mergeDeep.js.map +1 -0
  679. package/utilities/common/mergeOptions.d.ts +5 -0
  680. package/utilities/common/mergeOptions.d.ts.map +1 -0
  681. package/utilities/common/mergeOptions.js +8 -0
  682. package/utilities/common/mergeOptions.js.map +1 -0
  683. package/utilities/common/objects.d.ts +2 -0
  684. package/utilities/common/objects.d.ts.map +1 -0
  685. package/utilities/common/objects.js +4 -0
  686. package/utilities/common/objects.js.map +1 -0
  687. package/utilities/common/responseIterator.d.ts +10 -0
  688. package/utilities/common/responseIterator.d.ts.map +1 -0
  689. package/utilities/common/responseIterator.js +21 -0
  690. package/utilities/common/responseIterator.js.map +1 -0
  691. package/utilities/common/stringifyForDisplay.d.ts +2 -0
  692. package/utilities/common/stringifyForDisplay.d.ts.map +1 -0
  693. package/utilities/common/stringifyForDisplay.js +8 -0
  694. package/utilities/common/stringifyForDisplay.js.map +1 -0
  695. package/utilities/globals/DEV.d.ts +3 -0
  696. package/utilities/globals/DEV.d.ts.map +1 -0
  697. package/utilities/globals/DEV.js +9 -0
  698. package/utilities/globals/DEV.js.map +1 -0
  699. package/utilities/globals/fix-graphql.d.ts +2 -0
  700. package/utilities/globals/fix-graphql.d.ts.map +1 -0
  701. package/utilities/globals/fix-graphql.js +6 -0
  702. package/utilities/globals/fix-graphql.js.map +1 -0
  703. package/utilities/globals/global.d.ts +5 -0
  704. package/utilities/globals/global.d.ts.map +1 -0
  705. package/utilities/globals/global.js +6 -0
  706. package/utilities/globals/global.js.map +1 -0
  707. package/utilities/globals/globals.cjs +42 -0
  708. package/utilities/globals/globals.cjs.map +1 -0
  709. package/utilities/globals/globals.cjs.native.js +42 -0
  710. package/utilities/globals/index.d.ts +8 -0
  711. package/utilities/globals/index.d.ts.map +1 -0
  712. package/utilities/globals/index.js +10 -0
  713. package/utilities/globals/index.js.map +1 -0
  714. package/utilities/globals/maybe.d.ts +2 -0
  715. package/utilities/globals/maybe.d.ts.map +1 -0
  716. package/utilities/globals/maybe.js +7 -0
  717. package/utilities/globals/maybe.js.map +1 -0
  718. package/utilities/globals/package.json +8 -0
  719. package/utilities/graphql/directives.d.ts +18 -0
  720. package/utilities/graphql/directives.d.ts.map +1 -0
  721. package/utilities/graphql/directives.js +72 -0
  722. package/utilities/graphql/directives.js.map +1 -0
  723. package/utilities/graphql/fragments.d.ts +9 -0
  724. package/utilities/graphql/fragments.d.ts.map +1 -0
  725. package/utilities/graphql/fragments.js +64 -0
  726. package/utilities/graphql/fragments.js.map +1 -0
  727. package/utilities/graphql/getFromAST.d.ts +10 -0
  728. package/utilities/graphql/getFromAST.d.ts.map +1 -0
  729. package/utilities/graphql/getFromAST.js +76 -0
  730. package/utilities/graphql/getFromAST.js.map +1 -0
  731. package/utilities/graphql/storeUtils.d.ts +32 -0
  732. package/utilities/graphql/storeUtils.d.ts.map +1 -0
  733. package/utilities/graphql/storeUtils.js +208 -0
  734. package/utilities/graphql/storeUtils.js.map +1 -0
  735. package/utilities/graphql/transform.d.ts +27 -0
  736. package/utilities/graphql/transform.d.ts.map +1 -0
  737. package/utilities/graphql/transform.js +281 -0
  738. package/utilities/graphql/transform.js.map +1 -0
  739. package/utilities/index.d.ts +27 -0
  740. package/utilities/index.d.ts.map +1 -0
  741. package/utilities/index.js +27 -0
  742. package/utilities/index.js.map +1 -0
  743. package/utilities/observables/Concast.d.ts +27 -0
  744. package/utilities/observables/Concast.d.ts.map +1 -0
  745. package/utilities/observables/Concast.js +137 -0
  746. package/utilities/observables/Concast.js.map +1 -0
  747. package/utilities/observables/Observable.d.ts +5 -0
  748. package/utilities/observables/Observable.d.ts.map +1 -0
  749. package/utilities/observables/Observable.js +9 -0
  750. package/utilities/observables/Observable.js.map +1 -0
  751. package/utilities/observables/asyncMap.d.ts +3 -0
  752. package/utilities/observables/asyncMap.d.ts.map +1 -0
  753. package/utilities/observables/asyncMap.js +49 -0
  754. package/utilities/observables/asyncMap.js.map +1 -0
  755. package/utilities/observables/iteration.d.ts +3 -0
  756. package/utilities/observables/iteration.d.ts.map +1 -0
  757. package/utilities/observables/iteration.js +6 -0
  758. package/utilities/observables/iteration.js.map +1 -0
  759. package/utilities/observables/subclassing.d.ts +3 -0
  760. package/utilities/observables/subclassing.d.ts.map +1 -0
  761. package/utilities/observables/subclassing.js +13 -0
  762. package/utilities/observables/subclassing.js.map +1 -0
  763. package/utilities/package.json +8 -0
  764. package/utilities/policies/pagination.d.ts +28 -0
  765. package/utilities/policies/pagination.d.ts.map +1 -0
  766. package/utilities/policies/pagination.js +151 -0
  767. package/utilities/policies/pagination.js.map +1 -0
  768. package/utilities/types/IsStrictlyAny.d.ts +5 -0
  769. package/utilities/types/IsStrictlyAny.d.ts.map +1 -0
  770. package/utilities/types/IsStrictlyAny.js +2 -0
  771. package/utilities/types/IsStrictlyAny.js.map +1 -0
  772. package/utilities/utilities.cjs +1371 -0
  773. package/utilities/utilities.cjs.map +1 -0
  774. package/utilities/utilities.cjs.native.js +1371 -0
  775. package/version.d.ts +2 -0
  776. package/version.d.ts.map +1 -0
  777. package/version.js +2 -0
  778. package/version.js.map +1 -0
@@ -0,0 +1,2425 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var globals = require('../utilities/globals');
6
+ var tslib = require('tslib');
7
+ var optimism = require('optimism');
8
+ var utilities = require('../utilities');
9
+ var equality = require('@wry/equality');
10
+ var trie = require('@wry/trie');
11
+ var graphql = require('graphql');
12
+ var context = require('@wry/context');
13
+
14
+ var ApolloCache = (function () {
15
+ function ApolloCache() {
16
+ this.getFragmentDoc = optimism.wrap(utilities.getFragmentQueryDocument);
17
+ }
18
+ ApolloCache.prototype.batch = function (options) {
19
+ var _this = this;
20
+ var optimisticId = typeof options.optimistic === "string" ? options.optimistic :
21
+ options.optimistic === false ? null : void 0;
22
+ var updateResult;
23
+ this.performTransaction(function () { return updateResult = options.update(_this); }, optimisticId);
24
+ return updateResult;
25
+ };
26
+ ApolloCache.prototype.recordOptimisticTransaction = function (transaction, optimisticId) {
27
+ this.performTransaction(transaction, optimisticId);
28
+ };
29
+ ApolloCache.prototype.transformDocument = function (document) {
30
+ return document;
31
+ };
32
+ ApolloCache.prototype.transformForLink = function (document) {
33
+ return document;
34
+ };
35
+ ApolloCache.prototype.identify = function (object) {
36
+ return;
37
+ };
38
+ ApolloCache.prototype.gc = function () {
39
+ return [];
40
+ };
41
+ ApolloCache.prototype.modify = function (options) {
42
+ return false;
43
+ };
44
+ ApolloCache.prototype.readQuery = function (options, optimistic) {
45
+ if (optimistic === void 0) { optimistic = !!options.optimistic; }
46
+ return this.read(tslib.__assign(tslib.__assign({}, options), { rootId: options.id || 'ROOT_QUERY', optimistic: optimistic }));
47
+ };
48
+ ApolloCache.prototype.readFragment = function (options, optimistic) {
49
+ if (optimistic === void 0) { optimistic = !!options.optimistic; }
50
+ return this.read(tslib.__assign(tslib.__assign({}, options), { query: this.getFragmentDoc(options.fragment, options.fragmentName), rootId: options.id, optimistic: optimistic }));
51
+ };
52
+ ApolloCache.prototype.writeQuery = function (_a) {
53
+ var id = _a.id, data = _a.data, options = tslib.__rest(_a, ["id", "data"]);
54
+ return this.write(Object.assign(options, {
55
+ dataId: id || 'ROOT_QUERY',
56
+ result: data,
57
+ }));
58
+ };
59
+ ApolloCache.prototype.writeFragment = function (_a) {
60
+ var id = _a.id, data = _a.data, fragment = _a.fragment, fragmentName = _a.fragmentName, options = tslib.__rest(_a, ["id", "data", "fragment", "fragmentName"]);
61
+ return this.write(Object.assign(options, {
62
+ query: this.getFragmentDoc(fragment, fragmentName),
63
+ dataId: id,
64
+ result: data,
65
+ }));
66
+ };
67
+ ApolloCache.prototype.updateQuery = function (options, update) {
68
+ return this.batch({
69
+ update: function (cache) {
70
+ var value = cache.readQuery(options);
71
+ var data = update(value);
72
+ if (data === void 0 || data === null)
73
+ return value;
74
+ cache.writeQuery(tslib.__assign(tslib.__assign({}, options), { data: data }));
75
+ return data;
76
+ },
77
+ });
78
+ };
79
+ ApolloCache.prototype.updateFragment = function (options, update) {
80
+ return this.batch({
81
+ update: function (cache) {
82
+ var value = cache.readFragment(options);
83
+ var data = update(value);
84
+ if (data === void 0 || data === null)
85
+ return value;
86
+ cache.writeFragment(tslib.__assign(tslib.__assign({}, options), { data: data }));
87
+ return data;
88
+ },
89
+ });
90
+ };
91
+ return ApolloCache;
92
+ }());
93
+
94
+ exports.Cache = void 0;
95
+ (function (Cache) {
96
+ })(exports.Cache || (exports.Cache = {}));
97
+
98
+ var MissingFieldError = (function (_super) {
99
+ tslib.__extends(MissingFieldError, _super);
100
+ function MissingFieldError(message, path, query, variables) {
101
+ var _a;
102
+ var _this = _super.call(this, message) || this;
103
+ _this.message = message;
104
+ _this.path = path;
105
+ _this.query = query;
106
+ _this.variables = variables;
107
+ if (Array.isArray(_this.path)) {
108
+ _this.missing = _this.message;
109
+ for (var i = _this.path.length - 1; i >= 0; --i) {
110
+ _this.missing = (_a = {}, _a[_this.path[i]] = _this.missing, _a);
111
+ }
112
+ }
113
+ else {
114
+ _this.missing = _this.path;
115
+ }
116
+ _this.__proto__ = MissingFieldError.prototype;
117
+ return _this;
118
+ }
119
+ return MissingFieldError;
120
+ }(Error));
121
+
122
+ var hasOwn = Object.prototype.hasOwnProperty;
123
+ function isNullish(value) {
124
+ return value === null || value === void 0;
125
+ }
126
+ var isArray = Array.isArray;
127
+ function defaultDataIdFromObject(_a, context) {
128
+ var __typename = _a.__typename, id = _a.id, _id = _a._id;
129
+ if (typeof __typename === "string") {
130
+ if (context) {
131
+ context.keyObject =
132
+ !isNullish(id) ? { id: id } :
133
+ !isNullish(_id) ? { _id: _id } :
134
+ void 0;
135
+ }
136
+ if (isNullish(id) && !isNullish(_id)) {
137
+ id = _id;
138
+ }
139
+ if (!isNullish(id)) {
140
+ return "".concat(__typename, ":").concat((typeof id === "number" ||
141
+ typeof id === "string") ? id : JSON.stringify(id));
142
+ }
143
+ }
144
+ }
145
+ var defaultConfig = {
146
+ dataIdFromObject: defaultDataIdFromObject,
147
+ addTypename: true,
148
+ resultCaching: true,
149
+ canonizeResults: false,
150
+ };
151
+ function normalizeConfig(config) {
152
+ return utilities.compact(defaultConfig, config);
153
+ }
154
+ function shouldCanonizeResults(config) {
155
+ var value = config.canonizeResults;
156
+ return value === void 0 ? defaultConfig.canonizeResults : value;
157
+ }
158
+ function getTypenameFromStoreObject(store, objectOrReference) {
159
+ return utilities.isReference(objectOrReference)
160
+ ? store.get(objectOrReference.__ref, "__typename")
161
+ : objectOrReference && objectOrReference.__typename;
162
+ }
163
+ var TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i;
164
+ function fieldNameFromStoreName(storeFieldName) {
165
+ var match = storeFieldName.match(TypeOrFieldNameRegExp);
166
+ return match ? match[0] : storeFieldName;
167
+ }
168
+ function selectionSetMatchesResult(selectionSet, result, variables) {
169
+ if (utilities.isNonNullObject(result)) {
170
+ return isArray(result)
171
+ ? result.every(function (item) { return selectionSetMatchesResult(selectionSet, item, variables); })
172
+ : selectionSet.selections.every(function (field) {
173
+ if (utilities.isField(field) && utilities.shouldInclude(field, variables)) {
174
+ var key = utilities.resultKeyNameFromField(field);
175
+ return hasOwn.call(result, key) &&
176
+ (!field.selectionSet ||
177
+ selectionSetMatchesResult(field.selectionSet, result[key], variables));
178
+ }
179
+ return true;
180
+ });
181
+ }
182
+ return false;
183
+ }
184
+ function storeValueIsStoreObject(value) {
185
+ return utilities.isNonNullObject(value) &&
186
+ !utilities.isReference(value) &&
187
+ !isArray(value);
188
+ }
189
+ function makeProcessedFieldsMerger() {
190
+ return new utilities.DeepMerger;
191
+ }
192
+ function extractFragmentContext(document, fragments) {
193
+ var fragmentMap = utilities.createFragmentMap(utilities.getFragmentDefinitions(document));
194
+ return {
195
+ fragmentMap: fragmentMap,
196
+ lookupFragment: function (name) {
197
+ var def = fragmentMap[name];
198
+ if (!def && fragments) {
199
+ def = fragments.lookup(name);
200
+ }
201
+ return def || null;
202
+ },
203
+ };
204
+ }
205
+
206
+ var DELETE = Object.create(null);
207
+ var delModifier = function () { return DELETE; };
208
+ var INVALIDATE = Object.create(null);
209
+ exports.EntityStore = (function () {
210
+ function EntityStore(policies, group) {
211
+ var _this = this;
212
+ this.policies = policies;
213
+ this.group = group;
214
+ this.data = Object.create(null);
215
+ this.rootIds = Object.create(null);
216
+ this.refs = Object.create(null);
217
+ this.getFieldValue = function (objectOrReference, storeFieldName) { return utilities.maybeDeepFreeze(utilities.isReference(objectOrReference)
218
+ ? _this.get(objectOrReference.__ref, storeFieldName)
219
+ : objectOrReference && objectOrReference[storeFieldName]); };
220
+ this.canRead = function (objOrRef) {
221
+ return utilities.isReference(objOrRef)
222
+ ? _this.has(objOrRef.__ref)
223
+ : typeof objOrRef === "object";
224
+ };
225
+ this.toReference = function (objOrIdOrRef, mergeIntoStore) {
226
+ if (typeof objOrIdOrRef === "string") {
227
+ return utilities.makeReference(objOrIdOrRef);
228
+ }
229
+ if (utilities.isReference(objOrIdOrRef)) {
230
+ return objOrIdOrRef;
231
+ }
232
+ var id = _this.policies.identify(objOrIdOrRef)[0];
233
+ if (id) {
234
+ var ref = utilities.makeReference(id);
235
+ if (mergeIntoStore) {
236
+ _this.merge(id, objOrIdOrRef);
237
+ }
238
+ return ref;
239
+ }
240
+ };
241
+ }
242
+ EntityStore.prototype.toObject = function () {
243
+ return tslib.__assign({}, this.data);
244
+ };
245
+ EntityStore.prototype.has = function (dataId) {
246
+ return this.lookup(dataId, true) !== void 0;
247
+ };
248
+ EntityStore.prototype.get = function (dataId, fieldName) {
249
+ this.group.depend(dataId, fieldName);
250
+ if (hasOwn.call(this.data, dataId)) {
251
+ var storeObject = this.data[dataId];
252
+ if (storeObject && hasOwn.call(storeObject, fieldName)) {
253
+ return storeObject[fieldName];
254
+ }
255
+ }
256
+ if (fieldName === "__typename" &&
257
+ hasOwn.call(this.policies.rootTypenamesById, dataId)) {
258
+ return this.policies.rootTypenamesById[dataId];
259
+ }
260
+ if (this instanceof Layer) {
261
+ return this.parent.get(dataId, fieldName);
262
+ }
263
+ };
264
+ EntityStore.prototype.lookup = function (dataId, dependOnExistence) {
265
+ if (dependOnExistence)
266
+ this.group.depend(dataId, "__exists");
267
+ if (hasOwn.call(this.data, dataId)) {
268
+ return this.data[dataId];
269
+ }
270
+ if (this instanceof Layer) {
271
+ return this.parent.lookup(dataId, dependOnExistence);
272
+ }
273
+ if (this.policies.rootTypenamesById[dataId]) {
274
+ return Object.create(null);
275
+ }
276
+ };
277
+ EntityStore.prototype.merge = function (older, newer) {
278
+ var _this = this;
279
+ var dataId;
280
+ if (utilities.isReference(older))
281
+ older = older.__ref;
282
+ if (utilities.isReference(newer))
283
+ newer = newer.__ref;
284
+ var existing = typeof older === "string"
285
+ ? this.lookup(dataId = older)
286
+ : older;
287
+ var incoming = typeof newer === "string"
288
+ ? this.lookup(dataId = newer)
289
+ : newer;
290
+ if (!incoming)
291
+ return;
292
+ globals.__DEV__ ? globals.invariant(typeof dataId === "string", "store.merge expects a string ID") : globals.invariant(typeof dataId === "string", 1);
293
+ var merged = new utilities.DeepMerger(storeObjectReconciler).merge(existing, incoming);
294
+ this.data[dataId] = merged;
295
+ if (merged !== existing) {
296
+ delete this.refs[dataId];
297
+ if (this.group.caching) {
298
+ var fieldsToDirty_1 = Object.create(null);
299
+ if (!existing)
300
+ fieldsToDirty_1.__exists = 1;
301
+ Object.keys(incoming).forEach(function (storeFieldName) {
302
+ if (!existing || existing[storeFieldName] !== merged[storeFieldName]) {
303
+ fieldsToDirty_1[storeFieldName] = 1;
304
+ var fieldName = fieldNameFromStoreName(storeFieldName);
305
+ if (fieldName !== storeFieldName &&
306
+ !_this.policies.hasKeyArgs(merged.__typename, fieldName)) {
307
+ fieldsToDirty_1[fieldName] = 1;
308
+ }
309
+ if (merged[storeFieldName] === void 0 && !(_this instanceof Layer)) {
310
+ delete merged[storeFieldName];
311
+ }
312
+ }
313
+ });
314
+ if (fieldsToDirty_1.__typename &&
315
+ !(existing && existing.__typename) &&
316
+ this.policies.rootTypenamesById[dataId] === merged.__typename) {
317
+ delete fieldsToDirty_1.__typename;
318
+ }
319
+ Object.keys(fieldsToDirty_1).forEach(function (fieldName) { return _this.group.dirty(dataId, fieldName); });
320
+ }
321
+ }
322
+ };
323
+ EntityStore.prototype.modify = function (dataId, fields) {
324
+ var _this = this;
325
+ var storeObject = this.lookup(dataId);
326
+ if (storeObject) {
327
+ var changedFields_1 = Object.create(null);
328
+ var needToMerge_1 = false;
329
+ var allDeleted_1 = true;
330
+ var sharedDetails_1 = {
331
+ DELETE: DELETE,
332
+ INVALIDATE: INVALIDATE,
333
+ isReference: utilities.isReference,
334
+ toReference: this.toReference,
335
+ canRead: this.canRead,
336
+ readField: function (fieldNameOrOptions, from) { return _this.policies.readField(typeof fieldNameOrOptions === "string" ? {
337
+ fieldName: fieldNameOrOptions,
338
+ from: from || utilities.makeReference(dataId),
339
+ } : fieldNameOrOptions, { store: _this }); },
340
+ };
341
+ Object.keys(storeObject).forEach(function (storeFieldName) {
342
+ var fieldName = fieldNameFromStoreName(storeFieldName);
343
+ var fieldValue = storeObject[storeFieldName];
344
+ if (fieldValue === void 0)
345
+ return;
346
+ var modify = typeof fields === "function"
347
+ ? fields
348
+ : fields[storeFieldName] || fields[fieldName];
349
+ if (modify) {
350
+ var newValue = modify === delModifier ? DELETE :
351
+ modify(utilities.maybeDeepFreeze(fieldValue), tslib.__assign(tslib.__assign({}, sharedDetails_1), { fieldName: fieldName, storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) }));
352
+ if (newValue === INVALIDATE) {
353
+ _this.group.dirty(dataId, storeFieldName);
354
+ }
355
+ else {
356
+ if (newValue === DELETE)
357
+ newValue = void 0;
358
+ if (newValue !== fieldValue) {
359
+ changedFields_1[storeFieldName] = newValue;
360
+ needToMerge_1 = true;
361
+ fieldValue = newValue;
362
+ }
363
+ }
364
+ }
365
+ if (fieldValue !== void 0) {
366
+ allDeleted_1 = false;
367
+ }
368
+ });
369
+ if (needToMerge_1) {
370
+ this.merge(dataId, changedFields_1);
371
+ if (allDeleted_1) {
372
+ if (this instanceof Layer) {
373
+ this.data[dataId] = void 0;
374
+ }
375
+ else {
376
+ delete this.data[dataId];
377
+ }
378
+ this.group.dirty(dataId, "__exists");
379
+ }
380
+ return true;
381
+ }
382
+ }
383
+ return false;
384
+ };
385
+ EntityStore.prototype.delete = function (dataId, fieldName, args) {
386
+ var _a;
387
+ var storeObject = this.lookup(dataId);
388
+ if (storeObject) {
389
+ var typename = this.getFieldValue(storeObject, "__typename");
390
+ var storeFieldName = fieldName && args
391
+ ? this.policies.getStoreFieldName({ typename: typename, fieldName: fieldName, args: args })
392
+ : fieldName;
393
+ return this.modify(dataId, storeFieldName ? (_a = {},
394
+ _a[storeFieldName] = delModifier,
395
+ _a) : delModifier);
396
+ }
397
+ return false;
398
+ };
399
+ EntityStore.prototype.evict = function (options, limit) {
400
+ var evicted = false;
401
+ if (options.id) {
402
+ if (hasOwn.call(this.data, options.id)) {
403
+ evicted = this.delete(options.id, options.fieldName, options.args);
404
+ }
405
+ if (this instanceof Layer && this !== limit) {
406
+ evicted = this.parent.evict(options, limit) || evicted;
407
+ }
408
+ if (options.fieldName || evicted) {
409
+ this.group.dirty(options.id, options.fieldName || "__exists");
410
+ }
411
+ }
412
+ return evicted;
413
+ };
414
+ EntityStore.prototype.clear = function () {
415
+ this.replace(null);
416
+ };
417
+ EntityStore.prototype.extract = function () {
418
+ var _this = this;
419
+ var obj = this.toObject();
420
+ var extraRootIds = [];
421
+ this.getRootIdSet().forEach(function (id) {
422
+ if (!hasOwn.call(_this.policies.rootTypenamesById, id)) {
423
+ extraRootIds.push(id);
424
+ }
425
+ });
426
+ if (extraRootIds.length) {
427
+ obj.__META = { extraRootIds: extraRootIds.sort() };
428
+ }
429
+ return obj;
430
+ };
431
+ EntityStore.prototype.replace = function (newData) {
432
+ var _this = this;
433
+ Object.keys(this.data).forEach(function (dataId) {
434
+ if (!(newData && hasOwn.call(newData, dataId))) {
435
+ _this.delete(dataId);
436
+ }
437
+ });
438
+ if (newData) {
439
+ var __META = newData.__META, rest_1 = tslib.__rest(newData, ["__META"]);
440
+ Object.keys(rest_1).forEach(function (dataId) {
441
+ _this.merge(dataId, rest_1[dataId]);
442
+ });
443
+ if (__META) {
444
+ __META.extraRootIds.forEach(this.retain, this);
445
+ }
446
+ }
447
+ };
448
+ EntityStore.prototype.retain = function (rootId) {
449
+ return this.rootIds[rootId] = (this.rootIds[rootId] || 0) + 1;
450
+ };
451
+ EntityStore.prototype.release = function (rootId) {
452
+ if (this.rootIds[rootId] > 0) {
453
+ var count = --this.rootIds[rootId];
454
+ if (!count)
455
+ delete this.rootIds[rootId];
456
+ return count;
457
+ }
458
+ return 0;
459
+ };
460
+ EntityStore.prototype.getRootIdSet = function (ids) {
461
+ if (ids === void 0) { ids = new Set(); }
462
+ Object.keys(this.rootIds).forEach(ids.add, ids);
463
+ if (this instanceof Layer) {
464
+ this.parent.getRootIdSet(ids);
465
+ }
466
+ else {
467
+ Object.keys(this.policies.rootTypenamesById).forEach(ids.add, ids);
468
+ }
469
+ return ids;
470
+ };
471
+ EntityStore.prototype.gc = function () {
472
+ var _this = this;
473
+ var ids = this.getRootIdSet();
474
+ var snapshot = this.toObject();
475
+ ids.forEach(function (id) {
476
+ if (hasOwn.call(snapshot, id)) {
477
+ Object.keys(_this.findChildRefIds(id)).forEach(ids.add, ids);
478
+ delete snapshot[id];
479
+ }
480
+ });
481
+ var idsToRemove = Object.keys(snapshot);
482
+ if (idsToRemove.length) {
483
+ var root_1 = this;
484
+ while (root_1 instanceof Layer)
485
+ root_1 = root_1.parent;
486
+ idsToRemove.forEach(function (id) { return root_1.delete(id); });
487
+ }
488
+ return idsToRemove;
489
+ };
490
+ EntityStore.prototype.findChildRefIds = function (dataId) {
491
+ if (!hasOwn.call(this.refs, dataId)) {
492
+ var found_1 = this.refs[dataId] = Object.create(null);
493
+ var root = this.data[dataId];
494
+ if (!root)
495
+ return found_1;
496
+ var workSet_1 = new Set([root]);
497
+ workSet_1.forEach(function (obj) {
498
+ if (utilities.isReference(obj)) {
499
+ found_1[obj.__ref] = true;
500
+ }
501
+ if (utilities.isNonNullObject(obj)) {
502
+ Object.keys(obj).forEach(function (key) {
503
+ var child = obj[key];
504
+ if (utilities.isNonNullObject(child)) {
505
+ workSet_1.add(child);
506
+ }
507
+ });
508
+ }
509
+ });
510
+ }
511
+ return this.refs[dataId];
512
+ };
513
+ EntityStore.prototype.makeCacheKey = function () {
514
+ return this.group.keyMaker.lookupArray(arguments);
515
+ };
516
+ return EntityStore;
517
+ }());
518
+ var CacheGroup = (function () {
519
+ function CacheGroup(caching, parent) {
520
+ if (parent === void 0) { parent = null; }
521
+ this.caching = caching;
522
+ this.parent = parent;
523
+ this.d = null;
524
+ this.resetCaching();
525
+ }
526
+ CacheGroup.prototype.resetCaching = function () {
527
+ this.d = this.caching ? optimism.dep() : null;
528
+ this.keyMaker = new trie.Trie(utilities.canUseWeakMap);
529
+ };
530
+ CacheGroup.prototype.depend = function (dataId, storeFieldName) {
531
+ if (this.d) {
532
+ this.d(makeDepKey(dataId, storeFieldName));
533
+ var fieldName = fieldNameFromStoreName(storeFieldName);
534
+ if (fieldName !== storeFieldName) {
535
+ this.d(makeDepKey(dataId, fieldName));
536
+ }
537
+ if (this.parent) {
538
+ this.parent.depend(dataId, storeFieldName);
539
+ }
540
+ }
541
+ };
542
+ CacheGroup.prototype.dirty = function (dataId, storeFieldName) {
543
+ if (this.d) {
544
+ this.d.dirty(makeDepKey(dataId, storeFieldName), storeFieldName === "__exists" ? "forget" : "setDirty");
545
+ }
546
+ };
547
+ return CacheGroup;
548
+ }());
549
+ function makeDepKey(dataId, storeFieldName) {
550
+ return storeFieldName + '#' + dataId;
551
+ }
552
+ function maybeDependOnExistenceOfEntity(store, entityId) {
553
+ if (supportsResultCaching(store)) {
554
+ store.group.depend(entityId, "__exists");
555
+ }
556
+ }
557
+ (function (EntityStore) {
558
+ var Root = (function (_super) {
559
+ tslib.__extends(Root, _super);
560
+ function Root(_a) {
561
+ var policies = _a.policies, _b = _a.resultCaching, resultCaching = _b === void 0 ? true : _b, seed = _a.seed;
562
+ var _this = _super.call(this, policies, new CacheGroup(resultCaching)) || this;
563
+ _this.stump = new Stump(_this);
564
+ _this.storageTrie = new trie.Trie(utilities.canUseWeakMap);
565
+ if (seed)
566
+ _this.replace(seed);
567
+ return _this;
568
+ }
569
+ Root.prototype.addLayer = function (layerId, replay) {
570
+ return this.stump.addLayer(layerId, replay);
571
+ };
572
+ Root.prototype.removeLayer = function () {
573
+ return this;
574
+ };
575
+ Root.prototype.getStorage = function () {
576
+ return this.storageTrie.lookupArray(arguments);
577
+ };
578
+ return Root;
579
+ }(EntityStore));
580
+ EntityStore.Root = Root;
581
+ })(exports.EntityStore || (exports.EntityStore = {}));
582
+ var Layer = (function (_super) {
583
+ tslib.__extends(Layer, _super);
584
+ function Layer(id, parent, replay, group) {
585
+ var _this = _super.call(this, parent.policies, group) || this;
586
+ _this.id = id;
587
+ _this.parent = parent;
588
+ _this.replay = replay;
589
+ _this.group = group;
590
+ replay(_this);
591
+ return _this;
592
+ }
593
+ Layer.prototype.addLayer = function (layerId, replay) {
594
+ return new Layer(layerId, this, replay, this.group);
595
+ };
596
+ Layer.prototype.removeLayer = function (layerId) {
597
+ var _this = this;
598
+ var parent = this.parent.removeLayer(layerId);
599
+ if (layerId === this.id) {
600
+ if (this.group.caching) {
601
+ Object.keys(this.data).forEach(function (dataId) {
602
+ var ownStoreObject = _this.data[dataId];
603
+ var parentStoreObject = parent["lookup"](dataId);
604
+ if (!parentStoreObject) {
605
+ _this.delete(dataId);
606
+ }
607
+ else if (!ownStoreObject) {
608
+ _this.group.dirty(dataId, "__exists");
609
+ Object.keys(parentStoreObject).forEach(function (storeFieldName) {
610
+ _this.group.dirty(dataId, storeFieldName);
611
+ });
612
+ }
613
+ else if (ownStoreObject !== parentStoreObject) {
614
+ Object.keys(ownStoreObject).forEach(function (storeFieldName) {
615
+ if (!equality.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
616
+ _this.group.dirty(dataId, storeFieldName);
617
+ }
618
+ });
619
+ }
620
+ });
621
+ }
622
+ return parent;
623
+ }
624
+ if (parent === this.parent)
625
+ return this;
626
+ return parent.addLayer(this.id, this.replay);
627
+ };
628
+ Layer.prototype.toObject = function () {
629
+ return tslib.__assign(tslib.__assign({}, this.parent.toObject()), this.data);
630
+ };
631
+ Layer.prototype.findChildRefIds = function (dataId) {
632
+ var fromParent = this.parent.findChildRefIds(dataId);
633
+ return hasOwn.call(this.data, dataId) ? tslib.__assign(tslib.__assign({}, fromParent), _super.prototype.findChildRefIds.call(this, dataId)) : fromParent;
634
+ };
635
+ Layer.prototype.getStorage = function () {
636
+ var p = this.parent;
637
+ while (p.parent)
638
+ p = p.parent;
639
+ return p.getStorage.apply(p, arguments);
640
+ };
641
+ return Layer;
642
+ }(exports.EntityStore));
643
+ var Stump = (function (_super) {
644
+ tslib.__extends(Stump, _super);
645
+ function Stump(root) {
646
+ return _super.call(this, "EntityStore.Stump", root, function () { }, new CacheGroup(root.group.caching, root.group)) || this;
647
+ }
648
+ Stump.prototype.removeLayer = function () {
649
+ return this;
650
+ };
651
+ Stump.prototype.merge = function () {
652
+ return this.parent.merge.apply(this.parent, arguments);
653
+ };
654
+ return Stump;
655
+ }(Layer));
656
+ function storeObjectReconciler(existingObject, incomingObject, property) {
657
+ var existingValue = existingObject[property];
658
+ var incomingValue = incomingObject[property];
659
+ return equality.equal(existingValue, incomingValue) ? existingValue : incomingValue;
660
+ }
661
+ function supportsResultCaching(store) {
662
+ return !!(store instanceof exports.EntityStore && store.group.caching);
663
+ }
664
+
665
+ function shallowCopy(value) {
666
+ if (utilities.isNonNullObject(value)) {
667
+ return isArray(value)
668
+ ? value.slice(0)
669
+ : tslib.__assign({ __proto__: Object.getPrototypeOf(value) }, value);
670
+ }
671
+ return value;
672
+ }
673
+ var ObjectCanon = (function () {
674
+ function ObjectCanon() {
675
+ this.known = new (utilities.canUseWeakSet ? WeakSet : Set)();
676
+ this.pool = new trie.Trie(utilities.canUseWeakMap);
677
+ this.passes = new WeakMap();
678
+ this.keysByJSON = new Map();
679
+ this.empty = this.admit({});
680
+ }
681
+ ObjectCanon.prototype.isKnown = function (value) {
682
+ return utilities.isNonNullObject(value) && this.known.has(value);
683
+ };
684
+ ObjectCanon.prototype.pass = function (value) {
685
+ if (utilities.isNonNullObject(value)) {
686
+ var copy = shallowCopy(value);
687
+ this.passes.set(copy, value);
688
+ return copy;
689
+ }
690
+ return value;
691
+ };
692
+ ObjectCanon.prototype.admit = function (value) {
693
+ var _this = this;
694
+ if (utilities.isNonNullObject(value)) {
695
+ var original = this.passes.get(value);
696
+ if (original)
697
+ return original;
698
+ var proto = Object.getPrototypeOf(value);
699
+ switch (proto) {
700
+ case Array.prototype: {
701
+ if (this.known.has(value))
702
+ return value;
703
+ var array = value.map(this.admit, this);
704
+ var node = this.pool.lookupArray(array);
705
+ if (!node.array) {
706
+ this.known.add(node.array = array);
707
+ if (globals.__DEV__) {
708
+ Object.freeze(array);
709
+ }
710
+ }
711
+ return node.array;
712
+ }
713
+ case null:
714
+ case Object.prototype: {
715
+ if (this.known.has(value))
716
+ return value;
717
+ var proto_1 = Object.getPrototypeOf(value);
718
+ var array_1 = [proto_1];
719
+ var keys = this.sortedKeys(value);
720
+ array_1.push(keys.json);
721
+ var firstValueIndex_1 = array_1.length;
722
+ keys.sorted.forEach(function (key) {
723
+ array_1.push(_this.admit(value[key]));
724
+ });
725
+ var node = this.pool.lookupArray(array_1);
726
+ if (!node.object) {
727
+ var obj_1 = node.object = Object.create(proto_1);
728
+ this.known.add(obj_1);
729
+ keys.sorted.forEach(function (key, i) {
730
+ obj_1[key] = array_1[firstValueIndex_1 + i];
731
+ });
732
+ if (globals.__DEV__) {
733
+ Object.freeze(obj_1);
734
+ }
735
+ }
736
+ return node.object;
737
+ }
738
+ }
739
+ }
740
+ return value;
741
+ };
742
+ ObjectCanon.prototype.sortedKeys = function (obj) {
743
+ var keys = Object.keys(obj);
744
+ var node = this.pool.lookupArray(keys);
745
+ if (!node.keys) {
746
+ keys.sort();
747
+ var json = JSON.stringify(keys);
748
+ if (!(node.keys = this.keysByJSON.get(json))) {
749
+ this.keysByJSON.set(json, node.keys = { sorted: keys, json: json });
750
+ }
751
+ }
752
+ return node.keys;
753
+ };
754
+ return ObjectCanon;
755
+ }());
756
+ var canonicalStringify = Object.assign(function (value) {
757
+ if (utilities.isNonNullObject(value)) {
758
+ if (stringifyCanon === void 0) {
759
+ resetCanonicalStringify();
760
+ }
761
+ var canonical = stringifyCanon.admit(value);
762
+ var json = stringifyCache.get(canonical);
763
+ if (json === void 0) {
764
+ stringifyCache.set(canonical, json = JSON.stringify(canonical));
765
+ }
766
+ return json;
767
+ }
768
+ return JSON.stringify(value);
769
+ }, {
770
+ reset: resetCanonicalStringify,
771
+ });
772
+ var stringifyCanon;
773
+ var stringifyCache;
774
+ function resetCanonicalStringify() {
775
+ stringifyCanon = new ObjectCanon;
776
+ stringifyCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
777
+ }
778
+
779
+ function execSelectionSetKeyArgs(options) {
780
+ return [
781
+ options.selectionSet,
782
+ options.objectOrReference,
783
+ options.context,
784
+ options.context.canonizeResults,
785
+ ];
786
+ }
787
+ var StoreReader = (function () {
788
+ function StoreReader(config) {
789
+ var _this = this;
790
+ this.knownResults = new (utilities.canUseWeakMap ? WeakMap : Map)();
791
+ this.config = utilities.compact(config, {
792
+ addTypename: config.addTypename !== false,
793
+ canonizeResults: shouldCanonizeResults(config),
794
+ });
795
+ this.canon = config.canon || new ObjectCanon;
796
+ this.executeSelectionSet = optimism.wrap(function (options) {
797
+ var _a;
798
+ var canonizeResults = options.context.canonizeResults;
799
+ var peekArgs = execSelectionSetKeyArgs(options);
800
+ peekArgs[3] = !canonizeResults;
801
+ var other = (_a = _this.executeSelectionSet).peek.apply(_a, peekArgs);
802
+ if (other) {
803
+ if (canonizeResults) {
804
+ return tslib.__assign(tslib.__assign({}, other), { result: _this.canon.admit(other.result) });
805
+ }
806
+ return other;
807
+ }
808
+ maybeDependOnExistenceOfEntity(options.context.store, options.enclosingRef.__ref);
809
+ return _this.execSelectionSetImpl(options);
810
+ }, {
811
+ max: this.config.resultCacheMaxSize,
812
+ keyArgs: execSelectionSetKeyArgs,
813
+ makeCacheKey: function (selectionSet, parent, context, canonizeResults) {
814
+ if (supportsResultCaching(context.store)) {
815
+ return context.store.makeCacheKey(selectionSet, utilities.isReference(parent) ? parent.__ref : parent, context.varString, canonizeResults);
816
+ }
817
+ }
818
+ });
819
+ this.executeSubSelectedArray = optimism.wrap(function (options) {
820
+ maybeDependOnExistenceOfEntity(options.context.store, options.enclosingRef.__ref);
821
+ return _this.execSubSelectedArrayImpl(options);
822
+ }, {
823
+ max: this.config.resultCacheMaxSize,
824
+ makeCacheKey: function (_a) {
825
+ var field = _a.field, array = _a.array, context = _a.context;
826
+ if (supportsResultCaching(context.store)) {
827
+ return context.store.makeCacheKey(field, array, context.varString);
828
+ }
829
+ }
830
+ });
831
+ }
832
+ StoreReader.prototype.resetCanon = function () {
833
+ this.canon = new ObjectCanon;
834
+ };
835
+ StoreReader.prototype.diffQueryAgainstStore = function (_a) {
836
+ var store = _a.store, query = _a.query, _b = _a.rootId, rootId = _b === void 0 ? 'ROOT_QUERY' : _b, variables = _a.variables, _c = _a.returnPartialData, returnPartialData = _c === void 0 ? true : _c, _d = _a.canonizeResults, canonizeResults = _d === void 0 ? this.config.canonizeResults : _d;
837
+ var policies = this.config.cache.policies;
838
+ variables = tslib.__assign(tslib.__assign({}, utilities.getDefaultValues(utilities.getQueryDefinition(query))), variables);
839
+ var rootRef = utilities.makeReference(rootId);
840
+ var execResult = this.executeSelectionSet({
841
+ selectionSet: utilities.getMainDefinition(query).selectionSet,
842
+ objectOrReference: rootRef,
843
+ enclosingRef: rootRef,
844
+ context: tslib.__assign({ store: store, query: query, policies: policies, variables: variables, varString: canonicalStringify(variables), canonizeResults: canonizeResults }, extractFragmentContext(query, this.config.fragments)),
845
+ });
846
+ var missing;
847
+ if (execResult.missing) {
848
+ missing = [new MissingFieldError(firstMissing(execResult.missing), execResult.missing, query, variables)];
849
+ if (!returnPartialData) {
850
+ throw missing[0];
851
+ }
852
+ }
853
+ return {
854
+ result: execResult.result,
855
+ complete: !missing,
856
+ missing: missing,
857
+ };
858
+ };
859
+ StoreReader.prototype.isFresh = function (result, parent, selectionSet, context) {
860
+ if (supportsResultCaching(context.store) &&
861
+ this.knownResults.get(result) === selectionSet) {
862
+ var latest = this.executeSelectionSet.peek(selectionSet, parent, context, this.canon.isKnown(result));
863
+ if (latest && result === latest.result) {
864
+ return true;
865
+ }
866
+ }
867
+ return false;
868
+ };
869
+ StoreReader.prototype.execSelectionSetImpl = function (_a) {
870
+ var _this = this;
871
+ var selectionSet = _a.selectionSet, objectOrReference = _a.objectOrReference, enclosingRef = _a.enclosingRef, context = _a.context;
872
+ if (utilities.isReference(objectOrReference) &&
873
+ !context.policies.rootTypenamesById[objectOrReference.__ref] &&
874
+ !context.store.has(objectOrReference.__ref)) {
875
+ return {
876
+ result: this.canon.empty,
877
+ missing: "Dangling reference to missing ".concat(objectOrReference.__ref, " object"),
878
+ };
879
+ }
880
+ var variables = context.variables, policies = context.policies, store = context.store;
881
+ var typename = store.getFieldValue(objectOrReference, "__typename");
882
+ var objectsToMerge = [];
883
+ var missing;
884
+ var missingMerger = new utilities.DeepMerger();
885
+ if (this.config.addTypename &&
886
+ typeof typename === "string" &&
887
+ !policies.rootIdsByTypename[typename]) {
888
+ objectsToMerge.push({ __typename: typename });
889
+ }
890
+ function handleMissing(result, resultName) {
891
+ var _a;
892
+ if (result.missing) {
893
+ missing = missingMerger.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
894
+ }
895
+ return result.result;
896
+ }
897
+ var workSet = new Set(selectionSet.selections);
898
+ workSet.forEach(function (selection) {
899
+ var _a, _b;
900
+ if (!utilities.shouldInclude(selection, variables))
901
+ return;
902
+ if (utilities.isField(selection)) {
903
+ var fieldValue = policies.readField({
904
+ fieldName: selection.name.value,
905
+ field: selection,
906
+ variables: context.variables,
907
+ from: objectOrReference,
908
+ }, context);
909
+ var resultName = utilities.resultKeyNameFromField(selection);
910
+ if (fieldValue === void 0) {
911
+ if (!utilities.addTypenameToDocument.added(selection)) {
912
+ missing = missingMerger.merge(missing, (_a = {},
913
+ _a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(utilities.isReference(objectOrReference)
914
+ ? objectOrReference.__ref + " object"
915
+ : "object " + JSON.stringify(objectOrReference, null, 2)),
916
+ _a));
917
+ }
918
+ }
919
+ else if (isArray(fieldValue)) {
920
+ fieldValue = handleMissing(_this.executeSubSelectedArray({
921
+ field: selection,
922
+ array: fieldValue,
923
+ enclosingRef: enclosingRef,
924
+ context: context,
925
+ }), resultName);
926
+ }
927
+ else if (!selection.selectionSet) {
928
+ if (context.canonizeResults) {
929
+ fieldValue = _this.canon.pass(fieldValue);
930
+ }
931
+ }
932
+ else if (fieldValue != null) {
933
+ fieldValue = handleMissing(_this.executeSelectionSet({
934
+ selectionSet: selection.selectionSet,
935
+ objectOrReference: fieldValue,
936
+ enclosingRef: utilities.isReference(fieldValue) ? fieldValue : enclosingRef,
937
+ context: context,
938
+ }), resultName);
939
+ }
940
+ if (fieldValue !== void 0) {
941
+ objectsToMerge.push((_b = {}, _b[resultName] = fieldValue, _b));
942
+ }
943
+ }
944
+ else {
945
+ var fragment = utilities.getFragmentFromSelection(selection, context.lookupFragment);
946
+ if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
947
+ throw globals.__DEV__ ? new globals.InvariantError("No fragment named ".concat(selection.name.value)) : new globals.InvariantError(5);
948
+ }
949
+ if (fragment && policies.fragmentMatches(fragment, typename)) {
950
+ fragment.selectionSet.selections.forEach(workSet.add, workSet);
951
+ }
952
+ }
953
+ });
954
+ var result = utilities.mergeDeepArray(objectsToMerge);
955
+ var finalResult = { result: result, missing: missing };
956
+ var frozen = context.canonizeResults
957
+ ? this.canon.admit(finalResult)
958
+ : utilities.maybeDeepFreeze(finalResult);
959
+ if (frozen.result) {
960
+ this.knownResults.set(frozen.result, selectionSet);
961
+ }
962
+ return frozen;
963
+ };
964
+ StoreReader.prototype.execSubSelectedArrayImpl = function (_a) {
965
+ var _this = this;
966
+ var field = _a.field, array = _a.array, enclosingRef = _a.enclosingRef, context = _a.context;
967
+ var missing;
968
+ var missingMerger = new utilities.DeepMerger();
969
+ function handleMissing(childResult, i) {
970
+ var _a;
971
+ if (childResult.missing) {
972
+ missing = missingMerger.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
973
+ }
974
+ return childResult.result;
975
+ }
976
+ if (field.selectionSet) {
977
+ array = array.filter(context.store.canRead);
978
+ }
979
+ array = array.map(function (item, i) {
980
+ if (item === null) {
981
+ return null;
982
+ }
983
+ if (isArray(item)) {
984
+ return handleMissing(_this.executeSubSelectedArray({
985
+ field: field,
986
+ array: item,
987
+ enclosingRef: enclosingRef,
988
+ context: context,
989
+ }), i);
990
+ }
991
+ if (field.selectionSet) {
992
+ return handleMissing(_this.executeSelectionSet({
993
+ selectionSet: field.selectionSet,
994
+ objectOrReference: item,
995
+ enclosingRef: utilities.isReference(item) ? item : enclosingRef,
996
+ context: context,
997
+ }), i);
998
+ }
999
+ if (globals.__DEV__) {
1000
+ assertSelectionSetForIdValue(context.store, field, item);
1001
+ }
1002
+ return item;
1003
+ });
1004
+ return {
1005
+ result: context.canonizeResults ? this.canon.admit(array) : array,
1006
+ missing: missing,
1007
+ };
1008
+ };
1009
+ return StoreReader;
1010
+ }());
1011
+ function firstMissing(tree) {
1012
+ try {
1013
+ JSON.stringify(tree, function (_, value) {
1014
+ if (typeof value === "string")
1015
+ throw value;
1016
+ return value;
1017
+ });
1018
+ }
1019
+ catch (result) {
1020
+ return result;
1021
+ }
1022
+ }
1023
+ function assertSelectionSetForIdValue(store, field, fieldValue) {
1024
+ if (!field.selectionSet) {
1025
+ var workSet_1 = new Set([fieldValue]);
1026
+ workSet_1.forEach(function (value) {
1027
+ if (utilities.isNonNullObject(value)) {
1028
+ globals.__DEV__ ? globals.invariant(!utilities.isReference(value), "Missing selection set for object of type ".concat(getTypenameFromStoreObject(store, value), " returned for query field ").concat(field.name.value)) : globals.invariant(!utilities.isReference(value), 6);
1029
+ Object.values(value).forEach(workSet_1.add, workSet_1);
1030
+ }
1031
+ });
1032
+ }
1033
+ }
1034
+
1035
+ var cacheSlot = new context.Slot();
1036
+ var cacheInfoMap = new WeakMap();
1037
+ function getCacheInfo(cache) {
1038
+ var info = cacheInfoMap.get(cache);
1039
+ if (!info) {
1040
+ cacheInfoMap.set(cache, info = {
1041
+ vars: new Set,
1042
+ dep: optimism.dep(),
1043
+ });
1044
+ }
1045
+ return info;
1046
+ }
1047
+ function forgetCache(cache) {
1048
+ getCacheInfo(cache).vars.forEach(function (rv) { return rv.forgetCache(cache); });
1049
+ }
1050
+ function recallCache(cache) {
1051
+ getCacheInfo(cache).vars.forEach(function (rv) { return rv.attachCache(cache); });
1052
+ }
1053
+ function makeVar(value) {
1054
+ var caches = new Set();
1055
+ var listeners = new Set();
1056
+ var rv = function (newValue) {
1057
+ if (arguments.length > 0) {
1058
+ if (value !== newValue) {
1059
+ value = newValue;
1060
+ caches.forEach(function (cache) {
1061
+ getCacheInfo(cache).dep.dirty(rv);
1062
+ broadcast(cache);
1063
+ });
1064
+ var oldListeners = Array.from(listeners);
1065
+ listeners.clear();
1066
+ oldListeners.forEach(function (listener) { return listener(value); });
1067
+ }
1068
+ }
1069
+ else {
1070
+ var cache = cacheSlot.getValue();
1071
+ if (cache) {
1072
+ attach(cache);
1073
+ getCacheInfo(cache).dep(rv);
1074
+ }
1075
+ }
1076
+ return value;
1077
+ };
1078
+ rv.onNextChange = function (listener) {
1079
+ listeners.add(listener);
1080
+ return function () {
1081
+ listeners.delete(listener);
1082
+ };
1083
+ };
1084
+ var attach = rv.attachCache = function (cache) {
1085
+ caches.add(cache);
1086
+ getCacheInfo(cache).vars.add(rv);
1087
+ return rv;
1088
+ };
1089
+ rv.forgetCache = function (cache) { return caches.delete(cache); };
1090
+ return rv;
1091
+ }
1092
+ function broadcast(cache) {
1093
+ if (cache.broadcastWatches) {
1094
+ cache.broadcastWatches();
1095
+ }
1096
+ }
1097
+
1098
+ var specifierInfoCache = Object.create(null);
1099
+ function lookupSpecifierInfo(spec) {
1100
+ var cacheKey = JSON.stringify(spec);
1101
+ return specifierInfoCache[cacheKey] ||
1102
+ (specifierInfoCache[cacheKey] = Object.create(null));
1103
+ }
1104
+ function keyFieldsFnFromSpecifier(specifier) {
1105
+ var info = lookupSpecifierInfo(specifier);
1106
+ return info.keyFieldsFn || (info.keyFieldsFn = function (object, context) {
1107
+ var extract = function (from, key) { return context.readField(key, from); };
1108
+ var keyObject = context.keyObject = collectSpecifierPaths(specifier, function (schemaKeyPath) {
1109
+ var extracted = extractKeyPath(context.storeObject, schemaKeyPath, extract);
1110
+ if (extracted === void 0 &&
1111
+ object !== context.storeObject &&
1112
+ hasOwn.call(object, schemaKeyPath[0])) {
1113
+ extracted = extractKeyPath(object, schemaKeyPath, extractKey);
1114
+ }
1115
+ globals.__DEV__ ? globals.invariant(extracted !== void 0, "Missing field '".concat(schemaKeyPath.join('.'), "' while extracting keyFields from ").concat(JSON.stringify(object))) : globals.invariant(extracted !== void 0, 2);
1116
+ return extracted;
1117
+ });
1118
+ return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
1119
+ });
1120
+ }
1121
+ function keyArgsFnFromSpecifier(specifier) {
1122
+ var info = lookupSpecifierInfo(specifier);
1123
+ return info.keyArgsFn || (info.keyArgsFn = function (args, _a) {
1124
+ var field = _a.field, variables = _a.variables, fieldName = _a.fieldName;
1125
+ var collected = collectSpecifierPaths(specifier, function (keyPath) {
1126
+ var firstKey = keyPath[0];
1127
+ var firstChar = firstKey.charAt(0);
1128
+ if (firstChar === "@") {
1129
+ if (field && utilities.isNonEmptyArray(field.directives)) {
1130
+ var directiveName_1 = firstKey.slice(1);
1131
+ var d = field.directives.find(function (d) { return d.name.value === directiveName_1; });
1132
+ var directiveArgs = d && utilities.argumentsObjectFromField(d, variables);
1133
+ return directiveArgs && extractKeyPath(directiveArgs, keyPath.slice(1));
1134
+ }
1135
+ return;
1136
+ }
1137
+ if (firstChar === "$") {
1138
+ var variableName = firstKey.slice(1);
1139
+ if (variables && hasOwn.call(variables, variableName)) {
1140
+ var varKeyPath = keyPath.slice(0);
1141
+ varKeyPath[0] = variableName;
1142
+ return extractKeyPath(variables, varKeyPath);
1143
+ }
1144
+ return;
1145
+ }
1146
+ if (args) {
1147
+ return extractKeyPath(args, keyPath);
1148
+ }
1149
+ });
1150
+ var suffix = JSON.stringify(collected);
1151
+ if (args || suffix !== "{}") {
1152
+ fieldName += ":" + suffix;
1153
+ }
1154
+ return fieldName;
1155
+ });
1156
+ }
1157
+ function collectSpecifierPaths(specifier, extractor) {
1158
+ var merger = new utilities.DeepMerger;
1159
+ return getSpecifierPaths(specifier).reduce(function (collected, path) {
1160
+ var _a;
1161
+ var toMerge = extractor(path);
1162
+ if (toMerge !== void 0) {
1163
+ for (var i = path.length - 1; i >= 0; --i) {
1164
+ toMerge = (_a = {}, _a[path[i]] = toMerge, _a);
1165
+ }
1166
+ collected = merger.merge(collected, toMerge);
1167
+ }
1168
+ return collected;
1169
+ }, Object.create(null));
1170
+ }
1171
+ function getSpecifierPaths(spec) {
1172
+ var info = lookupSpecifierInfo(spec);
1173
+ if (!info.paths) {
1174
+ var paths_1 = info.paths = [];
1175
+ var currentPath_1 = [];
1176
+ spec.forEach(function (s, i) {
1177
+ if (isArray(s)) {
1178
+ getSpecifierPaths(s).forEach(function (p) { return paths_1.push(currentPath_1.concat(p)); });
1179
+ currentPath_1.length = 0;
1180
+ }
1181
+ else {
1182
+ currentPath_1.push(s);
1183
+ if (!isArray(spec[i + 1])) {
1184
+ paths_1.push(currentPath_1.slice(0));
1185
+ currentPath_1.length = 0;
1186
+ }
1187
+ }
1188
+ });
1189
+ }
1190
+ return info.paths;
1191
+ }
1192
+ function extractKey(object, key) {
1193
+ return object[key];
1194
+ }
1195
+ function extractKeyPath(object, path, extract) {
1196
+ extract = extract || extractKey;
1197
+ return normalize(path.reduce(function reducer(obj, key) {
1198
+ return isArray(obj)
1199
+ ? obj.map(function (child) { return reducer(child, key); })
1200
+ : obj && extract(obj, key);
1201
+ }, object));
1202
+ }
1203
+ function normalize(value) {
1204
+ if (utilities.isNonNullObject(value)) {
1205
+ if (isArray(value)) {
1206
+ return value.map(normalize);
1207
+ }
1208
+ return collectSpecifierPaths(Object.keys(value).sort(), function (path) { return extractKeyPath(value, path); });
1209
+ }
1210
+ return value;
1211
+ }
1212
+
1213
+ utilities.getStoreKeyName.setStringify(canonicalStringify);
1214
+ function argsFromFieldSpecifier(spec) {
1215
+ return spec.args !== void 0 ? spec.args :
1216
+ spec.field ? utilities.argumentsObjectFromField(spec.field, spec.variables) : null;
1217
+ }
1218
+ var nullKeyFieldsFn = function () { return void 0; };
1219
+ var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
1220
+ var mergeTrueFn = function (existing, incoming, _a) {
1221
+ var mergeObjects = _a.mergeObjects;
1222
+ return mergeObjects(existing, incoming);
1223
+ };
1224
+ var mergeFalseFn = function (_, incoming) { return incoming; };
1225
+ var Policies = (function () {
1226
+ function Policies(config) {
1227
+ this.config = config;
1228
+ this.typePolicies = Object.create(null);
1229
+ this.toBeAdded = Object.create(null);
1230
+ this.supertypeMap = new Map();
1231
+ this.fuzzySubtypes = new Map();
1232
+ this.rootIdsByTypename = Object.create(null);
1233
+ this.rootTypenamesById = Object.create(null);
1234
+ this.usingPossibleTypes = false;
1235
+ this.config = tslib.__assign({ dataIdFromObject: defaultDataIdFromObject }, config);
1236
+ this.cache = this.config.cache;
1237
+ this.setRootTypename("Query");
1238
+ this.setRootTypename("Mutation");
1239
+ this.setRootTypename("Subscription");
1240
+ if (config.possibleTypes) {
1241
+ this.addPossibleTypes(config.possibleTypes);
1242
+ }
1243
+ if (config.typePolicies) {
1244
+ this.addTypePolicies(config.typePolicies);
1245
+ }
1246
+ }
1247
+ Policies.prototype.identify = function (object, partialContext) {
1248
+ var _a;
1249
+ var policies = this;
1250
+ var typename = partialContext && (partialContext.typename ||
1251
+ ((_a = partialContext.storeObject) === null || _a === void 0 ? void 0 : _a.__typename)) || object.__typename;
1252
+ if (typename === this.rootTypenamesById.ROOT_QUERY) {
1253
+ return ["ROOT_QUERY"];
1254
+ }
1255
+ var storeObject = partialContext && partialContext.storeObject || object;
1256
+ var context = tslib.__assign(tslib.__assign({}, partialContext), { typename: typename, storeObject: storeObject, readField: partialContext && partialContext.readField || function () {
1257
+ var options = normalizeReadFieldOptions(arguments, storeObject);
1258
+ return policies.readField(options, {
1259
+ store: policies.cache["data"],
1260
+ variables: options.variables,
1261
+ });
1262
+ } });
1263
+ var id;
1264
+ var policy = typename && this.getTypePolicy(typename);
1265
+ var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
1266
+ while (keyFn) {
1267
+ var specifierOrId = keyFn(object, context);
1268
+ if (isArray(specifierOrId)) {
1269
+ keyFn = keyFieldsFnFromSpecifier(specifierOrId);
1270
+ }
1271
+ else {
1272
+ id = specifierOrId;
1273
+ break;
1274
+ }
1275
+ }
1276
+ id = id ? String(id) : void 0;
1277
+ return context.keyObject ? [id, context.keyObject] : [id];
1278
+ };
1279
+ Policies.prototype.addTypePolicies = function (typePolicies) {
1280
+ var _this = this;
1281
+ Object.keys(typePolicies).forEach(function (typename) {
1282
+ var _a = typePolicies[typename], queryType = _a.queryType, mutationType = _a.mutationType, subscriptionType = _a.subscriptionType, incoming = tslib.__rest(_a, ["queryType", "mutationType", "subscriptionType"]);
1283
+ if (queryType)
1284
+ _this.setRootTypename("Query", typename);
1285
+ if (mutationType)
1286
+ _this.setRootTypename("Mutation", typename);
1287
+ if (subscriptionType)
1288
+ _this.setRootTypename("Subscription", typename);
1289
+ if (hasOwn.call(_this.toBeAdded, typename)) {
1290
+ _this.toBeAdded[typename].push(incoming);
1291
+ }
1292
+ else {
1293
+ _this.toBeAdded[typename] = [incoming];
1294
+ }
1295
+ });
1296
+ };
1297
+ Policies.prototype.updateTypePolicy = function (typename, incoming) {
1298
+ var _this = this;
1299
+ var existing = this.getTypePolicy(typename);
1300
+ var keyFields = incoming.keyFields, fields = incoming.fields;
1301
+ function setMerge(existing, merge) {
1302
+ existing.merge =
1303
+ typeof merge === "function" ? merge :
1304
+ merge === true ? mergeTrueFn :
1305
+ merge === false ? mergeFalseFn :
1306
+ existing.merge;
1307
+ }
1308
+ setMerge(existing, incoming.merge);
1309
+ existing.keyFn =
1310
+ keyFields === false ? nullKeyFieldsFn :
1311
+ isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
1312
+ typeof keyFields === "function" ? keyFields :
1313
+ existing.keyFn;
1314
+ if (fields) {
1315
+ Object.keys(fields).forEach(function (fieldName) {
1316
+ var existing = _this.getFieldPolicy(typename, fieldName, true);
1317
+ var incoming = fields[fieldName];
1318
+ if (typeof incoming === "function") {
1319
+ existing.read = incoming;
1320
+ }
1321
+ else {
1322
+ var keyArgs = incoming.keyArgs, read = incoming.read, merge = incoming.merge;
1323
+ existing.keyFn =
1324
+ keyArgs === false ? simpleKeyArgsFn :
1325
+ isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
1326
+ typeof keyArgs === "function" ? keyArgs :
1327
+ existing.keyFn;
1328
+ if (typeof read === "function") {
1329
+ existing.read = read;
1330
+ }
1331
+ setMerge(existing, merge);
1332
+ }
1333
+ if (existing.read && existing.merge) {
1334
+ existing.keyFn = existing.keyFn || simpleKeyArgsFn;
1335
+ }
1336
+ });
1337
+ }
1338
+ };
1339
+ Policies.prototype.setRootTypename = function (which, typename) {
1340
+ if (typename === void 0) { typename = which; }
1341
+ var rootId = "ROOT_" + which.toUpperCase();
1342
+ var old = this.rootTypenamesById[rootId];
1343
+ if (typename !== old) {
1344
+ globals.__DEV__ ? globals.invariant(!old || old === which, "Cannot change root ".concat(which, " __typename more than once")) : globals.invariant(!old || old === which, 3);
1345
+ if (old)
1346
+ delete this.rootIdsByTypename[old];
1347
+ this.rootIdsByTypename[typename] = rootId;
1348
+ this.rootTypenamesById[rootId] = typename;
1349
+ }
1350
+ };
1351
+ Policies.prototype.addPossibleTypes = function (possibleTypes) {
1352
+ var _this = this;
1353
+ this.usingPossibleTypes = true;
1354
+ Object.keys(possibleTypes).forEach(function (supertype) {
1355
+ _this.getSupertypeSet(supertype, true);
1356
+ possibleTypes[supertype].forEach(function (subtype) {
1357
+ _this.getSupertypeSet(subtype, true).add(supertype);
1358
+ var match = subtype.match(TypeOrFieldNameRegExp);
1359
+ if (!match || match[0] !== subtype) {
1360
+ _this.fuzzySubtypes.set(subtype, new RegExp(subtype));
1361
+ }
1362
+ });
1363
+ });
1364
+ };
1365
+ Policies.prototype.getTypePolicy = function (typename) {
1366
+ var _this = this;
1367
+ if (!hasOwn.call(this.typePolicies, typename)) {
1368
+ var policy_1 = this.typePolicies[typename] = Object.create(null);
1369
+ policy_1.fields = Object.create(null);
1370
+ var supertypes = this.supertypeMap.get(typename);
1371
+ if (supertypes && supertypes.size) {
1372
+ supertypes.forEach(function (supertype) {
1373
+ var _a = _this.getTypePolicy(supertype), fields = _a.fields, rest = tslib.__rest(_a, ["fields"]);
1374
+ Object.assign(policy_1, rest);
1375
+ Object.assign(policy_1.fields, fields);
1376
+ });
1377
+ }
1378
+ }
1379
+ var inbox = this.toBeAdded[typename];
1380
+ if (inbox && inbox.length) {
1381
+ inbox.splice(0).forEach(function (policy) {
1382
+ _this.updateTypePolicy(typename, policy);
1383
+ });
1384
+ }
1385
+ return this.typePolicies[typename];
1386
+ };
1387
+ Policies.prototype.getFieldPolicy = function (typename, fieldName, createIfMissing) {
1388
+ if (typename) {
1389
+ var fieldPolicies = this.getTypePolicy(typename).fields;
1390
+ return fieldPolicies[fieldName] || (createIfMissing && (fieldPolicies[fieldName] = Object.create(null)));
1391
+ }
1392
+ };
1393
+ Policies.prototype.getSupertypeSet = function (subtype, createIfMissing) {
1394
+ var supertypeSet = this.supertypeMap.get(subtype);
1395
+ if (!supertypeSet && createIfMissing) {
1396
+ this.supertypeMap.set(subtype, supertypeSet = new Set());
1397
+ }
1398
+ return supertypeSet;
1399
+ };
1400
+ Policies.prototype.fragmentMatches = function (fragment, typename, result, variables) {
1401
+ var _this = this;
1402
+ if (!fragment.typeCondition)
1403
+ return true;
1404
+ if (!typename)
1405
+ return false;
1406
+ var supertype = fragment.typeCondition.name.value;
1407
+ if (typename === supertype)
1408
+ return true;
1409
+ if (this.usingPossibleTypes &&
1410
+ this.supertypeMap.has(supertype)) {
1411
+ var typenameSupertypeSet = this.getSupertypeSet(typename, true);
1412
+ var workQueue_1 = [typenameSupertypeSet];
1413
+ var maybeEnqueue_1 = function (subtype) {
1414
+ var supertypeSet = _this.getSupertypeSet(subtype, false);
1415
+ if (supertypeSet &&
1416
+ supertypeSet.size &&
1417
+ workQueue_1.indexOf(supertypeSet) < 0) {
1418
+ workQueue_1.push(supertypeSet);
1419
+ }
1420
+ };
1421
+ var needToCheckFuzzySubtypes = !!(result && this.fuzzySubtypes.size);
1422
+ var checkingFuzzySubtypes = false;
1423
+ for (var i = 0; i < workQueue_1.length; ++i) {
1424
+ var supertypeSet = workQueue_1[i];
1425
+ if (supertypeSet.has(supertype)) {
1426
+ if (!typenameSupertypeSet.has(supertype)) {
1427
+ if (checkingFuzzySubtypes) {
1428
+ globals.__DEV__ && globals.invariant.warn("Inferring subtype ".concat(typename, " of supertype ").concat(supertype));
1429
+ }
1430
+ typenameSupertypeSet.add(supertype);
1431
+ }
1432
+ return true;
1433
+ }
1434
+ supertypeSet.forEach(maybeEnqueue_1);
1435
+ if (needToCheckFuzzySubtypes &&
1436
+ i === workQueue_1.length - 1 &&
1437
+ selectionSetMatchesResult(fragment.selectionSet, result, variables)) {
1438
+ needToCheckFuzzySubtypes = false;
1439
+ checkingFuzzySubtypes = true;
1440
+ this.fuzzySubtypes.forEach(function (regExp, fuzzyString) {
1441
+ var match = typename.match(regExp);
1442
+ if (match && match[0] === typename) {
1443
+ maybeEnqueue_1(fuzzyString);
1444
+ }
1445
+ });
1446
+ }
1447
+ }
1448
+ }
1449
+ return false;
1450
+ };
1451
+ Policies.prototype.hasKeyArgs = function (typename, fieldName) {
1452
+ var policy = this.getFieldPolicy(typename, fieldName, false);
1453
+ return !!(policy && policy.keyFn);
1454
+ };
1455
+ Policies.prototype.getStoreFieldName = function (fieldSpec) {
1456
+ var typename = fieldSpec.typename, fieldName = fieldSpec.fieldName;
1457
+ var policy = this.getFieldPolicy(typename, fieldName, false);
1458
+ var storeFieldName;
1459
+ var keyFn = policy && policy.keyFn;
1460
+ if (keyFn && typename) {
1461
+ var context = {
1462
+ typename: typename,
1463
+ fieldName: fieldName,
1464
+ field: fieldSpec.field || null,
1465
+ variables: fieldSpec.variables,
1466
+ };
1467
+ var args = argsFromFieldSpecifier(fieldSpec);
1468
+ while (keyFn) {
1469
+ var specifierOrString = keyFn(args, context);
1470
+ if (isArray(specifierOrString)) {
1471
+ keyFn = keyArgsFnFromSpecifier(specifierOrString);
1472
+ }
1473
+ else {
1474
+ storeFieldName = specifierOrString || fieldName;
1475
+ break;
1476
+ }
1477
+ }
1478
+ }
1479
+ if (storeFieldName === void 0) {
1480
+ storeFieldName = fieldSpec.field
1481
+ ? utilities.storeKeyNameFromField(fieldSpec.field, fieldSpec.variables)
1482
+ : utilities.getStoreKeyName(fieldName, argsFromFieldSpecifier(fieldSpec));
1483
+ }
1484
+ if (storeFieldName === false) {
1485
+ return fieldName;
1486
+ }
1487
+ return fieldName === fieldNameFromStoreName(storeFieldName)
1488
+ ? storeFieldName
1489
+ : fieldName + ":" + storeFieldName;
1490
+ };
1491
+ Policies.prototype.readField = function (options, context) {
1492
+ var objectOrReference = options.from;
1493
+ if (!objectOrReference)
1494
+ return;
1495
+ var nameOrField = options.field || options.fieldName;
1496
+ if (!nameOrField)
1497
+ return;
1498
+ if (options.typename === void 0) {
1499
+ var typename = context.store.getFieldValue(objectOrReference, "__typename");
1500
+ if (typename)
1501
+ options.typename = typename;
1502
+ }
1503
+ var storeFieldName = this.getStoreFieldName(options);
1504
+ var fieldName = fieldNameFromStoreName(storeFieldName);
1505
+ var existing = context.store.getFieldValue(objectOrReference, storeFieldName);
1506
+ var policy = this.getFieldPolicy(options.typename, fieldName, false);
1507
+ var read = policy && policy.read;
1508
+ if (read) {
1509
+ var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context, context.store.getStorage(utilities.isReference(objectOrReference)
1510
+ ? objectOrReference.__ref
1511
+ : objectOrReference, storeFieldName));
1512
+ return cacheSlot.withValue(this.cache, read, [existing, readOptions]);
1513
+ }
1514
+ return existing;
1515
+ };
1516
+ Policies.prototype.getReadFunction = function (typename, fieldName) {
1517
+ var policy = this.getFieldPolicy(typename, fieldName, false);
1518
+ return policy && policy.read;
1519
+ };
1520
+ Policies.prototype.getMergeFunction = function (parentTypename, fieldName, childTypename) {
1521
+ var policy = this.getFieldPolicy(parentTypename, fieldName, false);
1522
+ var merge = policy && policy.merge;
1523
+ if (!merge && childTypename) {
1524
+ policy = this.getTypePolicy(childTypename);
1525
+ merge = policy && policy.merge;
1526
+ }
1527
+ return merge;
1528
+ };
1529
+ Policies.prototype.runMergeFunction = function (existing, incoming, _a, context, storage) {
1530
+ var field = _a.field, typename = _a.typename, merge = _a.merge;
1531
+ if (merge === mergeTrueFn) {
1532
+ return makeMergeObjectsFunction(context.store)(existing, incoming);
1533
+ }
1534
+ if (merge === mergeFalseFn) {
1535
+ return incoming;
1536
+ }
1537
+ if (context.overwrite) {
1538
+ existing = void 0;
1539
+ }
1540
+ return merge(existing, incoming, makeFieldFunctionOptions(this, void 0, { typename: typename, fieldName: field.name.value, field: field, variables: context.variables }, context, storage || Object.create(null)));
1541
+ };
1542
+ return Policies;
1543
+ }());
1544
+ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, context, storage) {
1545
+ var storeFieldName = policies.getStoreFieldName(fieldSpec);
1546
+ var fieldName = fieldNameFromStoreName(storeFieldName);
1547
+ var variables = fieldSpec.variables || context.variables;
1548
+ var _a = context.store, toReference = _a.toReference, canRead = _a.canRead;
1549
+ return {
1550
+ args: argsFromFieldSpecifier(fieldSpec),
1551
+ field: fieldSpec.field || null,
1552
+ fieldName: fieldName,
1553
+ storeFieldName: storeFieldName,
1554
+ variables: variables,
1555
+ isReference: utilities.isReference,
1556
+ toReference: toReference,
1557
+ storage: storage,
1558
+ cache: policies.cache,
1559
+ canRead: canRead,
1560
+ readField: function () {
1561
+ return policies.readField(normalizeReadFieldOptions(arguments, objectOrReference, variables), context);
1562
+ },
1563
+ mergeObjects: makeMergeObjectsFunction(context.store),
1564
+ };
1565
+ }
1566
+ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables) {
1567
+ var fieldNameOrOptions = readFieldArgs[0], from = readFieldArgs[1], argc = readFieldArgs.length;
1568
+ var options;
1569
+ if (typeof fieldNameOrOptions === "string") {
1570
+ options = {
1571
+ fieldName: fieldNameOrOptions,
1572
+ from: argc > 1 ? from : objectOrReference,
1573
+ };
1574
+ }
1575
+ else {
1576
+ options = tslib.__assign({}, fieldNameOrOptions);
1577
+ if (!hasOwn.call(options, "from")) {
1578
+ options.from = objectOrReference;
1579
+ }
1580
+ }
1581
+ if (globals.__DEV__ && options.from === void 0) {
1582
+ globals.__DEV__ && globals.invariant.warn("Undefined 'from' passed to readField with arguments ".concat(utilities.stringifyForDisplay(Array.from(readFieldArgs))));
1583
+ }
1584
+ if (void 0 === options.variables) {
1585
+ options.variables = variables;
1586
+ }
1587
+ return options;
1588
+ }
1589
+ function makeMergeObjectsFunction(store) {
1590
+ return function mergeObjects(existing, incoming) {
1591
+ if (isArray(existing) || isArray(incoming)) {
1592
+ throw globals.__DEV__ ? new globals.InvariantError("Cannot automatically merge arrays") : new globals.InvariantError(4);
1593
+ }
1594
+ if (utilities.isNonNullObject(existing) &&
1595
+ utilities.isNonNullObject(incoming)) {
1596
+ var eType = store.getFieldValue(existing, "__typename");
1597
+ var iType = store.getFieldValue(incoming, "__typename");
1598
+ var typesDiffer = eType && iType && eType !== iType;
1599
+ if (typesDiffer) {
1600
+ return incoming;
1601
+ }
1602
+ if (utilities.isReference(existing) &&
1603
+ storeValueIsStoreObject(incoming)) {
1604
+ store.merge(existing.__ref, incoming);
1605
+ return existing;
1606
+ }
1607
+ if (storeValueIsStoreObject(existing) &&
1608
+ utilities.isReference(incoming)) {
1609
+ store.merge(existing, incoming.__ref);
1610
+ return incoming;
1611
+ }
1612
+ if (storeValueIsStoreObject(existing) &&
1613
+ storeValueIsStoreObject(incoming)) {
1614
+ return tslib.__assign(tslib.__assign({}, existing), incoming);
1615
+ }
1616
+ }
1617
+ return incoming;
1618
+ };
1619
+ }
1620
+
1621
+ function getContextFlavor(context, clientOnly, deferred) {
1622
+ var key = "".concat(clientOnly).concat(deferred);
1623
+ var flavored = context.flavors.get(key);
1624
+ if (!flavored) {
1625
+ context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
1626
+ context.deferred === deferred) ? context : tslib.__assign(tslib.__assign({}, context), { clientOnly: clientOnly, deferred: deferred }));
1627
+ }
1628
+ return flavored;
1629
+ }
1630
+ var StoreWriter = (function () {
1631
+ function StoreWriter(cache, reader, fragments) {
1632
+ this.cache = cache;
1633
+ this.reader = reader;
1634
+ this.fragments = fragments;
1635
+ }
1636
+ StoreWriter.prototype.writeToStore = function (store, _a) {
1637
+ var _this = this;
1638
+ var query = _a.query, result = _a.result, dataId = _a.dataId, variables = _a.variables, overwrite = _a.overwrite;
1639
+ var operationDefinition = utilities.getOperationDefinition(query);
1640
+ var merger = makeProcessedFieldsMerger();
1641
+ variables = tslib.__assign(tslib.__assign({}, utilities.getDefaultValues(operationDefinition)), variables);
1642
+ var context = tslib.__assign(tslib.__assign({ store: store, written: Object.create(null), merge: function (existing, incoming) {
1643
+ return merger.merge(existing, incoming);
1644
+ }, variables: variables, varString: canonicalStringify(variables) }, extractFragmentContext(query, this.fragments)), { overwrite: !!overwrite, incomingById: new Map, clientOnly: false, deferred: false, flavors: new Map });
1645
+ var ref = this.processSelectionSet({
1646
+ result: result || Object.create(null),
1647
+ dataId: dataId,
1648
+ selectionSet: operationDefinition.selectionSet,
1649
+ mergeTree: { map: new Map },
1650
+ context: context,
1651
+ });
1652
+ if (!utilities.isReference(ref)) {
1653
+ throw globals.__DEV__ ? new globals.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new globals.InvariantError(7);
1654
+ }
1655
+ context.incomingById.forEach(function (_a, dataId) {
1656
+ var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
1657
+ var entityRef = utilities.makeReference(dataId);
1658
+ if (mergeTree && mergeTree.map.size) {
1659
+ var applied = _this.applyMerges(mergeTree, entityRef, storeObject, context);
1660
+ if (utilities.isReference(applied)) {
1661
+ return;
1662
+ }
1663
+ storeObject = applied;
1664
+ }
1665
+ if (globals.__DEV__ && !context.overwrite) {
1666
+ var fieldsWithSelectionSets_1 = Object.create(null);
1667
+ fieldNodeSet.forEach(function (field) {
1668
+ if (field.selectionSet) {
1669
+ fieldsWithSelectionSets_1[field.name.value] = true;
1670
+ }
1671
+ });
1672
+ var hasSelectionSet_1 = function (storeFieldName) {
1673
+ return fieldsWithSelectionSets_1[fieldNameFromStoreName(storeFieldName)] === true;
1674
+ };
1675
+ var hasMergeFunction_1 = function (storeFieldName) {
1676
+ var childTree = mergeTree && mergeTree.map.get(storeFieldName);
1677
+ return Boolean(childTree && childTree.info && childTree.info.merge);
1678
+ };
1679
+ Object.keys(storeObject).forEach(function (storeFieldName) {
1680
+ if (hasSelectionSet_1(storeFieldName) &&
1681
+ !hasMergeFunction_1(storeFieldName)) {
1682
+ warnAboutDataLoss(entityRef, storeObject, storeFieldName, context.store);
1683
+ }
1684
+ });
1685
+ }
1686
+ store.merge(dataId, storeObject);
1687
+ });
1688
+ store.retain(ref.__ref);
1689
+ return ref;
1690
+ };
1691
+ StoreWriter.prototype.processSelectionSet = function (_a) {
1692
+ var _this = this;
1693
+ var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context, mergeTree = _a.mergeTree;
1694
+ var policies = this.cache.policies;
1695
+ var incoming = Object.create(null);
1696
+ var typename = (dataId && policies.rootTypenamesById[dataId]) ||
1697
+ utilities.getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
1698
+ (dataId && context.store.get(dataId, "__typename"));
1699
+ if ("string" === typeof typename) {
1700
+ incoming.__typename = typename;
1701
+ }
1702
+ var readField = function () {
1703
+ var options = normalizeReadFieldOptions(arguments, incoming, context.variables);
1704
+ if (utilities.isReference(options.from)) {
1705
+ var info = context.incomingById.get(options.from.__ref);
1706
+ if (info) {
1707
+ var result_1 = policies.readField(tslib.__assign(tslib.__assign({}, options), { from: info.storeObject }), context);
1708
+ if (result_1 !== void 0) {
1709
+ return result_1;
1710
+ }
1711
+ }
1712
+ }
1713
+ return policies.readField(options, context);
1714
+ };
1715
+ var fieldNodeSet = new Set();
1716
+ this.flattenFields(selectionSet, result, context, typename).forEach(function (context, field) {
1717
+ var _a;
1718
+ var resultFieldKey = utilities.resultKeyNameFromField(field);
1719
+ var value = result[resultFieldKey];
1720
+ fieldNodeSet.add(field);
1721
+ if (value !== void 0) {
1722
+ var storeFieldName = policies.getStoreFieldName({
1723
+ typename: typename,
1724
+ fieldName: field.name.value,
1725
+ field: field,
1726
+ variables: context.variables,
1727
+ });
1728
+ var childTree = getChildMergeTree(mergeTree, storeFieldName);
1729
+ var incomingValue = _this.processFieldValue(value, field, field.selectionSet
1730
+ ? getContextFlavor(context, false, false)
1731
+ : context, childTree);
1732
+ var childTypename = void 0;
1733
+ if (field.selectionSet &&
1734
+ (utilities.isReference(incomingValue) ||
1735
+ storeValueIsStoreObject(incomingValue))) {
1736
+ childTypename = readField("__typename", incomingValue);
1737
+ }
1738
+ var merge = policies.getMergeFunction(typename, field.name.value, childTypename);
1739
+ if (merge) {
1740
+ childTree.info = {
1741
+ field: field,
1742
+ typename: typename,
1743
+ merge: merge,
1744
+ };
1745
+ }
1746
+ else {
1747
+ maybeRecycleChildMergeTree(mergeTree, storeFieldName);
1748
+ }
1749
+ incoming = context.merge(incoming, (_a = {},
1750
+ _a[storeFieldName] = incomingValue,
1751
+ _a));
1752
+ }
1753
+ else if (globals.__DEV__ &&
1754
+ !context.clientOnly &&
1755
+ !context.deferred &&
1756
+ !utilities.addTypenameToDocument.added(field) &&
1757
+ !policies.getReadFunction(typename, field.name.value)) {
1758
+ globals.__DEV__ && globals.invariant.error("Missing field '".concat(utilities.resultKeyNameFromField(field), "' while writing result ").concat(JSON.stringify(result, null, 2)).substring(0, 1000));
1759
+ }
1760
+ });
1761
+ try {
1762
+ var _b = policies.identify(result, {
1763
+ typename: typename,
1764
+ selectionSet: selectionSet,
1765
+ fragmentMap: context.fragmentMap,
1766
+ storeObject: incoming,
1767
+ readField: readField,
1768
+ }), id = _b[0], keyObject = _b[1];
1769
+ dataId = dataId || id;
1770
+ if (keyObject) {
1771
+ incoming = context.merge(incoming, keyObject);
1772
+ }
1773
+ }
1774
+ catch (e) {
1775
+ if (!dataId)
1776
+ throw e;
1777
+ }
1778
+ if ("string" === typeof dataId) {
1779
+ var dataRef = utilities.makeReference(dataId);
1780
+ var sets = context.written[dataId] || (context.written[dataId] = []);
1781
+ if (sets.indexOf(selectionSet) >= 0)
1782
+ return dataRef;
1783
+ sets.push(selectionSet);
1784
+ if (this.reader && this.reader.isFresh(result, dataRef, selectionSet, context)) {
1785
+ return dataRef;
1786
+ }
1787
+ var previous_1 = context.incomingById.get(dataId);
1788
+ if (previous_1) {
1789
+ previous_1.storeObject = context.merge(previous_1.storeObject, incoming);
1790
+ previous_1.mergeTree = mergeMergeTrees(previous_1.mergeTree, mergeTree);
1791
+ fieldNodeSet.forEach(function (field) { return previous_1.fieldNodeSet.add(field); });
1792
+ }
1793
+ else {
1794
+ context.incomingById.set(dataId, {
1795
+ storeObject: incoming,
1796
+ mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
1797
+ fieldNodeSet: fieldNodeSet,
1798
+ });
1799
+ }
1800
+ return dataRef;
1801
+ }
1802
+ return incoming;
1803
+ };
1804
+ StoreWriter.prototype.processFieldValue = function (value, field, context, mergeTree) {
1805
+ var _this = this;
1806
+ if (!field.selectionSet || value === null) {
1807
+ return globals.__DEV__ ? utilities.cloneDeep(value) : value;
1808
+ }
1809
+ if (isArray(value)) {
1810
+ return value.map(function (item, i) {
1811
+ var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
1812
+ maybeRecycleChildMergeTree(mergeTree, i);
1813
+ return value;
1814
+ });
1815
+ }
1816
+ return this.processSelectionSet({
1817
+ result: value,
1818
+ selectionSet: field.selectionSet,
1819
+ context: context,
1820
+ mergeTree: mergeTree,
1821
+ });
1822
+ };
1823
+ StoreWriter.prototype.flattenFields = function (selectionSet, result, context, typename) {
1824
+ if (typename === void 0) { typename = utilities.getTypenameFromResult(result, selectionSet, context.fragmentMap); }
1825
+ var fieldMap = new Map();
1826
+ var policies = this.cache.policies;
1827
+ var limitingTrie = new trie.Trie(false);
1828
+ (function flatten(selectionSet, inheritedContext) {
1829
+ var visitedNode = limitingTrie.lookup(selectionSet, inheritedContext.clientOnly, inheritedContext.deferred);
1830
+ if (visitedNode.visited)
1831
+ return;
1832
+ visitedNode.visited = true;
1833
+ selectionSet.selections.forEach(function (selection) {
1834
+ if (!utilities.shouldInclude(selection, context.variables))
1835
+ return;
1836
+ var clientOnly = inheritedContext.clientOnly, deferred = inheritedContext.deferred;
1837
+ if (!(clientOnly && deferred) &&
1838
+ utilities.isNonEmptyArray(selection.directives)) {
1839
+ selection.directives.forEach(function (dir) {
1840
+ var name = dir.name.value;
1841
+ if (name === "client")
1842
+ clientOnly = true;
1843
+ if (name === "defer") {
1844
+ var args = utilities.argumentsObjectFromField(dir, context.variables);
1845
+ if (!args || args.if !== false) {
1846
+ deferred = true;
1847
+ }
1848
+ }
1849
+ });
1850
+ }
1851
+ if (utilities.isField(selection)) {
1852
+ var existing = fieldMap.get(selection);
1853
+ if (existing) {
1854
+ clientOnly = clientOnly && existing.clientOnly;
1855
+ deferred = deferred && existing.deferred;
1856
+ }
1857
+ fieldMap.set(selection, getContextFlavor(context, clientOnly, deferred));
1858
+ }
1859
+ else {
1860
+ var fragment = utilities.getFragmentFromSelection(selection, context.lookupFragment);
1861
+ if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
1862
+ throw globals.__DEV__ ? new globals.InvariantError("No fragment named ".concat(selection.name.value)) : new globals.InvariantError(8);
1863
+ }
1864
+ if (fragment &&
1865
+ policies.fragmentMatches(fragment, typename, result, context.variables)) {
1866
+ flatten(fragment.selectionSet, getContextFlavor(context, clientOnly, deferred));
1867
+ }
1868
+ }
1869
+ });
1870
+ })(selectionSet, context);
1871
+ return fieldMap;
1872
+ };
1873
+ StoreWriter.prototype.applyMerges = function (mergeTree, existing, incoming, context, getStorageArgs) {
1874
+ var _a;
1875
+ var _this = this;
1876
+ if (mergeTree.map.size && !utilities.isReference(incoming)) {
1877
+ var e_1 = (!isArray(incoming) &&
1878
+ (utilities.isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
1879
+ var i_1 = incoming;
1880
+ if (e_1 && !getStorageArgs) {
1881
+ getStorageArgs = [utilities.isReference(e_1) ? e_1.__ref : e_1];
1882
+ }
1883
+ var changedFields_1;
1884
+ var getValue_1 = function (from, name) {
1885
+ return isArray(from)
1886
+ ? (typeof name === "number" ? from[name] : void 0)
1887
+ : context.store.getFieldValue(from, String(name));
1888
+ };
1889
+ mergeTree.map.forEach(function (childTree, storeFieldName) {
1890
+ var eVal = getValue_1(e_1, storeFieldName);
1891
+ var iVal = getValue_1(i_1, storeFieldName);
1892
+ if (void 0 === iVal)
1893
+ return;
1894
+ if (getStorageArgs) {
1895
+ getStorageArgs.push(storeFieldName);
1896
+ }
1897
+ var aVal = _this.applyMerges(childTree, eVal, iVal, context, getStorageArgs);
1898
+ if (aVal !== iVal) {
1899
+ changedFields_1 = changedFields_1 || new Map;
1900
+ changedFields_1.set(storeFieldName, aVal);
1901
+ }
1902
+ if (getStorageArgs) {
1903
+ globals.invariant(getStorageArgs.pop() === storeFieldName);
1904
+ }
1905
+ });
1906
+ if (changedFields_1) {
1907
+ incoming = (isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
1908
+ changedFields_1.forEach(function (value, name) {
1909
+ incoming[name] = value;
1910
+ });
1911
+ }
1912
+ }
1913
+ if (mergeTree.info) {
1914
+ return this.cache.policies.runMergeFunction(existing, incoming, mergeTree.info, context, getStorageArgs && (_a = context.store).getStorage.apply(_a, getStorageArgs));
1915
+ }
1916
+ return incoming;
1917
+ };
1918
+ return StoreWriter;
1919
+ }());
1920
+ var emptyMergeTreePool = [];
1921
+ function getChildMergeTree(_a, name) {
1922
+ var map = _a.map;
1923
+ if (!map.has(name)) {
1924
+ map.set(name, emptyMergeTreePool.pop() || { map: new Map });
1925
+ }
1926
+ return map.get(name);
1927
+ }
1928
+ function mergeMergeTrees(left, right) {
1929
+ if (left === right || !right || mergeTreeIsEmpty(right))
1930
+ return left;
1931
+ if (!left || mergeTreeIsEmpty(left))
1932
+ return right;
1933
+ var info = left.info && right.info ? tslib.__assign(tslib.__assign({}, left.info), right.info) : left.info || right.info;
1934
+ var needToMergeMaps = left.map.size && right.map.size;
1935
+ var map = needToMergeMaps ? new Map :
1936
+ left.map.size ? left.map : right.map;
1937
+ var merged = { info: info, map: map };
1938
+ if (needToMergeMaps) {
1939
+ var remainingRightKeys_1 = new Set(right.map.keys());
1940
+ left.map.forEach(function (leftTree, key) {
1941
+ merged.map.set(key, mergeMergeTrees(leftTree, right.map.get(key)));
1942
+ remainingRightKeys_1.delete(key);
1943
+ });
1944
+ remainingRightKeys_1.forEach(function (key) {
1945
+ merged.map.set(key, mergeMergeTrees(right.map.get(key), left.map.get(key)));
1946
+ });
1947
+ }
1948
+ return merged;
1949
+ }
1950
+ function mergeTreeIsEmpty(tree) {
1951
+ return !tree || !(tree.info || tree.map.size);
1952
+ }
1953
+ function maybeRecycleChildMergeTree(_a, name) {
1954
+ var map = _a.map;
1955
+ var childTree = map.get(name);
1956
+ if (childTree && mergeTreeIsEmpty(childTree)) {
1957
+ emptyMergeTreePool.push(childTree);
1958
+ map.delete(name);
1959
+ }
1960
+ }
1961
+ var warnings = new Set();
1962
+ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
1963
+ var getChild = function (objOrRef) {
1964
+ var child = store.getFieldValue(objOrRef, storeFieldName);
1965
+ return typeof child === "object" && child;
1966
+ };
1967
+ var existing = getChild(existingRef);
1968
+ if (!existing)
1969
+ return;
1970
+ var incoming = getChild(incomingObj);
1971
+ if (!incoming)
1972
+ return;
1973
+ if (utilities.isReference(existing))
1974
+ return;
1975
+ if (equality.equal(existing, incoming))
1976
+ return;
1977
+ if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
1978
+ return;
1979
+ }
1980
+ var parentType = store.getFieldValue(existingRef, "__typename") ||
1981
+ store.getFieldValue(incomingObj, "__typename");
1982
+ var fieldName = fieldNameFromStoreName(storeFieldName);
1983
+ var typeDotName = "".concat(parentType, ".").concat(fieldName);
1984
+ if (warnings.has(typeDotName))
1985
+ return;
1986
+ warnings.add(typeDotName);
1987
+ var childTypenames = [];
1988
+ if (!isArray(existing) &&
1989
+ !isArray(incoming)) {
1990
+ [existing, incoming].forEach(function (child) {
1991
+ var typename = store.getFieldValue(child, "__typename");
1992
+ if (typeof typename === "string" &&
1993
+ !childTypenames.includes(typename)) {
1994
+ childTypenames.push(typename);
1995
+ }
1996
+ });
1997
+ }
1998
+ globals.__DEV__ && globals.invariant.warn("Cache data may be lost when replacing the ".concat(fieldName, " field of a ").concat(parentType, " object.\n\nTo address this problem (which is not a bug in Apollo Client), ").concat(childTypenames.length
1999
+ ? "either ensure all objects of type " +
2000
+ childTypenames.join(" and ") + " have an ID or a custom merge function, or "
2001
+ : "", "define a custom merge function for the ").concat(typeDotName, " field, so InMemoryCache can safely merge these objects:\n\n existing: ").concat(JSON.stringify(existing).slice(0, 1000), "\n incoming: ").concat(JSON.stringify(incoming).slice(0, 1000), "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n"));
2002
+ }
2003
+
2004
+ var InMemoryCache = (function (_super) {
2005
+ tslib.__extends(InMemoryCache, _super);
2006
+ function InMemoryCache(config) {
2007
+ if (config === void 0) { config = {}; }
2008
+ var _this = _super.call(this) || this;
2009
+ _this.watches = new Set();
2010
+ _this.typenameDocumentCache = new Map();
2011
+ _this.makeVar = makeVar;
2012
+ _this.txCount = 0;
2013
+ _this.config = normalizeConfig(config);
2014
+ _this.addTypename = !!_this.config.addTypename;
2015
+ _this.policies = new Policies({
2016
+ cache: _this,
2017
+ dataIdFromObject: _this.config.dataIdFromObject,
2018
+ possibleTypes: _this.config.possibleTypes,
2019
+ typePolicies: _this.config.typePolicies,
2020
+ });
2021
+ _this.init();
2022
+ return _this;
2023
+ }
2024
+ InMemoryCache.prototype.init = function () {
2025
+ var rootStore = this.data = new exports.EntityStore.Root({
2026
+ policies: this.policies,
2027
+ resultCaching: this.config.resultCaching,
2028
+ });
2029
+ this.optimisticData = rootStore.stump;
2030
+ this.resetResultCache();
2031
+ };
2032
+ InMemoryCache.prototype.resetResultCache = function (resetResultIdentities) {
2033
+ var _this = this;
2034
+ var previousReader = this.storeReader;
2035
+ var fragments = this.config.fragments;
2036
+ this.storeWriter = new StoreWriter(this, this.storeReader = new StoreReader({
2037
+ cache: this,
2038
+ addTypename: this.addTypename,
2039
+ resultCacheMaxSize: this.config.resultCacheMaxSize,
2040
+ canonizeResults: shouldCanonizeResults(this.config),
2041
+ canon: resetResultIdentities
2042
+ ? void 0
2043
+ : previousReader && previousReader.canon,
2044
+ fragments: fragments,
2045
+ }), fragments);
2046
+ this.maybeBroadcastWatch = optimism.wrap(function (c, options) {
2047
+ return _this.broadcastWatch(c, options);
2048
+ }, {
2049
+ max: this.config.resultCacheMaxSize,
2050
+ makeCacheKey: function (c) {
2051
+ var store = c.optimistic ? _this.optimisticData : _this.data;
2052
+ if (supportsResultCaching(store)) {
2053
+ var optimistic = c.optimistic, id = c.id, variables = c.variables;
2054
+ return store.makeCacheKey(c.query, c.callback, canonicalStringify({ optimistic: optimistic, id: id, variables: variables }));
2055
+ }
2056
+ }
2057
+ });
2058
+ new Set([
2059
+ this.data.group,
2060
+ this.optimisticData.group,
2061
+ ]).forEach(function (group) { return group.resetCaching(); });
2062
+ };
2063
+ InMemoryCache.prototype.restore = function (data) {
2064
+ this.init();
2065
+ if (data)
2066
+ this.data.replace(data);
2067
+ return this;
2068
+ };
2069
+ InMemoryCache.prototype.extract = function (optimistic) {
2070
+ if (optimistic === void 0) { optimistic = false; }
2071
+ return (optimistic ? this.optimisticData : this.data).extract();
2072
+ };
2073
+ InMemoryCache.prototype.read = function (options) {
2074
+ var _a = options.returnPartialData, returnPartialData = _a === void 0 ? false : _a;
2075
+ try {
2076
+ return this.storeReader.diffQueryAgainstStore(tslib.__assign(tslib.__assign({}, options), { store: options.optimistic ? this.optimisticData : this.data, config: this.config, returnPartialData: returnPartialData })).result || null;
2077
+ }
2078
+ catch (e) {
2079
+ if (e instanceof MissingFieldError) {
2080
+ return null;
2081
+ }
2082
+ throw e;
2083
+ }
2084
+ };
2085
+ InMemoryCache.prototype.write = function (options) {
2086
+ try {
2087
+ ++this.txCount;
2088
+ return this.storeWriter.writeToStore(this.data, options);
2089
+ }
2090
+ finally {
2091
+ if (!--this.txCount && options.broadcast !== false) {
2092
+ this.broadcastWatches();
2093
+ }
2094
+ }
2095
+ };
2096
+ InMemoryCache.prototype.modify = function (options) {
2097
+ if (hasOwn.call(options, "id") && !options.id) {
2098
+ return false;
2099
+ }
2100
+ var store = options.optimistic
2101
+ ? this.optimisticData
2102
+ : this.data;
2103
+ try {
2104
+ ++this.txCount;
2105
+ return store.modify(options.id || "ROOT_QUERY", options.fields);
2106
+ }
2107
+ finally {
2108
+ if (!--this.txCount && options.broadcast !== false) {
2109
+ this.broadcastWatches();
2110
+ }
2111
+ }
2112
+ };
2113
+ InMemoryCache.prototype.diff = function (options) {
2114
+ return this.storeReader.diffQueryAgainstStore(tslib.__assign(tslib.__assign({}, options), { store: options.optimistic ? this.optimisticData : this.data, rootId: options.id || "ROOT_QUERY", config: this.config }));
2115
+ };
2116
+ InMemoryCache.prototype.watch = function (watch) {
2117
+ var _this = this;
2118
+ if (!this.watches.size) {
2119
+ recallCache(this);
2120
+ }
2121
+ this.watches.add(watch);
2122
+ if (watch.immediate) {
2123
+ this.maybeBroadcastWatch(watch);
2124
+ }
2125
+ return function () {
2126
+ if (_this.watches.delete(watch) && !_this.watches.size) {
2127
+ forgetCache(_this);
2128
+ }
2129
+ _this.maybeBroadcastWatch.forget(watch);
2130
+ };
2131
+ };
2132
+ InMemoryCache.prototype.gc = function (options) {
2133
+ canonicalStringify.reset();
2134
+ var ids = this.optimisticData.gc();
2135
+ if (options && !this.txCount) {
2136
+ if (options.resetResultCache) {
2137
+ this.resetResultCache(options.resetResultIdentities);
2138
+ }
2139
+ else if (options.resetResultIdentities) {
2140
+ this.storeReader.resetCanon();
2141
+ }
2142
+ }
2143
+ return ids;
2144
+ };
2145
+ InMemoryCache.prototype.retain = function (rootId, optimistic) {
2146
+ return (optimistic ? this.optimisticData : this.data).retain(rootId);
2147
+ };
2148
+ InMemoryCache.prototype.release = function (rootId, optimistic) {
2149
+ return (optimistic ? this.optimisticData : this.data).release(rootId);
2150
+ };
2151
+ InMemoryCache.prototype.identify = function (object) {
2152
+ if (utilities.isReference(object))
2153
+ return object.__ref;
2154
+ try {
2155
+ return this.policies.identify(object)[0];
2156
+ }
2157
+ catch (e) {
2158
+ globals.__DEV__ && globals.invariant.warn(e);
2159
+ }
2160
+ };
2161
+ InMemoryCache.prototype.evict = function (options) {
2162
+ if (!options.id) {
2163
+ if (hasOwn.call(options, "id")) {
2164
+ return false;
2165
+ }
2166
+ options = tslib.__assign(tslib.__assign({}, options), { id: "ROOT_QUERY" });
2167
+ }
2168
+ try {
2169
+ ++this.txCount;
2170
+ return this.optimisticData.evict(options, this.data);
2171
+ }
2172
+ finally {
2173
+ if (!--this.txCount && options.broadcast !== false) {
2174
+ this.broadcastWatches();
2175
+ }
2176
+ }
2177
+ };
2178
+ InMemoryCache.prototype.reset = function (options) {
2179
+ var _this = this;
2180
+ this.init();
2181
+ canonicalStringify.reset();
2182
+ if (options && options.discardWatches) {
2183
+ this.watches.forEach(function (watch) { return _this.maybeBroadcastWatch.forget(watch); });
2184
+ this.watches.clear();
2185
+ forgetCache(this);
2186
+ }
2187
+ else {
2188
+ this.broadcastWatches();
2189
+ }
2190
+ return Promise.resolve();
2191
+ };
2192
+ InMemoryCache.prototype.removeOptimistic = function (idToRemove) {
2193
+ var newOptimisticData = this.optimisticData.removeLayer(idToRemove);
2194
+ if (newOptimisticData !== this.optimisticData) {
2195
+ this.optimisticData = newOptimisticData;
2196
+ this.broadcastWatches();
2197
+ }
2198
+ };
2199
+ InMemoryCache.prototype.batch = function (options) {
2200
+ var _this = this;
2201
+ var update = options.update, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, removeOptimistic = options.removeOptimistic, onWatchUpdated = options.onWatchUpdated;
2202
+ var updateResult;
2203
+ var perform = function (layer) {
2204
+ var _a = _this, data = _a.data, optimisticData = _a.optimisticData;
2205
+ ++_this.txCount;
2206
+ if (layer) {
2207
+ _this.data = _this.optimisticData = layer;
2208
+ }
2209
+ try {
2210
+ return updateResult = update(_this);
2211
+ }
2212
+ finally {
2213
+ --_this.txCount;
2214
+ _this.data = data;
2215
+ _this.optimisticData = optimisticData;
2216
+ }
2217
+ };
2218
+ var alreadyDirty = new Set();
2219
+ if (onWatchUpdated && !this.txCount) {
2220
+ this.broadcastWatches(tslib.__assign(tslib.__assign({}, options), { onWatchUpdated: function (watch) {
2221
+ alreadyDirty.add(watch);
2222
+ return false;
2223
+ } }));
2224
+ }
2225
+ if (typeof optimistic === 'string') {
2226
+ this.optimisticData = this.optimisticData.addLayer(optimistic, perform);
2227
+ }
2228
+ else if (optimistic === false) {
2229
+ perform(this.data);
2230
+ }
2231
+ else {
2232
+ perform();
2233
+ }
2234
+ if (typeof removeOptimistic === "string") {
2235
+ this.optimisticData = this.optimisticData.removeLayer(removeOptimistic);
2236
+ }
2237
+ if (onWatchUpdated && alreadyDirty.size) {
2238
+ this.broadcastWatches(tslib.__assign(tslib.__assign({}, options), { onWatchUpdated: function (watch, diff) {
2239
+ var result = onWatchUpdated.call(this, watch, diff);
2240
+ if (result !== false) {
2241
+ alreadyDirty.delete(watch);
2242
+ }
2243
+ return result;
2244
+ } }));
2245
+ if (alreadyDirty.size) {
2246
+ alreadyDirty.forEach(function (watch) { return _this.maybeBroadcastWatch.dirty(watch); });
2247
+ }
2248
+ }
2249
+ else {
2250
+ this.broadcastWatches(options);
2251
+ }
2252
+ return updateResult;
2253
+ };
2254
+ InMemoryCache.prototype.performTransaction = function (update, optimisticId) {
2255
+ return this.batch({
2256
+ update: update,
2257
+ optimistic: optimisticId || (optimisticId !== null),
2258
+ });
2259
+ };
2260
+ InMemoryCache.prototype.transformDocument = function (document) {
2261
+ if (this.addTypename) {
2262
+ var result = this.typenameDocumentCache.get(document);
2263
+ if (!result) {
2264
+ result = utilities.addTypenameToDocument(document);
2265
+ this.typenameDocumentCache.set(document, result);
2266
+ this.typenameDocumentCache.set(result, result);
2267
+ }
2268
+ return result;
2269
+ }
2270
+ return document;
2271
+ };
2272
+ InMemoryCache.prototype.transformForLink = function (document) {
2273
+ var fragments = this.config.fragments;
2274
+ return fragments
2275
+ ? fragments.transform(document)
2276
+ : document;
2277
+ };
2278
+ InMemoryCache.prototype.broadcastWatches = function (options) {
2279
+ var _this = this;
2280
+ if (!this.txCount) {
2281
+ this.watches.forEach(function (c) { return _this.maybeBroadcastWatch(c, options); });
2282
+ }
2283
+ };
2284
+ InMemoryCache.prototype.broadcastWatch = function (c, options) {
2285
+ var lastDiff = c.lastDiff;
2286
+ var diff = this.diff(c);
2287
+ if (options) {
2288
+ if (c.optimistic &&
2289
+ typeof options.optimistic === "string") {
2290
+ diff.fromOptimisticTransaction = true;
2291
+ }
2292
+ if (options.onWatchUpdated &&
2293
+ options.onWatchUpdated.call(this, c, diff, lastDiff) === false) {
2294
+ return;
2295
+ }
2296
+ }
2297
+ if (!lastDiff || !equality.equal(lastDiff.result, diff.result)) {
2298
+ c.callback(c.lastDiff = diff, lastDiff);
2299
+ }
2300
+ };
2301
+ return InMemoryCache;
2302
+ }(ApolloCache));
2303
+
2304
+ function createFragmentRegistry() {
2305
+ var fragments = [];
2306
+ for (var _i = 0; _i < arguments.length; _i++) {
2307
+ fragments[_i] = arguments[_i];
2308
+ }
2309
+ return new (FragmentRegistry.bind.apply(FragmentRegistry, tslib.__spreadArray([void 0], fragments, false)))();
2310
+ }
2311
+ var arrayLikeForEach = Array.prototype.forEach;
2312
+ var FragmentRegistry = (function () {
2313
+ function FragmentRegistry() {
2314
+ var fragments = [];
2315
+ for (var _i = 0; _i < arguments.length; _i++) {
2316
+ fragments[_i] = arguments[_i];
2317
+ }
2318
+ this.registry = Object.create(null);
2319
+ this.resetCaches();
2320
+ if (fragments.length) {
2321
+ this.register.apply(this, fragments);
2322
+ }
2323
+ }
2324
+ FragmentRegistry.prototype.register = function () {
2325
+ var _this = this;
2326
+ var definitions = new Map();
2327
+ arrayLikeForEach.call(arguments, function (doc) {
2328
+ utilities.getFragmentDefinitions(doc).forEach(function (node) {
2329
+ definitions.set(node.name.value, node);
2330
+ });
2331
+ });
2332
+ definitions.forEach(function (node, name) {
2333
+ if (node !== _this.registry[name]) {
2334
+ _this.registry[name] = node;
2335
+ _this.invalidate(name);
2336
+ }
2337
+ });
2338
+ return this;
2339
+ };
2340
+ FragmentRegistry.prototype.invalidate = function (name) { };
2341
+ FragmentRegistry.prototype.resetCaches = function () {
2342
+ this.invalidate = (this.lookup = this.cacheUnaryMethod("lookup")).dirty;
2343
+ this.transform = this.cacheUnaryMethod("transform");
2344
+ this.findFragmentSpreads = this.cacheUnaryMethod("findFragmentSpreads");
2345
+ };
2346
+ FragmentRegistry.prototype.cacheUnaryMethod = function (name) {
2347
+ var registry = this;
2348
+ var originalMethod = FragmentRegistry.prototype[name];
2349
+ return optimism.wrap(function () {
2350
+ return originalMethod.apply(registry, arguments);
2351
+ }, {
2352
+ makeCacheKey: function (arg) { return arg; },
2353
+ });
2354
+ };
2355
+ FragmentRegistry.prototype.lookup = function (fragmentName) {
2356
+ return this.registry[fragmentName] || null;
2357
+ };
2358
+ FragmentRegistry.prototype.transform = function (document) {
2359
+ var _this = this;
2360
+ var defined = new Map();
2361
+ utilities.getFragmentDefinitions(document).forEach(function (def) {
2362
+ defined.set(def.name.value, def);
2363
+ });
2364
+ var unbound = new Set();
2365
+ var enqueue = function (spreadName) {
2366
+ if (!defined.has(spreadName)) {
2367
+ unbound.add(spreadName);
2368
+ }
2369
+ };
2370
+ var enqueueChildSpreads = function (node) { return Object.keys(_this.findFragmentSpreads(node)).forEach(enqueue); };
2371
+ enqueueChildSpreads(document);
2372
+ var missing = [];
2373
+ var map = Object.create(null);
2374
+ unbound.forEach(function (fragmentName) {
2375
+ var knownFragmentDef = defined.get(fragmentName);
2376
+ if (knownFragmentDef) {
2377
+ enqueueChildSpreads(map[fragmentName] = knownFragmentDef);
2378
+ }
2379
+ else {
2380
+ missing.push(fragmentName);
2381
+ var def = _this.lookup(fragmentName);
2382
+ if (def) {
2383
+ enqueueChildSpreads(map[fragmentName] = def);
2384
+ }
2385
+ }
2386
+ });
2387
+ if (missing.length) {
2388
+ var defsToAppend_1 = [];
2389
+ missing.forEach(function (name) {
2390
+ var def = map[name];
2391
+ if (def) {
2392
+ defsToAppend_1.push(def);
2393
+ }
2394
+ });
2395
+ if (defsToAppend_1.length) {
2396
+ document = tslib.__assign(tslib.__assign({}, document), { definitions: document.definitions.concat(defsToAppend_1) });
2397
+ }
2398
+ }
2399
+ return document;
2400
+ };
2401
+ FragmentRegistry.prototype.findFragmentSpreads = function (root) {
2402
+ var spreads = Object.create(null);
2403
+ graphql.visit(root, {
2404
+ FragmentSpread: function (node) {
2405
+ spreads[node.name.value] = node;
2406
+ },
2407
+ });
2408
+ return spreads;
2409
+ };
2410
+ return FragmentRegistry;
2411
+ }());
2412
+
2413
+ exports.isReference = utilities.isReference;
2414
+ exports.makeReference = utilities.makeReference;
2415
+ exports.ApolloCache = ApolloCache;
2416
+ exports.InMemoryCache = InMemoryCache;
2417
+ exports.MissingFieldError = MissingFieldError;
2418
+ exports.Policies = Policies;
2419
+ exports.cacheSlot = cacheSlot;
2420
+ exports.canonicalStringify = canonicalStringify;
2421
+ exports.createFragmentRegistry = createFragmentRegistry;
2422
+ exports.defaultDataIdFromObject = defaultDataIdFromObject;
2423
+ exports.fieldNameFromStoreName = fieldNameFromStoreName;
2424
+ exports.makeVar = makeVar;
2425
+ //# sourceMappingURL=cache.cjs.map