import type { AnyTable } from '../TableType' ; import type { TableToken } from './table-token' ; export abstract class Token { abstract reduce ( state , numberOfParameters , tables ) ; } export interface State { text : string [ ] ; parameters : any [ ] ; } export const createQueryState = ( tokens , currentParameterIndex = 0 , existingTables ? ) : State => { const initialState = { text : [ ] , parameters : [ ] , } ; const tables = [ ... ( existingTables ?? [ ] ) , ... tokens . filter ( ( token ) => 'getTable' in token ) . map ( ( tableToken ) => ( tableToken as unknown as TableToken ) . getTable ( ) ) , ] ; return tokens . reduce ( ( tokenState , token ) => token . reduce ( tokenState , tokenState . parameters . length + currentParameterIndex , tables ) , initialState ) ; } ;