@vielzeug/vault 2.4.0 → 3.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 (79) hide show
  1. package/README.md +25 -32
  2. package/dist/adapter-core.cjs +1 -1
  3. package/dist/adapter-core.cjs.map +1 -1
  4. package/dist/adapter-core.d.ts +32 -7
  5. package/dist/adapter-core.d.ts.map +1 -1
  6. package/dist/adapter-core.js +204 -120
  7. package/dist/adapter-core.js.map +1 -1
  8. package/dist/adapters/indexeddb.cjs +1 -1
  9. package/dist/adapters/indexeddb.cjs.map +1 -1
  10. package/dist/adapters/indexeddb.d.ts +8 -5
  11. package/dist/adapters/indexeddb.d.ts.map +1 -1
  12. package/dist/adapters/indexeddb.js +204 -172
  13. package/dist/adapters/indexeddb.js.map +1 -1
  14. package/dist/adapters/memory.cjs +1 -1
  15. package/dist/adapters/memory.cjs.map +1 -1
  16. package/dist/adapters/memory.d.ts +2 -4
  17. package/dist/adapters/memory.d.ts.map +1 -1
  18. package/dist/adapters/memory.js +30 -52
  19. package/dist/adapters/memory.js.map +1 -1
  20. package/dist/adapters/sqlite.cjs +21 -21
  21. package/dist/adapters/sqlite.cjs.map +1 -1
  22. package/dist/adapters/sqlite.d.ts +4 -6
  23. package/dist/adapters/sqlite.d.ts.map +1 -1
  24. package/dist/adapters/sqlite.js +246 -248
  25. package/dist/adapters/sqlite.js.map +1 -1
  26. package/dist/adapters/webstorage.cjs +1 -1
  27. package/dist/adapters/webstorage.cjs.map +1 -1
  28. package/dist/adapters/webstorage.d.ts +4 -4
  29. package/dist/adapters/webstorage.d.ts.map +1 -1
  30. package/dist/adapters/webstorage.js +100 -119
  31. package/dist/adapters/webstorage.js.map +1 -1
  32. package/dist/codec.cjs +2 -0
  33. package/dist/codec.cjs.map +1 -0
  34. package/dist/codec.d.ts +5 -0
  35. package/dist/codec.d.ts.map +1 -0
  36. package/dist/codec.js +6 -0
  37. package/dist/codec.js.map +1 -0
  38. package/dist/errors.cjs +1 -1
  39. package/dist/errors.cjs.map +1 -1
  40. package/dist/errors.d.ts +5 -0
  41. package/dist/errors.d.ts.map +1 -1
  42. package/dist/errors.js +10 -2
  43. package/dist/errors.js.map +1 -1
  44. package/dist/index.cjs +1 -1
  45. package/dist/index.d.ts +3 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +3 -2
  48. package/dist/indexeddb.d.ts +1 -1
  49. package/dist/indexeddb.d.ts.map +1 -1
  50. package/dist/internal.cjs +1 -1
  51. package/dist/internal.cjs.map +1 -1
  52. package/dist/internal.d.ts.map +1 -1
  53. package/dist/internal.js +16 -13
  54. package/dist/internal.js.map +1 -1
  55. package/dist/query.cjs +1 -1
  56. package/dist/query.cjs.map +1 -1
  57. package/dist/query.d.ts +8 -24
  58. package/dist/query.d.ts.map +1 -1
  59. package/dist/query.js +23 -35
  60. package/dist/query.js.map +1 -1
  61. package/dist/sqlite.d.ts +1 -1
  62. package/dist/sqlite.d.ts.map +1 -1
  63. package/dist/ttl.cjs +1 -1
  64. package/dist/ttl.cjs.map +1 -1
  65. package/dist/ttl.js +1 -1
  66. package/dist/ttl.js.map +1 -1
  67. package/dist/types.cjs +1 -1
  68. package/dist/types.cjs.map +1 -1
  69. package/dist/types.d.ts +46 -33
  70. package/dist/types.d.ts.map +1 -1
  71. package/dist/types.js +8 -2
  72. package/dist/types.js.map +1 -1
  73. package/dist/vault.cjs +1 -1
  74. package/dist/vault.cjs.map +1 -1
  75. package/dist/vault.iife.js +1 -1
  76. package/dist/vault.iife.js.map +1 -1
  77. package/dist/vault.js +1 -1
  78. package/dist/vault.js.map +1 -1
  79. package/package.json +10 -8
@@ -1 +1 @@
1
- {"version":3,"file":"vault.iife.js","names":[],"sources":["../src/errors.ts","../src/ttl.ts","../src/types.ts"],"sourcesContent":["/**\n * Base class for all vault errors. Catch with `instanceof VaultError` to\n * handle any vault-originated error regardless of its specific subtype.\n */\nexport class VaultError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n // Ensures `instanceof` works correctly when transpiled to ES5.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when an operation is attempted on a disposed adapter or observer hub. */\nexport class VaultDisposedError extends VaultError {\n constructor(message = 'adapter is disposed', opts?: ErrorOptions) {\n super(message, opts);\n }\n}\n\n/** Thrown when a `batch()` callback accesses a table not declared in the scope. */\nexport class VaultScopeError extends VaultError {}\n\n/** Thrown when a WebStorage write exceeds the storage quota. */\nexport class VaultQuotaError extends VaultError {}\n\n/** Thrown when an IndexedDB `onupgradeneeded` migration callback throws. */\nexport class VaultMigrationError extends VaultError {}\n","import { VaultError } from './errors';\n\n/** Duration helpers that produce finite, positive millisecond values. */\nexport const ttl = {\n days: (n: number) => assertPositiveFinite(n * 86_400_000, 'ttl.days'),\n hours: (n: number) => assertPositiveFinite(n * 3_600_000, 'ttl.hours'),\n minutes: (n: number) => assertPositiveFinite(n * 60_000, 'ttl.minutes'),\n ms: (n: number) => assertPositiveFinite(n, 'ttl.ms'),\n seconds: (n: number) => assertPositiveFinite(n * 1000, 'ttl.seconds'),\n} as const;\n\n/** Fixed storage envelope shared by every adapter, so data and indexes stay portable. */\nexport type StoredRecord<T> = { expiresAt?: number; value: T };\n\nexport function isExpired(expiresAt: number | undefined): boolean {\n return expiresAt !== undefined && Date.now() >= expiresAt;\n}\n\n/** Throws when `ttlMs` is not a finite, positive number. Returns it unchanged otherwise. */\nexport function assertPositiveFinite(ttlMs: number, source: string): number {\n if (!Number.isFinite(ttlMs) || ttlMs <= 0) {\n throw new VaultError(`${source} expected a finite positive number, received ${String(ttlMs)}`);\n }\n\n return ttlMs;\n}\n\nexport function parseStored<T>(raw: unknown): StoredRecord<T> | undefined {\n if (typeof raw !== 'object' || raw === null || !('value' in raw)) return undefined;\n\n const record = raw as { expiresAt?: unknown; value: unknown };\n\n if (record.expiresAt !== undefined && (typeof record.expiresAt !== 'number' || !Number.isFinite(record.expiresAt))) {\n return undefined;\n }\n\n return record as StoredRecord<T>;\n}\n","/// <reference lib=\"dom\" />\n\nimport { VaultError } from './errors';\nimport type { QueryBuilder } from './query';\nimport { assertPositiveFinite } from './ttl';\n\n/** Portable primary-key values. Vault preserves their type and encodes them distinctly at rest. */\nexport type VaultKey = number | string;\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> = {\n defaultTtl?: number;\n /** IndexedDB creates these as `value.<field>` indexes; other stores filter in memory. */\n indexes?: readonly (keyof T & string)[];\n key: Key;\n};\n\nexport type AnySchema = Record<string, { defaultTtl?: number; indexes?: readonly string[]; key: string }>;\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 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 schema: S;\n validators?: TableValidators<S>;\n};\n\n/** Methods available within an IndexedDB or SQLite 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 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 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?: number): Promise<void>;\n putAll<T extends K>(table: T, values: RecordOf<S, T>[], ttl?: number): 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?: number,\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?: number,\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 readonly disposalSignal: AbortSignal;\n dispose(): Promise<void>;\n readonly disposed: boolean;\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 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 observe<K extends keyof S & string>(\n table: K,\n listener: Observer<RecordOf<S, K>>,\n options?: { immediate?: boolean; signal?: AbortSignal },\n ): Unsubscribe;\n pruneExpired(): Promise<Record<keyof S & string, number>>;\n put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: number): Promise<void>;\n putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: number): 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?: number,\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?: number,\n ): Promise<RecordOf<S, K>>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\n/** Atomic, scoped transactions and lazy iteration supplied by storage engines that support them. */\nexport interface TransactionalVaultStore<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\n/** Define a typed table whose primary-key field holds a portable Vault key. */\nexport function table<T extends object, Key extends keyof T & string = keyof T & string>(\n key: Key,\n options: { defaultTtl?: number; indexes?: readonly (keyof T & string)[] } = {},\n): SchemaEntry<T, Key> {\n const { defaultTtl, indexes } = options;\n\n if (defaultTtl !== undefined) assertPositiveFinite(defaultTtl, 'table: defaultTtl');\n\n if (indexes) {\n const seen = new Set<string>();\n\n for (const field of indexes) {\n if (seen.has(field)) {\n throw new VaultError(`table: index \"${field}\" is already registered`);\n }\n\n seen.add(field);\n }\n }\n\n return { defaultTtl, indexes, key } as unknown as SchemaEntry<T, Key>;\n}\n"],"mappings":"oFAIA,IAAa,EAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KAEvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,EAAb,cAAwC,CAAW,CACjD,YAAY,EAAU,sBAAuB,EAAqB,CAChE,MAAM,EAAS,CAAI,CACrB,CACF,EAGa,EAAb,cAAqC,CAAW,CAAC,EAGpC,EAAb,cAAqC,CAAW,CAAC,EAGpC,EAAb,cAAyC,CAAW,CAAC,ECxBxC,EAAM,CACjB,KAAO,GAAc,EAAqB,EAAI,MAAY,UAAU,EACpE,MAAQ,GAAc,EAAqB,EAAI,KAAW,WAAW,EACrE,QAAU,GAAc,EAAqB,EAAI,IAAQ,aAAa,EACtE,GAAK,GAAc,EAAqB,EAAG,QAAQ,EACnD,QAAU,GAAc,EAAqB,EAAI,IAAM,aAAa,CACtE,EAKA,SAAgB,EAAU,EAAwC,CAChE,OAAO,IAAc,IAAA,IAAa,KAAK,IAAI,GAAK,CAClD,CAGA,SAAgB,EAAqB,EAAe,EAAwB,CAC1E,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,GAAS,EACtC,MAAM,IAAI,EAAW,GAAG,EAAO,+CAA+C,OAAO,CAAK,GAAG,EAG/F,OAAO,CACT,CCgGA,SAAgB,EACd,EACA,EAA4E,CAAC,EACxD,CACrB,GAAM,CAAE,aAAY,WAAY,EAIhC,GAFI,IAAe,IAAA,IAAW,EAAqB,EAAY,mBAAmB,EAE9E,EAAS,CACX,IAAM,EAAO,IAAI,IAEjB,IAAK,IAAM,KAAS,EAAS,CAC3B,GAAI,EAAK,IAAI,CAAK,EAChB,MAAM,IAAI,EAAW,iBAAiB,EAAM,wBAAwB,EAGtE,EAAK,IAAI,CAAK,CAChB,CACF,CAEA,MAAO,CAAE,aAAY,UAAS,KAAI,CACpC"}
1
+ {"version":3,"file":"vault.iife.js","names":[],"sources":["../src/errors.ts","../src/ttl.ts","../src/adapter-core.ts","../src/types.ts"],"sourcesContent":["/**\n * Base class for all vault errors. Catch with `instanceof VaultError` to\n * handle any vault-originated error regardless of its specific subtype.\n */\nexport class VaultError extends Error {\n protected static readonly errorName: string = 'VaultError';\n\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = (new.target as typeof VaultError).errorName;\n // Ensures `instanceof` works correctly when transpiled to ES5.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when an operation is attempted on a disposed adapter or observer hub. */\nexport class VaultDisposedError extends VaultError {\n protected static override readonly errorName = 'VaultDisposedError';\n\n constructor(message = 'adapter is disposed', opts?: ErrorOptions) {\n super(message, opts);\n }\n}\n\n/** Thrown when a `batch()` callback accesses a table not declared in the scope. */\nexport class VaultScopeError extends VaultError {\n protected static override readonly errorName = 'VaultScopeError';\n}\n\n/** Thrown when a WebStorage write exceeds the storage quota. */\nexport class VaultQuotaError extends VaultError {\n protected static override readonly errorName = 'VaultQuotaError';\n}\n\n/** Thrown when an IndexedDB `onupgradeneeded` migration callback throws. */\nexport class VaultMigrationError extends VaultError {\n protected static override readonly errorName = 'VaultMigrationError';\n}\n","import { VaultError } from './errors';\n\n/** Duration helpers that produce finite, positive millisecond values. */\nexport const ttl = {\n days: (n: number) => assertPositiveFinite(n * 86_400_000, 'ttl.days'),\n hours: (n: number) => assertPositiveFinite(n * 3_600_000, 'ttl.hours'),\n minutes: (n: number) => assertPositiveFinite(n * 60_000, 'ttl.minutes'),\n ms: (n: number) => assertPositiveFinite(n, 'ttl.ms'),\n seconds: (n: number) => assertPositiveFinite(n * 1000, 'ttl.seconds'),\n} as const;\n\n/** Fixed storage envelope shared by every adapter, so data and indexes stay portable. */\nexport type StoredRecord<T> = { expiresAt?: number; value: T };\n\nexport function isExpired(expiresAt: number | undefined): boolean {\n return expiresAt !== undefined && Date.now() >= expiresAt;\n}\n\n/** Throws when `ttlMs` is not a finite, positive number. Returns it unchanged otherwise. */\nexport function assertPositiveFinite(ttlMs: number, source: string): number {\n if (!Number.isFinite(ttlMs) || ttlMs <= 0) {\n throw new VaultError(`${source} expected a finite positive number, received ${String(ttlMs)}`);\n }\n\n return ttlMs;\n}\n\nexport function parseStored<T>(raw: unknown): StoredRecord<T> | undefined {\n if (typeof raw !== 'object' || raw === null || !('value' in raw)) return undefined;\n\n const record = raw as { expiresAt?: unknown; value: unknown };\n\n if (record.expiresAt !== undefined && (typeof record.expiresAt !== 'number' || !Number.isFinite(record.expiresAt))) {\n return undefined;\n }\n\n return record as StoredRecord<T>;\n}\n","import { validateRecord } from './codec';\nimport { VaultDisposedError, VaultError, VaultScopeError } from './errors';\nimport { createObserverHub, getRecordKey } from './internal';\nimport { createQueryBuilder } from './query';\nimport { assertPositiveFinite } from './ttl';\nimport type {\n AnySchema,\n DocumentVaultStore,\n DurableStoreOptions,\n KeyOf,\n KeyValueVaultStore,\n MemoryStoreOptions,\n RecordOf,\n TableCodecs,\n TransactionContext,\n} from './types';\n\n/* -------------------- Internal backend protocol -------------------- */\n\n/** @internal Full backend protocol implemented by each adapter. */\nexport type StorageBackend<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: readonly KeyOf<S, T>[]): Promise<number>;\n dispose?(): Promise<void>;\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 getAllKeys?<T extends K>(table: T): Promise<KeyOf<S, T>[]>;\n getMany?<T extends K>(table: T, keys: readonly KeyOf<S, T>[]): Promise<Array<RecordOf<S, T> | undefined>>;\n has?<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;\n /**\n * Optional: lazy iteration over live records. Document stores implement this natively\n * (IDB cursor, SQLite keyset pagination). Key-value stores fall back to getAll().\n */\n iterate?<T extends K>(table: T): AsyncIterable<RecordOf<S, T>>;\n /**\n * Optional: prune all expired records across all tables in a single atomic operation.\n * When present, `pruneExpired()` delegates here instead of calling `pruneExpiredInTable` N times.\n */\n pruneAllExpired?(): Promise<Record<string, number>>;\n pruneExpiredInTable<T extends K>(table: T): Promise<number>;\n put<T extends K>(table: T, value: RecordOf<S, T>, ttl?: number): Promise<void>;\n putAll<T extends K>(table: T, values: readonly RecordOf<S, T>[], ttl?: number): Promise<void>;\n};\n\n/** @internal */\nexport type BatchDeps<S extends AnySchema> = {\n notifyMutation: (table: keyof S & string) => void;\n validate: <K extends keyof S & string>(table: K, value: RecordOf<S, K>) => RecordOf<S, K>;\n};\n\n/** @internal */\nexport type BatchImpl<S extends AnySchema> = <K extends keyof S & string, R>(\n tables: readonly K[],\n fn: (tx: TransactionContext<S, K>) => Promise<R>,\n) => Promise<R>;\n\n/* -------------------- Helpers -------------------- */\n\nexport function assertBatchTables(tables: readonly string[]): void {\n if (tables.length === 0) throw new VaultError('batch: declare at least one table');\n}\n\nfunction resolveTtl<S extends AnySchema, K extends keyof S & string>(\n schema: S,\n table: K,\n ttl?: number,\n): number | undefined {\n if (ttl !== undefined) assertPositiveFinite(ttl, 'put/putAll');\n\n return ttl ?? schema[table].defaultTtl;\n}\n\nfunction verifyKey<S extends AnySchema, K extends keyof S & string>(\n schema: S,\n table: K,\n expected: KeyOf<S, K>,\n value: RecordOf<S, K>,\n op: string,\n): void {\n const actual = getRecordKey(schema, table, value);\n\n if (actual !== expected) {\n throw new VaultError(\n `${op}: key field \"${schema[table].key}\" must be \"${String(expected)}\" but got \"${String(actual)}\" in table \"${table}\"`,\n );\n }\n}\n\n/* -------------------- Codec helpers -------------------- */\n\nexport function makeValidator<S extends AnySchema>(\n codecs: TableCodecs<S> | undefined,\n): <K extends keyof S & string>(table: K, value: RecordOf<S, K>) => RecordOf<S, K> {\n return <K extends keyof S & string>(table: K, value: RecordOf<S, K>): RecordOf<S, K> => {\n const codec = codecs?.[table];\n\n if (!codec) return value;\n\n try {\n return validateRecord(codec, value);\n } catch (err) {\n throw new VaultError(`validation failed for table \"${table}\"`, { cause: err });\n }\n };\n}\n\n/* -------------------- buildTxContext -------------------- */\n\nexport function buildTxContext<S extends AnySchema, K extends keyof S & string>(\n schema: S,\n core: StorageBackend<S, K>,\n onMutate: (table: K) => void,\n validate?: <T extends K>(table: T, value: RecordOf<S, T>) => RecordOf<S, T>,\n scope?: ReadonlySet<string>,\n isActive: () => boolean = () => true,\n): TransactionContext<S, K> {\n const applyValidation = validate ?? ((_: K, v: RecordOf<S, K>) => v);\n\n const checkScope = (table: K): void => {\n if (!isActive()) throw new VaultScopeError('transaction context is no longer active');\n if (scope && !scope.has(table)) throw new VaultScopeError(`table \"${table}\" is not part of this batch scope`);\n };\n\n const context: TransactionContext<S, K> = {\n async clear(table) {\n checkScope(table);\n await core.clear(table);\n onMutate(table);\n },\n async count(table) {\n checkScope(table);\n return core.count ? core.count(table) : (await core.getAll(table)).length;\n },\n async delete(table, key) {\n checkScope(table);\n\n const deleted = await core.delete(table, key);\n\n if (deleted) onMutate(table);\n\n return deleted;\n },\n async deleteMany(table, keys) {\n checkScope(table);\n if (!core.deleteMany) {\n const results = await Promise.all(keys.map((key) => core.delete(table, key)));\n const deleted = results.filter(Boolean).length;\n if (deleted > 0) onMutate(table);\n return deleted;\n }\n const deleted = await core.deleteMany(table, keys);\n if (deleted > 0) onMutate(table);\n return deleted;\n },\n async get(table, key) {\n checkScope(table);\n\n return core.get(table, key);\n },\n async getAll(table) {\n checkScope(table);\n\n return core.getAll(table);\n },\n async getMany(table, keys) {\n checkScope(table);\n return core.getMany ? core.getMany(table, keys) : Promise.all(keys.map((key) => core.get(table, key)));\n },\n async has(table, key) {\n checkScope(table);\n return core.has ? core.has(table, key) : (await core.get(table, key)) !== undefined;\n },\n async isEmpty(table) {\n return (await context.count(table)) === 0;\n },\n iterate(table) {\n checkScope(table);\n\n if (core.iterate) return core.iterate(table);\n\n // Fallback: iterate over getAll() materialized records.\n return (async function* (): AsyncIterable<RecordOf<S, typeof table>> {\n const records = await core.getAll(table);\n\n for (const record of records) yield record;\n })();\n },\n async keys(table, filter) {\n checkScope(table);\n if (!filter && core.getAllKeys) return core.getAllKeys(table);\n const records = await core.getAll(table);\n const selected = filter ? records.filter(filter) : records;\n const keyField = schema[table].key;\n return selected.map((record) => (record as Record<string, unknown>)[keyField] as KeyOf<S, typeof table>);\n },\n async put(table, value, ttl) {\n checkScope(table);\n const canonical = applyValidation(table, value);\n await core.put(table, canonical, resolveTtl(schema, table, ttl));\n onMutate(table);\n return canonical;\n },\n async putAll(table, values, ttl) {\n checkScope(table);\n\n if (values.length === 0) return;\n\n const toWrite = values.map((v) => applyValidation(table, v));\n\n await core.putAll(table, toWrite, resolveTtl(schema, table, ttl));\n onMutate(table);\n },\n query(table) {\n checkScope(table);\n return createQueryBuilder({\n deleteMany: async (records) => {\n const keys = records.map((record) => getRecordKey(schema, table, record));\n return context.deleteMany(table, keys);\n },\n source: () => context.getAll(table),\n });\n },\n async update(table, key, changes, ttl) {\n const current = await context.get(table, key);\n if (current === undefined) return undefined;\n const merged = { ...current, ...changes } as RecordOf<S, typeof table>;\n verifyKey(schema, table, key, merged, 'update');\n return context.put(table, merged, ttl);\n },\n async upsert(table, key, update, ttl) {\n const value = update(await context.get(table, key));\n verifyKey(schema, table, key, value, 'upsert: update()');\n return context.put(table, value, ttl);\n },\n };\n\n return context;\n}\n\n/* -------------------- buildKeyValueStore -------------------- */\n\n/** Builds a KeyValueVaultStore from a backend and options. */\nexport function buildKeyValueStore<S extends AnySchema>(\n schema: S,\n core: StorageBackend<S>,\n options?: MemoryStoreOptions<S> & {\n onCrossTabMessage?: (notify: (table: keyof S & string) => void) => (() => void) | undefined;\n onMutation?: (table: keyof S & string) => void;\n onTransactions?: (deps: BatchDeps<S>) => void;\n },\n): KeyValueVaultStore<S> {\n const { codecs } = options ?? {};\n\n const observers = createObserverHub<S>((table) => core.getAll(table));\n\n const notifyMutation = (table: keyof S & string): void => {\n observers.notify(table);\n options?.onMutation?.(table);\n };\n\n // Cross-tab notifications must NOT call onMutation (which would re-publish to BroadcastChannel,\n // creating an infinite loop). They only notify local observers.\n const notifyExternal = (table: keyof S & string): void => {\n observers.notify(table);\n };\n\n const pruneAll = core.pruneAllExpired?.bind(core);\n\n const disconnectExternal = options?.onCrossTabMessage?.(notifyExternal) ?? undefined;\n\n const validate = makeValidator(codecs);\n\n options?.onTransactions?.({ notifyMutation, validate });\n\n const disposeController = new AbortController();\n let disposed = false;\n\n const checkDisposed = (): void => {\n if (disposed) throw new VaultDisposedError();\n };\n\n const adapter: KeyValueVaultStore<S> = {\n async clear(table) {\n checkDisposed();\n await core.clear(table);\n notifyMutation(table);\n },\n async count(table) {\n checkDisposed();\n return core.count ? core.count(table) : (await core.getAll(table)).length;\n },\n\n async delete(table, key) {\n checkDisposed();\n\n const deleted = await core.delete(table, key);\n\n if (deleted) notifyMutation(table);\n\n return deleted;\n },\n async deleteMany(table, keys) {\n checkDisposed();\n const deleted = core.deleteMany\n ? await core.deleteMany(table, keys)\n : (await Promise.all(keys.map((key) => core.delete(table, key)))).filter(Boolean).length;\n if (deleted > 0) notifyMutation(table);\n return deleted;\n },\n\n get disposalSignal(): AbortSignal {\n return disposeController.signal;\n },\n\n async dispose() {\n if (disposed) return;\n\n disposed = true;\n disposeController.abort();\n disconnectExternal?.();\n observers.dispose();\n await core.dispose?.();\n },\n\n get disposed(): boolean {\n return disposed;\n },\n\n async get(table, key) {\n checkDisposed();\n\n return core.get(table, key);\n },\n\n async getAll(table) {\n checkDisposed();\n\n return core.getAll(table);\n },\n async getMany(table, keys) {\n checkDisposed();\n return core.getMany ? core.getMany(table, keys) : Promise.all(keys.map((key) => core.get(table, key)));\n },\n async has(table, key) {\n checkDisposed();\n return core.has ? core.has(table, key) : (await core.get(table, key)) !== undefined;\n },\n async isEmpty(table) {\n return (await adapter.count(table)) === 0;\n },\n async keys(table, filter) {\n checkDisposed();\n if (!filter && core.getAllKeys) return core.getAllKeys(table);\n const records = await core.getAll(table);\n const selected = filter ? records.filter(filter) : records;\n const keyField = schema[table].key;\n return selected.map((record) => (record as Record<string, unknown>)[keyField] as KeyOf<S, typeof table>);\n },\n\n observe(table, listener, opts) {\n checkDisposed();\n\n return observers.observe(table, listener, opts);\n },\n\n async pruneExpired() {\n checkDisposed();\n\n if (pruneAll) {\n const result = await pruneAll();\n\n for (const [table, pruned] of Object.entries(result)) {\n if (pruned > 0) notifyMutation(table as keyof S & string);\n }\n\n return result as { [K in keyof S & string]: number };\n }\n\n const tableNames = Object.keys(schema) as Array<keyof S & string>;\n const pairs = await Promise.all(\n tableNames.map(async (name) => {\n const pruned = await core.pruneExpiredInTable(name);\n\n return [name, pruned] as const;\n }),\n );\n\n for (const [table, pruned] of pairs) {\n if (pruned > 0) notifyMutation(table);\n }\n\n return Object.fromEntries(pairs) as { [K in keyof S & string]: number };\n },\n\n async put(table, value, ttl) {\n checkDisposed();\n const canonical = validate(table, value);\n await core.put(table, canonical, resolveTtl(schema, table, ttl));\n notifyMutation(table);\n return canonical;\n },\n\n async putAll(table, values, ttl) {\n checkDisposed();\n\n if (values.length === 0) return;\n\n const toWrite = values.map((v) => validate(table, v));\n\n await core.putAll(table, toWrite, resolveTtl(schema, table, ttl));\n notifyMutation(table);\n },\n query(table) {\n checkDisposed();\n return createQueryBuilder({\n deleteMany: async (records) => {\n const keys = records.map((record) => getRecordKey(schema, table, record));\n return adapter.deleteMany(table, keys);\n },\n source: () => adapter.getAll(table),\n });\n },\n async update(table, key, changes, ttl) {\n const current = await adapter.get(table, key);\n if (current === undefined) return undefined;\n const merged = { ...current, ...changes } as RecordOf<S, typeof table>;\n verifyKey(schema, table, key, merged, 'update');\n return adapter.put(table, merged, ttl);\n },\n async upsert(table, key, apply, ttl) {\n const value = apply(await adapter.get(table, key));\n verifyKey(schema, table, key, value, 'upsert: apply()');\n return adapter.put(table, value, ttl);\n },\n\n async [Symbol.asyncDispose]() {\n await adapter.dispose();\n },\n };\n\n return adapter;\n}\n\n/* -------------------- buildDocumentStore -------------------- */\n\n/** A document store before batch() is attached. */\nexport type DocumentVaultStoreWithoutBatch<S extends AnySchema> = Omit<DocumentVaultStore<S>, 'batch'>;\n\n/** Builds a DocumentVaultStore (without batch) from a backend, codecs, and options. */\nexport function buildDocumentStore<S extends AnySchema>(\n schema: S,\n core: StorageBackend<S>,\n options: DurableStoreOptions<S> & {\n onCrossTabMessage?: (notify: (table: keyof S & string) => void) => (() => void) | undefined;\n onMutation?: (table: keyof S & string) => void;\n onTransactions?: (deps: BatchDeps<S>) => void;\n },\n): DocumentVaultStoreWithoutBatch<S> {\n const store = buildKeyValueStore(schema, core, options);\n\n return Object.assign(store, {\n iterate<K extends keyof S & string>(table: K): AsyncIterable<RecordOf<S, K>> {\n if (store.disposed) throw new VaultDisposedError();\n if (core.iterate) return core.iterate(table);\n return (async function* (): AsyncIterable<RecordOf<S, K>> {\n for (const record of await store.getAll(table)) yield record;\n })();\n },\n });\n}\n\n/** Attaches a batch() implementation to a document store. */\nexport function withBatch<S extends AnySchema>(\n store: DocumentVaultStoreWithoutBatch<S>,\n batch: BatchImpl<S>,\n schema: S,\n): DocumentVaultStore<S> {\n const runBatch: BatchImpl<S> = (tables, fn) => {\n if (store.disposed) return Promise.reject(new VaultDisposedError());\n return batch(tables, fn);\n };\n\n return Object.assign(store, {\n batch: runBatch,\n deleteMany<K extends keyof S & string>(table: K, keys: readonly KeyOf<S, K>[]) {\n return runBatch([table], (tx) => tx.deleteMany(table, keys));\n },\n query<K extends keyof S & string>(table: K) {\n if (store.disposed) throw new VaultDisposedError();\n return createQueryBuilder({\n deleteMany: async (records) => {\n const keys = records.map((record) => getRecordKey(schema, table, record));\n return runBatch([table], (tx) => tx.deleteMany(table, keys));\n },\n source: () => store.getAll(table),\n });\n },\n update<K extends keyof S & string>(table: K, key: KeyOf<S, K>, changes: Partial<RecordOf<S, K>>, ttl?: number) {\n return runBatch([table], (tx) => tx.update(table, key, changes, ttl));\n },\n upsert<K extends keyof S & string>(\n table: K,\n key: KeyOf<S, K>,\n apply: (existing: RecordOf<S, K> | undefined) => RecordOf<S, K>,\n ttl?: number,\n ) {\n return runBatch([table], (tx) => tx.upsert(table, key, apply, ttl));\n },\n }) as DocumentVaultStore<S>;\n}\n\n/* -------------------- Derived convenience helpers -------------------- */\n\n/** Check whether a record exists for the given key. */\nexport async function has<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n key: KeyOf<S, K>,\n): Promise<boolean> {\n return store.has(table, key);\n}\n\n/** Count live records in a table. */\nexport async function count<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n): Promise<number> {\n return store.count(table);\n}\n\n/** Check whether a table has no live records. */\nexport async function isEmpty<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n): Promise<boolean> {\n return store.isEmpty(table);\n}\n\n/** Fetch multiple records by key. Preserves key order; missing keys yield `undefined`. */\nexport async function getMany<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n keys: readonly KeyOf<S, K>[],\n): Promise<Array<RecordOf<S, K> | undefined>> {\n return store.getMany(table, keys);\n}\n\n/** Fetch all live primary keys for a table. */\nexport async function keys<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n filter?: (record: RecordOf<S, K>) => boolean,\n): Promise<KeyOf<S, K>[]> {\n return store.keys(table, filter);\n}\n\n/** Delete multiple records by key. Returns the count of records that were actually deleted. */\nexport async function deleteMany<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n keys: readonly KeyOf<S, K>[],\n): Promise<number> {\n return store.deleteMany(table, keys);\n}\n\n/** Partially update an existing record. Returns `undefined` when the key does not exist. */\nexport async function update<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n key: KeyOf<S, K>,\n changes: Partial<RecordOf<S, K>>,\n ttl?: number,\n): Promise<RecordOf<S, K> | undefined> {\n return store.update(table, key, changes, ttl);\n}\n\n/** Read-modify-write: the callback receives the current record (or `undefined`) and returns the value to store. */\nexport async function upsert<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n key: KeyOf<S, K>,\n apply: (existing: RecordOf<S, K> | undefined) => RecordOf<S, K>,\n ttl?: number,\n): Promise<RecordOf<S, K>> {\n return store.upsert(table, key, apply, ttl);\n}\n","/// <reference lib=\"dom\" />\n\nimport { VaultError } from './errors';\nimport type { QueryBuilder } from './query';\nimport { assertPositiveFinite } from './ttl';\n\n/** Portable primary-key values. Vault preserves their type and encodes them distinctly at rest. */\nexport type VaultKey = number | string;\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> = {\n defaultTtl?: number;\n /** IndexedDB creates these as `value.<field>` indexes; other stores filter in memory. */\n indexes?: readonly (keyof T & string)[];\n key: Key;\n};\n\nexport type AnySchema = Record<string, { defaultTtl?: number; indexes?: readonly string[]; key: string }>;\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\n/** A codec validates and decodes persisted values crossing a trust boundary. */\nexport type RecordCodec<T> = {\n decode(value: unknown): T;\n encode(value: T): unknown;\n};\n\nexport type RecordParser<T> = {\n parse(value: unknown): T;\n};\n\nexport type CodecInput<T> = RecordCodec<T> | RecordParser<T>;\n\nexport type TableCodecs<S extends AnySchema> = {\n [K in keyof S]: CodecInput<RecordOf<S, K>>;\n};\n\n/** A validator-only codec: encodes values as-is, validates on decode. */\nexport function validatorCodec<T>(validator: RecordParser<T>): RecordCodec<T> {\n return {\n decode: (value) => validator.parse(value),\n encode: (value) => value,\n };\n}\n\nexport type Observer<T> = (records: T[]) => void;\nexport type Unsubscribe = () => void;\n\n/** Shared factory options for stores that do not require durable codecs. */\nexport type MemoryStoreOptions<S extends AnySchema> = {\n schema: S;\n /** Optional per-table codecs. Memory values never cross a trust boundary, so codecs may be omitted. */\n codecs?: TableCodecs<S>;\n};\n\n/** Shared factory options for durable stores whose values cross a trust boundary. */\nexport type DurableStoreOptions<S extends AnySchema> = {\n schema: S;\n /** Required per-table codecs. Persisted values are decoded through these before entering typed code. */\n codecs: TableCodecs<S>;\n};\n\nexport type VaultConveniences<S extends AnySchema, K extends keyof S & string = keyof S & string> = {\n count<T extends K>(table: T): Promise<number>;\n deleteMany<T extends K>(table: T, keys: readonly KeyOf<S, T>[]): Promise<number>;\n getMany<T extends K>(table: T, keys: readonly KeyOf<S, T>[]): Promise<Array<RecordOf<S, T> | undefined>>;\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 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?: number,\n ): Promise<RecordOf<S, T> | undefined>;\n upsert<T extends K>(\n table: T,\n key: KeyOf<S, T>,\n update: (existing: RecordOf<S, T> | undefined) => RecordOf<S, T>,\n ttl?: number,\n ): Promise<RecordOf<S, T>>;\n};\n\n/** Methods available within an IndexedDB or SQLite transaction. */\nexport type TransactionContext<S extends AnySchema, K extends keyof S & string = keyof S & string> = VaultConveniences<\n S,\n K\n> & {\n clear<T extends K>(table: T): Promise<void>;\n delete<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;\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 iterate<T extends K>(table: T): AsyncIterable<RecordOf<S, T>>;\n put<T extends K>(table: T, value: RecordOf<S, T>, ttl?: number): Promise<RecordOf<S, T>>;\n putAll<T extends K>(table: T, values: readonly RecordOf<S, T>[], ttl?: number): Promise<void>;\n};\n\n/** Key-value store for Memory and Web Storage: core CRUD, observation, TTL, and pruning. */\nexport interface KeyValueVaultStore<S extends AnySchema> extends VaultConveniences<S> {\n clear<K extends keyof S & string>(table: K): Promise<void>;\n delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean>;\n readonly disposalSignal: AbortSignal;\n dispose(): Promise<void>;\n readonly disposed: boolean;\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 observe<K extends keyof S & string>(\n table: K,\n listener: Observer<RecordOf<S, K>>,\n options?: { immediate?: boolean; signal?: AbortSignal },\n ): Unsubscribe;\n pruneExpired(): Promise<Record<keyof S & string, number>>;\n put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: number): Promise<RecordOf<S, K>>;\n putAll<K extends keyof S & string>(table: K, values: readonly RecordOf<S, K>[], ttl?: number): Promise<void>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\n/** Document store for IndexedDB and SQLite: adds atomic transactions and lazy iteration. */\nexport interface DocumentVaultStore<S extends AnySchema> extends KeyValueVaultStore<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\ntype VaultKeyField<T extends object> = {\n [K in keyof T & string]: T[K] extends VaultKey ? K : never;\n}[keyof T & string];\n\n/** Define a typed table whose primary-key field holds a portable Vault key. */\nexport function table<T extends object, Key extends VaultKeyField<T> = VaultKeyField<T>>(\n key: Key,\n options: { defaultTtl?: number; indexes?: readonly (keyof T & string)[] } = {},\n): SchemaEntry<T, Key> {\n const { defaultTtl, indexes } = options;\n\n if (defaultTtl !== undefined) assertPositiveFinite(defaultTtl, 'table: defaultTtl');\n\n if (indexes) {\n const seen = new Set<string>();\n\n for (const field of indexes) {\n if (seen.has(field)) {\n throw new VaultError(`table: index \"${field}\" is already registered`);\n }\n\n seen.add(field);\n }\n }\n\n return { defaultTtl, indexes, key };\n}\n"],"mappings":"oFAIA,IAAa,EAAb,cAAgC,KAAM,CACpC,OAA0B,UAAoB,aAE9C,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAQ,WAAiC,UAE9C,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,EAAb,cAAwC,CAAW,CACjD,OAAmC,UAAY,qBAE/C,YAAY,EAAU,sBAAuB,EAAqB,CAChE,MAAM,EAAS,CAAI,CACrB,CACF,EAGa,EAAb,cAAqC,CAAW,CAC9C,OAAmC,UAAY,iBACjD,EAGa,EAAb,cAAqC,CAAW,CAC9C,OAAmC,UAAY,iBACjD,EAGa,EAAb,cAAyC,CAAW,CAClD,OAAmC,UAAY,qBACjD,EClCa,EAAM,CACjB,KAAO,GAAc,EAAqB,EAAI,MAAY,UAAU,EACpE,MAAQ,GAAc,EAAqB,EAAI,KAAW,WAAW,EACrE,QAAU,GAAc,EAAqB,EAAI,IAAQ,aAAa,EACtE,GAAK,GAAc,EAAqB,EAAG,QAAQ,EACnD,QAAU,GAAc,EAAqB,EAAI,IAAM,aAAa,CACtE,EAKA,SAAgB,EAAU,EAAwC,CAChE,OAAO,IAAc,IAAA,IAAa,KAAK,IAAI,GAAK,CAClD,CAGA,SAAgB,EAAqB,EAAe,EAAwB,CAC1E,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,GAAS,EACtC,MAAM,IAAI,EAAW,GAAG,EAAO,+CAA+C,OAAO,CAAK,GAAG,EAG/F,OAAO,CACT,CC2eA,eAAsB,EACpB,EACA,EACA,EACkB,CAClB,OAAO,EAAM,IAAI,EAAO,CAAG,CAC7B,CAGA,eAAsB,EACpB,EACA,EACiB,CACjB,OAAO,EAAM,MAAM,CAAK,CAC1B,CAGA,eAAsB,EACpB,EACA,EACkB,CAClB,OAAO,EAAM,QAAQ,CAAK,CAC5B,CAGA,eAAsB,EACpB,EACA,EACA,EAC4C,CAC5C,OAAO,EAAM,QAAQ,EAAO,CAAI,CAClC,CAGA,eAAsB,EACpB,EACA,EACA,EACwB,CACxB,OAAO,EAAM,KAAK,EAAO,CAAM,CACjC,CAGA,eAAsB,EACpB,EACA,EACA,EACiB,CACjB,OAAO,EAAM,WAAW,EAAO,CAAI,CACrC,CAGA,eAAsB,EACpB,EACA,EACA,EACA,EACA,EACqC,CACrC,OAAO,EAAM,OAAO,EAAO,EAAK,EAAS,CAAG,CAC9C,CAGA,eAAsB,EACpB,EACA,EACA,EACA,EACA,EACyB,CACzB,OAAO,EAAM,OAAO,EAAO,EAAK,EAAO,CAAG,CAC5C,CChiBA,SAAgB,EAAkB,EAA4C,CAC5E,MAAO,CACL,OAAS,GAAU,EAAU,MAAM,CAAK,EACxC,OAAS,GAAU,CACrB,CACF,CAyFA,SAAgB,EACd,EACA,EAA4E,CAAC,EACxD,CACrB,GAAM,CAAE,aAAY,WAAY,EAIhC,GAFI,IAAe,IAAA,IAAW,EAAqB,EAAY,mBAAmB,EAE9E,EAAS,CACX,IAAM,EAAO,IAAI,IAEjB,IAAK,IAAM,KAAS,EAAS,CAC3B,GAAI,EAAK,IAAI,CAAK,EAChB,MAAM,IAAI,EAAW,iBAAiB,EAAM,wBAAwB,EAGtE,EAAK,IAAI,CAAK,CAChB,CACF,CAEA,MAAO,CAAE,aAAY,UAAS,KAAI,CACpC"}
package/dist/vault.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},t=class extends e{constructor(e=`adapter is disposed`,t){super(e,t)}},n=class extends e{},r=class extends e{},i=class extends e{},a={days:e=>s(e*864e5,`ttl.days`),hours:e=>s(e*36e5,`ttl.hours`),minutes:e=>s(e*6e4,`ttl.minutes`),ms:e=>s(e,`ttl.ms`),seconds:e=>s(e*1e3,`ttl.seconds`)};function o(e){return e!==void 0&&Date.now()>=e}function s(t,n){if(!Number.isFinite(t)||t<=0)throw new e(`${n} expected a finite positive number, received ${String(t)}`);return t}function c(t,n={}){let{defaultTtl:r,indexes:i}=n;if(r!==void 0&&s(r,`table: defaultTtl`),i){let t=new Set;for(let n of i){if(t.has(n))throw new e(`table: index "${n}" is already registered`);t.add(n)}}return{defaultTtl:r,indexes:i,key:t}}export{t as VaultDisposedError,e as VaultError,i as VaultMigrationError,r as VaultQuotaError,n as VaultScopeError,o as isExpired,c as table,a as ttl};
1
+ var e=class extends Error{static errorName=`VaultError`;constructor(e,t){super(e,t),this.name=new.target.errorName,Object.setPrototypeOf(this,new.target.prototype)}},t=class extends e{static errorName=`VaultDisposedError`;constructor(e=`adapter is disposed`,t){super(e,t)}},n=class extends e{static errorName=`VaultScopeError`},r=class extends e{static errorName=`VaultQuotaError`},i=class extends e{static errorName=`VaultMigrationError`},a={days:e=>s(e*864e5,`ttl.days`),hours:e=>s(e*36e5,`ttl.hours`),minutes:e=>s(e*6e4,`ttl.minutes`),ms:e=>s(e,`ttl.ms`),seconds:e=>s(e*1e3,`ttl.seconds`)};function o(e){return e!==void 0&&Date.now()>=e}function s(t,n){if(!Number.isFinite(t)||t<=0)throw new e(`${n} expected a finite positive number, received ${String(t)}`);return t}async function c(e,t,n){return e.has(t,n)}async function l(e,t){return e.count(t)}async function u(e,t){return e.isEmpty(t)}async function d(e,t,n){return e.getMany(t,n)}async function f(e,t,n){return e.keys(t,n)}async function p(e,t,n){return e.deleteMany(t,n)}async function m(e,t,n,r,i){return e.update(t,n,r,i)}async function h(e,t,n,r,i){return e.upsert(t,n,r,i)}function g(e){return{decode:t=>e.parse(t),encode:e=>e}}function _(t,n={}){let{defaultTtl:r,indexes:i}=n;if(r!==void 0&&s(r,`table: defaultTtl`),i){let t=new Set;for(let n of i){if(t.has(n))throw new e(`table: index "${n}" is already registered`);t.add(n)}}return{defaultTtl:r,indexes:i,key:t}}export{t as VaultDisposedError,e as VaultError,i as VaultMigrationError,r as VaultQuotaError,n as VaultScopeError,l as count,p as deleteMany,d as getMany,c as has,u as isEmpty,o as isExpired,f as keys,_ as table,a as ttl,m as update,h as upsert,g as validatorCodec};
2
2
  //# sourceMappingURL=vault.js.map
package/dist/vault.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vault.js","names":[],"sources":["../src/errors.ts","../src/ttl.ts","../src/types.ts"],"sourcesContent":["/**\n * Base class for all vault errors. Catch with `instanceof VaultError` to\n * handle any vault-originated error regardless of its specific subtype.\n */\nexport class VaultError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n // Ensures `instanceof` works correctly when transpiled to ES5.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when an operation is attempted on a disposed adapter or observer hub. */\nexport class VaultDisposedError extends VaultError {\n constructor(message = 'adapter is disposed', opts?: ErrorOptions) {\n super(message, opts);\n }\n}\n\n/** Thrown when a `batch()` callback accesses a table not declared in the scope. */\nexport class VaultScopeError extends VaultError {}\n\n/** Thrown when a WebStorage write exceeds the storage quota. */\nexport class VaultQuotaError extends VaultError {}\n\n/** Thrown when an IndexedDB `onupgradeneeded` migration callback throws. */\nexport class VaultMigrationError extends VaultError {}\n","import { VaultError } from './errors';\n\n/** Duration helpers that produce finite, positive millisecond values. */\nexport const ttl = {\n days: (n: number) => assertPositiveFinite(n * 86_400_000, 'ttl.days'),\n hours: (n: number) => assertPositiveFinite(n * 3_600_000, 'ttl.hours'),\n minutes: (n: number) => assertPositiveFinite(n * 60_000, 'ttl.minutes'),\n ms: (n: number) => assertPositiveFinite(n, 'ttl.ms'),\n seconds: (n: number) => assertPositiveFinite(n * 1000, 'ttl.seconds'),\n} as const;\n\n/** Fixed storage envelope shared by every adapter, so data and indexes stay portable. */\nexport type StoredRecord<T> = { expiresAt?: number; value: T };\n\nexport function isExpired(expiresAt: number | undefined): boolean {\n return expiresAt !== undefined && Date.now() >= expiresAt;\n}\n\n/** Throws when `ttlMs` is not a finite, positive number. Returns it unchanged otherwise. */\nexport function assertPositiveFinite(ttlMs: number, source: string): number {\n if (!Number.isFinite(ttlMs) || ttlMs <= 0) {\n throw new VaultError(`${source} expected a finite positive number, received ${String(ttlMs)}`);\n }\n\n return ttlMs;\n}\n\nexport function parseStored<T>(raw: unknown): StoredRecord<T> | undefined {\n if (typeof raw !== 'object' || raw === null || !('value' in raw)) return undefined;\n\n const record = raw as { expiresAt?: unknown; value: unknown };\n\n if (record.expiresAt !== undefined && (typeof record.expiresAt !== 'number' || !Number.isFinite(record.expiresAt))) {\n return undefined;\n }\n\n return record as StoredRecord<T>;\n}\n","/// <reference lib=\"dom\" />\n\nimport { VaultError } from './errors';\nimport type { QueryBuilder } from './query';\nimport { assertPositiveFinite } from './ttl';\n\n/** Portable primary-key values. Vault preserves their type and encodes them distinctly at rest. */\nexport type VaultKey = number | string;\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> = {\n defaultTtl?: number;\n /** IndexedDB creates these as `value.<field>` indexes; other stores filter in memory. */\n indexes?: readonly (keyof T & string)[];\n key: Key;\n};\n\nexport type AnySchema = Record<string, { defaultTtl?: number; indexes?: readonly string[]; key: string }>;\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 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 schema: S;\n validators?: TableValidators<S>;\n};\n\n/** Methods available within an IndexedDB or SQLite 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 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 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?: number): Promise<void>;\n putAll<T extends K>(table: T, values: RecordOf<S, T>[], ttl?: number): 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?: number,\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?: number,\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 readonly disposalSignal: AbortSignal;\n dispose(): Promise<void>;\n readonly disposed: boolean;\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 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 observe<K extends keyof S & string>(\n table: K,\n listener: Observer<RecordOf<S, K>>,\n options?: { immediate?: boolean; signal?: AbortSignal },\n ): Unsubscribe;\n pruneExpired(): Promise<Record<keyof S & string, number>>;\n put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: number): Promise<void>;\n putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: number): 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?: number,\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?: number,\n ): Promise<RecordOf<S, K>>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\n/** Atomic, scoped transactions and lazy iteration supplied by storage engines that support them. */\nexport interface TransactionalVaultStore<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\n/** Define a typed table whose primary-key field holds a portable Vault key. */\nexport function table<T extends object, Key extends keyof T & string = keyof T & string>(\n key: Key,\n options: { defaultTtl?: number; indexes?: readonly (keyof T & string)[] } = {},\n): SchemaEntry<T, Key> {\n const { defaultTtl, indexes } = options;\n\n if (defaultTtl !== undefined) assertPositiveFinite(defaultTtl, 'table: defaultTtl');\n\n if (indexes) {\n const seen = new Set<string>();\n\n for (const field of indexes) {\n if (seen.has(field)) {\n throw new VaultError(`table: index \"${field}\" is already registered`);\n }\n\n seen.add(field);\n }\n }\n\n return { defaultTtl, indexes, key } as unknown as SchemaEntry<T, Key>;\n}\n"],"mappings":"AAIA,IAAa,EAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KAEvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,EAAb,cAAwC,CAAW,CACjD,YAAY,EAAU,sBAAuB,EAAqB,CAChE,MAAM,EAAS,CAAI,CACrB,CACF,EAGa,EAAb,cAAqC,CAAW,CAAC,EAGpC,EAAb,cAAqC,CAAW,CAAC,EAGpC,EAAb,cAAyC,CAAW,CAAC,ECxBxC,EAAM,CACjB,KAAO,GAAc,EAAqB,EAAI,MAAY,UAAU,EACpE,MAAQ,GAAc,EAAqB,EAAI,KAAW,WAAW,EACrE,QAAU,GAAc,EAAqB,EAAI,IAAQ,aAAa,EACtE,GAAK,GAAc,EAAqB,EAAG,QAAQ,EACnD,QAAU,GAAc,EAAqB,EAAI,IAAM,aAAa,CACtE,EAKA,SAAgB,EAAU,EAAwC,CAChE,OAAO,IAAc,IAAA,IAAa,KAAK,IAAI,GAAK,CAClD,CAGA,SAAgB,EAAqB,EAAe,EAAwB,CAC1E,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,GAAS,EACtC,MAAM,IAAI,EAAW,GAAG,EAAO,+CAA+C,OAAO,CAAK,GAAG,EAG/F,OAAO,CACT,CCgGA,SAAgB,EACd,EACA,EAA4E,CAAC,EACxD,CACrB,GAAM,CAAE,aAAY,WAAY,EAIhC,GAFI,IAAe,IAAA,IAAW,EAAqB,EAAY,mBAAmB,EAE9E,EAAS,CACX,IAAM,EAAO,IAAI,IAEjB,IAAK,IAAM,KAAS,EAAS,CAC3B,GAAI,EAAK,IAAI,CAAK,EAChB,MAAM,IAAI,EAAW,iBAAiB,EAAM,wBAAwB,EAGtE,EAAK,IAAI,CAAK,CAChB,CACF,CAEA,MAAO,CAAE,aAAY,UAAS,KAAI,CACpC"}
1
+ {"version":3,"file":"vault.js","names":[],"sources":["../src/errors.ts","../src/ttl.ts","../src/adapter-core.ts","../src/types.ts"],"sourcesContent":["/**\n * Base class for all vault errors. Catch with `instanceof VaultError` to\n * handle any vault-originated error regardless of its specific subtype.\n */\nexport class VaultError extends Error {\n protected static readonly errorName: string = 'VaultError';\n\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = (new.target as typeof VaultError).errorName;\n // Ensures `instanceof` works correctly when transpiled to ES5.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when an operation is attempted on a disposed adapter or observer hub. */\nexport class VaultDisposedError extends VaultError {\n protected static override readonly errorName = 'VaultDisposedError';\n\n constructor(message = 'adapter is disposed', opts?: ErrorOptions) {\n super(message, opts);\n }\n}\n\n/** Thrown when a `batch()` callback accesses a table not declared in the scope. */\nexport class VaultScopeError extends VaultError {\n protected static override readonly errorName = 'VaultScopeError';\n}\n\n/** Thrown when a WebStorage write exceeds the storage quota. */\nexport class VaultQuotaError extends VaultError {\n protected static override readonly errorName = 'VaultQuotaError';\n}\n\n/** Thrown when an IndexedDB `onupgradeneeded` migration callback throws. */\nexport class VaultMigrationError extends VaultError {\n protected static override readonly errorName = 'VaultMigrationError';\n}\n","import { VaultError } from './errors';\n\n/** Duration helpers that produce finite, positive millisecond values. */\nexport const ttl = {\n days: (n: number) => assertPositiveFinite(n * 86_400_000, 'ttl.days'),\n hours: (n: number) => assertPositiveFinite(n * 3_600_000, 'ttl.hours'),\n minutes: (n: number) => assertPositiveFinite(n * 60_000, 'ttl.minutes'),\n ms: (n: number) => assertPositiveFinite(n, 'ttl.ms'),\n seconds: (n: number) => assertPositiveFinite(n * 1000, 'ttl.seconds'),\n} as const;\n\n/** Fixed storage envelope shared by every adapter, so data and indexes stay portable. */\nexport type StoredRecord<T> = { expiresAt?: number; value: T };\n\nexport function isExpired(expiresAt: number | undefined): boolean {\n return expiresAt !== undefined && Date.now() >= expiresAt;\n}\n\n/** Throws when `ttlMs` is not a finite, positive number. Returns it unchanged otherwise. */\nexport function assertPositiveFinite(ttlMs: number, source: string): number {\n if (!Number.isFinite(ttlMs) || ttlMs <= 0) {\n throw new VaultError(`${source} expected a finite positive number, received ${String(ttlMs)}`);\n }\n\n return ttlMs;\n}\n\nexport function parseStored<T>(raw: unknown): StoredRecord<T> | undefined {\n if (typeof raw !== 'object' || raw === null || !('value' in raw)) return undefined;\n\n const record = raw as { expiresAt?: unknown; value: unknown };\n\n if (record.expiresAt !== undefined && (typeof record.expiresAt !== 'number' || !Number.isFinite(record.expiresAt))) {\n return undefined;\n }\n\n return record as StoredRecord<T>;\n}\n","import { validateRecord } from './codec';\nimport { VaultDisposedError, VaultError, VaultScopeError } from './errors';\nimport { createObserverHub, getRecordKey } from './internal';\nimport { createQueryBuilder } from './query';\nimport { assertPositiveFinite } from './ttl';\nimport type {\n AnySchema,\n DocumentVaultStore,\n DurableStoreOptions,\n KeyOf,\n KeyValueVaultStore,\n MemoryStoreOptions,\n RecordOf,\n TableCodecs,\n TransactionContext,\n} from './types';\n\n/* -------------------- Internal backend protocol -------------------- */\n\n/** @internal Full backend protocol implemented by each adapter. */\nexport type StorageBackend<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: readonly KeyOf<S, T>[]): Promise<number>;\n dispose?(): Promise<void>;\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 getAllKeys?<T extends K>(table: T): Promise<KeyOf<S, T>[]>;\n getMany?<T extends K>(table: T, keys: readonly KeyOf<S, T>[]): Promise<Array<RecordOf<S, T> | undefined>>;\n has?<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;\n /**\n * Optional: lazy iteration over live records. Document stores implement this natively\n * (IDB cursor, SQLite keyset pagination). Key-value stores fall back to getAll().\n */\n iterate?<T extends K>(table: T): AsyncIterable<RecordOf<S, T>>;\n /**\n * Optional: prune all expired records across all tables in a single atomic operation.\n * When present, `pruneExpired()` delegates here instead of calling `pruneExpiredInTable` N times.\n */\n pruneAllExpired?(): Promise<Record<string, number>>;\n pruneExpiredInTable<T extends K>(table: T): Promise<number>;\n put<T extends K>(table: T, value: RecordOf<S, T>, ttl?: number): Promise<void>;\n putAll<T extends K>(table: T, values: readonly RecordOf<S, T>[], ttl?: number): Promise<void>;\n};\n\n/** @internal */\nexport type BatchDeps<S extends AnySchema> = {\n notifyMutation: (table: keyof S & string) => void;\n validate: <K extends keyof S & string>(table: K, value: RecordOf<S, K>) => RecordOf<S, K>;\n};\n\n/** @internal */\nexport type BatchImpl<S extends AnySchema> = <K extends keyof S & string, R>(\n tables: readonly K[],\n fn: (tx: TransactionContext<S, K>) => Promise<R>,\n) => Promise<R>;\n\n/* -------------------- Helpers -------------------- */\n\nexport function assertBatchTables(tables: readonly string[]): void {\n if (tables.length === 0) throw new VaultError('batch: declare at least one table');\n}\n\nfunction resolveTtl<S extends AnySchema, K extends keyof S & string>(\n schema: S,\n table: K,\n ttl?: number,\n): number | undefined {\n if (ttl !== undefined) assertPositiveFinite(ttl, 'put/putAll');\n\n return ttl ?? schema[table].defaultTtl;\n}\n\nfunction verifyKey<S extends AnySchema, K extends keyof S & string>(\n schema: S,\n table: K,\n expected: KeyOf<S, K>,\n value: RecordOf<S, K>,\n op: string,\n): void {\n const actual = getRecordKey(schema, table, value);\n\n if (actual !== expected) {\n throw new VaultError(\n `${op}: key field \"${schema[table].key}\" must be \"${String(expected)}\" but got \"${String(actual)}\" in table \"${table}\"`,\n );\n }\n}\n\n/* -------------------- Codec helpers -------------------- */\n\nexport function makeValidator<S extends AnySchema>(\n codecs: TableCodecs<S> | undefined,\n): <K extends keyof S & string>(table: K, value: RecordOf<S, K>) => RecordOf<S, K> {\n return <K extends keyof S & string>(table: K, value: RecordOf<S, K>): RecordOf<S, K> => {\n const codec = codecs?.[table];\n\n if (!codec) return value;\n\n try {\n return validateRecord(codec, value);\n } catch (err) {\n throw new VaultError(`validation failed for table \"${table}\"`, { cause: err });\n }\n };\n}\n\n/* -------------------- buildTxContext -------------------- */\n\nexport function buildTxContext<S extends AnySchema, K extends keyof S & string>(\n schema: S,\n core: StorageBackend<S, K>,\n onMutate: (table: K) => void,\n validate?: <T extends K>(table: T, value: RecordOf<S, T>) => RecordOf<S, T>,\n scope?: ReadonlySet<string>,\n isActive: () => boolean = () => true,\n): TransactionContext<S, K> {\n const applyValidation = validate ?? ((_: K, v: RecordOf<S, K>) => v);\n\n const checkScope = (table: K): void => {\n if (!isActive()) throw new VaultScopeError('transaction context is no longer active');\n if (scope && !scope.has(table)) throw new VaultScopeError(`table \"${table}\" is not part of this batch scope`);\n };\n\n const context: TransactionContext<S, K> = {\n async clear(table) {\n checkScope(table);\n await core.clear(table);\n onMutate(table);\n },\n async count(table) {\n checkScope(table);\n return core.count ? core.count(table) : (await core.getAll(table)).length;\n },\n async delete(table, key) {\n checkScope(table);\n\n const deleted = await core.delete(table, key);\n\n if (deleted) onMutate(table);\n\n return deleted;\n },\n async deleteMany(table, keys) {\n checkScope(table);\n if (!core.deleteMany) {\n const results = await Promise.all(keys.map((key) => core.delete(table, key)));\n const deleted = results.filter(Boolean).length;\n if (deleted > 0) onMutate(table);\n return deleted;\n }\n const deleted = await core.deleteMany(table, keys);\n if (deleted > 0) onMutate(table);\n return deleted;\n },\n async get(table, key) {\n checkScope(table);\n\n return core.get(table, key);\n },\n async getAll(table) {\n checkScope(table);\n\n return core.getAll(table);\n },\n async getMany(table, keys) {\n checkScope(table);\n return core.getMany ? core.getMany(table, keys) : Promise.all(keys.map((key) => core.get(table, key)));\n },\n async has(table, key) {\n checkScope(table);\n return core.has ? core.has(table, key) : (await core.get(table, key)) !== undefined;\n },\n async isEmpty(table) {\n return (await context.count(table)) === 0;\n },\n iterate(table) {\n checkScope(table);\n\n if (core.iterate) return core.iterate(table);\n\n // Fallback: iterate over getAll() materialized records.\n return (async function* (): AsyncIterable<RecordOf<S, typeof table>> {\n const records = await core.getAll(table);\n\n for (const record of records) yield record;\n })();\n },\n async keys(table, filter) {\n checkScope(table);\n if (!filter && core.getAllKeys) return core.getAllKeys(table);\n const records = await core.getAll(table);\n const selected = filter ? records.filter(filter) : records;\n const keyField = schema[table].key;\n return selected.map((record) => (record as Record<string, unknown>)[keyField] as KeyOf<S, typeof table>);\n },\n async put(table, value, ttl) {\n checkScope(table);\n const canonical = applyValidation(table, value);\n await core.put(table, canonical, resolveTtl(schema, table, ttl));\n onMutate(table);\n return canonical;\n },\n async putAll(table, values, ttl) {\n checkScope(table);\n\n if (values.length === 0) return;\n\n const toWrite = values.map((v) => applyValidation(table, v));\n\n await core.putAll(table, toWrite, resolveTtl(schema, table, ttl));\n onMutate(table);\n },\n query(table) {\n checkScope(table);\n return createQueryBuilder({\n deleteMany: async (records) => {\n const keys = records.map((record) => getRecordKey(schema, table, record));\n return context.deleteMany(table, keys);\n },\n source: () => context.getAll(table),\n });\n },\n async update(table, key, changes, ttl) {\n const current = await context.get(table, key);\n if (current === undefined) return undefined;\n const merged = { ...current, ...changes } as RecordOf<S, typeof table>;\n verifyKey(schema, table, key, merged, 'update');\n return context.put(table, merged, ttl);\n },\n async upsert(table, key, update, ttl) {\n const value = update(await context.get(table, key));\n verifyKey(schema, table, key, value, 'upsert: update()');\n return context.put(table, value, ttl);\n },\n };\n\n return context;\n}\n\n/* -------------------- buildKeyValueStore -------------------- */\n\n/** Builds a KeyValueVaultStore from a backend and options. */\nexport function buildKeyValueStore<S extends AnySchema>(\n schema: S,\n core: StorageBackend<S>,\n options?: MemoryStoreOptions<S> & {\n onCrossTabMessage?: (notify: (table: keyof S & string) => void) => (() => void) | undefined;\n onMutation?: (table: keyof S & string) => void;\n onTransactions?: (deps: BatchDeps<S>) => void;\n },\n): KeyValueVaultStore<S> {\n const { codecs } = options ?? {};\n\n const observers = createObserverHub<S>((table) => core.getAll(table));\n\n const notifyMutation = (table: keyof S & string): void => {\n observers.notify(table);\n options?.onMutation?.(table);\n };\n\n // Cross-tab notifications must NOT call onMutation (which would re-publish to BroadcastChannel,\n // creating an infinite loop). They only notify local observers.\n const notifyExternal = (table: keyof S & string): void => {\n observers.notify(table);\n };\n\n const pruneAll = core.pruneAllExpired?.bind(core);\n\n const disconnectExternal = options?.onCrossTabMessage?.(notifyExternal) ?? undefined;\n\n const validate = makeValidator(codecs);\n\n options?.onTransactions?.({ notifyMutation, validate });\n\n const disposeController = new AbortController();\n let disposed = false;\n\n const checkDisposed = (): void => {\n if (disposed) throw new VaultDisposedError();\n };\n\n const adapter: KeyValueVaultStore<S> = {\n async clear(table) {\n checkDisposed();\n await core.clear(table);\n notifyMutation(table);\n },\n async count(table) {\n checkDisposed();\n return core.count ? core.count(table) : (await core.getAll(table)).length;\n },\n\n async delete(table, key) {\n checkDisposed();\n\n const deleted = await core.delete(table, key);\n\n if (deleted) notifyMutation(table);\n\n return deleted;\n },\n async deleteMany(table, keys) {\n checkDisposed();\n const deleted = core.deleteMany\n ? await core.deleteMany(table, keys)\n : (await Promise.all(keys.map((key) => core.delete(table, key)))).filter(Boolean).length;\n if (deleted > 0) notifyMutation(table);\n return deleted;\n },\n\n get disposalSignal(): AbortSignal {\n return disposeController.signal;\n },\n\n async dispose() {\n if (disposed) return;\n\n disposed = true;\n disposeController.abort();\n disconnectExternal?.();\n observers.dispose();\n await core.dispose?.();\n },\n\n get disposed(): boolean {\n return disposed;\n },\n\n async get(table, key) {\n checkDisposed();\n\n return core.get(table, key);\n },\n\n async getAll(table) {\n checkDisposed();\n\n return core.getAll(table);\n },\n async getMany(table, keys) {\n checkDisposed();\n return core.getMany ? core.getMany(table, keys) : Promise.all(keys.map((key) => core.get(table, key)));\n },\n async has(table, key) {\n checkDisposed();\n return core.has ? core.has(table, key) : (await core.get(table, key)) !== undefined;\n },\n async isEmpty(table) {\n return (await adapter.count(table)) === 0;\n },\n async keys(table, filter) {\n checkDisposed();\n if (!filter && core.getAllKeys) return core.getAllKeys(table);\n const records = await core.getAll(table);\n const selected = filter ? records.filter(filter) : records;\n const keyField = schema[table].key;\n return selected.map((record) => (record as Record<string, unknown>)[keyField] as KeyOf<S, typeof table>);\n },\n\n observe(table, listener, opts) {\n checkDisposed();\n\n return observers.observe(table, listener, opts);\n },\n\n async pruneExpired() {\n checkDisposed();\n\n if (pruneAll) {\n const result = await pruneAll();\n\n for (const [table, pruned] of Object.entries(result)) {\n if (pruned > 0) notifyMutation(table as keyof S & string);\n }\n\n return result as { [K in keyof S & string]: number };\n }\n\n const tableNames = Object.keys(schema) as Array<keyof S & string>;\n const pairs = await Promise.all(\n tableNames.map(async (name) => {\n const pruned = await core.pruneExpiredInTable(name);\n\n return [name, pruned] as const;\n }),\n );\n\n for (const [table, pruned] of pairs) {\n if (pruned > 0) notifyMutation(table);\n }\n\n return Object.fromEntries(pairs) as { [K in keyof S & string]: number };\n },\n\n async put(table, value, ttl) {\n checkDisposed();\n const canonical = validate(table, value);\n await core.put(table, canonical, resolveTtl(schema, table, ttl));\n notifyMutation(table);\n return canonical;\n },\n\n async putAll(table, values, ttl) {\n checkDisposed();\n\n if (values.length === 0) return;\n\n const toWrite = values.map((v) => validate(table, v));\n\n await core.putAll(table, toWrite, resolveTtl(schema, table, ttl));\n notifyMutation(table);\n },\n query(table) {\n checkDisposed();\n return createQueryBuilder({\n deleteMany: async (records) => {\n const keys = records.map((record) => getRecordKey(schema, table, record));\n return adapter.deleteMany(table, keys);\n },\n source: () => adapter.getAll(table),\n });\n },\n async update(table, key, changes, ttl) {\n const current = await adapter.get(table, key);\n if (current === undefined) return undefined;\n const merged = { ...current, ...changes } as RecordOf<S, typeof table>;\n verifyKey(schema, table, key, merged, 'update');\n return adapter.put(table, merged, ttl);\n },\n async upsert(table, key, apply, ttl) {\n const value = apply(await adapter.get(table, key));\n verifyKey(schema, table, key, value, 'upsert: apply()');\n return adapter.put(table, value, ttl);\n },\n\n async [Symbol.asyncDispose]() {\n await adapter.dispose();\n },\n };\n\n return adapter;\n}\n\n/* -------------------- buildDocumentStore -------------------- */\n\n/** A document store before batch() is attached. */\nexport type DocumentVaultStoreWithoutBatch<S extends AnySchema> = Omit<DocumentVaultStore<S>, 'batch'>;\n\n/** Builds a DocumentVaultStore (without batch) from a backend, codecs, and options. */\nexport function buildDocumentStore<S extends AnySchema>(\n schema: S,\n core: StorageBackend<S>,\n options: DurableStoreOptions<S> & {\n onCrossTabMessage?: (notify: (table: keyof S & string) => void) => (() => void) | undefined;\n onMutation?: (table: keyof S & string) => void;\n onTransactions?: (deps: BatchDeps<S>) => void;\n },\n): DocumentVaultStoreWithoutBatch<S> {\n const store = buildKeyValueStore(schema, core, options);\n\n return Object.assign(store, {\n iterate<K extends keyof S & string>(table: K): AsyncIterable<RecordOf<S, K>> {\n if (store.disposed) throw new VaultDisposedError();\n if (core.iterate) return core.iterate(table);\n return (async function* (): AsyncIterable<RecordOf<S, K>> {\n for (const record of await store.getAll(table)) yield record;\n })();\n },\n });\n}\n\n/** Attaches a batch() implementation to a document store. */\nexport function withBatch<S extends AnySchema>(\n store: DocumentVaultStoreWithoutBatch<S>,\n batch: BatchImpl<S>,\n schema: S,\n): DocumentVaultStore<S> {\n const runBatch: BatchImpl<S> = (tables, fn) => {\n if (store.disposed) return Promise.reject(new VaultDisposedError());\n return batch(tables, fn);\n };\n\n return Object.assign(store, {\n batch: runBatch,\n deleteMany<K extends keyof S & string>(table: K, keys: readonly KeyOf<S, K>[]) {\n return runBatch([table], (tx) => tx.deleteMany(table, keys));\n },\n query<K extends keyof S & string>(table: K) {\n if (store.disposed) throw new VaultDisposedError();\n return createQueryBuilder({\n deleteMany: async (records) => {\n const keys = records.map((record) => getRecordKey(schema, table, record));\n return runBatch([table], (tx) => tx.deleteMany(table, keys));\n },\n source: () => store.getAll(table),\n });\n },\n update<K extends keyof S & string>(table: K, key: KeyOf<S, K>, changes: Partial<RecordOf<S, K>>, ttl?: number) {\n return runBatch([table], (tx) => tx.update(table, key, changes, ttl));\n },\n upsert<K extends keyof S & string>(\n table: K,\n key: KeyOf<S, K>,\n apply: (existing: RecordOf<S, K> | undefined) => RecordOf<S, K>,\n ttl?: number,\n ) {\n return runBatch([table], (tx) => tx.upsert(table, key, apply, ttl));\n },\n }) as DocumentVaultStore<S>;\n}\n\n/* -------------------- Derived convenience helpers -------------------- */\n\n/** Check whether a record exists for the given key. */\nexport async function has<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n key: KeyOf<S, K>,\n): Promise<boolean> {\n return store.has(table, key);\n}\n\n/** Count live records in a table. */\nexport async function count<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n): Promise<number> {\n return store.count(table);\n}\n\n/** Check whether a table has no live records. */\nexport async function isEmpty<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n): Promise<boolean> {\n return store.isEmpty(table);\n}\n\n/** Fetch multiple records by key. Preserves key order; missing keys yield `undefined`. */\nexport async function getMany<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n keys: readonly KeyOf<S, K>[],\n): Promise<Array<RecordOf<S, K> | undefined>> {\n return store.getMany(table, keys);\n}\n\n/** Fetch all live primary keys for a table. */\nexport async function keys<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n filter?: (record: RecordOf<S, K>) => boolean,\n): Promise<KeyOf<S, K>[]> {\n return store.keys(table, filter);\n}\n\n/** Delete multiple records by key. Returns the count of records that were actually deleted. */\nexport async function deleteMany<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n keys: readonly KeyOf<S, K>[],\n): Promise<number> {\n return store.deleteMany(table, keys);\n}\n\n/** Partially update an existing record. Returns `undefined` when the key does not exist. */\nexport async function update<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n key: KeyOf<S, K>,\n changes: Partial<RecordOf<S, K>>,\n ttl?: number,\n): Promise<RecordOf<S, K> | undefined> {\n return store.update(table, key, changes, ttl);\n}\n\n/** Read-modify-write: the callback receives the current record (or `undefined`) and returns the value to store. */\nexport async function upsert<S extends AnySchema, K extends keyof S & string>(\n store: KeyValueVaultStore<S>,\n table: K,\n key: KeyOf<S, K>,\n apply: (existing: RecordOf<S, K> | undefined) => RecordOf<S, K>,\n ttl?: number,\n): Promise<RecordOf<S, K>> {\n return store.upsert(table, key, apply, ttl);\n}\n","/// <reference lib=\"dom\" />\n\nimport { VaultError } from './errors';\nimport type { QueryBuilder } from './query';\nimport { assertPositiveFinite } from './ttl';\n\n/** Portable primary-key values. Vault preserves their type and encodes them distinctly at rest. */\nexport type VaultKey = number | string;\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> = {\n defaultTtl?: number;\n /** IndexedDB creates these as `value.<field>` indexes; other stores filter in memory. */\n indexes?: readonly (keyof T & string)[];\n key: Key;\n};\n\nexport type AnySchema = Record<string, { defaultTtl?: number; indexes?: readonly string[]; key: string }>;\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\n/** A codec validates and decodes persisted values crossing a trust boundary. */\nexport type RecordCodec<T> = {\n decode(value: unknown): T;\n encode(value: T): unknown;\n};\n\nexport type RecordParser<T> = {\n parse(value: unknown): T;\n};\n\nexport type CodecInput<T> = RecordCodec<T> | RecordParser<T>;\n\nexport type TableCodecs<S extends AnySchema> = {\n [K in keyof S]: CodecInput<RecordOf<S, K>>;\n};\n\n/** A validator-only codec: encodes values as-is, validates on decode. */\nexport function validatorCodec<T>(validator: RecordParser<T>): RecordCodec<T> {\n return {\n decode: (value) => validator.parse(value),\n encode: (value) => value,\n };\n}\n\nexport type Observer<T> = (records: T[]) => void;\nexport type Unsubscribe = () => void;\n\n/** Shared factory options for stores that do not require durable codecs. */\nexport type MemoryStoreOptions<S extends AnySchema> = {\n schema: S;\n /** Optional per-table codecs. Memory values never cross a trust boundary, so codecs may be omitted. */\n codecs?: TableCodecs<S>;\n};\n\n/** Shared factory options for durable stores whose values cross a trust boundary. */\nexport type DurableStoreOptions<S extends AnySchema> = {\n schema: S;\n /** Required per-table codecs. Persisted values are decoded through these before entering typed code. */\n codecs: TableCodecs<S>;\n};\n\nexport type VaultConveniences<S extends AnySchema, K extends keyof S & string = keyof S & string> = {\n count<T extends K>(table: T): Promise<number>;\n deleteMany<T extends K>(table: T, keys: readonly KeyOf<S, T>[]): Promise<number>;\n getMany<T extends K>(table: T, keys: readonly KeyOf<S, T>[]): Promise<Array<RecordOf<S, T> | undefined>>;\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 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?: number,\n ): Promise<RecordOf<S, T> | undefined>;\n upsert<T extends K>(\n table: T,\n key: KeyOf<S, T>,\n update: (existing: RecordOf<S, T> | undefined) => RecordOf<S, T>,\n ttl?: number,\n ): Promise<RecordOf<S, T>>;\n};\n\n/** Methods available within an IndexedDB or SQLite transaction. */\nexport type TransactionContext<S extends AnySchema, K extends keyof S & string = keyof S & string> = VaultConveniences<\n S,\n K\n> & {\n clear<T extends K>(table: T): Promise<void>;\n delete<T extends K>(table: T, key: KeyOf<S, T>): Promise<boolean>;\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 iterate<T extends K>(table: T): AsyncIterable<RecordOf<S, T>>;\n put<T extends K>(table: T, value: RecordOf<S, T>, ttl?: number): Promise<RecordOf<S, T>>;\n putAll<T extends K>(table: T, values: readonly RecordOf<S, T>[], ttl?: number): Promise<void>;\n};\n\n/** Key-value store for Memory and Web Storage: core CRUD, observation, TTL, and pruning. */\nexport interface KeyValueVaultStore<S extends AnySchema> extends VaultConveniences<S> {\n clear<K extends keyof S & string>(table: K): Promise<void>;\n delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean>;\n readonly disposalSignal: AbortSignal;\n dispose(): Promise<void>;\n readonly disposed: boolean;\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 observe<K extends keyof S & string>(\n table: K,\n listener: Observer<RecordOf<S, K>>,\n options?: { immediate?: boolean; signal?: AbortSignal },\n ): Unsubscribe;\n pruneExpired(): Promise<Record<keyof S & string, number>>;\n put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: number): Promise<RecordOf<S, K>>;\n putAll<K extends keyof S & string>(table: K, values: readonly RecordOf<S, K>[], ttl?: number): Promise<void>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\n/** Document store for IndexedDB and SQLite: adds atomic transactions and lazy iteration. */\nexport interface DocumentVaultStore<S extends AnySchema> extends KeyValueVaultStore<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\ntype VaultKeyField<T extends object> = {\n [K in keyof T & string]: T[K] extends VaultKey ? K : never;\n}[keyof T & string];\n\n/** Define a typed table whose primary-key field holds a portable Vault key. */\nexport function table<T extends object, Key extends VaultKeyField<T> = VaultKeyField<T>>(\n key: Key,\n options: { defaultTtl?: number; indexes?: readonly (keyof T & string)[] } = {},\n): SchemaEntry<T, Key> {\n const { defaultTtl, indexes } = options;\n\n if (defaultTtl !== undefined) assertPositiveFinite(defaultTtl, 'table: defaultTtl');\n\n if (indexes) {\n const seen = new Set<string>();\n\n for (const field of indexes) {\n if (seen.has(field)) {\n throw new VaultError(`table: index \"${field}\" is already registered`);\n }\n\n seen.add(field);\n }\n }\n\n return { defaultTtl, indexes, key };\n}\n"],"mappings":"AAIA,IAAa,EAAb,cAAgC,KAAM,CACpC,OAA0B,UAAoB,aAE9C,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAQ,WAAiC,UAE9C,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,EAAb,cAAwC,CAAW,CACjD,OAAmC,UAAY,qBAE/C,YAAY,EAAU,sBAAuB,EAAqB,CAChE,MAAM,EAAS,CAAI,CACrB,CACF,EAGa,EAAb,cAAqC,CAAW,CAC9C,OAAmC,UAAY,iBACjD,EAGa,EAAb,cAAqC,CAAW,CAC9C,OAAmC,UAAY,iBACjD,EAGa,EAAb,cAAyC,CAAW,CAClD,OAAmC,UAAY,qBACjD,EClCa,EAAM,CACjB,KAAO,GAAc,EAAqB,EAAI,MAAY,UAAU,EACpE,MAAQ,GAAc,EAAqB,EAAI,KAAW,WAAW,EACrE,QAAU,GAAc,EAAqB,EAAI,IAAQ,aAAa,EACtE,GAAK,GAAc,EAAqB,EAAG,QAAQ,EACnD,QAAU,GAAc,EAAqB,EAAI,IAAM,aAAa,CACtE,EAKA,SAAgB,EAAU,EAAwC,CAChE,OAAO,IAAc,IAAA,IAAa,KAAK,IAAI,GAAK,CAClD,CAGA,SAAgB,EAAqB,EAAe,EAAwB,CAC1E,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,GAAS,EACtC,MAAM,IAAI,EAAW,GAAG,EAAO,+CAA+C,OAAO,CAAK,GAAG,EAG/F,OAAO,CACT,CC2eA,eAAsB,EACpB,EACA,EACA,EACkB,CAClB,OAAO,EAAM,IAAI,EAAO,CAAG,CAC7B,CAGA,eAAsB,EACpB,EACA,EACiB,CACjB,OAAO,EAAM,MAAM,CAAK,CAC1B,CAGA,eAAsB,EACpB,EACA,EACkB,CAClB,OAAO,EAAM,QAAQ,CAAK,CAC5B,CAGA,eAAsB,EACpB,EACA,EACA,EAC4C,CAC5C,OAAO,EAAM,QAAQ,EAAO,CAAI,CAClC,CAGA,eAAsB,EACpB,EACA,EACA,EACwB,CACxB,OAAO,EAAM,KAAK,EAAO,CAAM,CACjC,CAGA,eAAsB,EACpB,EACA,EACA,EACiB,CACjB,OAAO,EAAM,WAAW,EAAO,CAAI,CACrC,CAGA,eAAsB,EACpB,EACA,EACA,EACA,EACA,EACqC,CACrC,OAAO,EAAM,OAAO,EAAO,EAAK,EAAS,CAAG,CAC9C,CAGA,eAAsB,EACpB,EACA,EACA,EACA,EACA,EACyB,CACzB,OAAO,EAAM,OAAO,EAAO,EAAK,EAAO,CAAG,CAC5C,CChiBA,SAAgB,EAAkB,EAA4C,CAC5E,MAAO,CACL,OAAS,GAAU,EAAU,MAAM,CAAK,EACxC,OAAS,GAAU,CACrB,CACF,CAyFA,SAAgB,EACd,EACA,EAA4E,CAAC,EACxD,CACrB,GAAM,CAAE,aAAY,WAAY,EAIhC,GAFI,IAAe,IAAA,IAAW,EAAqB,EAAY,mBAAmB,EAE9E,EAAS,CACX,IAAM,EAAO,IAAI,IAEjB,IAAK,IAAM,KAAS,EAAS,CAC3B,GAAI,EAAK,IAAI,CAAK,EAChB,MAAM,IAAI,EAAW,iBAAiB,EAAM,wBAAwB,EAGtE,EAAK,IAAI,CAAK,CAChB,CACF,CAEA,MAAO,CAAE,aAAY,UAAS,KAAI,CACpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielzeug/vault",
3
- "version": "2.4.0",
3
+ "version": "3.0.0",
4
4
  "description": "Typed storage core with explicit browser and SQLite adapter entry points",
5
5
  "repository": {
6
6
  "type": "git",
@@ -74,22 +74,24 @@
74
74
  "registry": "https://registry.npmjs.org/"
75
75
  },
76
76
  "scripts": {
77
- "build": "vite build && pnpm run build:bundle && pnpm run build:types",
77
+ "build": "vite build && pnpm --silent run build:bundle && pnpm --silent run build:types && pnpm --silent run verify:exports",
78
78
  "build:bundle": "vite build --config vite.bundle.config.ts",
79
79
  "build:types": "tsc -p tsconfig.declarations.json",
80
80
  "fix": "biome check --write src",
81
81
  "lint": "biome ci src",
82
- "prepublishOnly": "pnpm run build",
82
+ "prepublishOnly": "pnpm --silent run build",
83
83
  "preview": "vite preview",
84
84
  "test": "vitest",
85
- "test:sqlite:bun": "bun test runtime-smoke/bun-sqlite.ts",
86
- "test:sqlite:deno": "deno test --allow-read --allow-env --allow-ffi runtime-smoke/deno-sqlite.ts"
85
+ "test:sqlite:bun": "bun test ./runtime-smoke/bun-sqlite.ts",
86
+ "test:sqlite:deno": "deno test --allow-read --allow-env --allow-ffi runtime-smoke/deno-sqlite.ts",
87
+ "verify:exports": "node verify-exports.mjs"
87
88
  },
88
89
  "devDependencies": {
89
- "@types/node": "^26.2.0",
90
+ "@types/node": "^26.4.1",
91
+ "@vielzeug/spell": "3.0.0",
90
92
  "fake-indexeddb": "^6.2.5",
91
93
  "typescript": "^6.0.3",
92
- "vite": "^8.2.1",
93
- "vitest": "^4.1.10"
94
+ "vite": "^8.2.2",
95
+ "vitest": "^5.0.0"
94
96
  }
95
97
  }