@apollo/client 3.8.0 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (443) hide show
  1. package/apollo-client.cjs +715 -587
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +253 -191
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +253 -191
  7. package/cache/core/cache.d.ts +4 -4
  8. package/cache/core/cache.d.ts.map +1 -1
  9. package/cache/core/cache.js +10 -7
  10. package/cache/core/cache.js.map +1 -1
  11. package/cache/core/types/Cache.d.ts +3 -3
  12. package/cache/core/types/Cache.d.ts.map +1 -1
  13. package/cache/core/types/Cache.js +0 -1
  14. package/cache/core/types/Cache.js.map +1 -1
  15. package/cache/core/types/DataProxy.d.ts +6 -6
  16. package/cache/core/types/DataProxy.d.ts.map +1 -1
  17. package/cache/core/types/DataProxy.js.map +1 -1
  18. package/cache/core/types/common.d.ts +3 -3
  19. package/cache/core/types/common.d.ts.map +1 -1
  20. package/cache/core/types/common.js.map +1 -1
  21. package/cache/index.d.ts +20 -20
  22. package/cache/index.d.ts.map +1 -1
  23. package/cache/index.js +13 -13
  24. package/cache/index.js.map +1 -1
  25. package/cache/inmemory/entityStore.d.ts +6 -6
  26. package/cache/inmemory/entityStore.d.ts.map +1 -1
  27. package/cache/inmemory/entityStore.js +38 -30
  28. package/cache/inmemory/entityStore.js.map +1 -1
  29. package/cache/inmemory/fixPolyfills.native.d.ts.map +1 -1
  30. package/cache/inmemory/fixPolyfills.native.js +10 -9
  31. package/cache/inmemory/fixPolyfills.native.js.map +1 -1
  32. package/cache/inmemory/fragmentRegistry.d.ts.map +1 -1
  33. package/cache/inmemory/fragmentRegistry.js +6 -4
  34. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  35. package/cache/inmemory/helpers.d.ts +6 -6
  36. package/cache/inmemory/helpers.d.ts.map +1 -1
  37. package/cache/inmemory/helpers.js +16 -14
  38. package/cache/inmemory/helpers.js.map +1 -1
  39. package/cache/inmemory/inMemoryCache.d.ts +9 -9
  40. package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
  41. package/cache/inmemory/inMemoryCache.js +29 -33
  42. package/cache/inmemory/inMemoryCache.js.map +1 -1
  43. package/cache/inmemory/key-extractor.d.ts.map +1 -1
  44. package/cache/inmemory/key-extractor.js +55 -49
  45. package/cache/inmemory/key-extractor.js.map +1 -1
  46. package/cache/inmemory/object-canon.d.ts.map +1 -1
  47. package/cache/inmemory/object-canon.js +5 -5
  48. package/cache/inmemory/object-canon.js.map +1 -1
  49. package/cache/inmemory/policies.d.ts +6 -6
  50. package/cache/inmemory/policies.d.ts.map +1 -1
  51. package/cache/inmemory/policies.js +74 -45
  52. package/cache/inmemory/policies.js.map +1 -1
  53. package/cache/inmemory/reactiveVars.d.ts +1 -1
  54. package/cache/inmemory/reactiveVars.d.ts.map +1 -1
  55. package/cache/inmemory/reactiveVars.js +5 -5
  56. package/cache/inmemory/reactiveVars.js.map +1 -1
  57. package/cache/inmemory/readFromStore.d.ts +7 -7
  58. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  59. package/cache/inmemory/readFromStore.js +21 -17
  60. package/cache/inmemory/readFromStore.js.map +1 -1
  61. package/cache/inmemory/types.d.ts +7 -7
  62. package/cache/inmemory/types.d.ts.map +1 -1
  63. package/cache/inmemory/types.js +0 -2
  64. package/cache/inmemory/types.js.map +1 -1
  65. package/cache/inmemory/writeToStore.d.ts +7 -7
  66. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  67. package/cache/inmemory/writeToStore.js +40 -30
  68. package/cache/inmemory/writeToStore.js.map +1 -1
  69. package/config/jest/setup.d.ts +2 -2
  70. package/config/jest/setup.js +5 -5
  71. package/config/jest/setup.js.map +1 -1
  72. package/core/ApolloClient.d.ts +11 -11
  73. package/core/ApolloClient.d.ts.map +1 -1
  74. package/core/ApolloClient.js +64 -50
  75. package/core/ApolloClient.js.map +1 -1
  76. package/core/LocalState.d.ts +6 -6
  77. package/core/LocalState.d.ts.map +1 -1
  78. package/core/LocalState.js +17 -16
  79. package/core/LocalState.js.map +1 -1
  80. package/core/ObservableQuery.d.ts +12 -10
  81. package/core/ObservableQuery.d.ts.map +1 -1
  82. package/core/ObservableQuery.js +57 -38
  83. package/core/ObservableQuery.js.map +1 -1
  84. package/core/QueryInfo.d.ts +11 -11
  85. package/core/QueryInfo.d.ts.map +1 -1
  86. package/core/QueryInfo.js +28 -34
  87. package/core/QueryInfo.js.map +1 -1
  88. package/core/QueryManager.d.ts +10 -10
  89. package/core/QueryManager.d.ts.map +1 -1
  90. package/core/QueryManager.js +117 -93
  91. package/core/QueryManager.js.map +1 -1
  92. package/core/core.cjs +255 -199
  93. package/core/core.cjs.map +1 -1
  94. package/core/core.cjs.native.js +255 -199
  95. package/core/networkStatus.js.map +1 -1
  96. package/core/types.d.ts +13 -13
  97. package/core/types.d.ts.map +1 -1
  98. package/core/types.js +0 -1
  99. package/core/types.js.map +1 -1
  100. package/core/watchQueryOptions.d.ts +11 -11
  101. package/core/watchQueryOptions.d.ts.map +1 -1
  102. package/core/watchQueryOptions.js.map +1 -1
  103. package/dev/dev.cjs +44 -40
  104. package/dev/dev.cjs.map +1 -1
  105. package/dev/dev.cjs.native.js +44 -40
  106. package/errors/errors.cjs +7 -5
  107. package/errors/errors.cjs.map +1 -1
  108. package/errors/errors.cjs.native.js +7 -5
  109. package/errors/index.d.ts +4 -4
  110. package/errors/index.d.ts.map +1 -1
  111. package/errors/index.js +9 -7
  112. package/errors/index.js.map +1 -1
  113. package/index.d.ts +2 -2
  114. package/index.js +2 -2
  115. package/index.js.map +1 -1
  116. package/invariantErrorCodes.d.ts.map +1 -1
  117. package/invariantErrorCodes.js +36 -36
  118. package/invariantErrorCodes.js.map +1 -1
  119. package/link/batch/batch.cjs +4 -4
  120. package/link/batch/batch.cjs.map +1 -1
  121. package/link/batch/batch.cjs.native.js +4 -4
  122. package/link/batch/batchLink.d.ts +6 -6
  123. package/link/batch/batchLink.d.ts.map +1 -1
  124. package/link/batch/batchLink.js +4 -4
  125. package/link/batch/batchLink.js.map +1 -1
  126. package/link/batch/batching.d.ts +2 -2
  127. package/link/batch/batching.d.ts.map +1 -1
  128. package/link/batch/batching.js +4 -4
  129. package/link/batch/batching.js.map +1 -1
  130. package/link/batch/index.d.ts +1 -1
  131. package/link/batch/index.js +1 -1
  132. package/link/batch/index.js.map +1 -1
  133. package/link/batch-http/batch-http.cjs +13 -11
  134. package/link/batch-http/batch-http.cjs.map +1 -1
  135. package/link/batch-http/batch-http.cjs.native.js +13 -11
  136. package/link/batch-http/batchHttpLink.d.ts +6 -6
  137. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  138. package/link/batch-http/batchHttpLink.js +17 -15
  139. package/link/batch-http/batchHttpLink.js.map +1 -1
  140. package/link/batch-http/index.d.ts +1 -1
  141. package/link/batch-http/index.js +1 -1
  142. package/link/batch-http/index.js.map +1 -1
  143. package/link/context/context.cjs.map +1 -1
  144. package/link/context/index.d.ts +3 -3
  145. package/link/context/index.js +2 -2
  146. package/link/context/index.js.map +1 -1
  147. package/link/core/ApolloLink.d.ts +3 -3
  148. package/link/core/ApolloLink.js +4 -4
  149. package/link/core/ApolloLink.js.map +1 -1
  150. package/link/core/concat.d.ts +1 -1
  151. package/link/core/concat.js +1 -1
  152. package/link/core/concat.js.map +1 -1
  153. package/link/core/core.cjs +1 -1
  154. package/link/core/core.cjs.map +1 -1
  155. package/link/core/core.cjs.native.js +1 -1
  156. package/link/core/empty.d.ts +1 -1
  157. package/link/core/empty.js +1 -1
  158. package/link/core/empty.js.map +1 -1
  159. package/link/core/execute.d.ts +1 -1
  160. package/link/core/execute.js +1 -1
  161. package/link/core/execute.js.map +1 -1
  162. package/link/core/from.d.ts +1 -1
  163. package/link/core/from.js +1 -1
  164. package/link/core/from.js.map +1 -1
  165. package/link/core/index.d.ts +8 -8
  166. package/link/core/index.js +8 -8
  167. package/link/core/index.js.map +1 -1
  168. package/link/core/split.d.ts +1 -1
  169. package/link/core/split.js +1 -1
  170. package/link/core/split.js.map +1 -1
  171. package/link/core/types.js.map +1 -1
  172. package/link/error/error.cjs.map +1 -1
  173. package/link/error/index.d.ts +5 -5
  174. package/link/error/index.js +2 -2
  175. package/link/error/index.js.map +1 -1
  176. package/link/http/HttpLink.d.ts +3 -3
  177. package/link/http/HttpLink.js +2 -2
  178. package/link/http/HttpLink.js.map +1 -1
  179. package/link/http/checkFetcher.d.ts +1 -1
  180. package/link/http/checkFetcher.d.ts.map +1 -1
  181. package/link/http/checkFetcher.js +2 -2
  182. package/link/http/checkFetcher.js.map +1 -1
  183. package/link/http/createHttpLink.d.ts +2 -2
  184. package/link/http/createHttpLink.d.ts.map +1 -1
  185. package/link/http/createHttpLink.js +27 -26
  186. package/link/http/createHttpLink.js.map +1 -1
  187. package/link/http/createSignalIfSupported.js +1 -1
  188. package/link/http/createSignalIfSupported.js.map +1 -1
  189. package/link/http/http.cjs +64 -41
  190. package/link/http/http.cjs.map +1 -1
  191. package/link/http/http.cjs.native.js +64 -41
  192. package/link/http/index.d.ts +13 -13
  193. package/link/http/index.js +10 -10
  194. package/link/http/index.js.map +1 -1
  195. package/link/http/iterators/nodeStream.d.ts.map +1 -1
  196. package/link/http/iterators/nodeStream.js.map +1 -1
  197. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  198. package/link/http/parseAndCheckHttpResponse.js +2 -2
  199. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  200. package/link/http/responseIterator.d.ts.map +1 -1
  201. package/link/http/responseIterator.js +20 -1
  202. package/link/http/responseIterator.js.map +1 -1
  203. package/link/http/rewriteURIForGET.d.ts +1 -1
  204. package/link/http/rewriteURIForGET.js +12 -12
  205. package/link/http/rewriteURIForGET.js.map +1 -1
  206. package/link/http/selectHttpOptionsAndBody.d.ts +5 -5
  207. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  208. package/link/http/selectHttpOptionsAndBody.js +8 -7
  209. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  210. package/link/http/selectURI.d.ts +1 -1
  211. package/link/http/selectURI.js +2 -2
  212. package/link/http/selectURI.js.map +1 -1
  213. package/link/http/serializeFetchParameter.d.ts +1 -1
  214. package/link/http/serializeFetchParameter.js +1 -1
  215. package/link/http/serializeFetchParameter.js.map +1 -1
  216. package/link/persisted-queries/index.d.ts +4 -4
  217. package/link/persisted-queries/index.d.ts.map +1 -1
  218. package/link/persisted-queries/index.js +26 -25
  219. package/link/persisted-queries/index.js.map +1 -1
  220. package/link/persisted-queries/persisted-queries.cjs +22 -17
  221. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  222. package/link/persisted-queries/persisted-queries.cjs.native.js +22 -17
  223. package/link/retry/delayFunction.d.ts +1 -1
  224. package/link/retry/delayFunction.js.map +1 -1
  225. package/link/retry/index.d.ts +1 -1
  226. package/link/retry/index.js +1 -1
  227. package/link/retry/index.js.map +1 -1
  228. package/link/retry/retry.cjs +2 -2
  229. package/link/retry/retry.cjs.map +1 -1
  230. package/link/retry/retry.cjs.native.js +2 -2
  231. package/link/retry/retryFunction.d.ts +1 -1
  232. package/link/retry/retryFunction.js.map +1 -1
  233. package/link/retry/retryLink.d.ts +5 -5
  234. package/link/retry/retryLink.d.ts.map +1 -1
  235. package/link/retry/retryLink.js +6 -6
  236. package/link/retry/retryLink.js.map +1 -1
  237. package/link/schema/index.d.ts +4 -4
  238. package/link/schema/index.d.ts.map +1 -1
  239. package/link/schema/index.js +13 -8
  240. package/link/schema/index.js.map +1 -1
  241. package/link/schema/schema.cjs +10 -5
  242. package/link/schema/schema.cjs.map +1 -1
  243. package/link/schema/schema.cjs.native.js +10 -5
  244. package/link/subscriptions/index.js +1 -1
  245. package/link/subscriptions/index.js.map +1 -1
  246. package/link/subscriptions/subscriptions.cjs.map +1 -1
  247. package/link/utils/createOperation.d.ts +1 -1
  248. package/link/utils/createOperation.js +3 -3
  249. package/link/utils/createOperation.js.map +1 -1
  250. package/link/utils/filterOperationVariables.d.ts +1 -1
  251. package/link/utils/filterOperationVariables.js +2 -2
  252. package/link/utils/filterOperationVariables.js.map +1 -1
  253. package/link/utils/fromError.d.ts +1 -1
  254. package/link/utils/fromError.js +1 -1
  255. package/link/utils/fromError.js.map +1 -1
  256. package/link/utils/fromPromise.d.ts +1 -1
  257. package/link/utils/fromPromise.js +1 -1
  258. package/link/utils/fromPromise.js.map +1 -1
  259. package/link/utils/index.d.ts +10 -10
  260. package/link/utils/index.js +9 -9
  261. package/link/utils/index.js.map +1 -1
  262. package/link/utils/throwServerError.js +1 -1
  263. package/link/utils/throwServerError.js.map +1 -1
  264. package/link/utils/toPromise.d.ts +1 -1
  265. package/link/utils/toPromise.js +1 -1
  266. package/link/utils/toPromise.js.map +1 -1
  267. package/link/utils/transformOperation.d.ts +1 -1
  268. package/link/utils/transformOperation.js +3 -3
  269. package/link/utils/transformOperation.js.map +1 -1
  270. package/link/utils/utils.cjs +12 -12
  271. package/link/utils/utils.cjs.map +1 -1
  272. package/link/utils/utils.cjs.native.js +12 -12
  273. package/link/utils/validateOperation.d.ts +1 -1
  274. package/link/utils/validateOperation.js +6 -6
  275. package/link/utils/validateOperation.js.map +1 -1
  276. package/link/ws/index.d.ts +5 -5
  277. package/link/ws/index.js +2 -2
  278. package/link/ws/index.js.map +1 -1
  279. package/link/ws/ws.cjs.map +1 -1
  280. package/package.json +27 -27
  281. package/react/cache/QueryReference.d.ts +1 -1
  282. package/react/cache/QueryReference.d.ts.map +1 -1
  283. package/react/cache/QueryReference.js +2 -0
  284. package/react/cache/QueryReference.js.map +1 -1
  285. package/react/hooks/constants.js +1 -1
  286. package/react/hooks/constants.js.map +1 -1
  287. package/react/hooks/hooks.cjs +10 -21
  288. package/react/hooks/hooks.cjs.map +1 -1
  289. package/react/hooks/hooks.cjs.native.js +10 -21
  290. package/react/hooks/useBackgroundQuery.d.ts +1 -1
  291. package/react/hooks/useBackgroundQuery.d.ts.map +1 -1
  292. package/react/hooks/useBackgroundQuery.js.map +1 -1
  293. package/react/hooks/useQuery.d.ts.map +1 -1
  294. package/react/hooks/useQuery.js +1 -8
  295. package/react/hooks/useQuery.js.map +1 -1
  296. package/react/hooks/useReactiveVar.d.ts.map +1 -1
  297. package/react/hooks/useReactiveVar.js +7 -12
  298. package/react/hooks/useReactiveVar.js.map +1 -1
  299. package/react/hooks/useReadQuery.d.ts +1 -1
  300. package/react/hooks/useReadQuery.d.ts.map +1 -1
  301. package/react/hooks/useReadQuery.js +1 -1
  302. package/react/hooks/useReadQuery.js.map +1 -1
  303. package/react/hooks/useSuspenseQuery.d.ts +1 -1
  304. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  305. package/react/hooks/useSuspenseQuery.js.map +1 -1
  306. package/react/react.cjs +2 -0
  307. package/react/react.cjs.map +1 -1
  308. package/react/react.cjs.native.js +2 -0
  309. package/react/types/types.js.map +1 -1
  310. package/testing/core/core.cjs +37 -28
  311. package/testing/core/core.cjs.map +1 -1
  312. package/testing/core/core.cjs.native.js +37 -28
  313. package/testing/core/itAsync.d.ts.map +1 -1
  314. package/testing/core/itAsync.js +8 -4
  315. package/testing/core/itAsync.js.map +1 -1
  316. package/testing/core/mocking/mockClient.d.ts +3 -3
  317. package/testing/core/mocking/mockClient.d.ts.map +1 -1
  318. package/testing/core/mocking/mockClient.js +6 -4
  319. package/testing/core/mocking/mockClient.js.map +1 -1
  320. package/testing/core/mocking/mockFetch.d.ts +1 -1
  321. package/testing/core/mocking/mockFetch.d.ts.map +1 -1
  322. package/testing/core/mocking/mockFetch.js +3 -3
  323. package/testing/core/mocking/mockFetch.js.map +1 -1
  324. package/testing/core/mocking/mockLink.d.ts +3 -3
  325. package/testing/core/mocking/mockLink.d.ts.map +1 -1
  326. package/testing/core/mocking/mockLink.js +24 -23
  327. package/testing/core/mocking/mockLink.js.map +1 -1
  328. package/testing/core/mocking/mockQueryManager.d.ts +2 -2
  329. package/testing/core/mocking/mockQueryManager.js +3 -3
  330. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  331. package/testing/core/mocking/mockSubscriptionLink.d.ts +3 -3
  332. package/testing/core/mocking/mockSubscriptionLink.js +4 -4
  333. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  334. package/testing/core/mocking/mockWatchQuery.d.ts +2 -2
  335. package/testing/core/mocking/mockWatchQuery.js +2 -2
  336. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  337. package/testing/core/observableToPromise.d.ts +3 -3
  338. package/testing/core/observableToPromise.d.ts.map +1 -1
  339. package/testing/core/observableToPromise.js +8 -4
  340. package/testing/core/observableToPromise.js.map +1 -1
  341. package/testing/core/subscribeAndCount.d.ts +1 -1
  342. package/testing/core/subscribeAndCount.d.ts.map +1 -1
  343. package/testing/core/subscribeAndCount.js +5 -3
  344. package/testing/core/subscribeAndCount.js.map +1 -1
  345. package/testing/core/wait.js.map +1 -1
  346. package/testing/core/withConsoleSpy.d.ts.map +1 -1
  347. package/testing/core/withConsoleSpy.js.map +1 -1
  348. package/testing/core/wrap.d.ts.map +1 -1
  349. package/testing/core/wrap.js +14 -12
  350. package/testing/core/wrap.js.map +1 -1
  351. package/testing/index.d.ts +4 -4
  352. package/testing/index.js +3 -3
  353. package/testing/index.js.map +1 -1
  354. package/testing/react/MockedProvider.d.ts +7 -7
  355. package/testing/react/MockedProvider.d.ts.map +1 -1
  356. package/testing/react/MockedProvider.js +10 -11
  357. package/testing/react/MockedProvider.js.map +1 -1
  358. package/testing/testing.cjs +3 -5
  359. package/testing/testing.cjs.map +1 -1
  360. package/testing/testing.cjs.native.js +3 -5
  361. package/utilities/common/canUse.d.ts.map +1 -1
  362. package/utilities/common/canUse.js +4 -5
  363. package/utilities/common/canUse.js.map +1 -1
  364. package/utilities/common/cloneDeep.js +2 -2
  365. package/utilities/common/cloneDeep.js.map +1 -1
  366. package/utilities/common/compact.d.ts +1 -1
  367. package/utilities/common/compact.js.map +1 -1
  368. package/utilities/common/filterInPlace.js.map +1 -1
  369. package/utilities/common/maybeDeepFreeze.js +1 -1
  370. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  371. package/utilities/common/mergeDeep.d.ts.map +1 -1
  372. package/utilities/common/mergeDeep.js +3 -1
  373. package/utilities/common/mergeDeep.js.map +1 -1
  374. package/utilities/common/mergeOptions.d.ts.map +1 -1
  375. package/utilities/common/mergeOptions.js.map +1 -1
  376. package/utilities/common/objects.js +2 -2
  377. package/utilities/common/objects.js.map +1 -1
  378. package/utilities/common/stringifyForDisplay.d.ts.map +1 -1
  379. package/utilities/common/stringifyForDisplay.js +3 -1
  380. package/utilities/common/stringifyForDisplay.js.map +1 -1
  381. package/utilities/globals/global.d.ts.map +1 -1
  382. package/utilities/globals/global.js +3 -1
  383. package/utilities/globals/global.js.map +1 -1
  384. package/utilities/globals/globals.cjs +8 -4
  385. package/utilities/globals/globals.cjs.map +1 -1
  386. package/utilities/globals/globals.cjs.native.js +8 -4
  387. package/utilities/globals/index.d.ts.map +1 -1
  388. package/utilities/globals/index.js +1 -1
  389. package/utilities/globals/index.js.map +1 -1
  390. package/utilities/globals/invariantWrappers.js +1 -1
  391. package/utilities/globals/invariantWrappers.js.map +1 -1
  392. package/utilities/globals/maybe.d.ts.map +1 -1
  393. package/utilities/globals/maybe.js.map +1 -1
  394. package/utilities/graphql/directives.d.ts +1 -1
  395. package/utilities/graphql/directives.d.ts.map +1 -1
  396. package/utilities/graphql/directives.js +17 -13
  397. package/utilities/graphql/directives.js.map +1 -1
  398. package/utilities/graphql/fragments.d.ts +1 -1
  399. package/utilities/graphql/fragments.d.ts.map +1 -1
  400. package/utilities/graphql/fragments.js +12 -12
  401. package/utilities/graphql/fragments.js.map +1 -1
  402. package/utilities/graphql/getFromAST.d.ts +1 -1
  403. package/utilities/graphql/getFromAST.js +16 -16
  404. package/utilities/graphql/getFromAST.js.map +1 -1
  405. package/utilities/graphql/storeUtils.d.ts +2 -2
  406. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  407. package/utilities/graphql/storeUtils.js +36 -34
  408. package/utilities/graphql/storeUtils.js.map +1 -1
  409. package/utilities/graphql/transform.d.ts +1 -1
  410. package/utilities/graphql/transform.d.ts.map +1 -1
  411. package/utilities/graphql/transform.js +48 -32
  412. package/utilities/graphql/transform.js.map +1 -1
  413. package/utilities/index.d.ts +0 -1
  414. package/utilities/index.d.ts.map +1 -1
  415. package/utilities/index.js +0 -1
  416. package/utilities/index.js.map +1 -1
  417. package/utilities/observables/Concast.d.ts.map +1 -1
  418. package/utilities/observables/Concast.js +5 -9
  419. package/utilities/observables/Concast.js.map +1 -1
  420. package/utilities/observables/Observable.d.ts +4 -4
  421. package/utilities/observables/Observable.d.ts.map +1 -1
  422. package/utilities/observables/Observable.js +6 -4
  423. package/utilities/observables/Observable.js.map +1 -1
  424. package/utilities/observables/asyncMap.d.ts.map +1 -1
  425. package/utilities/observables/asyncMap.js +5 -2
  426. package/utilities/observables/asyncMap.js.map +1 -1
  427. package/utilities/observables/iteration.js.map +1 -1
  428. package/utilities/policies/pagination.d.ts +1 -1
  429. package/utilities/policies/pagination.d.ts.map +1 -1
  430. package/utilities/policies/pagination.js +9 -7
  431. package/utilities/policies/pagination.js.map +1 -1
  432. package/utilities/types/IsStrictlyAny.d.ts +2 -2
  433. package/utilities/types/IsStrictlyAny.d.ts.map +1 -1
  434. package/utilities/types/IsStrictlyAny.js.map +1 -1
  435. package/utilities/utilities.cjs +147 -147
  436. package/utilities/utilities.cjs.map +1 -1
  437. package/utilities/utilities.cjs.native.js +147 -147
  438. package/version.js +1 -1
  439. package/version.js.map +1 -1
  440. package/utilities/common/responseIterator.d.ts +0 -10
  441. package/utilities/common/responseIterator.d.ts.map +0 -1
  442. package/utilities/common/responseIterator.js +0 -21
  443. package/utilities/common/responseIterator.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"key-extractor.js","sourceRoot":"","sources":["../../../src/cache/inmemory/key-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAA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,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG;QACpD,OAAO,OAAO,CAAC,GAAG,CAAC;YACjB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAnB,CAAmB,CAAC;YACvC,CAAC,CAAC,GAAG,IAAI,OAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACd,CAAC;AAED,SAAS,SAAS,CAAI,KAAQ;IAI5B,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE;QAC1B,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;YAClB,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAQ,CAAC;SACpC;QACD,OAAO,qBAAqB,CAC1B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EACzB,UAAA,IAAI,IAAI,OAAA,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,EAA3B,CAA2B,CAC/B,CAAC;KACR;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\n\nimport {\n argumentsObjectFromField,\n DeepMerger,\n isNonEmptyArray,\n isNonNullObject,\n} from \"../../utilities/index.js\";\n\nimport { hasOwn, isArray } from \"./helpers.js\";\nimport type {\n KeySpecifier,\n KeyFieldsFunction,\n KeyArgsFunction,\n} from \"./policies.js\";\n\n// Mapping from JSON-encoded KeySpecifier strings to associated information.\nconst specifierInfoCache: Record<string, {\n paths?: string[][];\n keyFieldsFn?: KeyFieldsFunction;\n keyArgsFn?: KeyArgsFunction;\n}> = Object.create(null);\n\nfunction lookupSpecifierInfo(spec: KeySpecifier) {\n // It's safe to encode KeySpecifier arrays with JSON.stringify, since they're\n // just arrays of strings or nested KeySpecifier arrays, and the order of the\n // array elements is important (and suitably preserved by JSON.stringify).\n const cacheKey = JSON.stringify(spec);\n return specifierInfoCache[cacheKey] ||\n (specifierInfoCache[cacheKey] = Object.create(null));\n}\n\nexport function keyFieldsFnFromSpecifier(\n specifier: KeySpecifier,\n): KeyFieldsFunction {\n const info = lookupSpecifierInfo(specifier);\n\n return info.keyFieldsFn || (info.keyFieldsFn = (\n object,\n context,\n ) => {\n const extract: typeof extractKey =\n (from, key) => context.readField(key, from);\n\n const keyObject = context.keyObject = collectSpecifierPaths(\n specifier,\n schemaKeyPath => {\n let extracted = extractKeyPath(\n context.storeObject,\n schemaKeyPath,\n // Using context.readField to extract paths from context.storeObject\n // allows the extraction to see through Reference objects and respect\n // custom read functions.\n extract,\n );\n\n if (\n extracted === void 0 &&\n object !== context.storeObject &&\n hasOwn.call(object, schemaKeyPath[0])\n ) {\n // If context.storeObject fails to provide a value for the requested\n // path, fall back to the raw result object, if it has a top-level key\n // matching the first key in the path (schemaKeyPath[0]). This allows\n // key fields included in the written data to be saved in the cache\n // even if they are not selected explicitly in context.selectionSet.\n // Not being mentioned by context.selectionSet is convenient here,\n // since it means these extra fields cannot be affected by field\n // aliasing, which is why we can use extractKey instead of\n // context.readField for this extraction.\n extracted = extractKeyPath(object, schemaKeyPath, extractKey);\n }\n\n invariant(\n extracted !== void 0,\n `Missing field '%s' while extracting keyFields from %s`,\n schemaKeyPath.join('.'),\n object,\n );\n\n return extracted;\n },\n );\n\n return `${context.typename}:${JSON.stringify(keyObject)}`;\n });\n}\n\n// The keyArgs extraction process is roughly analogous to keyFields extraction,\n// but there are no aliases involved, missing fields are tolerated (by merely\n// omitting them from the key), and drawing from field.directives or variables\n// is allowed (in addition to drawing from the field's arguments object).\n// Concretely, these differences mean passing a different key path extractor\n// function to collectSpecifierPaths, reusing the shared extractKeyPath helper\n// wherever possible.\nexport function keyArgsFnFromSpecifier(specifier: KeySpecifier): KeyArgsFunction {\n const info = lookupSpecifierInfo(specifier);\n\n return info.keyArgsFn || (info.keyArgsFn = (args, {\n field,\n variables,\n fieldName,\n }) => {\n const collected = collectSpecifierPaths(specifier, keyPath => {\n const firstKey = keyPath[0];\n const firstChar = firstKey.charAt(0);\n\n if (firstChar === \"@\") {\n if (field && isNonEmptyArray(field.directives)) {\n const directiveName = firstKey.slice(1);\n // If the directive appears multiple times, only the first\n // occurrence's arguments will be used. TODO Allow repetition?\n // TODO Cache this work somehow, a la aliasMap?\n const d = field.directives.find(d => d.name.value === directiveName);\n // Fortunately argumentsObjectFromField works for DirectiveNode!\n const directiveArgs = d && argumentsObjectFromField(d, variables);\n // For directives without arguments (d defined, but directiveArgs ===\n // null), the presence or absence of the directive still counts as\n // part of the field key, so we return null in those cases. If no\n // directive with this name was found for this field (d undefined and\n // thus directiveArgs undefined), we return undefined, which causes\n // this value to be omitted from the key object returned by\n // collectSpecifierPaths.\n return directiveArgs && extractKeyPath(\n directiveArgs,\n // If keyPath.length === 1, this code calls extractKeyPath with an\n // empty path, which works because it uses directiveArgs as the\n // extracted value.\n keyPath.slice(1),\n );\n }\n // If the key started with @ but there was no corresponding directive,\n // we want to omit this value from the key object, not fall through to\n // treating @whatever as a normal argument name.\n return;\n }\n\n if (firstChar === \"$\") {\n const variableName = firstKey.slice(1);\n if (variables && hasOwn.call(variables, variableName)) {\n const varKeyPath = keyPath.slice(0);\n varKeyPath[0] = variableName;\n return extractKeyPath(variables, varKeyPath);\n }\n // If the key started with $ but there was no corresponding variable, we\n // want to omit this value from the key object, not fall through to\n // treating $whatever as a normal argument name.\n return;\n }\n\n if (args) {\n return extractKeyPath(args, keyPath);\n }\n });\n\n const suffix = JSON.stringify(collected);\n\n // If no arguments were passed to this field, and it didn't have any other\n // field key contributions from directives or variables, hide the empty\n // :{} suffix from the field key. However, a field passed no arguments can\n // still end up with a non-empty :{...} suffix if its key configuration\n // refers to directives or variables.\n if (args || suffix !== \"{}\") {\n fieldName += \":\" + suffix;\n }\n\n return fieldName;\n });\n}\n\nexport function collectSpecifierPaths(\n specifier: KeySpecifier,\n extractor: (path: string[]) => any,\n): Record<string, any> {\n // For each path specified by specifier, invoke the extractor, and repeatedly\n // merge the results together, with appropriate ancestor context.\n const merger = new DeepMerger;\n return getSpecifierPaths(specifier).reduce((collected, path) => {\n let toMerge = extractor(path);\n if (toMerge !== void 0) {\n // This path is not expected to contain array indexes, so the toMerge\n // reconstruction will not contain arrays. TODO Fix this?\n for (let i = path.length - 1; i >= 0; --i) {\n toMerge = { [path[i]]: toMerge };\n }\n collected = merger.merge(collected, toMerge);\n }\n return collected;\n }, Object.create(null));\n}\n\nexport function getSpecifierPaths(spec: KeySpecifier): string[][] {\n const info = lookupSpecifierInfo(spec);\n\n if (!info.paths) {\n const paths: string[][] = info.paths = [];\n const currentPath: string[] = [];\n\n spec.forEach((s, i) => {\n if (isArray(s)) {\n getSpecifierPaths(s).forEach(p => paths.push(currentPath.concat(p)));\n currentPath.length = 0;\n } else {\n currentPath.push(s);\n if (!isArray(spec[i + 1])) {\n paths.push(currentPath.slice(0));\n currentPath.length = 0;\n }\n }\n });\n }\n\n return info.paths!;\n}\n\nfunction extractKey<\n TObj extends Record<string, any>,\n TKey extends string,\n>(object: TObj, key: TKey): TObj[TKey] | undefined {\n return object[key];\n}\n\nexport function extractKeyPath(\n object: Record<string, any>,\n path: string[],\n extract?: typeof extractKey,\n): any {\n // For each key in path, extract the corresponding child property from obj,\n // flattening arrays if encountered (uncommon for keyFields and keyArgs, but\n // possible). The final result of path.reduce is normalized so unexpected leaf\n // objects have their keys safely sorted. That final result is difficult to\n // type as anything other than any. You're welcome to try to improve the\n // return type, but keep in mind extractKeyPath is not a public function\n // (exported only for testing), so the effort may not be worthwhile unless the\n // limited set of actual callers (see above) pass arguments that TypeScript\n // can statically type. If we know only that path is some array of strings\n // (and not, say, a specific tuple of statically known strings), any (or\n // possibly unknown) is the honest answer.\n extract = extract || extractKey;\n return normalize(path.reduce(function reducer(obj, key): any {\n return isArray(obj)\n ? obj.map(child => reducer(child, key))\n : obj && extract!(obj, key);\n }, object));\n}\n\nfunction normalize<T>(value: T): T {\n // Usually the extracted value will be a scalar value, since most primary\n // key fields are scalar, but just in case we get an object or an array, we\n // need to do some normalization of the order of (nested) keys.\n if (isNonNullObject(value)) {\n if (isArray(value)) {\n return value.map(normalize) as any;\n }\n return collectSpecifierPaths(\n Object.keys(value).sort(),\n path => extractKeyPath(value, path),\n ) as T;\n }\n return value;\n}\n"]}
1
+ {"version":3,"file":"key-extractor.js","sourceRoot":"","sources":["../../../src/cache/inmemory/key-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,EACL,wBAAwB,EACxB,UAAU,EACV,eAAe,EACf,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAQ/C,IAAM,kBAAkB,GAOpB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAExB,SAAS,mBAAmB,CAAC,IAAkB;IAI7C,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,CACL,kBAAkB,CAAC,QAAQ,CAAC;QAC5B,CAAC,kBAAkB,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CACrD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,SAAuB;IAEvB,IAAM,IAAI,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAE5C,OAAO,CACL,IAAI,CAAC,WAAW;QAChB,CAAC,IAAI,CAAC,WAAW,GAAG,UAAC,MAAM,EAAE,OAAO;YAClC,IAAM,OAAO,GAAsB,UAAC,IAAI,EAAE,GAAG;gBAC3C,OAAA,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC;YAA5B,CAA4B,CAAC;YAE/B,IAAM,SAAS,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,qBAA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\nimport {\n argumentsObjectFromField,\n DeepMerger,\n isNonEmptyArray,\n isNonNullObject,\n} from \"../../utilities/index.js\";\n\nimport { hasOwn, isArray } from \"./helpers.js\";\nimport type {\n KeySpecifier,\n KeyFieldsFunction,\n KeyArgsFunction,\n} from \"./policies.js\";\n\n// Mapping from JSON-encoded KeySpecifier strings to associated information.\nconst specifierInfoCache: Record<\n string,\n {\n paths?: string[][];\n keyFieldsFn?: KeyFieldsFunction;\n keyArgsFn?: KeyArgsFunction;\n }\n> = Object.create(null);\n\nfunction lookupSpecifierInfo(spec: KeySpecifier) {\n // It's safe to encode KeySpecifier arrays with JSON.stringify, since they're\n // just arrays of strings or nested KeySpecifier arrays, and the order of the\n // array elements is important (and suitably preserved by JSON.stringify).\n const cacheKey = JSON.stringify(spec);\n return (\n specifierInfoCache[cacheKey] ||\n (specifierInfoCache[cacheKey] = Object.create(null))\n );\n}\n\nexport function keyFieldsFnFromSpecifier(\n specifier: KeySpecifier\n): KeyFieldsFunction {\n const info = lookupSpecifierInfo(specifier);\n\n return (\n info.keyFieldsFn ||\n (info.keyFieldsFn = (object, context) => {\n const extract: typeof extractKey = (from, key) =>\n context.readField(key, from);\n\n const keyObject = (context.keyObject = collectSpecifierPaths(\n specifier,\n (schemaKeyPath) => {\n let extracted = extractKeyPath(\n context.storeObject,\n schemaKeyPath,\n // Using context.readField to extract paths from context.storeObject\n // allows the extraction to see through Reference objects and respect\n // custom read functions.\n extract\n );\n\n if (\n extracted === void 0 &&\n object !== context.storeObject &&\n hasOwn.call(object, schemaKeyPath[0])\n ) {\n // If context.storeObject fails to provide a value for the requested\n // path, fall back to the raw result object, if it has a top-level key\n // matching the first key in the path (schemaKeyPath[0]). This allows\n // key fields included in the written data to be saved in the cache\n // even if they are not selected explicitly in context.selectionSet.\n // Not being mentioned by context.selectionSet is convenient here,\n // since it means these extra fields cannot be affected by field\n // aliasing, which is why we can use extractKey instead of\n // context.readField for this extraction.\n extracted = extractKeyPath(object, schemaKeyPath, extractKey);\n }\n\n invariant(\n extracted !== void 0,\n `Missing field '%s' while extracting keyFields from %s`,\n schemaKeyPath.join(\".\"),\n object\n );\n\n return extracted;\n }\n ));\n\n return `${context.typename}:${JSON.stringify(keyObject)}`;\n })\n );\n}\n\n// The keyArgs extraction process is roughly analogous to keyFields extraction,\n// but there are no aliases involved, missing fields are tolerated (by merely\n// omitting them from the key), and drawing from field.directives or variables\n// is allowed (in addition to drawing from the field's arguments object).\n// Concretely, these differences mean passing a different key path extractor\n// function to collectSpecifierPaths, reusing the shared extractKeyPath helper\n// wherever possible.\nexport function keyArgsFnFromSpecifier(\n specifier: KeySpecifier\n): KeyArgsFunction {\n const info = lookupSpecifierInfo(specifier);\n\n return (\n info.keyArgsFn ||\n (info.keyArgsFn = (args, { field, variables, fieldName }) => {\n const collected = collectSpecifierPaths(specifier, (keyPath) => {\n const firstKey = keyPath[0];\n const firstChar = firstKey.charAt(0);\n\n if (firstChar === \"@\") {\n if (field && isNonEmptyArray(field.directives)) {\n const directiveName = firstKey.slice(1);\n // If the directive appears multiple times, only the first\n // occurrence's arguments will be used. TODO Allow repetition?\n // TODO Cache this work somehow, a la aliasMap?\n const d = field.directives.find(\n (d) => d.name.value === directiveName\n );\n // Fortunately argumentsObjectFromField works for DirectiveNode!\n const directiveArgs = d && argumentsObjectFromField(d, variables);\n // For directives without arguments (d defined, but directiveArgs ===\n // null), the presence or absence of the directive still counts as\n // part of the field key, so we return null in those cases. If no\n // directive with this name was found for this field (d undefined and\n // thus directiveArgs undefined), we return undefined, which causes\n // this value to be omitted from the key object returned by\n // collectSpecifierPaths.\n return (\n directiveArgs &&\n extractKeyPath(\n directiveArgs,\n // If keyPath.length === 1, this code calls extractKeyPath with an\n // empty path, which works because it uses directiveArgs as the\n // extracted value.\n keyPath.slice(1)\n )\n );\n }\n // If the key started with @ but there was no corresponding directive,\n // we want to omit this value from the key object, not fall through to\n // treating @whatever as a normal argument name.\n return;\n }\n\n if (firstChar === \"$\") {\n const variableName = firstKey.slice(1);\n if (variables && hasOwn.call(variables, variableName)) {\n const varKeyPath = keyPath.slice(0);\n varKeyPath[0] = variableName;\n return extractKeyPath(variables, varKeyPath);\n }\n // If the key started with $ but there was no corresponding variable, we\n // want to omit this value from the key object, not fall through to\n // treating $whatever as a normal argument name.\n return;\n }\n\n if (args) {\n return extractKeyPath(args, keyPath);\n }\n });\n\n const suffix = JSON.stringify(collected);\n\n // If no arguments were passed to this field, and it didn't have any other\n // field key contributions from directives or variables, hide the empty\n // :{} suffix from the field key. However, a field passed no arguments can\n // still end up with a non-empty :{...} suffix if its key configuration\n // refers to directives or variables.\n if (args || suffix !== \"{}\") {\n fieldName += \":\" + suffix;\n }\n\n return fieldName;\n })\n );\n}\n\nexport function collectSpecifierPaths(\n specifier: KeySpecifier,\n extractor: (path: string[]) => any\n): Record<string, any> {\n // For each path specified by specifier, invoke the extractor, and repeatedly\n // merge the results together, with appropriate ancestor context.\n const merger = new DeepMerger();\n return getSpecifierPaths(specifier).reduce((collected, path) => {\n let toMerge = extractor(path);\n if (toMerge !== void 0) {\n // This path is not expected to contain array indexes, so the toMerge\n // reconstruction will not contain arrays. TODO Fix this?\n for (let i = path.length - 1; i >= 0; --i) {\n toMerge = { [path[i]]: toMerge };\n }\n collected = merger.merge(collected, toMerge);\n }\n return collected;\n }, Object.create(null));\n}\n\nexport function getSpecifierPaths(spec: KeySpecifier): string[][] {\n const info = lookupSpecifierInfo(spec);\n\n if (!info.paths) {\n const paths: string[][] = (info.paths = []);\n const currentPath: string[] = [];\n\n spec.forEach((s, i) => {\n if (isArray(s)) {\n getSpecifierPaths(s).forEach((p) => paths.push(currentPath.concat(p)));\n currentPath.length = 0;\n } else {\n currentPath.push(s);\n if (!isArray(spec[i + 1])) {\n paths.push(currentPath.slice(0));\n currentPath.length = 0;\n }\n }\n });\n }\n\n return info.paths!;\n}\n\nfunction extractKey<TObj extends Record<string, any>, TKey extends string>(\n object: TObj,\n key: TKey\n): TObj[TKey] | undefined {\n return object[key];\n}\n\nexport function extractKeyPath(\n object: Record<string, any>,\n path: string[],\n extract?: typeof extractKey\n): any {\n // For each key in path, extract the corresponding child property from obj,\n // flattening arrays if encountered (uncommon for keyFields and keyArgs, but\n // possible). The final result of path.reduce is normalized so unexpected leaf\n // objects have their keys safely sorted. That final result is difficult to\n // type as anything other than any. You're welcome to try to improve the\n // return type, but keep in mind extractKeyPath is not a public function\n // (exported only for testing), so the effort may not be worthwhile unless the\n // limited set of actual callers (see above) pass arguments that TypeScript\n // can statically type. If we know only that path is some array of strings\n // (and not, say, a specific tuple of statically known strings), any (or\n // possibly unknown) is the honest answer.\n extract = extract || extractKey;\n return normalize(\n path.reduce(function reducer(obj, key): any {\n return isArray(obj)\n ? obj.map((child) => reducer(child, key))\n : obj && extract!(obj, key);\n }, object)\n );\n}\n\nfunction normalize<T>(value: T): T {\n // Usually the extracted value will be a scalar value, since most primary\n // key fields are scalar, but just in case we get an object or an array, we\n // need to do some normalization of the order of (nested) keys.\n if (isNonNullObject(value)) {\n if (isArray(value)) {\n return value.map(normalize) as any;\n }\n return collectSpecifierPaths(Object.keys(value).sort(), (path) =>\n extractKeyPath(value, path)\n ) as T;\n }\n return value;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"object-canon.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/object-canon.ts"],"names":[],"mappings":"AAwEA,qBAAa,WAAW;IAGtB,OAAO,CAAC,KAAK,CAAiD;IAG9D,OAAO,CAAC,IAAI,CAIM;IAEX,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAMnC,OAAO,CAAC,MAAM,CAAiC;IACxC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;IAWpB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;IAuE5B,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,UAAU,CAAqC;IAGvD,SAAgB,KAAK,KAAkB;CACxC;AAUD,eAAO,MAAM,kBAAkB,WAAkC,GAAG,KAAG,MAAM;;CAkB3E,CAAC;AAMH,iBAAS,uBAAuB,SAG/B"}
1
+ {"version":3,"file":"object-canon.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/object-canon.ts"],"names":[],"mappings":"AAwEA,qBAAa,WAAW;IAGtB,OAAO,CAAC,KAAK,CAAiD;IAG9D,OAAO,CAAC,IAAI,CAIM;IAEX,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAMnC,OAAO,CAAC,MAAM,CAAiC;IACxC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;IAWpB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;IAuE5B,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,UAAU,CAAqC;IAGvD,SAAgB,KAAK,KAAkB;CACxC;AAUD,eAAO,MAAM,kBAAkB,WACZ,GAAG,KAAG,MAAM;;CAiB9B,CAAC;AAMF,iBAAS,uBAAuB,SAG/B"}
@@ -43,7 +43,7 @@ var ObjectCanon = (function () {
43
43
  var array = value.map(this.admit, this);
44
44
  var node = this.pool.lookupArray(array);
45
45
  if (!node.array) {
46
- this.known.add(node.array = array);
46
+ this.known.add((node.array = array));
47
47
  if (globalThis.__DEV__ !== false) {
48
48
  Object.freeze(array);
49
49
  }
@@ -64,7 +64,7 @@ var ObjectCanon = (function () {
64
64
  });
65
65
  var node = this.pool.lookupArray(array_1);
66
66
  if (!node.object) {
67
- var obj_1 = node.object = Object.create(proto_1);
67
+ var obj_1 = (node.object = Object.create(proto_1));
68
68
  this.known.add(obj_1);
69
69
  keys.sorted.forEach(function (key, i) {
70
70
  obj_1[key] = array_1[firstValueIndex_1 + i];
@@ -86,7 +86,7 @@ var ObjectCanon = (function () {
86
86
  keys.sort();
87
87
  var json = JSON.stringify(keys);
88
88
  if (!(node.keys = this.keysByJSON.get(json))) {
89
- this.keysByJSON.set(json, node.keys = { sorted: keys, json: json });
89
+ this.keysByJSON.set(json, (node.keys = { sorted: keys, json: json }));
90
90
  }
91
91
  }
92
92
  return node.keys;
@@ -102,7 +102,7 @@ export var canonicalStringify = Object.assign(function (value) {
102
102
  var canonical = stringifyCanon.admit(value);
103
103
  var json = stringifyCache.get(canonical);
104
104
  if (json === void 0) {
105
- stringifyCache.set(canonical, json = JSON.stringify(canonical));
105
+ stringifyCache.set(canonical, (json = JSON.stringify(canonical)));
106
106
  }
107
107
  return json;
108
108
  }
@@ -113,7 +113,7 @@ export var canonicalStringify = Object.assign(function (value) {
113
113
  var stringifyCanon;
114
114
  var stringifyCache;
115
115
  function resetCanonicalStringify() {
116
- stringifyCanon = new ObjectCanon;
116
+ stringifyCanon = new ObjectCanon();
117
117
  stringifyCache = new (canUseWeakMap ? WeakMap : Map)();
118
118
  }
119
119
  //# sourceMappingURL=object-canon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"object-canon.js","sourceRoot":"","sources":["../../../src/cache/inmemory/object-canon.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,IAAI,eAAe,GACnC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,WAAW,CAAI,KAAQ;IAC9B,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE;QAC1B,OAAO,OAAO,CAAC,KAAK,CAAC;YACnB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAa;YAC5B,CAAC,YAAG,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,IAAK,KAAK,CAAE,CAAC;KAC3D;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAyDD;IAAA;QAGU,UAAK,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAU,CAAC;QAGtD,SAAI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AAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACzC,IAAI,IAAI,KAAK,KAAK,CAAC,EAAE;YACnB,cAAc,CAAC,GAAG,CAChB,SAAS,EACT,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CACjC,CAAC;SACH;QACD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC,EAAE;IACD,KAAK,EAAE,uBAAuB;CAC/B,CAAC,CAAC;AAGH,IAAI,cAA2B,CAAC;AAChC,IAAI,cAAuC,CAAC;AAE5C,SAAS,uBAAuB;IAC9B,cAAc,GAAG,IAAI,WAAW,CAAC;IACjC,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import { Trie } from \"@wry/trie\";\nimport {\n canUseWeakMap,\n canUseWeakSet,\n isNonNullObject as isObjectOrArray,\n} from \"../../utilities/index.js\";\nimport { isArray } from \"./helpers.js\";\n\nfunction shallowCopy<T>(value: T): T {\n if (isObjectOrArray(value)) {\n return isArray(value)\n ? value.slice(0) as any as T\n : { __proto__: Object.getPrototypeOf(value), ...value };\n }\n return value;\n}\n\n// When programmers talk about the \"canonical form\" of an object, they\n// usually have the following meaning in mind, which I've copied from\n// https://en.wiktionary.org/wiki/canonical_form:\n//\n// 1. A standard or normal presentation of a mathematical entity [or\n// object]. A canonical form is an element of a set of representatives\n// of equivalence classes of forms such that there is a function or\n// procedure which projects every element of each equivalence class\n// onto that one element, the canonical form of that equivalence\n// class. The canonical form is expected to be simpler than the rest of\n// the forms in some way.\n//\n// That's a long-winded way of saying any two objects that have the same\n// canonical form may be considered equivalent, even if they are !==,\n// which usually means the objects are structurally equivalent (deeply\n// equal), but don't necessarily use the same memory.\n//\n// Like a literary or musical canon, this ObjectCanon class represents a\n// collection of unique canonical items (JavaScript objects), with the\n// important property that canon.admit(a) === canon.admit(b) if a and b\n// are deeply equal to each other. In terms of the definition above, the\n// canon.admit method is the \"function or procedure which projects every\"\n// object \"onto that one element, the canonical form.\"\n//\n// In the worst case, the canonicalization process may involve looking at\n// every property in the provided object tree, so it takes the same order\n// of time as deep equality checking. Fortunately, already-canonicalized\n// objects are returned immediately from canon.admit, so the presence of\n// canonical subtrees tends to speed up canonicalization.\n//\n// Since consumers of canonical objects can check for deep equality in\n// constant time, canonicalizing cache results can massively improve the\n// performance of application code that skips re-rendering unchanged\n// results, such as \"pure\" UI components in a framework like React.\n//\n// Of course, since canonical objects may be shared widely between\n// unrelated consumers, it's important to think of them as immutable, even\n// though they are not actually frozen with Object.freeze in production,\n// due to the extra performance overhead that comes with frozen objects.\n//\n// Custom scalar objects whose internal class name is neither Array nor\n// Object can be included safely in the admitted tree, but they will not\n// be replaced with a canonical version (to put it another way, they are\n// assumed to be canonical already).\n//\n// If we ignore custom objects, no detection of cycles or repeated object\n// references is currently required by the StoreReader class, since\n// GraphQL result objects are JSON-serializable trees (and thus contain\n// neither cycles nor repeated subtrees), so we can avoid the complexity\n// of keeping track of objects we've already seen during the recursion of\n// the admit method.\n//\n// In the future, we may consider adding additional cases to the switch\n// statement to handle other common object types, such as \"[object Date]\"\n// objects, as needed.\nexport class ObjectCanon {\n // Set of all canonical objects this ObjectCanon has admitted, allowing\n // canon.admit to return previously-canonicalized objects immediately.\n private known = new (canUseWeakSet ? WeakSet : Set)<object>();\n\n // Efficient storage/lookup structure for canonical objects.\n private pool = new Trie<{\n array?: any[];\n object?: Record<string, any>;\n keys?: SortedKeysInfo;\n }>(canUseWeakMap);\n\n public isKnown(value: any): boolean {\n return isObjectOrArray(value) && this.known.has(value);\n }\n\n // Make the ObjectCanon assume this value has already been\n // canonicalized.\n private passes = new WeakMap<object, object>();\n public pass<T>(value: T): T;\n public pass(value: any) {\n if (isObjectOrArray(value)) {\n const copy = shallowCopy(value);\n this.passes.set(copy, value);\n return copy;\n }\n return value;\n }\n\n // Returns the canonical version of value.\n public admit<T>(value: T): T;\n public admit(value: any) {\n if (isObjectOrArray(value)) {\n const original = this.passes.get(value);\n if (original) return original;\n\n const proto = Object.getPrototypeOf(value);\n switch (proto) {\n case Array.prototype: {\n if (this.known.has(value)) return value;\n const array: any[] = (value as any[]).map(this.admit, this);\n // Arrays are looked up in the Trie using their recursively\n // canonicalized elements, and the known version of the array is\n // preserved as node.array.\n const node = this.pool.lookupArray(array);\n if (!node.array) {\n this.known.add(node.array = array);\n // Since canonical arrays may be shared widely between\n // unrelated consumers, it's important to regard them as\n // immutable, even if they are not frozen in production.\n if (__DEV__) {\n Object.freeze(array);\n }\n }\n return node.array;\n }\n\n case null:\n case Object.prototype: {\n if (this.known.has(value)) return value;\n const proto = Object.getPrototypeOf(value);\n const array = [proto];\n const keys = this.sortedKeys(value);\n array.push(keys.json);\n const firstValueIndex = array.length;\n keys.sorted.forEach(key => {\n array.push(this.admit((value as any)[key]));\n });\n // Objects are looked up in the Trie by their prototype (which\n // is *not* recursively canonicalized), followed by a JSON\n // representation of their (sorted) keys, followed by the\n // sequence of recursively canonicalized values corresponding to\n // those keys. To keep the final results unambiguous with other\n // sequences (such as arrays that just happen to contain [proto,\n // keys.json, value1, value2, ...]), the known version of the\n // object is stored as node.object.\n const node = this.pool.lookupArray(array);\n if (!node.object) {\n const obj = node.object = Object.create(proto);\n this.known.add(obj);\n keys.sorted.forEach((key, i) => {\n obj[key] = array[firstValueIndex + i];\n });\n // Since canonical objects may be shared widely between\n // unrelated consumers, it's important to regard them as\n // immutable, even if they are not frozen in production.\n if (__DEV__) {\n Object.freeze(obj);\n }\n }\n return node.object;\n }\n }\n }\n return value;\n }\n\n // It's worthwhile to cache the sorting of arrays of strings, since the\n // same initial unsorted arrays tend to be encountered many times.\n // Fortunately, we can reuse the Trie machinery to look up the sorted\n // arrays in linear time (which is faster than sorting large arrays).\n private sortedKeys(obj: object) {\n const keys = Object.keys(obj);\n const node = this.pool.lookupArray(keys);\n if (!node.keys) {\n keys.sort();\n const json = JSON.stringify(keys);\n if (!(node.keys = this.keysByJSON.get(json))) {\n this.keysByJSON.set(json, node.keys = { sorted: keys, json });\n }\n }\n return node.keys;\n }\n // Arrays that contain the same elements in a different order can share\n // the same SortedKeysInfo object, to save memory.\n private keysByJSON = new Map<string, SortedKeysInfo>();\n\n // This has to come last because it depends on keysByJSON.\n public readonly empty = this.admit({});\n}\n\ntype SortedKeysInfo = {\n sorted: string[];\n json: string;\n};\n\n// Since the keys of canonical objects are always created in lexicographically\n// sorted order, we can use the ObjectCanon to implement a fast and stable\n// version of JSON.stringify, which automatically sorts object keys.\nexport const canonicalStringify = Object.assign(function (value: any): string {\n if (isObjectOrArray(value)) {\n if (stringifyCanon === void 0) {\n resetCanonicalStringify();\n }\n const canonical = stringifyCanon.admit(value);\n let json = stringifyCache.get(canonical);\n if (json === void 0) {\n stringifyCache.set(\n canonical,\n json = JSON.stringify(canonical),\n );\n }\n return json;\n }\n return JSON.stringify(value);\n}, {\n reset: resetCanonicalStringify,\n});\n\n// Can be reset by calling canonicalStringify.reset().\nlet stringifyCanon: ObjectCanon;\nlet stringifyCache: WeakMap<object, string>;\n\nfunction resetCanonicalStringify() {\n stringifyCanon = new ObjectCanon;\n stringifyCache = new (canUseWeakMap ? WeakMap : Map)();\n}\n"]}
1
+ {"version":3,"file":"object-canon.js","sourceRoot":"","sources":["../../../src/cache/inmemory/object-canon.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,IAAI,eAAe,GACnC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,WAAW,CAAI,KAAQ;IAC9B,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE;QAC1B,OAAO,OAAO,CAAC,KAAK,CAAC;YACnB,CAAC,CAAE,KAAK,CAAC,KAAK,C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AD,CAAC,AAvHD,IAuHC;;AAUD,MAAM,CAAC,IAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAC7C,UAAU,KAAU;IAClB,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE;QAC1B,IAAI,cAAc,KAAK,KAAK,CAAC,EAAE;YAC7B,uBAAuB,EAAE,CAAC;SAC3B;QACD,IAAM,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,IAAI,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACzC,IAAI,IAAI,KAAK,KAAK,CAAC,EAAE;YACnB,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SACnE;QACD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC,EACD;IACE,KAAK,EAAE,uBAAuB;CAC/B,CACF,CAAC;AAGF,IAAI,cAA2B,CAAC;AAChC,IAAI,cAAuC,CAAC;AAE5C,SAAS,uBAAuB;IAC9B,cAAc,GAAG,IAAI,WAAW,EAAE,CAAC;IACnC,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import { Trie } from \"@wry/trie\";\nimport {\n canUseWeakMap,\n canUseWeakSet,\n isNonNullObject as isObjectOrArray,\n} from \"../../utilities/index.js\";\nimport { isArray } from \"./helpers.js\";\n\nfunction shallowCopy<T>(value: T): T {\n if (isObjectOrArray(value)) {\n return isArray(value)\n ? (value.slice(0) as any as T)\n : { __proto__: Object.getPrototypeOf(value), ...value };\n }\n return value;\n}\n\n// When programmers talk about the \"canonical form\" of an object, they\n// usually have the following meaning in mind, which I've copied from\n// https://en.wiktionary.org/wiki/canonical_form:\n//\n// 1. A standard or normal presentation of a mathematical entity [or\n// object]. A canonical form is an element of a set of representatives\n// of equivalence classes of forms such that there is a function or\n// procedure which projects every element of each equivalence class\n// onto that one element, the canonical form of that equivalence\n// class. The canonical form is expected to be simpler than the rest of\n// the forms in some way.\n//\n// That's a long-winded way of saying any two objects that have the same\n// canonical form may be considered equivalent, even if they are !==,\n// which usually means the objects are structurally equivalent (deeply\n// equal), but don't necessarily use the same memory.\n//\n// Like a literary or musical canon, this ObjectCanon class represents a\n// collection of unique canonical items (JavaScript objects), with the\n// important property that canon.admit(a) === canon.admit(b) if a and b\n// are deeply equal to each other. In terms of the definition above, the\n// canon.admit method is the \"function or procedure which projects every\"\n// object \"onto that one element, the canonical form.\"\n//\n// In the worst case, the canonicalization process may involve looking at\n// every property in the provided object tree, so it takes the same order\n// of time as deep equality checking. Fortunately, already-canonicalized\n// objects are returned immediately from canon.admit, so the presence of\n// canonical subtrees tends to speed up canonicalization.\n//\n// Since consumers of canonical objects can check for deep equality in\n// constant time, canonicalizing cache results can massively improve the\n// performance of application code that skips re-rendering unchanged\n// results, such as \"pure\" UI components in a framework like React.\n//\n// Of course, since canonical objects may be shared widely between\n// unrelated consumers, it's important to think of them as immutable, even\n// though they are not actually frozen with Object.freeze in production,\n// due to the extra performance overhead that comes with frozen objects.\n//\n// Custom scalar objects whose internal class name is neither Array nor\n// Object can be included safely in the admitted tree, but they will not\n// be replaced with a canonical version (to put it another way, they are\n// assumed to be canonical already).\n//\n// If we ignore custom objects, no detection of cycles or repeated object\n// references is currently required by the StoreReader class, since\n// GraphQL result objects are JSON-serializable trees (and thus contain\n// neither cycles nor repeated subtrees), so we can avoid the complexity\n// of keeping track of objects we've already seen during the recursion of\n// the admit method.\n//\n// In the future, we may consider adding additional cases to the switch\n// statement to handle other common object types, such as \"[object Date]\"\n// objects, as needed.\nexport class ObjectCanon {\n // Set of all canonical objects this ObjectCanon has admitted, allowing\n // canon.admit to return previously-canonicalized objects immediately.\n private known = new (canUseWeakSet ? WeakSet : Set)<object>();\n\n // Efficient storage/lookup structure for canonical objects.\n private pool = new Trie<{\n array?: any[];\n object?: Record<string, any>;\n keys?: SortedKeysInfo;\n }>(canUseWeakMap);\n\n public isKnown(value: any): boolean {\n return isObjectOrArray(value) && this.known.has(value);\n }\n\n // Make the ObjectCanon assume this value has already been\n // canonicalized.\n private passes = new WeakMap<object, object>();\n public pass<T>(value: T): T;\n public pass(value: any) {\n if (isObjectOrArray(value)) {\n const copy = shallowCopy(value);\n this.passes.set(copy, value);\n return copy;\n }\n return value;\n }\n\n // Returns the canonical version of value.\n public admit<T>(value: T): T;\n public admit(value: any) {\n if (isObjectOrArray(value)) {\n const original = this.passes.get(value);\n if (original) return original;\n\n const proto = Object.getPrototypeOf(value);\n switch (proto) {\n case Array.prototype: {\n if (this.known.has(value)) return value;\n const array: any[] = (value as any[]).map(this.admit, this);\n // Arrays are looked up in the Trie using their recursively\n // canonicalized elements, and the known version of the array is\n // preserved as node.array.\n const node = this.pool.lookupArray(array);\n if (!node.array) {\n this.known.add((node.array = array));\n // Since canonical arrays may be shared widely between\n // unrelated consumers, it's important to regard them as\n // immutable, even if they are not frozen in production.\n if (__DEV__) {\n Object.freeze(array);\n }\n }\n return node.array;\n }\n\n case null:\n case Object.prototype: {\n if (this.known.has(value)) return value;\n const proto = Object.getPrototypeOf(value);\n const array = [proto];\n const keys = this.sortedKeys(value);\n array.push(keys.json);\n const firstValueIndex = array.length;\n keys.sorted.forEach((key) => {\n array.push(this.admit((value as any)[key]));\n });\n // Objects are looked up in the Trie by their prototype (which\n // is *not* recursively canonicalized), followed by a JSON\n // representation of their (sorted) keys, followed by the\n // sequence of recursively canonicalized values corresponding to\n // those keys. To keep the final results unambiguous with other\n // sequences (such as arrays that just happen to contain [proto,\n // keys.json, value1, value2, ...]), the known version of the\n // object is stored as node.object.\n const node = this.pool.lookupArray(array);\n if (!node.object) {\n const obj = (node.object = Object.create(proto));\n this.known.add(obj);\n keys.sorted.forEach((key, i) => {\n obj[key] = array[firstValueIndex + i];\n });\n // Since canonical objects may be shared widely between\n // unrelated consumers, it's important to regard them as\n // immutable, even if they are not frozen in production.\n if (__DEV__) {\n Object.freeze(obj);\n }\n }\n return node.object;\n }\n }\n }\n return value;\n }\n\n // It's worthwhile to cache the sorting of arrays of strings, since the\n // same initial unsorted arrays tend to be encountered many times.\n // Fortunately, we can reuse the Trie machinery to look up the sorted\n // arrays in linear time (which is faster than sorting large arrays).\n private sortedKeys(obj: object) {\n const keys = Object.keys(obj);\n const node = this.pool.lookupArray(keys);\n if (!node.keys) {\n keys.sort();\n const json = JSON.stringify(keys);\n if (!(node.keys = this.keysByJSON.get(json))) {\n this.keysByJSON.set(json, (node.keys = { sorted: keys, json }));\n }\n }\n return node.keys;\n }\n // Arrays that contain the same elements in a different order can share\n // the same SortedKeysInfo object, to save memory.\n private keysByJSON = new Map<string, SortedKeysInfo>();\n\n // This has to come last because it depends on keysByJSON.\n public readonly empty = this.admit({});\n}\n\ntype SortedKeysInfo = {\n sorted: string[];\n json: string;\n};\n\n// Since the keys of canonical objects are always created in lexicographically\n// sorted order, we can use the ObjectCanon to implement a fast and stable\n// version of JSON.stringify, which automatically sorts object keys.\nexport const canonicalStringify = Object.assign(\n function (value: any): string {\n if (isObjectOrArray(value)) {\n if (stringifyCanon === void 0) {\n resetCanonicalStringify();\n }\n const canonical = stringifyCanon.admit(value);\n let json = stringifyCache.get(canonical);\n if (json === void 0) {\n stringifyCache.set(canonical, (json = JSON.stringify(canonical)));\n }\n return json;\n }\n return JSON.stringify(value);\n },\n {\n reset: resetCanonicalStringify,\n }\n);\n\n// Can be reset by calling canonicalStringify.reset().\nlet stringifyCanon: ObjectCanon;\nlet stringifyCache: WeakMap<object, string>;\n\nfunction resetCanonicalStringify() {\n stringifyCanon = new ObjectCanon();\n stringifyCache = new (canUseWeakMap ? WeakMap : Map)();\n}\n"]}
@@ -1,10 +1,10 @@
1
- import type { InlineFragmentNode, FragmentDefinitionNode, SelectionSetNode, FieldNode } from 'graphql';
2
- import type { FragmentMap, StoreValue, StoreObject, Reference } from '../../utilities/index.js';
3
- import { isReference } from '../../utilities/index.js';
1
+ import type { InlineFragmentNode, FragmentDefinitionNode, SelectionSetNode, FieldNode } from "graphql";
2
+ import type { FragmentMap, StoreValue, StoreObject, Reference } from "../../utilities/index.js";
3
+ import { isReference } from "../../utilities/index.js";
4
4
  import type { IdGetter, MergeInfo, ReadMergeModifyContext } from "./types.js";
5
- import type { InMemoryCache } from './inMemoryCache.js';
6
- import type { SafeReadonly, FieldSpecifier, ToReferenceFunction, ReadFieldFunction, ReadFieldOptions, CanReadFunction } from '../core/types/common.js';
7
- import type { WriteContext } from './writeToStore.js';
5
+ import type { InMemoryCache } from "./inMemoryCache.js";
6
+ import type { SafeReadonly, FieldSpecifier, ToReferenceFunction, ReadFieldFunction, ReadFieldOptions, CanReadFunction } from "../core/types/common.js";
7
+ import type { WriteContext } from "./writeToStore.js";
8
8
  export type TypePolicies = {
9
9
  [__typename: string]: TypePolicy;
10
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/policies.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,SAAS,EACV,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAC7C,OAAO,EAGL,WAAW,EAIZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EAET,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAWpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,K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AC,cAAc;IAoBtB,OAAO,CAAC,eAAe;IAWhB,eAAe,CACpB,QAAQ,EAAE,kBAAkB,GAAG,sBAAsB,EACrD,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC9B,OAAO;IA6FH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM;IAK1D,iBAAiB,CAAC,SAAS,EAAE,cAAc,GAAG,MAAM;IA+CpD,SAAS,CAAC,CAAC,GAAG,UAAU,EAC7B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,sBAAsB,GAC9B,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS;IAgDvB,eAAe,CACpB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,GAChB,iBAAiB,GAAG,SAAS;IAKzB,gBAAgB,CACrB,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,kBAAkB,GAAG,SAAS;IAa1B,gBAAgB,CACrB,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,UAAU,EACpB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,SAAS,EACrC,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,WAAW;CAqDxB;AAmCD,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,UAAU,EACzB,iBAAiB,EAAE,WAAW,GAAG,SAAS,GAAG,SAAS,EACtD,SAAS,CAAC,EAAE,sBAAsB,CAAC,WAAW,CAAC,GAC9C,gBAAgB,CAkClB"}
@@ -1,14 +1,17 @@
1
1
  import { __assign, __rest } from "tslib";
2
- import { invariant, newInvariantError } from '../../utilities/globals/index.js';
3
- import { storeKeyNameFromField, argumentsObjectFromField, isReference, getStoreKeyName, isNonNullObject, stringifyForDisplay, } from '../../utilities/index.js';
4
- import { hasOwn, fieldNameFromStoreName, storeValueIsStoreObject, selectionSetMatchesResult, TypeOrFieldNameRegExp, defaultDataIdFromObject, isArray, } from './helpers.js';
5
- import { cacheSlot } from './reactiveVars.js';
6
- import { canonicalStringify } from './object-canon.js';
7
- import { keyArgsFnFromSpecifier, keyFieldsFnFromSpecifier } from './key-extractor.js';
2
+ import { invariant, newInvariantError } from "../../utilities/globals/index.js";
3
+ import { storeKeyNameFromField, argumentsObjectFromField, isReference, getStoreKeyName, isNonNullObject, stringifyForDisplay, } from "../../utilities/index.js";
4
+ import { hasOwn, fieldNameFromStoreName, storeValueIsStoreObject, selectionSetMatchesResult, TypeOrFieldNameRegExp, defaultDataIdFromObject, isArray, } from "./helpers.js";
5
+ import { cacheSlot } from "./reactiveVars.js";
6
+ import { canonicalStringify } from "./object-canon.js";
7
+ import { keyArgsFnFromSpecifier, keyFieldsFnFromSpecifier, } from "./key-extractor.js";
8
8
  getStoreKeyName.setStringify(canonicalStringify);
9
9
  function argsFromFieldSpecifier(spec) {
10
- return spec.args !== void 0 ? spec.args :
11
- spec.field ? argumentsObjectFromField(spec.field, spec.variables) : null;
10
+ return spec.args !== void 0
11
+ ? spec.args
12
+ : spec.field
13
+ ? argumentsObjectFromField(spec.field, spec.variables)
14
+ : null;
12
15
  }
13
16
  var nullKeyFieldsFn = function () { return void 0; };
14
17
  var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
@@ -42,22 +45,24 @@ var Policies = (function () {
42
45
  Policies.prototype.identify = function (object, partialContext) {
43
46
  var _a;
44
47
  var policies = this;
45
- var typename = partialContext && (partialContext.typename ||
46
- ((_a = partialContext.storeObject) === null || _a === void 0 ? void 0 : _a.__typename)) || object.__typename;
48
+ var typename = (partialContext &&
49
+ (partialContext.typename || ((_a = partialContext.storeObject) === null || _a === void 0 ? void 0 : _a.__typename))) ||
50
+ object.__typename;
47
51
  if (typename === this.rootTypenamesById.ROOT_QUERY) {
48
52
  return ["ROOT_QUERY"];
49
53
  }
50
- var storeObject = partialContext && partialContext.storeObject || object;
51
- var context = __assign(__assign({}, partialContext), { typename: typename, storeObject: storeObject, readField: partialContext && partialContext.readField || function () {
52
- var options = normalizeReadFieldOptions(arguments, storeObject);
53
- return policies.readField(options, {
54
- store: policies.cache["data"],
55
- variables: options.variables,
56
- });
57
- } });
54
+ var storeObject = (partialContext && partialContext.storeObject) || object;
55
+ var context = __assign(__assign({}, partialContext), { typename: typename, storeObject: storeObject, readField: (partialContext && partialContext.readField) ||
56
+ function () {
57
+ var options = normalizeReadFieldOptions(arguments, storeObject);
58
+ return policies.readField(options, {
59
+ store: policies.cache["data"],
60
+ variables: options.variables,
61
+ });
62
+ } });
58
63
  var id;
59
64
  var policy = typename && this.getTypePolicy(typename);
60
- var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
65
+ var keyFn = (policy && policy.keyFn) || this.config.dataIdFromObject;
61
66
  while (keyFn) {
62
67
  var specifierOrId = keyFn(__assign(__assign({}, object), storeObject), context);
63
68
  if (isArray(specifierOrId)) {
@@ -95,17 +100,28 @@ var Policies = (function () {
95
100
  var keyFields = incoming.keyFields, fields = incoming.fields;
96
101
  function setMerge(existing, merge) {
97
102
  existing.merge =
98
- typeof merge === "function" ? merge :
99
- merge === true ? mergeTrueFn :
100
- merge === false ? mergeFalseFn :
101
- existing.merge;
103
+ typeof merge === "function"
104
+ ? merge
105
+ :
106
+ merge === true
107
+ ? mergeTrueFn
108
+ :
109
+ merge === false
110
+ ? mergeFalseFn
111
+ : existing.merge;
102
112
  }
103
113
  setMerge(existing, incoming.merge);
104
114
  existing.keyFn =
105
- keyFields === false ? nullKeyFieldsFn :
106
- isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :
107
- typeof keyFields === "function" ? keyFields :
108
- existing.keyFn;
115
+ keyFields === false
116
+ ? nullKeyFieldsFn
117
+ :
118
+ isArray(keyFields)
119
+ ? keyFieldsFnFromSpecifier(keyFields)
120
+ :
121
+ typeof keyFields === "function"
122
+ ? keyFields
123
+ :
124
+ existing.keyFn;
109
125
  if (fields) {
110
126
  Object.keys(fields).forEach(function (fieldName) {
111
127
  var existing = _this.getFieldPolicy(typename, fieldName, true);
@@ -116,10 +132,16 @@ var Policies = (function () {
116
132
  else {
117
133
  var keyArgs = incoming.keyArgs, read = incoming.read, merge = incoming.merge;
118
134
  existing.keyFn =
119
- keyArgs === false ? simpleKeyArgsFn :
120
- isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :
121
- typeof keyArgs === "function" ? keyArgs :
122
- existing.keyFn;
135
+ keyArgs === false
136
+ ? simpleKeyArgsFn
137
+ :
138
+ isArray(keyArgs)
139
+ ? keyArgsFnFromSpecifier(keyArgs)
140
+ :
141
+ typeof keyArgs === "function"
142
+ ? keyArgs
143
+ :
144
+ existing.keyFn;
123
145
  if (typeof read === "function") {
124
146
  existing.read = read;
125
147
  }
@@ -160,7 +182,7 @@ var Policies = (function () {
160
182
  Policies.prototype.getTypePolicy = function (typename) {
161
183
  var _this = this;
162
184
  if (!hasOwn.call(this.typePolicies, typename)) {
163
- var policy_1 = this.typePolicies[typename] = Object.create(null);
185
+ var policy_1 = (this.typePolicies[typename] = Object.create(null));
164
186
  policy_1.fields = Object.create(null);
165
187
  var supertypes_1 = this.supertypeMap.get(typename);
166
188
  if (!supertypes_1 && this.fuzzySubtypes.size) {
@@ -169,7 +191,9 @@ var Policies = (function () {
169
191
  if (regExp.test(typename)) {
170
192
  var fuzzySupertypes = _this.supertypeMap.get(fuzzy);
171
193
  if (fuzzySupertypes) {
172
- fuzzySupertypes.forEach(function (supertype) { return supertypes_1.add(supertype); });
194
+ fuzzySupertypes.forEach(function (supertype) {
195
+ return supertypes_1.add(supertype);
196
+ });
173
197
  }
174
198
  }
175
199
  });
@@ -193,13 +217,14 @@ var Policies = (function () {
193
217
  Policies.prototype.getFieldPolicy = function (typename, fieldName, createIfMissing) {
194
218
  if (typename) {
195
219
  var fieldPolicies = this.getTypePolicy(typename).fields;
196
- return fieldPolicies[fieldName] || (createIfMissing && (fieldPolicies[fieldName] = Object.create(null)));
220
+ return (fieldPolicies[fieldName] ||
221
+ (createIfMissing && (fieldPolicies[fieldName] = Object.create(null))));
197
222
  }
198
223
  };
199
224
  Policies.prototype.getSupertypeSet = function (subtype, createIfMissing) {
200
225
  var supertypeSet = this.supertypeMap.get(subtype);
201
226
  if (!supertypeSet && createIfMissing) {
202
- this.supertypeMap.set(subtype, supertypeSet = new Set());
227
+ this.supertypeMap.set(subtype, (supertypeSet = new Set()));
203
228
  }
204
229
  return supertypeSet;
205
230
  };
@@ -212,8 +237,7 @@ var Policies = (function () {
212
237
  var supertype = fragment.typeCondition.name.value;
213
238
  if (typename === supertype)
214
239
  return true;
215
- if (this.usingPossibleTypes &&
216
- this.supertypeMap.has(supertype)) {
240
+ if (this.usingPossibleTypes && this.supertypeMap.has(supertype)) {
217
241
  var typenameSupertypeSet = this.getSupertypeSet(typename, true);
218
242
  var workQueue_1 = [typenameSupertypeSet];
219
243
  var maybeEnqueue_1 = function (subtype) {
@@ -315,7 +339,10 @@ var Policies = (function () {
315
339
  var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context, context.store.getStorage(isReference(objectOrReference)
316
340
  ? objectOrReference.__ref
317
341
  : objectOrReference, storeFieldName));
318
- return cacheSlot.withValue(this.cache, read, [existing, readOptions]);
342
+ return cacheSlot.withValue(this.cache, read, [
343
+ existing,
344
+ readOptions,
345
+ ]);
319
346
  }
320
347
  return existing;
321
348
  };
@@ -343,7 +370,12 @@ var Policies = (function () {
343
370
  if (context.overwrite) {
344
371
  existing = void 0;
345
372
  }
346
- return merge(existing, incoming, makeFieldFunctionOptions(this, void 0, { typename: typename, fieldName: field.name.value, field: field, variables: context.variables }, context, storage || Object.create(null)));
373
+ return merge(existing, incoming, makeFieldFunctionOptions(this, void 0, {
374
+ typename: typename,
375
+ fieldName: field.name.value,
376
+ field: field,
377
+ variables: context.variables,
378
+ }, context, storage || Object.create(null)));
347
379
  };
348
380
  return Policies;
349
381
  }());
@@ -398,21 +430,18 @@ function makeMergeObjectsFunction(store) {
398
430
  if (isArray(existing) || isArray(incoming)) {
399
431
  throw newInvariantError(6);
400
432
  }
401
- if (isNonNullObject(existing) &&
402
- isNonNullObject(incoming)) {
433
+ if (isNonNullObject(existing) && isNonNullObject(incoming)) {
403
434
  var eType = store.getFieldValue(existing, "__typename");
404
435
  var iType = store.getFieldValue(incoming, "__typename");
405
436
  var typesDiffer = eType && iType && eType !== iType;
406
437
  if (typesDiffer) {
407
438
  return incoming;
408
439
  }
409
- if (isReference(existing) &&
410
- storeValueIsStoreObject(incoming)) {
440
+ if (isReference(existing) && storeValueIsStoreObject(incoming)) {
411
441
  store.merge(existing.__ref, incoming);
412
442
  return existing;
413
443
  }
414
- if (storeValueIsStoreObject(existing) &&
415
- isReference(incoming)) {
444
+ if (storeValueIsStoreObject(existing) && isReference(incoming)) {
416
445
  store.merge(existing, incoming.__ref);
417
446
  return incoming;
418
447
  }