tina4-nodejs 3.13.110 → 3.13.111

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.
@@ -16917,6 +16917,775 @@ var init_docstore = __esm({
16917
16917
  }
16918
16918
  });
16919
16919
 
16920
+ // ../orm/src/graph/graphUrl.ts
16921
+ var SCHEME_ENGINE, ENGINE_DEFAULT_PORT, GraphUrl;
16922
+ var init_graphUrl = __esm({
16923
+ "../orm/src/graph/graphUrl.ts"() {
16924
+ "use strict";
16925
+ SCHEME_ENGINE = {
16926
+ ultipa: "ultipa",
16927
+ ultipas: "ultipa",
16928
+ // TLS variant
16929
+ neo4j: "bolt",
16930
+ "neo4j+s": "bolt",
16931
+ bolt: "bolt",
16932
+ "bolt+s": "bolt",
16933
+ memgraph: "bolt",
16934
+ arango: "arango",
16935
+ arangodb: "arango"
16936
+ };
16937
+ ENGINE_DEFAULT_PORT = {
16938
+ ultipa: 60061,
16939
+ bolt: 7687,
16940
+ arango: 8529
16941
+ };
16942
+ GraphUrl = class _GraphUrl {
16943
+ raw;
16944
+ scheme;
16945
+ engine;
16946
+ host;
16947
+ port;
16948
+ /** The graph/database name (leading slash stripped), or null when absent. */
16949
+ graph;
16950
+ username;
16951
+ password;
16952
+ params;
16953
+ useTls;
16954
+ constructor(url) {
16955
+ this.raw = url;
16956
+ let parsed;
16957
+ try {
16958
+ parsed = new URL(url);
16959
+ } catch {
16960
+ throw new Error(
16961
+ `Unsupported graph URL '${url}' \u2014 expected scheme://[user[:password]@]host[:port]/graph (e.g. ultipa://host:60061/mygraph).`
16962
+ );
16963
+ }
16964
+ const scheme = parsed.protocol.replace(/:$/, "").toLowerCase();
16965
+ const engine = SCHEME_ENGINE[scheme];
16966
+ if (engine === void 0) {
16967
+ throw new Error(
16968
+ `Unsupported graph URL scheme '${scheme}'. Supported: ${Object.keys(SCHEME_ENGINE).sort().join(", ")} (e.g. ultipa://host:60061/mygraph).`
16969
+ );
16970
+ }
16971
+ this.scheme = scheme;
16972
+ this.engine = engine;
16973
+ this.host = parsed.hostname || "localhost";
16974
+ this.port = parsed.port ? parseInt(parsed.port, 10) : ENGINE_DEFAULT_PORT[engine];
16975
+ const path8 = (parsed.pathname || "").replace(/^\//, "");
16976
+ this.graph = path8 === "" ? null : path8;
16977
+ this.username = parsed.username ? decodeURIComponent(parsed.username) : null;
16978
+ this.password = parsed.password ? decodeURIComponent(parsed.password) : null;
16979
+ this.params = {};
16980
+ for (const [key, value] of parsed.searchParams) {
16981
+ if (!(key in this.params)) this.params[key] = value;
16982
+ }
16983
+ this.useTls = scheme.endsWith("s") || this.params.tls === "1" || this.params.tls === "true";
16984
+ }
16985
+ /** host:port/graph — for messages, never carrying credentials. */
16986
+ getDsn() {
16987
+ const target = this.port ? `${this.host}:${this.port}` : this.host;
16988
+ return this.graph ? `${target}/${this.graph}` : target;
16989
+ }
16990
+ static fromEnv(envKey = "TINA4_GRAPH_URL") {
16991
+ const url = (process.env[envKey] ?? "").trim();
16992
+ return url === "" ? null : new _GraphUrl(url);
16993
+ }
16994
+ };
16995
+ }
16996
+ });
16997
+
16998
+ // ../orm/src/graph/errors.ts
16999
+ var GraphError, GraphConnectTimeout;
17000
+ var init_errors = __esm({
17001
+ "../orm/src/graph/errors.ts"() {
17002
+ "use strict";
17003
+ GraphError = class extends Error {
17004
+ constructor(message, cause) {
17005
+ super(message, cause === void 0 ? void 0 : { cause });
17006
+ this.name = "GraphError";
17007
+ }
17008
+ };
17009
+ GraphConnectTimeout = class extends GraphError {
17010
+ constructor(message, cause) {
17011
+ super(message, cause);
17012
+ this.name = "GraphConnectTimeout";
17013
+ }
17014
+ };
17015
+ }
17016
+ });
17017
+
17018
+ // ../orm/src/graph/shapes.ts
17019
+ var GraphNode, GraphEdge, GraphResult;
17020
+ var init_shapes = __esm({
17021
+ "../orm/src/graph/shapes.ts"() {
17022
+ "use strict";
17023
+ GraphNode = class {
17024
+ id;
17025
+ labels;
17026
+ properties;
17027
+ constructor(id, labels = null, properties = null) {
17028
+ this.id = id;
17029
+ this.labels = [...labels ?? []];
17030
+ this.properties = { ...properties ?? {} };
17031
+ }
17032
+ toDict() {
17033
+ return { id: this.id, labels: this.labels, properties: this.properties };
17034
+ }
17035
+ };
17036
+ GraphEdge = class {
17037
+ id;
17038
+ type;
17039
+ from;
17040
+ to;
17041
+ properties;
17042
+ constructor(id, type2, from, to, properties = null) {
17043
+ this.id = id;
17044
+ this.type = type2;
17045
+ this.from = from;
17046
+ this.to = to;
17047
+ this.properties = { ...properties ?? {} };
17048
+ }
17049
+ toDict() {
17050
+ return {
17051
+ id: this.id,
17052
+ type: this.type,
17053
+ from: this.from,
17054
+ to: this.to,
17055
+ properties: this.properties
17056
+ };
17057
+ }
17058
+ };
17059
+ GraphResult = class {
17060
+ records;
17061
+ columns;
17062
+ constructor(records = null, columns = null) {
17063
+ this.records = [...records ?? []];
17064
+ this.columns = [...columns ?? []];
17065
+ }
17066
+ toArray() {
17067
+ return this.records;
17068
+ }
17069
+ /** The first value of the first record, or null. */
17070
+ scalar() {
17071
+ if (this.records.length === 0) return null;
17072
+ const values = Object.values(this.records[0]);
17073
+ return values.length ? values[0] : null;
17074
+ }
17075
+ [Symbol.iterator]() {
17076
+ return this.records[Symbol.iterator]();
17077
+ }
17078
+ get length() {
17079
+ return this.records.length;
17080
+ }
17081
+ };
17082
+ }
17083
+ });
17084
+
17085
+ // ../orm/src/graph/connectTimeout.ts
17086
+ function resolveGraphConnectTimeout() {
17087
+ const raw = (process.env[GRAPH_CONNECT_TIMEOUT_VARIABLE] ?? "").trim();
17088
+ if (raw === "") {
17089
+ return DEFAULT_GRAPH_CONNECT_TIMEOUT_SECONDS;
17090
+ }
17091
+ const seconds = Number(raw);
17092
+ if (!Number.isFinite(seconds)) {
17093
+ Log.warning(
17094
+ `${GRAPH_CONNECT_TIMEOUT_VARIABLE}="${raw}" is not a number of seconds \u2014 bounding graph connects at the ${DEFAULT_GRAPH_CONNECT_TIMEOUT_SECONDS}s default instead`
17095
+ );
17096
+ return DEFAULT_GRAPH_CONNECT_TIMEOUT_SECONDS;
17097
+ }
17098
+ return seconds <= 0 ? null : seconds;
17099
+ }
17100
+ var GRAPH_CONNECT_TIMEOUT_VARIABLE, DEFAULT_GRAPH_CONNECT_TIMEOUT_SECONDS;
17101
+ var init_connectTimeout2 = __esm({
17102
+ "../orm/src/graph/connectTimeout.ts"() {
17103
+ "use strict";
17104
+ init_index();
17105
+ GRAPH_CONNECT_TIMEOUT_VARIABLE = "TINA4_GRAPH_CONNECT_TIMEOUT";
17106
+ DEFAULT_GRAPH_CONNECT_TIMEOUT_SECONDS = 10;
17107
+ }
17108
+ });
17109
+
17110
+ // ../orm/src/graph/adapters/ultipa.ts
17111
+ var ultipa_exports = {};
17112
+ __export(ultipa_exports, {
17113
+ UltipaGraphAdapter: () => UltipaGraphAdapter
17114
+ });
17115
+ function propClause(properties) {
17116
+ const props = properties ?? {};
17117
+ const keys = Object.keys(props);
17118
+ if (keys.length === 0) return { clause: "{}", params: {} };
17119
+ const pairs = keys.map((key) => `${key}: $p_${key}`).join(", ");
17120
+ const params = {};
17121
+ for (const key of keys) params[`p_${key}`] = props[key];
17122
+ return { clause: `{${pairs}}`, params };
17123
+ }
17124
+ function errorMessage(exc) {
17125
+ if (exc instanceof Error) return exc.message;
17126
+ return String(exc);
17127
+ }
17128
+ var DRIVER_PACKAGE, driver, UltipaClient, UltipaConnectError, UNBOUNDED_CONNECT_SECONDS, UltipaGraphAdapter;
17129
+ var init_ultipa = __esm({
17130
+ async "../orm/src/graph/adapters/ultipa.ts"() {
17131
+ "use strict";
17132
+ init_shapes();
17133
+ init_errors();
17134
+ init_connectTimeout2();
17135
+ DRIVER_PACKAGE = "tina4-ultipa";
17136
+ driver = await import(DRIVER_PACKAGE);
17137
+ UltipaClient = driver.UltipaClient;
17138
+ UltipaConnectError = driver.UltipaConnectError;
17139
+ UNBOUNDED_CONNECT_SECONDS = 31536e4;
17140
+ UltipaGraphAdapter = class {
17141
+ url;
17142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17143
+ client;
17144
+ lastError = null;
17145
+ constructor(graphUrl, credentials = {}) {
17146
+ this.url = graphUrl;
17147
+ const timeout = resolveGraphConnectTimeout();
17148
+ this.client = new UltipaClient({
17149
+ host: graphUrl.host,
17150
+ port: graphUrl.port,
17151
+ username: graphUrl.username || credentials.username || null,
17152
+ password: graphUrl.password || credentials.password || null,
17153
+ graph: graphUrl.graph,
17154
+ connectTimeout: timeout ?? UNBOUNDED_CONNECT_SECONDS,
17155
+ useTls: graphUrl.useTls
17156
+ });
17157
+ }
17158
+ // -- connection + raw pass-through -------------------------------------
17159
+ async run(gql, params = null, readOnly = true) {
17160
+ try {
17161
+ await this.client.connect();
17162
+ } catch (exc) {
17163
+ this.lastError = errorMessage(exc);
17164
+ if (exc instanceof UltipaConnectError || exc?.name === "UltipaConnectError") {
17165
+ const elapsed = typeof exc?.elapsed === "number" ? exc.elapsed : 0;
17166
+ throw new GraphConnectTimeout(
17167
+ `Graph connect to ${this.url.host}:${this.url.port} timed out after ${elapsed.toFixed(1)}s (${GRAPH_CONNECT_TIMEOUT_VARIABLE}). Raise ${GRAPH_CONNECT_TIMEOUT_VARIABLE} if the server is simply slow, or set it to 0 to wait indefinitely.`,
17168
+ exc
17169
+ );
17170
+ }
17171
+ throw new GraphError(this.lastError, exc);
17172
+ }
17173
+ try {
17174
+ return await this.client.query(gql, { params: params ?? null, readOnly });
17175
+ } catch (exc) {
17176
+ this.lastError = errorMessage(exc);
17177
+ throw new GraphError(this.lastError, exc);
17178
+ }
17179
+ }
17180
+ async query(text, params = null) {
17181
+ const result = await this.run(text, params, true);
17182
+ return new GraphResult(result.dicts(), result.columns);
17183
+ }
17184
+ async execute(text, params = null) {
17185
+ const result = await this.run(text, params, false);
17186
+ return new GraphResult(result.dicts(), result.columns);
17187
+ }
17188
+ // -- portable node/edge/traverse core (GQL) ----------------------------
17189
+ nodeFromRow(row) {
17190
+ if (row === null || row === void 0) return null;
17191
+ return new GraphNode(
17192
+ String(row.id),
17193
+ row.labels ?? [],
17194
+ row.props ?? {}
17195
+ );
17196
+ }
17197
+ async addNode(label, properties = null) {
17198
+ const { clause, params } = propClause(properties);
17199
+ const gql = `INSERT (n:\`${label}\` ${clause}) RETURN id(n) AS id, labels(n) AS labels, properties(n) AS props`;
17200
+ const rows = (await this.run(gql, params, false)).dicts();
17201
+ return rows.length ? this.nodeFromRow(rows[0]) : null;
17202
+ }
17203
+ async addEdge(fromId, toId, type2, properties = null) {
17204
+ const { clause, params } = propClause(properties);
17205
+ params.from_id = fromId;
17206
+ params.to_id = toId;
17207
+ const gql = `MATCH (a), (b) WHERE id(a) = $from_id AND id(b) = $to_id INSERT (a)-[e:\`${type2}\` ${clause}]->(b) RETURN id(e) AS id, type(e) AS type, id(a) AS f, id(b) AS t, properties(e) AS props`;
17208
+ const rows = (await this.run(gql, params, false)).dicts();
17209
+ if (rows.length === 0) return null;
17210
+ const row = rows[0];
17211
+ return new GraphEdge(
17212
+ String(row.id),
17213
+ String(row.type),
17214
+ String(row.f),
17215
+ String(row.t),
17216
+ row.props ?? {}
17217
+ );
17218
+ }
17219
+ async getNode(nodeId) {
17220
+ const gql = `MATCH (n) WHERE id(n) = $id RETURN id(n) AS id, labels(n) AS labels, properties(n) AS props`;
17221
+ const rows = (await this.run(gql, { id: nodeId }, true)).dicts();
17222
+ return rows.length ? this.nodeFromRow(rows[0]) : null;
17223
+ }
17224
+ async updateNode(nodeId, properties) {
17225
+ const props = properties ?? {};
17226
+ const keys = Object.keys(props);
17227
+ const sets = keys.map((key) => `n.${key} = $p_${key}`).join(", ");
17228
+ const params = { id: nodeId };
17229
+ for (const key of keys) params[`p_${key}`] = props[key];
17230
+ const gql = `MATCH (n) WHERE id(n) = $id SET ${sets} RETURN id(n) AS id, labels(n) AS labels, properties(n) AS props`;
17231
+ const rows = (await this.run(gql, params, false)).dicts();
17232
+ return rows.length ? this.nodeFromRow(rows[0]) : null;
17233
+ }
17234
+ async deleteNode(nodeId) {
17235
+ const gql = "MATCH (n) WHERE id(n) = $id DETACH DELETE n";
17236
+ await this.run(gql, { id: nodeId }, false);
17237
+ return true;
17238
+ }
17239
+ async neighbors(nodeId, options = {}) {
17240
+ const direction = options.direction ?? "both";
17241
+ const limit = options.limit ?? 100;
17242
+ const edge = options.edgeType ? `:\`${options.edgeType}\`` : "";
17243
+ const pattern = {
17244
+ out: `(n)-[${edge}]->(m)`,
17245
+ in: `(n)<-[${edge}]-(m)`,
17246
+ both: `(n)-[${edge}]-(m)`
17247
+ }[direction];
17248
+ const gql = `MATCH ${pattern} WHERE id(n) = $id RETURN DISTINCT id(m) AS id, labels(m) AS labels, properties(m) AS props LIMIT ${Math.trunc(limit)}`;
17249
+ const rows = (await this.run(gql, { id: nodeId }, true)).dicts();
17250
+ return rows.map((row) => this.nodeFromRow(row)).filter((node) => node !== null);
17251
+ }
17252
+ async traverse(startId, options = {}) {
17253
+ const depth = options.depth ?? 1;
17254
+ const direction = options.direction ?? "both";
17255
+ const limit = options.limit ?? 1e3;
17256
+ const edge = options.edgeType ? `:\`${options.edgeType}\`` : "";
17257
+ const quant = `{1,${Math.trunc(depth)}}`;
17258
+ const pattern = {
17259
+ out: `(n)-[${edge}]->${quant}(m)`,
17260
+ in: `(n)<-[${edge}]-${quant}(m)`,
17261
+ both: `(n)-[${edge}]-${quant}(m)`
17262
+ }[direction];
17263
+ const gql = `MATCH ${pattern} WHERE id(n) = $start RETURN DISTINCT id(m) AS id, labels(m) AS labels, properties(m) AS props LIMIT ${Math.trunc(limit)}`;
17264
+ const rows = (await this.run(gql, { start: startId }, true)).dicts();
17265
+ return rows.map((row) => this.nodeFromRow(row)).filter((node) => node !== null);
17266
+ }
17267
+ close() {
17268
+ this.client.close();
17269
+ }
17270
+ getError() {
17271
+ return this.lastError;
17272
+ }
17273
+ };
17274
+ }
17275
+ });
17276
+
17277
+ // ../orm/src/graph/adapters/bolt.ts
17278
+ var bolt_exports = {};
17279
+ __export(bolt_exports, {
17280
+ BoltGraphAdapter: () => BoltGraphAdapter
17281
+ });
17282
+ function errorMessage2(exc) {
17283
+ if (exc instanceof Error) return exc.message;
17284
+ return String(exc);
17285
+ }
17286
+ function boltId(id) {
17287
+ const value = Number(id);
17288
+ return Number.isNaN(value) ? -1 : value;
17289
+ }
17290
+ var DRIVER_PACKAGE2, driverModule, neo4j, BoltGraphAdapter;
17291
+ var init_bolt = __esm({
17292
+ async "../orm/src/graph/adapters/bolt.ts"() {
17293
+ "use strict";
17294
+ init_shapes();
17295
+ init_errors();
17296
+ init_connectTimeout2();
17297
+ DRIVER_PACKAGE2 = "neo4j-driver";
17298
+ driverModule = await import(DRIVER_PACKAGE2);
17299
+ neo4j = driverModule.default ?? driverModule;
17300
+ BoltGraphAdapter = class {
17301
+ url;
17302
+ database;
17303
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17304
+ driver;
17305
+ lastError = null;
17306
+ constructor(graphUrl, credentials = {}) {
17307
+ this.url = graphUrl;
17308
+ this.database = graphUrl.graph || null;
17309
+ const user = graphUrl.username || credentials.username || "neo4j";
17310
+ const pwd = graphUrl.password || credentials.password || "";
17311
+ const scheme = graphUrl.useTls ? "bolt+s" : "bolt";
17312
+ const uri = `${scheme}://${graphUrl.host}:${graphUrl.port}`;
17313
+ const timeout = resolveGraphConnectTimeout();
17314
+ const config = { disableLosslessIntegers: true };
17315
+ if (timeout !== null) {
17316
+ const ms = Math.max(1, Math.ceil(timeout * 1e3));
17317
+ config.connectionTimeout = ms;
17318
+ config.connectionAcquisitionTimeout = ms;
17319
+ config.maxTransactionRetryTime = ms;
17320
+ }
17321
+ this.driver = neo4j.driver(uri, neo4j.auth.basic(user, pwd), config);
17322
+ }
17323
+ // -- connection + raw pass-through -------------------------------------
17324
+ async run(cypher, params = null) {
17325
+ const session = this.database ? this.driver.session({ database: this.database }) : this.driver.session();
17326
+ try {
17327
+ const result = await session.run(cypher, params ?? {});
17328
+ return result.records.map((record) => record.toObject());
17329
+ } catch (exc) {
17330
+ this.lastError = errorMessage2(exc);
17331
+ const code = exc?.code ?? "";
17332
+ const message = this.lastError.toLowerCase();
17333
+ if (code === "ServiceUnavailable" || code === neo4j.error?.SERVICE_UNAVAILABLE || message.includes("timed out") || message.includes("timeout")) {
17334
+ throw new GraphConnectTimeout(
17335
+ `Graph connect to ${this.url.host}:${this.url.port} timed out (${GRAPH_CONNECT_TIMEOUT_VARIABLE}). Raise ${GRAPH_CONNECT_TIMEOUT_VARIABLE} if the server is simply slow, or set it to 0 to wait indefinitely.`,
17336
+ exc
17337
+ );
17338
+ }
17339
+ throw new GraphError(this.lastError, exc);
17340
+ } finally {
17341
+ await session.close();
17342
+ }
17343
+ }
17344
+ async query(text, params = null) {
17345
+ const rows = await this.run(text, params);
17346
+ const columns = rows.length ? Object.keys(rows[0]) : [];
17347
+ return new GraphResult(rows, columns);
17348
+ }
17349
+ async execute(text, params = null) {
17350
+ return this.query(text, params);
17351
+ }
17352
+ // -- portable node/edge/traverse core (Cypher) -------------------------
17353
+ nodeFromRow(row) {
17354
+ if (row === null || row === void 0) return null;
17355
+ return new GraphNode(
17356
+ String(row.id),
17357
+ row.labels ?? [],
17358
+ row.props ?? {}
17359
+ );
17360
+ }
17361
+ async addNode(label, properties = null) {
17362
+ const cypher = `CREATE (n:\`${label}\` $props) RETURN id(n) AS id, labels(n) AS labels, properties(n) AS props`;
17363
+ const rows = await this.run(cypher, { props: properties ?? {} });
17364
+ return rows.length ? this.nodeFromRow(rows[0]) : null;
17365
+ }
17366
+ async addEdge(fromId, toId, type2, properties = null) {
17367
+ const cypher = `MATCH (a), (b) WHERE id(a) = $from_id AND id(b) = $to_id CREATE (a)-[e:\`${type2}\` $props]->(b) RETURN id(e) AS id, type(e) AS type, id(a) AS f, id(b) AS t, properties(e) AS props`;
17368
+ const rows = await this.run(cypher, {
17369
+ from_id: boltId(fromId),
17370
+ to_id: boltId(toId),
17371
+ props: properties ?? {}
17372
+ });
17373
+ if (rows.length === 0) return null;
17374
+ const row = rows[0];
17375
+ return new GraphEdge(
17376
+ String(row.id),
17377
+ String(row.type),
17378
+ String(row.f),
17379
+ String(row.t),
17380
+ row.props ?? {}
17381
+ );
17382
+ }
17383
+ async getNode(nodeId) {
17384
+ const cypher = `MATCH (n) WHERE id(n) = $id RETURN id(n) AS id, labels(n) AS labels, properties(n) AS props`;
17385
+ const rows = await this.run(cypher, { id: boltId(nodeId) });
17386
+ return rows.length ? this.nodeFromRow(rows[0]) : null;
17387
+ }
17388
+ async updateNode(nodeId, properties) {
17389
+ const cypher = `MATCH (n) WHERE id(n) = $id SET n += $props RETURN id(n) AS id, labels(n) AS labels, properties(n) AS props`;
17390
+ const rows = await this.run(cypher, { id: boltId(nodeId), props: properties ?? {} });
17391
+ return rows.length ? this.nodeFromRow(rows[0]) : null;
17392
+ }
17393
+ async deleteNode(nodeId) {
17394
+ await this.run("MATCH (n) WHERE id(n) = $id DETACH DELETE n", { id: boltId(nodeId) });
17395
+ return true;
17396
+ }
17397
+ async neighbors(nodeId, options = {}) {
17398
+ const direction = options.direction ?? "both";
17399
+ const limit = options.limit ?? 100;
17400
+ const edge = options.edgeType ? `:\`${options.edgeType}\`` : "";
17401
+ const pattern = {
17402
+ out: `(n)-[${edge}]->(m)`,
17403
+ in: `(n)<-[${edge}]-(m)`,
17404
+ both: `(n)-[${edge}]-(m)`
17405
+ }[direction];
17406
+ const cypher = `MATCH ${pattern} WHERE id(n) = $id RETURN DISTINCT id(m) AS id, labels(m) AS labels, properties(m) AS props LIMIT ${Math.trunc(limit)}`;
17407
+ const rows = await this.run(cypher, { id: boltId(nodeId) });
17408
+ return rows.map((row) => this.nodeFromRow(row)).filter((node) => node !== null);
17409
+ }
17410
+ async traverse(startId, options = {}) {
17411
+ const depth = options.depth ?? 1;
17412
+ const direction = options.direction ?? "both";
17413
+ const limit = options.limit ?? 1e3;
17414
+ const edge = options.edgeType ? `:\`${options.edgeType}\`` : "";
17415
+ const range = `*1..${Math.trunc(depth)}`;
17416
+ const arrow = {
17417
+ out: `-[${edge}${range}]->`,
17418
+ in: `<-[${edge}${range}]-`,
17419
+ both: `-[${edge}${range}]-`
17420
+ }[direction];
17421
+ const cypher = `MATCH (n)${arrow}(m) WHERE id(n) = $start RETURN DISTINCT id(m) AS id, labels(m) AS labels, properties(m) AS props LIMIT ${Math.trunc(limit)}`;
17422
+ const rows = await this.run(cypher, { start: boltId(startId) });
17423
+ return rows.map((row) => this.nodeFromRow(row)).filter((node) => node !== null);
17424
+ }
17425
+ async close() {
17426
+ await this.driver.close();
17427
+ }
17428
+ getError() {
17429
+ return this.lastError;
17430
+ }
17431
+ };
17432
+ }
17433
+ });
17434
+
17435
+ // ../orm/src/graph/adapters/arango.ts
17436
+ var arango_exports = {};
17437
+ __export(arango_exports, {
17438
+ ArangoGraphAdapter: () => ArangoGraphAdapter
17439
+ });
17440
+ function cleanProps(doc) {
17441
+ const props = {};
17442
+ for (const [key, value] of Object.entries(doc)) {
17443
+ if (!RESERVED.has(key)) props[key] = value;
17444
+ }
17445
+ return props;
17446
+ }
17447
+ function errorMessage3(exc) {
17448
+ if (exc instanceof Error) return exc.message;
17449
+ return String(exc);
17450
+ }
17451
+ var DRIVER_PACKAGE3, driverModule2, ArangoDatabase, VERTEX_COLLECTION, EDGE_COLLECTION, RESERVED, ArangoGraphAdapter;
17452
+ var init_arango = __esm({
17453
+ async "../orm/src/graph/adapters/arango.ts"() {
17454
+ "use strict";
17455
+ init_shapes();
17456
+ init_errors();
17457
+ init_connectTimeout2();
17458
+ DRIVER_PACKAGE3 = "arangojs";
17459
+ driverModule2 = await import(DRIVER_PACKAGE3);
17460
+ ArangoDatabase = driverModule2.Database ?? driverModule2.default?.Database;
17461
+ VERTEX_COLLECTION = "tina4_nodes";
17462
+ EDGE_COLLECTION = "tina4_edges";
17463
+ RESERVED = /* @__PURE__ */ new Set(["_id", "_key", "_rev", "_from", "_to", "_labels", "_type"]);
17464
+ ArangoGraphAdapter = class {
17465
+ url;
17466
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17467
+ db;
17468
+ ensured = false;
17469
+ lastError = null;
17470
+ constructor(graphUrl, credentials = {}) {
17471
+ this.url = graphUrl;
17472
+ const scheme = graphUrl.useTls ? "https" : "http";
17473
+ const user = graphUrl.username || credentials.username || "root";
17474
+ const pwd = graphUrl.password || credentials.password || "";
17475
+ const database = graphUrl.graph || "_system";
17476
+ const timeout = resolveGraphConnectTimeout();
17477
+ const config = {
17478
+ url: `${scheme}://${graphUrl.host}:${graphUrl.port}`,
17479
+ databaseName: database,
17480
+ auth: { username: user, password: pwd }
17481
+ };
17482
+ if (timeout !== null) config.timeout = Math.max(1, Math.ceil(timeout * 1e3));
17483
+ this.db = new ArangoDatabase(config);
17484
+ }
17485
+ connectOrError(exc) {
17486
+ const text = errorMessage3(exc).toLowerCase();
17487
+ if (text.includes("timed out") || text.includes("timeout") || text.includes("connection") || text.includes("econnrefused") || text.includes("etimedout") || text.includes("max retries")) {
17488
+ return new GraphConnectTimeout(
17489
+ `Graph connect to ${this.url.host}:${this.url.port} timed out (${GRAPH_CONNECT_TIMEOUT_VARIABLE}). Raise ${GRAPH_CONNECT_TIMEOUT_VARIABLE} if the server is simply slow, or set it to 0 to wait indefinitely.`,
17490
+ exc
17491
+ );
17492
+ }
17493
+ return new GraphError(errorMessage3(exc), exc);
17494
+ }
17495
+ async ensureCollections() {
17496
+ if (this.ensured) return;
17497
+ try {
17498
+ const nodes = this.db.collection(VERTEX_COLLECTION);
17499
+ if (!await nodes.exists()) await this.db.createCollection(VERTEX_COLLECTION);
17500
+ const edges = this.db.collection(EDGE_COLLECTION);
17501
+ if (!await edges.exists()) await this.db.createEdgeCollection(EDGE_COLLECTION);
17502
+ this.ensured = true;
17503
+ } catch (exc) {
17504
+ this.lastError = errorMessage3(exc);
17505
+ throw this.connectOrError(exc);
17506
+ }
17507
+ }
17508
+ async aql(query, bind2 = null) {
17509
+ await this.ensureCollections();
17510
+ try {
17511
+ const cursor = await this.db.query({ query, bindVars: bind2 ?? {} });
17512
+ return await cursor.all();
17513
+ } catch (exc) {
17514
+ this.lastError = errorMessage3(exc);
17515
+ throw this.connectOrError(exc);
17516
+ }
17517
+ }
17518
+ async query(text, params = null) {
17519
+ const rows = await this.aql(text, params);
17520
+ const first = rows[0];
17521
+ const columns = rows.length && first && typeof first === "object" ? Object.keys(first) : [];
17522
+ return new GraphResult(rows, columns);
17523
+ }
17524
+ async execute(text, params = null) {
17525
+ return this.query(text, params);
17526
+ }
17527
+ // -- portable node/edge/traverse core (AQL) ----------------------------
17528
+ nodeFromDoc(doc) {
17529
+ if (doc === null || doc === void 0) return null;
17530
+ return new GraphNode(
17531
+ String(doc._id),
17532
+ doc._labels ?? [],
17533
+ cleanProps(doc)
17534
+ );
17535
+ }
17536
+ async addNode(label, properties = null) {
17537
+ const doc = { ...properties ?? {}, _labels: [label] };
17538
+ const rows = await this.aql(`INSERT @doc INTO ${VERTEX_COLLECTION} RETURN NEW`, { doc });
17539
+ return rows.length ? this.nodeFromDoc(rows[0]) : null;
17540
+ }
17541
+ async addEdge(fromId, toId, type2, properties = null) {
17542
+ const doc = { ...properties ?? {}, _from: fromId, _to: toId, _type: type2 };
17543
+ const rows = await this.aql(`INSERT @doc INTO ${EDGE_COLLECTION} RETURN NEW`, { doc });
17544
+ if (rows.length === 0) return null;
17545
+ const row = rows[0];
17546
+ return new GraphEdge(
17547
+ String(row._id),
17548
+ String(row._type),
17549
+ String(row._from),
17550
+ String(row._to),
17551
+ cleanProps(row)
17552
+ );
17553
+ }
17554
+ async getNode(nodeId) {
17555
+ const rows = await this.aql("RETURN DOCUMENT(@id)", { id: nodeId });
17556
+ return rows.length && rows[0] ? this.nodeFromDoc(rows[0]) : null;
17557
+ }
17558
+ async updateNode(nodeId, properties) {
17559
+ const rows = await this.aql(
17560
+ `UPDATE PARSE_IDENTIFIER(@id).key WITH @props IN ${VERTEX_COLLECTION} RETURN NEW`,
17561
+ { id: nodeId, props: properties ?? {} }
17562
+ );
17563
+ return rows.length ? this.nodeFromDoc(rows[0]) : null;
17564
+ }
17565
+ async deleteNode(nodeId) {
17566
+ await this.aql(
17567
+ `FOR e IN ${EDGE_COLLECTION} FILTER e._from == @id OR e._to == @id REMOVE e IN ${EDGE_COLLECTION}`,
17568
+ { id: nodeId }
17569
+ );
17570
+ await this.aql(
17571
+ `REMOVE PARSE_IDENTIFIER(@id).key IN ${VERTEX_COLLECTION}`,
17572
+ { id: nodeId }
17573
+ );
17574
+ return true;
17575
+ }
17576
+ async neighbors(nodeId, options = {}) {
17577
+ const direction = options.direction ?? "both";
17578
+ const limit = options.limit ?? 100;
17579
+ const arangoDir = { out: "OUTBOUND", in: "INBOUND", both: "ANY" }[direction];
17580
+ const typeFilter = options.edgeType ? "FILTER e._type == @etype " : "";
17581
+ const bind2 = { start: nodeId, limit: Math.trunc(limit) };
17582
+ if (options.edgeType) bind2.etype = options.edgeType;
17583
+ const rows = await this.aql(
17584
+ `FOR v, e IN 1..1 ${arangoDir} @start ${EDGE_COLLECTION} ${typeFilter}LIMIT @limit RETURN DISTINCT v`,
17585
+ bind2
17586
+ );
17587
+ return rows.map((doc) => this.nodeFromDoc(doc)).filter((node) => node !== null);
17588
+ }
17589
+ async traverse(startId, options = {}) {
17590
+ const depth = options.depth ?? 1;
17591
+ const direction = options.direction ?? "both";
17592
+ const limit = options.limit ?? 1e3;
17593
+ const arangoDir = { out: "OUTBOUND", in: "INBOUND", both: "ANY" }[direction];
17594
+ const typeFilter = options.edgeType ? "FILTER e._type == @etype " : "";
17595
+ const bind2 = { start: startId, limit: Math.trunc(limit) };
17596
+ if (options.edgeType) bind2.etype = options.edgeType;
17597
+ const rows = await this.aql(
17598
+ `FOR v, e IN 1..${Math.trunc(depth)} ${arangoDir} @start ${EDGE_COLLECTION} ${typeFilter}LIMIT @limit RETURN DISTINCT v`,
17599
+ bind2
17600
+ );
17601
+ return rows.map((doc) => this.nodeFromDoc(doc)).filter((node) => node !== null);
17602
+ }
17603
+ async close() {
17604
+ if (typeof this.db.close === "function") this.db.close();
17605
+ }
17606
+ getError() {
17607
+ return this.lastError;
17608
+ }
17609
+ };
17610
+ }
17611
+ });
17612
+
17613
+ // ../orm/src/graph/graphDatabase.ts
17614
+ var ENGINE_ADAPTERS, GraphDatabase;
17615
+ var init_graphDatabase = __esm({
17616
+ "../orm/src/graph/graphDatabase.ts"() {
17617
+ "use strict";
17618
+ init_graphUrl();
17619
+ init_errors();
17620
+ ENGINE_ADAPTERS = {
17621
+ ultipa: {
17622
+ load: () => init_ultipa().then(() => ultipa_exports),
17623
+ className: "UltipaGraphAdapter",
17624
+ package: "tina4-ultipa",
17625
+ installCommand: "npm install tina4-ultipa"
17626
+ },
17627
+ bolt: {
17628
+ // Neo4j AND Memgraph — both speak Bolt/Cypher over the neo4j-driver package.
17629
+ load: () => init_bolt().then(() => bolt_exports),
17630
+ className: "BoltGraphAdapter",
17631
+ package: "neo4j-driver",
17632
+ installCommand: "npm install neo4j-driver"
17633
+ },
17634
+ arango: {
17635
+ load: () => init_arango().then(() => arango_exports),
17636
+ className: "ArangoGraphAdapter",
17637
+ package: "arangojs",
17638
+ installCommand: "npm install arangojs"
17639
+ }
17640
+ };
17641
+ GraphDatabase = class _GraphDatabase {
17642
+ /**
17643
+ * Parse the URL, pick the engine adapter, connect lazily.
17644
+ *
17645
+ * The engine driver is imported only here (first use of that engine); if it is
17646
+ * absent the error names the package and the install command. Async because the
17647
+ * driver import is dynamic — the connect itself still happens lazily on first
17648
+ * operation (mirroring the relational adapters).
17649
+ */
17650
+ static async create(url, credentials = {}) {
17651
+ const graphUrl = new GraphUrl(url);
17652
+ const registration = ENGINE_ADAPTERS[graphUrl.engine];
17653
+ if (registration === void 0) {
17654
+ throw new GraphError(
17655
+ `No graph adapter for engine '${graphUrl.engine}' yet (scheme '${graphUrl.scheme}'). Available: ${Object.keys(ENGINE_ADAPTERS).sort().join(", ")}.`
17656
+ );
17657
+ }
17658
+ let module;
17659
+ try {
17660
+ module = await registration.load();
17661
+ } catch (cause) {
17662
+ throw new GraphError(
17663
+ `The graph driver for '${graphUrl.engine}' is not installed (${registration.package}). Install it with:
17664
+ ${registration.installCommand}`,
17665
+ cause
17666
+ );
17667
+ }
17668
+ const AdapterClass = module[registration.className];
17669
+ if (AdapterClass === void 0) {
17670
+ throw new GraphError(
17671
+ `The graph adapter '${registration.className}' is missing from its module for engine '${graphUrl.engine}'.`
17672
+ );
17673
+ }
17674
+ return new AdapterClass(graphUrl, credentials);
17675
+ }
17676
+ /** Build from TINA4_GRAPH_URL (+ TINA4_GRAPH_USERNAME/_PASSWORD). */
17677
+ static async fromEnv(envKey = "TINA4_GRAPH_URL") {
17678
+ const url = (process.env[envKey] ?? "").trim();
17679
+ if (url === "") return null;
17680
+ return _GraphDatabase.create(url, {
17681
+ username: process.env.TINA4_GRAPH_USERNAME,
17682
+ password: process.env.TINA4_GRAPH_PASSWORD
17683
+ });
17684
+ }
17685
+ };
17686
+ }
17687
+ });
17688
+
16920
17689
  // ../orm/src/realtime/models/workspace.ts
16921
17690
  var Workspace;
16922
17691
  var init_workspace = __esm({
@@ -17475,6 +18244,7 @@ __export(src_exports, {
17475
18244
  CachedDatabaseAdapter: () => CachedDatabaseAdapter,
17476
18245
  Cursor: () => Cursor,
17477
18246
  DEFAULT_DATABASE_CONNECT_TIMEOUT_SECONDS: () => DEFAULT_DATABASE_CONNECT_TIMEOUT_SECONDS,
18247
+ DEFAULT_GRAPH_CONNECT_TIMEOUT_SECONDS: () => DEFAULT_GRAPH_CONNECT_TIMEOUT_SECONDS,
17478
18248
  DEFAULT_SRID: () => DEFAULT_SRID,
17479
18249
  Database: () => Database,
17480
18250
  DatabaseResult: () => DatabaseResult,
@@ -17482,6 +18252,14 @@ __export(src_exports, {
17482
18252
  DocStoreDriverMissing: () => DocStoreDriverMissing,
17483
18253
  FakeData: () => FakeData2,
17484
18254
  FirebirdAdapter: () => FirebirdAdapter,
18255
+ GRAPH_CONNECT_TIMEOUT_VARIABLE: () => GRAPH_CONNECT_TIMEOUT_VARIABLE,
18256
+ GraphConnectTimeout: () => GraphConnectTimeout,
18257
+ GraphDatabase: () => GraphDatabase,
18258
+ GraphEdge: () => GraphEdge,
18259
+ GraphError: () => GraphError,
18260
+ GraphNode: () => GraphNode,
18261
+ GraphResult: () => GraphResult,
18262
+ GraphUrl: () => GraphUrl,
17485
18263
  InvalidId: () => InvalidId,
17486
18264
  LocalStorage: () => LocalStorage,
17487
18265
  Migration: () => Migration,
@@ -17563,6 +18341,7 @@ __export(src_exports, {
17563
18341
  resetRequestCaches: () => resetRequestCaches,
17564
18342
  resolveDbPool: () => resolveDbPool,
17565
18343
  resolveFirebirdCharset: () => resolveFirebirdCharset,
18344
+ resolveGraphConnectTimeout: () => resolveGraphConnectTimeout,
17566
18345
  rollback: () => rollback,
17567
18346
  seedModels: () => seedModels,
17568
18347
  seedOrm: () => seedOrm,
@@ -17612,6 +18391,11 @@ var init_src = __esm({
17612
18391
  init_firebird();
17613
18392
  init_mongodb();
17614
18393
  init_odbc();
18394
+ init_graphDatabase();
18395
+ init_graphUrl();
18396
+ init_shapes();
18397
+ init_errors();
18398
+ init_connectTimeout2();
17615
18399
  init_realtime2();
17616
18400
  }
17617
18401
  });
@@ -21287,7 +22071,7 @@ var init_mongoHandler = __esm({
21287
22071
  // src/sessionHandlers/sqlClient.ts
21288
22072
  import { createRequire as createRequire7 } from "node:module";
21289
22073
  function driverPath(engine) {
21290
- const packageName = DRIVER_PACKAGE[engine];
22074
+ const packageName = DRIVER_PACKAGE4[engine];
21291
22075
  try {
21292
22076
  return requireFromHere.resolve(packageName);
21293
22077
  } catch {
@@ -21311,14 +22095,14 @@ function sqlCommandSync(target, sql, params = [], label = "Database session") {
21311
22095
  return [];
21312
22096
  }
21313
22097
  }
21314
- var SQL_SESSION_ENGINES, CONNECT_TIMEOUT_MS2, DRIVER_PACKAGE, requireFromHere, SQL_WORKER;
22098
+ var SQL_SESSION_ENGINES, CONNECT_TIMEOUT_MS2, DRIVER_PACKAGE4, requireFromHere, SQL_WORKER;
21315
22099
  var init_sqlClient = __esm({
21316
22100
  "src/sessionHandlers/sqlClient.ts"() {
21317
22101
  "use strict";
21318
22102
  init_syncBridge();
21319
22103
  SQL_SESSION_ENGINES = ["sqlite", "postgres", "mysql", "mssql", "firebird"];
21320
22104
  CONNECT_TIMEOUT_MS2 = 3e3;
21321
- DRIVER_PACKAGE = {
22105
+ DRIVER_PACKAGE4 = {
21322
22106
  postgres: "pg",
21323
22107
  mysql: "mysql2",
21324
22108
  mssql: "tedious",