Skip to content

Commit f34a72b

Browse files
committed
Update CQB exp() to handle path patterns natively
1 parent 2d1dd1a commit f34a72b

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/components/language/language.repository.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
createNode,
3030
createRelationships,
3131
defineSorters,
32-
exp,
3332
filter,
3433
FullTextIndex,
3534
matchChangesetAndChangedProps,
@@ -373,15 +372,11 @@ const isPresetInventory = (query: Query) =>
373372
),
374373
})
375374
.return(
376-
any(
377-
'project',
378-
collect('project'),
379-
exp.path([
380-
node('project'),
381-
relation('out', '', 'presetInventory', ACTIVE),
382-
node('', 'Property', { value: variable('true') }),
383-
]),
384-
).as('presetInventory'),
375+
any('project', collect('project'), [
376+
node('project'),
377+
relation('out', '', 'presetInventory', ACTIVE),
378+
node('', 'Property', { value: variable('true') }),
379+
]).as('presetInventory'),
385380
),
386381
);
387382

src/core/database/query/cypher-expression.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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';
33
import { type Many, ServerException } from '~/common';
44
import { quoteKey } from '../query-augmentation/interpolate';
55

66
export type ExpressionInput =
7-
| Many<string | boolean | number | null | undefined>
7+
| Many<string | boolean | number | Pattern | Nil>
88
| readonly ExpressionInput[]
99
| { [prop: string]: ExpressionInput }
1010
| CypherExpression;
@@ -43,11 +43,11 @@ export const exp = (exp: ExpressionInput): CypherExpression => {
4343
);
4444
};
4545

46-
exp.path = (pattern: Exclude<PatternCollection, any[][]>) => {
46+
const expPath = (pattern: Pattern[]) => {
4747
// Using merge as shortcut to compile path to string.
4848
const clause = new Merge(pattern);
4949
// Slice off the "MERGE " prefix from built clause.
50-
return exp(clause.build().slice(6));
50+
return clause.build().slice(6);
5151
};
5252

5353
export const isExp = (value: unknown): value is CypherExpression =>
@@ -71,7 +71,15 @@ const buildExp = (exp: ExpressionInput): string => {
7171
return exp.toString();
7272
}
7373

74+
if (exp instanceof NodePattern) {
75+
return expPath([exp]);
76+
}
77+
7478
if (isArray(exp)) {
79+
if (exp[0] instanceof NodePattern) {
80+
return expPath(exp as unknown as NodePattern[]);
81+
}
82+
7583
const list = exp.filter((e) => e !== undefined).map(buildExp);
7684
return shouldMultiline(list)
7785
? `[${makeMultiline(list)}]`

0 commit comments

Comments
 (0)