Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,87 @@
|
||||
// Generated, do not edit. sha256:f8b7d4cfde53f5e36967f7e1ae667dea2e048f4cbedb5088c2d2e8af98709896
|
||||
import { CONFIG } from '../../shared/config.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
|
||||
const DOORLATEN = new Set(['then', 'toJSON', 'constructor', 'hasOwnProperty', 'nodeType', 'length',
|
||||
'inspect', 'valueOf', 'toString']);
|
||||
|
||||
function bewaakteRij(rij) {
|
||||
return new Proxy(rij, {
|
||||
get(doel, naam) {
|
||||
if (typeof naam === 'symbol' || naam in doel || DOORLATEN.has(naam)) return Reflect.get(doel, naam);
|
||||
throw new Error(
|
||||
`Onbekende kolom '${String(naam)}' op een rij met: ${Object.keys(doel).join(', ')}. ` +
|
||||
`Waarschijnlijk een naam van vóór de baseline.`);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function bewaak(waarde) {
|
||||
if (waarde instanceof Map) return new Map([...waarde].map(([k, v]) => [k, bewaak(v)]));
|
||||
if (Array.isArray(waarde)) return waarde.map(bewaak);
|
||||
if (waarde && typeof waarde === 'object') return bewaakteRij(waarde);
|
||||
return waarde;
|
||||
}
|
||||
|
||||
export function decodeer(waarde) {
|
||||
if (Array.isArray(waarde)) return waarde.map(decodeer);
|
||||
if (waarde && typeof waarde === 'object') {
|
||||
if (waarde.__t === 'Map') return new Map(waarde.v.map(([k, v]) => [k, decodeer(v)]));
|
||||
if (waarde.__t === 'Set') return new Set(waarde.v.map(decodeer));
|
||||
return Object.fromEntries(Object.entries(waarde).map(([k, v]) => [k, decodeer(v)]));
|
||||
}
|
||||
return waarde;
|
||||
}
|
||||
|
||||
let guardAan = CONFIG.ROW_GUARD;
|
||||
export function setRowGuard(aan) { guardAan = !!aan; }
|
||||
export function rowGuardAan() { return guardAan; }
|
||||
|
||||
const DISPATCH_VENSTER_MS = 500;
|
||||
const laatstGedispatcht = new Map();
|
||||
|
||||
export function dispatchChanges(namen) {
|
||||
if (!Array.isArray(namen) || !namen.length) return [];
|
||||
const nu = Date.now();
|
||||
const uit = [];
|
||||
for (const naam of namen) {
|
||||
if (typeof naam !== 'string' || !naam) continue;
|
||||
const vorige = laatstGedispatcht.get(naam);
|
||||
if (vorige != null && nu - vorige < DISPATCH_VENSTER_MS) continue;
|
||||
laatstGedispatcht.set(naam, nu);
|
||||
uit.push(naam);
|
||||
document.dispatchEvent(new CustomEvent(naam));
|
||||
}
|
||||
return uit;
|
||||
}
|
||||
|
||||
export function serverFoutTekst(json) {
|
||||
if (!json) return '';
|
||||
if (json.key) {
|
||||
try { return t(json.key, json.params); } catch { }
|
||||
}
|
||||
return json.error || '';
|
||||
}
|
||||
|
||||
export async function rpc(module, functie, ...args) {
|
||||
let res;
|
||||
try {
|
||||
res = await fetch(`/api/data/${module}/${functie}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ args }),
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(`No connection to the server (${module}/${functie}): ${e.message}`);
|
||||
}
|
||||
if (res.status === 401) {
|
||||
location.replace(CONFIG.AUTH.LOGIN_PATH);
|
||||
throw new Error(t('common.sessionExpired'));
|
||||
}
|
||||
const json = await res.json().catch(() => null);
|
||||
if (!res.ok) throw Object.assign(new Error(serverFoutTekst(json) || `HTTP ${res.status} bij ${module}/${functie}`), { key: json?.key ?? null });
|
||||
|
||||
if (json && json.changes) dispatchChanges(json.changes);
|
||||
const result = decodeer(json ? json.result : null);
|
||||
return guardAan ? bewaak(result) : result;
|
||||
}
|
||||
Reference in new issue
Block a user