feat(8.0)!: delete fork/branch/commit/history/versions — superseded by the Db API
The COW version-control surface (fork, branches, checkout, commit,
getHistory/streamHistory, asOfCommit, brain.versions) is gone, along with
its subsystems: src/versioning/, the COW object store (CommitLog,
CommitObject, RefManager, TreeObject), HistoricalStorageAdapter, and the
TypeAwareHNSWIndex path it kept alive. The Db API (now/transact/asOf/
with/persist/restore) is the one versioning model in 8.0.
Survivors and replacements:
- BlobStorage survives (the VFS stores file content through it), relocated
to src/storage/blobStorage.ts with binaryDataCodec.ts; its adapter
interface is now BlobStoreAdapter, slimmed to the consumed surface
(write/read/has/delete/getMetadata + MIME-aware compression policy).
- brain.migrate() backup branches are replaced by persist-before-migrate:
MigrateOptions.backupTo persists a hard-link snapshot of the current
generation before any transform runs; MigrationResult.backupPath reports
it, and brain.restore(path) brings it back wholesale.
- CLI: cow.ts (fork/branch/checkout/history/migrate) is replaced by
snapshot.ts — snapshot <path>, restore <path>, history (tx-log),
generation.
- New public read API: brain.transactionLog({limit}) exposes the reified
tx-log (generation/timestamp/meta, newest first) that backs the CLI
history command; TxLogEntry is exported.
Tests: superseded suites deleted; fork/commit blocks excised from shared
suites; BlobStorage tests relocated + reworked against the slimmed store;
migration tests now prove the backupTo snapshot/restore round trip; new
transactionLog coverage in db-mvcc.
This commit is contained in:
parent
431cd64406
commit
8f93add705
64 changed files with 1444 additions and 16313 deletions
77
src/storage/binaryDataCodec.ts
Normal file
77
src/storage/binaryDataCodec.ts
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* @module storage/binaryDataCodec
|
||||
* @description Single source of truth for wrapping/unwrapping binary payloads
|
||||
* stored in JSON-based object storage. Binary bytes (compressed blobs, raw
|
||||
* buffers) are persisted as `{ _binary: true, data: "<base64>" }` so they can
|
||||
* travel through adapters whose object primitive is JSON. `unwrapBinaryData`
|
||||
* reverses that wrapping — and MUST be used everywhere bytes come back out,
|
||||
* because content hashes are computed over the original bytes, not the
|
||||
* wrapper.
|
||||
*
|
||||
* Used by `BaseStorage`'s blob-store bridge and by `BlobStorage`'s
|
||||
* defense-in-depth verification path.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description Wrapped binary data format used when storing binary data in
|
||||
* JSON-based storage.
|
||||
*/
|
||||
export interface WrappedBinaryData {
|
||||
_binary: true
|
||||
data: string // base64-encoded
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Type guard for the wrapped binary format.
|
||||
* @param data - Candidate value.
|
||||
* @returns True when `data` is a `{ _binary: true, data: string }` wrapper.
|
||||
*/
|
||||
export function isWrappedBinary(data: any): data is WrappedBinaryData {
|
||||
return (
|
||||
typeof data === 'object' &&
|
||||
data !== null &&
|
||||
data._binary === true &&
|
||||
typeof data.data === 'string'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Unwrap binary data from its JSON wrapper.
|
||||
*
|
||||
* Handles:
|
||||
* - `Buffer` → `Buffer` (pass-through)
|
||||
* - `{ _binary: true, data: "<base64>" }` → `Buffer` (unwrap)
|
||||
* - Plain object → `Buffer` (JSON stringify — defensive)
|
||||
* - String → `Buffer`
|
||||
*
|
||||
* @param data - Data to unwrap (Buffer, wrapped object, plain object, or string).
|
||||
* @returns The unwrapped bytes.
|
||||
* @throws Error when the value cannot be interpreted as binary data.
|
||||
*/
|
||||
export function unwrapBinaryData(data: any): Buffer {
|
||||
// Case 1: Already a Buffer (no unwrapping needed)
|
||||
if (Buffer.isBuffer(data)) {
|
||||
return data
|
||||
}
|
||||
|
||||
// Case 2: Wrapped binary data {_binary: true, data: "base64..."}
|
||||
if (isWrappedBinary(data)) {
|
||||
return Buffer.from(data.data, 'base64')
|
||||
}
|
||||
|
||||
// Case 3: Plain object (shouldn't happen for binary blobs, but handle gracefully)
|
||||
if (typeof data === 'object' && data !== null) {
|
||||
return Buffer.from(JSON.stringify(data))
|
||||
}
|
||||
|
||||
// Case 4: String (convert to Buffer)
|
||||
if (typeof data === 'string') {
|
||||
return Buffer.from(data)
|
||||
}
|
||||
|
||||
// Case 5: Invalid type
|
||||
throw new Error(
|
||||
`Invalid data type for unwrap: ${typeof data}. ` +
|
||||
`Expected Buffer or {_binary: true, data: "base64..."}`
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue