|
2 | 2 | * This file patches pattern conditions to support referencing existing variables.
|
3 | 3 | * This is achieved by wrapping the variable name in a `variable()` call.
|
4 | 4 | */
|
5 |
| -import { mapValues } from '@seedcompany/common'; |
6 | 5 | import { Clause, NodePattern } from 'cypher-query-builder';
|
7 | 6 | import type { Pattern as TSPattern } from 'cypher-query-builder/dist/typings/clauses/pattern';
|
8 | 7 | import type {
|
@@ -37,24 +36,15 @@ export class Variable extends Parameter {
|
37 | 36 | */
|
38 | 37 | export const variable = (expression: string) => new Variable(expression);
|
39 | 38 |
|
| 39 | +const origAddParam = ParameterBag.prototype.addParam; |
40 | 40 | ParameterBag.prototype.addParam = function addParam(
|
41 | 41 | this: TSParameterBag,
|
42 | 42 | value: any | Variable,
|
43 | 43 | name?: string,
|
44 | 44 | ) {
|
45 |
| - const actualName = this.getName(name); |
46 |
| - const param = |
47 |
| - value instanceof Variable |
48 |
| - ? new Variable(value.value, actualName) |
49 |
| - : new Parameter(actualName, value); |
50 |
| - this.parameterMap[actualName] = param; |
51 |
| - return param; |
52 |
| -}; |
53 |
| - |
54 |
| -ParameterBag.prototype.getParams = function getParams(this: TSParameterBag) { |
55 |
| - return mapValues(this.parameterMap, (_, param, { SKIP }) => |
56 |
| - param instanceof Variable ? SKIP : param.value, |
57 |
| - ).asRecord; |
| 45 | + return value instanceof Variable |
| 46 | + ? value |
| 47 | + : origAddParam.call(this, value, name); |
58 | 48 | };
|
59 | 49 |
|
60 | 50 | Pattern.prototype.setExpandedConditions = function (
|
|
0 commit comments