@yielded/agent-storage-cloudflare 0.1.0-beta.166 → 0.1.0-beta.168
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/DoMemoryStore.mjs +1 -1
- package/dist/DoMessageDeliveryStore.d.mts +1 -1
- package/dist/DoMessageDeliveryStore.mjs +3 -2
- package/dist/DoMessageDeliveryStore.mjs.map +1 -1
- package/dist/DoScheduleStore.mjs +16 -37
- package/dist/DoScheduleStore.mjs.map +1 -1
- package/dist/DoStorageConfig.d.mts +2 -10
- package/dist/DoStorageConfig.mjs +2 -11
- package/dist/DoStorageConfig.mjs.map +1 -1
- package/dist/{DoStorageError-CGuAfSwF.d.mts → DoStorageError-CxjMnzUA.d.mts} +7 -18
- package/dist/DoStorageError.d.mts +2 -2
- package/dist/DoStorageError.mjs +14 -30
- package/dist/DoStorageError.mjs.map +1 -1
- package/dist/DoStorageFailpoint.d.mts +1 -1
- package/dist/DoStorageFailpointTesting.d.mts +1 -1
- package/dist/{DoStorageVersion-iNSyi3cJ.d.mts → DoStorageVersion-DTFoLglB.d.mts} +3 -4
- package/dist/DoStorageVersion.d.mts +1 -1
- package/dist/DoStorageVersion.mjs +2 -2
- package/dist/DoStorageVersion.mjs.map +1 -1
- package/dist/DoSubmissionLedger.d.mts +7 -5
- package/dist/DoSubmissionLedger.mjs +378 -528
- package/dist/DoSubmissionLedger.mjs.map +1 -1
- package/dist/DoSubscriptionStore.mjs +5 -24
- package/dist/DoSubscriptionStore.mjs.map +1 -1
- package/dist/{DoThreadStore-D_83OjCH.d.mts → DoThreadStore-Bd4fTns3.d.mts} +17 -18
- package/dist/DoThreadStore-CwBvTLoq.mjs +468 -0
- package/dist/DoThreadStore-CwBvTLoq.mjs.map +1 -0
- package/dist/DoThreadStore.d.mts +2 -2
- package/dist/DoThreadStore.mjs +4 -529
- package/dist/MemoryProtocol.mjs +3 -3
- package/dist/MemoryProtocol.mjs.map +1 -1
- package/dist/PortProtocol.d.mts +11727 -3410
- package/dist/PortProtocol.mjs +103 -15
- package/dist/PortProtocol.mjs.map +1 -1
- package/dist/PortRouting.d.mts +14 -9
- package/dist/PortRouting.mjs +155 -29
- package/dist/PortRouting.mjs.map +1 -1
- package/dist/do-journal-Cawnsetj.mjs +761 -0
- package/dist/do-journal-Cawnsetj.mjs.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/migrations-D_EP3KYf.mjs +148 -0
- package/dist/migrations-D_EP3KYf.mjs.map +1 -0
- package/dist/{owned-state-DHm2aRXx.mjs → owned-state-BHzUi0eb.mjs} +50 -19
- package/dist/owned-state-BHzUi0eb.mjs.map +1 -0
- package/package.json +1 -1
- package/src/DoMessageDeliveryStore.ts +2 -1
- package/src/DoScheduleStore.ts +19 -59
- package/src/DoStorageConfig.ts +2 -11
- package/src/DoStorageError.ts +3 -26
- package/src/DoStorageVersion.ts +1 -1
- package/src/DoSubmissionLedger.ts +1806 -2030
- package/src/DoSubscriptionStore.ts +5 -47
- package/src/DoThreadStore.ts +276 -622
- package/src/MemoryProtocol.ts +3 -3
- package/src/PortProtocol.ts +198 -12
- package/src/PortRouting.ts +527 -108
- package/src/internal/canonical-append.ts +15 -0
- package/src/internal/do-journal.ts +548 -1440
- package/src/internal/migrations.ts +184 -287
- package/src/internal/owned-state.ts +81 -30
- package/src/internal/prompt-checkpoint.ts +158 -0
- package/src/internal/storage-span.ts +2 -5
- package/dist/DoThreadStore.mjs.map +0 -1
- package/dist/do-journal-DUhjZkOf.mjs +0 -1352
- package/dist/do-journal-DUhjZkOf.mjs.map +0 -1
- package/dist/migrations-DtKz_Gxr.mjs +0 -306
- package/dist/migrations-DtKz_Gxr.mjs.map +0 -1
- package/dist/owned-state-DHm2aRXx.mjs.map +0 -1
- package/src/internal/message-delivery-schema.ts +0 -24
- package/src/internal/recovery-checkpoint-schema.ts +0 -17
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { BrowserCrypto } from "@effect/platform-browser";
|
|
2
|
-
import { upgradeV2Subscriptions } from "@yielded/agent-storage-sql/sql-storage-v2-upgrade";
|
|
3
1
|
import { makeSqlSubscriptionStore } from "@yielded/agent-storage-sql/sql-subscription-store";
|
|
4
2
|
import {
|
|
5
3
|
SourcePartition,
|
|
@@ -66,7 +64,7 @@ const validate = <A, I>(schema: Schema.Codec<A, I>, value: unknown, code: string
|
|
|
66
64
|
const decodeRows = <A, I>(schema: Schema.Codec<A, I>, rows: unknown, code: string) =>
|
|
67
65
|
Schema.decodeUnknownEffect(Schema.Array(schema))(rows).pipe(Effect.mapError(() => corrupt(code)));
|
|
68
66
|
|
|
69
|
-
const initializeDoSubscriptionStore = Effect.
|
|
67
|
+
const initializeDoSubscriptionStore = Effect.fnUntraced(function* () {
|
|
70
68
|
const sql = yield* SqlClientService.SqlClient;
|
|
71
69
|
|
|
72
70
|
const names = yield* sql<Record<string, unknown>>`
|
|
@@ -153,44 +151,6 @@ const initializeDoSubscriptionStore = Effect.fn("DoSubscriptionStore.initialize"
|
|
|
153
151
|
|
|
154
152
|
const state = yield* decodeRows(StoreStateRow, rows, "read subscription storage version");
|
|
155
153
|
|
|
156
|
-
if (state.length === 1 && state[0].storage_version === 2) {
|
|
157
|
-
const failpoint = yield* SubscriptionFailpoint;
|
|
158
|
-
|
|
159
|
-
yield* sql
|
|
160
|
-
.withTransaction(
|
|
161
|
-
Effect.gen(function* () {
|
|
162
|
-
const current = yield* sql<{
|
|
163
|
-
storage_version: number;
|
|
164
|
-
}>`SELECT storage_version FROM effect_agent_subscription_store_state WHERE singleton=1`;
|
|
165
|
-
|
|
166
|
-
if (current.length === 1 && current[0].storage_version === 3) return;
|
|
167
|
-
if (current.length !== 1 || current[0].storage_version !== 2)
|
|
168
|
-
return yield* corrupt("subscription version changed during upgrade");
|
|
169
|
-
yield* upgradeV2Subscriptions(1_900_000);
|
|
170
|
-
yield* failpoint.hit("upgrade:before-version");
|
|
171
|
-
yield* sql`UPDATE effect_agent_subscription_store_state SET storage_version=3 WHERE singleton=1`;
|
|
172
|
-
yield* failpoint.hit("upgrade:after-version");
|
|
173
|
-
}),
|
|
174
|
-
)
|
|
175
|
-
.pipe(
|
|
176
|
-
Effect.provide(BrowserCrypto.layer),
|
|
177
|
-
Effect.catchTag("StorageUpgradeError", (error) =>
|
|
178
|
-
SubscriptionError.make({
|
|
179
|
-
reason: "corrupt",
|
|
180
|
-
code: "upgrade-v2-subscriptions",
|
|
181
|
-
cause: error,
|
|
182
|
-
}),
|
|
183
|
-
),
|
|
184
|
-
Effect.catchTag("SqlError", () => unavailable("upgrade v2 subscriptions")),
|
|
185
|
-
Effect.catchTag("SchemaError", () => corrupt("upgrade v2 subscription encoding")),
|
|
186
|
-
Effect.catchTag("SubscriptionFailpointError", () =>
|
|
187
|
-
unavailable("upgrade v2 subscriptions failpoint"),
|
|
188
|
-
),
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
154
|
if (state.length !== 1 || state[0].storage_version !== CURRENT_SUBSCRIPTION_STORE_VERSION)
|
|
195
155
|
return yield* corrupt(
|
|
196
156
|
state.length === 1
|
|
@@ -199,9 +159,7 @@ const initializeDoSubscriptionStore = Effect.fn("DoSubscriptionStore.initialize"
|
|
|
199
159
|
);
|
|
200
160
|
});
|
|
201
161
|
|
|
202
|
-
const makeSubscriptionStore = Effect.
|
|
203
|
-
owned: SourcePartition,
|
|
204
|
-
) {
|
|
162
|
+
const makeSubscriptionStore = Effect.fnUntraced(function* (owned: SourcePartition) {
|
|
205
163
|
const partition = yield* validate(SourcePartition, owned, "partition");
|
|
206
164
|
const sql = yield* SqlClientService.SqlClient;
|
|
207
165
|
const failpoint = yield* SubscriptionFailpoint;
|
|
@@ -214,7 +172,7 @@ const makeSubscriptionStore = Effect.fn("DoSubscriptionStore.make")(function* (
|
|
|
214
172
|
code: string,
|
|
215
173
|
) => effect.pipe(Effect.mapError(() => unavailable(code)));
|
|
216
174
|
|
|
217
|
-
const readIndexedDeadline = Effect.
|
|
175
|
+
const readIndexedDeadline = Effect.fnUntraced(function* () {
|
|
218
176
|
const scanRows = yield* query(
|
|
219
177
|
sql<Record<string, unknown>>`
|
|
220
178
|
SELECT event_scan_cursor, delivery_scan_cursor, recovery_scan_cursor FROM effect_agent_subscription_sequences
|
|
@@ -262,7 +220,7 @@ const makeSubscriptionStore = Effect.fn("DoSubscriptionStore.make")(function* (
|
|
|
262
220
|
return decoded[0].deadline;
|
|
263
221
|
});
|
|
264
222
|
|
|
265
|
-
const replaceAlarm = Effect.
|
|
223
|
+
const replaceAlarm = Effect.fnUntraced(function* (
|
|
266
224
|
replace: DoSubscriptionReplaceAlarm,
|
|
267
225
|
deadlineAtMillis: number | null,
|
|
268
226
|
) {
|
|
@@ -299,7 +257,7 @@ const makeSubscriptionStore = Effect.fn("DoSubscriptionStore.make")(function* (
|
|
|
299
257
|
transaction: transact,
|
|
300
258
|
});
|
|
301
259
|
|
|
302
|
-
const prearm = Effect.
|
|
260
|
+
const prearm = Effect.fnUntraced(function* (deadlineAtMillis: number) {
|
|
303
261
|
yield* transactions.run((replace) => replaceAlarm(replace, deadlineAtMillis));
|
|
304
262
|
yield* failpoint.hit("subscription:prearm:after");
|
|
305
263
|
});
|