@systemfsoftware/agent-storage-memory 0.0.0-bootstrap.0 → 0.1.0-beta.192
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/LICENSE +21 -0
- package/dist/MemoryMessageDeliveryStore-B50JDqxF.mjs +609 -0
- package/dist/MemoryMessageDeliveryStore-B50JDqxF.mjs.map +1 -0
- package/dist/MemoryMessageDeliveryStore-BmLntoBA.d.mts +18 -0
- package/dist/MemoryMessageDeliveryStore.d.mts +2 -0
- package/dist/MemoryMessageDeliveryStore.mjs +1 -0
- package/dist/MemoryScheduleStore-Bb85CXg1.mjs +163 -0
- package/dist/MemoryScheduleStore-Bb85CXg1.mjs.map +1 -0
- package/dist/MemoryScheduleStore-C_ll7Xyr.d.mts +8 -0
- package/dist/MemoryScheduleStore.d.mts +2 -0
- package/dist/MemoryScheduleStore.mjs +1 -0
- package/dist/MemorySemanticIndex-DYljUBy4.mjs +224 -0
- package/dist/MemorySemanticIndex-DYljUBy4.mjs.map +1 -0
- package/dist/MemorySemanticIndex-DrcJ7UG4.d.mts +20 -0
- package/dist/MemorySemanticIndex.d.mts +2 -0
- package/dist/MemorySemanticIndex.mjs +1 -0
- package/dist/MemorySubmissionLedger-DO-F22Gu.d.mts +28 -0
- package/dist/MemorySubmissionLedger-lc4VJ_vq.mjs +1566 -0
- package/dist/MemorySubmissionLedger-lc4VJ_vq.mjs.map +1 -0
- package/dist/MemorySubmissionLedger.d.mts +2 -0
- package/dist/MemorySubmissionLedger.mjs +1 -0
- package/dist/MemorySubscriptionStore-BWZ9lcIY.d.mts +7 -0
- package/dist/MemorySubscriptionStore-CFuGVxFD.mjs +929 -0
- package/dist/MemorySubscriptionStore-CFuGVxFD.mjs.map +1 -0
- package/dist/MemorySubscriptionStore.d.mts +2 -0
- package/dist/MemorySubscriptionStore.mjs +1 -0
- package/dist/MemoryThreadStore-BX3sRYhE.d.mts +21 -0
- package/dist/MemoryThreadStore-Dtwe-7h4.mjs +1415 -0
- package/dist/MemoryThreadStore-Dtwe-7h4.mjs.map +1 -0
- package/dist/MemoryThreadStore.d.mts +2 -0
- package/dist/MemoryThreadStore.mjs +1 -0
- package/dist/MemoryThreadStoreKernel-5ya9AJvL.d.mts +85 -0
- package/dist/WorkSelection-Xr9mCon_.mjs +29 -0
- package/dist/WorkSelection-Xr9mCon_.mjs.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +7 -0
- package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
- package/package.json +67 -5
- package/src/MemoryMessageDeliveryStore.ts +1004 -0
- package/src/MemoryScheduleStore.ts +324 -0
- package/src/MemorySemanticIndex.ts +360 -0
- package/src/MemorySubmissionLedger.ts +3590 -0
- package/src/MemorySubscriptionStore.ts +1762 -0
- package/src/MemoryThreadStore.ts +2810 -0
- package/src/index.ts +6 -0
- package/src/internal/MemoryThreadStoreKernel.ts +156 -0
- package/src/internal/WorkSelection.ts +29 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemorySubscriptionStore-CFuGVxFD.mjs","names":[],"sources":["../src/MemorySubscriptionStore.ts"],"sourcesContent":["import { Digest } from '@systemfsoftware/agent/records'\nimport { compareScheduleNames } from '@systemfsoftware/agent/schedule-transition'\nimport {\n AcceptedEvent,\n defaultSubscriptionLimits,\n DeliveryChange,\n SourcePartition,\n SubscriptionChange,\n SubscriptionDelivery,\n SubscriptionDeliveryKey,\n subscriptionDeliveryKeyString,\n SubscriptionError,\n SubscriptionFailpoint,\n SubscriptionKey,\n subscriptionKeyString,\n SubscriptionLimits,\n SubscriptionName,\n SubscriptionRecord,\n SubscriptionRetentionPolicy,\n SubscriptionScanCursors,\n SubscriptionStore,\n} from '@systemfsoftware/agent/subscription'\nimport {\n applySubscriptionChange,\n applySubscriptionDeliveryChange,\n sameAcceptedEventIdentity,\n subscriptionCanSelect,\n subscriptionDeliveryCanSelect,\n subscriptionDeliveryUsesCapacity,\n subscriptionUsesCapacity,\n validateEventRetention,\n} from '@systemfsoftware/agent/subscription-transition'\nimport * as Clock from 'effect/Clock'\nimport * as Effect from 'effect/Effect'\nimport * as Layer from 'effect/Layer'\nimport * as Ref from 'effect/Ref'\nimport * as Result from 'effect/Result'\nimport * as Schema from 'effect/Schema'\n\ninterface RegistrationCapacity {\n readonly registrationExpiries: ReadonlyArray<number>\n readonly ownerRegistrationExpiries: ReadonlyMap<string, ReadonlyArray<number>>\n}\n\ninterface MemorySubscriptionState extends RegistrationCapacity {\n readonly sequence: number\n readonly retentionDeadline: number | null\n readonly tombstoneCount: number\n readonly eventKeys: ReadonlyArray<string>\n readonly deliveryKeys: ReadonlyArray<string>\n readonly maintenanceEvents: string\n readonly maintenanceDeliveries: string\n readonly recoveryCounts: ReadonlyMap<string, number>\n readonly eventDeliveryCounts: ReadonlyMap<string, number>\n readonly retentionHorizon: number | null\n readonly registrations: ReadonlyMap<string, string>\n readonly events: ReadonlyMap<string, string>\n readonly deliveries: ReadonlyMap<string, string>\n readonly registrationIndex: ReadonlyMap<string, RegistrationIndex>\n readonly candidateIndex: ReadonlyMap<string, ReadonlyArray<string>>\n readonly eventIndex: ReadonlyMap<string, EventIndex>\n readonly deliveryIndex: ReadonlyMap<string, DeliveryIndex>\n readonly ownerDeliveryCounts: ReadonlyMap<string, number>\n readonly liveDeliveryCount: number\n readonly pendingEventCount: number\n readonly scanCursors: SubscriptionScanCursors\n}\n\ninterface RegistrationIndex {\n readonly key: SubscriptionKey\n readonly ordinal: number\n readonly state: SubscriptionRecord['state']\n readonly recoveryKey: string | null\n readonly recoveryAt: number | null\n}\ninterface EventIndex {\n readonly routingComplete: boolean\n readonly nextAttemptAtMillis: number\n}\ninterface DeliveryIndex {\n readonly key: SubscriptionDeliveryKey\n readonly state: SubscriptionDelivery['state']\n readonly parked?: boolean\n readonly observeSettlement?: boolean\n readonly nextAttemptAtMillis: number\n}\n\nconst error = (reason: SubscriptionError['reason'], code: string) => SubscriptionError.make({ reason, code })\n\nconst samePartition = (left: SourcePartition, right: SourcePartition): boolean =>\n left.tenantId === right.tenantId && left.address === right.address\n\nconst sameSource = (left: AcceptedEvent['source'], right: AcceptedEvent['source']): boolean =>\n left.name === right.name && left.version === right.version\n\nconst encode = <A, I>(\n schema: Schema.Codec<A, I>,\n value: A,\n code: string,\n): Result.Result<string, SubscriptionError> =>\n Result.try({\n try: () => Schema.encodeSync(Schema.fromJsonString(schema))(value),\n catch: () => error('corrupt', code),\n })\n\nconst decode = <A, I>(\n schema: Schema.Codec<A, I>,\n value: string,\n code: string,\n): Result.Result<A, SubscriptionError> =>\n Result.try({\n try: () => Schema.decodeSync(Schema.fromJsonString(schema))(value),\n catch: () => error('corrupt', code),\n })\n\nconst decodeEffect = <A, I>(schema: Schema.Codec<A, I>, value: string, code: string) =>\n Effect.fromResult(decode(schema, value, code))\n\nconst validate = <A, I>(schema: Schema.Codec<A, I>, value: unknown, code: string) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(() => error('validation', code)))\n\nconst jsonBytes = (value: unknown): number => new TextEncoder().encode(JSON.stringify(value)).byteLength\n\nconst sameDeliveryIdentity = (left: SubscriptionDelivery, right: SubscriptionDelivery): boolean =>\n subscriptionDeliveryKeyString(left.key) === subscriptionDeliveryKeyString(right.key) &&\n left.deliveryId === right.deliveryId &&\n left.source.name === right.source.name &&\n left.source.version === right.source.version &&\n left.threadId === right.threadId &&\n left.admissionKey === right.admissionKey &&\n left.subscriptionFingerprint === right.subscriptionFingerprint &&\n left.eventDigest === right.eventDigest\n\nconst candidateIndexKey = (record: SubscriptionRecord): string =>\n JSON.stringify([\n record.configuration.source.name,\n record.configuration.source.version,\n record.configuration.matchingKey,\n ])\n\nconst eventCandidateIndexKey = (event: AcceptedEvent): string =>\n JSON.stringify([event.source.name, event.source.version, event.matchingKey])\n\nconst sameEventIdentity = sameAcceptedEventIdentity\n\nconst deliveryBelongsTo = (\n delivery: SubscriptionDelivery,\n record: SubscriptionRecord,\n event: AcceptedEvent,\n): boolean =>\n subscriptionKeyString(delivery.key.subscription) === subscriptionKeyString(record.key) &&\n delivery.key.eventId === event.eventId &&\n sameSource(delivery.source, event.source)\n\n// Ordered in-memory indexes allow bounded maintenance pages without scanning retained values.\nconst removeKeys = (\n keys: ReadonlyArray<string>,\n removed: ReadonlySet<string>,\n): ReadonlyArray<string> => {\n if (removed.size === 0) return keys\n const result = [...keys]\n\n for (const key of removed) {\n const index = upperBound(result, key) - 1\n\n if (result[index] === key) result.splice(index, 1)\n }\n\n return result\n}\n\nconst upperBound = (keys: ReadonlyArray<string>, after: string): number => {\n let low = 0\n let high = keys.length\n\n while (low < high) {\n const middle = Math.floor((low + high) / 2)\n const key = keys[middle]\n\n if (key !== undefined && compareScheduleNames(key, after) <= 0) low = middle + 1\n else high = middle\n }\n\n return low\n}\n\nconst insertKey = (keys: ReadonlyArray<string>, key: string): ReadonlyArray<string> => {\n const at = upperBound(keys, key)\n\n if (at > 0 && keys[at - 1] === key) return keys\n\n return [...keys.slice(0, at), key, ...keys.slice(at)]\n}\n\n// Count unexpired registrations without reading retained history. Keeping sorted expiry values\n// also makes clock changes safe; expiry alone never deletes or rewrites the canonical record.\nconst expiryUpperBound = (expiries: ReadonlyArray<number>, nowMillis: number): number => {\n let low = 0\n let high = expiries.length\n\n while (low < high) {\n const middle = Math.floor((low + high) / 2)\n const expiry = expiries[middle]\n\n if (expiry !== undefined && expiry <= nowMillis) low = middle + 1\n else high = middle\n }\n\n return low\n}\n\nconst registrationCount = (\n current: MemorySubscriptionState,\n nowMillis: number,\n ownerId?: string,\n): number => {\n const expiries = ownerId === undefined\n ? current.registrationExpiries\n : (current.ownerRegistrationExpiries.get(ownerId) ?? [])\n\n return expiries.length - expiryUpperBound(expiries, nowMillis)\n}\n\nconst registrationExpiriesAfter = (\n current: RegistrationCapacity,\n before: SubscriptionRecord | undefined,\n after: SubscriptionRecord,\n): RegistrationCapacity => {\n const expiry = (record: SubscriptionRecord | undefined) =>\n record !== undefined && (record.state === 'active' || record.state === 'paused')\n ? (record.configuration.expiresAtMillis ?? Number.POSITIVE_INFINITY)\n : null\n\n const previous = expiry(before)\n const next = expiry(after)\n\n const replace = (expiries: ReadonlyArray<number>): ReadonlyArray<number> => {\n if (previous === next) return expiries\n const updated = [...expiries]\n\n if (previous !== null) updated.splice(expiryUpperBound(updated, previous) - 1, 1)\n if (next !== null) updated.splice(expiryUpperBound(updated, next), 0, next)\n\n return updated\n }\n\n const owners = new Map(current.ownerRegistrationExpiries)\n const expiries = replace(owners.get(after.key.ownerId) ?? [])\n\n if (expiries.length === 0) owners.delete(after.key.ownerId)\n else owners.set(after.key.ownerId, expiries)\n\n return {\n registrationExpiries: replace(current.registrationExpiries),\n ownerRegistrationExpiries: owners,\n }\n}\n\nconst recoveryCountsAfter = (\n current: MemorySubscriptionState,\n next: ReadonlyMap<string, RegistrationIndex>,\n keys: ReadonlyArray<string>,\n): ReadonlyMap<string, number> => {\n const counts = new Map(current.recoveryCounts)\n\n for (const key of keys) {\n const before = current.registrationIndex.get(key)?.recoveryKey\n const after = next.get(key)?.recoveryKey\n\n if (before === after) continue\n if (before !== null && before !== undefined) counts.set(before, (counts.get(before) ?? 0) - 1)\n if (after !== null && after !== undefined) counts.set(after, (counts.get(after) ?? 0) + 1)\n }\n\n return counts\n}\n\nconst makeMemorySubscriptionStore = Effect.fnUntraced(function*(ownedPartition: SourcePartition) {\n const partition = yield* validate(SourcePartition, ownedPartition, 'partition')\n\n const state = yield* Ref.make<MemorySubscriptionState>({\n sequence: 0,\n retentionDeadline: null,\n tombstoneCount: 0,\n eventKeys: [],\n deliveryKeys: [],\n maintenanceEvents: '',\n maintenanceDeliveries: '',\n recoveryCounts: new Map(),\n eventDeliveryCounts: new Map(),\n retentionHorizon: null,\n registrations: new Map(),\n events: new Map(),\n deliveries: new Map(),\n registrationIndex: new Map(),\n candidateIndex: new Map(),\n registrationExpiries: [],\n ownerRegistrationExpiries: new Map(),\n eventIndex: new Map(),\n deliveryIndex: new Map(),\n ownerDeliveryCounts: new Map(),\n liveDeliveryCount: 0,\n pendingEventCount: 0,\n scanCursors: { events: '', deliveries: '', recovery: 0 },\n })\n\n const failpoint = yield* SubscriptionFailpoint\n\n const requirePartition = <A extends { readonly partition: SourcePartition }>(\n value: A,\n code: string,\n ) =>\n samePartition(value.partition, partition)\n ? Effect.succeed(value)\n : Effect.fail(error('validation', code))\n\n const requireKey = (key: SubscriptionKey, code: string) =>\n validate(SubscriptionKey, key, code).pipe(\n Effect.flatMap((decoded) => requirePartition(decoded, code)),\n )\n\n const register: SubscriptionStore['Service']['register'] = Effect.fnUntraced(\n function*(input, inputLimits) {\n const record = yield* validate(SubscriptionRecord, input, 'register-record')\n const limits = yield* validate(SubscriptionLimits, inputLimits, 'register-limits')\n\n yield* requirePartition(record.key, 'register-partition')\n yield* failpoint.hit('subscription:register:before')\n const nowMillis = yield* Clock.currentTimeMillis\n\n const result = yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (\n current,\n ): readonly [\n Result.Result<SubscriptionRecord, SubscriptionError>,\n MemorySubscriptionState,\n ] => {\n const key = subscriptionKeyString(record.key)\n const existingText = current.registrations.get(key)\n\n if (existingText !== undefined) {\n const existing = decode(SubscriptionRecord, existingText, 'register-existing')\n\n if (Result.isFailure(existing)) return [Result.fail(existing.failure), current]\n\n return existing.success.creationFingerprint === record.creationFingerprint\n ? [Result.succeed(existing.success), current]\n : [Result.fail(error('conflict', 'registration-identity')), current]\n }\n if (jsonBytes(record.configuration.context) > limits.maxContextBytes) {\n return [Result.fail(error('capacity', 'context-bytes')), current]\n }\n if (jsonBytes(record.configuration.parameters) > limits.maxPayloadBytes) {\n return [Result.fail(error('capacity', 'parameters-bytes')), current]\n }\n if (\n record.configuration.expiresAtMillis !== null &&\n record.configuration.expiresAtMillis - record.createdAtMillis >\n limits.maxLifetimeMillis\n ) {\n return [Result.fail(error('capacity', 'lifetime')), current]\n }\n if (\n subscriptionUsesCapacity(record, nowMillis) &&\n registrationCount(current, nowMillis) >= limits.maxRegistrations\n ) {\n return [Result.fail(error('capacity', 'registrations')), current]\n }\n if (\n subscriptionUsesCapacity(record, nowMillis) &&\n registrationCount(current, nowMillis, record.key.ownerId) >=\n limits.maxRegistrationsPerOwner\n ) {\n return [Result.fail(error('capacity', 'owner-registrations')), current]\n }\n const assigned = { ...record, ordinal: current.sequence + 1 }\n const encoded = encode(SubscriptionRecord, assigned, 'register-encode')\n\n if (Result.isFailure(encoded)) return [Result.fail(encoded.failure), current]\n const registrations = new Map(current.registrations)\n\n registrations.set(key, encoded.success)\n const registrationIndex = new Map(current.registrationIndex)\n\n registrationIndex.set(key, {\n key: assigned.key,\n ordinal: assigned.ordinal,\n state: assigned.state,\n recoveryKey: assigned.recovery === null ? null : candidateIndexKey(assigned),\n recoveryAt: assigned.recovery?.nextAttemptAtMillis ?? null,\n })\n const candidateIndex = new Map(current.candidateIndex)\n const candidateKey = candidateIndexKey(assigned)\n\n candidateIndex.set(candidateKey, [...(candidateIndex.get(candidateKey) ?? []), key])\n\n return [\n Result.succeed(assigned),\n {\n ...current,\n sequence: assigned.ordinal,\n registrations,\n registrationIndex,\n recoveryCounts: recoveryCountsAfter(current, registrationIndex, [key]),\n candidateIndex,\n ...registrationExpiriesAfter(current, undefined, assigned),\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n\n yield* failpoint.hit('subscription:register:after')\n\n return result\n },\n )\n\n const get: SubscriptionStore['Service']['get'] = Effect.fnUntraced(function*(input) {\n const key = yield* requireKey(input, 'get-key')\n const text = (yield* Ref.get(state)).registrations.get(subscriptionKeyString(key))\n\n return text === undefined ? null : yield* decodeEffect(SubscriptionRecord, text, 'get-record')\n })\n\n const list: SubscriptionStore['Service']['list'] = Effect.fnUntraced(\n function*(ownerId, after, limit) {\n if (!Number.isSafeInteger(after) || after < 0 || !Number.isSafeInteger(limit) || limit <= 0) {\n return yield* error('validation', 'list-page')\n }\n const current = yield* Ref.get(state)\n const records: Array<SubscriptionRecord> = []\n\n for (const [storageKey, indexed] of current.registrationIndex) {\n if (indexed.key.ownerId !== ownerId || indexed.ordinal <= after) continue\n const text = current.registrations.get(storageKey)\n\n if (text === undefined) return yield* error('corrupt', 'list-index')\n records.push(yield* decodeEffect(SubscriptionRecord, text, 'list-record'))\n }\n records.sort((a, b) => a.ordinal - b.ordinal)\n\n return records.slice(0, limit)\n },\n )\n\n const change: SubscriptionStore['Service']['change'] = Effect.fnUntraced(function*(\n input,\n expectedRevision,\n inputChange,\n inputLimits = defaultSubscriptionLimits,\n ) {\n const key = yield* requireKey(input, 'change-key')\n const change = yield* validate(SubscriptionChange, inputChange, 'change')\n const limits = yield* validate(SubscriptionLimits, inputLimits, 'change-limits')\n\n yield* validate(Schema.Int.check(Schema.isGreaterThan(0)), expectedRevision, 'revision')\n yield* failpoint.hit('subscription:change:before')\n const nowMillis = yield* Clock.currentTimeMillis\n\n const updated = yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (\n current,\n ): readonly [\n Result.Result<SubscriptionRecord, SubscriptionError>,\n MemorySubscriptionState,\n ] => {\n const storageKey = subscriptionKeyString(key)\n const text = current.registrations.get(storageKey)\n\n if (text === undefined) return [Result.fail(error('not-found', 'subscription')), current]\n const existing = decode(SubscriptionRecord, text, 'change-record')\n\n if (Result.isFailure(existing)) return [existing, current]\n const updated = applySubscriptionChange(existing.success, expectedRevision, change)\n\n if (Result.isFailure(updated)) return [updated, current]\n if (\n !subscriptionUsesCapacity(existing.success, nowMillis) &&\n subscriptionUsesCapacity(updated.success, nowMillis)\n ) {\n if (registrationCount(current, nowMillis) >= limits.maxRegistrations) {\n return [Result.fail(error('capacity', 'registrations')), current]\n }\n if (\n registrationCount(current, nowMillis, key.ownerId) >= limits.maxRegistrationsPerOwner\n ) {\n return [Result.fail(error('capacity', 'owner-registrations')), current]\n }\n }\n const revised = { ...updated.success, ordinal: current.sequence + 1 }\n const encoded = encode(SubscriptionRecord, revised, 'change-encode')\n\n if (Result.isFailure(encoded)) return [Result.fail(encoded.failure), current]\n const registrations = new Map(current.registrations)\n\n registrations.set(storageKey, encoded.success)\n const registrationIndex = new Map(current.registrationIndex)\n\n registrationIndex.set(storageKey, {\n key,\n ordinal: revised.ordinal,\n state: revised.state,\n recoveryKey: revised.recovery === null ? null : candidateIndexKey(revised),\n recoveryAt: revised.recovery?.nextAttemptAtMillis ?? null,\n })\n const candidateIndex = new Map(current.candidateIndex)\n const oldKey = candidateIndexKey(existing.success)\n const nextKey = candidateIndexKey(revised)\n\n {\n candidateIndex.set(\n oldKey,\n (candidateIndex.get(oldKey) ?? []).filter((key) => key !== storageKey),\n )\n candidateIndex.set(\n nextKey,\n [...(candidateIndex.get(nextKey) ?? []), storageKey].sort(\n (a, b) =>\n (registrationIndex.get(a)?.ordinal ?? 0) -\n (registrationIndex.get(b)?.ordinal ?? 0),\n ),\n )\n }\n\n return [\n Result.succeed(revised),\n {\n ...current,\n sequence: revised.ordinal,\n registrations,\n registrationIndex,\n candidateIndex,\n ...registrationExpiriesAfter(current, existing.success, revised),\n recoveryCounts: recoveryCountsAfter(current, registrationIndex, [storageKey]),\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n\n yield* failpoint.hit('subscription:change:after')\n\n return updated\n })\n\n const cancel: SubscriptionStore['Service']['cancel'] = Effect.fnUntraced(\n function*(input, expectedRevision) {\n const key = yield* requireKey(input, 'cancel-key')\n\n yield* failpoint.hit('subscription:cancel:before')\n\n const result = yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (\n current,\n ): readonly [\n Result.Result<SubscriptionRecord, SubscriptionError>,\n MemorySubscriptionState,\n ] => {\n const storageKey = subscriptionKeyString(key)\n const text = current.registrations.get(storageKey)\n\n if (text === undefined) {\n return [Result.fail(error('not-found', 'subscription')), current]\n }\n const decoded = decode(SubscriptionRecord, text, 'cancel-record')\n\n if (Result.isFailure(decoded)) return [decoded, current]\n if (\n expectedRevision !== undefined &&\n expectedRevision !== decoded.success.configurationRevision &&\n !(\n decoded.success.state === 'cancelled' &&\n expectedRevision + 1 === decoded.success.configurationRevision\n )\n ) {\n return [\n Result.fail(\n SubscriptionError.make({\n reason: 'conflict',\n code: 'configuration-revision',\n currentRevision: decoded.success.configurationRevision,\n currentState: decoded.success.state,\n }),\n ),\n current,\n ]\n }\n if (decoded.success.state === 'cancelled') {\n return [Result.succeed(decoded.success), current]\n }\n\n const cancelled = {\n ...decoded.success,\n configurationRevision: decoded.success.configurationRevision + 1,\n state: 'cancelled' as const,\n recovery: null,\n }\n\n const encoded = encode(SubscriptionRecord, cancelled, 'cancel-encode')\n\n if (Result.isFailure(encoded)) return [Result.fail(encoded.failure), current]\n const registrations = new Map(current.registrations)\n\n registrations.set(storageKey, encoded.success)\n const registrationIndex = new Map(current.registrationIndex)\n const indexed = registrationIndex.get(storageKey)\n\n if (indexed === undefined) {\n return [Result.fail(error('corrupt', 'cancel-index')), current]\n }\n registrationIndex.set(storageKey, {\n ...indexed,\n state: 'cancelled',\n recoveryAt: null,\n recoveryKey: null,\n })\n\n return [\n Result.succeed(cancelled),\n {\n ...current,\n registrations,\n registrationIndex,\n ...registrationExpiriesAfter(current, decoded.success, cancelled),\n recoveryCounts: recoveryCountsAfter(current, registrationIndex, [storageKey]),\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n\n yield* failpoint.hit('subscription:cancel:after')\n\n return result\n },\n )\n\n const accept: SubscriptionStore['Service']['accept'] = Effect.fnUntraced(\n function*(input, inputLimits) {\n const event = yield* validate(AcceptedEvent, input, 'accept-event')\n const currentTimeMillis = yield* Clock.currentTimeMillis\n const limits = yield* validate(SubscriptionLimits, inputLimits, 'accept-limits')\n\n yield* requirePartition(event, 'accept-partition')\n yield* failpoint.hit('subscription:accept:before')\n\n const result = yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (\n current,\n ): readonly [\n Result.Result<AcceptedEvent, SubscriptionError>,\n MemorySubscriptionState,\n ] => {\n const existingText = current.events.get(event.eventId)\n\n if (existingText !== undefined) {\n const existing = decode(AcceptedEvent, existingText, 'accept-existing')\n\n if (Result.isFailure(existing)) return [Result.fail(existing.failure), current]\n\n return sameEventIdentity(existing.success, event)\n ? [Result.succeed(existing.success), current]\n : [Result.fail(error('conflict', 'event-identity')), current]\n }\n if (\n current.retentionHorizon !== null &&\n current.retentionHorizon !== limits.retention?.replayHorizonMillis\n ) {\n return [Result.fail(error('conflict', 'retention-horizon')), current]\n }\n const horizon = validateEventRetention(event, limits, currentTimeMillis)\n\n if (Result.isFailure(horizon)) return [Result.fail(horizon.failure), current]\n if (jsonBytes(event.payload) > limits.maxPayloadBytes) {\n return [Result.fail(error('capacity', 'payload-bytes')), current]\n }\n if (current.pendingEventCount >= limits.maxEvents) {\n return [Result.fail(error('capacity', 'events')), current]\n }\n\n const accepted: AcceptedEvent = {\n ...event,\n cutoff: current.sequence + 1,\n cursor: 0,\n routingComplete: false,\n routingFailure: null,\n }\n\n const encoded = encode(AcceptedEvent, accepted, 'accept-encode')\n\n if (Result.isFailure(encoded)) return [Result.fail(encoded.failure), current]\n const events = new Map(current.events)\n\n events.set(accepted.eventId, encoded.success)\n const eventIndex = new Map(current.eventIndex)\n\n eventIndex.set(accepted.eventId, {\n routingComplete: false,\n nextAttemptAtMillis: accepted.nextAttemptAtMillis,\n })\n\n return [\n Result.succeed(accepted),\n {\n ...current,\n sequence: accepted.cutoff,\n events,\n eventIndex,\n pendingEventCount: current.pendingEventCount + 1,\n eventKeys: insertKey(current.eventKeys, accepted.eventId),\n retentionHorizon: limits.retention?.replayHorizonMillis ?? current.retentionHorizon,\n retentionDeadline: limits.retention === undefined\n ? current.retentionDeadline\n : accepted.acceptedAtMillis,\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n\n yield* failpoint.hit('subscription:accept:after')\n\n return result\n },\n )\n\n const event: SubscriptionStore['Service']['event'] = Effect.fnUntraced(function*(eventId) {\n const text = (yield* Ref.get(state)).events.get(eventId)\n\n return text === undefined ? null : yield* decodeEffect(AcceptedEvent, text, 'event-record')\n })\n\n const pendingEvents: SubscriptionStore['Service']['pendingEvents'] = Effect.fnUntraced(\n function*(nowMillis, after, limit) {\n const events: Array<string> = []\n\n for (const [eventId, indexed] of (yield* Ref.get(state)).eventIndex) {\n if (\n !indexed.routingComplete &&\n indexed.nextAttemptAtMillis <= nowMillis &&\n compareScheduleNames(eventId, after) > 0\n ) {\n events.push(eventId)\n }\n }\n events.sort(compareScheduleNames)\n\n return events.slice(0, limit)\n },\n )\n\n const candidates: SubscriptionStore['Service']['candidates'] = Effect.fnUntraced(\n function*(input, limit) {\n const accepted = yield* validate(AcceptedEvent, input, 'candidates-event')\n\n yield* requirePartition(accepted, 'candidates-partition')\n const stored = yield* event(accepted.eventId)\n\n if (stored === null || !sameEventIdentity(stored, accepted)) {\n return yield* error(stored === null ? 'not-found' : 'conflict', 'event')\n }\n const current = yield* Ref.get(state)\n const records: Array<SubscriptionRecord> = []\n\n for (const storageKey of current.candidateIndex.get(eventCandidateIndexKey(stored)) ?? []) {\n const indexed = current.registrationIndex.get(storageKey)\n\n if (indexed === undefined) return yield* error('corrupt', 'candidate-index')\n if (indexed.ordinal <= stored.cursor || indexed.ordinal > stored.cutoff) continue\n const text = current.registrations.get(storageKey)\n\n if (text === undefined) return yield* error('corrupt', 'candidate-record')\n records.push(yield* decodeEffect(SubscriptionRecord, text, 'candidate-record'))\n }\n records.sort((a, b) => a.ordinal - b.ordinal)\n\n return records.slice(0, limit)\n },\n )\n\n const select: SubscriptionStore['Service']['select'] = Effect.fnUntraced(\n function*(inputEvent, inputDeliveries, cursor, complete, nowMillis, inputLimits) {\n const suppliedEvent = yield* validate(AcceptedEvent, inputEvent, 'select-event')\n\n const deliveries = yield* validate(\n Schema.Array(SubscriptionDelivery),\n inputDeliveries,\n 'select-deliveries',\n )\n\n if (\n new Set(deliveries.map((delivery) => subscriptionDeliveryKeyString(delivery.key))).size !==\n deliveries.length\n ) {\n return yield* error('validation', 'duplicate-delivery')\n }\n const limits = yield* validate(SubscriptionLimits, inputLimits, 'select-limits')\n\n yield* requirePartition(suppliedEvent, 'select-partition')\n yield* failpoint.hit('subscription:select:before')\n const effectiveNowMillis = Math.max(nowMillis, yield* Clock.currentTimeMillis)\n\n yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (current): readonly [Result.Result<void, SubscriptionError>, MemorySubscriptionState] => {\n const eventText = current.events.get(suppliedEvent.eventId)\n\n if (eventText === undefined) return [Result.fail(error('not-found', 'event')), current]\n const decodedEvent = decode(AcceptedEvent, eventText, 'select-event-record')\n\n if (Result.isFailure(decodedEvent)) return [Result.fail(decodedEvent.failure), current]\n const accepted = decodedEvent.success\n\n if (\n !sameEventIdentity(accepted, suppliedEvent) ||\n suppliedEvent.cursor !== accepted.cursor\n ) {\n return [Result.fail(error('conflict', 'event-cursor')), current]\n }\n if (accepted.routingComplete) {\n return [\n complete && cursor === accepted.cursor\n ? Result.void\n : Result.fail(error('conflict', 'routing-complete')),\n current,\n ]\n }\n if (\n !Number.isSafeInteger(cursor) ||\n cursor < accepted.cursor ||\n cursor > accepted.cutoff\n ) {\n return [Result.fail(error('validation', 'cursor')), current]\n }\n\n const additions: Array<readonly [string, string]> = []\n const updates: Array<readonly [string, string]> = []\n const additionIndex: Array<readonly [string, DeliveryIndex, string]> = []\n const registrationUpdates: Array<readonly [string, RegistrationIndex]> = []\n const owners = new Map(current.ownerDeliveryCounts)\n\n let registrationCapacity: RegistrationCapacity = {\n registrationExpiries: current.registrationExpiries,\n ownerRegistrationExpiries: current.ownerRegistrationExpiries,\n }\n\n for (const delivery of deliveries) {\n const recordText = current.registrations.get(\n subscriptionKeyString(delivery.key.subscription),\n )\n\n if (recordText === undefined) {\n return [Result.fail(error('not-found', 'subscription')), current]\n }\n const record = decode(SubscriptionRecord, recordText, 'select-registration')\n\n if (Result.isFailure(record)) return [Result.fail(record.failure), current]\n if (\n !deliveryBelongsTo(delivery, record.success, accepted) ||\n !subscriptionDeliveryCanSelect(delivery, record.success, accepted) ||\n record.success.ordinal <= accepted.cursor ||\n record.success.ordinal > cursor\n ) {\n return [Result.fail(error('conflict', 'selection')), current]\n }\n if (!subscriptionCanSelect(record.success, accepted, effectiveNowMillis, false)) {\n continue\n }\n const deliveryKey = subscriptionDeliveryKeyString(delivery.key)\n const existingText = current.deliveries.get(deliveryKey)\n\n if (existingText !== undefined) {\n const existing = decode(SubscriptionDelivery, existingText, 'select-existing')\n\n if (Result.isFailure(existing)) return [Result.fail(existing.failure), current]\n if (!sameDeliveryIdentity(existing.success, delivery)) {\n return [Result.fail(error('conflict', 'delivery-identity')), current]\n }\n continue\n }\n\n const encodedDelivery = encode(\n SubscriptionDelivery,\n delivery,\n 'select-delivery-encode',\n )\n\n if (Result.isFailure(encodedDelivery)) {\n return [Result.fail(encodedDelivery.failure), current]\n }\n additions.push([deliveryKey, encodedDelivery.success])\n additionIndex.push([\n deliveryKey,\n {\n key: delivery.key,\n state: delivery.state,\n nextAttemptAtMillis: delivery.retry.nextAttemptAtMillis,\n },\n record.success.key.ownerId,\n ])\n const ownerId = record.success.key.ownerId\n\n owners.set(ownerId, (owners.get(ownerId) ?? 0) + 1)\n if ((owners.get(ownerId) ?? 0) > limits.maxDeliveriesPerOwner) {\n return [Result.fail(error('capacity', 'owner-deliveries')), current]\n }\n if (record.success.configuration.mode === 'once') {\n const consumed = { ...record.success, state: 'consumed' as const, recovery: null }\n\n const encodedRecord = encode(\n SubscriptionRecord,\n consumed,\n 'select-registration-encode',\n )\n\n if (Result.isFailure(encodedRecord)) {\n return [Result.fail(encodedRecord.failure), current]\n }\n const consumedKey = subscriptionKeyString(consumed.key)\n\n updates.push([consumedKey, encodedRecord.success])\n const indexed = current.registrationIndex.get(consumedKey)\n\n if (indexed === undefined) {\n return [Result.fail(error('corrupt', 'selection-index')), current]\n }\n registrationUpdates.push([\n consumedKey,\n { ...indexed, state: 'consumed', recoveryAt: null, recoveryKey: null },\n ])\n registrationCapacity = registrationExpiriesAfter(\n registrationCapacity,\n record.success,\n consumed,\n )\n }\n }\n if (current.liveDeliveryCount + additions.length > limits.maxDeliveries) {\n return [Result.fail(error('capacity', 'deliveries')), current]\n }\n const registrations = new Map(current.registrations)\n\n for (const [key, value] of updates) registrations.set(key, value)\n const nextDeliveries = new Map(current.deliveries)\n\n for (const [key, value] of additions) nextDeliveries.set(key, value)\n const deliveryIndex = new Map(current.deliveryIndex)\n\n for (const [key, value] of additionIndex) deliveryIndex.set(key, value)\n const registrationIndex = new Map(current.registrationIndex)\n\n for (const [key, value] of registrationUpdates) registrationIndex.set(key, value)\n\n const eventDeliveryCounts = new Map(current.eventDeliveryCounts)\n\n eventDeliveryCounts.set(\n accepted.eventId,\n (eventDeliveryCounts.get(accepted.eventId) ?? 0) + additions.length,\n )\n\n const nextEvent: AcceptedEvent = {\n ...accepted,\n cursor,\n routingComplete: complete,\n routingFailure: null,\n }\n\n const encodedEvent = encode(AcceptedEvent, nextEvent, 'select-event-encode')\n\n if (Result.isFailure(encodedEvent)) return [Result.fail(encodedEvent.failure), current]\n const events = new Map(current.events)\n\n events.set(nextEvent.eventId, encodedEvent.success)\n const eventIndex = new Map(current.eventIndex)\n\n eventIndex.set(nextEvent.eventId, {\n routingComplete: nextEvent.routingComplete,\n nextAttemptAtMillis: nextEvent.nextAttemptAtMillis,\n })\n\n return [\n Result.void,\n {\n ...current,\n registrations,\n registrationIndex,\n recoveryCounts: recoveryCountsAfter(\n current,\n registrationIndex,\n registrationUpdates.map(([key]) => key),\n ),\n eventDeliveryCounts,\n events,\n eventIndex,\n deliveries: nextDeliveries,\n liveDeliveryCount: current.liveDeliveryCount + additions.length,\n pendingEventCount: current.pendingEventCount - Number(complete),\n deliveryKeys: additions.reduce(\n (keys, [key]) => insertKey(keys, key),\n current.deliveryKeys,\n ),\n deliveryIndex,\n ownerDeliveryCounts: owners,\n ...registrationCapacity,\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n yield* failpoint.hit('subscription:select:after')\n },\n )\n\n const catchUp: SubscriptionStore['Service']['catchUp'] = Effect.fnUntraced(\n function*(inputEvent, inputDelivery, nowMillis, inputLimits) {\n const suppliedEvent = yield* validate(AcceptedEvent, inputEvent, 'catch-up-event')\n const delivery = yield* validate(SubscriptionDelivery, inputDelivery, 'catch-up-delivery')\n const limits = yield* validate(SubscriptionLimits, inputLimits, 'catch-up-limits')\n\n yield* requirePartition(suppliedEvent, 'catch-up-partition')\n yield* failpoint.hit('subscription:catch-up:before')\n const effectiveNowMillis = Math.max(nowMillis, yield* Clock.currentTimeMillis)\n\n yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (current): readonly [Result.Result<void, SubscriptionError>, MemorySubscriptionState] => {\n const eventText = current.events.get(suppliedEvent.eventId)\n\n const recordText = current.registrations.get(\n subscriptionKeyString(delivery.key.subscription),\n )\n\n if (eventText === undefined || recordText === undefined) {\n return [\n Result.fail(error('not-found', eventText === undefined ? 'event' : 'subscription')),\n current,\n ]\n }\n const accepted = decode(AcceptedEvent, eventText, 'catch-up-event-record')\n\n if (Result.isFailure(accepted)) return [Result.fail(accepted.failure), current]\n const record = decode(SubscriptionRecord, recordText, 'catch-up-registration')\n\n if (Result.isFailure(record)) return [Result.fail(record.failure), current]\n if (\n !sameEventIdentity(accepted.success, suppliedEvent) ||\n !deliveryBelongsTo(delivery, record.success, accepted.success) ||\n !subscriptionDeliveryCanSelect(delivery, record.success, accepted.success) ||\n record.success.configuration.mode !== 'once'\n ) {\n return [Result.fail(error('conflict', 'catch-up-identity')), current]\n }\n const key = subscriptionDeliveryKeyString(delivery.key)\n const existingText = current.deliveries.get(key)\n\n if (existingText !== undefined) {\n const existing = decode(SubscriptionDelivery, existingText, 'catch-up-existing')\n\n if (Result.isFailure(existing)) return [Result.fail(existing.failure), current]\n\n return sameDeliveryIdentity(existing.success, delivery)\n ? [Result.void, current]\n : [Result.fail(error('conflict', 'delivery-identity')), current]\n }\n if (!subscriptionCanSelect(record.success, accepted.success, effectiveNowMillis, true)) {\n return [Result.fail(error('conflict', 'catch-up-eligibility')), current]\n }\n if (current.liveDeliveryCount >= limits.maxDeliveries) {\n return [Result.fail(error('capacity', 'deliveries')), current]\n }\n const ownerCount = current.ownerDeliveryCounts.get(record.success.key.ownerId) ?? 0\n\n if (ownerCount >= limits.maxDeliveriesPerOwner) {\n return [Result.fail(error('capacity', 'owner-deliveries')), current]\n }\n\n const encodedDelivery = encode(\n SubscriptionDelivery,\n delivery,\n 'catch-up-delivery-encode',\n )\n\n if (Result.isFailure(encodedDelivery)) {\n return [Result.fail(encodedDelivery.failure), current]\n }\n const consumed = { ...record.success, state: 'consumed' as const, recovery: null }\n\n const encodedRecord = encode(\n SubscriptionRecord,\n consumed,\n 'catch-up-registration-encode',\n )\n\n if (Result.isFailure(encodedRecord)) {\n return [Result.fail(encodedRecord.failure), current]\n }\n const deliveries = new Map(current.deliveries)\n\n deliveries.set(key, encodedDelivery.success)\n const registrations = new Map(current.registrations)\n const consumedKey = subscriptionKeyString(consumed.key)\n\n registrations.set(consumedKey, encodedRecord.success)\n const registrationIndex = new Map(current.registrationIndex)\n const indexed = registrationIndex.get(consumedKey)\n\n if (indexed === undefined) {\n return [Result.fail(error('corrupt', 'catch-up-index')), current]\n }\n registrationIndex.set(consumedKey, {\n ...indexed,\n state: 'consumed',\n recoveryAt: null,\n recoveryKey: null,\n })\n const deliveryIndex = new Map(current.deliveryIndex)\n\n deliveryIndex.set(key, {\n key: delivery.key,\n state: delivery.state,\n nextAttemptAtMillis: delivery.retry.nextAttemptAtMillis,\n })\n const ownerDeliveryCounts = new Map(current.ownerDeliveryCounts)\n const eventDeliveryCounts = new Map(current.eventDeliveryCounts)\n\n eventDeliveryCounts.set(\n accepted.success.eventId,\n (eventDeliveryCounts.get(accepted.success.eventId) ?? 0) + 1,\n )\n\n ownerDeliveryCounts.set(consumed.key.ownerId, ownerCount + 1)\n\n return [\n Result.void,\n {\n ...current,\n deliveries,\n deliveryIndex,\n deliveryKeys: insertKey(current.deliveryKeys, key),\n ownerDeliveryCounts,\n ...registrationExpiriesAfter(current, record.success, consumed),\n liveDeliveryCount: current.liveDeliveryCount + 1,\n registrations,\n registrationIndex,\n recoveryCounts: recoveryCountsAfter(current, registrationIndex, [consumedKey]),\n eventDeliveryCounts,\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n yield* failpoint.hit('subscription:catch-up:after')\n },\n )\n\n const deferEvent: SubscriptionStore['Service']['deferEvent'] = Effect.fnUntraced(\n function*(eventId, nextAttemptAtMillis, code) {\n const routingFailure = code === undefined\n ? 'routing-failed'\n : yield* validate(SubscriptionName, code, 'routing-failure')\n\n yield* failpoint.hit('subscription:defer-event:before')\n yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (current): readonly [Result.Result<void, SubscriptionError>, MemorySubscriptionState] => {\n const text = current.events.get(eventId)\n\n if (text === undefined) return [Result.fail(error('not-found', 'event')), current]\n const accepted = decode(AcceptedEvent, text, 'defer-event-record')\n\n if (Result.isFailure(accepted)) return [Result.fail(accepted.failure), current]\n const updated = { ...accepted.success, nextAttemptAtMillis, routingFailure }\n const encoded = encode(AcceptedEvent, updated, 'defer-event-encode')\n\n if (Result.isFailure(encoded)) return [Result.fail(encoded.failure), current]\n const events = new Map(current.events)\n\n events.set(eventId, encoded.success)\n const eventIndex = new Map(current.eventIndex)\n const indexed = eventIndex.get(eventId)\n\n if (indexed === undefined) {\n return [Result.fail(error('corrupt', 'defer-event-index')), current]\n }\n eventIndex.set(eventId, { ...indexed, nextAttemptAtMillis })\n\n return [Result.void, { ...current, events, eventIndex }]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n yield* failpoint.hit('subscription:defer-event:after')\n },\n )\n\n const delivery: SubscriptionStore['Service']['delivery'] = Effect.fnUntraced(function*(input) {\n const key = yield* validate(SubscriptionDeliveryKey, input, 'delivery-key')\n\n yield* requirePartition(key.subscription, 'delivery-partition')\n const text = (yield* Ref.get(state)).deliveries.get(subscriptionDeliveryKeyString(key))\n\n return text === undefined\n ? null\n : yield* decodeEffect(SubscriptionDelivery, text, 'delivery-record')\n })\n\n const pendingDeliveries: SubscriptionStore['Service']['pendingDeliveries'] = Effect.fnUntraced(\n function*(nowMillis, after, limit) {\n const items: Array<SubscriptionDeliveryKey> = []\n\n for (const [storageKey, item] of (yield* Ref.get(state)).deliveryIndex) {\n if (\n ((item.state !== 'delivered' && item.state !== 'refused' && item.parked !== true) ||\n (item.state === 'delivered' && item.observeSettlement === true)) &&\n item.nextAttemptAtMillis <= nowMillis &&\n compareScheduleNames(storageKey, after) > 0\n ) {\n items.push(item.key)\n }\n }\n items.sort((a, b) => compareScheduleNames(subscriptionDeliveryKeyString(a), subscriptionDeliveryKeyString(b)))\n\n return items.slice(0, limit)\n },\n )\n\n const listDeliveries: SubscriptionStore['Service']['listDeliveries'] = Effect.fnUntraced(\n function*(input, after, limit) {\n const key = yield* requireKey(input, 'list-deliveries-key')\n const items: Array<SubscriptionDelivery> = []\n\n for (const text of (yield* Ref.get(state)).deliveries.values()) {\n const item = yield* decodeEffect(SubscriptionDelivery, text, 'list-delivery')\n const itemKey = subscriptionDeliveryKeyString(item.key)\n\n if (\n subscriptionKeyString(item.key.subscription) === subscriptionKeyString(key) &&\n compareScheduleNames(itemKey, after) > 0\n ) {\n items.push(item)\n }\n }\n items.sort((a, b) =>\n compareScheduleNames(\n subscriptionDeliveryKeyString(a.key),\n subscriptionDeliveryKeyString(b.key),\n )\n )\n\n return items.slice(0, limit)\n },\n )\n\n const changeDelivery: SubscriptionStore['Service']['changeDelivery'] = Effect.fnUntraced(\n function*(inputKey, inputDeliveryId, inputChange, inputLimits = defaultSubscriptionLimits) {\n const key = yield* validate(SubscriptionDeliveryKey, inputKey, 'change-delivery-key')\n const deliveryId = yield* validate(Digest, inputDeliveryId, 'change-delivery-id')\n const change = yield* validate(DeliveryChange, inputChange, 'change-delivery-change')\n const limits = yield* validate(SubscriptionLimits, inputLimits, 'change-delivery-limits')\n\n yield* requirePartition(key.subscription, 'change-delivery-partition')\n yield* failpoint.hit(`subscription:delivery-${change._tag.toLowerCase()}:before`)\n\n const effectiveChange = change._tag === 'Prepare'\n ? { ...change, nowMillis: Math.max(change.nowMillis, yield* Clock.currentTimeMillis) }\n : change\n\n const result = yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (\n current,\n ): readonly [\n Result.Result<SubscriptionDelivery, SubscriptionError>,\n MemorySubscriptionState,\n ] => {\n const storageKey = subscriptionDeliveryKeyString(key)\n const text = current.deliveries.get(storageKey)\n\n if (text === undefined) return [Result.fail(error('not-found', 'delivery')), current]\n const decoded = decode(SubscriptionDelivery, text, 'change-delivery-record')\n\n if (Result.isFailure(decoded)) return [decoded, current]\n\n const registrationText = current.registrations.get(\n subscriptionKeyString(key.subscription),\n )\n\n if (registrationText === undefined) {\n return [Result.fail(error('corrupt', 'delivery-registration')), current]\n }\n\n const registration = decode(\n SubscriptionRecord,\n registrationText,\n 'delivery-registration',\n )\n\n if (Result.isFailure(registration)) return [Result.fail(registration.failure), current]\n\n const transition = applySubscriptionDeliveryChange(\n decoded.success,\n registration.success,\n deliveryId,\n effectiveChange,\n )\n\n if (Result.isFailure(transition)) return [Result.fail(transition.failure), current]\n if (transition.success === decoded.success) {\n return [Result.succeed(decoded.success), current]\n }\n const updated = transition.success\n\n const capacityDelta = Number(subscriptionDeliveryUsesCapacity(updated)) -\n Number(subscriptionDeliveryUsesCapacity(decoded.success))\n\n const ownerId = key.subscription.ownerId\n const ownerCount = current.ownerDeliveryCounts.get(ownerId) ?? 0\n\n if (capacityDelta > 0) {\n if (current.liveDeliveryCount >= limits.maxDeliveries) {\n return [Result.fail(error('capacity', 'deliveries')), current]\n }\n if (ownerCount >= limits.maxDeliveriesPerOwner) {\n return [Result.fail(error('capacity', 'owner-deliveries')), current]\n }\n }\n const encoded = encode(SubscriptionDelivery, updated, 'change-delivery-encode')\n\n if (Result.isFailure(encoded)) return [Result.fail(encoded.failure), current]\n const deliveries = new Map(current.deliveries)\n\n deliveries.set(storageKey, encoded.success)\n const deliveryIndex = new Map(current.deliveryIndex)\n const indexed = deliveryIndex.get(storageKey)\n\n if (indexed === undefined) {\n return [Result.fail(error('corrupt', 'delivery-index')), current]\n }\n deliveryIndex.set(storageKey, {\n ...indexed,\n state: updated.state,\n parked: updated.retry.parked ?? false,\n observeSettlement: updated.observeSettlement ?? false,\n nextAttemptAtMillis: updated.retry.nextAttemptAtMillis,\n })\n const ownerDeliveryCounts = new Map(current.ownerDeliveryCounts)\n\n if (ownerCount + capacityDelta === 0) ownerDeliveryCounts.delete(ownerId)\n else ownerDeliveryCounts.set(ownerId, ownerCount + capacityDelta)\n\n return [\n Result.succeed(updated),\n {\n ...current,\n deliveries,\n deliveryIndex,\n ownerDeliveryCounts,\n liveDeliveryCount: current.liveDeliveryCount + capacityDelta,\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n\n yield* failpoint.hit(`subscription:delivery-${change._tag.toLowerCase()}:after`)\n\n return result\n },\n )\n\n const recovering: SubscriptionStore['Service']['recovering'] = Effect.fnUntraced(\n function*(nowMillis, after, limit) {\n const records: Array<{ readonly key: SubscriptionKey; readonly ordinal: number }> = []\n\n for (const item of (yield* Ref.get(state)).registrationIndex.values()) {\n if (\n item.ordinal > after &&\n item.state === 'active' &&\n item.recoveryAt !== null &&\n item.recoveryAt <= nowMillis\n ) {\n records.push({ key: item.key, ordinal: item.ordinal })\n }\n }\n records.sort((a, b) => a.ordinal - b.ordinal)\n\n return records.slice(0, limit)\n },\n )\n\n const deferRecovery: SubscriptionStore['Service']['deferRecovery'] = Effect.fnUntraced(\n function*(input, expectedRevision, recovery) {\n const key = yield* requireKey(input, 'defer-recovery-key')\n\n yield* failpoint.hit('subscription:defer-recovery:before')\n yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (current): readonly [Result.Result<void, SubscriptionError>, MemorySubscriptionState] => {\n const storageKey = subscriptionKeyString(key)\n const text = current.registrations.get(storageKey)\n\n if (text === undefined) {\n return [Result.fail(error('not-found', 'subscription')), current]\n }\n const record = decode(SubscriptionRecord, text, 'defer-recovery-record')\n\n if (Result.isFailure(record)) return [Result.fail(record.failure), current]\n\n if (record.success.configurationRevision !== expectedRevision) {\n return [Result.void, current]\n }\n\n const updated = {\n ...record.success,\n recovery: record.success.state === 'active' || record.success.state === 'paused'\n ? recovery\n : null,\n }\n\n const encoded = encode(SubscriptionRecord, updated, 'defer-recovery-encode')\n\n if (Result.isFailure(encoded)) return [Result.fail(encoded.failure), current]\n const registrations = new Map(current.registrations)\n\n registrations.set(storageKey, encoded.success)\n const registrationIndex = new Map(current.registrationIndex)\n const indexed = registrationIndex.get(storageKey)\n\n if (indexed === undefined) {\n return [Result.fail(error('corrupt', 'recovery-index')), current]\n }\n registrationIndex.set(storageKey, {\n ...indexed,\n recoveryKey: updated.recovery === null ? null : candidateIndexKey(updated),\n recoveryAt: updated.recovery?.nextAttemptAtMillis ?? null,\n })\n\n return [\n Result.void,\n {\n ...current,\n registrations,\n registrationIndex,\n recoveryCounts: recoveryCountsAfter(current, registrationIndex, [storageKey]),\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n yield* failpoint.hit('subscription:defer-recovery:after')\n },\n )\n\n const readScanCursors: SubscriptionStore['Service']['readScanCursors'] = Ref.get(state).pipe(\n Effect.map((current) => current.scanCursors),\n )\n\n const advanceScanCursors: SubscriptionStore['Service']['advanceScanCursors'] = Effect.fnUntraced(\n function*(input) {\n const cursors = yield* validate(SubscriptionScanCursors, input, 'scan-cursors')\n\n yield* failpoint.hit('subscription:advance-scan-cursors:before')\n yield* Effect.uninterruptible(\n Ref.update(state, (current) => ({ ...current, scanCursors: cursors })),\n )\n yield* failpoint.hit('subscription:advance-scan-cursors:after')\n },\n )\n\n const nextDeadline = Effect.gen(function*() {\n let deadline: number | null = null\n const current = yield* Ref.get(state)\n\n if (\n current.scanCursors.events !== '' ||\n current.scanCursors.deliveries !== '' ||\n current.scanCursors.recovery !== 0\n ) {\n return 0\n }\n\n const consider = (value: number) => {\n if (deadline === null || value < deadline) deadline = value\n }\n\n if (current.retentionDeadline !== null) consider(current.retentionDeadline)\n for (const accepted of current.eventIndex.values()) {\n if (!accepted.routingComplete) consider(accepted.nextAttemptAtMillis)\n }\n for (const item of current.deliveryIndex.values()) {\n if (\n (item.state !== 'delivered' && item.state !== 'refused' && item.parked !== true) ||\n (item.state === 'delivered' && item.observeSettlement === true)\n ) {\n consider(item.nextAttemptAtMillis)\n }\n }\n for (const record of current.registrationIndex.values()) {\n if (record.state === 'active' && record.recoveryAt !== null) consider(record.recoveryAt)\n }\n\n return deadline\n })\n\n const compact: SubscriptionStore['Service']['compact'] = Effect.fnUntraced(\n function*(nowMillis, inputPolicy, requestedLimit) {\n nowMillis = Math.min(nowMillis, yield* Clock.currentTimeMillis)\n const policy = yield* validate(SubscriptionRetentionPolicy, inputPolicy, 'retention-policy')\n\n const limit = yield* validate(\n Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })),\n requestedLimit,\n 'maintenance-limit',\n )\n\n yield* failpoint.hit('subscription:compact:before')\n let corruptCandidates = 0\n\n const result = yield* Effect.uninterruptible(\n Ref.modify(\n state,\n (\n current,\n ): readonly [Result.Result<number, SubscriptionError>, MemorySubscriptionState] => {\n if (\n current.retentionHorizon !== null &&\n current.retentionHorizon !== policy.replayHorizonMillis\n ) {\n return [Result.fail(error('conflict', 'retention-horizon')), current]\n }\n const events = new Map(current.events)\n const eventIndex = new Map(current.eventIndex)\n const deliveries = new Map(current.deliveries)\n const deliveryIndex = new Map(current.deliveryIndex)\n const eventDeliveryCounts = new Map(current.eventDeliveryCounts)\n const ownerDeliveryCounts = new Map(current.ownerDeliveryCounts)\n let liveDeliveryCount = current.liveDeliveryCount\n\n // Page indexes before decoding. Each pass reads at most 2 * limit event values and\n // limit delivery values; relationship checks use maintained reference counts.\n const deliveryPage = current.deliveryKeys.slice(\n upperBound(current.deliveryKeys, current.maintenanceDeliveries),\n upperBound(current.deliveryKeys, current.maintenanceDeliveries) + limit,\n )\n\n const eventPage = current.eventKeys.slice(\n upperBound(current.eventKeys, current.maintenanceEvents),\n upperBound(current.eventKeys, current.maintenanceEvents) + limit,\n )\n\n const cutoff = nowMillis - policy.completedRetentionMillis\n let removed = 0\n const removedEvents = new Set<string>()\n const removedDeliveries = new Set<string>()\n\n for (const key of deliveryPage) {\n const text = deliveries.get(key)\n\n if (text === undefined) continue\n const decoded = decode(SubscriptionDelivery, text, 'compact-delivery')\n\n if (Result.isFailure(decoded)) {\n corruptCandidates++\n continue\n }\n const delivery = decoded.success\n\n if (\n subscriptionDeliveryKeyString(delivery.key) !== key ||\n !samePartition(delivery.key.subscription.partition, partition)\n ) {\n corruptCandidates++\n continue\n }\n\n if (\n delivery.state !== 'refused' &&\n (delivery.state !== 'delivered' || delivery.settledAtMillis === undefined)\n ) {\n continue\n }\n if (\n (delivery.settledAtMillis ??\n delivery.completedAtMillis ??\n delivery.selectedAtMillis) > cutoff\n ) {\n continue\n }\n const eventText = events.get(delivery.key.eventId)\n\n if (eventText === undefined) continue\n const accepted = decode(AcceptedEvent, eventText, 'compact-delivery-event')\n\n if (Result.isFailure(accepted)) {\n corruptCandidates++\n continue\n }\n const event = accepted.success\n\n if (\n event.eventId !== delivery.key.eventId ||\n !samePartition(event.partition, partition)\n ) {\n corruptCandidates++\n continue\n }\n\n if (\n !event.routingComplete ||\n event.occurredAtMillis === undefined ||\n event.acceptedAtMillis > cutoff ||\n (current.recoveryCounts.get(eventCandidateIndexKey(event)) ?? 0) > 0\n ) {\n continue\n }\n deliveries.delete(key)\n removedDeliveries.add(key)\n deliveryIndex.delete(key)\n eventDeliveryCounts.set(\n event.eventId,\n (eventDeliveryCounts.get(event.eventId) ?? 1) - 1,\n )\n if (subscriptionDeliveryUsesCapacity(delivery)) {\n liveDeliveryCount--\n const owner = delivery.key.subscription.ownerId\n const count = (ownerDeliveryCounts.get(owner) ?? 1) - 1\n\n if (count === 0) ownerDeliveryCounts.delete(owner)\n else ownerDeliveryCounts.set(owner, count)\n }\n }\n let tombstones = current.tombstoneCount\n\n for (const key of eventPage) {\n const text = events.get(key)\n\n if (text === undefined) continue\n const decoded = decode(AcceptedEvent, text, 'compact-event')\n\n if (Result.isFailure(decoded)) {\n corruptCandidates++\n continue\n }\n const event = decoded.success\n\n if (event.eventId !== key || !samePartition(event.partition, partition)) {\n corruptCandidates++\n continue\n }\n\n if (!event.routingComplete || event.occurredAtMillis === undefined) continue\n const expired = event.occurredAtMillis <= nowMillis - policy.replayHorizonMillis\n\n if (event.tombstone === true && !expired) continue\n if (\n event.acceptedAtMillis > cutoff ||\n (eventDeliveryCounts.get(key) ?? 0) > 0 ||\n (current.recoveryCounts.get(eventCandidateIndexKey(event)) ?? 0) > 0\n ) {\n continue\n }\n if (expired) {\n events.delete(key)\n removedEvents.add(key)\n eventIndex.delete(key)\n eventDeliveryCounts.delete(key)\n if (event.tombstone === true) tombstones--\n } else {\n if (tombstones >= policy.maxTombstones) continue\n\n const encoded = encode(\n AcceptedEvent,\n { ...event, payload: null, tombstone: true },\n 'compact-tombstone',\n )\n\n if (Result.isFailure(encoded)) continue\n events.set(key, encoded.success)\n tombstones++\n }\n removed++\n }\n\n return [\n Result.succeed(removed),\n {\n ...current,\n events,\n eventIndex,\n deliveries,\n deliveryIndex,\n eventDeliveryCounts,\n ownerDeliveryCounts,\n liveDeliveryCount,\n eventKeys: removeKeys(current.eventKeys, removedEvents),\n deliveryKeys: removeKeys(current.deliveryKeys, removedDeliveries),\n tombstoneCount: tombstones,\n maintenanceEvents: eventPage.length < limit ? '' : (eventPage.at(-1) ?? ''),\n maintenanceDeliveries: deliveryPage.length < limit ? '' : (deliveryPage.at(-1) ?? ''),\n retentionHorizon: policy.replayHorizonMillis,\n retentionDeadline: events.size === 0 ? null : nowMillis + 60_000,\n },\n ]\n },\n ),\n ).pipe(Effect.flatMap(Effect.fromResult))\n\n if (corruptCandidates > 0) {\n yield* Effect.logWarning('Subscription retention preserved corrupt candidates', {\n count: corruptCandidates,\n })\n }\n yield* failpoint.hit('subscription:compact:after')\n\n return result\n },\n )\n\n return SubscriptionStore.of({\n partition,\n compact,\n register,\n get,\n list,\n cancel,\n change,\n accept,\n event,\n pendingEvents,\n candidates,\n select,\n catchUp,\n deferEvent,\n delivery,\n pendingDeliveries,\n listDeliveries,\n changeDelivery,\n recovering,\n deferRecovery,\n readScanCursors,\n advanceScanCursors,\n nextDeadline,\n })\n})\n\nexport const memorySubscriptionStoreLayer = (\n partition: SourcePartition,\n): Layer.Layer<SubscriptionStore, SubscriptionError> =>\n Layer.effect(SubscriptionStore, makeMemorySubscriptionStore(partition))\n"],"mappings":";;;;;;;;;;;;;AAuFA,MAAM,SAAS,QAAqC,SAAiB,kBAAkB,KAAK;CAAE;CAAQ;AAAK,CAAC;AAE5G,MAAM,iBAAiB,MAAuB,UAC5C,KAAK,aAAa,MAAM,YAAY,KAAK,YAAY,MAAM;AAE7D,MAAM,cAAc,MAA+B,UACjD,KAAK,SAAS,MAAM,QAAQ,KAAK,YAAY,MAAM;AAErD,MAAM,UACJ,QACA,OACA,SAEA,OAAO,IAAI;CACT,WAAW,OAAO,WAAW,OAAO,eAAe,MAAM,CAAC,CAAC,CAAC,KAAK;CACjE,aAAa,MAAM,WAAW,IAAI;AACpC,CAAC;AAEH,MAAM,UACJ,QACA,OACA,SAEA,OAAO,IAAI;CACT,WAAW,OAAO,WAAW,OAAO,eAAe,MAAM,CAAC,CAAC,CAAC,KAAK;CACjE,aAAa,MAAM,WAAW,IAAI;AACpC,CAAC;AAEH,MAAM,gBAAsB,QAA4B,OAAe,SACrE,OAAO,WAAW,OAAO,QAAQ,OAAO,IAAI,CAAC;AAE/C,MAAM,YAAkB,QAA4B,OAAgB,SAClE,OAAO,oBAAoB,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,eAAe,MAAM,cAAc,IAAI,CAAC,CAAC;AAEjG,MAAM,aAAa,UAA2B,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK,UAAU,KAAK,CAAC,CAA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,OAAO,kBAAkB,GAAG;EAC1B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH,CAAC;AAED,MAAa,gCACX,cAEA,MAAM,OAAO,mBAAmB,4BAA4B,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as memorySubscriptionStoreLayer } from "./MemorySubscriptionStore-CFuGVxFD.mjs";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StorageOwner } from "@systemfsoftware/agent/run-storage";
|
|
2
|
+
import { ThreadImport } from "@systemfsoftware/agent/thread-import";
|
|
3
|
+
import { ThreadReader, ThreadStore } from "@systemfsoftware/agent/thread-store";
|
|
4
|
+
import * as CryptoDigest from "effect/crypto/Digest";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import { t as MemoryThreadStoreKernel } from "./MemoryThreadStoreKernel-5ya9AJvL.mjs";
|
|
7
|
+
declare namespace MemoryThreadStore_d_exports {
|
|
8
|
+
export { MemoryThreadStoreLive, memoryThreadStoreLayer };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* In-memory canonical Thread persistence. Durable accepted work is served by the separate
|
|
12
|
+
* SubmissionLedger port; this Layer provides ThreadStore, ThreadReader, and ThreadImport.
|
|
13
|
+
* Importing admissions requires a MemorySubmissionLedger paired with this store.
|
|
14
|
+
* Publishing canonical messages requires a paired MemoryMessageDeliveryStore.
|
|
15
|
+
*/
|
|
16
|
+
declare const MemoryThreadStoreLive: Layer.Layer<MemoryThreadStoreKernel | StorageOwner | ThreadImport | ThreadReader | ThreadStore, never, CryptoDigest.Digest>;
|
|
17
|
+
/** Configure a finite retained Thread capacity. Invalid construction options throw immediately. */
|
|
18
|
+
declare const memoryThreadStoreLayer: (options?: {
|
|
19
|
+
readonly maxThreads?: number;
|
|
20
|
+
}) => Layer.Layer<MemoryThreadStoreKernel | StorageOwner | ThreadImport | ThreadReader | ThreadStore, never, CryptoDigest.Digest>;
|
|
21
|
+
export { MemoryThreadStore_d_exports as n, memoryThreadStoreLayer as r, MemoryThreadStoreLive as t };
|