import type { Schema } from '../schema/Schema' import type { MultiMap } from '../utils/MultiMap' import type { Stream, StreamEvent, StreamDispatcher } from "@andyfischer/streams" import type { StatusTableItem } from '../statustable/StatusTable' import type { DiffItem } from './diff' import type { StreamToTableCallbacks } from './streamToTable' import type { CustomFormatOptions } from './debugFunctions' import { TableIndex } from './TableIndex' import { TableListenPlan, ListenToTableOptions } from './Listeners' export interface Table { schema: Schema // Direct access to data for memory tables indexType?: TableIndexType items?: any attrData?: Map indexes?: Map defaultIndex?: TableIndex insert(item: ItemType): ItemType // Single value functions set(item: ItemType): void get(): ItemType // Common accessors listAll(): ItemType[] itemEquals(item1: ItemType, item2: ItemType): boolean item_to_uniqueKey(item: ItemType): any item_matches_uniqueKey(item: ItemType, uniqueKey: any): boolean deleteItem(item: ItemType): void delete_with_uniqueKey(uniqueKey: any): void supportsFunc(funcName: string): boolean assertSupport(funcName: string): void checkInvariants(): void // Sharing data via listeners listenerStreams: StreamDispatcher listen(options?: ListenToTableOptions): Stream // Importing data from a stream listenToStream(stream: Stream, callbacks?: StreamToTableCallbacks): void receiveUpdate(evt: StreamEvent): void toStream(): Stream // Diff diff(compare: Table): IterableIterator // Status status: Table isLoading(): boolean hasError(): boolean waitForData(): Promise // Debug functions consoleLog(options?: CustomFormatOptions): void // Common functions each(): IterableIterator eachWithFilter(condition: (item:ItemType) => boolean): IterableIterator t: 'table' // Other functions added based on schema.funcs [ funcName: string ]: any /* Generated functions can include: get_with_(attrValue: any): ItemType - Return a single items where attr = attrValue. If there are multiple matches, return the first. list_with_(attrValue: any): ItemType[] - Return an Array of items where attr = attrValue */ } export interface MultiMapIndex { indexType: 'multimap' items: MultiMap } export interface MapIndex { indexType: 'map' items: Map } export interface ListIndex { indexType: 'list' items: Array } export interface SingleValueIndex { indexType: 'single_value' items: any[] } export type TableIndexType = 'map' | 'list' | 'multimap' | 'single_value'