@apollo/client 3.9.0-alpha.4 → 3.9.0-alpha.5

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 (687) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/beige-geese-wink.md +5 -0
  3. package/.changeset/breezy-spiders-tap.md +38 -0
  4. package/.changeset/clean-items-smash.md +5 -0
  5. package/.changeset/cold-llamas-turn.md +8 -0
  6. package/.changeset/config.json +14 -0
  7. package/.changeset/dirty-kids-crash.md +5 -0
  8. package/.changeset/forty-cups-shop.md +5 -0
  9. package/.changeset/friendly-clouds-laugh.md +7 -0
  10. package/.changeset/hot-ducks-burn.md +5 -0
  11. package/.changeset/polite-avocados-warn.md +5 -0
  12. package/.changeset/pre.json +29 -0
  13. package/.changeset/quick-hats-marry.md +5 -0
  14. package/.changeset/shaggy-ears-scream.md +5 -0
  15. package/.changeset/shaggy-sheep-pull.md +5 -0
  16. package/.changeset/sixty-boxes-rest.md +8 -0
  17. package/.changeset/sour-sheep-walk.md +7 -0
  18. package/.changeset/strong-terms-perform.md +46 -0
  19. package/.changeset/thick-mice-collect.md +5 -0
  20. package/.changeset/thirty-ties-arrive.md +26 -0
  21. package/.changeset/violet-lions-draw.md +5 -0
  22. package/.changeset/wild-dolphins-jog.md +5 -0
  23. package/.changeset/yellow-flies-repeat.md +5 -0
  24. package/CHANGELOG.md +3535 -0
  25. package/apollo-client.cjs +475 -398
  26. package/apollo-client.cjs.map +1 -1
  27. package/apollo-client.min.cjs +1 -1
  28. package/cache/cache.cjs +135 -153
  29. package/cache/cache.cjs.map +1 -1
  30. package/cache/cache.cjs.native.js +135 -153
  31. package/cache/core/cache.d.ts +10 -0
  32. package/cache/core/cache.js +17 -5
  33. package/cache/core/cache.js.map +1 -1
  34. package/cache/core/types/Cache.d.ts +1 -1
  35. package/cache/core/types/Cache.js.map +1 -1
  36. package/cache/core/types/DataProxy.d.ts +92 -0
  37. package/cache/core/types/common.d.ts +1 -1
  38. package/cache/core/types/common.js +4 -1
  39. package/cache/core/types/common.js.map +1 -1
  40. package/cache/inmemory/entityStore.d.ts +10 -1
  41. package/cache/inmemory/entityStore.js +190 -29
  42. package/cache/inmemory/entityStore.js.map +1 -1
  43. package/cache/inmemory/fixPolyfills.js +9 -0
  44. package/cache/inmemory/fixPolyfills.js.map +1 -1
  45. package/cache/inmemory/fixPolyfills.native.js +12 -0
  46. package/cache/inmemory/fixPolyfills.native.js.map +1 -1
  47. package/cache/inmemory/fragmentRegistry.d.ts +1 -0
  48. package/cache/inmemory/fragmentRegistry.js +23 -14
  49. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  50. package/cache/inmemory/helpers.js +20 -11
  51. package/cache/inmemory/helpers.js.map +1 -1
  52. package/cache/inmemory/inMemoryCache.js +164 -8
  53. package/cache/inmemory/inMemoryCache.js.map +1 -1
  54. package/cache/inmemory/key-extractor.js +72 -4
  55. package/cache/inmemory/key-extractor.js.map +1 -1
  56. package/cache/inmemory/object-canon.js +87 -3
  57. package/cache/inmemory/object-canon.js.map +1 -1
  58. package/cache/inmemory/policies.js +190 -43
  59. package/cache/inmemory/policies.js.map +1 -1
  60. package/cache/inmemory/reactiveVars.js +20 -2
  61. package/cache/inmemory/reactiveVars.js.map +1 -1
  62. package/cache/inmemory/readFromStore.d.ts +4 -0
  63. package/cache/inmemory/readFromStore.js +58 -9
  64. package/cache/inmemory/readFromStore.js.map +1 -1
  65. package/cache/inmemory/types.d.ts +28 -0
  66. package/cache/inmemory/types.js.map +1 -1
  67. package/cache/inmemory/writeToStore.js +152 -25
  68. package/cache/inmemory/writeToStore.js.map +1 -1
  69. package/config/jest/setup.js +2 -0
  70. package/config/jest/setup.js.map +1 -1
  71. package/core/ApolloClient.d.ts +264 -3
  72. package/core/ApolloClient.js +235 -7
  73. package/core/ApolloClient.js.map +1 -1
  74. package/core/LocalState.d.ts +4 -6
  75. package/core/LocalState.js +56 -18
  76. package/core/LocalState.js.map +1 -1
  77. package/core/ObservableQuery.d.ts +25 -0
  78. package/core/ObservableQuery.js +239 -30
  79. package/core/ObservableQuery.js.map +1 -1
  80. package/core/QueryInfo.d.ts +3 -3
  81. package/core/QueryInfo.js +118 -13
  82. package/core/QueryInfo.js.map +1 -1
  83. package/core/QueryManager.d.ts +8 -1
  84. package/core/QueryManager.js +247 -46
  85. package/core/QueryManager.js.map +1 -1
  86. package/core/core.cjs +127 -114
  87. package/core/core.cjs.map +1 -1
  88. package/core/core.cjs.native.js +127 -114
  89. package/core/equalByQuery.js +20 -1
  90. package/core/equalByQuery.js.map +1 -1
  91. package/core/index.d.ts +1 -1
  92. package/core/index.js +19 -0
  93. package/core/index.js.map +1 -1
  94. package/core/networkStatus.d.ts +39 -0
  95. package/core/networkStatus.js +39 -0
  96. package/core/networkStatus.js.map +1 -1
  97. package/core/types.d.ts +9 -0
  98. package/core/types.js.map +1 -1
  99. package/core/watchQueryOptions.d.ts +225 -1
  100. package/core/watchQueryOptions.js.map +1 -1
  101. package/dev/dev.cjs +10 -119
  102. package/dev/dev.cjs.map +1 -1
  103. package/dev/dev.cjs.native.js +10 -119
  104. package/dev/loadErrorMessageHandler.js.map +1 -1
  105. package/errors/errors.cjs +1 -1
  106. package/errors/errors.cjs.map +1 -1
  107. package/errors/errors.cjs.native.js +1 -1
  108. package/errors/index.js +14 -1
  109. package/errors/index.js.map +1 -1
  110. package/invariantErrorCodes.js +6 -8
  111. package/link/batch/batch.cjs +2 -2
  112. package/link/batch/batch.cjs.map +1 -1
  113. package/link/batch/batch.cjs.native.js +2 -2
  114. package/link/batch/batchLink.d.ts +21 -0
  115. package/link/batch/batchLink.js +2 -1
  116. package/link/batch/batchLink.js.map +1 -1
  117. package/link/batch/batching.js +24 -1
  118. package/link/batch/batching.js.map +1 -1
  119. package/link/batch-http/batch-http.cjs +3 -2
  120. package/link/batch-http/batch-http.cjs.map +1 -1
  121. package/link/batch-http/batch-http.cjs.native.js +3 -2
  122. package/link/batch-http/batchHttpLink.d.ts +4 -0
  123. package/link/batch-http/batchHttpLink.js +53 -2
  124. package/link/batch-http/batchHttpLink.js.map +1 -1
  125. package/link/context/context.cjs.map +1 -1
  126. package/link/context/index.js +1 -0
  127. package/link/context/index.js.map +1 -1
  128. package/link/core/ApolloLink.js +12 -5
  129. package/link/core/ApolloLink.js.map +1 -1
  130. package/link/core/core.cjs +5 -5
  131. package/link/core/core.cjs.map +1 -1
  132. package/link/core/core.cjs.native.js +5 -5
  133. package/link/error/error.cjs +1 -1
  134. package/link/error/error.cjs.map +1 -1
  135. package/link/error/error.cjs.native.js +1 -1
  136. package/link/error/index.d.ts +3 -0
  137. package/link/error/index.js +4 -1
  138. package/link/error/index.js.map +1 -1
  139. package/link/http/HttpLink.d.ts +0 -2
  140. package/link/http/HttpLink.js +1 -1
  141. package/link/http/HttpLink.js.map +1 -1
  142. package/link/http/checkFetcher.js.map +1 -1
  143. package/link/http/createHttpLink.js +23 -1
  144. package/link/http/createHttpLink.js.map +1 -1
  145. package/link/http/createSignalIfSupported.d.ts +5 -0
  146. package/link/http/createSignalIfSupported.js +5 -0
  147. package/link/http/createSignalIfSupported.js.map +1 -1
  148. package/link/http/http.cjs +14 -12
  149. package/link/http/http.cjs.map +1 -1
  150. package/link/http/http.cjs.native.js +14 -12
  151. package/link/http/index.js +2 -1
  152. package/link/http/index.js.map +1 -1
  153. package/link/http/iterators/async.d.ts +4 -0
  154. package/link/http/iterators/async.js +4 -0
  155. package/link/http/iterators/async.js.map +1 -1
  156. package/link/http/iterators/nodeStream.d.ts +4 -0
  157. package/link/http/iterators/nodeStream.js +4 -0
  158. package/link/http/iterators/nodeStream.js.map +1 -1
  159. package/link/http/iterators/promise.d.ts +4 -0
  160. package/link/http/iterators/promise.js +4 -0
  161. package/link/http/iterators/promise.js.map +1 -1
  162. package/link/http/iterators/reader.d.ts +4 -0
  163. package/link/http/iterators/reader.js +4 -0
  164. package/link/http/iterators/reader.js.map +1 -1
  165. package/link/http/parseAndCheckHttpResponse.js +51 -10
  166. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  167. package/link/http/responseIterator.d.ts +4 -0
  168. package/link/http/responseIterator.js +6 -0
  169. package/link/http/responseIterator.js.map +1 -1
  170. package/link/http/rewriteURIForGET.d.ts +1 -1
  171. package/link/http/rewriteURIForGET.js +10 -0
  172. package/link/http/rewriteURIForGET.js.map +1 -1
  173. package/link/http/selectHttpOptionsAndBody.d.ts +45 -0
  174. package/link/http/selectHttpOptionsAndBody.js +23 -0
  175. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  176. package/link/http/selectURI.js.map +1 -1
  177. package/link/http/serializeFetchParameter.js.map +1 -1
  178. package/link/persisted-queries/index.js +34 -4
  179. package/link/persisted-queries/index.js.map +1 -1
  180. package/link/persisted-queries/persisted-queries.cjs +4 -4
  181. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  182. package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
  183. package/link/remove-typename/remove-typename.cjs +12 -9
  184. package/link/remove-typename/remove-typename.cjs.map +1 -1
  185. package/link/remove-typename/remove-typename.cjs.native.js +12 -9
  186. package/link/remove-typename/removeTypenameFromVariables.js +12 -9
  187. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  188. package/link/retry/delayFunction.d.ts +29 -0
  189. package/link/retry/delayFunction.js +6 -0
  190. package/link/retry/delayFunction.js.map +1 -1
  191. package/link/retry/retry.cjs +5 -5
  192. package/link/retry/retry.cjs.map +1 -1
  193. package/link/retry/retry.cjs.native.js +5 -5
  194. package/link/retry/retryFunction.d.ts +20 -0
  195. package/link/retry/retryLink.d.ts +6 -0
  196. package/link/retry/retryLink.js +31 -6
  197. package/link/retry/retryLink.js.map +1 -1
  198. package/link/schema/index.d.ts +13 -0
  199. package/link/schema/index.js +3 -3
  200. package/link/schema/index.js.map +1 -1
  201. package/link/schema/schema.cjs +3 -3
  202. package/link/schema/schema.cjs.map +1 -1
  203. package/link/schema/schema.cjs.native.js +3 -3
  204. package/link/subscriptions/index.js +35 -2
  205. package/link/subscriptions/index.js.map +1 -1
  206. package/link/subscriptions/subscriptions.cjs +3 -2
  207. package/link/subscriptions/subscriptions.cjs.map +1 -1
  208. package/link/subscriptions/subscriptions.cjs.native.js +3 -2
  209. package/link/utils/createOperation.js.map +1 -1
  210. package/link/utils/filterOperationVariables.js +4 -0
  211. package/link/utils/filterOperationVariables.js.map +1 -1
  212. package/link/utils/toPromise.js.map +1 -1
  213. package/link/utils/transformOperation.js +3 -2
  214. package/link/utils/transformOperation.js.map +1 -1
  215. package/link/utils/utils.cjs +2 -2
  216. package/link/utils/utils.cjs.map +1 -1
  217. package/link/utils/utils.cjs.native.js +2 -2
  218. package/link/utils/validateOperation.js.map +1 -1
  219. package/link/ws/index.d.ts +12 -0
  220. package/link/ws/index.js +1 -1
  221. package/link/ws/index.js.map +1 -1
  222. package/link/ws/ws.cjs +1 -1
  223. package/link/ws/ws.cjs.map +1 -1
  224. package/link/ws/ws.cjs.native.js +1 -1
  225. package/package.json +50 -38
  226. package/react/cache/QueryReference.d.ts +18 -10
  227. package/react/cache/QueryReference.js +52 -8
  228. package/react/cache/QueryReference.js.map +1 -1
  229. package/react/cache/SuspenseCache.d.ts +10 -0
  230. package/react/cache/SuspenseCache.js +1 -2
  231. package/react/cache/SuspenseCache.js.map +1 -1
  232. package/react/cache/getSuspenseCache.js.map +1 -1
  233. package/react/cache/types.d.ts +3 -0
  234. package/react/cache/types.js.map +1 -1
  235. package/react/context/ApolloContext.d.ts +5 -0
  236. package/react/context/ApolloContext.js +10 -3
  237. package/react/context/ApolloContext.js.map +1 -1
  238. package/react/context/context.cjs +1 -3
  239. package/react/context/context.cjs.map +1 -1
  240. package/react/context/context.cjs.native.js +1 -3
  241. package/react/hoc/graphql.js.map +1 -1
  242. package/react/hoc/hoc-utils.js +3 -1
  243. package/react/hoc/hoc-utils.js.map +1 -1
  244. package/react/hoc/hoc.cjs +9 -17
  245. package/react/hoc/hoc.cjs.map +1 -1
  246. package/react/hoc/hoc.cjs.native.js +9 -17
  247. package/react/hoc/mutation-hoc.js +9 -4
  248. package/react/hoc/mutation-hoc.js.map +1 -1
  249. package/react/hoc/query-hoc.js +10 -4
  250. package/react/hoc/query-hoc.js.map +1 -1
  251. package/react/hoc/subscription-hoc.js +10 -4
  252. package/react/hoc/subscription-hoc.js.map +1 -1
  253. package/react/hoc/withApollo.js +3 -4
  254. package/react/hoc/withApollo.js.map +1 -1
  255. package/react/hooks/hooks.cjs +138 -66
  256. package/react/hooks/hooks.cjs.map +1 -1
  257. package/react/hooks/hooks.cjs.native.js +138 -66
  258. package/react/hooks/index.d.ts +2 -0
  259. package/react/hooks/index.js +1 -0
  260. package/react/hooks/index.js.map +1 -1
  261. package/react/hooks/internal/__use.js +5 -0
  262. package/react/hooks/internal/__use.js.map +1 -1
  263. package/react/hooks/internal/index.d.ts +1 -0
  264. package/react/hooks/internal/index.js +2 -0
  265. package/react/hooks/internal/index.js.map +1 -1
  266. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  267. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
  268. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  269. package/react/hooks/internal/useRenderGuard.d.ts +2 -0
  270. package/react/hooks/internal/useRenderGuard.js +17 -0
  271. package/react/hooks/internal/useRenderGuard.js.map +1 -0
  272. package/react/hooks/useBackgroundQuery.js +14 -11
  273. package/react/hooks/useBackgroundQuery.js.map +1 -1
  274. package/react/hooks/useFragment.js +4 -3
  275. package/react/hooks/useFragment.js.map +1 -1
  276. package/react/hooks/useLazyQuery.js +13 -4
  277. package/react/hooks/useLazyQuery.js.map +1 -1
  278. package/react/hooks/useLoadableQuery.d.ts +30 -0
  279. package/react/hooks/useLoadableQuery.js +61 -0
  280. package/react/hooks/useLoadableQuery.js.map +1 -0
  281. package/react/hooks/useMutation.js +8 -3
  282. package/react/hooks/useMutation.js.map +1 -1
  283. package/react/hooks/useQuery.d.ts +11 -0
  284. package/react/hooks/useQuery.js +138 -6
  285. package/react/hooks/useQuery.js.map +1 -1
  286. package/react/hooks/useReactiveVar.js +5 -0
  287. package/react/hooks/useReactiveVar.js.map +1 -1
  288. package/react/hooks/useReadQuery.d.ts +19 -0
  289. package/react/hooks/useReadQuery.js +4 -10
  290. package/react/hooks/useReadQuery.js.map +1 -1
  291. package/react/hooks/useSubscription.js +5 -0
  292. package/react/hooks/useSubscription.js.map +1 -1
  293. package/react/hooks/useSuspenseQuery.js +22 -22
  294. package/react/hooks/useSuspenseQuery.js.map +1 -1
  295. package/react/hooks/useSyncExternalStore.js +53 -1
  296. package/react/hooks/useSyncExternalStore.js.map +1 -1
  297. package/react/parser/index.d.ts +3 -0
  298. package/react/parser/index.js +13 -6
  299. package/react/parser/index.js.map +1 -1
  300. package/react/parser/parser.cjs +11 -5
  301. package/react/parser/parser.cjs.map +1 -1
  302. package/react/parser/parser.cjs.native.js +11 -5
  303. package/react/ssr/RenderPromises.js +21 -1
  304. package/react/ssr/RenderPromises.js.map +1 -1
  305. package/react/ssr/getDataFromTree.js +18 -3
  306. package/react/ssr/getDataFromTree.js.map +1 -1
  307. package/react/ssr/ssr.cjs +6 -4
  308. package/react/ssr/ssr.cjs.map +1 -1
  309. package/react/ssr/ssr.cjs.native.js +6 -4
  310. package/react/types/types.d.ts +123 -1
  311. package/react/types/types.js.map +1 -1
  312. package/testing/core/core.cjs +14 -11
  313. package/testing/core/core.cjs.map +1 -1
  314. package/testing/core/core.cjs.native.js +14 -11
  315. package/testing/core/itAsync.d.ts +1 -1
  316. package/testing/core/itAsync.js.map +1 -1
  317. package/testing/core/mocking/mockFetch.d.ts +2 -2
  318. package/testing/core/mocking/mockFetch.js +8 -4
  319. package/testing/core/mocking/mockFetch.js.map +1 -1
  320. package/testing/core/mocking/mockLink.d.ts +1 -1
  321. package/testing/core/mocking/mockLink.js +17 -7
  322. package/testing/core/mocking/mockLink.js.map +1 -1
  323. package/testing/core/mocking/mockQueryManager.js +2 -0
  324. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  325. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  326. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  327. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  328. package/testing/core/mocking/mockWatchQuery.js +1 -1
  329. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  330. package/testing/core/observableToPromise.d.ts +17 -3
  331. package/testing/core/observableToPromise.js +5 -0
  332. package/testing/core/observableToPromise.js.map +1 -1
  333. package/testing/core/subscribeAndCount.js +3 -0
  334. package/testing/core/subscribeAndCount.js.map +1 -1
  335. package/testing/core/wait.js +2 -2
  336. package/testing/core/wait.js.map +1 -1
  337. package/testing/core/withConsoleSpy.d.ts +3 -0
  338. package/testing/core/withConsoleSpy.js +7 -1
  339. package/testing/core/withConsoleSpy.js.map +1 -1
  340. package/testing/core/wrap.js +2 -0
  341. package/testing/core/wrap.js.map +1 -1
  342. package/testing/internal/ObservableStream.js +14 -14
  343. package/testing/internal/ObservableStream.js.map +1 -1
  344. package/testing/internal/disposables/disableActWarnings.d.ts +10 -0
  345. package/testing/internal/disposables/disableActWarnings.js +15 -0
  346. package/testing/internal/disposables/disableActWarnings.js.map +1 -0
  347. package/testing/internal/disposables/index.d.ts +1 -0
  348. package/testing/internal/disposables/index.js +1 -0
  349. package/testing/internal/disposables/index.js.map +1 -1
  350. package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
  351. package/testing/internal/disposables/spyOnConsole.js +2 -0
  352. package/testing/internal/disposables/spyOnConsole.js.map +1 -1
  353. package/testing/internal/disposables/withCleanup.d.ts +1 -0
  354. package/testing/internal/disposables/withCleanup.js +3 -0
  355. package/testing/internal/disposables/withCleanup.js.map +1 -1
  356. package/testing/internal/profile/Render.d.ts +32 -1
  357. package/testing/internal/profile/Render.js +14 -2
  358. package/testing/internal/profile/Render.js.map +1 -1
  359. package/testing/internal/profile/context.d.ts +10 -0
  360. package/testing/internal/profile/context.js +14 -0
  361. package/testing/internal/profile/context.js.map +1 -0
  362. package/testing/internal/profile/index.d.ts +2 -2
  363. package/testing/internal/profile/index.js +1 -1
  364. package/testing/internal/profile/index.js.map +1 -1
  365. package/testing/internal/profile/profile.d.ts +67 -13
  366. package/testing/internal/profile/profile.js +153 -79
  367. package/testing/internal/profile/profile.js.map +1 -1
  368. package/testing/internal/profile/traces.d.ts +4 -0
  369. package/testing/internal/profile/traces.js +9 -5
  370. package/testing/internal/profile/traces.js.map +1 -1
  371. package/testing/matchers/ProfiledComponent.js +29 -26
  372. package/testing/matchers/ProfiledComponent.js.map +1 -1
  373. package/testing/matchers/index.js +2 -0
  374. package/testing/matchers/index.js.map +1 -1
  375. package/testing/matchers/toBeGarbageCollected.d.ts +8 -0
  376. package/testing/matchers/toBeGarbageCollected.js +48 -0
  377. package/testing/matchers/toBeGarbageCollected.js.map +1 -0
  378. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  379. package/testing/matchers/toMatchDocument.js.map +1 -1
  380. package/testing/react/MockedProvider.d.ts +5 -1
  381. package/testing/react/MockedProvider.js +6 -2
  382. package/testing/react/MockedProvider.js.map +1 -1
  383. package/testing/testing.cjs +4 -2
  384. package/testing/testing.cjs.map +1 -1
  385. package/testing/testing.cjs.native.js +4 -2
  386. package/utilities/common/arrays.js +1 -0
  387. package/utilities/common/arrays.js.map +1 -1
  388. package/utilities/common/canUse.js +16 -1
  389. package/utilities/common/canUse.js.map +1 -1
  390. package/utilities/common/canonicalStringify.d.ts +17 -0
  391. package/utilities/common/canonicalStringify.js +41 -0
  392. package/utilities/common/canonicalStringify.js.map +1 -1
  393. package/utilities/common/cloneDeep.d.ts +3 -0
  394. package/utilities/common/cloneDeep.js +5 -0
  395. package/utilities/common/cloneDeep.js.map +1 -1
  396. package/utilities/common/compact.d.ts +4 -0
  397. package/utilities/common/compact.js +4 -0
  398. package/utilities/common/compact.js.map +1 -1
  399. package/utilities/common/errorHandling.js +1 -3
  400. package/utilities/common/errorHandling.js.map +1 -1
  401. package/utilities/common/incrementalResult.js +3 -0
  402. package/utilities/common/incrementalResult.js.map +1 -1
  403. package/utilities/common/makeUniqueId.js +2 -0
  404. package/utilities/common/makeUniqueId.js.map +1 -1
  405. package/utilities/common/maybeDeepFreeze.js +3 -0
  406. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  407. package/utilities/common/mergeDeep.js +12 -1
  408. package/utilities/common/mergeDeep.js.map +1 -1
  409. package/utilities/common/mergeOptions.d.ts +1 -1
  410. package/utilities/common/mergeOptions.js.map +1 -1
  411. package/utilities/common/omitDeep.js.map +1 -1
  412. package/utilities/globals/global.js +7 -1
  413. package/utilities/globals/global.js.map +1 -1
  414. package/utilities/globals/globals.cjs +4 -5
  415. package/utilities/globals/globals.cjs.map +1 -1
  416. package/utilities/globals/globals.cjs.native.js +4 -5
  417. package/utilities/globals/index.d.ts +4 -0
  418. package/utilities/globals/index.js +7 -0
  419. package/utilities/globals/index.js.map +1 -1
  420. package/utilities/globals/invariantWrappers.d.ts +40 -0
  421. package/utilities/globals/invariantWrappers.js +11 -3
  422. package/utilities/globals/invariantWrappers.js.map +1 -1
  423. package/utilities/globals/maybe.js.map +1 -1
  424. package/utilities/graphql/DocumentTransform.d.ts +6 -5
  425. package/utilities/graphql/DocumentTransform.js +48 -27
  426. package/utilities/graphql/DocumentTransform.js.map +1 -1
  427. package/utilities/graphql/directives.js +3 -0
  428. package/utilities/graphql/directives.js.map +1 -1
  429. package/utilities/graphql/fragments.d.ts +25 -0
  430. package/utilities/graphql/fragments.js +36 -0
  431. package/utilities/graphql/fragments.js.map +1 -1
  432. package/utilities/graphql/getFromAST.d.ts +5 -0
  433. package/utilities/graphql/getFromAST.js +9 -0
  434. package/utilities/graphql/getFromAST.js.map +1 -1
  435. package/utilities/graphql/print.js +4 -5
  436. package/utilities/graphql/print.js.map +1 -1
  437. package/utilities/graphql/storeUtils.d.ts +14 -0
  438. package/utilities/graphql/storeUtils.js +8 -2
  439. package/utilities/graphql/storeUtils.js.map +1 -1
  440. package/utilities/graphql/transform.js +106 -7
  441. package/utilities/graphql/transform.js.map +1 -1
  442. package/utilities/index.d.ts +2 -0
  443. package/utilities/index.js.map +1 -1
  444. package/utilities/observables/Concast.d.ts +1 -1
  445. package/utilities/observables/Concast.js +85 -2
  446. package/utilities/observables/Concast.js.map +1 -1
  447. package/utilities/observables/Observable.js +6 -0
  448. package/utilities/observables/Observable.js.map +1 -1
  449. package/utilities/observables/asyncMap.js +12 -3
  450. package/utilities/observables/asyncMap.js.map +1 -1
  451. package/utilities/observables/iteration.js +3 -0
  452. package/utilities/observables/iteration.js.map +1 -1
  453. package/utilities/observables/subclassing.js +14 -0
  454. package/utilities/observables/subclassing.js.map +1 -1
  455. package/utilities/policies/pagination.js +47 -3
  456. package/utilities/policies/pagination.js.map +1 -1
  457. package/utilities/promises/decoration.js +1 -0
  458. package/utilities/promises/decoration.js.map +1 -1
  459. package/utilities/subscriptions/relay/index.js.map +1 -1
  460. package/utilities/subscriptions/relay/relay.cjs +9 -8
  461. package/utilities/subscriptions/relay/relay.cjs.map +1 -1
  462. package/utilities/subscriptions/relay/relay.cjs.native.js +9 -8
  463. package/utilities/subscriptions/urql/index.js.map +1 -1
  464. package/utilities/subscriptions/urql/urql.cjs +9 -8
  465. package/utilities/subscriptions/urql/urql.cjs.map +1 -1
  466. package/utilities/subscriptions/urql/urql.cjs.native.js +9 -8
  467. package/utilities/types/DeepOmit.js.map +1 -1
  468. package/utilities/types/DeepPartial.d.ts +1 -1
  469. package/utilities/types/DeepPartial.js +4 -0
  470. package/utilities/types/DeepPartial.js.map +1 -1
  471. package/utilities/types/IsStrictlyAny.js.map +1 -1
  472. package/utilities/types/OnlyRequiredProperties.d.ts +7 -0
  473. package/utilities/types/OnlyRequiredProperties.js +2 -0
  474. package/utilities/types/OnlyRequiredProperties.js.map +1 -0
  475. package/utilities/types/TODO.d.ts +3 -0
  476. package/utilities/types/TODO.js +2 -0
  477. package/utilities/types/TODO.js.map +1 -0
  478. package/utilities/utilities.cjs +61 -53
  479. package/utilities/utilities.cjs.map +1 -1
  480. package/utilities/utilities.cjs.native.js +61 -53
  481. package/version.js +1 -1
  482. package/cache/core/cache.d.ts.map +0 -1
  483. package/cache/core/types/Cache.d.ts.map +0 -1
  484. package/cache/core/types/DataProxy.d.ts.map +0 -1
  485. package/cache/core/types/common.d.ts.map +0 -1
  486. package/cache/index.d.ts.map +0 -1
  487. package/cache/inmemory/entityStore.d.ts.map +0 -1
  488. package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
  489. package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
  490. package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
  491. package/cache/inmemory/helpers.d.ts.map +0 -1
  492. package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
  493. package/cache/inmemory/key-extractor.d.ts.map +0 -1
  494. package/cache/inmemory/object-canon.d.ts.map +0 -1
  495. package/cache/inmemory/policies.d.ts.map +0 -1
  496. package/cache/inmemory/reactiveVars.d.ts.map +0 -1
  497. package/cache/inmemory/readFromStore.d.ts.map +0 -1
  498. package/cache/inmemory/types.d.ts.map +0 -1
  499. package/cache/inmemory/writeToStore.d.ts.map +0 -1
  500. package/config/jest/setup.d.ts.map +0 -1
  501. package/core/ApolloClient.d.ts.map +0 -1
  502. package/core/LocalState.d.ts.map +0 -1
  503. package/core/ObservableQuery.d.ts.map +0 -1
  504. package/core/QueryInfo.d.ts.map +0 -1
  505. package/core/QueryManager.d.ts.map +0 -1
  506. package/core/equalByQuery.d.ts.map +0 -1
  507. package/core/index.d.ts.map +0 -1
  508. package/core/networkStatus.d.ts.map +0 -1
  509. package/core/types.d.ts.map +0 -1
  510. package/core/watchQueryOptions.d.ts.map +0 -1
  511. package/dev/index.d.ts.map +0 -1
  512. package/dev/loadDevMessages.d.ts.map +0 -1
  513. package/dev/loadErrorMessageHandler.d.ts.map +0 -1
  514. package/dev/loadErrorMessages.d.ts.map +0 -1
  515. package/errors/index.d.ts.map +0 -1
  516. package/index.d.ts.map +0 -1
  517. package/invariantErrorCodes.d.ts.map +0 -1
  518. package/link/batch/batchLink.d.ts.map +0 -1
  519. package/link/batch/batching.d.ts.map +0 -1
  520. package/link/batch/index.d.ts.map +0 -1
  521. package/link/batch-http/batchHttpLink.d.ts.map +0 -1
  522. package/link/batch-http/index.d.ts.map +0 -1
  523. package/link/context/index.d.ts.map +0 -1
  524. package/link/core/ApolloLink.d.ts.map +0 -1
  525. package/link/core/concat.d.ts.map +0 -1
  526. package/link/core/empty.d.ts.map +0 -1
  527. package/link/core/execute.d.ts.map +0 -1
  528. package/link/core/from.d.ts.map +0 -1
  529. package/link/core/index.d.ts.map +0 -1
  530. package/link/core/split.d.ts.map +0 -1
  531. package/link/core/types.d.ts.map +0 -1
  532. package/link/error/index.d.ts.map +0 -1
  533. package/link/http/HttpLink.d.ts.map +0 -1
  534. package/link/http/checkFetcher.d.ts.map +0 -1
  535. package/link/http/createHttpLink.d.ts.map +0 -1
  536. package/link/http/createSignalIfSupported.d.ts.map +0 -1
  537. package/link/http/index.d.ts.map +0 -1
  538. package/link/http/iterators/async.d.ts.map +0 -1
  539. package/link/http/iterators/nodeStream.d.ts.map +0 -1
  540. package/link/http/iterators/promise.d.ts.map +0 -1
  541. package/link/http/iterators/reader.d.ts.map +0 -1
  542. package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
  543. package/link/http/responseIterator.d.ts.map +0 -1
  544. package/link/http/rewriteURIForGET.d.ts.map +0 -1
  545. package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
  546. package/link/http/selectURI.d.ts.map +0 -1
  547. package/link/http/serializeFetchParameter.d.ts.map +0 -1
  548. package/link/persisted-queries/index.d.ts.map +0 -1
  549. package/link/remove-typename/index.d.ts.map +0 -1
  550. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
  551. package/link/retry/delayFunction.d.ts.map +0 -1
  552. package/link/retry/index.d.ts.map +0 -1
  553. package/link/retry/retryFunction.d.ts.map +0 -1
  554. package/link/retry/retryLink.d.ts.map +0 -1
  555. package/link/schema/index.d.ts.map +0 -1
  556. package/link/subscriptions/index.d.ts.map +0 -1
  557. package/link/utils/createOperation.d.ts.map +0 -1
  558. package/link/utils/filterOperationVariables.d.ts.map +0 -1
  559. package/link/utils/fromError.d.ts.map +0 -1
  560. package/link/utils/fromPromise.d.ts.map +0 -1
  561. package/link/utils/index.d.ts.map +0 -1
  562. package/link/utils/throwServerError.d.ts.map +0 -1
  563. package/link/utils/toPromise.d.ts.map +0 -1
  564. package/link/utils/transformOperation.d.ts.map +0 -1
  565. package/link/utils/validateOperation.d.ts.map +0 -1
  566. package/link/ws/index.d.ts.map +0 -1
  567. package/react/cache/QueryReference.d.ts.map +0 -1
  568. package/react/cache/SuspenseCache.d.ts.map +0 -1
  569. package/react/cache/getSuspenseCache.d.ts.map +0 -1
  570. package/react/cache/index.d.ts.map +0 -1
  571. package/react/cache/types.d.ts.map +0 -1
  572. package/react/components/Mutation.d.ts.map +0 -1
  573. package/react/components/Query.d.ts.map +0 -1
  574. package/react/components/Subscription.d.ts.map +0 -1
  575. package/react/components/index.d.ts.map +0 -1
  576. package/react/components/types.d.ts.map +0 -1
  577. package/react/context/ApolloConsumer.d.ts.map +0 -1
  578. package/react/context/ApolloContext.d.ts.map +0 -1
  579. package/react/context/ApolloProvider.d.ts.map +0 -1
  580. package/react/context/index.d.ts.map +0 -1
  581. package/react/hoc/graphql.d.ts.map +0 -1
  582. package/react/hoc/hoc-utils.d.ts.map +0 -1
  583. package/react/hoc/index.d.ts.map +0 -1
  584. package/react/hoc/mutation-hoc.d.ts.map +0 -1
  585. package/react/hoc/query-hoc.d.ts.map +0 -1
  586. package/react/hoc/subscription-hoc.d.ts.map +0 -1
  587. package/react/hoc/types.d.ts.map +0 -1
  588. package/react/hoc/withApollo.d.ts.map +0 -1
  589. package/react/hooks/constants.d.ts.map +0 -1
  590. package/react/hooks/index.d.ts.map +0 -1
  591. package/react/hooks/internal/__use.d.ts.map +0 -1
  592. package/react/hooks/internal/index.d.ts.map +0 -1
  593. package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
  594. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
  595. package/react/hooks/useApolloClient.d.ts.map +0 -1
  596. package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
  597. package/react/hooks/useFragment.d.ts.map +0 -1
  598. package/react/hooks/useLazyQuery.d.ts.map +0 -1
  599. package/react/hooks/useMutation.d.ts.map +0 -1
  600. package/react/hooks/useQuery.d.ts.map +0 -1
  601. package/react/hooks/useReactiveVar.d.ts.map +0 -1
  602. package/react/hooks/useReadQuery.d.ts.map +0 -1
  603. package/react/hooks/useSubscription.d.ts.map +0 -1
  604. package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
  605. package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
  606. package/react/index.d.ts.map +0 -1
  607. package/react/parser/index.d.ts.map +0 -1
  608. package/react/ssr/RenderPromises.d.ts.map +0 -1
  609. package/react/ssr/getDataFromTree.d.ts.map +0 -1
  610. package/react/ssr/index.d.ts.map +0 -1
  611. package/react/ssr/renderToStringWithData.d.ts.map +0 -1
  612. package/react/types/types.d.ts.map +0 -1
  613. package/testing/core/index.d.ts.map +0 -1
  614. package/testing/core/itAsync.d.ts.map +0 -1
  615. package/testing/core/mocking/mockClient.d.ts.map +0 -1
  616. package/testing/core/mocking/mockFetch.d.ts.map +0 -1
  617. package/testing/core/mocking/mockLink.d.ts.map +0 -1
  618. package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
  619. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
  620. package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
  621. package/testing/core/observableToPromise.d.ts.map +0 -1
  622. package/testing/core/subscribeAndCount.d.ts.map +0 -1
  623. package/testing/core/wait.d.ts.map +0 -1
  624. package/testing/core/withConsoleSpy.d.ts.map +0 -1
  625. package/testing/core/wrap.d.ts.map +0 -1
  626. package/testing/index.d.ts.map +0 -1
  627. package/testing/internal/ObservableStream.d.ts.map +0 -1
  628. package/testing/internal/disposables/index.d.ts.map +0 -1
  629. package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
  630. package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
  631. package/testing/internal/index.d.ts.map +0 -1
  632. package/testing/internal/profile/Render.d.ts.map +0 -1
  633. package/testing/internal/profile/index.d.ts.map +0 -1
  634. package/testing/internal/profile/profile.d.ts.map +0 -1
  635. package/testing/internal/profile/traces.d.ts.map +0 -1
  636. package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
  637. package/testing/matchers/index.d.ts.map +0 -1
  638. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
  639. package/testing/matchers/toMatchDocument.d.ts.map +0 -1
  640. package/testing/react/MockedProvider.d.ts.map +0 -1
  641. package/utilities/common/arrays.d.ts.map +0 -1
  642. package/utilities/common/canUse.d.ts.map +0 -1
  643. package/utilities/common/canonicalStringify.d.ts.map +0 -1
  644. package/utilities/common/cloneDeep.d.ts.map +0 -1
  645. package/utilities/common/compact.d.ts.map +0 -1
  646. package/utilities/common/errorHandling.d.ts.map +0 -1
  647. package/utilities/common/filterInPlace.d.ts +0 -2
  648. package/utilities/common/filterInPlace.d.ts.map +0 -1
  649. package/utilities/common/filterInPlace.js +0 -11
  650. package/utilities/common/filterInPlace.js.map +0 -1
  651. package/utilities/common/incrementalResult.d.ts.map +0 -1
  652. package/utilities/common/makeUniqueId.d.ts.map +0 -1
  653. package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
  654. package/utilities/common/mergeDeep.d.ts.map +0 -1
  655. package/utilities/common/mergeOptions.d.ts.map +0 -1
  656. package/utilities/common/objects.d.ts.map +0 -1
  657. package/utilities/common/omitDeep.d.ts.map +0 -1
  658. package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
  659. package/utilities/common/stripTypename.d.ts.map +0 -1
  660. package/utilities/globals/global.d.ts.map +0 -1
  661. package/utilities/globals/index.d.ts.map +0 -1
  662. package/utilities/globals/invariantWrappers.d.ts.map +0 -1
  663. package/utilities/globals/maybe.d.ts.map +0 -1
  664. package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
  665. package/utilities/graphql/directives.d.ts.map +0 -1
  666. package/utilities/graphql/fragments.d.ts.map +0 -1
  667. package/utilities/graphql/getFromAST.d.ts.map +0 -1
  668. package/utilities/graphql/operations.d.ts.map +0 -1
  669. package/utilities/graphql/print.d.ts.map +0 -1
  670. package/utilities/graphql/storeUtils.d.ts.map +0 -1
  671. package/utilities/graphql/transform.d.ts.map +0 -1
  672. package/utilities/index.d.ts.map +0 -1
  673. package/utilities/observables/Concast.d.ts.map +0 -1
  674. package/utilities/observables/Observable.d.ts.map +0 -1
  675. package/utilities/observables/asyncMap.d.ts.map +0 -1
  676. package/utilities/observables/iteration.d.ts.map +0 -1
  677. package/utilities/observables/subclassing.d.ts.map +0 -1
  678. package/utilities/policies/pagination.d.ts.map +0 -1
  679. package/utilities/promises/decoration.d.ts.map +0 -1
  680. package/utilities/subscriptions/relay/index.d.ts.map +0 -1
  681. package/utilities/subscriptions/shared.d.ts.map +0 -1
  682. package/utilities/subscriptions/urql/index.d.ts.map +0 -1
  683. package/utilities/types/DeepOmit.d.ts.map +0 -1
  684. package/utilities/types/DeepPartial.d.ts.map +0 -1
  685. package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
  686. package/utilities/types/Primitive.d.ts.map +0 -1
  687. package/version.d.ts.map +0 -1
@@ -3,53 +3,107 @@ import type { Render, BaseRender } from "./Render.js";
3
3
  type ValidSnapshot = void | (object & {
4
4
  call?: never;
5
5
  });
6
+ /** only used for passing around data internally */
6
7
  declare const _stackTrace: unique symbol;
8
+ /** @internal */
7
9
  export interface NextRenderOptions {
8
10
  timeout?: number;
9
11
  [_stackTrace]?: string;
10
12
  }
11
- export interface ProfiledComponent<Props, Snapshot> extends React.FC<Props>, ProfiledComponentFields<Props, Snapshot>, ProfiledComponenOnlyFields<Props, Snapshot> {
13
+ /** @internal */
14
+ interface ProfilerProps {
15
+ children: React.ReactNode;
12
16
  }
13
- interface UpdateSnapshot<Snapshot> {
17
+ /** @internal */
18
+ export interface Profiler<Snapshot> extends React.FC<ProfilerProps>, ProfiledComponentFields<Snapshot>, ProfiledComponentOnlyFields<Snapshot> {
19
+ }
20
+ interface ReplaceSnapshot<Snapshot> {
14
21
  (newSnapshot: Snapshot): void;
15
22
  (updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;
16
23
  }
17
- interface ProfiledComponenOnlyFields<Props, Snapshot> {
18
- updateSnapshot: UpdateSnapshot<Snapshot>;
24
+ interface MergeSnapshot<Snapshot> {
25
+ (partialSnapshot: Partial<Snapshot>): void;
26
+ (updatePartialSnapshot: (lastSnapshot: Readonly<Snapshot>) => Partial<Snapshot>): void;
27
+ }
28
+ interface ProfiledComponentOnlyFields<Snapshot> {
29
+ mergeSnapshot: MergeSnapshot<Snapshot>;
30
+ replaceSnapshot: ReplaceSnapshot<Snapshot>;
19
31
  }
20
- interface ProfiledComponentFields<Props, Snapshot> {
32
+ interface ProfiledComponentFields<Snapshot> {
33
+ /**
34
+ * An array of all renders that have happened so far.
35
+ * Errors thrown during component render will be captured here, too.
36
+ */
21
37
  renders: Array<Render<Snapshot> | {
22
38
  phase: "snapshotError";
23
39
  count: number;
24
40
  error: unknown;
25
41
  }>;
42
+ /**
43
+ * Peeks the next render from the current iterator position, without advancing the iterator.
44
+ * If no render has happened yet, it will wait for the next render to happen.
45
+ * @throws {WaitForRenderTimeoutError} if no render happens within the timeout
46
+ */
26
47
  peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
48
+ /**
49
+ * Iterates to the next render and returns it.
50
+ * If no render has happened yet, it will wait for the next render to happen.
51
+ * @throws {WaitForRenderTimeoutError} if no render happens within the timeout
52
+ */
27
53
  takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
28
- currentRenderCount(): number;
54
+ /**
55
+ * Returns the total number of renders.
56
+ */
57
+ totalRenderCount(): number;
58
+ /**
59
+ * Returns the current render.
60
+ * @throws {Error} if no render has happened yet
61
+ */
29
62
  getCurrentRender(): Render<Snapshot>;
30
- takeUntilRenderCount(count: number, optionsPerRender?: NextRenderOptions): Promise<void>;
63
+ /**
64
+ * Waits for the next render to happen.
65
+ * Does not advance the render iterator.
66
+ */
31
67
  waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
32
68
  }
33
- export declare function profile<Snapshot extends ValidSnapshot = void, Props = Record<string, never>>({ Component, onRender, snapshotDOM, initialSnapshot, }: {
69
+ export interface ProfiledComponent<Snapshot extends ValidSnapshot, Props = {}> extends React.FC<Props>, ProfiledComponentFields<Snapshot>, ProfiledComponentOnlyFields<Snapshot> {
70
+ }
71
+ /** @internal */
72
+ export declare function profile<Snapshot extends ValidSnapshot = void, Props = {}>({ Component, ...options }: Parameters<typeof createProfiler<Snapshot>>[0] & {
34
73
  Component: React.ComponentType<Props>;
74
+ }): ProfiledComponent<Snapshot, Props>;
75
+ /** @internal */
76
+ export declare function createProfiler<Snapshot extends ValidSnapshot = void>({ onRender, snapshotDOM, initialSnapshot, skipNonTrackingRenders, }?: {
35
77
  onRender?: (info: BaseRender & {
36
78
  snapshot: Snapshot;
37
- updateSnapshot: UpdateSnapshot<Snapshot>;
79
+ replaceSnapshot: ReplaceSnapshot<Snapshot>;
80
+ mergeSnapshot: MergeSnapshot<Snapshot>;
38
81
  }) => void;
39
82
  snapshotDOM?: boolean;
40
83
  initialSnapshot?: Snapshot;
41
- }): ProfiledComponent<Props, Snapshot>;
84
+ /**
85
+ * This will skip renders during which no renders tracked by
86
+ * `useTrackRenders` occured.
87
+ */
88
+ skipNonTrackingRenders?: boolean;
89
+ }): Profiler<Snapshot>;
90
+ /** @internal */
42
91
  export declare class WaitForRenderTimeoutError extends Error {
43
92
  constructor();
44
93
  }
45
94
  type StringReplaceRenderWithSnapshot<T extends string> = T extends `${infer Pre}Render${infer Post}` ? `${Pre}Snapshot${Post}` : T;
46
95
  type ResultReplaceRenderWithSnapshot<T> = T extends (...args: infer Args) => Render<infer Snapshot> ? (...args: Args) => Snapshot : T extends (...args: infer Args) => Promise<Render<infer Snapshot>> ? (...args: Args) => Promise<Snapshot> : T;
47
- type ProfiledHookFields<Props, ReturnValue> = ProfiledComponentFields<Props, ReturnValue> extends infer PC ? {
96
+ type ProfiledHookFields<ReturnValue> = ProfiledComponentFields<ReturnValue> extends infer PC ? {
48
97
  [K in keyof PC as StringReplaceRenderWithSnapshot<K & string>]: ResultReplaceRenderWithSnapshot<PC[K]>;
49
98
  } : never;
50
- export interface ProfiledHook<Props, ReturnValue> extends React.FC<Props>, ProfiledHookFields<Props, ReturnValue> {
51
- ProfiledComponent: ProfiledComponent<Props, ReturnValue>;
99
+ /** @internal */
100
+ export interface ProfiledHook<Props, ReturnValue> extends React.FC<Props>, ProfiledHookFields<ReturnValue> {
101
+ Profiler: Profiler<ReturnValue>;
52
102
  }
103
+ /** @internal */
53
104
  export declare function profileHook<ReturnValue extends ValidSnapshot, Props>(renderCallback: (props: Props) => ReturnValue): ProfiledHook<Props, ReturnValue>;
105
+ export declare function useTrackRenders({ name }?: {
106
+ name?: string;
107
+ }): void;
54
108
  export {};
55
109
  //# sourceMappingURL=profile.d.ts.map
@@ -1,32 +1,67 @@
1
1
  var _a, _b;
2
- import { __assign, __awaiter, __extends, __generator } from "tslib";
2
+ import { __addDisposableResource, __assign, __awaiter, __disposeResources, __extends, __generator, __rest } from "tslib";
3
3
  import * as React from "react";
4
4
  import { TextEncoder, TextDecoder } from "util";
5
5
  (_a = global.TextEncoder) !== null && _a !== void 0 ? _a : (global.TextEncoder = TextEncoder);
6
+ // @ts-ignore
6
7
  (_b = global.TextDecoder) !== null && _b !== void 0 ? _b : (global.TextDecoder = TextDecoder);
7
8
  import { RenderInstance } from "./Render.js";
8
9
  import { applyStackTrace, captureStackTrace } from "./traces.js";
10
+ import { ProfilerContextProvider, useProfilerContext } from "./context.js";
11
+ import { disableActWarnings } from "../disposables/index.js";
12
+ /** only used for passing around data internally */
9
13
  var _stackTrace = Symbol();
14
+ /** @internal */
10
15
  export function profile(_a) {
11
- var Component = _a.Component, onRender = _a.onRender, _b = _a.snapshotDOM, snapshotDOM = _b === void 0 ? false : _b, initialSnapshot = _a.initialSnapshot;
12
- var currentRender;
16
+ var Component = _a.Component, options = __rest(_a, ["Component"]);
17
+ var Profiler = createProfiler(options);
18
+ return Object.assign(function ProfiledComponent(props) {
19
+ return (React.createElement(Profiler, null,
20
+ React.createElement(Component, __assign({}, props))));
21
+ }, {
22
+ mergeSnapshot: Profiler.mergeSnapshot,
23
+ replaceSnapshot: Profiler.replaceSnapshot,
24
+ getCurrentRender: Profiler.getCurrentRender,
25
+ peekRender: Profiler.peekRender,
26
+ takeRender: Profiler.takeRender,
27
+ totalRenderCount: Profiler.totalRenderCount,
28
+ waitForNextRender: Profiler.waitForNextRender,
29
+ get renders() {
30
+ return Profiler.renders;
31
+ },
32
+ });
33
+ }
34
+ /** @internal */
35
+ export function createProfiler(_a) {
36
+ var _b = _a === void 0 ? {} : _a, onRender = _b.onRender, _c = _b.snapshotDOM, snapshotDOM = _c === void 0 ? false : _c, initialSnapshot = _b.initialSnapshot, skipNonTrackingRenders = _b.skipNonTrackingRenders;
13
37
  var nextRender;
14
38
  var resolveNextRender;
15
39
  var rejectNextRender;
16
40
  var snapshotRef = { current: initialSnapshot };
17
- var updateSnapshot = function (snap) {
41
+ var replaceSnapshot = function (snap) {
18
42
  if (typeof snap === "function") {
19
43
  if (!initialSnapshot) {
20
44
  throw new Error("Cannot use a function to update the snapshot if no initial snapshot was provided.");
21
45
  }
22
- snapshotRef.current = snap(typeof snapshotRef.current === "object"
23
- ? __assign({}, snapshotRef.current) : snapshotRef.current);
46
+ snapshotRef.current = snap(typeof snapshotRef.current === "object" ? __assign({}, snapshotRef.current) : snapshotRef.current);
24
47
  }
25
48
  else {
26
49
  snapshotRef.current = snap;
27
50
  }
28
51
  };
52
+ var mergeSnapshot = function (partialSnapshot) {
53
+ replaceSnapshot(function (snapshot) { return (__assign(__assign({}, snapshot), (typeof partialSnapshot === "function" ?
54
+ partialSnapshot(snapshot)
55
+ : partialSnapshot))); });
56
+ };
57
+ var profilerContext = {
58
+ renderedComponents: [],
59
+ };
29
60
  var profilerOnRender = function (id, phase, actualDuration, baseDuration, startTime, commitTime) {
61
+ if (skipNonTrackingRenders &&
62
+ profilerContext.renderedComponents.length === 0) {
63
+ return;
64
+ }
30
65
  var baseRender = {
31
66
  id: id,
32
67
  phase: phase,
@@ -34,23 +69,28 @@ export function profile(_a) {
34
69
  baseDuration: baseDuration,
35
70
  startTime: startTime,
36
71
  commitTime: commitTime,
37
- count: Profiled.renders.length + 1,
72
+ count: Profiler.renders.length + 1,
38
73
  };
39
74
  try {
40
- onRender === null || onRender === void 0 ? void 0 : onRender(__assign(__assign({}, baseRender), { updateSnapshot: updateSnapshot, snapshot: snapshotRef.current }));
75
+ /*
76
+ * The `onRender` function could contain `expect` calls that throw
77
+ * `JestAssertionError`s - but we are still inside of React, where errors
78
+ * might be swallowed.
79
+ * So we record them and re-throw them in `takeRender`
80
+ * Additionally, we reject the `waitForNextRender` promise.
81
+ */
82
+ onRender === null || onRender === void 0 ? void 0 : onRender(__assign(__assign({}, baseRender), { replaceSnapshot: replaceSnapshot, mergeSnapshot: mergeSnapshot, snapshot: snapshotRef.current }));
41
83
  var snapshot = snapshotRef.current;
42
- var domSnapshot = snapshotDOM
43
- ? window.document.body.innerHTML
44
- : undefined;
45
- var render = new RenderInstance(baseRender, snapshot, domSnapshot);
46
- currentRender = render;
47
- Profiled.renders.push(render);
84
+ var domSnapshot = snapshotDOM ? window.document.body.innerHTML : undefined;
85
+ var render = new RenderInstance(baseRender, snapshot, domSnapshot, profilerContext.renderedComponents);
86
+ profilerContext.renderedComponents = [];
87
+ Profiler.renders.push(render);
48
88
  resolveNextRender === null || resolveNextRender === void 0 ? void 0 : resolveNextRender(render);
49
89
  }
50
90
  catch (error) {
51
- Profiled.renders.push({
91
+ Profiler.renders.push({
52
92
  phase: "snapshotError",
53
- count: Profiled.renders.length,
93
+ count: Profiler.renders.length,
54
94
  error: error,
55
95
  });
56
96
  rejectNextRender === null || rejectNextRender === void 0 ? void 0 : rejectNextRender(error);
@@ -60,83 +100,101 @@ export function profile(_a) {
60
100
  }
61
101
  };
62
102
  var iteratorPosition = 0;
63
- var Profiled = Object.assign(function (props) { return (React.createElement(React.Profiler, { id: "test", onRender: profilerOnRender },
64
- React.createElement(Component, __assign({}, props)))); }, {
65
- updateSnapshot: updateSnapshot,
103
+ var Profiler = Object.assign(function (_a) {
104
+ var children = _a.children;
105
+ return (React.createElement(ProfilerContextProvider, { value: profilerContext },
106
+ React.createElement(React.Profiler, { id: "test", onRender: profilerOnRender }, children)));
107
+ }, {
108
+ replaceSnapshot: replaceSnapshot,
109
+ mergeSnapshot: mergeSnapshot,
66
110
  }, {
67
111
  renders: new Array(),
68
- currentRenderCount: function () {
69
- return Profiled.renders.length;
112
+ totalRenderCount: function () {
113
+ return Profiler.renders.length;
70
114
  },
71
115
  peekRender: function (options) {
72
116
  if (options === void 0) { options = {}; }
73
117
  return __awaiter(this, void 0, void 0, function () {
74
- var render_1, render;
118
+ var render;
75
119
  var _a;
76
120
  return __generator(this, function (_b) {
77
- if (iteratorPosition < Profiled.renders.length) {
78
- render_1 = Profiled.renders[iteratorPosition];
79
- if (render_1.phase === "snapshotError") {
80
- throw render_1.error;
121
+ if (iteratorPosition < Profiler.renders.length) {
122
+ render = Profiler.renders[iteratorPosition];
123
+ if (render.phase === "snapshotError") {
124
+ throw render.error;
81
125
  }
82
- return [2, render_1];
126
+ return [2 /*return*/, render];
83
127
  }
84
- render = Profiled.waitForNextRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiled.peekRender), _a), options));
85
- return [2, render];
128
+ return [2 /*return*/, Profiler.waitForNextRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiler.peekRender), _a), options))];
86
129
  });
87
130
  });
88
131
  },
89
132
  takeRender: function (options) {
90
133
  if (options === void 0) { options = {}; }
91
134
  return __awaiter(this, void 0, void 0, function () {
92
- var error, e_1;
135
+ var env_1, _disabledActWarnings, error, e_1, e_2;
93
136
  var _a;
94
137
  return __generator(this, function (_b) {
95
138
  switch (_b.label) {
96
139
  case 0:
97
- error = undefined;
140
+ env_1 = { stack: [], error: void 0, hasError: false };
98
141
  _b.label = 1;
99
142
  case 1:
100
- _b.trys.push([1, 3, 4, 5]);
101
- return [4, Profiled.peekRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiled.takeRender), _a), options))];
102
- case 2: return [2, _b.sent()];
103
- case 3:
143
+ _b.trys.push([1, 7, 8, 9]);
144
+ _disabledActWarnings = __addDisposableResource(env_1, disableActWarnings(), false);
145
+ error = undefined;
146
+ _b.label = 2;
147
+ case 2:
148
+ _b.trys.push([2, 4, 5, 6]);
149
+ return [4 /*yield*/, Profiler.peekRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiler.takeRender), _a), options))];
150
+ case 3: return [2 /*return*/, _b.sent()];
151
+ case 4:
104
152
  e_1 = _b.sent();
105
153
  error = e_1;
106
154
  throw e_1;
107
- case 4:
155
+ case 5:
108
156
  if (!(error && error instanceof WaitForRenderTimeoutError)) {
109
157
  iteratorPosition++;
110
158
  }
111
- return [7];
112
- case 5: return [2];
159
+ return [7 /*endfinally*/];
160
+ case 6: return [3 /*break*/, 9];
161
+ case 7:
162
+ e_2 = _b.sent();
163
+ env_1.error = e_2;
164
+ env_1.hasError = true;
165
+ return [3 /*break*/, 9];
166
+ case 8:
167
+ __disposeResources(env_1);
168
+ return [7 /*endfinally*/];
169
+ case 9: return [2 /*return*/];
113
170
  }
114
171
  });
115
172
  });
116
173
  },
117
174
  getCurrentRender: function () {
118
- if (!currentRender) {
119
- throw new Error("Has not been rendered yet!");
175
+ // The "current" render should point at the same render that the most
176
+ // recent `takeRender` call returned, so we need to get the "previous"
177
+ // iterator position, otherwise `takeRender` advances the iterator
178
+ // to the next render. This means we need to call `takeRender` at least
179
+ // once before we can get a current render.
180
+ var currentPosition = iteratorPosition - 1;
181
+ if (currentPosition < 0) {
182
+ throw new Error("No current render available. You need to call `takeRender` before you can get the current render.");
120
183
  }
121
- return currentRender;
122
- },
123
- takeUntilRenderCount: function (count, optionsPerRender) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- return __generator(this, function (_a) {
126
- switch (_a.label) {
127
- case 0:
128
- if (!(Profiled.renders.length < count)) return [3, 2];
129
- return [4, Profiled.takeRender(optionsPerRender)];
130
- case 1:
131
- _a.sent();
132
- return [3, 0];
133
- case 2: return [2];
134
- }
135
- });
136
- });
184
+ var render = Profiler.renders[currentPosition];
185
+ if (render.phase === "snapshotError") {
186
+ throw render.error;
187
+ }
188
+ return render;
137
189
  },
138
190
  waitForNextRender: function (_a) {
139
- var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 1000 : _c, _d = _stackTrace, _e = _b[_d], stackTrace = _e === void 0 ? captureStackTrace(Profiled.waitForNextRender) : _e;
191
+ var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 1000 : _c,
192
+ // capture the stack trace here so its stack trace is as close to the calling code as possible
193
+ _d = _stackTrace,
194
+ // capture the stack trace here so its stack trace is as close to the calling code as possible
195
+ _e = _b[_d],
196
+ // capture the stack trace here so its stack trace is as close to the calling code as possible
197
+ stackTrace = _e === void 0 ? captureStackTrace(Profiler.waitForNextRender) : _e;
140
198
  if (!nextRender) {
141
199
  nextRender = Promise.race([
142
200
  new Promise(function (resolve, reject) {
@@ -153,9 +211,10 @@ export function profile(_a) {
153
211
  return nextRender;
154
212
  },
155
213
  });
156
- return Profiled;
214
+ return Profiler;
157
215
  }
158
- var WaitForRenderTimeoutError = (function (_super) {
216
+ /** @internal */
217
+ var WaitForRenderTimeoutError = /** @class */ (function (_super) {
159
218
  __extends(WaitForRenderTimeoutError, _super);
160
219
  function WaitForRenderTimeoutError() {
161
220
  var _newTarget = this.constructor;
@@ -166,29 +225,27 @@ var WaitForRenderTimeoutError = (function (_super) {
166
225
  return WaitForRenderTimeoutError;
167
226
  }(Error));
168
227
  export { WaitForRenderTimeoutError };
228
+ /** @internal */
169
229
  export function profileHook(renderCallback) {
170
- var returnValue;
171
- var Component = function (props) {
172
- ProfiledComponent.updateSnapshot(renderCallback(props));
230
+ var Profiler = createProfiler();
231
+ var ProfiledHook = function (props) {
232
+ Profiler.replaceSnapshot(renderCallback(props));
173
233
  return null;
174
234
  };
175
- var ProfiledComponent = profile({
176
- Component: Component,
177
- onRender: function () { return returnValue; },
178
- });
179
- return Object.assign(function ProfiledHook(props) {
180
- return React.createElement(ProfiledComponent, __assign({}, props));
235
+ return Object.assign(function App(props) {
236
+ return (React.createElement(Profiler, null,
237
+ React.createElement(ProfiledHook, __assign({}, props))));
181
238
  }, {
182
- ProfiledComponent: ProfiledComponent,
239
+ Profiler: Profiler,
183
240
  }, {
184
- renders: ProfiledComponent.renders,
185
- currentSnapshotCount: ProfiledComponent.currentRenderCount,
241
+ renders: Profiler.renders,
242
+ totalSnapshotCount: Profiler.totalRenderCount,
186
243
  peekSnapshot: function (options) {
187
244
  return __awaiter(this, void 0, void 0, function () {
188
245
  return __generator(this, function (_a) {
189
246
  switch (_a.label) {
190
- case 0: return [4, ProfiledComponent.peekRender(options)];
191
- case 1: return [2, (_a.sent()).snapshot];
247
+ case 0: return [4 /*yield*/, Profiler.peekRender(options)];
248
+ case 1: return [2 /*return*/, (_a.sent()).snapshot];
192
249
  }
193
250
  });
194
251
  });
@@ -197,26 +254,43 @@ export function profileHook(renderCallback) {
197
254
  return __awaiter(this, void 0, void 0, function () {
198
255
  return __generator(this, function (_a) {
199
256
  switch (_a.label) {
200
- case 0: return [4, ProfiledComponent.takeRender(options)];
201
- case 1: return [2, (_a.sent()).snapshot];
257
+ case 0: return [4 /*yield*/, Profiler.takeRender(options)];
258
+ case 1: return [2 /*return*/, (_a.sent()).snapshot];
202
259
  }
203
260
  });
204
261
  });
205
262
  },
206
263
  getCurrentSnapshot: function () {
207
- return ProfiledComponent.getCurrentRender().snapshot;
264
+ return Profiler.getCurrentRender().snapshot;
208
265
  },
209
- takeUntilSnapshotCount: ProfiledComponent.takeUntilRenderCount,
210
266
  waitForNextSnapshot: function (options) {
211
267
  return __awaiter(this, void 0, void 0, function () {
212
268
  return __generator(this, function (_a) {
213
269
  switch (_a.label) {
214
- case 0: return [4, ProfiledComponent.waitForNextRender(options)];
215
- case 1: return [2, (_a.sent()).snapshot];
270
+ case 0: return [4 /*yield*/, Profiler.waitForNextRender(options)];
271
+ case 1: return [2 /*return*/, (_a.sent()).snapshot];
216
272
  }
217
273
  });
218
274
  });
219
275
  },
220
276
  });
221
277
  }
278
+ function resolveHookOwner() {
279
+ var _a, _b, _c;
280
+ return (_c = (_b = (_a = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _a === void 0 ? void 0 : _a.ReactCurrentOwner) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.elementType;
281
+ }
282
+ export function useTrackRenders(_a) {
283
+ var _b = _a === void 0 ? {} : _a, name = _b.name;
284
+ var component = name || resolveHookOwner();
285
+ if (!component) {
286
+ throw new Error("useTrackRender: Unable to determine component. Please ensure the hook is called inside a rendered component or provide a `name` option.");
287
+ }
288
+ var ctx = useProfilerContext();
289
+ if (!ctx) {
290
+ throw new Error("useTrackComponentRender: A Profiler must be created and rendered to track component renders");
291
+ }
292
+ React.useLayoutEffect(function () {
293
+ ctx.renderedComponents.unshift(component);
294
+ });
295
+ }
222
296
  //# sourceMappingURL=profile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/profile.tsx"],"names":[],"mappings":";;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEhD,MAA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AAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,IAAM,iBAAiB,GAAG,OAAO,CAAqB;QACpD,SAAS,WAAA;QACT,QAAQ,EAAE,cAAM,OAAA,WAAW,EAAX,CAAW;KAC5B,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAClB,SAAS,YAAY,CAAC,KAAY;QAChC,OAAO,oBAAC,iBAAiB,eAAM,KAAa,EAAI,CAAC;IACnD,CAAC,EACD;QACE,iBAAiB,mBAAA;KAClB,EACD;QACE,OAAO,EAAE,iBAAiB,CAAC,OAAO;QAClC,oBAAoB,EAAE,iBAAiB,CAAC,kBAAkB;QACpD,YAAY,YAAC,OAAO;;;;gCAChB,WAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAA;gCAAnD,WAAO,CAAC,SAA2C,CAAC,CAAC,QAAQ,EAAC;;;;SAC/D;QACK,YAAY,YAAC,OAAO;;;;gCAChB,WAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAA;gCAAnD,WAAO,CAAC,SAA2C,CAAC,CAAC,QAAQ,EAAC;;;;SAC/D;QACD,kBAAkB;YAChB,OAAO,iBAAiB,CAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC;QACvD,CAAC;QACD,sBAAsB,EAAE,iBAAiB,CAAC,oBAAoB;QACxD,mBAAmB,YAAC,OAAO;;;;gCACvB,WAAM,iBAAiB,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAA;gCAA1D,WAAO,CAAC,SAAkD,CAAC,CAAC,QAAQ,EAAC;;;;SACtE;KAC+C,CACnD,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport { TextEncoder, TextDecoder } from \"util\";\n\nglobal.TextEncoder ??= TextEncoder;\n// @ts-ignore\nglobal.TextDecoder ??= TextDecoder;\nimport type { Render, BaseRender } from \"./Render.js\";\nimport { RenderInstance } from \"./Render.js\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\n\ntype ValidSnapshot = void | (object & { /* not a function */ call?: never });\n\n/** only used for passing around data internally */\nconst _stackTrace = Symbol();\n/** @internal */\nexport interface NextRenderOptions {\n timeout?: number;\n [_stackTrace]?: string;\n}\n\n/** @internal */\nexport interface ProfiledComponent<Props, Snapshot>\n extends React.FC<Props>,\n ProfiledComponentFields<Props, Snapshot>,\n ProfiledComponenOnlyFields<Props, Snapshot> {}\n\ninterface UpdateSnapshot<Snapshot> {\n (newSnapshot: Snapshot): void;\n (updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;\n}\n\ninterface ProfiledComponenOnlyFields<Props, Snapshot> {\n updateSnapshot: UpdateSnapshot<Snapshot>;\n}\ninterface ProfiledComponentFields<Props, Snapshot> {\n /**\n * An array of all renders that have happened so far.\n * Errors thrown during component render will be captured here, too.\n */\n renders: Array<\n Render<Snapshot> | { phase: \"snapshotError\"; count: number; error: unknown }\n >;\n /**\n * Peeks the next render from the current iterator position, without advancing the iterator.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Iterates to the next render and returns it.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Returns the current render count.\n */\n currentRenderCount(): number;\n /**\n * Returns the current render.\n * @throws {Error} if no render has happened yet\n */\n getCurrentRender(): Render<Snapshot>;\n /**\n * Iterates the renders until the render count is reached.\n */\n takeUntilRenderCount(\n count: number,\n optionsPerRender?: NextRenderOptions\n ): Promise<void>;\n /**\n * Waits for the next render to happen.\n * Does not advance the render iterator.\n */\n waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n}\n\n/** @internal */\nexport function profile<\n Snapshot extends ValidSnapshot = void,\n Props = Record<string, never>,\n>({\n Component,\n onRender,\n snapshotDOM = false,\n initialSnapshot,\n}: {\n Component: React.ComponentType<Props>;\n onRender?: (\n info: BaseRender & {\n snapshot: Snapshot;\n updateSnapshot: UpdateSnapshot<Snapshot>;\n }\n ) => void;\n snapshotDOM?: boolean;\n initialSnapshot?: Snapshot;\n}) {\n let currentRender: Render<Snapshot> | undefined;\n let nextRender: Promise<Render<Snapshot>> | undefined;\n let resolveNextRender: ((render: Render<Snapshot>) => void) | undefined;\n let rejectNextRender: ((error: unknown) => void) | undefined;\n const snapshotRef = { current: initialSnapshot };\n const updateSnapshot: UpdateSnapshot<Snapshot> = (snap) => {\n if (typeof snap === \"function\") {\n if (!initialSnapshot) {\n throw new Error(\n \"Cannot use a function to update the snapshot if no initial snapshot was provided.\"\n );\n }\n snapshotRef.current = snap(\n typeof snapshotRef.current === \"object\"\n ? // \"cheap best effort\" to prevent accidental mutation of the last snapshot\n { ...snapshotRef.current! }\n : snapshotRef.current!\n );\n } else {\n snapshotRef.current = snap;\n }\n };\n const profilerOnRender: React.ProfilerOnRenderCallback = (\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime\n ) => {\n const baseRender = {\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime,\n count: Profiled.renders.length + 1,\n };\n try {\n /*\n * The `onRender` function could contain `expect` calls that throw\n * `JestAssertionError`s - but we are still inside of React, where errors\n * might be swallowed.\n * So we record them and re-throw them in `takeRender`\n * Additionally, we reject the `waitForNextRender` promise.\n */\n onRender?.({\n ...baseRender,\n updateSnapshot,\n snapshot: snapshotRef.current!,\n });\n\n const snapshot = snapshotRef.current as Snapshot;\n const domSnapshot = snapshotDOM\n ? window.document.body.innerHTML\n : undefined;\n const render = new RenderInstance(baseRender, snapshot, domSnapshot);\n // eslint-disable-next-line testing-library/render-result-naming-convention\n currentRender = render;\n Profiled.renders.push(render);\n resolveNextRender?.(render);\n } catch (error) {\n Profiled.renders.push({\n phase: \"snapshotError\",\n count: Profiled.renders.length,\n error,\n });\n rejectNextRender?.(error);\n } finally {\n nextRender = resolveNextRender = rejectNextRender = undefined;\n }\n };\n\n let iteratorPosition = 0;\n const Profiled: ProfiledComponent<Props, Snapshot> = Object.assign(\n (props: Props) => (\n <React.Profiler id=\"test\" onRender={profilerOnRender}>\n <Component {...(props as any)} />\n </React.Profiler>\n ),\n {\n updateSnapshot,\n } satisfies ProfiledComponenOnlyFields<Props, Snapshot>,\n {\n renders: new Array<\n | Render<Snapshot>\n | { phase: \"snapshotError\"; count: number; error: unknown }\n >(),\n currentRenderCount() {\n return Profiled.renders.length;\n },\n async peekRender(options: NextRenderOptions = {}) {\n if (iteratorPosition < Profiled.renders.length) {\n const render = Profiled.renders[iteratorPosition];\n if (render.phase === \"snapshotError\") {\n throw render.error;\n }\n return render;\n }\n const render = Profiled.waitForNextRender({\n [_stackTrace]: captureStackTrace(Profiled.peekRender),\n ...options,\n });\n return render;\n },\n async takeRender(options: NextRenderOptions = {}) {\n let error: { message?: string } | undefined = undefined;\n try {\n return await Profiled.peekRender({\n [_stackTrace]: captureStackTrace(Profiled.takeRender),\n ...options,\n });\n } catch (e) {\n error = e;\n throw e;\n } finally {\n if (!(error && error instanceof WaitForRenderTimeoutError)) {\n iteratorPosition++;\n }\n }\n },\n getCurrentRender() {\n if (!currentRender) {\n throw new Error(\"Has not been rendered yet!\");\n }\n return currentRender;\n },\n async takeUntilRenderCount(\n count: number,\n optionsPerRender?: NextRenderOptions\n ) {\n while (Profiled.renders.length < count) {\n await Profiled.takeRender(optionsPerRender);\n }\n },\n waitForNextRender({\n timeout = 1000,\n // capture the stack trace here so its stack trace is as close to the calling code as possible\n [_stackTrace]: stackTrace = captureStackTrace(\n Profiled.waitForNextRender\n ),\n }: NextRenderOptions = {}) {\n if (!nextRender) {\n nextRender = Promise.race<Render<Snapshot>>([\n new Promise<Render<Snapshot>>((resolve, reject) => {\n resolveNextRender = resolve;\n rejectNextRender = reject;\n }),\n new Promise<Render<Snapshot>>((_, reject) =>\n setTimeout(\n () =>\n reject(\n applyStackTrace(new WaitForRenderTimeoutError(), stackTrace)\n ),\n timeout\n )\n ),\n ]);\n }\n return nextRender;\n },\n } satisfies ProfiledComponentFields<Props, Snapshot>\n );\n return Profiled;\n}\n\n/** @internal */\nexport class WaitForRenderTimeoutError extends Error {\n constructor() {\n super(\"Exceeded timeout waiting for next render.\");\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\ntype StringReplaceRenderWithSnapshot<T extends string> =\n T extends `${infer Pre}Render${infer Post}` ? `${Pre}Snapshot${Post}` : T;\n\ntype ResultReplaceRenderWithSnapshot<T> = T extends (\n ...args: infer Args\n) => Render<infer Snapshot>\n ? (...args: Args) => Snapshot\n : T extends (...args: infer Args) => Promise<Render<infer Snapshot>>\n ? (...args: Args) => Promise<Snapshot>\n : T;\n\ntype ProfiledHookFields<Props, ReturnValue> = ProfiledComponentFields<\n Props,\n ReturnValue\n> extends infer PC\n ? {\n [K in keyof PC as StringReplaceRenderWithSnapshot<\n K & string\n >]: ResultReplaceRenderWithSnapshot<PC[K]>;\n }\n : never;\n\n/** @internal */\nexport interface ProfiledHook<Props, ReturnValue>\n extends React.FC<Props>,\n ProfiledHookFields<Props, ReturnValue> {\n ProfiledComponent: ProfiledComponent<Props, ReturnValue>;\n}\n\n/** @internal */\nexport function profileHook<ReturnValue extends ValidSnapshot, Props>(\n renderCallback: (props: Props) => ReturnValue\n): ProfiledHook<Props, ReturnValue> {\n let returnValue: ReturnValue;\n const Component = (props: Props) => {\n ProfiledComponent.updateSnapshot(renderCallback(props));\n return null;\n };\n const ProfiledComponent = profile<ReturnValue, Props>({\n Component,\n onRender: () => returnValue,\n });\n return Object.assign(\n function ProfiledHook(props: Props) {\n return <ProfiledComponent {...(props as any)} />;\n },\n {\n ProfiledComponent,\n },\n {\n renders: ProfiledComponent.renders,\n currentSnapshotCount: ProfiledComponent.currentRenderCount,\n async peekSnapshot(options) {\n return (await ProfiledComponent.peekRender(options)).snapshot;\n },\n async takeSnapshot(options) {\n return (await ProfiledComponent.takeRender(options)).snapshot;\n },\n getCurrentSnapshot() {\n return ProfiledComponent.getCurrentRender().snapshot;\n },\n takeUntilSnapshotCount: ProfiledComponent.takeUntilRenderCount,\n async waitForNextSnapshot(options) {\n return (await ProfiledComponent.waitForNextRender(options)).snapshot;\n },\n } satisfies ProfiledHookFields<Props, ReturnValue>\n );\n}\n"]}
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/profile.tsx"],"names":[],"mappings":";;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEhD,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC;AACnC,aAAa;AACb,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAI7D,mDAAmD;AACnD,IAAM,WAAW,GAAG,MAAM,EAAE,CAAC;AA+E7B,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAAoD,EAK1E;IAJC,IAAA,SAAS,eAAA,EACN,OAAO,cAF+D,aAG1E,CADW;IAIV,IAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAEzC,OAAO,MAAM,CAAC,MAAM,CAClB,SAAS,iBAAiB,CAAC,KAAY;QACrC,OAAO,CACL,oBAAC,QAAQ;YACP,oBAAC,SAAS,eAAM,KAAa,EAAI,CACxB,CACZ,CAAC;IACJ,CAAC,EACD;QACE,aAAa,EAAE,QAAQ,CAAC,aAAa;QACrC,eAAe,EAAE,QA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AAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport { TextEncoder, TextDecoder } from \"util\";\n\nglobal.TextEncoder ??= TextEncoder;\n// @ts-ignore\nglobal.TextDecoder ??= TextDecoder;\nimport type { Render, BaseRender } from \"./Render.js\";\nimport { RenderInstance } from \"./Render.js\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\nimport type { ProfilerContextValue } from \"./context.js\";\nimport { ProfilerContextProvider, useProfilerContext } from \"./context.js\";\nimport { disableActWarnings } from \"../disposables/index.js\";\n\ntype ValidSnapshot = void | (object & { /* not a function */ call?: never });\n\n/** only used for passing around data internally */\nconst _stackTrace = Symbol();\n/** @internal */\nexport interface NextRenderOptions {\n timeout?: number;\n [_stackTrace]?: string;\n}\n\n/** @internal */\ninterface ProfilerProps {\n children: React.ReactNode;\n}\n\n/** @internal */\nexport interface Profiler<Snapshot>\n extends React.FC<ProfilerProps>,\n ProfiledComponentFields<Snapshot>,\n ProfiledComponentOnlyFields<Snapshot> {}\n\ninterface ReplaceSnapshot<Snapshot> {\n (newSnapshot: Snapshot): void;\n (updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;\n}\n\ninterface MergeSnapshot<Snapshot> {\n (partialSnapshot: Partial<Snapshot>): void;\n (\n updatePartialSnapshot: (\n lastSnapshot: Readonly<Snapshot>\n ) => Partial<Snapshot>\n ): void;\n}\n\ninterface ProfiledComponentOnlyFields<Snapshot> {\n // Allows for partial updating of the snapshot by shallow merging the results\n mergeSnapshot: MergeSnapshot<Snapshot>;\n // Performs a full replacement of the snapshot\n replaceSnapshot: ReplaceSnapshot<Snapshot>;\n}\ninterface ProfiledComponentFields<Snapshot> {\n /**\n * An array of all renders that have happened so far.\n * Errors thrown during component render will be captured here, too.\n */\n renders: Array<\n Render<Snapshot> | { phase: \"snapshotError\"; count: number; error: unknown }\n >;\n /**\n * Peeks the next render from the current iterator position, without advancing the iterator.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Iterates to the next render and returns it.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Returns the total number of renders.\n */\n totalRenderCount(): number;\n /**\n * Returns the current render.\n * @throws {Error} if no render has happened yet\n */\n getCurrentRender(): Render<Snapshot>;\n /**\n * Waits for the next render to happen.\n * Does not advance the render iterator.\n */\n waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n}\n\nexport interface ProfiledComponent<Snapshot extends ValidSnapshot, Props = {}>\n extends React.FC<Props>,\n ProfiledComponentFields<Snapshot>,\n ProfiledComponentOnlyFields<Snapshot> {}\n\n/** @internal */\nexport function profile<Snapshot extends ValidSnapshot = void, Props = {}>({\n Component,\n ...options\n}: Parameters<typeof createProfiler<Snapshot>>[0] & {\n Component: React.ComponentType<Props>;\n}): ProfiledComponent<Snapshot, Props> {\n const Profiler = createProfiler(options);\n\n return Object.assign(\n function ProfiledComponent(props: Props) {\n return (\n <Profiler>\n <Component {...(props as any)} />\n </Profiler>\n );\n },\n {\n mergeSnapshot: Profiler.mergeSnapshot,\n replaceSnapshot: Profiler.replaceSnapshot,\n getCurrentRender: Profiler.getCurrentRender,\n peekRender: Profiler.peekRender,\n takeRender: Profiler.takeRender,\n totalRenderCount: Profiler.totalRenderCount,\n waitForNextRender: Profiler.waitForNextRender,\n get renders() {\n return Profiler.renders;\n },\n }\n );\n}\n\n/** @internal */\nexport function createProfiler<Snapshot extends ValidSnapshot = void>({\n onRender,\n snapshotDOM = false,\n initialSnapshot,\n skipNonTrackingRenders,\n}: {\n onRender?: (\n info: BaseRender & {\n snapshot: Snapshot;\n replaceSnapshot: ReplaceSnapshot<Snapshot>;\n mergeSnapshot: MergeSnapshot<Snapshot>;\n }\n ) => void;\n snapshotDOM?: boolean;\n initialSnapshot?: Snapshot;\n /**\n * This will skip renders during which no renders tracked by\n * `useTrackRenders` occured.\n */\n skipNonTrackingRenders?: boolean;\n} = {}) {\n let nextRender: Promise<Render<Snapshot>> | undefined;\n let resolveNextRender: ((render: Render<Snapshot>) => void) | undefined;\n let rejectNextRender: ((error: unknown) => void) | undefined;\n const snapshotRef = { current: initialSnapshot };\n const replaceSnapshot: ReplaceSnapshot<Snapshot> = (snap) => {\n if (typeof snap === \"function\") {\n if (!initialSnapshot) {\n throw new Error(\n \"Cannot use a function to update the snapshot if no initial snapshot was provided.\"\n );\n }\n snapshotRef.current = snap(\n typeof snapshotRef.current === \"object\" ?\n // \"cheap best effort\" to prevent accidental mutation of the last snapshot\n { ...snapshotRef.current! }\n : snapshotRef.current!\n );\n } else {\n snapshotRef.current = snap;\n }\n };\n\n const mergeSnapshot: MergeSnapshot<Snapshot> = (partialSnapshot) => {\n replaceSnapshot((snapshot) => ({\n ...snapshot,\n ...(typeof partialSnapshot === \"function\" ?\n partialSnapshot(snapshot)\n : partialSnapshot),\n }));\n };\n\n const profilerContext: ProfilerContextValue = {\n renderedComponents: [],\n };\n\n const profilerOnRender: React.ProfilerOnRenderCallback = (\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime\n ) => {\n if (\n skipNonTrackingRenders &&\n profilerContext.renderedComponents.length === 0\n ) {\n return;\n }\n const baseRender = {\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime,\n count: Profiler.renders.length + 1,\n };\n try {\n /*\n * The `onRender` function could contain `expect` calls that throw\n * `JestAssertionError`s - but we are still inside of React, where errors\n * might be swallowed.\n * So we record them and re-throw them in `takeRender`\n * Additionally, we reject the `waitForNextRender` promise.\n */\n onRender?.({\n ...baseRender,\n replaceSnapshot,\n mergeSnapshot,\n snapshot: snapshotRef.current!,\n });\n\n const snapshot = snapshotRef.current as Snapshot;\n const domSnapshot =\n snapshotDOM ? window.document.body.innerHTML : undefined;\n const render = new RenderInstance(\n baseRender,\n snapshot,\n domSnapshot,\n profilerContext.renderedComponents\n );\n profilerContext.renderedComponents = [];\n Profiler.renders.push(render);\n resolveNextRender?.(render);\n } catch (error) {\n Profiler.renders.push({\n phase: \"snapshotError\",\n count: Profiler.renders.length,\n error,\n });\n rejectNextRender?.(error);\n } finally {\n nextRender = resolveNextRender = rejectNextRender = undefined;\n }\n };\n\n let iteratorPosition = 0;\n const Profiler: Profiler<Snapshot> = Object.assign(\n ({ children }: ProfilerProps) => {\n return (\n <ProfilerContextProvider value={profilerContext}>\n <React.Profiler id=\"test\" onRender={profilerOnRender}>\n {children}\n </React.Profiler>\n </ProfilerContextProvider>\n );\n },\n {\n replaceSnapshot,\n mergeSnapshot,\n } satisfies ProfiledComponentOnlyFields<Snapshot>,\n {\n renders: new Array<\n | Render<Snapshot>\n | { phase: \"snapshotError\"; count: number; error: unknown }\n >(),\n totalRenderCount() {\n return Profiler.renders.length;\n },\n async peekRender(options: NextRenderOptions = {}) {\n if (iteratorPosition < Profiler.renders.length) {\n const render = Profiler.renders[iteratorPosition];\n\n if (render.phase === \"snapshotError\") {\n throw render.error;\n }\n\n return render;\n }\n return Profiler.waitForNextRender({\n [_stackTrace]: captureStackTrace(Profiler.peekRender),\n ...options,\n });\n },\n async takeRender(options: NextRenderOptions = {}) {\n // In many cases we do not control the resolution of the suspended\n // promise which results in noisy tests when the profiler due to\n // repeated act warnings.\n using _disabledActWarnings = disableActWarnings();\n\n let error: unknown = undefined;\n\n try {\n return await Profiler.peekRender({\n [_stackTrace]: captureStackTrace(Profiler.takeRender),\n ...options,\n });\n } catch (e) {\n error = e;\n throw e;\n } finally {\n if (!(error && error instanceof WaitForRenderTimeoutError)) {\n iteratorPosition++;\n }\n }\n },\n getCurrentRender() {\n // The \"current\" render should point at the same render that the most\n // recent `takeRender` call returned, so we need to get the \"previous\"\n // iterator position, otherwise `takeRender` advances the iterator\n // to the next render. This means we need to call `takeRender` at least\n // once before we can get a current render.\n const currentPosition = iteratorPosition - 1;\n\n if (currentPosition < 0) {\n throw new Error(\n \"No current render available. You need to call `takeRender` before you can get the current render.\"\n );\n }\n\n const render = Profiler.renders[currentPosition];\n\n if (render.phase === \"snapshotError\") {\n throw render.error;\n }\n return render;\n },\n waitForNextRender({\n timeout = 1000,\n // capture the stack trace here so its stack trace is as close to the calling code as possible\n [_stackTrace]: stackTrace = captureStackTrace(\n Profiler.waitForNextRender\n ),\n }: NextRenderOptions = {}) {\n if (!nextRender) {\n nextRender = Promise.race<Render<Snapshot>>([\n new Promise<Render<Snapshot>>((resolve, reject) => {\n resolveNextRender = resolve;\n rejectNextRender = reject;\n }),\n new Promise<Render<Snapshot>>((_, reject) =>\n setTimeout(\n () =>\n reject(\n applyStackTrace(new WaitForRenderTimeoutError(), stackTrace)\n ),\n timeout\n )\n ),\n ]);\n }\n return nextRender;\n },\n } satisfies ProfiledComponentFields<Snapshot>\n );\n return Profiler;\n}\n\n/** @internal */\nexport class WaitForRenderTimeoutError extends Error {\n constructor() {\n super(\"Exceeded timeout waiting for next render.\");\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\ntype StringReplaceRenderWithSnapshot<T extends string> =\n T extends `${infer Pre}Render${infer Post}` ? `${Pre}Snapshot${Post}` : T;\n\ntype ResultReplaceRenderWithSnapshot<T> =\n T extends (...args: infer Args) => Render<infer Snapshot> ?\n (...args: Args) => Snapshot\n : T extends (...args: infer Args) => Promise<Render<infer Snapshot>> ?\n (...args: Args) => Promise<Snapshot>\n : T;\n\ntype ProfiledHookFields<ReturnValue> =\n ProfiledComponentFields<ReturnValue> extends infer PC ?\n {\n [K in keyof PC as StringReplaceRenderWithSnapshot<\n K & string\n >]: ResultReplaceRenderWithSnapshot<PC[K]>;\n }\n : never;\n\n/** @internal */\nexport interface ProfiledHook<Props, ReturnValue>\n extends React.FC<Props>,\n ProfiledHookFields<ReturnValue> {\n Profiler: Profiler<ReturnValue>;\n}\n\n/** @internal */\nexport function profileHook<ReturnValue extends ValidSnapshot, Props>(\n renderCallback: (props: Props) => ReturnValue\n): ProfiledHook<Props, ReturnValue> {\n const Profiler = createProfiler<ReturnValue>();\n\n const ProfiledHook = (props: Props) => {\n Profiler.replaceSnapshot(renderCallback(props));\n return null;\n };\n\n return Object.assign(\n function App(props: Props) {\n return (\n <Profiler>\n <ProfiledHook {...(props as any)} />\n </Profiler>\n );\n },\n {\n Profiler,\n },\n {\n renders: Profiler.renders,\n totalSnapshotCount: Profiler.totalRenderCount,\n async peekSnapshot(options) {\n return (await Profiler.peekRender(options)).snapshot;\n },\n async takeSnapshot(options) {\n return (await Profiler.takeRender(options)).snapshot;\n },\n getCurrentSnapshot() {\n return Profiler.getCurrentRender().snapshot;\n },\n async waitForNextSnapshot(options) {\n return (await Profiler.waitForNextRender(options)).snapshot;\n },\n } satisfies ProfiledHookFields<ReturnValue>\n );\n}\n\nfunction resolveHookOwner(): React.ComponentType | undefined {\n return (React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED\n ?.ReactCurrentOwner?.current?.elementType;\n}\n\nexport function useTrackRenders({ name }: { name?: string } = {}) {\n const component = name || resolveHookOwner();\n\n if (!component) {\n throw new Error(\n \"useTrackRender: Unable to determine component. Please ensure the hook is called inside a rendered component or provide a `name` option.\"\n );\n }\n\n const ctx = useProfilerContext();\n\n if (!ctx) {\n throw new Error(\n \"useTrackComponentRender: A Profiler must be created and rendered to track component renders\"\n );\n }\n\n React.useLayoutEffect(() => {\n ctx.renderedComponents.unshift(component);\n });\n}\n"]}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Captures a StackTrace and (if passed) cuts off
3
+ * the first lines including the calling function.
4
+ */
1
5
  export declare function captureStackTrace(callingFunction?: string | (() => {})): string;
2
6
  export declare function applyStackTrace(error: Error, stackTrace: string): Error;
3
7
  //# sourceMappingURL=traces.d.ts.map
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Captures a StackTrace and (if passed) cuts off
3
+ * the first lines including the calling function.
4
+ */
1
5
  export function captureStackTrace(callingFunction) {
2
6
  var stack = "";
3
7
  try {
@@ -6,15 +10,15 @@ export function captureStackTrace(callingFunction) {
6
10
  catch (e) {
7
11
  (stack = e.stack);
8
12
  }
9
- var callerName = typeof callingFunction === "string"
10
- ? callingFunction
11
- : callingFunction
12
- ? callingFunction.name
13
+ var callerName = typeof callingFunction === "string" ? callingFunction
14
+ : callingFunction ? callingFunction.name
13
15
  : undefined;
14
16
  if (callerName && stack.includes(callerName)) {
15
17
  var lines = stack.split("\n");
16
18
  stack = lines
17
- .slice(lines.findLastIndex(function (line) { return line.includes(callerName); }) + 1)
19
+ .slice(
20
+ // @ts-expect-error this is too old of a TS target, but node has it
21
+ lines.findLastIndex(function (line) { return line.includes(callerName); }) + 1)
18
22
  .join("\n");
19
23
  }
20
24
  return stack;
@@ -1 +1 @@
1
- {"version":3,"file":"traces.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/traces.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,iBAAiB,CAAC,eAAqC;IACrE,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI;QACF,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;KACrB;IAAC,OAAO,CAAM,EAAE;QACf,CAAG,KAAK,GAAK,CAAC,MAAN,CAAO,CAAC;KACjB;IAED,IAAM,UAAU,GACd,OAAO,eAAe,KAAK,QAAQ;QACjC,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,eAAe,CAAC,IAAI;YACtB,CAAC,CAAC,SAAS,CAAC;IAEhB,IAAI,UAAU,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QAC5C,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEhC,KAAK,GAAG,KAAK;aACV,KAAK,CAEJ,KAAK,CAAC,aAAa,CAAC,UAAC,IAAY,IAAK,OAAA,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAzB,CAAyB,CAAC,GAAG,CAAC,CACrE;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,UAAkB;IAC9D,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;IAChD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Captures a StackTrace and (if passed) cuts off\n * the first lines including the calling function.\n */\nexport function captureStackTrace(callingFunction?: string | (() => {})) {\n let stack = \"\";\n try {\n throw new Error(\"\");\n } catch (e: any) {\n ({ stack } = e);\n }\n\n const callerName =\n typeof callingFunction === \"string\"\n ? callingFunction\n : callingFunction\n ? callingFunction.name\n : undefined;\n\n if (callerName && stack.includes(callerName)) {\n const lines = stack.split(\"\\n\");\n\n stack = lines\n .slice(\n // @ts-expect-error this is too old of a TS target, but node has it\n lines.findLastIndex((line: string) => line.includes(callerName)) + 1\n )\n .join(\"\\n\");\n }\n\n return stack;\n}\n\nexport function applyStackTrace(error: Error, stackTrace: string) {\n error.stack = error.message + \"\\n\" + stackTrace;\n return error;\n}\n"]}
1
+ {"version":3,"file":"traces.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/traces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,eAAqC;IACrE,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,CAAC;QACH,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,CAAG,KAAK,GAAK,CAAC,MAAN,CAAO,CAAC;IAClB,CAAC;IAED,IAAM,UAAU,GACd,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe;QACrD,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI;YACxC,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,UAAU,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEhC,KAAK,GAAG,KAAK;aACV,KAAK;QACJ,mEAAmE;QACnE,KAAK,CAAC,aAAa,CAAC,UAAC,IAAY,IAAK,OAAA,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAzB,CAAyB,CAAC,GAAG,CAAC,CACrE;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,UAAkB;IAC9D,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;IAChD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Captures a StackTrace and (if passed) cuts off\n * the first lines including the calling function.\n */\nexport function captureStackTrace(callingFunction?: string | (() => {})) {\n let stack = \"\";\n try {\n throw new Error(\"\");\n } catch (e: any) {\n ({ stack } = e);\n }\n\n const callerName =\n typeof callingFunction === \"string\" ? callingFunction\n : callingFunction ? callingFunction.name\n : undefined;\n\n if (callerName && stack.includes(callerName)) {\n const lines = stack.split(\"\\n\");\n\n stack = lines\n .slice(\n // @ts-expect-error this is too old of a TS target, but node has it\n lines.findLastIndex((line: string) => line.includes(callerName)) + 1\n )\n .join(\"\\n\");\n }\n\n return stack;\n}\n\nexport function applyStackTrace(error: Error, stackTrace: string) {\n error.stack = error.message + \"\\n\" + stackTrace;\n return error;\n}\n"]}