diff --git a/docs/modules/ROOT/partials/http-ts/response/AnalyzeResponse.adoc b/docs/modules/ROOT/partials/http-ts/response/AnalyzeResponse.adoc new file mode 100644 index 0000000000..bd0edb4398 --- /dev/null +++ b/docs/modules/ROOT/partials/http-ts/response/AnalyzeResponse.adoc @@ -0,0 +1,15 @@ +[#_AnalyzeResponse] +=== AnalyzeResponse + +[caption=""] +.Fields +// tag::properties[] +[cols=",,"] +[options="header"] +|=== +|Name |Type |Description +a| `annotations` a| `FetchAnnotations` a| +a| `structure` a| `FunctionStructure` a| +|=== +// end::properties[] + diff --git a/http-ts/docs_structure.bzl b/http-ts/docs_structure.bzl index b22fd083cf..3ac146a052 100644 --- a/http-ts/docs_structure.bzl +++ b/http-ts/docs_structure.bzl @@ -36,6 +36,7 @@ class_nesting_prefixes = [ dir_mapping = { "TypeDBHttpDriver.adoc": "connection", + "AnalyzeResponse.adoc": "response", "ApiErrorResponse.adoc": "response", "Attribute.adoc": "concept", "ConceptDocumentsQueryResponse.adoc": "response", diff --git a/http-ts/src/analyze.ts b/http-ts/src/analyze.ts new file mode 100644 index 0000000000..384d0b2223 --- /dev/null +++ b/http-ts/src/analyze.ts @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {QueryConstraintAny, QueryVariableInfo} from "./query-structure"; +import {Type, ValueType} from "./concept"; + + +type VariableId = string; +export interface PipelineStructure { + conjunctions: QueryConstraintAny[][], + variables: {[name: VariableId]: QueryVariableInfo }, + pipeline: PipelineStage[], + outputs: string[], +} + +type ConjunctionIndex = number; +export type PipelineStage = + { tag: "match", block: ConjunctionIndex } | + { tag: "insert", block: ConjunctionIndex } | + { tag: "delete", block: ConjunctionIndex, deletedVariables: VariableId[] } | + { tag: "put", block: ConjunctionIndex } | + { tag: "update", block: ConjunctionIndex } | + { tag: "select", variables: VariableId[] } | + { tag: "sort", variables: VariableId[] } | + { tag: "require", variables: VariableId } | + { tag: "offset", offset: number } | + { tag: "limit", limit: number } | + { tag: "distinct" } | + { tag: "reduce", reducers: { assigned: VariableId, reducer: Reducer }[] }; + +export interface FunctionStructure { + arguments: VariableId[], + body: PipelineStructure, + returns: FunctionReturnStructure, +} + +export type Reducer = { reducer: string, variable: VariableId[] }; +export type FunctionSingleReturnSelector = "first" | "last" ; +export type FunctionReturnStructure = + { tag: "single", variables: VariableId[], selector: FunctionSingleReturnSelector } | + { tag: "stream", variables: VariableId[] } | + { tag: "check" } | + { tag: "reduce", reducers: Reducer[] } + +export type VariableAnnotations = + { tag: "thing", annotations: Type[] } | + { tag: "type", annotations: Type[] } | + { tag: "value", valueTypes: ValueType[] }; + +export interface PipelineAnnotations { + annotationsByConjunction: { + variableAnnotations: {[name: VariableId]: VariableAnnotations } + }[] +} + +export interface FunctionAnnotations { + arguments: VariableAnnotations[], + returns: { tag: "single" | "stream", annotations: VariableAnnotations[] }, + body: PipelineAnnotations, +} + +export type FetchAnnotations = + { tag: "list", elements: FetchAnnotations } | + { tag : "object", possibleFields: FetchAnnotationFieldEntry[] } | + { tag : "value", valueTypes: ValueType[] }; + +export type FetchAnnotationFieldEntry = FetchAnnotations & { key: string }; diff --git a/http-ts/src/response.ts b/http-ts/src/response.ts index 6b2239001d..87183e7e93 100644 --- a/http-ts/src/response.ts +++ b/http-ts/src/response.ts @@ -20,6 +20,13 @@ import { Database, User } from "./index"; import { Concept } from "./concept"; import { QueryStructure } from "./query-structure"; +import { + FetchAnnotations, + FunctionAnnotations, + FunctionStructure, + PipelineAnnotations, + PipelineStructure +} from "./analyze"; export interface SignInResponse { token: string; @@ -84,6 +91,18 @@ export interface ConceptDocumentsQueryResponse extends QueryResponseBase { export type QueryResponse = OkQueryResponse | ConceptRowsQueryResponse | ConceptDocumentsQueryResponse; +export interface AnalyzeResponse { + structure: { + preamble: FunctionStructure[], + query: PipelineStructure, + } + annotations: { + preamble: FunctionAnnotations[], + query: PipelineAnnotations, + fetch: FetchAnnotations | null, + } +} + export type ApiOkResponse = { ok: OK_RES }; export type ApiError = { code: string; message: string };