@relaycast/engine 11.0.0 → 11.1.1
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/dist/adapters/node/database.d.ts +8 -3
- package/dist/adapters/node/database.d.ts.map +1 -1
- package/dist/adapters/node/database.js +9 -30
- package/dist/adapters/node/database.js.map +1 -1
- package/dist/adapters/node/migration-source.d.ts +17 -0
- package/dist/adapters/node/migration-source.d.ts.map +1 -0
- package/dist/adapters/node/migration-source.js +31 -0
- package/dist/adapters/node/migration-source.js.map +1 -0
- package/dist/adapters/node/pinned-https-fetch.d.ts +16 -0
- package/dist/adapters/node/pinned-https-fetch.d.ts.map +1 -0
- package/dist/adapters/node/pinned-https-fetch.js +83 -0
- package/dist/adapters/node/pinned-https-fetch.js.map +1 -0
- package/dist/adapters/node/sqlite-driver.d.ts +27 -0
- package/dist/adapters/node/sqlite-driver.d.ts.map +1 -0
- package/dist/adapters/node/sqlite-driver.js +9 -0
- package/dist/adapters/node/sqlite-driver.js.map +1 -0
- package/dist/adapters/node/ssrf-fetch.d.ts.map +1 -1
- package/dist/adapters/node/ssrf-fetch.js +35 -28
- package/dist/adapters/node/ssrf-fetch.js.map +1 -1
- package/dist/bin/serve.js +9 -0
- package/dist/bin/serve.js.map +1 -1
- package/dist/bin/version.d.ts +8 -0
- package/dist/bin/version.d.ts.map +1 -0
- package/dist/bin/version.js +12 -0
- package/dist/bin/version.js.map +1 -0
- package/dist/db/migrations/0076_deliveries_agent_status_created_index.sql +17 -0
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +2 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/engine/usage.d.ts +10 -0
- package/dist/engine/usage.d.ts.map +1 -1
- package/dist/engine/usage.js +18 -0
- package/dist/engine/usage.js.map +1 -1
- package/dist/env.d.ts +7 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/httpError.d.ts.map +1 -1
- package/dist/lib/httpError.js +3 -0
- package/dist/lib/httpError.js.map +1 -1
- package/dist/lib/planLimitError.d.ts +26 -0
- package/dist/lib/planLimitError.d.ts.map +1 -0
- package/dist/lib/planLimitError.js +16 -0
- package/dist/lib/planLimitError.js.map +1 -0
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +26 -1
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/planLimits.d.ts +31 -0
- package/dist/middleware/planLimits.d.ts.map +1 -1
- package/dist/middleware/planLimits.js +136 -4
- package/dist/middleware/planLimits.js.map +1 -1
- package/dist/ports/entitlements.d.ts +30 -0
- package/dist/ports/entitlements.d.ts.map +1 -1
- package/dist/ports/index.d.ts +1 -1
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js.map +1 -1
- package/dist/providers/static-entitlements.d.ts +1 -1
- package/dist/providers/static-entitlements.d.ts.map +1 -1
- package/dist/providers/static-entitlements.js +6 -1
- package/dist/providers/static-entitlements.js.map +1 -1
- package/dist/routes/dm.d.ts.map +1 -1
- package/dist/routes/dm.js +3 -1
- package/dist/routes/dm.js.map +1 -1
- package/dist/routes/groupDm.d.ts.map +1 -1
- package/dist/routes/groupDm.js +11 -7
- package/dist/routes/groupDm.js.map +1 -1
- package/dist/routes/message.d.ts.map +1 -1
- package/dist/routes/message.js +6 -2
- package/dist/routes/message.js.map +1 -1
- package/dist/routes/thread.d.ts.map +1 -1
- package/dist/routes/thread.js +6 -2
- package/dist/routes/thread.js.map +1 -1
- package/dist/routes/workspace.js +3 -0
- package/dist/routes/workspace.js.map +1 -1
- package/package.json +8 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { RunResult } from 'better-sqlite3';
|
|
2
|
+
import { type SqliteConnection } from './sqlite-driver.js';
|
|
2
3
|
import type { EngineDb, TransactionCapability } from '../../ports/database.js';
|
|
3
4
|
/**
|
|
4
5
|
* The engine handle specialized to better-sqlite3's synchronous run-result,
|
|
@@ -8,8 +9,12 @@ import type { EngineDb, TransactionCapability } from '../../ports/database.js';
|
|
|
8
9
|
export type NodeEngineDb = EngineDb<RunResult> & TransactionCapability;
|
|
9
10
|
export interface SqliteDbHandle {
|
|
10
11
|
db: NodeEngineDb;
|
|
11
|
-
/**
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The raw SQLite connection (for migrations, pragmas, backups). better-sqlite3
|
|
14
|
+
* on Node; a better-sqlite3-compatible `bun:sqlite` facade in the standalone
|
|
15
|
+
* binary.
|
|
16
|
+
*/
|
|
17
|
+
sqlite: SqliteConnection;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* Open a SQLite-backed {@link EngineDb} for self-host. Pass a file path
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/adapters/node/database.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/adapters/node/database.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEzE,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAE/E;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,SAAS,CAAC,GAAG,qBAAqB,CAAC;AAEvE,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,YAAY,CAAC;IACjB;;;;OAIG;IACH,MAAM,EAAE,gBAAgB,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAexD;AA6OD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAoC3E"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import Database from 'better-sqlite3';
|
|
6
|
-
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
7
|
-
import * as schema from '../../db/schema.js';
|
|
8
2
|
import { planMigrations } from '../../db/migrationPlan.js';
|
|
3
|
+
import { sqliteDriver } from './sqlite-driver.js';
|
|
4
|
+
import { loadMigrationSource } from './migration-source.js';
|
|
9
5
|
/**
|
|
10
6
|
* Open a SQLite-backed {@link EngineDb} for self-host. Pass a file path
|
|
11
7
|
* (created if absent) or `':memory:'` for tests. Sets WAL + foreign keys.
|
|
@@ -16,9 +12,9 @@ import { planMigrations } from '../../db/migrationPlan.js';
|
|
|
16
12
|
* is preserved, so {@link NodeEngineDb} stays precisely typed.
|
|
17
13
|
*/
|
|
18
14
|
export function getSqliteDb(path) {
|
|
19
|
-
const sqlite =
|
|
15
|
+
const sqlite = sqliteDriver.open(path);
|
|
20
16
|
configureSqlite(sqlite, { enableWal: true });
|
|
21
|
-
const db = drizzle(sqlite
|
|
17
|
+
const db = sqliteDriver.drizzle(sqlite);
|
|
22
18
|
// `:memory:` databases are connection-local: a transaction and a raw write
|
|
23
19
|
// share the same connection, so there is no cross-connection lock contention
|
|
24
20
|
// and no event-loop-freezing busy-wait. Keep the shared connection and only
|
|
@@ -117,10 +113,10 @@ function withFileWriteGate(db, path) {
|
|
|
117
113
|
// unrelated statements can't join the open transaction. `runAtomicWrites`
|
|
118
114
|
// detects this capability and prefers it over a batch.
|
|
119
115
|
db.withTransaction = (fn) => runGated(async () => {
|
|
120
|
-
const txSqlite =
|
|
116
|
+
const txSqlite = sqliteDriver.open(path);
|
|
121
117
|
try {
|
|
122
118
|
configureSqlite(txSqlite);
|
|
123
|
-
const txDb = drizzle(txSqlite
|
|
119
|
+
const txDb = sqliteDriver.drizzle(txSqlite);
|
|
124
120
|
txSqlite.exec('BEGIN IMMEDIATE');
|
|
125
121
|
try {
|
|
126
122
|
const result = await fn(txDb);
|
|
@@ -243,19 +239,6 @@ function configureSqlite(sqlite, options = {}) {
|
|
|
243
239
|
sqlite.pragma('foreign_keys = ON');
|
|
244
240
|
sqlite.pragma('busy_timeout = 5000');
|
|
245
241
|
}
|
|
246
|
-
function migrationsDir() {
|
|
247
|
-
// dist/adapters/node/database.js -> dist/db/migrations
|
|
248
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
249
|
-
const candidates = [
|
|
250
|
-
join(here, '../../db/migrations'),
|
|
251
|
-
join(here, '../../../src/db/migrations'),
|
|
252
|
-
];
|
|
253
|
-
for (const dir of candidates) {
|
|
254
|
-
if (existsSync(dir))
|
|
255
|
-
return dir;
|
|
256
|
-
}
|
|
257
|
-
return candidates[0];
|
|
258
|
-
}
|
|
259
242
|
/**
|
|
260
243
|
* Apply the engine's SQL migrations to a fresh/old SQLite database, in order.
|
|
261
244
|
* Tracks applied files in a `_engine_migrations` table so repeated boots are
|
|
@@ -268,12 +251,8 @@ export function runMigrations(handle) {
|
|
|
268
251
|
.prepare(`SELECT name FROM _engine_migrations`)
|
|
269
252
|
.all()
|
|
270
253
|
.map((r) => r.name));
|
|
271
|
-
const
|
|
272
|
-
const
|
|
273
|
-
.filter((f) => f.endsWith('.sql'))
|
|
274
|
-
.sort();
|
|
275
|
-
const supersessionsPath = join(dir, 'supersessions.json');
|
|
276
|
-
const pending = planMigrations(files, done, JSON.parse(readFileSync(supersessionsPath, 'utf8')));
|
|
254
|
+
const source = loadMigrationSource();
|
|
255
|
+
const pending = planMigrations(source.files, done, source.supersessions);
|
|
277
256
|
const applied = [];
|
|
278
257
|
const insert = sqlite.prepare(`INSERT INTO _engine_migrations (name, applied_at) VALUES (?, ?)`);
|
|
279
258
|
for (const file of pending) {
|
|
@@ -282,7 +261,7 @@ export function runMigrations(handle) {
|
|
|
282
261
|
// applied in one transaction so a crash mid-migration can't leave the schema
|
|
283
262
|
// changed but unrecorded (which would replay and fail on the next boot).
|
|
284
263
|
// drizzle migrations never contain their own BEGIN/COMMIT, so this won't nest.
|
|
285
|
-
const ddl =
|
|
264
|
+
const ddl = source.read(file).replace(/-->\s*statement-breakpoint/g, '');
|
|
286
265
|
const applyOne = sqlite.transaction(() => {
|
|
287
266
|
sqlite.exec(ddl);
|
|
288
267
|
insert.run(file, Math.floor(Date.now() / 1000));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/adapters/node/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/adapters/node/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAyB,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAoB5D;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,eAAe,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAiB,CAAC;IAExD,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,mCAAmC;IACnC,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,uBAAuB,CAAC,EAAE,EAAE,MAAM,CAAC,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IACrC,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IAEzE,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAC3B,iEAAiE,CAClE,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,6EAA6E;QAC7E,0EAA0E;QAC1E,6EAA6E;QAC7E,yEAAyE;QACzE,+EAA+E;QAC/E,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,6BAA6B,EAAE,EAAE,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE;YACvC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QACH,QAAQ,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The engine's SQL migrations: file names, their contents, and the supersession manifest. */
|
|
2
|
+
export interface MigrationSource {
|
|
3
|
+
/** Migration file names (`NNNN_name.sql`). Order is not significant; the planner sorts. */
|
|
4
|
+
files: string[];
|
|
5
|
+
/** Read one migration file's SQL. */
|
|
6
|
+
read(file: string): string;
|
|
7
|
+
/** Parsed `supersessions.json`. */
|
|
8
|
+
supersessions: unknown;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Load migrations from the package's `db/migrations` directory on disk.
|
|
12
|
+
*
|
|
13
|
+
* The standalone single-file build replaces this module at bundle time with one
|
|
14
|
+
* that serves the same files embedded in the binary.
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadMigrationSource(): MigrationSource;
|
|
17
|
+
//# sourceMappingURL=migration-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-source.d.ts","sourceRoot":"","sources":["../../../src/adapters/node/migration-source.ts"],"names":[],"mappings":"AAIA,8FAA8F;AAC9F,MAAM,WAAW,eAAe;IAC9B,2FAA2F;IAC3F,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,qCAAqC;IACrC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,mCAAmC;IACnC,aAAa,EAAE,OAAO,CAAC;CACxB;AAeD;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,eAAe,CAOrD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
function migrationsDir() {
|
|
5
|
+
// dist/adapters/node/migration-source.js -> dist/db/migrations
|
|
6
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const candidates = [
|
|
8
|
+
join(here, '../../db/migrations'),
|
|
9
|
+
join(here, '../../../src/db/migrations'),
|
|
10
|
+
];
|
|
11
|
+
for (const dir of candidates) {
|
|
12
|
+
if (existsSync(dir))
|
|
13
|
+
return dir;
|
|
14
|
+
}
|
|
15
|
+
return candidates[0];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Load migrations from the package's `db/migrations` directory on disk.
|
|
19
|
+
*
|
|
20
|
+
* The standalone single-file build replaces this module at bundle time with one
|
|
21
|
+
* that serves the same files embedded in the binary.
|
|
22
|
+
*/
|
|
23
|
+
export function loadMigrationSource() {
|
|
24
|
+
const dir = migrationsDir();
|
|
25
|
+
return {
|
|
26
|
+
files: readdirSync(dir).filter((f) => f.endsWith('.sql')),
|
|
27
|
+
read: (file) => readFileSync(join(dir, file), 'utf8'),
|
|
28
|
+
supersessions: JSON.parse(readFileSync(join(dir, 'supersessions.json'), 'utf8')),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=migration-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-source.js","sourceRoot":"","sources":["../../../src/adapters/node/migration-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAYzC,SAAS,aAAa;IACpB,+DAA+D;IAC/D,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG;QACjB,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC;QACjC,IAAI,CAAC,IAAI,EAAE,4BAA4B,CAAC;KACzC,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC7B,IAAI,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC;IAClC,CAAC;IACD,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,GAAG,GAAG,aAAa,EAAE,CAAC;IAC5B,OAAO;QACL,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACzD,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QACrD,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC,CAAC;KACjF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LookupFunction } from 'node:net';
|
|
2
|
+
/**
|
|
3
|
+
* A minimal `fetch` over `node:https` whose connection resolves the hostname
|
|
4
|
+
* through `lookup`, so the socket opens to exactly the address `lookup`
|
|
5
|
+
* approved, while TLS still verifies the certificate against the URL hostname
|
|
6
|
+
* (SNI and the Host header keep the hostname).
|
|
7
|
+
*
|
|
8
|
+
* This exists for Bun: Bun replaces the `undici` package with a built-in shim
|
|
9
|
+
* whose `fetch` ignores `dispatcher`, so undici's `connect.lookup` pinning
|
|
10
|
+
* silently stops applying. Bun's `node:https` honours `lookup`.
|
|
11
|
+
*
|
|
12
|
+
* Redirects are never followed (callers use `redirect: 'manual'`); the 3xx
|
|
13
|
+
* response is returned as-is.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createLookupPinnedHttpsFetch(lookup: LookupFunction): typeof globalThis.fetch;
|
|
16
|
+
//# sourceMappingURL=pinned-https-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinned-https-fetch.d.ts","sourceRoot":"","sources":["../../../src/adapters/node/pinned-https-fetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAM/C;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,UAAU,CAAC,KAAK,CA6D5F"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { request as httpsRequest } from 'node:https';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
/** Statuses whose response must not carry a body (`new Response` rejects one). */
|
|
4
|
+
const NULL_BODY_STATUSES = new Set([101, 204, 205, 304]);
|
|
5
|
+
/**
|
|
6
|
+
* A minimal `fetch` over `node:https` whose connection resolves the hostname
|
|
7
|
+
* through `lookup`, so the socket opens to exactly the address `lookup`
|
|
8
|
+
* approved, while TLS still verifies the certificate against the URL hostname
|
|
9
|
+
* (SNI and the Host header keep the hostname).
|
|
10
|
+
*
|
|
11
|
+
* This exists for Bun: Bun replaces the `undici` package with a built-in shim
|
|
12
|
+
* whose `fetch` ignores `dispatcher`, so undici's `connect.lookup` pinning
|
|
13
|
+
* silently stops applying. Bun's `node:https` honours `lookup`.
|
|
14
|
+
*
|
|
15
|
+
* Redirects are never followed (callers use `redirect: 'manual'`); the 3xx
|
|
16
|
+
* response is returned as-is.
|
|
17
|
+
*/
|
|
18
|
+
export function createLookupPinnedHttpsFetch(lookup) {
|
|
19
|
+
return async (input, init) => {
|
|
20
|
+
const req = new Request(input, init);
|
|
21
|
+
const url = new URL(req.url);
|
|
22
|
+
if (url.protocol !== 'https:')
|
|
23
|
+
throw new TypeError(`Pinned fetch only supports https: (${url.protocol})`);
|
|
24
|
+
const signal = init?.signal ?? req.signal;
|
|
25
|
+
signal?.throwIfAborted();
|
|
26
|
+
const body = req.body ? Buffer.from(await req.arrayBuffer()) : undefined;
|
|
27
|
+
// The signal may have aborted while the body was buffered.
|
|
28
|
+
signal?.throwIfAborted();
|
|
29
|
+
const headers = {};
|
|
30
|
+
req.headers.forEach((value, key) => {
|
|
31
|
+
headers[key] = value;
|
|
32
|
+
});
|
|
33
|
+
if (body && headers['content-length'] === undefined)
|
|
34
|
+
headers['content-length'] = String(body.length);
|
|
35
|
+
// Response bodies are passed through undecoded, so ask for an unencoded one.
|
|
36
|
+
if (headers['accept-encoding'] === undefined)
|
|
37
|
+
headers['accept-encoding'] = 'identity';
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const client = httpsRequest({
|
|
40
|
+
protocol: 'https:',
|
|
41
|
+
hostname: url.hostname.replace(/^\[(.*)\]$/, '$1'),
|
|
42
|
+
port: url.port || 443,
|
|
43
|
+
path: `${url.pathname}${url.search}`,
|
|
44
|
+
method: req.method,
|
|
45
|
+
headers,
|
|
46
|
+
lookup,
|
|
47
|
+
agent: false,
|
|
48
|
+
}, (res) => {
|
|
49
|
+
// This callback runs outside the executor, so a throw here (e.g.
|
|
50
|
+
// `new Response` refusing a status outside 200-599) would escape as
|
|
51
|
+
// an uncaught exception instead of rejecting the fetch.
|
|
52
|
+
try {
|
|
53
|
+
const responseHeaders = new Headers();
|
|
54
|
+
for (const [key, value] of Object.entries(res.headers)) {
|
|
55
|
+
if (value === undefined)
|
|
56
|
+
continue;
|
|
57
|
+
for (const item of Array.isArray(value) ? value : [value])
|
|
58
|
+
responseHeaders.append(key, item);
|
|
59
|
+
}
|
|
60
|
+
const status = res.statusCode ?? 502;
|
|
61
|
+
if (status < 200 || status > 599)
|
|
62
|
+
throw new TypeError(`Unsupported response status ${status}`);
|
|
63
|
+
const responseBody = NULL_BODY_STATUSES.has(status) || req.method === 'HEAD'
|
|
64
|
+
? null
|
|
65
|
+
: Readable.toWeb(res);
|
|
66
|
+
if (responseBody === null)
|
|
67
|
+
res.resume();
|
|
68
|
+
resolve(new Response(responseBody, { status, statusText: res.statusMessage, headers: responseHeaders }));
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
res.destroy();
|
|
72
|
+
reject(err);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const onAbort = () => client.destroy(signal?.reason instanceof Error ? signal.reason : new Error('The operation was aborted'));
|
|
76
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
77
|
+
client.on('close', () => signal?.removeEventListener('abort', onAbort));
|
|
78
|
+
client.on('error', reject);
|
|
79
|
+
client.end(body);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=pinned-https-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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ACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
/**
|
|
3
|
+
* The raw SQLite connection surface the Node adapter uses for migrations,
|
|
4
|
+
* pragmas, transactions, and shutdown. It is better-sqlite3's `Database`;
|
|
5
|
+
* another driver supplies a facade that implements the subset the engine
|
|
6
|
+
* relies on (`exec`, `prepare`, `pragma`, `transaction`, `inTransaction`,
|
|
7
|
+
* `open`, `close`).
|
|
8
|
+
*/
|
|
9
|
+
export type SqliteConnection = Database.Database;
|
|
10
|
+
/**
|
|
11
|
+
* The seam between the Node adapter and a concrete synchronous SQLite driver.
|
|
12
|
+
*
|
|
13
|
+
* This module is the default (better-sqlite3). The standalone single-file
|
|
14
|
+
* build replaces it at bundle time with a `bun:sqlite` implementation that
|
|
15
|
+
* exports the same `sqliteDriver` binding (see `packages/engine/standalone/`),
|
|
16
|
+
* so every engine code path stays shared.
|
|
17
|
+
*/
|
|
18
|
+
export interface SqliteDriver {
|
|
19
|
+
/** Driver name, for diagnostics. */
|
|
20
|
+
readonly name: string;
|
|
21
|
+
/** Open (creating if absent) a database file, or `':memory:'`. */
|
|
22
|
+
open(path: string): SqliteConnection;
|
|
23
|
+
/** Build the synchronous Drizzle handle over the engine schema for `sqlite`. */
|
|
24
|
+
drizzle(sqlite: SqliteConnection): unknown;
|
|
25
|
+
}
|
|
26
|
+
export declare const sqliteDriver: SqliteDriver;
|
|
27
|
+
//# sourceMappingURL=sqlite-driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-driver.d.ts","sourceRoot":"","sources":["../../../src/adapters/node/sqlite-driver.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAItC;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,QAAQ,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACrC,gFAAgF;IAChF,OAAO,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC;CAC5C;AAED,eAAO,MAAM,YAAY,EAAE,YAI1B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
3
|
+
import * as schema from '../../db/schema.js';
|
|
4
|
+
export const sqliteDriver = {
|
|
5
|
+
name: 'better-sqlite3',
|
|
6
|
+
open: (path) => new Database(path),
|
|
7
|
+
drizzle: (sqlite) => drizzle(sqlite, { schema }),
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=sqlite-driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-driver.js","sourceRoot":"","sources":["../../../src/adapters/node/sqlite-driver.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAC;AA4B7C,MAAM,CAAC,MAAM,YAAY,GAAiB;IACxC,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC;CACjD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssrf-fetch.d.ts","sourceRoot":"","sources":["../../../src/adapters/node/ssrf-fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ssrf-fetch.d.ts","sourceRoot":"","sources":["../../../src/adapters/node/ssrf-fetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,IAAI,WAAW,EAAyC,MAAM,QAAQ,CAAC;AA4C5F,uFAAuF;AACvF,wBAAgB,0BAA0B,CACxC,SAAS,GAAE,OAAO,WAA6B,GAC9C,OAAO,UAAU,CAAC,KAAK,CAmBzB;AAED,eAAO,MAAM,oBAAoB,cAA+B,CAAC;AAejE;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,GAAE,OAAO,UAAU,CAAC,KAA4B,EACzD,UAAU,GAAE,OAAO,UAAU,CAAC,KAAwB,GACrD,OAAO,UAAU,CAAC,KAAK,CAQzB"}
|
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
import { lookup } from 'node:dns';
|
|
2
2
|
import { Agent, fetch as undiciFetch } from 'undici';
|
|
3
3
|
import { isGlobalIpAddress, isSafeExternalUrl } from '../../lib/ssrf.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
4
|
+
import { createLookupPinnedHttpsFetch } from './pinned-https-fetch.js';
|
|
5
|
+
/**
|
|
6
|
+
* The connection's DNS lookup, not a preflight lookup: the transport opens the
|
|
7
|
+
* socket to the exact address classified here while preserving the URL
|
|
8
|
+
* hostname for Host/SNI/TLS verification.
|
|
9
|
+
*/
|
|
10
|
+
const pinnedGlobalLookup = (hostname, options, callback) => {
|
|
11
|
+
lookup(hostname, { all: true, verbatim: true }, (error, addresses) => {
|
|
12
|
+
if (error) {
|
|
13
|
+
callback(error, '', 0);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const unsafe = addresses.find((entry) => !isGlobalIpAddress(entry.address));
|
|
17
|
+
if (unsafe || addresses.length === 0) {
|
|
18
|
+
const rejection = Object.assign(new Error(`Outbound webhook DNS resolved to a non-global address for ${hostname}`), { code: 'ENOTFOUND' });
|
|
19
|
+
callback(rejection, '', 0);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (options.all) {
|
|
23
|
+
callback(null, addresses);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
callback(null, addresses[0].address, addresses[0].family);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const dispatcher = new Agent({ connect: { lookup: pinnedGlobalLookup } });
|
|
31
|
+
/**
|
|
32
|
+
* Under Bun (the standalone binary, or the package run with `bun`), `undici`
|
|
33
|
+
* resolves to Bun's built-in shim, whose `fetch` ignores `dispatcher` — the
|
|
34
|
+
* pinned lookup above would silently stop applying. Bun's `node:https`
|
|
35
|
+
* honours `lookup`, so use it there; Node keeps undici.
|
|
36
|
+
*/
|
|
37
|
+
const pinnedTransport = (typeof process.versions.bun === 'string' ? createLookupPinnedHttpsFetch(pinnedGlobalLookup) : undiciFetch);
|
|
31
38
|
/** HTTPS-only fetch whose connector validates and pins DNS answers at connect time. */
|
|
32
|
-
export function createNodeSafeWebhookFetch(fetchImpl =
|
|
39
|
+
export function createNodeSafeWebhookFetch(fetchImpl = pinnedTransport) {
|
|
33
40
|
return async (input, init) => {
|
|
34
41
|
const rawUrl = typeof input === 'string'
|
|
35
42
|
? input
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssrf-fetch.js","sourceRoot":"","sources":["../../../src/adapters/node/ssrf-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"ssrf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,CAAC,KAA6B;IAClD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ;YACtC,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,KAAK,YAAY,GAAG;gBACpB,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE;gBAClB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC;QAChB,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC5C,QAAiB,EACjB,YAAqC,oBAAoB,EACzD,aAAsC,UAAU,CAAC,KAAK;IAEtD,MAAM,eAAe,GAAG,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAClE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACrB,IAAI,eAAe,IAAI,aAAa,CAAC,KAAK,CAAC,KAAK,eAAe,EAAE,CAAC;YAChE,OAAO,UAAU,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/bin/serve.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { startServer } from '../entrypoints/node.js';
|
|
3
|
+
import { engineVersion } from './version.js';
|
|
3
4
|
const HELP = `relaycast-engine — run a self-hosted Relaycast server (Node + SQLite)
|
|
4
5
|
|
|
5
6
|
Usage:
|
|
@@ -10,6 +11,7 @@ Options:
|
|
|
10
11
|
--port <n> HTTP port (default: $PORT or 8787)
|
|
11
12
|
--base-url <url> Public origin for signed file URLs (default: http://localhost:<port>)
|
|
12
13
|
--env <name> Environment label (default: production)
|
|
14
|
+
-v, --version Print the engine version
|
|
13
15
|
-h, --help Show this help
|
|
14
16
|
|
|
15
17
|
After start, create a workspace:
|
|
@@ -22,11 +24,14 @@ function parseArgs(argv, env) {
|
|
|
22
24
|
baseUrl: undefined,
|
|
23
25
|
environment: env.RELAYCAST_ENV ?? 'production',
|
|
24
26
|
help: false,
|
|
27
|
+
version: false,
|
|
25
28
|
};
|
|
26
29
|
for (let i = 0; i < argv.length; i++) {
|
|
27
30
|
const arg = argv[i];
|
|
28
31
|
if (arg === '--help' || arg === '-h')
|
|
29
32
|
out.help = true;
|
|
33
|
+
else if (arg === '--version' || arg === '-v')
|
|
34
|
+
out.version = true;
|
|
30
35
|
else if (arg === '--db')
|
|
31
36
|
out.db = argv[++i] ?? out.db;
|
|
32
37
|
else if (arg === '--port')
|
|
@@ -44,6 +49,10 @@ async function main() {
|
|
|
44
49
|
process.stdout.write(HELP);
|
|
45
50
|
return;
|
|
46
51
|
}
|
|
52
|
+
if (opts.version) {
|
|
53
|
+
process.stdout.write(`${engineVersion()}\n`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
47
56
|
if (!Number.isFinite(opts.port) || opts.port <= 0) {
|
|
48
57
|
process.stderr.write('Invalid --port\n');
|
|
49
58
|
process.exitCode = 1;
|
package/dist/bin/serve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/bin/serve.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/bin/serve.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;CAeZ,CAAC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AAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxD;QACD,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtC,CAAC,CAAC;IAEH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,OAAO,SAAS,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACvF,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,sCAAsC,OAAO,8EAA8E,CAC5H,CAAC;IAEF,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,GAAG,EAAE;YACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;YAC3C,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACjC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qCAAqC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine package version, read from `package.json` next to the build.
|
|
3
|
+
*
|
|
4
|
+
* The standalone single-file build replaces this module at bundle time with one
|
|
5
|
+
* that inlines the version, since the binary carries no `package.json`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function engineVersion(): string;
|
|
8
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/bin/version.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAKtC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* The engine package version, read from `package.json` next to the build.
|
|
4
|
+
*
|
|
5
|
+
* The standalone single-file build replaces this module at bundle time with one
|
|
6
|
+
* that inlines the version, since the binary carries no `package.json`.
|
|
7
|
+
*/
|
|
8
|
+
export function engineVersion() {
|
|
9
|
+
const pkg = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
|
|
10
|
+
return pkg.version;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/bin/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAE1F,CAAC;IACF,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- `GET /v1/deliveries?status=<status>` (`listDeliveries` with an explicit
|
|
2
|
+
-- status) filters one agent's rows by status and orders them by
|
|
3
|
+
-- (created_at, id). The only index that serves that ORDER BY is
|
|
4
|
+
-- idx_deliveries_status (workspace_id, status, created_at), which is not
|
|
5
|
+
-- agent-scoped: the query walks every row with that status in the whole
|
|
6
|
+
-- workspace, discarding other agents' rows, then sorts the id tie-break in a
|
|
7
|
+
-- temp b-tree. On the hosted gateway ~4M of ~6.5M delivery rows are
|
|
8
|
+
-- `dead_lettered`, so one agent's `?status=dead_lettered` read could scan
|
|
9
|
+
-- millions of rows on the shared D1 before its LIMIT applied.
|
|
10
|
+
--
|
|
11
|
+
-- This index makes that read an agent-scoped seek that is already in the
|
|
12
|
+
-- requested order, so it stops at the LIMIT. The existing
|
|
13
|
+
-- idx_deliveries_agent_status_seq orders by `seq`, which is not the API's
|
|
14
|
+
-- order for historical rows (0029 renumbered active rows above settled ones).
|
|
15
|
+
-- No data changes. Building it is one pass over `deliveries`.
|
|
16
|
+
CREATE INDEX IF NOT EXISTS idx_deliveries_agent_status_created
|
|
17
|
+
ON deliveries(workspace_id, agent_id, status, created_at, id);
|