@apollo/client 3.8.7 → 3.8.8
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/config.json +14 -0
- package/CHANGELOG.md +3357 -0
- package/apollo-client.cjs +314 -316
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +133 -152
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +133 -152
- 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.js +4 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +1 -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.js +23 -12
- 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 +161 -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 +91 -3
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.js +193 -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 +54 -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 +116 -13
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +4 -0
- package/core/QueryManager.js +229 -33
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +112 -103
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +112 -103
- 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 +5 -111
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +5 -111
- 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 +1 -0
- 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 +49 -38
- package/react/cache/QueryReference.d.ts +6 -1
- package/react/cache/QueryReference.js +26 -1
- package/react/cache/QueryReference.js.map +1 -1
- package/react/cache/SuspenseCache.d.ts +10 -0
- package/react/cache/SuspenseCache.js +1 -1
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/cache/getSuspenseCache.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 +30 -22
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +30 -22
- package/react/hooks/internal/__use.js +5 -0
- package/react/hooks/internal/__use.js.map +1 -1
- package/react/hooks/internal/index.js +1 -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/useBackgroundQuery.js +6 -0
- 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/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 +137 -5
- 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.map +1 -1
- package/react/hooks/useSubscription.js +5 -0
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +11 -5
- 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.js +4 -5
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +2 -4
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +2 -4
- 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 +66 -0
- 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.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/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 +28 -0
- package/testing/internal/profile/Render.js +12 -1
- package/testing/internal/profile/Render.js.map +1 -1
- package/testing/internal/profile/profile.d.ts +44 -7
- package/testing/internal/profile/profile.js +63 -51
- 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 +27 -22
- package/testing/matchers/ProfiledComponent.js.map +1 -1
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
- package/testing/matchers/toMatchDocument.js.map +1 -1
- package/testing/react/MockedProvider.d.ts +4 -0
- 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/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.js +19 -6
- 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.map +1 -1
- package/utilities/graphql/storeUtils.d.ts +14 -0
- package/utilities/graphql/storeUtils.js +7 -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/observables/Concast.d.ts +1 -1
- package/utilities/observables/Concast.js +84 -1
- 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/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/TODO.d.ts +3 -0
- package/utilities/types/TODO.js +2 -0
- package/utilities/types/TODO.js.map +1 -0
- package/utilities/utilities.cjs +31 -27
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +31 -27
- 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/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/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
|
@@ -8,24 +8,37 @@ import { hasOwn, fieldNameFromStoreName } from "./helpers.js";
|
|
|
8
8
|
var DELETE = Object.create(null);
|
|
9
9
|
var delModifier = function () { return DELETE; };
|
|
10
10
|
var INVALIDATE = Object.create(null);
|
|
11
|
-
var EntityStore = (function () {
|
|
11
|
+
var EntityStore = /** @class */ (function () {
|
|
12
12
|
function EntityStore(policies, group) {
|
|
13
13
|
var _this = this;
|
|
14
14
|
this.policies = policies;
|
|
15
15
|
this.group = group;
|
|
16
16
|
this.data = Object.create(null);
|
|
17
|
+
// Maps root entity IDs to the number of times they have been retained, minus
|
|
18
|
+
// the number of times they have been released. Retained entities keep other
|
|
19
|
+
// entities they reference (even indirectly) from being garbage collected.
|
|
17
20
|
this.rootIds = Object.create(null);
|
|
21
|
+
// Lazily tracks { __ref: <dataId> } strings contained by this.data[dataId].
|
|
18
22
|
this.refs = Object.create(null);
|
|
23
|
+
// Bound function that can be passed around to provide easy access to fields
|
|
24
|
+
// of Reference objects as well as ordinary objects.
|
|
19
25
|
this.getFieldValue = function (objectOrReference, storeFieldName) {
|
|
20
|
-
return maybeDeepFreeze(isReference(objectOrReference)
|
|
21
|
-
|
|
26
|
+
return maybeDeepFreeze(isReference(objectOrReference) ?
|
|
27
|
+
_this.get(objectOrReference.__ref, storeFieldName)
|
|
22
28
|
: objectOrReference && objectOrReference[storeFieldName]);
|
|
23
29
|
};
|
|
30
|
+
// Returns true for non-normalized StoreObjects and non-dangling
|
|
31
|
+
// References, indicating that readField(name, objOrRef) has a chance of
|
|
32
|
+
// working. Useful for filtering out dangling references from lists.
|
|
24
33
|
this.canRead = function (objOrRef) {
|
|
25
|
-
return isReference(objOrRef)
|
|
26
|
-
|
|
34
|
+
return isReference(objOrRef) ?
|
|
35
|
+
_this.has(objOrRef.__ref)
|
|
27
36
|
: typeof objOrRef === "object";
|
|
28
37
|
};
|
|
38
|
+
// Bound function that converts an id or an object with a __typename and
|
|
39
|
+
// primary key fields to a Reference object. If called with a Reference object,
|
|
40
|
+
// that same Reference object is returned. Pass true for mergeIntoStore to persist
|
|
41
|
+
// an object into the store.
|
|
29
42
|
this.toReference = function (objOrIdOrRef, mergeIntoStore) {
|
|
30
43
|
if (typeof objOrIdOrRef === "string") {
|
|
31
44
|
return makeReference(objOrIdOrRef);
|
|
@@ -43,6 +56,9 @@ var EntityStore = (function () {
|
|
|
43
56
|
}
|
|
44
57
|
};
|
|
45
58
|
}
|
|
59
|
+
// Although the EntityStore class is abstract, it contains concrete
|
|
60
|
+
// implementations of the various NormalizedCache interface methods that
|
|
61
|
+
// are inherited by the Root and Layer subclasses.
|
|
46
62
|
EntityStore.prototype.toObject = function () {
|
|
47
63
|
return __assign({}, this.data);
|
|
48
64
|
};
|
|
@@ -66,6 +82,11 @@ var EntityStore = (function () {
|
|
|
66
82
|
}
|
|
67
83
|
};
|
|
68
84
|
EntityStore.prototype.lookup = function (dataId, dependOnExistence) {
|
|
85
|
+
// The has method (above) calls lookup with dependOnExistence = true, so
|
|
86
|
+
// that it can later be invalidated when we add or remove a StoreObject for
|
|
87
|
+
// this dataId. Any consumer who cares about the contents of the StoreObject
|
|
88
|
+
// should not rely on this dependency, since the contents could change
|
|
89
|
+
// without the object being added or removed.
|
|
69
90
|
if (dependOnExistence)
|
|
70
91
|
this.group.depend(dataId, "__exists");
|
|
71
92
|
if (hasOwn.call(this.data, dataId)) {
|
|
@@ -81,32 +102,54 @@ var EntityStore = (function () {
|
|
|
81
102
|
EntityStore.prototype.merge = function (older, newer) {
|
|
82
103
|
var _this = this;
|
|
83
104
|
var dataId;
|
|
105
|
+
// Convert unexpected references to ID strings.
|
|
84
106
|
if (isReference(older))
|
|
85
107
|
older = older.__ref;
|
|
86
108
|
if (isReference(newer))
|
|
87
109
|
newer = newer.__ref;
|
|
88
110
|
var existing = typeof older === "string" ? this.lookup((dataId = older)) : older;
|
|
89
111
|
var incoming = typeof newer === "string" ? this.lookup((dataId = newer)) : newer;
|
|
112
|
+
// If newer was a string ID, but that ID was not defined in this store,
|
|
113
|
+
// then there are no fields to be merged, so we're done.
|
|
90
114
|
if (!incoming)
|
|
91
115
|
return;
|
|
92
116
|
invariant(typeof dataId === "string", 1);
|
|
93
117
|
var merged = new DeepMerger(storeObjectReconciler).merge(existing, incoming);
|
|
118
|
+
// Even if merged === existing, existing may have come from a lower
|
|
119
|
+
// layer, so we always need to set this.data[dataId] on this level.
|
|
94
120
|
this.data[dataId] = merged;
|
|
95
121
|
if (merged !== existing) {
|
|
96
122
|
delete this.refs[dataId];
|
|
97
123
|
if (this.group.caching) {
|
|
98
124
|
var fieldsToDirty_1 = Object.create(null);
|
|
125
|
+
// If we added a new StoreObject where there was previously none, dirty
|
|
126
|
+
// anything that depended on the existence of this dataId, such as the
|
|
127
|
+
// EntityStore#has method.
|
|
99
128
|
if (!existing)
|
|
100
129
|
fieldsToDirty_1.__exists = 1;
|
|
130
|
+
// Now invalidate dependents who called getFieldValue for any fields
|
|
131
|
+
// that are changing as a result of this merge.
|
|
101
132
|
Object.keys(incoming).forEach(function (storeFieldName) {
|
|
102
133
|
if (!existing ||
|
|
103
134
|
existing[storeFieldName] !== merged[storeFieldName]) {
|
|
135
|
+
// Always dirty the full storeFieldName, which may include
|
|
136
|
+
// serialized arguments following the fieldName prefix.
|
|
104
137
|
fieldsToDirty_1[storeFieldName] = 1;
|
|
138
|
+
// Also dirty fieldNameFromStoreName(storeFieldName) if it's
|
|
139
|
+
// different from storeFieldName and this field does not have
|
|
140
|
+
// keyArgs configured, because that means the cache can't make
|
|
141
|
+
// any assumptions about how field values with the same field
|
|
142
|
+
// name but different arguments might be interrelated, so it
|
|
143
|
+
// must err on the side of invalidating all field values that
|
|
144
|
+
// share the same short fieldName, regardless of arguments.
|
|
105
145
|
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
106
146
|
if (fieldName !== storeFieldName &&
|
|
107
147
|
!_this.policies.hasKeyArgs(merged.__typename, fieldName)) {
|
|
108
148
|
fieldsToDirty_1[fieldName] = 1;
|
|
109
149
|
}
|
|
150
|
+
// If merged[storeFieldName] has become undefined, and this is the
|
|
151
|
+
// Root layer, actually delete the property from the merged object,
|
|
152
|
+
// which is guaranteed to have been created fresh in this method.
|
|
110
153
|
if (merged[storeFieldName] === void 0 && !(_this instanceof Layer)) {
|
|
111
154
|
delete merged[storeFieldName];
|
|
112
155
|
}
|
|
@@ -114,6 +157,10 @@ var EntityStore = (function () {
|
|
|
114
157
|
});
|
|
115
158
|
if (fieldsToDirty_1.__typename &&
|
|
116
159
|
!(existing && existing.__typename) &&
|
|
160
|
+
// Since we return default root __typename strings
|
|
161
|
+
// automatically from store.get, we don't need to dirty the
|
|
162
|
+
// ROOT_QUERY.__typename field if merged.__typename is equal
|
|
163
|
+
// to the default string (usually "Query").
|
|
117
164
|
this.policies.rootTypenamesById[dataId] === merged.__typename) {
|
|
118
165
|
delete fieldsToDirty_1.__typename;
|
|
119
166
|
}
|
|
@@ -137,8 +184,8 @@ var EntityStore = (function () {
|
|
|
137
184
|
toReference: this.toReference,
|
|
138
185
|
canRead: this.canRead,
|
|
139
186
|
readField: function (fieldNameOrOptions, from) {
|
|
140
|
-
return _this.policies.readField(typeof fieldNameOrOptions === "string"
|
|
141
|
-
|
|
187
|
+
return _this.policies.readField(typeof fieldNameOrOptions === "string" ?
|
|
188
|
+
{
|
|
142
189
|
fieldName: fieldNameOrOptions,
|
|
143
190
|
from: from || makeReference(dataId),
|
|
144
191
|
}
|
|
@@ -150,13 +197,9 @@ var EntityStore = (function () {
|
|
|
150
197
|
var fieldValue = storeObject[storeFieldName];
|
|
151
198
|
if (fieldValue === void 0)
|
|
152
199
|
return;
|
|
153
|
-
var modify = typeof fields === "function"
|
|
154
|
-
? fields
|
|
155
|
-
: fields[storeFieldName] || fields[fieldName];
|
|
200
|
+
var modify = typeof fields === "function" ? fields : (fields[storeFieldName] || fields[fieldName]);
|
|
156
201
|
if (modify) {
|
|
157
|
-
var newValue = modify === delModifier
|
|
158
|
-
? DELETE
|
|
159
|
-
: modify(maybeDeepFreeze(fieldValue), __assign(__assign({}, sharedDetails_1), { fieldName: fieldName, storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) }));
|
|
202
|
+
var newValue = modify === delModifier ? DELETE : (modify(maybeDeepFreeze(fieldValue), __assign(__assign({}, sharedDetails_1), { fieldName: fieldName, storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) })));
|
|
160
203
|
if (newValue === INVALIDATE) {
|
|
161
204
|
_this.group.dirty(dataId, storeFieldName);
|
|
162
205
|
}
|
|
@@ -178,6 +221,7 @@ var EntityStore = (function () {
|
|
|
178
221
|
checkReference(newValue);
|
|
179
222
|
}
|
|
180
223
|
else if (Array.isArray(newValue)) {
|
|
224
|
+
// Warn about writing "mixed" arrays of Reference and non-Reference objects
|
|
181
225
|
var seenReference = false;
|
|
182
226
|
var someNonReference = void 0;
|
|
183
227
|
for (var _i = 0, newValue_1 = newValue; _i < newValue_1.length; _i++) {
|
|
@@ -188,8 +232,11 @@ var EntityStore = (function () {
|
|
|
188
232
|
break;
|
|
189
233
|
}
|
|
190
234
|
else {
|
|
235
|
+
// Do not warn on primitive values, since those could never be represented
|
|
236
|
+
// by a reference. This is a valid (albeit uncommon) use case.
|
|
191
237
|
if (typeof value === "object" && !!value) {
|
|
192
238
|
var id = _this.policies.identify(value)[0];
|
|
239
|
+
// check if object could even be referenced, otherwise we are not interested in it for this warning
|
|
193
240
|
if (id) {
|
|
194
241
|
someNonReference = value;
|
|
195
242
|
}
|
|
@@ -225,18 +272,23 @@ var EntityStore = (function () {
|
|
|
225
272
|
}
|
|
226
273
|
return false;
|
|
227
274
|
};
|
|
275
|
+
// If called with only one argument, removes the entire entity
|
|
276
|
+
// identified by dataId. If called with a fieldName as well, removes all
|
|
277
|
+
// fields of that entity whose names match fieldName according to the
|
|
278
|
+
// fieldNameFromStoreName helper function. If called with a fieldName
|
|
279
|
+
// and variables, removes all fields of that entity whose names match fieldName
|
|
280
|
+
// and whose arguments when cached exactly match the variables passed.
|
|
228
281
|
EntityStore.prototype.delete = function (dataId, fieldName, args) {
|
|
229
282
|
var _a;
|
|
230
283
|
var storeObject = this.lookup(dataId);
|
|
231
284
|
if (storeObject) {
|
|
232
285
|
var typename = this.getFieldValue(storeObject, "__typename");
|
|
233
|
-
var storeFieldName = fieldName && args
|
|
234
|
-
|
|
286
|
+
var storeFieldName = fieldName && args ?
|
|
287
|
+
this.policies.getStoreFieldName({ typename: typename, fieldName: fieldName, args: args })
|
|
235
288
|
: fieldName;
|
|
236
|
-
return this.modify(dataId, storeFieldName
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
_a) : delModifier);
|
|
289
|
+
return this.modify(dataId, storeFieldName ? (_a = {},
|
|
290
|
+
_a[storeFieldName] = delModifier,
|
|
291
|
+
_a) : delModifier);
|
|
240
292
|
}
|
|
241
293
|
return false;
|
|
242
294
|
};
|
|
@@ -249,6 +301,10 @@ var EntityStore = (function () {
|
|
|
249
301
|
if (this instanceof Layer && this !== limit) {
|
|
250
302
|
evicted = this.parent.evict(options, limit) || evicted;
|
|
251
303
|
}
|
|
304
|
+
// Always invalidate the field to trigger rereading of watched
|
|
305
|
+
// queries, even if no cache data was modified by the eviction,
|
|
306
|
+
// because queries may depend on computed fields with custom read
|
|
307
|
+
// functions, whose values are not stored in the EntityStore.
|
|
252
308
|
if (options.fieldName || evicted) {
|
|
253
309
|
this.group.dirty(options.id, options.fieldName || "__exists");
|
|
254
310
|
}
|
|
@@ -301,6 +357,8 @@ var EntityStore = (function () {
|
|
|
301
357
|
}
|
|
302
358
|
return 0;
|
|
303
359
|
};
|
|
360
|
+
// Return a Set<string> of all the ID strings that have been retained by
|
|
361
|
+
// this layer/root *and* any layers/roots beneath it.
|
|
304
362
|
EntityStore.prototype.getRootIdSet = function (ids) {
|
|
305
363
|
if (ids === void 0) { ids = new Set(); }
|
|
306
364
|
Object.keys(this.rootIds).forEach(ids.add, ids);
|
|
@@ -308,17 +366,29 @@ var EntityStore = (function () {
|
|
|
308
366
|
this.parent.getRootIdSet(ids);
|
|
309
367
|
}
|
|
310
368
|
else {
|
|
369
|
+
// Official singleton IDs like ROOT_QUERY and ROOT_MUTATION are
|
|
370
|
+
// always considered roots for garbage collection, regardless of
|
|
371
|
+
// their retainment counts in this.rootIds.
|
|
311
372
|
Object.keys(this.policies.rootTypenamesById).forEach(ids.add, ids);
|
|
312
373
|
}
|
|
313
374
|
return ids;
|
|
314
375
|
};
|
|
376
|
+
// The goal of garbage collection is to remove IDs from the Root layer of the
|
|
377
|
+
// store that are no longer reachable starting from any IDs that have been
|
|
378
|
+
// explicitly retained (see retain and release, above). Returns an array of
|
|
379
|
+
// dataId strings that were removed from the store.
|
|
315
380
|
EntityStore.prototype.gc = function () {
|
|
316
381
|
var _this = this;
|
|
317
382
|
var ids = this.getRootIdSet();
|
|
318
383
|
var snapshot = this.toObject();
|
|
319
384
|
ids.forEach(function (id) {
|
|
320
385
|
if (hasOwn.call(snapshot, id)) {
|
|
386
|
+
// Because we are iterating over an ECMAScript Set, the IDs we add here
|
|
387
|
+
// will be visited in later iterations of the forEach loop only if they
|
|
388
|
+
// were not previously contained by the Set.
|
|
321
389
|
Object.keys(_this.findChildRefIds(id)).forEach(ids.add, ids);
|
|
390
|
+
// By removing IDs from the snapshot object here, we protect them from
|
|
391
|
+
// getting removed from the root store layer below.
|
|
322
392
|
delete snapshot[id];
|
|
323
393
|
}
|
|
324
394
|
});
|
|
@@ -338,13 +408,24 @@ var EntityStore = (function () {
|
|
|
338
408
|
if (!root)
|
|
339
409
|
return found_1;
|
|
340
410
|
var workSet_1 = new Set([root]);
|
|
411
|
+
// Within the store, only arrays and objects can contain child entity
|
|
412
|
+
// references, so we can prune the traversal using this predicate:
|
|
341
413
|
workSet_1.forEach(function (obj) {
|
|
342
414
|
if (isReference(obj)) {
|
|
343
415
|
found_1[obj.__ref] = true;
|
|
416
|
+
// In rare cases, a { __ref } Reference object may have other fields.
|
|
417
|
+
// This often indicates a mismerging of References with StoreObjects,
|
|
418
|
+
// but garbage collection should not be fooled by a stray __ref
|
|
419
|
+
// property in a StoreObject (ignoring all the other fields just
|
|
420
|
+
// because the StoreObject looks like a Reference). To avoid this
|
|
421
|
+
// premature termination of findChildRefIds recursion, we fall through
|
|
422
|
+
// to the code below, which will handle any other properties of obj.
|
|
344
423
|
}
|
|
345
424
|
if (isNonNullObject(obj)) {
|
|
346
425
|
Object.keys(obj).forEach(function (key) {
|
|
347
426
|
var child = obj[key];
|
|
427
|
+
// No need to add primitive values to the workSet, since they cannot
|
|
428
|
+
// contain reference objects.
|
|
348
429
|
if (isNonNullObject(child)) {
|
|
349
430
|
workSet_1.add(child);
|
|
350
431
|
}
|
|
@@ -360,7 +441,20 @@ var EntityStore = (function () {
|
|
|
360
441
|
return EntityStore;
|
|
361
442
|
}());
|
|
362
443
|
export { EntityStore };
|
|
363
|
-
|
|
444
|
+
// A single CacheGroup represents a set of one or more EntityStore objects,
|
|
445
|
+
// typically the Root store in a CacheGroup by itself, and all active Layer
|
|
446
|
+
// stores in a group together. A single EntityStore object belongs to only
|
|
447
|
+
// one CacheGroup, store.group. The CacheGroup is responsible for tracking
|
|
448
|
+
// dependencies, so store.group is helpful for generating unique keys for
|
|
449
|
+
// cached results that need to be invalidated when/if those dependencies
|
|
450
|
+
// change. If we used the EntityStore objects themselves as cache keys (that
|
|
451
|
+
// is, store rather than store.group), the cache would become unnecessarily
|
|
452
|
+
// fragmented by all the different Layer objects. Instead, the CacheGroup
|
|
453
|
+
// approach allows all optimistic Layer objects in the same linked list to
|
|
454
|
+
// belong to one CacheGroup, with the non-optimistic Root object belonging
|
|
455
|
+
// to another CacheGroup, allowing resultCaching dependencies to be tracked
|
|
456
|
+
// separately for optimistic and non-optimistic entity data.
|
|
457
|
+
var CacheGroup = /** @class */ (function () {
|
|
364
458
|
function CacheGroup(caching, parent) {
|
|
365
459
|
if (parent === void 0) { parent = null; }
|
|
366
460
|
this.caching = caching;
|
|
@@ -377,6 +471,11 @@ var CacheGroup = (function () {
|
|
|
377
471
|
this.d(makeDepKey(dataId, storeFieldName));
|
|
378
472
|
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
379
473
|
if (fieldName !== storeFieldName) {
|
|
474
|
+
// Fields with arguments that contribute extra identifying
|
|
475
|
+
// information to the fieldName (thus forming the storeFieldName)
|
|
476
|
+
// depend not only on the full storeFieldName but also on the
|
|
477
|
+
// short fieldName, so the field can be invalidated using either
|
|
478
|
+
// level of specificity.
|
|
380
479
|
this.d(makeDepKey(dataId, fieldName));
|
|
381
480
|
}
|
|
382
481
|
if (this.parent) {
|
|
@@ -386,21 +485,41 @@ var CacheGroup = (function () {
|
|
|
386
485
|
};
|
|
387
486
|
CacheGroup.prototype.dirty = function (dataId, storeFieldName) {
|
|
388
487
|
if (this.d) {
|
|
389
|
-
this.d.dirty(makeDepKey(dataId, storeFieldName),
|
|
488
|
+
this.d.dirty(makeDepKey(dataId, storeFieldName),
|
|
489
|
+
// When storeFieldName === "__exists", that means the entity identified
|
|
490
|
+
// by dataId has either disappeared from the cache or was newly added,
|
|
491
|
+
// so the result caching system would do well to "forget everything it
|
|
492
|
+
// knows" about that object. To achieve that kind of invalidation, we
|
|
493
|
+
// not only dirty the associated result cache entry, but also remove it
|
|
494
|
+
// completely from the dependency graph. For the optimism implementation
|
|
495
|
+
// details, see https://github.com/benjamn/optimism/pull/195.
|
|
496
|
+
storeFieldName === "__exists" ? "forget" : "setDirty");
|
|
390
497
|
}
|
|
391
498
|
};
|
|
392
499
|
return CacheGroup;
|
|
393
500
|
}());
|
|
394
501
|
function makeDepKey(dataId, storeFieldName) {
|
|
502
|
+
// Since field names cannot have '#' characters in them, this method
|
|
503
|
+
// of joining the field name and the ID should be unambiguous, and much
|
|
504
|
+
// cheaper than JSON.stringify([dataId, fieldName]).
|
|
395
505
|
return storeFieldName + "#" + dataId;
|
|
396
506
|
}
|
|
397
507
|
export function maybeDependOnExistenceOfEntity(store, entityId) {
|
|
398
508
|
if (supportsResultCaching(store)) {
|
|
509
|
+
// We use this pseudo-field __exists elsewhere in the EntityStore code to
|
|
510
|
+
// represent changes in the existence of the entity object identified by
|
|
511
|
+
// entityId. This dependency gets reliably dirtied whenever an object with
|
|
512
|
+
// this ID is deleted (or newly created) within this group, so any result
|
|
513
|
+
// cache entries (for example, StoreReader#executeSelectionSet results) that
|
|
514
|
+
// depend on __exists for this entityId will get dirtied as well, leading to
|
|
515
|
+
// the eventual recomputation (instead of reuse) of those result objects the
|
|
516
|
+
// next time someone reads them from the cache.
|
|
399
517
|
store.group.depend(entityId, "__exists");
|
|
400
518
|
}
|
|
401
519
|
}
|
|
402
520
|
(function (EntityStore) {
|
|
403
|
-
|
|
521
|
+
// Refer to this class as EntityStore.Root outside this namespace.
|
|
522
|
+
var Root = /** @class */ (function (_super) {
|
|
404
523
|
__extends(Root, _super);
|
|
405
524
|
function Root(_a) {
|
|
406
525
|
var policies = _a.policies, _b = _a.resultCaching, resultCaching = _b === void 0 ? true : _b, seed = _a.seed;
|
|
@@ -412,9 +531,13 @@ export function maybeDependOnExistenceOfEntity(store, entityId) {
|
|
|
412
531
|
return _this;
|
|
413
532
|
}
|
|
414
533
|
Root.prototype.addLayer = function (layerId, replay) {
|
|
534
|
+
// Adding an optimistic Layer on top of the Root actually adds the Layer
|
|
535
|
+
// on top of the Stump, so the Stump always comes between the Root and
|
|
536
|
+
// any Layer objects that we've added.
|
|
415
537
|
return this.stump.addLayer(layerId, replay);
|
|
416
538
|
};
|
|
417
539
|
Root.prototype.removeLayer = function () {
|
|
540
|
+
// Never remove the root layer.
|
|
418
541
|
return this;
|
|
419
542
|
};
|
|
420
543
|
Root.prototype.getStorage = function () {
|
|
@@ -424,7 +547,9 @@ export function maybeDependOnExistenceOfEntity(store, entityId) {
|
|
|
424
547
|
}(EntityStore));
|
|
425
548
|
EntityStore.Root = Root;
|
|
426
549
|
})(EntityStore || (EntityStore = {}));
|
|
427
|
-
|
|
550
|
+
// Not exported, since all Layer instances are created by the addLayer method
|
|
551
|
+
// of the EntityStore.Root class.
|
|
552
|
+
var Layer = /** @class */ (function (_super) {
|
|
428
553
|
__extends(Layer, _super);
|
|
429
554
|
function Layer(id, parent, replay, group) {
|
|
430
555
|
var _this = _super.call(this, parent.policies, group) || this;
|
|
@@ -440,22 +565,39 @@ var Layer = (function (_super) {
|
|
|
440
565
|
};
|
|
441
566
|
Layer.prototype.removeLayer = function (layerId) {
|
|
442
567
|
var _this = this;
|
|
568
|
+
// Remove all instances of the given id, not just the first one.
|
|
443
569
|
var parent = this.parent.removeLayer(layerId);
|
|
444
570
|
if (layerId === this.id) {
|
|
445
571
|
if (this.group.caching) {
|
|
572
|
+
// Dirty every ID we're removing. Technically we might be able to avoid
|
|
573
|
+
// dirtying fields that have values in higher layers, but we don't have
|
|
574
|
+
// easy access to higher layers here, and we're about to recreate those
|
|
575
|
+
// layers anyway (see parent.addLayer below).
|
|
446
576
|
Object.keys(this.data).forEach(function (dataId) {
|
|
447
577
|
var ownStoreObject = _this.data[dataId];
|
|
448
578
|
var parentStoreObject = parent["lookup"](dataId);
|
|
449
579
|
if (!parentStoreObject) {
|
|
580
|
+
// The StoreObject identified by dataId was defined in this layer
|
|
581
|
+
// but will be undefined in the parent layer, so we can delete the
|
|
582
|
+
// whole entity using this.delete(dataId). Since we're about to
|
|
583
|
+
// throw this layer away, the only goal of this deletion is to dirty
|
|
584
|
+
// the removed fields.
|
|
450
585
|
_this.delete(dataId);
|
|
451
586
|
}
|
|
452
587
|
else if (!ownStoreObject) {
|
|
588
|
+
// This layer had an entry for dataId but it was undefined, which
|
|
589
|
+
// means the entity was deleted in this layer, and it's about to
|
|
590
|
+
// become undeleted when we remove this layer, so we need to dirty
|
|
591
|
+
// all fields that are about to be reexposed.
|
|
453
592
|
_this.group.dirty(dataId, "__exists");
|
|
454
593
|
Object.keys(parentStoreObject).forEach(function (storeFieldName) {
|
|
455
594
|
_this.group.dirty(dataId, storeFieldName);
|
|
456
595
|
});
|
|
457
596
|
}
|
|
458
597
|
else if (ownStoreObject !== parentStoreObject) {
|
|
598
|
+
// If ownStoreObject is not exactly the same as parentStoreObject,
|
|
599
|
+
// dirty any fields whose values will change as a result of this
|
|
600
|
+
// removal.
|
|
459
601
|
Object.keys(ownStoreObject).forEach(function (storeFieldName) {
|
|
460
602
|
if (!equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
|
|
461
603
|
_this.group.dirty(dataId, storeFieldName);
|
|
@@ -466,8 +608,10 @@ var Layer = (function (_super) {
|
|
|
466
608
|
}
|
|
467
609
|
return parent;
|
|
468
610
|
}
|
|
611
|
+
// No changes are necessary if the parent chain remains identical.
|
|
469
612
|
if (parent === this.parent)
|
|
470
613
|
return this;
|
|
614
|
+
// Recreate this layer on top of the new parent.
|
|
471
615
|
return parent.addLayer(this.id, this.replay);
|
|
472
616
|
};
|
|
473
617
|
Layer.prototype.toObject = function () {
|
|
@@ -475,36 +619,53 @@ var Layer = (function (_super) {
|
|
|
475
619
|
};
|
|
476
620
|
Layer.prototype.findChildRefIds = function (dataId) {
|
|
477
621
|
var fromParent = this.parent.findChildRefIds(dataId);
|
|
478
|
-
return hasOwn.call(this.data, dataId)
|
|
479
|
-
? __assign(__assign({}, fromParent), _super.prototype.findChildRefIds.call(this, dataId)) : fromParent;
|
|
622
|
+
return hasOwn.call(this.data, dataId) ? __assign(__assign({}, fromParent), _super.prototype.findChildRefIds.call(this, dataId)) : fromParent;
|
|
480
623
|
};
|
|
481
624
|
Layer.prototype.getStorage = function () {
|
|
482
625
|
var p = this.parent;
|
|
483
626
|
while (p.parent)
|
|
484
627
|
p = p.parent;
|
|
485
|
-
return p.getStorage.apply(p,
|
|
628
|
+
return p.getStorage.apply(p,
|
|
629
|
+
// @ts-expect-error
|
|
630
|
+
arguments);
|
|
486
631
|
};
|
|
487
632
|
return Layer;
|
|
488
633
|
}(EntityStore));
|
|
489
|
-
|
|
634
|
+
// Represents a Layer permanently installed just above the Root, which allows
|
|
635
|
+
// reading optimistically (and registering optimistic dependencies) even when
|
|
636
|
+
// no optimistic layers are currently active. The stump.group CacheGroup object
|
|
637
|
+
// is shared by any/all Layer objects added on top of the Stump.
|
|
638
|
+
var Stump = /** @class */ (function (_super) {
|
|
490
639
|
__extends(Stump, _super);
|
|
491
640
|
function Stump(root) {
|
|
492
641
|
return _super.call(this, "EntityStore.Stump", root, function () { }, new CacheGroup(root.group.caching, root.group)) || this;
|
|
493
642
|
}
|
|
494
643
|
Stump.prototype.removeLayer = function () {
|
|
644
|
+
// Never remove the Stump layer.
|
|
495
645
|
return this;
|
|
496
646
|
};
|
|
497
|
-
Stump.prototype.merge = function () {
|
|
498
|
-
|
|
647
|
+
Stump.prototype.merge = function (older, newer) {
|
|
648
|
+
// We never want to write any data into the Stump, so we forward any merge
|
|
649
|
+
// calls to the Root instead. Another option here would be to throw an
|
|
650
|
+
// exception, but the toReference(object, true) function can sometimes
|
|
651
|
+
// trigger Stump writes (which used to be Root writes, before the Stump
|
|
652
|
+
// concept was introduced).
|
|
653
|
+
return this.parent.merge(older, newer);
|
|
499
654
|
};
|
|
500
655
|
return Stump;
|
|
501
656
|
}(Layer));
|
|
502
657
|
function storeObjectReconciler(existingObject, incomingObject, property) {
|
|
503
658
|
var existingValue = existingObject[property];
|
|
504
659
|
var incomingValue = incomingObject[property];
|
|
660
|
+
// Wherever there is a key collision, prefer the incoming value, unless
|
|
661
|
+
// it is deeply equal to the existing value. It's worth checking deep
|
|
662
|
+
// equality here (even though blindly returning incoming would be
|
|
663
|
+
// logically correct) because preserving the referential identity of
|
|
664
|
+
// existing data can prevent needless rereading and rerendering.
|
|
505
665
|
return equal(existingValue, incomingValue) ? existingValue : incomingValue;
|
|
506
666
|
}
|
|
507
667
|
export function supportsResultCaching(store) {
|
|
668
|
+
// When result caching is disabled, store.depend will be null.
|
|
508
669
|
return !!(store instanceof EntityStore && store.group.caching);
|
|
509
670
|
}
|
|
510
671
|
//# sourceMappingURL=entityStore.js.map
|