Initial Sample.

This commit is contained in:
2024-06-03 20:23:50 +05:30
parent ef2b65f673
commit 5269ec3c66
2575 changed files with 282312 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import { WeakCache, StrongCache } from "@wry/caches";
/**
* @internal
* A version of WeakCache that will auto-schedule a cleanup of the cache when
* a new item is added.
* Throttled to once per 100ms.
*
* @privateRemarks
* Should be used throughout the rest of the codebase instead of WeakCache,
* with the notable exception of usage in `wrap` from `optimism` - that one
* already handles cleanup and should remain a `WeakCache`.
*/
export declare const AutoCleanedWeakCache: typeof WeakCache;
/**
* @internal
*/
export type AutoCleanedWeakCache<K extends object, V> = WeakCache<K, V>;
/**
* @internal
* A version of StrongCache that will auto-schedule a cleanup of the cache when
* a new item is added.
* Throttled to once per 100ms.
*
* @privateRemarks
* Should be used throughout the rest of the codebase instead of StrongCache,
* with the notable exception of usage in `wrap` from `optimism` - that one
* already handles cleanup and should remain a `StrongCache`.
*/
export declare const AutoCleanedStrongCache: typeof StrongCache;
/**
* @internal
*/
export type AutoCleanedStrongCache<K, V> = StrongCache<K, V>;
//# sourceMappingURL=caches.d.ts.map

View File

@@ -0,0 +1,64 @@
import { WeakCache, StrongCache } from "@wry/caches";
var scheduledCleanup = new WeakSet();
function schedule(cache) {
if (!scheduledCleanup.has(cache)) {
scheduledCleanup.add(cache);
setTimeout(function () {
cache.clean();
scheduledCleanup.delete(cache);
}, 100);
}
}
/**
* @internal
* A version of WeakCache that will auto-schedule a cleanup of the cache when
* a new item is added.
* Throttled to once per 100ms.
*
* @privateRemarks
* Should be used throughout the rest of the codebase instead of WeakCache,
* with the notable exception of usage in `wrap` from `optimism` - that one
* already handles cleanup and should remain a `WeakCache`.
*/
export var AutoCleanedWeakCache = function (max, dispose) {
/*
Some builds of `WeakCache` are function prototypes, some are classes.
This library still builds with an ES5 target, so we can't extend the
real classes.
Instead, we have to use this workaround until we switch to a newer build
target.
*/
var cache = new WeakCache(max, dispose);
cache.set = function (key, value) {
schedule(this);
return WeakCache.prototype.set.call(this, key, value);
};
return cache;
};
/**
* @internal
* A version of StrongCache that will auto-schedule a cleanup of the cache when
* a new item is added.
* Throttled to once per 100ms.
*
* @privateRemarks
* Should be used throughout the rest of the codebase instead of StrongCache,
* with the notable exception of usage in `wrap` from `optimism` - that one
* already handles cleanup and should remain a `StrongCache`.
*/
export var AutoCleanedStrongCache = function (max, dispose) {
/*
Some builds of `StrongCache` are function prototypes, some are classes.
This library still builds with an ES5 target, so we can't extend the
real classes.
Instead, we have to use this workaround until we switch to a newer build
target.
*/
var cache = new StrongCache(max, dispose);
cache.set = function (key, value) {
schedule(this);
return StrongCache.prototype.set.call(this, key, value);
};
return cache;
};
//# sourceMappingURL=caches.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"caches.js","sourceRoot":"","sources":["../../../src/utilities/caching/caches.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAErD,IAAM,gBAAgB,GAAG,IAAI,OAAO,EAAyB,CAAC;AAC9D,SAAS,QAAQ,CAAC,KAA4B;IAC5C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5B,UAAU,CAAC;YACT,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC;AACH,CAAC;AACD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAClC,GAAwB,EACxB,OAAsD;IAEtD;;;;;;MAME;IACF,IAAM,KAAK,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1C,KAAK,CAAC,GAAG,GAAG,UAAU,GAAQ,EAAE,KAAU;QACxC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAA4B,CAAC;AAM7B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,sBAAsB,GAAG,UACpC,GAAwB,EACxB,OAAsD;IAEtD;;;;;;MAME;IACF,IAAM,KAAK,GAAG,IAAI,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5C,KAAK,CAAC,GAAG,GAAG,UAAU,GAAQ,EAAE,KAAU;QACxC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAA8B,CAAC","sourcesContent":["import type { CommonCache } from \"@wry/caches\";\nimport { WeakCache, StrongCache } from \"@wry/caches\";\n\nconst scheduledCleanup = new WeakSet<CommonCache<any, any>>();\nfunction schedule(cache: CommonCache<any, any>) {\n if (!scheduledCleanup.has(cache)) {\n scheduledCleanup.add(cache);\n setTimeout(() => {\n cache.clean();\n scheduledCleanup.delete(cache);\n }, 100);\n }\n}\n/**\n * @internal\n * A version of WeakCache that will auto-schedule a cleanup of the cache when\n * a new item is added.\n * Throttled to once per 100ms.\n *\n * @privateRemarks\n * Should be used throughout the rest of the codebase instead of WeakCache,\n * with the notable exception of usage in `wrap` from `optimism` - that one\n * already handles cleanup and should remain a `WeakCache`.\n */\nexport const AutoCleanedWeakCache = function (\n max?: number | undefined,\n dispose?: ((value: any, key: any) => void) | undefined\n) {\n /*\n Some builds of `WeakCache` are function prototypes, some are classes.\n This library still builds with an ES5 target, so we can't extend the\n real classes.\n Instead, we have to use this workaround until we switch to a newer build\n target.\n */\n const cache = new WeakCache(max, dispose);\n cache.set = function (key: any, value: any) {\n schedule(this);\n return WeakCache.prototype.set.call(this, key, value);\n };\n return cache;\n} as any as typeof WeakCache;\n/**\n * @internal\n */\nexport type AutoCleanedWeakCache<K extends object, V> = WeakCache<K, V>;\n\n/**\n * @internal\n * A version of StrongCache that will auto-schedule a cleanup of the cache when\n * a new item is added.\n * Throttled to once per 100ms.\n *\n * @privateRemarks\n * Should be used throughout the rest of the codebase instead of StrongCache,\n * with the notable exception of usage in `wrap` from `optimism` - that one\n * already handles cleanup and should remain a `StrongCache`.\n */\nexport const AutoCleanedStrongCache = function (\n max?: number | undefined,\n dispose?: ((value: any, key: any) => void) | undefined\n) {\n /*\n Some builds of `StrongCache` are function prototypes, some are classes.\n This library still builds with an ES5 target, so we can't extend the\n real classes.\n Instead, we have to use this workaround until we switch to a newer build\n target.\n */\n const cache = new StrongCache(max, dispose);\n cache.set = function (key: any, value: any) {\n schedule(this);\n return StrongCache.prototype.set.call(this, key, value);\n };\n return cache;\n} as any as typeof StrongCache;\n/**\n * @internal\n */\nexport type AutoCleanedStrongCache<K, V> = StrongCache<K, V>;\n"]}

View File

@@ -0,0 +1,76 @@
declare const globalCaches: {
print?: () => number;
parser?: () => number;
canonicalStringify?: () => number;
};
export declare function registerGlobalCache(name: keyof typeof globalCaches, getSize: () => number): void;
/**
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
* @internal
*/
export declare const getApolloClientMemoryInternals: (() => {
limits: {
[k: string]: number;
};
sizes: {
cache?: {
fragmentQueryDocuments: number | undefined;
} | undefined;
addTypenameDocumentTransform?: {
cache: number;
}[] | undefined;
inMemoryCache?: {
executeSelectionSet: number | undefined;
executeSubSelectedArray: number | undefined;
maybeBroadcastWatch: number | undefined;
} | undefined;
fragmentRegistry?: {
findFragmentSpreads: number | undefined;
lookup: number | undefined;
transform: number | undefined;
} | undefined;
print: number | undefined;
parser: number | undefined;
canonicalStringify: number | undefined;
links: unknown[];
queryManager: {
getDocumentInfo: number;
documentTransforms: {
cache: number;
}[];
};
};
}) | undefined;
/**
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
* @internal
*/
export declare const getInMemoryCacheMemoryInternals: (() => {
addTypenameDocumentTransform: {
cache: number;
}[];
inMemoryCache: {
executeSelectionSet: number | undefined;
executeSubSelectedArray: number | undefined;
maybeBroadcastWatch: number | undefined;
};
fragmentRegistry: {
findFragmentSpreads: number | undefined;
lookup: number | undefined;
transform: number | undefined;
};
cache: {
fragmentQueryDocuments: number | undefined;
};
}) | undefined;
/**
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
* @internal
*/
export declare const getApolloCacheMemoryInternals: (() => {
cache: {
fragmentQueryDocuments: number | undefined;
};
}) | undefined;
export {};
//# sourceMappingURL=getMemoryInternals.d.ts.map

View File

@@ -0,0 +1,112 @@
import { __assign, __spreadArray } from "tslib";
import { cacheSizes } from "./sizes.js";
var globalCaches = {};
export function registerGlobalCache(name, getSize) {
globalCaches[name] = getSize;
}
/**
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
* @internal
*/
export var getApolloClientMemoryInternals = globalThis.__DEV__ !== false ?
_getApolloClientMemoryInternals
: undefined;
/**
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
* @internal
*/
export var getInMemoryCacheMemoryInternals = globalThis.__DEV__ !== false ?
_getInMemoryCacheMemoryInternals
: undefined;
/**
* For internal purposes only - please call `ApolloClient.getMemoryInternals` instead
* @internal
*/
export var getApolloCacheMemoryInternals = globalThis.__DEV__ !== false ?
_getApolloCacheMemoryInternals
: undefined;
function getCurrentCacheSizes() {
// `defaultCacheSizes` is a `const enum` that will be inlined during build, so we have to reconstruct it's shape here
var defaults = {
parser: 1000 /* defaultCacheSizes["parser"] */,
canonicalStringify: 1000 /* defaultCacheSizes["canonicalStringify"] */,
print: 2000 /* defaultCacheSizes["print"] */,
"documentTransform.cache": 2000 /* defaultCacheSizes["documentTransform.cache"] */,
"queryManager.getDocumentInfo": 2000 /* defaultCacheSizes["queryManager.getDocumentInfo"] */,
"PersistedQueryLink.persistedQueryHashes": 2000 /* defaultCacheSizes["PersistedQueryLink.persistedQueryHashes"] */,
"fragmentRegistry.transform": 2000 /* defaultCacheSizes["fragmentRegistry.transform"] */,
"fragmentRegistry.lookup": 1000 /* defaultCacheSizes["fragmentRegistry.lookup"] */,
"fragmentRegistry.findFragmentSpreads": 4000 /* defaultCacheSizes["fragmentRegistry.findFragmentSpreads"] */,
"cache.fragmentQueryDocuments": 1000 /* defaultCacheSizes["cache.fragmentQueryDocuments"] */,
"removeTypenameFromVariables.getVariableDefinitions": 2000 /* defaultCacheSizes["removeTypenameFromVariables.getVariableDefinitions"] */,
"inMemoryCache.maybeBroadcastWatch": 5000 /* defaultCacheSizes["inMemoryCache.maybeBroadcastWatch"] */,
"inMemoryCache.executeSelectionSet": 50000 /* defaultCacheSizes["inMemoryCache.executeSelectionSet"] */,
"inMemoryCache.executeSubSelectedArray": 10000 /* defaultCacheSizes["inMemoryCache.executeSubSelectedArray"] */,
};
return Object.fromEntries(Object.entries(defaults).map(function (_a) {
var k = _a[0], v = _a[1];
return [
k,
cacheSizes[k] || v,
];
}));
}
function _getApolloClientMemoryInternals() {
var _a, _b, _c, _d, _e;
if (!(globalThis.__DEV__ !== false))
throw new Error("only supported in development mode");
return {
limits: getCurrentCacheSizes(),
sizes: __assign({ print: (_a = globalCaches.print) === null || _a === void 0 ? void 0 : _a.call(globalCaches), parser: (_b = globalCaches.parser) === null || _b === void 0 ? void 0 : _b.call(globalCaches), canonicalStringify: (_c = globalCaches.canonicalStringify) === null || _c === void 0 ? void 0 : _c.call(globalCaches), links: linkInfo(this.link), queryManager: {
getDocumentInfo: this["queryManager"]["transformCache"].size,
documentTransforms: transformInfo(this["queryManager"].documentTransform),
} }, (_e = (_d = this.cache).getMemoryInternals) === null || _e === void 0 ? void 0 : _e.call(_d)),
};
}
function _getApolloCacheMemoryInternals() {
return {
cache: {
fragmentQueryDocuments: getWrapperInformation(this["getFragmentDoc"]),
},
};
}
function _getInMemoryCacheMemoryInternals() {
var fragments = this.config.fragments;
return __assign(__assign({}, _getApolloCacheMemoryInternals.apply(this)), { addTypenameDocumentTransform: transformInfo(this["addTypenameTransform"]), inMemoryCache: {
executeSelectionSet: getWrapperInformation(this["storeReader"]["executeSelectionSet"]),
executeSubSelectedArray: getWrapperInformation(this["storeReader"]["executeSubSelectedArray"]),
maybeBroadcastWatch: getWrapperInformation(this["maybeBroadcastWatch"]),
}, fragmentRegistry: {
findFragmentSpreads: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.findFragmentSpreads),
lookup: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.lookup),
transform: getWrapperInformation(fragments === null || fragments === void 0 ? void 0 : fragments.transform),
} });
}
function isWrapper(f) {
return !!f && "dirtyKey" in f;
}
function getWrapperInformation(f) {
return isWrapper(f) ? f.size : undefined;
}
function isDefined(value) {
return value != null;
}
function transformInfo(transform) {
return recurseTransformInfo(transform).map(function (cache) { return ({ cache: cache }); });
}
function recurseTransformInfo(transform) {
return transform ?
__spreadArray(__spreadArray([
getWrapperInformation(transform === null || transform === void 0 ? void 0 : transform["performWork"])
], recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform["left"]), true), recurseTransformInfo(transform === null || transform === void 0 ? void 0 : transform["right"]), true).filter(isDefined)
: [];
}
function linkInfo(link) {
var _a;
return link ?
__spreadArray(__spreadArray([
(_a = link === null || link === void 0 ? void 0 : link.getMemoryInternals) === null || _a === void 0 ? void 0 : _a.call(link)
], linkInfo(link === null || link === void 0 ? void 0 : link.left), true), linkInfo(link === null || link === void 0 ? void 0 : link.right), true).filter(isDefined)
: [];
}
//# sourceMappingURL=getMemoryInternals.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
export { AutoCleanedStrongCache, AutoCleanedWeakCache } from "./caches.js";
export type { CacheSizes } from "./sizes.js";
export { cacheSizes, defaultCacheSizes } from "./sizes.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,3 @@
export { AutoCleanedStrongCache, AutoCleanedWeakCache } from "./caches.js";
export { cacheSizes } from "./sizes.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utilities/caching/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE3E,OAAO,EAAE,UAAU,EAAqB,MAAM,YAAY,CAAC","sourcesContent":["export { AutoCleanedStrongCache, AutoCleanedWeakCache } from \"./caches.js\";\nexport type { CacheSizes } from \"./sizes.js\";\nexport { cacheSizes, defaultCacheSizes } from \"./sizes.js\";\n"]}

View File

@@ -0,0 +1,311 @@
declare global {
interface Window {
[cacheSizeSymbol]?: Partial<CacheSizes>;
}
}
/**
* The cache sizes used by various Apollo Client caches.
*
* @remarks
* All configurable caches hold memoized values. If an item is
* cache-collected, it incurs only a small performance impact and
* doesn't cause data loss. A smaller cache size might save you memory.
*
* You should choose cache sizes appropriate for storing a reasonable
* number of values rather than every value. To prevent too much recalculation,
* choose cache sizes that are at least large enough to hold memoized values for
* all hooks/queries on the screen at any given time.
*/
export interface CacheSizes {
/**
* Cache size for the [`print`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/graphql/print.ts) function.
*
* It is called with transformed `DocumentNode`s.
*
* @defaultValue
* Defaults to `2000`.
*
* @remarks
* This method is called to transform a GraphQL query AST parsed by `gql`
* back into a GraphQL string.
*
* @privateRemarks
* This method is called from the `QueryManager` and various `ApolloLink`s,
* always with the "serverQuery", so the server-facing part of a transformed
* `DocumentNode`.
*/
print: number;
/**
* Cache size for the [`parser`](https://github.com/apollographql/apollo-client/blob/main/src/react/parser/index.ts) function.
*
* It is called with user-provided `DocumentNode`s.
*
* @defaultValue
* Defaults to `1000`.
*
* @remarks
* This method is called by HOCs and hooks.
*
* @privateRemarks
* This function is used directly in HOCs, and nowadays mainly accessed by
* calling `verifyDocumentType` from various hooks.
* It is called with a user-provided DocumentNode.
*/
parser: number;
/**
* Cache size for the cache of [`DocumentTransform`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/graphql/DocumentTransform.ts)
* instances with the `cache` option set to `true`.
*
* Can be called with user-defined or already-transformed `DocumentNode`s.
*
* @defaultValue
* Defaults to `2000`.
*
* @remarks
* The cache size here should be chosen with other `DocumentTransform`s in mind.
* For example, if there was a `DocumentTransform` that would take `x` `DocumentNode`s,
* and returned a differently-transformed `DocumentNode` depending if the app is
* online or offline, then we assume that the cache returns `2*x` documents.
* If that were concatenated with another `DocumentTransform` that would
* also duplicate the cache size, you'd need to account for `4*x` documents
* returned by the second transform.
*
* Due to an implementation detail of Apollo Client, if you use custom document
* transforms you should always add `n` (the "base" number of user-provided
* Documents) to the resulting cache size.
*
* If we assume that the user-provided transforms receive `n` documents and
* return `n` documents, the cache size should be `2*n`.
*
* If we assume that the chain of user-provided transforms receive `n` documents and
* return `4*n` documents, the cache size should be `5*n`.
*
* This size should also then be used in every other cache that mentions that
* it operates on a "transformed" `DocumentNode`.
*
* @privateRemarks
* Cache size for the `performWork` method of each [`DocumentTransform`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/graphql/DocumentTransform.ts).
*
* No user-provided DocumentNode will actually be "the last one", as we run the
* `defaultDocumentTransform` before *and* after the user-provided transforms.
* For that reason, we need the extra `n` here - `n` for "before transformation"
* plus the actual maximum cache size of the user-provided transform chain.
*
* This method is called from `transformDocument`, which is called from
* `QueryManager` with a user-provided DocumentNode.
* It is also called with already-transformed DocumentNodes, assuming the
* user provided additional transforms.
*
*/
"documentTransform.cache": number;
/**
* A cache inside of [`QueryManager`](https://github.com/apollographql/apollo-client/blob/main/src/core/QueryManager.ts).
*
* It is called with transformed `DocumentNode`s.
*
* @defaultValue
* Defaults to `2000`.
*
* @privateRemarks
* Cache size for the `transformCache` used in the `getDocumentInfo` method of `QueryManager`.
* Called throughout the `QueryManager` with transformed DocumentNodes.
*/
"queryManager.getDocumentInfo": number;
/**
* A cache inside of [`PersistedQueryLink`](https://github.com/apollographql/apollo-client/blob/main/src/link/persisted-queries/index.ts).
*
* It is called with transformed `DocumentNode`s.
*
* @defaultValue
* Defaults to `2000`.
*
* @remarks
* This cache is used to cache the hashes of persisted queries.
*
* @privateRemarks
* Cache size for the `hashesByQuery` cache in the `PersistedQueryLink`.
*/
"PersistedQueryLink.persistedQueryHashes": number;
/**
* Cache used by [`canonicalStringify`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/common/canonicalStringify.ts).
*
* @defaultValue
* Defaults to `1000`.
*
* @remarks
* This cache contains the sorted keys of objects that are stringified by
* `canonicalStringify`.
* It uses the stringified unsorted keys of objects as keys.
* The cache will not grow beyond the size of different object **shapes**
* encountered in an application, no matter how much actual data gets stringified.
*
* @privateRemarks
* Cache size for the `sortingMap` in `canonicalStringify`.
*/
canonicalStringify: number;
/**
* A cache inside of [`FragmentRegistry`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/fragmentRegistry.ts).
*
* Can be called with user-defined or already-transformed `DocumentNode`s.
*
* @defaultValue
* Defaults to `2000`.
*
* @privateRemarks
*
* Cache size for the `transform` method of FragmentRegistry.
* This function is called as part of the `defaultDocumentTransform` which will be called with
* user-provided and already-transformed DocumentNodes.
*
*/
"fragmentRegistry.transform": number;
/**
* A cache inside of [`FragmentRegistry`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/fragmentRegistry.ts).
*
* This function is called with fragment names in the form of a string.
*
* @defaultValue
* Defaults to `1000`.
*
* @remarks
* The size of this case should be chosen with the number of fragments in
* your application in mind.
*
* Note:
* This function is a dependency of `fragmentRegistry.transform`, so having too small of a cache size here
* might involuntarily invalidate values in the `transform` cache.
*
* @privateRemarks
* Cache size for the `lookup` method of FragmentRegistry.
*/
"fragmentRegistry.lookup": number;
/**
* Cache size for the `findFragmentSpreads` method of [`FragmentRegistry`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/fragmentRegistry.ts).
*
* This function is called with transformed `DocumentNode`s, as well as recursively
* with every fragment spread referenced within that, or a fragment referenced by a
* fragment spread.
*
* @defaultValue
* Defaults to `4000`.
*
* @remarks
*
* Note: This function is a dependency of `fragmentRegistry.transform`, so having too small of cache size here
* might involuntarily invalidate values in the `transform` cache.
*/
"fragmentRegistry.findFragmentSpreads": number;
/**
* Cache size for the `getFragmentDoc` method of [`ApolloCache`](https://github.com/apollographql/apollo-client/blob/main/src/cache/core/cache.ts).
*
* This function is called with user-provided fragment definitions.
*
* @defaultValue
* Defaults to `1000`.
*
* @remarks
* This function is called from `readFragment` with user-provided fragment definitions.
*/
"cache.fragmentQueryDocuments": number;
/**
* Cache used in [`removeTypenameFromVariables`](https://github.com/apollographql/apollo-client/blob/main/src/link/remove-typename/removeTypenameFromVariables.ts).
*
* This function is called transformed `DocumentNode`s.
*
* @defaultValue
* Defaults to `2000`.
*
* @privateRemarks
* Cache size for the `getVariableDefinitions` function of `removeTypenameFromVariables`.
*/
"removeTypenameFromVariables.getVariableDefinitions": number;
/**
* Cache size for the `maybeBroadcastWatch` method on [`InMemoryCache`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/inMemoryCache.ts).
*
* Note: `maybeBroadcastWatch` will be set to the `resultCacheMaxSize` option and
* will fall back to this configuration value if the option is not set.
*
* @defaultValue
* Defaults to `5000`.
*
* @remarks
* This method is used for dependency tracking in the `InMemoryCache` and
* prevents from unnecessary re-renders.
* It is recommended to keep this value significantly higher than the number of
* possible subscribers you will have active at the same time in your application
* at any time.
*/
"inMemoryCache.maybeBroadcastWatch": number;
/**
* Cache size for the `executeSelectionSet` method on [`StoreReader`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/readFromStore.ts).
*
* Note:
* `executeSelectionSet` will be set to the `resultCacheMaxSize` option and
* will fall back to this configuration value if the option is not set.
*
* @defaultValue
* Defaults to `10000`.
*
* @remarks
* Every object that is read from the cache will be cached here, so it is
* recommended to set this to a high value.
*/
"inMemoryCache.executeSelectionSet": number;
/**
* Cache size for the `executeSubSelectedArray` method on [`StoreReader`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/readFromStore.ts).
*
* Note:
* `executeSubSelectedArray` will be set to the `resultCacheMaxSize` option and
* will fall back to this configuration value if the option is not set.
*
* @defaultValue
* Defaults to `5000`.
*
* @remarks
* Every array that is read from the cache will be cached here, so it is
* recommended to set this to a high value.
*/
"inMemoryCache.executeSubSelectedArray": number;
}
declare const cacheSizeSymbol: unique symbol;
/**
*
* The global cache size configuration for Apollo Client.
*
* @remarks
*
* You can directly modify this object, but any modification will
* only have an effect on caches that are created after the modification.
*
* So for global caches, such as `parser`, `canonicalStringify` and `print`,
* you might need to call `.reset` on them, which will essentially re-create them.
*
* Alternatively, you can set `globalThis[Symbol.for("apollo.cacheSize")]` before
* you load the Apollo Client package:
*
* @example
* ```ts
* globalThis[Symbol.for("apollo.cacheSize")] = {
* parser: 100
* } satisfies Partial<CacheSizes> // the `satisfies` is optional if using TypeScript
* ```
*/
export declare const cacheSizes: Partial<CacheSizes>;
export declare const enum defaultCacheSizes {
parser = 1000,
canonicalStringify = 1000,
print = 2000,
"documentTransform.cache" = 2000,
"queryManager.getDocumentInfo" = 2000,
"PersistedQueryLink.persistedQueryHashes" = 2000,
"fragmentRegistry.transform" = 2000,
"fragmentRegistry.lookup" = 1000,
"fragmentRegistry.findFragmentSpreads" = 4000,
"cache.fragmentQueryDocuments" = 1000,
"removeTypenameFromVariables.getVariableDefinitions" = 2000,
"inMemoryCache.maybeBroadcastWatch" = 5000,
"inMemoryCache.executeSelectionSet" = 50000,
"inMemoryCache.executeSubSelectedArray" = 10000
}
export {};
//# sourceMappingURL=sizes.d.ts.map

View File

@@ -0,0 +1,27 @@
import { __assign } from "tslib";
import { global } from "../globals/index.js";
var cacheSizeSymbol = Symbol.for("apollo.cacheSize");
/**
*
* The global cache size configuration for Apollo Client.
*
* @remarks
*
* You can directly modify this object, but any modification will
* only have an effect on caches that are created after the modification.
*
* So for global caches, such as `parser`, `canonicalStringify` and `print`,
* you might need to call `.reset` on them, which will essentially re-create them.
*
* Alternatively, you can set `globalThis[Symbol.for("apollo.cacheSize")]` before
* you load the Apollo Client package:
*
* @example
* ```ts
* globalThis[Symbol.for("apollo.cacheSize")] = {
* parser: 100
* } satisfies Partial<CacheSizes> // the `satisfies` is optional if using TypeScript
* ```
*/
export var cacheSizes = __assign({}, global[cacheSizeSymbol]);
//# sourceMappingURL=sizes.js.map

File diff suppressed because one or more lines are too long