UNPKG

4.5 kBTypeScriptView Raw
1import type { DocumentNode, FieldNode } from "graphql";
2import type { Transaction } from "../core/cache.js";
3import type { StoreObject, StoreValue, Reference } from "../../utilities/index.js";
4import type { FieldValueGetter } from "./entityStore.js";
5import type { TypePolicies, PossibleTypesMap, KeyFieldsFunction, StorageType, FieldMergeFunction } from "./policies.js";
6import type { Modifiers, ToReferenceFunction, CanReadFunction, AllFieldsModifier } from "../core/types/common.js";
7import type { FragmentRegistryAPI } from "./fragmentRegistry.js";
8export type { StoreObject, StoreValue, Reference };
9export interface IdGetterObj extends Object {
10 __typename?: string;
11 id?: string;
12 _id?: string;
13}
14export declare type IdGetter = (value: IdGetterObj) => string | undefined;
15/**
16 * This is an interface used to access, set and remove
17 * StoreObjects from the cache
18 */
19export interface NormalizedCache {
20 has(dataId: string): boolean;
21 get(dataId: string, fieldName: string): StoreValue;
22 merge(olderId: string, newerObject: StoreObject): void;
23 merge(olderObject: StoreObject, newerId: string): void;
24 modify<Entity extends Record<string, any>>(dataId: string, fields: Modifiers<Entity> | AllFieldsModifier<Entity>): boolean;
25 delete(dataId: string, fieldName?: string): boolean;
26 clear(): void;
27 /**
28 * returns an Object with key-value pairs matching the contents of the store
29 */
30 toObject(): NormalizedCacheObject;
31 /**
32 * replace the state of the store
33 */
34 replace(newData: NormalizedCacheObject): void;
35 /**
36 * Retain (or release) a given root ID to protect (or expose) it and its
37 * transitive child entities from (or to) garbage collection. The current
38 * retainment count is returned by both methods. Note that releasing a root
39 * ID does not cause that entity to be garbage collected, but merely removes
40 * it from the set of root IDs that will be considered during the next
41 * mark-and-sweep collection.
42 */
43 retain(rootId: string): number;
44 release(rootId: string): number;
45 getFieldValue: FieldValueGetter;
46 toReference: ToReferenceFunction;
47 canRead: CanReadFunction;
48 getStorage(idOrObj: string | StoreObject, ...storeFieldNames: (string | number)[]): StorageType;
49}
50/**
51 * This is a normalized representation of the Apollo query result cache. It consists of
52 * a flattened representation of query result trees.
53 */
54export interface NormalizedCacheObject {
55 __META?: {
56 extraRootIds: string[];
57 };
58 [dataId: string]: StoreObject | undefined;
59}
60export type OptimisticStoreItem = {
61 id: string;
62 data: NormalizedCacheObject;
63 transaction: Transaction<NormalizedCacheObject>;
64};
65export type ReadQueryOptions = {
66 /**
67 * The Apollo Client store object.
68 */
69 store: NormalizedCache;
70 /**
71 * A parsed GraphQL query document.
72 */
73 query: DocumentNode;
74 variables?: Object;
75 previousResult?: any;
76 /**
77 * @deprecated
78 * Using `canonizeResults` can result in memory leaks so we generally do not
79 * recommend using this option anymore.
80 * A future version of Apollo Client will contain a similar feature without
81 * the risk of memory leaks.
82 */
83 canonizeResults?: boolean;
84 rootId?: string;
85 config?: ApolloReducerConfig;
86};
87export type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
88 returnPartialData?: boolean;
89};
90export type ApolloReducerConfig = {
91 dataIdFromObject?: KeyFieldsFunction;
92 addTypename?: boolean;
93};
94export interface InMemoryCacheConfig extends ApolloReducerConfig {
95 resultCaching?: boolean;
96 possibleTypes?: PossibleTypesMap;
97 typePolicies?: TypePolicies;
98 /**
99 * @deprecated
100 * Please use `cacheSizes` instead.
101 */
102 resultCacheMaxSize?: number;
103 /**
104 * @deprecated
105 * Using `canonizeResults` can result in memory leaks so we generally do not
106 * recommend using this option anymore.
107 * A future version of Apollo Client will contain a similar feature.
108 */
109 canonizeResults?: boolean;
110 fragments?: FragmentRegistryAPI;
111}
112export interface MergeInfo {
113 field: FieldNode;
114 typename: string | undefined;
115 merge: FieldMergeFunction;
116}
117export interface MergeTree {
118 info?: MergeInfo;
119 map: Map<string | number, MergeTree>;
120}
121export interface ReadMergeModifyContext {
122 store: NormalizedCache;
123 variables?: Record<string, any>;
124 varString?: string;
125}
126//# sourceMappingURL=types.d.ts.map
\No newline at end of file