@effect-agent/storage-cloudflare 0.1.0-beta.8 → 0.1.0-beta.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/DoMemoryStore.d.mts +29 -0
  2. package/dist/DoMemoryStore.mjs +55 -0
  3. package/dist/DoMemoryStore.mjs.map +1 -0
  4. package/dist/DoMessageDeliveryStore.d.mts +17 -0
  5. package/dist/DoMessageDeliveryStore.mjs +32 -0
  6. package/dist/DoMessageDeliveryStore.mjs.map +1 -0
  7. package/dist/DoScheduleStore.d.mts +36 -0
  8. package/dist/DoScheduleStore.mjs +388 -0
  9. package/dist/DoScheduleStore.mjs.map +1 -0
  10. package/dist/DoStorageConfig.d.mts +45 -0
  11. package/dist/DoStorageConfig.mjs +52 -0
  12. package/dist/DoStorageConfig.mjs.map +1 -0
  13. package/dist/DoStorageError-Cmhvl4TQ.d.mts +98 -0
  14. package/dist/DoStorageError.d.mts +2 -0
  15. package/dist/DoStorageError.mjs +164 -0
  16. package/dist/DoStorageError.mjs.map +1 -0
  17. package/dist/DoStorageFailpoint.d.mts +17 -0
  18. package/dist/DoStorageFailpoint.mjs +14 -0
  19. package/dist/DoStorageFailpoint.mjs.map +1 -0
  20. package/dist/DoStorageFailpointTesting.d.mts +34 -0
  21. package/dist/DoStorageFailpointTesting.mjs +35 -0
  22. package/dist/DoStorageFailpointTesting.mjs.map +1 -0
  23. package/dist/DoStorageVersion-x5OOurvZ.d.mts +12 -0
  24. package/dist/DoStorageVersion.d.mts +2 -0
  25. package/dist/DoStorageVersion.mjs +8 -0
  26. package/dist/DoStorageVersion.mjs.map +1 -0
  27. package/dist/DoSubmissionLedger.d.mts +23 -0
  28. package/dist/DoSubmissionLedger.mjs +1849 -0
  29. package/dist/DoSubmissionLedger.mjs.map +1 -0
  30. package/dist/DoSubscriptionStore.d.mts +25 -0
  31. package/dist/DoSubscriptionStore.mjs +183 -0
  32. package/dist/DoSubscriptionStore.mjs.map +1 -0
  33. package/dist/DoThreadStore.d.mts +59 -0
  34. package/dist/DoThreadStore.mjs +465 -0
  35. package/dist/DoThreadStore.mjs.map +1 -0
  36. package/dist/MemoryProtocol.d.mts +38160 -0
  37. package/dist/MemoryProtocol.mjs +219 -0
  38. package/dist/MemoryProtocol.mjs.map +1 -0
  39. package/dist/PortProtocol.d.mts +3207 -0
  40. package/dist/PortProtocol.mjs +176 -0
  41. package/dist/PortProtocol.mjs.map +1 -0
  42. package/dist/PortRouting.d.mts +83 -0
  43. package/dist/PortRouting.mjs +410 -0
  44. package/dist/PortRouting.mjs.map +1 -0
  45. package/dist/do-journal-DHqCQeBU.mjs +991 -0
  46. package/dist/do-journal-DHqCQeBU.mjs.map +1 -0
  47. package/dist/index.d.mts +14 -1521
  48. package/dist/index.mjs +14 -3695
  49. package/dist/migrations-Ba_kOrSx.mjs +287 -0
  50. package/dist/migrations-Ba_kOrSx.mjs.map +1 -0
  51. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  52. package/package.json +1 -45
  53. package/src/DoMemoryStore.ts +59 -0
  54. package/src/DoMessageDeliveryStore.ts +53 -0
  55. package/src/DoScheduleStore.ts +622 -0
  56. package/src/{errors.ts → DoStorageError.ts} +10 -3
  57. package/src/DoStorageFailpoint.ts +20 -0
  58. package/src/{do-storage-failpoint.ts → DoStorageFailpointTesting.ts} +5 -18
  59. package/src/DoStorageVersion.ts +2 -0
  60. package/src/{do-ledger.ts → DoSubmissionLedger.ts} +862 -163
  61. package/src/DoSubscriptionStore.ts +329 -0
  62. package/src/DoThreadStore.ts +1014 -0
  63. package/src/MemoryProtocol.ts +355 -0
  64. package/src/{port-protocol.ts → PortProtocol.ts} +44 -37
  65. package/src/{routing.ts → PortRouting.ts} +292 -264
  66. package/src/index.ts +13 -32
  67. package/src/{do-journal.ts → internal/do-journal.ts} +716 -232
  68. package/src/internal/message-delivery-schema.ts +24 -0
  69. package/src/{migrations.ts → internal/migrations.ts} +51 -35
  70. package/src/internal/recovery-checkpoint-schema.ts +17 -0
  71. package/dist/index.mjs.map +0 -1
  72. package/src/do-conversation-store.ts +0 -850
  73. /package/src/{do-storage-config.ts → DoStorageConfig.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DoScheduleStore.mjs","names":[],"sources":["../src/DoScheduleStore.ts"],"sourcesContent":["import {\n ScheduleCapacityError,\n ScheduleDueCursor,\n defaultSchedulingLimits,\n ScheduleChange,\n ScheduleConflict,\n ScheduleFailpoint,\n type ScheduleFailpointError,\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 applyScheduleChange,\n scheduleUsesCapacity,\n scheduleDeadline,\n} from \"@effect-agent/thread/ScheduleTransition\";\nimport { upgradeV2Schedules } from \"@effect-agent/thread/SqlStorageV2Upgrade\";\nimport { Context, Effect, Layer, Result, Schema } from \"effect\";\nimport * as SqlClientService from \"effect/unstable/sql/SqlClient\";\n\nconst CURRENT_SCHEDULE_STORE_VERSION = 3;\nconst MAX_STORED_SCHEDULE_BYTES = 1_900_000;\n\nconst StoredScheduleJson = Schema.String.check(Schema.isMaxLength(MAX_STORED_SCHEDULE_BYTES));\nconst StoredDeadline = Schema.NullOr(ScheduleInstant);\n\nclass ScheduleRow extends Schema.Class<ScheduleRow>(\"@effect-agent/storage-cloudflare/ScheduleRow\")(\n {\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) {}\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-cloudflare/ScheduleCountRow\",\n)({\n schedule_count: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n}) {}\n\nclass ScheduleDeadlineRow extends Schema.Class<ScheduleDeadlineRow>(\n \"@effect-agent/storage-cloudflare/ScheduleDeadlineRow\",\n)({\n deadline_at_millis: StoredDeadline,\n}) {}\n\nclass ScheduleStoreStateRow extends Schema.Class<ScheduleStoreStateRow>(\n \"@effect-agent/storage-cloudflare/ScheduleStoreStateRow\",\n)({\n storage_version: Schema.Int.check(Schema.isGreaterThan(0)),\n alarm_generation: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n}) {}\n\nclass ScheduleTableNameRow extends Schema.Class<ScheduleTableNameRow>(\n \"@effect-agent/storage-cloudflare/ScheduleTableNameRow\",\n)({\n name: Schema.String,\n}) {}\n\nexport interface DoScheduleAlarmReplacement {\n readonly deadlineAtMillis: number | null;\n /** Included in every logical alarm payload so equal-time replacement stays distinguishable. */\n readonly generation: number;\n}\n\nexport type DoScheduleReplaceAlarm = (\n replacement: DoScheduleAlarmReplacement,\n) => Effect.Effect<void, ScheduleStorageError>;\n\n/**\n * Platform-owned transaction boundary for schedule SQL and logical alarm mutation. The callback\n * and its `replaceAlarm` capability belong to one fiber and must not escape or fork.\n */\nexport class DoScheduleTransaction extends Context.Service<\n DoScheduleTransaction,\n {\n readonly run: <A, E, R>(\n body: (replaceAlarm: DoScheduleReplaceAlarm) => Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | ScheduleStorageError, R>;\n }\n>()(\"@effect-agent/storage-cloudflare/DoScheduleTransaction\") {}\n\n/** Platform driver operations that use the same schedule-state and alarm transaction. */\nexport class DoScheduleAlarmControl extends Context.Service<\n DoScheduleAlarmControl,\n {\n /** Establish a future recovery wake before cross-Object admission starts. */\n readonly prearm: (\n deadlineAtMillis: number,\n ) => Effect.Effect<void, ScheduleStorageError | ScheduleFailpointError>;\n /** Replace or cancel the wake from the object's authoritative indexed deadline. */\n readonly reconcile: Effect.Effect<void, ScheduleStorageError | ScheduleFailpointError>;\n }\n>()(\"@effect-agent/storage-cloudflare/DoScheduleAlarmControl\") {}\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(\"DoScheduleStore.decodeRows\")(function* <A, I, R>(\n schema: Schema.Codec<A, I, R>,\n rows: ReadonlyArray<unknown>,\n operation: string,\n): Effect.fn.Return<A, ScheduleStorageError, R> {\n return yield* Schema.decodeUnknownEffect(schema)(rows).pipe(\n Effect.mapError(() => corrupt(operation)),\n );\n});\n\nconst decodeBoundary = <A, I, R>(\n schema: Schema.Codec<A, I, R>,\n value: unknown,\n operation: string,\n): Effect.Effect<A, ScheduleStorageError, R> =>\n Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(() => corrupt(operation)));\n\nconst decodeRecord = Effect.fn(\"DoScheduleStore.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 index\");\n }\n\n return record;\n});\n\nconst encodeRecord = Effect.fn(\"DoScheduleStore.encodeRecord\")(function* (\n record: ScheduleRecord,\n): Effect.fn.Return<string, ScheduleStorageError> {\n const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(ScheduleRecord))(record).pipe(\n Effect.mapError(() => corrupt(\"encode schedule\")),\n );\n\n return yield* Schema.decodeUnknownEffect(StoredScheduleJson)(encoded).pipe(\n Effect.mapError(() => corrupt(\"encode schedule bounds\")),\n );\n});\n\nconst initializeScheduleStore = Effect.fn(\"DoScheduleStore.initialize\")(function* () {\n const sql = yield* SqlClientService.SqlClient;\n const operation = \"initialize schedule store\";\n\n const rawTables = yield* sql<Record<string, unknown>>`\n SELECT name\n FROM sqlite_master\n WHERE type = 'table'\n AND name IN (\n 'effect_agent_schedule_store_state',\n 'effect_agent_schedules'\n )\n ORDER BY name\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n const tables = yield* decodeRows(Schema.Array(ScheduleTableNameRow), rawTables, operation);\n const hasState = tables.some((row) => row.name === \"effect_agent_schedule_store_state\");\n const hasSchedules = tables.some((row) => row.name === \"effect_agent_schedules\");\n\n if (!hasState) {\n if (hasSchedules) return yield* corrupt(operation);\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n yield* sql`\n CREATE TABLE effect_agent_schedule_store_state (\n singleton INTEGER PRIMARY KEY NOT NULL CHECK (singleton = 1),\n storage_version INTEGER NOT NULL,\n alarm_generation INTEGER NOT NULL\n )\n `.withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_schedules (\n tenant_id TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n schedule_id TEXT NOT NULL,\n deadline_at_millis INTEGER,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, owner_id, schedule_id)\n )\n `.withoutTransform;\n yield* sql`\n CREATE INDEX effect_agent_schedules_deadline\n ON effect_agent_schedules (deadline_at_millis, tenant_id, owner_id, schedule_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n yield* sql`\n CREATE INDEX effect_agent_schedules_owner_deadline\n ON effect_agent_schedules (tenant_id, owner_id, deadline_at_millis, schedule_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n yield* sql`\n INSERT INTO effect_agent_schedule_store_state (\n singleton, storage_version, alarm_generation\n ) VALUES (1, ${CURRENT_SCHEDULE_STORE_VERSION}, 0)\n `.withoutTransform;\n }),\n )\n .pipe(Effect.mapError(() => unavailable(operation)));\n\n return;\n }\n\n if (!hasSchedules) return yield* corrupt(operation);\n\n const rawState = yield* sql<Record<string, unknown>>`\n SELECT storage_version, alarm_generation\n FROM effect_agent_schedule_store_state\n WHERE singleton = 1\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n const state = yield* decodeRows(Schema.Array(ScheduleStoreStateRow), rawState, operation);\n\n if (state.length === 1 && state[0].storage_version === 2) {\n const failpoint = yield* ScheduleFailpoint;\n\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* sql<{\n storage_version: number;\n }>`SELECT storage_version FROM effect_agent_schedule_store_state WHERE singleton=1`;\n\n if (current.length === 1 && current[0].storage_version === 3) return;\n if (current.length !== 1 || current[0].storage_version !== 2)\n return yield* corrupt(\"schedule version changed during upgrade\");\n yield* upgradeV2Schedules(MAX_STORED_SCHEDULE_BYTES);\n yield* failpoint.hit(\"upgrade:before-version\");\n yield* sql`UPDATE effect_agent_schedule_store_state SET storage_version=3 WHERE singleton=1`;\n yield* failpoint.hit(\"upgrade:after-version\");\n }),\n )\n .pipe(\n Effect.catchTag(\"StorageUpgradeError\", (error) =>\n ScheduleStorageError.make({\n reason: \"corrupt\",\n operation: \"upgrade v2 schedules\",\n cause: error,\n }),\n ),\n Effect.catchTag(\"SqlError\", () => unavailable(\"upgrade v2 schedules\")),\n Effect.catchTag(\"ScheduleFailpointError\", () =>\n unavailable(\"upgrade v2 schedules failpoint\"),\n ),\n );\n\n return;\n }\n\n if (state.length !== 1 || state[0].storage_version !== CURRENT_SCHEDULE_STORE_VERSION) {\n return yield* corrupt(\n state.length === 1\n ? `${operation}: incompatible storage version ${state[0].storage_version}; expected ${CURRENT_SCHEDULE_STORE_VERSION}`\n : `${operation}: invalid storage version row`,\n );\n }\n});\n\nconst makeServices = Effect.gen(function* () {\n const sql = yield* SqlClientService.SqlClient;\n const transactions = yield* DoScheduleTransaction;\n const scheduleFailpoint = yield* ScheduleFailpoint;\n\n yield* initializeScheduleStore();\n\n const readRows = Effect.fn(\"DoScheduleStore.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(\"DoScheduleStore.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 readNextDeadline = Effect.fn(\"DoScheduleStore.readNextDeadline\")(function* (\n owner: ScheduleOwner | undefined,\n operation: string,\n ): Effect.fn.Return<number | null, ScheduleStorageError> {\n const rows =\n owner === 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 = ${owner.tenantId}\n AND owner_id = ${owner.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 const replaceAlarm = Effect.fn(\"DoScheduleStore.replaceAlarm\")(function* (\n replace: DoScheduleReplaceAlarm,\n deadlineAtMillis: number | null,\n operation: string,\n ) {\n const rawState = yield* sql<Record<string, unknown>>`\n UPDATE effect_agent_schedule_store_state\n SET alarm_generation = alarm_generation + 1\n WHERE singleton = 1\n RETURNING storage_version, alarm_generation\n `.pipe(Effect.mapError(() => unavailable(operation)));\n\n const state = yield* decodeRows(Schema.Array(ScheduleStoreStateRow), rawState, operation);\n\n if (state.length !== 1 || state[0].storage_version !== CURRENT_SCHEDULE_STORE_VERSION) {\n return yield* corrupt(operation);\n }\n yield* scheduleFailpoint.hit(\"schedule:alarm:before\");\n yield* replace({ deadlineAtMillis, generation: state[0].alarm_generation });\n yield* scheduleFailpoint.hit(\"schedule:alarm:after\");\n });\n\n const insert: ScheduleStore[\"Service\"][\"insert\"] = Effect.fn(\"DoScheduleStore.insert\")(\n function* (record, ownerLimit) {\n const operation = \"insert schedule\";\n const canonical = yield* decodeBoundary(ScheduleRecord, record, operation);\n const recordJson = yield* encodeRecord(canonical);\n\n const result = yield* transactions.run((replace) =>\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({ reason: \"creation\", key: canonical });\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 const deadline = yield* readNextDeadline(undefined, operation);\n\n yield* replaceAlarm(replace, deadline, operation);\n\n return { record: canonical, inserted: true } as const;\n }),\n );\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(\"DoScheduleStore.get\")(function* (key) {\n const canonical = yield* decodeBoundary(ScheduleKey, key, \"get schedule\");\n\n return yield* readOne(canonical, \"get schedule\");\n });\n\n const list: ScheduleStore[\"Service\"][\"list\"] = Effect.fn(\"DoScheduleStore.list\")(function* (\n requestValue: SchedulePageRequest,\n ): Effect.fn.Return<SchedulePage, ScheduleStorageError> {\n const operation = \"list schedules\";\n const request = yield* decodeBoundary(SchedulePageRequest, requestValue, operation);\n\n const rows =\n request.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 = ${request.owner.tenantId}\n AND owner_id = ${request.owner.ownerId}\n ORDER BY schedule_id\n LIMIT ${request.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 = ${request.owner.tenantId}\n AND owner_id = ${request.owner.ownerId}\n AND schedule_id > ${request.after}\n ORDER BY schedule_id\n LIMIT ${request.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 > request.limit;\n const items = hasNext ? records.slice(0, request.limit) : records;\n\n return { items, next: hasNext ? (items.at(-1)?.scheduleId ?? null) : null };\n });\n\n const change: ScheduleStore[\"Service\"][\"change\"] = Effect.fn(\"DoScheduleStore.change\")(function* (\n key,\n change,\n ownerLimit = defaultSchedulingLimits.maxSchedulesPerOwner,\n ) {\n const operation = \"change schedule\";\n const canonicalKey = yield* decodeBoundary(ScheduleKey, key, operation);\n const canonicalChange = yield* decodeBoundary(ScheduleChange, change, operation);\n\n const result = yield* transactions.run((replace) =>\n Effect.gen(function* () {\n const current = yield* readOne(canonicalKey, operation);\n\n if (current === null) return yield* ScheduleNotFound.make({ key: canonicalKey });\n const transition = applyScheduleChange(current, canonicalChange);\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(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 if (next === current) return { record: current, changed: false } as const;\n const recordJson = yield* encodeRecord(next);\n\n yield* scheduleFailpoint.hit(`schedule:${canonicalChange._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 = ${canonicalKey.owner.tenantId}\n AND owner_id = ${canonicalKey.owner.ownerId}\n AND schedule_id = ${canonicalKey.scheduleId}\n `.pipe(Effect.mapError(() => unavailable(operation)));\n const deadline = yield* readNextDeadline(undefined, operation);\n\n yield* replaceAlarm(replace, deadline, operation);\n\n return { record: next, changed: true } as const;\n }),\n );\n\n if (result.changed) {\n yield* scheduleFailpoint.hit(`schedule:${canonicalChange._tag.toLowerCase()}:after`);\n }\n\n return result.record;\n });\n\n const due: ScheduleStore[\"Service\"][\"due\"] = Effect.fn(\"DoScheduleStore.due\")(function* (\n nowMillis,\n limit,\n owner?: ScheduleOwner,\n after?: ScheduleDueCursor,\n ) {\n const operation = \"query due schedules\";\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 owner === 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 = ${owner.tenantId}\n AND owner_id = ${owner.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 \"DoScheduleStore.nextDeadline\",\n )(function* (owner?: ScheduleOwner) {\n const operation = \"query next schedule deadline\";\n\n return yield* readNextDeadline(owner, operation);\n });\n\n const prearm = Effect.fn(\"DoScheduleStore.prearm\")(function* (\n deadlineAtMillis: number,\n ): Effect.fn.Return<void, ScheduleStorageError | ScheduleFailpointError> {\n yield* decodeBoundary(ScheduleInstant, deadlineAtMillis, \"pre-arm schedule recovery\");\n yield* transactions.run((replace) =>\n replaceAlarm(replace, deadlineAtMillis, \"pre-arm schedule recovery\"),\n );\n yield* scheduleFailpoint.hit(\"schedule:prearm:after\");\n });\n\n const reconcile = Effect.gen(function* () {\n yield* transactions.run((replace) =>\n Effect.gen(function* () {\n const deadline = yield* readNextDeadline(undefined, \"reconcile schedule alarm\");\n\n yield* replaceAlarm(replace, deadline, \"reconcile schedule alarm\");\n }),\n );\n yield* scheduleFailpoint.hit(\"schedule:reconcile:after\");\n });\n\n return Context.make(ScheduleStore, {\n insert,\n get,\n list,\n change,\n due,\n nextDeadline,\n }).pipe(Context.add(DoScheduleAlarmControl, { prearm, reconcile }));\n});\n\n/**\n * Durable Object SQLite ScheduleStore. Platform code supplies the one transaction owner that\n * combines these SQL mutations with its logical and native alarm lifecycle.\n */\nexport const scheduleStoreLayer: Layer.Layer<\n ScheduleStore | DoScheduleAlarmControl,\n ScheduleStorageError,\n SqlClientService.SqlClient | DoScheduleTransaction\n> = Layer.effectContext(makeServices);\n"],"mappings":";;;;;;;;;;;;AA4BA,MAAM,iCAAiC;AACvC,MAAM,4BAA4B;AAElC,MAAM,qBAAqB,OAAO,OAAO,MAAM,OAAO,YAAY,yBAAyB,CAAC;AAC5F,MAAM,iBAAiB,OAAO,OAAO,eAAe;AAEpD,IAAM,cAAN,cAA0B,OAAO,MAAmB,8CAA8C,CAAC,CACjG;CACE,WAAW,cAAc,OAAO;CAChC,UAAU,cAA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CAGb,MAAM,SAAS;+BAChB,MAAM,QAAQ;0CACH,UAAU,OAAO,aAAa;;oBAEpD,MAAM;YACd,KAAK,OAAO,eAAe,YAAY,SAAS,CAAC,CAAC;EAI1D,QAAO,OAFgB,WAAW,OAAO,MAAM,cAAc,GAAG,MAAM,SAAS,EAAA,CAEhE,KAAK,SAAS;GAC3B,OAAO;IAAE,UAAU,IAAI;IAAW,SAAS,IAAI;GAAS;GACxD,YAAY,IAAI;GAChB,kBAAkB,IAAI;EACxB,EAAE;CACJ,CAAC;CAED,MAAM,eAAyD,OAAO,GACpE,8BACF,CAAC,CAAC,WAAW,OAAuB;EAGlC,OAAO,OAAO,iBAAiB,OAAO,8BAAS;CACjD,CAAC;CAED,MAAM,SAAS,OAAO,GAAG,wBAAwB,CAAC,CAAC,WACjD,kBACuE;EACvE,OAAO,eAAe,iBAAiB,kBAAkB,2BAA2B;EACpF,OAAO,aAAa,KAAK,YACvB,aAAa,SAAS,kBAAkB,2BAA2B,CACrE;EACA,OAAO,kBAAkB,IAAI,uBAAuB;CACtD,CAAC;CAED,MAAM,YAAY,OAAO,IAAI,aAAa;EACxC,OAAO,aAAa,KAAK,YACvB,OAAO,IAAI,aAAa;GACtB,MAAM,WAAW,OAAO,iBAAiB,KAAA,GAAW,0BAA0B;GAE9E,OAAO,aAAa,SAAS,UAAU,0BAA0B;EACnE,CAAC,CACH;EACA,OAAO,kBAAkB,IAAI,0BAA0B;CACzD,CAAC;CAED,OAAO,QAAQ,KAAK,eAAe;EACjC;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,wBAAwB;EAAE;EAAQ;CAAU,CAAC,CAAC;AACpE,CAAC;;;;;AAMD,MAAa,qBAIT,MAAM,cAAc,YAAY"}
@@ -0,0 +1,45 @@
1
+ import { Context, Schema } from "effect";
2
+ declare namespace DoStorageConfig_d_exports {
3
+ export { DEFAULT_MAX_STORED_VALUE_BYTES, DoStorageConfig, DoStorageConfigValue };
4
+ }
5
+ /**
6
+ * Default per-value byte bound, kept under the Durable Object platform's 2 MB SQLite value
7
+ * limit with a safety margin. This is the DC analogue of Node's 16 MB `BoundedStoredText`
8
+ * bound: both fail typed before mutating, only the threshold differs (a documented DN/DC
9
+ * behavioral difference; Travel Planner payloads sit orders of magnitude below both).
10
+ */
11
+ declare const DEFAULT_MAX_STORED_VALUE_BYTES = 1900000;
12
+ declare const DoStorageConfigValue_base: Schema.Class<DoStorageConfigValue, Schema.Struct<{
13
+ readonly observationPollInterval: Schema.Int;
14
+ /**
15
+ * Submission ownership lease duration in milliseconds (D5). Inside one Durable Object the
16
+ * object itself is the serialized owner, so the lease's primary DC role is fencing work
17
+ * across DO incarnations (an evicted incarnation's claim becomes reclaimable); correctness
18
+ * never depends on it because every canonical append is fenced by producer epoch.
19
+ */
20
+ readonly ownershipLeaseDuration: Schema.Int;
21
+ /**
22
+ * Maximum bytes for any single stored text value (canonical batch/record JSON, admission
23
+ * input payload, checkpoint JSON). Enforced typed BEFORE any write; must stay under the
24
+ * platform's 2 MB per-value limit.
25
+ */
26
+ readonly maxStoredValueBytes: Schema.Int;
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
+ readonly verifyOnOpen: Schema.Boolean;
33
+ }>, {}>;
34
+ /**
35
+ * Validated construction configuration consumed by the Durable Object storage Layers. The
36
+ * storage identity itself belongs to the SqlClient Layer (built from `ctx.storage`);
37
+ * duplicating it here could silently diverge from the handle actually in use.
38
+ */
39
+ declare class DoStorageConfigValue extends DoStorageConfigValue_base {}
40
+ declare const DoStorageConfig_base: Context.ServiceClass<DoStorageConfig, "@effect-agent/storage-cloudflare/DoStorageConfig", DoStorageConfigValue>;
41
+ /** Explicit Durable Object storage configuration authority. */
42
+ declare class DoStorageConfig extends DoStorageConfig_base {}
43
+ //#endregion
44
+ export { DEFAULT_MAX_STORED_VALUE_BYTES, DoStorageConfig, DoStorageConfigValue, DoStorageConfig_d_exports as t };
45
+ //# sourceMappingURL=DoStorageConfig.d.mts.map
@@ -0,0 +1,52 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Context, Schema } from "effect";
3
+ //#region src/DoStorageConfig.ts
4
+ var DoStorageConfig_exports = /* @__PURE__ */ __exportAll({
5
+ DEFAULT_MAX_STORED_VALUE_BYTES: () => DEFAULT_MAX_STORED_VALUE_BYTES,
6
+ DoStorageConfig: () => DoStorageConfig,
7
+ DoStorageConfigValue: () => DoStorageConfigValue
8
+ });
9
+ const ObservationPollInterval = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
10
+ const OwnershipLeaseMillis = Schema.Int.check(Schema.isGreaterThan(0));
11
+ /**
12
+ * Default per-value byte bound, kept under the Durable Object platform's 2 MB SQLite value
13
+ * limit with a safety margin. This is the DC analogue of Node's 16 MB `BoundedStoredText`
14
+ * bound: both fail typed before mutating, only the threshold differs (a documented DN/DC
15
+ * behavioral difference; Travel Planner payloads sit orders of magnitude below both).
16
+ */
17
+ const DEFAULT_MAX_STORED_VALUE_BYTES = 19e5;
18
+ /** The hard schema ceiling for the configurable bound: never at or above the platform limit. */
19
+ const MaxStoredValueBytes = Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(2e6));
20
+ /**
21
+ * Validated construction configuration consumed by the Durable Object storage Layers. The
22
+ * storage identity itself belongs to the SqlClient Layer (built from `ctx.storage`);
23
+ * duplicating it here could silently diverge from the handle actually in use.
24
+ */
25
+ var DoStorageConfigValue = class extends Schema.Class("@effect-agent/storage-cloudflare/DoStorageConfigValue")({
26
+ observationPollInterval: ObservationPollInterval,
27
+ /**
28
+ * Submission ownership lease duration in milliseconds (D5). Inside one Durable Object the
29
+ * object itself is the serialized owner, so the lease's primary DC role is fencing work
30
+ * across DO incarnations (an evicted incarnation's claim becomes reclaimable); correctness
31
+ * never depends on it because every canonical append is fenced by producer epoch.
32
+ */
33
+ ownershipLeaseDuration: OwnershipLeaseMillis,
34
+ /**
35
+ * Maximum bytes for any single stored text value (canonical batch/record JSON, admission
36
+ * input payload, checkpoint JSON). Enforced typed BEFORE any write; must stay under the
37
+ * platform's 2 MB per-value limit.
38
+ */
39
+ maxStoredValueBytes: MaxStoredValueBytes,
40
+ /**
41
+ * Re-verify every stored payload and digest chain while opening the store. Per-operation
42
+ * Schema decoding and the digest chain already fail clearly on corrupt rows, so the full
43
+ * scan is an explicit opt-in integrity audit rather than a startup requirement.
44
+ */
45
+ verifyOnOpen: Schema.Boolean
46
+ }) {};
47
+ /** Explicit Durable Object storage configuration authority. */
48
+ var DoStorageConfig = class extends Context.Service()("@effect-agent/storage-cloudflare/DoStorageConfig") {};
49
+ //#endregion
50
+ export { DEFAULT_MAX_STORED_VALUE_BYTES, DoStorageConfig, DoStorageConfigValue, DoStorageConfig_exports as t };
51
+
52
+ //# sourceMappingURL=DoStorageConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DoStorageConfig.mjs","names":[],"sources":["../src/DoStorageConfig.ts"],"sourcesContent":["import { Context, Schema } from \"effect\";\n\nconst ObservationPollInterval = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));\nconst OwnershipLeaseMillis = Schema.Int.check(Schema.isGreaterThan(0));\n\n/**\n * Default per-value byte bound, kept under the Durable Object platform's 2 MB SQLite value\n * limit with a safety margin. This is the DC analogue of Node's 16 MB `BoundedStoredText`\n * bound: both fail typed before mutating, only the threshold differs (a documented DN/DC\n * behavioral difference; Travel Planner payloads sit orders of magnitude below both).\n */\nexport const DEFAULT_MAX_STORED_VALUE_BYTES = 1_900_000;\n\n/** The hard schema ceiling for the configurable bound: never at or above the platform limit. */\nconst MaxStoredValueBytes = Schema.Int.check(\n Schema.isGreaterThan(0),\n Schema.isLessThanOrEqualTo(2_000_000),\n);\n\n/**\n * Validated construction configuration consumed by the Durable Object storage Layers. The\n * storage identity itself belongs to the SqlClient Layer (built from `ctx.storage`);\n * duplicating it here could silently diverge from the handle actually in use.\n */\nexport class DoStorageConfigValue extends Schema.Class<DoStorageConfigValue>(\n \"@effect-agent/storage-cloudflare/DoStorageConfigValue\",\n)({\n observationPollInterval: ObservationPollInterval,\n /**\n * Submission ownership lease duration in milliseconds (D5). Inside one Durable Object the\n * object itself is the serialized owner, so the lease's primary DC role is fencing work\n * across DO incarnations (an evicted incarnation's claim becomes reclaimable); correctness\n * never depends on it because every canonical append is fenced by producer epoch.\n */\n ownershipLeaseDuration: OwnershipLeaseMillis,\n /**\n * Maximum bytes for any single stored text value (canonical batch/record JSON, admission\n * input payload, checkpoint JSON). Enforced typed BEFORE any write; must stay under the\n * platform's 2 MB per-value limit.\n */\n maxStoredValueBytes: MaxStoredValueBytes,\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 Durable Object storage configuration authority. */\nexport class DoStorageConfig extends Context.Service<DoStorageConfig, DoStorageConfigValue>()(\n \"@effect-agent/storage-cloudflare/DoStorageConfig\",\n) {}\n"],"mappings":";;;;;;;;AAEA,MAAM,0BAA0B,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;AACjF,MAAM,uBAAuB,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;;;;;;;AAQrE,MAAa,iCAAiC;;AAG9C,MAAM,sBAAsB,OAAO,IAAI,MACrC,OAAO,cAAc,CAAC,GACtB,OAAO,oBAAoB,GAAS,CACtC;;;;;;AAOA,IAAa,uBAAb,cAA0C,OAAO,MAC/C,uDACF,CAAC,CAAC;CACA,yBAAyB;;;;;;;CAOzB,wBAAwB;;;;;;CAMxB,qBAAqB;;;;;;CAMrB,cAAc,OAAO;AACvB,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa,kBAAb,cAAqC,QAAQ,QAA+C,CAAC,CAC3F,kDACF,CAAC,CAAC,CAAC"}
@@ -0,0 +1,98 @@
1
+ import { Schema } from "effect";
2
+ declare namespace DoStorageError_d_exports {
3
+ export { DoAppendConflict, DoCheckpointConflict, DoFenceRejected, DoLedgerError, DoStorageCompatibilityError, DoStorageCorruptionError, DoStorageError, DoStorageFailpointError, DoStorageFailpointLocation, DoValueBoundExceeded };
4
+ }
5
+ declare const DoStorageCompatibilityError_base: Schema.Class<DoStorageCompatibilityError, Schema.TaggedStruct<"DoStorageCompatibilityError", {
6
+ readonly actualVersion: Schema.Int;
7
+ readonly message: Schema.String;
8
+ readonly supportedVersion: Schema.Int;
9
+ }>, import("effect/Cause").YieldableError>;
10
+ /** The Durable Object's SQLite storage uses a private-development format this adapter cannot read. */
11
+ declare class DoStorageCompatibilityError extends DoStorageCompatibilityError_base {}
12
+ declare const DoStorageCorruptionError_base: Schema.Class<DoStorageCorruptionError, Schema.TaggedStruct<"DoStorageCorruptionError", {
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 DoStorageCorruptionError extends DoStorageCorruptionError_base {}
19
+ declare const DoStorageError_base: Schema.Class<DoStorageError, Schema.TaggedStruct<"DoStorageError", {
20
+ readonly cause: Schema.optionalKey<Schema.Defect>;
21
+ readonly message: Schema.String;
22
+ readonly operation: Schema.String;
23
+ }>, import("effect/Cause").YieldableError>;
24
+ /** Durable Object SQLite infrastructure failed while opening or operating the store. */
25
+ declare class DoStorageError extends DoStorageError_base {}
26
+ declare const DoLedgerError_base: Schema.Class<DoLedgerError, Schema.TaggedStruct<"DoLedgerError", {
27
+ readonly cause: Schema.optionalKey<Schema.Defect>;
28
+ readonly message: Schema.String;
29
+ readonly operation: Schema.String;
30
+ }>, import("effect/Cause").YieldableError>;
31
+ /**
32
+ * Durable Object SQLite infrastructure failed while operating the Submission Ledger. Surfaces
33
+ * at the SubmissionLedger port as the typed `LedgerError` with this error preserved as its
34
+ * cause, so the adapter-level tag is never erased.
35
+ */
36
+ declare class DoLedgerError extends DoLedgerError_base {}
37
+ declare const DoValueBoundExceeded_base: Schema.Class<DoValueBoundExceeded, Schema.TaggedStruct<"DoValueBoundExceeded", {
38
+ readonly actualBytes: Schema.Int;
39
+ readonly maxBytes: Schema.Int;
40
+ readonly operation: Schema.String;
41
+ }>, import("effect/Cause").YieldableError>;
42
+ /**
43
+ * A value to be stored exceeds the configured Durable Object per-value bound
44
+ * (`DoStorageConfigValue.maxStoredValueBytes`, kept under the platform's 2 MB SQLite value
45
+ * limit). The refusal happens typed BEFORE any durable mutation; no partial state is written.
46
+ * Payloads of this size are the designed overflow case for a future R2-backed AttachmentStore
47
+ * (deployment spec §3.1, deferred until a real attachment requirement exists).
48
+ */
49
+ declare class DoValueBoundExceeded extends DoValueBoundExceeded_base {
50
+ get message(): string;
51
+ }
52
+ declare const DoAppendConflict_base: Schema.Class<DoAppendConflict, Schema.TaggedStruct<"DoAppendConflict", {
53
+ readonly message: Schema.String;
54
+ readonly reason: Schema.Literals<readonly ["batch-digest", "record-identity", "tail"]>;
55
+ readonly actualTailSequence: Schema.optionalKey<Schema.brand<Schema.Natural, "@effect-agent/thread/CanonicalSequence">>;
56
+ readonly actualTailDigest: Schema.optionalKey<Schema.String>;
57
+ }>, import("effect/Cause").YieldableError>;
58
+ /**
59
+ * A canonical batch retry conflicts with existing append state. Tail conflicts carry the
60
+ * actual committed tail as a diagnostic resume hint.
61
+ */
62
+ declare class DoAppendConflict extends DoAppendConflict_base {}
63
+ declare const DoFenceRejected_base: Schema.Class<DoFenceRejected, Schema.TaggedStruct<"DoFenceRejected", {
64
+ readonly actualEpoch: Schema.brand<Schema.Natural, "@effect-agent/thread/ProducerEpoch">;
65
+ readonly message: Schema.String;
66
+ readonly producerEpoch: Schema.brand<Schema.Natural, "@effect-agent/thread/ProducerEpoch">;
67
+ }>, import("effect/Cause").YieldableError>;
68
+ /**
69
+ * A producer epoch does not match the Thread's current writer registration. Appends
70
+ * require the exact registered epoch, so both older and newer unregistered epochs are fenced;
71
+ * a newer epoch takes over by materializing first.
72
+ */
73
+ declare class DoFenceRejected extends DoFenceRejected_base {}
74
+ declare const DoCheckpointConflict_base: Schema.Class<DoCheckpointConflict, Schema.TaggedStruct<"DoCheckpointConflict", {
75
+ readonly message: Schema.String;
76
+ }>, import("effect/Cause").YieldableError>;
77
+ /** A checkpoint conflicts with a previously stored checkpoint at the same offset. */
78
+ declare class DoCheckpointConflict extends DoCheckpointConflict_base {}
79
+ /**
80
+ * Deterministic fault-injection locations at Durable Object storage operation boundaries.
81
+ *
82
+ * The string list is copied VERBATIM from `SqliteStorageFailpointLocation`
83
+ * (`packages/storage-sqlite/src/errors.ts`) so every crash-matrix row keeps the same name on
84
+ * both platforms — the DN process-kill evidence and the DC eviction evidence address identical
85
+ * locations. There is intentionally no Cloudflare-only location.
86
+ */
87
+ declare const DoStorageFailpointLocation: 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", "save-recovery-checkpoint:before", "save-recovery-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"]>;
88
+ type DoStorageFailpointLocation = typeof DoStorageFailpointLocation.Type;
89
+ declare const DoStorageFailpointError_base: Schema.Class<DoStorageFailpointError, Schema.TaggedStruct<"DoStorageFailpointError", {
90
+ 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", "save-recovery-checkpoint:before", "save-recovery-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"]>;
91
+ }>, import("effect/Cause").YieldableError>;
92
+ /** Deterministic test-only fault or pause injected at a Durable Object storage boundary. */
93
+ declare class DoStorageFailpointError extends DoStorageFailpointError_base {
94
+ get message(): string;
95
+ }
96
+ //#endregion
97
+ export { DoStorageCompatibilityError as a, DoStorageError_d_exports as c, DoValueBoundExceeded as d, DoLedgerError as i, DoStorageFailpointError as l, DoCheckpointConflict as n, DoStorageCorruptionError as o, DoFenceRejected as r, DoStorageError as s, DoAppendConflict as t, DoStorageFailpointLocation as u };
98
+ //# sourceMappingURL=DoStorageError-Cmhvl4TQ.d.mts.map
@@ -0,0 +1,2 @@
1
+ import { a as DoStorageCompatibilityError, d as DoValueBoundExceeded, i as DoLedgerError, l as DoStorageFailpointError, n as DoCheckpointConflict, o as DoStorageCorruptionError, r as DoFenceRejected, s as DoStorageError, t as DoAppendConflict, u as DoStorageFailpointLocation } from "./DoStorageError-Cmhvl4TQ.mjs";
2
+ export { DoAppendConflict, DoCheckpointConflict, DoFenceRejected, DoLedgerError, DoStorageCompatibilityError, DoStorageCorruptionError, DoStorageError, DoStorageFailpointError, DoStorageFailpointLocation, DoValueBoundExceeded };
@@ -0,0 +1,164 @@
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/DoStorageError.ts
5
+ var DoStorageError_exports = /* @__PURE__ */ __exportAll({
6
+ DoAppendConflict: () => DoAppendConflict,
7
+ DoCheckpointConflict: () => DoCheckpointConflict,
8
+ DoFenceRejected: () => DoFenceRejected,
9
+ DoLedgerError: () => DoLedgerError,
10
+ DoStorageCompatibilityError: () => DoStorageCompatibilityError,
11
+ DoStorageCorruptionError: () => DoStorageCorruptionError,
12
+ DoStorageError: () => DoStorageError,
13
+ DoStorageFailpointError: () => DoStorageFailpointError,
14
+ DoStorageFailpointLocation: () => DoStorageFailpointLocation,
15
+ DoValueBoundExceeded: () => DoValueBoundExceeded
16
+ });
17
+ /** The Durable Object's SQLite storage uses a private-development format this adapter cannot read. */
18
+ var DoStorageCompatibilityError = class extends Schema.TaggedError()("DoStorageCompatibilityError", {
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 DoStorageCorruptionError = class extends Schema.TaggedError()("DoStorageCorruptionError", {
25
+ message: Schema.String,
26
+ rowKey: Schema.String,
27
+ table: Schema.String
28
+ }) {};
29
+ /** Durable Object SQLite infrastructure failed while opening or operating the store. */
30
+ var DoStorageError = class extends Schema.TaggedError()("DoStorageError", {
31
+ cause: Schema.optionalKey(Schema.Defect()),
32
+ message: Schema.String,
33
+ operation: Schema.String
34
+ }) {};
35
+ /**
36
+ * Durable Object SQLite infrastructure failed while operating the Submission Ledger. Surfaces
37
+ * at the SubmissionLedger port as the typed `LedgerError` with this error preserved as its
38
+ * cause, so the adapter-level tag is never erased.
39
+ */
40
+ var DoLedgerError = class extends Schema.TaggedError()("DoLedgerError", {
41
+ cause: Schema.optionalKey(Schema.Defect()),
42
+ message: Schema.String,
43
+ operation: Schema.String
44
+ }) {};
45
+ /**
46
+ * A value to be stored exceeds the configured Durable Object per-value bound
47
+ * (`DoStorageConfigValue.maxStoredValueBytes`, kept under the platform's 2 MB SQLite value
48
+ * limit). The refusal happens typed BEFORE any durable mutation; no partial state is written.
49
+ * Payloads of this size are the designed overflow case for a future R2-backed AttachmentStore
50
+ * (deployment spec §3.1, deferred until a real attachment requirement exists).
51
+ */
52
+ var DoValueBoundExceeded = class extends Schema.TaggedError()("DoValueBoundExceeded", {
53
+ actualBytes: Schema.Int,
54
+ maxBytes: Schema.Int,
55
+ operation: Schema.String
56
+ }) {
57
+ get message() {
58
+ return `A stored value of ${this.actualBytes} bytes exceeds the Durable Object per-value bound of ${this.maxBytes} bytes during ${this.operation}. Nothing was written. Values of this size are the designed R2 AttachmentStore overflow path (deferred, deployment spec §3.1).`;
59
+ }
60
+ };
61
+ /**
62
+ * A canonical batch retry conflicts with existing append state. Tail conflicts carry the
63
+ * actual committed tail as a diagnostic resume hint.
64
+ */
65
+ var DoAppendConflict = class extends Schema.TaggedError()("DoAppendConflict", {
66
+ message: Schema.String,
67
+ reason: Schema.Literals([
68
+ "batch-digest",
69
+ "record-identity",
70
+ "tail"
71
+ ]),
72
+ actualTailSequence: Schema.optionalKey(CanonicalSequence),
73
+ actualTailDigest: Schema.optionalKey(Schema.String)
74
+ }) {};
75
+ /**
76
+ * A producer epoch does not match the Thread's current writer registration. Appends
77
+ * require the exact registered epoch, so both older and newer unregistered epochs are fenced;
78
+ * a newer epoch takes over by materializing first.
79
+ */
80
+ var DoFenceRejected = class extends Schema.TaggedError()("DoFenceRejected", {
81
+ actualEpoch: ProducerEpoch,
82
+ message: Schema.String,
83
+ producerEpoch: ProducerEpoch
84
+ }) {};
85
+ /** A checkpoint conflicts with a previously stored checkpoint at the same offset. */
86
+ var DoCheckpointConflict = class extends Schema.TaggedError()("DoCheckpointConflict", { message: Schema.String }) {};
87
+ /**
88
+ * Deterministic fault-injection locations at Durable Object storage operation boundaries.
89
+ *
90
+ * The string list is copied VERBATIM from `SqliteStorageFailpointLocation`
91
+ * (`packages/storage-sqlite/src/errors.ts`) so every crash-matrix row keeps the same name on
92
+ * both platforms — the DN process-kill evidence and the DC eviction evidence address identical
93
+ * locations. There is intentionally no Cloudflare-only location.
94
+ */
95
+ const DoStorageFailpointLocation = Schema.Literals([
96
+ "upgrade:before-mutation",
97
+ "upgrade:after-mutation",
98
+ "upgrade:before-version",
99
+ "upgrade:after-version",
100
+ "materialize:before",
101
+ "materialize:after",
102
+ "append:before",
103
+ "append:after-batch-insert",
104
+ "append:after-record-insert",
105
+ "append:after-tail-update",
106
+ "append:after",
107
+ "export:after-thread-read",
108
+ "save-checkpoint:before",
109
+ "save-checkpoint:after",
110
+ "save-recovery-checkpoint:before",
111
+ "save-recovery-checkpoint:after",
112
+ "ledger:admit:before",
113
+ "ledger:admit:after",
114
+ "ledger:mark-ready:before",
115
+ "ledger:mark-ready:after",
116
+ "ledger:claim:before",
117
+ "ledger:claim:after",
118
+ "ledger:mark-input-applied:before",
119
+ "ledger:mark-input-applied:after",
120
+ "ledger:renew:before",
121
+ "ledger:renew:after",
122
+ "ledger:reserve-settlement:before",
123
+ "ledger:reserve-settlement:after",
124
+ "ledger:finalize-settlement:before",
125
+ "ledger:finalize-settlement:after",
126
+ "ledger:request-abort:before",
127
+ "ledger:request-abort:after",
128
+ "ledger:release:before",
129
+ "ledger:release:after",
130
+ "ledger:claim-joining:before",
131
+ "ledger:claim-joining:after",
132
+ "ledger:mark-joined:before",
133
+ "ledger:mark-joined:after",
134
+ "ledger:revert-joining:before",
135
+ "ledger:revert-joining:after",
136
+ "ledger:suspend:before",
137
+ "ledger:suspend:after",
138
+ "ledger:approval-decision:before",
139
+ "ledger:approval-decision:after",
140
+ "ledger:mark-unknown:before",
141
+ "ledger:mark-unknown:after",
142
+ "ledger:unknown-resolution:before",
143
+ "ledger:unknown-resolution:after",
144
+ "ledger:child-reservation:before",
145
+ "ledger:child-reservation:after",
146
+ "ledger:child-attach:before",
147
+ "ledger:child-attach:after",
148
+ "ledger:child-release-pending:before",
149
+ "ledger:child-release-pending:after",
150
+ "ledger:child-release:before",
151
+ "ledger:child-release:after",
152
+ "ledger:child-settled:before",
153
+ "ledger:child-settled:after"
154
+ ]);
155
+ /** Deterministic test-only fault or pause injected at a Durable Object storage boundary. */
156
+ var DoStorageFailpointError = class extends Schema.TaggedError()("DoStorageFailpointError", { location: DoStorageFailpointLocation }) {
157
+ get message() {
158
+ return `Injected Durable Object storage failure at ${this.location}.`;
159
+ }
160
+ };
161
+ //#endregion
162
+ export { DoAppendConflict, DoCheckpointConflict, DoFenceRejected, DoLedgerError, DoStorageCompatibilityError, DoStorageCorruptionError, DoStorageError, DoStorageFailpointError, DoStorageFailpointLocation, DoValueBoundExceeded, DoStorageError_exports as t };
163
+
164
+ //# sourceMappingURL=DoStorageError.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DoStorageError.mjs","names":[],"sources":["../src/DoStorageError.ts"],"sourcesContent":["import { CanonicalSequence, ProducerEpoch } from \"@effect-agent/thread/Records\";\nimport { Schema } from \"effect\";\n\n/** The Durable Object's SQLite storage uses a private-development format this adapter cannot read. */\nexport class DoStorageCompatibilityError extends Schema.TaggedError<DoStorageCompatibilityError>()(\n \"DoStorageCompatibilityError\",\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 DoStorageCorruptionError extends Schema.TaggedError<DoStorageCorruptionError>()(\n \"DoStorageCorruptionError\",\n {\n message: Schema.String,\n rowKey: Schema.String,\n table: Schema.String,\n },\n) {}\n\n/** Durable Object SQLite infrastructure failed while opening or operating the store. */\nexport class DoStorageError extends Schema.TaggedError<DoStorageError>()(\"DoStorageError\", {\n cause: Schema.optionalKey(Schema.Defect()),\n message: Schema.String,\n operation: Schema.String,\n}) {}\n\n/**\n * Durable Object SQLite infrastructure failed while operating the Submission Ledger. Surfaces\n * at the SubmissionLedger port as the typed `LedgerError` with this error preserved as its\n * cause, so the adapter-level tag is never erased.\n */\nexport class DoLedgerError extends Schema.TaggedError<DoLedgerError>()(\"DoLedgerError\", {\n cause: Schema.optionalKey(Schema.Defect()),\n message: Schema.String,\n operation: Schema.String,\n}) {}\n\n/**\n * A value to be stored exceeds the configured Durable Object per-value bound\n * (`DoStorageConfigValue.maxStoredValueBytes`, kept under the platform's 2 MB SQLite value\n * limit). The refusal happens typed BEFORE any durable mutation; no partial state is written.\n * Payloads of this size are the designed overflow case for a future R2-backed AttachmentStore\n * (deployment spec §3.1, deferred until a real attachment requirement exists).\n */\nexport class DoValueBoundExceeded extends Schema.TaggedError<DoValueBoundExceeded>()(\n \"DoValueBoundExceeded\",\n {\n actualBytes: Schema.Int,\n maxBytes: Schema.Int,\n operation: Schema.String,\n },\n) {\n override get message() {\n return (\n `A stored value of ${this.actualBytes} bytes exceeds the Durable Object per-value bound ` +\n `of ${this.maxBytes} bytes during ${this.operation}. Nothing was written. Values of this ` +\n \"size are the designed R2 AttachmentStore overflow path (deferred, deployment spec §3.1).\"\n );\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 DoAppendConflict extends Schema.TaggedError<DoAppendConflict>()(\"DoAppendConflict\", {\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 * 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 DoFenceRejected extends Schema.TaggedError<DoFenceRejected>()(\"DoFenceRejected\", {\n actualEpoch: ProducerEpoch,\n message: Schema.String,\n producerEpoch: ProducerEpoch,\n}) {}\n\n/** A checkpoint conflicts with a previously stored checkpoint at the same offset. */\nexport class DoCheckpointConflict extends Schema.TaggedError<DoCheckpointConflict>()(\n \"DoCheckpointConflict\",\n {\n message: Schema.String,\n },\n) {}\n\n/**\n * Deterministic fault-injection locations at Durable Object storage operation boundaries.\n *\n * The string list is copied VERBATIM from `SqliteStorageFailpointLocation`\n * (`packages/storage-sqlite/src/errors.ts`) so every crash-matrix row keeps the same name on\n * both platforms — the DN process-kill evidence and the DC eviction evidence address identical\n * locations. There is intentionally no Cloudflare-only location.\n */\nexport const DoStorageFailpointLocation = Schema.Literals([\n \"upgrade:before-mutation\",\n \"upgrade:after-mutation\",\n \"upgrade:before-version\",\n \"upgrade:after-version\",\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 \"save-recovery-checkpoint:before\",\n \"save-recovery-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 DoStorageFailpointLocation = typeof DoStorageFailpointLocation.Type;\n\n/** Deterministic test-only fault or pause injected at a Durable Object storage boundary. */\nexport class DoStorageFailpointError extends Schema.TaggedError<DoStorageFailpointError>()(\n \"DoStorageFailpointError\",\n {\n location: DoStorageFailpointLocation,\n },\n) {\n override get message() {\n return `Injected Durable Object storage failure at ${this.location}.`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAIA,IAAa,8BAAb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,CAAC;;AAGJ,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAClF,wBACA,EACE,SAAS,OAAO,OAClB,CACF,CAAC,CAAC,CAAC;;;;;;;;;AAUH,MAAa,6BAA6B,OAAO,SAAS;CACxD;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;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAKD,IAAa,0BAAb,cAA6C,OAAO,YAAqC,CAAC,CACxF,2BACA,EACE,UAAU,2BACZ,CACF,CAAC,CAAC;CACA,IAAa,UAAU;EACrB,OAAO,8CAA8C,KAAK,SAAS;CACrE;AACF"}
@@ -0,0 +1,17 @@
1
+ import { l as DoStorageFailpointError, u as DoStorageFailpointLocation } from "./DoStorageError-Cmhvl4TQ.mjs";
2
+ import { Context, Effect, Layer } from "effect";
3
+ declare namespace DoStorageFailpoint_d_exports {
4
+ export { DoStorageFailpoint, DoStorageFailpointHandler };
5
+ }
6
+ type DoStorageFailpointHandler = (location: DoStorageFailpointLocation) => Effect.Effect<void, DoStorageFailpointError>;
7
+ declare const DoStorageFailpoint_base: Context.ServiceClass<DoStorageFailpoint, "@effect-agent/storage-cloudflare/DoStorageFailpoint", {
8
+ readonly hit: DoStorageFailpointHandler;
9
+ }>;
10
+ /** Explicit fault-injection authority used at Durable Object storage operation boundaries. */
11
+ declare class DoStorageFailpoint extends DoStorageFailpoint_base {
12
+ /** Production default: no fault injection. */
13
+ static readonly layer: Layer.Layer<DoStorageFailpoint, never, never>;
14
+ }
15
+ //#endregion
16
+ export { DoStorageFailpoint, DoStorageFailpointHandler, DoStorageFailpoint_d_exports as t };
17
+ //# sourceMappingURL=DoStorageFailpoint.d.mts.map
@@ -0,0 +1,14 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Context, Effect, Layer } from "effect";
3
+ //#region src/DoStorageFailpoint.ts
4
+ var DoStorageFailpoint_exports = /* @__PURE__ */ __exportAll({ DoStorageFailpoint: () => DoStorageFailpoint });
5
+ const noFailpoint = () => Effect.void;
6
+ /** Explicit fault-injection authority used at Durable Object storage operation boundaries. */
7
+ var DoStorageFailpoint = class extends Context.Service()("@effect-agent/storage-cloudflare/DoStorageFailpoint") {
8
+ /** Production default: no fault injection. */
9
+ static layer = Layer.succeed(this)({ hit: noFailpoint });
10
+ };
11
+ //#endregion
12
+ export { DoStorageFailpoint, DoStorageFailpoint_exports as t };
13
+
14
+ //# sourceMappingURL=DoStorageFailpoint.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DoStorageFailpoint.mjs","names":[],"sources":["../src/DoStorageFailpoint.ts"],"sourcesContent":["import { Context, Effect, Layer } from \"effect\";\n\nimport type { DoStorageFailpointError, DoStorageFailpointLocation } from \"./DoStorageError.ts\";\n\nexport type DoStorageFailpointHandler = (\n location: DoStorageFailpointLocation,\n) => Effect.Effect<void, DoStorageFailpointError>;\n\nconst noFailpoint: DoStorageFailpointHandler = () => Effect.void;\n\n/** Explicit fault-injection authority used at Durable Object storage operation boundaries. */\nexport class DoStorageFailpoint extends Context.Service<\n DoStorageFailpoint,\n {\n readonly hit: DoStorageFailpointHandler;\n }\n>()(\"@effect-agent/storage-cloudflare/DoStorageFailpoint\") {\n /** Production default: no fault injection. */\n static readonly layer = Layer.succeed(this)({ hit: noFailpoint });\n}\n"],"mappings":";;;;AAQA,MAAM,oBAA+C,OAAO;;AAG5D,IAAa,qBAAb,cAAwC,QAAQ,QAK9C,CAAC,CAAC,qDAAqD,CAAC,CAAC;;CAEzD,OAAgB,QAAQ,MAAM,QAAQ,IAAI,CAAC,CAAC,EAAE,KAAK,YAAY,CAAC;AAClE"}
@@ -0,0 +1,34 @@
1
+ import { u as DoStorageFailpointLocation } from "./DoStorageError-Cmhvl4TQ.mjs";
2
+ import { DoStorageFailpoint, DoStorageFailpointHandler } from "./DoStorageFailpoint.mjs";
3
+ import { Context, Effect, Layer } from "effect";
4
+ //#region src/DoStorageFailpointTesting.d.ts
5
+ declare const DoStorageFailpointTestControl_base: Context.ServiceClass<DoStorageFailpointTestControl, "@effect-agent/storage-cloudflare/DoStorageFailpointTestControl", {
6
+ readonly clear: Effect.Effect<void>;
7
+ readonly setHandler: (handler: DoStorageFailpointHandler) => Effect.Effect<void>;
8
+ }>;
9
+ /** Test-only control for replacing the active Durable Object failpoint handler. */
10
+ declare class DoStorageFailpointTestControl extends DoStorageFailpointTestControl_base {
11
+ /** Reusable test Layer with a control service backed by the same handler Ref. */
12
+ static readonly layer: Layer.Layer<DoStorageFailpoint | DoStorageFailpointTestControl, never, never>;
13
+ }
14
+ /**
15
+ * The DC-specific eviction failpoint mode: instead of failing typed, an armed hit evicts the
16
+ * Durable Object through an injected `evict` thunk — in production-shaped harnesses that thunk
17
+ * is `() => ctx.abort()`, the platform's real failure mode. `ctx.abort()` never returns (it
18
+ * throws while destroying the in-memory instance and every in-flight implicit or explicit
19
+ * storage transaction rolls back), so an armed hit ends the current Attempt exactly like an
20
+ * unannounced platform eviction; DO storage — the only correctness-critical state — survives
21
+ * for the next incarnation, which the persisted alarm wakes without any incoming request.
22
+ *
23
+ * The handles stay injected: this package never imports `cloudflare:workers`, so the harness
24
+ * that owns a `DurableObjectState` supplies the thunk.
25
+ */
26
+ declare const evictionFailpointHandler: (options: {
27
+ readonly isArmed: (location: DoStorageFailpointLocation) => Effect.Effect<boolean>;
28
+ /** Kills the incarnation — e.g. `() => ctx.abort()`. Typed `void` because the platform
29
+ * declares `abort` as returning, but it throws while destroying the instance. */
30
+ readonly evict: (location: DoStorageFailpointLocation) => void;
31
+ }) => DoStorageFailpointHandler;
32
+ //#endregion
33
+ export { DoStorageFailpointTestControl, evictionFailpointHandler };
34
+ //# sourceMappingURL=DoStorageFailpointTesting.d.mts.map
@@ -0,0 +1,35 @@
1
+ import { DoStorageFailpoint } from "./DoStorageFailpoint.mjs";
2
+ import { Context, Effect, Layer, Ref } from "effect";
3
+ //#region src/DoStorageFailpointTesting.ts
4
+ const noFailpoint = () => Effect.void;
5
+ /** Test-only control for replacing the active Durable Object failpoint handler. */
6
+ var DoStorageFailpointTestControl = class DoStorageFailpointTestControl extends Context.Service()("@effect-agent/storage-cloudflare/DoStorageFailpointTestControl") {
7
+ /** Reusable test Layer with a control service backed by the same handler Ref. */
8
+ static layer = Layer.effectContext(Effect.gen(function* () {
9
+ const handler = yield* Ref.make(noFailpoint);
10
+ return Context.make(DoStorageFailpoint, DoStorageFailpoint.of({ hit: (location) => Ref.get(handler).pipe(Effect.flatMap((current) => current(location))) })).pipe(Context.add(DoStorageFailpointTestControl, DoStorageFailpointTestControl.of({
11
+ clear: Ref.set(handler, noFailpoint),
12
+ setHandler: (next) => Ref.set(handler, next)
13
+ })));
14
+ }));
15
+ };
16
+ /**
17
+ * The DC-specific eviction failpoint mode: instead of failing typed, an armed hit evicts the
18
+ * Durable Object through an injected `evict` thunk — in production-shaped harnesses that thunk
19
+ * is `() => ctx.abort()`, the platform's real failure mode. `ctx.abort()` never returns (it
20
+ * throws while destroying the in-memory instance and every in-flight implicit or explicit
21
+ * storage transaction rolls back), so an armed hit ends the current Attempt exactly like an
22
+ * unannounced platform eviction; DO storage — the only correctness-critical state — survives
23
+ * for the next incarnation, which the persisted alarm wakes without any incoming request.
24
+ *
25
+ * The handles stay injected: this package never imports `cloudflare:workers`, so the harness
26
+ * that owns a `DurableObjectState` supplies the thunk.
27
+ */
28
+ const evictionFailpointHandler = (options) => (location) => options.isArmed(location).pipe(Effect.flatMap((armed) => armed ? Effect.sync(() => {
29
+ options.evict(location);
30
+ throw new Error(`Durable Object eviction did not interrupt execution at ${location}.`);
31
+ }) : Effect.void));
32
+ //#endregion
33
+ export { DoStorageFailpointTestControl, evictionFailpointHandler };
34
+
35
+ //# sourceMappingURL=DoStorageFailpointTesting.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DoStorageFailpointTesting.mjs","names":[],"sources":["../src/DoStorageFailpointTesting.ts"],"sourcesContent":["import { Context, Effect, Layer, Ref } from \"effect\";\n\nimport type { DoStorageFailpointLocation } from \"./DoStorageError.ts\";\nimport { DoStorageFailpoint, type DoStorageFailpointHandler } from \"./DoStorageFailpoint.ts\";\n\nconst noFailpoint: DoStorageFailpointHandler = () => Effect.void;\n\n/** Test-only control for replacing the active Durable Object failpoint handler. */\nexport class DoStorageFailpointTestControl extends Context.Service<\n DoStorageFailpointTestControl,\n {\n readonly clear: Effect.Effect<void>;\n readonly setHandler: (handler: DoStorageFailpointHandler) => Effect.Effect<void>;\n }\n>()(\"@effect-agent/storage-cloudflare/DoStorageFailpointTestControl\") {\n /** Reusable test Layer with a control service backed by the same handler Ref. */\n static readonly layer = Layer.effectContext(\n Effect.gen(function* () {\n const handler = yield* Ref.make<DoStorageFailpointHandler>(noFailpoint);\n\n return Context.make(\n DoStorageFailpoint,\n DoStorageFailpoint.of({\n hit: (location) => Ref.get(handler).pipe(Effect.flatMap((current) => current(location))),\n }),\n ).pipe(\n Context.add(\n DoStorageFailpointTestControl,\n DoStorageFailpointTestControl.of({\n clear: Ref.set(handler, noFailpoint),\n setHandler: (next) => Ref.set(handler, next),\n }),\n ),\n );\n }),\n );\n}\n\n/**\n * The DC-specific eviction failpoint mode: instead of failing typed, an armed hit evicts the\n * Durable Object through an injected `evict` thunk — in production-shaped harnesses that thunk\n * is `() => ctx.abort()`, the platform's real failure mode. `ctx.abort()` never returns (it\n * throws while destroying the in-memory instance and every in-flight implicit or explicit\n * storage transaction rolls back), so an armed hit ends the current Attempt exactly like an\n * unannounced platform eviction; DO storage — the only correctness-critical state — survives\n * for the next incarnation, which the persisted alarm wakes without any incoming request.\n *\n * The handles stay injected: this package never imports `cloudflare:workers`, so the harness\n * that owns a `DurableObjectState` supplies the thunk.\n */\nexport const evictionFailpointHandler =\n (options: {\n readonly isArmed: (location: DoStorageFailpointLocation) => Effect.Effect<boolean>;\n /** Kills the incarnation — e.g. `() => ctx.abort()`. Typed `void` because the platform\n * declares `abort` as returning, but it throws while destroying the instance. */\n readonly evict: (location: DoStorageFailpointLocation) => void;\n }): DoStorageFailpointHandler =>\n (location) =>\n options.isArmed(location).pipe(\n Effect.flatMap((armed) =>\n armed\n ? // `ctx.abort()` throws while destroying the instance; that throw surfaces as a\n // defect in the (already dying) incarnation. The defensive throw below keeps the\n // guarantee — nothing after an armed hit may observe in-memory state — even if a\n // harness supplies an evict thunk that returns.\n Effect.sync((): never => {\n options.evict(location);\n throw new Error(\n `Durable Object eviction did not interrupt execution at ${location}.`,\n );\n })\n : Effect.void,\n ),\n );\n"],"mappings":";;;AAKA,MAAM,oBAA+C,OAAO;;AAG5D,IAAa,gCAAb,MAAa,sCAAsC,QAAQ,QAMzD,CAAC,CAAC,gEAAgE,CAAC,CAAC;;CAEpE,OAAgB,QAAQ,MAAM,cAC5B,OAAO,IAAI,aAAa;EACtB,MAAM,UAAU,OAAO,IAAI,KAAgC,WAAW;EAEtE,OAAO,QAAQ,KACb,oBACA,mBAAmB,GAAG,EACpB,MAAM,aAAa,IAAI,IAAI,OAAO,CAAC,CAAC,KAAK,OAAO,SAAS,YAAY,QAAQ,QAAQ,CAAC,CAAC,EACzF,CAAC,CACH,CAAC,CAAC,KACA,QAAQ,IACN,+BACA,8BAA8B,GAAG;GAC/B,OAAO,IAAI,IAAI,SAAS,WAAW;GACnC,aAAa,SAAS,IAAI,IAAI,SAAS,IAAI;EAC7C,CAAC,CACH,CACF;CACF,CAAC,CACH;AACF;;;;;;;;;;;;;AAcA,MAAa,4BACV,aAMA,aACC,QAAQ,QAAQ,QAAQ,CAAC,CAAC,KACxB,OAAO,SAAS,UACd,QAKI,OAAO,WAAkB;CACvB,QAAQ,MAAM,QAAQ;CACtB,MAAM,IAAI,MACR,0DAA0D,SAAS,EACrE;AACF,CAAC,IACD,OAAO,IACb,CACF"}
@@ -0,0 +1,12 @@
1
+ import { Effect } from "effect";
2
+ import "effect/unstable/sql/SqlClient";
3
+ import { SqliteMigrator } from "@effect/sql-sqlite-do";
4
+ //#region src/internal/migrations.d.ts
5
+ /** The current storage version recorded in `effect_agent_meta`. */
6
+ declare const CurrentDoStorageVersion = 6;
7
+ declare namespace DoStorageVersion_d_exports {
8
+ export { CurrentDoStorageVersion };
9
+ }
10
+ //#endregion
11
+ export { CurrentDoStorageVersion as n, DoStorageVersion_d_exports as t };
12
+ //# sourceMappingURL=DoStorageVersion-x5OOurvZ.d.mts.map