@effect-agent/storage-sqlite 0.1.0-beta.6 → 0.1.0-beta.61
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/SqliteActivityStore.d.mts +14 -0
- package/dist/SqliteActivityStore.mjs +310 -0
- package/dist/SqliteActivityStore.mjs.map +1 -0
- package/dist/SqliteMessageDeliveryStore.d.mts +14 -0
- package/dist/SqliteMessageDeliveryStore.mjs +24 -0
- package/dist/SqliteMessageDeliveryStore.mjs.map +1 -0
- package/dist/SqliteScheduleStore.d.mts +14 -0
- package/dist/SqliteScheduleStore.mjs +255 -0
- package/dist/SqliteScheduleStore.mjs.map +1 -0
- package/dist/SqliteStorageConfig.d.mts +34 -0
- package/dist/SqliteStorageConfig.mjs +39 -0
- package/dist/SqliteStorageConfig.mjs.map +1 -0
- package/dist/SqliteStorageError-CzKmwCLl.d.mts +86 -0
- package/dist/SqliteStorageError.d.mts +2 -0
- package/dist/SqliteStorageError.mjs +148 -0
- package/dist/SqliteStorageError.mjs.map +1 -0
- package/dist/SqliteStorageFailpoint.d.mts +17 -0
- package/dist/SqliteStorageFailpoint.mjs +14 -0
- package/dist/SqliteStorageFailpoint.mjs.map +1 -0
- package/dist/SqliteStorageFailpointTesting.d.mts +15 -0
- package/dist/SqliteStorageFailpointTesting.mjs +19 -0
- package/dist/SqliteStorageFailpointTesting.mjs.map +1 -0
- package/dist/SqliteStorageVersion-gA7_96xM.d.mts +9 -0
- package/dist/SqliteStorageVersion.d.mts +2 -0
- package/dist/SqliteStorageVersion.mjs +8 -0
- package/dist/SqliteStorageVersion.mjs.map +1 -0
- package/dist/SqliteSubmissionLedger.d.mts +23 -0
- package/dist/SqliteSubmissionLedger.mjs +1765 -0
- package/dist/SqliteSubmissionLedger.mjs.map +1 -0
- package/dist/SqliteSubscriptionStore.d.mts +13 -0
- package/dist/SqliteSubscriptionStore.mjs +28 -0
- package/dist/SqliteSubscriptionStore.mjs.map +1 -0
- package/dist/SqliteThreadStore.d.mts +49 -0
- package/dist/SqliteThreadStore.mjs +427 -0
- package/dist/SqliteThreadStore.mjs.map +1 -0
- package/dist/index.d.mts +11 -193
- package/dist/index.mjs +11 -3082
- package/dist/migrations-dnTR0RKq.mjs +326 -0
- package/dist/migrations-dnTR0RKq.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/sqlite-journal-lDduEakl.mjs +887 -0
- package/dist/sqlite-journal-lDduEakl.mjs.map +1 -0
- package/package.json +1 -41
- package/src/SqliteActivityStore.ts +556 -0
- package/src/SqliteMessageDeliveryStore.ts +42 -0
- package/src/SqliteScheduleStore.ts +404 -0
- package/src/{sqlite-storage-config.ts → SqliteStorageConfig.ts} +1 -1
- package/src/{errors.ts → SqliteStorageError.ts} +8 -3
- package/src/SqliteStorageFailpoint.ts +23 -0
- package/src/{sqlite-storage-failpoint.ts → SqliteStorageFailpointTesting.ts} +7 -18
- package/src/SqliteStorageVersion.ts +2 -0
- package/src/{sqlite-ledger.ts → SqliteSubmissionLedger.ts} +753 -118
- package/src/SqliteSubscriptionStore.ts +59 -0
- package/src/{sqlite-conversation-store.ts → SqliteThreadStore.ts} +372 -302
- package/src/index.ts +10 -6
- package/src/internal/message-delivery-schema.ts +24 -0
- package/src/{migrations.ts → internal/migrations.ts} +145 -79
- package/src/{sqlite-journal.ts → internal/sqlite-journal.ts} +534 -222
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { a as initializeSqliteJournal } from "./sqlite-journal-lDduEakl.mjs";
|
|
3
|
+
import { Effect, Layer, Result, Schema } from "effect";
|
|
4
|
+
import * as SqlClientService from "effect/unstable/sql/SqlClient";
|
|
5
|
+
import { ScheduleCapacityError, ScheduleChange, ScheduleConflict, ScheduleDueCursor, ScheduleFailpoint, ScheduleId, ScheduleInstant, ScheduleKey, ScheduleNotFound, ScheduleOwner, SchedulePageRequest, ScheduleRecord, ScheduleStorageError, ScheduleStore, defaultSchedulingLimits } from "@effect-agent/thread/Schedule";
|
|
6
|
+
import { applyScheduleChange, scheduleDeadline, scheduleUsesCapacity } from "@effect-agent/thread/ScheduleTransition";
|
|
7
|
+
//#region src/SqliteScheduleStore.ts
|
|
8
|
+
var SqliteScheduleStore_exports = /* @__PURE__ */ __exportAll({ scheduleStoreLayer: () => scheduleStoreLayer });
|
|
9
|
+
const StoredScheduleJson = Schema.String.check(Schema.isMaxLength(16777216));
|
|
10
|
+
const StoredDeadline = Schema.NullOr(ScheduleInstant);
|
|
11
|
+
var ScheduleRow = class extends Schema.Class("@effect-agent/storage-sqlite/ScheduleRow")({
|
|
12
|
+
tenant_id: ScheduleOwner.fields.tenantId,
|
|
13
|
+
owner_id: ScheduleOwner.fields.ownerId,
|
|
14
|
+
schedule_id: ScheduleId,
|
|
15
|
+
deadline_at_millis: StoredDeadline,
|
|
16
|
+
record_json: StoredScheduleJson
|
|
17
|
+
}) {};
|
|
18
|
+
const ScheduleDueRow = Schema.Struct({
|
|
19
|
+
tenant_id: ScheduleOwner.fields.tenantId,
|
|
20
|
+
owner_id: ScheduleOwner.fields.ownerId,
|
|
21
|
+
schedule_id: ScheduleId,
|
|
22
|
+
deadline_at_millis: ScheduleInstant
|
|
23
|
+
});
|
|
24
|
+
var ScheduleCountRow = class extends Schema.Class("@effect-agent/storage-sqlite/ScheduleCountRow")({ schedule_count: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)) }) {};
|
|
25
|
+
var ScheduleDeadlineRow = class extends Schema.Class("@effect-agent/storage-sqlite/ScheduleDeadlineRow")({ deadline_at_millis: StoredDeadline }) {};
|
|
26
|
+
const unavailable = (operation) => ScheduleStorageError.make({
|
|
27
|
+
operation,
|
|
28
|
+
reason: "unavailable"
|
|
29
|
+
});
|
|
30
|
+
const corrupt = (operation) => ScheduleStorageError.make({
|
|
31
|
+
operation,
|
|
32
|
+
reason: "corrupt"
|
|
33
|
+
});
|
|
34
|
+
const decodeRows = Effect.fn("SqliteScheduleStore.decodeRows")(function* (schema, rows, operation) {
|
|
35
|
+
return yield* Schema.decodeUnknownEffect(schema)(rows).pipe(Effect.mapError(() => corrupt(operation)));
|
|
36
|
+
});
|
|
37
|
+
const decodeRecord = Effect.fn("SqliteScheduleStore.decodeRecord")(function* (row) {
|
|
38
|
+
const record = yield* Schema.decodeEffect(Schema.fromJsonString(ScheduleRecord))(row.record_json).pipe(Effect.mapError(() => corrupt("decode schedule")));
|
|
39
|
+
if (record.owner.tenantId !== row.tenant_id || record.owner.ownerId !== row.owner_id || record.scheduleId !== row.schedule_id || scheduleDeadline(record) !== row.deadline_at_millis) return yield* corrupt("decode schedule identity");
|
|
40
|
+
return record;
|
|
41
|
+
});
|
|
42
|
+
const encodeRecord = Effect.fn("SqliteScheduleStore.encodeRecord")(function* (record) {
|
|
43
|
+
return yield* Schema.encodeEffect(Schema.fromJsonString(ScheduleRecord))(record).pipe(Effect.mapError(() => corrupt("encode schedule")));
|
|
44
|
+
});
|
|
45
|
+
const decodeInput = Effect.fn("SqliteScheduleStore.decodeInput")(function* (operation, schema, value) {
|
|
46
|
+
return yield* Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(() => corrupt(operation)));
|
|
47
|
+
});
|
|
48
|
+
const makeScheduleStore = Effect.gen(function* () {
|
|
49
|
+
const sql = yield* SqlClientService.SqlClient;
|
|
50
|
+
const scheduleFailpoint = yield* ScheduleFailpoint;
|
|
51
|
+
yield* initializeSqliteJournal();
|
|
52
|
+
const readRows = Effect.fn("SqliteScheduleStore.readRows")(function* (key, operation) {
|
|
53
|
+
const rows = yield* sql`
|
|
54
|
+
SELECT tenant_id, owner_id, schedule_id, deadline_at_millis, record_json
|
|
55
|
+
FROM effect_agent_schedules
|
|
56
|
+
WHERE tenant_id = ${key.owner.tenantId}
|
|
57
|
+
AND owner_id = ${key.owner.ownerId}
|
|
58
|
+
AND schedule_id = ${key.scheduleId}
|
|
59
|
+
`.pipe(Effect.mapError(() => unavailable(operation)));
|
|
60
|
+
return yield* decodeRows(Schema.Array(ScheduleRow), rows, operation);
|
|
61
|
+
});
|
|
62
|
+
const readOne = Effect.fn("SqliteScheduleStore.readOne")(function* (key, operation) {
|
|
63
|
+
const rows = yield* readRows(key, operation);
|
|
64
|
+
if (rows.length === 0) return null;
|
|
65
|
+
if (rows.length !== 1) return yield* corrupt(operation);
|
|
66
|
+
return yield* decodeRecord(rows[0]);
|
|
67
|
+
});
|
|
68
|
+
const insert = Effect.fn("SqliteScheduleStore.insert")(function* (record, ownerLimit) {
|
|
69
|
+
const operation = "insert schedule";
|
|
70
|
+
const canonical = yield* decodeInput(operation, ScheduleRecord, record);
|
|
71
|
+
const recordJson = yield* encodeRecord(canonical);
|
|
72
|
+
const result = yield* sql.withTransaction(Effect.gen(function* () {
|
|
73
|
+
const existing = yield* readOne(canonical, operation);
|
|
74
|
+
if (existing !== null) {
|
|
75
|
+
if (existing.creationFingerprint === canonical.creationFingerprint) return {
|
|
76
|
+
record: existing,
|
|
77
|
+
inserted: false
|
|
78
|
+
};
|
|
79
|
+
return yield* ScheduleConflict.make({
|
|
80
|
+
reason: "creation",
|
|
81
|
+
key: {
|
|
82
|
+
owner: canonical.owner,
|
|
83
|
+
scheduleId: canonical.scheduleId
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const rawCounts = yield* sql`
|
|
88
|
+
SELECT COUNT(*) AS schedule_count
|
|
89
|
+
FROM effect_agent_schedules
|
|
90
|
+
WHERE tenant_id = ${canonical.owner.tenantId}
|
|
91
|
+
AND owner_id = ${canonical.owner.ownerId}
|
|
92
|
+
AND (json_extract(record_json, '$.pending') IS NOT NULL OR
|
|
93
|
+
(json_extract(record_json, '$.state') != 'cancelled' AND json_extract(record_json, '$.nextAtMillis') IS NOT NULL))
|
|
94
|
+
`.pipe(Effect.mapError(() => unavailable(operation)));
|
|
95
|
+
const counts = yield* decodeRows(Schema.Array(ScheduleCountRow), rawCounts, operation);
|
|
96
|
+
if (counts.length !== 1) return yield* corrupt(operation);
|
|
97
|
+
if (counts[0].schedule_count >= ownerLimit) return yield* ScheduleCapacityError.make({ limit: ownerLimit });
|
|
98
|
+
yield* scheduleFailpoint.hit("schedule:insert:before");
|
|
99
|
+
yield* sql`
|
|
100
|
+
INSERT INTO effect_agent_schedules (
|
|
101
|
+
tenant_id, owner_id, schedule_id, deadline_at_millis, record_json
|
|
102
|
+
) VALUES (
|
|
103
|
+
${canonical.owner.tenantId},
|
|
104
|
+
${canonical.owner.ownerId},
|
|
105
|
+
${canonical.scheduleId},
|
|
106
|
+
${scheduleDeadline(canonical)},
|
|
107
|
+
${recordJson}
|
|
108
|
+
)
|
|
109
|
+
`.pipe(Effect.mapError(() => unavailable(operation)));
|
|
110
|
+
return {
|
|
111
|
+
record: canonical,
|
|
112
|
+
inserted: true
|
|
113
|
+
};
|
|
114
|
+
})).pipe(Effect.catchTag("SqlError", () => Effect.fail(unavailable(operation))));
|
|
115
|
+
if (result.inserted) yield* scheduleFailpoint.hit("schedule:insert:after");
|
|
116
|
+
return result.record;
|
|
117
|
+
});
|
|
118
|
+
const get = Effect.fn("SqliteScheduleStore.get")(function* (key) {
|
|
119
|
+
const decodedKey = yield* decodeInput("get schedule", ScheduleKey, key);
|
|
120
|
+
return yield* readOne(decodedKey, "get schedule");
|
|
121
|
+
});
|
|
122
|
+
const list = Effect.fn("SqliteScheduleStore.list")(function* (request) {
|
|
123
|
+
const operation = "list schedules";
|
|
124
|
+
const decodedRequest = yield* decodeInput(operation, SchedulePageRequest, request);
|
|
125
|
+
const rows = decodedRequest.after === void 0 ? yield* sql`
|
|
126
|
+
SELECT tenant_id, owner_id, schedule_id, deadline_at_millis, record_json
|
|
127
|
+
FROM effect_agent_schedules
|
|
128
|
+
WHERE tenant_id = ${decodedRequest.owner.tenantId}
|
|
129
|
+
AND owner_id = ${decodedRequest.owner.ownerId}
|
|
130
|
+
ORDER BY schedule_id
|
|
131
|
+
LIMIT ${decodedRequest.limit + 1}
|
|
132
|
+
`.pipe(Effect.mapError(() => unavailable(operation))) : yield* sql`
|
|
133
|
+
SELECT tenant_id, owner_id, schedule_id, deadline_at_millis, record_json
|
|
134
|
+
FROM effect_agent_schedules
|
|
135
|
+
WHERE tenant_id = ${decodedRequest.owner.tenantId}
|
|
136
|
+
AND owner_id = ${decodedRequest.owner.ownerId}
|
|
137
|
+
AND schedule_id > ${decodedRequest.after}
|
|
138
|
+
ORDER BY schedule_id
|
|
139
|
+
LIMIT ${decodedRequest.limit + 1}
|
|
140
|
+
`.pipe(Effect.mapError(() => unavailable(operation)));
|
|
141
|
+
const decoded = yield* decodeRows(Schema.Array(ScheduleRow), rows, operation);
|
|
142
|
+
const records = yield* Effect.forEach(decoded, decodeRecord);
|
|
143
|
+
const hasNext = records.length > decodedRequest.limit;
|
|
144
|
+
const items = hasNext ? records.slice(0, decodedRequest.limit) : records;
|
|
145
|
+
return {
|
|
146
|
+
items,
|
|
147
|
+
next: hasNext ? items.at(-1)?.scheduleId ?? null : null
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
const change = Effect.fn("SqliteScheduleStore.change")(function* (key, change, ownerLimit = defaultSchedulingLimits.maxSchedulesPerOwner) {
|
|
151
|
+
const operation = "change schedule";
|
|
152
|
+
const decodedKey = yield* decodeInput(operation, ScheduleKey, key);
|
|
153
|
+
const decodedChange = yield* decodeInput(operation, ScheduleChange, change);
|
|
154
|
+
const result = yield* sql.withTransaction(Effect.gen(function* () {
|
|
155
|
+
const current = yield* readOne(decodedKey, operation);
|
|
156
|
+
if (current === null) return yield* ScheduleNotFound.make({ key: decodedKey });
|
|
157
|
+
const transition = applyScheduleChange(current, decodedChange);
|
|
158
|
+
if (Result.isFailure(transition)) return yield* transition.failure;
|
|
159
|
+
const next = transition.success;
|
|
160
|
+
if (!scheduleUsesCapacity(current) && scheduleUsesCapacity(next)) {
|
|
161
|
+
const rawCounts = yield* sql`
|
|
162
|
+
SELECT COUNT(*) AS schedule_count FROM effect_agent_schedules
|
|
163
|
+
WHERE tenant_id = ${key.owner.tenantId} AND owner_id = ${key.owner.ownerId}
|
|
164
|
+
AND (json_extract(record_json, '$.pending') IS NOT NULL OR
|
|
165
|
+
(json_extract(record_json, '$.state') != 'cancelled' AND json_extract(record_json, '$.nextAtMillis') IS NOT NULL))
|
|
166
|
+
`.pipe(Effect.mapError(() => unavailable(operation)));
|
|
167
|
+
const counts = yield* decodeRows(Schema.Array(ScheduleCountRow), rawCounts, operation);
|
|
168
|
+
if (counts.length !== 1) return yield* corrupt(operation);
|
|
169
|
+
if (counts[0].schedule_count >= ownerLimit) return yield* ScheduleCapacityError.make({ limit: ownerLimit });
|
|
170
|
+
}
|
|
171
|
+
if (next === current) return {
|
|
172
|
+
record: current,
|
|
173
|
+
changed: false
|
|
174
|
+
};
|
|
175
|
+
const recordJson = yield* encodeRecord(next);
|
|
176
|
+
yield* scheduleFailpoint.hit(`schedule:${decodedChange._tag.toLowerCase()}:before`);
|
|
177
|
+
yield* sql`
|
|
178
|
+
UPDATE effect_agent_schedules
|
|
179
|
+
SET deadline_at_millis = ${scheduleDeadline(next)}, record_json = ${recordJson}
|
|
180
|
+
WHERE tenant_id = ${decodedKey.owner.tenantId}
|
|
181
|
+
AND owner_id = ${decodedKey.owner.ownerId}
|
|
182
|
+
AND schedule_id = ${decodedKey.scheduleId}
|
|
183
|
+
`.pipe(Effect.mapError(() => unavailable(operation)));
|
|
184
|
+
return {
|
|
185
|
+
record: next,
|
|
186
|
+
changed: true
|
|
187
|
+
};
|
|
188
|
+
})).pipe(Effect.catchTag("SqlError", () => Effect.fail(unavailable(operation))));
|
|
189
|
+
if (result.changed) yield* scheduleFailpoint.hit(`schedule:${decodedChange._tag.toLowerCase()}:after`);
|
|
190
|
+
return result.record;
|
|
191
|
+
});
|
|
192
|
+
const due = Effect.fn("SqliteScheduleStore.due")(function* (nowMillis, limit, owner, after) {
|
|
193
|
+
const operation = "query due schedules";
|
|
194
|
+
const decodedOwner = owner === void 0 ? void 0 : yield* decodeInput(operation, ScheduleOwner, owner);
|
|
195
|
+
const cursor = after === void 0 ? void 0 : yield* Schema.decodeUnknownEffect(ScheduleDueCursor)(after).pipe(Effect.mapError(() => corrupt(operation)));
|
|
196
|
+
const continuation = cursor === void 0 ? sql`1 = 1` : sql`
|
|
197
|
+
(deadline_at_millis, tenant_id, owner_id, schedule_id) >
|
|
198
|
+
(${cursor.deadlineAtMillis}, ${cursor.owner.tenantId}, ${cursor.owner.ownerId}, ${cursor.scheduleId})`;
|
|
199
|
+
const rows = decodedOwner === void 0 ? yield* sql`
|
|
200
|
+
SELECT tenant_id, owner_id, schedule_id, deadline_at_millis
|
|
201
|
+
FROM effect_agent_schedules
|
|
202
|
+
WHERE deadline_at_millis <= ${nowMillis} AND ${continuation}
|
|
203
|
+
ORDER BY deadline_at_millis, tenant_id, owner_id, schedule_id
|
|
204
|
+
LIMIT ${limit}
|
|
205
|
+
`.pipe(Effect.mapError(() => unavailable(operation))) : yield* sql`
|
|
206
|
+
SELECT tenant_id, owner_id, schedule_id, deadline_at_millis
|
|
207
|
+
FROM effect_agent_schedules
|
|
208
|
+
WHERE tenant_id = ${decodedOwner.tenantId}
|
|
209
|
+
AND owner_id = ${decodedOwner.ownerId}
|
|
210
|
+
AND deadline_at_millis <= ${nowMillis} AND ${continuation}
|
|
211
|
+
ORDER BY deadline_at_millis, schedule_id
|
|
212
|
+
LIMIT ${limit}
|
|
213
|
+
`.pipe(Effect.mapError(() => unavailable(operation)));
|
|
214
|
+
return (yield* decodeRows(Schema.Array(ScheduleDueRow), rows, operation)).map((row) => ({
|
|
215
|
+
owner: {
|
|
216
|
+
tenantId: row.tenant_id,
|
|
217
|
+
ownerId: row.owner_id
|
|
218
|
+
},
|
|
219
|
+
scheduleId: row.schedule_id,
|
|
220
|
+
deadlineAtMillis: row.deadline_at_millis
|
|
221
|
+
}));
|
|
222
|
+
});
|
|
223
|
+
const nextDeadline = Effect.fn("SqliteScheduleStore.nextDeadline")(function* (owner) {
|
|
224
|
+
const operation = "query next schedule deadline";
|
|
225
|
+
const decodedOwner = owner === void 0 ? void 0 : yield* decodeInput(operation, ScheduleOwner, owner);
|
|
226
|
+
const rows = decodedOwner === void 0 ? yield* sql`
|
|
227
|
+
SELECT MIN(deadline_at_millis) AS deadline_at_millis
|
|
228
|
+
FROM effect_agent_schedules
|
|
229
|
+
WHERE deadline_at_millis IS NOT NULL
|
|
230
|
+
`.pipe(Effect.mapError(() => unavailable(operation))) : yield* sql`
|
|
231
|
+
SELECT MIN(deadline_at_millis) AS deadline_at_millis
|
|
232
|
+
FROM effect_agent_schedules
|
|
233
|
+
WHERE tenant_id = ${decodedOwner.tenantId}
|
|
234
|
+
AND owner_id = ${decodedOwner.ownerId}
|
|
235
|
+
AND deadline_at_millis IS NOT NULL
|
|
236
|
+
`.pipe(Effect.mapError(() => unavailable(operation)));
|
|
237
|
+
const decoded = yield* decodeRows(Schema.Array(ScheduleDeadlineRow), rows, operation);
|
|
238
|
+
if (decoded.length !== 1) return yield* corrupt(operation);
|
|
239
|
+
return decoded[0].deadline_at_millis;
|
|
240
|
+
});
|
|
241
|
+
return ScheduleStore.of({
|
|
242
|
+
insert,
|
|
243
|
+
get,
|
|
244
|
+
list,
|
|
245
|
+
change,
|
|
246
|
+
due,
|
|
247
|
+
nextDeadline
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
/** SQLite implementation of the atomic ScheduleStore port. */
|
|
251
|
+
const scheduleStoreLayer = Layer.effect(ScheduleStore)(makeScheduleStore);
|
|
252
|
+
//#endregion
|
|
253
|
+
export { scheduleStoreLayer, SqliteScheduleStore_exports as t };
|
|
254
|
+
|
|
255
|
+
//# sourceMappingURL=SqliteScheduleStore.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqliteScheduleStore.mjs","names":[],"sources":["../src/SqliteScheduleStore.ts"],"sourcesContent":["import {\n ScheduleCapacityError,\n ScheduleDueCursor,\n defaultSchedulingLimits,\n ScheduleChange,\n ScheduleConflict,\n ScheduleFailpoint,\n ScheduleKey,\n ScheduleId,\n ScheduleInstant,\n ScheduleNotFound,\n ScheduleOwner,\n type SchedulePage,\n SchedulePageRequest,\n ScheduleRecord,\n ScheduleStorageError,\n ScheduleStore,\n} from \"@effect-agent/thread/Schedule\";\nimport {\n scheduleUsesCapacity,\n applyScheduleChange,\n scheduleDeadline,\n} from \"@effect-agent/thread/ScheduleTransition\";\nimport { Effect, Layer, Result, Schema } from \"effect\";\nimport * as SqlClientService from \"effect/unstable/sql/SqlClient\";\n\nimport { initializeSqliteJournal } from \"./internal/sqlite-journal.ts\";\nimport type { SqliteStorageConfig } from \"./SqliteStorageConfig.ts\";\nimport type { SqliteStorageFailpoint } from \"./SqliteStorageFailpoint.ts\";\nimport type { SqliteStorageInitializationError } from \"./SqliteThreadStore.ts\";\n\n// Configuration and the immutable pending envelope may each carry the canonical input. Leave\n// room for JSON escaping and bounded status while rejecting an unreadable oversized row.\nconst StoredScheduleJson = Schema.String.check(Schema.isMaxLength(16 * 1024 * 1024));\nconst StoredDeadline = Schema.NullOr(ScheduleInstant);\n\nclass ScheduleRow extends Schema.Class<ScheduleRow>(\"@effect-agent/storage-sqlite/ScheduleRow\")({\n tenant_id: ScheduleOwner.fields.tenantId,\n owner_id: ScheduleOwner.fields.ownerId,\n schedule_id: ScheduleId,\n deadline_at_millis: StoredDeadline,\n record_json: StoredScheduleJson,\n}) {}\n\nconst ScheduleDueRow = Schema.Struct({\n tenant_id: ScheduleOwner.fields.tenantId,\n owner_id: ScheduleOwner.fields.ownerId,\n schedule_id: ScheduleId,\n deadline_at_millis: ScheduleInstant,\n});\n\nclass ScheduleCountRow extends Schema.Class<ScheduleCountRow>(\n \"@effect-agent/storage-sqlite/ScheduleCountRow\",\n)({\n schedule_count: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n}) {}\n\nclass ScheduleDeadlineRow extends Schema.Class<ScheduleDeadlineRow>(\n \"@effect-agent/storage-sqlite/ScheduleDeadlineRow\",\n)({\n deadline_at_millis: StoredDeadline,\n}) {}\n\nconst unavailable = (operation: string): ScheduleStorageError =>\n ScheduleStorageError.make({ operation, reason: \"unavailable\" });\n\nconst corrupt = (operation: string): ScheduleStorageError =>\n ScheduleStorageError.make({ operation, reason: \"corrupt\" });\n\nconst decodeRows = Effect.fn(\"SqliteScheduleStore.decodeRows\")(function* <A, I>(\n schema: Schema.Codec<A, I, never>,\n rows: ReadonlyArray<unknown>,\n operation: string,\n): Effect.fn.Return<A, ScheduleStorageError> {\n return yield* Schema.decodeUnknownEffect(schema)(rows).pipe(\n Effect.mapError(() => corrupt(operation)),\n );\n});\n\nconst decodeRecord = Effect.fn(\"SqliteScheduleStore.decodeRecord\")(function* (\n row: ScheduleRow,\n): Effect.fn.Return<ScheduleRecord, ScheduleStorageError> {\n const record = yield* Schema.decodeEffect(Schema.fromJsonString(ScheduleRecord))(\n row.record_json,\n ).pipe(Effect.mapError(() => corrupt(\"decode schedule\")));\n\n if (\n record.owner.tenantId !== row.tenant_id ||\n record.owner.ownerId !== row.owner_id ||\n record.scheduleId !== row.schedule_id ||\n scheduleDeadline(record) !== row.deadline_at_millis\n ) {\n return yield* corrupt(\"decode schedule identity\");\n }\n\n return record;\n});\n\nconst encodeRecord = Effect.fn(\"SqliteScheduleStore.encodeRecord\")(function* (\n record: ScheduleRecord,\n): Effect.fn.Return<string, ScheduleStorageError> {\n return yield* Schema.encodeEffect(Schema.fromJsonString(ScheduleRecord))(record).pipe(\n Effect.mapError(() => corrupt(\"encode schedule\")),\n );\n});\n\nconst decodeInput = Effect.fn(\"SqliteScheduleStore.decodeInput\")(function* <A, I>(\n operation: string,\n schema: Schema.Codec<A, I, never>,\n value: unknown,\n): Effect.fn.Return<A, ScheduleStorageError> {\n return yield* Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => corrupt(operation)),\n );\n});\n\nconst makeScheduleStore = Effect.gen(function* () {\n const sql = yield* SqlClientService.SqlClient;\n const scheduleFailpoint = yield* ScheduleFailpoint;\n\n yield* initializeSqliteJournal();\n\n const readRows = Effect.fn(\"SqliteScheduleStore.readRows\")(function* (\n key: ScheduleKey,\n operation: string,\n ): Effect.fn.Return<ReadonlyArray<ScheduleRow>, ScheduleStorageError> {\n const rows = yield* sql<Record<string, unknown>>`\n SELECT tenant_id, owner_id, schedule_id, deadline_at_millis, record_json\n FROM effect_agent_schedules\n WHERE tenant_id = ${key.owner.tenantId}\n AND owner_id = ${key.owner.ownerId}\n AND schedule_id = ${key.scheduleId}\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n return yield* decodeRows(Schema.Array(ScheduleRow), rows, operation);\n });\n\n const readOne = Effect.fn(\"SqliteScheduleStore.readOne\")(function* (\n key: ScheduleKey,\n operation: string,\n ): Effect.fn.Return<ScheduleRecord | null, ScheduleStorageError> {\n const rows = yield* readRows(key, operation);\n\n if (rows.length === 0) return null;\n if (rows.length !== 1) return yield* corrupt(operation);\n\n return yield* decodeRecord(rows[0]);\n });\n\n const insert: ScheduleStore[\"Service\"][\"insert\"] = Effect.fn(\"SqliteScheduleStore.insert\")(\n function* (record, ownerLimit) {\n const operation = \"insert schedule\";\n const canonical = yield* decodeInput(operation, ScheduleRecord, record);\n const recordJson = yield* encodeRecord(canonical);\n\n const result = yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const existing = yield* readOne(canonical, operation);\n\n if (existing !== null) {\n if (existing.creationFingerprint === canonical.creationFingerprint) {\n return { record: existing, inserted: false } as const;\n }\n\n return yield* ScheduleConflict.make({\n reason: \"creation\",\n key: { owner: canonical.owner, scheduleId: canonical.scheduleId },\n });\n }\n\n const rawCounts = yield* sql<Record<string, unknown>>`\n SELECT COUNT(*) AS schedule_count\n FROM effect_agent_schedules\n WHERE tenant_id = ${canonical.owner.tenantId}\n AND owner_id = ${canonical.owner.ownerId}\n AND (json_extract(record_json, '$.pending') IS NOT NULL OR\n (json_extract(record_json, '$.state') != 'cancelled' AND json_extract(record_json, '$.nextAtMillis') IS NOT NULL))\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n const counts = yield* decodeRows(Schema.Array(ScheduleCountRow), rawCounts, operation);\n\n if (counts.length !== 1) return yield* corrupt(operation);\n if (counts[0].schedule_count >= ownerLimit) {\n return yield* ScheduleCapacityError.make({ limit: ownerLimit });\n }\n yield* scheduleFailpoint.hit(\"schedule:insert:before\");\n yield* sql`\n INSERT INTO effect_agent_schedules (\n tenant_id, owner_id, schedule_id, deadline_at_millis, record_json\n ) VALUES (\n ${canonical.owner.tenantId},\n ${canonical.owner.ownerId},\n ${canonical.scheduleId},\n ${scheduleDeadline(canonical)},\n ${recordJson}\n )\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n return { record: canonical, inserted: true } as const;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(unavailable(operation))));\n\n if (result.inserted) yield* scheduleFailpoint.hit(\"schedule:insert:after\");\n\n return result.record;\n },\n );\n\n const get: ScheduleStore[\"Service\"][\"get\"] = Effect.fn(\"SqliteScheduleStore.get\")(\n function* (key) {\n const decodedKey = yield* decodeInput(\"get schedule\", ScheduleKey, key);\n\n return yield* readOne(decodedKey, \"get schedule\");\n },\n );\n\n const list: ScheduleStore[\"Service\"][\"list\"] = Effect.fn(\"SqliteScheduleStore.list\")(function* (\n request: SchedulePageRequest,\n ): Effect.fn.Return<SchedulePage, ScheduleStorageError> {\n const operation = \"list schedules\";\n const decodedRequest = yield* decodeInput(operation, SchedulePageRequest, request);\n\n const rows =\n decodedRequest.after === undefined\n ? yield* sql<Record<string, unknown>>`\n SELECT tenant_id, owner_id, schedule_id, deadline_at_millis, record_json\n FROM effect_agent_schedules\n WHERE tenant_id = ${decodedRequest.owner.tenantId}\n AND owner_id = ${decodedRequest.owner.ownerId}\n ORDER BY schedule_id\n LIMIT ${decodedRequest.limit + 1}\n `.pipe(Effect.mapError(() => unavailable(operation)))\n : yield* sql<Record<string, unknown>>`\n SELECT tenant_id, owner_id, schedule_id, deadline_at_millis, record_json\n FROM effect_agent_schedules\n WHERE tenant_id = ${decodedRequest.owner.tenantId}\n AND owner_id = ${decodedRequest.owner.ownerId}\n AND schedule_id > ${decodedRequest.after}\n ORDER BY schedule_id\n LIMIT ${decodedRequest.limit + 1}\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n const decoded = yield* decodeRows(Schema.Array(ScheduleRow), rows, operation);\n const records = yield* Effect.forEach(decoded, decodeRecord);\n const hasNext = records.length > decodedRequest.limit;\n const items = hasNext ? records.slice(0, decodedRequest.limit) : records;\n\n return { items, next: hasNext ? (items.at(-1)?.scheduleId ?? null) : null };\n });\n\n const change: ScheduleStore[\"Service\"][\"change\"] = Effect.fn(\"SqliteScheduleStore.change\")(\n function* (key, change, ownerLimit = defaultSchedulingLimits.maxSchedulesPerOwner) {\n const operation = \"change schedule\";\n const decodedKey = yield* decodeInput(operation, ScheduleKey, key);\n const decodedChange = yield* decodeInput(operation, ScheduleChange, change);\n\n const result = yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* readOne(decodedKey, operation);\n\n if (current === null) return yield* ScheduleNotFound.make({ key: decodedKey });\n const transition = applyScheduleChange(current, decodedChange);\n\n if (Result.isFailure(transition)) return yield* transition.failure;\n const next = transition.success;\n\n if (!scheduleUsesCapacity(current) && scheduleUsesCapacity(next)) {\n const rawCounts = yield* sql<Record<string, unknown>>`\n SELECT COUNT(*) AS schedule_count FROM effect_agent_schedules\n WHERE tenant_id = ${key.owner.tenantId} AND owner_id = ${key.owner.ownerId}\n AND (json_extract(record_json, '$.pending') IS NOT NULL OR\n (json_extract(record_json, '$.state') != 'cancelled' AND json_extract(record_json, '$.nextAtMillis') IS NOT NULL))\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n const counts = yield* decodeRows(\n Schema.Array(ScheduleCountRow),\n rawCounts,\n operation,\n );\n\n if (counts.length !== 1) return yield* corrupt(operation);\n if (counts[0].schedule_count >= ownerLimit)\n return yield* ScheduleCapacityError.make({ limit: ownerLimit });\n }\n if (next === current) return { record: current, changed: false } as const;\n const recordJson = yield* encodeRecord(next);\n\n yield* scheduleFailpoint.hit(`schedule:${decodedChange._tag.toLowerCase()}:before`);\n yield* sql`\n UPDATE effect_agent_schedules\n SET deadline_at_millis = ${scheduleDeadline(next)}, record_json = ${recordJson}\n WHERE tenant_id = ${decodedKey.owner.tenantId}\n AND owner_id = ${decodedKey.owner.ownerId}\n AND schedule_id = ${decodedKey.scheduleId}\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n return { record: next, changed: true } as const;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(unavailable(operation))));\n\n if (result.changed) {\n yield* scheduleFailpoint.hit(`schedule:${decodedChange._tag.toLowerCase()}:after`);\n }\n\n return result.record;\n },\n );\n\n const due: ScheduleStore[\"Service\"][\"due\"] = Effect.fn(\"SqliteScheduleStore.due\")(function* (\n nowMillis,\n limit,\n owner?: ScheduleOwner,\n after?: ScheduleDueCursor,\n ) {\n const operation = \"query due schedules\";\n\n const decodedOwner =\n owner === undefined ? undefined : yield* decodeInput(operation, ScheduleOwner, owner);\n\n const cursor =\n after === undefined\n ? undefined\n : yield* Schema.decodeUnknownEffect(ScheduleDueCursor)(after).pipe(\n Effect.mapError(() => corrupt(operation)),\n );\n\n const continuation =\n cursor === undefined\n ? sql`1 = 1`\n : sql`\n (deadline_at_millis, tenant_id, owner_id, schedule_id) >\n (${cursor.deadlineAtMillis}, ${cursor.owner.tenantId}, ${cursor.owner.ownerId}, ${cursor.scheduleId})`;\n\n const rows =\n decodedOwner === undefined\n ? yield* sql<Record<string, unknown>>`\n SELECT tenant_id, owner_id, schedule_id, deadline_at_millis\n FROM effect_agent_schedules\n WHERE deadline_at_millis <= ${nowMillis} AND ${continuation}\n ORDER BY deadline_at_millis, tenant_id, owner_id, schedule_id\n LIMIT ${limit}\n `.pipe(Effect.mapError(() => unavailable(operation)))\n : yield* sql<Record<string, unknown>>`\n SELECT tenant_id, owner_id, schedule_id, deadline_at_millis\n FROM effect_agent_schedules\n WHERE tenant_id = ${decodedOwner.tenantId}\n AND owner_id = ${decodedOwner.ownerId}\n AND deadline_at_millis <= ${nowMillis} AND ${continuation}\n ORDER BY deadline_at_millis, schedule_id\n LIMIT ${limit}\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n const decoded = yield* decodeRows(Schema.Array(ScheduleDueRow), rows, operation);\n\n return decoded.map((row) => ({\n owner: { tenantId: row.tenant_id, ownerId: row.owner_id },\n scheduleId: row.schedule_id,\n deadlineAtMillis: row.deadline_at_millis,\n }));\n });\n\n const nextDeadline: ScheduleStore[\"Service\"][\"nextDeadline\"] = Effect.fn(\n \"SqliteScheduleStore.nextDeadline\",\n )(function* (owner?: ScheduleOwner) {\n const operation = \"query next schedule deadline\";\n\n const decodedOwner =\n owner === undefined ? undefined : yield* decodeInput(operation, ScheduleOwner, owner);\n\n const rows =\n decodedOwner === undefined\n ? yield* sql<Record<string, unknown>>`\n SELECT MIN(deadline_at_millis) AS deadline_at_millis\n FROM effect_agent_schedules\n WHERE deadline_at_millis IS NOT NULL\n `.pipe(Effect.mapError(() => unavailable(operation)))\n : yield* sql<Record<string, unknown>>`\n SELECT MIN(deadline_at_millis) AS deadline_at_millis\n FROM effect_agent_schedules\n WHERE tenant_id = ${decodedOwner.tenantId}\n AND owner_id = ${decodedOwner.ownerId}\n AND deadline_at_millis IS NOT NULL\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n const decoded = yield* decodeRows(Schema.Array(ScheduleDeadlineRow), rows, operation);\n\n if (decoded.length !== 1) return yield* corrupt(operation);\n\n return decoded[0].deadline_at_millis;\n });\n\n return ScheduleStore.of({ insert, get, list, change, due, nextDeadline });\n});\n\n/** SQLite implementation of the atomic ScheduleStore port. */\nexport const scheduleStoreLayer: Layer.Layer<\n ScheduleStore,\n SqliteStorageInitializationError,\n SqliteStorageConfig | SqliteStorageFailpoint | SqlClientService.SqlClient\n> =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AAY,WAAW,eAAe,KAAK;EAEtF,MAAM,OACJ,iBAAiB,KAAA,IACb,OAAO,GAA4B;;;;UAInC,KAAK,OAAO,eAAe,YAAY,SAAS,CAAC,CAAC,IAClD,OAAO,GAA4B;;;8BAGf,aAAa,SAAS;6BACvB,aAAa,QAAQ;;UAExC,KAAK,OAAO,eAAe,YAAY,SAAS,CAAC,CAAC;EAExD,MAAM,UAAU,OAAO,WAAW,OAAO,MAAM,mBAAmB,GAAG,MAAM,SAAS;EAEpF,IAAI,QAAQ,WAAW,GAAG,OAAO,OAAO,QAAQ,SAAS;EAEzD,OAAO,QAAQ,EAAE,CAAC;CACpB,CAAC;CAED,OAAO,cAAc,GAAG;EAAE;EAAQ;EAAK;EAAM;EAAQ;EAAK;CAAa,CAAC;AAC1E,CAAC;;AAGD,MAAa,qBAIT,MAAM,OAAO,aAAa,CAAC,CAAC,iBAAiB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Context, Schema } from "effect";
|
|
2
|
+
declare namespace SqliteStorageConfig_d_exports {
|
|
3
|
+
export { SqliteStorageConfig, SqliteStorageConfigValue };
|
|
4
|
+
}
|
|
5
|
+
declare const SqliteStorageConfigValue_base: Schema.Class<SqliteStorageConfigValue, Schema.Struct<{
|
|
6
|
+
readonly observationPollInterval: Schema.Int;
|
|
7
|
+
/** Bounded SQLITE_BUSY retry window for write-lock acquisition, in milliseconds. */
|
|
8
|
+
readonly busyTimeout: Schema.Int;
|
|
9
|
+
/**
|
|
10
|
+
* Submission ownership lease duration in milliseconds (D5). The lease is a liveness hint
|
|
11
|
+
* that makes an abandoned claim reclaimable; correctness never depends on it because every
|
|
12
|
+
* canonical append is fenced by producer epoch. Convenience layers default this to
|
|
13
|
+
* `DEFAULT_OWNERSHIP_LEASE_DURATION` from `@effect-agent/thread`.
|
|
14
|
+
*/
|
|
15
|
+
readonly ownershipLeaseDuration: Schema.Int;
|
|
16
|
+
/**
|
|
17
|
+
* Re-verify every stored payload and digest chain while opening the store. Per-operation
|
|
18
|
+
* Schema decoding and the digest chain already fail clearly on corrupt rows, so the full
|
|
19
|
+
* scan is an explicit opt-in integrity audit rather than a startup requirement.
|
|
20
|
+
*/
|
|
21
|
+
readonly verifyOnOpen: Schema.Boolean;
|
|
22
|
+
}>, {}>;
|
|
23
|
+
/**
|
|
24
|
+
* Validated construction configuration consumed by the SQLite storage Layer. The database
|
|
25
|
+
* identity itself belongs to the SqlClient Layer; duplicating it here could silently diverge
|
|
26
|
+
* from the connection actually in use.
|
|
27
|
+
*/
|
|
28
|
+
declare class SqliteStorageConfigValue extends SqliteStorageConfigValue_base {}
|
|
29
|
+
declare const SqliteStorageConfig_base: Context.ServiceClass<SqliteStorageConfig, "@effect-agent/storage-sqlite/SqliteStorageConfig", SqliteStorageConfigValue>;
|
|
30
|
+
/** Explicit SQLite storage configuration authority. */
|
|
31
|
+
declare class SqliteStorageConfig extends SqliteStorageConfig_base {}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { SqliteStorageConfig, SqliteStorageConfigValue, SqliteStorageConfig_d_exports as t };
|
|
34
|
+
//# sourceMappingURL=SqliteStorageConfig.d.mts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { Context, Schema } from "effect";
|
|
3
|
+
//#region src/SqliteStorageConfig.ts
|
|
4
|
+
var SqliteStorageConfig_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
SqliteStorageConfig: () => SqliteStorageConfig,
|
|
6
|
+
SqliteStorageConfigValue: () => SqliteStorageConfigValue
|
|
7
|
+
});
|
|
8
|
+
const ObservationPollInterval = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
9
|
+
const BusyTimeoutMillis = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
10
|
+
const OwnershipLeaseMillis = Schema.Int.check(Schema.isGreaterThan(0));
|
|
11
|
+
/**
|
|
12
|
+
* Validated construction configuration consumed by the SQLite storage Layer. The database
|
|
13
|
+
* identity itself belongs to the SqlClient Layer; duplicating it here could silently diverge
|
|
14
|
+
* from the connection actually in use.
|
|
15
|
+
*/
|
|
16
|
+
var SqliteStorageConfigValue = class extends Schema.Class("@effect-agent/storage-sqlite/SqliteStorageConfigValue")({
|
|
17
|
+
observationPollInterval: ObservationPollInterval,
|
|
18
|
+
/** Bounded SQLITE_BUSY retry window for write-lock acquisition, in milliseconds. */
|
|
19
|
+
busyTimeout: BusyTimeoutMillis,
|
|
20
|
+
/**
|
|
21
|
+
* Submission ownership lease duration in milliseconds (D5). The lease is a liveness hint
|
|
22
|
+
* that makes an abandoned claim reclaimable; correctness never depends on it because every
|
|
23
|
+
* canonical append is fenced by producer epoch. Convenience layers default this to
|
|
24
|
+
* `DEFAULT_OWNERSHIP_LEASE_DURATION` from `@effect-agent/thread`.
|
|
25
|
+
*/
|
|
26
|
+
ownershipLeaseDuration: OwnershipLeaseMillis,
|
|
27
|
+
/**
|
|
28
|
+
* Re-verify every stored payload and digest chain while opening the store. Per-operation
|
|
29
|
+
* Schema decoding and the digest chain already fail clearly on corrupt rows, so the full
|
|
30
|
+
* scan is an explicit opt-in integrity audit rather than a startup requirement.
|
|
31
|
+
*/
|
|
32
|
+
verifyOnOpen: Schema.Boolean
|
|
33
|
+
}) {};
|
|
34
|
+
/** Explicit SQLite storage configuration authority. */
|
|
35
|
+
var SqliteStorageConfig = class extends Context.Service()("@effect-agent/storage-sqlite/SqliteStorageConfig") {};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { SqliteStorageConfig, SqliteStorageConfigValue, SqliteStorageConfig_exports as t };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=SqliteStorageConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqliteStorageConfig.mjs","names":[],"sources":["../src/SqliteStorageConfig.ts"],"sourcesContent":["import { Context, Schema } from \"effect\";\n\nconst ObservationPollInterval = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));\nconst BusyTimeoutMillis = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));\nconst OwnershipLeaseMillis = Schema.Int.check(Schema.isGreaterThan(0));\n\n/**\n * Validated construction configuration consumed by the SQLite storage Layer. The database\n * identity itself belongs to the SqlClient Layer; duplicating it here could silently diverge\n * from the connection actually in use.\n */\nexport class SqliteStorageConfigValue extends Schema.Class<SqliteStorageConfigValue>(\n \"@effect-agent/storage-sqlite/SqliteStorageConfigValue\",\n)({\n observationPollInterval: ObservationPollInterval,\n /** Bounded SQLITE_BUSY retry window for write-lock acquisition, in milliseconds. */\n busyTimeout: BusyTimeoutMillis,\n /**\n * Submission ownership lease duration in milliseconds (D5). The lease is a liveness hint\n * that makes an abandoned claim reclaimable; correctness never depends on it because every\n * canonical append is fenced by producer epoch. Convenience layers default this to\n * `DEFAULT_OWNERSHIP_LEASE_DURATION` from `@effect-agent/thread`.\n */\n ownershipLeaseDuration: OwnershipLeaseMillis,\n /**\n * Re-verify every stored payload and digest chain while opening the store. Per-operation\n * Schema decoding and the digest chain already fail clearly on corrupt rows, so the full\n * scan is an explicit opt-in integrity audit rather than a startup requirement.\n */\n verifyOnOpen: Schema.Boolean,\n}) {}\n\n/** Explicit SQLite storage configuration authority. */\nexport class SqliteStorageConfig extends Context.Service<\n SqliteStorageConfig,\n SqliteStorageConfigValue\n>()(\"@effect-agent/storage-sqlite/SqliteStorageConfig\") {}\n"],"mappings":";;;;;;;AAEA,MAAM,0BAA0B,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;AACjF,MAAM,oBAAoB,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;AAC3E,MAAM,uBAAuB,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;;;;;;AAOrE,IAAa,2BAAb,cAA8C,OAAO,MACnD,uDACF,CAAC,CAAC;CACA,yBAAyB;;CAEzB,aAAa;;;;;;;CAOb,wBAAwB;;;;;;CAMxB,cAAc,OAAO;AACvB,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa,sBAAb,cAAyC,QAAQ,QAG/C,CAAC,CAAC,kDAAkD,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
declare namespace SqliteStorageError_d_exports {
|
|
3
|
+
export { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteLedgerError, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointError, SqliteStorageFailpointLocation, SqliteWriteContention };
|
|
4
|
+
}
|
|
5
|
+
declare const SqliteStorageCompatibilityError_base: Schema.Class<SqliteStorageCompatibilityError, Schema.TaggedStruct<"SqliteStorageCompatibilityError", {
|
|
6
|
+
readonly actualVersion: Schema.Int;
|
|
7
|
+
readonly message: Schema.String;
|
|
8
|
+
readonly supportedVersion: Schema.Int;
|
|
9
|
+
}>, import("effect/Cause").YieldableError>;
|
|
10
|
+
/** The SQLite file uses a private-development format this adapter cannot read. */
|
|
11
|
+
declare class SqliteStorageCompatibilityError extends SqliteStorageCompatibilityError_base {}
|
|
12
|
+
declare const SqliteStorageCorruptionError_base: Schema.Class<SqliteStorageCorruptionError, Schema.TaggedStruct<"SqliteStorageCorruptionError", {
|
|
13
|
+
readonly message: Schema.String;
|
|
14
|
+
readonly rowKey: Schema.String;
|
|
15
|
+
readonly table: Schema.String;
|
|
16
|
+
}>, import("effect/Cause").YieldableError>;
|
|
17
|
+
/** Stored bytes failed the current Schema and cannot be used as recovery truth. */
|
|
18
|
+
declare class SqliteStorageCorruptionError extends SqliteStorageCorruptionError_base {}
|
|
19
|
+
declare const SqliteStorageError_base: Schema.Class<SqliteStorageError, Schema.TaggedStruct<"SqliteStorageError", {
|
|
20
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
21
|
+
readonly message: Schema.String;
|
|
22
|
+
readonly operation: Schema.String;
|
|
23
|
+
}>, import("effect/Cause").YieldableError>;
|
|
24
|
+
/** SQLite infrastructure failed while opening or operating the store. */
|
|
25
|
+
declare class SqliteStorageError extends SqliteStorageError_base {}
|
|
26
|
+
declare const SqliteLedgerError_base: Schema.Class<SqliteLedgerError, Schema.TaggedStruct<"SqliteLedgerError", {
|
|
27
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
28
|
+
readonly message: Schema.String;
|
|
29
|
+
readonly operation: Schema.String;
|
|
30
|
+
}>, import("effect/Cause").YieldableError>;
|
|
31
|
+
/**
|
|
32
|
+
* SQLite infrastructure failed while operating the Submission Ledger. Surfaces at the
|
|
33
|
+
* SubmissionLedger port as the typed `LedgerError` with this error preserved as its cause,
|
|
34
|
+
* so the adapter-level tag is never erased.
|
|
35
|
+
*/
|
|
36
|
+
declare class SqliteLedgerError extends SqliteLedgerError_base {}
|
|
37
|
+
declare const SqliteAppendConflict_base: Schema.Class<SqliteAppendConflict, Schema.TaggedStruct<"SqliteAppendConflict", {
|
|
38
|
+
readonly message: Schema.String;
|
|
39
|
+
readonly reason: Schema.Literals<readonly ["batch-digest", "record-identity", "tail"]>;
|
|
40
|
+
readonly actualTailSequence: Schema.optionalKey<Schema.brand<Schema.Natural, "@effect-agent/thread/CanonicalSequence">>;
|
|
41
|
+
readonly actualTailDigest: Schema.optionalKey<Schema.String>;
|
|
42
|
+
}>, import("effect/Cause").YieldableError>;
|
|
43
|
+
/**
|
|
44
|
+
* A canonical batch retry conflicts with existing append state. Tail conflicts carry the
|
|
45
|
+
* actual committed tail as a diagnostic resume hint.
|
|
46
|
+
*/
|
|
47
|
+
declare class SqliteAppendConflict extends SqliteAppendConflict_base {}
|
|
48
|
+
declare const SqliteFenceRejected_base: Schema.Class<SqliteFenceRejected, Schema.TaggedStruct<"SqliteFenceRejected", {
|
|
49
|
+
readonly actualEpoch: Schema.brand<Schema.Natural, "@effect-agent/thread/ProducerEpoch">;
|
|
50
|
+
readonly message: Schema.String;
|
|
51
|
+
readonly producerEpoch: Schema.brand<Schema.Natural, "@effect-agent/thread/ProducerEpoch">;
|
|
52
|
+
}>, import("effect/Cause").YieldableError>;
|
|
53
|
+
/**
|
|
54
|
+
* A producer epoch does not match the Thread's current writer registration. Appends
|
|
55
|
+
* require the exact registered epoch, so both older and newer unregistered epochs are fenced;
|
|
56
|
+
* a newer epoch takes over by materializing first.
|
|
57
|
+
*/
|
|
58
|
+
declare class SqliteFenceRejected extends SqliteFenceRejected_base {}
|
|
59
|
+
declare const SqliteWriteContention_base: Schema.Class<SqliteWriteContention, Schema.TaggedStruct<"SqliteWriteContention", {
|
|
60
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
61
|
+
readonly message: Schema.String;
|
|
62
|
+
readonly operation: Schema.String;
|
|
63
|
+
}>, import("effect/Cause").YieldableError>;
|
|
64
|
+
/**
|
|
65
|
+
* A write transaction could not acquire the SQLite write lock within the configured busy
|
|
66
|
+
* timeout (SQLITE_BUSY / SQLITE_LOCKED). Another transiently coexisting owner is writing;
|
|
67
|
+
* the operation did not mutate canonical state and is safe to retry.
|
|
68
|
+
*/
|
|
69
|
+
declare class SqliteWriteContention extends SqliteWriteContention_base {}
|
|
70
|
+
declare const SqliteCheckpointConflict_base: Schema.Class<SqliteCheckpointConflict, Schema.TaggedStruct<"SqliteCheckpointConflict", {
|
|
71
|
+
readonly message: Schema.String;
|
|
72
|
+
}>, import("effect/Cause").YieldableError>;
|
|
73
|
+
/** A checkpoint conflicts with a previously stored checkpoint at the same offset. */
|
|
74
|
+
declare class SqliteCheckpointConflict extends SqliteCheckpointConflict_base {}
|
|
75
|
+
declare const SqliteStorageFailpointLocation: Schema.Literals<readonly ["upgrade:before-mutation", "upgrade:after-mutation", "upgrade:before-version", "upgrade:after-version", "materialize:before", "materialize:after", "append:before", "append:after-batch-insert", "append:after-record-insert", "append:after-tail-update", "append:after", "export:after-thread-read", "save-checkpoint:before", "save-checkpoint:after", "ledger:admit:before", "ledger:admit:after", "ledger:mark-ready:before", "ledger:mark-ready:after", "ledger:claim:before", "ledger:claim:after", "ledger:mark-input-applied:before", "ledger:mark-input-applied:after", "ledger:renew:before", "ledger:renew:after", "ledger:reserve-settlement:before", "ledger:reserve-settlement:after", "ledger:finalize-settlement:before", "ledger:finalize-settlement:after", "ledger:request-abort:before", "ledger:request-abort:after", "ledger:release:before", "ledger:release:after", "ledger:claim-joining:before", "ledger:claim-joining:after", "ledger:mark-joined:before", "ledger:mark-joined:after", "ledger:revert-joining:before", "ledger:revert-joining:after", "ledger:suspend:before", "ledger:suspend:after", "ledger:approval-decision:before", "ledger:approval-decision:after", "ledger:mark-unknown:before", "ledger:mark-unknown:after", "ledger:unknown-resolution:before", "ledger:unknown-resolution:after", "ledger:child-reservation:before", "ledger:child-reservation:after", "ledger:child-attach:before", "ledger:child-attach:after", "ledger:child-release-pending:before", "ledger:child-release-pending:after", "ledger:child-release:before", "ledger:child-release:after", "ledger:child-settled:before", "ledger:child-settled:after"]>;
|
|
76
|
+
type SqliteStorageFailpointLocation = typeof SqliteStorageFailpointLocation.Type;
|
|
77
|
+
declare const SqliteStorageFailpointError_base: Schema.Class<SqliteStorageFailpointError, Schema.TaggedStruct<"SqliteStorageFailpointError", {
|
|
78
|
+
readonly location: Schema.Literals<readonly ["upgrade:before-mutation", "upgrade:after-mutation", "upgrade:before-version", "upgrade:after-version", "materialize:before", "materialize:after", "append:before", "append:after-batch-insert", "append:after-record-insert", "append:after-tail-update", "append:after", "export:after-thread-read", "save-checkpoint:before", "save-checkpoint:after", "ledger:admit:before", "ledger:admit:after", "ledger:mark-ready:before", "ledger:mark-ready:after", "ledger:claim:before", "ledger:claim:after", "ledger:mark-input-applied:before", "ledger:mark-input-applied:after", "ledger:renew:before", "ledger:renew:after", "ledger:reserve-settlement:before", "ledger:reserve-settlement:after", "ledger:finalize-settlement:before", "ledger:finalize-settlement:after", "ledger:request-abort:before", "ledger:request-abort:after", "ledger:release:before", "ledger:release:after", "ledger:claim-joining:before", "ledger:claim-joining:after", "ledger:mark-joined:before", "ledger:mark-joined:after", "ledger:revert-joining:before", "ledger:revert-joining:after", "ledger:suspend:before", "ledger:suspend:after", "ledger:approval-decision:before", "ledger:approval-decision:after", "ledger:mark-unknown:before", "ledger:mark-unknown:after", "ledger:unknown-resolution:before", "ledger:unknown-resolution:after", "ledger:child-reservation:before", "ledger:child-reservation:after", "ledger:child-attach:before", "ledger:child-attach:after", "ledger:child-release-pending:before", "ledger:child-release-pending:after", "ledger:child-release:before", "ledger:child-release:after", "ledger:child-settled:before", "ledger:child-settled:after"]>;
|
|
79
|
+
}>, import("effect/Cause").YieldableError>;
|
|
80
|
+
/** Deterministic test-only fault or pause injected at a SQLite operation boundary. */
|
|
81
|
+
declare class SqliteStorageFailpointError extends SqliteStorageFailpointError_base {
|
|
82
|
+
get message(): string;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { SqliteStorageCompatibilityError as a, SqliteStorageError_d_exports as c, SqliteWriteContention as d, SqliteLedgerError as i, SqliteStorageFailpointError as l, SqliteCheckpointConflict as n, SqliteStorageCorruptionError as o, SqliteFenceRejected as r, SqliteStorageError as s, SqliteAppendConflict as t, SqliteStorageFailpointLocation as u };
|
|
86
|
+
//# sourceMappingURL=SqliteStorageError-CzKmwCLl.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SqliteStorageCompatibilityError, d as SqliteWriteContention, i as SqliteLedgerError, l as SqliteStorageFailpointError, n as SqliteCheckpointConflict, o as SqliteStorageCorruptionError, r as SqliteFenceRejected, s as SqliteStorageError, t as SqliteAppendConflict, u as SqliteStorageFailpointLocation } from "./SqliteStorageError-CzKmwCLl.mjs";
|
|
2
|
+
export { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteLedgerError, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointError, SqliteStorageFailpointLocation, SqliteWriteContention };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import { CanonicalSequence, ProducerEpoch } from "@effect-agent/thread/Records";
|
|
4
|
+
//#region src/SqliteStorageError.ts
|
|
5
|
+
var SqliteStorageError_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
SqliteAppendConflict: () => SqliteAppendConflict,
|
|
7
|
+
SqliteCheckpointConflict: () => SqliteCheckpointConflict,
|
|
8
|
+
SqliteFenceRejected: () => SqliteFenceRejected,
|
|
9
|
+
SqliteLedgerError: () => SqliteLedgerError,
|
|
10
|
+
SqliteStorageCompatibilityError: () => SqliteStorageCompatibilityError,
|
|
11
|
+
SqliteStorageCorruptionError: () => SqliteStorageCorruptionError,
|
|
12
|
+
SqliteStorageError: () => SqliteStorageError,
|
|
13
|
+
SqliteStorageFailpointError: () => SqliteStorageFailpointError,
|
|
14
|
+
SqliteStorageFailpointLocation: () => SqliteStorageFailpointLocation,
|
|
15
|
+
SqliteWriteContention: () => SqliteWriteContention
|
|
16
|
+
});
|
|
17
|
+
/** The SQLite file uses a private-development format this adapter cannot read. */
|
|
18
|
+
var SqliteStorageCompatibilityError = class extends Schema.TaggedError()("SqliteStorageCompatibilityError", {
|
|
19
|
+
actualVersion: Schema.Int,
|
|
20
|
+
message: Schema.String,
|
|
21
|
+
supportedVersion: Schema.Int
|
|
22
|
+
}) {};
|
|
23
|
+
/** Stored bytes failed the current Schema and cannot be used as recovery truth. */
|
|
24
|
+
var SqliteStorageCorruptionError = class extends Schema.TaggedError()("SqliteStorageCorruptionError", {
|
|
25
|
+
message: Schema.String,
|
|
26
|
+
rowKey: Schema.String,
|
|
27
|
+
table: Schema.String
|
|
28
|
+
}) {};
|
|
29
|
+
/** SQLite infrastructure failed while opening or operating the store. */
|
|
30
|
+
var SqliteStorageError = class extends Schema.TaggedError()("SqliteStorageError", {
|
|
31
|
+
cause: Schema.optionalKey(Schema.Defect()),
|
|
32
|
+
message: Schema.String,
|
|
33
|
+
operation: Schema.String
|
|
34
|
+
}) {};
|
|
35
|
+
/**
|
|
36
|
+
* SQLite infrastructure failed while operating the Submission Ledger. Surfaces at the
|
|
37
|
+
* SubmissionLedger port as the typed `LedgerError` with this error preserved as its cause,
|
|
38
|
+
* so the adapter-level tag is never erased.
|
|
39
|
+
*/
|
|
40
|
+
var SqliteLedgerError = class extends Schema.TaggedError()("SqliteLedgerError", {
|
|
41
|
+
cause: Schema.optionalKey(Schema.Defect()),
|
|
42
|
+
message: Schema.String,
|
|
43
|
+
operation: Schema.String
|
|
44
|
+
}) {};
|
|
45
|
+
/**
|
|
46
|
+
* A canonical batch retry conflicts with existing append state. Tail conflicts carry the
|
|
47
|
+
* actual committed tail as a diagnostic resume hint.
|
|
48
|
+
*/
|
|
49
|
+
var SqliteAppendConflict = class extends Schema.TaggedError()("SqliteAppendConflict", {
|
|
50
|
+
message: Schema.String,
|
|
51
|
+
reason: Schema.Literals([
|
|
52
|
+
"batch-digest",
|
|
53
|
+
"record-identity",
|
|
54
|
+
"tail"
|
|
55
|
+
]),
|
|
56
|
+
actualTailSequence: Schema.optionalKey(CanonicalSequence),
|
|
57
|
+
actualTailDigest: Schema.optionalKey(Schema.String)
|
|
58
|
+
}) {};
|
|
59
|
+
/**
|
|
60
|
+
* A producer epoch does not match the Thread's current writer registration. Appends
|
|
61
|
+
* require the exact registered epoch, so both older and newer unregistered epochs are fenced;
|
|
62
|
+
* a newer epoch takes over by materializing first.
|
|
63
|
+
*/
|
|
64
|
+
var SqliteFenceRejected = class extends Schema.TaggedError()("SqliteFenceRejected", {
|
|
65
|
+
actualEpoch: ProducerEpoch,
|
|
66
|
+
message: Schema.String,
|
|
67
|
+
producerEpoch: ProducerEpoch
|
|
68
|
+
}) {};
|
|
69
|
+
/**
|
|
70
|
+
* A write transaction could not acquire the SQLite write lock within the configured busy
|
|
71
|
+
* timeout (SQLITE_BUSY / SQLITE_LOCKED). Another transiently coexisting owner is writing;
|
|
72
|
+
* the operation did not mutate canonical state and is safe to retry.
|
|
73
|
+
*/
|
|
74
|
+
var SqliteWriteContention = class extends Schema.TaggedError()("SqliteWriteContention", {
|
|
75
|
+
cause: Schema.optionalKey(Schema.Defect()),
|
|
76
|
+
message: Schema.String,
|
|
77
|
+
operation: Schema.String
|
|
78
|
+
}) {};
|
|
79
|
+
/** A checkpoint conflicts with a previously stored checkpoint at the same offset. */
|
|
80
|
+
var SqliteCheckpointConflict = class extends Schema.TaggedError()("SqliteCheckpointConflict", { message: Schema.String }) {};
|
|
81
|
+
const SqliteStorageFailpointLocation = Schema.Literals([
|
|
82
|
+
"upgrade:before-mutation",
|
|
83
|
+
"upgrade:after-mutation",
|
|
84
|
+
"upgrade:before-version",
|
|
85
|
+
"upgrade:after-version",
|
|
86
|
+
"materialize:before",
|
|
87
|
+
"materialize:after",
|
|
88
|
+
"append:before",
|
|
89
|
+
"append:after-batch-insert",
|
|
90
|
+
"append:after-record-insert",
|
|
91
|
+
"append:after-tail-update",
|
|
92
|
+
"append:after",
|
|
93
|
+
"export:after-thread-read",
|
|
94
|
+
"save-checkpoint:before",
|
|
95
|
+
"save-checkpoint:after",
|
|
96
|
+
"ledger:admit:before",
|
|
97
|
+
"ledger:admit:after",
|
|
98
|
+
"ledger:mark-ready:before",
|
|
99
|
+
"ledger:mark-ready:after",
|
|
100
|
+
"ledger:claim:before",
|
|
101
|
+
"ledger:claim:after",
|
|
102
|
+
"ledger:mark-input-applied:before",
|
|
103
|
+
"ledger:mark-input-applied:after",
|
|
104
|
+
"ledger:renew:before",
|
|
105
|
+
"ledger:renew:after",
|
|
106
|
+
"ledger:reserve-settlement:before",
|
|
107
|
+
"ledger:reserve-settlement:after",
|
|
108
|
+
"ledger:finalize-settlement:before",
|
|
109
|
+
"ledger:finalize-settlement:after",
|
|
110
|
+
"ledger:request-abort:before",
|
|
111
|
+
"ledger:request-abort:after",
|
|
112
|
+
"ledger:release:before",
|
|
113
|
+
"ledger:release:after",
|
|
114
|
+
"ledger:claim-joining:before",
|
|
115
|
+
"ledger:claim-joining:after",
|
|
116
|
+
"ledger:mark-joined:before",
|
|
117
|
+
"ledger:mark-joined:after",
|
|
118
|
+
"ledger:revert-joining:before",
|
|
119
|
+
"ledger:revert-joining:after",
|
|
120
|
+
"ledger:suspend:before",
|
|
121
|
+
"ledger:suspend:after",
|
|
122
|
+
"ledger:approval-decision:before",
|
|
123
|
+
"ledger:approval-decision:after",
|
|
124
|
+
"ledger:mark-unknown:before",
|
|
125
|
+
"ledger:mark-unknown:after",
|
|
126
|
+
"ledger:unknown-resolution:before",
|
|
127
|
+
"ledger:unknown-resolution:after",
|
|
128
|
+
"ledger:child-reservation:before",
|
|
129
|
+
"ledger:child-reservation:after",
|
|
130
|
+
"ledger:child-attach:before",
|
|
131
|
+
"ledger:child-attach:after",
|
|
132
|
+
"ledger:child-release-pending:before",
|
|
133
|
+
"ledger:child-release-pending:after",
|
|
134
|
+
"ledger:child-release:before",
|
|
135
|
+
"ledger:child-release:after",
|
|
136
|
+
"ledger:child-settled:before",
|
|
137
|
+
"ledger:child-settled:after"
|
|
138
|
+
]);
|
|
139
|
+
/** Deterministic test-only fault or pause injected at a SQLite operation boundary. */
|
|
140
|
+
var SqliteStorageFailpointError = class extends Schema.TaggedError()("SqliteStorageFailpointError", { location: SqliteStorageFailpointLocation }) {
|
|
141
|
+
get message() {
|
|
142
|
+
return `Injected SQLite storage failure at ${this.location}.`;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
//#endregion
|
|
146
|
+
export { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteLedgerError, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointError, SqliteStorageFailpointLocation, SqliteWriteContention, SqliteStorageError_exports as t };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=SqliteStorageError.mjs.map
|