tina4-nodejs 3.13.110 → 3.13.112
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/CLAUDE.md +2 -2
- package/package.json +1 -1
- package/packages/cli/dist/bin.js +951 -153
- package/packages/core/dist/index.js +951 -153
- package/packages/core/src/devAdmin.ts +181 -145
- package/packages/core/src/server.ts +6 -0
- package/packages/orm/dist/index.js +958 -150
- package/packages/orm/src/graph/adapters/arango.ts +256 -0
- package/packages/orm/src/graph/adapters/bolt.ts +259 -0
- package/packages/orm/src/graph/adapters/ultipa.ts +271 -0
- package/packages/orm/src/graph/connectTimeout.ts +39 -0
- package/packages/orm/src/graph/errors.ts +29 -0
- package/packages/orm/src/graph/graphAdapter.ts +53 -0
- package/packages/orm/src/graph/graphDatabase.ts +114 -0
- package/packages/orm/src/graph/graphUrl.ts +98 -0
- package/packages/orm/src/graph/shapes.ts +95 -0
- package/packages/orm/src/index.ts +137 -115
- package/types/core/src/devAdmin.d.ts +1 -0
- package/types/orm/src/graph/adapters/arango.d.ts +42 -0
- package/types/orm/src/graph/adapters/bolt.d.ts +43 -0
- package/types/orm/src/graph/adapters/ultipa.d.ts +39 -0
- package/types/orm/src/graph/connectTimeout.d.ts +12 -0
- package/types/orm/src/graph/errors.d.ts +21 -0
- package/types/orm/src/graph/graphAdapter.d.ts +38 -0
- package/types/orm/src/graph/graphDatabase.d.ts +44 -0
- package/types/orm/src/graph/graphUrl.d.ts +28 -0
- package/types/orm/src/graph/shapes.d.ts +37 -0
- package/types/orm/src/index.d.ts +8 -0
|
@@ -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 =
|
|
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,
|
|
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
|
-
|
|
22105
|
+
DRIVER_PACKAGE4 = {
|
|
21322
22106
|
postgres: "pg",
|
|
21323
22107
|
mysql: "mysql2",
|
|
21324
22108
|
mssql: "tedious",
|
|
@@ -32049,47 +32833,120 @@ function renderToolbarHtml(ctx) {
|
|
|
32049
32833
|
const method = escapeHtml(ctx.method);
|
|
32050
32834
|
const path8 = escapeHtml(ctx.path);
|
|
32051
32835
|
const matchedPattern = escapeHtml(ctx.matchedPattern);
|
|
32052
|
-
|
|
32053
|
-
|
|
32054
|
-
|
|
32055
|
-
|
|
32056
|
-
|
|
32057
|
-
|
|
32836
|
+
const reload = ctx.reload === false ? "0" : "1";
|
|
32837
|
+
return `<link rel="stylesheet" href="/__dev/toolbar.css">
|
|
32838
|
+
<div id="tina4-dev-toolbar" data-reload="${reload}">
|
|
32839
|
+
<span id="tina4-ver-btn" title="Click to check for updates">Tina4 v${ctx.version}</span>
|
|
32840
|
+
<div id="tina4-ver-modal">
|
|
32841
|
+
<div class="t4-modal-head">
|
|
32842
|
+
<strong class="t4-modal-title">Version Info</strong>
|
|
32843
|
+
<span id="tina4-ver-close" class="t4-x">×</span>
|
|
32058
32844
|
</div>
|
|
32059
|
-
<div id="tina4-ver-body"
|
|
32060
|
-
<div>Current: <strong
|
|
32061
|
-
<div id="tina4-ver-latest"
|
|
32845
|
+
<div id="tina4-ver-body">
|
|
32846
|
+
<div>Current: <strong class="t4-ok">v${ctx.version}</strong></div>
|
|
32847
|
+
<div id="tina4-ver-latest" class="t4-dim">Checking for updates...</div>
|
|
32062
32848
|
</div>
|
|
32063
32849
|
</div>
|
|
32064
|
-
<span
|
|
32850
|
+
<span class="t4-green">${method}</span>
|
|
32065
32851
|
<span>${path8}</span>
|
|
32066
|
-
<span
|
|
32067
|
-
<span
|
|
32068
|
-
<span
|
|
32069
|
-
<span
|
|
32070
|
-
<a href="#"
|
|
32071
|
-
<span
|
|
32852
|
+
<span class="t4-arrow">→ ${matchedPattern}</span>
|
|
32853
|
+
<span class="t4-yellow">req:${ctx.requestId}</span>
|
|
32854
|
+
<span class="t4-blue">${ctx.routeCount} routes</span>
|
|
32855
|
+
<span class="t4-dim">Node.js ${nodeVersion}</span>
|
|
32856
|
+
<a href="#" id="tina4-dash-link" class="t4-dash">Dashboard ↗</a>
|
|
32857
|
+
<span id="tina4-bar-close" class="t4-x t4-bar-close">✕</span>
|
|
32072
32858
|
</div>
|
|
32073
|
-
<script
|
|
32074
|
-
|
|
32075
|
-
|
|
32076
|
-
|
|
32077
|
-
|
|
32078
|
-
|
|
32859
|
+
<script src="/__dev/toolbar.js"></script>`;
|
|
32860
|
+
}
|
|
32861
|
+
function toolbarCss() {
|
|
32862
|
+
return `#tina4-dev-toolbar{position:fixed;bottom:0;left:0;right:0;background:#333;color:#fff;font-family:monospace;font-size:12px;padding:6px 16px;z-index:99999;display:flex;align-items:center;gap:16px}
|
|
32863
|
+
#tina4-dev-toolbar a{text-decoration:none}
|
|
32864
|
+
#tina4-ver-btn{color:#2e7d32;font-weight:bold;cursor:pointer;text-decoration:underline dotted}
|
|
32865
|
+
#tina4-ver-modal{display:none;position:fixed;bottom:3rem;left:1rem;background:#1e1e2e;border:1px solid #2e7d32;border-radius:8px;padding:16px 20px;z-index:100000;min-width:320px;box-shadow:0 8px 32px rgba(0,0,0,.5);font-family:monospace;font-size:13px;color:#cdd6f4}
|
|
32866
|
+
.t4-modal-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}
|
|
32867
|
+
.t4-modal-title{color:#89b4fa}
|
|
32868
|
+
#tina4-ver-body{line-height:1.8}
|
|
32869
|
+
.t4-x{cursor:pointer;color:#888}
|
|
32870
|
+
.t4-bar-close{margin-left:8px}
|
|
32871
|
+
.t4-green{color:#4caf50}
|
|
32872
|
+
.t4-dim{color:#888}
|
|
32873
|
+
.t4-arrow{color:#666}
|
|
32874
|
+
.t4-yellow{color:#ffeb3b}
|
|
32875
|
+
.t4-blue{color:#90caf9}
|
|
32876
|
+
.t4-ok{color:#a6e3a1}
|
|
32877
|
+
.t4-warn{color:#f9e2af}
|
|
32878
|
+
.t4-err{color:#f38ba8}
|
|
32879
|
+
.t4-purple{color:#cba6f7}
|
|
32880
|
+
.t4-link{color:#89b4fa}
|
|
32881
|
+
.t4-code{background:#313244;padding:2px 6px;border-radius:3px}
|
|
32882
|
+
.t4-note{margin-top:6px}
|
|
32883
|
+
.t4-dash{color:#ef9a9a;margin-left:auto;cursor:pointer}
|
|
32884
|
+
#tina4-dev-panel{position:fixed;top:3rem;left:0;right:0;bottom:2rem;z-index:99998;transition:all .2s}
|
|
32885
|
+
#tina4-dev-panel iframe{width:100%;height:100%;border:1px solid #2e7d32;border-radius:.5rem;box-shadow:0 8px 32px rgba(0,0,0,.5);background:#0f172a}`;
|
|
32886
|
+
}
|
|
32887
|
+
function toolbarJs() {
|
|
32888
|
+
return `(function () {
|
|
32889
|
+
var bar = document.getElementById('tina4-dev-toolbar');
|
|
32890
|
+
if (!bar) { return; }
|
|
32891
|
+
|
|
32892
|
+
var modal = document.getElementById('tina4-ver-modal');
|
|
32893
|
+
function upToDate(el, latest) {
|
|
32894
|
+
el.className = 't4-ok';
|
|
32895
|
+
el.innerHTML = 'Latest: <strong class="t4-ok">v' + latest + '</strong> — You are up to date!';
|
|
32896
|
+
}
|
|
32897
|
+
function checkVersion() {
|
|
32898
|
+
if (modal.style.display === 'block') { modal.style.display = 'none'; return; }
|
|
32899
|
+
modal.style.display = 'block';
|
|
32900
|
+
var el = document.getElementById('tina4-ver-latest');
|
|
32901
|
+
el.className = 't4-dim';
|
|
32902
|
+
el.textContent = 'Checking for updates...';
|
|
32903
|
+
fetch('/__dev/api/version-check').then(function (r) { return r.json(); }).then(function (d) {
|
|
32904
|
+
var latest = d.latest, current = d.current;
|
|
32905
|
+
if (latest === current) { upToDate(el, latest); return; }
|
|
32906
|
+
var cP = current.split('.').map(Number), lP = latest.split('.').map(Number);
|
|
32907
|
+
var isNewer = false, i, c, l;
|
|
32908
|
+
for (i = 0; i < Math.max(cP.length, lP.length); i++) { c = cP[i] || 0; l = lP[i] || 0; if (l > c) { isNewer = true; break; } if (l < c) { break; } }
|
|
32909
|
+
var isAhead = false;
|
|
32910
|
+
if (!isNewer) { for (i = 0; i < Math.max(cP.length, lP.length); i++) { var c2 = cP[i] || 0, l2 = lP[i] || 0; if (c2 > l2) { isAhead = true; break; } if (c2 < l2) { break; } } }
|
|
32911
|
+
if (isNewer) {
|
|
32912
|
+
var breaking = (lP[0] !== cP[0] || lP[1] !== cP[1]);
|
|
32913
|
+
el.className = '';
|
|
32914
|
+
el.innerHTML = 'Latest: <strong class="t4-warn">v' + latest + '</strong>';
|
|
32915
|
+
if (breaking) {
|
|
32916
|
+
el.innerHTML += '<div class="t4-err t4-note">⚠ Major/minor version change — check the <a href="https://github.com/tina4stack/tina4-nodejs/releases" target="_blank" class="t4-link">changelog</a> for breaking changes before upgrading.</div>';
|
|
32917
|
+
} else {
|
|
32918
|
+
el.innerHTML += '<div class="t4-warn t4-note">Patch update available. Run: <code class="t4-code">npm install tina4-nodejs@latest</code></div>';
|
|
32919
|
+
}
|
|
32920
|
+
} else if (isAhead) {
|
|
32921
|
+
el.className = 't4-purple';
|
|
32922
|
+
el.innerHTML = 'You are running <strong class="t4-purple">v' + current + '</strong> (ahead of npm <strong>v' + latest + '</strong> — not yet published).';
|
|
32923
|
+
} else {
|
|
32924
|
+
upToDate(el, latest);
|
|
32925
|
+
}
|
|
32926
|
+
}).catch(function () {
|
|
32927
|
+
el.className = 't4-err';
|
|
32928
|
+
el.textContent = 'Could not check for updates (offline?)';
|
|
32929
|
+
});
|
|
32930
|
+
}
|
|
32931
|
+
var verBtn = document.getElementById('tina4-ver-btn');
|
|
32932
|
+
if (verBtn) { verBtn.addEventListener('click', checkVersion); }
|
|
32933
|
+
var verClose = document.getElementById('tina4-ver-close');
|
|
32934
|
+
if (verClose) { verClose.addEventListener('click', function () { modal.style.display = 'none'; }); }
|
|
32935
|
+
var barClose = document.getElementById('tina4-bar-close');
|
|
32936
|
+
if (barClose) { barClose.addEventListener('click', function () { bar.style.display = 'none'; }); }
|
|
32937
|
+
|
|
32079
32938
|
var STATE_KEY = 'tina4_dev_overlay_open';
|
|
32080
32939
|
function buildOverlay() {
|
|
32081
32940
|
var c = document.createElement('div');
|
|
32082
32941
|
c.id = 'tina4-dev-panel';
|
|
32083
|
-
c.style.cssText = 'position:fixed;top:3rem;left:0;right:0;bottom:2rem;z-index:99998;transition:all 0.2s';
|
|
32084
32942
|
var f = document.createElement('iframe');
|
|
32085
32943
|
f.src = '/__dev';
|
|
32086
|
-
f.style.cssText = 'width:100%;height:100%;border:1px solid #2e7d32;border-radius:0.5rem;box-shadow:0 8px 32px rgba(0,0,0,0.5);background:#0f172a';
|
|
32087
32944
|
c.appendChild(f);
|
|
32088
32945
|
document.body.appendChild(c);
|
|
32089
32946
|
return c;
|
|
32090
32947
|
}
|
|
32091
|
-
|
|
32092
|
-
if (e) e.preventDefault();
|
|
32948
|
+
function toggleOverlay(e) {
|
|
32949
|
+
if (e) { e.preventDefault(); }
|
|
32093
32950
|
var p = document.getElementById('tina4-dev-panel');
|
|
32094
32951
|
if (p) {
|
|
32095
32952
|
var hide = p.style.display !== 'none';
|
|
@@ -32099,137 +32956,61 @@ function renderToolbarHtml(ctx) {
|
|
|
32099
32956
|
}
|
|
32100
32957
|
buildOverlay();
|
|
32101
32958
|
try { localStorage.setItem(STATE_KEY, '1'); } catch (_) {}
|
|
32102
|
-
};
|
|
32103
|
-
function restoreIfOpen() {
|
|
32104
|
-
try {
|
|
32105
|
-
if (location.pathname.indexOf('/__dev') === 0) return;
|
|
32106
|
-
if (localStorage.getItem(STATE_KEY) === '1' && !document.getElementById('tina4-dev-panel')) {
|
|
32107
|
-
buildOverlay();
|
|
32108
|
-
}
|
|
32109
|
-
} catch (_) {}
|
|
32110
32959
|
}
|
|
32111
|
-
|
|
32112
|
-
|
|
32113
|
-
|
|
32114
|
-
|
|
32115
|
-
|
|
32116
|
-
|
|
32117
|
-
|
|
32118
|
-
|
|
32119
|
-
|
|
32120
|
-
|
|
32121
|
-
if(
|
|
32122
|
-
|
|
32123
|
-
var
|
|
32124
|
-
|
|
32125
|
-
|
|
32126
|
-
|
|
32127
|
-
|
|
32128
|
-
|
|
32129
|
-
|
|
32130
|
-
|
|
32131
|
-
|
|
32132
|
-
el.innerHTML='Latest: <strong style="color:#a6e3a1;">v'+latest+'</strong> — You are up to date!';
|
|
32133
|
-
el.style.color='#a6e3a1';
|
|
32134
|
-
}else{
|
|
32135
|
-
var cParts=current.split('.').map(Number);
|
|
32136
|
-
var lParts=latest.split('.').map(Number);
|
|
32137
|
-
var isNewer=false;
|
|
32138
|
-
for(var i=0;i<Math.max(cParts.length,lParts.length);i++){
|
|
32139
|
-
var c=cParts[i]||0,l=lParts[i]||0;
|
|
32140
|
-
if(l>c){isNewer=true;break;}
|
|
32141
|
-
if(l<c)break;
|
|
32142
|
-
}
|
|
32143
|
-
var isAhead=false;
|
|
32144
|
-
if(!isNewer){for(var i=0;i<Math.max(cParts.length,lParts.length);i++){var c2=cParts[i]||0,l2=lParts[i]||0;if(c2>l2){isAhead=true;break;}if(c2<l2)break;}}
|
|
32145
|
-
if(isNewer){
|
|
32146
|
-
var breaking=(lParts[0]!==cParts[0]||lParts[1]!==cParts[1]);
|
|
32147
|
-
el.innerHTML='Latest: <strong style="color:#f9e2af;">v'+latest+'</strong>';
|
|
32148
|
-
if(breaking){
|
|
32149
|
-
el.innerHTML+='<div style="color:#f38ba8;margin-top:6px;">⚠ Major/minor version change — check the <a href="https://github.com/tina4stack/tina4-nodejs/releases" target="_blank" style="color:#89b4fa;">changelog</a> for breaking changes before upgrading.</div>';
|
|
32150
|
-
}else{
|
|
32151
|
-
el.innerHTML+='<div style="color:#f9e2af;margin-top:6px;">Patch update available. Run: <code style="background:#313244;padding:2px 6px;border-radius:3px;">npm install tina4-nodejs@latest</code></div>';
|
|
32152
|
-
}
|
|
32153
|
-
}else if(isAhead){
|
|
32154
|
-
el.innerHTML='You are running <strong style="color:#cba6f7;">v'+current+'</strong> (ahead of npm <strong>v'+latest+'</strong> — not yet published).';
|
|
32155
|
-
el.style.color='#cba6f7';
|
|
32156
|
-
}else{
|
|
32157
|
-
el.innerHTML='Latest: <strong style="color:#a6e3a1;">v'+latest+'</strong> — You are up to date!';
|
|
32158
|
-
el.style.color='#a6e3a1';
|
|
32159
|
-
}
|
|
32160
|
-
}
|
|
32161
|
-
})
|
|
32162
|
-
.catch(function(){
|
|
32163
|
-
el.innerHTML='Could not check for updates (offline?)';
|
|
32164
|
-
el.style.color='#f38ba8';
|
|
32165
|
-
});
|
|
32166
|
-
}
|
|
32167
|
-
</script>
|
|
32168
|
-
<script>
|
|
32169
|
-
(function(){
|
|
32170
|
-
// WebSocket-primary dev reloader. The running server re-imports changed
|
|
32171
|
-
// src/ routes in-process and pushes a {type,file,mtime} message over
|
|
32172
|
-
// /__dev_reload \u2014 no respawn, instant refresh. The mtime poll below is a
|
|
32173
|
-
// FALLBACK only, started when the socket is down and stopped on connect.
|
|
32174
|
-
var _t4_css_exts=['.css','.scss'],_t4_debounce=null;
|
|
32175
|
-
var _t4_interval=3000;
|
|
32176
|
-
var _t4_ws=null,_t4_poll_timer=null,_t4_mtime=null;
|
|
32177
|
-
function _t4_apply(d){
|
|
32178
|
-
d=d||{};
|
|
32179
|
-
var f=d.file||'',t=d.type||'';
|
|
32180
|
-
var isCss=t==='css'||_t4_css_exts.some(function(e){return f.endsWith(e)});
|
|
32181
|
-
if(isCss){
|
|
32182
|
-
var links=document.querySelectorAll('link[rel="stylesheet"]');
|
|
32183
|
-
links.forEach(function(l){
|
|
32184
|
-
var href=l.getAttribute('href');
|
|
32185
|
-
if(href){l.setAttribute('href',href.split('?')[0]+'?_t4='+(d.mtime||Date.now()))}
|
|
32960
|
+
var dash = document.getElementById('tina4-dash-link');
|
|
32961
|
+
if (dash) { dash.addEventListener('click', toggleOverlay); }
|
|
32962
|
+
try {
|
|
32963
|
+
if (location.pathname.indexOf('/__dev') !== 0
|
|
32964
|
+
&& localStorage.getItem(STATE_KEY) === '1'
|
|
32965
|
+
&& !document.getElementById('tina4-dev-panel')) {
|
|
32966
|
+
buildOverlay();
|
|
32967
|
+
}
|
|
32968
|
+
} catch (_) {}
|
|
32969
|
+
|
|
32970
|
+
if (bar.getAttribute('data-reload') !== '1') { return; }
|
|
32971
|
+
var cssExts = ['.css', '.scss'], debounce = null, interval = 3000;
|
|
32972
|
+
var ws = null, pollTimer = null, mtime = null;
|
|
32973
|
+
function apply(d) {
|
|
32974
|
+
d = d || {};
|
|
32975
|
+
var f = d.file || '', t = d.type || '';
|
|
32976
|
+
var isCss = t === 'css' || cssExts.some(function (e) { return f.endsWith(e); });
|
|
32977
|
+
if (isCss) {
|
|
32978
|
+
document.querySelectorAll('link[rel="stylesheet"]').forEach(function (l) {
|
|
32979
|
+
var href = l.getAttribute('href');
|
|
32980
|
+
if (href) { l.setAttribute('href', href.split('?')[0] + '?_t4=' + (d.mtime || Date.now())); }
|
|
32186
32981
|
});
|
|
32187
|
-
}else{
|
|
32982
|
+
} else {
|
|
32188
32983
|
location.reload();
|
|
32189
32984
|
}
|
|
32190
32985
|
}
|
|
32191
|
-
function
|
|
32192
|
-
fetch('/__dev/api/mtime').then(function(r){return r.json()}).then(function(d){
|
|
32193
|
-
|
|
32194
|
-
|
|
32195
|
-
|
|
32196
|
-
|
|
32197
|
-
|
|
32198
|
-
|
|
32199
|
-
|
|
32200
|
-
|
|
32201
|
-
|
|
32202
|
-
|
|
32203
|
-
|
|
32204
|
-
|
|
32205
|
-
|
|
32206
|
-
|
|
32207
|
-
|
|
32208
|
-
|
|
32209
|
-
|
|
32210
|
-
if(_t4_poll_timer){clearInterval(_t4_poll_timer);_t4_poll_timer=null;}
|
|
32211
|
-
}
|
|
32212
|
-
function _t4_connect(){
|
|
32213
|
-
var url=(location.protocol==='https:'?'wss':'ws')+'://'+location.host+'/__dev_reload';
|
|
32214
|
-
try{_t4_ws=new WebSocket(url);}catch(_){_t4_startPoll();return;}
|
|
32215
|
-
_t4_ws.addEventListener('open',function(){_t4_stopPoll();});
|
|
32216
|
-
_t4_ws.addEventListener('message',function(ev){
|
|
32217
|
-
var d=null;
|
|
32218
|
-
try{d=typeof ev.data==='string'?JSON.parse(ev.data):null;}catch(_){}
|
|
32219
|
-
if(!d)return;
|
|
32220
|
-
if(d.type==='reload'||d.type==='change'||d.type==='css'){
|
|
32221
|
-
if(_t4_debounce)clearTimeout(_t4_debounce);
|
|
32222
|
-
_t4_debounce=setTimeout(function(){_t4_apply(d);},150);
|
|
32986
|
+
function poll() {
|
|
32987
|
+
fetch('/__dev/api/mtime').then(function (r) { return r.json(); }).then(function (d) {
|
|
32988
|
+
if (mtime === null) { mtime = d.mtime; return; }
|
|
32989
|
+
if (d.mtime !== mtime) { mtime = d.mtime; if (debounce) { clearTimeout(debounce); } debounce = setTimeout(function () { apply(d); }, 500); }
|
|
32990
|
+
}).catch(function () {});
|
|
32991
|
+
}
|
|
32992
|
+
function startPoll() { if (pollTimer) { return; } mtime = null; pollTimer = setInterval(poll, interval); }
|
|
32993
|
+
function stopPoll() { if (pollTimer) { clearInterval(pollTimer); pollTimer = null; } }
|
|
32994
|
+
function connect() {
|
|
32995
|
+
var url = (location.protocol === 'https:' ? 'wss' : 'ws') + '://' + location.host + '/__dev_reload';
|
|
32996
|
+
try { ws = new WebSocket(url); } catch (_) { startPoll(); return; }
|
|
32997
|
+
ws.addEventListener('open', function () { stopPoll(); });
|
|
32998
|
+
ws.addEventListener('message', function (ev) {
|
|
32999
|
+
var d = null;
|
|
33000
|
+
try { d = typeof ev.data === 'string' ? JSON.parse(ev.data) : null; } catch (_) {}
|
|
33001
|
+
if (!d) { return; }
|
|
33002
|
+
if (d.type === 'reload' || d.type === 'change' || d.type === 'css') {
|
|
33003
|
+
if (debounce) { clearTimeout(debounce); }
|
|
33004
|
+
debounce = setTimeout(function () { apply(d); }, 150);
|
|
32223
33005
|
}
|
|
32224
33006
|
});
|
|
32225
|
-
|
|
32226
|
-
|
|
33007
|
+
ws.addEventListener('close', function () { ws = null; startPoll(); setTimeout(connect, 2000); });
|
|
33008
|
+
ws.addEventListener('error', function () { try { ws && ws.close(); } catch (_) {} });
|
|
32227
33009
|
}
|
|
32228
|
-
|
|
32229
|
-
})()
|
|
32230
|
-
</script>`;
|
|
33010
|
+
connect();
|
|
33011
|
+
})();`;
|
|
32231
33012
|
}
|
|
32232
|
-
var cpuCount, DEV_SAFE_METHODS, DEV_MCP_PREFIXES, DEV_SECRET_BASENAMES, DEV_SECRET_SUFFIXES, MessageLog, RequestInspector, ErrorTracker, DevMailboxStore, DevQueue, WsTracker, DevAdmin, handleDashboard, _reloadMtime, _reloadFile, handleMtime, handleReload, handleMessages, handleMessagesClear, handleRequests, handleRequestsClear, handleSystem, handleMessagesSearch, handleQueue, handleQueueTopics, handleQueueDeadLetters, handleQueueRetry, handleQueuePurge, handleQueueReplay, handleMailbox, handleMailboxRead, handleMailboxSeed, handleMailboxClear, handleTable, handleTables, handleSeed, handleQuery, handleBroken, handleBrokenResolve, handleBrokenClear, handleWebsockets, handleWebsocketsDisconnect, handleTool, handleChat, DEFAULT_MCP_URL, handleGroundingStatus, handleGroundingToken, handleMigrate, handleSeedRun, handleTest, handleThreads, handleThreadsSub, handleConnections, handleConnectionsTest, handleConnectionsSave, __devAdminFilename, __devAdminDirname, handleGalleryList, handleVersionCheck, handleThoughts, handleSuperviseStub, handleExecute, DEV_FILES_IGNORED, handleFiles, DEV_ADMIN_LANG_MAP, handleFileRead, handleFileSave, handleFileRaw, handleFileRename, handleFileDelete, handleDepsSearch, handleDepsInstall, handleGitStatus, handleMcpTools, handleMcpCall, handleMcpStreamable, handleMcpDelete, handleMcpGet405, handleMcpLegacyMessage, handleMcpSse, handleScaffoldList, handleScaffoldRun, handlePlanCurrent, handlePlanList, handlePlanCreate, handlePlanSwitch, handlePlanCompleteStep, handlePlanAddStep, handlePlanNote, handlePlanArchive, handlePlanRead, handlePlanFlesh, handleIndexRebuild, handleIndexSearch, handleIndexFile, handleIndexOverview, handleDocsSearch, handleDocsClass, handleDocsMethod, handleDocsIndex, handleDocsWellKnown, handleDevAdminJs;
|
|
33013
|
+
var cpuCount, DEV_SAFE_METHODS, DEV_MCP_PREFIXES, DEV_SECRET_BASENAMES, DEV_SECRET_SUFFIXES, MessageLog, RequestInspector, ErrorTracker, DevMailboxStore, DevQueue, WsTracker, DevAdmin, handleDashboard, _reloadMtime, _reloadFile, handleMtime, handleReload, handleMessages, handleMessagesClear, handleRequests, handleRequestsClear, handleSystem, handleMessagesSearch, handleQueue, handleQueueTopics, handleQueueDeadLetters, handleQueueRetry, handleQueuePurge, handleQueueReplay, handleMailbox, handleMailboxRead, handleMailboxSeed, handleMailboxClear, handleTable, handleTables, handleSeed, handleQuery, handleBroken, handleBrokenResolve, handleBrokenClear, handleWebsockets, handleWebsocketsDisconnect, handleTool, handleChat, DEFAULT_MCP_URL, handleGroundingStatus, handleGroundingToken, handleMigrate, handleSeedRun, handleTest, handleThreads, handleThreadsSub, handleConnections, handleConnectionsTest, handleConnectionsSave, __devAdminFilename, __devAdminDirname, handleGalleryList, handleVersionCheck, handleThoughts, handleSuperviseStub, handleExecute, DEV_FILES_IGNORED, handleFiles, DEV_ADMIN_LANG_MAP, handleFileRead, handleFileSave, handleFileRaw, handleFileRename, handleFileDelete, handleDepsSearch, handleDepsInstall, handleGitStatus, handleMcpTools, handleMcpCall, handleMcpStreamable, handleMcpDelete, handleMcpGet405, handleMcpLegacyMessage, handleMcpSse, handleScaffoldList, handleScaffoldRun, handlePlanCurrent, handlePlanList, handlePlanCreate, handlePlanSwitch, handlePlanCompleteStep, handlePlanAddStep, handlePlanNote, handlePlanArchive, handlePlanRead, handlePlanFlesh, handleIndexRebuild, handleIndexSearch, handleIndexFile, handleIndexOverview, handleDocsSearch, handleDocsClass, handleDocsMethod, handleDocsIndex, handleDocsWellKnown, handleDevAdminJs, handleToolbarCss, handleToolbarJs;
|
|
32233
33014
|
var init_devAdmin = __esm({
|
|
32234
33015
|
"src/devAdmin.ts"() {
|
|
32235
33016
|
"use strict";
|
|
@@ -32695,7 +33476,12 @@ var init_devAdmin = __esm({
|
|
|
32695
33476
|
{ method: "GET", pattern: "/__dev/api/docs/index", handler: handleDocsIndex },
|
|
32696
33477
|
{ method: "GET", pattern: "/__dev/api/docs/.well-known.json", handler: handleDocsWellKnown },
|
|
32697
33478
|
// JS asset
|
|
32698
|
-
{ method: "GET", pattern: "/__dev/js/tina4-dev-admin.min.js", handler: handleDevAdminJs }
|
|
33479
|
+
{ method: "GET", pattern: "/__dev/js/tina4-dev-admin.min.js", handler: handleDevAdminJs },
|
|
33480
|
+
// Dev-toolbar assets — served as external CSS/JS so the injected toolbar is
|
|
33481
|
+
// CSP-clean (no inline style=, onclick=, or <script>) under a strict
|
|
33482
|
+
// `default-src 'self'`. Parity with PHP's /__dev/toolbar.css + toolbar.js.
|
|
33483
|
+
{ method: "GET", pattern: "/__dev/toolbar.css", handler: handleToolbarCss },
|
|
33484
|
+
{ method: "GET", pattern: "/__dev/toolbar.js", handler: handleToolbarJs }
|
|
32699
33485
|
];
|
|
32700
33486
|
for (const route of routes) {
|
|
32701
33487
|
router.addRoute({
|
|
@@ -34131,6 +34917,14 @@ var init_devAdmin = __esm({
|
|
|
34131
34917
|
res.raw.writeHead(404, { "Content-Type": "text/plain" });
|
|
34132
34918
|
res.raw.end("tina4-dev-admin.min.js not found");
|
|
34133
34919
|
};
|
|
34920
|
+
handleToolbarCss = (_req, res) => {
|
|
34921
|
+
res.raw.writeHead(200, { "Content-Type": "text/css; charset=utf-8", "Cache-Control": "no-cache" });
|
|
34922
|
+
res.raw.end(toolbarCss());
|
|
34923
|
+
};
|
|
34924
|
+
handleToolbarJs = (_req, res) => {
|
|
34925
|
+
res.raw.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8", "Cache-Control": "no-cache" });
|
|
34926
|
+
res.raw.end(toolbarJs());
|
|
34927
|
+
};
|
|
34134
34928
|
}
|
|
34135
34929
|
});
|
|
34136
34930
|
|
|
@@ -35992,7 +36786,11 @@ function injectIntoHtml(ctx, devToolbar, html) {
|
|
|
35992
36786
|
path: ctx.pathname,
|
|
35993
36787
|
matchedPattern: ctx.matchedPattern.value || ctx.pathname,
|
|
35994
36788
|
requestId: ctx.requestId,
|
|
35995
|
-
routeCount: ctx.router.getRoutes().length
|
|
36789
|
+
routeCount: ctx.router.getRoutes().length,
|
|
36790
|
+
// Suppress the live reloader on the AI/stable port (data-reload="0"); the
|
|
36791
|
+
// toolbar JS early-returns when data-reload !== "1". Mirrors PHP's
|
|
36792
|
+
// suppressReload flag.
|
|
36793
|
+
reload: !ctx.isAiPortRequest
|
|
35996
36794
|
};
|
|
35997
36795
|
return injectFeedbackWidget(ctx.req, injectDevToolbar(html, toolbarCtx));
|
|
35998
36796
|
}
|