import type { InlineFragmentNode, FragmentDefinitionNode, SelectionSetNode, FieldNode } from "graphql"; import type { FragmentMap, StoreValue, StoreObject, Reference } from "../../utilities/index.js"; import { isReference } from "../../utilities/index.js"; import type { IdGetter, MergeInfo, ReadMergeModifyContext } from "./types.js"; import type { InMemoryCache } from "./inMemoryCache.js"; import type { SafeReadonly, FieldSpecifier, ToReferenceFunction, ReadFieldFunction, ReadFieldOptions, CanReadFunction } from "../core/types/common.js"; import type { WriteContext } from "./writeToStore.js"; export type TypePolicies = { [__typename: string]: TypePolicy; }; export type KeySpecifier = ReadonlyArray; export type KeyFieldsContext = { typename: string | undefined; storeObject: StoreObject; readField: ReadFieldFunction; selectionSet?: SelectionSetNode; fragmentMap?: FragmentMap; keyObject?: Record; }; export type KeyFieldsFunction = (object: Readonly, context: KeyFieldsContext) => KeySpecifier | false | ReturnType; export type TypePolicy = { keyFields?: KeySpecifier | KeyFieldsFunction | false; merge?: FieldMergeFunction | boolean; queryType?: true; mutationType?: true; subscriptionType?: true; fields?: { [fieldName: string]: FieldPolicy | FieldReadFunction; }; }; export type KeyArgsFunction = (args: Record | null, context: { typename: string; fieldName: string; field: FieldNode | null; variables?: Record; }) => KeySpecifier | false | ReturnType; export type FieldPolicy = { keyArgs?: KeySpecifier | KeyArgsFunction | false; read?: FieldReadFunction; merge?: FieldMergeFunction | boolean; }; export type StorageType = Record; export interface FieldFunctionOptions, TVars = Record> { args: TArgs | null; fieldName: string; storeFieldName: string; field: FieldNode | null; variables?: TVars; isReference: typeof isReference; toReference: ToReferenceFunction; storage: StorageType; cache: InMemoryCache; readField: ReadFieldFunction; canRead: CanReadFunction; mergeObjects: MergeObjectsFunction; } type MergeObjectsFunction = (existing: T, incoming: T) => T; export type FieldReadFunction = (existing: SafeReadonly | undefined, options: TOptions) => TReadResult | undefined; export type FieldMergeFunction = (existing: SafeReadonly | undefined, incoming: SafeReadonly, options: TOptions) => SafeReadonly; export type PossibleTypesMap = { [supertype: string]: string[]; }; export declare class Policies { private config; private typePolicies; private toBeAdded; private supertypeMap; private fuzzySubtypes; readonly cache: InMemoryCache; readonly rootIdsByTypename: Record; readonly rootTypenamesById: Record; readonly usingPossibleTypes = false; constructor(config: { cache: InMemoryCache; dataIdFromObject?: KeyFieldsFunction; possibleTypes?: PossibleTypesMap; typePolicies?: TypePolicies; }); identify(object: StoreObject, partialContext?: Partial): [string?, StoreObject?]; addTypePolicies(typePolicies: TypePolicies): void; private updateTypePolicy; private setRootTypename; addPossibleTypes(possibleTypes: PossibleTypesMap): void; private getTypePolicy; private getFieldPolicy; private getSupertypeSet; fragmentMatches(fragment: InlineFragmentNode | FragmentDefinitionNode, typename: string | undefined, result?: Record, variables?: Record): boolean; hasKeyArgs(typename: string | undefined, fieldName: string): boolean; getStoreFieldName(fieldSpec: FieldSpecifier): string; readField(options: ReadFieldOptions, context: ReadMergeModifyContext): SafeReadonly | undefined; getReadFunction(typename: string | undefined, fieldName: string): FieldReadFunction | undefined; getMergeFunction(parentTypename: string | undefined, fieldName: string, childTypename: string | undefined): FieldMergeFunction | undefined; runMergeFunction(existing: StoreValue, incoming: StoreValue, { field, typename, merge }: MergeInfo, context: WriteContext, storage?: StorageType): any; } export declare function normalizeReadFieldOptions(readFieldArgs: IArguments, objectOrReference: StoreObject | Reference | undefined, variables?: ReadMergeModifyContext["variables"]): ReadFieldOptions; export {}; //# sourceMappingURL=policies.d.ts.map