haematite 0.6.1

Content-addressed, branchable, actor-native storage engine
Documentation
use js_sys::Promise;
use wasm_bindgen::JsValue;
use web_sys::{FileSystemDirectoryHandle, FileSystemFileHandle};

#[wasm_bindgen::prelude::wasm_bindgen(inline_js = r#"
export async function haem_list_files(directory) {
  const names = [];
  for await (const [name, handle] of directory.entries()) {
    if (handle.kind === "file") names.push(name);
  }
  names.sort();
  return names;
}
export async function haem_move_file(file, target) { await file.move(target); }
export async function haem_acquire_owner(name) {
  let release;
  let acquiredResolve;
  const acquired = new Promise((resolve) => { acquiredResolve = resolve; });
  const hold = new Promise((resolve) => { release = resolve; });
  const completion = navigator.locks.request(name, async () => {
    acquiredResolve();
    await hold;
  });
  await acquired;
  return { release, completion };
}
export function haem_release_owner_now(owner) { owner.release(); }
export async function haem_release_owner(owner) {
  haem_release_owner_now(owner);
  await owner.completion;
}
"#)]
extern "C" {
    pub(super) fn haem_list_files(directory: &FileSystemDirectoryHandle) -> Promise;
    pub(super) fn haem_move_file(file: &FileSystemFileHandle, target: &str) -> Promise;
    pub(super) fn haem_acquire_owner(name: &str) -> Promise;
    pub(super) fn haem_release_owner(owner: &JsValue) -> Promise;
    pub(super) fn haem_release_owner_now(owner: &JsValue);
}