@vielzeug/vault 1.0.4 → 2.0.0

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.
Files changed (86) hide show
  1. package/README.md +18 -59
  2. package/dist/_dev.cjs +1 -1
  3. package/dist/_dev.cjs.map +1 -1
  4. package/dist/_dev.js +3 -8
  5. package/dist/_dev.js.map +1 -1
  6. package/dist/adapter-core.cjs +1 -1
  7. package/dist/adapter-core.cjs.map +1 -1
  8. package/dist/adapter-core.d.ts +6 -3
  9. package/dist/adapter-core.d.ts.map +1 -1
  10. package/dist/adapter-core.js +138 -148
  11. package/dist/adapter-core.js.map +1 -1
  12. package/dist/adapters/indexeddb.cjs +1 -1
  13. package/dist/adapters/indexeddb.cjs.map +1 -1
  14. package/dist/adapters/indexeddb.d.ts +2 -5
  15. package/dist/adapters/indexeddb.d.ts.map +1 -1
  16. package/dist/adapters/indexeddb.js +113 -127
  17. package/dist/adapters/indexeddb.js.map +1 -1
  18. package/dist/adapters/memory.cjs +1 -1
  19. package/dist/adapters/memory.cjs.map +1 -1
  20. package/dist/adapters/memory.d.ts +3 -9
  21. package/dist/adapters/memory.d.ts.map +1 -1
  22. package/dist/adapters/memory.js +104 -140
  23. package/dist/adapters/memory.js.map +1 -1
  24. package/dist/adapters/webstorage.cjs +1 -1
  25. package/dist/adapters/webstorage.cjs.map +1 -1
  26. package/dist/adapters/webstorage.d.ts +3 -3
  27. package/dist/adapters/webstorage.d.ts.map +1 -1
  28. package/dist/adapters/webstorage.js +72 -67
  29. package/dist/adapters/webstorage.js.map +1 -1
  30. package/dist/errors.cjs.map +1 -1
  31. package/dist/errors.js.map +1 -1
  32. package/dist/index.cjs +1 -1
  33. package/dist/index.d.ts +2 -7
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +8 -10
  36. package/dist/internal.cjs +1 -1
  37. package/dist/internal.cjs.map +1 -1
  38. package/dist/internal.d.ts +8 -37
  39. package/dist/internal.d.ts.map +1 -1
  40. package/dist/internal.js +48 -98
  41. package/dist/internal.js.map +1 -1
  42. package/dist/migration.cjs +1 -1
  43. package/dist/migration.cjs.map +1 -1
  44. package/dist/migration.js +1 -3
  45. package/dist/migration.js.map +1 -1
  46. package/dist/prune.cjs +1 -1
  47. package/dist/prune.cjs.map +1 -1
  48. package/dist/prune.d.ts +2 -2
  49. package/dist/prune.d.ts.map +1 -1
  50. package/dist/prune.js +13 -13
  51. package/dist/prune.js.map +1 -1
  52. package/dist/query.cjs +1 -1
  53. package/dist/query.cjs.map +1 -1
  54. package/dist/query.d.ts +6 -6
  55. package/dist/query.d.ts.map +1 -1
  56. package/dist/query.js +1 -1
  57. package/dist/query.js.map +1 -1
  58. package/dist/streaming.d.ts +1 -21
  59. package/dist/streaming.d.ts.map +1 -1
  60. package/dist/ttl.cjs +1 -1
  61. package/dist/ttl.cjs.map +1 -1
  62. package/dist/ttl.d.ts +2 -47
  63. package/dist/ttl.d.ts.map +1 -1
  64. package/dist/ttl.js +1 -8
  65. package/dist/ttl.js.map +1 -1
  66. package/dist/types.cjs.map +1 -1
  67. package/dist/types.d.ts +29 -316
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/types.js.map +1 -1
  70. package/dist/vault.cjs +1 -1
  71. package/dist/vault.cjs.map +1 -1
  72. package/dist/vault.iife.js +1 -1
  73. package/dist/vault.iife.js.map +1 -1
  74. package/dist/vault.js +1 -1
  75. package/dist/vault.js.map +1 -1
  76. package/dist/versioned-codec.d.ts +1 -43
  77. package/dist/versioned-codec.d.ts.map +1 -1
  78. package/package.json +4 -4
  79. package/dist/streaming.cjs +0 -2
  80. package/dist/streaming.cjs.map +0 -1
  81. package/dist/streaming.js +0 -21
  82. package/dist/streaming.js.map +0 -1
  83. package/dist/versioned-codec.cjs +0 -2
  84. package/dist/versioned-codec.cjs.map +0 -1
  85. package/dist/versioned-codec.js +0 -32
  86. package/dist/versioned-codec.js.map +0 -1
package/dist/types.d.ts CHANGED
@@ -1,63 +1,30 @@
1
1
  import type { QueryBuilder } from './query';
2
- import { type TtlMs, type VaultCodec } from './ttl';
3
- export type { TtlMs, VaultCodec };
4
- /**
5
- * Schema entry for a single table.
6
- * `T` is the record type; `Key` is the primary key field name.
7
- *
8
- * The phantom brand `[schemaEntryBrand]` holds `T` in a directly inferable position so
9
- * TypeScript can recover `T` in `RecordOf` conditional types. It uses a unique symbol key
10
- * so it is invisible in IDE autocompletion and cannot be set accidentally.
11
- */
12
- export type SchemaEntry<T extends Record<string, unknown>, Key extends keyof T & string = keyof T & string> = {
2
+ import { type TtlMs } from './ttl';
3
+ export type { TtlMs };
4
+ /** Portable primary-key values. Vault preserves their type and encodes them distinctly at rest. */
5
+ export type VaultKey = number | string;
6
+ declare const schemaEntryBrand: unique symbol;
7
+ /** A typed table definition whose primary-key field must hold a portable Vault key. */
8
+ export type SchemaEntry<T extends object, Key extends keyof T & string = keyof T & string> = T[Key] extends VaultKey ? {
13
9
  defaultTtl?: TtlMs;
14
- /**
15
- * Secondary index field names. The IndexedDB adapter creates an IDB index for each field,
16
- * enabling push-down optimisation for `equals`, `between`, and `startsWith` queries on those
17
- * fields — avoiding a full-table scan.
18
- *
19
- * ```ts
20
- * const schema = {
21
- * users: table<User>('id').index('email').index('city'),
22
- * };
23
- * // db.query('users').equals('email', 'alice@example.com') → uses IDB index
24
- * ```
25
- */
10
+ /** IndexedDB creates these as `value.<field>` indexes; other stores filter in memory. */
26
11
  indexes?: readonly (keyof T & string)[];
27
12
  key: Key;
28
- };
29
- /** A schema is any record of `SchemaEntry`-compatible values. Checked structurally so that
30
- * concrete `SchemaEntry<T, Key>` values satisfy it without covariance constraints. */
13
+ readonly [schemaEntryBrand]?: T;
14
+ } : never;
31
15
  export type AnySchema = Record<string, {
32
16
  defaultTtl?: TtlMs;
33
17
  indexes?: readonly string[];
34
18
  key: string;
35
19
  }>;
36
- /**
37
- * Fluent builder returned by `table()` — satisfies `SchemaEntry` and adds `.ttl()` and `.index()` chaining.
38
- * Export this type to annotate schema entry variables without using `ReturnType<typeof table<T, K>>`.
39
- */
40
- export type TableBuilder<T extends Record<string, unknown>, Key extends keyof T & string = keyof T & string> = SchemaEntry<T, Key> & {
41
- /**
42
- * Register a secondary index on the given field. Can be chained multiple times.
43
- * Only used by the IndexedDB adapter; other adapters fall back to in-memory filtering.
44
- *
45
- * **Custom codec caveat:** the IndexedDB adapter creates the index with keyPath
46
- * `value.<field>`, which assumes the default `{ value, expiresAt? }` storage envelope
47
- * (see `VaultCodec`). A custom codec that changes the top-level shape (e.g.
48
- * `createVersionedCodec`, or a compact/encrypted format) breaks index push-down silently —
49
- * queries on the indexed field return empty results instead of throwing. Avoid combining
50
- * `.index()` with a non-default codec, or design the custom codec to preserve `value.<field>`.
51
- */
20
+ export type TableBuilder<T extends object, Key extends keyof T & string = keyof T & string> = SchemaEntry<T, Key> & {
52
21
  index: <F extends keyof T & string>(field: F) => TableBuilder<T, Key>;
53
- /** Set a default TTL (ms) applied to all `put`/`putAll` calls that don't specify one explicitly. */
54
22
  ttl: (ms: TtlMs) => TableBuilder<T, Key>;
55
23
  };
56
- export declare function table<T extends Record<string, unknown>, Key extends keyof T & string = keyof T & string>(key: Key): TableBuilder<T, Key>;
57
- /** Extracts the record type from a schema table entry. */
58
- export type RecordOf<S extends AnySchema, K extends keyof S> = S[K] extends SchemaEntry<infer R, string> ? R : never;
59
- /** Extracts the primary key value type from a schema table entry. */
60
- export type KeyOf<S extends AnySchema, K extends keyof S> = S[K] extends SchemaEntry<infer R, infer Key> ? R[Key] : never;
24
+ /** Define a table once so all stores share the same record and portable-key contract. */
25
+ export declare function table<T extends object, Key extends keyof T & string = keyof T & string>(key: Key & (T[Key] extends VaultKey ? unknown : never)): TableBuilder<T, Key>;
26
+ export type RecordOf<S extends AnySchema, K extends keyof S> = S[K] extends SchemaEntry<infer R, infer _Key> ? R : never;
27
+ export type KeyOf<S extends AnySchema, K extends keyof S> = Extract<S[K] extends SchemaEntry<infer R, infer Key> ? R[Key] : never, VaultKey>;
61
28
  export type MigrationContext = {
62
29
  db: IDBDatabase;
63
30
  newVersion: number | null;
@@ -65,124 +32,31 @@ export type MigrationContext = {
65
32
  tx: IDBTransaction;
66
33
  };
67
34
  export type MigrationFn = (ctx: MigrationContext) => void;
68
- /**
69
- * Minimal logger interface satisfied structurally by `/rune` Logger.
70
- * Pass a rune Logger instance directly — no adapter needed:
71
- *
72
- * ```ts
73
- * import { createLogger } from '@vielzeug/rune';
74
- * const db = createMemory({ schema, logger: createLogger('db') });
75
- * ```
76
- *
77
- * Vault only emits error-level logs, so a single rune-compatible `error`
78
- * method is enough.
79
- */
80
35
  export interface VaultLogger {
81
36
  error(messageOrContext?: Record<string, unknown> | Error | string, message?: string): void;
82
37
  }
83
- /**
84
- * Minimal synchronous validator interface satisfied structurally by
85
- * `/sieve` Schema.
86
- * Pass a sieve schema directly — no adapter needed:
87
- *
88
- * ```ts
89
- * import { s } from '@vielzeug/spell';
90
- * const db = createMemory({
91
- * schema: { users: table<User>('id') },
92
- * validators: { users: v.object({ id: v.number(), name: v.string() }) },
93
- * });
94
- * ```
95
- *
96
- * Vault requires synchronous validation because writes may execute inside a
97
- * live IndexedDB transaction. Any object with a `parse(value: unknown): T`
98
- * method works.
99
- */
100
38
  export interface RecordValidator<T> {
101
39
  parse(value: unknown): T;
102
40
  }
103
- /**
104
- * Per-table record parsers. Keys match your vault schema table names.
105
- * Validators run before every `put`, `putAll`, and inside `update`/`upsert`.
106
- */
107
41
  export type TableValidators<S extends AnySchema> = {
108
42
  [K in keyof S]?: RecordValidator<RecordOf<S, K>>;
109
43
  };
110
- /**
111
- * Minimal writable-signal interface satisfied structurally by
112
- * `/ripple` `Signal<T>` and `Store<T>`.
113
- * Pass a ripple signal directly — no adapter needed:
114
- *
115
- * ```ts
116
- * import { signal } from '@vielzeug/ripple';
117
- * const usersSignal = signal<User[]>([]);
118
- *
119
- * const db = createMemory({
120
- * schema: { users: table<User>('id') },
121
- * signals: { users: usersSignal },
122
- * });
123
- *
124
- * // usersSignal.value is now always in sync with the users table.
125
- * ```
126
- *
127
- * Any object with an `update(fn: (current: T) => T): void` method satisfies
128
- * this interface. Vault calls `signal.update(() => snapshot)` on each change.
129
- */
130
- export interface ReactiveSignal<T> {
131
- update(fn: (current: T) => T): void;
132
- }
133
- /**
134
- * Per-table reactive signals. Keys match your vault schema table names.
135
- * Each signal is automatically kept in sync with the table via `observe()`.
136
- * Signals are wired at construction time and cleaned up on `dispose()`.
137
- */
138
- export type TableSignals<S extends AnySchema> = {
139
- [K in keyof S]?: ReactiveSignal<RecordOf<S, K>[]>;
140
- };
141
44
  export type Observer<T> = (records: T[]) => void;
142
- /** A function that cancels an active subscription. Returned by `observe()` and `observeMany()`. */
143
45
  export type Unsubscribe = () => void;
144
- /**
145
- * Common options shared by all adapter factories.
146
- * Individual adapters extend this with adapter-specific fields.
147
- */
46
+ /** Shared factory options. Values always use Vault's fixed `{ value, expiresAt? }` envelope. */
148
47
  export type BaseAdapterOptions<S extends AnySchema> = {
149
- /**
150
- * Pluggable serialization codec. Provide a custom implementation to change how values
151
- * are encoded at rest (e.g. compact keys, encryption, msgpack).
152
- * Defaults to the standard `{ value, expiresAt? }` JSON envelope.
153
- *
154
- * **IndexedDB + `.index()` caveat:** secondary indexes are created with keyPath
155
- * `value.<field>`, which assumes the default envelope shape. A custom codec that changes
156
- * the top-level shape breaks index push-down silently (queries return empty results
157
- * instead of throwing) — see `TableBuilder.index`.
158
- */
159
- codec?: VaultCodec;
160
- /** Structured logger. A /rune Logger satisfies VaultLogger directly. */
161
48
  logger?: VaultLogger;
162
- /** Performance monitoring hook. Called after every operation with duration in ms. */
163
49
  onMetrics?: (event: MetricsEvent) => void;
164
50
  schema: S;
165
- /**
166
- * Per-table reactive signals. A /ripple Signal<T[]> satisfies ReactiveSignal directly.
167
- * Each signal is kept in sync with its table automatically via observe().
168
- */
169
- signals?: TableSignals<S>;
170
- /** Per-table validators. A /sieve Schema satisfies this directly via `parse()`. */
171
51
  validators?: TableValidators<S>;
172
52
  };
173
53
  export type MetricsEvent = {
174
54
  duration: number;
175
55
  operation: 'batch' | 'clear' | 'count' | 'delete' | 'deleteMany' | 'entries' | 'get' | 'getAll' | 'getMany' | 'getOrDefault' | 'has' | 'isEmpty' | 'keys' | 'put' | 'putAll' | 'query' | 'queryDelete' | 'update' | 'upsert';
176
- /**
177
- * The table name. For `batch` operations this is `'*'` because a batch may
178
- * span multiple tables and there is no single canonical table name.
179
- */
180
56
  table: string;
181
57
  };
182
58
  export type DebugStats = {
183
- /** Number of TTL-expired records still physically in the store (not yet lazily evicted). */
184
59
  expiredCount: number;
185
- /** Number of live (non-expired) records. */
186
60
  recordCount: number;
187
61
  };
188
62
  export type DebugInfo<S extends AnySchema> = {
@@ -190,220 +64,59 @@ export type DebugInfo<S extends AnySchema> = {
190
64
  name: keyof S & string;
191
65
  } & DebugStats>;
192
66
  };
193
- /**
194
- * Available inside `batch()` callbacks. For IndexedDB, operations run in a real atomic IDB transaction.
195
- * The batch scope restricts accessed tables to those declared in `batch(tables, fn)` — accessing
196
- * others throws `VaultScopeError`.
197
- */
67
+ /** Methods available within an IndexedDB transaction. */
198
68
  export type TransactionContext<S extends AnySchema, K extends keyof S & string = keyof S & string> = {
199
69
  clear<T extends K>(table: T): Promise<void>;
200
70
  count<T extends K>(table: T): Promise<number>;
201
71
  delete<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;
202
- /** Delete multiple records by key in a single operation. Returns the number of records removed. */
203
72
  deleteMany<T extends K>(table: T, keys: KeyOf<S, T>[]): Promise<number>;
204
- /**
205
- * Returns all `[key, record]` pairs in the table.
206
- * Useful for cache-warming, migration scripts, and debugging.
207
- */
208
73
  entries<T extends K>(table: T): Promise<Array<[KeyOf<S, T>, RecordOf<S, T>]>>;
209
74
  get<T extends K>(table: T, key: KeyOf<S, T>): Promise<RecordOf<S, T> | undefined>;
210
- /** Fetch all records in the table. */
211
75
  getAll<T extends K>(table: T): Promise<RecordOf<S, T>[]>;
212
- /** Fetch multiple records by key in a single operation. Preserves key order; missing keys yield `undefined`. */
213
76
  getMany<T extends K>(table: T, keys: KeyOf<S, T>[]): Promise<Array<RecordOf<S, T> | undefined>>;
214
- /**
215
- * Read-or-insert: returns the existing record if present, otherwise calls `defaultFn()`,
216
- * writes the result, and returns it. Equivalent to an `upsert` that never overwrites.
217
- *
218
- * **Not atomic for memory and WebStorage adapters.** Two concurrent calls may both observe
219
- * a missing record and both invoke `defaultFn()`, writing twice. For guaranteed atomicity,
220
- * wrap in `batch(['table'], tx => tx.getOrDefault(...))` with the IndexedDB adapter.
221
- */
222
77
  getOrDefault<T extends K>(table: T, key: KeyOf<S, T>, defaultFn: () => RecordOf<S, T>, ttl?: TtlMs): Promise<RecordOf<S, T>>;
223
78
  has<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;
224
- /** Returns `true` if the table contains no live records. Equivalent to `(await count(table)) === 0`. */
225
79
  isEmpty<T extends K>(table: T): Promise<boolean>;
226
- /**
227
- * Returns the primary key of every live record in the table.
228
- * Without a `filter`, uses a key-only backend path (no full records fetched).
229
- * Useful for existence checks, diffing, and cache-invalidation.
230
- *
231
- * Pass an optional `filter` predicate to restrict results — when provided, all records are
232
- * fetched internally and the predicate is applied before key extraction.
233
- */
234
80
  keys<T extends K>(table: T, filter?: (record: RecordOf<S, T>) => boolean): Promise<KeyOf<S, T>[]>;
235
81
  put<T extends K>(table: T, value: RecordOf<S, T>, ttl?: TtlMs): Promise<void>;
236
82
  putAll<T extends K>(table: T, values: RecordOf<S, T>[], ttl?: TtlMs): Promise<void>;
237
83
  query<T extends K>(table: T): QueryBuilder<RecordOf<S, T>>;
238
- /**
239
- * Merge `changes` into the existing record identified by `key` and persist the result.
240
- * Returns `undefined` when the key does not exist — use `upsert` for insert-or-update semantics.
241
- */
242
84
  update<T extends K>(table: T, key: KeyOf<S, T>, changes: Partial<RecordOf<S, T>>, ttl?: TtlMs): Promise<RecordOf<S, T> | undefined>;
243
85
  upsert<T extends K>(table: T, key: KeyOf<S, T>, fn: (existing: RecordOf<S, T> | undefined) => RecordOf<S, T>, ttl?: TtlMs): Promise<RecordOf<S, T>>;
244
86
  };
245
- /** Full client API for vault adapters. */
246
- export interface Adapter<S extends AnySchema> {
87
+ /** Portable API returned by memory and Web Storage factories. */
88
+ export interface VaultStore<S extends AnySchema> {
247
89
  clear<K extends keyof S & string>(table: K): Promise<void>;
248
90
  count<K extends keyof S & string>(table: K): Promise<number>;
249
91
  delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean>;
250
- /** Delete multiple records by key in a single operation. Returns the number of records removed. */
251
92
  deleteMany<K extends keyof S & string>(table: K, keys: KeyOf<S, K>[]): Promise<number>;
252
- /**
253
- * Returns all `[key, record]` pairs in the table.
254
- * Useful for cache-warming, migration scripts, and debugging.
255
- */
256
93
  entries<K extends keyof S & string>(table: K): Promise<Array<[KeyOf<S, K>, RecordOf<S, K>]>>;
257
94
  get<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<RecordOf<S, K> | undefined>;
258
- /** Fetch all records in the table. */
259
95
  getAll<K extends keyof S & string>(table: K): Promise<RecordOf<S, K>[]>;
260
- /** Fetch multiple records by key in a single operation. Preserves key order; missing keys yield `undefined`. */
261
96
  getMany<K extends keyof S & string>(table: K, keys: KeyOf<S, K>[]): Promise<Array<RecordOf<S, K> | undefined>>;
262
- /**
263
- * Read-or-insert: returns the existing record if present, otherwise calls `defaultFn()`,
264
- * writes the result, and returns it. Equivalent to an `upsert` that never overwrites.
265
- *
266
- * **Not atomic for memory and WebStorage adapters.** Two concurrent calls may both observe
267
- * a missing record and both invoke `defaultFn()`, writing twice. For guaranteed atomicity,
268
- * wrap in `batch(['table'], tx => tx.getOrDefault(...))` with the IndexedDB adapter.
269
- */
270
97
  getOrDefault<K extends keyof S & string>(table: K, key: KeyOf<S, K>, defaultFn: () => RecordOf<S, K>, ttl?: TtlMs): Promise<RecordOf<S, K>>;
271
98
  has<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean>;
272
- /** Returns `true` if the table contains no live records. Equivalent to `(await count(table)) === 0`. */
273
99
  isEmpty<K extends keyof S & string>(table: K): Promise<boolean>;
274
- /**
275
- * Returns the primary key of every live record in the table.
276
- * Without a `filter`, uses a key-only backend path (no full records fetched).
277
- * Useful for existence checks, diffing, and cache-invalidation.
278
- *
279
- * Pass an optional `filter` predicate to restrict results — when provided, all records are
280
- * fetched internally and the predicate is applied before key extraction.
281
- */
282
100
  keys<K extends keyof S & string>(table: K, filter?: (record: RecordOf<S, K>) => boolean): Promise<KeyOf<S, K>[]>;
283
101
  put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: TtlMs): Promise<void>;
284
102
  putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: TtlMs): Promise<void>;
285
103
  query<K extends keyof S & string>(table: K): QueryBuilder<RecordOf<S, K>>;
286
- /**
287
- * Merge `changes` into the existing record identified by `key` and persist the result.
288
- * Returns `undefined` when the key does not exist — use `upsert` for insert-or-update semantics.
289
- */
290
104
  update<K extends keyof S & string>(table: K, key: KeyOf<S, K>, changes: Partial<RecordOf<S, K>>, ttl?: TtlMs): Promise<RecordOf<S, K> | undefined>;
291
105
  upsert<K extends keyof S & string>(table: K, key: KeyOf<S, K>, fn: (existing: RecordOf<S, K> | undefined) => RecordOf<S, K>, ttl?: TtlMs): Promise<RecordOf<S, K>>;
292
- /**
293
- * Execute multiple operations against a set of tables with deferred observer notifications.
294
- *
295
- * All observer callbacks fire once per dirty table after `fn` resolves, instead of after
296
- * each individual write. Inside `fn`, only the tables declared in `tables` may be accessed.
297
- *
298
- * **Atomicity:** For the IndexedDB adapter this runs as a real IDB transaction — all writes
299
- * are atomic and rolled back on error. For the memory and WebStorage adapters the operation
300
- * is **not atomic** — concurrent `batch()` calls or concurrent mutations may interleave.
301
- */
302
- batch<K extends keyof S & string, R>(tables: readonly K[], fn: (tx: TransactionContext<S, K>) => Promise<R>): Promise<R>;
303
- /** Returns live record counts and expired-but-not-yet-evicted counts per table. */
106
+ pruneExpired(): Promise<Record<keyof S & string, number>>;
304
107
  debug(): Promise<DebugInfo<S>>;
305
- /** `AbortSignal` aborted when `dispose()` is called. Use to tie external lifetimes to this adapter. */
306
- readonly disposalSignal: AbortSignal;
307
- /** Releases all resources (observers, cross-tab channel, DB connection). */
308
- dispose(): Promise<void>;
309
- /** `true` after `dispose()` has been called. */
310
- readonly disposed: boolean;
311
- /** Delegates to `dispose()`. Enables `await using` declarations. */
312
- [Symbol.asyncDispose](): Promise<void>;
313
108
  observe<K extends keyof S & string>(table: K, listener: Observer<RecordOf<S, K>>, options?: {
314
- /**
315
- * When `false`, skips the automatic initial snapshot fired on registration.
316
- * Useful when the caller already has the current table state (e.g. from a
317
- * preceding `getAll()` call) and only wants change notifications.
318
- * Defaults to `true`.
319
- */
320
109
  immediate?: boolean;
321
- /**
322
- * An `AbortSignal` that, when aborted, automatically unsubscribes this observer.
323
- * Aligns with the platform pattern used by `fetch`, `addEventListener`, etc.
324
- *
325
- * ```ts
326
- * const controller = new AbortController();
327
- * db.observe('users', (users) => render(users), { signal: controller.signal });
328
- * // later:
329
- * controller.abort(); // stops the observer
330
- * ```
331
- */
332
110
  signal?: AbortSignal;
333
111
  }): Unsubscribe;
334
- /**
335
- * Observe multiple tables simultaneously. The listener receives a combined snapshot
336
- * `{ [tableName]: RecordOf<S, T>[] }` and fires once after all tables have delivered
337
- * their first snapshot (initial load). Subsequent firings are coalesced per microtask,
338
- * so a batch that writes to multiple observed tables triggers exactly one combined callback.
339
- *
340
- * @param tables - The tables to observe. Must be non-empty.
341
- * @param listener - Called with a snapshot map keyed by table name.
342
- * @param options.signal - An `AbortSignal` that automatically unsubscribes all observers.
343
- * @returns An unsubscribe function that stops all underlying observers.
344
- */
345
- observeMany<K extends keyof S & string>(tables: readonly K[], listener: (snapshots: {
346
- [T in K]: RecordOf<S, T>[];
347
- }) => void, options?: {
348
- /**
349
- * When `true`, fires the listener as soon as any table delivers its first snapshot,
350
- * using empty arrays for tables not yet resolved. Defaults to `false` (wait for all tables).
351
- *
352
- * Useful when some tables may be large and you want to render partial data immediately.
353
- */
354
- eager?: boolean;
355
- signal?: AbortSignal;
356
- }): Unsubscribe;
357
- /**
358
- * Explicitly delete all TTL-expired records from the specified tables (or all tables when
359
- * no filter is provided). Returns the number of records pruned per table.
360
- *
361
- * Useful as a scheduled maintenance task for write-heavy tables that are rarely
362
- * read (lazy eviction would not reclaim storage otherwise).
363
- *
364
- * ```ts
365
- * // Prune all tables
366
- * await db.pruneExpired();
367
- *
368
- * // Prune only TTL-bearing tables
369
- * await db.pruneExpired(['sessions', 'tokens']);
370
- * ```
371
- *
372
- * **Does not trigger observer callbacks.** TTL-expired records are already logically
373
- * absent, so their physical removal does not change observable state.
374
- */
375
- pruneExpired(tables?: readonly (keyof S & string)[]): Promise<{
376
- [K in keyof S & string]: number;
377
- }>;
378
- /**
379
- * An AsyncIterable that yields a fresh snapshot of the table on every change.
380
- * The first value is emitted immediately.
381
- *
382
- * ```ts
383
- * for await (const users of db.watch('users')) {
384
- * render(users);
385
- * }
386
- * ```
387
- *
388
- * Pass an `AbortSignal` to stop iteration from outside the loop:
389
- * ```ts
390
- * const controller = new AbortController();
391
- * for await (const users of db.watch('users', { signal: controller.signal })) {
392
- * render(users);
393
- * }
394
- * controller.abort(); // stops the iteration
395
- * ```
396
- *
397
- * @param options.mode
398
- * - `'latest'` (default): if the consumer lags, intermediate snapshots are dropped and
399
- * only the most recent one is retained. Best for rendering/display use-cases.
400
- * - `'all'`: every snapshot is queued and delivered in order. Use when every intermediate
401
- * state matters (audit trails, animation frames).
402
- * @param options.signal - An `AbortSignal` that stops the iteration.
403
- */
404
- watch<K extends keyof S & string>(table: K, options?: {
405
- mode?: 'all' | 'latest';
406
- signal?: AbortSignal;
407
- }): AsyncIterable<RecordOf<S, K>[]>;
112
+ dispose(): Promise<void>;
113
+ readonly disposed: boolean;
114
+ readonly disposalSignal: AbortSignal;
115
+ [Symbol.asyncDispose](): Promise<void>;
116
+ }
117
+ /** IndexedDB-only guarantees: cursor iteration and atomic, scoped transactions. */
118
+ export interface IndexedDbVaultStore<S extends AnySchema> extends VaultStore<S> {
119
+ batch<K extends keyof S & string, R>(tables: readonly K[], fn: (tx: TransactionContext<S, K>) => Promise<R>): Promise<R>;
120
+ iterate<K extends keyof S & string>(table: K): AsyncIterable<RecordOf<S, K>>;
408
121
  }
409
122
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAe,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAC;AAIjE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AAOlC;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,SAAS,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,IAAI;IAC5G,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;IACxC,GAAG,EAAE,GAAG,CAAC;CAGV,CAAC;AAEF;uFACuF;AACvF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,UAAU,CAAC,EAAE,KAAK,CAAC;IAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEzG;;;GAGG;AACH,MAAM,MAAM,YAAY,CACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,GAAG,SAAS,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,C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AI,CAAC,CAAC;CACxC;AAED,mFAAmF;AACnF,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,SAAS,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IAC7E,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EAAE,CAAC,EACjC,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,EAAE,EAAE,CAAC,EAAE,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC/C,OAAO,CAAC,CAAC,CAAC,CAAC;IACd,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAC9E"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { QueryBuilder } from './query';\n\nimport { VaultError } from './errors';\nimport { assertTtlMs, type TtlMs, type VaultCodec } from './ttl';\n\n/* -------------------- Re-export TtlMs and VaultCodec for public API -------------------- */\n\nexport type { TtlMs, VaultCodec };\n\n/* -------------------- Schema types -------------------- */\n\n/** @internal Unique symbol used as a phantom type brand — never appears at runtime. */\ndeclare const schemaEntryBrand: unique symbol;\n\n/**\n * Schema entry for a single table.\n * `T` is the record type; `Key` is the primary key field name.\n *\n * The phantom brand `[schemaEntryBrand]` holds `T` in a directly inferable position so\n * TypeScript can recover `T` in `RecordOf` conditional types. It uses a unique symbol key\n * so it is invisible in IDE autocompletion and cannot be set accidentally.\n */\nexport type SchemaEntry<T extends Record<string, unknown>, Key extends keyof T & string = keyof T & string> = {\n defaultTtl?: TtlMs;\n /**\n * Secondary index field names. The IndexedDB adapter creates an IDB index for each field,\n * enabling push-down optimisation for `equals`, `between`, and `startsWith` queries on those\n * fields — avoiding a full-table scan.\n *\n * ```ts\n * const schema = {\n * users: table<User>('id').index('email').index('city'),\n * };\n * // db.query('users').equals('email', 'alice@example.com') → uses IDB index\n * ```\n */\n indexes?: readonly (keyof T & string)[];\n key: Key;\n /** @internal Phantom brand — enables TypeScript to infer T. Never has a runtime value. */\n readonly [schemaEntryBrand]?: T;\n};\n\n/** A schema is any record of `SchemaEntry`-compatible values. Checked structurally so that\n * concrete `SchemaEntry<T, Key>` values satisfy it without covariance constraints. */\nexport type AnySchema = Record<string, { defaultTtl?: TtlMs; indexes?: readonly string[]; key: string }>;\n\n/**\n * Fluent builder returned by `table()` — satisfies `SchemaEntry` and adds `.ttl()` and `.index()` chaining.\n * Export this type to annotate schema entry variables without using `ReturnType<typeof table<T, K>>`.\n */\nexport type TableBuilder<\n T extends Record<string, unknown>,\n Key extends keyof T & string = keyof T & string,\n> = SchemaEntry<T, Key> & {\n /**\n * Register a secondary index on the given field. Can be chained multiple times.\n * Only used by the IndexedDB adapter; other adapters fall back to in-memory filtering.\n *\n * **Custom codec caveat:** the IndexedDB adapter creates the index with keyPath\n * `value.<field>`, which assumes the default `{ value, expiresAt? }` storage envelope\n * (see `VaultCodec`). A custom codec that changes the top-level shape (e.g.\n * `createVersionedCodec`, or a compact/encrypted format) breaks index push-down silently —\n * queries on the indexed field return empty results instead of throwing. Avoid combining\n * `.index()` with a non-default codec, or design the custom codec to preserve `value.<field>`.\n */\n index: <F extends keyof T & string>(field: F) => TableBuilder<T, Key>;\n /** Set a default TTL (ms) applied to all `put`/`putAll` calls that don't specify one explicitly. */\n ttl: (ms: TtlMs) => TableBuilder<T, Key>;\n};\n\nexport function table<T extends Record<string, unknown>, Key extends keyof T & string = keyof T & string>(\n key: Key,\n): TableBuilder<T, Key> {\n function makeBuilder(entry: SchemaEntry<T, Key>): TableBuilder<T, Key> {\n return {\n ...entry,\n index: <F extends keyof T & string>(field: F): TableBuilder<T, Key> => {\n const current = (entry.indexes ?? []) as readonly (keyof T & string)[];\n\n if (current.includes(field)) {\n throw new VaultError(`table index \"${field}\" is already registered`);\n }\n\n return makeBuilder({ ...entry, indexes: [...current, field] });\n },\n ttl: (ms: TtlMs): TableBuilder<T, Key> => {\n assertTtlMs(ms, 'table.ttl');\n\n return makeBuilder({ ...entry, defaultTtl: ms });\n },\n };\n }\n\n return makeBuilder({ key });\n}\n\n/** Extracts the record type from a schema table entry. */\nexport type RecordOf<S extends AnySchema, K extends keyof S> = S[K] extends SchemaEntry<infer R, string> ? R : never;\n\n/** Extracts the primary key value type from a schema table entry. */\nexport type KeyOf<S extends AnySchema, K extends keyof S> =\n S[K] extends SchemaEntry<infer R, infer Key> ? R[Key] : never;\n\n/* -------------------- Migration -------------------- */\n\nexport type MigrationContext = {\n db: IDBDatabase;\n newVersion: number | null;\n oldVersion: number;\n tx: IDBTransaction;\n};\n\nexport type MigrationFn = (ctx: MigrationContext) => void;\n\n/* -------------------- Plugin / integration types -------------------- */\n\n/**\n * Minimal logger interface satisfied structurally by `/rune` Logger.\n * Pass a rune Logger instance directly — no adapter needed:\n *\n * ```ts\n * import { createLogger } from '@vielzeug/rune';\n * const db = createMemory({ schema, logger: createLogger('db') });\n * ```\n *\n * Vault only emits error-level logs, so a single rune-compatible `error`\n * method is enough.\n */\nexport interface VaultLogger {\n error(messageOrContext?: Record<string, unknown> | Error | string, message?: string): void;\n}\n\n/**\n * Minimal synchronous validator interface satisfied structurally by\n * `/sieve` Schema.\n * Pass a sieve schema directly — no adapter needed:\n *\n * ```ts\n * import { s } from '@vielzeug/spell';\n * const db = createMemory({\n * schema: { users: table<User>('id') },\n * validators: { users: v.object({ id: v.number(), name: v.string() }) },\n * });\n * ```\n *\n * Vault requires synchronous validation because writes may execute inside a\n * live IndexedDB transaction. Any object with a `parse(value: unknown): T`\n * method works.\n */\nexport interface RecordValidator<T> {\n parse(value: unknown): T;\n}\n\n/**\n * Per-table record parsers. Keys match your vault schema table names.\n * Validators run before every `put`, `putAll`, and inside `update`/`upsert`.\n */\nexport type TableValidators<S extends AnySchema> = {\n [K in keyof S]?: RecordValidator<RecordOf<S, K>>;\n};\n\n/**\n * Minimal writable-signal interface satisfied structurally by\n * `/ripple` `Signal<T>` and `Store<T>`.\n * Pass a ripple signal directly — no adapter needed:\n *\n * ```ts\n * import { signal } from '@vielzeug/ripple';\n * const usersSignal = signal<User[]>([]);\n *\n * const db = createMemory({\n * schema: { users: table<User>('id') },\n * signals: { users: usersSignal },\n * });\n *\n * // usersSignal.value is now always in sync with the users table.\n * ```\n *\n * Any object with an `update(fn: (current: T) => T): void` method satisfies\n * this interface. Vault calls `signal.update(() => snapshot)` on each change.\n */\nexport interface ReactiveSignal<T> {\n update(fn: (current: T) => T): void;\n}\n\n/**\n * Per-table reactive signals. Keys match your vault schema table names.\n * Each signal is automatically kept in sync with the table via `observe()`.\n * Signals are wired at construction time and cleaned up on `dispose()`.\n */\nexport type TableSignals<S extends AnySchema> = {\n [K in keyof S]?: ReactiveSignal<RecordOf<S, K>[]>;\n};\n\n/* -------------------- Observer -------------------- */\n\nexport type Observer<T> = (records: T[]) => void;\n\n/** A function that cancels an active subscription. Returned by `observe()` and `observeMany()`. */\nexport type Unsubscribe = () => void;\n\n/* -------------------- Shared adapter options -------------------- */\n\n/**\n * Common options shared by all adapter factories.\n * Individual adapters extend this with adapter-specific fields.\n */\nexport type BaseAdapterOptions<S extends AnySchema> = {\n /**\n * Pluggable serialization codec. Provide a custom implementation to change how values\n * are encoded at rest (e.g. compact keys, encryption, msgpack).\n * Defaults to the standard `{ value, expiresAt? }` JSON envelope.\n *\n * **IndexedDB + `.index()` caveat:** secondary indexes are created with keyPath\n * `value.<field>`, which assumes the default envelope shape. A custom codec that changes\n * the top-level shape breaks index push-down silently (queries return empty results\n * instead of throwing) — see `TableBuilder.index`.\n */\n codec?: VaultCodec;\n /** Structured logger. A /rune Logger satisfies VaultLogger directly. */\n logger?: VaultLogger;\n /** Performance monitoring hook. Called after every operation with duration in ms. */\n onMetrics?: (event: MetricsEvent) => void;\n schema: S;\n /**\n * Per-table reactive signals. A /ripple Signal<T[]> satisfies ReactiveSignal directly.\n * Each signal is kept in sync with its table automatically via observe().\n */\n signals?: TableSignals<S>;\n /** Per-table validators. A /sieve Schema satisfies this directly via `parse()`. */\n validators?: TableValidators<S>;\n};\n\n/* -------------------- Metrics -------------------- */\n\nexport type MetricsEvent = {\n duration: number;\n operation:\n | 'batch'\n | 'clear'\n | 'count'\n | 'delete'\n | 'deleteMany'\n | 'entries'\n | 'get'\n | 'getAll'\n | 'getMany'\n | 'getOrDefault'\n | 'has'\n | 'isEmpty'\n | 'keys'\n | 'put'\n | 'putAll'\n | 'query'\n | 'queryDelete'\n | 'update'\n | 'upsert';\n /**\n * The table name. For `batch` operations this is `'*'` because a batch may\n * span multiple tables and there is no single canonical table name.\n */\n table: string;\n};\n\n/* -------------------- Debug info -------------------- */\n\nexport type DebugStats = {\n /** Number of TTL-expired records still physically in the store (not yet lazily evicted). */\n expiredCount: number;\n /** Number of live (non-expired) records. */\n recordCount: number;\n};\n\nexport type DebugInfo<S extends AnySchema> = {\n tables: Array<{ name: keyof S & string } & DebugStats>;\n};\n\n/* -------------------- Transaction context -------------------- */\n\n/**\n * Available inside `batch()` callbacks. For IndexedDB, operations run in a real atomic IDB transaction.\n * The batch scope restricts accessed tables to those declared in `batch(tables, fn)` — accessing\n * others throws `VaultScopeError`.\n */\nexport type TransactionContext<S extends AnySchema, K extends keyof S & string = keyof S & string> = {\n clear<T extends K>(table: T): Promise<void>;\n count<T extends K>(table: T): Promise<number>;\n delete<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;\n /** Delete multiple records by key in a single operation. Returns the number of records removed. */\n deleteMany<T extends K>(table: T, keys: KeyOf<S, T>[]): Promise<number>;\n /**\n * Returns all `[key, record]` pairs in the table.\n * Useful for cache-warming, migration scripts, and debugging.\n */\n entries<T extends K>(table: T): Promise<Array<[KeyOf<S, T>, RecordOf<S, T>]>>;\n get<T extends K>(table: T, key: KeyOf<S, T>): Promise<RecordOf<S, T> | undefined>;\n /** Fetch all records in the table. */\n getAll<T extends K>(table: T): Promise<RecordOf<S, T>[]>;\n /** Fetch multiple records by key in a single operation. Preserves key order; missing keys yield `undefined`. */\n getMany<T extends K>(table: T, keys: KeyOf<S, T>[]): Promise<Array<RecordOf<S, T> | undefined>>;\n /**\n * Read-or-insert: returns the existing record if present, otherwise calls `defaultFn()`,\n * writes the result, and returns it. Equivalent to an `upsert` that never overwrites.\n *\n * **Not atomic for memory and WebStorage adapters.** Two concurrent calls may both observe\n * a missing record and both invoke `defaultFn()`, writing twice. For guaranteed atomicity,\n * wrap in `batch(['table'], tx => tx.getOrDefault(...))` with the IndexedDB adapter.\n */\n getOrDefault<T extends K>(\n table: T,\n key: KeyOf<S, T>,\n defaultFn: () => RecordOf<S, T>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, T>>;\n has<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;\n /** Returns `true` if the table contains no live records. Equivalent to `(await count(table)) === 0`. */\n isEmpty<T extends K>(table: T): Promise<boolean>;\n /**\n * Returns the primary key of every live record in the table.\n * Without a `filter`, uses a key-only backend path (no full records fetched).\n * Useful for existence checks, diffing, and cache-invalidation.\n *\n * Pass an optional `filter` predicate to restrict results — when provided, all records are\n * fetched internally and the predicate is applied before key extraction.\n */\n keys<T extends K>(table: T, filter?: (record: RecordOf<S, T>) => boolean): Promise<KeyOf<S, T>[]>;\n put<T extends K>(table: T, value: RecordOf<S, T>, ttl?: TtlMs): Promise<void>;\n putAll<T extends K>(table: T, values: RecordOf<S, T>[], ttl?: TtlMs): Promise<void>;\n query<T extends K>(table: T): QueryBuilder<RecordOf<S, T>>;\n /**\n * Merge `changes` into the existing record identified by `key` and persist the result.\n * Returns `undefined` when the key does not exist — use `upsert` for insert-or-update semantics.\n */\n update<T extends K>(\n table: T,\n key: KeyOf<S, T>,\n changes: Partial<RecordOf<S, T>>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, T> | undefined>;\n upsert<T extends K>(\n table: T,\n key: KeyOf<S, T>,\n fn: (existing: RecordOf<S, T> | undefined) => RecordOf<S, T>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, T>>;\n};\n\n/* -------------------- Adapter interface -------------------- */\n\n/** Full client API for vault adapters. */\nexport interface Adapter<S extends AnySchema> {\n clear<K extends keyof S & string>(table: K): Promise<void>;\n count<K extends keyof S & string>(table: K): Promise<number>;\n delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean>;\n /** Delete multiple records by key in a single operation. Returns the number of records removed. */\n deleteMany<K extends keyof S & string>(table: K, keys: KeyOf<S, K>[]): Promise<number>;\n /**\n * Returns all `[key, record]` pairs in the table.\n * Useful for cache-warming, migration scripts, and debugging.\n */\n entries<K extends keyof S & string>(table: K): Promise<Array<[KeyOf<S, K>, RecordOf<S, K>]>>;\n get<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<RecordOf<S, K> | undefined>;\n /** Fetch all records in the table. */\n getAll<K extends keyof S & string>(table: K): Promise<RecordOf<S, K>[]>;\n /** Fetch multiple records by key in a single operation. Preserves key order; missing keys yield `undefined`. */\n getMany<K extends keyof S & string>(table: K, keys: KeyOf<S, K>[]): Promise<Array<RecordOf<S, K> | undefined>>;\n /**\n * Read-or-insert: returns the existing record if present, otherwise calls `defaultFn()`,\n * writes the result, and returns it. Equivalent to an `upsert` that never overwrites.\n *\n * **Not atomic for memory and WebStorage adapters.** Two concurrent calls may both observe\n * a missing record and both invoke `defaultFn()`, writing twice. For guaranteed atomicity,\n * wrap in `batch(['table'], tx => tx.getOrDefault(...))` with the IndexedDB adapter.\n */\n getOrDefault<K extends keyof S & string>(\n table: K,\n key: KeyOf<S, K>,\n defaultFn: () => RecordOf<S, K>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, K>>;\n has<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean>;\n /** Returns `true` if the table contains no live records. Equivalent to `(await count(table)) === 0`. */\n isEmpty<K extends keyof S & string>(table: K): Promise<boolean>;\n /**\n * Returns the primary key of every live record in the table.\n * Without a `filter`, uses a key-only backend path (no full records fetched).\n * Useful for existence checks, diffing, and cache-invalidation.\n *\n * Pass an optional `filter` predicate to restrict results — when provided, all records are\n * fetched internally and the predicate is applied before key extraction.\n */\n keys<K extends keyof S & string>(table: K, filter?: (record: RecordOf<S, K>) => boolean): Promise<KeyOf<S, K>[]>;\n put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: TtlMs): Promise<void>;\n putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: TtlMs): Promise<void>;\n query<K extends keyof S & string>(table: K): QueryBuilder<RecordOf<S, K>>;\n /**\n * Merge `changes` into the existing record identified by `key` and persist the result.\n * Returns `undefined` when the key does not exist — use `upsert` for insert-or-update semantics.\n */\n update<K extends keyof S & string>(\n table: K,\n key: KeyOf<S, K>,\n changes: Partial<RecordOf<S, K>>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, K> | undefined>;\n upsert<K extends keyof S & string>(\n table: K,\n key: KeyOf<S, K>,\n fn: (existing: RecordOf<S, K> | undefined) => RecordOf<S, K>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, K>>;\n /**\n * Execute multiple operations against a set of tables with deferred observer notifications.\n *\n * All observer callbacks fire once per dirty table after `fn` resolves, instead of after\n * each individual write. Inside `fn`, only the tables declared in `tables` may be accessed.\n *\n * **Atomicity:** For the IndexedDB adapter this runs as a real IDB transaction — all writes\n * are atomic and rolled back on error. For the memory and WebStorage adapters the operation\n * is **not atomic** — concurrent `batch()` calls or concurrent mutations may interleave.\n */\n batch<K extends keyof S & string, R>(\n tables: readonly K[],\n fn: (tx: TransactionContext<S, K>) => Promise<R>,\n ): Promise<R>;\n /** Returns live record counts and expired-but-not-yet-evicted counts per table. */\n debug(): Promise<DebugInfo<S>>;\n /** `AbortSignal` aborted when `dispose()` is called. Use to tie external lifetimes to this adapter. */\n readonly disposalSignal: AbortSignal;\n /** Releases all resources (observers, cross-tab channel, DB connection). */\n dispose(): Promise<void>;\n /** `true` after `dispose()` has been called. */\n readonly disposed: boolean;\n /** Delegates to `dispose()`. Enables `await using` declarations. */\n [Symbol.asyncDispose](): Promise<void>;\n observe<K extends keyof S & string>(\n table: K,\n listener: Observer<RecordOf<S, K>>,\n options?: {\n /**\n * When `false`, skips the automatic initial snapshot fired on registration.\n * Useful when the caller already has the current table state (e.g. from a\n * preceding `getAll()` call) and only wants change notifications.\n * Defaults to `true`.\n */\n immediate?: boolean;\n /**\n * An `AbortSignal` that, when aborted, automatically unsubscribes this observer.\n * Aligns with the platform pattern used by `fetch`, `addEventListener`, etc.\n *\n * ```ts\n * const controller = new AbortController();\n * db.observe('users', (users) => render(users), { signal: controller.signal });\n * // later:\n * controller.abort(); // stops the observer\n * ```\n */\n signal?: AbortSignal;\n },\n ): Unsubscribe;\n /**\n * Observe multiple tables simultaneously. The listener receives a combined snapshot\n * `{ [tableName]: RecordOf<S, T>[] }` and fires once after all tables have delivered\n * their first snapshot (initial load). Subsequent firings are coalesced per microtask,\n * so a batch that writes to multiple observed tables triggers exactly one combined callback.\n *\n * @param tables - The tables to observe. Must be non-empty.\n * @param listener - Called with a snapshot map keyed by table name.\n * @param options.signal - An `AbortSignal` that automatically unsubscribes all observers.\n * @returns An unsubscribe function that stops all underlying observers.\n */\n observeMany<K extends keyof S & string>(\n tables: readonly K[],\n listener: (snapshots: { [T in K]: RecordOf<S, T>[] }) => void,\n options?: {\n /**\n * When `true`, fires the listener as soon as any table delivers its first snapshot,\n * using empty arrays for tables not yet resolved. Defaults to `false` (wait for all tables).\n *\n * Useful when some tables may be large and you want to render partial data immediately.\n */\n eager?: boolean;\n signal?: AbortSignal;\n },\n ): Unsubscribe;\n /**\n * Explicitly delete all TTL-expired records from the specified tables (or all tables when\n * no filter is provided). Returns the number of records pruned per table.\n *\n * Useful as a scheduled maintenance task for write-heavy tables that are rarely\n * read (lazy eviction would not reclaim storage otherwise).\n *\n * ```ts\n * // Prune all tables\n * await db.pruneExpired();\n *\n * // Prune only TTL-bearing tables\n * await db.pruneExpired(['sessions', 'tokens']);\n * ```\n *\n * **Does not trigger observer callbacks.** TTL-expired records are already logically\n * absent, so their physical removal does not change observable state.\n */\n pruneExpired(tables?: readonly (keyof S & string)[]): Promise<{ [K in keyof S & string]: number }>;\n /**\n * An AsyncIterable that yields a fresh snapshot of the table on every change.\n * The first value is emitted immediately.\n *\n * ```ts\n * for await (const users of db.watch('users')) {\n * render(users);\n * }\n * ```\n *\n * Pass an `AbortSignal` to stop iteration from outside the loop:\n * ```ts\n * const controller = new AbortController();\n * for await (const users of db.watch('users', { signal: controller.signal })) {\n * render(users);\n * }\n * controller.abort(); // stops the iteration\n * ```\n *\n * @param options.mode\n * - `'latest'` (default): if the consumer lags, intermediate snapshots are dropped and\n * only the most recent one is retained. Best for rendering/display use-cases.\n * - `'all'`: every snapshot is queued and delivered in order. Use when every intermediate\n * state matters (audit trails, animation frames).\n * @param options.signal - An `AbortSignal` that stops the iteration.\n */\n watch<K extends keyof S & string>(\n table: K,\n options?: { mode?: 'all' | 'latest'; signal?: AbortSignal },\n ): AsyncIterable<RecordOf<S, K>[]>;\n}\n"],"mappings":";;;AAsEA,SAAgB,EACd,GACsB;CACtB,SAAS,EAAY,GAAkD;EACrE,OAAO;GACL,GAAG;GACH,QAAoC,MAAmC;IACrE,IAAM,IAAW,EAAM,WAAW,CAAC;IAEnC,IAAI,EAAQ,SAAS,CAAK,GACxB,MAAM,IAAI,EAAW,gBAAgB,EAAM,wBAAwB;IAGrE,OAAO,EAAY;KAAE,GAAG;KAAO,SAAS,CAAC,GAAG,GAAS,CAAK;IAAE,CAAC;GAC/D;GACA,MAAM,OACJ,EAAY,GAAI,WAAW,GAEpB,EAAY;IAAE,GAAG;IAAO,YAAY;GAAG,CAAC;EAEnD;CACF;CAEA,OAAO,EAAY,EAAE,OAAI,CAAC;AAC5B"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { QueryBuilder } from './query';\n\nimport { VaultError } from './errors';\nimport { assertTtlMs, type TtlMs } from './ttl';\n\nexport type { TtlMs };\n\n/** Portable primary-key values. Vault preserves their type and encodes them distinctly at rest. */\nexport type VaultKey = number | string;\n\ndeclare const schemaEntryBrand: unique symbol;\n\n/** A typed table definition whose primary-key field must hold a portable Vault key. */\nexport type SchemaEntry<T extends object, Key extends keyof T & string = keyof T & string> = T[Key] extends VaultKey\n ? {\n defaultTtl?: TtlMs;\n /** IndexedDB creates these as `value.<field>` indexes; other stores filter in memory. */\n indexes?: readonly (keyof T & string)[];\n key: Key;\n readonly [schemaEntryBrand]?: T;\n }\n : never;\n\nexport type AnySchema = Record<string, { defaultTtl?: TtlMs; indexes?: readonly string[]; key: string }>;\n\nexport type TableBuilder<T extends object, Key extends keyof T & string = keyof T & string> = SchemaEntry<T, Key> & {\n index: <F extends keyof T & string>(field: F) => TableBuilder<T, Key>;\n ttl: (ms: TtlMs) => TableBuilder<T, Key>;\n};\n\n/** Define a table once so all stores share the same record and portable-key contract. */\nexport function table<T extends object, Key extends keyof T & string = keyof T & string>(\n key: Key & (T[Key] extends VaultKey ? unknown : never),\n): TableBuilder<T, Key> {\n function makeBuilder(entry: SchemaEntry<T, Key>): TableBuilder<T, Key> {\n return {\n ...entry,\n index: <F extends keyof T & string>(field: F): TableBuilder<T, Key> => {\n const current = (entry.indexes ?? []) as readonly (keyof T & string)[];\n\n if (current.includes(field)) {\n throw new VaultError(`table index \"${field}\" is already registered`);\n }\n\n return makeBuilder({ ...entry, indexes: [...current, field] });\n },\n ttl: (ms: TtlMs): TableBuilder<T, Key> => {\n assertTtlMs(ms, 'table.ttl');\n\n return makeBuilder({ ...entry, defaultTtl: ms });\n },\n };\n }\n\n return makeBuilder({ key } as unknown as SchemaEntry<T, Key>);\n}\n\nexport type RecordOf<S extends AnySchema, K extends keyof S> =\n S[K] extends SchemaEntry<infer R, infer _Key> ? R : never;\nexport type KeyOf<S extends AnySchema, K extends keyof S> = Extract<\n S[K] extends SchemaEntry<infer R, infer Key> ? R[Key] : never,\n VaultKey\n>;\n\nexport type MigrationContext = {\n db: IDBDatabase;\n newVersion: number | null;\n oldVersion: number;\n tx: IDBTransaction;\n};\n\nexport type MigrationFn = (ctx: MigrationContext) => void;\n\nexport interface VaultLogger {\n error(messageOrContext?: Record<string, unknown> | Error | string, message?: string): void;\n}\n\nexport interface RecordValidator<T> {\n parse(value: unknown): T;\n}\n\nexport type TableValidators<S extends AnySchema> = {\n [K in keyof S]?: RecordValidator<RecordOf<S, K>>;\n};\n\nexport type Observer<T> = (records: T[]) => void;\nexport type Unsubscribe = () => void;\n\n/** Shared factory options. Values always use Vault's fixed `{ value, expiresAt? }` envelope. */\nexport type BaseAdapterOptions<S extends AnySchema> = {\n logger?: VaultLogger;\n onMetrics?: (event: MetricsEvent) => void;\n schema: S;\n validators?: TableValidators<S>;\n};\n\nexport type MetricsEvent = {\n duration: number;\n operation:\n | 'batch'\n | 'clear'\n | 'count'\n | 'delete'\n | 'deleteMany'\n | 'entries'\n | 'get'\n | 'getAll'\n | 'getMany'\n | 'getOrDefault'\n | 'has'\n | 'isEmpty'\n | 'keys'\n | 'put'\n | 'putAll'\n | 'query'\n | 'queryDelete'\n | 'update'\n | 'upsert';\n table: string;\n};\n\nexport type DebugStats = { expiredCount: number; recordCount: number };\nexport type DebugInfo<S extends AnySchema> = { tables: Array<{ name: keyof S & string } & DebugStats> };\n\n/** Methods available within an IndexedDB transaction. */\nexport type TransactionContext<S extends AnySchema, K extends keyof S & string = keyof S & string> = {\n clear<T extends K>(table: T): Promise<void>;\n count<T extends K>(table: T): Promise<number>;\n delete<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;\n deleteMany<T extends K>(table: T, keys: KeyOf<S, T>[]): Promise<number>;\n entries<T extends K>(table: T): Promise<Array<[KeyOf<S, T>, RecordOf<S, T>]>>;\n get<T extends K>(table: T, key: KeyOf<S, T>): Promise<RecordOf<S, T> | undefined>;\n getAll<T extends K>(table: T): Promise<RecordOf<S, T>[]>;\n getMany<T extends K>(table: T, keys: KeyOf<S, T>[]): Promise<Array<RecordOf<S, T> | undefined>>;\n getOrDefault<T extends K>(\n table: T,\n key: KeyOf<S, T>,\n defaultFn: () => RecordOf<S, T>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, T>>;\n has<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;\n isEmpty<T extends K>(table: T): Promise<boolean>;\n keys<T extends K>(table: T, filter?: (record: RecordOf<S, T>) => boolean): Promise<KeyOf<S, T>[]>;\n put<T extends K>(table: T, value: RecordOf<S, T>, ttl?: TtlMs): Promise<void>;\n putAll<T extends K>(table: T, values: RecordOf<S, T>[], ttl?: TtlMs): Promise<void>;\n query<T extends K>(table: T): QueryBuilder<RecordOf<S, T>>;\n update<T extends K>(\n table: T,\n key: KeyOf<S, T>,\n changes: Partial<RecordOf<S, T>>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, T> | undefined>;\n upsert<T extends K>(\n table: T,\n key: KeyOf<S, T>,\n fn: (existing: RecordOf<S, T> | undefined) => RecordOf<S, T>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, T>>;\n};\n\n/** Portable API returned by memory and Web Storage factories. */\nexport interface VaultStore<S extends AnySchema> {\n clear<K extends keyof S & string>(table: K): Promise<void>;\n count<K extends keyof S & string>(table: K): Promise<number>;\n delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean>;\n deleteMany<K extends keyof S & string>(table: K, keys: KeyOf<S, K>[]): Promise<number>;\n entries<K extends keyof S & string>(table: K): Promise<Array<[KeyOf<S, K>, RecordOf<S, K>]>>;\n get<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<RecordOf<S, K> | undefined>;\n getAll<K extends keyof S & string>(table: K): Promise<RecordOf<S, K>[]>;\n getMany<K extends keyof S & string>(table: K, keys: KeyOf<S, K>[]): Promise<Array<RecordOf<S, K> | undefined>>;\n getOrDefault<K extends keyof S & string>(\n table: K,\n key: KeyOf<S, K>,\n defaultFn: () => RecordOf<S, K>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, K>>;\n has<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean>;\n isEmpty<K extends keyof S & string>(table: K): Promise<boolean>;\n keys<K extends keyof S & string>(table: K, filter?: (record: RecordOf<S, K>) => boolean): Promise<KeyOf<S, K>[]>;\n put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: TtlMs): Promise<void>;\n putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: TtlMs): Promise<void>;\n query<K extends keyof S & string>(table: K): QueryBuilder<RecordOf<S, K>>;\n update<K extends keyof S & string>(\n table: K,\n key: KeyOf<S, K>,\n changes: Partial<RecordOf<S, K>>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, K> | undefined>;\n upsert<K extends keyof S & string>(\n table: K,\n key: KeyOf<S, K>,\n fn: (existing: RecordOf<S, K> | undefined) => RecordOf<S, K>,\n ttl?: TtlMs,\n ): Promise<RecordOf<S, K>>;\n pruneExpired(): Promise<Record<keyof S & string, number>>;\n debug(): Promise<DebugInfo<S>>;\n observe<K extends keyof S & string>(\n table: K,\n listener: Observer<RecordOf<S, K>>,\n options?: { immediate?: boolean; signal?: AbortSignal },\n ): Unsubscribe;\n dispose(): Promise<void>;\n readonly disposed: boolean;\n readonly disposalSignal: AbortSignal;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\n/** IndexedDB-only guarantees: cursor iteration and atomic, scoped transactions. */\nexport interface IndexedDbVaultStore<S extends AnySchema> extends VaultStore<S> {\n batch<K extends keyof S & string, R>(\n tables: readonly K[],\n fn: (tx: TransactionContext<S, K>) => Promise<R>,\n ): Promise<R>;\n iterate<K extends keyof S & string>(table: K): AsyncIterable<RecordOf<S, K>>;\n}\n"],"mappings":";;;AA+BA,SAAgB,EACd,GACsB;CACtB,SAAS,EAAY,GAAkD;EACrE,OAAO;GACL,GAAG;GACH,QAAoC,MAAmC;IACrE,IAAM,IAAW,EAAM,WAAW,CAAC;IAEnC,IAAI,EAAQ,SAAS,CAAK,GACxB,MAAM,IAAI,EAAW,gBAAgB,EAAM,wBAAwB;IAGrE,OAAO,EAAY;KAAE,GAAG;KAAO,SAAS,CAAC,GAAG,GAAS,CAAK;IAAE,CAAC;GAC/D;GACA,MAAM,OACJ,EAAY,GAAI,WAAW,GAEpB,EAAY;IAAE,GAAG;IAAO,YAAY;GAAG,CAAC;EAEnD;CACF;CAEA,OAAO,EAAY,EAAE,OAAI,CAAmC;AAC9D"}