@effect-agent/storage-sqlite 0.1.0-beta.45 → 0.1.0-beta.46
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/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/{sqlite-storage-failpoint-Cr0SXflP.d.mts → SqliteStorageError-W1oM5ka3.d.mts} +6 -15
- package/dist/SqliteStorageError.d.mts +2 -0
- package/dist/SqliteStorageError.mjs +144 -0
- package/dist/SqliteStorageError.mjs.map +1 -0
- package/dist/SqliteStorageFailpoint.d.mts +17 -0
- package/dist/{sqlite-storage-failpoint-DIwWk5dw.mjs → SqliteStorageFailpoint.mjs} +5 -3
- package/dist/SqliteStorageFailpoint.mjs.map +1 -0
- package/dist/{testing.d.mts → SqliteStorageFailpointTesting.d.mts} +3 -3
- package/dist/{testing.mjs → SqliteStorageFailpointTesting.mjs} +3 -3
- package/dist/SqliteStorageFailpointTesting.mjs.map +1 -0
- package/dist/SqliteStorageVersion-DwQbn4bw.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 +1656 -0
- package/dist/SqliteSubmissionLedger.mjs.map +1 -0
- package/dist/SqliteSubscriptionStore.d.mts +13 -0
- package/dist/SqliteSubscriptionStore.mjs +596 -0
- package/dist/SqliteSubscriptionStore.mjs.map +1 -0
- package/dist/SqliteThreadStore.d.mts +49 -0
- package/dist/SqliteThreadStore.mjs +422 -0
- package/dist/SqliteThreadStore.mjs.map +1 -0
- package/dist/index.d.mts +10 -108
- package/dist/index.mjs +10 -4265
- package/dist/migrations-B82C9A3r.mjs +293 -0
- package/dist/migrations-B82C9A3r.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/sqlite-journal-C5SZnSdC.mjs +656 -0
- package/dist/sqlite-journal-C5SZnSdC.mjs.map +1 -0
- package/package.json +1 -1
- package/src/{sqlite-activity-store.ts → SqliteActivityStore.ts} +2 -2
- package/src/{sqlite-schedule-store.ts → SqliteScheduleStore.ts} +9 -7
- package/src/{errors.ts → SqliteStorageError.ts} +1 -1
- package/src/{sqlite-storage-failpoint.ts → SqliteStorageFailpoint.ts} +4 -1
- package/src/{sqlite-storage-failpoint-testing.ts → SqliteStorageFailpointTesting.ts} +1 -1
- package/src/SqliteStorageVersion.ts +2 -0
- package/src/{sqlite-ledger.ts → SqliteSubmissionLedger.ts} +17 -15
- package/src/{sqlite-subscription-store.ts → SqliteSubscriptionStore.ts} +14 -12
- package/src/{sqlite-thread-store.ts → SqliteThreadStore.ts} +19 -21
- package/src/index.ts +9 -10
- package/src/{sqlite-journal.ts → internal/sqlite-journal.ts} +5 -5
- package/dist/index.mjs.map +0 -1
- package/dist/sqlite-storage-failpoint-DIwWk5dw.mjs.map +0 -1
- package/dist/testing.mjs.map +0 -1
- package/src/sqlite-memory-store.ts +0 -7
- package/src/testing.ts +0 -2
- /package/src/{sqlite-storage-config.ts → SqliteStorageConfig.ts} +0 -0
- /package/src/{migrations.ts → internal/migrations.ts} +0 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { a as initializeSqliteJournal } from "./sqlite-journal-C5SZnSdC.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> = Layer.effect(ScheduleStore)(makeScheduleStore);\n"],"mappings":";;;;;;;;AAiCA,MAAM,qBAAqB,OAAO,OAAO,MAAM,OAAO,YAAY,QAAgB,CAAC;AACnF,MAAM,iBAAiB,OAAO,OAAO,eAAe;AAEpD,IAAM,cAAN,cAA0B,OAAO,MAAmB,0CAA0C,CAAC,CAAC;CAC9F,WAAW,cAAc,OAAO;CAChC,UAAU,cAAc,OAAO;CAC/B,aAAa;CACb,oBAAoB;CACpB,aAAa;AACf,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAM,iBAAiB,OAAO,OAAO;CACnC,WAAW,cAAc,OAAO;CAChC,UAAU,cAAc,OAAO;CAC/B,aAAa;CACb,oBAAoB;AACtB,CAAC;AAED,IAAM,mBAAN,cAA+B,OAAO,MACpC,+CACF,CAAC,CAAC,EACA,gBAAgB,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC,EACnE,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAM,sBAAN,cAAkC,OAAO,MACvC,kDACF,CAAC,CAAC,EACA,oBAAoB,eACtB,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAM,eAAe,cACnB,qBAAqB,KAAK;CAAE;CAAW,QAAQ;AAAc,CAAC;AAEhE,MAAM,WAAW,cACf,qBAAqB,KAAK;CAAE;CAAW,QAAQ;AAAU,CAAC;AAE5D,MAAM,aAAa,OAAO,GAAG,gCAAgC,CAAC,CAAC,WAC7D,QACA,MACA,WAC2C;CAC3C,OAAO,OAAO,OAAO,oBAAoB,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,KACrD,OAAO,eAAe,QAAQ,SAAS,CAAC,CAC1C;AACF,CAAC;AAED,MAAM,eAAe,OAAO,GAAG,kCAAkC,CAAC,CAAC,WACjE,KACwD;CACxD,MAAM,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AAyD,OAAO,GACpE,kCACF,CAAC,CAAC,WAAW,OAAuB;EAClC,MAAM,YAAY;EAElB,MAAM,eACJ,UAAU,KAAA,IAAY,KAAA,IAAY,OAAO,YAAY,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"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
declare namespace SqliteStorageError_d_exports {
|
|
3
|
+
export { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteLedgerError, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointError, SqliteStorageFailpointLocation, SqliteWriteContention };
|
|
4
|
+
}
|
|
3
5
|
declare const SqliteStorageCompatibilityError_base: Schema.Class<SqliteStorageCompatibilityError, Schema.TaggedStruct<"SqliteStorageCompatibilityError", {
|
|
4
6
|
readonly actualVersion: Schema.Int;
|
|
5
7
|
readonly message: Schema.String;
|
|
@@ -80,16 +82,5 @@ declare class SqliteStorageFailpointError extends SqliteStorageFailpointError_ba
|
|
|
80
82
|
get message(): string;
|
|
81
83
|
}
|
|
82
84
|
//#endregion
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
declare const SqliteStorageFailpoint_base: Context.ServiceClass<SqliteStorageFailpoint, "@effect-agent/storage-sqlite/SqliteStorageFailpoint", {
|
|
86
|
-
readonly hit: SqliteStorageFailpointHandler;
|
|
87
|
-
}>;
|
|
88
|
-
/** Explicit fault-injection authority used at SQLite operation boundaries. */
|
|
89
|
-
declare class SqliteStorageFailpoint extends SqliteStorageFailpoint_base {
|
|
90
|
-
/** Production default: no fault injection. */
|
|
91
|
-
static readonly layer: Layer.Layer<SqliteStorageFailpoint, never, never>;
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
|
-
export { SqliteFenceRejected as a, SqliteStorageCorruptionError as c, SqliteStorageFailpointLocation as d, SqliteWriteContention as f, SqliteCheckpointConflict as i, SqliteStorageError as l, SqliteStorageFailpointHandler as n, SqliteLedgerError as o, SqliteAppendConflict as r, SqliteStorageCompatibilityError as s, SqliteStorageFailpoint as t, SqliteStorageFailpointError as u };
|
|
95
|
-
//# sourceMappingURL=sqlite-storage-failpoint-Cr0SXflP.d.mts.map
|
|
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-W1oM5ka3.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-W1oM5ka3.mjs";
|
|
2
|
+
export { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteLedgerError, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointError, SqliteStorageFailpointLocation, SqliteWriteContention };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { CanonicalSequence, ProducerEpoch } from "@effect-agent/thread/Records";
|
|
3
|
+
import { Schema } from "effect";
|
|
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
|
+
"materialize:before",
|
|
83
|
+
"materialize:after",
|
|
84
|
+
"append:before",
|
|
85
|
+
"append:after-batch-insert",
|
|
86
|
+
"append:after-record-insert",
|
|
87
|
+
"append:after-tail-update",
|
|
88
|
+
"append:after",
|
|
89
|
+
"export:after-thread-read",
|
|
90
|
+
"save-checkpoint:before",
|
|
91
|
+
"save-checkpoint:after",
|
|
92
|
+
"ledger:admit:before",
|
|
93
|
+
"ledger:admit:after",
|
|
94
|
+
"ledger:mark-ready:before",
|
|
95
|
+
"ledger:mark-ready:after",
|
|
96
|
+
"ledger:claim:before",
|
|
97
|
+
"ledger:claim:after",
|
|
98
|
+
"ledger:mark-input-applied:before",
|
|
99
|
+
"ledger:mark-input-applied:after",
|
|
100
|
+
"ledger:renew:before",
|
|
101
|
+
"ledger:renew:after",
|
|
102
|
+
"ledger:reserve-settlement:before",
|
|
103
|
+
"ledger:reserve-settlement:after",
|
|
104
|
+
"ledger:finalize-settlement:before",
|
|
105
|
+
"ledger:finalize-settlement:after",
|
|
106
|
+
"ledger:request-abort:before",
|
|
107
|
+
"ledger:request-abort:after",
|
|
108
|
+
"ledger:release:before",
|
|
109
|
+
"ledger:release:after",
|
|
110
|
+
"ledger:claim-joining:before",
|
|
111
|
+
"ledger:claim-joining:after",
|
|
112
|
+
"ledger:mark-joined:before",
|
|
113
|
+
"ledger:mark-joined:after",
|
|
114
|
+
"ledger:revert-joining:before",
|
|
115
|
+
"ledger:revert-joining:after",
|
|
116
|
+
"ledger:suspend:before",
|
|
117
|
+
"ledger:suspend:after",
|
|
118
|
+
"ledger:approval-decision:before",
|
|
119
|
+
"ledger:approval-decision:after",
|
|
120
|
+
"ledger:mark-unknown:before",
|
|
121
|
+
"ledger:mark-unknown:after",
|
|
122
|
+
"ledger:unknown-resolution:before",
|
|
123
|
+
"ledger:unknown-resolution:after",
|
|
124
|
+
"ledger:child-reservation:before",
|
|
125
|
+
"ledger:child-reservation:after",
|
|
126
|
+
"ledger:child-attach:before",
|
|
127
|
+
"ledger:child-attach:after",
|
|
128
|
+
"ledger:child-release-pending:before",
|
|
129
|
+
"ledger:child-release-pending:after",
|
|
130
|
+
"ledger:child-release:before",
|
|
131
|
+
"ledger:child-release:after",
|
|
132
|
+
"ledger:child-settled:before",
|
|
133
|
+
"ledger:child-settled:after"
|
|
134
|
+
]);
|
|
135
|
+
/** Deterministic test-only fault or pause injected at a SQLite operation boundary. */
|
|
136
|
+
var SqliteStorageFailpointError = class extends Schema.TaggedError()("SqliteStorageFailpointError", { location: SqliteStorageFailpointLocation }) {
|
|
137
|
+
get message() {
|
|
138
|
+
return `Injected SQLite storage failure at ${this.location}.`;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
//#endregion
|
|
142
|
+
export { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteLedgerError, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointError, SqliteStorageFailpointLocation, SqliteWriteContention, SqliteStorageError_exports as t };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=SqliteStorageError.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqliteStorageError.mjs","names":[],"sources":["../src/SqliteStorageError.ts"],"sourcesContent":["import { CanonicalSequence, ProducerEpoch } from \"@effect-agent/thread/Records\";\nimport { Schema } from \"effect\";\n\n/** The SQLite file uses a private-development format this adapter cannot read. */\nexport class SqliteStorageCompatibilityError extends Schema.TaggedError<SqliteStorageCompatibilityError>()(\n \"SqliteStorageCompatibilityError\",\n {\n actualVersion: Schema.Int,\n message: Schema.String,\n supportedVersion: Schema.Int,\n },\n) {}\n\n/** Stored bytes failed the current Schema and cannot be used as recovery truth. */\nexport class SqliteStorageCorruptionError extends Schema.TaggedError<SqliteStorageCorruptionError>()(\n \"SqliteStorageCorruptionError\",\n {\n message: Schema.String,\n rowKey: Schema.String,\n table: Schema.String,\n },\n) {}\n\n/** SQLite infrastructure failed while opening or operating the store. */\nexport class SqliteStorageError extends Schema.TaggedError<SqliteStorageError>()(\n \"SqliteStorageError\",\n {\n cause: Schema.optionalKey(Schema.Defect()),\n message: Schema.String,\n operation: Schema.String,\n },\n) {}\n\n/**\n * SQLite infrastructure failed while operating the Submission Ledger. Surfaces at the\n * SubmissionLedger port as the typed `LedgerError` with this error preserved as its cause,\n * so the adapter-level tag is never erased.\n */\nexport class SqliteLedgerError extends Schema.TaggedError<SqliteLedgerError>()(\n \"SqliteLedgerError\",\n {\n cause: Schema.optionalKey(Schema.Defect()),\n message: Schema.String,\n operation: Schema.String,\n },\n) {}\n\n/**\n * A canonical batch retry conflicts with existing append state. Tail conflicts carry the\n * actual committed tail as a diagnostic resume hint.\n */\nexport class SqliteAppendConflict extends Schema.TaggedError<SqliteAppendConflict>()(\n \"SqliteAppendConflict\",\n {\n message: Schema.String,\n reason: Schema.Literals([\"batch-digest\", \"record-identity\", \"tail\"]),\n actualTailSequence: Schema.optionalKey(CanonicalSequence),\n actualTailDigest: Schema.optionalKey(Schema.String),\n },\n) {}\n\n/**\n * A producer epoch does not match the Thread's current writer registration. Appends\n * require the exact registered epoch, so both older and newer unregistered epochs are fenced;\n * a newer epoch takes over by materializing first.\n */\nexport class SqliteFenceRejected extends Schema.TaggedError<SqliteFenceRejected>()(\n \"SqliteFenceRejected\",\n {\n actualEpoch: ProducerEpoch,\n message: Schema.String,\n producerEpoch: ProducerEpoch,\n },\n) {}\n\n/**\n * A write transaction could not acquire the SQLite write lock within the configured busy\n * timeout (SQLITE_BUSY / SQLITE_LOCKED). Another transiently coexisting owner is writing;\n * the operation did not mutate canonical state and is safe to retry.\n */\nexport class SqliteWriteContention extends Schema.TaggedError<SqliteWriteContention>()(\n \"SqliteWriteContention\",\n {\n cause: Schema.optionalKey(Schema.Defect()),\n message: Schema.String,\n operation: Schema.String,\n },\n) {}\n\n/** A checkpoint conflicts with a previously stored checkpoint at the same offset. */\nexport class SqliteCheckpointConflict extends Schema.TaggedError<SqliteCheckpointConflict>()(\n \"SqliteCheckpointConflict\",\n {\n message: Schema.String,\n },\n) {}\n\nexport const SqliteStorageFailpointLocation = Schema.Literals([\n \"materialize:before\",\n \"materialize:after\",\n \"append:before\",\n \"append:after-batch-insert\",\n \"append:after-record-insert\",\n \"append:after-tail-update\",\n \"append:after\",\n \"export:after-thread-read\",\n \"save-checkpoint:before\",\n \"save-checkpoint:after\",\n \"ledger:admit:before\",\n \"ledger:admit:after\",\n \"ledger:mark-ready:before\",\n \"ledger:mark-ready:after\",\n \"ledger:claim:before\",\n \"ledger:claim:after\",\n \"ledger:mark-input-applied:before\",\n \"ledger:mark-input-applied:after\",\n \"ledger:renew:before\",\n \"ledger:renew:after\",\n \"ledger:reserve-settlement:before\",\n \"ledger:reserve-settlement:after\",\n \"ledger:finalize-settlement:before\",\n \"ledger:finalize-settlement:after\",\n \"ledger:request-abort:before\",\n \"ledger:request-abort:after\",\n \"ledger:release:before\",\n \"ledger:release:after\",\n \"ledger:claim-joining:before\",\n \"ledger:claim-joining:after\",\n \"ledger:mark-joined:before\",\n \"ledger:mark-joined:after\",\n \"ledger:revert-joining:before\",\n \"ledger:revert-joining:after\",\n \"ledger:suspend:before\",\n \"ledger:suspend:after\",\n \"ledger:approval-decision:before\",\n \"ledger:approval-decision:after\",\n \"ledger:mark-unknown:before\",\n \"ledger:mark-unknown:after\",\n \"ledger:unknown-resolution:before\",\n \"ledger:unknown-resolution:after\",\n \"ledger:child-reservation:before\",\n \"ledger:child-reservation:after\",\n \"ledger:child-attach:before\",\n \"ledger:child-attach:after\",\n \"ledger:child-release-pending:before\",\n \"ledger:child-release-pending:after\",\n \"ledger:child-release:before\",\n \"ledger:child-release:after\",\n \"ledger:child-settled:before\",\n \"ledger:child-settled:after\",\n]);\n\nexport type SqliteStorageFailpointLocation = typeof SqliteStorageFailpointLocation.Type;\n\n/** Deterministic test-only fault or pause injected at a SQLite operation boundary. */\nexport class SqliteStorageFailpointError extends Schema.TaggedError<SqliteStorageFailpointError>()(\n \"SqliteStorageFailpointError\",\n {\n location: SqliteStorageFailpointLocation,\n },\n) {\n override get message() {\n return `Injected SQLite storage failure at ${this.location}.`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAIA,IAAa,kCAAb,cAAqD,OAAO,YAA6C,CAAC,CACxG,mCACA;CACE,eAAe,OAAO;CACtB,SAAS,OAAO;CAChB,kBAAkB,OAAO;AAC3B,CACF,CAAC,CAAC,CAAC;;AAGH,IAAa,+BAAb,cAAkD,OAAO,YAA0C,CAAC,CAClG,gCACA;CACE,SAAS,OAAO;CAChB,QAAQ,OAAO;CACf,OAAO,OAAO;AAChB,CACF,CAAC,CAAC,CAAC;;AAGH,IAAa,qBAAb,cAAwC,OAAO,YAAgC,CAAC,CAC9E,sBACA;CACE,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;CACzC,SAAS,OAAO;CAChB,WAAW,OAAO;AACpB,CACF,CAAC,CAAC,CAAC;;;;;;AAOH,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA;CACE,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;CACzC,SAAS,OAAO;CAChB,WAAW,OAAO;AACpB,CACF,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAClF,wBACA;CACE,SAAS,OAAO;CAChB,QAAQ,OAAO,SAAS;EAAC;EAAgB;EAAmB;CAAM,CAAC;CACnE,oBAAoB,OAAO,YAAY,iBAAiB;CACxD,kBAAkB,OAAO,YAAY,OAAO,MAAM;AACpD,CACF,CAAC,CAAC,CAAC;;;;;;AAOH,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CACE,aAAa;CACb,SAAS,OAAO;CAChB,eAAe;AACjB,CACF,CAAC,CAAC,CAAC;;;;;;AAOH,IAAa,wBAAb,cAA2C,OAAO,YAAmC,CAAC,CACpF,yBACA;CACE,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;CACzC,SAAS,OAAO;CAChB,WAAW,OAAO;AACpB,CACF,CAAC,CAAC,CAAC;;AAGH,IAAa,2BAAb,cAA8C,OAAO,YAAsC,CAAC,CAC1F,4BACA,EACE,SAAS,OAAO,OAClB,CACF,CAAC,CAAC,CAAC;AAEH,MAAa,iCAAiC,OAAO,SAAS;CAC5D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAKD,IAAa,8BAAb,cAAiD,OAAO,YAAyC,CAAC,CAChG,+BACA,EACE,UAAU,+BACZ,CACF,CAAC,CAAC;CACA,IAAa,UAAU;EACrB,OAAO,sCAAsC,KAAK,SAAS;CAC7D;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { l as SqliteStorageFailpointError, u as SqliteStorageFailpointLocation } from "./SqliteStorageError-W1oM5ka3.mjs";
|
|
2
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
|
+
declare namespace SqliteStorageFailpoint_d_exports {
|
|
4
|
+
export { SqliteStorageFailpoint, SqliteStorageFailpointHandler };
|
|
5
|
+
}
|
|
6
|
+
type SqliteStorageFailpointHandler = (location: SqliteStorageFailpointLocation) => Effect.Effect<void, SqliteStorageFailpointError>;
|
|
7
|
+
declare const SqliteStorageFailpoint_base: Context.ServiceClass<SqliteStorageFailpoint, "@effect-agent/storage-sqlite/SqliteStorageFailpoint", {
|
|
8
|
+
readonly hit: SqliteStorageFailpointHandler;
|
|
9
|
+
}>;
|
|
10
|
+
/** Explicit fault-injection authority used at SQLite operation boundaries. */
|
|
11
|
+
declare class SqliteStorageFailpoint extends SqliteStorageFailpoint_base {
|
|
12
|
+
/** Production default: no fault injection. */
|
|
13
|
+
static readonly layer: Layer.Layer<SqliteStorageFailpoint, never, never>;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { SqliteStorageFailpoint, SqliteStorageFailpointHandler, SqliteStorageFailpoint_d_exports as t };
|
|
17
|
+
//# sourceMappingURL=SqliteStorageFailpoint.d.mts.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
1
2
|
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
//#region src/
|
|
3
|
+
//#region src/SqliteStorageFailpoint.ts
|
|
4
|
+
var SqliteStorageFailpoint_exports = /* @__PURE__ */ __exportAll({ SqliteStorageFailpoint: () => SqliteStorageFailpoint });
|
|
3
5
|
const noFailpoint = () => Effect.void;
|
|
4
6
|
/** Explicit fault-injection authority used at SQLite operation boundaries. */
|
|
5
7
|
var SqliteStorageFailpoint = class extends Context.Service()("@effect-agent/storage-sqlite/SqliteStorageFailpoint") {
|
|
@@ -7,6 +9,6 @@ var SqliteStorageFailpoint = class extends Context.Service()("@effect-agent/stor
|
|
|
7
9
|
static layer = Layer.succeed(this)({ hit: noFailpoint });
|
|
8
10
|
};
|
|
9
11
|
//#endregion
|
|
10
|
-
export { SqliteStorageFailpoint as t };
|
|
12
|
+
export { SqliteStorageFailpoint, SqliteStorageFailpoint_exports as t };
|
|
11
13
|
|
|
12
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=SqliteStorageFailpoint.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqliteStorageFailpoint.mjs","names":[],"sources":["../src/SqliteStorageFailpoint.ts"],"sourcesContent":["import { Context, Effect, Layer } from \"effect\";\n\nimport type {\n SqliteStorageFailpointError,\n SqliteStorageFailpointLocation,\n} from \"./SqliteStorageError.ts\";\n\nexport type SqliteStorageFailpointHandler = (\n location: SqliteStorageFailpointLocation,\n) => Effect.Effect<void, SqliteStorageFailpointError>;\n\nconst noFailpoint: SqliteStorageFailpointHandler = () => Effect.void;\n\n/** Explicit fault-injection authority used at SQLite operation boundaries. */\nexport class SqliteStorageFailpoint extends Context.Service<\n SqliteStorageFailpoint,\n {\n readonly hit: SqliteStorageFailpointHandler;\n }\n>()(\"@effect-agent/storage-sqlite/SqliteStorageFailpoint\") {\n /** Production default: no fault injection. */\n static readonly layer = Layer.succeed(this)({ hit: noFailpoint });\n}\n"],"mappings":";;;;AAWA,MAAM,oBAAmD,OAAO;;AAGhE,IAAa,yBAAb,cAA4C,QAAQ,QAKlD,CAAC,CAAC,qDAAqD,CAAC,CAAC;;CAEzD,OAAgB,QAAQ,MAAM,QAAQ,IAAI,CAAC,CAAC,EAAE,KAAK,YAAY,CAAC;AAClE"}
|