import type * as graphql from "graphql"; import type { Collections, CollectionName, CollectionProperty, MutableCollectionName, Resource, MutationPayload } from "../collections"; export type Definitions = { [N in CollectionName]: Definition; }; export type Definition> = N extends MutableCollectionName ? { mutable: true; } : { mutable?: false; }; type Data = string extends N ? Partial : N extends keyof O ? Partial> : never; type MethodName = string; export interface GraphQlRequestType | MutationName | string = string> { graphql: N; } export interface Web3RequestType<_C extends Collections, N extends MethodName | string = string> { web3: N | string; } export type RequestType = GraphQlRequestType | Web3RequestType; export type RequestData> = R extends { graphql: infer N; } ? N extends string ? string extends N ? Data & Mutation, N> : Data, N> | Data, N> : never : any; export interface GraphQlRequest { type: "graphql"; request: string | graphql.DocumentNode; variables: { [name: string]: any; }; } export interface Web3Request { type: "web3"; method: string; params: any[]; } export type ProcessRequest | undefined> = "graphql" extends keyof R ? GraphQlRequest : "web3" extends keyof R ? Web3Request : GraphQlRequest | Web3Request; export type ProcessResponse> = R extends { graphql: string; } ? { data: RequestData; } : { id: number; jsonrpc: "2.0"; result: RequestData; }; export type Process | undefined = undefined> = R extends RequestType ? Generator, T, ProcessResponse> : Generator, T, any>; export type Processor | undefined = undefined> = (...args: A) => Process; export type QueryName = CollectionName> = { [K in N]: CollectionProperty<"names", C, K>["resource"] | CollectionProperty<"names", C, K>["resources"]; }[N]; type UnionToIntersection = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never; type CollectionQuery = CollectionName> = UnionToIntersection<{ [K in N]: { [Q in QueryName]: Q extends CollectionProperty<"names", C, K>["resource"] ? Resource | null : Q extends CollectionProperty<"names", C, K>["resources"] ? Resource[] : never; }; }[N]>; export type Query = QueryName> = { [K in Q]: K extends keyof CollectionQuery ? CollectionQuery[K] : never; }; export type MutationName = CollectionName> = { [K in N]: CollectionProperty<"names", C, K>["resourcesMutate"]; }[N]; type CollectionMutation = CollectionName> = UnionToIntersection<{ [K in N]: { [M in MutationName]: MutationPayload; }; }[N]>; export type Mutation = MutationName> = { [K in M]: K extends keyof CollectionMutation ? CollectionMutation[K] : never; }; export {};