Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
## ADDED Requirements
### Requirement: Delta package provides delta manager
The `@suaveplan/bitpacker-delta` package SHALL expose a `DeltaManager` that detects changes between successive values and encodes only deltas.
#### Scenario: Field-level delta encoding
- **WHEN** two successive objects differ in only one field
- **THEN** only the changed field is encoded, plus a field-change bitmask
#### Scenario: XOR delta for numbers
- **WHEN** two successive numeric values are packed with XOR delta
- **THEN** the packed size is smaller than full encoding when values are close
## MODIFIED Requirements
None.
## REMOVED Requirements
None.

View File

@@ -0,0 +1,30 @@
## ADDED Requirements
### Requirement: Schema package provides schema registry
The `@suaveplan/bitpacker-schema` package SHALL expose a `SchemaRegistry` that stores named schemas and resolves `_ref` tokens.
#### Scenario: Register and retrieve named schema
- **WHEN** `registry.register("player", { name: "-16", health: 255 })` is called
- **THEN** `registry.resolve("player")` returns the registered schema
### Requirement: Schema package provides validation
The `@suaveplan/bitpacker-schema` package SHALL validate that data conforms to a schema before packing.
#### Scenario: Validate data against schema
- **WHEN** `validate(data, schema)` is called with data that exceeds a numeric range
- **THEN** a `BitpackerError` is thrown with code `VALUE_OUT_OF_RANGE`
### Requirement: Schema package supports versioning
The `@suaveplan/bitpacker-schema` package SHALL support schema versioning with forward-compatibility rules.
#### Scenario: Versioned schema migration
- **WHEN** a schema contains `{ _version: 2, _schemas: [oldSchema, newSchema] }`
- **THEN** the correct schema is selected based on the version number
## MODIFIED Requirements
None.
## REMOVED Requirements
None.

View File

@@ -0,0 +1,31 @@
## ADDED Requirements
### Requirement: Strategies package provides all built-in packing strategies
The `@suaveplan/bitpacker-strategies` package SHALL provide `PackingStrategy` implementations for all schema tokens: number, string, boolean, null, bigint, object, array, enum, optional, oneOf, conditional, version, ref, datetime, varint, map, set, bitarray, blob, bitset.
#### Scenario: String strategy handles fixed and variable length
- **WHEN** a schema is `"8"` (fixed) or `"-8"` (variable)
- **THEN** the strategy packs and unpacks strings correctly for both formats
#### Scenario: Enum strategy packs index with minimum bits
- **WHEN** a schema is `{ _enum: ["a", "b", "c"] }`
- **THEN** the packed value uses exactly 2 bits for the index
#### Scenario: Optional strategy uses presence bit
- **WHEN** a schema is `{ _optional: 255 }` and the value is `undefined`
- **THEN** only a single 0 bit is written
### Requirement: Strategies package exposes a default registration function
The `@suaveplan/bitpacker-strategies` package SHALL expose `registerDefaultStrategies(manager)` that adds all built-in strategies to a `PackingStrategyManager` in the correct order.
#### Scenario: Default strategies cover all primitive schemas
- **WHEN** `registerDefaultStrategies` is called on a manager
- **THEN** every primitive schema token has a matching strategy
## MODIFIED Requirements
None.
## REMOVED Requirements
None.

View File

@@ -0,0 +1,27 @@
## ADDED Requirements
### Requirement: Streaming package provides chunked pack/unpack
The `@suaveplan/bitpacker-streaming` package SHALL expose functions that pack/unpack values in chunks suitable for streaming I/O.
#### Scenario: Pack to chunks
- **WHEN** `packToChunks(data, schema, chunkSize)` is called
- **THEN** an iterable of `Uint8Array` chunks is returned, each at most `chunkSize` bytes
#### Scenario: Unpack from chunks
- **WHEN** `unpackFromChunks(chunks, schema)` is called with an async iterable of chunks
- **THEN** the original value is reconstructed
### Requirement: Streaming package supports AbortSignal
The `@suaveplan/bitpacker-streaming` package SHALL accept an optional `AbortSignal` on all iterative APIs.
#### Scenario: Abort mid-stream
- **WHEN** an `AbortSignal` is aborted during chunk processing
- **THEN** the operation throws an abort error
## MODIFIED Requirements
None.
## REMOVED Requirements
None.

View File

@@ -0,0 +1,53 @@
## ADDED Requirements
### Requirement: Core package exposes low-level bit I/O
The `@suaveplan/bitpacker` package SHALL expose `BitWriter` and `BitReader` classes for bit-level read/write operations.
#### Scenario: BitWriter packs bits sequentially
- **WHEN** a caller invokes `writeUint(42, 8)` followed by `writeBool(true)` on a `BitWriter`
- **THEN** the resulting byte array contains 42 in the first 8 bits and 1 in the 9th bit
#### Scenario: BitReader unpacks bits sequentially
- **WHEN** a caller constructs a `BitReader` from a packed byte array and invokes `readUint(8)` then `readBool()`
- **THEN** the values match the original written values
### Requirement: Core package exposes strategy manager
The `@suaveplan/bitpacker` package SHALL expose `PackingStrategyManager` that maintains an ordered chain of `PackingStrategy` instances.
#### Scenario: Strategy manager resolves schema to strategy
- **WHEN** `findStrategy(schema)` is called with a schema token
- **THEN** the first strategy whose `canHandle(schema)` returns `true` is returned
#### Scenario: Custom strategy registration
- **WHEN** `registerStrategy(strategy)` is called
- **THEN** the strategy is inserted before the catch-all `InvalidSchemaStrategy`
### Requirement: Core package exposes BitPacker orchestrator
The `@suaveplan/bitpacker` package SHALL expose a `BitPacker` class that uses a `PackingStrategyManager` to pack/unpack values against schemas.
#### Scenario: Round-trip pack and unpack
- **WHEN** `pack(data, schema)` is invoked followed by `unpack(bytes, schema)`
- **THEN** the unpacked value equals the original data
#### Scenario: Schema registry resolves references
- **WHEN** a schema contains `{ _ref: "namedSchema" }` and the name is registered via `registerSchema`
- **THEN** the referenced schema is used for pack/unpack
### Requirement: Genesis additions are preserved in core
The core package SHALL preserve `zigzagEncode`/`zigzagDecode`, `packBits`/`unpackBits`, `peek(bits)`, `seek(position)`, and `align()`.
#### Scenario: Peek does not advance bit position
- **WHEN** `peek(8)` is called on a `BitReader`
- **THEN** the returned value matches the next 8 bits and `bitPosition` is unchanged
#### Scenario: Zigzag encoding round-trips
- **WHEN** `zigzagEncode(n)` is called followed by `zigzagDecode` on the result
- **THEN** the original value is restored for both positive and negative integers
## MODIFIED Requirements
None.
## REMOVED Requirements
None.