perf(file-transfer): share byte-bucket, integer and control-character guards (Q-B)
Identical private copies lived in both file adapters and in five browser-transfer modules. One copy each now lives next to isValidByteLength in the browser-file-storage port (outside every reference-runtime source root, so it adds no namespace export): - byteBucket (browser-files/file-observer, presigned/http-common) -> browserDataByteBucket; both modules re-export it under the old name - positiveSafeInteger / nonNegativeSafeInteger (checkpoint-schema, http-control-plane-adapter, runtime-policy, upload-byte-source, image-cdn-policy, browser-image-probe, file-policy's isPositiveSafeInteger) -> isPositiveSafeInteger / isNonNegativeSafeInteger - hasControlCharacters (image-cdn-policy) and hasForbiddenHeaderValueCharacter (fetch-json-transport) -> hasControlCharacter Same predicates, same results for every input. file-transfer reference runtime: 55306 -> 55154 gzip bytes. offline-indexeddb: 35957 -> 35951. realtime, service-worker-pwa unchanged. Verified: check:architecture, check:types:app, check:types:test, lint, test:unit, test:component, check:adapter-inventory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7b6fc4796e
commit
09402478d6
@@ -183,6 +183,43 @@ export function isValidByteLength(value: number): boolean {
|
||||
return Number.isSafeInteger(value) && value >= 0;
|
||||
}
|
||||
|
||||
export function isNonNegativeSafeInteger(value: unknown): value is number {
|
||||
return Number.isSafeInteger(value) && (value as number) >= 0;
|
||||
}
|
||||
|
||||
/** True when `value` carries a C0 control character or DEL. */
|
||||
export function hasControlCharacter(value: string): boolean {
|
||||
return [...value].some((character) => {
|
||||
const codePoint = character.codePointAt(0) ?? 0;
|
||||
return codePoint < 0x20 || codePoint === 0x7f;
|
||||
});
|
||||
}
|
||||
|
||||
export function isPositiveSafeInteger(value: unknown): value is number {
|
||||
return Number.isSafeInteger(value) && (value as number) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The observation bucket for a byte length. An absent, fractional, negative or
|
||||
* unsafe length has no bucket, so an observation never reports a guessed size.
|
||||
*/
|
||||
export function browserDataByteBucket(
|
||||
byteLength: number | null | undefined,
|
||||
): BrowserDataObservation["byteBucket"] {
|
||||
if (
|
||||
byteLength === null ||
|
||||
byteLength === undefined ||
|
||||
!isValidByteLength(byteLength)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
if (byteLength === 0) return "ZERO";
|
||||
if (byteLength < 1_048_576) return "LT1MIB";
|
||||
if (byteLength < 10_485_760) return "1_TO_9MIB";
|
||||
if (byteLength < 104_857_600) return "10_TO_99MIB";
|
||||
return "GTE100MIB";
|
||||
}
|
||||
|
||||
export function assertValidStoragePolicy(
|
||||
policy: BrowserStoragePolicy,
|
||||
): void {
|
||||
|
||||
Reference in New Issue
Block a user