const GLOBAL_KEY = "__openMercatoOptimisticLockReaders__";
function readGlobal() {
  try {
    const value = globalThis[GLOBAL_KEY];
    if (value && typeof value === "object") {
      return value;
    }
    return {};
  } catch {
    return {};
  }
}
function writeGlobal(value) {
  try {
    ;
    globalThis[GLOBAL_KEY] = value;
  } catch {
  }
}
function registerOptimisticLockReaders(readers) {
  const existing = readGlobal();
  writeGlobal({ ...existing, ...readers });
}
function registerOptimisticLockReaderIfAbsent(readers) {
  const existing = readGlobal();
  const next = { ...existing };
  const written = [];
  for (const [key, reader] of Object.entries(readers)) {
    if (!(key in existing)) {
      next[key] = reader;
      written.push(key);
    }
  }
  if (written.length > 0) writeGlobal(next);
  return written;
}
function getAllOptimisticLockReaders() {
  return readGlobal();
}
function clearOptimisticLockReadersForTests() {
  try {
    delete globalThis[GLOBAL_KEY];
  } catch {
  }
}
export {
  clearOptimisticLockReadersForTests,
  getAllOptimisticLockReaders,
  registerOptimisticLockReaderIfAbsent,
  registerOptimisticLockReaders
};
//# sourceMappingURL=optimistic-lock-store.js.map
