import { GraphQLField, GraphQLObjectType, GraphQLSchema } from 'graphql'; import { DOCUMENT_CONNECTIONS_SYMBOL, DOCUMENT_KEY_SYMBOL, DOCUMENT_GRAPHQL_TYPENAME } from './constants'; export type DocumentKey = string; export type GraphQLTypeName = string; export type KeyOrDocument = DocumentKey | Document; export type Document = { [k: string]: any; [DOCUMENT_KEY_SYMBOL]: DocumentKey; [DOCUMENT_CONNECTIONS_SYMBOL]: ConnectionsMap; [DOCUMENT_GRAPHQL_TYPENAME]: GraphQLTypeName; __typename: string; }; export type SerializedDocument = { [k: string]: any; __meta__: { DOCUMENT_KEY: DocumentKey; DOCUMENT_CONNECTIONS: ConnectionsMap; DOCUMENT_GRAPHQL_TYPENAME: GraphQLTypeName; }; }; export type DocumentPartial = Partial; type ConnectionFieldName = string; export type ConnectionsMap = Record; type Connections = Array; export type DocumentStore = Record; export type SerializedDocumentStore = Record; export type OperationContext = { store: DocumentStore; schema: GraphQLSchema; eventQueue: Event[]; }; export interface Operation { (context: OperationContext, ...operationArgs: any[]): any; } export interface OperationMap { [key: string]: Operation; } type OmitFirstArg = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never; export type BoundOperationMap = { [P in keyof T]: OmitFirstArg; }; export type AllowedTransactionCallbackReturnTypes = undefined | null | void | Document | (Document | null | undefined)[] | Record; export interface TransactionCallback { (operations: BoundOperationMap): AllowedTransactionCallbackReturnTypes; } export interface FieldValidator { /** * Skip when the field is represented by a connected value on the document */ skipConnectionValue: boolean; /** * Skip when the field is represented by a null or undefined value on the document */ skipNullValue: boolean; validate(parts: { graphqlSchema: GraphQLSchema; type: GraphQLObjectType; field: GraphQLField; document: Document; fieldName: string; fieldValue: any; fieldConnections: Connections | undefined; store: DocumentStore; }): void; } export interface DocumentTypeValidator { validate(parts: { type: GraphQLObjectType; document: Document; graphqlSchema: GraphQLSchema; store: DocumentStore; }): void; } export type PaperEvent = Event & { name: string; store: DocumentStore; [key: string]: any; }; export type PaperDocumentEvent = PaperEvent & { document: Document; }; export interface Hook { (operations: BoundOperationMap): any; } export type HooksMap = { beforeTransaction: Hook[]; afterTransaction: Hook[]; }; export type SerializedPaper = { store: SerializedDocumentStore; __meta__: { NULL_DOCUMENT_KEY: DocumentKey; }; }; export {};