| 1 | import { Readable } from 'node:stream'; |
| 2 | import { buffer as |
| 3 | |
| 4 | import { prefixed, type |
| 5 | import { |
| 6 | decodeEntryHeader, |
| 7 | decodeIndex, |
| 8 | encodeIndex, |
| 9 | } from '../wal/wal-codec.js'; |
| 10 | import type { WalIndex |
| 11 | |
| 12 | /** In-memory stand-in for object storage that keeps the real codec and CAS semantics. */ |
| 13 | export class InMemoryWalStore |
| 14 | private readonly objects |
| 15 | private readonly etags |
| 16 | private version = |
| 17 | |
| 18 | async readIndex(repoId |
| 19 | const key = |
| 20 | const stored = |
| 21 | if (!stored) |
| 22 | return { index: |
| 23 | } |
| 24 | |
| 25 | async casIndex(repoId |
| 26 | const key = |
| 27 | const current = |
| 28 | if (current !== |
| 29 | |
| 30 | this.objects.set |
| 31 | this.etags.set |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | async putEntry( |
| 36 | repoId: string, |
| 37 | ulid: string, |
| 38 | header: Buffer |
| 39 | pack: GitRequestBody |
| 40 | packStart = 0, |
| 41 | ) { |
| 42 | this.objects.set |
| 43 | this.entryKey(repoId |
| 44 | await readStream(prefixed |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | async openEntryPack(repoId |
| 49 | const stored = |
| 50 | return Readable.from |
| 51 | } |
| 52 | |
| 53 | async readEntryHeader(repoId |
| 54 | const stored = |
| 55 | return stored ? |
| 56 | } |
| 57 | |
| 58 | private indexKey(repoId |
| 59 | return `repos/${repoId |
| 60 | } |
| 61 | |
| 62 | private entryKey(repoId |
| 63 | return `repos/${repoId |
| 64 | } |
| 65 | } |