@sixb/sqlite 0.1.19 → 0.1.21
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/action-run-storage.d.ts +4 -0
- package/dist/action-run-storage.d.ts.map +1 -1
- package/dist/activity-storage.d.ts +20 -0
- package/dist/activity-storage.d.ts.map +1 -0
- package/dist/agents/agent-storage.d.ts.map +1 -1
- package/dist/agents/threads.d.ts +4 -0
- package/dist/agents/threads.d.ts.map +1 -1
- package/dist/ai-limit-storage.d.ts.map +1 -1
- package/dist/ai-usage-storage.d.ts.map +1 -1
- package/dist/artifact-storage.d.ts +22 -0
- package/dist/artifact-storage.d.ts.map +1 -0
- package/dist/auth-storage/auth-storage.d.ts.map +1 -1
- package/dist/auth-storage/magic-links.d.ts.map +1 -1
- package/dist/auth-storage/oidc-attempts.d.ts.map +1 -1
- package/dist/auth-storage/rows.d.ts +0 -3
- package/dist/auth-storage/rows.d.ts.map +1 -1
- package/dist/auth-storage/sessions.d.ts +2 -11
- package/dist/auth-storage/sessions.d.ts.map +1 -1
- package/dist/auth-storage/shared.d.ts +0 -2
- package/dist/auth-storage/shared.d.ts.map +1 -1
- package/dist/execution-storage.d.ts +2 -1
- package/dist/execution-storage.d.ts.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +933 -128
- package/dist/index.js.map +32 -30
- package/dist/migrations.d.ts +2 -0
- package/dist/migrations.d.ts.map +1 -1
- package/dist/objects/storage.d.ts.map +1 -1
- package/dist/ontology-storage/sources.d.ts +2 -1
- package/dist/ontology-storage/sources.d.ts.map +1 -1
- package/dist/pipeline-run-storage.d.ts.map +1 -1
- package/dist/projection-run-storage.d.ts.map +1 -1
- package/dist/rules-storage.d.ts.map +1 -1
- package/dist/share-grant-storage.d.ts +2 -1
- package/dist/share-grant-storage.d.ts.map +1 -1
- package/dist/share-session-storage.d.ts.map +1 -1
- package/dist/sync-run-storage.d.ts.map +1 -1
- package/dist/timeseries-storage.d.ts.map +1 -1
- package/dist/transactions.d.ts +0 -1
- package/dist/transactions.d.ts.map +1 -1
- package/dist/webhook-run-storage.d.ts.map +1 -1
- package/dist/workflow-intervention-storage.d.ts.map +1 -1
- package/dist/workflow-run-storage.d.ts +4 -0
- package/dist/workflow-run-storage.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/action-run-storage.ts +27 -5
- package/src/activity-storage.ts +588 -0
- package/src/agents/agent-storage.ts +0 -5
- package/src/agents/threads.ts +27 -0
- package/src/ai-limit-storage.ts +0 -2
- package/src/ai-usage-storage.ts +0 -4
- package/src/artifact-storage.ts +356 -0
- package/src/auth-storage/auth-storage.ts +0 -23
- package/src/auth-storage/magic-links.ts +1 -6
- package/src/auth-storage/oidc-attempts.ts +1 -6
- package/src/auth-storage/rows.ts +0 -6
- package/src/auth-storage/sessions.ts +21 -42
- package/src/auth-storage/shared.ts +3 -20
- package/src/execution-storage.ts +56 -0
- package/src/index.ts +11 -10
- package/src/migrations/061-drop-auth-audience.sql +16 -0
- package/src/migrations/062-artifacts.sql +71 -0
- package/src/migrations/063-drop-output-diagnostics.sql +19 -0
- package/src/migrations/064-activity.sql +61 -0
- package/src/migrations/065-activity-timeline.sql +19 -0
- package/src/migrations/066-activity-interactions.sql +20 -0
- package/src/migrations.ts +36 -0
- package/src/objects/storage.ts +0 -5
- package/src/ontology-storage/sources.ts +41 -0
- package/src/pipeline-run-storage.ts +0 -5
- package/src/projection-run-storage.ts +0 -5
- package/src/rules-storage.ts +0 -5
- package/src/share-grant-storage.ts +25 -2
- package/src/share-session-storage.ts +0 -2
- package/src/sync-run-storage.ts +0 -5
- package/src/timeseries-storage.ts +0 -5
- package/src/transactions.ts +8 -8
- package/src/webhook-run-storage.ts +0 -3
- package/src/workflow-intervention-storage.ts +0 -5
- package/src/workflow-run-storage.ts +27 -5
package/src/rules-storage.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type {
|
|
|
11
11
|
StoredRuleResolvedEvent,
|
|
12
12
|
StoredRuleTriggeredEvent,
|
|
13
13
|
} from "@sixb/core/storage"
|
|
14
|
-
import { installFreshSqliteSchema } from "./migrations"
|
|
15
14
|
import {
|
|
16
15
|
closeSqliteStoreConnection,
|
|
17
16
|
openSqliteStoreConnection,
|
|
@@ -33,10 +32,6 @@ export class SqliteRulesStorage implements RulesStorage {
|
|
|
33
32
|
constructor(options: SqliteRulesStorageOptions = {}) {
|
|
34
33
|
this.connection = openSqliteStoreConnection(options)
|
|
35
34
|
this.db = this.connection.db
|
|
36
|
-
|
|
37
|
-
if (this.connection.installFreshSchema) {
|
|
38
|
-
installFreshSqliteSchema(this.db)
|
|
39
|
-
}
|
|
40
35
|
}
|
|
41
36
|
|
|
42
37
|
async getActive(params: {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import type {
|
|
10
10
|
CreateShareGrantInput,
|
|
11
11
|
GetShareGrantByIdInput,
|
|
12
|
+
GetShareGrantsByIdsInput,
|
|
12
13
|
ListShareGrantsInput,
|
|
13
14
|
ListShareGrantsResult,
|
|
14
15
|
RevokeShareGrantInput,
|
|
@@ -16,7 +17,6 @@ import type {
|
|
|
16
17
|
ShareGrantStorage,
|
|
17
18
|
} from "@sixb/core/storage"
|
|
18
19
|
import { ShareGrantStorageError } from "@sixb/core/storage"
|
|
19
|
-
import { installFreshSqliteSchema } from "./migrations"
|
|
20
20
|
import { isUniqueConstraintError } from "./storage-errors"
|
|
21
21
|
import {
|
|
22
22
|
closeSqliteStoreConnection,
|
|
@@ -37,7 +37,6 @@ export class SqliteShareGrantStorage implements ShareGrantStorage {
|
|
|
37
37
|
constructor(options: SqliteShareGrantStorageOptions = {}) {
|
|
38
38
|
this.connection = openSqliteStoreConnection(options)
|
|
39
39
|
this.db = this.connection.db
|
|
40
|
-
if (this.connection.installFreshSchema) installFreshSqliteSchema(this.db)
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
async create(input: CreateShareGrantInput): Promise<ShareGrantRecord> {
|
|
@@ -87,6 +86,30 @@ export class SqliteShareGrantStorage implements ShareGrantStorage {
|
|
|
87
86
|
return this.getRow(normalized.projectId, normalized.id)
|
|
88
87
|
}
|
|
89
88
|
|
|
89
|
+
async getByIds(input: GetShareGrantsByIdsInput): Promise<readonly ShareGrantRecord[]> {
|
|
90
|
+
const ids = [...new Set(input.ids)]
|
|
91
|
+
if (ids.length === 0) {
|
|
92
|
+
return []
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const rows = this.db
|
|
96
|
+
.query(
|
|
97
|
+
`
|
|
98
|
+
SELECT *
|
|
99
|
+
FROM share_grants
|
|
100
|
+
WHERE project_id = ?
|
|
101
|
+
AND id IN (SELECT value FROM json_each(?))
|
|
102
|
+
`
|
|
103
|
+
)
|
|
104
|
+
.all(input.projectId, JSON.stringify(ids)) as SqliteShareGrantRow[]
|
|
105
|
+
|
|
106
|
+
const byId = new Map(rows.map((row) => [row.id, row]))
|
|
107
|
+
return ids.flatMap((id) => {
|
|
108
|
+
const row = byId.get(id)
|
|
109
|
+
return row ? [rowToRecord(row)] : []
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
90
113
|
async list(input: ListShareGrantsInput): Promise<ListShareGrantsResult> {
|
|
91
114
|
const normalized = normalizeListShareGrantsInput(input)
|
|
92
115
|
const where = ["project_id = ?"]
|
|
@@ -15,7 +15,6 @@ import type {
|
|
|
15
15
|
ShareSessionStorage,
|
|
16
16
|
} from "@sixb/core/storage"
|
|
17
17
|
import { ShareSessionStorageError } from "@sixb/core/storage"
|
|
18
|
-
import { installFreshSqliteSchema } from "./migrations"
|
|
19
18
|
import { isForeignKeyConstraintError, isUniqueConstraintError } from "./storage-errors"
|
|
20
19
|
import {
|
|
21
20
|
closeSqliteStoreConnection,
|
|
@@ -36,7 +35,6 @@ export class SqliteShareSessionStorage implements ShareSessionStorage {
|
|
|
36
35
|
constructor(options: SqliteShareSessionStorageOptions = {}) {
|
|
37
36
|
this.connection = openSqliteStoreConnection(options)
|
|
38
37
|
this.db = this.connection.db
|
|
39
|
-
if (this.connection.installFreshSchema) installFreshSqliteSchema(this.db)
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
async create(input: CreateShareSessionInput): Promise<ShareSessionRecord> {
|
package/src/sync-run-storage.ts
CHANGED
|
@@ -17,7 +17,6 @@ import type {
|
|
|
17
17
|
} from "@sixb/core/storage"
|
|
18
18
|
import { SYNC_RUN_FAILURE_CODES, SyncRunError } from "@sixb/core/storage"
|
|
19
19
|
import { queryLatestRunsByOwnerId } from "./latest-run-query"
|
|
20
|
-
import { installFreshSqliteSchema } from "./migrations"
|
|
21
20
|
import {
|
|
22
21
|
appendRunListFilters,
|
|
23
22
|
hasEmptyStatuses,
|
|
@@ -48,10 +47,6 @@ export class SqliteSyncRunStorage implements SyncRunStorage {
|
|
|
48
47
|
this.connection = openSqliteStoreConnection(options)
|
|
49
48
|
this.db = this.connection.db
|
|
50
49
|
this.executions = options.executions
|
|
51
|
-
|
|
52
|
-
if (this.connection.installFreshSchema) {
|
|
53
|
-
installFreshSqliteSchema(this.db)
|
|
54
|
-
}
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
async queue(input: QueueSyncRunInput): Promise<SyncRunRecord> {
|
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
TimeseriesPoint,
|
|
6
6
|
TimeseriesStorage,
|
|
7
7
|
} from "@sixb/core/storage"
|
|
8
|
-
import { installFreshSqliteSchema } from "./migrations"
|
|
9
8
|
import {
|
|
10
9
|
closeSqliteStoreConnection,
|
|
11
10
|
openSqliteStoreConnection,
|
|
@@ -31,10 +30,6 @@ export class SqliteTimeseriesStorage implements TimeseriesStorage {
|
|
|
31
30
|
constructor(options: SqliteTimeseriesStorageOptions = {}) {
|
|
32
31
|
this.connection = openSqliteStoreConnection(options)
|
|
33
32
|
this.db = this.connection.db
|
|
34
|
-
|
|
35
|
-
if (this.connection.installFreshSchema) {
|
|
36
|
-
installFreshSqliteSchema(this.db)
|
|
37
|
-
}
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
async getHistory(params: {
|
package/src/transactions.ts
CHANGED
|
@@ -2,11 +2,11 @@ import type { Database } from "bun:sqlite"
|
|
|
2
2
|
import { Database as SqliteDatabase } from "bun:sqlite"
|
|
3
3
|
import { mkdirSync } from "node:fs"
|
|
4
4
|
import { dirname } from "node:path"
|
|
5
|
+
import { freshSqliteDatabase } from "./migrations"
|
|
5
6
|
|
|
6
7
|
export interface SqliteStoreConnection {
|
|
7
8
|
readonly db: Database
|
|
8
9
|
readonly ownsConnection: boolean
|
|
9
|
-
readonly installFreshSchema: boolean
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface SqliteStoreConnectionOptions {
|
|
@@ -22,20 +22,20 @@ export function openSqliteStoreConnection(
|
|
|
22
22
|
return {
|
|
23
23
|
db: options.connection.db,
|
|
24
24
|
ownsConnection: false,
|
|
25
|
-
installFreshSchema: false,
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
const path = options.path ?? ":memory:"
|
|
30
29
|
if (path !== ":memory:" && !options.readonly) mkdirSync(dirname(path), { recursive: true })
|
|
31
|
-
|
|
30
|
+
// A file is brought up to date by its migrators; a writable in-memory database starts with the
|
|
31
|
+
// whole schema.
|
|
32
|
+
const db =
|
|
33
|
+
path === ":memory:" && !options.readonly
|
|
34
|
+
? freshSqliteDatabase()
|
|
35
|
+
: new SqliteDatabase(path, options.readonly ? { readonly: true } : undefined)
|
|
32
36
|
db.run("PRAGMA foreign_keys = ON")
|
|
33
37
|
db.run("PRAGMA busy_timeout = 5000")
|
|
34
|
-
return {
|
|
35
|
-
db,
|
|
36
|
-
ownsConnection: true,
|
|
37
|
-
installFreshSchema: path === ":memory:" && !options.readonly,
|
|
38
|
-
}
|
|
38
|
+
return { db, ownsConnection: true }
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function closeSqliteStoreConnection(connection: SqliteStoreConnection): void {
|
|
@@ -13,7 +13,6 @@ import type {
|
|
|
13
13
|
WebhookRunStorage,
|
|
14
14
|
} from "@sixb/core/storage"
|
|
15
15
|
import { canRetryWebhookRun, WEBHOOK_RUN_FAILURE_CODES, WebhookRunError } from "@sixb/core/storage"
|
|
16
|
-
import { installFreshSqliteSchema } from "./migrations"
|
|
17
16
|
import {
|
|
18
17
|
appendRunListFilters,
|
|
19
18
|
hasEmptyStatuses,
|
|
@@ -45,8 +44,6 @@ export class SqliteWebhookRunStorage implements WebhookRunStorage {
|
|
|
45
44
|
this.connection = openSqliteStoreConnection(options)
|
|
46
45
|
this.db = this.connection.db
|
|
47
46
|
this.executions = options.executions
|
|
48
|
-
|
|
49
|
-
if (this.connection.installFreshSchema) installFreshSqliteSchema(this.db)
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
async start(input: StartWebhookRunInput): Promise<WebhookRunRecord> {
|
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
WorkflowInterventionStorage,
|
|
13
13
|
} from "@sixb/core/storage"
|
|
14
14
|
import { WorkflowInterventionError } from "@sixb/core/storage"
|
|
15
|
-
import { installFreshSqliteSchema } from "./migrations"
|
|
16
15
|
import { isUniqueConstraintError } from "./storage-errors"
|
|
17
16
|
import {
|
|
18
17
|
closeSqliteStoreConnection,
|
|
@@ -34,10 +33,6 @@ export class SqliteWorkflowInterventionStorage implements WorkflowInterventionSt
|
|
|
34
33
|
constructor(options: SqliteWorkflowInterventionStorageOptions = {}) {
|
|
35
34
|
this.connection = openSqliteStoreConnection(options)
|
|
36
35
|
this.db = this.connection.db
|
|
37
|
-
|
|
38
|
-
if (this.connection.installFreshSchema) {
|
|
39
|
-
installFreshSqliteSchema(this.db)
|
|
40
|
-
}
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
async create(input: CreateWorkflowInterventionInput): Promise<WorkflowInterventionRecord> {
|
|
@@ -44,7 +44,6 @@ import {
|
|
|
44
44
|
WorkflowRunError,
|
|
45
45
|
} from "@sixb/core/storage"
|
|
46
46
|
import { queryLatestRunsByOwnerId } from "./latest-run-query"
|
|
47
|
-
import { installFreshSqliteSchema } from "./migrations"
|
|
48
47
|
import {
|
|
49
48
|
appendRunListFilters,
|
|
50
49
|
hasEmptyStatuses,
|
|
@@ -80,10 +79,6 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
|
|
|
80
79
|
this.db = this.connection.db
|
|
81
80
|
this.executions = options.executions
|
|
82
81
|
|
|
83
|
-
if (this.connection.installFreshSchema) {
|
|
84
|
-
installFreshSqliteSchema(this.db)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
82
|
this.nodes = new SqliteWorkflowNodeRunStorage(this.db)
|
|
88
83
|
this.agentNodes = new SqliteWorkflowAgentNodeRunStorage(this.db, this.executions)
|
|
89
84
|
}
|
|
@@ -363,6 +358,33 @@ export class SqliteWorkflowRunStorage implements WorkflowRunStorage {
|
|
|
363
358
|
return row ? rowToWorkflowRunRecord(row) : null
|
|
364
359
|
}
|
|
365
360
|
|
|
361
|
+
async getByExecutionIds(params: {
|
|
362
|
+
readonly projectId: string
|
|
363
|
+
readonly executionIds: readonly string[]
|
|
364
|
+
}): Promise<readonly WorkflowRunRecord[]> {
|
|
365
|
+
const executionIds = [...new Set(params.executionIds)]
|
|
366
|
+
if (executionIds.length === 0) {
|
|
367
|
+
return []
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const rows = this.db
|
|
371
|
+
.query(
|
|
372
|
+
`
|
|
373
|
+
SELECT *
|
|
374
|
+
FROM workflow_runs
|
|
375
|
+
WHERE project_id = ?
|
|
376
|
+
AND execution_id IN (SELECT value FROM json_each(?))
|
|
377
|
+
`
|
|
378
|
+
)
|
|
379
|
+
.all(params.projectId, JSON.stringify(executionIds)) as WorkflowRunDatabaseRow[]
|
|
380
|
+
|
|
381
|
+
const byExecution = new Map(rows.map((row) => [row.execution_id, row]))
|
|
382
|
+
return executionIds.flatMap((executionId) => {
|
|
383
|
+
const row = byExecution.get(executionId)
|
|
384
|
+
return row ? [rowToWorkflowRunRecord(row)] : []
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
|
|
366
388
|
async list(input: ListWorkflowRunsInput): Promise<ListWorkflowRunsResult> {
|
|
367
389
|
if (hasEmptyStatuses(input) || input.workflowIds?.length === 0) {
|
|
368
390
|
return {
|