@effect-agent/storage-sqlite 0.1.0-beta.85 → 0.1.0-beta.86
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 +1 -1
- package/dist/SqliteActivityStore.mjs +2 -2
- package/dist/SqliteActivityStore.mjs.map +1 -1
- package/dist/SqliteMessageDeliveryStore.d.mts +1 -1
- package/dist/SqliteMessageDeliveryStore.mjs +3 -3
- package/dist/SqliteMessageDeliveryStore.mjs.map +1 -1
- package/dist/SqliteScheduleStore.d.mts +1 -1
- package/dist/SqliteScheduleStore.mjs +3 -3
- package/dist/SqliteScheduleStore.mjs.map +1 -1
- package/dist/SqliteStorageConfig.d.mts +1 -1
- package/dist/SqliteStorageConfig.mjs +1 -1
- package/dist/SqliteStorageConfig.mjs.map +1 -1
- package/dist/SqliteStorageError.mjs +1 -1
- package/dist/SqliteStorageError.mjs.map +1 -1
- package/dist/SqliteSubmissionLedger.d.mts +1 -1
- package/dist/SqliteSubmissionLedger.mjs +5 -5
- package/dist/SqliteSubmissionLedger.mjs.map +1 -1
- package/dist/SqliteSubscriptionStore.d.mts +1 -1
- package/dist/SqliteSubscriptionStore.mjs +3 -3
- package/dist/SqliteSubscriptionStore.mjs.map +1 -1
- package/dist/SqliteThreadStore.d.mts +2 -2
- package/dist/SqliteThreadStore.mjs +5 -5
- package/dist/SqliteThreadStore.mjs.map +1 -1
- package/dist/{sqlite-journal-B1dejOUb.mjs → sqlite-journal-CBOQDySe.mjs} +7 -7
- package/dist/sqlite-journal-CBOQDySe.mjs.map +1 -0
- package/package.json +1 -1
- package/src/SqliteActivityStore.ts +3 -3
- package/src/SqliteMessageDeliveryStore.ts +3 -3
- package/src/SqliteScheduleStore.ts +3 -3
- package/src/SqliteStorageConfig.ts +1 -1
- package/src/SqliteStorageError.ts +1 -1
- package/src/SqliteSubmissionLedger.ts +7 -7
- package/src/SqliteSubscriptionStore.ts +3 -7
- package/src/SqliteThreadStore.ts +19 -19
- package/src/internal/sqlite-journal.ts +9 -12
- package/dist/sqlite-journal-B1dejOUb.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import * as SqlClientService from "effect/unstable/sql/SqlClient";
|
|
3
|
-
import { ActivityMutationFailpoint, ActivityMutationFailure, ActivityProcessorStore, ActivityStoreError } from "
|
|
3
|
+
import { ActivityMutationFailpoint, ActivityMutationFailure, ActivityProcessorStore, ActivityStoreError } from "effect-agent/activity-store";
|
|
4
4
|
declare namespace SqliteActivityStore_d_exports {
|
|
5
5
|
export { SqliteActivityInitializationError, activityProcessorStoreLayer, activityProcessorStoreLayerWithFailpoints };
|
|
6
6
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { Clock, Effect, Layer, Schema } from "effect";
|
|
3
3
|
import * as SqlClientService from "effect/unstable/sql/SqlClient";
|
|
4
|
-
import { Digest } from "
|
|
5
|
-
import { ActivityBusy, ActivityClaim, ActivityClaimRequest, ActivityMutationFailpoint, ActivityOwnershipLost, ActivityProcessorKey, ActivityProcessorStore, ActivityProgress, ActivityStoreError, ActivityWorkConflict, PreparedActivity } from "
|
|
4
|
+
import { Digest } from "effect-agent/records";
|
|
5
|
+
import { ActivityBusy, ActivityClaim, ActivityClaimRequest, ActivityMutationFailpoint, ActivityOwnershipLost, ActivityProcessorKey, ActivityProcessorStore, ActivityProgress, ActivityStoreError, ActivityWorkConflict, PreparedActivity } from "effect-agent/activity-store";
|
|
6
6
|
//#region src/SqliteActivityStore.ts
|
|
7
7
|
var SqliteActivityStore_exports = /* @__PURE__ */ __exportAll({
|
|
8
8
|
activityProcessorStoreLayer: () => activityProcessorStoreLayer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteActivityStore.mjs","names":[],"sources":["../src/SqliteActivityStore.ts"],"sourcesContent":["import {\n ActivityBusy,\n ActivityClaim,\n ActivityClaimRequest,\n ActivityMutationFailpoint,\n type ActivityMutationFailure,\n ActivityOwnershipLost,\n ActivityProcessorKey,\n ActivityProcessorStore,\n ActivityProgress,\n ActivityStoreError,\n ActivityWorkConflict,\n PreparedActivity,\n} from \"@effect-agent/thread/ActivityStore\";\nimport { Digest } from \"@effect-agent/thread/Records\";\nimport { Clock, Effect, Layer, Schema } from \"effect\";\nimport * as SqlClientService from \"effect/unstable/sql/SqlClient\";\nimport type { SqlError } from \"effect/unstable/sql/SqlError\";\n\nconst STORAGE_VERSION = 1 as const;\nconst METADATA_COMPONENT = \"activity\";\nconst STATE_TABLE = \"effect_agent_activity_processor_state_v1\";\nconst StoredJson = Schema.String.check(Schema.isMaxLength(16 * 1024 * 1024));\nconst sameKey = Schema.toEquivalence(ActivityProcessorKey);\nconst sameWork = Schema.toEquivalence(PreparedActivity);\n\nclass ActivityMetadataRow extends Schema.Class<ActivityMetadataRow>(\n \"@effect-agent/storage-sqlite/ActivityMetadataRow\",\n)({\n version: Schema.Int,\n}) {}\n\nclass ActivityTableRow extends Schema.Class<ActivityTableRow>(\n \"@effect-agent/storage-sqlite/ActivityTableRow\",\n)({\n name: Schema.NonEmptyString,\n}) {}\n\nclass ActivityStateRow extends Schema.Class<ActivityStateRow>(\n \"@effect-agent/storage-sqlite/ActivityStateRow\",\n)({\n processor_id: ActivityProcessorKey.fields.processorId,\n processor_version: ActivityProcessorKey.fields.processorVersion,\n thread_id: ActivityProcessorKey.fields.threadId,\n format_version: Schema.Int,\n through_sequence: ActivityProgress.fields.throughSequence,\n epoch: ActivityProgress.fields.epoch,\n owner: ActivityProgress.fields.owner,\n lease_expires_at: ActivityProgress.fields.leaseExpiresAt,\n progress_json: StoredJson,\n}) {}\n\nclass ActivityChangeCountRow extends Schema.Class<ActivityChangeCountRow>(\n \"@effect-agent/storage-sqlite/ActivityChangeCountRow\",\n)({\n changed: Schema.Int,\n}) {}\n\nconst StoredVersionHeader = Schema.Struct({ version: Schema.Int });\n\nexport type SqliteActivityInitializationError = ActivityStoreError | ActivityMutationFailure;\n\nconst storeError = (\n operation: string,\n reason: ActivityStoreError[\"reason\"] = \"unavailable\",\n): ActivityStoreError => ActivityStoreError.make({ operation, reason });\n\nconst query = <A extends object>(\n effect: Effect.Effect<ReadonlyArray<A>, SqlError>,\n operation: string,\n) => effect.pipe(Effect.mapError(() => storeError(operation)));\n\nconst decodeRows = Effect.fn(\"SqliteActivityStore.decodeRows\")(function* <A, I>(\n schema: Schema.Codec<A, I, never>,\n rows: ReadonlyArray<unknown>,\n operation: string,\n): Effect.fn.Return<ReadonlyArray<A>, ActivityStoreError> {\n return yield* Schema.decodeUnknownEffect(Schema.Array(schema))(rows).pipe(\n Effect.mapError(() => storeError(operation, \"corrupt\")),\n );\n});\n\nconst decodeInput = Effect.fn(\"SqliteActivityStore.decodeInput\")(function* <A, I>(\n schema: Schema.Codec<A, I, never>,\n value: unknown,\n operation: string,\n): Effect.fn.Return<A, ActivityStoreError> {\n return yield* Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => storeError(operation, \"invalid-input\")),\n );\n});\n\nconst encodeProgress = Effect.fn(\"SqliteActivityStore.encodeProgress\")(function* (\n progress: ActivityProgress,\n operation: string,\n): Effect.fn.Return<string, ActivityStoreError> {\n return yield* Schema.encodeEffect(Schema.fromJsonString(ActivityProgress))(progress).pipe(\n Effect.mapError(() => storeError(operation, \"corrupt\")),\n Effect.flatMap((encoded) =>\n Schema.decodeEffect(StoredJson)(encoded).pipe(\n Effect.mapError(() => storeError(operation, \"invalid-input\")),\n ),\n ),\n );\n});\n\nconst decodeProgress = Effect.fn(\"SqliteActivityStore.decodeProgress\")(function* (\n value: string,\n operation: string,\n): Effect.fn.Return<ActivityProgress, ActivityStoreError> {\n const header = yield* Schema.decodeEffect(Schema.fromJsonString(StoredVersionHeader))(value).pipe(\n Effect.mapError(() => storeError(operation, \"corrupt\")),\n );\n\n if (header.version !== STORAGE_VERSION) {\n return yield* storeError(operation, \"incompatible\");\n }\n\n const progress = yield* Schema.decodeEffect(Schema.fromJsonString(ActivityProgress))(value).pipe(\n Effect.mapError(() => storeError(operation, \"corrupt\")),\n );\n\n const canonical = yield* encodeProgress(progress, operation);\n\n if (canonical !== value) return yield* storeError(operation, \"corrupt\");\n\n return progress;\n});\n\nconst validateProgress = Effect.fn(\"SqliteActivityStore.validateProgress\")(function* (\n progress: ActivityProgress,\n operation: string,\n): Effect.fn.Return<ActivityProgress, ActivityStoreError> {\n if (\n progress.epoch < 1 ||\n (progress.owner === null && progress.leaseExpiresAt !== 0) ||\n (progress.pending !== null &&\n (!sameKey(progress.pending.key, progress.key) ||\n progress.pending.sequence !== progress.throughSequence + 1))\n ) {\n return yield* storeError(operation, \"corrupt\");\n }\n\n return progress;\n});\n\nconst makeClaim = (progress: ActivityProgress): ActivityClaim | null =>\n progress.owner === null\n ? null\n : ActivityClaim.make({\n key: progress.key,\n owner: progress.owner,\n epoch: progress.epoch,\n throughSequence: progress.throughSequence,\n leaseExpiresAt: progress.leaseExpiresAt,\n pending: progress.pending,\n });\n\nconst ownershipLost = (claim: ActivityClaim) =>\n ActivityOwnershipLost.make({ key: claim.key, owner: claim.owner, epoch: claim.epoch });\n\n// The pinned Node SQLite client's writable withTransaction begins with BEGIN IMMEDIATE.\n// Each mutation therefore locks before reading progress, which serializes independent\n// connections without a deferred read-to-write upgrade.\nconst makeActivityStore = Effect.fn(\"SqliteActivityStore.make\")(function* () {\n const sql = yield* SqlClientService.SqlClient;\n const failpoint = yield* ActivityMutationFailpoint;\n\n yield* failpoint.hit(\"activity:initialize:before\");\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n yield* sql`\n CREATE TABLE IF NOT EXISTS effect_agent_activity_metadata (\n component TEXT PRIMARY KEY NOT NULL,\n version INTEGER NOT NULL\n )\n `;\n\n const metadataRows = yield* sql<Record<string, unknown>>`\n SELECT version FROM effect_agent_activity_metadata\n WHERE component = ${METADATA_COMPONENT}\n `;\n\n const metadata = yield* decodeRows(\n ActivityMetadataRow,\n metadataRows,\n \"decode activity schema version\",\n );\n\n if (metadata.length > 1) {\n return yield* storeError(\"decode activity schema version\", \"corrupt\");\n }\n const currentVersion = metadata[0]?.version;\n\n if (currentVersion !== undefined && currentVersion !== STORAGE_VERSION) {\n return yield* storeError(\"initialize activity schema\", \"incompatible\");\n }\n if (currentVersion === undefined) {\n const tableRows = yield* sql<Record<string, unknown>>`\n SELECT name FROM sqlite_master\n WHERE type = 'table' AND name = ${STATE_TABLE}\n `;\n\n const existing = yield* decodeRows(\n ActivityTableRow,\n tableRows,\n \"inspect activity schema\",\n );\n\n if (existing.length > 0) {\n return yield* storeError(\"initialize activity schema\", \"incompatible\");\n }\n yield* sql`\n CREATE TABLE effect_agent_activity_processor_state_v1 (\n processor_id TEXT NOT NULL,\n processor_version TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n format_version INTEGER NOT NULL,\n through_sequence INTEGER NOT NULL,\n epoch INTEGER NOT NULL,\n owner TEXT,\n lease_expires_at REAL NOT NULL,\n progress_json TEXT NOT NULL,\n PRIMARY KEY (processor_id, processor_version, thread_id)\n )\n `;\n yield* sql`\n INSERT INTO effect_agent_activity_metadata (component, version)\n VALUES (${METADATA_COMPONENT}, ${STORAGE_VERSION})\n `;\n }\n yield* sql`\n SELECT processor_id, processor_version, thread_id, format_version,\n through_sequence, epoch, owner, lease_expires_at, progress_json\n FROM effect_agent_activity_processor_state_v1\n LIMIT 0\n `;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(\"initialize activity schema\"))));\n yield* failpoint.hit(\"activity:initialize:after\");\n\n const readProgress = Effect.fn(\"SqliteActivityStore.readProgress\")(function* (\n key: ActivityProcessorKey,\n operation: string,\n ): Effect.fn.Return<ActivityProgress | null, ActivityStoreError> {\n const rawRows = yield* query(\n sql<Record<string, unknown>>`\n SELECT processor_id, processor_version, thread_id, format_version,\n through_sequence, epoch, owner, lease_expires_at, progress_json\n FROM effect_agent_activity_processor_state_v1\n WHERE processor_id = ${key.processorId}\n AND processor_version = ${key.processorVersion}\n AND thread_id = ${key.threadId}\n `,\n operation,\n );\n\n const rows = yield* decodeRows(ActivityStateRow, rawRows, operation);\n\n if (rows.length === 0) return null;\n if (rows.length !== 1) return yield* storeError(operation, \"corrupt\");\n const row = rows[0];\n\n if (row.format_version !== STORAGE_VERSION) {\n return yield* storeError(operation, \"incompatible\");\n }\n const progress = yield* decodeProgress(row.progress_json, operation);\n\n yield* validateProgress(progress, operation);\n if (\n !sameKey(progress.key, key) ||\n row.processor_id !== key.processorId ||\n row.processor_version !== key.processorVersion ||\n row.thread_id !== key.threadId ||\n row.through_sequence !== progress.throughSequence ||\n row.epoch !== progress.epoch ||\n row.owner !== progress.owner ||\n row.lease_expires_at !== progress.leaseExpiresAt\n ) {\n return yield* storeError(operation, \"corrupt\");\n }\n\n return progress;\n });\n\n const checkChanged = Effect.fn(\"SqliteActivityStore.checkChanged\")(function* (\n operation: string,\n ): Effect.fn.Return<void, ActivityStoreError> {\n const rawRows = yield* query(\n sql<Record<string, unknown>>`SELECT changes() AS changed`,\n operation,\n );\n\n const rows = yield* decodeRows(ActivityChangeCountRow, rawRows, operation);\n\n if (rows.length !== 1 || rows[0].changed !== 1) {\n return yield* storeError(operation, \"corrupt\");\n }\n });\n\n const insertProgress = Effect.fn(\"SqliteActivityStore.insertProgress\")(function* (\n progress: ActivityProgress,\n operation: string,\n ) {\n const progressJson = yield* encodeProgress(progress, operation);\n\n yield* sql`\n INSERT INTO effect_agent_activity_processor_state_v1 (\n processor_id, processor_version, thread_id, format_version, through_sequence,\n epoch, owner, lease_expires_at, progress_json\n ) VALUES (\n ${progress.key.processorId}, ${progress.key.processorVersion}, ${progress.key.threadId},\n ${STORAGE_VERSION}, ${progress.throughSequence}, ${progress.epoch}, ${progress.owner},\n ${progress.leaseExpiresAt}, ${progressJson}\n )\n `;\n yield* checkChanged(operation);\n });\n\n const updateProgress = Effect.fn(\"SqliteActivityStore.updateProgress\")(function* (\n current: ActivityProgress,\n next: ActivityProgress,\n operation: string,\n ) {\n const progressJson = yield* encodeProgress(next, operation);\n\n yield* sql`\n UPDATE effect_agent_activity_processor_state_v1\n SET format_version = ${STORAGE_VERSION},\n through_sequence = ${next.throughSequence},\n epoch = ${next.epoch},\n owner = ${next.owner},\n lease_expires_at = ${next.leaseExpiresAt},\n progress_json = ${progressJson}\n WHERE processor_id = ${current.key.processorId}\n AND processor_version = ${current.key.processorVersion}\n AND thread_id = ${current.key.threadId}\n AND through_sequence = ${current.throughSequence}\n AND epoch = ${current.epoch}\n `;\n yield* checkChanged(operation);\n });\n\n const requireLive = Effect.fn(\"SqliteActivityStore.requireLive\")(function* (\n progress: ActivityProgress | null,\n claim: ActivityClaim,\n requireSequence: boolean,\n ): Effect.fn.Return<ActivityProgress, ActivityOwnershipLost> {\n const now = yield* Clock.currentTimeMillis;\n\n if (\n progress === null ||\n !sameKey(progress.key, claim.key) ||\n progress.owner !== claim.owner ||\n progress.epoch !== claim.epoch ||\n progress.leaseExpiresAt <= now ||\n (requireSequence && progress.throughSequence !== claim.throughSequence)\n ) {\n return yield* ownershipLost(claim);\n }\n\n return progress;\n });\n\n const inspect: ActivityProcessorStore[\"Service\"][\"inspect\"] = Effect.fn(\n \"SqliteActivityStore.inspect\",\n )(function* (key) {\n const decodedKey = yield* decodeInput(ActivityProcessorKey, key, \"inspect activity progress\");\n\n return yield* readProgress(decodedKey, \"inspect activity progress\");\n });\n\n const claim: ActivityProcessorStore[\"Service\"][\"claim\"] = Effect.fn(\"SqliteActivityStore.claim\")(\n function* (request) {\n const operation = \"claim activity progress\";\n const decoded = yield* decodeInput(ActivityClaimRequest, request, operation);\n\n yield* failpoint.hit(\"activity:claim:before\");\n\n const claimed = yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* readProgress(decoded.key, operation);\n const now = yield* Clock.currentTimeMillis;\n\n if (current !== null && current.owner !== null && current.leaseExpiresAt > now) {\n return yield* ActivityBusy.make({\n key: decoded.key,\n leaseExpiresAt: current.leaseExpiresAt,\n });\n }\n\n const next = yield* Schema.decodeEffect(ActivityProgress)({\n version: STORAGE_VERSION,\n key: decoded.key,\n throughSequence: current?.throughSequence ?? 0,\n epoch: (current?.epoch ?? 0) + 1,\n owner: decoded.owner,\n leaseExpiresAt: now + decoded.leaseMillis,\n pending: current?.pending ?? null,\n advancedAt: current?.advancedAt ?? null,\n }).pipe(Effect.mapError(() => storeError(operation, \"corrupt\")));\n\n if (current === null) yield* insertProgress(next, operation);\n else yield* updateProgress(current, next, operation);\n yield* failpoint.hit(\"activity:claim:after-state\");\n const result = makeClaim(next);\n\n if (result === null) return yield* storeError(operation, \"corrupt\");\n\n return result;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(operation))));\n\n yield* failpoint.hit(\"activity:claim:after\");\n\n return claimed;\n },\n );\n\n const prepare: ActivityProcessorStore[\"Service\"][\"prepare\"] = Effect.fn(\n \"SqliteActivityStore.prepare\",\n )(function* (request) {\n const operation = \"prepare activity output\";\n const claim = yield* decodeInput(ActivityClaim, request.claim, operation);\n const work = yield* decodeInput(PreparedActivity, request.work, operation);\n\n yield* failpoint.hit(\"activity:prepare:before\");\n\n const result = yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* requireLive(\n yield* readProgress(claim.key, operation),\n claim,\n true,\n );\n\n if (current.pending !== null) {\n if (sameWork(current.pending, work)) {\n return { work: current.pending, changed: false } as const;\n }\n\n return yield* ActivityWorkConflict.make({ key: claim.key, workId: work.workId });\n }\n if (!sameKey(work.key, claim.key) || work.sequence !== current.throughSequence + 1) {\n return yield* ActivityWorkConflict.make({ key: claim.key, workId: work.workId });\n }\n const next = ActivityProgress.make({ ...current, pending: work });\n\n yield* updateProgress(current, next, operation);\n yield* failpoint.hit(\"activity:prepare:after-state\");\n\n return { work, changed: true } as const;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(operation))));\n\n if (result.changed) yield* failpoint.hit(\"activity:prepare:after\");\n\n return result.work;\n });\n\n const advance: ActivityProcessorStore[\"Service\"][\"advance\"] = Effect.fn(\n \"SqliteActivityStore.advance\",\n )(function* (request) {\n const operation = \"advance activity progress\";\n const claim = yield* decodeInput(ActivityClaim, request.claim, operation);\n const workId = yield* decodeInput(Digest, request.workId, operation);\n\n yield* failpoint.hit(\"activity:advance:before\");\n\n const nextClaim = yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* requireLive(\n yield* readProgress(claim.key, operation),\n claim,\n true,\n );\n\n if (current.pending === null || current.pending.workId !== workId) {\n return yield* ActivityWorkConflict.make({ key: claim.key, workId });\n }\n\n const next = ActivityProgress.make({\n ...current,\n throughSequence: current.pending.sequence,\n pending: null,\n advancedAt: yield* Clock.currentTimeMillis,\n });\n\n yield* updateProgress(current, next, operation);\n yield* failpoint.hit(\"activity:advance:after-state\");\n const result = makeClaim(next);\n\n if (result === null) return yield* storeError(operation, \"corrupt\");\n\n return result;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(operation))));\n\n yield* failpoint.hit(\"activity:advance:after\");\n\n return nextClaim;\n });\n\n const release: ActivityProcessorStore[\"Service\"][\"release\"] = Effect.fn(\n \"SqliteActivityStore.release\",\n )(function* (claim) {\n const operation = \"release activity claim\";\n const decoded = yield* decodeInput(ActivityClaim, claim, operation);\n\n yield* failpoint.hit(\"activity:release:before\");\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* readProgress(decoded.key, operation);\n\n if (\n current === null ||\n current.owner !== decoded.owner ||\n current.epoch !== decoded.epoch\n ) {\n return yield* ownershipLost(decoded);\n }\n const next = ActivityProgress.make({ ...current, owner: null, leaseExpiresAt: 0 });\n\n yield* updateProgress(current, next, operation);\n yield* failpoint.hit(\"activity:release:after-state\");\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(operation))));\n yield* failpoint.hit(\"activity:release:after\");\n });\n\n return ActivityProcessorStore.of({ inspect, claim, prepare, advance, release });\n});\n\n/** SQLite activity progress with mutation failpoints kept injectable for recovery tests. */\nexport const activityProcessorStoreLayerWithFailpoints: Layer.Layer<\n ActivityProcessorStore,\n SqliteActivityInitializationError,\n SqlClientService.SqlClient | ActivityMutationFailpoint\n> = Layer.effect(ActivityProcessorStore, makeActivityStore());\n\n/** SQLite activity progress with the production no-op mutation failpoint. */\nexport const activityProcessorStoreLayer: Layer.Layer<\n ActivityProcessorStore,\n SqliteActivityInitializationError,\n SqlClientService.SqlClient\n> = activityProcessorStoreLayerWithFailpoints.pipe(Layer.provide(ActivityMutationFailpoint.layer));\n"],"mappings":";;;;;;;;;;AAmBA,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,cAAc;AACpB,MAAM,aAAa,OAAO,OAAO,MAAM,OAAO,YAAY,QAAgB,CAAC;AAC3E,MAAM,UAAU,OAAO,cAAc,oBAAoB;AACzD,MAAM,WAAW,OAAO,cAAc,gBAAgB;AAEtD,IAAM,sBAAN,cAAkC,OAAO,MACvC,kDACF,CAAC,CAAC,EACA,SAAS,OAAO,IAClB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAM,mBAAN,cAA+B,OAAO,MACpC,+CACF,CAAC,CAAC,EACA,MAAM,OAAO,eACf,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAM,mBAAN,cAA+B,OAAO,MACpC,+CACF,CAAC,CAAC;CACA,cAAc,qBAAqB,OAAO;CAC1C,mBAAmB,qBAAqB,OAAO;CAC/C,WAAW,qBAAqB,OAAO;CACvC,gBAAgB,OAAO;CACvB,kBAAkB,iBAAiB,OAAO;CAC1C,OAAO,iBAAiB,OAAO;CAC/B,OAAO,iBAAiB,OAAO;CAC/B,kBAAkB,iBAAiB,OAAO;CAC1C,eAAe;AACjB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAM,yBAAN,cAAqC,OAAO,MAC1C,qDACF,CAAC,CAAC,EACA,SAA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ElE,OAAO,UAAU,IAAI,yBAAyB;EAC9C,OAAO,IACJ,gBACC,OAAO,IAAI,aAAa;GACtB,MAAM,UAAU,OAAO,aAAa,QAAQ,KAAK,SAAS;GAE1D,IACE,YAAY,QACZ,QAAQ,UAAU,QAAQ,SAC1B,QAAQ,UAAU,QAAQ,OAE1B,OAAO,OAAO,cAAc,OAAO;GAErC,MAAM,OAAO,iBAAiB,KAAK;IAAE,GAAG;IAAS,OAAO;IAAM,gBAAgB;GAAE,CAAC;GAEjF,OAAO,eAAe,SAAS,MAAM,SAAS;GAC9C,OAAO,UAAU,IAAI,8BAA8B;EACrD,CAAC,CACH,CAAC,CACA,KAAK,OAAO,SAAS,kBAAkB,OAAO,KAAK,WAAW,SAAS,CAAC,CAAC,CAAC;EAC7E,OAAO,UAAU,IAAI,wBAAwB;CAC/C,CAAC;CAED,OAAO,uBAAuB,GAAG;EAAE;EAAS;EAAO;EAAS;EAAS;CAAQ,CAAC;AAChF,CAAC;;AAGD,MAAa,4CAIT,MAAM,OAAO,wBAAwB,kBAAkB,CAAC;;AAG5D,MAAa,8BAIT,0CAA0C,KAAK,MAAM,QAAQ,0BAA0B,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"SqliteActivityStore.mjs","names":[],"sources":["../src/SqliteActivityStore.ts"],"sourcesContent":["import { Clock, Effect, Layer, Schema } from \"effect\";\nimport {\n ActivityBusy,\n ActivityClaim,\n ActivityClaimRequest,\n ActivityMutationFailpoint,\n type ActivityMutationFailure,\n ActivityOwnershipLost,\n ActivityProcessorKey,\n ActivityProcessorStore,\n ActivityProgress,\n ActivityStoreError,\n ActivityWorkConflict,\n PreparedActivity,\n} from \"effect-agent/activity-store\";\nimport { Digest } from \"effect-agent/records\";\nimport * as SqlClientService from \"effect/unstable/sql/SqlClient\";\nimport type { SqlError } from \"effect/unstable/sql/SqlError\";\n\nconst STORAGE_VERSION = 1 as const;\nconst METADATA_COMPONENT = \"activity\";\nconst STATE_TABLE = \"effect_agent_activity_processor_state_v1\";\nconst StoredJson = Schema.String.check(Schema.isMaxLength(16 * 1024 * 1024));\nconst sameKey = Schema.toEquivalence(ActivityProcessorKey);\nconst sameWork = Schema.toEquivalence(PreparedActivity);\n\nclass ActivityMetadataRow extends Schema.Class<ActivityMetadataRow>(\n \"@effect-agent/storage-sqlite/ActivityMetadataRow\",\n)({\n version: Schema.Int,\n}) {}\n\nclass ActivityTableRow extends Schema.Class<ActivityTableRow>(\n \"@effect-agent/storage-sqlite/ActivityTableRow\",\n)({\n name: Schema.NonEmptyString,\n}) {}\n\nclass ActivityStateRow extends Schema.Class<ActivityStateRow>(\n \"@effect-agent/storage-sqlite/ActivityStateRow\",\n)({\n processor_id: ActivityProcessorKey.fields.processorId,\n processor_version: ActivityProcessorKey.fields.processorVersion,\n thread_id: ActivityProcessorKey.fields.threadId,\n format_version: Schema.Int,\n through_sequence: ActivityProgress.fields.throughSequence,\n epoch: ActivityProgress.fields.epoch,\n owner: ActivityProgress.fields.owner,\n lease_expires_at: ActivityProgress.fields.leaseExpiresAt,\n progress_json: StoredJson,\n}) {}\n\nclass ActivityChangeCountRow extends Schema.Class<ActivityChangeCountRow>(\n \"@effect-agent/storage-sqlite/ActivityChangeCountRow\",\n)({\n changed: Schema.Int,\n}) {}\n\nconst StoredVersionHeader = Schema.Struct({ version: Schema.Int });\n\nexport type SqliteActivityInitializationError = ActivityStoreError | ActivityMutationFailure;\n\nconst storeError = (\n operation: string,\n reason: ActivityStoreError[\"reason\"] = \"unavailable\",\n): ActivityStoreError => ActivityStoreError.make({ operation, reason });\n\nconst query = <A extends object>(\n effect: Effect.Effect<ReadonlyArray<A>, SqlError>,\n operation: string,\n) => effect.pipe(Effect.mapError(() => storeError(operation)));\n\nconst decodeRows = Effect.fn(\"SqliteActivityStore.decodeRows\")(function* <A, I>(\n schema: Schema.Codec<A, I, never>,\n rows: ReadonlyArray<unknown>,\n operation: string,\n): Effect.fn.Return<ReadonlyArray<A>, ActivityStoreError> {\n return yield* Schema.decodeUnknownEffect(Schema.Array(schema))(rows).pipe(\n Effect.mapError(() => storeError(operation, \"corrupt\")),\n );\n});\n\nconst decodeInput = Effect.fn(\"SqliteActivityStore.decodeInput\")(function* <A, I>(\n schema: Schema.Codec<A, I, never>,\n value: unknown,\n operation: string,\n): Effect.fn.Return<A, ActivityStoreError> {\n return yield* Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => storeError(operation, \"invalid-input\")),\n );\n});\n\nconst encodeProgress = Effect.fn(\"SqliteActivityStore.encodeProgress\")(function* (\n progress: ActivityProgress,\n operation: string,\n): Effect.fn.Return<string, ActivityStoreError> {\n return yield* Schema.encodeEffect(Schema.fromJsonString(ActivityProgress))(progress).pipe(\n Effect.mapError(() => storeError(operation, \"corrupt\")),\n Effect.flatMap((encoded) =>\n Schema.decodeEffect(StoredJson)(encoded).pipe(\n Effect.mapError(() => storeError(operation, \"invalid-input\")),\n ),\n ),\n );\n});\n\nconst decodeProgress = Effect.fn(\"SqliteActivityStore.decodeProgress\")(function* (\n value: string,\n operation: string,\n): Effect.fn.Return<ActivityProgress, ActivityStoreError> {\n const header = yield* Schema.decodeEffect(Schema.fromJsonString(StoredVersionHeader))(value).pipe(\n Effect.mapError(() => storeError(operation, \"corrupt\")),\n );\n\n if (header.version !== STORAGE_VERSION) {\n return yield* storeError(operation, \"incompatible\");\n }\n\n const progress = yield* Schema.decodeEffect(Schema.fromJsonString(ActivityProgress))(value).pipe(\n Effect.mapError(() => storeError(operation, \"corrupt\")),\n );\n\n const canonical = yield* encodeProgress(progress, operation);\n\n if (canonical !== value) return yield* storeError(operation, \"corrupt\");\n\n return progress;\n});\n\nconst validateProgress = Effect.fn(\"SqliteActivityStore.validateProgress\")(function* (\n progress: ActivityProgress,\n operation: string,\n): Effect.fn.Return<ActivityProgress, ActivityStoreError> {\n if (\n progress.epoch < 1 ||\n (progress.owner === null && progress.leaseExpiresAt !== 0) ||\n (progress.pending !== null &&\n (!sameKey(progress.pending.key, progress.key) ||\n progress.pending.sequence !== progress.throughSequence + 1))\n ) {\n return yield* storeError(operation, \"corrupt\");\n }\n\n return progress;\n});\n\nconst makeClaim = (progress: ActivityProgress): ActivityClaim | null =>\n progress.owner === null\n ? null\n : ActivityClaim.make({\n key: progress.key,\n owner: progress.owner,\n epoch: progress.epoch,\n throughSequence: progress.throughSequence,\n leaseExpiresAt: progress.leaseExpiresAt,\n pending: progress.pending,\n });\n\nconst ownershipLost = (claim: ActivityClaim) =>\n ActivityOwnershipLost.make({ key: claim.key, owner: claim.owner, epoch: claim.epoch });\n\n// The pinned Node SQLite client's writable withTransaction begins with BEGIN IMMEDIATE.\n// Each mutation therefore locks before reading progress, which serializes independent\n// connections without a deferred read-to-write upgrade.\nconst makeActivityStore = Effect.fn(\"SqliteActivityStore.make\")(function* () {\n const sql = yield* SqlClientService.SqlClient;\n const failpoint = yield* ActivityMutationFailpoint;\n\n yield* failpoint.hit(\"activity:initialize:before\");\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n yield* sql`\n CREATE TABLE IF NOT EXISTS effect_agent_activity_metadata (\n component TEXT PRIMARY KEY NOT NULL,\n version INTEGER NOT NULL\n )\n `;\n\n const metadataRows = yield* sql<Record<string, unknown>>`\n SELECT version FROM effect_agent_activity_metadata\n WHERE component = ${METADATA_COMPONENT}\n `;\n\n const metadata = yield* decodeRows(\n ActivityMetadataRow,\n metadataRows,\n \"decode activity schema version\",\n );\n\n if (metadata.length > 1) {\n return yield* storeError(\"decode activity schema version\", \"corrupt\");\n }\n const currentVersion = metadata[0]?.version;\n\n if (currentVersion !== undefined && currentVersion !== STORAGE_VERSION) {\n return yield* storeError(\"initialize activity schema\", \"incompatible\");\n }\n if (currentVersion === undefined) {\n const tableRows = yield* sql<Record<string, unknown>>`\n SELECT name FROM sqlite_master\n WHERE type = 'table' AND name = ${STATE_TABLE}\n `;\n\n const existing = yield* decodeRows(\n ActivityTableRow,\n tableRows,\n \"inspect activity schema\",\n );\n\n if (existing.length > 0) {\n return yield* storeError(\"initialize activity schema\", \"incompatible\");\n }\n yield* sql`\n CREATE TABLE effect_agent_activity_processor_state_v1 (\n processor_id TEXT NOT NULL,\n processor_version TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n format_version INTEGER NOT NULL,\n through_sequence INTEGER NOT NULL,\n epoch INTEGER NOT NULL,\n owner TEXT,\n lease_expires_at REAL NOT NULL,\n progress_json TEXT NOT NULL,\n PRIMARY KEY (processor_id, processor_version, thread_id)\n )\n `;\n yield* sql`\n INSERT INTO effect_agent_activity_metadata (component, version)\n VALUES (${METADATA_COMPONENT}, ${STORAGE_VERSION})\n `;\n }\n yield* sql`\n SELECT processor_id, processor_version, thread_id, format_version,\n through_sequence, epoch, owner, lease_expires_at, progress_json\n FROM effect_agent_activity_processor_state_v1\n LIMIT 0\n `;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(\"initialize activity schema\"))));\n yield* failpoint.hit(\"activity:initialize:after\");\n\n const readProgress = Effect.fn(\"SqliteActivityStore.readProgress\")(function* (\n key: ActivityProcessorKey,\n operation: string,\n ): Effect.fn.Return<ActivityProgress | null, ActivityStoreError> {\n const rawRows = yield* query(\n sql<Record<string, unknown>>`\n SELECT processor_id, processor_version, thread_id, format_version,\n through_sequence, epoch, owner, lease_expires_at, progress_json\n FROM effect_agent_activity_processor_state_v1\n WHERE processor_id = ${key.processorId}\n AND processor_version = ${key.processorVersion}\n AND thread_id = ${key.threadId}\n `,\n operation,\n );\n\n const rows = yield* decodeRows(ActivityStateRow, rawRows, operation);\n\n if (rows.length === 0) return null;\n if (rows.length !== 1) return yield* storeError(operation, \"corrupt\");\n const row = rows[0];\n\n if (row.format_version !== STORAGE_VERSION) {\n return yield* storeError(operation, \"incompatible\");\n }\n const progress = yield* decodeProgress(row.progress_json, operation);\n\n yield* validateProgress(progress, operation);\n if (\n !sameKey(progress.key, key) ||\n row.processor_id !== key.processorId ||\n row.processor_version !== key.processorVersion ||\n row.thread_id !== key.threadId ||\n row.through_sequence !== progress.throughSequence ||\n row.epoch !== progress.epoch ||\n row.owner !== progress.owner ||\n row.lease_expires_at !== progress.leaseExpiresAt\n ) {\n return yield* storeError(operation, \"corrupt\");\n }\n\n return progress;\n });\n\n const checkChanged = Effect.fn(\"SqliteActivityStore.checkChanged\")(function* (\n operation: string,\n ): Effect.fn.Return<void, ActivityStoreError> {\n const rawRows = yield* query(\n sql<Record<string, unknown>>`SELECT changes() AS changed`,\n operation,\n );\n\n const rows = yield* decodeRows(ActivityChangeCountRow, rawRows, operation);\n\n if (rows.length !== 1 || rows[0].changed !== 1) {\n return yield* storeError(operation, \"corrupt\");\n }\n });\n\n const insertProgress = Effect.fn(\"SqliteActivityStore.insertProgress\")(function* (\n progress: ActivityProgress,\n operation: string,\n ) {\n const progressJson = yield* encodeProgress(progress, operation);\n\n yield* sql`\n INSERT INTO effect_agent_activity_processor_state_v1 (\n processor_id, processor_version, thread_id, format_version, through_sequence,\n epoch, owner, lease_expires_at, progress_json\n ) VALUES (\n ${progress.key.processorId}, ${progress.key.processorVersion}, ${progress.key.threadId},\n ${STORAGE_VERSION}, ${progress.throughSequence}, ${progress.epoch}, ${progress.owner},\n ${progress.leaseExpiresAt}, ${progressJson}\n )\n `;\n yield* checkChanged(operation);\n });\n\n const updateProgress = Effect.fn(\"SqliteActivityStore.updateProgress\")(function* (\n current: ActivityProgress,\n next: ActivityProgress,\n operation: string,\n ) {\n const progressJson = yield* encodeProgress(next, operation);\n\n yield* sql`\n UPDATE effect_agent_activity_processor_state_v1\n SET format_version = ${STORAGE_VERSION},\n through_sequence = ${next.throughSequence},\n epoch = ${next.epoch},\n owner = ${next.owner},\n lease_expires_at = ${next.leaseExpiresAt},\n progress_json = ${progressJson}\n WHERE processor_id = ${current.key.processorId}\n AND processor_version = ${current.key.processorVersion}\n AND thread_id = ${current.key.threadId}\n AND through_sequence = ${current.throughSequence}\n AND epoch = ${current.epoch}\n `;\n yield* checkChanged(operation);\n });\n\n const requireLive = Effect.fn(\"SqliteActivityStore.requireLive\")(function* (\n progress: ActivityProgress | null,\n claim: ActivityClaim,\n requireSequence: boolean,\n ): Effect.fn.Return<ActivityProgress, ActivityOwnershipLost> {\n const now = yield* Clock.currentTimeMillis;\n\n if (\n progress === null ||\n !sameKey(progress.key, claim.key) ||\n progress.owner !== claim.owner ||\n progress.epoch !== claim.epoch ||\n progress.leaseExpiresAt <= now ||\n (requireSequence && progress.throughSequence !== claim.throughSequence)\n ) {\n return yield* ownershipLost(claim);\n }\n\n return progress;\n });\n\n const inspect: ActivityProcessorStore[\"Service\"][\"inspect\"] = Effect.fn(\n \"SqliteActivityStore.inspect\",\n )(function* (key) {\n const decodedKey = yield* decodeInput(ActivityProcessorKey, key, \"inspect activity progress\");\n\n return yield* readProgress(decodedKey, \"inspect activity progress\");\n });\n\n const claim: ActivityProcessorStore[\"Service\"][\"claim\"] = Effect.fn(\"SqliteActivityStore.claim\")(\n function* (request) {\n const operation = \"claim activity progress\";\n const decoded = yield* decodeInput(ActivityClaimRequest, request, operation);\n\n yield* failpoint.hit(\"activity:claim:before\");\n\n const claimed = yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* readProgress(decoded.key, operation);\n const now = yield* Clock.currentTimeMillis;\n\n if (current !== null && current.owner !== null && current.leaseExpiresAt > now) {\n return yield* ActivityBusy.make({\n key: decoded.key,\n leaseExpiresAt: current.leaseExpiresAt,\n });\n }\n\n const next = yield* Schema.decodeEffect(ActivityProgress)({\n version: STORAGE_VERSION,\n key: decoded.key,\n throughSequence: current?.throughSequence ?? 0,\n epoch: (current?.epoch ?? 0) + 1,\n owner: decoded.owner,\n leaseExpiresAt: now + decoded.leaseMillis,\n pending: current?.pending ?? null,\n advancedAt: current?.advancedAt ?? null,\n }).pipe(Effect.mapError(() => storeError(operation, \"corrupt\")));\n\n if (current === null) yield* insertProgress(next, operation);\n else yield* updateProgress(current, next, operation);\n yield* failpoint.hit(\"activity:claim:after-state\");\n const result = makeClaim(next);\n\n if (result === null) return yield* storeError(operation, \"corrupt\");\n\n return result;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(operation))));\n\n yield* failpoint.hit(\"activity:claim:after\");\n\n return claimed;\n },\n );\n\n const prepare: ActivityProcessorStore[\"Service\"][\"prepare\"] = Effect.fn(\n \"SqliteActivityStore.prepare\",\n )(function* (request) {\n const operation = \"prepare activity output\";\n const claim = yield* decodeInput(ActivityClaim, request.claim, operation);\n const work = yield* decodeInput(PreparedActivity, request.work, operation);\n\n yield* failpoint.hit(\"activity:prepare:before\");\n\n const result = yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* requireLive(\n yield* readProgress(claim.key, operation),\n claim,\n true,\n );\n\n if (current.pending !== null) {\n if (sameWork(current.pending, work)) {\n return { work: current.pending, changed: false } as const;\n }\n\n return yield* ActivityWorkConflict.make({ key: claim.key, workId: work.workId });\n }\n if (!sameKey(work.key, claim.key) || work.sequence !== current.throughSequence + 1) {\n return yield* ActivityWorkConflict.make({ key: claim.key, workId: work.workId });\n }\n const next = ActivityProgress.make({ ...current, pending: work });\n\n yield* updateProgress(current, next, operation);\n yield* failpoint.hit(\"activity:prepare:after-state\");\n\n return { work, changed: true } as const;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(operation))));\n\n if (result.changed) yield* failpoint.hit(\"activity:prepare:after\");\n\n return result.work;\n });\n\n const advance: ActivityProcessorStore[\"Service\"][\"advance\"] = Effect.fn(\n \"SqliteActivityStore.advance\",\n )(function* (request) {\n const operation = \"advance activity progress\";\n const claim = yield* decodeInput(ActivityClaim, request.claim, operation);\n const workId = yield* decodeInput(Digest, request.workId, operation);\n\n yield* failpoint.hit(\"activity:advance:before\");\n\n const nextClaim = yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* requireLive(\n yield* readProgress(claim.key, operation),\n claim,\n true,\n );\n\n if (current.pending === null || current.pending.workId !== workId) {\n return yield* ActivityWorkConflict.make({ key: claim.key, workId });\n }\n\n const next = ActivityProgress.make({\n ...current,\n throughSequence: current.pending.sequence,\n pending: null,\n advancedAt: yield* Clock.currentTimeMillis,\n });\n\n yield* updateProgress(current, next, operation);\n yield* failpoint.hit(\"activity:advance:after-state\");\n const result = makeClaim(next);\n\n if (result === null) return yield* storeError(operation, \"corrupt\");\n\n return result;\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(operation))));\n\n yield* failpoint.hit(\"activity:advance:after\");\n\n return nextClaim;\n });\n\n const release: ActivityProcessorStore[\"Service\"][\"release\"] = Effect.fn(\n \"SqliteActivityStore.release\",\n )(function* (claim) {\n const operation = \"release activity claim\";\n const decoded = yield* decodeInput(ActivityClaim, claim, operation);\n\n yield* failpoint.hit(\"activity:release:before\");\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* readProgress(decoded.key, operation);\n\n if (\n current === null ||\n current.owner !== decoded.owner ||\n current.epoch !== decoded.epoch\n ) {\n return yield* ownershipLost(decoded);\n }\n const next = ActivityProgress.make({ ...current, owner: null, leaseExpiresAt: 0 });\n\n yield* updateProgress(current, next, operation);\n yield* failpoint.hit(\"activity:release:after-state\");\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", () => Effect.fail(storeError(operation))));\n yield* failpoint.hit(\"activity:release:after\");\n });\n\n return ActivityProcessorStore.of({ inspect, claim, prepare, advance, release });\n});\n\n/** SQLite activity progress with mutation failpoints kept injectable for recovery tests. */\nexport const activityProcessorStoreLayerWithFailpoints: Layer.Layer<\n ActivityProcessorStore,\n SqliteActivityInitializationError,\n SqlClientService.SqlClient | ActivityMutationFailpoint\n> = Layer.effect(ActivityProcessorStore, makeActivityStore());\n\n/** SQLite activity progress with the production no-op mutation failpoint. */\nexport const activityProcessorStoreLayer: Layer.Layer<\n ActivityProcessorStore,\n SqliteActivityInitializationError,\n SqlClientService.SqlClient\n> = activityProcessorStoreLayerWithFailpoints.pipe(Layer.provide(ActivityMutationFailpoint.layer));\n"],"mappings":";;;;;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kB,OAAO,KAAK,WAAW,SAAS,CAAC,CAAC,CAAC;EAC7E,OAAO,UAAU,IAAI,wBAAwB;CAC/C,CAAC;CAED,OAAO,uBAAuB,GAAG;EAAE;EAAS;EAAO;EAAS;EAAS;CAAQ,CAAC;AAChF,CAAC;;AAGD,MAAa,4CAIT,MAAM,OAAO,wBAAwB,kBAAkB,CAAC;;AAG5D,MAAa,8BAIT,0CAA0C,KAAK,MAAM,QAAQ,0BAA0B,KAAK,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as SqliteStorageCompatibilityError, o as SqliteStorageCorruptionError, s as SqliteStorageError } from "./SqliteStorageError-DVWeaWLm.mjs";
|
|
2
2
|
import { SqliteStorageConfig } from "./SqliteStorageConfig.mjs";
|
|
3
3
|
import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
|
|
4
|
-
import { MessageDeliveryError, MessageDeliveryStore, MessageDeliveryStoreLimits } from "@effect-agent/thread/MessageDelivery";
|
|
5
4
|
import { Layer } from "effect";
|
|
5
|
+
import { MessageDeliveryError, MessageDeliveryStore, MessageDeliveryStoreLimits } from "effect-agent/message-delivery";
|
|
6
6
|
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
7
7
|
declare namespace SqliteMessageDeliveryStore_d_exports {
|
|
8
8
|
export { messageDeliveryStoreLayer };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { a as initializeSqliteJournal } from "./sqlite-journal-
|
|
3
|
-
import { MessageDeliveryError, MessageDeliveryStore } from "@effect-agent/thread/MessageDelivery";
|
|
4
|
-
import { SqlMessageDeliveryTransaction, makeSqlMessageDeliveryStore } from "@effect-agent/thread/SqlMessageDeliveryStore";
|
|
2
|
+
import { a as initializeSqliteJournal } from "./sqlite-journal-CBOQDySe.mjs";
|
|
5
3
|
import { Effect, Layer } from "effect";
|
|
4
|
+
import { MessageDeliveryError, MessageDeliveryStore } from "effect-agent/message-delivery";
|
|
5
|
+
import { SqlMessageDeliveryTransaction, makeSqlMessageDeliveryStore } from "effect-agent/sql-message-delivery-store";
|
|
6
6
|
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
7
7
|
//#region src/SqliteMessageDeliveryStore.ts
|
|
8
8
|
var SqliteMessageDeliveryStore_exports = /* @__PURE__ */ __exportAll({ messageDeliveryStoreLayer: () => messageDeliveryStoreLayer });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteMessageDeliveryStore.mjs","names":[],"sources":["../src/SqliteMessageDeliveryStore.ts"],"sourcesContent":["import {\n MessageDeliveryError,\n MessageDeliveryStore,\n type MessageDeliveryStoreLimits,\n} from \"
|
|
1
|
+
{"version":3,"file":"SqliteMessageDeliveryStore.mjs","names":[],"sources":["../src/SqliteMessageDeliveryStore.ts"],"sourcesContent":["import { Effect, Layer } from \"effect\";\nimport {\n MessageDeliveryError,\n MessageDeliveryStore,\n type MessageDeliveryStoreLimits,\n} from \"effect-agent/message-delivery\";\nimport {\n makeSqlMessageDeliveryStore,\n SqlMessageDeliveryTransaction,\n} from \"effect-agent/sql-message-delivery-store\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\nimport { initializeSqliteJournal } from \"./internal/sqlite-journal.ts\";\n\nconst transactions = Layer.effect(\n SqlMessageDeliveryTransaction,\n Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n return SqlMessageDeliveryTransaction.of({\n run: (body) =>\n sql\n .withTransaction(body)\n .pipe(\n Effect.catchTag(\"SqlError\", () =>\n MessageDeliveryError.make({ reason: \"storage\", operation: \"transaction\" }),\n ),\n ),\n });\n }),\n);\n\n/** Source-owned message obligations in the host's existing SQLite database. */\nexport const messageDeliveryStoreLayer = (limits?: MessageDeliveryStoreLimits) =>\n Layer.effect(\n MessageDeliveryStore,\n Effect.gen(function* () {\n yield* initializeSqliteJournal();\n\n return yield* makeSqlMessageDeliveryStore(limits, { maxStoredValueBytes: 16 * 1024 * 1024 });\n }),\n ).pipe(Layer.provide(transactions));\n"],"mappings":";;;;;;;;AAcA,MAAM,eAAe,MAAM,OACzB,+BACA,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,OAAO,UAAU;CAE7B,OAAO,8BAA8B,GAAG,EACtC,MAAM,SACJ,IACG,gBAAgB,IAAI,CAAC,CACrB,KACC,OAAO,SAAS,kBACd,qBAAqB,KAAK;EAAE,QAAQ;EAAW,WAAW;CAAc,CAAC,CAC3E,CACF,EACN,CAAC;AACH,CAAC,CACH;;AAGA,MAAa,6BAA6B,WACxC,MAAM,OACJ,sBACA,OAAO,IAAI,aAAa;CACtB,OAAO,wBAAwB;CAE/B,OAAO,OAAO,4BAA4B,QAAQ,EAAE,qBAAqB,SAAiB,CAAC;AAC7F,CAAC,CACH,CAAC,CAAC,KAAK,MAAM,QAAQ,YAAY,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
|
|
|
3
3
|
import { SqliteStorageInitializationError } from "./SqliteThreadStore.mjs";
|
|
4
4
|
import { Layer } from "effect";
|
|
5
5
|
import * as SqlClientService from "effect/unstable/sql/SqlClient";
|
|
6
|
-
import { ScheduleStore } from "
|
|
6
|
+
import { ScheduleStore } from "effect-agent/schedule";
|
|
7
7
|
declare namespace SqliteScheduleStore_d_exports {
|
|
8
8
|
export { scheduleStoreLayer };
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { a as initializeSqliteJournal } from "./sqlite-journal-
|
|
2
|
+
import { a as initializeSqliteJournal } from "./sqlite-journal-CBOQDySe.mjs";
|
|
3
3
|
import { Effect, Layer, Result, Schema } from "effect";
|
|
4
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 "
|
|
6
|
-
import { applyScheduleChange, scheduleDeadline, scheduleUsesCapacity } from "
|
|
5
|
+
import { ScheduleCapacityError, ScheduleChange, ScheduleConflict, ScheduleDueCursor, ScheduleFailpoint, ScheduleId, ScheduleInstant, ScheduleKey, ScheduleNotFound, ScheduleOwner, SchedulePageRequest, ScheduleRecord, ScheduleStorageError, ScheduleStore, defaultSchedulingLimits } from "effect-agent/schedule";
|
|
6
|
+
import { applyScheduleChange, scheduleDeadline, scheduleUsesCapacity } from "effect-agent/schedule-transition";
|
|
7
7
|
//#region src/SqliteScheduleStore.ts
|
|
8
8
|
var SqliteScheduleStore_exports = /* @__PURE__ */ __exportAll({ scheduleStoreLayer: () => scheduleStoreLayer });
|
|
9
9
|
const StoredScheduleJson = Schema.String.check(Schema.isMaxLength(16777216));
|
|
@@ -1 +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.decodeEffect(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,cA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,CAAC;AAC1E,CAAC;;AAGD,MAAa,qBAIT,MAAM,OAAO,aAAa,CAAC,CAAC,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"SqliteScheduleStore.mjs","names":[],"sources":["../src/SqliteScheduleStore.ts"],"sourcesContent":["import { Effect, Layer, Result, Schema } from \"effect\";\nimport {\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/schedule\";\nimport {\n scheduleUsesCapacity,\n applyScheduleChange,\n scheduleDeadline,\n} from \"effect-agent/schedule-transition\";\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.decodeEffect(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,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AkB,IAAI;EACxB,EAAE;CACJ,CAAC;CAED,MAAM,eAAyD,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"}
|
|
@@ -10,7 +10,7 @@ declare const SqliteStorageConfigValue_base: Schema.Class<SqliteStorageConfigVal
|
|
|
10
10
|
* Submission ownership lease duration in milliseconds (D5). The lease is a liveness hint
|
|
11
11
|
* that makes an abandoned claim reclaimable; correctness never depends on it because every
|
|
12
12
|
* canonical append is fenced by producer epoch. Convenience layers default this to
|
|
13
|
-
* `DEFAULT_OWNERSHIP_LEASE_DURATION` from
|
|
13
|
+
* `DEFAULT_OWNERSHIP_LEASE_DURATION` from `effect-agent/submission-ledger`.
|
|
14
14
|
*/
|
|
15
15
|
readonly ownershipLeaseDuration: Schema.Int;
|
|
16
16
|
/**
|
|
@@ -21,7 +21,7 @@ var SqliteStorageConfigValue = class extends Schema.Class("@effect-agent/storage
|
|
|
21
21
|
* Submission ownership lease duration in milliseconds (D5). The lease is a liveness hint
|
|
22
22
|
* that makes an abandoned claim reclaimable; correctness never depends on it because every
|
|
23
23
|
* canonical append is fenced by producer epoch. Convenience layers default this to
|
|
24
|
-
* `DEFAULT_OWNERSHIP_LEASE_DURATION` from
|
|
24
|
+
* `DEFAULT_OWNERSHIP_LEASE_DURATION` from `effect-agent/submission-ledger`.
|
|
25
25
|
*/
|
|
26
26
|
ownershipLeaseDuration: OwnershipLeaseMillis,
|
|
27
27
|
/**
|
|
@@ -1 +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
|
|
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/submission-ledger`.\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,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
|
-
import { CanonicalSequence, ProducerEpoch } from "
|
|
3
|
+
import { CanonicalSequence, ProducerEpoch } from "effect-agent/records";
|
|
4
4
|
//#region src/SqliteStorageError.ts
|
|
5
5
|
var SqliteStorageError_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
SqliteAppendConflict: () => SqliteAppendConflict,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteStorageError.mjs","names":[],"sources":["../src/SqliteStorageError.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"SqliteStorageError.mjs","names":[],"sources":["../src/SqliteStorageError.ts"],"sourcesContent":["import { Schema } from \"effect\";\nimport { CanonicalSequence, ProducerEpoch } from \"effect-agent/records\";\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 \"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 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":";;;;;;;;;;;;;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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;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"}
|
|
@@ -3,7 +3,7 @@ import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
|
|
|
3
3
|
import { SqliteStorageInitializationError, SqliteStorageOptions } from "./SqliteThreadStore.mjs";
|
|
4
4
|
import { Crypto, Layer } from "effect";
|
|
5
5
|
import * as SqlClientService from "effect/unstable/sql/SqlClient";
|
|
6
|
-
import { SubmissionLedger } from "
|
|
6
|
+
import { SubmissionLedger } from "effect-agent/submission-ledger";
|
|
7
7
|
declare namespace SqliteSubmissionLedger_d_exports {
|
|
8
8
|
export { ledgerLayer, submissionLedgerLayer };
|
|
9
9
|
}
|
|
@@ -2,16 +2,16 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
|
2
2
|
import { SqliteStorageConfig } from "./SqliteStorageConfig.mjs";
|
|
3
3
|
import { SqliteLedgerError, SqliteStorageCorruptionError, SqliteStorageError, SqliteWriteContention } from "./SqliteStorageError.mjs";
|
|
4
4
|
import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
|
|
5
|
-
import { a as initializeSqliteJournal, i as decodeRows } from "./sqlite-journal-
|
|
5
|
+
import { a as initializeSqliteJournal, i as decodeRows } from "./sqlite-journal-CBOQDySe.mjs";
|
|
6
6
|
import { storageConfigLayer, storageFailpointLayer } from "./SqliteThreadStore.mjs";
|
|
7
7
|
import { Clock, Context, Crypto, DateTime, Effect, Layer, Option, Schema, Stream } from "effect";
|
|
8
8
|
import * as SqlClientService from "effect/unstable/sql/SqlClient";
|
|
9
|
-
import { EMPTY_TAIL_DIGEST } from "@effect-agent/thread/Digest";
|
|
10
|
-
import { ApprovalDecision, CanonicalSequence, DefinitionDigests, Digest, PersistedJson, ProducerEpoch, RecordEnvelope, SettlementOutcome, WorkerAdmission } from "@effect-agent/thread/Records";
|
|
11
9
|
import { NodeCrypto } from "@effect/platform-node";
|
|
12
10
|
import { SqliteClient } from "@effect/sql-sqlite-node";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
11
|
+
import { EMPTY_TAIL_DIGEST } from "effect-agent/digest";
|
|
12
|
+
import { ApprovalDecision, CanonicalSequence, DefinitionDigests, Digest, PersistedJson, ProducerEpoch, RecordEnvelope, SettlementOutcome, WorkerAdmission } from "effect-agent/records";
|
|
13
|
+
import { InputMessage } from "effect-agent/messaging";
|
|
14
|
+
import { AbortCommand, AbortIntent, AbortIntentRequest, AdmissionAdmitted, AdmissionConflict, AdmissionFence, AdmissionGroup, AdmissionNotAdmitted, AdmissionPolicyError, AdmissionRequest, AdmissionResult, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, AttachChildToReservationRequest, BeginChildBudgetReleaseRequest, ChildAttachmentSnapshot, ChildBudgetReservationRequest, ChildBudgetReservationSnapshot, ChildReservationConflict, ChildReservationStatus, ChildSettledNotification, Claim, ClaimJoiningRequest, ClaimRequest, InputAppliedMarker, JoinSnapshot, JoinedToHost, JoiningClaim, LedgerCapabilities, LedgerError, MarkInputAppliedRequest, MarkJoinedRequest, MarkReadyRequest, MarkUnknownRequest, OwnershipLost, OwnershipRenewal, OwnershipSnapshot, ParentLinkage, QueueSequence, RecoverySnapshot, RecoverySnapshotRequest, ReleaseChildBudgetRequest, ReleaseOwnershipRequest, RenewOwnershipRequest, ReservedChildBudget, ReservedSettlement, RevertJoiningRequest, Settlement, SettlementConflict, SettlementFinalization, SettlementReservation, SettlementReservationSnapshot, SubmissionAdmissionFence, SubmissionLedger, SubmissionLookup, SubmissionLookupByKey, SubmissionSnapshot, SubmissionState, SuspendRequest, SuspensionReason, SuspensionSnapshot, UnknownResolution, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, settlementFailureFromRecord, submissionAbortRecordId } from "effect-agent/submission-ledger";
|
|
15
15
|
//#region src/SqliteSubmissionLedger.ts
|
|
16
16
|
var SqliteSubmissionLedger_exports = /* @__PURE__ */ __exportAll({
|
|
17
17
|
ledgerLayer: () => ledgerLayer,
|