tina4-nodejs 3.13.165 → 3.13.166
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 +12 -5
- package/package.json +1 -1
- package/packages/cli/dist/bin.js +596 -342
- package/packages/cli/src/commands/seed.ts +10 -11
- package/packages/core/dist/index.js +586 -328
- package/packages/core/src/connectionUrl.ts +242 -0
- package/packages/core/src/devAdmin.ts +18 -3
- package/packages/core/src/fakeData.ts +47 -12
- package/packages/core/src/index.ts +1 -1
- package/packages/core/src/mqtt.ts +24 -48
- package/packages/core/src/queueBackends/rabbitmqBackend.ts +32 -20
- package/packages/core/src/router.ts +44 -30
- package/packages/core/src/server.ts +35 -18
- package/packages/core/src/urlRedaction.ts +252 -0
- package/packages/core/src/websocketBackplane.ts +15 -3
- package/packages/orm/dist/index.js +577 -320
- package/packages/orm/src/database.ts +7 -1
- package/packages/orm/src/databaseUrl.ts +73 -190
- package/packages/orm/src/docstore.ts +8 -1
- package/packages/orm/src/graph/graphUrl.ts +43 -7
- package/types/core/src/connectionUrl.d.ts +61 -0
- package/types/core/src/fakeData.d.ts +11 -2
- package/types/core/src/index.d.ts +1 -1
- package/types/core/src/queueBackends/rabbitmqBackend.d.ts +0 -7
- package/types/core/src/router.d.ts +17 -2
- package/types/core/src/server.d.ts +13 -0
- package/types/core/src/urlRedaction.d.ts +61 -0
- package/types/orm/src/databaseUrl.d.ts +18 -19
- package/types/orm/src/graph/graphUrl.d.ts +18 -0
|
@@ -10,6 +10,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
10
10
|
import type { DatabaseAdapter, DatabaseResult as DatabaseWriteResult, ColumnInfo, FieldDefinition } from "./types.js";
|
|
11
11
|
import { DatabaseResult } from "./databaseResult.js";
|
|
12
12
|
import { DatabaseUrl } from "./databaseUrl.js";
|
|
13
|
+
import { canonicalConnectionUrl, splitConnectionUrl } from "../../core/src/connectionUrl.js";
|
|
13
14
|
import { CachedDatabaseAdapter, type CachedAdapterOptions } from "./cachedDatabase.js";
|
|
14
15
|
import { QueryCache, SQLTranslator } from "./sqlTranslator.js";
|
|
15
16
|
import { quoteIdentifierAnsi, assertColumnNames } from "./adapters/sqlDialect.js";
|
|
@@ -1841,7 +1842,12 @@ async function buildAdapterFromUrl(url: string, username?: string, password?: st
|
|
|
1841
1842
|
}
|
|
1842
1843
|
case "mongodb": {
|
|
1843
1844
|
const { MongodbAdapter } = await import("./adapters/mongodb.js");
|
|
1844
|
-
|
|
1845
|
+
// The driver runs its OWN URL parser and quotes what it could not parse
|
|
1846
|
+
// ("Unable to parse u:Pq1 with URL"), so it gets the credentials
|
|
1847
|
+
// percent-encoded - never a raw password holding / ? # @ (GHSA-h2mr-m3v3-cq8c).
|
|
1848
|
+
const adapter = new MongodbAdapter(
|
|
1849
|
+
canonicalConnectionUrl(splitConnectionUrl(url, { label: "DatabaseUrl", allowHostList: true })),
|
|
1850
|
+
);
|
|
1845
1851
|
await adapter.connect();
|
|
1846
1852
|
return adapter;
|
|
1847
1853
|
}
|
|
@@ -20,6 +20,8 @@ file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
20
20
|
* key, byte-identical in all four.
|
|
21
21
|
*/
|
|
22
22
|
import { inspect } from "node:util";
|
|
23
|
+
import { REDACTED, redactCredentials } from "../../core/src/urlRedaction.js";
|
|
24
|
+
import { ConnectionUrlError, splitConnectionUrl, type ConnectionUrlParts } from "../../core/src/connectionUrl.js";
|
|
23
25
|
|
|
24
26
|
/** The canonical engine names. Aliases resolve to these ONCE, at parse. */
|
|
25
27
|
export type DatabaseEngine =
|
|
@@ -76,171 +78,42 @@ function stripOneSlash(path: string): string {
|
|
|
76
78
|
return path.startsWith("/") ? path.slice(1) : path;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
function decode(value: string | undefined): string | null {
|
|
80
|
-
if (value === undefined || value === "") return null;
|
|
81
|
-
return decodeURIComponent(value);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
81
|
// ── redaction ──────────────────────────────────────────────────────────────
|
|
85
82
|
// ONE primitive, used by every path that can put a connection string in front
|
|
86
|
-
// of a human.
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
/** The single mask. One spelling, so grepping for it finds every redaction. */
|
|
92
|
-
const REDACTED = "***";
|
|
83
|
+
// of a human. It lives in core's dependency-free urlRedaction.ts so that core
|
|
84
|
+
// (mqtt, the AMQP queue, the backplane, the boot log) and this package share
|
|
85
|
+
// the SAME rule rather than two drifting copies. Re-exported here because it
|
|
86
|
+
// has always been part of @tina4/orm's public surface.
|
|
87
|
+
export { redactCredentials };
|
|
93
88
|
|
|
94
89
|
/**
|
|
95
|
-
*
|
|
90
|
+
* The failure a malformed `TINA4_DATABASE_URL` raises.
|
|
96
91
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* `;` for ODBC/libpq, `&` for a query string - plus the closing brace/quote of
|
|
101
|
-
* a quoted value, since `PWD={p;w}` and the libpq quoted form both legally
|
|
102
|
-
* contain a separator.
|
|
92
|
+
* The message NEVER carries the URL, and nothing it chains does either. It
|
|
93
|
+
* stays diagnosable: the scheme or engine is named, plus the host:port when it
|
|
94
|
+
* sits after the last `@` (the only place it cannot be part of a password).
|
|
103
95
|
*/
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let i = start + 1;
|
|
112
|
-
while (i < text.length) {
|
|
113
|
-
if (text[i] === "\\") { i += 2; continue; }
|
|
114
|
-
if (text[i] === open) return i + 1;
|
|
115
|
-
i++;
|
|
116
|
-
}
|
|
117
|
-
return text.length;
|
|
118
|
-
}
|
|
119
|
-
let i = start;
|
|
120
|
-
while (i < text.length && text[i] !== ";" && text[i] !== "&") i++;
|
|
121
|
-
return i;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** `PWD=`/`password=`/`passwd=` in an ODBC DSN, a libpq DSN or a query string. */
|
|
125
|
-
const SECRET_KEYWORD_PATTERN = /(^|[;&?\s])(pwd|password|passwd)(\s*=\s*)/gi;
|
|
126
|
-
|
|
127
|
-
function redactKeywordValues(text: string): string {
|
|
128
|
-
const pattern = new RegExp(SECRET_KEYWORD_PATTERN.source, SECRET_KEYWORD_PATTERN.flags);
|
|
129
|
-
let out = "";
|
|
130
|
-
let cursor = 0;
|
|
131
|
-
let match: RegExpExecArray | null;
|
|
132
|
-
while ((match = pattern.exec(text)) !== null) {
|
|
133
|
-
const valueStart = match.index + match[0].length;
|
|
134
|
-
out += text.slice(cursor, valueStart) + REDACTED;
|
|
135
|
-
cursor = endOfKeywordValue(text, valueStart);
|
|
136
|
-
pattern.lastIndex = cursor;
|
|
96
|
+
function invalidUrlError(raw: string, engine: DatabaseEngine, why: string): Error {
|
|
97
|
+
let hostPort: string | undefined;
|
|
98
|
+
try {
|
|
99
|
+
const parts = splitConnectionUrl(raw, { label: "DatabaseUrl" });
|
|
100
|
+
if (parts.userinfo !== null && parts.hostPort !== "") hostPort = parts.hostPort;
|
|
101
|
+
} catch {
|
|
102
|
+
// already refused: name nothing beyond the engine
|
|
137
103
|
}
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
* The authority of `scheme://user:pass@host:port/path`, or null when the string
|
|
143
|
-
* has no `://` at all. Everything the other helpers need is derived from here,
|
|
144
|
-
* so "where does userinfo end" is decided in exactly one place.
|
|
145
|
-
*/
|
|
146
|
-
function authorityOf(raw: string): string | null {
|
|
147
|
-
const separator = raw.indexOf("://");
|
|
148
|
-
if (separator === -1) return null;
|
|
149
|
-
const rest = raw.slice(separator + 3);
|
|
150
|
-
const end = rest.search(/[/?#]/);
|
|
151
|
-
return end === -1 ? rest : rest.slice(0, end);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* The raw, still-encoded userinfo, or null when the URL carries none.
|
|
156
|
-
*
|
|
157
|
-
* Read off the RAW string on purpose: `new URL()` normalises
|
|
158
|
-
* `postgres://user:@host/db` and `postgres://user@host/db` to the identical
|
|
159
|
-
* href, so the URL object cannot tell an explicitly-blank password from an
|
|
160
|
-
* absent one (measured on Node 24.9.0 - both report `.password === ""`).
|
|
161
|
-
*/
|
|
162
|
-
function rawUserinfo(raw: string): string | null {
|
|
163
|
-
const authority = authorityOf(raw);
|
|
164
|
-
if (authority === null) return null;
|
|
165
|
-
const at = authority.lastIndexOf("@");
|
|
166
|
-
return at === -1 ? null : authority.slice(0, at);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function redactUserinfoPassword(raw: string): string {
|
|
170
|
-
const authority = authorityOf(raw);
|
|
171
|
-
if (authority === null) return raw;
|
|
172
|
-
const at = authority.lastIndexOf("@");
|
|
173
|
-
if (at === -1) return raw;
|
|
174
|
-
const colon = authority.slice(0, at).indexOf(":");
|
|
175
|
-
if (colon === -1) return raw; // a username with no password
|
|
176
|
-
const authorityStart = raw.indexOf("://") + 3;
|
|
177
|
-
return (
|
|
178
|
-
raw.slice(0, authorityStart + colon + 1) + REDACTED + raw.slice(authorityStart + at)
|
|
104
|
+
return new ConnectionUrlError(
|
|
105
|
+
`DatabaseUrl: invalid ${engine} URL${hostPort ? ` at '${hostPort}'` : ""} (${why}) - expected ` +
|
|
106
|
+
"scheme://[user[:password]@]host[:port]/database. " +
|
|
107
|
+
"The URL itself is not shown because it may contain a password.",
|
|
179
108
|
);
|
|
180
109
|
}
|
|
181
110
|
|
|
182
|
-
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
* second, weaker rule.
|
|
189
|
-
*
|
|
190
|
-
* It cannot be complete on a string with no recognisable credential structure
|
|
191
|
-
* (`notaurl-with-hunter2` has nothing to key off), which is exactly why the
|
|
192
|
-
* invalid-URL error reports the scheme and host instead of any form of the
|
|
193
|
-
* input. Redaction is for strings we can parse enough to redact.
|
|
194
|
-
*/
|
|
195
|
-
export function redactCredentials(raw: string): string {
|
|
196
|
-
if (typeof raw !== "string" || raw === "") return raw;
|
|
197
|
-
return redactKeywordValues(redactUserinfoPassword(raw));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/** `postgres` from `postgres://…`, or null when the string names no scheme. */
|
|
201
|
-
function schemeOf(raw: string): string | null {
|
|
202
|
-
const match = raw.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);
|
|
203
|
-
return match ? match[1].toLowerCase() : null;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* The `host:port` slice of the authority, or null.
|
|
208
|
-
*
|
|
209
|
-
* Credential-free BY CONSTRUCTION: it is the part AFTER the last `@`, and
|
|
210
|
-
* userinfo - the only place a password may appear in a URL - is entirely
|
|
211
|
-
* before it. That is what makes it safe to name in an error message.
|
|
212
|
-
*/
|
|
213
|
-
function hostPortOf(raw: string): string | null {
|
|
214
|
-
const authority = authorityOf(raw);
|
|
215
|
-
if (authority === null) return null;
|
|
216
|
-
const at = authority.lastIndexOf("@");
|
|
217
|
-
const hostPort = at === -1 ? authority : authority.slice(at + 1);
|
|
218
|
-
return hostPort === "" ? null : hostPort;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* The failure a malformed `TINA4_DATABASE_URL` raises.
|
|
223
|
-
*
|
|
224
|
-
* The message NEVER carries the URL. The old one interpolated it, so a typo in
|
|
225
|
-
* the port wrote the password into the boot log, the crash report, the error
|
|
226
|
-
* overlay and the CI log - measured: `TINA4_DATABASE_URL` of
|
|
227
|
-
* `postgres://user:SuperSecret123@host:notaport/db` produced
|
|
228
|
-
* `DatabaseUrl: invalid URL format 'postgres://user:SuperSecret123@host:notaport/db'`.
|
|
229
|
-
*
|
|
230
|
-
* It stays diagnosable: the scheme (or engine) and the host:port are both in
|
|
231
|
-
* the message, along with the shape that was expected. A redaction that leaves
|
|
232
|
-
* nothing to debug with is its own kind of bug.
|
|
233
|
-
*/
|
|
234
|
-
function invalidUrlError(raw: string, engine?: DatabaseEngine): Error {
|
|
235
|
-
const named = engine ?? schemeOf(raw);
|
|
236
|
-
const subject = named ? `invalid ${named} URL` : "invalid URL (no scheme found)";
|
|
237
|
-
const hostPort = hostPortOf(raw);
|
|
238
|
-
const at = hostPort === null ? "" : ` at '${hostPort}'`;
|
|
239
|
-
return new Error(
|
|
240
|
-
`DatabaseUrl: ${subject}${at} - expected ` +
|
|
241
|
-
"scheme://[user[:password]@]host[:port]/database. " +
|
|
242
|
-
"The URL itself is not shown because it may contain a password."
|
|
243
|
-
);
|
|
111
|
+
/** Split under the shared rule; the refusal names the scheme, never the value. */
|
|
112
|
+
function split(url: string): ConnectionUrlParts {
|
|
113
|
+
return splitConnectionUrl(url, {
|
|
114
|
+
label: "DatabaseUrl",
|
|
115
|
+
expected: "scheme://[user[:password]@]host[:port]/database",
|
|
116
|
+
});
|
|
244
117
|
}
|
|
245
118
|
|
|
246
119
|
/**
|
|
@@ -388,13 +261,14 @@ export class DatabaseUrl {
|
|
|
388
261
|
if (url.startsWith("odbc:///")) {
|
|
389
262
|
return { engine: "odbc", connectionString: url.slice("odbc:///".length) };
|
|
390
263
|
}
|
|
391
|
-
|
|
392
|
-
|
|
264
|
+
const parts = split(url);
|
|
265
|
+
if (parts.scheme === "mssql" || parts.scheme === "sqlserver") {
|
|
266
|
+
return DatabaseUrl.parsePathForm(url, parts, "mssql");
|
|
393
267
|
}
|
|
394
|
-
if (
|
|
395
|
-
return DatabaseUrl.
|
|
268
|
+
if (parts.scheme === "firebird") {
|
|
269
|
+
return DatabaseUrl.parsePathForm(url, parts, "firebird");
|
|
396
270
|
}
|
|
397
|
-
return DatabaseUrl.parseStandard(url);
|
|
271
|
+
return DatabaseUrl.parseStandard(url, parts);
|
|
398
272
|
}
|
|
399
273
|
|
|
400
274
|
/**
|
|
@@ -422,60 +296,69 @@ export class DatabaseUrl {
|
|
|
422
296
|
}
|
|
423
297
|
|
|
424
298
|
/**
|
|
425
|
-
* mssql and firebird:
|
|
426
|
-
* matched directly.
|
|
299
|
+
* mssql and firebird: `host[:port]/database`, split by the shared splitter.
|
|
427
300
|
*
|
|
428
|
-
*
|
|
301
|
+
* These used to be one regex each that split userinfo at the FIRST `@` and
|
|
302
|
+
* the password at the first `/`, so `mssql://u:p@ss@h/db` connected to a host
|
|
303
|
+
* named `ss@h` and printed it in the driver's error.
|
|
304
|
+
*
|
|
305
|
+
* The database keeps its own leading slash when the URL had two, which is
|
|
429
306
|
* how the documented absolute Firebird form survives. The old code did
|
|
430
307
|
* `"/" + match[5]`, ADDING a slash - so an absolute path came back with two
|
|
431
308
|
* and a relative path was silently made absolute. Verified against live
|
|
432
309
|
* Firebird 5.0.4: the driver takes one or two leading slashes and rejects a
|
|
433
310
|
* relative path outright.
|
|
434
311
|
*/
|
|
435
|
-
private static
|
|
436
|
-
|
|
437
|
-
|
|
312
|
+
private static parsePathForm(url: string, parts: ConnectionUrlParts, engine: DatabaseEngine): ParsedParts {
|
|
313
|
+
if (parts.host === "" || /[:/]/.test(parts.host) || parts.hostPort.startsWith("[")) {
|
|
314
|
+
throw invalidUrlError(url, engine, "a host is required");
|
|
315
|
+
}
|
|
316
|
+
if (!parts.tail.startsWith("/")) throw invalidUrlError(url, engine, "a /database is required");
|
|
438
317
|
return {
|
|
439
318
|
engine,
|
|
440
|
-
username:
|
|
441
|
-
password:
|
|
442
|
-
host:
|
|
443
|
-
port:
|
|
444
|
-
database:
|
|
319
|
+
username: parts.username === "" ? null : parts.username,
|
|
320
|
+
password: parts.password,
|
|
321
|
+
host: parts.host,
|
|
322
|
+
port: parts.port ?? undefined,
|
|
323
|
+
database: parts.tail.slice(1),
|
|
445
324
|
};
|
|
446
325
|
}
|
|
447
326
|
|
|
448
|
-
/**
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
327
|
+
/**
|
|
328
|
+
* postgres / mysql / mongodb.
|
|
329
|
+
*
|
|
330
|
+
* Userinfo comes from the shared splitter (the last-`@` rule), never from the
|
|
331
|
+
* URL class: `new URL()` cuts a password at its first `/`, `?` or `#`, reads
|
|
332
|
+
* `postgres:/u:pw@h` as a path, and throws a TypeError whose `.input` is the
|
|
333
|
+
* whole URL. The class only sees a credential-free rebuild, for the host,
|
|
334
|
+
* port and path it already normalises the way every corpus row expects.
|
|
335
|
+
*/
|
|
336
|
+
private static parseStandard(url: string, parts: ConnectionUrlParts): ParsedParts {
|
|
337
|
+
const engine = ENGINE_ALIASES[parts.scheme];
|
|
458
338
|
if (engine === undefined) {
|
|
459
339
|
throw new Error(
|
|
460
|
-
`DatabaseUrl: Unsupported database scheme '${scheme}'. Supported: ${Object.keys(ENGINE_ALIASES).join(", ")}`
|
|
340
|
+
`DatabaseUrl: Unsupported database scheme '${parts.scheme}'. Supported: ${Object.keys(ENGINE_ALIASES).join(", ")}`
|
|
461
341
|
);
|
|
462
342
|
}
|
|
343
|
+
let parsed: URL;
|
|
344
|
+
try {
|
|
345
|
+
parsed = new URL(`${parts.scheme}://${parts.hostPort}${parts.tail}`);
|
|
346
|
+
} catch {
|
|
347
|
+
// No `cause`: the TypeError carries its input.
|
|
348
|
+
throw invalidUrlError(url, engine, "the host, port or path is malformed");
|
|
349
|
+
}
|
|
463
350
|
const database = stripOneSlash(parsed.pathname);
|
|
464
351
|
// A password that was WRITTEN but left blank (`postgres://user:@host/db`)
|
|
465
352
|
// is an explicitly-empty password, NOT an absent one, so the
|
|
466
353
|
// TINA4_DATABASE_PASSWORD fallback in the constructor must not fire for it.
|
|
467
|
-
//
|
|
468
|
-
//
|
|
469
|
-
// framework read it. The URL object cannot tell the two apart (it
|
|
470
|
-
// normalises both to `.password === ""`), so the RAW userinfo decides.
|
|
471
|
-
const userinfo = rawUserinfo(url);
|
|
472
|
-
const passwordWasWritten = userinfo !== null && userinfo.includes(":");
|
|
354
|
+
// The splitter reads the RAW userinfo, so it tells the two apart (`""`
|
|
355
|
+
// versus null) where the URL class normalised both to `.password === ""`.
|
|
473
356
|
return {
|
|
474
357
|
engine,
|
|
475
358
|
host: parsed.hostname || undefined,
|
|
476
359
|
port: parsed.port ? parseInt(parsed.port, 10) : undefined,
|
|
477
|
-
username:
|
|
478
|
-
password:
|
|
360
|
+
username: parts.username === "" ? null : parts.username,
|
|
361
|
+
password: parts.password,
|
|
479
362
|
database: engine === "mongodb" ? database || "tina4" : database,
|
|
480
363
|
};
|
|
481
364
|
}
|
|
@@ -58,6 +58,7 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
58
58
|
import { randomBytes } from "node:crypto";
|
|
59
59
|
import { mkdirSync } from "node:fs";
|
|
60
60
|
import { dirname, isAbsolute, join } from "node:path";
|
|
61
|
+
import { canonicalConnectionUrl, splitConnectionUrl } from "../../core/src/connectionUrl.js";
|
|
61
62
|
|
|
62
63
|
// ── ObjectId: zero-dependency 12-byte / 24-hex id ──────────────────────────
|
|
63
64
|
|
|
@@ -1061,7 +1062,13 @@ function mongoConnection(uri: string, dbName: string): Promise<{ client: any; db
|
|
|
1061
1062
|
if (!pending) {
|
|
1062
1063
|
pending = (async () => {
|
|
1063
1064
|
const { MongoClient } = await importMongoDriver();
|
|
1064
|
-
|
|
1065
|
+
// The driver's own parser quotes what it cannot parse ("Protocol and host
|
|
1066
|
+
// list are required in \"mongodb://u:pw@/db\""), so it only ever sees a
|
|
1067
|
+
// URI the shared rule split and re-encoded; anything else is refused
|
|
1068
|
+
// without echoing it (GHSA-h2mr-m3v3-cq8c).
|
|
1069
|
+
const client = new MongoClient(
|
|
1070
|
+
canonicalConnectionUrl(splitConnectionUrl(uri, { label: "DocStore", allowHostList: true })),
|
|
1071
|
+
);
|
|
1065
1072
|
await client.connect();
|
|
1066
1073
|
return { client, db: client.db(dbName) };
|
|
1067
1074
|
})();
|
|
@@ -14,7 +14,10 @@ file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
14
14
|
* alias (bolt/neo4j/memgraph all speak Bolt/Cypher and share ONE adapter) resolves
|
|
15
15
|
* to its engine here. See tina4-documentation/plan/v3/features/139-graph-databases.md.
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import { inspect } from "node:util";
|
|
18
|
+
|
|
19
|
+
import { redactCredentials } from "../../../core/src/urlRedaction.js";
|
|
20
|
+
import { ConnectionUrlError, splitConnectionUrl } from "../../../core/src/connectionUrl.js";
|
|
18
21
|
|
|
19
22
|
/** The canonical graph engine names. */
|
|
20
23
|
export type GraphEngine = "ultipa" | "bolt" | "arango";
|
|
@@ -59,13 +62,20 @@ export class GraphUrl {
|
|
|
59
62
|
|
|
60
63
|
constructor(url: string) {
|
|
61
64
|
this.raw = url;
|
|
65
|
+
// Userinfo by the shared last-`@` rule; the URL class only ever sees the
|
|
66
|
+
// credential-free rest. It used to parse the whole value, so a password
|
|
67
|
+
// holding `/`, `?` or `#` became the host/port/graph (and then the
|
|
68
|
+
// "connect to <host>" error), and the refusal quoted the URL back.
|
|
69
|
+
const expected = "scheme://[user[:password]@]host[:port]/graph (e.g. ultipa://host:60061/mygraph)";
|
|
70
|
+
const parts = splitConnectionUrl(url, { label: "GraphUrl", expected });
|
|
62
71
|
let parsed: URL;
|
|
63
72
|
try {
|
|
64
|
-
parsed = new URL(
|
|
73
|
+
parsed = new URL(`${parts.scheme}://${parts.hostPort}${parts.tail}`);
|
|
65
74
|
} catch {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
// No `cause`: the TypeError carries its input.
|
|
76
|
+
throw new ConnectionUrlError(
|
|
77
|
+
`GraphUrl: invalid ${parts.scheme} URL - expected ${expected}. `
|
|
78
|
+
+ "The URL itself is not shown because it may contain a password.",
|
|
69
79
|
);
|
|
70
80
|
}
|
|
71
81
|
const scheme = parsed.protocol.replace(/:$/, "").toLowerCase();
|
|
@@ -83,8 +93,8 @@ export class GraphUrl {
|
|
|
83
93
|
this.port = parsed.port ? parseInt(parsed.port, 10) : ENGINE_DEFAULT_PORT[engine];
|
|
84
94
|
const path = (parsed.pathname || "").replace(/^\//, "");
|
|
85
95
|
this.graph = path === "" ? null : path;
|
|
86
|
-
this.username =
|
|
87
|
-
this.password =
|
|
96
|
+
this.username = parts.username ? parts.username : null;
|
|
97
|
+
this.password = parts.password ? parts.password : null;
|
|
88
98
|
this.params = {};
|
|
89
99
|
for (const [key, value] of parsed.searchParams) {
|
|
90
100
|
// First value wins, matching Python's parse_qs[0].
|
|
@@ -94,6 +104,32 @@ export class GraphUrl {
|
|
|
94
104
|
this.useTls = scheme.endsWith("s") || this.params.tls === "1" || this.params.tls === "true";
|
|
95
105
|
}
|
|
96
106
|
|
|
107
|
+
/**
|
|
108
|
+
* What `JSON.stringify` emits, directly or as one field of a logged object.
|
|
109
|
+
* `password` and `raw` both hold the secret, so the default dump printed it
|
|
110
|
+
* twice (GHSA-h2mr-m3v3-cq8c). DatabaseUrl guards the same way; PHP has
|
|
111
|
+
* __debugInfo/jsonSerialize and Ruby a redacted #inspect.
|
|
112
|
+
*/
|
|
113
|
+
toJSON(): Record<string, unknown> {
|
|
114
|
+
return {
|
|
115
|
+
raw: redactCredentials(this.raw),
|
|
116
|
+
scheme: this.scheme,
|
|
117
|
+
engine: this.engine,
|
|
118
|
+
host: this.host,
|
|
119
|
+
port: this.port,
|
|
120
|
+
graph: this.graph,
|
|
121
|
+
username: this.username,
|
|
122
|
+
password: this.password === null ? null : "***",
|
|
123
|
+
params: this.params,
|
|
124
|
+
useTls: this.useTls,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** What `console.log(url)` / `util.inspect(url)` print. */
|
|
129
|
+
[inspect.custom](): string {
|
|
130
|
+
return `GraphUrl('${redactCredentials(this.raw)}')`;
|
|
131
|
+
}
|
|
132
|
+
|
|
97
133
|
/** host:port/graph — for messages, never carrying credentials. */
|
|
98
134
|
getDsn(): string {
|
|
99
135
|
const target = this.port ? `${this.host}:${this.port}` : this.host;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error every parser throws for a connection URL it will not accept.
|
|
3
|
+
*
|
|
4
|
+
* The message NEVER carries the value and the error NEVER has a `cause`: a
|
|
5
|
+
* TypeError from `new URL()` keeps the input on `.input`, and a driver's parse
|
|
6
|
+
* error quotes it, so chaining either would put the password straight back.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConnectionUrlError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
export interface ConnectionUrlParts {
|
|
12
|
+
/** Lower-cased scheme, e.g. `postgres`, `mongodb+srv`. */
|
|
13
|
+
scheme: string;
|
|
14
|
+
/** Raw (still-encoded) userinfo, or null when the URL has no `@`. */
|
|
15
|
+
userinfo: string | null;
|
|
16
|
+
/** Raw (still-encoded) user, or null. */
|
|
17
|
+
rawUsername: string | null;
|
|
18
|
+
/** Raw (still-encoded) password, or null when no `:` was written. */
|
|
19
|
+
rawPassword: string | null;
|
|
20
|
+
/** Decoded user, or null. */
|
|
21
|
+
username: string | null;
|
|
22
|
+
/** Decoded password, or null when no `:` was written ("" when written blank). */
|
|
23
|
+
password: string | null;
|
|
24
|
+
/** The raw `host[:port]` (or host list) after userinfo - credential-free. */
|
|
25
|
+
hostPort: string;
|
|
26
|
+
/** First host, brackets removed for IPv6, or "" when there is none. */
|
|
27
|
+
host: string;
|
|
28
|
+
/** First host's port, or null when none was written. */
|
|
29
|
+
port: number | null;
|
|
30
|
+
/** Path, query and fragment as written: "" or starting with `/`, `?` or `#`. */
|
|
31
|
+
tail: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SplitOptions {
|
|
34
|
+
/** Prefix for the error message, e.g. "DatabaseUrl". */
|
|
35
|
+
label: string;
|
|
36
|
+
/** What the message says was expected, e.g. "scheme://[user[:password]@]host[:port]/database". */
|
|
37
|
+
expected?: string;
|
|
38
|
+
/** Accept `h1:1,h2:2` (MongoDB). */
|
|
39
|
+
allowHostList?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Percent-decode, leaving an invalid escape as written instead of throwing. */
|
|
42
|
+
export declare function decodeComponent(value: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Split `scheme://[user[:password]@]host[:port][/path][?query][#fragment]`
|
|
45
|
+
* under THE RULE (see the header), refusing what it cannot split safely.
|
|
46
|
+
*
|
|
47
|
+
* Accepts an unencoded `/`, `?`, `#`, `@`, `:` or `%` in a password, which is
|
|
48
|
+
* what people actually paste into a .env file. Refuses, with a message that
|
|
49
|
+
* never echoes the value:
|
|
50
|
+
* - no `scheme://` (including `scheme:/` and `scheme//`)
|
|
51
|
+
* - an `@` outside userinfo (`?email=a@b` - encode it as `%40`)
|
|
52
|
+
* - userinfo with no host after it, a non-numeric port, a bad IPv6 bracket,
|
|
53
|
+
* or whitespace in the host
|
|
54
|
+
*/
|
|
55
|
+
export declare function splitConnectionUrl(raw: string, options: SplitOptions): ConnectionUrlParts;
|
|
56
|
+
/**
|
|
57
|
+
* The same URL with its credentials percent-encoded - what a driver that runs
|
|
58
|
+
* its own URL parser (mongodb, redis) is handed, so it can never re-split a
|
|
59
|
+
* password holding `/`, `?`, `#` or `@` and quote the pieces in its errors.
|
|
60
|
+
*/
|
|
61
|
+
export declare function canonicalConnectionUrl(parts: ConnectionUrlParts): string;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export declare class SeedError extends Error {
|
|
2
|
+
readonly seedFile: string;
|
|
3
|
+
readonly completed: string[];
|
|
4
|
+
constructor(seedFile: string, completed: string[], cause: unknown);
|
|
5
|
+
}
|
|
1
6
|
export declare const FIRST_NAMES: string[];
|
|
2
7
|
export declare const LAST_NAMES: string[];
|
|
3
8
|
export declare const PRODUCT_ADJECTIVES: string[];
|
|
@@ -56,8 +61,12 @@ export declare class FakeData {
|
|
|
56
61
|
*/
|
|
57
62
|
choice<T>(items: T[]): T;
|
|
58
63
|
/**
|
|
59
|
-
* Run seed files
|
|
60
|
-
*
|
|
64
|
+
* Run the seed files in a directory in name order, skipping files whose name
|
|
65
|
+
* starts with "_". A file's default export, or else the named run() that
|
|
66
|
+
* `generate seeder` writes, is awaited when it is a function.
|
|
67
|
+
* Returns the executed file paths in order ([] when the directory is missing).
|
|
68
|
+
* A seed file that throws stops the run: it is logged and a SeedError naming
|
|
69
|
+
* it is thrown, and no later file runs (ADR-0108).
|
|
61
70
|
*/
|
|
62
71
|
seedDir(seedDir?: string): Promise<string[]>;
|
|
63
72
|
/**
|
|
@@ -25,7 +25,7 @@ export { getToken, validToken, getPayload, hashPassword, checkPassword, authMidd
|
|
|
25
25
|
export { Session, FileSessionHandler, RedisSessionHandler, buildSessionCookie, isSecureScheme, isValidSessionId, sessionCookieName, VALID_SESSION_BACKENDS, CANONICAL_SESSION_BACKENDS } from "./session.js";
|
|
26
26
|
export type { SessionConfig, SessionHandler } from "./session.js";
|
|
27
27
|
export { I18n } from "./i18n.js";
|
|
28
|
-
export { FakeData } from "./fakeData.js";
|
|
28
|
+
export { FakeData, SeedError } from "./fakeData.js";
|
|
29
29
|
export { Queue } from "./queue.js";
|
|
30
30
|
export type { QueueConfig, QueueJob, ProcessOptions } from "./queue.js";
|
|
31
31
|
export { createJob } from "./job.js";
|
|
@@ -12,13 +12,6 @@ export interface RabbitMQConfig {
|
|
|
12
12
|
*/
|
|
13
13
|
visibilityTimeout?: number;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Parse an AMQP URL (amqp://[user:pass@]host[:port][/vhost]) into a partial
|
|
17
|
-
* RabbitMQConfig. Mirrors the Python/PHP/Ruby `parse_amqp_url` semantics:
|
|
18
|
-
* strips a leading amqp:// or amqps:// scheme, splits optional credentials,
|
|
19
|
-
* and reads the path segment as the URL-decoded vhost name. Only fields
|
|
20
|
-
* present in the URL are populated.
|
|
21
|
-
*/
|
|
22
15
|
export declare function parseAmqpUrl(url: string): RabbitMQConfig;
|
|
23
16
|
export interface QueueBackend {
|
|
24
17
|
push(queue: string, payload: unknown, delay?: number, priority?: number, raw?: boolean): string;
|
|
@@ -60,12 +60,16 @@ export declare class WsRouteRef {
|
|
|
60
60
|
/**
|
|
61
61
|
* Thin reference to a registered route, enabling chained modifiers.
|
|
62
62
|
*
|
|
63
|
+
* A ref may cover several compiled routes: `any()` registers one route per
|
|
64
|
+
* method, and a modifier chained on it must reach every one of them, not only
|
|
65
|
+
* the last one registered.
|
|
66
|
+
*
|
|
63
67
|
* Usage:
|
|
64
68
|
* router.get("/api/data", handler).secure().cache();
|
|
65
69
|
*/
|
|
66
70
|
export declare class RouteRef {
|
|
67
|
-
private
|
|
68
|
-
constructor(route: CompiledRoute);
|
|
71
|
+
private routes;
|
|
72
|
+
constructor(route: CompiledRoute | CompiledRoute[]);
|
|
69
73
|
/** Mark this route as requiring bearer-token authentication. */
|
|
70
74
|
secure(): this;
|
|
71
75
|
/** Opt out of secure-by-default auth (for public write routes). */
|
|
@@ -88,6 +92,12 @@ export declare class RouteRef {
|
|
|
88
92
|
* concrete requirement. Chain for AND. Implies auth. Feature 138.
|
|
89
93
|
*/
|
|
90
94
|
can(...permissions: string[]): this;
|
|
95
|
+
/**
|
|
96
|
+
* Add one OR-group of roles or permissions to every route this ref covers,
|
|
97
|
+
* and secure them (a guard implies auth). Empty names are dropped; a call
|
|
98
|
+
* with none left changes nothing.
|
|
99
|
+
*/
|
|
100
|
+
private guard;
|
|
91
101
|
/** Mark this route's response as cacheable. */
|
|
92
102
|
cache(): this;
|
|
93
103
|
/**
|
|
@@ -128,6 +138,8 @@ export declare class Router {
|
|
|
128
138
|
* Add a raw route definition (used internally and by file-based routing).
|
|
129
139
|
*/
|
|
130
140
|
addRoute(definition: RouteDefinition): RouteRef;
|
|
141
|
+
/** Compile and store one route definition; returns the stored route. */
|
|
142
|
+
private registerRoute;
|
|
131
143
|
/**
|
|
132
144
|
* Register a GET route programmatically.
|
|
133
145
|
*/
|
|
@@ -166,6 +178,9 @@ export declare class Router {
|
|
|
166
178
|
options(path: string, handler: RouteHandler, middlewares?: MiddlewareSpec[], meta?: RouteMeta): RouteRef;
|
|
167
179
|
/**
|
|
168
180
|
* Register a route that matches ANY HTTP method.
|
|
181
|
+
*
|
|
182
|
+
* One route is stored per method; the returned ref covers all of them, so
|
|
183
|
+
* `any(...).secure()` / `.role()` / `.noAuth()` apply to every method.
|
|
169
184
|
*/
|
|
170
185
|
any(path: string, handler: RouteHandler, middlewares?: MiddlewareSpec[], meta?: RouteMeta): RouteRef;
|
|
171
186
|
/**
|
|
@@ -17,6 +17,19 @@ export declare const DEFAULT_SHUTDOWN_TIMEOUT_SECONDS = 30;
|
|
|
17
17
|
* zero-second force-kill.
|
|
18
18
|
*/
|
|
19
19
|
export declare function shutdownTimeoutSeconds(): number;
|
|
20
|
+
/**
|
|
21
|
+
* The signals `startServer()` traps into its graceful shutdown on this platform.
|
|
22
|
+
*
|
|
23
|
+
* POSIX: SIGTERM (an orchestrator's stop) and SIGINT (Ctrl+C).
|
|
24
|
+
*
|
|
25
|
+
* Windows adds SIGBREAK: Ctrl+Break, and the CTRL_BREAK_EVENT a console or
|
|
26
|
+
* service manager sends a process group, arrive as SIGBREAK, and with no
|
|
27
|
+
* listener Node's default action kills the process on the spot (exit
|
|
28
|
+
* 0xC000013A) - in-flight requests dropped, no drain. Parity with tina4-python,
|
|
29
|
+
* which traps SIGINT/SIGBREAK/SIGTERM on Windows. Every listener registered for
|
|
30
|
+
* these replaces Node's default and therefore MUST exit (see background.ts).
|
|
31
|
+
*/
|
|
32
|
+
export declare function shutdownSignals(platform?: NodeJS.Platform): NodeJS.Signals[];
|
|
20
33
|
/**
|
|
21
34
|
* Build the startup banner's optional surface lines (issue #99).
|
|
22
35
|
*
|