@oxidezap/baileyrs 0.2.11 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,84 @@
1
1
  import type { AuthenticationState } from '../Types/index.js';
2
+ /**
3
+ * Pure classifier for directory-barrier failures: does this error mean
4
+ * "this platform cannot sync directory handles" (degrade to process-crash
5
+ * atomicity) or "the durability barrier did not hold" (propagate)?
6
+ *
7
+ * - `ENOSYS` / `ENOTSUP` on any platform: the operation is not
8
+ * implemented — genuinely unsupported, safe to degrade.
9
+ * - `EINVAL` / `EPERM` / `EISDIR` on `win32` only: Windows directory
10
+ * handles reject open-for-read and FlushFileBuffers with these codes,
11
+ * so they are the documented platform fallback there. On Linux/macOS
12
+ * the same codes from a freshly opened directory handle mean something
13
+ * is genuinely wrong and they propagate.
14
+ * - Everything else propagates everywhere: `EIO`, `ENOSPC`, `EROFS`,
15
+ * `EACCES`, `ENOENT`, and notably `EBADF` (a bad handle is a real bug,
16
+ * never evidence of an unsupported platform).
17
+ *
18
+ * `platform` defaults to the running platform; tests pass explicit values
19
+ * to cover the matrix deterministically on any OS.
20
+ */
21
+ export declare const isUnsupportedDirSync: (e: unknown, platform?: NodeJS.Platform) => boolean;
22
+ type BridgeStoreFileHandle = {
23
+ writeFile(value: Uint8Array): Promise<void>;
24
+ sync(): Promise<void>;
25
+ close(): Promise<void>;
26
+ };
27
+ type BridgeStoreFileIO = {
28
+ writeTmp?(tmpPath: string, value: Uint8Array): Promise<void>;
29
+ publishTmp?(tmpPath: string, finalPath: string): Promise<void>;
30
+ syncDir?(dir: string): Promise<void>;
31
+ openTmp?(tmpPath: string): Promise<BridgeStoreFileHandle>;
32
+ };
33
+ type BridgeStoreOptions = {
34
+ io?: BridgeStoreFileIO;
35
+ };
2
36
  /**
3
37
  * Creates a file-based store for the WASM bridge.
4
38
  *
5
39
  * Each (store, key) pair maps to a file: `<folder>/<store>-<key>.bin`
6
40
  *
7
- * Uses a write-through in-memory cache to avoid redundant disk reads.
8
- * Writes go to both cache and disk. Reads hit cache first, disk on miss.
41
+ * Durability model:
42
+ * - Caller buffers are copied synchronously at admission (`set`/`setMany`
43
+ * copy before queueing), so mutating a buffer after the call — even
44
+ * before awaiting it — can never change what gets persisted.
45
+ * - Critical stores write through `durableWrite` before `set`/`setMany`
46
+ * resolve. The in-memory map only records bytes AFTER the full barrier
47
+ * (write + fsync + atomic rename + directory sync) succeeds, so an
48
+ * identical retry following a failure is never skipped and always
49
+ * re-attempts the write.
50
+ * - If the post-rename barrier fails, the key is marked uncertain: prior
51
+ * durable knowledge is discarded, reads serve best-available bytes
52
+ * without re-certifying them, and no identical set is skipped until a
53
+ * later operation completes the full barrier for that key.
54
+ * - Non-critical stores are debounced (50ms coalescing) and readable
55
+ * immediately (read-your-write), but such reads are NOT durable until
56
+ * `flush()` succeeds. A failed flush keeps the pending entry and throws,
57
+ * so the next `flush()` retries the same bytes.
58
+ * - `flush()` first waits for every operation admitted before it
59
+ * (barrier), then drains the pending writes those operations produced.
60
+ * Failures observed by the barrier propagate — a failed admitted write
61
+ * fails the flush — but only operations outstanding during that flush
62
+ * are reported, so history never poisons later flushes. A drain pass
63
+ * with any failure stops at that pass and leaves the failed entries
64
+ * for the next explicit flush. `flush()` never reports quiescence
65
+ * while prior admitted work is still running.
66
+ * - All operations on one key (set, delete, flush, concurrent batches) run
67
+ * through a per-key chain, so a stale failure can never erase newer
68
+ * state and an in-flight write can never resurrect a deleted key.
69
+ * - A failed delete restores the preceding pending/durable state, so an
70
+ * acknowledged value stays readable and flushable; only a successful
71
+ * delete (unlink + directory barrier) clears it. A delete retried while
72
+ * the key is uncertain re-runs the directory barrier instead of
73
+ * swallowing the uncertainty as idempotent absence — except that a
74
+ * directory removed externally surfaces ENOENT rather than success.
75
+ * - Every byte array handed back to callers is a copy.
9
76
  *
10
77
  * @param folder Directory to store bridge state files
78
+ * @param options Optional per-store file-I/O steps. Test/fault-injection
79
+ * seam only: the default implementation is the sole provider of the
80
+ * durability contract above.
11
81
  */
12
- export declare function useBridgeStore(folder: string): Promise<NonNullable<AuthenticationState['store']>>;
82
+ export declare function useBridgeStore(folder: string, options?: BridgeStoreOptions): Promise<NonNullable<AuthenticationState['store']>>;
83
+ export {};
13
84
  //# sourceMappingURL=use-bridge-store.d.ts.map