1
- import { Merge } from 'cypher-query-builder ' ;
2
- import { type PatternCollection } from 'cypher-query-builder/dist/typings/clauses/pattern-clause ' ;
1
+ import { type Nil } from '@seedcompany/common ' ;
2
+ import { Merge , NodePattern , type Pattern } from 'cypher-query-builder' ;
3
3
import { type Many , ServerException } from '~/common' ;
4
4
import { quoteKey } from '../query-augmentation/interpolate' ;
5
5
6
6
export type ExpressionInput =
7
- | Many < string | boolean | number | null | undefined >
7
+ | Many < string | boolean | number | Pattern | Nil >
8
8
| readonly ExpressionInput [ ]
9
9
| { [ prop : string ] : ExpressionInput }
10
10
| CypherExpression ;
@@ -43,11 +43,11 @@ export const exp = (exp: ExpressionInput): CypherExpression => {
43
43
) ;
44
44
} ;
45
45
46
- exp . path = ( pattern : Exclude < PatternCollection , any [ ] [ ] > ) => {
46
+ const expPath = ( pattern : Pattern [ ] ) => {
47
47
// Using merge as shortcut to compile path to string.
48
48
const clause = new Merge ( pattern ) ;
49
49
// Slice off the "MERGE " prefix from built clause.
50
- return exp ( clause . build ( ) . slice ( 6 ) ) ;
50
+ return clause . build ( ) . slice ( 6 ) ;
51
51
} ;
52
52
53
53
export const isExp = ( value : unknown ) : value is CypherExpression =>
@@ -71,7 +71,15 @@ const buildExp = (exp: ExpressionInput): string => {
71
71
return exp . toString ( ) ;
72
72
}
73
73
74
+ if ( exp instanceof NodePattern ) {
75
+ return expPath ( [ exp ] ) ;
76
+ }
77
+
74
78
if ( isArray ( exp ) ) {
79
+ if ( exp [ 0 ] instanceof NodePattern ) {
80
+ return expPath ( exp as unknown as NodePattern [ ] ) ;
81
+ }
82
+
75
83
const list = exp . filter ( ( e ) => e !== undefined ) . map ( buildExp ) ;
76
84
return shouldMultiline ( list )
77
85
? `[${ makeMultiline ( list ) } ]`
0 commit comments