fix: harden persistence tiers and opfs durability

This commit is contained in:
Youzini-afk
2026-04-14 15:43:59 +08:00
parent 246af61f6c
commit 33b8d298f7
11 changed files with 1916 additions and 438 deletions

View File

@@ -3,6 +3,21 @@ let triedLoad = false;
let loadError = null;
let moduleSource = "none";
function shouldRetryNativeLoad() {
return (
!cachedNativeModule &&
triedLoad &&
typeof globalThis.__stBmeLoadRustWasmLayout === "function"
);
}
export function resetNativeModuleStatus() {
cachedNativeModule = null;
triedLoad = false;
loadError = null;
moduleSource = "none";
}
async function resolveWasmModuleInput(wasmUrl) {
if (
wasmUrl &&
@@ -69,12 +84,18 @@ async function loadFromWasmPackArtifacts() {
};
}
async function loadNativeModule() {
async function loadNativeModule(options = {}) {
if (cachedNativeModule) return cachedNativeModule;
if (triedLoad) {
if (triedLoad && !(options?.forceRetry === true || shouldRetryNativeLoad())) {
throw loadError || new Error("stbme_core native module unavailable");
}
if (triedLoad && (options?.forceRetry === true || shouldRetryNativeLoad())) {
triedLoad = false;
loadError = null;
moduleSource = "none";
}
triedLoad = true;
let wasmPackError = null;
@@ -148,7 +169,9 @@ export async function solveLayout(payload) {
}
export async function installNativePersistDeltaHook() {
const module = await loadNativeModule();
const module = await loadNativeModule({
forceRetry: shouldRetryNativeLoad(),
});
if (
!module ||
(typeof module.build_persist_delta_compact_hash !== "function" &&