@neo4j/cypher-builder
Advanced tools
Comparing version 1.10.3 to 1.11.0
@@ -20,8 +20,15 @@ import type { CypherEnvironment } from "../Environment"; | ||
export declare class Call extends Clause { | ||
private subQuery; | ||
private importWith; | ||
constructor(subQuery: Clause); | ||
private subquery; | ||
private _importWith; | ||
private _usingImportWith; | ||
constructor(subquery: Clause); | ||
/** Adds a `WITH` statement inside `CALL {`, this `WITH` can is used to import variables outside of the subquery | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/subqueries/call-subquery/#call-importing-variables) | ||
*/ | ||
importWith(...params: Array<Variable | "*">): this; | ||
/** @deprecated Use {@link importWith} instead */ | ||
innerWith(...params: Array<Variable | "*">): this; | ||
/** @internal */ | ||
getCypher(env: CypherEnvironment): string; | ||
private getSubqueryCypher; | ||
} |
@@ -31,2 +31,3 @@ "use strict"; | ||
const Clause_1 = require("./Clause"); | ||
const Union_1 = require("./Union"); | ||
const WithCreate_1 = require("./mixins/clauses/WithCreate"); | ||
@@ -42,2 +43,3 @@ const WithMatch_1 = require("./mixins/clauses/WithMatch"); | ||
const ImportWith_1 = require("./sub-clauses/ImportWith"); | ||
const concat_1 = require("./utils/concat"); | ||
const mixin_1 = require("./utils/mixin"); | ||
@@ -49,14 +51,31 @@ /** | ||
let Call = class Call extends Clause_1.Clause { | ||
constructor(subQuery) { | ||
constructor(subquery) { | ||
super(); | ||
const rootQuery = subQuery.getRoot(); | ||
// This is to preserve compatibility with innerWith and avoid breaking changes | ||
// Remove on 2.0.0 | ||
this._usingImportWith = false; | ||
const rootQuery = subquery.getRoot(); | ||
this.addChildren(rootQuery); | ||
this.subQuery = rootQuery; | ||
this.subquery = rootQuery; | ||
} | ||
/** Adds a `WITH` statement inside `CALL {`, this `WITH` can is used to import variables outside of the subquery | ||
* @see [Cypher Documentation](https://neo4j.com/docs/cypher-manual/current/subqueries/call-subquery/#call-importing-variables) | ||
*/ | ||
importWith(...params) { | ||
if (this._importWith) | ||
throw new Error("Call import already set"); | ||
if (params.length > 0) { | ||
this._importWith = new ImportWith_1.ImportWith(this, [...params]); | ||
this.addChildren(this._importWith); | ||
this._usingImportWith = true; | ||
} | ||
return this; | ||
} | ||
/** @deprecated Use {@link importWith} instead */ | ||
innerWith(...params) { | ||
if (this.importWith) | ||
if (this._importWith) | ||
throw new Error("Call import already set"); | ||
if (params.length > 0) { | ||
this.importWith = new ImportWith_1.ImportWith(this, [...params]); | ||
this.addChildren(this.importWith); | ||
this._importWith = new ImportWith_1.ImportWith(this, [...params]); | ||
this.addChildren(this._importWith); | ||
} | ||
@@ -67,11 +86,19 @@ return this; | ||
getCypher(env) { | ||
const subQueryStr = this.subQuery.getCypher(env); | ||
const innerWithCypher = (0, compile_cypher_if_exists_1.compileCypherIfExists)(this.importWith, env, { suffix: "\n" }); | ||
const importWithCypher = (0, compile_cypher_if_exists_1.compileCypherIfExists)(this._importWith, env, { suffix: "\n" }); | ||
const subQueryStr = this.getSubqueryCypher(env, importWithCypher); | ||
const removeCypher = (0, compile_cypher_if_exists_1.compileCypherIfExists)(this.removeClause, env, { prefix: "\n" }); | ||
const deleteCypher = (0, compile_cypher_if_exists_1.compileCypherIfExists)(this.deleteClause, env, { prefix: "\n" }); | ||
const setCypher = (0, compile_cypher_if_exists_1.compileCypherIfExists)(this.setSubClause, env, { prefix: "\n" }); | ||
const inCallBlock = `${innerWithCypher}${subQueryStr}`; | ||
const inCallBlock = `${importWithCypher}${subQueryStr}`; | ||
const nextClause = this.compileNextClause(env); | ||
return `CALL {\n${(0, pad_block_1.padBlock)(inCallBlock)}\n}${setCypher}${removeCypher}${deleteCypher}${nextClause}`; | ||
} | ||
getSubqueryCypher(env, importWithCypher) { | ||
// This ensures the import with is added to all the union subqueries | ||
if (this._usingImportWith && (this.subquery instanceof Union_1.Union || this.subquery instanceof concat_1.CompositeClause)) { | ||
//TODO: try to embed the importWithCypher in the environment for a more generic solution | ||
return this.subquery.getCypher(env, importWithCypher); | ||
} | ||
return this.subquery.getCypher(env); | ||
} | ||
}; | ||
@@ -78,0 +105,0 @@ exports.Call = Call; |
@@ -12,4 +12,7 @@ import type { CypherEnvironment } from "../Environment"; | ||
all(): this; | ||
/** @internal */ | ||
getCypher(env: CypherEnvironment): string; | ||
/** | ||
* If importWithCypher is provided, it will be added at the beginning of each subquery except first | ||
* @internal | ||
*/ | ||
getCypher(env: CypherEnvironment, importWithCypher?: string): string; | ||
} |
@@ -39,9 +39,12 @@ "use strict"; | ||
} | ||
/** @internal */ | ||
getCypher(env) { | ||
/** | ||
* If importWithCypher is provided, it will be added at the beginning of each subquery except first | ||
* @internal | ||
*/ | ||
getCypher(env, importWithCypher) { | ||
const subqueriesStr = this.subqueries.map((s) => s.getCypher(env)); | ||
const unionStr = this.includeAll ? "UNION ALL" : "UNION"; | ||
return subqueriesStr.join(`\n${unionStr}\n`); | ||
return subqueriesStr.join(`\n${unionStr}\n${importWithCypher ?? ""}`); | ||
} | ||
} | ||
exports.Union = Union; |
@@ -18,3 +18,3 @@ import type { CypherASTNode } from "../../CypherASTNode"; | ||
/** @internal */ | ||
getCypher(env: CypherEnvironment): string; | ||
getCypher(env: CypherEnvironment, importWithCypher?: string): string; | ||
private filterClauses; | ||
@@ -21,0 +21,0 @@ private filterEmptyComposite; |
@@ -22,2 +22,3 @@ "use strict"; | ||
exports.concat = exports.CompositeClause = void 0; | ||
const __1 = require("../.."); | ||
const filter_truthy_1 = require("../../utils/filter-truthy"); | ||
@@ -51,4 +52,10 @@ const Clause_1 = require("../Clause"); | ||
/** @internal */ | ||
getCypher(env) { | ||
const childrenStrs = this._children.map((c) => c.getCypher(env)); | ||
getCypher(env, importWithCypher) { | ||
// NOTE: importWithCypher used to pass down import WITH to UNION clauses | ||
const childrenStrs = this._children.map((c) => { | ||
if (importWithCypher && c instanceof __1.Union) { | ||
return c.getCypher(env, importWithCypher); | ||
} | ||
return c.getCypher(env); | ||
}); | ||
return childrenStrs.join(this.separator); | ||
@@ -55,0 +62,0 @@ } |
@@ -23,2 +23,3 @@ export { Call } from "./clauses/Call"; | ||
export { Case } from "./expressions/Case"; | ||
export { CypherTypes as TYPE, isNotType, isType } from "./expressions/IsType"; | ||
export { Count } from "./expressions/subquery/Count"; | ||
@@ -25,0 +26,0 @@ export { Exists } from "./expressions/subquery/Exists"; |
@@ -47,5 +47,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.gte = exports.gt = exports.eq = exports.endsWith = exports.contains = exports.xor = exports.or = exports.not = exports.and = exports.MapProjection = exports.Map = exports.PatternComprehension = exports.List = exports.ListComprehension = exports.cdc = exports.apoc = exports.Exists = exports.Count = exports.Case = exports.Variable = exports.NamedVariable = exports.Relationship = exports.NamedRelationship = exports.Property = exports.Path = exports.NamedPath = exports.Param = exports.NamedParam = exports.Node = exports.NamedNode = exports.true = exports.false = exports.Null = exports.Literal = exports.Pattern = exports.labelExpr = exports.concat = exports.With = exports.Use = exports.Unwind = exports.Union = exports.Return = exports.RawCypher = exports.Raw = exports.Merge = exports.OptionalMatch = exports.Match = exports.Foreach = exports.Create = exports.Call = void 0; | ||
exports.tan = exports.sqrt = exports.sin = exports.sign = exports.round = exports.rand = exports.radians = exports.pi = exports.log10 = exports.log = exports.isNaN = exports.haversin = exports.floor = exports.exp = exports.e = exports.degrees = exports.cot = exports.cos = exports.ceil = exports.atan2 = exports.atan = exports.asin = exports.acos = exports.abs = exports.graph = exports.sum = exports.stDevP = exports.stDev = exports.percentileDisc = exports.percentileCont = exports.min = exports.max = exports.count = exports.collect = exports.avg = exports.Function = exports.pow = exports.plus = exports.multiply = exports.mod = exports.minus = exports.divide = exports.startsWith = exports.neq = exports.matches = exports.lte = exports.lt = exports.isNull = exports.isNotNull = exports.in = void 0; | ||
exports.utils = exports.db = exports.VoidProcedure = exports.Procedure = exports.single = exports.none = exports.isEmpty = exports.exists = exports.any = exports.all = exports.time = exports.localtime = exports.localdatetime = exports.duration = exports.datetime = exports.date = void 0; | ||
exports.endsWith = exports.contains = exports.xor = exports.or = exports.not = exports.and = exports.MapProjection = exports.Map = exports.PatternComprehension = exports.List = exports.ListComprehension = exports.cdc = exports.apoc = exports.Exists = exports.Count = exports.isType = exports.isNotType = exports.TYPE = exports.Case = exports.Variable = exports.NamedVariable = exports.Relationship = exports.NamedRelationship = exports.Property = exports.Path = exports.NamedPath = exports.Param = exports.NamedParam = exports.Node = exports.NamedNode = exports.true = exports.false = exports.Null = exports.Literal = exports.Pattern = exports.labelExpr = exports.concat = exports.With = exports.Use = exports.Unwind = exports.Union = exports.Return = exports.RawCypher = exports.Raw = exports.Merge = exports.OptionalMatch = exports.Match = exports.Foreach = exports.Create = exports.Call = void 0; | ||
exports.sign = exports.round = exports.rand = exports.radians = exports.pi = exports.log10 = exports.log = exports.isNaN = exports.haversin = exports.floor = exports.exp = exports.e = exports.degrees = exports.cot = exports.cos = exports.ceil = exports.atan2 = exports.atan = exports.asin = exports.acos = exports.abs = exports.graph = exports.sum = exports.stDevP = exports.stDev = exports.percentileDisc = exports.percentileCont = exports.min = exports.max = exports.count = exports.collect = exports.avg = exports.Function = exports.pow = exports.plus = exports.multiply = exports.mod = exports.minus = exports.divide = exports.startsWith = exports.neq = exports.matches = exports.lte = exports.lt = exports.isNull = exports.isNotNull = exports.in = exports.gte = exports.gt = exports.eq = void 0; | ||
exports.utils = exports.db = exports.VoidProcedure = exports.Procedure = exports.single = exports.none = exports.isEmpty = exports.exists = exports.any = exports.all = exports.time = exports.localtime = exports.localdatetime = exports.duration = exports.datetime = exports.date = exports.tan = exports.sqrt = exports.sin = void 0; | ||
// Clauses | ||
@@ -109,2 +109,6 @@ var Call_1 = require("./clauses/Call"); | ||
Object.defineProperty(exports, "Case", { enumerable: true, get: function () { return Case_1.Case; } }); | ||
var IsType_1 = require("./expressions/IsType"); | ||
Object.defineProperty(exports, "TYPE", { enumerable: true, get: function () { return IsType_1.CypherTypes; } }); | ||
Object.defineProperty(exports, "isNotType", { enumerable: true, get: function () { return IsType_1.isNotType; } }); | ||
Object.defineProperty(exports, "isType", { enumerable: true, get: function () { return IsType_1.isType; } }); | ||
var Count_1 = require("./expressions/subquery/Count"); | ||
@@ -111,0 +115,0 @@ Object.defineProperty(exports, "Count", { enumerable: true, get: function () { return Count_1.Count; } }); |
@@ -17,2 +17,3 @@ import { WithWhere } from "../../clauses/mixins/sub-clauses/WithWhere"; | ||
constructor(pattern: Pattern | NodeRef, mapExpr?: Expr); | ||
map(mapExpr: Expr): this; | ||
/** | ||
@@ -19,0 +20,0 @@ * @internal |
@@ -38,2 +38,3 @@ "use strict"; | ||
let PatternComprehension = class PatternComprehension extends CypherASTNode_1.CypherASTNode { | ||
// NOTE: mapExpr parameter is deprecated in favour of `.map` | ||
constructor(pattern, mapExpr) { | ||
@@ -49,2 +50,6 @@ super(); | ||
} | ||
map(mapExpr) { | ||
this.mapExpr = mapExpr; | ||
return this; | ||
} | ||
/** | ||
@@ -51,0 +56,0 @@ * @internal |
@@ -5,2 +5,3 @@ import type { Raw, RawCypher } from "."; | ||
import type { HasLabel } from "./expressions/HasLabel"; | ||
import type { IsType } from "./expressions/IsType"; | ||
import type { CypherFunction } from "./expressions/functions/CypherFunctions"; | ||
@@ -28,3 +29,3 @@ import type { PredicateFunction } from "./expressions/functions/predicate"; | ||
/** Represents a predicate statement (i.e returns a boolean). Note that Raw is only added for compatibility */ | ||
export type Predicate = BooleanOp | ComparisonOp | Raw | RawCypher | Exists | Count | PredicateFunction | Literal<boolean> | Case | HasLabel; | ||
export type Predicate = BooleanOp | ComparisonOp | Raw | RawCypher | Exists | Count | PredicateFunction | Literal<boolean> | Case | HasLabel | IsType; | ||
export type CypherResult = { | ||
@@ -31,0 +32,0 @@ cypher: string; |
{ | ||
"name": "@neo4j/cypher-builder", | ||
"version": "1.10.3", | ||
"version": "1.11.0", | ||
"description": "A programmatic API for building Cypher queries for Neo4j", | ||
@@ -5,0 +5,0 @@ "exports": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
406771
215
9978