1 | import type { DocumentNode, FieldNode } from "graphql";
|
2 | import type { Reference, StoreObject, StoreValue, isReference, AsStoreObject, DeepPartial } from "../../../utilities/index.js";
|
3 | import type { StorageType } from "../../inmemory/policies.js";
|
4 | export type SafeReadonly<T> = T extends object ? Readonly<T> : T;
|
5 | export type MissingTree = string | {
|
6 | readonly [key: string]: MissingTree;
|
7 | };
|
8 | export 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 | }
|
16 | export interface FieldSpecifier {
|
17 | typename?: string;
|
18 | fieldName: string;
|
19 | field?: FieldNode;
|
20 | args?: Record<string, any>;
|
21 | variables?: Record<string, any>;
|
22 | }
|
23 | export interface ReadFieldOptions extends FieldSpecifier {
|
24 | from?: StoreObject | Reference;
|
25 | }
|
26 | export interface ReadFieldFunction {
|
27 | <V = StoreValue>(options: ReadFieldOptions): SafeReadonly<V> | undefined;
|
28 | <V = StoreValue>(fieldName: string, from?: StoreObject | Reference): SafeReadonly<V> | undefined;
|
29 | }
|
30 | export type ToReferenceFunction = (objOrIdOrRef: StoreObject | string | Reference, mergeIntoStore?: boolean) => Reference | undefined;
|
31 | export type CanReadFunction = (value: StoreValue) => boolean;
|
32 | declare const _deleteModifier: unique symbol;
|
33 | export interface DeleteModifier {
|
34 | [_deleteModifier]: true;
|
35 | }
|
36 | declare const _invalidateModifier: unique symbol;
|
37 | export interface InvalidateModifier {
|
38 | [_invalidateModifier]: true;
|
39 | }
|
40 | declare const _ignoreModifier: unique symbol;
|
41 | export interface IgnoreModifier {
|
42 | [_ignoreModifier]: true;
|
43 | }
|
44 | export 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 | };
|
55 | export type Modifier<T> = (value: T, details: ModifierDetails) => DeepPartial<T> | DeleteModifier | InvalidateModifier | undefined;
|
56 | type 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;
|
59 | export type AllFieldsModifier<Entity extends Record<string, any>> = Modifier<Entity[keyof Entity] extends infer Value ? StoreObjectValueMaybeReference<Exclude<Value, undefined>> : never>;
|
60 | export type Modifiers<T extends Record<string, any> = Record<string, unknown>> = Partial<{
|
61 | [FieldName in keyof T]: Modifier<StoreObjectValueMaybeReference<Exclude<T[FieldName], undefined>>>;
|
62 | }>;
|
63 | export {};
|
64 |
|
\ | No newline at end of file |