@systemfsoftware/agent-storage-sqlite 0.0.0-stage → 0.1.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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/dist/SqliteActivityStore-CSvw-3OJ.mjs +25 -0
  3. package/dist/SqliteActivityStore-CSvw-3OJ.mjs.map +1 -0
  4. package/dist/SqliteActivityStore-DM-gMSMv.d.mts +15 -0
  5. package/dist/SqliteActivityStore.d.mts +2 -0
  6. package/dist/SqliteActivityStore.mjs +1 -0
  7. package/dist/SqliteMessageDeliveryStore-C0D-jYWc.mjs +18 -0
  8. package/dist/SqliteMessageDeliveryStore-C0D-jYWc.mjs.map +1 -0
  9. package/dist/SqliteMessageDeliveryStore-D1pwnufl.d.mts +11 -0
  10. package/dist/SqliteMessageDeliveryStore.d.mts +2 -0
  11. package/dist/SqliteMessageDeliveryStore.mjs +1 -0
  12. package/dist/SqliteScheduleStore-CrH-tLQB.d.mts +12 -0
  13. package/dist/SqliteScheduleStore-Nph_W_Lg.mjs +19 -0
  14. package/dist/SqliteScheduleStore-Nph_W_Lg.mjs.map +1 -0
  15. package/dist/SqliteScheduleStore.d.mts +2 -0
  16. package/dist/SqliteScheduleStore.mjs +1 -0
  17. package/dist/SqliteStorageConfig-6HRtBHf8.d.mts +27 -0
  18. package/dist/SqliteStorageConfig-DN-WwQrw.mjs +32 -0
  19. package/dist/SqliteStorageConfig-DN-WwQrw.mjs.map +1 -0
  20. package/dist/SqliteStorageConfig.d.mts +2 -0
  21. package/dist/SqliteStorageConfig.mjs +1 -0
  22. package/dist/SqliteStorageError-Bc-iVib1.d.mts +71 -0
  23. package/dist/SqliteStorageError-d_tygf_W.mjs +79 -0
  24. package/dist/SqliteStorageError-d_tygf_W.mjs.map +1 -0
  25. package/dist/SqliteStorageError.d.mts +2 -0
  26. package/dist/SqliteStorageError.mjs +1 -0
  27. package/dist/SqliteStorageFailpoint-BqxmxFBb.mjs +15 -0
  28. package/dist/SqliteStorageFailpoint-BqxmxFBb.mjs.map +1 -0
  29. package/dist/SqliteStorageFailpoint-CJRyxmsW.d.mts +17 -0
  30. package/dist/SqliteStorageFailpoint.d.mts +2 -0
  31. package/dist/SqliteStorageFailpoint.mjs +1 -0
  32. package/dist/SqliteStorageVersion-Bayz1P9w.d.mts +8 -0
  33. package/dist/SqliteStorageVersion-BxAVd_1t.mjs +7 -0
  34. package/dist/SqliteStorageVersion-BxAVd_1t.mjs.map +1 -0
  35. package/dist/SqliteStorageVersion.d.mts +3 -0
  36. package/dist/SqliteStorageVersion.mjs +2 -0
  37. package/dist/SqliteSubmissionLedger-2lHitXAA.d.mts +25 -0
  38. package/dist/SqliteSubmissionLedger-DTWaRPjV.mjs +46 -0
  39. package/dist/SqliteSubmissionLedger-DTWaRPjV.mjs.map +1 -0
  40. package/dist/SqliteSubmissionLedger.d.mts +2 -0
  41. package/dist/SqliteSubmissionLedger.mjs +1 -0
  42. package/dist/SqliteSubscriptionStore-CFmi_ULJ.mjs +21 -0
  43. package/dist/SqliteSubscriptionStore-CFmi_ULJ.mjs.map +1 -0
  44. package/dist/SqliteSubscriptionStore-CRkOEBaa.d.mts +11 -0
  45. package/dist/SqliteSubscriptionStore.d.mts +2 -0
  46. package/dist/SqliteSubscriptionStore.mjs +1 -0
  47. package/dist/SqliteThreadStore-CUkk9A0Y.mjs +235 -0
  48. package/dist/SqliteThreadStore-CUkk9A0Y.mjs.map +1 -0
  49. package/dist/SqliteThreadStore-DKac999S.d.mts +89 -0
  50. package/dist/SqliteThreadStore.d.mts +2 -0
  51. package/dist/SqliteThreadStore.mjs +1 -0
  52. package/dist/index.d.mts +11 -0
  53. package/dist/index.mjs +11 -0
  54. package/dist/migrations-_uIpJR5O.mjs +240 -0
  55. package/dist/migrations-_uIpJR5O.mjs.map +1 -0
  56. package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
  57. package/dist/sqlite-journal-3Zguf9OC.mjs +112 -0
  58. package/dist/sqlite-journal-3Zguf9OC.mjs.map +1 -0
  59. package/package.json +87 -3
  60. package/src/SqliteActivityStore.ts +35 -0
  61. package/src/SqliteMessageDeliveryStore.ts +23 -0
  62. package/src/SqliteScheduleStore.ts +38 -0
  63. package/src/SqliteStorageConfig.ts +31 -0
  64. package/src/SqliteStorageError.ts +96 -0
  65. package/src/SqliteStorageFailpoint.ts +22 -0
  66. package/src/SqliteStorageVersion.ts +2 -0
  67. package/src/SqliteSubmissionLedger.ts +80 -0
  68. package/src/SqliteSubscriptionStore.ts +31 -0
  69. package/src/SqliteThreadStore.ts +395 -0
  70. package/src/index.ts +10 -0
  71. package/src/internal/migrations.ts +396 -0
  72. package/src/internal/sqlite-client-layer.ts +19 -0
  73. package/src/internal/sqlite-journal.ts +205 -0
  74. package/src/internal/sqlite-ledger-errors.ts +25 -0
  75. package/README.md +0 -3
@@ -0,0 +1,21 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs";
2
+ import { makeSqlSubscriptionStore } from "@systemfsoftware/agent-storage-sql/sql-subscription-store";
3
+ import { SourcePartition, SubscriptionError, SubscriptionStore } from "@systemfsoftware/agent/subscription";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Schema from "effect/Schema";
7
+ import { i as initializeSqliteStorage } from "./sqlite-journal-3Zguf9OC.mjs";
8
+ // src/SqliteSubscriptionStore.ts
9
+ var SqliteSubscriptionStore_exports = /* @__PURE__ */ __exportAll({ subscriptionStoreLayer: () => subscriptionStoreLayer });
10
+ const makeSubscriptionStore = Effect.fnUntraced(function* (owned) {
11
+ const partition = yield* Schema.decodeEffect(SourcePartition)(owned).pipe(Effect.mapError(() => SubscriptionError.make({
12
+ reason: "validation",
13
+ code: "partition"
14
+ })));
15
+ yield* initializeSqliteStorage();
16
+ return yield* makeSqlSubscriptionStore(partition, { maxStoredJsonLength: 16777216 });
17
+ });
18
+ const subscriptionStoreLayer = (partition) => Layer.effect(SubscriptionStore, makeSubscriptionStore(partition));
19
+ export { subscriptionStoreLayer as n, SqliteSubscriptionStore_exports as t };
20
+
21
+ //# sourceMappingURL=SqliteSubscriptionStore-CFmi_ULJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteSubscriptionStore-CFmi_ULJ.mjs","names":[],"sources":["../src/SqliteSubscriptionStore.ts"],"sourcesContent":["import { makeSqlSubscriptionStore } from '@systemfsoftware/agent-storage-sql/sql-subscription-store'\nimport { SourcePartition, SubscriptionError, SubscriptionStore } from '@systemfsoftware/agent/subscription'\nimport * as Effect from 'effect/Effect'\nimport * as Layer from 'effect/Layer'\nimport * as Schema from 'effect/Schema'\nimport type * as SqlClientService from 'effect/sql/SqlClient'\n\nimport { initializeSqliteStorage } from './internal/sqlite-journal'\nimport type { SqliteStorageConfig } from './SqliteStorageConfig'\nimport type { SqliteStorageFailpoint } from './SqliteStorageFailpoint'\nimport type { SqliteStorageInitializationError } from './SqliteThreadStore'\n\nconst makeSubscriptionStore = Effect.fnUntraced(function*(owned: SourcePartition) {\n const partition = yield* Schema.decodeEffect(SourcePartition)(owned).pipe(\n Effect.mapError(() => SubscriptionError.make({ reason: 'validation', code: 'partition' })),\n )\n\n yield* initializeSqliteStorage()\n\n return yield* makeSqlSubscriptionStore(partition, {\n maxStoredJsonLength: 16 * 1024 * 1024,\n })\n})\n\nexport const subscriptionStoreLayer = (\n partition: SourcePartition,\n): Layer.Layer<\n SubscriptionStore,\n SqliteStorageInitializationError | SubscriptionError,\n SqliteStorageConfig | SqliteStorageFailpoint | SqlClientService.SqlClient\n> => Layer.effect(SubscriptionStore, makeSubscriptionStore(partition))\n"],"mappings":";;;;;;;;;AAYA,MAAM,wBAAwB,OAAO,WAAW,WAAU,OAAwB;CAChF,MAAM,YAAY,OAAO,OAAO,aAAa,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,KACnE,OAAO,eAAe,kBAAkB,KAAK;EAAE,QAAQ;EAAc,MAAM;CAAY,CAAC,CAAC,CAC3F;CAEA,OAAO,wBAAwB;CAE/B,OAAO,OAAO,yBAAyB,WAAW,EAChD,qBAAqB,SACvB,CAAC;AACH,CAAC;AAED,MAAa,0BACX,cAKG,MAAM,OAAO,mBAAmB,sBAAsB,SAAS,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { SourcePartition, SubscriptionError, SubscriptionStore } from "@systemfsoftware/agent/subscription";
2
+ import * as Layer from "effect/Layer";
3
+ import * as SqlClientService from "effect/sql/SqlClient";
4
+ import { t as SqliteStorageConfig } from "./SqliteStorageConfig-6HRtBHf8.mjs";
5
+ import { t as SqliteStorageFailpoint } from "./SqliteStorageFailpoint-CJRyxmsW.mjs";
6
+ import { t as SqliteStorageInitializationError } from "./SqliteThreadStore-DKac999S.mjs";
7
+ declare namespace SqliteSubscriptionStore_d_exports {
8
+ export { subscriptionStoreLayer };
9
+ }
10
+ declare const subscriptionStoreLayer: (partition: SourcePartition) => Layer.Layer<SubscriptionStore, SqliteStorageInitializationError | SubscriptionError, SqliteStorageConfig | SqliteStorageFailpoint | SqlClientService.SqlClient>;
11
+ export { subscriptionStoreLayer as n, SqliteSubscriptionStore_d_exports as t };
@@ -0,0 +1,2 @@
1
+ import { n as subscriptionStoreLayer } from "./SqliteSubscriptionStore-CRkOEBaa.mjs";
2
+ export { subscriptionStoreLayer };
@@ -0,0 +1 @@
1
+ export { n as subscriptionStoreLayer } from "./SqliteSubscriptionStore-CFmi_ULJ.mjs";
@@ -0,0 +1,235 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs";
2
+ import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
3
+ import { sqlStorageOwner } from "@systemfsoftware/agent-storage-sql/sql-journal";
4
+ import { makeSqlRunStorage } from "@systemfsoftware/agent-storage-sql/sql-run-storage";
5
+ import { SqlInteger, makeSqlTransaction } from "@systemfsoftware/agent-storage-sql/sql-storage";
6
+ import { makeSqlThreadImport } from "@systemfsoftware/agent-storage-sql/sql-thread-import";
7
+ import { makeSqlThreadStoreKernel } from "@systemfsoftware/agent-storage-sql/sql-thread-store";
8
+ import { RunStorage, StorageOwner } from "@systemfsoftware/agent/run-storage";
9
+ import { SettlementPublisher } from "@systemfsoftware/agent/settlement-publisher";
10
+ import { LedgerError, SubmissionLedger } from "@systemfsoftware/agent/submission-ledger";
11
+ import { ThreadImport } from "@systemfsoftware/agent/thread-import";
12
+ import { ThreadExportSource, ThreadReader, ThreadStore, ThreadStoreError } from "@systemfsoftware/agent/thread-store";
13
+ import { checkExportSource } from "@systemfsoftware/agent/thread-transfer";
14
+ import * as Context from "effect/Context";
15
+ import * as CryptoDigest from "effect/crypto/Digest";
16
+ import * as SecureRandom from "effect/crypto/SecureRandom";
17
+ import * as Effect from "effect/Effect";
18
+ import * as Layer from "effect/Layer";
19
+ import * as Schema from "effect/Schema";
20
+ import * as Scope from "effect/Scope";
21
+ import * as SqlClientService from "effect/sql/SqlClient";
22
+ import * as Statement from "effect/sql/Statement";
23
+ import { i as readSqliteStorageHeader, r as inspectManagedSqliteStorage } from "./migrations-_uIpJR5O.mjs";
24
+ import * as SqliteClient from "@effect/sql-sqlite-node/SqliteClient";
25
+ import { i as SqliteStorageCompatibilityError, o as SqliteStorageError, r as SqliteLedgerError, u as SqliteWriteContention } from "./SqliteStorageError-d_tygf_W.mjs";
26
+ import { a as sqliteErrors, n as initializeSqliteJournal, r as initializeSqliteJournalKernel, t as configureSqliteSynchronous } from "./sqlite-journal-3Zguf9OC.mjs";
27
+ import { n as SqliteStorageConfigValue, t as SqliteStorageConfig } from "./SqliteStorageConfig-DN-WwQrw.mjs";
28
+ import { t as SqliteStorageFailpoint } from "./SqliteStorageFailpoint-BqxmxFBb.mjs";
29
+ // src/internal/sqlite-client-layer.ts
30
+ const sqliteClientLayer = (options, operation) => SqliteClient.layer(options).pipe(Layer.catch((cause) => Layer.effectContext(Effect.fail(SqliteStorageError.make({
31
+ operation,
32
+ message: cause.message,
33
+ cause
34
+ })))));
35
+ // src/internal/sqlite-ledger-errors.ts
36
+ /** Wrap an adapter-internal failure into the port's LedgerError without erasing its tag. */
37
+ const internalFailure = (operation) => (error) => LedgerError.make({
38
+ operation,
39
+ message: error.message,
40
+ cause: error
41
+ });
42
+ /** Classify raw SQL failures: write-lock timeouts stay retryable typed contention. */
43
+ const sqlFailure = (operation) => (error) => {
44
+ const internal = error.reason._tag === "LockTimeoutError" ? SqliteWriteContention.make({
45
+ cause: error,
46
+ operation,
47
+ message: `Another producer holds the SQLite write lock; ${operation} is safe to retry.`
48
+ }) : SqliteLedgerError.make({
49
+ cause: error,
50
+ operation,
51
+ message: error.message
52
+ });
53
+ return internalFailure(operation)(internal);
54
+ };
55
+ // src/SqliteThreadStore.ts
56
+ var SqliteThreadStore_exports = /* @__PURE__ */ __exportAll({
57
+ exclusiveHostClientLayer: () => exclusiveHostClientLayer,
58
+ exclusiveRunStorageLayer: () => exclusiveRunStorageLayer,
59
+ exportSourceLayer: () => exportSourceLayer,
60
+ exportThread: () => exportThread,
61
+ layer: () => layer,
62
+ storageConfigLayer: () => storageConfigLayer,
63
+ storageFailpointLayer: () => storageFailpointLayer,
64
+ threadStoreLayer: () => threadStoreLayer
65
+ });
66
+ /** Only the exclusive client acquisition can construct managed mutation authority. */
67
+ var ExclusiveSqliteHost = class extends Context.Service()("@effect-agent/storage-sqlite/internal/ExclusiveSqliteHost") {};
68
+ const ExclusiveMode = Schema.Tuple([Schema.Struct({ locking_mode: Schema.Literal("exclusive") })]);
69
+ const JournalMode = Schema.Tuple([Schema.Struct({ journal_mode: Schema.String })]);
70
+ const DatabaseHeader = Schema.Tuple([Schema.Struct({
71
+ user_version: SqlInteger,
72
+ schema_object_count: SqlInteger
73
+ })]);
74
+ /**
75
+ * Acquire process-lifetime authority over a dedicated SQLite client before exposing it to a
76
+ * managed host. Open the client with `disableWAL: true`: WAL setup and lock contention must
77
+ * fail through this Layer's typed initialization error. The client Scope owns the lock;
78
+ * never change its locking mode or close it while host work is alive.
79
+ *
80
+ * This excludes ALL other database connections, including readers. After compatibility checks,
81
+ * initialize fresh storage or atomically upgrade supported predecessor layouts, then recover from durable facts. Scope closure
82
+ * retires local capabilities; no ownership is restored from the database. Only the exact
83
+ * declared triggers on Thread storage tables are permitted before any initialization;
84
+ * application and optional memory tables retain their own schema contracts.
85
+ */
86
+ const exclusiveHostClientLayer = Layer.effectContext(Effect.gen(function* () {
87
+ const sql = (yield* SqlClientService.SqlClient).withoutTransforms();
88
+ const acquireError = (cause) => SqliteStorageError.make({
89
+ operation: "acquire exclusive host",
90
+ message: "Cannot acquire exclusive SQLite host authority; close other database connections.",
91
+ cause
92
+ });
93
+ yield* Effect.gen(function* () {
94
+ yield* sql`PRAGMA busy_timeout = 0`;
95
+ const mode = yield* sql`PRAGMA main.locking_mode = EXCLUSIVE`;
96
+ yield* Schema.decodeUnknownEffect(ExclusiveMode)(mode);
97
+ const [journal] = yield* Schema.decodeUnknownEffect(JournalMode)(yield* sql`PRAGMA journal_mode`);
98
+ if (journal.journal_mode !== "wal") {
99
+ const [header] = yield* Schema.decodeUnknownEffect(DatabaseHeader)(yield* sql`
100
+ SELECT (SELECT user_version FROM pragma_user_version) AS user_version,
101
+ (SELECT COUNT(*) FROM sqlite_master) AS schema_object_count
102
+ `);
103
+ if (header.user_version !== 0 || header.schema_object_count !== 0) return yield* SqliteStorageCompatibilityError.make({
104
+ actualVersion: header.user_version,
105
+ supportedVersion: 31,
106
+ message: "An existing managed-host database must use SQLite WAL mode; no data was changed."
107
+ });
108
+ yield* sql`PRAGMA journal_mode = WAL`;
109
+ }
110
+ yield* configureSqliteSynchronous();
111
+ yield* makeSqlTransaction(sql, { begin: "BEGIN IMMEDIATE" })(Effect.void);
112
+ yield* inspectManagedSqliteStorage();
113
+ }).pipe(Effect.mapError((error) => Schema.is(SqliteStorageCompatibilityError)(error) ? error : acquireError(error)));
114
+ yield* initializeSqliteJournal.pipe(Effect.provideService(SqlClientService.SqlClient, sql));
115
+ return Context.make(SqlClientService.SqlClient, sql).pipe(Context.add(ExclusiveSqliteHost, { sql }));
116
+ }));
117
+ const makeServices = Effect.fnUntraced(function* () {
118
+ const config = yield* SqliteStorageConfig;
119
+ const failpoint = yield* SqliteStorageFailpoint;
120
+ const journal = yield* initializeSqliteJournal;
121
+ return {
122
+ ...yield* makeSqlThreadStoreKernel(journal, {
123
+ ...config,
124
+ errors: sqliteErrors,
125
+ hitFailpoint: failpoint.hit,
126
+ offsetPrefix: "effect-agent-sqlite@1:"
127
+ }),
128
+ owner: journal.owner
129
+ };
130
+ });
131
+ /**
132
+ * SQLite Thread Store implementation with configuration, failpoint, SQL, and Digest
133
+ * authority kept visible in its input channel.
134
+ * Inject a client opened with `disableWAL: true`; this adapter enables WAL only for a
135
+ * fresh file so unsupported files reject before persistent driver configuration changes.
136
+ */
137
+ const threadStoreLayer = Layer.effect(ThreadReader, Effect.map(ThreadStore, (store) => ThreadReader.fromStore(store))).pipe(Layer.provideMerge(Layer.effectContext(Effect.map(makeServices(), ({ store, importer, owner }) => Context.make(ThreadStore, store).pipe(Context.add(ThreadImport, importer), Context.add(StorageOwner, owner))))), Layer.provide(exclusiveHostClientLayer));
138
+ /**
139
+ * Managed-host storage for an already acquired exclusiveHostClientLayer. The composition
140
+ * root consumes the mutation ports privately and exposes only ThreadReader to application
141
+ * bindings. Its private construction witness binds the exact exclusive client; supplying a
142
+ * generic SqlClient cannot bypass the required exclusive acquisition.
143
+ */
144
+ const exclusiveRunStorageLayer = Layer.effectContext(Effect.gen(function* () {
145
+ const exclusive = yield* ExclusiveSqliteHost;
146
+ const live = yield* Effect.context();
147
+ const context = Context.add(Context.pick(CryptoDigest.Digest, SecureRandom.SecureRandom, SqliteStorageConfig, SqliteStorageFailpoint, Scope.Scope)(live), SqlClientService.SqlClient, exclusive.sql);
148
+ return yield* Effect.setContext(Effect.gen(function* () {
149
+ const config = yield* SqliteStorageConfig;
150
+ const failpoint = yield* SqliteStorageFailpoint;
151
+ const journal = yield* initializeSqliteJournalKernel();
152
+ const services = yield* makeSqlRunStorage(journal, {
153
+ ...config,
154
+ errors: sqliteErrors,
155
+ hitFailpoint: failpoint.hit,
156
+ offsetPrefix: "effect-agent-sqlite@1:"
157
+ }, {
158
+ errors: sqliteErrors,
159
+ hitFailpoint: failpoint.hit,
160
+ offsetPrefix: "effect-agent-sqlite@1:",
161
+ sqlFailure
162
+ });
163
+ return Context.make(ThreadStore, services.store).pipe(Context.add(ThreadReader, services.reader), Context.add(ThreadImport, services.importer), Context.add(SubmissionLedger, services.ledger), Context.add(SettlementPublisher, services.publisher), Context.add(RunStorage, services.runStorage), Context.add(StorageOwner, services.owner));
164
+ }), Context.merge(Context.omit(Statement.CurrentTransformer, exclusive.sql.transactionService)(live), context));
165
+ }));
166
+ /**
167
+ * Validated SQLite storage configuration Layer with the documented defaults applied. Shared
168
+ * by the ThreadStore and SubmissionLedger convenience layers so their defaults cannot
169
+ * drift.
170
+ */
171
+ const storageConfigLayer = (options) => Layer.effect(SqliteStorageConfig)(Schema.decodeEffect(SqliteStorageConfigValue)({
172
+ observationPollInterval: options.observationPollInterval ?? 25,
173
+ busyTimeout: options.busyTimeout ?? 5e3,
174
+ synchronous: options.synchronous ?? "FULL",
175
+ verifyOnOpen: options.verifyOnOpen ?? false
176
+ }).pipe(Effect.mapError((error) => SqliteStorageError.make({
177
+ cause: error,
178
+ operation: "configure SQLite storage",
179
+ message: error.message
180
+ }))));
181
+ /** The failpoint Layer selected by convenience options: explicit handler or the no-op default. */
182
+ const storageFailpointLayer = (options) => options.failpoint === void 0 ? SqliteStorageFailpoint.layer : Layer.succeed(SqliteStorageFailpoint)({ hit: options.failpoint });
183
+ /**
184
+ * A composition-root convenience Layer for canonical Threads. Durable accepted work is
185
+ * served by the separate SubmissionLedger port.
186
+ */
187
+ const layer = (options) => Layer.unwrap(Effect.map(SqliteStorageConfig, (config) => threadStoreLayer.pipe(Layer.provide(Layer.mergeAll(Layer.succeed(SqliteStorageConfig)(config), storageFailpointLayer(options), sqliteClientLayer({
188
+ filename: options.filename,
189
+ disableWAL: true
190
+ }, "open SQLite"), NodeCrypto.layer))))).pipe(Layer.provide(storageConfigLayer(options)));
191
+ /**
192
+ * Export a quiesced current-layout database without initializing layout or retiring
193
+ * ownership. Its read-only connection closes before returning; the source remains untouched.
194
+ */
195
+ const exportThread = Effect.fn("SqliteThreadStore.exportThread")(function* (options, request) {
196
+ yield* checkExportSource(request.threadId);
197
+ return yield* Effect.gen(function* () {
198
+ const sql = yield* SqlClientService.SqlClient;
199
+ const owner = yield* sqlStorageOwner(sql);
200
+ return yield* owner.withMutation(makeSqlTransaction(sql, { begin: "BEGIN" })(Effect.gen(function* () {
201
+ yield* readSqliteStorageHeader();
202
+ return yield* (yield* makeSqlThreadImport({
203
+ owner,
204
+ offsetPrefix: "effect-agent-sqlite@1:",
205
+ read: (body) => body,
206
+ write: () => Effect.die("A read-only exporter cannot import")
207
+ })).export(request);
208
+ })).pipe(Effect.catchTag("SqlError", (cause) => SqliteStorageError.make({
209
+ operation: "export Thread snapshot",
210
+ message: cause.message,
211
+ cause
212
+ }))));
213
+ }).pipe(Effect.scoped, Effect.provide(Layer.merge(sqliteClientLayer({
214
+ filename: options.filename,
215
+ readonly: true,
216
+ disableWAL: true,
217
+ busyTimeout: options.busyTimeout ?? 5e3
218
+ }, "open SQLite for export"), NodeCrypto.layer)));
219
+ });
220
+ /** Read-only page exports retain native diagnostics in the transfer port's typed storage failure. */
221
+ const exportSourceLayer = (options) => {
222
+ const failure = (cause) => ThreadStoreError.make({
223
+ operation: "export Thread snapshot",
224
+ message: cause.message,
225
+ cause
226
+ });
227
+ return Layer.succeed(ThreadExportSource, { export: (request) => exportThread(options, request).pipe(Effect.catchTags({
228
+ SqliteStorageCompatibilityError: failure,
229
+ SqliteStorageCorruptionError: failure,
230
+ SqliteStorageError: failure
231
+ })) });
232
+ };
233
+ export { exportThread as a, storageFailpointLayer as c, sqliteClientLayer as d, exportSourceLayer as i, threadStoreLayer as l, exclusiveHostClientLayer as n, layer as o, exclusiveRunStorageLayer as r, storageConfigLayer as s, SqliteThreadStore_exports as t, sqlFailure as u };
234
+
235
+ //# sourceMappingURL=SqliteThreadStore-CUkk9A0Y.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteThreadStore-CUkk9A0Y.mjs","names":[],"sources":["../src/internal/sqlite-client-layer.ts","../src/internal/sqlite-ledger-errors.ts","../src/SqliteThreadStore.ts"],"sourcesContent":["import * as SqliteClient from '@effect/sql-sqlite-node/SqliteClient'\nimport * as Effect from 'effect/Effect'\nimport * as Layer from 'effect/Layer'\n\nimport { SqliteStorageError } from '../SqliteStorageError'\n\nexport const sqliteClientLayer = (\n options: Parameters<typeof SqliteClient.layer>[0],\n operation: string,\n) =>\n SqliteClient.layer(options).pipe(\n Layer.catch((cause) =>\n Layer.effectContext<\n Layer.Success<ReturnType<typeof SqliteClient.layer>>,\n SqliteStorageError,\n never\n >(Effect.fail(SqliteStorageError.make({ operation, message: cause.message, cause })))\n ),\n )\n","import { LedgerError } from '@systemfsoftware/agent/submission-ledger'\nimport type * as SqlError from 'effect/sql/SqlError'\n\nimport { SqliteLedgerError, SqliteWriteContention } from '../SqliteStorageError'\n\n/** Wrap an adapter-internal failure into the port's LedgerError without erasing its tag. */\nconst internalFailure = (operation: string) => (error: { readonly message: string }): LedgerError =>\n LedgerError.make({ operation, message: error.message, cause: error })\n\n/** Classify raw SQL failures: write-lock timeouts stay retryable typed contention. */\nexport const sqlFailure = (operation: string) => (error: SqlError.SqlError): LedgerError => {\n const internal = error.reason._tag === 'LockTimeoutError'\n ? SqliteWriteContention.make({\n cause: error,\n operation,\n message: `Another producer holds the SQLite write lock; ${operation} is safe to retry.`,\n })\n : SqliteLedgerError.make({\n cause: error,\n operation,\n message: error.message,\n })\n\n return internalFailure(operation)(internal)\n}\n","import * as NodeCrypto from '@effect/platform-node/NodeCrypto'\nimport { sqlStorageOwner } from '@systemfsoftware/agent-storage-sql/sql-journal'\nimport { makeSqlRunStorage } from '@systemfsoftware/agent-storage-sql/sql-run-storage'\nimport { makeSqlTransaction, SqlInteger } from '@systemfsoftware/agent-storage-sql/sql-storage'\nimport { makeSqlThreadImport } from '@systemfsoftware/agent-storage-sql/sql-thread-import'\nimport { makeSqlThreadStoreKernel } from '@systemfsoftware/agent-storage-sql/sql-thread-store'\nimport { RunStorage, StorageOwner } from '@systemfsoftware/agent/run-storage'\nimport { SettlementPublisher } from '@systemfsoftware/agent/settlement-publisher'\nimport { SubmissionLedger } from '@systemfsoftware/agent/submission-ledger'\nimport { ThreadImport } from '@systemfsoftware/agent/thread-import'\nimport type { ThreadExportRequest } from '@systemfsoftware/agent/thread-store'\nimport { ThreadExportSource, ThreadReader, ThreadStore, ThreadStoreError } from '@systemfsoftware/agent/thread-store'\nimport { checkExportSource } from '@systemfsoftware/agent/thread-transfer'\nimport * as Context from 'effect/Context'\nimport * as CryptoDigest from 'effect/crypto/Digest'\nimport * as SecureRandom from 'effect/crypto/SecureRandom'\nimport * as Effect from 'effect/Effect'\nimport * as Layer from 'effect/Layer'\nimport * as Schema from 'effect/Schema'\nimport * as Scope from 'effect/Scope'\nimport * as SqlClientService from 'effect/sql/SqlClient'\nimport * as Statement from 'effect/sql/Statement'\n\nimport {\n CurrentSqliteStorageVersion,\n inspectManagedSqliteStorage,\n readSqliteStorageHeader,\n} from './internal/migrations'\nimport { sqliteClientLayer } from './internal/sqlite-client-layer'\nimport {\n configureSqliteSynchronous,\n initializeSqliteJournal,\n initializeSqliteJournalKernel,\n sqliteErrors,\n} from './internal/sqlite-journal'\nimport { sqlFailure } from './internal/sqlite-ledger-errors'\nimport { SqliteStorageConfig, SqliteStorageConfigValue } from './SqliteStorageConfig'\nimport type { SqliteStorageCorruptionError } from './SqliteStorageError'\nimport { SqliteStorageCompatibilityError, SqliteStorageError } from './SqliteStorageError'\nimport { SqliteStorageFailpoint, type SqliteStorageFailpointHandler } from './SqliteStorageFailpoint'\n\nexport interface SqliteStorageOptions {\n readonly filename: string\n readonly observationPollInterval?: number | undefined\n /** Bounded SQLITE_BUSY retry window for write-lock acquisition, in milliseconds. */\n readonly busyTimeout?: number | undefined\n /**\n * SQLite WAL synchronization for this store's connection. Defaults to FULL. NORMAL can lose\n * acknowledged commits after power loss or an OS crash, potentially repeating external effects.\n * All stores sharing a client must select the same mode when constructed.\n */\n readonly synchronous?: 'FULL' | 'NORMAL' | undefined\n /**\n * Audit stored payloads, identities, and batch coverage on open. Defaults to false. Full reads validate\n * canonical records; readPrompt trusts write-time validation of the omitted fields.\n */\n readonly verifyOnOpen?: boolean | undefined\n readonly failpoint?: SqliteStorageFailpointHandler | undefined\n}\n\nexport type SqliteStorageInitializationError =\n | SqliteStorageCompatibilityError\n | SqliteStorageCorruptionError\n | SqliteStorageError\n\n/** Only the exclusive client acquisition can construct managed mutation authority. */\nclass ExclusiveSqliteHost extends Context.Service<\n ExclusiveSqliteHost,\n { readonly sql: SqlClientService.SqlClient }\n>()('@effect-agent/storage-sqlite/internal/ExclusiveSqliteHost') {}\n\nconst ExclusiveMode = Schema.Tuple([Schema.Struct({ locking_mode: Schema.Literal('exclusive') })])\nconst JournalMode = Schema.Tuple([Schema.Struct({ journal_mode: Schema.String })])\n\nconst DatabaseHeader = Schema.Tuple([\n Schema.Struct({ user_version: SqlInteger, schema_object_count: SqlInteger }),\n])\n\n/**\n * Acquire process-lifetime authority over a dedicated SQLite client before exposing it to a\n * managed host. Open the client with `disableWAL: true`: WAL setup and lock contention must\n * fail through this Layer's typed initialization error. The client Scope owns the lock;\n * never change its locking mode or close it while host work is alive.\n *\n * This excludes ALL other database connections, including readers. After compatibility checks,\n * initialize fresh storage or atomically upgrade supported predecessor layouts, then recover from durable facts. Scope closure\n * retires local capabilities; no ownership is restored from the database. Only the exact\n * declared triggers on Thread storage tables are permitted before any initialization;\n * application and optional memory tables retain their own schema contracts.\n */\nexport const exclusiveHostClientLayer: Layer.Layer<\n SqlClientService.SqlClient | ExclusiveSqliteHost,\n SqliteStorageInitializationError,\n SqliteStorageConfig | SqliteStorageFailpoint | SqlClientService.SqlClient | CryptoDigest.Digest\n> = Layer.effectContext(\n Effect.gen(function*() {\n const sql = (yield* SqlClientService.SqlClient).withoutTransforms()\n\n const acquireError = (cause: unknown) =>\n SqliteStorageError.make({\n operation: 'acquire exclusive host',\n message: 'Cannot acquire exclusive SQLite host authority; close other database connections.',\n cause,\n })\n\n yield* Effect.gen(function*() {\n yield* sql`PRAGMA busy_timeout = 0`\n const mode = yield* sql`PRAGMA main.locking_mode = EXCLUSIVE`\n\n yield* Schema.decodeUnknownEffect(ExclusiveMode)(mode)\n\n const [journal] = yield* Schema.decodeUnknownEffect(JournalMode)(\n yield* sql`PRAGMA journal_mode`,\n )\n\n if (journal.journal_mode !== 'wal') {\n const [header] = yield* Schema.decodeUnknownEffect(DatabaseHeader)(\n yield* sql`\n SELECT (SELECT user_version FROM pragma_user_version) AS user_version,\n (SELECT COUNT(*) FROM sqlite_master) AS schema_object_count\n `,\n )\n\n // Only a version-zero file with no schema objects may change journal mode. Existing\n // stores must already satisfy the adapter's WAL contract, including predecessors.\n if (header.user_version !== 0 || header.schema_object_count !== 0) {\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: header.user_version,\n supportedVersion: CurrentSqliteStorageVersion,\n message: 'An existing managed-host database must use SQLite WAL mode; no data was changed.',\n })\n }\n yield* sql`PRAGMA journal_mode = WAL`\n }\n yield* configureSqliteSynchronous()\n // A mode setting alone is not authority. Acquire the write lock now; EXCLUSIVE mode\n // retains it after commit/rollback until this client's enclosing Scope closes.\n yield* makeSqlTransaction(sql, { begin: 'BEGIN IMMEDIATE' })(Effect.void)\n\n yield* inspectManagedSqliteStorage()\n }).pipe(\n Effect.mapError((error) => Schema.is(SqliteStorageCompatibilityError)(error) ? error : acquireError(error)),\n )\n\n yield* initializeSqliteJournal.pipe(Effect.provideService(SqlClientService.SqlClient, sql))\n\n return Context.make(SqlClientService.SqlClient, sql).pipe(\n Context.add(ExclusiveSqliteHost, { sql }),\n )\n }),\n)\n\nconst makeServices = Effect.fnUntraced(function*() {\n const config = yield* SqliteStorageConfig\n const failpoint = yield* SqliteStorageFailpoint\n const journal = yield* initializeSqliteJournal\n\n const services = yield* makeSqlThreadStoreKernel(journal, {\n ...config,\n errors: sqliteErrors,\n hitFailpoint: failpoint.hit,\n offsetPrefix: 'effect-agent-sqlite@1:',\n })\n\n return { ...services, owner: journal.owner }\n})\n\n/**\n * SQLite Thread Store implementation with configuration, failpoint, SQL, and Digest\n * authority kept visible in its input channel.\n * Inject a client opened with `disableWAL: true`; this adapter enables WAL only for a\n * fresh file so unsupported files reject before persistent driver configuration changes.\n */\nexport const threadStoreLayer: Layer.Layer<\n ThreadStore | ThreadReader | ThreadImport | StorageOwner,\n SqliteStorageInitializationError,\n SqliteStorageConfig | SqliteStorageFailpoint | SqlClientService.SqlClient | CryptoDigest.Digest\n> = Layer.effect(\n ThreadReader,\n Effect.map(ThreadStore, (store) => ThreadReader.fromStore(store)),\n).pipe(\n Layer.provideMerge(\n Layer.effectContext(\n Effect.map(makeServices(), ({ store, importer, owner }) =>\n Context.make(ThreadStore, store).pipe(\n Context.add(ThreadImport, importer),\n Context.add(StorageOwner, owner),\n )),\n ),\n ),\n Layer.provide(exclusiveHostClientLayer),\n)\n\n/**\n * Managed-host storage for an already acquired exclusiveHostClientLayer. The composition\n * root consumes the mutation ports privately and exposes only ThreadReader to application\n * bindings. Its private construction witness binds the exact exclusive client; supplying a\n * generic SqlClient cannot bypass the required exclusive acquisition.\n */\nexport const exclusiveRunStorageLayer = Layer.effectContext(\n Effect.gen(function*() {\n const exclusive = yield* ExclusiveSqliteHost\n\n const live = yield* Effect.context<\n | CryptoDigest.Digest\n | SecureRandom.SecureRandom\n | SqliteStorageConfig\n | SqliteStorageFailpoint\n | Scope.Scope\n >()\n\n const context = Context.add(\n Context.pick(\n CryptoDigest.Digest,\n SecureRandom.SecureRandom,\n SqliteStorageConfig,\n SqliteStorageFailpoint,\n Scope.Scope,\n )(live),\n SqlClientService.SqlClient,\n exclusive.sql,\n )\n\n return yield* Effect.setContext(\n Effect.gen(function*() {\n const config = yield* SqliteStorageConfig\n const failpoint = yield* SqliteStorageFailpoint\n const journal = yield* initializeSqliteJournalKernel()\n\n const services = yield* makeSqlRunStorage(\n journal,\n {\n ...config,\n errors: sqliteErrors,\n hitFailpoint: failpoint.hit,\n offsetPrefix: 'effect-agent-sqlite@1:',\n },\n {\n errors: sqliteErrors,\n hitFailpoint: failpoint.hit,\n offsetPrefix: 'effect-agent-sqlite@1:',\n sqlFailure,\n },\n )\n\n return Context.make(ThreadStore, services.store).pipe(\n Context.add(ThreadReader, services.reader),\n Context.add(ThreadImport, services.importer),\n Context.add(SubmissionLedger, services.ledger),\n Context.add(SettlementPublisher, services.publisher),\n Context.add(RunStorage, services.runStorage),\n Context.add(StorageOwner, services.owner),\n )\n }),\n Context.merge(\n Context.omit(Statement.CurrentTransformer, exclusive.sql.transactionService)(live),\n context,\n ),\n )\n }),\n)\n\n/**\n * Validated SQLite storage configuration Layer with the documented defaults applied. Shared\n * by the ThreadStore and SubmissionLedger convenience layers so their defaults cannot\n * drift.\n */\nexport const storageConfigLayer = (\n options: SqliteStorageOptions,\n): Layer.Layer<SqliteStorageConfig, SqliteStorageError> =>\n Layer.effect(SqliteStorageConfig)(\n Schema.decodeEffect(SqliteStorageConfigValue)({\n observationPollInterval: options.observationPollInterval ?? 25,\n busyTimeout: options.busyTimeout ?? 5_000,\n synchronous: options.synchronous ?? 'FULL',\n verifyOnOpen: options.verifyOnOpen ?? false,\n }).pipe(\n Effect.mapError((error) =>\n SqliteStorageError.make({\n cause: error,\n operation: 'configure SQLite storage',\n message: error.message,\n })\n ),\n ),\n )\n\n/** The failpoint Layer selected by convenience options: explicit handler or the no-op default. */\nexport const storageFailpointLayer = (\n options: SqliteStorageOptions,\n): Layer.Layer<SqliteStorageFailpoint> =>\n options.failpoint === undefined\n ? SqliteStorageFailpoint.layer\n : Layer.succeed(SqliteStorageFailpoint)({ hit: options.failpoint })\n\n/**\n * A composition-root convenience Layer for canonical Threads. Durable accepted work is\n * served by the separate SubmissionLedger port.\n */\nexport const layer = (\n options: SqliteStorageOptions,\n): Layer.Layer<\n ThreadStore | ThreadReader | ThreadImport | StorageOwner,\n SqliteStorageInitializationError\n> =>\n Layer.unwrap(\n Effect.map(SqliteStorageConfig, (config) =>\n threadStoreLayer.pipe(\n Layer.provide(\n Layer.mergeAll(\n Layer.succeed(SqliteStorageConfig)(config),\n storageFailpointLayer(options),\n // The journal enables WAL only after proving the file is fresh.\n sqliteClientLayer({ filename: options.filename, disableWAL: true }, 'open SQLite'),\n NodeCrypto.layer,\n ),\n ),\n )),\n ).pipe(Layer.provide(storageConfigLayer(options)))\n\n/**\n * Export a quiesced current-layout database without initializing layout or retiring\n * ownership. Its read-only connection closes before returning; the source remains untouched.\n */\nexport const exportThread = Effect.fn('SqliteThreadStore.exportThread')(function*(\n options: Pick<SqliteStorageOptions, 'filename' | 'busyTimeout'>,\n request: ThreadExportRequest,\n) {\n yield* checkExportSource(request.threadId)\n\n return yield* Effect.gen(function*() {\n const sql = yield* SqlClientService.SqlClient\n\n const owner = yield* sqlStorageOwner(sql)\n\n return yield* owner.withMutation(\n makeSqlTransaction(sql, { begin: 'BEGIN' })(\n Effect.gen(function*() {\n yield* readSqliteStorageHeader()\n\n const transfer = yield* makeSqlThreadImport({\n owner,\n offsetPrefix: 'effect-agent-sqlite@1:',\n read: (body) => body,\n write: () => Effect.die('A read-only exporter cannot import'),\n })\n\n return yield* transfer.export(request)\n }),\n ).pipe(\n Effect.catchTag('SqlError', (cause) =>\n SqliteStorageError.make({\n operation: 'export Thread snapshot',\n message: cause.message,\n cause,\n })),\n ),\n )\n }).pipe(\n Effect.scoped,\n Effect.provide(\n Layer.merge(\n sqliteClientLayer(\n {\n filename: options.filename,\n readonly: true,\n disableWAL: true,\n busyTimeout: options.busyTimeout ?? 5_000,\n },\n 'open SQLite for export',\n ),\n NodeCrypto.layer,\n ),\n ),\n )\n})\n\n/** Read-only page exports retain native diagnostics in the transfer port's typed storage failure. */\nexport const exportSourceLayer = (\n options: Pick<SqliteStorageOptions, 'filename' | 'busyTimeout'>,\n): Layer.Layer<ThreadExportSource> => {\n const failure = (cause: SqliteStorageInitializationError) =>\n ThreadStoreError.make({ operation: 'export Thread snapshot', message: cause.message, cause })\n\n return Layer.succeed(ThreadExportSource, {\n export: (request) =>\n exportThread(options, request).pipe(\n Effect.catchTags({\n SqliteStorageCompatibilityError: failure,\n SqliteStorageCorruptionError: failure,\n SqliteStorageError: failure,\n }),\n ),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAa,qBACX,SACA,cAEA,aAAa,MAAM,OAAO,CAAC,CAAC,KAC1B,MAAM,OAAO,UACX,MAAM,cAIJ,OAAO,KAAK,mBAAmB,KAAK;CAAE;CAAW,SAAS,MAAM;CAAS;AAAM,CAAC,CAAC,CAAC,CACtF,CACF;;;ACZF,MAAM,mBAAmB,eAAuB,UAC9C,YAAY,KAAK;CAAE;CAAW,SAAS,MAAM;CAAS,OAAO;AAAM,CAAC;;AAGtE,MAAa,cAAc,eAAuB,UAA0C;CAC1F,MAAM,WAAW,MAAM,OAAO,SAAS,qBACnC,sBAAsB,KAAK;EAC3B,OAAO;EACP;EACA,SAAS,iDAAiD,UAAU;CACtE,CAAC,IACC,kBAAkB,KAAK;EACvB,OAAO;EACP;EACA,SAAS,MAAM;CACjB,CAAC;CAEH,OAAO,gBAAgB,SAAS,CAAC,CAAC,QAAQ;AAC5C;;;;;;;;;;;;;AC0CA,IAAM,sBAAN,cAAkC,QAAQ,QAGxC,CAAC,CAAC,2DAA2D,CAAC,CAAC,CAAC;AAElE,MAAM,gBAAgB,OAAO,MAAM,CAAC,OAAO,OAAO,EAAE,cAAc,OAAO,QAAQ,WAAW,EAAE,CAAC,CAAC,CAAC;AACjG,MAAM,cAAc,OAAO,MAAM,CAAC,OAAO,OAAO,EAAE,cAAc,OAAO,OAAO,CAAC,CAAC,CAAC;AAEjF,MAAM,iBAAi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Y;EACnC,MAAM,MAAM,OAAO,iBAAiB;EAEpC,MAAM,QAAQ,OAAO,gBAAgB,GAAG;EAExC,OAAO,OAAO,MAAM,aAClB,mBAAmB,KAAK,EAAE,OAAO,QAAQ,CAAC,CAAC,CACzC,OAAO,IAAI,aAAY;GACrB,OAAO,wBAAwB;GAS/B,OAAO,QAAO,OAPU,oBAAoB;IAC1C;IACA,cAAc;IACd,OAAO,SAAS;IAChB,aAAa,OAAO,IAAI,oCAAoC;GAC9D,CAAC,EAAA,CAEsB,OAAO,OAAO;EACvC,CAAC,CACH,CAAC,CAAC,KACA,OAAO,SAAS,aAAa,UAC3B,mBAAmB,KAAK;GACtB,WAAW;GACX,SAAS,MAAM;GACf;EACF,CAAC,CAAC,CACN,CACF;CACF,CAAC,CAAC,CAAC,KACD,OAAO,QACP,OAAO,QACL,MAAM,MACJ,kBACE;EACE,UAAU,QAAQ;EAClB,UAAU;EACV,YAAY;EACZ,aAAa,QAAQ,eAAe;CACtC,GACA,wBACF,GACA,WAAW,KACb,CACF,CACF;AACF,CAAC;;AAGD,MAAa,qBACX,YACoC;CACpC,MAAM,WAAW,UACf,iBAAiB,KAAK;EAAE,WAAW;EAA0B,SAAS,MAAM;EAAS;CAAM,CAAC;CAE9F,OAAO,MAAM,QAAQ,oBAAoB,EACvC,SAAS,YACP,aAAa,SAAS,OAAO,CAAC,CAAC,KAC7B,OAAO,UAAU;EACf,iCAAiC;EACjC,8BAA8B;EAC9B,oBAAoB;CACtB,CAAC,CACH,EACJ,CAAC;AACH"}
@@ -0,0 +1,89 @@
1
+ import { RunStorage, StorageOwner } from "@systemfsoftware/agent/run-storage";
2
+ import { SettlementPublisher } from "@systemfsoftware/agent/settlement-publisher";
3
+ import { SubmissionLedger } from "@systemfsoftware/agent/submission-ledger";
4
+ import { ThreadImport } from "@systemfsoftware/agent/thread-import";
5
+ import { ThreadExportRequest, ThreadExportSource, ThreadReader, ThreadStore, ThreadStoreError } from "@systemfsoftware/agent/thread-store";
6
+ import * as Context from "effect/Context";
7
+ import * as CryptoDigest from "effect/crypto/Digest";
8
+ import * as SecureRandom from "effect/crypto/SecureRandom";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Layer from "effect/Layer";
11
+ import * as SqlClientService from "effect/sql/SqlClient";
12
+ import { t as SqliteStorageConfig } from "./SqliteStorageConfig-6HRtBHf8.mjs";
13
+ import { a as SqliteStorageCorruptionError, i as SqliteStorageCompatibilityError, o as SqliteStorageError } from "./SqliteStorageError-Bc-iVib1.mjs";
14
+ import { n as SqliteStorageFailpointHandler, t as SqliteStorageFailpoint } from "./SqliteStorageFailpoint-CJRyxmsW.mjs";
15
+ declare namespace SqliteThreadStore_d_exports {
16
+ export { SqliteStorageInitializationError, SqliteStorageOptions, exclusiveHostClientLayer, exclusiveRunStorageLayer, exportSourceLayer, exportThread, layer, storageConfigLayer, storageFailpointLayer, threadStoreLayer };
17
+ }
18
+ interface SqliteStorageOptions {
19
+ readonly filename: string;
20
+ readonly observationPollInterval?: number | undefined;
21
+ /** Bounded SQLITE_BUSY retry window for write-lock acquisition, in milliseconds. */
22
+ readonly busyTimeout?: number | undefined;
23
+ /**
24
+ * SQLite WAL synchronization for this store's connection. Defaults to FULL. NORMAL can lose
25
+ * acknowledged commits after power loss or an OS crash, potentially repeating external effects.
26
+ * All stores sharing a client must select the same mode when constructed.
27
+ */
28
+ readonly synchronous?: 'FULL' | 'NORMAL' | undefined;
29
+ /**
30
+ * Audit stored payloads, identities, and batch coverage on open. Defaults to false. Full reads validate
31
+ * canonical records; readPrompt trusts write-time validation of the omitted fields.
32
+ */
33
+ readonly verifyOnOpen?: boolean | undefined;
34
+ readonly failpoint?: SqliteStorageFailpointHandler | undefined;
35
+ }
36
+ type SqliteStorageInitializationError = SqliteStorageCompatibilityError | SqliteStorageCorruptionError | SqliteStorageError;
37
+ declare const ExclusiveSqliteHost_base: Context.ServiceClass<ExclusiveSqliteHost, "@effect-agent/storage-sqlite/internal/ExclusiveSqliteHost", {
38
+ readonly sql: SqlClientService.SqlClient;
39
+ }>;
40
+ /** Only the exclusive client acquisition can construct managed mutation authority. */
41
+ declare class ExclusiveSqliteHost extends ExclusiveSqliteHost_base {}
42
+ /**
43
+ * Acquire process-lifetime authority over a dedicated SQLite client before exposing it to a
44
+ * managed host. Open the client with `disableWAL: true`: WAL setup and lock contention must
45
+ * fail through this Layer's typed initialization error. The client Scope owns the lock;
46
+ * never change its locking mode or close it while host work is alive.
47
+ *
48
+ * This excludes ALL other database connections, including readers. After compatibility checks,
49
+ * initialize fresh storage or atomically upgrade supported predecessor layouts, then recover from durable facts. Scope closure
50
+ * retires local capabilities; no ownership is restored from the database. Only the exact
51
+ * declared triggers on Thread storage tables are permitted before any initialization;
52
+ * application and optional memory tables retain their own schema contracts.
53
+ */
54
+ declare const exclusiveHostClientLayer: Layer.Layer<SqlClientService.SqlClient | ExclusiveSqliteHost, SqliteStorageInitializationError, SqliteStorageConfig | SqliteStorageFailpoint | SqlClientService.SqlClient | CryptoDigest.Digest>;
55
+ /**
56
+ * SQLite Thread Store implementation with configuration, failpoint, SQL, and Digest
57
+ * authority kept visible in its input channel.
58
+ * Inject a client opened with `disableWAL: true`; this adapter enables WAL only for a
59
+ * fresh file so unsupported files reject before persistent driver configuration changes.
60
+ */
61
+ declare const threadStoreLayer: Layer.Layer<ThreadStore | ThreadReader | ThreadImport | StorageOwner, SqliteStorageInitializationError, SqliteStorageConfig | SqliteStorageFailpoint | SqlClientService.SqlClient | CryptoDigest.Digest>;
62
+ /**
63
+ * Managed-host storage for an already acquired exclusiveHostClientLayer. The composition
64
+ * root consumes the mutation ports privately and exposes only ThreadReader to application
65
+ * bindings. Its private construction witness binds the exact exclusive client; supplying a
66
+ * generic SqlClient cannot bypass the required exclusive acquisition.
67
+ */
68
+ declare const exclusiveRunStorageLayer: Layer.Layer<RunStorage | SettlementPublisher | StorageOwner | SubmissionLedger | ThreadImport | ThreadReader | ThreadStore, SqliteStorageCompatibilityError | SqliteStorageCorruptionError | SqliteStorageError, CryptoDigest.Digest | ExclusiveSqliteHost | SecureRandom.SecureRandom | SqliteStorageConfig | SqliteStorageFailpoint>;
69
+ /**
70
+ * Validated SQLite storage configuration Layer with the documented defaults applied. Shared
71
+ * by the ThreadStore and SubmissionLedger convenience layers so their defaults cannot
72
+ * drift.
73
+ */
74
+ declare const storageConfigLayer: (options: SqliteStorageOptions) => Layer.Layer<SqliteStorageConfig, SqliteStorageError>;
75
+ /** The failpoint Layer selected by convenience options: explicit handler or the no-op default. */
76
+ declare const storageFailpointLayer: (options: SqliteStorageOptions) => Layer.Layer<SqliteStorageFailpoint>;
77
+ /**
78
+ * A composition-root convenience Layer for canonical Threads. Durable accepted work is
79
+ * served by the separate SubmissionLedger port.
80
+ */
81
+ declare const layer: (options: SqliteStorageOptions) => Layer.Layer<ThreadStore | ThreadReader | ThreadImport | StorageOwner, SqliteStorageInitializationError>;
82
+ /**
83
+ * Export a quiesced current-layout database without initializing layout or retiring
84
+ * ownership. Its read-only connection closes before returning; the source remains untouched.
85
+ */
86
+ declare const exportThread: (options: Pick<SqliteStorageOptions, "busyTimeout" | "filename">, request: ThreadExportRequest) => Effect.Effect<import("@systemfsoftware/agent/thread-store").ThreadExport, SqliteStorageCompatibilityError | SqliteStorageCorruptionError | SqliteStorageError | import("@systemfsoftware/agent/thread-store").ThreadExportRejected | import("@systemfsoftware/agent/thread-store").ThreadNotMaterialized | ThreadStoreError, never>;
87
+ /** Read-only page exports retain native diagnostics in the transfer port's typed storage failure. */
88
+ declare const exportSourceLayer: (options: Pick<SqliteStorageOptions, 'filename' | 'busyTimeout'>) => Layer.Layer<ThreadExportSource>;
89
+ export { exclusiveRunStorageLayer as a, layer as c, threadStoreLayer as d, exclusiveHostClientLayer as i, storageConfigLayer as l, SqliteStorageOptions as n, exportSourceLayer as o, SqliteThreadStore_d_exports as r, exportThread as s, SqliteStorageInitializationError as t, storageFailpointLayer as u };
@@ -0,0 +1,2 @@
1
+ import { a as exclusiveRunStorageLayer, c as layer, d as threadStoreLayer, i as exclusiveHostClientLayer, l as storageConfigLayer, n as SqliteStorageOptions, o as exportSourceLayer, s as exportThread, t as SqliteStorageInitializationError, u as storageFailpointLayer } from "./SqliteThreadStore-DKac999S.mjs";
2
+ export { SqliteStorageInitializationError, SqliteStorageOptions, exclusiveHostClientLayer, exclusiveRunStorageLayer, exportSourceLayer, exportThread, layer, storageConfigLayer, storageFailpointLayer, threadStoreLayer };
@@ -0,0 +1 @@
1
+ export { n as exclusiveHostClientLayer, r as exclusiveRunStorageLayer, i as exportSourceLayer, a as exportThread, o as layer, s as storageConfigLayer, c as storageFailpointLayer, l as threadStoreLayer } from "./SqliteThreadStore-CUkk9A0Y.mjs";
@@ -0,0 +1,11 @@
1
+ import { n as SqliteActivityStore_d_exports } from "./SqliteActivityStore-DM-gMSMv.mjs";
2
+ import { t as SqliteMessageDeliveryStore_d_exports } from "./SqliteMessageDeliveryStore-D1pwnufl.mjs";
3
+ import { t as SqliteScheduleStore_d_exports } from "./SqliteScheduleStore-CrH-tLQB.mjs";
4
+ import { r as SqliteStorageConfig_d_exports } from "./SqliteStorageConfig-6HRtBHf8.mjs";
5
+ import { s as SqliteStorageError_d_exports } from "./SqliteStorageError-Bc-iVib1.mjs";
6
+ import { r as SqliteStorageFailpoint_d_exports } from "./SqliteStorageFailpoint-CJRyxmsW.mjs";
7
+ import { t as SqliteStorageVersion_d_exports } from "./SqliteStorageVersion-Bayz1P9w.mjs";
8
+ import { t as SqliteSubmissionLedger_d_exports } from "./SqliteSubmissionLedger-2lHitXAA.mjs";
9
+ import { t as SqliteSubscriptionStore_d_exports } from "./SqliteSubscriptionStore-CRkOEBaa.mjs";
10
+ import { r as SqliteThreadStore_d_exports } from "./SqliteThreadStore-DKac999S.mjs";
11
+ export { SqliteActivityStore_d_exports as SqliteActivityStore, SqliteMessageDeliveryStore_d_exports as SqliteMessageDeliveryStore, SqliteScheduleStore_d_exports as SqliteScheduleStore, SqliteStorageConfig_d_exports as SqliteStorageConfig, SqliteStorageError_d_exports as SqliteStorageError, SqliteStorageFailpoint_d_exports as SqliteStorageFailpoint, SqliteStorageVersion_d_exports as SqliteStorageVersion, SqliteSubmissionLedger_d_exports as SqliteSubmissionLedger, SqliteSubscriptionStore_d_exports as SqliteSubscriptionStore, SqliteThreadStore_d_exports as SqliteThreadStore };
package/dist/index.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import { t as SqliteActivityStore_exports } from "./SqliteActivityStore-CSvw-3OJ.mjs";
2
+ import { t as SqliteMessageDeliveryStore_exports } from "./SqliteMessageDeliveryStore-C0D-jYWc.mjs";
3
+ import { t as SqliteScheduleStore_exports } from "./SqliteScheduleStore-Nph_W_Lg.mjs";
4
+ import { r as SqliteStorageConfig_exports } from "./SqliteStorageConfig-DN-WwQrw.mjs";
5
+ import { s as SqliteStorageError_exports } from "./SqliteStorageError-d_tygf_W.mjs";
6
+ import { n as SqliteStorageFailpoint_exports } from "./SqliteStorageFailpoint-BqxmxFBb.mjs";
7
+ import { t as SqliteStorageVersion_exports } from "./SqliteStorageVersion-BxAVd_1t.mjs";
8
+ import { t as SqliteSubmissionLedger_exports } from "./SqliteSubmissionLedger-DTWaRPjV.mjs";
9
+ import { t as SqliteSubscriptionStore_exports } from "./SqliteSubscriptionStore-CFmi_ULJ.mjs";
10
+ import { t as SqliteThreadStore_exports } from "./SqliteThreadStore-CUkk9A0Y.mjs";
11
+ export { SqliteActivityStore_exports as SqliteActivityStore, SqliteMessageDeliveryStore_exports as SqliteMessageDeliveryStore, SqliteScheduleStore_exports as SqliteScheduleStore, SqliteStorageConfig_exports as SqliteStorageConfig, SqliteStorageError_exports as SqliteStorageError, SqliteStorageFailpoint_exports as SqliteStorageFailpoint, SqliteStorageVersion_exports as SqliteStorageVersion, SqliteSubmissionLedger_exports as SqliteSubmissionLedger, SqliteSubscriptionStore_exports as SqliteSubscriptionStore, SqliteThreadStore_exports as SqliteThreadStore };