Files
rea/src/domain/javascript/javascriptApplicationProjectionResources.ts
T
Ysopwnable 4999e4be2c fix(javascript): isolate source analysis and retain bounded partial evidence (#1651)
* refactor(javascript): validate transferable file projections

* test(javascript): consume decoded module and static facts

* fix(javascript): isolate source analysis and retain bounded partial evidence

* test(javascript): verify cleanup retention and repeated source paths
2026-10-11 07:22:50 +08:00

43 lines
1.7 KiB
TypeScript

import type { JavaScriptStaticAnalysis } from "./javascriptStaticAnalysisTypes.js";
/** Forecast static-fact expansion into observations, nodes and relationships. */
export const estimateJavaScriptStaticApplicationProjection = (
facts: JavaScriptStaticAnalysis,
checkpointBytes: number,
sourcePath: string,
): number => {
// A finding can produce a node, a separate observation and several edges.
// Allow for identifiers, locations, authority, coverage and schema copies,
// independently of the producer's compact checkpoint representation.
const findings =
facts.references.length +
facts.endpoints.length +
facts.storage.length +
facts.role_paths.length +
facts.source_map_urls.length +
facts.electron.browser_windows.length +
facts.electron.context_bridge_apis.length +
facts.electron.ipc.length +
facts.electron.sender_validations.length +
facts.electron.utility_processes.length +
facts.electron.native_addon_bindings.length;
let records = findings * 8;
let repeatedBytes = 0;
for (const registration of facts.bundler_registrations) {
records +=
3 +
registration.modules.length * 3 +
registration.entry_module_keys.length * 3 +
registration.async_chunk_keys.length * 3;
// Every module observation and containment edge repeats its chunk keys.
repeatedBytes +=
Buffer.byteLength(JSON.stringify(registration.chunk_keys)) *
registration.modules.length *
2;
}
for (const binding of facts.electron.native_addon_bindings)
records += binding.members.length * 3;
const metadataBytes = 2048 + Buffer.byteLength(sourcePath) * 4;
return (checkpointBytes * 4 + repeatedBytes + records * metadataBytes) * 8;
};