UNPKG

3.05 kBTypeScriptView Raw
1import type { DocumentNode, FieldNode } from "graphql";
2import type { Reference, StoreObject, StoreValue, isReference, AsStoreObject, DeepPartial } from "../../../utilities/index.js";
3import type { StorageType } from "../../inmemory/policies.js";
4export type SafeReadonly<T> = T extends object ? Readonly<T> : T;
5export type MissingTree = string | {
6 readonly [key: string]: MissingTree;
7};
8export declare class MissingFieldError extends Error {
9 readonly message: string;
10 readonly path: MissingTree | Array<string | number>;
11 readonly query: DocumentNode;
12 readonly variables?: Record<string, any> | undefined;
13 constructor(message: string, path: MissingTree | Array<string | number>, query: DocumentNode, variables?: Record<string, any> | undefined);
14 readonly missing: MissingTree;
15}
16export interface FieldSpecifier {
17 typename?: string;
18 fieldName: string;
19 field?: FieldNode;
20 args?: Record<string, any>;
21 variables?: Record<string, any>;
22}
23export interface ReadFieldOptions extends FieldSpecifier {
24 from?: StoreObject | Reference;
25}
26export interface ReadFieldFunction {
27 <V = StoreValue>(options: ReadFieldOptions): SafeReadonly<V> | undefined;
28 <V = StoreValue>(fieldName: string, from?: StoreObject | Reference): SafeReadonly<V> | undefined;
29}
30export type ToReferenceFunction = (objOrIdOrRef: StoreObject | string | Reference, mergeIntoStore?: boolean) => Reference | undefined;
31export type CanReadFunction = (value: StoreValue) => boolean;
32declare const _deleteModifier: unique symbol;
33export interface DeleteModifier {
34 [_deleteModifier]: true;
35}
36declare const _invalidateModifier: unique symbol;
37export interface InvalidateModifier {
38 [_invalidateModifier]: true;
39}
40declare const _ignoreModifier: unique symbol;
41export interface IgnoreModifier {
42 [_ignoreModifier]: true;
43}
44export type ModifierDetails = {
45 DELETE: DeleteModifier;
46 INVALIDATE: InvalidateModifier;
47 fieldName: string;
48 storeFieldName: string;
49 readField: ReadFieldFunction;
50 canRead: CanReadFunction;
51 isReference: typeof isReference;
52 toReference: ToReferenceFunction;
53 storage: StorageType;
54};
55export type Modifier<T> = (value: T, details: ModifierDetails) => DeepPartial<T> | DeleteModifier | InvalidateModifier | undefined;
56type StoreObjectValueMaybeReference<StoreVal> = StoreVal extends Array<Record<string, any>> ? StoreVal extends Array<infer Item> ? [
57 Item
58] extends [Record<string, any>] ? ReadonlyArray<AsStoreObject<Item> | Reference> : never : never : StoreVal extends Record<string, any> ? AsStoreObject<StoreVal> | Reference : StoreVal;
59export type AllFieldsModifier<Entity extends Record<string, any>> = Modifier<Entity[keyof Entity] extends infer Value ? StoreObjectValueMaybeReference<Exclude<Value, undefined>> : never>;
60export type Modifiers<T extends Record<string, any> = Record<string, unknown>> = Partial<{
61 [FieldName in keyof T]: Modifier<StoreObjectValueMaybeReference<Exclude<T[FieldName], undefined>>>;
62}>;
63export {};
64//# sourceMappingURL=common.d.ts.map
\No newline at end of file