1- import { getVariableName , QueryConstraintAny , QueryStructure , QueryVertex } from "typedb- driver-http" ;
1+ import { getVariableName , ConstraintVertexAny } from "@ typedb/ driver-http" ;
22import {
33 EdgeAttributes ,
44 EdgeMetadata ,
@@ -21,13 +21,18 @@ import {
2121} from "./graph" ;
2222import { ILogicalGraphConverter } from "./visualisation" ;
2323import { StudioConverterStructureParameters , StudioConverterStyleParameters } from "./config" ;
24+ import {
25+ AnalyzedPipelineBackwardsCompatible ,
26+ backwardCompatible_expressionAssigned ,
27+ ConstraintBackwardsCompatible
28+ } from "./index" ;
2429
25- type QueryVertexOrSpecial = QueryVertex | VertexFunction | VertexExpression ;
30+ type ConstraintVertexOrSpecial = ConstraintVertexAny | VertexFunction | VertexExpression ;
2631
2732export class StudioConverter implements ILogicalGraphConverter {
2833
2934 constructor (
30- public readonly graph : VisualGraph , public readonly queryStructure : QueryStructure ,
35+ public readonly graph : VisualGraph , public readonly queryStructure : AnalyzedPipelineBackwardsCompatible ,
3136 public readonly isFollowupQuery : boolean , public readonly structureParameters : StudioConverterStructureParameters ,
3237 public readonly styleParameters : StudioConverterStyleParameters
3338 ) {
@@ -81,11 +86,11 @@ export class StudioConverter implements ILogicalGraphConverter {
8186 return `${ from_id } :${ to_id } :${ edge_type_id } ` ;
8287 }
8388
84- private shouldCreateNode ( queryVertex : QueryVertexOrSpecial ) {
89+ private shouldCreateNode ( queryVertex : ConstraintVertexOrSpecial ) {
8590 return shouldCreateNode ( this . queryStructure , queryVertex ) ;
8691 }
8792
88- private shouldCreateEdge ( edge : DataConstraintAny , from : QueryVertexOrSpecial , to : QueryVertexOrSpecial ) {
93+ private shouldCreateEdge ( edge : DataConstraintAny , from : ConstraintVertexOrSpecial , to : ConstraintVertexOrSpecial ) {
8994 return shouldCreateEdge ( this . queryStructure , edge . queryConstraint , from , to ) ;
9095 }
9196
@@ -105,7 +110,7 @@ export class StudioConverter implements ILogicalGraphConverter {
105110 }
106111 }
107112
108- private maybeCreateEdge ( answerIndex : number , edge : DataConstraintAny , label : string , from : DataVertex , to : DataVertex , queryFrom : QueryVertexOrSpecial , queryTo : QueryVertexOrSpecial ) {
113+ private maybeCreateEdge ( answerIndex : number , edge : DataConstraintAny , label : string , from : DataVertex , to : DataVertex , queryFrom : ConstraintVertexOrSpecial , queryTo : ConstraintVertexOrSpecial ) {
109114 if ( this . shouldCreateEdge ( edge , queryFrom , queryTo ) ) {
110115 let fromKey = this . put_vertex ( answerIndex , from , queryFrom ) ;
111116 let toKey = this . put_vertex ( answerIndex , to , queryTo ) ;
@@ -124,7 +129,7 @@ export class StudioConverter implements ILogicalGraphConverter {
124129
125130 // ILogicalGraphConverter
126131 // Vertices
127- put_vertex ( answerIndex : number , vertex : DataVertex , queryVertex : QueryVertexOrSpecial ) : string {
132+ put_vertex ( answerIndex : number , vertex : DataVertex , queryVertex : ConstraintVertexOrSpecial ) : string {
128133 const key = vertexMapKey ( vertex ) ;
129134 if ( this . shouldCreateNode ( queryVertex ) ) {
130135 this . createVertex ( key , this . vertexAttributes ( vertex ) )
@@ -207,13 +212,11 @@ export class StudioConverter implements ILogicalGraphConverter {
207212 repr : constraint . text ,
208213 vertex_map_key : expressionVertexKey
209214 }
210- expression . assigned
211- . forEach ( ( assigned , i ) => {
212- let queryVertex = constraint . queryConstraint . assigned [ i ] ;
213- let varNameOrId = getVariableName ( this . queryStructure , queryVertex ) ?? `$_${ queryVertex . id } ` ;
214- let label = `assign[${ varNameOrId } ]` ;
215- this . maybeCreateEdge ( answerIndex , constraint , label , expressionVertex , assigned , expressionVertex , queryVertex ) ;
216- } ) ;
215+
216+ let queryVertex = backwardCompatible_expressionAssigned ( constraint . queryConstraint ) ;
217+ let varNameOrId = getVariableName ( this . queryStructure , queryVertex ) ?? `$_${ queryVertex . id } ` ;
218+ let label = `assign[${ varNameOrId } ]` ;
219+ this . maybeCreateEdge ( answerIndex , constraint , label , expressionVertex , expression . assigned , expressionVertex , queryVertex ) ;
217220 expression . arguments
218221 . forEach ( ( arg , i ) => {
219222 let queryVertex = constraint . queryConstraint . arguments [ i ] ;
@@ -253,15 +256,15 @@ export class StudioConverter implements ILogicalGraphConverter {
253256 }
254257}
255258
256- export function shouldCreateNode ( structure : QueryStructure , vertex : QueryVertexOrSpecial ) {
259+ export function shouldCreateNode ( structure : AnalyzedPipelineBackwardsCompatible , vertex : ConstraintVertexOrSpecial ) {
257260 return ! (
258261 ( vertex . tag === "label" ||
259262 ( vertex . tag == "variable" && ! structure . outputs . includes ( vertex . id ) )
260263 )
261264 ) ;
262265}
263266
264- export function shouldCreateEdge ( structure : QueryStructure , _edge : QueryConstraintAny , from : QueryVertexOrSpecial , to : QueryVertexOrSpecial ) {
267+ export function shouldCreateEdge ( structure : AnalyzedPipelineBackwardsCompatible , _edge : ConstraintBackwardsCompatible , from : ConstraintVertexOrSpecial , to : ConstraintVertexOrSpecial ) {
265268 return shouldCreateNode ( structure , from ) && shouldCreateNode ( structure , to ) ;
266269}
267270
@@ -297,6 +300,6 @@ function functionVertexKeyFromArgsAndAssigned(constraint: DataConstraintFunction
297300
298301function expressionVertexKeyFromArgsAndAssigned ( constraint : DataConstraintExpression ) : string {
299302 let args = constraint . arguments . map ( v => vertexMapKey ( v ) ) . join ( "," ) ;
300- let assigned = constraint . assigned . map ( v => vertexMapKey ( v ) ) . join ( "," ) ;
303+ let assigned = constraint . assigned ;
301304 return `${ constraint . text } (${ args } ) -> ${ assigned } ` ;
302305}
0 commit comments