@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.
- package/.changeset/README.md +8 -0
- package/.changeset/beige-geese-wink.md +5 -0
- package/.changeset/breezy-spiders-tap.md +38 -0
- package/.changeset/clean-items-smash.md +5 -0
- package/.changeset/cold-llamas-turn.md +8 -0
- package/.changeset/config.json +14 -0
- package/.changeset/dirty-kids-crash.md +5 -0
- package/.changeset/forty-cups-shop.md +5 -0
- package/.changeset/friendly-clouds-laugh.md +7 -0
- package/.changeset/hot-ducks-burn.md +5 -0
- package/.changeset/polite-avocados-warn.md +5 -0
- package/.changeset/pre.json +29 -0
- package/.changeset/quick-hats-marry.md +5 -0
- package/.changeset/shaggy-ears-scream.md +5 -0
- package/.changeset/shaggy-sheep-pull.md +5 -0
- package/.changeset/sixty-boxes-rest.md +8 -0
- package/.changeset/sour-sheep-walk.md +7 -0
- package/.changeset/strong-terms-perform.md +46 -0
- package/.changeset/thick-mice-collect.md +5 -0
- package/.changeset/thirty-ties-arrive.md +26 -0
- package/.changeset/violet-lions-draw.md +5 -0
- package/.changeset/wild-dolphins-jog.md +5 -0
- package/.changeset/yellow-flies-repeat.md +5 -0
- package/CHANGELOG.md +3535 -0
- package/apollo-client.cjs +475 -398
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +135 -153
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +135 -153
- package/cache/core/cache.d.ts +10 -0
- package/cache/core/cache.js +17 -5
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +1 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +92 -0
- package/cache/core/types/common.d.ts +1 -1
- package/cache/core/types/common.js +4 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +10 -1
- package/cache/inmemory/entityStore.js +190 -29
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/fixPolyfills.js +9 -0
- package/cache/inmemory/fixPolyfills.js.map +1 -1
- package/cache/inmemory/fixPolyfills.native.js +12 -0
- package/cache/inmemory/fixPolyfills.native.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.d.ts +1 -0
- package/cache/inmemory/fragmentRegistry.js +23 -14
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/cache/inmemory/helpers.js +20 -11
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.js +164 -8
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +72 -4
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/object-canon.js +87 -3
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.js +190 -43
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/reactiveVars.js +20 -2
- package/cache/inmemory/reactiveVars.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +4 -0
- package/cache/inmemory/readFromStore.js +58 -9
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +28 -0
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.js +152 -25
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/config/jest/setup.js +2 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.d.ts +264 -3
- package/core/ApolloClient.js +235 -7
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.d.ts +4 -6
- package/core/LocalState.js +56 -18
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +25 -0
- package/core/ObservableQuery.js +239 -30
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +3 -3
- package/core/QueryInfo.js +118 -13
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +8 -1
- package/core/QueryManager.js +247 -46
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +127 -114
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +127 -114
- package/core/equalByQuery.js +20 -1
- package/core/equalByQuery.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +19 -0
- package/core/index.js.map +1 -1
- package/core/networkStatus.d.ts +39 -0
- package/core/networkStatus.js +39 -0
- package/core/networkStatus.js.map +1 -1
- package/core/types.d.ts +9 -0
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +225 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +10 -119
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +10 -119
- package/dev/loadErrorMessageHandler.js.map +1 -1
- package/errors/errors.cjs +1 -1
- package/errors/errors.cjs.map +1 -1
- package/errors/errors.cjs.native.js +1 -1
- package/errors/index.js +14 -1
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +6 -8
- package/link/batch/batch.cjs +2 -2
- package/link/batch/batch.cjs.map +1 -1
- package/link/batch/batch.cjs.native.js +2 -2
- package/link/batch/batchLink.d.ts +21 -0
- package/link/batch/batchLink.js +2 -1
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch/batching.js +24 -1
- package/link/batch/batching.js.map +1 -1
- package/link/batch-http/batch-http.cjs +3 -2
- package/link/batch-http/batch-http.cjs.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +3 -2
- package/link/batch-http/batchHttpLink.d.ts +4 -0
- package/link/batch-http/batchHttpLink.js +53 -2
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/context/context.cjs.map +1 -1
- package/link/context/index.js +1 -0
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.js +12 -5
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +5 -5
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +5 -5
- package/link/error/error.cjs +1 -1
- package/link/error/error.cjs.map +1 -1
- package/link/error/error.cjs.native.js +1 -1
- package/link/error/index.d.ts +3 -0
- package/link/error/index.js +4 -1
- package/link/error/index.js.map +1 -1
- package/link/http/HttpLink.d.ts +0 -2
- package/link/http/HttpLink.js +1 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/checkFetcher.js.map +1 -1
- package/link/http/createHttpLink.js +23 -1
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/createSignalIfSupported.d.ts +5 -0
- package/link/http/createSignalIfSupported.js +5 -0
- package/link/http/createSignalIfSupported.js.map +1 -1
- package/link/http/http.cjs +14 -12
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +14 -12
- package/link/http/index.js +2 -1
- package/link/http/index.js.map +1 -1
- package/link/http/iterators/async.d.ts +4 -0
- package/link/http/iterators/async.js +4 -0
- package/link/http/iterators/async.js.map +1 -1
- package/link/http/iterators/nodeStream.d.ts +4 -0
- package/link/http/iterators/nodeStream.js +4 -0
- package/link/http/iterators/nodeStream.js.map +1 -1
- package/link/http/iterators/promise.d.ts +4 -0
- package/link/http/iterators/promise.js +4 -0
- package/link/http/iterators/promise.js.map +1 -1
- package/link/http/iterators/reader.d.ts +4 -0
- package/link/http/iterators/reader.js +4 -0
- package/link/http/iterators/reader.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +51 -10
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/responseIterator.d.ts +4 -0
- package/link/http/responseIterator.js +6 -0
- package/link/http/responseIterator.js.map +1 -1
- package/link/http/rewriteURIForGET.d.ts +1 -1
- package/link/http/rewriteURIForGET.js +10 -0
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +45 -0
- package/link/http/selectHttpOptionsAndBody.js +23 -0
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/selectURI.js.map +1 -1
- package/link/http/serializeFetchParameter.js.map +1 -1
- package/link/persisted-queries/index.js +34 -4
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +4 -4
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
- package/link/remove-typename/remove-typename.cjs +12 -9
- package/link/remove-typename/remove-typename.cjs.map +1 -1
- package/link/remove-typename/remove-typename.cjs.native.js +12 -9
- package/link/remove-typename/removeTypenameFromVariables.js +12 -9
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/delayFunction.d.ts +29 -0
- package/link/retry/delayFunction.js +6 -0
- package/link/retry/delayFunction.js.map +1 -1
- package/link/retry/retry.cjs +5 -5
- package/link/retry/retry.cjs.map +1 -1
- package/link/retry/retry.cjs.native.js +5 -5
- package/link/retry/retryFunction.d.ts +20 -0
- package/link/retry/retryLink.d.ts +6 -0
- package/link/retry/retryLink.js +31 -6
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +13 -0
- package/link/schema/index.js +3 -3
- package/link/schema/index.js.map +1 -1
- package/link/schema/schema.cjs +3 -3
- package/link/schema/schema.cjs.map +1 -1
- package/link/schema/schema.cjs.native.js +3 -3
- package/link/subscriptions/index.js +35 -2
- package/link/subscriptions/index.js.map +1 -1
- package/link/subscriptions/subscriptions.cjs +3 -2
- package/link/subscriptions/subscriptions.cjs.map +1 -1
- package/link/subscriptions/subscriptions.cjs.native.js +3 -2
- package/link/utils/createOperation.js.map +1 -1
- package/link/utils/filterOperationVariables.js +4 -0
- package/link/utils/filterOperationVariables.js.map +1 -1
- package/link/utils/toPromise.js.map +1 -1
- package/link/utils/transformOperation.js +3 -2
- package/link/utils/transformOperation.js.map +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js.map +1 -1
- package/link/ws/index.d.ts +12 -0
- package/link/ws/index.js +1 -1
- package/link/ws/index.js.map +1 -1
- package/link/ws/ws.cjs +1 -1
- package/link/ws/ws.cjs.map +1 -1
- package/link/ws/ws.cjs.native.js +1 -1
- package/package.json +50 -38
- package/react/cache/QueryReference.d.ts +18 -10
- package/react/cache/QueryReference.js +52 -8
- package/react/cache/QueryReference.js.map +1 -1
- package/react/cache/SuspenseCache.d.ts +10 -0
- package/react/cache/SuspenseCache.js +1 -2
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/cache/getSuspenseCache.js.map +1 -1
- package/react/cache/types.d.ts +3 -0
- package/react/cache/types.js.map +1 -1
- package/react/context/ApolloContext.d.ts +5 -0
- package/react/context/ApolloContext.js +10 -3
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/context.cjs +1 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +1 -3
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc-utils.js +3 -1
- package/react/hoc/hoc-utils.js.map +1 -1
- package/react/hoc/hoc.cjs +9 -17
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +9 -17
- package/react/hoc/mutation-hoc.js +9 -4
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.js +10 -4
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.js +10 -4
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.js +3 -4
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +138 -66
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +138 -66
- package/react/hooks/index.d.ts +2 -0
- package/react/hooks/index.js +1 -0
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/internal/__use.js +5 -0
- package/react/hooks/internal/__use.js.map +1 -1
- package/react/hooks/internal/index.d.ts +1 -0
- package/react/hooks/internal/index.js +2 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
- package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
- package/react/hooks/internal/useRenderGuard.d.ts +2 -0
- package/react/hooks/internal/useRenderGuard.js +17 -0
- package/react/hooks/internal/useRenderGuard.js.map +1 -0
- package/react/hooks/useBackgroundQuery.js +14 -11
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +4 -3
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +13 -4
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +30 -0
- package/react/hooks/useLoadableQuery.js +61 -0
- package/react/hooks/useLoadableQuery.js.map +1 -0
- package/react/hooks/useMutation.js +8 -3
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +11 -0
- package/react/hooks/useQuery.js +138 -6
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useReactiveVar.js +5 -0
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +19 -0
- package/react/hooks/useReadQuery.js +4 -10
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +5 -0
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +22 -22
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +53 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/parser/index.d.ts +3 -0
- package/react/parser/index.js +13 -6
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +11 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +11 -5
- package/react/ssr/RenderPromises.js +21 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/getDataFromTree.js +18 -3
- package/react/ssr/getDataFromTree.js.map +1 -1
- package/react/ssr/ssr.cjs +6 -4
- package/react/ssr/ssr.cjs.map +1 -1
- package/react/ssr/ssr.cjs.native.js +6 -4
- package/react/types/types.d.ts +123 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +14 -11
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +14 -11
- package/testing/core/itAsync.d.ts +1 -1
- package/testing/core/itAsync.js.map +1 -1
- package/testing/core/mocking/mockFetch.d.ts +2 -2
- package/testing/core/mocking/mockFetch.js +8 -4
- package/testing/core/mocking/mockFetch.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +1 -1
- package/testing/core/mocking/mockLink.js +17 -7
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.js +2 -0
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
- package/testing/core/mocking/mockWatchQuery.js +1 -1
- package/testing/core/mocking/mockWatchQuery.js.map +1 -1
- package/testing/core/observableToPromise.d.ts +17 -3
- package/testing/core/observableToPromise.js +5 -0
- package/testing/core/observableToPromise.js.map +1 -1
- package/testing/core/subscribeAndCount.js +3 -0
- package/testing/core/subscribeAndCount.js.map +1 -1
- package/testing/core/wait.js +2 -2
- package/testing/core/wait.js.map +1 -1
- package/testing/core/withConsoleSpy.d.ts +3 -0
- package/testing/core/withConsoleSpy.js +7 -1
- package/testing/core/withConsoleSpy.js.map +1 -1
- package/testing/core/wrap.js +2 -0
- package/testing/core/wrap.js.map +1 -1
- package/testing/internal/ObservableStream.js +14 -14
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/disposables/disableActWarnings.d.ts +10 -0
- package/testing/internal/disposables/disableActWarnings.js +15 -0
- package/testing/internal/disposables/disableActWarnings.js.map +1 -0
- package/testing/internal/disposables/index.d.ts +1 -0
- package/testing/internal/disposables/index.js +1 -0
- package/testing/internal/disposables/index.js.map +1 -1
- package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
- package/testing/internal/disposables/spyOnConsole.js +2 -0
- package/testing/internal/disposables/spyOnConsole.js.map +1 -1
- package/testing/internal/disposables/withCleanup.d.ts +1 -0
- package/testing/internal/disposables/withCleanup.js +3 -0
- package/testing/internal/disposables/withCleanup.js.map +1 -1
- package/testing/internal/profile/Render.d.ts +32 -1
- package/testing/internal/profile/Render.js +14 -2
- package/testing/internal/profile/Render.js.map +1 -1
- package/testing/internal/profile/context.d.ts +10 -0
- package/testing/internal/profile/context.js +14 -0
- package/testing/internal/profile/context.js.map +1 -0
- package/testing/internal/profile/index.d.ts +2 -2
- package/testing/internal/profile/index.js +1 -1
- package/testing/internal/profile/index.js.map +1 -1
- package/testing/internal/profile/profile.d.ts +67 -13
- package/testing/internal/profile/profile.js +153 -79
- package/testing/internal/profile/profile.js.map +1 -1
- package/testing/internal/profile/traces.d.ts +4 -0
- package/testing/internal/profile/traces.js +9 -5
- package/testing/internal/profile/traces.js.map +1 -1
- package/testing/matchers/ProfiledComponent.js +29 -26
- package/testing/matchers/ProfiledComponent.js.map +1 -1
- package/testing/matchers/index.js +2 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toBeGarbageCollected.d.ts +8 -0
- package/testing/matchers/toBeGarbageCollected.js +48 -0
- package/testing/matchers/toBeGarbageCollected.js.map +1 -0
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
- package/testing/matchers/toMatchDocument.js.map +1 -1
- package/testing/react/MockedProvider.d.ts +5 -1
- package/testing/react/MockedProvider.js +6 -2
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +4 -2
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +4 -2
- package/utilities/common/arrays.js +1 -0
- package/utilities/common/arrays.js.map +1 -1
- package/utilities/common/canUse.js +16 -1
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/canonicalStringify.d.ts +17 -0
- package/utilities/common/canonicalStringify.js +41 -0
- package/utilities/common/canonicalStringify.js.map +1 -1
- package/utilities/common/cloneDeep.d.ts +3 -0
- package/utilities/common/cloneDeep.js +5 -0
- package/utilities/common/cloneDeep.js.map +1 -1
- package/utilities/common/compact.d.ts +4 -0
- package/utilities/common/compact.js +4 -0
- package/utilities/common/compact.js.map +1 -1
- package/utilities/common/errorHandling.js +1 -3
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/common/incrementalResult.js +3 -0
- package/utilities/common/incrementalResult.js.map +1 -1
- package/utilities/common/makeUniqueId.js +2 -0
- package/utilities/common/makeUniqueId.js.map +1 -1
- package/utilities/common/maybeDeepFreeze.js +3 -0
- package/utilities/common/maybeDeepFreeze.js.map +1 -1
- package/utilities/common/mergeDeep.js +12 -1
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/common/omitDeep.js.map +1 -1
- package/utilities/globals/global.js +7 -1
- package/utilities/globals/global.js.map +1 -1
- package/utilities/globals/globals.cjs +4 -5
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +4 -5
- package/utilities/globals/index.d.ts +4 -0
- package/utilities/globals/index.js +7 -0
- package/utilities/globals/index.js.map +1 -1
- package/utilities/globals/invariantWrappers.d.ts +40 -0
- package/utilities/globals/invariantWrappers.js +11 -3
- package/utilities/globals/invariantWrappers.js.map +1 -1
- package/utilities/globals/maybe.js.map +1 -1
- package/utilities/graphql/DocumentTransform.d.ts +6 -5
- package/utilities/graphql/DocumentTransform.js +48 -27
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/graphql/directives.js +3 -0
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.d.ts +25 -0
- package/utilities/graphql/fragments.js +36 -0
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.d.ts +5 -0
- package/utilities/graphql/getFromAST.js +9 -0
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/print.js +4 -5
- package/utilities/graphql/print.js.map +1 -1
- package/utilities/graphql/storeUtils.d.ts +14 -0
- package/utilities/graphql/storeUtils.js +8 -2
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.js +106 -7
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +2 -0
- package/utilities/index.js.map +1 -1
- package/utilities/observables/Concast.d.ts +1 -1
- package/utilities/observables/Concast.js +85 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/observables/Observable.js +6 -0
- package/utilities/observables/Observable.js.map +1 -1
- package/utilities/observables/asyncMap.js +12 -3
- package/utilities/observables/asyncMap.js.map +1 -1
- package/utilities/observables/iteration.js +3 -0
- package/utilities/observables/iteration.js.map +1 -1
- package/utilities/observables/subclassing.js +14 -0
- package/utilities/observables/subclassing.js.map +1 -1
- package/utilities/policies/pagination.js +47 -3
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/promises/decoration.js +1 -0
- package/utilities/promises/decoration.js.map +1 -1
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/utilities/subscriptions/relay/relay.cjs +9 -8
- package/utilities/subscriptions/relay/relay.cjs.map +1 -1
- package/utilities/subscriptions/relay/relay.cjs.native.js +9 -8
- package/utilities/subscriptions/urql/index.js.map +1 -1
- package/utilities/subscriptions/urql/urql.cjs +9 -8
- package/utilities/subscriptions/urql/urql.cjs.map +1 -1
- package/utilities/subscriptions/urql/urql.cjs.native.js +9 -8
- package/utilities/types/DeepOmit.js.map +1 -1
- package/utilities/types/DeepPartial.d.ts +1 -1
- package/utilities/types/DeepPartial.js +4 -0
- package/utilities/types/DeepPartial.js.map +1 -1
- package/utilities/types/IsStrictlyAny.js.map +1 -1
- package/utilities/types/OnlyRequiredProperties.d.ts +7 -0
- package/utilities/types/OnlyRequiredProperties.js +2 -0
- package/utilities/types/OnlyRequiredProperties.js.map +1 -0
- package/utilities/types/TODO.d.ts +3 -0
- package/utilities/types/TODO.js +2 -0
- package/utilities/types/TODO.js.map +1 -0
- package/utilities/utilities.cjs +61 -53
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +61 -53
- package/version.js +1 -1
- package/cache/core/cache.d.ts.map +0 -1
- package/cache/core/types/Cache.d.ts.map +0 -1
- package/cache/core/types/DataProxy.d.ts.map +0 -1
- package/cache/core/types/common.d.ts.map +0 -1
- package/cache/index.d.ts.map +0 -1
- package/cache/inmemory/entityStore.d.ts.map +0 -1
- package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
- package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
- package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
- package/cache/inmemory/helpers.d.ts.map +0 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
- package/cache/inmemory/key-extractor.d.ts.map +0 -1
- package/cache/inmemory/object-canon.d.ts.map +0 -1
- package/cache/inmemory/policies.d.ts.map +0 -1
- package/cache/inmemory/reactiveVars.d.ts.map +0 -1
- package/cache/inmemory/readFromStore.d.ts.map +0 -1
- package/cache/inmemory/types.d.ts.map +0 -1
- package/cache/inmemory/writeToStore.d.ts.map +0 -1
- package/config/jest/setup.d.ts.map +0 -1
- package/core/ApolloClient.d.ts.map +0 -1
- package/core/LocalState.d.ts.map +0 -1
- package/core/ObservableQuery.d.ts.map +0 -1
- package/core/QueryInfo.d.ts.map +0 -1
- package/core/QueryManager.d.ts.map +0 -1
- package/core/equalByQuery.d.ts.map +0 -1
- package/core/index.d.ts.map +0 -1
- package/core/networkStatus.d.ts.map +0 -1
- package/core/types.d.ts.map +0 -1
- package/core/watchQueryOptions.d.ts.map +0 -1
- package/dev/index.d.ts.map +0 -1
- package/dev/loadDevMessages.d.ts.map +0 -1
- package/dev/loadErrorMessageHandler.d.ts.map +0 -1
- package/dev/loadErrorMessages.d.ts.map +0 -1
- package/errors/index.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/invariantErrorCodes.d.ts.map +0 -1
- package/link/batch/batchLink.d.ts.map +0 -1
- package/link/batch/batching.d.ts.map +0 -1
- package/link/batch/index.d.ts.map +0 -1
- package/link/batch-http/batchHttpLink.d.ts.map +0 -1
- package/link/batch-http/index.d.ts.map +0 -1
- package/link/context/index.d.ts.map +0 -1
- package/link/core/ApolloLink.d.ts.map +0 -1
- package/link/core/concat.d.ts.map +0 -1
- package/link/core/empty.d.ts.map +0 -1
- package/link/core/execute.d.ts.map +0 -1
- package/link/core/from.d.ts.map +0 -1
- package/link/core/index.d.ts.map +0 -1
- package/link/core/split.d.ts.map +0 -1
- package/link/core/types.d.ts.map +0 -1
- package/link/error/index.d.ts.map +0 -1
- package/link/http/HttpLink.d.ts.map +0 -1
- package/link/http/checkFetcher.d.ts.map +0 -1
- package/link/http/createHttpLink.d.ts.map +0 -1
- package/link/http/createSignalIfSupported.d.ts.map +0 -1
- package/link/http/index.d.ts.map +0 -1
- package/link/http/iterators/async.d.ts.map +0 -1
- package/link/http/iterators/nodeStream.d.ts.map +0 -1
- package/link/http/iterators/promise.d.ts.map +0 -1
- package/link/http/iterators/reader.d.ts.map +0 -1
- package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
- package/link/http/responseIterator.d.ts.map +0 -1
- package/link/http/rewriteURIForGET.d.ts.map +0 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
- package/link/http/selectURI.d.ts.map +0 -1
- package/link/http/serializeFetchParameter.d.ts.map +0 -1
- package/link/persisted-queries/index.d.ts.map +0 -1
- package/link/remove-typename/index.d.ts.map +0 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
- package/link/retry/delayFunction.d.ts.map +0 -1
- package/link/retry/index.d.ts.map +0 -1
- package/link/retry/retryFunction.d.ts.map +0 -1
- package/link/retry/retryLink.d.ts.map +0 -1
- package/link/schema/index.d.ts.map +0 -1
- package/link/subscriptions/index.d.ts.map +0 -1
- package/link/utils/createOperation.d.ts.map +0 -1
- package/link/utils/filterOperationVariables.d.ts.map +0 -1
- package/link/utils/fromError.d.ts.map +0 -1
- package/link/utils/fromPromise.d.ts.map +0 -1
- package/link/utils/index.d.ts.map +0 -1
- package/link/utils/throwServerError.d.ts.map +0 -1
- package/link/utils/toPromise.d.ts.map +0 -1
- package/link/utils/transformOperation.d.ts.map +0 -1
- package/link/utils/validateOperation.d.ts.map +0 -1
- package/link/ws/index.d.ts.map +0 -1
- package/react/cache/QueryReference.d.ts.map +0 -1
- package/react/cache/SuspenseCache.d.ts.map +0 -1
- package/react/cache/getSuspenseCache.d.ts.map +0 -1
- package/react/cache/index.d.ts.map +0 -1
- package/react/cache/types.d.ts.map +0 -1
- package/react/components/Mutation.d.ts.map +0 -1
- package/react/components/Query.d.ts.map +0 -1
- package/react/components/Subscription.d.ts.map +0 -1
- package/react/components/index.d.ts.map +0 -1
- package/react/components/types.d.ts.map +0 -1
- package/react/context/ApolloConsumer.d.ts.map +0 -1
- package/react/context/ApolloContext.d.ts.map +0 -1
- package/react/context/ApolloProvider.d.ts.map +0 -1
- package/react/context/index.d.ts.map +0 -1
- package/react/hoc/graphql.d.ts.map +0 -1
- package/react/hoc/hoc-utils.d.ts.map +0 -1
- package/react/hoc/index.d.ts.map +0 -1
- package/react/hoc/mutation-hoc.d.ts.map +0 -1
- package/react/hoc/query-hoc.d.ts.map +0 -1
- package/react/hoc/subscription-hoc.d.ts.map +0 -1
- package/react/hoc/types.d.ts.map +0 -1
- package/react/hoc/withApollo.d.ts.map +0 -1
- package/react/hooks/constants.d.ts.map +0 -1
- package/react/hooks/index.d.ts.map +0 -1
- package/react/hooks/internal/__use.d.ts.map +0 -1
- package/react/hooks/internal/index.d.ts.map +0 -1
- package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
- package/react/hooks/useApolloClient.d.ts.map +0 -1
- package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
- package/react/hooks/useFragment.d.ts.map +0 -1
- package/react/hooks/useLazyQuery.d.ts.map +0 -1
- package/react/hooks/useMutation.d.ts.map +0 -1
- package/react/hooks/useQuery.d.ts.map +0 -1
- package/react/hooks/useReactiveVar.d.ts.map +0 -1
- package/react/hooks/useReadQuery.d.ts.map +0 -1
- package/react/hooks/useSubscription.d.ts.map +0 -1
- package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
- package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
- package/react/index.d.ts.map +0 -1
- package/react/parser/index.d.ts.map +0 -1
- package/react/ssr/RenderPromises.d.ts.map +0 -1
- package/react/ssr/getDataFromTree.d.ts.map +0 -1
- package/react/ssr/index.d.ts.map +0 -1
- package/react/ssr/renderToStringWithData.d.ts.map +0 -1
- package/react/types/types.d.ts.map +0 -1
- package/testing/core/index.d.ts.map +0 -1
- package/testing/core/itAsync.d.ts.map +0 -1
- package/testing/core/mocking/mockClient.d.ts.map +0 -1
- package/testing/core/mocking/mockFetch.d.ts.map +0 -1
- package/testing/core/mocking/mockLink.d.ts.map +0 -1
- package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
- package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
- package/testing/core/observableToPromise.d.ts.map +0 -1
- package/testing/core/subscribeAndCount.d.ts.map +0 -1
- package/testing/core/wait.d.ts.map +0 -1
- package/testing/core/withConsoleSpy.d.ts.map +0 -1
- package/testing/core/wrap.d.ts.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/internal/ObservableStream.d.ts.map +0 -1
- package/testing/internal/disposables/index.d.ts.map +0 -1
- package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
- package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
- package/testing/internal/index.d.ts.map +0 -1
- package/testing/internal/profile/Render.d.ts.map +0 -1
- package/testing/internal/profile/index.d.ts.map +0 -1
- package/testing/internal/profile/profile.d.ts.map +0 -1
- package/testing/internal/profile/traces.d.ts.map +0 -1
- package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
- package/testing/matchers/index.d.ts.map +0 -1
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
- package/testing/matchers/toMatchDocument.d.ts.map +0 -1
- package/testing/react/MockedProvider.d.ts.map +0 -1
- package/utilities/common/arrays.d.ts.map +0 -1
- package/utilities/common/canUse.d.ts.map +0 -1
- package/utilities/common/canonicalStringify.d.ts.map +0 -1
- package/utilities/common/cloneDeep.d.ts.map +0 -1
- package/utilities/common/compact.d.ts.map +0 -1
- package/utilities/common/errorHandling.d.ts.map +0 -1
- package/utilities/common/filterInPlace.d.ts +0 -2
- package/utilities/common/filterInPlace.d.ts.map +0 -1
- package/utilities/common/filterInPlace.js +0 -11
- package/utilities/common/filterInPlace.js.map +0 -1
- package/utilities/common/incrementalResult.d.ts.map +0 -1
- package/utilities/common/makeUniqueId.d.ts.map +0 -1
- package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
- package/utilities/common/mergeDeep.d.ts.map +0 -1
- package/utilities/common/mergeOptions.d.ts.map +0 -1
- package/utilities/common/objects.d.ts.map +0 -1
- package/utilities/common/omitDeep.d.ts.map +0 -1
- package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
- package/utilities/common/stripTypename.d.ts.map +0 -1
- package/utilities/globals/global.d.ts.map +0 -1
- package/utilities/globals/index.d.ts.map +0 -1
- package/utilities/globals/invariantWrappers.d.ts.map +0 -1
- package/utilities/globals/maybe.d.ts.map +0 -1
- package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
- package/utilities/graphql/directives.d.ts.map +0 -1
- package/utilities/graphql/fragments.d.ts.map +0 -1
- package/utilities/graphql/getFromAST.d.ts.map +0 -1
- package/utilities/graphql/operations.d.ts.map +0 -1
- package/utilities/graphql/print.d.ts.map +0 -1
- package/utilities/graphql/storeUtils.d.ts.map +0 -1
- package/utilities/graphql/transform.d.ts.map +0 -1
- package/utilities/index.d.ts.map +0 -1
- package/utilities/observables/Concast.d.ts.map +0 -1
- package/utilities/observables/Observable.d.ts.map +0 -1
- package/utilities/observables/asyncMap.d.ts.map +0 -1
- package/utilities/observables/iteration.d.ts.map +0 -1
- package/utilities/observables/subclassing.d.ts.map +0 -1
- package/utilities/policies/pagination.d.ts.map +0 -1
- package/utilities/promises/decoration.d.ts.map +0 -1
- package/utilities/subscriptions/relay/index.d.ts.map +0 -1
- package/utilities/subscriptions/shared.d.ts.map +0 -1
- package/utilities/subscriptions/urql/index.d.ts.map +0 -1
- package/utilities/types/DeepOmit.d.ts.map +0 -1
- package/utilities/types/DeepPartial.d.ts.map +0 -1
- package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
- package/utilities/types/Primitive.d.ts.map +0 -1
- 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
|
-
|
|
13
|
+
/** @internal */
|
|
14
|
+
interface ProfilerProps {
|
|
15
|
+
children: React.ReactNode;
|
|
12
16
|
}
|
|
13
|
-
|
|
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
|
|
18
|
-
|
|
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<
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
79
|
+
replaceSnapshot: ReplaceSnapshot<Snapshot>;
|
|
80
|
+
mergeSnapshot: MergeSnapshot<Snapshot>;
|
|
38
81
|
}) => void;
|
|
39
82
|
snapshotDOM?: boolean;
|
|
40
83
|
initialSnapshot?: Snapshot;
|
|
41
|
-
|
|
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<
|
|
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
|
-
|
|
51
|
-
|
|
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,
|
|
12
|
-
var
|
|
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
|
|
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:
|
|
72
|
+
count: Profiler.renders.length + 1,
|
|
38
73
|
};
|
|
39
74
|
try {
|
|
40
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
91
|
+
Profiler.renders.push({
|
|
52
92
|
phase: "snapshotError",
|
|
53
|
-
count:
|
|
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
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
69
|
-
return
|
|
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
|
|
118
|
+
var render;
|
|
75
119
|
var _a;
|
|
76
120
|
return __generator(this, function (_b) {
|
|
77
|
-
if (iteratorPosition <
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
throw
|
|
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
|
|
126
|
+
return [2 /*return*/, render];
|
|
83
127
|
}
|
|
84
|
-
|
|
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
|
-
|
|
140
|
+
env_1 = { stack: [], error: void 0, hasError: false };
|
|
98
141
|
_b.label = 1;
|
|
99
142
|
case 1:
|
|
100
|
-
_b.trys.push([1,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
|
155
|
+
case 5:
|
|
108
156
|
if (!(error && error instanceof WaitForRenderTimeoutError)) {
|
|
109
157
|
iteratorPosition++;
|
|
110
158
|
}
|
|
111
|
-
return [7];
|
|
112
|
-
case
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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,
|
|
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
|
|
214
|
+
return Profiler;
|
|
157
215
|
}
|
|
158
|
-
|
|
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
|
|
171
|
-
var
|
|
172
|
-
|
|
230
|
+
var Profiler = createProfiler();
|
|
231
|
+
var ProfiledHook = function (props) {
|
|
232
|
+
Profiler.replaceSnapshot(renderCallback(props));
|
|
173
233
|
return null;
|
|
174
234
|
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
239
|
+
Profiler: Profiler,
|
|
183
240
|
}, {
|
|
184
|
-
renders:
|
|
185
|
-
|
|
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
|
|
191
|
-
case 1: return [2
|
|
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
|
|
201
|
-
case 1: return [2
|
|
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
|
|
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
|
|
215
|
-
case 1: return [2
|
|
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,MAAA,MAAM,CAAC,WAAW,oC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AAC,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,QAAQ,CAAC,eAAe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;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(
|
|
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":"
|
|
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"]}
|