|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import {QueryConstraintAny, QueryVariableInfo} from "./query-structure"; |
| 21 | +import {Type, ValueType} from "./concept"; |
| 22 | + |
| 23 | + |
| 24 | +type VariableId = string; |
| 25 | +export interface PipelineStructure { |
| 26 | + conjunctions: QueryConstraintAny[][], |
| 27 | + variables: {[name: VariableId]: QueryVariableInfo }, |
| 28 | + pipeline: PipelineStage[], |
| 29 | + outputs: string[], |
| 30 | +} |
| 31 | + |
| 32 | +type ConjunctionIndex = number; |
| 33 | +export type PipelineStage = |
| 34 | + { tag: "match", block: ConjunctionIndex } | |
| 35 | + { tag: "insert", block: ConjunctionIndex } | |
| 36 | + { tag: "delete", block: ConjunctionIndex, deletedVariables: VariableId[] } | |
| 37 | + { tag: "put", block: ConjunctionIndex } | |
| 38 | + { tag: "update", block: ConjunctionIndex } | |
| 39 | + { tag: "select", variables: VariableId[] } | |
| 40 | + { tag: "sort", variables: VariableId[] } | |
| 41 | + { tag: "require", variables: VariableId } | |
| 42 | + { tag: "offset", offset: number } | |
| 43 | + { tag: "limit", limit: number } | |
| 44 | + { tag: "distinct" } | |
| 45 | + { tag: "reduce", reducers: { assigned: VariableId, reducer: Reducer }[] }; |
| 46 | + |
| 47 | +export interface FunctionStructure { |
| 48 | + arguments: VariableId[], |
| 49 | + body: PipelineStructure, |
| 50 | + returns: FunctionReturnStructure, |
| 51 | +} |
| 52 | + |
| 53 | +export type Reducer = { reducer: string, variable: VariableId[] }; |
| 54 | +export type FunctionSingleReturnSelector = "first" | "last" ; |
| 55 | +export type FunctionReturnStructure = |
| 56 | + { tag: "single", variables: VariableId[], selector: FunctionSingleReturnSelector } | |
| 57 | + { tag: "stream", variables: VariableId[] } | |
| 58 | + { tag: "check" } | |
| 59 | + { tag: "reduce", reducers: Reducer[] } |
| 60 | + |
| 61 | +export type VariableAnnotations = |
| 62 | + { tag: "thing", annotations: Type[] } | |
| 63 | + { tag: "type", annotations: Type[] } | |
| 64 | + { tag: "value", valueTypes: ValueType[] }; |
| 65 | + |
| 66 | +export interface PipelineAnnotations { |
| 67 | + annotationsByConjunction: { |
| 68 | + variableAnnotations: {[name: VariableId]: VariableAnnotations } |
| 69 | + }[] |
| 70 | +} |
| 71 | + |
| 72 | +export interface FunctionAnnotations { |
| 73 | + arguments: VariableAnnotations[], |
| 74 | + returns: { tag: "single" | "stream", annotations: VariableAnnotations[] }, |
| 75 | + body: PipelineAnnotations, |
| 76 | +} |
| 77 | + |
| 78 | +export type FetchAnnotations = |
| 79 | + { tag: "list", elements: FetchAnnotations } | |
| 80 | + { tag : "object", possibleFields: FetchAnnotationFieldEntry[] } | |
| 81 | + { tag : "value", valueTypes: ValueType[] }; |
| 82 | + |
| 83 | +export type FetchAnnotationFieldEntry = FetchAnnotations & { key: string }; |
0 commit comments