import { decimal } from '@lib/shared'; import { Timestamp } from '@lib/use-timestamp'; type Types = string | number | bigint | decimal; export const eq = (value: T) => ({ type: 'eq' as const, value }); export const gt = (value: T) => ({ type: 'gt' as const, value }); export const lt = (value: T) => ({ type: 'lt' as const, value }); export const between = (min: T, max: T) => ({ type: 'between' as const, min, max }); export type QueryObject = Record & { timestamp: Timestamp<'ns'> }; export type QueryObjectType = { discriminator: string; type: { [key in keyof T]: QueryMappingType; }; }; export type QueryWhere = | ReturnType | ReturnType | ReturnType | ReturnType; export type Query = { where?: Partial<{ [key in keyof T]: QueryWhere; }>; orderBy?: 'ASC' | 'DESC'; limit?: number; offset?: number; }; export type QueryMappingType = 'number' | 'bigint' | 'string' | 'decimal'; export type InferQueryObject = T extends QueryObjectType ? { [key in keyof T['type']]: T['type'][key] extends 'number' ? number : T['type'][key] extends 'bigint' ? bigint : T['type'][key] extends 'string' ? string : T['type'][key] extends 'decimal' ? decimal : never; } & { timestamp: Timestamp<'ns'> } : never; export abstract class Storage { static createObject< K extends QueryObject, T extends { [key in keyof K]: QueryMappingType } >(discriminator: string, type: T) { return { discriminator, type }; } abstract index(): Promise>; abstract save, K extends QueryObject>( type: T, objects: InferQueryObject[] ): Promise; abstract query, K extends QueryObject>( type: T, query: Query> ): Promise[]>; }