// Shared helpers for Saltcorn state-cache interactions. // Refresh Saltcorn's in-memory model caches. Mutations done in another process // (e.g. saltcorn run-js, prior ingest, or a peer's push) are not visible to // Model.findOne / Model.find until we refresh, because those methods read from // state.tables/views/pages/triggers arrays populated at startup. // // Best-effort: if Saltcorn changes its API and a refresh function disappears, // callers fall back to whatever's in the cache. const refreshState = async () => { try { const { getState } = require("@saltcorn/data/db/state"); const s = getState(); if (s.refresh_tables) await s.refresh_tables(true); if (s.refresh_views) await s.refresh_views(true); if (s.refresh_pages) await s.refresh_pages(true); if (s.refresh_triggers) await s.refresh_triggers(true); if (s.refresh_page_groups) await s.refresh_page_groups(true); } catch (e) { // ignore — best-effort } }; module.exports = { refreshState };