@sixb/sqlite 0.1.18 → 0.1.20

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.
Files changed (59) hide show
  1. package/dist/action-run-storage.d.ts +4 -9
  2. package/dist/action-run-storage.d.ts.map +1 -1
  3. package/dist/agents/agent-storage.d.ts.map +1 -1
  4. package/dist/ai-limit-storage.d.ts.map +1 -1
  5. package/dist/ai-usage-storage.d.ts.map +1 -1
  6. package/dist/auth-storage/auth-storage.d.ts.map +1 -1
  7. package/dist/auth-storage/magic-links.d.ts.map +1 -1
  8. package/dist/auth-storage/oidc-attempts.d.ts.map +1 -1
  9. package/dist/auth-storage/rows.d.ts +0 -3
  10. package/dist/auth-storage/rows.d.ts.map +1 -1
  11. package/dist/auth-storage/sessions.d.ts +0 -10
  12. package/dist/auth-storage/sessions.d.ts.map +1 -1
  13. package/dist/auth-storage/shared.d.ts +0 -2
  14. package/dist/auth-storage/shared.d.ts.map +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +301 -398
  17. package/dist/index.js.map +27 -27
  18. package/dist/migrations.d.ts +2 -0
  19. package/dist/migrations.d.ts.map +1 -1
  20. package/dist/objects/storage.d.ts.map +1 -1
  21. package/dist/pipeline-run-storage.d.ts.map +1 -1
  22. package/dist/projection-run-storage.d.ts.map +1 -1
  23. package/dist/rules-storage.d.ts.map +1 -1
  24. package/dist/share-grant-storage.d.ts.map +1 -1
  25. package/dist/share-session-storage.d.ts.map +1 -1
  26. package/dist/sync-run-storage.d.ts.map +1 -1
  27. package/dist/timeseries-storage.d.ts.map +1 -1
  28. package/dist/transactions.d.ts +0 -1
  29. package/dist/transactions.d.ts.map +1 -1
  30. package/dist/webhook-run-storage.d.ts.map +1 -1
  31. package/dist/workflow-intervention-storage.d.ts.map +1 -1
  32. package/dist/workflow-run-storage.d.ts.map +1 -1
  33. package/package.json +3 -3
  34. package/src/action-run-storage.ts +104 -447
  35. package/src/agents/agent-storage.ts +0 -5
  36. package/src/ai-limit-storage.ts +0 -2
  37. package/src/ai-usage-storage.ts +0 -4
  38. package/src/auth-storage/auth-storage.ts +0 -23
  39. package/src/auth-storage/magic-links.ts +1 -6
  40. package/src/auth-storage/oidc-attempts.ts +1 -6
  41. package/src/auth-storage/rows.ts +0 -6
  42. package/src/auth-storage/sessions.ts +1 -49
  43. package/src/auth-storage/shared.ts +3 -20
  44. package/src/index.ts +1 -10
  45. package/src/migrations/060-terminal-action-runs.sql +149 -0
  46. package/src/migrations/061-drop-auth-audience.sql +16 -0
  47. package/src/migrations.ts +24 -0
  48. package/src/objects/storage.ts +0 -5
  49. package/src/pipeline-run-storage.ts +0 -5
  50. package/src/projection-run-storage.ts +0 -5
  51. package/src/rules-storage.ts +0 -5
  52. package/src/share-grant-storage.ts +0 -2
  53. package/src/share-session-storage.ts +0 -2
  54. package/src/sync-run-storage.ts +0 -5
  55. package/src/timeseries-storage.ts +0 -5
  56. package/src/transactions.ts +8 -8
  57. package/src/webhook-run-storage.ts +0 -3
  58. package/src/workflow-intervention-storage.ts +0 -5
  59. package/src/workflow-run-storage.ts +0 -5
@@ -22,7 +22,6 @@ import type {
22
22
  QueryObjectsInput,
23
23
  QueryObjectsResult,
24
24
  } from "@sixb/core/storage"
25
- import { installFreshSqliteSchema } from "../migrations"
26
25
  import {
27
26
  closeSqliteStoreConnection,
28
27
  openSqliteStoreConnection,
@@ -124,10 +123,6 @@ export class SqliteObjectStorage implements ObjectStorage {
124
123
  this.connection = openSqliteStoreConnection(options)
125
124
  this.db = this.connection.db
126
125
  this.reader = new SqliteObjectReader(this.db, DEFAULT_OBJECT_QUERY_SOURCE)
127
-
128
- if (this.connection.installFreshSchema) {
129
- installFreshSqliteSchema(this.db)
130
- }
131
126
  }
132
127
 
133
128
  queryCapabilities(): ObjectQueryCapabilities {
@@ -22,7 +22,6 @@ import type {
22
22
  } from "@sixb/core/storage"
23
23
  import { PIPELINE_RUN_FAILURE_CODES, PipelineRunError } from "@sixb/core/storage"
24
24
  import { queryLatestRunsByOwnerId } from "./latest-run-query"
25
- import { installFreshSqliteSchema } from "./migrations"
26
25
  import {
27
26
  appendRunListFilters,
28
27
  hasEmptyStatuses,
@@ -54,10 +53,6 @@ export class SqlitePipelineRunStorage implements PipelineRunStorage {
54
53
  this.connection = openSqliteStoreConnection(options)
55
54
  this.db = this.connection.db
56
55
  this.executions = options.executions
57
-
58
- if (this.connection.installFreshSchema) {
59
- installFreshSqliteSchema(this.db)
60
- }
61
56
  }
62
57
 
63
58
  async queue(input: QueuePipelineRunInput): Promise<PipelineRunRecord> {
@@ -56,7 +56,6 @@ import type {
56
56
  } from "@sixb/core/storage"
57
57
  import { PROJECTION_RUN_FAILURE_CODES, ProjectionRunError } from "@sixb/core/storage"
58
58
  import { queryLatestRunsByOwnerId } from "./latest-run-query"
59
- import { installFreshSqliteSchema } from "./migrations"
60
59
  import {
61
60
  closeSqliteStoreConnection,
62
61
  openSqliteStoreConnection,
@@ -82,10 +81,6 @@ export class SqliteProjectionRunStorage implements ProjectionRunStorage {
82
81
  this.connection = openSqliteStoreConnection(options)
83
82
  this.db = this.connection.db
84
83
  this.executions = options.executions
85
-
86
- if (this.connection.installFreshSchema) {
87
- installFreshSqliteSchema(this.db)
88
- }
89
84
  }
90
85
 
91
86
  async queue(input: QueueProjectionRunInput): Promise<ProjectionRunRecord> {
@@ -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: {
@@ -16,7 +16,6 @@ import type {
16
16
  ShareGrantStorage,
17
17
  } from "@sixb/core/storage"
18
18
  import { ShareGrantStorageError } from "@sixb/core/storage"
19
- import { installFreshSqliteSchema } from "./migrations"
20
19
  import { isUniqueConstraintError } from "./storage-errors"
21
20
  import {
22
21
  closeSqliteStoreConnection,
@@ -37,7 +36,6 @@ export class SqliteShareGrantStorage implements ShareGrantStorage {
37
36
  constructor(options: SqliteShareGrantStorageOptions = {}) {
38
37
  this.connection = openSqliteStoreConnection(options)
39
38
  this.db = this.connection.db
40
- if (this.connection.installFreshSchema) installFreshSqliteSchema(this.db)
41
39
  }
42
40
 
43
41
  async create(input: CreateShareGrantInput): Promise<ShareGrantRecord> {
@@ -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> {
@@ -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: {
@@ -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
- const db = new SqliteDatabase(path, options.readonly ? { readonly: true } : undefined)
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
  }