@cyphra/query 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @cyphra/query
2
+
3
+ Cypher template tag and minimal query builder for Cyphra.
4
+
5
+ ## Tagged template
6
+
7
+ ```ts
8
+ import { cypher } from "@cyphra/query";
9
+
10
+ const { text, params } = cypher`
11
+ MATCH (u:User) WHERE u.id = ${userId} RETURN u
12
+ `;
13
+ ```
14
+
15
+ ## Builder
16
+
17
+ ```ts
18
+ import { node, rel, prop, eq, select } from "@cyphra/query";
19
+
20
+ const u = node("User", "u");
21
+ const o = node("Organization", "o");
22
+ const m = rel("MEMBER_OF", "m");
23
+
24
+ const q = select()
25
+ .match(u.out(m, o))
26
+ .where(eq(prop(m.alias, "role"), "admin"))
27
+ .returnFields({ userId: prop(u.alias, "id"), orgName: prop(o.alias, "name") });
28
+
29
+ q.toCypher();
30
+ ```
@@ -0,0 +1,278 @@
1
+ /**
2
+ * Result of compiling a tagged Cypher template: query text and Neo4j parameters.
3
+ * Values from `${…}` are **never** concatenated as raw Cypher — only bound as parameters.
4
+ */
5
+ type CompiledCypher = {
6
+ readonly text: string;
7
+ readonly params: Readonly<Record<string, unknown>>;
8
+ };
9
+ /**
10
+ * Compile a template literal into Cypher with positional parameters `p0`, `p1`, …
11
+ *
12
+ * @param strings - Static fragments from the template literal.
13
+ * @param values - Interpolated values; each becomes a separate parameter.
14
+ * @returns Query text and a flat parameter map for `session.run`.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const { text, params } = compileCypher(
19
+ * ["MATCH (u:User) WHERE u.id = ", " RETURN u"] as unknown as TemplateStringsArray,
20
+ * ["x-1"],
21
+ * );
22
+ * // text: "MATCH (u:User) WHERE u.id = $p0 RETURN u"
23
+ * ```
24
+ */
25
+ declare function compileCypher(strings: TemplateStringsArray, values: readonly unknown[]): CompiledCypher;
26
+ /**
27
+ * Tagged template: `` cypher`MATCH (u) WHERE u.id = ${id}` ``
28
+ *
29
+ * @param strings - Template strings.
30
+ * @param values - Bound parameters (never inlined as Cypher text).
31
+ */
32
+ declare function cypher(strings: TemplateStringsArray, ...values: unknown[]): CompiledCypher;
33
+
34
+ /** Symbolic node variable in a pattern (`(u:User)`). */
35
+ type NodeRef = {
36
+ readonly label: string;
37
+ readonly alias: string;
38
+ /**
39
+ * Outgoing relationship pattern fragment: `(u)-[m:REL]->(o)`.
40
+ *
41
+ * @param r - Relationship reference.
42
+ * @param to - Target node.
43
+ */
44
+ out(r: RelRef, to: NodeRef): string;
45
+ /**
46
+ * Incoming relationship pattern: `(o)<-[m:REL]-(u)`.
47
+ *
48
+ * @param r - Relationship reference.
49
+ * @param from - Source node (the “other” end of the arrow).
50
+ */
51
+ in(r: RelRef, from: NodeRef): string;
52
+ /**
53
+ * Undirected pattern: `(a)-[r:T]-(b)` (both ends symmetric).
54
+ *
55
+ * @param r - Relationship reference.
56
+ * @param other - The other node in the undirected segment.
57
+ */
58
+ both(r: RelRef, other: NodeRef): string;
59
+ };
60
+ /** Symbolic relationship variable (`[m:MEMBER_OF]`). */
61
+ type RelRef = {
62
+ readonly type: string;
63
+ readonly alias: string;
64
+ };
65
+ /** Property reference for WHERE / RETURN / ORDER BY (`u.email`, `m.role`). */
66
+ type PropRef = {
67
+ readonly alias: string;
68
+ readonly name: string;
69
+ };
70
+ /**
71
+ * Create a node reference for patterns and projections.
72
+ *
73
+ * @param label - Neo4j label (e.g. `User`).
74
+ * @param alias - Cypher variable name.
75
+ */
76
+ declare function node(label: string, alias: string): NodeRef;
77
+ /**
78
+ * Create a relationship reference.
79
+ *
80
+ * @param type - Neo4j relationship type.
81
+ * @param alias - Cypher variable name.
82
+ */
83
+ declare function rel(type: string, alias: string): RelRef;
84
+ /**
85
+ * Reference a property on a node or relationship alias.
86
+ *
87
+ * @param alias - Cypher variable (`u`, `m`, …).
88
+ * @param name - Property name.
89
+ */
90
+ declare function prop(alias: string, name: string): PropRef;
91
+ /** Predicate combined with AND in {@link SelectQuery.where}. */
92
+ type WherePredicate = {
93
+ readonly kind: "and";
94
+ readonly items: readonly WherePredicate[];
95
+ } | {
96
+ readonly kind: "or";
97
+ readonly items: readonly WherePredicate[];
98
+ } | {
99
+ readonly kind: "not";
100
+ readonly inner: WherePredicate;
101
+ } | {
102
+ readonly kind: "eq";
103
+ readonly left: PropRef;
104
+ readonly right: unknown;
105
+ } | {
106
+ readonly kind: "neq";
107
+ readonly left: PropRef;
108
+ readonly right: unknown;
109
+ } | {
110
+ readonly kind: "gt";
111
+ readonly left: PropRef;
112
+ readonly right: unknown;
113
+ } | {
114
+ readonly kind: "gte";
115
+ readonly left: PropRef;
116
+ readonly right: unknown;
117
+ } | {
118
+ readonly kind: "lt";
119
+ readonly left: PropRef;
120
+ readonly right: unknown;
121
+ } | {
122
+ readonly kind: "lte";
123
+ readonly left: PropRef;
124
+ readonly right: unknown;
125
+ } | {
126
+ readonly kind: "between";
127
+ readonly left: PropRef;
128
+ readonly low: unknown;
129
+ readonly high: unknown;
130
+ } | {
131
+ readonly kind: "isNull";
132
+ readonly left: PropRef;
133
+ } | {
134
+ readonly kind: "isNotNull";
135
+ readonly left: PropRef;
136
+ } | {
137
+ readonly kind: "in";
138
+ readonly left: PropRef;
139
+ readonly values: readonly unknown[];
140
+ } | {
141
+ readonly kind: "startsWith";
142
+ readonly left: PropRef;
143
+ readonly substring: string;
144
+ } | {
145
+ readonly kind: "endsWith";
146
+ readonly left: PropRef;
147
+ readonly substring: string;
148
+ } | {
149
+ readonly kind: "contains";
150
+ readonly left: PropRef;
151
+ readonly substring: string;
152
+ } | {
153
+ readonly kind: "matches";
154
+ readonly left: PropRef;
155
+ readonly pattern: string;
156
+ };
157
+ /** Equality branch of {@link WherePredicate}. */
158
+ type EqPredicate = Extract<WherePredicate, {
159
+ kind: "eq";
160
+ }>;
161
+ /**
162
+ * `(p0 AND p1 AND …)` — use with {@link or} for grouped conditions.
163
+ * Top-level {@link SelectQuery.where} arguments are already AND-combined.
164
+ */
165
+ declare function and(...items: WherePredicate[]): WherePredicate;
166
+ /**
167
+ * `(p0 OR p1 OR …)` — Cypher precedence: AND binds tighter than OR; children are parenthesized when needed.
168
+ */
169
+ declare function or(...items: WherePredicate[]): WherePredicate;
170
+ /** `NOT (inner …)` — `inner` uses the same parameter rules as top-level predicates. */
171
+ declare function not(inner: WherePredicate): WherePredicate;
172
+ /** `left = $pN` */
173
+ declare function eq(left: PropRef, right: unknown): WherePredicate;
174
+ /** `left <> $pN` */
175
+ declare function neq(left: PropRef, right: unknown): WherePredicate;
176
+ /** `left > $pN` */
177
+ declare function gt(left: PropRef, right: unknown): WherePredicate;
178
+ /** `left >= $pN` */
179
+ declare function gte(left: PropRef, right: unknown): WherePredicate;
180
+ /** `left < $pN` */
181
+ declare function lt(left: PropRef, right: unknown): WherePredicate;
182
+ /** `left <= $pN` */
183
+ declare function lte(left: PropRef, right: unknown): WherePredicate;
184
+ /**
185
+ * Inclusive range: `(left >= $pN AND left <= $pM)` — both bounds are parameters.
186
+ */
187
+ declare function between(left: PropRef, low: unknown, high: unknown): WherePredicate;
188
+ /** `left IS NULL` */
189
+ declare function isNull(left: PropRef): WherePredicate;
190
+ /** `left IS NOT NULL` */
191
+ declare function isNotNull(left: PropRef): WherePredicate;
192
+ /**
193
+ * `left IN $pN` — list is passed as a single parameter (never concatenated into Cypher).
194
+ *
195
+ * @throws If `values` is empty (use other predicates; `IN []` is always false in Cypher).
196
+ */
197
+ declare function inList(left: PropRef, values: readonly unknown[]): WherePredicate;
198
+ /** `left STARTS WITH $pN` */
199
+ declare function startsWith(left: PropRef, substring: string): WherePredicate;
200
+ /** `left ENDS WITH $pN` */
201
+ declare function endsWith(left: PropRef, substring: string): WherePredicate;
202
+ /** `left CONTAINS $pN` */
203
+ declare function contains(left: PropRef, substring: string): WherePredicate;
204
+ /**
205
+ * `left =~ $pN` — regular-expression match; the pattern is always a bound parameter.
206
+ * Neo4j uses Java-compatible regex (see Cypher manual).
207
+ */
208
+ declare function matches(left: PropRef, pattern: string): WherePredicate;
209
+ type OrderDirection = "ASC" | "DESC";
210
+ type OrderByClause = {
211
+ readonly prop: PropRef;
212
+ readonly direction: OrderDirection;
213
+ };
214
+ /**
215
+ * `MATCH … OPTIONAL MATCH … WHERE … RETURN … ORDER BY … SKIP … LIMIT` builder (Cypher remains explicit in `match()` / `optionalMatch()`).
216
+ * WHERE clauses are AND-combined; use {@link and} / {@link or} for explicit grouping.
217
+ * Every bound value is a parameter except `IS NULL` / `IS NOT NULL`.
218
+ */
219
+ declare class SelectQuery {
220
+ private matchPattern;
221
+ private optionalPatterns;
222
+ private predicates;
223
+ private projection;
224
+ private returnDistinctFlag;
225
+ private order;
226
+ private skipCount;
227
+ private limitCount;
228
+ /**
229
+ * @param pattern - Full `MATCH` pattern body (e.g. from {@link NodeRef.out}).
230
+ */
231
+ match(pattern: string): this;
232
+ /**
233
+ * Append `OPTIONAL MATCH` after the primary {@link match} (same pattern string rules: full clause body only).
234
+ *
235
+ * @throws If {@link match} was not called yet.
236
+ */
237
+ optionalMatch(pattern: string): this;
238
+ /**
239
+ * AND-combine predicates. When you pass more than one argument, any root-level {@link or}
240
+ * is parenthesized so it is not parsed as `a OR (b AND c)`.
241
+ */
242
+ where(...preds: WherePredicate[]): this;
243
+ /**
244
+ * @param fields - Map of output alias → property reference.
245
+ */
246
+ returnFields(fields: Record<string, PropRef>): this;
247
+ /** `RETURN *` (mutually exclusive with {@link returnFields} — last call wins). */
248
+ returnStar(): this;
249
+ /**
250
+ * `RETURN DISTINCT …` — may be called before or after {@link returnFields} / {@link returnStar}
251
+ * (projection must still be set before {@link toCypher}).
252
+ */
253
+ returnDistinct(): this;
254
+ /**
255
+ * Append `ORDER BY` clauses (direction is whitelisted, never from user strings).
256
+ *
257
+ * @param clauses - Property + ASC/DESC pairs.
258
+ */
259
+ orderBy(...clauses: OrderByClause[]): this;
260
+ /**
261
+ * `SKIP` with a bound parameter.
262
+ *
263
+ * @param n - Number of rows to skip.
264
+ */
265
+ skip(n: number): this;
266
+ /**
267
+ * `LIMIT` with a bound parameter.
268
+ *
269
+ * @param n - Maximum rows.
270
+ */
271
+ limit(n: number): this;
272
+ /** Generated Cypher and parameters (for debugging or execution). */
273
+ toCypher(): CompiledCypher;
274
+ }
275
+ /** Start a fluent `MATCH` query. */
276
+ declare function select(): SelectQuery;
277
+
278
+ export { type CompiledCypher, type EqPredicate, type NodeRef, type OrderByClause, type OrderDirection, type PropRef, type RelRef, SelectQuery, type WherePredicate, and, between, compileCypher, contains, cypher, endsWith, eq, gt, gte, inList, isNotNull, isNull, lt, lte, matches, neq, node, not, or, prop, rel, select, startsWith };
package/dist/index.js ADDED
@@ -0,0 +1,380 @@
1
+ // src/cypher.ts
2
+ function compileCypher(strings, values) {
3
+ if (values.length !== strings.length - 1) {
4
+ throw new Error(
5
+ `cypher template: expected ${strings.length - 1} interpolated values, got ${values.length}`
6
+ );
7
+ }
8
+ const params = {};
9
+ let text = "";
10
+ for (let i = 0; i < strings.length - 1; i++) {
11
+ text += strings[i];
12
+ const key = `p${i}`;
13
+ params[key] = values[i];
14
+ text += `$${key}`;
15
+ }
16
+ text += strings[strings.length - 1];
17
+ return { text, params };
18
+ }
19
+ function cypher(strings, ...values) {
20
+ return compileCypher(strings, values);
21
+ }
22
+
23
+ // src/builder.ts
24
+ function node(label, alias) {
25
+ return {
26
+ label,
27
+ alias,
28
+ out(r, to) {
29
+ return `(${alias}:${label})-[${r.alias}:${r.type}]->(${to.alias}:${to.label})`;
30
+ },
31
+ in(r, from) {
32
+ return `(${alias}:${label})<-[${r.alias}:${r.type}]-(${from.alias}:${from.label})`;
33
+ },
34
+ both(r, other) {
35
+ return `(${alias}:${label})-[${r.alias}:${r.type}]-(${other.alias}:${other.label})`;
36
+ }
37
+ };
38
+ }
39
+ function rel(type, alias) {
40
+ return { type, alias };
41
+ }
42
+ function prop(alias, name) {
43
+ return { alias, name };
44
+ }
45
+ function propExpr(p) {
46
+ return `${p.alias}.${p.name}`;
47
+ }
48
+ function emitUnderAnd(pred, sink) {
49
+ if (pred.kind === "or") {
50
+ return `(${emitPredicate(pred, sink)})`;
51
+ }
52
+ return emitPredicate(pred, sink);
53
+ }
54
+ function emitUnderOr(pred, sink) {
55
+ if (pred.kind === "and") {
56
+ return `(${emitPredicate(pred, sink)})`;
57
+ }
58
+ return emitPredicate(pred, sink);
59
+ }
60
+ function emitPredicate(pred, sink) {
61
+ switch (pred.kind) {
62
+ case "and": {
63
+ if (pred.items.length === 0) {
64
+ throw new Error("and(): at least one predicate is required");
65
+ }
66
+ if (pred.items.length === 1) {
67
+ return emitPredicate(pred.items[0], sink);
68
+ }
69
+ return pred.items.map((item) => emitUnderAnd(item, sink)).join(" AND ");
70
+ }
71
+ case "or": {
72
+ if (pred.items.length === 0) {
73
+ throw new Error("or(): at least one predicate is required");
74
+ }
75
+ if (pred.items.length === 1) {
76
+ return emitPredicate(pred.items[0], sink);
77
+ }
78
+ return pred.items.map((item) => emitUnderOr(item, sink)).join(" OR ");
79
+ }
80
+ case "not":
81
+ return `NOT (${emitPredicate(pred.inner, sink)})`;
82
+ case "eq": {
83
+ const k = sink.nextParam();
84
+ sink.params[k] = pred.right;
85
+ return `${propExpr(pred.left)} = $${k}`;
86
+ }
87
+ case "neq": {
88
+ const k = sink.nextParam();
89
+ sink.params[k] = pred.right;
90
+ return `${propExpr(pred.left)} <> $${k}`;
91
+ }
92
+ case "gt": {
93
+ const k = sink.nextParam();
94
+ sink.params[k] = pred.right;
95
+ return `${propExpr(pred.left)} > $${k}`;
96
+ }
97
+ case "gte": {
98
+ const k = sink.nextParam();
99
+ sink.params[k] = pred.right;
100
+ return `${propExpr(pred.left)} >= $${k}`;
101
+ }
102
+ case "lt": {
103
+ const k = sink.nextParam();
104
+ sink.params[k] = pred.right;
105
+ return `${propExpr(pred.left)} < $${k}`;
106
+ }
107
+ case "lte": {
108
+ const k = sink.nextParam();
109
+ sink.params[k] = pred.right;
110
+ return `${propExpr(pred.left)} <= $${k}`;
111
+ }
112
+ case "between": {
113
+ const kLo = sink.nextParam();
114
+ const kHi = sink.nextParam();
115
+ sink.params[kLo] = pred.low;
116
+ sink.params[kHi] = pred.high;
117
+ const pe = propExpr(pred.left);
118
+ return `(${pe} >= $${kLo} AND ${pe} <= $${kHi})`;
119
+ }
120
+ case "isNull":
121
+ return `${propExpr(pred.left)} IS NULL`;
122
+ case "isNotNull":
123
+ return `${propExpr(pred.left)} IS NOT NULL`;
124
+ case "in": {
125
+ const k = sink.nextParam();
126
+ sink.params[k] = [...pred.values];
127
+ return `${propExpr(pred.left)} IN $${k}`;
128
+ }
129
+ case "startsWith": {
130
+ const k = sink.nextParam();
131
+ sink.params[k] = pred.substring;
132
+ return `${propExpr(pred.left)} STARTS WITH $${k}`;
133
+ }
134
+ case "endsWith": {
135
+ const k = sink.nextParam();
136
+ sink.params[k] = pred.substring;
137
+ return `${propExpr(pred.left)} ENDS WITH $${k}`;
138
+ }
139
+ case "contains": {
140
+ const k = sink.nextParam();
141
+ sink.params[k] = pred.substring;
142
+ return `${propExpr(pred.left)} CONTAINS $${k}`;
143
+ }
144
+ case "matches": {
145
+ const k = sink.nextParam();
146
+ sink.params[k] = pred.pattern;
147
+ return `${propExpr(pred.left)} =~ $${k}`;
148
+ }
149
+ default: {
150
+ const _exhaustive = pred;
151
+ throw new Error(`Unhandled predicate: ${JSON.stringify(_exhaustive)}`);
152
+ }
153
+ }
154
+ }
155
+ function and(...items) {
156
+ if (items.length === 0) {
157
+ throw new Error("and(): at least one predicate is required");
158
+ }
159
+ return { kind: "and", items };
160
+ }
161
+ function or(...items) {
162
+ if (items.length === 0) {
163
+ throw new Error("or(): at least one predicate is required");
164
+ }
165
+ return { kind: "or", items };
166
+ }
167
+ function not(inner) {
168
+ return { kind: "not", inner };
169
+ }
170
+ function eq(left, right) {
171
+ return { kind: "eq", left, right };
172
+ }
173
+ function neq(left, right) {
174
+ return { kind: "neq", left, right };
175
+ }
176
+ function gt(left, right) {
177
+ return { kind: "gt", left, right };
178
+ }
179
+ function gte(left, right) {
180
+ return { kind: "gte", left, right };
181
+ }
182
+ function lt(left, right) {
183
+ return { kind: "lt", left, right };
184
+ }
185
+ function lte(left, right) {
186
+ return { kind: "lte", left, right };
187
+ }
188
+ function between(left, low, high) {
189
+ return { kind: "between", left, low, high };
190
+ }
191
+ function isNull(left) {
192
+ return { kind: "isNull", left };
193
+ }
194
+ function isNotNull(left) {
195
+ return { kind: "isNotNull", left };
196
+ }
197
+ function inList(left, values) {
198
+ if (values.length === 0) {
199
+ throw new Error("inList: empty list is not supported; use explicit false or omit the clause");
200
+ }
201
+ return { kind: "in", left, values };
202
+ }
203
+ function startsWith(left, substring) {
204
+ return { kind: "startsWith", left, substring };
205
+ }
206
+ function endsWith(left, substring) {
207
+ return { kind: "endsWith", left, substring };
208
+ }
209
+ function contains(left, substring) {
210
+ return { kind: "contains", left, substring };
211
+ }
212
+ function matches(left, pattern) {
213
+ return { kind: "matches", left, pattern };
214
+ }
215
+ var SelectQuery = class {
216
+ matchPattern = "";
217
+ optionalPatterns = [];
218
+ predicates = [];
219
+ projection = null;
220
+ returnDistinctFlag = false;
221
+ order = [];
222
+ skipCount = null;
223
+ limitCount = null;
224
+ /**
225
+ * @param pattern - Full `MATCH` pattern body (e.g. from {@link NodeRef.out}).
226
+ */
227
+ match(pattern) {
228
+ this.matchPattern = pattern;
229
+ return this;
230
+ }
231
+ /**
232
+ * Append `OPTIONAL MATCH` after the primary {@link match} (same pattern string rules: full clause body only).
233
+ *
234
+ * @throws If {@link match} was not called yet.
235
+ */
236
+ optionalMatch(pattern) {
237
+ if (!this.matchPattern) {
238
+ throw new Error("SelectQuery: call match() before optionalMatch()");
239
+ }
240
+ this.optionalPatterns.push(pattern);
241
+ return this;
242
+ }
243
+ /**
244
+ * AND-combine predicates. When you pass more than one argument, any root-level {@link or}
245
+ * is parenthesized so it is not parsed as `a OR (b AND c)`.
246
+ */
247
+ where(...preds) {
248
+ this.predicates.push(...preds);
249
+ return this;
250
+ }
251
+ /**
252
+ * @param fields - Map of output alias → property reference.
253
+ */
254
+ returnFields(fields) {
255
+ this.projection = fields;
256
+ return this;
257
+ }
258
+ /** `RETURN *` (mutually exclusive with {@link returnFields} — last call wins). */
259
+ returnStar() {
260
+ this.projection = "star";
261
+ return this;
262
+ }
263
+ /**
264
+ * `RETURN DISTINCT …` — may be called before or after {@link returnFields} / {@link returnStar}
265
+ * (projection must still be set before {@link toCypher}).
266
+ */
267
+ returnDistinct() {
268
+ this.returnDistinctFlag = true;
269
+ return this;
270
+ }
271
+ /**
272
+ * Append `ORDER BY` clauses (direction is whitelisted, never from user strings).
273
+ *
274
+ * @param clauses - Property + ASC/DESC pairs.
275
+ */
276
+ orderBy(...clauses) {
277
+ this.order.push(...clauses);
278
+ return this;
279
+ }
280
+ /**
281
+ * `SKIP` with a bound parameter.
282
+ *
283
+ * @param n - Number of rows to skip.
284
+ */
285
+ skip(n) {
286
+ if (!Number.isInteger(n) || n < 0) {
287
+ throw new Error("SelectQuery.skip: n must be a non-negative integer");
288
+ }
289
+ this.skipCount = n;
290
+ return this;
291
+ }
292
+ /**
293
+ * `LIMIT` with a bound parameter.
294
+ *
295
+ * @param n - Maximum rows.
296
+ */
297
+ limit(n) {
298
+ if (!Number.isInteger(n) || n < 0) {
299
+ throw new Error("SelectQuery.limit: n must be a non-negative integer");
300
+ }
301
+ this.limitCount = n;
302
+ return this;
303
+ }
304
+ /** Generated Cypher and parameters (for debugging or execution). */
305
+ toCypher() {
306
+ if (!this.matchPattern) {
307
+ throw new Error("SelectQuery: call match() before toCypher()");
308
+ }
309
+ if (this.projection === null) {
310
+ throw new Error("SelectQuery: call returnFields() or returnStar() before toCypher()");
311
+ }
312
+ const params = {};
313
+ let p = 0;
314
+ const nextParam = () => {
315
+ const key = `p${p++}`;
316
+ return key;
317
+ };
318
+ const sink = { params, nextParam };
319
+ let text = `MATCH ${this.matchPattern}`;
320
+ for (const opt of this.optionalPatterns) {
321
+ text += ` OPTIONAL MATCH ${opt}`;
322
+ }
323
+ if (this.predicates.length > 0) {
324
+ const parts = this.predicates.length === 1 ? [emitPredicate(this.predicates[0], sink)] : this.predicates.map((pred) => emitUnderAnd(pred, sink));
325
+ text += ` WHERE ${parts.join(" AND ")}`;
326
+ }
327
+ const distinctKw = this.returnDistinctFlag ? "DISTINCT " : "";
328
+ if (this.projection === "star") {
329
+ text += ` RETURN ${distinctKw}*`;
330
+ } else {
331
+ const ret = Object.entries(this.projection).map(([out, pr]) => `${pr.alias}.${pr.name} AS ${out}`).join(", ");
332
+ text += ` RETURN ${distinctKw}${ret}`;
333
+ }
334
+ if (this.order.length > 0) {
335
+ const ob = this.order.map((c) => `${c.prop.alias}.${c.prop.name} ${c.direction}`).join(", ");
336
+ text += ` ORDER BY ${ob}`;
337
+ }
338
+ if (this.skipCount !== null) {
339
+ const key = nextParam();
340
+ params[key] = this.skipCount;
341
+ text += ` SKIP $${key}`;
342
+ }
343
+ if (this.limitCount !== null) {
344
+ const key = nextParam();
345
+ params[key] = this.limitCount;
346
+ text += ` LIMIT $${key}`;
347
+ }
348
+ return { text, params };
349
+ }
350
+ };
351
+ function select() {
352
+ return new SelectQuery();
353
+ }
354
+ export {
355
+ SelectQuery,
356
+ and,
357
+ between,
358
+ compileCypher,
359
+ contains,
360
+ cypher,
361
+ endsWith,
362
+ eq,
363
+ gt,
364
+ gte,
365
+ inList,
366
+ isNotNull,
367
+ isNull,
368
+ lt,
369
+ lte,
370
+ matches,
371
+ neq,
372
+ node,
373
+ not,
374
+ or,
375
+ prop,
376
+ rel,
377
+ select,
378
+ startsWith
379
+ };
380
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cypher.ts","../src/builder.ts"],"sourcesContent":["/**\n * Result of compiling a tagged Cypher template: query text and Neo4j parameters.\n * Values from `${…}` are **never** concatenated as raw Cypher — only bound as parameters.\n */\nexport type CompiledCypher = {\n readonly text: string;\n readonly params: Readonly<Record<string, unknown>>;\n};\n\n/**\n * Compile a template literal into Cypher with positional parameters `p0`, `p1`, …\n *\n * @param strings - Static fragments from the template literal.\n * @param values - Interpolated values; each becomes a separate parameter.\n * @returns Query text and a flat parameter map for `session.run`.\n *\n * @example\n * ```ts\n * const { text, params } = compileCypher(\n * [\"MATCH (u:User) WHERE u.id = \", \" RETURN u\"] as unknown as TemplateStringsArray,\n * [\"x-1\"],\n * );\n * // text: \"MATCH (u:User) WHERE u.id = $p0 RETURN u\"\n * ```\n */\nexport function compileCypher(\n strings: TemplateStringsArray,\n values: readonly unknown[],\n): CompiledCypher {\n if (values.length !== strings.length - 1) {\n throw new Error(\n `cypher template: expected ${strings.length - 1} interpolated values, got ${values.length}`,\n );\n }\n const params: Record<string, unknown> = {};\n let text = \"\";\n for (let i = 0; i < strings.length - 1; i++) {\n text += strings[i];\n const key = `p${i}`;\n params[key] = values[i];\n text += `$${key}`;\n }\n text += strings[strings.length - 1];\n return { text, params };\n}\n\n/**\n * Tagged template: `` cypher`MATCH (u) WHERE u.id = ${id}` ``\n *\n * @param strings - Template strings.\n * @param values - Bound parameters (never inlined as Cypher text).\n */\nexport function cypher(strings: TemplateStringsArray, ...values: unknown[]): CompiledCypher {\n return compileCypher(strings, values);\n}\n","import type { CompiledCypher } from \"./cypher.js\";\n\n/** Symbolic node variable in a pattern (`(u:User)`). */\nexport type NodeRef = {\n readonly label: string;\n readonly alias: string;\n /**\n * Outgoing relationship pattern fragment: `(u)-[m:REL]->(o)`.\n *\n * @param r - Relationship reference.\n * @param to - Target node.\n */\n out(r: RelRef, to: NodeRef): string;\n /**\n * Incoming relationship pattern: `(o)<-[m:REL]-(u)`.\n *\n * @param r - Relationship reference.\n * @param from - Source node (the “other” end of the arrow).\n */\n in(r: RelRef, from: NodeRef): string;\n /**\n * Undirected pattern: `(a)-[r:T]-(b)` (both ends symmetric).\n *\n * @param r - Relationship reference.\n * @param other - The other node in the undirected segment.\n */\n both(r: RelRef, other: NodeRef): string;\n};\n\n/** Symbolic relationship variable (`[m:MEMBER_OF]`). */\nexport type RelRef = {\n readonly type: string;\n readonly alias: string;\n};\n\n/** Property reference for WHERE / RETURN / ORDER BY (`u.email`, `m.role`). */\nexport type PropRef = {\n readonly alias: string;\n readonly name: string;\n};\n\n/**\n * Create a node reference for patterns and projections.\n *\n * @param label - Neo4j label (e.g. `User`).\n * @param alias - Cypher variable name.\n */\nexport function node(label: string, alias: string): NodeRef {\n return {\n label,\n alias,\n out(r: RelRef, to: NodeRef): string {\n return `(${alias}:${label})-[${r.alias}:${r.type}]->(${to.alias}:${to.label})`;\n },\n in(r: RelRef, from: NodeRef): string {\n return `(${alias}:${label})<-[${r.alias}:${r.type}]-(${from.alias}:${from.label})`;\n },\n both(r: RelRef, other: NodeRef): string {\n return `(${alias}:${label})-[${r.alias}:${r.type}]-(${other.alias}:${other.label})`;\n },\n };\n}\n\n/**\n * Create a relationship reference.\n *\n * @param type - Neo4j relationship type.\n * @param alias - Cypher variable name.\n */\nexport function rel(type: string, alias: string): RelRef {\n return { type, alias };\n}\n\n/**\n * Reference a property on a node or relationship alias.\n *\n * @param alias - Cypher variable (`u`, `m`, …).\n * @param name - Property name.\n */\nexport function prop(alias: string, name: string): PropRef {\n return { alias, name };\n}\n\nfunction propExpr(p: PropRef): string {\n return `${p.alias}.${p.name}`;\n}\n\ntype ParamSink = {\n readonly params: Record<string, unknown>;\n readonly nextParam: () => string;\n};\n\n/** Under AND: OR children need parentheses (OR has lower precedence than AND in Cypher). */\nfunction emitUnderAnd(pred: WherePredicate, sink: ParamSink): string {\n if (pred.kind === \"or\") {\n return `(${emitPredicate(pred, sink)})`;\n }\n return emitPredicate(pred, sink);\n}\n\n/** Under OR: AND children need parentheses. */\nfunction emitUnderOr(pred: WherePredicate, sink: ParamSink): string {\n if (pred.kind === \"and\") {\n return `(${emitPredicate(pred, sink)})`;\n }\n return emitPredicate(pred, sink);\n}\n\n/** Emit one WHERE fragment; mutates `sink.params` for bound values. */\nfunction emitPredicate(pred: WherePredicate, sink: ParamSink): string {\n switch (pred.kind) {\n case \"and\": {\n if (pred.items.length === 0) {\n throw new Error(\"and(): at least one predicate is required\");\n }\n if (pred.items.length === 1) {\n return emitPredicate(pred.items[0]!, sink);\n }\n return pred.items.map((item) => emitUnderAnd(item, sink)).join(\" AND \");\n }\n case \"or\": {\n if (pred.items.length === 0) {\n throw new Error(\"or(): at least one predicate is required\");\n }\n if (pred.items.length === 1) {\n return emitPredicate(pred.items[0]!, sink);\n }\n return pred.items.map((item) => emitUnderOr(item, sink)).join(\" OR \");\n }\n case \"not\":\n return `NOT (${emitPredicate(pred.inner, sink)})`;\n case \"eq\": {\n const k = sink.nextParam();\n sink.params[k] = pred.right;\n return `${propExpr(pred.left)} = $${k}`;\n }\n case \"neq\": {\n const k = sink.nextParam();\n sink.params[k] = pred.right;\n return `${propExpr(pred.left)} <> $${k}`;\n }\n case \"gt\": {\n const k = sink.nextParam();\n sink.params[k] = pred.right;\n return `${propExpr(pred.left)} > $${k}`;\n }\n case \"gte\": {\n const k = sink.nextParam();\n sink.params[k] = pred.right;\n return `${propExpr(pred.left)} >= $${k}`;\n }\n case \"lt\": {\n const k = sink.nextParam();\n sink.params[k] = pred.right;\n return `${propExpr(pred.left)} < $${k}`;\n }\n case \"lte\": {\n const k = sink.nextParam();\n sink.params[k] = pred.right;\n return `${propExpr(pred.left)} <= $${k}`;\n }\n case \"between\": {\n const kLo = sink.nextParam();\n const kHi = sink.nextParam();\n sink.params[kLo] = pred.low;\n sink.params[kHi] = pred.high;\n const pe = propExpr(pred.left);\n return `(${pe} >= $${kLo} AND ${pe} <= $${kHi})`;\n }\n case \"isNull\":\n return `${propExpr(pred.left)} IS NULL`;\n case \"isNotNull\":\n return `${propExpr(pred.left)} IS NOT NULL`;\n case \"in\": {\n const k = sink.nextParam();\n sink.params[k] = [...pred.values];\n return `${propExpr(pred.left)} IN $${k}`;\n }\n case \"startsWith\": {\n const k = sink.nextParam();\n sink.params[k] = pred.substring;\n return `${propExpr(pred.left)} STARTS WITH $${k}`;\n }\n case \"endsWith\": {\n const k = sink.nextParam();\n sink.params[k] = pred.substring;\n return `${propExpr(pred.left)} ENDS WITH $${k}`;\n }\n case \"contains\": {\n const k = sink.nextParam();\n sink.params[k] = pred.substring;\n return `${propExpr(pred.left)} CONTAINS $${k}`;\n }\n case \"matches\": {\n const k = sink.nextParam();\n sink.params[k] = pred.pattern;\n return `${propExpr(pred.left)} =~ $${k}`;\n }\n default: {\n const _exhaustive: never = pred;\n throw new Error(`Unhandled predicate: ${JSON.stringify(_exhaustive)}`);\n }\n }\n}\n\n/** Predicate combined with AND in {@link SelectQuery.where}. */\nexport type WherePredicate =\n | { readonly kind: \"and\"; readonly items: readonly WherePredicate[] }\n | { readonly kind: \"or\"; readonly items: readonly WherePredicate[] }\n | { readonly kind: \"not\"; readonly inner: WherePredicate }\n | { readonly kind: \"eq\"; readonly left: PropRef; readonly right: unknown }\n | { readonly kind: \"neq\"; readonly left: PropRef; readonly right: unknown }\n | { readonly kind: \"gt\"; readonly left: PropRef; readonly right: unknown }\n | { readonly kind: \"gte\"; readonly left: PropRef; readonly right: unknown }\n | { readonly kind: \"lt\"; readonly left: PropRef; readonly right: unknown }\n | { readonly kind: \"lte\"; readonly left: PropRef; readonly right: unknown }\n | {\n readonly kind: \"between\";\n readonly left: PropRef;\n readonly low: unknown;\n readonly high: unknown;\n }\n | { readonly kind: \"isNull\"; readonly left: PropRef }\n | { readonly kind: \"isNotNull\"; readonly left: PropRef }\n | { readonly kind: \"in\"; readonly left: PropRef; readonly values: readonly unknown[] }\n | { readonly kind: \"startsWith\"; readonly left: PropRef; readonly substring: string }\n | { readonly kind: \"endsWith\"; readonly left: PropRef; readonly substring: string }\n | { readonly kind: \"contains\"; readonly left: PropRef; readonly substring: string }\n | { readonly kind: \"matches\"; readonly left: PropRef; readonly pattern: string };\n\n/** Equality branch of {@link WherePredicate}. */\nexport type EqPredicate = Extract<WherePredicate, { kind: \"eq\" }>;\n\n/**\n * `(p0 AND p1 AND …)` — use with {@link or} for grouped conditions.\n * Top-level {@link SelectQuery.where} arguments are already AND-combined.\n */\nexport function and(...items: WherePredicate[]): WherePredicate {\n if (items.length === 0) {\n throw new Error(\"and(): at least one predicate is required\");\n }\n return { kind: \"and\", items };\n}\n\n/**\n * `(p0 OR p1 OR …)` — Cypher precedence: AND binds tighter than OR; children are parenthesized when needed.\n */\nexport function or(...items: WherePredicate[]): WherePredicate {\n if (items.length === 0) {\n throw new Error(\"or(): at least one predicate is required\");\n }\n return { kind: \"or\", items };\n}\n\n/** `NOT (inner …)` — `inner` uses the same parameter rules as top-level predicates. */\nexport function not(inner: WherePredicate): WherePredicate {\n return { kind: \"not\", inner };\n}\n\n/** `left = $pN` */\nexport function eq(left: PropRef, right: unknown): WherePredicate {\n return { kind: \"eq\", left, right };\n}\n\n/** `left <> $pN` */\nexport function neq(left: PropRef, right: unknown): WherePredicate {\n return { kind: \"neq\", left, right };\n}\n\n/** `left > $pN` */\nexport function gt(left: PropRef, right: unknown): WherePredicate {\n return { kind: \"gt\", left, right };\n}\n\n/** `left >= $pN` */\nexport function gte(left: PropRef, right: unknown): WherePredicate {\n return { kind: \"gte\", left, right };\n}\n\n/** `left < $pN` */\nexport function lt(left: PropRef, right: unknown): WherePredicate {\n return { kind: \"lt\", left, right };\n}\n\n/** `left <= $pN` */\nexport function lte(left: PropRef, right: unknown): WherePredicate {\n return { kind: \"lte\", left, right };\n}\n\n/**\n * Inclusive range: `(left >= $pN AND left <= $pM)` — both bounds are parameters.\n */\nexport function between(left: PropRef, low: unknown, high: unknown): WherePredicate {\n return { kind: \"between\", left, low, high };\n}\n\n/** `left IS NULL` */\nexport function isNull(left: PropRef): WherePredicate {\n return { kind: \"isNull\", left };\n}\n\n/** `left IS NOT NULL` */\nexport function isNotNull(left: PropRef): WherePredicate {\n return { kind: \"isNotNull\", left };\n}\n\n/**\n * `left IN $pN` — list is passed as a single parameter (never concatenated into Cypher).\n *\n * @throws If `values` is empty (use other predicates; `IN []` is always false in Cypher).\n */\nexport function inList(left: PropRef, values: readonly unknown[]): WherePredicate {\n if (values.length === 0) {\n throw new Error(\"inList: empty list is not supported; use explicit false or omit the clause\");\n }\n return { kind: \"in\", left, values };\n}\n\n/** `left STARTS WITH $pN` */\nexport function startsWith(left: PropRef, substring: string): WherePredicate {\n return { kind: \"startsWith\", left, substring };\n}\n\n/** `left ENDS WITH $pN` */\nexport function endsWith(left: PropRef, substring: string): WherePredicate {\n return { kind: \"endsWith\", left, substring };\n}\n\n/** `left CONTAINS $pN` */\nexport function contains(left: PropRef, substring: string): WherePredicate {\n return { kind: \"contains\", left, substring };\n}\n\n/**\n * `left =~ $pN` — regular-expression match; the pattern is always a bound parameter.\n * Neo4j uses Java-compatible regex (see Cypher manual).\n */\nexport function matches(left: PropRef, pattern: string): WherePredicate {\n return { kind: \"matches\", left, pattern };\n}\n\nexport type OrderDirection = \"ASC\" | \"DESC\";\n\nexport type OrderByClause = {\n readonly prop: PropRef;\n readonly direction: OrderDirection;\n};\n\ntype Projection = \"star\" | Record<string, PropRef>;\n\n/**\n * `MATCH … OPTIONAL MATCH … WHERE … RETURN … ORDER BY … SKIP … LIMIT` builder (Cypher remains explicit in `match()` / `optionalMatch()`).\n * WHERE clauses are AND-combined; use {@link and} / {@link or} for explicit grouping.\n * Every bound value is a parameter except `IS NULL` / `IS NOT NULL`.\n */\nexport class SelectQuery {\n private matchPattern = \"\";\n private optionalPatterns: string[] = [];\n private predicates: WherePredicate[] = [];\n private projection: Projection | null = null;\n private returnDistinctFlag = false;\n private order: OrderByClause[] = [];\n private skipCount: number | null = null;\n private limitCount: number | null = null;\n\n /**\n * @param pattern - Full `MATCH` pattern body (e.g. from {@link NodeRef.out}).\n */\n match(pattern: string): this {\n this.matchPattern = pattern;\n return this;\n }\n\n /**\n * Append `OPTIONAL MATCH` after the primary {@link match} (same pattern string rules: full clause body only).\n *\n * @throws If {@link match} was not called yet.\n */\n optionalMatch(pattern: string): this {\n if (!this.matchPattern) {\n throw new Error(\"SelectQuery: call match() before optionalMatch()\");\n }\n this.optionalPatterns.push(pattern);\n return this;\n }\n\n /**\n * AND-combine predicates. When you pass more than one argument, any root-level {@link or}\n * is parenthesized so it is not parsed as `a OR (b AND c)`.\n */\n where(...preds: WherePredicate[]): this {\n this.predicates.push(...preds);\n return this;\n }\n\n /**\n * @param fields - Map of output alias → property reference.\n */\n returnFields(fields: Record<string, PropRef>): this {\n this.projection = fields;\n return this;\n }\n\n /** `RETURN *` (mutually exclusive with {@link returnFields} — last call wins). */\n returnStar(): this {\n this.projection = \"star\";\n return this;\n }\n\n /**\n * `RETURN DISTINCT …` — may be called before or after {@link returnFields} / {@link returnStar}\n * (projection must still be set before {@link toCypher}).\n */\n returnDistinct(): this {\n this.returnDistinctFlag = true;\n return this;\n }\n\n /**\n * Append `ORDER BY` clauses (direction is whitelisted, never from user strings).\n *\n * @param clauses - Property + ASC/DESC pairs.\n */\n orderBy(...clauses: OrderByClause[]): this {\n this.order.push(...clauses);\n return this;\n }\n\n /**\n * `SKIP` with a bound parameter.\n *\n * @param n - Number of rows to skip.\n */\n skip(n: number): this {\n if (!Number.isInteger(n) || n < 0) {\n throw new Error(\"SelectQuery.skip: n must be a non-negative integer\");\n }\n this.skipCount = n;\n return this;\n }\n\n /**\n * `LIMIT` with a bound parameter.\n *\n * @param n - Maximum rows.\n */\n limit(n: number): this {\n if (!Number.isInteger(n) || n < 0) {\n throw new Error(\"SelectQuery.limit: n must be a non-negative integer\");\n }\n this.limitCount = n;\n return this;\n }\n\n /** Generated Cypher and parameters (for debugging or execution). */\n toCypher(): CompiledCypher {\n if (!this.matchPattern) {\n throw new Error(\"SelectQuery: call match() before toCypher()\");\n }\n if (this.projection === null) {\n throw new Error(\"SelectQuery: call returnFields() or returnStar() before toCypher()\");\n }\n const params: Record<string, unknown> = {};\n let p = 0;\n const nextParam = (): string => {\n const key = `p${p++}`;\n return key;\n };\n const sink: ParamSink = { params, nextParam };\n\n let text = `MATCH ${this.matchPattern}`;\n for (const opt of this.optionalPatterns) {\n text += ` OPTIONAL MATCH ${opt}`;\n }\n if (this.predicates.length > 0) {\n // Multiple where() args are AND-combined; a bare OR at this level must stay grouped (Cypher: AND > OR).\n const parts =\n this.predicates.length === 1\n ? [emitPredicate(this.predicates[0]!, sink)]\n : this.predicates.map((pred) => emitUnderAnd(pred, sink));\n text += ` WHERE ${parts.join(\" AND \")}`;\n }\n const distinctKw = this.returnDistinctFlag ? \"DISTINCT \" : \"\";\n if (this.projection === \"star\") {\n text += ` RETURN ${distinctKw}*`;\n } else {\n const ret = Object.entries(this.projection)\n .map(([out, pr]) => `${pr.alias}.${pr.name} AS ${out}`)\n .join(\", \");\n text += ` RETURN ${distinctKw}${ret}`;\n }\n if (this.order.length > 0) {\n const ob = this.order.map((c) => `${c.prop.alias}.${c.prop.name} ${c.direction}`).join(\", \");\n text += ` ORDER BY ${ob}`;\n }\n if (this.skipCount !== null) {\n const key = nextParam();\n params[key] = this.skipCount;\n text += ` SKIP $${key}`;\n }\n if (this.limitCount !== null) {\n const key = nextParam();\n params[key] = this.limitCount;\n text += ` LIMIT $${key}`;\n }\n return { text, params };\n }\n}\n\n/** Start a fluent `MATCH` query. */\nexport function select(): SelectQuery {\n return new SelectQuery();\n}\n"],"mappings":";AAyBO,SAAS,cACd,SACA,QACgB;AAChB,MAAI,OAAO,WAAW,QAAQ,SAAS,GAAG;AACxC,UAAM,IAAI;AAAA,MACR,6BAA6B,QAAQ,SAAS,CAAC,6BAA6B,OAAO,MAAM;AAAA,IAC3F;AAAA,EACF;AACA,QAAM,SAAkC,CAAC;AACzC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,QAAQ,SAAS,GAAG,KAAK;AAC3C,YAAQ,QAAQ,CAAC;AACjB,UAAM,MAAM,IAAI,CAAC;AACjB,WAAO,GAAG,IAAI,OAAO,CAAC;AACtB,YAAQ,IAAI,GAAG;AAAA,EACjB;AACA,UAAQ,QAAQ,QAAQ,SAAS,CAAC;AAClC,SAAO,EAAE,M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her-first query utilities: template tag and minimal fluent builder for Cyphra",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^22.10.2",
24
+ "tsup": "^8.3.5",
25
+ "typescript": "^5.7.2",
26
+ "vitest": "^3.0.2"
27
+ },
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "typecheck": "tsc --noEmit",
31
+ "test": "vitest run"
32
+ }
33
+ }