@cyphra/runtime 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 +21 -0
- package/dist/index.d.ts +129 -0
- package/dist/index.js +163 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @cyphra/runtime
|
|
2
|
+
|
|
3
|
+
Neo4j driver wrapper for Cyphra: sessions, transactions, and safe execution of compiled Cypher.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { CyphraClient } from "@cyphra/runtime";
|
|
7
|
+
import { cypher } from "@cyphra/query";
|
|
8
|
+
|
|
9
|
+
const client = new CyphraClient({
|
|
10
|
+
uri: process.env.NEO4J_URI!,
|
|
11
|
+
user: process.env.NEO4J_USER!,
|
|
12
|
+
password: process.env.NEO4J_PASSWORD!,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
await client.withSession(async (session) => {
|
|
16
|
+
const res = await client.runCompiled(session, cypher`RETURN 1 AS n`);
|
|
17
|
+
console.log(res.records[0].get("n"));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await client.close();
|
|
21
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Config, Driver, Session, ManagedTransaction, Result, QueryResult } from 'neo4j-driver';
|
|
2
|
+
export { Config, Driver, ManagedTransaction, Session } from 'neo4j-driver';
|
|
3
|
+
import { CompiledCypher, SelectQuery } from '@cyphra/query';
|
|
4
|
+
|
|
5
|
+
type CyphraClientOptions = {
|
|
6
|
+
/** Bolt / Neo4j URI, e.g. `neo4j+s://xxx.databases.neo4j.io`. */
|
|
7
|
+
uri: string;
|
|
8
|
+
user: string;
|
|
9
|
+
password: string;
|
|
10
|
+
/** Optional database name (Neo4j 4+). */
|
|
11
|
+
database?: string;
|
|
12
|
+
/** When true, logs compiled Cypher and parameter keys (never values). */
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
/** Third argument to `neo4j.driver` — pool size, acquisition timeout, logging, etc. */
|
|
15
|
+
driverConfig?: Config;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Thin facade over `neo4j-driver`: sessions, transactions, and the Cyphra `cypher` tag.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const client = new CyphraClient({
|
|
23
|
+
* uri: process.env.NEO4J_URI!,
|
|
24
|
+
* user: process.env.NEO4J_USER!,
|
|
25
|
+
* password: process.env.NEO4J_PASSWORD!,
|
|
26
|
+
* });
|
|
27
|
+
* const session = client.session();
|
|
28
|
+
* try {
|
|
29
|
+
* import { cypher } from "@cyphra/query";
|
|
30
|
+
* await client.runCompiled(session, cypher`RETURN 1 AS n`);
|
|
31
|
+
* } finally {
|
|
32
|
+
* await session.close();
|
|
33
|
+
* }
|
|
34
|
+
* await client.close();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare class CyphraClient {
|
|
38
|
+
private readonly driver;
|
|
39
|
+
private readonly database?;
|
|
40
|
+
private readonly debug;
|
|
41
|
+
constructor(opts: CyphraClientOptions);
|
|
42
|
+
/** Underlying driver for advanced use. */
|
|
43
|
+
get rawDriver(): Driver;
|
|
44
|
+
/** Create a new session (caller must `close()`). */
|
|
45
|
+
session(): Session;
|
|
46
|
+
/**
|
|
47
|
+
* Run a compiled query. Parameter **values** are never logged when `debug` is on.
|
|
48
|
+
*/
|
|
49
|
+
runCompiled(session: Session, compiled: CompiledCypher): Promise<ReturnType<Session["run"]>>;
|
|
50
|
+
/**
|
|
51
|
+
* Like {@link runCompiled}, but on a managed transaction from {@link withWriteTransaction} /
|
|
52
|
+
* {@link withReadTransaction}.
|
|
53
|
+
*/
|
|
54
|
+
runCompiledTx(tx: ManagedTransaction, compiled: CompiledCypher): Promise<ReturnType<ManagedTransaction["run"]>>;
|
|
55
|
+
/**
|
|
56
|
+
* Tagged template executed on `tx` (values are parameterized).
|
|
57
|
+
*/
|
|
58
|
+
runCypherTx(tx: ManagedTransaction, strings: TemplateStringsArray, ...values: unknown[]): Promise<ReturnType<ManagedTransaction["run"]>>;
|
|
59
|
+
/**
|
|
60
|
+
* Tagged template executed on `session` (values are parameterized).
|
|
61
|
+
*
|
|
62
|
+
* @param session - Open Neo4j session.
|
|
63
|
+
* @param strings - Template literal static parts.
|
|
64
|
+
* @param values - Interpolated parameter values.
|
|
65
|
+
*/
|
|
66
|
+
runCypher(session: Session, strings: TemplateStringsArray, ...values: unknown[]): Promise<ReturnType<Session["run"]>>;
|
|
67
|
+
/**
|
|
68
|
+
* Run compiled Cypher and map rows to plain objects (`record.toObject()`).
|
|
69
|
+
*
|
|
70
|
+
* @param session - Open session.
|
|
71
|
+
* @param compiled - From {@link compileCypher}, {@link import("@cyphra/query").cypher}, or {@link SelectQuery.toCypher}.
|
|
72
|
+
*/
|
|
73
|
+
queryRecords(session: Session, compiled: CompiledCypher): Promise<Record<string, unknown>[]>;
|
|
74
|
+
/**
|
|
75
|
+
* First row as a plain object, or `undefined` if empty.
|
|
76
|
+
*
|
|
77
|
+
* @param session - Open session.
|
|
78
|
+
* @param compiled - Compiled query.
|
|
79
|
+
*/
|
|
80
|
+
queryRecord(session: Session, compiled: CompiledCypher): Promise<Record<string, unknown> | undefined>;
|
|
81
|
+
/** {@link queryRecords} on a managed transaction. */
|
|
82
|
+
queryRecordsTx(tx: ManagedTransaction, compiled: CompiledCypher): Promise<Record<string, unknown>[]>;
|
|
83
|
+
/** {@link queryRecord} on a managed transaction. */
|
|
84
|
+
queryRecordTx(tx: ManagedTransaction, compiled: CompiledCypher): Promise<Record<string, unknown> | undefined>;
|
|
85
|
+
/** Shorthand for {@link queryRecords} with a {@link SelectQuery}. */
|
|
86
|
+
selectRecords(session: Session, query: SelectQuery): Promise<Record<string, unknown>[]>;
|
|
87
|
+
/** Shorthand for {@link queryRecord} with a {@link SelectQuery}. */
|
|
88
|
+
selectRecord(session: Session, query: SelectQuery): Promise<Record<string, unknown> | undefined>;
|
|
89
|
+
/** {@link selectRecords} on a managed transaction. */
|
|
90
|
+
selectRecordsTx(tx: ManagedTransaction, query: SelectQuery): Promise<Record<string, unknown>[]>;
|
|
91
|
+
/** {@link selectRecord} on a managed transaction. */
|
|
92
|
+
selectRecordTx(tx: ManagedTransaction, query: SelectQuery): Promise<Record<string, unknown> | undefined>;
|
|
93
|
+
/** Open a session, run `fn`, always close the session. */
|
|
94
|
+
withSession<T>(fn: (session: Session) => Promise<T>): Promise<T>;
|
|
95
|
+
/**
|
|
96
|
+
* Execute work inside a write transaction.
|
|
97
|
+
*
|
|
98
|
+
* @param fn - Receives a managed transaction from the driver.
|
|
99
|
+
*/
|
|
100
|
+
withWriteTransaction<T>(fn: (tx: ManagedTransaction) => Promise<T>): Promise<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Execute work inside a read transaction.
|
|
103
|
+
*/
|
|
104
|
+
withReadTransaction<T>(fn: (tx: ManagedTransaction) => Promise<T>): Promise<T>;
|
|
105
|
+
/** Close the driver (call on shutdown). */
|
|
106
|
+
close(): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Consume a driver {@link Result} (or an already-awaited {@link QueryResult}) and map rows to plain objects.
|
|
111
|
+
*
|
|
112
|
+
* @param result - From `session.run` / {@link import("./client.js").CyphraClient.runCompiled} (awaited or not, depending on driver typings).
|
|
113
|
+
* @returns Plain objects keyed by Cypher return aliases.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const result = await client.runCompiled(session, cypher`RETURN 1 AS n`);
|
|
118
|
+
* const rows = await toPlainRecords(result);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function toPlainRecords(result: Result | QueryResult): Promise<Record<string, unknown>[]>;
|
|
122
|
+
/**
|
|
123
|
+
* First row as a plain object, or `undefined` if the result is empty.
|
|
124
|
+
*
|
|
125
|
+
* @param result - Driver result from `run` / `runCompiled`.
|
|
126
|
+
*/
|
|
127
|
+
declare function toPlainRecord(result: Result | QueryResult): Promise<Record<string, unknown> | undefined>;
|
|
128
|
+
|
|
129
|
+
export { CyphraClient, type CyphraClientOptions, toPlainRecord, toPlainRecords };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import neo4j from "neo4j-driver";
|
|
3
|
+
import { compileCypher } from "@cyphra/query";
|
|
4
|
+
|
|
5
|
+
// src/records.ts
|
|
6
|
+
async function toPlainRecords(result) {
|
|
7
|
+
const summary = await result;
|
|
8
|
+
return summary.records.map((r) => r.toObject());
|
|
9
|
+
}
|
|
10
|
+
async function toPlainRecord(result) {
|
|
11
|
+
const rows = await toPlainRecords(result);
|
|
12
|
+
return rows[0];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/client.ts
|
|
16
|
+
var CyphraClient = class {
|
|
17
|
+
driver;
|
|
18
|
+
database;
|
|
19
|
+
debug;
|
|
20
|
+
constructor(opts) {
|
|
21
|
+
this.driver = neo4j.driver(
|
|
22
|
+
opts.uri,
|
|
23
|
+
neo4j.auth.basic(opts.user, opts.password),
|
|
24
|
+
opts.driverConfig
|
|
25
|
+
);
|
|
26
|
+
this.database = opts.database;
|
|
27
|
+
this.debug = opts.debug ?? false;
|
|
28
|
+
}
|
|
29
|
+
/** Underlying driver for advanced use. */
|
|
30
|
+
get rawDriver() {
|
|
31
|
+
return this.driver;
|
|
32
|
+
}
|
|
33
|
+
/** Create a new session (caller must `close()`). */
|
|
34
|
+
session() {
|
|
35
|
+
return this.driver.session({ database: this.database });
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Run a compiled query. Parameter **values** are never logged when `debug` is on.
|
|
39
|
+
*/
|
|
40
|
+
async runCompiled(session, compiled) {
|
|
41
|
+
if (this.debug) {
|
|
42
|
+
console.debug("[cyphra] cypher:", compiled.text, "param keys:", Object.keys(compiled.params));
|
|
43
|
+
}
|
|
44
|
+
return session.run(compiled.text, compiled.params);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Like {@link runCompiled}, but on a managed transaction from {@link withWriteTransaction} /
|
|
48
|
+
* {@link withReadTransaction}.
|
|
49
|
+
*/
|
|
50
|
+
async runCompiledTx(tx, compiled) {
|
|
51
|
+
if (this.debug) {
|
|
52
|
+
console.debug("[cyphra] cypher:", compiled.text, "param keys:", Object.keys(compiled.params));
|
|
53
|
+
}
|
|
54
|
+
return tx.run(compiled.text, compiled.params);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Tagged template executed on `tx` (values are parameterized).
|
|
58
|
+
*/
|
|
59
|
+
async runCypherTx(tx, strings, ...values) {
|
|
60
|
+
const compiled = compileCypher(strings, values);
|
|
61
|
+
return this.runCompiledTx(tx, compiled);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Tagged template executed on `session` (values are parameterized).
|
|
65
|
+
*
|
|
66
|
+
* @param session - Open Neo4j session.
|
|
67
|
+
* @param strings - Template literal static parts.
|
|
68
|
+
* @param values - Interpolated parameter values.
|
|
69
|
+
*/
|
|
70
|
+
async runCypher(session, strings, ...values) {
|
|
71
|
+
const compiled = compileCypher(strings, values);
|
|
72
|
+
return this.runCompiled(session, compiled);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Run compiled Cypher and map rows to plain objects (`record.toObject()`).
|
|
76
|
+
*
|
|
77
|
+
* @param session - Open session.
|
|
78
|
+
* @param compiled - From {@link compileCypher}, {@link import("@cyphra/query").cypher}, or {@link SelectQuery.toCypher}.
|
|
79
|
+
*/
|
|
80
|
+
async queryRecords(session, compiled) {
|
|
81
|
+
const result = await this.runCompiled(session, compiled);
|
|
82
|
+
return toPlainRecords(result);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* First row as a plain object, or `undefined` if empty.
|
|
86
|
+
*
|
|
87
|
+
* @param session - Open session.
|
|
88
|
+
* @param compiled - Compiled query.
|
|
89
|
+
*/
|
|
90
|
+
async queryRecord(session, compiled) {
|
|
91
|
+
const result = await this.runCompiled(session, compiled);
|
|
92
|
+
return toPlainRecord(result);
|
|
93
|
+
}
|
|
94
|
+
/** {@link queryRecords} on a managed transaction. */
|
|
95
|
+
async queryRecordsTx(tx, compiled) {
|
|
96
|
+
const result = await this.runCompiledTx(tx, compiled);
|
|
97
|
+
return toPlainRecords(result);
|
|
98
|
+
}
|
|
99
|
+
/** {@link queryRecord} on a managed transaction. */
|
|
100
|
+
async queryRecordTx(tx, compiled) {
|
|
101
|
+
const result = await this.runCompiledTx(tx, compiled);
|
|
102
|
+
return toPlainRecord(result);
|
|
103
|
+
}
|
|
104
|
+
/** Shorthand for {@link queryRecords} with a {@link SelectQuery}. */
|
|
105
|
+
async selectRecords(session, query) {
|
|
106
|
+
return this.queryRecords(session, query.toCypher());
|
|
107
|
+
}
|
|
108
|
+
/** Shorthand for {@link queryRecord} with a {@link SelectQuery}. */
|
|
109
|
+
async selectRecord(session, query) {
|
|
110
|
+
return this.queryRecord(session, query.toCypher());
|
|
111
|
+
}
|
|
112
|
+
/** {@link selectRecords} on a managed transaction. */
|
|
113
|
+
async selectRecordsTx(tx, query) {
|
|
114
|
+
return this.queryRecordsTx(tx, query.toCypher());
|
|
115
|
+
}
|
|
116
|
+
/** {@link selectRecord} on a managed transaction. */
|
|
117
|
+
async selectRecordTx(tx, query) {
|
|
118
|
+
return this.queryRecordTx(tx, query.toCypher());
|
|
119
|
+
}
|
|
120
|
+
/** Open a session, run `fn`, always close the session. */
|
|
121
|
+
async withSession(fn) {
|
|
122
|
+
const session = this.session();
|
|
123
|
+
try {
|
|
124
|
+
return await fn(session);
|
|
125
|
+
} finally {
|
|
126
|
+
await session.close();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Execute work inside a write transaction.
|
|
131
|
+
*
|
|
132
|
+
* @param fn - Receives a managed transaction from the driver.
|
|
133
|
+
*/
|
|
134
|
+
async withWriteTransaction(fn) {
|
|
135
|
+
const session = this.session();
|
|
136
|
+
try {
|
|
137
|
+
return await session.executeWrite(fn);
|
|
138
|
+
} finally {
|
|
139
|
+
await session.close();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Execute work inside a read transaction.
|
|
144
|
+
*/
|
|
145
|
+
async withReadTransaction(fn) {
|
|
146
|
+
const session = this.session();
|
|
147
|
+
try {
|
|
148
|
+
return await session.executeRead(fn);
|
|
149
|
+
} finally {
|
|
150
|
+
await session.close();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Close the driver (call on shutdown). */
|
|
154
|
+
async close() {
|
|
155
|
+
await this.driver.close();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
export {
|
|
159
|
+
CyphraClient,
|
|
160
|
+
toPlainRecord,
|
|
161
|
+
toPlainRecords
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/records.ts"],"sourcesContent":["import neo4j, {\n type Config,\n type Driver,\n type ManagedTransaction,\n type Session,\n} from \"neo4j-driver\";\nimport { compileCypher, type CompiledCypher, type SelectQuery } from \"@cyphra/query\";\nimport { toPlainRecord, toPlainRecords } from \"./records.js\";\n\nexport type CyphraClientOptions = {\n /** Bolt / Neo4j URI, e.g. `neo4j+s://xxx.databases.neo4j.io`. */\n uri: string;\n user: string;\n password: string;\n /** Optional database name (Neo4j 4+). */\n database?: string;\n /** When true, logs compiled Cypher and parameter keys (never values). */\n debug?: boolean;\n /** Third argument to `neo4j.driver` — pool size, acquisition timeout, logging, etc. */\n driverConfig?: Config;\n};\n\n/**\n * Thin facade over `neo4j-driver`: sessions, transactions, and the Cyphra `cypher` tag.\n *\n * @example\n * ```ts\n * const client = new CyphraClient({\n * uri: process.env.NEO4J_URI!,\n * user: process.env.NEO4J_USER!,\n * password: process.env.NEO4J_PASSWORD!,\n * });\n * const session = client.session();\n * try {\n * import { cypher } from \"@cyphra/query\";\n * await client.runCompiled(session, cypher`RETURN 1 AS n`);\n * } finally {\n * await session.close();\n * }\n * await client.close();\n * ```\n */\nexport class CyphraClient {\n private readonly driver: Driver;\n private readonly database?: string;\n private readonly debug: boolean;\n\n constructor(opts: CyphraClientOptions) {\n this.driver = neo4j.driver(\n opts.uri,\n neo4j.auth.basic(opts.user, opts.password),\n opts.driverConfig,\n );\n this.database = opts.database;\n this.debug = opts.debug ?? false;\n }\n\n /** Underlying driver for advanced use. */\n get rawDriver(): Driver {\n return this.driver;\n }\n\n /** Create a new session (caller must `close()`). */\n session(): Session {\n return this.driver.session({ database: this.database });\n }\n\n /**\n * Run a compiled query. Parameter **values** are never logged when `debug` is on.\n */\n async runCompiled(\n session: Session,\n compiled: CompiledCypher,\n ): Promise<ReturnType<Session[\"run\"]>> {\n if (this.debug) {\n console.debug(\"[cyphra] cypher:\", compiled.text, \"param keys:\", Object.keys(compiled.params));\n }\n return session.run(compiled.text, compiled.params);\n }\n\n /**\n * Like {@link runCompiled}, but on a managed transaction from {@link withWriteTransaction} /\n * {@link withReadTransaction}.\n */\n async runCompiledTx(\n tx: ManagedTransaction,\n compiled: CompiledCypher,\n ): Promise<ReturnType<ManagedTransaction[\"run\"]>> {\n if (this.debug) {\n console.debug(\"[cyphra] cypher:\", compiled.text, \"param keys:\", Object.keys(compiled.params));\n }\n return tx.run(compiled.text, compiled.params);\n }\n\n /**\n * Tagged template executed on `tx` (values are parameterized).\n */\n async runCypherTx(\n tx: ManagedTransaction,\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): Promise<ReturnType<ManagedTransaction[\"run\"]>> {\n const compiled = compileCypher(strings, values);\n return this.runCompiledTx(tx, compiled);\n }\n\n /**\n * Tagged template executed on `session` (values are parameterized).\n *\n * @param session - Open Neo4j session.\n * @param strings - Template literal static parts.\n * @param values - Interpolated parameter values.\n */\n async runCypher(\n session: Session,\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): Promise<ReturnType<Session[\"run\"]>> {\n const compiled = compileCypher(strings, values);\n return this.runCompiled(session, compiled);\n }\n\n /**\n * Run compiled Cypher and map rows to plain objects (`record.toObject()`).\n *\n * @param session - Open session.\n * @param compiled - From {@link compileCypher}, {@link import(\"@cyphra/query\").cypher}, or {@link SelectQuery.toCypher}.\n */\n async queryRecords(\n session: Session,\n compiled: CompiledCypher,\n ): Promise<Record<string, unknown>[]> {\n const result = await this.runCompiled(session, compiled);\n return toPlainRecords(result);\n }\n\n /**\n * First row as a plain object, or `undefined` if empty.\n *\n * @param session - Open session.\n * @param compiled - Compiled query.\n */\n async queryRecord(\n session: Session,\n compiled: CompiledCypher,\n ): Promise<Record<string, unknown> | undefined> {\n const result = await this.runCompiled(session, compiled);\n return toPlainRecord(result);\n }\n\n /** {@link queryRecords} on a managed transaction. */\n async queryRecordsTx(\n tx: ManagedTransaction,\n compiled: CompiledCypher,\n ): Promise<Record<string, unknown>[]> {\n const result = await this.runCompiledTx(tx, compiled);\n return toPlainRecords(result);\n }\n\n /** {@link queryRecord} on a managed transaction. */\n async queryRecordTx(\n tx: ManagedTransaction,\n compiled: CompiledCypher,\n ): Promise<Record<string, unknown> | undefined> {\n const result = await this.runCompiledTx(tx, compiled);\n return toPlainRecord(result);\n }\n\n /** Shorthand for {@link queryRecords} with a {@link SelectQuery}. */\n async selectRecords(session: Session, query: SelectQuery): Promise<Record<string, unknown>[]> {\n return this.queryRecords(session, query.toCypher());\n }\n\n /** Shorthand for {@link queryRecord} with a {@link SelectQuery}. */\n async selectRecord(\n session: Session,\n query: SelectQuery,\n ): Promise<Record<string, unknown> | undefined> {\n return this.queryRecord(session, query.toCypher());\n }\n\n /** {@link selectRecords} on a managed transaction. */\n async selectRecordsTx(\n tx: ManagedTransaction,\n query: SelectQuery,\n ): Promise<Record<string, unknown>[]> {\n return this.queryRecordsTx(tx, query.toCypher());\n }\n\n /** {@link selectRecord} on a managed transaction. */\n async selectRecordTx(\n tx: ManagedTransaction,\n query: SelectQuery,\n ): Promise<Record<string, unknown> | undefined> {\n return this.queryRecordTx(tx, query.toCypher());\n }\n\n /** Open a session, run `fn`, always close the session. */\n async withSession<T>(fn: (session: Session) => Promise<T>): Promise<T> {\n const session = this.session();\n try {\n return await fn(session);\n } finally {\n await session.close();\n }\n }\n\n /**\n * Execute work inside a write transaction.\n *\n * @param fn - Receives a managed transaction from the driver.\n */\n async withWriteTransaction<T>(fn: (tx: ManagedTransaction) => Promise<T>): Promise<T> {\n const session = this.session();\n try {\n return await session.executeWrite(fn);\n } finally {\n await session.close();\n }\n }\n\n /**\n * Execute work inside a read transaction.\n */\n async withReadTransaction<T>(fn: (tx: ManagedTransaction) => Promise<T>): Promise<T> {\n const session = this.session();\n try {\n return await session.executeRead(fn);\n } finally {\n await session.close();\n }\n }\n\n /** Close the driver (call on shutdown). */\n async close(): Promise<void> {\n await this.driver.close();\n }\n}\n\nexport type { Config, Driver, ManagedTransaction, Session };\n","import type { Record as Neo4jRecord, QueryResult, Result } from \"neo4j-driver\";\n\n/**\n * Consume a driver {@link Result} (or an already-awaited {@link QueryResult}) and map rows to plain objects.\n *\n * @param result - From `session.run` / {@link import(\"./client.js\").CyphraClient.runCompiled} (awaited or not, depending on driver typings).\n * @returns Plain objects keyed by Cypher return aliases.\n *\n * @example\n * ```ts\n * const result = await client.runCompiled(session, cypher`RETURN 1 AS n`);\n * const rows = await toPlainRecords(result);\n * ```\n */\nexport async function toPlainRecords(\n result: Result | QueryResult,\n): Promise<Record<string, unknown>[]> {\n const summary = (await (result as PromiseLike<QueryResult>)) as QueryResult;\n return summary.records.map((r: Neo4jRecord) => r.toObject());\n}\n\n/**\n * First row as a plain object, or `undefined` if the result is empty.\n *\n * @param result - Driver result from `run` / `runCompiled`.\n */\nexport async function toPlainRecord(\n result: Result | QueryResult,\n): Promise<Record<string, unknown> | undefined> {\n const rows = await toPlainRecords(result);\n return rows[0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AChD;AAAA;AAAA,EAGA,MAAM,YAAe,IAAkD;AACrE,UAAM,UAAU,KAAK,QAAQ;AAC7B,QAAI;AACF,aAAO,MAAM,GAAG,OAAO;AAAA,IACzB,UAAE;AACA,YAAM,QAAQ,MAAM;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,qBAAwB,IAAwD;AACpF,UAAM,UAAU,KAAK,QAAQ;AAC7B,QAAI;AACF,aAAO,MAAM,QAAQ,aAAa,EAAE;AAAA,IACtC,UAAE;AACA,YAAM,QAAQ,MAAM;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,oBAAuB,IAAwD;AACnF,UAAM,UAAU,KAAK,QAAQ;AAC7B,QAAI;AACF,aAAO,MAAM,QAAQ,YAAY,EAAE;AAAA,IACrC,UAAE;AACA,YAAM,QAAQ,MAAM;AAAA,IACtB;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,QAAuB;AAC3B,UAAM,KAAK,OAAO,MAAM;AAAA,EAC1B;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cyphra/runtime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Neo4j execution layer for Cyphra: sessions, transactions, and cypher tag",
|
|
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
|
+
"dependencies": {
|
|
23
|
+
"neo4j-driver": "^5.27.0",
|
|
24
|
+
"@cyphra/query": "0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.10.2",
|
|
28
|
+
"tsup": "^8.3.5",
|
|
29
|
+
"typescript": "^5.7.2",
|
|
30
|
+
"vitest": "^3.0.2"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|