@shipfox/api-logs 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +179 -0
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/dist/api/object-storage.d.ts +69 -0
- package/dist/api/object-storage.d.ts.map +1 -0
- package/dist/api/object-storage.js +199 -0
- package/dist/api/object-storage.js.map +1 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +108 -0
- package/dist/config.js.map +1 -0
- package/dist/core/append-logs.d.ts +28 -0
- package/dist/core/append-logs.d.ts.map +1 -0
- package/dist/core/append-logs.js +318 -0
- package/dist/core/append-logs.js.map +1 -0
- package/dist/core/budget.d.ts +12 -0
- package/dist/core/budget.d.ts.map +1 -0
- package/dist/core/budget.js +9 -0
- package/dist/core/budget.js.map +1 -0
- package/dist/core/close-stream.d.ts +27 -0
- package/dist/core/close-stream.d.ts.map +1 -0
- package/dist/core/close-stream.js +59 -0
- package/dist/core/close-stream.js.map +1 -0
- package/dist/core/compaction.d.ts +28 -0
- package/dist/core/compaction.d.ts.map +1 -0
- package/dist/core/compaction.js +49 -0
- package/dist/core/compaction.js.map +1 -0
- package/dist/core/entities/attempt-stream.d.ts +37 -0
- package/dist/core/entities/attempt-stream.d.ts.map +1 -0
- package/dist/core/entities/attempt-stream.js +15 -0
- package/dist/core/entities/attempt-stream.js.map +1 -0
- package/dist/core/entities/job-accounting.d.ts +12 -0
- package/dist/core/entities/job-accounting.d.ts.map +1 -0
- package/dist/core/entities/job-accounting.js +6 -0
- package/dist/core/entities/job-accounting.js.map +1 -0
- package/dist/core/entities/log-object.d.ts +13 -0
- package/dist/core/entities/log-object.d.ts.map +1 -0
- package/dist/core/entities/log-object.js +9 -0
- package/dist/core/entities/log-object.js.map +1 -0
- package/dist/core/errors.d.ts +26 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +31 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/finalize-attempt-stream.d.ts +22 -0
- package/dist/core/finalize-attempt-stream.d.ts.map +1 -0
- package/dist/core/finalize-attempt-stream.js +48 -0
- package/dist/core/finalize-attempt-stream.js.map +1 -0
- package/dist/core/read-logs.d.ts +33 -0
- package/dist/core/read-logs.d.ts.map +1 -0
- package/dist/core/read-logs.js +49 -0
- package/dist/core/read-logs.js.map +1 -0
- package/dist/core/reap-stale-open-streams.d.ts +27 -0
- package/dist/core/reap-stale-open-streams.d.ts.map +1 -0
- package/dist/core/reap-stale-open-streams.js +50 -0
- package/dist/core/reap-stale-open-streams.js.map +1 -0
- package/dist/core/retention.d.ts +32 -0
- package/dist/core/retention.d.ts.map +1 -0
- package/dist/core/retention.js +148 -0
- package/dist/core/retention.js.map +1 -0
- package/dist/core/session/claude/rows.d.ts +6 -0
- package/dist/core/session/claude/rows.d.ts.map +1 -0
- package/dist/core/session/claude/rows.js +145 -0
- package/dist/core/session/claude/rows.js.map +1 -0
- package/dist/core/session/claude-parser.d.ts +4 -0
- package/dist/core/session/claude-parser.d.ts.map +1 -0
- package/dist/core/session/claude-parser.js +42 -0
- package/dist/core/session/claude-parser.js.map +1 -0
- package/dist/core/session/entry-schema.d.ts +51 -0
- package/dist/core/session/entry-schema.d.ts.map +1 -0
- package/dist/core/session/entry-schema.js +61 -0
- package/dist/core/session/entry-schema.js.map +1 -0
- package/dist/core/session/object.d.ts +12 -0
- package/dist/core/session/object.d.ts.map +1 -0
- package/dist/core/session/object.js +50 -0
- package/dist/core/session/object.js.map +1 -0
- package/dist/core/session/parse-session.d.ts +5 -0
- package/dist/core/session/parse-session.d.ts.map +1 -0
- package/dist/core/session/parse-session.js +18 -0
- package/dist/core/session/parse-session.js.map +1 -0
- package/dist/core/session/pi/message-rows.d.ts +4 -0
- package/dist/core/session/pi/message-rows.d.ts.map +1 -0
- package/dist/core/session/pi/message-rows.js +113 -0
- package/dist/core/session/pi/message-rows.js.map +1 -0
- package/dist/core/session/pi/metadata.d.ts +18 -0
- package/dist/core/session/pi/metadata.d.ts.map +1 -0
- package/dist/core/session/pi/metadata.js +120 -0
- package/dist/core/session/pi/metadata.js.map +1 -0
- package/dist/core/session/pi/text.d.ts +12 -0
- package/dist/core/session/pi/text.d.ts.map +1 -0
- package/dist/core/session/pi/text.js +59 -0
- package/dist/core/session/pi/text.js.map +1 -0
- package/dist/core/session/pi-parser.d.ts +5 -0
- package/dist/core/session/pi-parser.d.ts.map +1 -0
- package/dist/core/session/pi-parser.js +73 -0
- package/dist/core/session/pi-parser.js.map +1 -0
- package/dist/core/session/rows.d.ts +7 -0
- package/dist/core/session/rows.d.ts.map +1 -0
- package/dist/core/session/rows.js +39 -0
- package/dist/core/session/rows.js.map +1 -0
- package/dist/core/session/session-record.d.ts +5 -0
- package/dist/core/session/session-record.d.ts.map +1 -0
- package/dist/core/session/session-record.js +3 -0
- package/dist/core/session/session-record.js.map +1 -0
- package/dist/db/accounting.d.ts +33 -0
- package/dist/db/accounting.d.ts.map +1 -0
- package/dist/db/accounting.js +52 -0
- package/dist/db/accounting.js.map +1 -0
- package/dist/db/chunks.d.ts +62 -0
- package/dist/db/chunks.d.ts.map +1 -0
- package/dist/db/chunks.js +88 -0
- package/dist/db/chunks.js.map +1 -0
- package/dist/db/db.d.ts +752 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +24 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +5 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema/attempt-streams.d.ts +304 -0
- package/dist/db/schema/attempt-streams.d.ts.map +1 -0
- package/dist/db/schema/attempt-streams.js +100 -0
- package/dist/db/schema/attempt-streams.js.map +1 -0
- package/dist/db/schema/chunks.d.ts +166 -0
- package/dist/db/schema/chunks.d.ts.map +1 -0
- package/dist/db/schema/chunks.js +47 -0
- package/dist/db/schema/chunks.js.map +1 -0
- package/dist/db/schema/common.d.ts +29 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +11 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/job-accounting.d.ts +143 -0
- package/dist/db/schema/job-accounting.d.ts.map +1 -0
- package/dist/db/schema/job-accounting.js +43 -0
- package/dist/db/schema/job-accounting.js.map +1 -0
- package/dist/db/schema/outbox.d.ts +195 -0
- package/dist/db/schema/outbox.d.ts.map +1 -0
- package/dist/db/schema/outbox.js +5 -0
- package/dist/db/schema/outbox.js.map +1 -0
- package/dist/db/streams.d.ts +141 -0
- package/dist/db/streams.d.ts.map +1 -0
- package/dist/db/streams.js +197 -0
- package/dist/db/streams.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +3 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +14 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +16 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/metrics/service.d.ts +2 -0
- package/dist/metrics/service.d.ts.map +1 -0
- package/dist/metrics/service.js +20 -0
- package/dist/metrics/service.js.map +1 -0
- package/dist/presentation/dto/read-logs.d.ts +4 -0
- package/dist/presentation/dto/read-logs.d.ts.map +1 -0
- package/dist/presentation/dto/read-logs.js +22 -0
- package/dist/presentation/dto/read-logs.js.map +1 -0
- package/dist/presentation/routes/append-logs.d.ts +2 -0
- package/dist/presentation/routes/append-logs.d.ts.map +1 -0
- package/dist/presentation/routes/append-logs.js +71 -0
- package/dist/presentation/routes/append-logs.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +3 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +32 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/read-logs.d.ts +2 -0
- package/dist/presentation/routes/read-logs.d.ts.map +1 -0
- package/dist/presentation/routes/read-logs.js +41 -0
- package/dist/presentation/routes/read-logs.js.map +1 -0
- package/dist/presentation/subscribers/on-job-terminated.d.ts +8 -0
- package/dist/presentation/subscribers/on-job-terminated.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-job-terminated.js +32 -0
- package/dist/presentation/subscribers/on-job-terminated.js.map +1 -0
- package/dist/presentation/subscribers/on-log-stream-closed.d.ts +9 -0
- package/dist/presentation/subscribers/on-log-stream-closed.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-log-stream-closed.js +31 -0
- package/dist/presentation/subscribers/on-log-stream-closed.js.map +1 -0
- package/dist/presentation/subscribers/on-step-attempt-terminated.d.ts +3 -0
- package/dist/presentation/subscribers/on-step-attempt-terminated.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-step-attempt-terminated.js +14 -0
- package/dist/presentation/subscribers/on-step-attempt-terminated.js.map +1 -0
- package/dist/temporal/activities/close-abandoned-streams.d.ts +12 -0
- package/dist/temporal/activities/close-abandoned-streams.d.ts.map +1 -0
- package/dist/temporal/activities/close-abandoned-streams.js +33 -0
- package/dist/temporal/activities/close-abandoned-streams.js.map +1 -0
- package/dist/temporal/activities/compact-stream.d.ts +33 -0
- package/dist/temporal/activities/compact-stream.d.ts.map +1 -0
- package/dist/temporal/activities/compact-stream.js +95 -0
- package/dist/temporal/activities/compact-stream.js.map +1 -0
- package/dist/temporal/activities/compaction-reconcile.d.ts +16 -0
- package/dist/temporal/activities/compaction-reconcile.d.ts.map +1 -0
- package/dist/temporal/activities/compaction-reconcile.js +52 -0
- package/dist/temporal/activities/compaction-reconcile.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +14 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +16 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/reap-stale-open-streams.d.ts +4 -0
- package/dist/temporal/activities/reap-stale-open-streams.d.ts.map +1 -0
- package/dist/temporal/activities/reap-stale-open-streams.js +11 -0
- package/dist/temporal/activities/reap-stale-open-streams.js.map +1 -0
- package/dist/temporal/activities/retention-sweep.d.ts +7 -0
- package/dist/temporal/activities/retention-sweep.d.ts.map +1 -0
- package/dist/temporal/activities/retention-sweep.js +19 -0
- package/dist/temporal/activities/retention-sweep.js.map +1 -0
- package/dist/temporal/constants.d.ts +7 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +13 -0
- package/dist/temporal/constants.js.map +1 -0
- package/dist/temporal/workflows/close-abandoned-streams.d.ts +11 -0
- package/dist/temporal/workflows/close-abandoned-streams.d.ts.map +1 -0
- package/dist/temporal/workflows/close-abandoned-streams.js +22 -0
- package/dist/temporal/workflows/close-abandoned-streams.js.map +1 -0
- package/dist/temporal/workflows/compact-stream.d.ts +6 -0
- package/dist/temporal/workflows/compact-stream.d.ts.map +1 -0
- package/dist/temporal/workflows/compact-stream.js +25 -0
- package/dist/temporal/workflows/compact-stream.js.map +1 -0
- package/dist/temporal/workflows/compaction-reconcile-cron.d.ts +3 -0
- package/dist/temporal/workflows/compaction-reconcile-cron.d.ts.map +1 -0
- package/dist/temporal/workflows/compaction-reconcile-cron.js +15 -0
- package/dist/temporal/workflows/compaction-reconcile-cron.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +6 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +7 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/temporal/workflows/reap-stale-open-streams-cron.d.ts +2 -0
- package/dist/temporal/workflows/reap-stale-open-streams-cron.d.ts.map +1 -0
- package/dist/temporal/workflows/reap-stale-open-streams-cron.js +15 -0
- package/dist/temporal/workflows/reap-stale-open-streams-cron.js.map +1 -0
- package/dist/temporal/workflows/retention-sweep-cron.d.ts +2 -0
- package/dist/temporal/workflows/retention-sweep-cron.d.ts.map +1 -0
- package/dist/temporal/workflows/retention-sweep-cron.js +23 -0
- package/dist/temporal/workflows/retention-sweep-cron.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +65 -0
- package/drizzle/meta/0000_snapshot.json +529 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +84 -0
- package/src/api/object-storage-credentials.test.ts +70 -0
- package/src/api/object-storage.test.ts +64 -0
- package/src/api/object-storage.ts +226 -0
- package/src/config.test.ts +118 -0
- package/src/config.ts +130 -0
- package/src/core/append-logs.test.ts +563 -0
- package/src/core/append-logs.ts +384 -0
- package/src/core/budget.test.ts +30 -0
- package/src/core/budget.ts +19 -0
- package/src/core/close-stream.ts +72 -0
- package/src/core/compaction.ts +68 -0
- package/src/core/entities/attempt-stream.ts +38 -0
- package/src/core/entities/job-accounting.ts +11 -0
- package/src/core/entities/log-object.test.ts +25 -0
- package/src/core/entities/log-object.ts +18 -0
- package/src/core/errors.ts +37 -0
- package/src/core/finalize-attempt-stream.test.ts +90 -0
- package/src/core/finalize-attempt-stream.ts +59 -0
- package/src/core/read-logs.ts +77 -0
- package/src/core/reap-stale-open-streams.test.ts +137 -0
- package/src/core/reap-stale-open-streams.ts +60 -0
- package/src/core/retention.test.ts +388 -0
- package/src/core/retention.ts +184 -0
- package/src/core/session/claude/rows.ts +223 -0
- package/src/core/session/claude-parser.test.ts +199 -0
- package/src/core/session/claude-parser.ts +38 -0
- package/src/core/session/entry-schema.ts +82 -0
- package/src/core/session/object.ts +57 -0
- package/src/core/session/parse-session.ts +23 -0
- package/src/core/session/pi/message-rows.ts +211 -0
- package/src/core/session/pi/metadata.ts +148 -0
- package/src/core/session/pi/text.ts +83 -0
- package/src/core/session/pi-parser.test.ts +451 -0
- package/src/core/session/pi-parser.ts +107 -0
- package/src/core/session/rows.ts +38 -0
- package/src/core/session/session-record.ts +4 -0
- package/src/db/accounting.ts +81 -0
- package/src/db/chunks.ts +143 -0
- package/src/db/db.ts +22 -0
- package/src/db/index.ts +4 -0
- package/src/db/schema/attempt-streams.ts +106 -0
- package/src/db/schema/chunks.ts +43 -0
- package/src/db/schema/common.ts +12 -0
- package/src/db/schema/job-accounting.ts +38 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/streams.test.ts +47 -0
- package/src/db/streams.ts +368 -0
- package/src/index.ts +77 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/instance.ts +33 -0
- package/src/metrics/service.ts +23 -0
- package/src/presentation/dto/read-logs.ts +24 -0
- package/src/presentation/routes/append-logs.test.ts +279 -0
- package/src/presentation/routes/append-logs.ts +66 -0
- package/src/presentation/routes/index.ts +27 -0
- package/src/presentation/routes/read-logs.test.ts +504 -0
- package/src/presentation/routes/read-logs.ts +38 -0
- package/src/presentation/subscribers/on-job-terminated.test.ts +64 -0
- package/src/presentation/subscribers/on-job-terminated.ts +26 -0
- package/src/presentation/subscribers/on-log-stream-closed.test.ts +63 -0
- package/src/presentation/subscribers/on-log-stream-closed.ts +26 -0
- package/src/presentation/subscribers/on-step-attempt-terminated.ts +16 -0
- package/src/temporal/activities/close-abandoned-streams.test.ts +84 -0
- package/src/temporal/activities/close-abandoned-streams.ts +30 -0
- package/src/temporal/activities/compact-stream.test.ts +221 -0
- package/src/temporal/activities/compact-stream.ts +123 -0
- package/src/temporal/activities/compaction-reconcile.test.ts +143 -0
- package/src/temporal/activities/compaction-reconcile.ts +48 -0
- package/src/temporal/activities/index.ts +15 -0
- package/src/temporal/activities/reap-stale-open-streams.test.ts +48 -0
- package/src/temporal/activities/reap-stale-open-streams.ts +14 -0
- package/src/temporal/activities/retention-sweep.test.ts +38 -0
- package/src/temporal/activities/retention-sweep.ts +23 -0
- package/src/temporal/constants.ts +14 -0
- package/src/temporal/workflows/close-abandoned-streams.ts +25 -0
- package/src/temporal/workflows/compact-stream.ts +26 -0
- package/src/temporal/workflows/compaction-reconcile-cron.ts +14 -0
- package/src/temporal/workflows/index.ts +5 -0
- package/src/temporal/workflows/reap-stale-open-streams-cron.ts +13 -0
- package/src/temporal/workflows/retention-sweep-cron.ts +23 -0
- package/test/env.ts +37 -0
- package/test/factories/job-accounting.ts +38 -0
- package/test/fixtures/closed-stream.ts +53 -0
- package/test/fixtures/lease-token.ts +42 -0
- package/test/fixtures/ndjson.ts +34 -0
- package/test/globalSetup.ts +44 -0
- package/test/index.ts +9 -0
- package/test/queries.ts +54 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAOnE,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAyD,CAAC;AAE7E,MAAM,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAIhF,wBAAgB,EAAE,aAGjB;AAED,wBAAgB,OAAO,IAAI,IAAI,CAE9B"}
|
package/dist/db/db.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { drizzle } from '@shipfox/node-drizzle';
|
|
2
|
+
import { pgClient } from '@shipfox/node-postgres';
|
|
3
|
+
import { attemptStreams } from './schema/attempt-streams.js';
|
|
4
|
+
import { logChunks } from './schema/chunks.js';
|
|
5
|
+
import { jobAccounting } from './schema/job-accounting.js';
|
|
6
|
+
import { logsOutbox } from './schema/outbox.js';
|
|
7
|
+
export const schema = {
|
|
8
|
+
jobAccounting,
|
|
9
|
+
attemptStreams,
|
|
10
|
+
logChunks,
|
|
11
|
+
logsOutbox
|
|
12
|
+
};
|
|
13
|
+
let _db;
|
|
14
|
+
export function db() {
|
|
15
|
+
if (!_db) _db = drizzle(pgClient(), {
|
|
16
|
+
schema
|
|
17
|
+
});
|
|
18
|
+
return _db;
|
|
19
|
+
}
|
|
20
|
+
export function closeDb() {
|
|
21
|
+
_db = undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/db.ts"],"sourcesContent":["import {drizzle, type NodePgDatabase} from '@shipfox/node-drizzle';\nimport {pgClient} from '@shipfox/node-postgres';\nimport {attemptStreams} from './schema/attempt-streams.js';\nimport {logChunks} from './schema/chunks.js';\nimport {jobAccounting} from './schema/job-accounting.js';\nimport {logsOutbox} from './schema/outbox.js';\n\nexport const schema = {jobAccounting, attemptStreams, logChunks, logsOutbox};\n\nexport type Database = NodePgDatabase<typeof schema>;\nexport type Transaction = Parameters<Parameters<Database['transaction']>[0]>[0];\n\nlet _db: Database | undefined;\n\nexport function db() {\n if (!_db) _db = drizzle(pgClient(), {schema});\n return _db;\n}\n\nexport function closeDb(): void {\n _db = undefined;\n}\n"],"names":["drizzle","pgClient","attemptStreams","logChunks","jobAccounting","logsOutbox","schema","_db","db","closeDb","undefined"],"mappings":"AAAA,SAAQA,OAAO,QAA4B,wBAAwB;AACnE,SAAQC,QAAQ,QAAO,yBAAyB;AAChD,SAAQC,cAAc,QAAO,8BAA8B;AAC3D,SAAQC,SAAS,QAAO,qBAAqB;AAC7C,SAAQC,aAAa,QAAO,6BAA6B;AACzD,SAAQC,UAAU,QAAO,qBAAqB;AAE9C,OAAO,MAAMC,SAAS;IAACF;IAAeF;IAAgBC;IAAWE;AAAU,EAAE;AAK7E,IAAIE;AAEJ,OAAO,SAASC;IACd,IAAI,CAACD,KAAKA,MAAMP,QAAQC,YAAY;QAACK;IAAM;IAC3C,OAAOC;AACT;AAEA,OAAO,SAASE;IACdF,MAAMG;AACR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,QAAoE,CAAC"}
|
package/dist/db/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/index.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path';\nimport {fileURLToPath} from 'node:url';\n\nexport const migrationsPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../drizzle');\n"],"names":["dirname","resolve","fileURLToPath","migrationsPath","url"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAY;AAC3C,SAAQC,aAAa,QAAO,WAAW;AAEvC,OAAO,MAAMC,iBAAiBF,QAAQD,QAAQE,cAAc,YAAYE,GAAG,IAAI,iBAAiB"}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import type { AttemptStream } from '#core/entities/attempt-stream.js';
|
|
2
|
+
/**
|
|
3
|
+
* One stream per (job, step, attempt). Identity is scoped by `job_id` (from the
|
|
4
|
+
* lease), so a lease can only ever reach its own job's streams — cross-job log
|
|
5
|
+
* injection is structurally impossible. `workspace_id`, `project_id`, and `workflow_run_attempt_id`
|
|
6
|
+
* are stamped from the lease at create time; they are functionally determined by
|
|
7
|
+
* `job_id` via workflows FKs, so they are denormalized here for self-contained
|
|
8
|
+
* authorization (per-project read filtering, audit) without joining back to
|
|
9
|
+
* workflows. `committed_length` is the offset-CAS axis (raw NDJSON spool bytes the
|
|
10
|
+
* server has durably accepted from the runner).
|
|
11
|
+
*
|
|
12
|
+
* `truncated` is an out-of-band terminal flag set when the timeout sweep
|
|
13
|
+
* force-closes a stream the runner never ended; the `AttemptStream` entity is the
|
|
14
|
+
* canonical reference for what it means.
|
|
15
|
+
*
|
|
16
|
+
* Per-row `committed_length` and `declared_total_bytes` are bounded by the
|
|
17
|
+
* per-job budget, so `mode: 'number'` is safe on the hot path. Any cross-row
|
|
18
|
+
* aggregate (workspace or system-wide totals) MUST read as bigint at the
|
|
19
|
+
* query site — the global sum is unbounded and would silently lose precision
|
|
20
|
+
* past 2^53 as a JS number.
|
|
21
|
+
*/
|
|
22
|
+
export declare const attemptStreams: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
23
|
+
name: "attempt_streams";
|
|
24
|
+
schema: undefined;
|
|
25
|
+
columns: {
|
|
26
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
27
|
+
name: "id";
|
|
28
|
+
tableName: "attempt_streams";
|
|
29
|
+
dataType: "string";
|
|
30
|
+
columnType: "PgUUID";
|
|
31
|
+
data: string;
|
|
32
|
+
driverParam: string;
|
|
33
|
+
notNull: true;
|
|
34
|
+
hasDefault: true;
|
|
35
|
+
isPrimaryKey: true;
|
|
36
|
+
isAutoincrement: false;
|
|
37
|
+
hasRuntimeDefault: false;
|
|
38
|
+
enumValues: undefined;
|
|
39
|
+
baseColumn: never;
|
|
40
|
+
identity: undefined;
|
|
41
|
+
generated: undefined;
|
|
42
|
+
}, {}, {}>;
|
|
43
|
+
jobId: import("drizzle-orm/pg-core").PgColumn<{
|
|
44
|
+
name: "job_id";
|
|
45
|
+
tableName: "attempt_streams";
|
|
46
|
+
dataType: "string";
|
|
47
|
+
columnType: "PgUUID";
|
|
48
|
+
data: string;
|
|
49
|
+
driverParam: string;
|
|
50
|
+
notNull: true;
|
|
51
|
+
hasDefault: false;
|
|
52
|
+
isPrimaryKey: false;
|
|
53
|
+
isAutoincrement: false;
|
|
54
|
+
hasRuntimeDefault: false;
|
|
55
|
+
enumValues: undefined;
|
|
56
|
+
baseColumn: never;
|
|
57
|
+
identity: undefined;
|
|
58
|
+
generated: undefined;
|
|
59
|
+
}, {}, {}>;
|
|
60
|
+
stepId: import("drizzle-orm/pg-core").PgColumn<{
|
|
61
|
+
name: "step_id";
|
|
62
|
+
tableName: "attempt_streams";
|
|
63
|
+
dataType: "string";
|
|
64
|
+
columnType: "PgUUID";
|
|
65
|
+
data: string;
|
|
66
|
+
driverParam: string;
|
|
67
|
+
notNull: true;
|
|
68
|
+
hasDefault: false;
|
|
69
|
+
isPrimaryKey: false;
|
|
70
|
+
isAutoincrement: false;
|
|
71
|
+
hasRuntimeDefault: false;
|
|
72
|
+
enumValues: undefined;
|
|
73
|
+
baseColumn: never;
|
|
74
|
+
identity: undefined;
|
|
75
|
+
generated: undefined;
|
|
76
|
+
}, {}, {}>;
|
|
77
|
+
attempt: import("drizzle-orm/pg-core").PgColumn<{
|
|
78
|
+
name: "attempt";
|
|
79
|
+
tableName: "attempt_streams";
|
|
80
|
+
dataType: "number";
|
|
81
|
+
columnType: "PgInteger";
|
|
82
|
+
data: number;
|
|
83
|
+
driverParam: string | number;
|
|
84
|
+
notNull: true;
|
|
85
|
+
hasDefault: false;
|
|
86
|
+
isPrimaryKey: false;
|
|
87
|
+
isAutoincrement: false;
|
|
88
|
+
hasRuntimeDefault: false;
|
|
89
|
+
enumValues: undefined;
|
|
90
|
+
baseColumn: never;
|
|
91
|
+
identity: undefined;
|
|
92
|
+
generated: undefined;
|
|
93
|
+
}, {}, {}>;
|
|
94
|
+
workspaceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
95
|
+
name: "workspace_id";
|
|
96
|
+
tableName: "attempt_streams";
|
|
97
|
+
dataType: "string";
|
|
98
|
+
columnType: "PgUUID";
|
|
99
|
+
data: string;
|
|
100
|
+
driverParam: string;
|
|
101
|
+
notNull: true;
|
|
102
|
+
hasDefault: false;
|
|
103
|
+
isPrimaryKey: false;
|
|
104
|
+
isAutoincrement: false;
|
|
105
|
+
hasRuntimeDefault: false;
|
|
106
|
+
enumValues: undefined;
|
|
107
|
+
baseColumn: never;
|
|
108
|
+
identity: undefined;
|
|
109
|
+
generated: undefined;
|
|
110
|
+
}, {}, {}>;
|
|
111
|
+
projectId: import("drizzle-orm/pg-core").PgColumn<{
|
|
112
|
+
name: "project_id";
|
|
113
|
+
tableName: "attempt_streams";
|
|
114
|
+
dataType: "string";
|
|
115
|
+
columnType: "PgUUID";
|
|
116
|
+
data: string;
|
|
117
|
+
driverParam: string;
|
|
118
|
+
notNull: true;
|
|
119
|
+
hasDefault: false;
|
|
120
|
+
isPrimaryKey: false;
|
|
121
|
+
isAutoincrement: false;
|
|
122
|
+
hasRuntimeDefault: false;
|
|
123
|
+
enumValues: undefined;
|
|
124
|
+
baseColumn: never;
|
|
125
|
+
identity: undefined;
|
|
126
|
+
generated: undefined;
|
|
127
|
+
}, {}, {}>;
|
|
128
|
+
workflowRunAttemptId: import("drizzle-orm/pg-core").PgColumn<{
|
|
129
|
+
name: "workflow_run_attempt_id";
|
|
130
|
+
tableName: "attempt_streams";
|
|
131
|
+
dataType: "string";
|
|
132
|
+
columnType: "PgUUID";
|
|
133
|
+
data: string;
|
|
134
|
+
driverParam: string;
|
|
135
|
+
notNull: true;
|
|
136
|
+
hasDefault: false;
|
|
137
|
+
isPrimaryKey: false;
|
|
138
|
+
isAutoincrement: false;
|
|
139
|
+
hasRuntimeDefault: false;
|
|
140
|
+
enumValues: undefined;
|
|
141
|
+
baseColumn: never;
|
|
142
|
+
identity: undefined;
|
|
143
|
+
generated: undefined;
|
|
144
|
+
}, {}, {}>;
|
|
145
|
+
committedLength: import("drizzle-orm/pg-core").PgColumn<{
|
|
146
|
+
name: "committed_length";
|
|
147
|
+
tableName: "attempt_streams";
|
|
148
|
+
dataType: "number";
|
|
149
|
+
columnType: "PgBigInt53";
|
|
150
|
+
data: number;
|
|
151
|
+
driverParam: string | number;
|
|
152
|
+
notNull: true;
|
|
153
|
+
hasDefault: true;
|
|
154
|
+
isPrimaryKey: false;
|
|
155
|
+
isAutoincrement: false;
|
|
156
|
+
hasRuntimeDefault: false;
|
|
157
|
+
enumValues: undefined;
|
|
158
|
+
baseColumn: never;
|
|
159
|
+
identity: undefined;
|
|
160
|
+
generated: undefined;
|
|
161
|
+
}, {}, {}>;
|
|
162
|
+
state: import("drizzle-orm/pg-core").PgColumn<{
|
|
163
|
+
name: "state";
|
|
164
|
+
tableName: "attempt_streams";
|
|
165
|
+
dataType: "string";
|
|
166
|
+
columnType: "PgText";
|
|
167
|
+
data: "open" | "closed";
|
|
168
|
+
driverParam: string;
|
|
169
|
+
notNull: true;
|
|
170
|
+
hasDefault: true;
|
|
171
|
+
isPrimaryKey: false;
|
|
172
|
+
isAutoincrement: false;
|
|
173
|
+
hasRuntimeDefault: false;
|
|
174
|
+
enumValues: ["open", "closed"];
|
|
175
|
+
baseColumn: never;
|
|
176
|
+
identity: undefined;
|
|
177
|
+
generated: undefined;
|
|
178
|
+
}, {}, {}>;
|
|
179
|
+
closeReason: import("drizzle-orm/pg-core").PgColumn<{
|
|
180
|
+
name: "close_reason";
|
|
181
|
+
tableName: "attempt_streams";
|
|
182
|
+
dataType: "string";
|
|
183
|
+
columnType: "PgText";
|
|
184
|
+
data: "declared" | "timeout";
|
|
185
|
+
driverParam: string;
|
|
186
|
+
notNull: false;
|
|
187
|
+
hasDefault: false;
|
|
188
|
+
isPrimaryKey: false;
|
|
189
|
+
isAutoincrement: false;
|
|
190
|
+
hasRuntimeDefault: false;
|
|
191
|
+
enumValues: ["declared", "timeout"];
|
|
192
|
+
baseColumn: never;
|
|
193
|
+
identity: undefined;
|
|
194
|
+
generated: undefined;
|
|
195
|
+
}, {}, {}>;
|
|
196
|
+
declaredTotalBytes: import("drizzle-orm/pg-core").PgColumn<{
|
|
197
|
+
name: "declared_total_bytes";
|
|
198
|
+
tableName: "attempt_streams";
|
|
199
|
+
dataType: "number";
|
|
200
|
+
columnType: "PgBigInt53";
|
|
201
|
+
data: number;
|
|
202
|
+
driverParam: string | number;
|
|
203
|
+
notNull: false;
|
|
204
|
+
hasDefault: false;
|
|
205
|
+
isPrimaryKey: false;
|
|
206
|
+
isAutoincrement: false;
|
|
207
|
+
hasRuntimeDefault: false;
|
|
208
|
+
enumValues: undefined;
|
|
209
|
+
baseColumn: never;
|
|
210
|
+
identity: undefined;
|
|
211
|
+
generated: undefined;
|
|
212
|
+
}, {}, {}>;
|
|
213
|
+
truncated: import("drizzle-orm/pg-core").PgColumn<{
|
|
214
|
+
name: "truncated";
|
|
215
|
+
tableName: "attempt_streams";
|
|
216
|
+
dataType: "boolean";
|
|
217
|
+
columnType: "PgBoolean";
|
|
218
|
+
data: boolean;
|
|
219
|
+
driverParam: boolean;
|
|
220
|
+
notNull: true;
|
|
221
|
+
hasDefault: true;
|
|
222
|
+
isPrimaryKey: false;
|
|
223
|
+
isAutoincrement: false;
|
|
224
|
+
hasRuntimeDefault: false;
|
|
225
|
+
enumValues: undefined;
|
|
226
|
+
baseColumn: never;
|
|
227
|
+
identity: undefined;
|
|
228
|
+
generated: undefined;
|
|
229
|
+
}, {}, {}>;
|
|
230
|
+
objectKey: import("drizzle-orm/pg-core").PgColumn<{
|
|
231
|
+
name: "object_key";
|
|
232
|
+
tableName: "attempt_streams";
|
|
233
|
+
dataType: "string";
|
|
234
|
+
columnType: "PgText";
|
|
235
|
+
data: string;
|
|
236
|
+
driverParam: string;
|
|
237
|
+
notNull: false;
|
|
238
|
+
hasDefault: false;
|
|
239
|
+
isPrimaryKey: false;
|
|
240
|
+
isAutoincrement: false;
|
|
241
|
+
hasRuntimeDefault: false;
|
|
242
|
+
enumValues: [string, ...string[]];
|
|
243
|
+
baseColumn: never;
|
|
244
|
+
identity: undefined;
|
|
245
|
+
generated: undefined;
|
|
246
|
+
}, {}, {}>;
|
|
247
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
248
|
+
name: "created_at";
|
|
249
|
+
tableName: "attempt_streams";
|
|
250
|
+
dataType: "date";
|
|
251
|
+
columnType: "PgTimestamp";
|
|
252
|
+
data: Date;
|
|
253
|
+
driverParam: string;
|
|
254
|
+
notNull: true;
|
|
255
|
+
hasDefault: true;
|
|
256
|
+
isPrimaryKey: false;
|
|
257
|
+
isAutoincrement: false;
|
|
258
|
+
hasRuntimeDefault: false;
|
|
259
|
+
enumValues: undefined;
|
|
260
|
+
baseColumn: never;
|
|
261
|
+
identity: undefined;
|
|
262
|
+
generated: undefined;
|
|
263
|
+
}, {}, {}>;
|
|
264
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
265
|
+
name: "updated_at";
|
|
266
|
+
tableName: "attempt_streams";
|
|
267
|
+
dataType: "date";
|
|
268
|
+
columnType: "PgTimestamp";
|
|
269
|
+
data: Date;
|
|
270
|
+
driverParam: string;
|
|
271
|
+
notNull: true;
|
|
272
|
+
hasDefault: true;
|
|
273
|
+
isPrimaryKey: false;
|
|
274
|
+
isAutoincrement: false;
|
|
275
|
+
hasRuntimeDefault: false;
|
|
276
|
+
enumValues: undefined;
|
|
277
|
+
baseColumn: never;
|
|
278
|
+
identity: undefined;
|
|
279
|
+
generated: undefined;
|
|
280
|
+
}, {}, {}>;
|
|
281
|
+
closedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
282
|
+
name: "closed_at";
|
|
283
|
+
tableName: "attempt_streams";
|
|
284
|
+
dataType: "date";
|
|
285
|
+
columnType: "PgTimestamp";
|
|
286
|
+
data: Date;
|
|
287
|
+
driverParam: string;
|
|
288
|
+
notNull: false;
|
|
289
|
+
hasDefault: false;
|
|
290
|
+
isPrimaryKey: false;
|
|
291
|
+
isAutoincrement: false;
|
|
292
|
+
hasRuntimeDefault: false;
|
|
293
|
+
enumValues: undefined;
|
|
294
|
+
baseColumn: never;
|
|
295
|
+
identity: undefined;
|
|
296
|
+
generated: undefined;
|
|
297
|
+
}, {}, {}>;
|
|
298
|
+
};
|
|
299
|
+
dialect: "pg";
|
|
300
|
+
}>;
|
|
301
|
+
export type AttemptStreamDb = typeof attemptStreams.$inferSelect;
|
|
302
|
+
export type AttemptStreamInsertDb = typeof attemptStreams.$inferInsert;
|
|
303
|
+
export declare function toAttemptStream(row: AttemptStreamDb): AttemptStream;
|
|
304
|
+
//# sourceMappingURL=attempt-streams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt-streams.d.ts","sourceRoot":"","sources":["../../../src/db/schema/attempt-streams.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kCAAkC,CAAC;AAGpE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8C1B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,cAAc,CAAC,YAAY,CAAC;AACjE,MAAM,MAAM,qBAAqB,GAAG,OAAO,cAAc,CAAC,YAAY,CAAC;AAEvE,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,GAAG,aAAa,CAmBnE"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { uuidv7PrimaryKey } from '@shipfox/node-drizzle';
|
|
2
|
+
import { sql } from 'drizzle-orm';
|
|
3
|
+
import { bigint, boolean, index, integer, text, timestamp, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
|
|
4
|
+
import { pgTable } from './common.js';
|
|
5
|
+
/**
|
|
6
|
+
* One stream per (job, step, attempt). Identity is scoped by `job_id` (from the
|
|
7
|
+
* lease), so a lease can only ever reach its own job's streams — cross-job log
|
|
8
|
+
* injection is structurally impossible. `workspace_id`, `project_id`, and `workflow_run_attempt_id`
|
|
9
|
+
* are stamped from the lease at create time; they are functionally determined by
|
|
10
|
+
* `job_id` via workflows FKs, so they are denormalized here for self-contained
|
|
11
|
+
* authorization (per-project read filtering, audit) without joining back to
|
|
12
|
+
* workflows. `committed_length` is the offset-CAS axis (raw NDJSON spool bytes the
|
|
13
|
+
* server has durably accepted from the runner).
|
|
14
|
+
*
|
|
15
|
+
* `truncated` is an out-of-band terminal flag set when the timeout sweep
|
|
16
|
+
* force-closes a stream the runner never ended; the `AttemptStream` entity is the
|
|
17
|
+
* canonical reference for what it means.
|
|
18
|
+
*
|
|
19
|
+
* Per-row `committed_length` and `declared_total_bytes` are bounded by the
|
|
20
|
+
* per-job budget, so `mode: 'number'` is safe on the hot path. Any cross-row
|
|
21
|
+
* aggregate (workspace or system-wide totals) MUST read as bigint at the
|
|
22
|
+
* query site — the global sum is unbounded and would silently lose precision
|
|
23
|
+
* past 2^53 as a JS number.
|
|
24
|
+
*/ export const attemptStreams = pgTable('attempt_streams', {
|
|
25
|
+
id: uuidv7PrimaryKey(),
|
|
26
|
+
jobId: uuid('job_id').notNull(),
|
|
27
|
+
stepId: uuid('step_id').notNull(),
|
|
28
|
+
attempt: integer('attempt').notNull(),
|
|
29
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
30
|
+
projectId: uuid('project_id').notNull(),
|
|
31
|
+
workflowRunAttemptId: uuid('workflow_run_attempt_id').notNull(),
|
|
32
|
+
committedLength: bigint('committed_length', {
|
|
33
|
+
mode: 'number'
|
|
34
|
+
}).notNull().default(0),
|
|
35
|
+
state: text('state', {
|
|
36
|
+
enum: [
|
|
37
|
+
'open',
|
|
38
|
+
'closed'
|
|
39
|
+
]
|
|
40
|
+
}).notNull().default('open'),
|
|
41
|
+
closeReason: text('close_reason', {
|
|
42
|
+
enum: [
|
|
43
|
+
'declared',
|
|
44
|
+
'timeout'
|
|
45
|
+
]
|
|
46
|
+
}),
|
|
47
|
+
declaredTotalBytes: bigint('declared_total_bytes', {
|
|
48
|
+
mode: 'number'
|
|
49
|
+
}),
|
|
50
|
+
truncated: boolean('truncated').notNull().default(false),
|
|
51
|
+
objectKey: text('object_key'),
|
|
52
|
+
createdAt: timestamp('created_at', {
|
|
53
|
+
withTimezone: true
|
|
54
|
+
}).notNull().defaultNow(),
|
|
55
|
+
updatedAt: timestamp('updated_at', {
|
|
56
|
+
withTimezone: true
|
|
57
|
+
}).notNull().defaultNow(),
|
|
58
|
+
closedAt: timestamp('closed_at', {
|
|
59
|
+
withTimezone: true
|
|
60
|
+
})
|
|
61
|
+
}, (table)=>[
|
|
62
|
+
uniqueIndex('logs_attempt_streams_identity_unique').on(table.jobId, table.stepId, table.attempt),
|
|
63
|
+
// The session read path looks up a stream by (step, attempt) without the job id, so the
|
|
64
|
+
// identity unique (which leads with job_id) can't serve it. This index keeps that lookup
|
|
65
|
+
// off a sequential scan as the table grows.
|
|
66
|
+
index('logs_attempt_streams_step_attempt_idx').on(table.stepId, table.attempt),
|
|
67
|
+
// Timeout-close sweeps an open job's streams by job_id; the partial index keeps
|
|
68
|
+
// it off the closed tail.
|
|
69
|
+
index('logs_attempt_streams_open_by_job_idx').on(table.jobId).where(sql`"state" = 'open'`),
|
|
70
|
+
// Open-age reaping needs an index that stays off the closed tail; created_at is
|
|
71
|
+
// immutable, so appends do not churn it.
|
|
72
|
+
index('logs_attempt_streams_open_age_idx').on(table.createdAt).where(sql`"state" = 'open'`),
|
|
73
|
+
// Retention scans closed streams by close age; partial so it never carries the
|
|
74
|
+
// open (in-flight) set.
|
|
75
|
+
index('logs_attempt_streams_retention_idx').on(table.closedAt).where(sql`"state" = 'closed'`),
|
|
76
|
+
// Reconcile re-drives closed streams that never got an object key.
|
|
77
|
+
index('logs_attempt_streams_uncompacted_idx').on(table.closedAt).where(sql`"state" = 'closed' and "object_key" is null`)
|
|
78
|
+
]);
|
|
79
|
+
export function toAttemptStream(row) {
|
|
80
|
+
return {
|
|
81
|
+
id: row.id,
|
|
82
|
+
jobId: row.jobId,
|
|
83
|
+
stepId: row.stepId,
|
|
84
|
+
attempt: row.attempt,
|
|
85
|
+
workspaceId: row.workspaceId,
|
|
86
|
+
projectId: row.projectId,
|
|
87
|
+
workflowRunAttemptId: row.workflowRunAttemptId,
|
|
88
|
+
committedLength: row.committedLength,
|
|
89
|
+
state: row.state,
|
|
90
|
+
closeReason: row.closeReason,
|
|
91
|
+
declaredTotalBytes: row.declaredTotalBytes,
|
|
92
|
+
truncated: row.truncated,
|
|
93
|
+
objectKey: row.objectKey,
|
|
94
|
+
createdAt: row.createdAt,
|
|
95
|
+
updatedAt: row.updatedAt,
|
|
96
|
+
closedAt: row.closedAt
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=attempt-streams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/db/schema/attempt-streams.ts"],"sourcesContent":["import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';\nimport {sql} from 'drizzle-orm';\nimport {\n bigint,\n boolean,\n index,\n integer,\n text,\n timestamp,\n uniqueIndex,\n uuid,\n} from 'drizzle-orm/pg-core';\nimport type {AttemptStream} from '#core/entities/attempt-stream.js';\nimport {pgTable} from './common.js';\n\n/**\n * One stream per (job, step, attempt). Identity is scoped by `job_id` (from the\n * lease), so a lease can only ever reach its own job's streams — cross-job log\n * injection is structurally impossible. `workspace_id`, `project_id`, and `workflow_run_attempt_id`\n * are stamped from the lease at create time; they are functionally determined by\n * `job_id` via workflows FKs, so they are denormalized here for self-contained\n * authorization (per-project read filtering, audit) without joining back to\n * workflows. `committed_length` is the offset-CAS axis (raw NDJSON spool bytes the\n * server has durably accepted from the runner).\n *\n * `truncated` is an out-of-band terminal flag set when the timeout sweep\n * force-closes a stream the runner never ended; the `AttemptStream` entity is the\n * canonical reference for what it means.\n *\n * Per-row `committed_length` and `declared_total_bytes` are bounded by the\n * per-job budget, so `mode: 'number'` is safe on the hot path. Any cross-row\n * aggregate (workspace or system-wide totals) MUST read as bigint at the\n * query site — the global sum is unbounded and would silently lose precision\n * past 2^53 as a JS number.\n */\nexport const attemptStreams = pgTable(\n 'attempt_streams',\n {\n id: uuidv7PrimaryKey(),\n jobId: uuid('job_id').notNull(),\n stepId: uuid('step_id').notNull(),\n attempt: integer('attempt').notNull(),\n workspaceId: uuid('workspace_id').notNull(),\n projectId: uuid('project_id').notNull(),\n workflowRunAttemptId: uuid('workflow_run_attempt_id').notNull(),\n committedLength: bigint('committed_length', {mode: 'number'}).notNull().default(0),\n state: text('state', {enum: ['open', 'closed']})\n .notNull()\n .default('open'),\n closeReason: text('close_reason', {enum: ['declared', 'timeout']}),\n declaredTotalBytes: bigint('declared_total_bytes', {mode: 'number'}),\n truncated: boolean('truncated').notNull().default(false),\n objectKey: text('object_key'),\n createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),\n updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),\n closedAt: timestamp('closed_at', {withTimezone: true}),\n },\n (table) => [\n uniqueIndex('logs_attempt_streams_identity_unique').on(\n table.jobId,\n table.stepId,\n table.attempt,\n ),\n // The session read path looks up a stream by (step, attempt) without the job id, so the\n // identity unique (which leads with job_id) can't serve it. This index keeps that lookup\n // off a sequential scan as the table grows.\n index('logs_attempt_streams_step_attempt_idx').on(table.stepId, table.attempt),\n // Timeout-close sweeps an open job's streams by job_id; the partial index keeps\n // it off the closed tail.\n index('logs_attempt_streams_open_by_job_idx').on(table.jobId).where(sql`\"state\" = 'open'`),\n // Open-age reaping needs an index that stays off the closed tail; created_at is\n // immutable, so appends do not churn it.\n index('logs_attempt_streams_open_age_idx').on(table.createdAt).where(sql`\"state\" = 'open'`),\n // Retention scans closed streams by close age; partial so it never carries the\n // open (in-flight) set.\n index('logs_attempt_streams_retention_idx').on(table.closedAt).where(sql`\"state\" = 'closed'`),\n // Reconcile re-drives closed streams that never got an object key.\n index('logs_attempt_streams_uncompacted_idx')\n .on(table.closedAt)\n .where(sql`\"state\" = 'closed' and \"object_key\" is null`),\n ],\n);\n\nexport type AttemptStreamDb = typeof attemptStreams.$inferSelect;\nexport type AttemptStreamInsertDb = typeof attemptStreams.$inferInsert;\n\nexport function toAttemptStream(row: AttemptStreamDb): AttemptStream {\n return {\n id: row.id,\n jobId: row.jobId,\n stepId: row.stepId,\n attempt: row.attempt,\n workspaceId: row.workspaceId,\n projectId: row.projectId,\n workflowRunAttemptId: row.workflowRunAttemptId,\n committedLength: row.committedLength,\n state: row.state,\n closeReason: row.closeReason,\n declaredTotalBytes: row.declaredTotalBytes,\n truncated: row.truncated,\n objectKey: row.objectKey,\n createdAt: row.createdAt,\n updatedAt: row.updatedAt,\n closedAt: row.closedAt,\n };\n}\n"],"names":["uuidv7PrimaryKey","sql","bigint","boolean","index","integer","text","timestamp","uniqueIndex","uuid","pgTable","attemptStreams","id","jobId","notNull","stepId","attempt","workspaceId","projectId","workflowRunAttemptId","committedLength","mode","default","state","enum","closeReason","declaredTotalBytes","truncated","objectKey","createdAt","withTimezone","defaultNow","updatedAt","closedAt","table","on","where","toAttemptStream","row"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,wBAAwB;AACvD,SAAQC,GAAG,QAAO,cAAc;AAChC,SACEC,MAAM,EACNC,OAAO,EACPC,KAAK,EACLC,OAAO,EACPC,IAAI,EACJC,SAAS,EACTC,WAAW,EACXC,IAAI,QACC,sBAAsB;AAE7B,SAAQC,OAAO,QAAO,cAAc;AAEpC;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,MAAMC,iBAAiBD,QAC5B,mBACA;IACEE,IAAIZ;IACJa,OAAOJ,KAAK,UAAUK,OAAO;IAC7BC,QAAQN,KAAK,WAAWK,OAAO;IAC/BE,SAASX,QAAQ,WAAWS,OAAO;IACnCG,aAAaR,KAAK,gBAAgBK,OAAO;IACzCI,WAAWT,KAAK,cAAcK,OAAO;IACrCK,sBAAsBV,KAAK,2BAA2BK,OAAO;IAC7DM,iBAAiBlB,OAAO,oBAAoB;QAACmB,MAAM;IAAQ,GAAGP,OAAO,GAAGQ,OAAO,CAAC;IAChFC,OAAOjB,KAAK,SAAS;QAACkB,MAAM;YAAC;YAAQ;SAAS;IAAA,GAC3CV,OAAO,GACPQ,OAAO,CAAC;IACXG,aAAanB,KAAK,gBAAgB;QAACkB,MAAM;YAAC;YAAY;SAAU;IAAA;IAChEE,oBAAoBxB,OAAO,wBAAwB;QAACmB,MAAM;IAAQ;IAClEM,WAAWxB,QAAQ,aAAaW,OAAO,GAAGQ,OAAO,CAAC;IAClDM,WAAWtB,KAAK;IAChBuB,WAAWtB,UAAU,cAAc;QAACuB,cAAc;IAAI,GAAGhB,OAAO,GAAGiB,UAAU;IAC7EC,WAAWzB,UAAU,cAAc;QAACuB,cAAc;IAAI,GAAGhB,OAAO,GAAGiB,UAAU;IAC7EE,UAAU1B,UAAU,aAAa;QAACuB,cAAc;IAAI;AACtD,GACA,CAACI,QAAU;QACT1B,YAAY,wCAAwC2B,EAAE,CACpDD,MAAMrB,KAAK,EACXqB,MAAMnB,MAAM,EACZmB,MAAMlB,OAAO;QAEf,wFAAwF;QACxF,yFAAyF;QACzF,4CAA4C;QAC5CZ,MAAM,yCAAyC+B,EAAE,CAACD,MAAMnB,MAAM,EAAEmB,MAAMlB,OAAO;QAC7E,gFAAgF;QAChF,0BAA0B;QAC1BZ,MAAM,wCAAwC+B,EAAE,CAACD,MAAMrB,KAAK,EAAEuB,KAAK,CAACnC,GAAG,CAAC,gBAAgB,CAAC;QACzF,gFAAgF;QAChF,yCAAyC;QACzCG,MAAM,qCAAqC+B,EAAE,CAACD,MAAML,SAAS,EAAEO,KAAK,CAACnC,GAAG,CAAC,gBAAgB,CAAC;QAC1F,+EAA+E;QAC/E,wBAAwB;QACxBG,MAAM,sCAAsC+B,EAAE,CAACD,MAAMD,QAAQ,EAAEG,KAAK,CAACnC,GAAG,CAAC,kBAAkB,CAAC;QAC5F,mEAAmE;QACnEG,MAAM,wCACH+B,EAAE,CAACD,MAAMD,QAAQ,EACjBG,KAAK,CAACnC,GAAG,CAAC,2CAA2C,CAAC;KAC1D,EACD;AAKF,OAAO,SAASoC,gBAAgBC,GAAoB;IAClD,OAAO;QACL1B,IAAI0B,IAAI1B,EAAE;QACVC,OAAOyB,IAAIzB,KAAK;QAChBE,QAAQuB,IAAIvB,MAAM;QAClBC,SAASsB,IAAItB,OAAO;QACpBC,aAAaqB,IAAIrB,WAAW;QAC5BC,WAAWoB,IAAIpB,SAAS;QACxBC,sBAAsBmB,IAAInB,oBAAoB;QAC9CC,iBAAiBkB,IAAIlB,eAAe;QACpCG,OAAOe,IAAIf,KAAK;QAChBE,aAAaa,IAAIb,WAAW;QAC5BC,oBAAoBY,IAAIZ,kBAAkB;QAC1CC,WAAWW,IAAIX,SAAS;QACxBC,WAAWU,IAAIV,SAAS;QACxBC,WAAWS,IAAIT,SAAS;QACxBG,WAAWM,IAAIN,SAAS;QACxBC,UAAUK,IAAIL,QAAQ;IACxB;AACF"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hot, append-only log bytes for open streams, pending compaction.
|
|
3
|
+
*
|
|
4
|
+
* Two byte axes meet here and MUST stay distinct:
|
|
5
|
+
*
|
|
6
|
+
* Runner spool (CAS axis) Stored chunk stream (read axis, by seq)
|
|
7
|
+
* offset 0 ┌────────────┐ ───► seq 1 │ normalized chunk A │ origin=runner
|
|
8
|
+
* 100 ├─ chunk A ──┤ ───► seq 2 │ normalized chunk B │ origin=runner
|
|
9
|
+
* 250 ├─ chunk B ──┤ ───► seq 3 │ {capped} │ origin=control ← server-injected;
|
|
10
|
+
* └────────────┘ does NOT advance committed_length
|
|
11
|
+
*
|
|
12
|
+
* `origin` is `runner` for bytes accepted from a runner append after ingest normalization, and
|
|
13
|
+
* `control` for a server-injected tombstone. `stream_offset` is the runner-axis position of a
|
|
14
|
+
* runner chunk; for a server `control` chunk it is informational. `seq` (insertion order) is the
|
|
15
|
+
* read axis the reader walks, so server records interleave correctly with normalized runner
|
|
16
|
+
* records.
|
|
17
|
+
*/
|
|
18
|
+
export declare const logChunks: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
19
|
+
name: "chunks";
|
|
20
|
+
schema: undefined;
|
|
21
|
+
columns: {
|
|
22
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
23
|
+
name: "id";
|
|
24
|
+
tableName: "chunks";
|
|
25
|
+
dataType: "string";
|
|
26
|
+
columnType: "PgUUID";
|
|
27
|
+
data: string;
|
|
28
|
+
driverParam: string;
|
|
29
|
+
notNull: true;
|
|
30
|
+
hasDefault: true;
|
|
31
|
+
isPrimaryKey: true;
|
|
32
|
+
isAutoincrement: false;
|
|
33
|
+
hasRuntimeDefault: false;
|
|
34
|
+
enumValues: undefined;
|
|
35
|
+
baseColumn: never;
|
|
36
|
+
identity: undefined;
|
|
37
|
+
generated: undefined;
|
|
38
|
+
}, {}, {}>;
|
|
39
|
+
streamId: import("drizzle-orm/pg-core").PgColumn<{
|
|
40
|
+
name: "stream_id";
|
|
41
|
+
tableName: "chunks";
|
|
42
|
+
dataType: "string";
|
|
43
|
+
columnType: "PgUUID";
|
|
44
|
+
data: string;
|
|
45
|
+
driverParam: string;
|
|
46
|
+
notNull: true;
|
|
47
|
+
hasDefault: false;
|
|
48
|
+
isPrimaryKey: false;
|
|
49
|
+
isAutoincrement: false;
|
|
50
|
+
hasRuntimeDefault: false;
|
|
51
|
+
enumValues: undefined;
|
|
52
|
+
baseColumn: never;
|
|
53
|
+
identity: undefined;
|
|
54
|
+
generated: undefined;
|
|
55
|
+
}, {}, {}>;
|
|
56
|
+
seq: import("drizzle-orm/pg-core").PgColumn<{
|
|
57
|
+
name: "seq";
|
|
58
|
+
tableName: "chunks";
|
|
59
|
+
dataType: "number";
|
|
60
|
+
columnType: "PgBigSerial53";
|
|
61
|
+
data: number;
|
|
62
|
+
driverParam: number;
|
|
63
|
+
notNull: true;
|
|
64
|
+
hasDefault: true;
|
|
65
|
+
isPrimaryKey: false;
|
|
66
|
+
isAutoincrement: false;
|
|
67
|
+
hasRuntimeDefault: false;
|
|
68
|
+
enumValues: undefined;
|
|
69
|
+
baseColumn: never;
|
|
70
|
+
identity: undefined;
|
|
71
|
+
generated: undefined;
|
|
72
|
+
}, {}, {}>;
|
|
73
|
+
streamOffset: import("drizzle-orm/pg-core").PgColumn<{
|
|
74
|
+
name: "stream_offset";
|
|
75
|
+
tableName: "chunks";
|
|
76
|
+
dataType: "number";
|
|
77
|
+
columnType: "PgBigInt53";
|
|
78
|
+
data: number;
|
|
79
|
+
driverParam: string | number;
|
|
80
|
+
notNull: true;
|
|
81
|
+
hasDefault: false;
|
|
82
|
+
isPrimaryKey: false;
|
|
83
|
+
isAutoincrement: false;
|
|
84
|
+
hasRuntimeDefault: false;
|
|
85
|
+
enumValues: undefined;
|
|
86
|
+
baseColumn: never;
|
|
87
|
+
identity: undefined;
|
|
88
|
+
generated: undefined;
|
|
89
|
+
}, {}, {}>;
|
|
90
|
+
byteLen: import("drizzle-orm/pg-core").PgColumn<{
|
|
91
|
+
name: "byte_len";
|
|
92
|
+
tableName: "chunks";
|
|
93
|
+
dataType: "number";
|
|
94
|
+
columnType: "PgInteger";
|
|
95
|
+
data: number;
|
|
96
|
+
driverParam: string | number;
|
|
97
|
+
notNull: true;
|
|
98
|
+
hasDefault: false;
|
|
99
|
+
isPrimaryKey: false;
|
|
100
|
+
isAutoincrement: false;
|
|
101
|
+
hasRuntimeDefault: false;
|
|
102
|
+
enumValues: undefined;
|
|
103
|
+
baseColumn: never;
|
|
104
|
+
identity: undefined;
|
|
105
|
+
generated: undefined;
|
|
106
|
+
}, {}, {}>;
|
|
107
|
+
data: import("drizzle-orm/pg-core").PgColumn<{
|
|
108
|
+
name: "data";
|
|
109
|
+
tableName: "chunks";
|
|
110
|
+
dataType: "custom";
|
|
111
|
+
columnType: "PgCustomColumn";
|
|
112
|
+
data: Buffer<ArrayBufferLike>;
|
|
113
|
+
driverParam: Buffer<ArrayBufferLike>;
|
|
114
|
+
notNull: true;
|
|
115
|
+
hasDefault: false;
|
|
116
|
+
isPrimaryKey: false;
|
|
117
|
+
isAutoincrement: false;
|
|
118
|
+
hasRuntimeDefault: false;
|
|
119
|
+
enumValues: undefined;
|
|
120
|
+
baseColumn: never;
|
|
121
|
+
identity: undefined;
|
|
122
|
+
generated: undefined;
|
|
123
|
+
}, {}, {
|
|
124
|
+
pgColumnBuilderBrand: "PgCustomColumnBuilderBrand";
|
|
125
|
+
}>;
|
|
126
|
+
origin: import("drizzle-orm/pg-core").PgColumn<{
|
|
127
|
+
name: "origin";
|
|
128
|
+
tableName: "chunks";
|
|
129
|
+
dataType: "string";
|
|
130
|
+
columnType: "PgText";
|
|
131
|
+
data: "runner" | "control";
|
|
132
|
+
driverParam: string;
|
|
133
|
+
notNull: true;
|
|
134
|
+
hasDefault: false;
|
|
135
|
+
isPrimaryKey: false;
|
|
136
|
+
isAutoincrement: false;
|
|
137
|
+
hasRuntimeDefault: false;
|
|
138
|
+
enumValues: ["runner", "control"];
|
|
139
|
+
baseColumn: never;
|
|
140
|
+
identity: undefined;
|
|
141
|
+
generated: undefined;
|
|
142
|
+
}, {}, {}>;
|
|
143
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
144
|
+
name: "created_at";
|
|
145
|
+
tableName: "chunks";
|
|
146
|
+
dataType: "date";
|
|
147
|
+
columnType: "PgTimestamp";
|
|
148
|
+
data: Date;
|
|
149
|
+
driverParam: string;
|
|
150
|
+
notNull: true;
|
|
151
|
+
hasDefault: true;
|
|
152
|
+
isPrimaryKey: false;
|
|
153
|
+
isAutoincrement: false;
|
|
154
|
+
hasRuntimeDefault: false;
|
|
155
|
+
enumValues: undefined;
|
|
156
|
+
baseColumn: never;
|
|
157
|
+
identity: undefined;
|
|
158
|
+
generated: undefined;
|
|
159
|
+
}, {}, {}>;
|
|
160
|
+
};
|
|
161
|
+
dialect: "pg";
|
|
162
|
+
}>;
|
|
163
|
+
export type LogChunkDb = typeof logChunks.$inferSelect;
|
|
164
|
+
export type LogChunkInsertDb = typeof logChunks.$inferInsert;
|
|
165
|
+
export type ChunkOrigin = 'runner' | 'control';
|
|
166
|
+
//# sourceMappingURL=chunks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../../../src/db/schema/chunks.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAerB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,YAAY,CAAC;AACvD,MAAM,MAAM,gBAAgB,GAAG,OAAO,SAAS,CAAC,YAAY,CAAC;AAE7D,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC"}
|