3.7 KiB
3.7 KiB
Tasks: enterprise-bitpacker
Change ID: enterprise-bitpacker
Package: @suaveplan/bitpacker
Target path: universal/compression/bitpacker
Prerequisite packages on Verdaccio: @suaveplan/error, @suaveplan/types
1. Scaffold
- Create directory
universal/compression/bitpacker/withsrc/,tests/,src/__benchmarks__/, and all feature subdirectories per the layout inproposal.md. - Write
package.jsonat version0.1.0with"type": "module","sideEffects": false, fullexportsmap, deps:@suaveplan/error workspace:^,@suaveplan/types workspace:^,zod catalog:forms,@opentelemetry/api catalog:observability. - Write
tsconfig.jsonextending@suaveplan/typescript-config/library.json. - Write
vitest.config.tsusingcreateTestConfig()from@suaveplan/testing/config. - Add
lint,typecheck,test,test:coverage,build,docs:checkscripts.
2. Types + errors
- Write
src/types/common.ts—FieldType,FieldDef,BitSchemainterface. - Write
src/types/common.md. - Write
src/error-codes.ts—BitpackerErrorCode,BITPACKER_ERROR_METADATA,registerBitpackerErrorCodes(). - Write Zod schema:
FieldDefSchema.
3. BitWriter
- Implement
BitWriter— dynamicUint8Arraybuffer (double-capacity growth), bit-cursor tracking,writeUint,writeInt(two's complement),writeBool,writeFixed,writeBytes,align,toUint8Array,bitLength,byteLength. - Throws
BitpackerError(BITPACKER_INVALID_BIT_WIDTH)for bits ≤ 0 or bits > 53. - Throws
BitpackerError(BITPACKER_VALUE_OUT_OF_RANGE)for out-of-range values. - Write
bit-writer.test.ts(≤500 lines): each method, boundary values, growth, align padding. - Write
bit-writer.md.
4. BitReader
- Implement
BitReader— reads from frozenUint8Array,readUint,readInt,readBool,readFixed,readBytes,align,bitPosition,bitsRemaining,peek,seek. - Throws
BitpackerError(BITPACKER_UNDERFLOW)when reading past end. - Throws
BitpackerError(BITPACKER_INVALID_BIT_WIDTH)for bits ≤ 0 or bits > 53. - Write
bit-reader.test.ts(≤500 lines): each method, underflow, seek/peek. - Write
bit-reader.md.
5. BitSchema
- Implement
defineBitSchema<T>(fields): BitSchema<T>— validates field definitions via Zod, computesbyteSizefor fixed-width schemas, exposes typedpack(values): Uint8Arrayandunpack(data): T. - Write
bit-schema.test.tsandbit-schema.md.
6. Pack utilities
- Implement
packBits,unpackBits,countBits,zigzagEncode,zigzagDecodeinutils/pack-bits.tsandutils/zigzag.ts. - Wire OTel counters on
packBits/unpackBits. - Write
pack-bits.test.ts,pack-bits.md,zigzag.test.ts,zigzag.md.
7. Benchmarks
- Write
src/__benchmarks__/bitpacker.bench.ts— pack 1000 × 7-bit uints, schema pack/unpack 100-field struct,packBits10000 values.
8. Tests
- Write
tests/integration.test.ts— BitWriter → BitReader full round-trip including schema. - Write
tests/property.test.ts(fast-check) — pack/unpack round-trip for arbitrary bit widths and values in range,zigzagEncode(zigzagDecode(n)) === n.
9. Docs + verify + publish
- All co-located
.mdfiles (≥200 words each). - Write
README.mdat package root. bunx turbo lint typecheck test --filter=@suaveplan/bitpacker— green.bunx turbo test:coverage --filter=@suaveplan/bitpacker— 100%.bun scripts/publish.ts --package @suaveplan/bitpacker.- Archive to
openspec/archive/2026-04-24-enterprise-bitpacker/.