MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeEncryptedCompaction

Function makeEncryptedCompaction

packages/effect/src/eventlog/EventLogRemote.ts:606–717  ·  view source on GitHub ↗
({ client, encryption, session: { framed, request } }: {
  readonly session: RemoteSession
  readonly client: CompactionClient
  readonly encryption: EventLogEncryption["Service"]
})

Source from the content-addressed store, hash-verified

604const segmentAttempts = 3
605
606const makeEncryptedCompaction = ({ client, encryption, session: { framed, request } }: {
607 readonly session: RemoteSession
608 readonly client: CompactionClient
609 readonly encryption: EventLogEncryption["Service"]
610}): EventLogRemoteCompaction => {
611 const stageRequest = (stage: CompactionStage) => ({
612 publicKey: stage.identity.publicKey,
613 storeId: stage.storeId,
614 stageId: stage.stageId
615 })
616
617 return {
618 status: ({ identity, storeId }) =>
619 request(
620 "compactionStatus",
621 identity,
622 client["EventLog.CompactionStatus"]({ publicKey: identity.publicKey, storeId })
623 ),
624 begin: ({ identity, storeId }) =>
625 request(
626 "compactionBegin",
627 identity,
628 client["EventLog.CompactionBegin"]({ publicKey: identity.publicKey, storeId })
629 ),
630 input: (stage) =>
631 framed(
632 "compactionInput",
633 stage.identity,
634 () => client["EventLog.CompactionInput"](stageRequest(stage)),
635 CompactionInputRpc.decodeHeaders
636 ),
637 fetch: (stage, sequences) =>
638 framed(
639 "compactionFetch",
640 stage.identity,
641 () => client["EventLog.CompactionFetch"]({ ...stageRequest(stage), batches: sequences }),
642 (data) =>
643 Effect.flatMap(
644 ChangesRpc.decodeEncrypted(data),
645 (batches) => encryption.decrypt(stage.identity, stage.storeId, batches)
646 )
647 ),
648 upload: (stage, entries) =>
649 Effect.suspend(() => {
650 let segment: Array<EncryptedBatch> = []
651 let segmentBytes = 0
652 let segmentCount = 0
653
654 // The server forgets a segment's pieces when the connection drops, so a
655 // retry resends all of them.
656 const sendSegment = Effect.suspend(() => {
657 if (!Arr.isArrayNonEmpty(segment)) return Effect.void
658 const batches = segment
659 const id = segmentCount++
660 segment = []
661 segmentBytes = 0
662 return Effect.flatMap(CompactionPartRpc.encodeSegment(batches), (data) => {
663 const pieces = ChunkedMessage.split(id, data)

Callers 1

EventLogRemote.tsFile · 0.85

Calls 11

toBatchesFunction · 0.90
stageRequestFunction · 0.85
decryptMethod · 0.80
requestFunction · 0.70
framedFunction · 0.70
pipeMethod · 0.65
forEachMethod · 0.65
isMethod · 0.65
splitMethod · 0.45
retryMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected