import { ListIteratee, ListIterator, Many, NotVoid, ObjectIteratee, ObjectIterator } from 'lodash' import { Metadata, Rule } from './mem' import { Model } from './model' import { Struct } from './struct' import { Query } from './query' import { Datum } from './datum' import { List } from './list' import { Set } from './set' type NAVI_LEAF = number export type DATA = Partial[] | { [id: string]: Partial } export type DATUM = Partial export type DIC = { [key: string]: T } export type HASH = { [key in K]: T } export type SET = Set export type LIST = List export type QUERY = Query export type QUERY_WITH_SCOPE = Query & A[2] export type ID = string | number export type PATH = string | (string | number)[] export type LeafEmitter = Emitter export type OrderEmitter = Emitter export type MODEL = Model | Struct export interface MODEL_DATA { idx?: string _id?: string id: string } export type NAVI = { [key: string]: NAVI | NAVI_LEAF } export type DEPLOY = { (this: O, cmd: { o: O; model: CLASS; reduce: LeafEmitter; order: OrderEmitter }): void } export type SCHEMA = { (this: Rule): void } export type SCOPE = { (all: QUERY_WITH_SCOPE): Partial } export type DEFAULT_RULE_TYPE = [MODEL_DATA, DIC, DIC] export type Emitter = { (keys: PATH, cmd: T): void } export type NameBase = { base: string list: string id: string ids: string relations: string[] deploys: DEPLOY[] depends: (() => void)[] } export type Cache = { $format: { [path: string]: ReduceLeaf } $memory: Memory $sort: { [path: string]: OrderCmd } } export type Filter = { (item: any, meta: Metadata): boolean } export type PathCmd = { key: string } export type RelationCmd = Partial<{ key: string target: string miss: string cost: number directed: boolean reverse: boolean }> export type SortIterationCmd = Many< | ListIterator | ListIteratee | ObjectIterator | ObjectIteratee > export type SortCmd = [SortIterationCmd] | [SortIterationCmd, Many] export type OrderCmd = Partial<{ belongs_to: string pluck: string index: string cover: string[] diff: string[] quantile: number mode: boolean page: boolean sort: SortCmd }> export type ReduceOrderPage = ReduceOrder[] & { query: Query from: ReduceLeaf all: number page_idx(this: Reduce[][], item: Object): number | null } export type ReduceOrder = List & Partial<{ query: Query from: ReduceLeaf id: string all: number remain: string[] cover: string[] quantile: ReduceOrder }> export type LeafCmd = Partial<{ id: ID list: boolean navi: string[] set: string | number max: string | number min: string | number count: number all: number pow: number }> export type ReduceLeaf = Partial<{ id: ID list: (Model | Struct)[] hash: { [key: string]: Model | Struct } navi: NAVI set: string[] max_is: any min_is: any max: string | number min: string | number variance_data: number[] variance: number count: number all: number pow: number avg: number sd: number standard(this: ReduceLeaf, data: number): number range: number density: number }> export type Reduce = | { [key: string]: Reduce } | ReduceLeaf export type ReduceDefault = { list: LIST hash: HASH } export interface Memory { [key: string]: Datum } export interface SetContext { model: typeof Model | typeof Struct all: Query base: Cache journal: Cache meta: Metadata deploys: DEPLOY[] from: DATA parent: Object | undefined } export type CLASS = { $name: NameBase bless(data: any, query?: any): asserts data is O new (): O new (rule: any): O } export type QUERY_ARGS = { [path: string]: (string | number)[] | RegExp | string | number | boolean | null }