cultcache-ts: the header peek is the one judge of a stamp; isStoreSnapshot is a shape test; byte-offset views, array16/32 and str16/32 leads and a spaced stamp pinned
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
13706c795f
commit
38dfa60804
2 changed files with 15 additions and 11 deletions
|
|
@ -16,16 +16,12 @@ const PERSISTED_RECORD_SLOTS = 4;
|
|||
const STORE_SLOTS = 3;
|
||||
|
||||
/**
|
||||
* True for a v1 or v3 snapshot, false for anything that is not a CultCache store header (the legacy
|
||||
* envelope array). Any other `cultcache.store.*` header is refused by name.
|
||||
* True for a decoded array that leads with a `cultcache.store.*` stamp, false for the legacy envelope array. It judges the
|
||||
* shape only: the verdict on the stamp is {@link refuseUnreadStoreBytes}, which a reader calls on the bytes before it decodes,
|
||||
* so the stamp of a decoded array it is given is one this runtime reads.
|
||||
*/
|
||||
export function isStoreSnapshot(decoded: unknown): decoded is [StoreFormat, ...unknown[]] {
|
||||
if (!Array.isArray(decoded) || typeof decoded[0] !== "string" || !decoded[0].startsWith(STORE_FORMAT_PREFIX)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
refuseUnreadFormat(decoded[0]);
|
||||
return true;
|
||||
return Array.isArray(decoded) && typeof decoded[0] === "string" && decoded[0].startsWith(STORE_FORMAT_PREFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue