Skip to content

Commit 7451355

Browse files
Update the HTTP-TS driver with analyze endpoint response (#783)
## Usage and product changes Update the HTTP-TS driver with the response structure for the analyze endpoint
1 parent 867032e commit 7451355

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[#_AnalyzeResponse]
2+
=== AnalyzeResponse
3+
4+
[caption=""]
5+
.Fields
6+
// tag::properties[]
7+
[cols=",,"]
8+
[options="header"]
9+
|===
10+
|Name |Type |Description
11+
a| `annotations` a| `FetchAnnotations` a|
12+
a| `structure` a| `FunctionStructure` a|
13+
|===
14+
// end::properties[]
15+

http-ts/docs_structure.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class_nesting_prefixes = [
3636
dir_mapping = {
3737
"TypeDBHttpDriver.adoc": "connection",
3838

39+
"AnalyzeResponse.adoc": "response",
3940
"ApiErrorResponse.adoc": "response",
4041
"Attribute.adoc": "concept",
4142
"ConceptDocumentsQueryResponse.adoc": "response",

http-ts/src/analyze.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 };

http-ts/src/response.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
import { Database, User } from "./index";
2121
import { Concept } from "./concept";
2222
import { QueryStructure } from "./query-structure";
23+
import {
24+
FetchAnnotations,
25+
FunctionAnnotations,
26+
FunctionStructure,
27+
PipelineAnnotations,
28+
PipelineStructure
29+
} from "./analyze";
2330

2431
export interface SignInResponse {
2532
token: string;
@@ -84,6 +91,18 @@ export interface ConceptDocumentsQueryResponse extends QueryResponseBase {
8491

8592
export type QueryResponse = OkQueryResponse | ConceptRowsQueryResponse | ConceptDocumentsQueryResponse;
8693

94+
export interface AnalyzeResponse {
95+
structure: {
96+
preamble: FunctionStructure[],
97+
query: PipelineStructure,
98+
}
99+
annotations: {
100+
preamble: FunctionAnnotations[],
101+
query: PipelineAnnotations,
102+
fetch: FetchAnnotations | null,
103+
}
104+
}
105+
87106
export type ApiOkResponse<OK_RES = {}> = { ok: OK_RES };
88107

89108
export type ApiError = { code: string; message: string };

0 commit comments

Comments
 (0)