declare namespace Type { namespace Topology { namespace Specification { type Definition = { name?: string base?: string[] model?: { [name: string]: Model.Definition } topic?: { [topic: string]: Model.Joint[] } } } namespace Backend { type Definition = MongoBackendDefinition | MemoryArrayBackendDefinition | MemoryMapBackendDefinition | MemorySingleBackendDefinition type MongoBackendDefinition = { name?: string engine: "mongodb" index?: { [key: string]: { unique?: boolean sparse?: boolean } } } type MemoryArrayBackendDefinition = { name?: string engine: "array" index?: string } type MemoryMapBackendDefinition = { name?: string engine: "map" index: string } type MemorySingleBackendDefinition = { name?: string engine: "single" } } namespace Condition { type CriteriaTemplate = CriteriaData & Tagged<"criteriaTemplate"> type Criteria = CriteriaData & Tagged<"criteria"> type CriteriaData = { ors: Matches[] } type Matches = { ands: Match[] } & Tagged<"matches"> type Match = { path: string type: "lte" | "gte" | "lt" | "gt" | "eq" | "reg" | "wildcard" | "in" reference?: string value?: any // Missing value of this condition is acceptable optional?: boolean } & Tagged<"match"> } namespace Permission { type AccessDetail = { // not accessible mask mask?: Model.Joint[] // accessible mask whitelist?: Model.Joint[] // only accessible if sanity check pass sanity?: Condition.Criteria } type AccessControl = boolean | Model.Joint | AccessDetail type Accessibility = { create?: AccessControl delete?: AccessControl read?: AccessControl update?: AccessControl } type Rule = { role?: string from?: Model.Joint via?: Model.Joint[] access?: AccessControl } & Accessibility } namespace Model { type Definition = { // name should be capitalized camelcased name: string backend: Backend.Definition unique?: string[] | string permission?: { [name: string]: Permission.Rule } inits?: T[] } type LinkStep = { topic: string joint: { from: Joint to: Joint } model: { from: Model.Name to: Model.Name } } type Link = { from: Model.Name to: Model.Name signature: string steps: LinkStep[] } type Name = string type Joint = string namespace Topic { type Name = string } type JointInfo = { topics: string[] } type TopicInfo = { name: string joints: Joint[] } } namespace Wrapper { type Container = { data: T name?: string } & Tagged type Part = { data: T name: string } & Tagged<"part"> type Model = { data: T name: string } & Tagged<"model"> type AggregationOutput = { data: T name: string } & Tagged<"AggregationOutput"> } type Infer = { name: string } & Tagged<"infer"> namespace Infer { type Context = { datas: { [name: string]: InferSource } } & Tagged<"inferContext"> type InferSource = { data: { [key: string]: any } } & Tagged<"contextData"> } type Tagged = { tag?: T } namespace Resolution { // (Prev1.src + Prv1.criteriaTemplate) + (Prev2.src + Prev2.criteriaTemplate) => Cur.criteria => Cur.src type Pot = { name: Model.Name | string type: "source" | "model" | "product" | "aggregation" modelName?: Model.Name // to === null => final froms?: string[] tos?: string[] aggregate?: (any) => any } type Pipe = { name: string //@pipe transform?: ((src: TFrom) => TTo) //@model criteriaTemplate?: Condition.CriteriaTemplate to: string from: string } type Restriction = { pipe: { [from_to: string]: { query?: Condition.Criteria } } pot: { [name: string]: { query?: Condition.Criteria option?: QueryOption } } } type Data = { pot: { [name: string]: { srcs?: any[] datas?: any[] aggregations?: any[] products?: any[] query?: Condition.Criteria option?: QueryOption } } pipe: { [name: string]: { pipeQueries?: any[] query?: any datas?: any[] } } } type Execution = { graph: Graph target: string restriction: Restriction data: Data action: ExecutionAction debug?: boolean } type ExecutionAction = CreatesAction | CreateAction | EnsureAction | UpdatesAction | UpdateAction | DeletesAction | SomeAction | OneAction | ExistsAction | NotExistsAction | MapAction | IndexAction | ValidateAction | FilterAction type CreatesAction = { type: "creates" datas: any[] } type CreateAction = { type: "create" data: any } type EnsureAction = { type: "ensure" data: any } type UpdatesAction = { type: "updates" update: any } type UpdateAction = { type: "update" update: any } type DeletesAction = { type: "deletes" } type SomeAction = { type: "some" } type FilterAction = { type: "filter" filter: (data: any) => boolean } type OneAction = { type: "one" } type ExistsAction = { type: "exists" } type NotExistsAction = { type: "notExists" } type MapAction = { type: "map" handler: (data: any, done?: Callback) => any } type IndexAction = { type: "index" key: string } type ValidateAction = { type: "validate" validator: (data: any) => any } type Graph = { name: string inputs: string[] pots: { [name: string]: Pot } pipes: { [from_to: string]: Pipe } } type QueryOption = { offset?: number count?: number sort?: Sort } type Sort = { [key: string]: 1 | -1 } } } }