import type { Status } from "@/sync/index.js"; import type { UserId, UserRecord, UserTable, UserValue, } from "@/types/schema.js"; import type { Prettify } from "@/types/utils.js"; import type { Hex } from "viem"; export type ReadonlyStore = { findUnique(options: { tableName: string; id: UserId; }): Promise; findMany(options: { tableName: string; where?: WhereInput; orderBy?: OrderByInput; before?: string | null; after?: string | null; limit?: number; }): Promise<{ items: UserRecord[]; pageInfo: { startCursor: string | null; endCursor: string | null; hasNextPage: boolean; hasPreviousPage: boolean; }; }>; }; export type WriteStore< env extends "historical" | "realtime", /// checkpointProp = env extends "realtime" ? { encodedCheckpoint: string } : { encodedCheckpoint?: never }, > = { create( options: { tableName: string; id: UserId; data?: Omit; } & checkpointProp, ): Promise; createMany( options: { tableName: string; data: UserRecord[]; } & checkpointProp, ): Promise; update( options: { tableName: string; id: UserId; data?: | Partial> | ((args: { current: UserRecord }) => Partial>); } & checkpointProp, ): Promise; updateMany( options: { tableName: string; where?: WhereInput; data?: | Partial> | ((args: { current: UserRecord }) => Partial>); } & checkpointProp, ): Promise; upsert( options: { tableName: string; id: UserId; create?: Omit; update?: | Partial> | ((args: { current: UserRecord }) => Partial>); } & checkpointProp, ): Promise; delete( options: { tableName: string; id: UserId; } & checkpointProp, ): Promise; }; export type RealtimeStore = ReadonlyStore & WriteStore<"realtime">; export type HistoricalStore = ReadonlyStore & WriteStore<"historical"> & { flush: (arg: { isFullFlush: boolean }) => Promise; }; export type MetadataStore = { setStatus: (status: Status) => Promise; getStatus: () => Promise; }; export type IndexingStore< env extends "historical" | "realtime" = "historical" | "realtime", > = ReadonlyStore & WriteStore; type OperatorMap = { equals?: column; not?: column; } & (column extends unknown[] ? { has?: column[number]; notHas?: column[number]; } : { in?: column[]; notIn?: column[]; }) & (column extends string ? column extends Hex ? {} : { contains?: column; notContains?: column; startsWith?: column; notStartsWith?: column; endsWith?: column; notEndsWith?: column; } : {}) & (column extends number | bigint | Hex ? { gt?: column; gte?: column; lt?: column; lte?: column; } : {}); export type WhereInput = { [columnName in keyof table]?: | Prettify> | table[columnName]; } & { AND?: Prettify>[]; OR?: Prettify>[]; }; export type OrderByInput = { [ColumnName in columns]?: "asc" | "desc"; };