@vielzeug/vault 3.0.1 → 3.0.3

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 (78) hide show
  1. package/dist/adapter-core.cjs +1 -1
  2. package/dist/adapter-core.cjs.map +1 -1
  3. package/dist/adapter-core.d.ts +5 -34
  4. package/dist/adapter-core.d.ts.map +1 -1
  5. package/dist/adapter-core.js +1 -282
  6. package/dist/adapter-core.js.map +1 -1
  7. package/dist/adapters/indexeddb.cjs +1 -1
  8. package/dist/adapters/indexeddb.cjs.map +1 -1
  9. package/dist/adapters/indexeddb.d.ts +5 -35
  10. package/dist/adapters/indexeddb.d.ts.map +1 -1
  11. package/dist/adapters/indexeddb.js +1 -365
  12. package/dist/adapters/indexeddb.js.map +1 -1
  13. package/dist/adapters/memory.cjs +1 -1
  14. package/dist/adapters/memory.cjs.map +1 -1
  15. package/dist/adapters/memory.d.ts +8 -3
  16. package/dist/adapters/memory.d.ts.map +1 -1
  17. package/dist/adapters/memory.js +1 -60
  18. package/dist/adapters/memory.js.map +1 -1
  19. package/dist/adapters/sqlite.cjs +14 -32
  20. package/dist/adapters/sqlite.cjs.map +1 -1
  21. package/dist/adapters/sqlite.d.ts.map +1 -1
  22. package/dist/adapters/sqlite.js +14 -409
  23. package/dist/adapters/sqlite.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 +0 -6
  27. package/dist/adapters/webstorage.d.ts.map +1 -1
  28. package/dist/adapters/webstorage.js +1 -160
  29. package/dist/adapters/webstorage.js.map +1 -1
  30. package/dist/codec.cjs +1 -1
  31. package/dist/codec.cjs.map +1 -1
  32. package/dist/codec.js +1 -5
  33. package/dist/codec.js.map +1 -1
  34. package/dist/errors.cjs +1 -1
  35. package/dist/errors.cjs.map +1 -1
  36. package/dist/errors.d.ts +0 -5
  37. package/dist/errors.d.ts.map +1 -1
  38. package/dist/errors.js +1 -21
  39. package/dist/errors.js.map +1 -1
  40. package/dist/index.cjs +1 -1
  41. package/dist/index.d.ts +1 -3
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +1 -5
  44. package/dist/indexeddb.cjs +1 -1
  45. package/dist/indexeddb.d.ts +2 -2
  46. package/dist/indexeddb.d.ts.map +1 -1
  47. package/dist/indexeddb.js +1 -2
  48. package/dist/internal.cjs +1 -1
  49. package/dist/internal.cjs.map +1 -1
  50. package/dist/internal.js +1 -72
  51. package/dist/internal.js.map +1 -1
  52. package/dist/local-storage.js +1 -2
  53. package/dist/memory.js +1 -2
  54. package/dist/session-storage.js +1 -2
  55. package/dist/sqlite.js +1 -2
  56. package/dist/ttl.cjs +1 -1
  57. package/dist/ttl.cjs.map +1 -1
  58. package/dist/ttl.js +1 -24
  59. package/dist/ttl.js.map +1 -1
  60. package/dist/types.cjs +1 -1
  61. package/dist/types.cjs.map +1 -1
  62. package/dist/types.d.ts +0 -2
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/types.js +1 -27
  65. package/dist/types.js.map +1 -1
  66. package/dist/vault.cjs +1 -1
  67. package/dist/vault.cjs.map +1 -1
  68. package/dist/vault.iife.js +1 -1
  69. package/dist/vault.iife.js.map +1 -1
  70. package/dist/vault.js +1 -1
  71. package/dist/vault.js.map +1 -1
  72. package/package.json +5 -5
  73. package/dist/query.cjs +0 -2
  74. package/dist/query.cjs.map +0 -1
  75. package/dist/query.d.ts +0 -23
  76. package/dist/query.d.ts.map +0 -1
  77. package/dist/query.js +0 -54
  78. package/dist/query.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"webstorage.cjs","names":[],"sources":["../../src/adapters/webstorage.ts"],"sourcesContent":["import { buildKeyValueStore, type StorageBackend } from '../adapter-core';\nimport { decodeRecord, encodeRecord } from '../codec';\nimport { VaultError, VaultQuotaError } from '../errors';\nimport {\n decodeStorageTableFromKey,\n encodeDbPrefix,\n encodeStorageKey,\n encodeStorageTablePrefix,\n getRecordKey,\n} from '../internal';\nimport { isExpired, parseStored, type StoredRecord } from '../ttl';\nimport type { AnySchema, DurableStoreOptions, KeyOf, KeyValueVaultStore, RecordOf } from '../types';\n\n// Firefox historically threw 'NS_ERROR_DOM_QUOTA_REACHED'; modern browsers use the standard name.\nconst QUOTA_ERROR_NAMES = new Set(['QuotaExceededError', 'NS_ERROR_DOM_QUOTA_REACHED']);\n\ntype WebStorageOptions<S extends AnySchema> = DurableStoreOptions<S> & {\n name: string;\n /**\n * Called when localStorage/sessionStorage quota is exceeded on a write.\n * Return `'ignore'` to silently drop the write, or `'throw'` (default) to rethrow the error.\n */\n onQuotaExceeded?: (table: keyof S, error: VaultQuotaError) => 'ignore' | 'throw';\n};\n\nfunction createWebStorageAdapter<S extends AnySchema>(\n options: WebStorageOptions<S> & {\n getStorage: () => Storage;\n storageLabel: string;\n },\n): KeyValueVaultStore<S> {\n const { getStorage, name, onQuotaExceeded, schema, storageLabel, codecs } = options;\n\n if (!codecs) {\n throw new VaultError(`${storageLabel} requires codecs for durable persistence`);\n }\n\n let resolvedStorage: Storage;\n\n try {\n resolvedStorage = getStorage();\n } catch (cause) {\n throw new VaultError(\n `${storageLabel} is not available in this environment (private browsing or sandboxed iframe?)`,\n {\n cause,\n },\n );\n }\n\n const storage = (): Storage => resolvedStorage;\n\n const prefixMap = new Map(Object.keys(schema).map((table) => [table, encodeStorageTablePrefix(name, table)]));\n const getPrefix = (table: string): string => {\n const cached = prefixMap.get(table);\n\n if (!cached) throw new VaultError(`table \"${table}\" not in schema`);\n\n return cached;\n };\n\n const writeItem = (table: keyof S, storageKey: string, value: unknown): void => {\n try {\n storage().setItem(storageKey, JSON.stringify(value));\n } catch (error) {\n if (error instanceof DOMException && QUOTA_ERROR_NAMES.has(error.name)) {\n const wrappedError = new VaultQuotaError(`${storageLabel} quota exceeded while writing record`, {\n cause: error,\n });\n\n if (onQuotaExceeded?.(table, wrappedError) === 'ignore') return;\n\n throw wrappedError;\n }\n\n throw error;\n }\n };\n\n // Per-instance registry of storage keys owned by this namespace.\n // Table-wide operations resynchronize it so same-window adapters stay consistent.\n const ownedKeys = new Set<string>();\n\n const syncOwnedKeys = (): void => {\n const dbPrefix = encodeDbPrefix(name);\n ownedKeys.clear();\n\n for (let i = 0; i < resolvedStorage.length; i++) {\n const key = resolvedStorage.key(i);\n\n if (key?.startsWith(dbPrefix)) ownedKeys.add(key);\n }\n };\n\n syncOwnedKeys();\n\n /**\n * Reads a single entry without side effects. Returns the decoded live value,\n * or `undefined` if missing/expired/corrupt.\n *\n * Callers that want to evict stale entries must call `evict(storageKey)` explicitly.\n */\n const parseEntry = <T extends object>(table: keyof S, storageKey: string): T | undefined => {\n const raw = storage().getItem(storageKey);\n\n if (!raw) return undefined;\n\n let stored: StoredRecord<unknown> | undefined;\n try {\n stored = parseStored<unknown>(JSON.parse(raw) as unknown);\n } catch {\n return undefined;\n }\n\n if (!stored || isExpired(stored.expiresAt)) return undefined;\n\n try {\n return decodeRecord(codecs[table], stored.value) as unknown as T;\n } catch (error) {\n throw new VaultError(`validation failed for table \"${String(table)}\"`, { cause: error });\n }\n };\n\n /** Removes a stale/expired/corrupt entry from storage and the owned-keys registry. */\n const evict = (storageKey: string): void => {\n storage().removeItem(storageKey);\n ownedKeys.delete(storageKey);\n };\n\n const core: StorageBackend<S> = {\n async clear<K extends keyof S & string>(table: K): Promise<void> {\n syncOwnedKeys();\n const target = storage();\n const prefix = getPrefix(table);\n const toRemove: string[] = [];\n\n for (const key of ownedKeys) {\n if (key.startsWith(prefix)) toRemove.push(key);\n }\n\n for (const key of toRemove) {\n target.removeItem(key);\n ownedKeys.delete(key);\n }\n },\n\n async delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean> {\n const storageKey = encodeStorageKey(name, table, key);\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value !== undefined) {\n evict(storageKey);\n\n return true;\n }\n\n if (ownedKeys.has(storageKey)) evict(storageKey);\n\n return false;\n },\n\n async get<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<RecordOf<S, K> | undefined> {\n const storageKey = encodeStorageKey(name, table, key);\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value === undefined && ownedKeys.has(storageKey)) evict(storageKey);\n\n return value;\n },\n\n async getAll<K extends keyof S & string>(table: K): Promise<RecordOf<S, K>[]> {\n syncOwnedKeys();\n const records: RecordOf<S, K>[] = [];\n const expiredKeys: string[] = [];\n const prefix = getPrefix(table);\n\n for (const storageKey of ownedKeys) {\n if (!storageKey.startsWith(prefix)) continue;\n\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value === undefined) {\n expiredKeys.push(storageKey);\n continue;\n }\n\n records.push(value);\n }\n\n for (const storageKey of expiredKeys) {\n evict(storageKey);\n }\n\n return records;\n },\n\n async pruneExpiredInTable<K extends keyof S & string>(table: K): Promise<number> {\n syncOwnedKeys();\n const prefix = getPrefix(table);\n const expiredKeys: string[] = [];\n\n for (const storageKey of ownedKeys) {\n if (!storageKey.startsWith(prefix)) continue;\n\n const raw = storage().getItem(storageKey);\n\n if (raw === null) {\n expiredKeys.push(storageKey);\n continue;\n }\n\n try {\n const stored = parseStored(JSON.parse(raw) as unknown);\n\n if (!stored || isExpired(stored.expiresAt)) {\n expiredKeys.push(storageKey);\n }\n } catch {\n expiredKeys.push(storageKey);\n }\n }\n\n for (const storageKey of expiredKeys) {\n evict(storageKey);\n }\n\n return expiredKeys.length;\n },\n\n async put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: number): Promise<void> {\n const storageKey = encodeStorageKey(name, table, getRecordKey(schema, table, value));\n const expiresAt = ttl !== undefined ? Date.now() + ttl : undefined;\n const encoded = encodeRecord(codecs[table], value);\n\n writeItem(table, storageKey, expiresAt === undefined ? { value: encoded } : { expiresAt, value: encoded });\n ownedKeys.add(storageKey);\n },\n\n async putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: number): Promise<void> {\n const expiresAt = ttl !== undefined ? Date.now() + ttl : undefined;\n\n for (const value of values) {\n const storageKey = encodeStorageKey(name, table, getRecordKey(schema, table, value));\n const encoded = encodeRecord(codecs[table], value);\n\n writeItem(table, storageKey, expiresAt === undefined ? { value: encoded } : { expiresAt, value: encoded });\n ownedKeys.add(storageKey);\n }\n },\n };\n\n return buildKeyValueStore(schema, core, {\n codecs,\n onCrossTabMessage(notify) {\n if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') {\n return undefined;\n }\n\n const listener = (event: StorageEvent) => {\n if (event.storageArea && event.storageArea !== resolvedStorage) return;\n\n if (event.key === null) {\n // storage.clear() from another tab — all keys are gone; purge ownedKeys\n ownedKeys.clear();\n\n for (const table of Object.keys(schema)) {\n notify(table as keyof S & string);\n }\n\n return;\n }\n\n const tableName = decodeStorageTableFromKey(name, event.key);\n\n if (tableName && Object.hasOwn(schema, tableName)) {\n if (event.newValue === null) {\n ownedKeys.delete(event.key);\n } else {\n ownedKeys.add(event.key);\n }\n\n notify(tableName as keyof S & string);\n }\n };\n\n window.addEventListener('storage', listener);\n\n return () => window.removeEventListener('storage', listener);\n },\n schema,\n });\n}\n\nexport function createLocalStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S> {\n return createWebStorageAdapter({\n ...options,\n getStorage: () => (typeof window !== 'undefined' ? window.localStorage : localStorage),\n storageLabel: 'localStorage',\n });\n}\n\nexport function createSessionStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S> {\n return createWebStorageAdapter({\n ...options,\n getStorage: () => (typeof window !== 'undefined' ? window.sessionStorage : sessionStorage),\n storageLabel: 'sessionStorage',\n });\n}\n"],"mappings":"iJAcA,IAAM,EAAoB,IAAI,IAAI,CAAC,qBAAsB,4BAA4B,CAAC,EAWtF,SAAS,EACP,EAIuB,CACvB,GAAM,CAAE,aAAY,OAAM,kBAAiB,SAAQ,eAAc,UAAW,EAE5E,GAAI,CAAC,EACH,MAAM,IAAI,EAAA,WAA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B,EAAM,EAAO,EAAA,aAAa,EAAQ,EAAO,CAAK,CAAC,EAC7E,EAAU,EAAA,aAAa,EAAO,GAAQ,CAAK,EAEjD,EAAU,EAAO,EAAY,IAAc,IAAA,GAAY,CAAE,MAAO,CAAQ,EAAI,CAAE,YAAW,MAAO,CAAQ,CAAC,EACzG,EAAU,IAAI,CAAU,CAC1B,CACF,CAGgC,EAAM,CACtC,SACA,kBAAkB,EAAQ,CACxB,GAAI,OAAO,OAAW,KAAe,OAAO,OAAO,kBAAqB,WACtE,OAGF,IAAM,EAAY,GAAwB,CACxC,GAAI,EAAM,aAAe,EAAM,cAAgB,EAAiB,OAEhE,GAAI,EAAM,MAAQ,KAAM,CAEtB,EAAU,MAAM,EAEhB,IAAK,IAAM,KAAS,OAAO,KAAK,CAAM,EACpC,EAAO,CAAyB,EAGlC,MACF,CAEA,IAAM,EAAY,EAAA,0BAA0B,EAAM,EAAM,GAAG,EAEvD,GAAa,OAAO,OAAO,EAAQ,CAAS,IAC1C,EAAM,WAAa,KACrB,EAAU,OAAO,EAAM,GAAG,EAE1B,EAAU,IAAI,EAAM,GAAG,EAGzB,EAAO,CAA6B,EAExC,EAIA,OAFA,OAAO,iBAAiB,UAAW,CAAQ,MAE9B,OAAO,oBAAoB,UAAW,CAAQ,CAC7D,EACA,QACF,CAAC,CACH,CAEA,SAAgB,EAAwC,EAAsD,CAC5G,OAAO,EAAwB,CAC7B,GAAG,EACH,eAAmB,OAAO,OAAW,IAAc,OAAO,aAAe,aACzE,aAAc,cAChB,CAAC,CACH,CAEA,SAAgB,EAA0C,EAAsD,CAC9G,OAAO,EAAwB,CAC7B,GAAG,EACH,eAAmB,OAAO,OAAW,IAAc,OAAO,eAAiB,eAC3E,aAAc,gBAChB,CAAC,CACH"}
1
+ {"version":3,"file":"webstorage.cjs","names":[],"sources":["../../src/adapters/webstorage.ts"],"sourcesContent":["import { buildVaultStore, type StorageBackend } from '../adapter-core';\nimport { decodeRecord, encodeRecord } from '../codec';\nimport { VaultError, VaultQuotaError } from '../errors';\nimport {\n decodeStorageTableFromKey,\n encodeDbPrefix,\n encodeStorageKey,\n encodeStorageTablePrefix,\n getRecordKey,\n} from '../internal';\nimport { isExpired, parseStored, type StoredRecord } from '../ttl';\nimport type { AnySchema, DurableStoreOptions, KeyOf, KeyValueVaultStore, RecordOf } from '../types';\n\n// Firefox historically threw 'NS_ERROR_DOM_QUOTA_REACHED'; modern browsers use the standard name.\nconst QUOTA_ERROR_NAMES = new Set(['QuotaExceededError', 'NS_ERROR_DOM_QUOTA_REACHED']);\n\ntype WebStorageOptions<S extends AnySchema> = DurableStoreOptions<S> & {\n name: string;\n};\n\nfunction createWebStorageAdapter<S extends AnySchema>(\n options: WebStorageOptions<S> & {\n getStorage: () => Storage;\n storageLabel: string;\n },\n): KeyValueVaultStore<S> {\n const { getStorage, name, schema, storageLabel, codecs } = options;\n\n if (!codecs) {\n throw new VaultError(`${storageLabel} requires codecs for durable persistence`);\n }\n\n let resolvedStorage: Storage;\n\n try {\n resolvedStorage = getStorage();\n } catch (cause) {\n throw new VaultError(\n `${storageLabel} is not available in this environment (private browsing or sandboxed iframe?)`,\n {\n cause,\n },\n );\n }\n\n const storage = (): Storage => resolvedStorage;\n\n const prefixMap = new Map(Object.keys(schema).map((table) => [table, encodeStorageTablePrefix(name, table)]));\n const getPrefix = (table: string): string => {\n const cached = prefixMap.get(table);\n\n if (!cached) throw new VaultError(`table \"${table}\" not in schema`);\n\n return cached;\n };\n\n const writeItem = (storageKey: string, value: unknown): void => {\n try {\n storage().setItem(storageKey, JSON.stringify(value));\n } catch (error) {\n if (error instanceof DOMException && QUOTA_ERROR_NAMES.has(error.name)) {\n throw new VaultQuotaError(`${storageLabel} quota exceeded while writing record`, { cause: error });\n }\n\n throw error;\n }\n };\n\n // Per-instance registry of storage keys owned by this namespace.\n // Table-wide operations resynchronize it so same-window adapters stay consistent.\n const ownedKeys = new Set<string>();\n\n const syncOwnedKeys = (): void => {\n const dbPrefix = encodeDbPrefix(name);\n ownedKeys.clear();\n\n for (let i = 0; i < resolvedStorage.length; i++) {\n const key = resolvedStorage.key(i);\n\n if (key?.startsWith(dbPrefix)) ownedKeys.add(key);\n }\n };\n\n syncOwnedKeys();\n\n /**\n * Reads a single entry without side effects. Returns the decoded live value,\n * or `undefined` if missing/expired/corrupt.\n *\n * Callers that want to evict stale entries must call `evict(storageKey)` explicitly.\n */\n const parseEntry = <T extends object>(table: keyof S, storageKey: string): T | undefined => {\n const raw = storage().getItem(storageKey);\n\n if (!raw) return undefined;\n\n let stored: StoredRecord<unknown> | undefined;\n try {\n stored = parseStored<unknown>(JSON.parse(raw) as unknown);\n } catch {\n return undefined;\n }\n\n if (!stored || isExpired(stored.expiresAt)) return undefined;\n\n try {\n return decodeRecord(codecs[table], stored.value) as unknown as T;\n } catch (error) {\n throw new VaultError(`validation failed for table \"${String(table)}\"`, { cause: error });\n }\n };\n\n /** Removes a stale/expired/corrupt entry from storage and the owned-keys registry. */\n const evict = (storageKey: string): void => {\n storage().removeItem(storageKey);\n ownedKeys.delete(storageKey);\n };\n\n const core: StorageBackend<S> = {\n async clear<K extends keyof S & string>(table: K): Promise<void> {\n syncOwnedKeys();\n const target = storage();\n const prefix = getPrefix(table);\n const toRemove: string[] = [];\n\n for (const key of ownedKeys) {\n if (key.startsWith(prefix)) toRemove.push(key);\n }\n\n for (const key of toRemove) {\n target.removeItem(key);\n ownedKeys.delete(key);\n }\n },\n\n async delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean> {\n const storageKey = encodeStorageKey(name, table, key);\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value !== undefined) {\n evict(storageKey);\n\n return true;\n }\n\n if (ownedKeys.has(storageKey)) evict(storageKey);\n\n return false;\n },\n\n async get<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<RecordOf<S, K> | undefined> {\n const storageKey = encodeStorageKey(name, table, key);\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value === undefined && ownedKeys.has(storageKey)) evict(storageKey);\n\n return value;\n },\n\n async getAll<K extends keyof S & string>(table: K): Promise<RecordOf<S, K>[]> {\n syncOwnedKeys();\n const records: RecordOf<S, K>[] = [];\n const expiredKeys: string[] = [];\n const prefix = getPrefix(table);\n\n for (const storageKey of ownedKeys) {\n if (!storageKey.startsWith(prefix)) continue;\n\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value === undefined) {\n expiredKeys.push(storageKey);\n continue;\n }\n\n records.push(value);\n }\n\n for (const storageKey of expiredKeys) {\n evict(storageKey);\n }\n\n return records;\n },\n\n async pruneExpiredInTable<K extends keyof S & string>(table: K): Promise<number> {\n syncOwnedKeys();\n const prefix = getPrefix(table);\n const expiredKeys: string[] = [];\n\n for (const storageKey of ownedKeys) {\n if (!storageKey.startsWith(prefix)) continue;\n\n const raw = storage().getItem(storageKey);\n\n if (raw === null) {\n expiredKeys.push(storageKey);\n continue;\n }\n\n try {\n const stored = parseStored(JSON.parse(raw) as unknown);\n\n if (!stored || isExpired(stored.expiresAt)) {\n expiredKeys.push(storageKey);\n }\n } catch {\n expiredKeys.push(storageKey);\n }\n }\n\n for (const storageKey of expiredKeys) {\n evict(storageKey);\n }\n\n return expiredKeys.length;\n },\n\n async put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: number): Promise<void> {\n const storageKey = encodeStorageKey(name, table, getRecordKey(schema, table, value));\n const expiresAt = ttl !== undefined ? Date.now() + ttl : undefined;\n const encoded = encodeRecord(codecs[table], value);\n\n writeItem(storageKey, expiresAt === undefined ? { value: encoded } : { expiresAt, value: encoded });\n ownedKeys.add(storageKey);\n },\n\n async putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: number): Promise<void> {\n const expiresAt = ttl !== undefined ? Date.now() + ttl : undefined;\n\n for (const value of values) {\n const storageKey = encodeStorageKey(name, table, getRecordKey(schema, table, value));\n const encoded = encodeRecord(codecs[table], value);\n\n writeItem(storageKey, expiresAt === undefined ? { value: encoded } : { expiresAt, value: encoded });\n ownedKeys.add(storageKey);\n }\n },\n };\n\n return buildVaultStore(schema, core, {\n codecs,\n onCrossTabMessage(notify) {\n if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') {\n return undefined;\n }\n\n const listener = (event: StorageEvent) => {\n if (event.storageArea && event.storageArea !== resolvedStorage) return;\n\n if (event.key === null) {\n // storage.clear() from another tab — all keys are gone; purge ownedKeys\n ownedKeys.clear();\n\n for (const table of Object.keys(schema)) {\n notify(table as keyof S & string);\n }\n\n return;\n }\n\n const tableName = decodeStorageTableFromKey(name, event.key);\n\n if (tableName && Object.hasOwn(schema, tableName)) {\n if (event.newValue === null) {\n ownedKeys.delete(event.key);\n } else {\n ownedKeys.add(event.key);\n }\n\n notify(tableName as keyof S & string);\n }\n };\n\n window.addEventListener('storage', listener);\n\n return () => window.removeEventListener('storage', listener);\n },\n schema,\n });\n}\n\nexport function createLocalStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S> {\n return createWebStorageAdapter({\n ...options,\n getStorage: () => (typeof window !== 'undefined' ? window.localStorage : localStorage),\n storageLabel: 'localStorage',\n });\n}\n\nexport function createSessionStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S> {\n return createWebStorageAdapter({\n ...options,\n getStorage: () => (typeof window !== 'undefined' ? window.sessionStorage : sessionStorage),\n storageLabel: 'sessionStorage',\n });\n}\n"],"mappings":"iJAcA,IAAM,EAAoB,IAAI,IAAI,CAAC,qBAAsB,4BAA4B,CAAC,EAMtF,SAAS,wBACP,EAIuB,CACvB,GAAM,CAAE,aAAY,OAAM,SAAQ,eAAc,UAAW,EAE3D,GAAI,CAAC,EACH,MAAM,IAAI,EAAA,WAAW,GAAG,EAAa,yCAAyC,EAGhF,IAAI,EAEJ,GAAI,CACF,EAAkB,EAAW,CAC/B,OAAS,EAAO,CACd,MAAM,IAAI,EAAA,WACR,GAAG,EAAa,+EAChB,CACE,OACF,CACF,CACF,CA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A,kBAAkB,EAAQ,CACxB,GAAI,OAAO,OAAW,KAAe,OAAO,OAAO,kBAAqB,WACtE,OAGF,IAAM,SAAY,GAAwB,CACxC,GAAI,EAAM,aAAe,EAAM,cAAgB,EAAiB,OAEhE,GAAI,EAAM,MAAQ,KAAM,CAEtB,EAAU,MAAM,EAEhB,IAAK,IAAM,KAAS,OAAO,KAAK,CAAM,EACpC,EAAO,CAAyB,EAGlC,MACF,CAEA,IAAM,EAAY,EAAA,0BAA0B,EAAM,EAAM,GAAG,EAEvD,GAAa,OAAO,OAAO,EAAQ,CAAS,IAC1C,EAAM,WAAa,KACrB,EAAU,OAAO,EAAM,GAAG,EAE1B,EAAU,IAAI,EAAM,GAAG,EAGzB,EAAO,CAA6B,EAExC,EAIA,OAFA,OAAO,iBAAiB,UAAW,QAAQ,MAE9B,OAAO,oBAAoB,UAAW,QAAQ,CAC7D,EACA,QACF,CAAC,CACH,CAEA,SAAgB,mBAAwC,EAAsD,CAC5G,OAAO,wBAAwB,CAC7B,GAAG,EACH,eAAmB,OAAO,OAAW,IAAc,OAAO,aAAe,aACzE,aAAc,cAChB,CAAC,CACH,CAEA,SAAgB,qBAA0C,EAAsD,CAC9G,OAAO,wBAAwB,CAC7B,GAAG,EACH,eAAmB,OAAO,OAAW,IAAc,OAAO,eAAiB,eAC3E,aAAc,gBAChB,CAAC,CACH"}
@@ -1,12 +1,6 @@
1
- import { VaultQuotaError } from '../errors';
2
1
  import type { AnySchema, DurableStoreOptions, KeyValueVaultStore } from '../types';
3
2
  type WebStorageOptions<S extends AnySchema> = DurableStoreOptions<S> & {
4
3
  name: string;
5
- /**
6
- * Called when localStorage/sessionStorage quota is exceeded on a write.
7
- * Return `'ignore'` to silently drop the write, or `'throw'` (default) to rethrow the error.
8
- */
9
- onQuotaExceeded?: (table: keyof S, error: VaultQuotaError) => 'ignore' | 'throw';
10
4
  };
11
5
  export declare function createLocalStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S>;
12
6
  export declare function createSessionStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S>;
@@ -1 +1 @@
1
- {"version":3,"file":"webstorage.d.ts","sourceRoot":"","sources":["../../src/adapters/webstorage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,eAAe,EAAE,MAAM,WAAW,CAAC;AASxD,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAS,kBAAkB,EAAY,MAAM,UAAU,CAAC;AAKpG,KAAK,iBAAiB,CAAC,CAAC,SAAS,SAAS,IAAI,mBAAmB,CAAC,CAAC,CAAC,GAAG;IACrE,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,eAAe,KAAK,QAAQ,GAAG,OAAO,CAAC;CAClF,CAAC;AA8QF,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAM5G;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAM9G"}
1
+ {"version":3,"file":"webstorage.d.ts","sourceRoot":"","sources":["../../src/adapters/webstorage.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAS,kBAAkB,EAAY,MAAM,UAAU,CAAC;AAKpG,KAAK,iBAAiB,CAAC,CAAC,SAAS,SAAS,IAAI,mBAAmB,CAAC,CAAC,CAAC,GAAG;IACrE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAwQF,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAM5G;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAM9G"}
@@ -1,161 +1,2 @@
1
- import { decodeRecord as e, encodeRecord as t } from "../codec.js";
2
- import { VaultError as n, VaultQuotaError as r } from "../errors.js";
3
- import { decodeStorageTableFromKey as i, encodeDbPrefix as a, encodeStorageKey as o, encodeStorageTablePrefix as s, getRecordKey as c } from "../internal.js";
4
- import { isExpired as l, parseStored as u } from "../ttl.js";
5
- import { buildKeyValueStore as d } from "../adapter-core.js";
6
- //#region src/adapters/webstorage.ts
7
- var f = /* @__PURE__ */ new Set(["QuotaExceededError", "NS_ERROR_DOM_QUOTA_REACHED"]);
8
- function p(p) {
9
- let { getStorage: m, name: h, onQuotaExceeded: g, schema: _, storageLabel: v, codecs: y } = p;
10
- if (!y) throw new n(`${v} requires codecs for durable persistence`);
11
- let b;
12
- try {
13
- b = m();
14
- } catch (e) {
15
- throw new n(`${v} is not available in this environment (private browsing or sandboxed iframe?)`, { cause: e });
16
- }
17
- let x = () => b, S = new Map(Object.keys(_).map((e) => [e, s(h, e)])), C = (e) => {
18
- let t = S.get(e);
19
- if (!t) throw new n(`table "${e}" not in schema`);
20
- return t;
21
- }, w = (e, t, n) => {
22
- try {
23
- x().setItem(t, JSON.stringify(n));
24
- } catch (t) {
25
- if (t instanceof DOMException && f.has(t.name)) {
26
- let n = new r(`${v} quota exceeded while writing record`, { cause: t });
27
- if (g?.(e, n) === "ignore") return;
28
- throw n;
29
- }
30
- throw t;
31
- }
32
- }, T = /* @__PURE__ */ new Set(), E = () => {
33
- let e = a(h);
34
- T.clear();
35
- for (let t = 0; t < b.length; t++) {
36
- let n = b.key(t);
37
- n?.startsWith(e) && T.add(n);
38
- }
39
- };
40
- E();
41
- let D = (t, r) => {
42
- let i = x().getItem(r);
43
- if (!i) return;
44
- let a;
45
- try {
46
- a = u(JSON.parse(i));
47
- } catch {
48
- return;
49
- }
50
- if (a && !l(a.expiresAt)) try {
51
- return e(y[t], a.value);
52
- } catch (e) {
53
- throw new n(`validation failed for table "${String(t)}"`, { cause: e });
54
- }
55
- }, O = (e) => {
56
- x().removeItem(e), T.delete(e);
57
- };
58
- return d(_, {
59
- async clear(e) {
60
- E();
61
- let t = x(), n = C(e), r = [];
62
- for (let e of T) e.startsWith(n) && r.push(e);
63
- for (let e of r) t.removeItem(e), T.delete(e);
64
- },
65
- async delete(e, t) {
66
- let n = o(h, e, t);
67
- return D(e, n) === void 0 ? (T.has(n) && O(n), !1) : (O(n), !0);
68
- },
69
- async get(e, t) {
70
- let n = o(h, e, t), r = D(e, n);
71
- return r === void 0 && T.has(n) && O(n), r;
72
- },
73
- async getAll(e) {
74
- E();
75
- let t = [], n = [], r = C(e);
76
- for (let i of T) {
77
- if (!i.startsWith(r)) continue;
78
- let a = D(e, i);
79
- if (a === void 0) {
80
- n.push(i);
81
- continue;
82
- }
83
- t.push(a);
84
- }
85
- for (let e of n) O(e);
86
- return t;
87
- },
88
- async pruneExpiredInTable(e) {
89
- E();
90
- let t = C(e), n = [];
91
- for (let e of T) {
92
- if (!e.startsWith(t)) continue;
93
- let r = x().getItem(e);
94
- if (r === null) {
95
- n.push(e);
96
- continue;
97
- }
98
- try {
99
- let t = u(JSON.parse(r));
100
- (!t || l(t.expiresAt)) && n.push(e);
101
- } catch {
102
- n.push(e);
103
- }
104
- }
105
- for (let e of n) O(e);
106
- return n.length;
107
- },
108
- async put(e, n, r) {
109
- let i = o(h, e, c(_, e, n)), a = r === void 0 ? void 0 : Date.now() + r, s = t(y[e], n);
110
- w(e, i, a === void 0 ? { value: s } : {
111
- expiresAt: a,
112
- value: s
113
- }), T.add(i);
114
- },
115
- async putAll(e, n, r) {
116
- let i = r === void 0 ? void 0 : Date.now() + r;
117
- for (let r of n) {
118
- let n = o(h, e, c(_, e, r)), a = t(y[e], r);
119
- w(e, n, i === void 0 ? { value: a } : {
120
- expiresAt: i,
121
- value: a
122
- }), T.add(n);
123
- }
124
- }
125
- }, {
126
- codecs: y,
127
- onCrossTabMessage(e) {
128
- if (typeof window > "u" || typeof window.addEventListener != "function") return;
129
- let t = (t) => {
130
- if (t.storageArea && t.storageArea !== b) return;
131
- if (t.key === null) {
132
- T.clear();
133
- for (let t of Object.keys(_)) e(t);
134
- return;
135
- }
136
- let n = i(h, t.key);
137
- n && Object.hasOwn(_, n) && (t.newValue === null ? T.delete(t.key) : T.add(t.key), e(n));
138
- };
139
- return window.addEventListener("storage", t), () => window.removeEventListener("storage", t);
140
- },
141
- schema: _
142
- });
143
- }
144
- function m(e) {
145
- return p({
146
- ...e,
147
- getStorage: () => typeof window < "u" ? window.localStorage : localStorage,
148
- storageLabel: "localStorage"
149
- });
150
- }
151
- function h(e) {
152
- return p({
153
- ...e,
154
- getStorage: () => typeof window < "u" ? window.sessionStorage : sessionStorage,
155
- storageLabel: "sessionStorage"
156
- });
157
- }
158
- //#endregion
159
- export { m as createLocalStorage, h as createSessionStorage };
160
-
1
+ import{VaultError as e,VaultQuotaError as t}from"../errors.js";import{isExpired as n,parseStored as r}from"../ttl.js";import{decodeRecord as i,encodeRecord as a}from"../codec.js";import{decodeStorageTableFromKey as o,encodeDbPrefix as s,encodeStorageKey as c,encodeStorageTablePrefix as l,getRecordKey as u}from"../internal.js";import{buildVaultStore as d}from"../adapter-core.js";var f=new Set([`QuotaExceededError`,`NS_ERROR_DOM_QUOTA_REACHED`]);function createWebStorageAdapter(p){let{getStorage:m,name:h,schema:g,storageLabel:_,codecs:v}=p;if(!v)throw new e(`${_} requires codecs for durable persistence`);let y;try{y=m()}catch(t){throw new e(`${_} is not available in this environment (private browsing or sandboxed iframe?)`,{cause:t})}let storage=()=>y,b=new Map(Object.keys(g).map(e=>[e,l(h,e)])),getPrefix=t=>{let n=b.get(t);if(!n)throw new e(`table "${t}" not in schema`);return n},writeItem=(e,n)=>{try{storage().setItem(e,JSON.stringify(n))}catch(e){throw e instanceof DOMException&&f.has(e.name)?new t(`${_} quota exceeded while writing record`,{cause:e}):e}},x=new Set,syncOwnedKeys=()=>{let e=s(h);x.clear();for(let t=0;t<y.length;t++){let n=y.key(t);n?.startsWith(e)&&x.add(n)}};syncOwnedKeys();let parseEntry=(t,a)=>{let o=storage().getItem(a);if(!o)return;let s;try{s=r(JSON.parse(o))}catch{return}if(s&&!n(s.expiresAt))try{return i(v[t],s.value)}catch(n){throw new e(`validation failed for table "${String(t)}"`,{cause:n})}},evict=e=>{storage().removeItem(e),x.delete(e)};return d(g,{async clear(e){syncOwnedKeys();let t=storage(),n=getPrefix(e),r=[];for(let e of x)e.startsWith(n)&&r.push(e);for(let e of r)t.removeItem(e),x.delete(e)},async delete(e,t){let n=c(h,e,t);return parseEntry(e,n)===void 0?(x.has(n)&&evict(n),!1):(evict(n),!0)},async get(e,t){let n=c(h,e,t),r=parseEntry(e,n);return r===void 0&&x.has(n)&&evict(n),r},async getAll(e){syncOwnedKeys();let t=[],n=[],r=getPrefix(e);for(let i of x){if(!i.startsWith(r))continue;let a=parseEntry(e,i);if(a===void 0){n.push(i);continue}t.push(a)}for(let e of n)evict(e);return t},async pruneExpiredInTable(e){syncOwnedKeys();let t=getPrefix(e),i=[];for(let e of x){if(!e.startsWith(t))continue;let a=storage().getItem(e);if(a===null){i.push(e);continue}try{let t=r(JSON.parse(a));(!t||n(t.expiresAt))&&i.push(e)}catch{i.push(e)}}for(let e of i)evict(e);return i.length},async put(e,t,n){let r=c(h,e,u(g,e,t)),i=n===void 0?void 0:Date.now()+n,o=a(v[e],t);writeItem(r,i===void 0?{value:o}:{expiresAt:i,value:o}),x.add(r)},async putAll(e,t,n){let r=n===void 0?void 0:Date.now()+n;for(let n of t){let t=c(h,e,u(g,e,n)),i=a(v[e],n);writeItem(t,r===void 0?{value:i}:{expiresAt:r,value:i}),x.add(t)}}},{codecs:v,onCrossTabMessage(e){if(typeof window>`u`||typeof window.addEventListener!=`function`)return;let listener=t=>{if(t.storageArea&&t.storageArea!==y)return;if(t.key===null){x.clear();for(let t of Object.keys(g))e(t);return}let n=o(h,t.key);n&&Object.hasOwn(g,n)&&(t.newValue===null?x.delete(t.key):x.add(t.key),e(n))};return window.addEventListener(`storage`,listener),()=>window.removeEventListener(`storage`,listener)},schema:g})}function createLocalStorage(e){return createWebStorageAdapter({...e,getStorage:()=>typeof window<`u`?window.localStorage:localStorage,storageLabel:`localStorage`})}function createSessionStorage(e){return createWebStorageAdapter({...e,getStorage:()=>typeof window<`u`?window.sessionStorage:sessionStorage,storageLabel:`sessionStorage`})}export{createLocalStorage,createSessionStorage};
161
2
  //# sourceMappingURL=webstorage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webstorage.js","names":[],"sources":["../../src/adapters/webstorage.ts"],"sourcesContent":["import { buildKeyValueStore, type StorageBackend } from '../adapter-core';\nimport { decodeRecord, encodeRecord } from '../codec';\nimport { VaultError, VaultQuotaError } from '../errors';\nimport {\n decodeStorageTableFromKey,\n encodeDbPrefix,\n encodeStorageKey,\n encodeStorageTablePrefix,\n getRecordKey,\n} from '../internal';\nimport { isExpired, parseStored, type StoredRecord } from '../ttl';\nimport type { AnySchema, DurableStoreOptions, KeyOf, KeyValueVaultStore, RecordOf } from '../types';\n\n// Firefox historically threw 'NS_ERROR_DOM_QUOTA_REACHED'; modern browsers use the standard name.\nconst QUOTA_ERROR_NAMES = new Set(['QuotaExceededError', 'NS_ERROR_DOM_QUOTA_REACHED']);\n\ntype WebStorageOptions<S extends AnySchema> = DurableStoreOptions<S> & {\n name: string;\n /**\n * Called when localStorage/sessionStorage quota is exceeded on a write.\n * Return `'ignore'` to silently drop the write, or `'throw'` (default) to rethrow the error.\n */\n onQuotaExceeded?: (table: keyof S, error: VaultQuotaError) => 'ignore' | 'throw';\n};\n\nfunction createWebStorageAdapter<S extends AnySchema>(\n options: WebStorageOptions<S> & {\n getStorage: () => Storage;\n storageLabel: string;\n },\n): KeyValueVaultStore<S> {\n const { getStorage, name, onQuotaExceeded, schema, storageLabel, codecs } = options;\n\n if (!codecs) {\n throw new VaultError(`${storageLabel} requires codecs for durable persistence`);\n }\n\n let resolvedStorage: Storage;\n\n try {\n resolvedStorage = getStorage();\n } catch (cause) {\n throw new VaultError(\n `${storageLabel} is not available in this environment (private browsing or sandboxed iframe?)`,\n {\n cause,\n },\n );\n }\n\n const storage = (): Storage => resolvedStorage;\n\n const prefixMap = new Map(Object.keys(schema).map((table) => [table, encodeStorageTablePrefix(name, table)]));\n const getPrefix = (table: string): string => {\n const cached = prefixMap.get(table);\n\n if (!cached) throw new VaultError(`table \"${table}\" not in schema`);\n\n return cached;\n };\n\n const writeItem = (table: keyof S, storageKey: string, value: unknown): void => {\n try {\n storage().setItem(storageKey, JSON.stringify(value));\n } catch (error) {\n if (error instanceof DOMException && QUOTA_ERROR_NAMES.has(error.name)) {\n const wrappedError = new VaultQuotaError(`${storageLabel} quota exceeded while writing record`, {\n cause: error,\n });\n\n if (onQuotaExceeded?.(table, wrappedError) === 'ignore') return;\n\n throw wrappedError;\n }\n\n throw error;\n }\n };\n\n // Per-instance registry of storage keys owned by this namespace.\n // Table-wide operations resynchronize it so same-window adapters stay consistent.\n const ownedKeys = new Set<string>();\n\n const syncOwnedKeys = (): void => {\n const dbPrefix = encodeDbPrefix(name);\n ownedKeys.clear();\n\n for (let i = 0; i < resolvedStorage.length; i++) {\n const key = resolvedStorage.key(i);\n\n if (key?.startsWith(dbPrefix)) ownedKeys.add(key);\n }\n };\n\n syncOwnedKeys();\n\n /**\n * Reads a single entry without side effects. Returns the decoded live value,\n * or `undefined` if missing/expired/corrupt.\n *\n * Callers that want to evict stale entries must call `evict(storageKey)` explicitly.\n */\n const parseEntry = <T extends object>(table: keyof S, storageKey: string): T | undefined => {\n const raw = storage().getItem(storageKey);\n\n if (!raw) return undefined;\n\n let stored: StoredRecord<unknown> | undefined;\n try {\n stored = parseStored<unknown>(JSON.parse(raw) as unknown);\n } catch {\n return undefined;\n }\n\n if (!stored || isExpired(stored.expiresAt)) return undefined;\n\n try {\n return decodeRecord(codecs[table], stored.value) as unknown as T;\n } catch (error) {\n throw new VaultError(`validation failed for table \"${String(table)}\"`, { cause: error });\n }\n };\n\n /** Removes a stale/expired/corrupt entry from storage and the owned-keys registry. */\n const evict = (storageKey: string): void => {\n storage().removeItem(storageKey);\n ownedKeys.delete(storageKey);\n };\n\n const core: StorageBackend<S> = {\n async clear<K extends keyof S & string>(table: K): Promise<void> {\n syncOwnedKeys();\n const target = storage();\n const prefix = getPrefix(table);\n const toRemove: string[] = [];\n\n for (const key of ownedKeys) {\n if (key.startsWith(prefix)) toRemove.push(key);\n }\n\n for (const key of toRemove) {\n target.removeItem(key);\n ownedKeys.delete(key);\n }\n },\n\n async delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean> {\n const storageKey = encodeStorageKey(name, table, key);\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value !== undefined) {\n evict(storageKey);\n\n return true;\n }\n\n if (ownedKeys.has(storageKey)) evict(storageKey);\n\n return false;\n },\n\n async get<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<RecordOf<S, K> | undefined> {\n const storageKey = encodeStorageKey(name, table, key);\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value === undefined && ownedKeys.has(storageKey)) evict(storageKey);\n\n return value;\n },\n\n async getAll<K extends keyof S & string>(table: K): Promise<RecordOf<S, K>[]> {\n syncOwnedKeys();\n const records: RecordOf<S, K>[] = [];\n const expiredKeys: string[] = [];\n const prefix = getPrefix(table);\n\n for (const storageKey of ownedKeys) {\n if (!storageKey.startsWith(prefix)) continue;\n\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value === undefined) {\n expiredKeys.push(storageKey);\n continue;\n }\n\n records.push(value);\n }\n\n for (const storageKey of expiredKeys) {\n evict(storageKey);\n }\n\n return records;\n },\n\n async pruneExpiredInTable<K extends keyof S & string>(table: K): Promise<number> {\n syncOwnedKeys();\n const prefix = getPrefix(table);\n const expiredKeys: string[] = [];\n\n for (const storageKey of ownedKeys) {\n if (!storageKey.startsWith(prefix)) continue;\n\n const raw = storage().getItem(storageKey);\n\n if (raw === null) {\n expiredKeys.push(storageKey);\n continue;\n }\n\n try {\n const stored = parseStored(JSON.parse(raw) as unknown);\n\n if (!stored || isExpired(stored.expiresAt)) {\n expiredKeys.push(storageKey);\n }\n } catch {\n expiredKeys.push(storageKey);\n }\n }\n\n for (const storageKey of expiredKeys) {\n evict(storageKey);\n }\n\n return expiredKeys.length;\n },\n\n async put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: number): Promise<void> {\n const storageKey = encodeStorageKey(name, table, getRecordKey(schema, table, value));\n const expiresAt = ttl !== undefined ? Date.now() + ttl : undefined;\n const encoded = encodeRecord(codecs[table], value);\n\n writeItem(table, storageKey, expiresAt === undefined ? { value: encoded } : { expiresAt, value: encoded });\n ownedKeys.add(storageKey);\n },\n\n async putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: number): Promise<void> {\n const expiresAt = ttl !== undefined ? Date.now() + ttl : undefined;\n\n for (const value of values) {\n const storageKey = encodeStorageKey(name, table, getRecordKey(schema, table, value));\n const encoded = encodeRecord(codecs[table], value);\n\n writeItem(table, storageKey, expiresAt === undefined ? { value: encoded } : { expiresAt, value: encoded });\n ownedKeys.add(storageKey);\n }\n },\n };\n\n return buildKeyValueStore(schema, core, {\n codecs,\n onCrossTabMessage(notify) {\n if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') {\n return undefined;\n }\n\n const listener = (event: StorageEvent) => {\n if (event.storageArea && event.storageArea !== resolvedStorage) return;\n\n if (event.key === null) {\n // storage.clear() from another tab — all keys are gone; purge ownedKeys\n ownedKeys.clear();\n\n for (const table of Object.keys(schema)) {\n notify(table as keyof S & string);\n }\n\n return;\n }\n\n const tableName = decodeStorageTableFromKey(name, event.key);\n\n if (tableName && Object.hasOwn(schema, tableName)) {\n if (event.newValue === null) {\n ownedKeys.delete(event.key);\n } else {\n ownedKeys.add(event.key);\n }\n\n notify(tableName as keyof S & string);\n }\n };\n\n window.addEventListener('storage', listener);\n\n return () => window.removeEventListener('storage', listener);\n },\n schema,\n });\n}\n\nexport function createLocalStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S> {\n return createWebStorageAdapter({\n ...options,\n getStorage: () => (typeof window !== 'undefined' ? window.localStorage : localStorage),\n storageLabel: 'localStorage',\n });\n}\n\nexport function createSessionStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S> {\n return createWebStorageAdapter({\n ...options,\n getStorage: () => (typeof window !== 'undefined' ? window.sessionStorage : sessionStorage),\n storageLabel: 'sessionStorage',\n });\n}\n"],"mappings":";;;;;;AAcA,IAAM,oBAAoB,IAAI,IAAI,CAAC,sBAAsB,4BAA4B,CAAC;AAWtF,SAAS,EACP,GAIuB;CACvB,IAAM,EAAE,eAAY,SAAM,oBAAiB,WAAQ,iBAAc,cAAW;CAE5E,IAAI,CAAC,GACH,MAAM,IAAI,EAAW,GAAG,EAAa,yCAAyC;CAGhF,IAAI;CAEJ,IAAI;EACF,IAAkB,EAAW;CAC/B,SAAS,GAAO;EACd,MAAM,IAAI,EACR,GAAG,EAAa,gFAChB,EACE,SACF,CACF;CACF;CAEA,IAAM,UAAyB,GAEzB,IAAY,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,CAAC,KAAK,MAAU,CAAC,GAAO,EAAyB,GAAM,CAAK,CAAC,CAAC,CAAC,GACtG,KAAa,MAA0B;EAC3C,IAAM,IAAS,EAAU,IAAI,CAAK;EAElC,IAAI,CAAC,GAAQ,MAAM,IAAI,EAAW,UAAU,EAAM,gBAAgB;EAElE,OAAO;CACT,GAEM,KAAa,GAAgB,GAAoB,MAAyB;EAC9E,IAAI;GACF,EAAQ,CAAC,CAAC,QAAQ,GAAY,KAAK,UAAU,CAAK,CAAC;EACrD,SAAS,GAAO;GACd,IAAI,aAAiB,gBAAgB,EAAkB,IAAI,EAAM,IAAI,GAAG;IACt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AG,GAGzB,EAAO,CAA6B;GAExC;GAIA,OAFA,OAAO,iBAAiB,WAAW,CAAQ,SAE9B,OAAO,oBAAoB,WAAW,CAAQ;EAC7D;EACA;CACF,CAAC;AACH;AAEA,SAAgB,EAAwC,GAAsD;CAC5G,OAAO,EAAwB;EAC7B,GAAG;EACH,kBAAmB,OAAO,SAAW,MAAc,OAAO,eAAe;EACzE,cAAc;CAChB,CAAC;AACH;AAEA,SAAgB,EAA0C,GAAsD;CAC9G,OAAO,EAAwB;EAC7B,GAAG;EACH,kBAAmB,OAAO,SAAW,MAAc,OAAO,iBAAiB;EAC3E,cAAc;CAChB,CAAC;AACH"}
1
+ {"version":3,"file":"webstorage.js","names":[],"sources":["../../src/adapters/webstorage.ts"],"sourcesContent":["import { buildVaultStore, type StorageBackend } from '../adapter-core';\nimport { decodeRecord, encodeRecord } from '../codec';\nimport { VaultError, VaultQuotaError } from '../errors';\nimport {\n decodeStorageTableFromKey,\n encodeDbPrefix,\n encodeStorageKey,\n encodeStorageTablePrefix,\n getRecordKey,\n} from '../internal';\nimport { isExpired, parseStored, type StoredRecord } from '../ttl';\nimport type { AnySchema, DurableStoreOptions, KeyOf, KeyValueVaultStore, RecordOf } from '../types';\n\n// Firefox historically threw 'NS_ERROR_DOM_QUOTA_REACHED'; modern browsers use the standard name.\nconst QUOTA_ERROR_NAMES = new Set(['QuotaExceededError', 'NS_ERROR_DOM_QUOTA_REACHED']);\n\ntype WebStorageOptions<S extends AnySchema> = DurableStoreOptions<S> & {\n name: string;\n};\n\nfunction createWebStorageAdapter<S extends AnySchema>(\n options: WebStorageOptions<S> & {\n getStorage: () => Storage;\n storageLabel: string;\n },\n): KeyValueVaultStore<S> {\n const { getStorage, name, schema, storageLabel, codecs } = options;\n\n if (!codecs) {\n throw new VaultError(`${storageLabel} requires codecs for durable persistence`);\n }\n\n let resolvedStorage: Storage;\n\n try {\n resolvedStorage = getStorage();\n } catch (cause) {\n throw new VaultError(\n `${storageLabel} is not available in this environment (private browsing or sandboxed iframe?)`,\n {\n cause,\n },\n );\n }\n\n const storage = (): Storage => resolvedStorage;\n\n const prefixMap = new Map(Object.keys(schema).map((table) => [table, encodeStorageTablePrefix(name, table)]));\n const getPrefix = (table: string): string => {\n const cached = prefixMap.get(table);\n\n if (!cached) throw new VaultError(`table \"${table}\" not in schema`);\n\n return cached;\n };\n\n const writeItem = (storageKey: string, value: unknown): void => {\n try {\n storage().setItem(storageKey, JSON.stringify(value));\n } catch (error) {\n if (error instanceof DOMException && QUOTA_ERROR_NAMES.has(error.name)) {\n throw new VaultQuotaError(`${storageLabel} quota exceeded while writing record`, { cause: error });\n }\n\n throw error;\n }\n };\n\n // Per-instance registry of storage keys owned by this namespace.\n // Table-wide operations resynchronize it so same-window adapters stay consistent.\n const ownedKeys = new Set<string>();\n\n const syncOwnedKeys = (): void => {\n const dbPrefix = encodeDbPrefix(name);\n ownedKeys.clear();\n\n for (let i = 0; i < resolvedStorage.length; i++) {\n const key = resolvedStorage.key(i);\n\n if (key?.startsWith(dbPrefix)) ownedKeys.add(key);\n }\n };\n\n syncOwnedKeys();\n\n /**\n * Reads a single entry without side effects. Returns the decoded live value,\n * or `undefined` if missing/expired/corrupt.\n *\n * Callers that want to evict stale entries must call `evict(storageKey)` explicitly.\n */\n const parseEntry = <T extends object>(table: keyof S, storageKey: string): T | undefined => {\n const raw = storage().getItem(storageKey);\n\n if (!raw) return undefined;\n\n let stored: StoredRecord<unknown> | undefined;\n try {\n stored = parseStored<unknown>(JSON.parse(raw) as unknown);\n } catch {\n return undefined;\n }\n\n if (!stored || isExpired(stored.expiresAt)) return undefined;\n\n try {\n return decodeRecord(codecs[table], stored.value) as unknown as T;\n } catch (error) {\n throw new VaultError(`validation failed for table \"${String(table)}\"`, { cause: error });\n }\n };\n\n /** Removes a stale/expired/corrupt entry from storage and the owned-keys registry. */\n const evict = (storageKey: string): void => {\n storage().removeItem(storageKey);\n ownedKeys.delete(storageKey);\n };\n\n const core: StorageBackend<S> = {\n async clear<K extends keyof S & string>(table: K): Promise<void> {\n syncOwnedKeys();\n const target = storage();\n const prefix = getPrefix(table);\n const toRemove: string[] = [];\n\n for (const key of ownedKeys) {\n if (key.startsWith(prefix)) toRemove.push(key);\n }\n\n for (const key of toRemove) {\n target.removeItem(key);\n ownedKeys.delete(key);\n }\n },\n\n async delete<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<boolean> {\n const storageKey = encodeStorageKey(name, table, key);\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value !== undefined) {\n evict(storageKey);\n\n return true;\n }\n\n if (ownedKeys.has(storageKey)) evict(storageKey);\n\n return false;\n },\n\n async get<K extends keyof S & string>(table: K, key: KeyOf<S, K>): Promise<RecordOf<S, K> | undefined> {\n const storageKey = encodeStorageKey(name, table, key);\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value === undefined && ownedKeys.has(storageKey)) evict(storageKey);\n\n return value;\n },\n\n async getAll<K extends keyof S & string>(table: K): Promise<RecordOf<S, K>[]> {\n syncOwnedKeys();\n const records: RecordOf<S, K>[] = [];\n const expiredKeys: string[] = [];\n const prefix = getPrefix(table);\n\n for (const storageKey of ownedKeys) {\n if (!storageKey.startsWith(prefix)) continue;\n\n const value = parseEntry<RecordOf<S, K>>(table, storageKey);\n\n if (value === undefined) {\n expiredKeys.push(storageKey);\n continue;\n }\n\n records.push(value);\n }\n\n for (const storageKey of expiredKeys) {\n evict(storageKey);\n }\n\n return records;\n },\n\n async pruneExpiredInTable<K extends keyof S & string>(table: K): Promise<number> {\n syncOwnedKeys();\n const prefix = getPrefix(table);\n const expiredKeys: string[] = [];\n\n for (const storageKey of ownedKeys) {\n if (!storageKey.startsWith(prefix)) continue;\n\n const raw = storage().getItem(storageKey);\n\n if (raw === null) {\n expiredKeys.push(storageKey);\n continue;\n }\n\n try {\n const stored = parseStored(JSON.parse(raw) as unknown);\n\n if (!stored || isExpired(stored.expiresAt)) {\n expiredKeys.push(storageKey);\n }\n } catch {\n expiredKeys.push(storageKey);\n }\n }\n\n for (const storageKey of expiredKeys) {\n evict(storageKey);\n }\n\n return expiredKeys.length;\n },\n\n async put<K extends keyof S & string>(table: K, value: RecordOf<S, K>, ttl?: number): Promise<void> {\n const storageKey = encodeStorageKey(name, table, getRecordKey(schema, table, value));\n const expiresAt = ttl !== undefined ? Date.now() + ttl : undefined;\n const encoded = encodeRecord(codecs[table], value);\n\n writeItem(storageKey, expiresAt === undefined ? { value: encoded } : { expiresAt, value: encoded });\n ownedKeys.add(storageKey);\n },\n\n async putAll<K extends keyof S & string>(table: K, values: RecordOf<S, K>[], ttl?: number): Promise<void> {\n const expiresAt = ttl !== undefined ? Date.now() + ttl : undefined;\n\n for (const value of values) {\n const storageKey = encodeStorageKey(name, table, getRecordKey(schema, table, value));\n const encoded = encodeRecord(codecs[table], value);\n\n writeItem(storageKey, expiresAt === undefined ? { value: encoded } : { expiresAt, value: encoded });\n ownedKeys.add(storageKey);\n }\n },\n };\n\n return buildVaultStore(schema, core, {\n codecs,\n onCrossTabMessage(notify) {\n if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') {\n return undefined;\n }\n\n const listener = (event: StorageEvent) => {\n if (event.storageArea && event.storageArea !== resolvedStorage) return;\n\n if (event.key === null) {\n // storage.clear() from another tab — all keys are gone; purge ownedKeys\n ownedKeys.clear();\n\n for (const table of Object.keys(schema)) {\n notify(table as keyof S & string);\n }\n\n return;\n }\n\n const tableName = decodeStorageTableFromKey(name, event.key);\n\n if (tableName && Object.hasOwn(schema, tableName)) {\n if (event.newValue === null) {\n ownedKeys.delete(event.key);\n } else {\n ownedKeys.add(event.key);\n }\n\n notify(tableName as keyof S & string);\n }\n };\n\n window.addEventListener('storage', listener);\n\n return () => window.removeEventListener('storage', listener);\n },\n schema,\n });\n}\n\nexport function createLocalStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S> {\n return createWebStorageAdapter({\n ...options,\n getStorage: () => (typeof window !== 'undefined' ? window.localStorage : localStorage),\n storageLabel: 'localStorage',\n });\n}\n\nexport function createSessionStorage<S extends AnySchema>(options: WebStorageOptions<S>): KeyValueVaultStore<S> {\n return createWebStorageAdapter({\n ...options,\n getStorage: () => (typeof window !== 'undefined' ? window.sessionStorage : sessionStorage),\n storageLabel: 'sessionStorage',\n });\n}\n"],"mappings":"6XAcA,IAAM,EAAoB,IAAI,IAAI,CAAC,qBAAsB,4BAA4B,CAAC,EAMtF,SAAS,wBACP,EAIuB,CACvB,GAAM,CAAE,aAAY,OAAM,SAAQ,eAAc,UAAW,EAE3D,GAAI,CAAC,EACH,MAAM,IAAI,EAAW,GAAG,EAAa,yCAAyC,EAGhF,IAAI,EAEJ,GAAI,CACF,EAAkB,EAAW,CAC/B,OAAS,EAAO,CACd,MAAM,IAAI,EACR,GAAG,EAAa,+EAChB,CACE,OACF,CACF,CACF,CAEA,IAAM,YAAyB,EAEzB,EAAY,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,CAAC,IAAK,GAAU,CAAC,EAAO,EAAyB,EAAM,CAAK,CAAC,CAAC,CAAC,EACtG,UAAa,GAA0B,CAC3C,IAAM,EAAS,EAAU,IAAI,CAAK,EAElC,GAAI,CAAC,EAAQ,MAAM,IAAI,EAAW,UAAU,EAAM,gBAAgB,EAElE,OAAO,CACT,EAEM,WAAa,EAAoB,IAAyB,CAC9D,GAAI,CACF,QAAQ,CAAC,CAAC,QAAQ,EAAY,KAAK,UAAU,CAAK,CAAC,CACrD,OAAS,EAAO,CAKd,MAJI,aAAiB,cAAgB,EAAkB,IAAI,EAAM,IAAI,EAC7D,IAAI,EAAgB,GAAG,EAAa,sCAAuC,CAAE,MAAO,CAAM,CAAC,EAG7F,CACR,CACF,EAIM,EAAY,IAAI,IAEhB,kBAA4B,CAChC,IAAM,EAAW,EAAe,CAAI,EACpC,EAAU,MAAM,EAEhB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAgB,OAAQ,IAAK,CAC/C,IAAM,EAAM,EAAgB,IAAI,CAAC,E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AAC,CACH"}
package/dist/codec.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=e=>`encode`in e&&`decode`in e,t=(t,n)=>e(t)?t.encode(n):n,n=(t,n)=>e(t)?t.decode(n):t.parse(n),r=(t,n)=>e(t)?t.decode(t.encode(n)):t.parse(n);exports.decodeRecord=n,exports.encodeRecord=t,exports.validateRecord=r;
1
+ var isCodec=e=>`encode`in e&&`decode`in e,encodeRecord=(e,t)=>isCodec(e)?e.encode(t):t,decodeRecord=(e,t)=>isCodec(e)?e.decode(t):e.parse(t),validateRecord=(e,t)=>isCodec(e)?e.decode(e.encode(t)):e.parse(t);exports.decodeRecord=decodeRecord,exports.encodeRecord=encodeRecord,exports.validateRecord=validateRecord;
2
2
  //# sourceMappingURL=codec.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"codec.cjs","names":[],"sources":["../src/codec.ts"],"sourcesContent":["import type { CodecInput, RecordCodec } from './types';\n\nconst isCodec = <T>(input: CodecInput<T>): input is RecordCodec<T> => 'encode' in input && 'decode' in input;\n\nexport const encodeRecord = <T>(input: CodecInput<T>, value: T): unknown =>\n isCodec(input) ? input.encode(value) : value;\n\nexport const decodeRecord = <T>(input: CodecInput<T>, value: unknown): T =>\n isCodec(input) ? input.decode(value) : input.parse(value);\n\nexport const validateRecord = <T>(input: CodecInput<T>, value: T): T =>\n isCodec(input) ? input.decode(input.encode(value)) : input.parse(value);\n"],"mappings":"AAEA,IAAM,EAAc,GAAkD,WAAY,GAAS,WAAY,EAE1F,GAAmB,EAAsB,IACpD,EAAQ,CAAK,EAAI,EAAM,OAAO,CAAK,EAAI,EAE5B,GAAmB,EAAsB,IACpD,EAAQ,CAAK,EAAI,EAAM,OAAO,CAAK,EAAI,EAAM,MAAM,CAAK,EAE7C,GAAqB,EAAsB,IACtD,EAAQ,CAAK,EAAI,EAAM,OAAO,EAAM,OAAO,CAAK,CAAC,EAAI,EAAM,MAAM,CAAK"}
1
+ {"version":3,"file":"codec.cjs","names":[],"sources":["../src/codec.ts"],"sourcesContent":["import type { CodecInput, RecordCodec } from './types';\n\nconst isCodec = <T>(input: CodecInput<T>): input is RecordCodec<T> => 'encode' in input && 'decode' in input;\n\nexport const encodeRecord = <T>(input: CodecInput<T>, value: T): unknown =>\n isCodec(input) ? input.encode(value) : value;\n\nexport const decodeRecord = <T>(input: CodecInput<T>, value: unknown): T =>\n isCodec(input) ? input.decode(value) : input.parse(value);\n\nexport const validateRecord = <T>(input: CodecInput<T>, value: T): T =>\n isCodec(input) ? input.decode(input.encode(value)) : input.parse(value);\n"],"mappings":"AAEA,IAAM,QAAc,GAAkD,WAAY,GAAS,WAAY,EAE1F,cAAmB,EAAsB,IACpD,QAAQ,CAAK,EAAI,EAAM,OAAO,CAAK,EAAI,EAE5B,cAAmB,EAAsB,IACpD,QAAQ,CAAK,EAAI,EAAM,OAAO,CAAK,EAAI,EAAM,MAAM,CAAK,EAE7C,gBAAqB,EAAsB,IACtD,QAAQ,CAAK,EAAI,EAAM,OAAO,EAAM,OAAO,CAAK,CAAC,EAAI,EAAM,MAAM,CAAK"}
package/dist/codec.js CHANGED
@@ -1,6 +1,2 @@
1
- //#region src/codec.ts
2
- var e = (e) => "encode" in e && "decode" in e, t = (t, n) => e(t) ? t.encode(n) : n, n = (t, n) => e(t) ? t.decode(n) : t.parse(n), r = (t, n) => e(t) ? t.decode(t.encode(n)) : t.parse(n);
3
- //#endregion
4
- export { n as decodeRecord, t as encodeRecord, r as validateRecord };
5
-
1
+ var isCodec=e=>`encode`in e&&`decode`in e,encodeRecord=(e,t)=>isCodec(e)?e.encode(t):t,decodeRecord=(e,t)=>isCodec(e)?e.decode(t):e.parse(t),validateRecord=(e,t)=>isCodec(e)?e.decode(e.encode(t)):e.parse(t);export{decodeRecord,encodeRecord,validateRecord};
6
2
  //# sourceMappingURL=codec.js.map
package/dist/codec.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"codec.js","names":[],"sources":["../src/codec.ts"],"sourcesContent":["import type { CodecInput, RecordCodec } from './types';\n\nconst isCodec = <T>(input: CodecInput<T>): input is RecordCodec<T> => 'encode' in input && 'decode' in input;\n\nexport const encodeRecord = <T>(input: CodecInput<T>, value: T): unknown =>\n isCodec(input) ? input.encode(value) : value;\n\nexport const decodeRecord = <T>(input: CodecInput<T>, value: unknown): T =>\n isCodec(input) ? input.decode(value) : input.parse(value);\n\nexport const validateRecord = <T>(input: CodecInput<T>, value: T): T =>\n isCodec(input) ? input.decode(input.encode(value)) : input.parse(value);\n"],"mappings":";AAEA,IAAM,KAAc,MAAkD,YAAY,KAAS,YAAY,GAE1F,KAAmB,GAAsB,MACpD,EAAQ,CAAK,IAAI,EAAM,OAAO,CAAK,IAAI,GAE5B,KAAmB,GAAsB,MACpD,EAAQ,CAAK,IAAI,EAAM,OAAO,CAAK,IAAI,EAAM,MAAM,CAAK,GAE7C,KAAqB,GAAsB,MACtD,EAAQ,CAAK,IAAI,EAAM,OAAO,EAAM,OAAO,CAAK,CAAC,IAAI,EAAM,MAAM,CAAK"}
1
+ {"version":3,"file":"codec.js","names":[],"sources":["../src/codec.ts"],"sourcesContent":["import type { CodecInput, RecordCodec } from './types';\n\nconst isCodec = <T>(input: CodecInput<T>): input is RecordCodec<T> => 'encode' in input && 'decode' in input;\n\nexport const encodeRecord = <T>(input: CodecInput<T>, value: T): unknown =>\n isCodec(input) ? input.encode(value) : value;\n\nexport const decodeRecord = <T>(input: CodecInput<T>, value: unknown): T =>\n isCodec(input) ? input.decode(value) : input.parse(value);\n\nexport const validateRecord = <T>(input: CodecInput<T>, value: T): T =>\n isCodec(input) ? input.decode(input.encode(value)) : input.parse(value);\n"],"mappings":"AAEA,IAAM,QAAc,GAAkD,WAAY,GAAS,WAAY,EAE1F,cAAmB,EAAsB,IACpD,QAAQ,CAAK,EAAI,EAAM,OAAO,CAAK,EAAI,EAE5B,cAAmB,EAAsB,IACpD,QAAQ,CAAK,EAAI,EAAM,OAAO,CAAK,EAAI,EAAM,MAAM,CAAK,EAE7C,gBAAqB,EAAsB,IACtD,QAAQ,CAAK,EAAI,EAAM,OAAO,EAAM,OAAO,CAAK,CAAC,EAAI,EAAM,MAAM,CAAK"}
package/dist/errors.cjs CHANGED
@@ -1,2 +1,2 @@
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`};exports.VaultDisposedError=t,exports.VaultError=e,exports.VaultMigrationError=i,exports.VaultQuotaError=r,exports.VaultScopeError=n;
1
+ var VaultError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},VaultDisposedError=class extends VaultError{constructor(e=`adapter is disposed`,t){super(e,t)}},VaultScopeError=class extends VaultError{},VaultQuotaError=class extends VaultError{},VaultMigrationError=class extends VaultError{};exports.VaultDisposedError=VaultDisposedError,exports.VaultError=VaultError,exports.VaultMigrationError=VaultMigrationError,exports.VaultQuotaError=VaultQuotaError,exports.VaultScopeError=VaultScopeError;
2
2
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.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"],"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"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.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"],"mappings":"AAIA,IAAa,WAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KAEvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,mBAAb,cAAwC,UAAW,CACjD,YAAY,EAAU,sBAAuB,EAAqB,CAChE,MAAM,EAAS,CAAI,CACrB,CACF,EAGa,gBAAb,cAAqC,UAAW,CAAC,EAGpC,gBAAb,cAAqC,UAAW,CAAC,EAGpC,oBAAb,cAAyC,UAAW,CAAC"}
package/dist/errors.d.ts CHANGED
@@ -3,24 +3,19 @@
3
3
  * handle any vault-originated error regardless of its specific subtype.
4
4
  */
5
5
  export declare class VaultError extends Error {
6
- protected static readonly errorName: string;
7
6
  constructor(message: string, opts?: ErrorOptions);
8
7
  }
9
8
  /** Thrown when an operation is attempted on a disposed adapter or observer hub. */
10
9
  export declare class VaultDisposedError extends VaultError {
11
- protected static readonly errorName = "VaultDisposedError";
12
10
  constructor(message?: string, opts?: ErrorOptions);
13
11
  }
14
12
  /** Thrown when a `batch()` callback accesses a table not declared in the scope. */
15
13
  export declare class VaultScopeError extends VaultError {
16
- protected static readonly errorName = "VaultScopeError";
17
14
  }
18
15
  /** Thrown when a WebStorage write exceeds the storage quota. */
19
16
  export declare class VaultQuotaError extends VaultError {
20
- protected static readonly errorName = "VaultQuotaError";
21
17
  }
22
18
  /** Thrown when an IndexedDB `onupgradeneeded` migration callback throws. */
23
19
  export declare class VaultMigrationError extends VaultError {
24
- protected static readonly errorName = "VaultMigrationError";
25
20
  }
26
21
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAgB;gBAE/C,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAMjD;AAED,mFAAmF;AACnF,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,0BAAmC,SAAS,wBAAwB;gBAExD,OAAO,SAAwB,EAAE,IAAI,CAAC,EAAE,YAAY;CAGjE;AAED,mFAAmF;AACnF,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,0BAAmC,SAAS,qBAAqB;CAClE;AAED,gEAAgE;AAChE,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,0BAAmC,SAAS,qBAAqB;CAClE;AAED,4EAA4E;AAC5E,qBAAa,mBAAoB,SAAQ,UAAU;IACjD,0BAAmC,SAAS,yBAAyB;CACtE"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAMjD;AAED,mFAAmF;AACnF,qBAAa,kBAAmB,SAAQ,UAAU;gBACpC,OAAO,SAAwB,EAAE,IAAI,CAAC,EAAE,YAAY;CAGjE;AAED,mFAAmF;AACnF,qBAAa,eAAgB,SAAQ,UAAU;CAAG;AAElD,gEAAgE;AAChE,qBAAa,eAAgB,SAAQ,UAAU;CAAG;AAElD,4EAA4E;AAC5E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG"}
package/dist/errors.js CHANGED
@@ -1,22 +1,2 @@
1
- //#region src/errors.ts
2
- var e = class extends Error {
3
- static errorName = "VaultError";
4
- constructor(e, t) {
5
- super(e, t), this.name = new.target.errorName, Object.setPrototypeOf(this, new.target.prototype);
6
- }
7
- }, t = class extends e {
8
- static errorName = "VaultDisposedError";
9
- constructor(e = "adapter is disposed", t) {
10
- super(e, t);
11
- }
12
- }, n = class extends e {
13
- static errorName = "VaultScopeError";
14
- }, r = class extends e {
15
- static errorName = "VaultQuotaError";
16
- }, i = class extends e {
17
- static errorName = "VaultMigrationError";
18
- };
19
- //#endregion
20
- export { t as VaultDisposedError, e as VaultError, i as VaultMigrationError, r as VaultQuotaError, n as VaultScopeError };
21
-
1
+ var VaultError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},VaultDisposedError=class extends VaultError{constructor(e=`adapter is disposed`,t){super(e,t)}},VaultScopeError=class extends VaultError{},VaultQuotaError=class extends VaultError{},VaultMigrationError=class extends VaultError{};export{VaultDisposedError,VaultError,VaultMigrationError,VaultQuotaError,VaultScopeError};
22
2
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.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"],"mappings":";AAIA,IAAa,IAAb,cAAgC,MAAM;CACpC,OAA0B,YAAoB;CAE9C,YAAY,GAAiB,GAAqB;EAIhD,AAHA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAQ,WAAiC,WAE9C,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,IAAb,cAAwC,EAAW;CACjD,OAAmC,YAAY;CAE/C,YAAY,IAAU,uBAAuB,GAAqB;EAChE,MAAM,GAAS,CAAI;CACrB;AACF,GAGa,IAAb,cAAqC,EAAW;CAC9C,OAAmC,YAAY;AACjD,GAGa,IAAb,cAAqC,EAAW;CAC9C,OAAmC,YAAY;AACjD,GAGa,IAAb,cAAyC,EAAW;CAClD,OAAmC,YAAY;AACjD"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.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"],"mappings":"AAIA,IAAa,WAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KAEvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,mBAAb,cAAwC,UAAW,CACjD,YAAY,EAAU,sBAAuB,EAAqB,CAChE,MAAM,EAAS,CAAI,CACrB,CACF,EAGa,gBAAb,cAAqC,UAAW,CAAC,EAGpC,gBAAb,cAAqC,UAAW,CAAC,EAGpC,oBAAb,cAAyC,UAAW,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./ttl.cjs"),n=require("./adapter-core.cjs"),r=require("./types.cjs");exports.VaultDisposedError=e.VaultDisposedError,exports.VaultError=e.VaultError,exports.VaultMigrationError=e.VaultMigrationError,exports.VaultQuotaError=e.VaultQuotaError,exports.VaultScopeError=e.VaultScopeError,exports.count=n.count,exports.deleteMany=n.deleteMany,exports.getMany=n.getMany,exports.has=n.has,exports.isEmpty=n.isEmpty,exports.isExpired=t.isExpired,exports.keys=n.keys,exports.table=r.table,exports.ttl=t.ttl,exports.update=n.update,exports.upsert=n.upsert,exports.validatorCodec=r.validatorCodec;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./ttl.cjs"),n=require("./types.cjs");exports.VaultDisposedError=e.VaultDisposedError,exports.VaultError=e.VaultError,exports.VaultMigrationError=e.VaultMigrationError,exports.VaultQuotaError=e.VaultQuotaError,exports.VaultScopeError=e.VaultScopeError,exports.table=n.table,exports.ttl=t.ttl,exports.validatorCodec=n.validatorCodec;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- export { count, deleteMany, getMany, has, isEmpty, keys, update, upsert, } from './adapter-core';
2
1
  export { VaultDisposedError, VaultError, VaultMigrationError, VaultQuotaError, VaultScopeError } from './errors';
3
- export type { QueryBuilder } from './query';
4
- export { isExpired, ttl } from './ttl';
2
+ export { ttl } from './ttl';
5
3
  export type { AnySchema, CodecInput, DocumentVaultStore, DurableStoreOptions, KeyOf, KeyValueVaultStore, MemoryStoreOptions, Observer, RecordCodec, RecordOf, RecordParser, SchemaEntry, TableCodecs, TransactionContext, Unsubscribe, VaultConveniences, VaultKey, } from './types';
6
4
  export { table, validatorCodec } from './types';
7
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,UAAU,EACV,OAAO,EACP,GAAG,EACH,OAAO,EACP,IAAI,EACJ,MAAM,EACN,MAAM,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACjH,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,YAAY,EACV,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,EACL,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACjH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,YAAY,EACV,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,EACL,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1 @@
1
- import { VaultDisposedError as e, VaultError as t, VaultMigrationError as n, VaultQuotaError as r, VaultScopeError as i } from "./errors.js";
2
- import { isExpired as a, ttl as o } from "./ttl.js";
3
- import { count as s, deleteMany as c, getMany as l, has as u, isEmpty as d, keys as f, update as p, upsert as m } from "./adapter-core.js";
4
- import { table as h, validatorCodec as g } from "./types.js";
5
- export { e as VaultDisposedError, t as VaultError, n as VaultMigrationError, r as VaultQuotaError, i as VaultScopeError, s as count, c as deleteMany, l as getMany, u as has, d as isEmpty, a as isExpired, f as keys, h as table, o as ttl, p as update, m as upsert, g as validatorCodec };
1
+ import{VaultDisposedError as e,VaultError as t,VaultMigrationError as n,VaultQuotaError as r,VaultScopeError as i}from"./errors.js";import{ttl as a}from"./ttl.js";import{table as o,validatorCodec as s}from"./types.js";export{e as VaultDisposedError,t as VaultError,n as VaultMigrationError,r as VaultQuotaError,i as VaultScopeError,o as table,a as ttl,s as validatorCodec};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./adapters/indexeddb.cjs");exports.createIndexedDB=e.createIndexedDB,exports.defineMigration=e.defineMigration;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./adapters/indexeddb.cjs");exports.createIndexedDB=e.createIndexedDB;
@@ -1,4 +1,4 @@
1
- export type { MigrationContext, MigrationFn, MigrationStep } from './adapters/indexeddb';
2
- export { createIndexedDB, defineMigration } from './adapters/indexeddb';
1
+ export type { MigrationContext, MigrationFn } from './adapters/indexeddb';
2
+ export { createIndexedDB } from './adapters/indexeddb';
3
3
  export type { TransactionContext } from './types';
4
4
  //# sourceMappingURL=indexeddb.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../src/indexeddb.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACxE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../src/indexeddb.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
package/dist/indexeddb.js CHANGED
@@ -1,2 +1 @@
1
- import { createIndexedDB as e, defineMigration as t } from "./adapters/indexeddb.js";
2
- export { e as createIndexedDB, t as defineMigration };
1
+ import{createIndexedDB as e}from"./adapters/indexeddb.js";export{e as createIndexedDB};
package/dist/internal.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs");var t=`\0`;function n(t){if(typeof t==`number`){if(!Number.isFinite(t))throw new e.VaultError(`primary key must be a finite number, received ${String(t)}`);return`n:${String(t)}`}return`s:${encodeURIComponent(t)}`}function r(e){return`${encodeURIComponent(e)}${t}`}function i(e,r,i){return`${encodeURIComponent(e)}${t}${encodeURIComponent(r)}${t}${n(i)}`}function a(e,n){return`${encodeURIComponent(e)}${t}${encodeURIComponent(n)}${t}`}function o(e,n){if(!n)return;let i=r(e);if(!n.startsWith(i))return;let a=n.slice(i.length),o=a.indexOf(t);if(o!==-1)try{return decodeURIComponent(a.slice(0,o))}catch{return}}function s(t){let n=new Map,r=new Map,i=!1,a=e=>{if(i)return;let a=(r.get(e)??0)+1;r.set(e,a);let o=n.get(e);o&&o.size!==0&&t(e).then(t=>{if(i||r.get(e)!==a)return;let o=n.get(e);if(o&&o.size!==0)for(let e of o)try{e(t)}catch{}}).catch(()=>{})};return{dispose:()=>{i=!0,n.clear(),r.clear()},notify:a,observe:(t,r,{immediate:o=!0,signal:s}={})=>{if(i)throw new e.VaultDisposedError(`observer hub is disposed`);if(s?.aborted)return()=>{};let c=r,l=n.get(t)??new Set;n.set(t,l),l.add(c),o&&a(t);let u=()=>{s?.removeEventListener(`abort`,u);let e=n.get(t);e&&(e.delete(c),e.size===0&&n.delete(t))};return s?.addEventListener(`abort`,u,{once:!0}),u}}}function c(t,n,r){let i=String(t[n].key),a=r[i];if(typeof a!=`number`&&typeof a!=`string`)throw new e.VaultError(`record in table "${String(n)}" must have a string or finite-number key at "${i}"`);if(typeof a==`number`&&!Number.isFinite(a))throw new e.VaultError(`record in table "${String(n)}" must have a finite-number key at "${i}"`);return a}exports.createObserverHub=s,exports.decodeStorageTableFromKey=o,exports.encodeDbPrefix=r,exports.encodeStorageKey=i,exports.encodeStorageTablePrefix=a,exports.encodeVaultKey=n,exports.getRecordKey=c;
1
+ const e=require("./errors.cjs");var t=`\0`;function encodeVaultKey(t){if(typeof t==`number`){if(!Number.isFinite(t))throw new e.VaultError(`primary key must be a finite number, received ${String(t)}`);return`n:${String(t)}`}return`s:${encodeURIComponent(t)}`}function encodeDbPrefix(e){return`${encodeURIComponent(e)}${t}`}function encodeStorageKey(e,n,r){return`${encodeURIComponent(e)}${t}${encodeURIComponent(n)}${t}${encodeVaultKey(r)}`}function encodeStorageTablePrefix(e,n){return`${encodeURIComponent(e)}${t}${encodeURIComponent(n)}${t}`}function decodeStorageTableFromKey(e,n){if(!n)return;let r=encodeDbPrefix(e);if(!n.startsWith(r))return;let i=n.slice(r.length),a=i.indexOf(t);if(a!==-1)try{return decodeURIComponent(i.slice(0,a))}catch{return}}function createObserverHub(t){let n=new Map,r=new Map,i=!1,notify=e=>{if(i)return;let a=(r.get(e)??0)+1;r.set(e,a);let o=n.get(e);o&&o.size!==0&&t(e).then(t=>{if(i||r.get(e)!==a)return;let o=n.get(e);if(o&&o.size!==0)for(let e of o)try{e(t)}catch{}}).catch(()=>{})},observe=(t,r,{immediate:a=!0,signal:o}={})=>{if(i)throw new e.VaultDisposedError(`observer hub is disposed`);if(o?.aborted)return()=>{};let s=r,c=n.get(t)??new Set;n.set(t,c),c.add(s),a&&notify(t);let stop=()=>{o?.removeEventListener(`abort`,stop);let e=n.get(t);e&&(e.delete(s),e.size===0&&n.delete(t))};return o?.addEventListener(`abort`,stop,{once:!0}),stop};return{dispose:()=>{i=!0,n.clear(),r.clear()},notify,observe}}function getRecordKey(t,n,r){let i=String(t[n].key),a=r[i];if(typeof a!=`number`&&typeof a!=`string`)throw new e.VaultError(`record in table "${String(n)}" must have a string or finite-number key at "${i}"`);if(typeof a==`number`&&!Number.isFinite(a))throw new e.VaultError(`record in table "${String(n)}" must have a finite-number key at "${i}"`);return a}exports.createObserverHub=createObserverHub,exports.decodeStorageTableFromKey=decodeStorageTableFromKey,exports.encodeDbPrefix=encodeDbPrefix,exports.encodeStorageKey=encodeStorageKey,exports.encodeStorageTablePrefix=encodeStorageTablePrefix,exports.encodeVaultKey=encodeVaultKey,exports.getRecordKey=getRecordKey;
2
2
  //# sourceMappingURL=internal.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.cjs","names":[],"sources":["../src/internal.ts"],"sourcesContent":["import { VaultDisposedError, VaultError } from './errors';\nimport type { AnySchema, KeyOf, RecordOf, VaultKey } from './types';\n\ntype ObserverListener<T> = (records: T[]) => void;\n\nconst SEP = '\\x00';\n\n/**\n * Type-tagged keys make `1` and `'1'` distinct in string-keyed adapters while\n * keeping the same portable primary-key contract as IndexedDB.\n */\nexport function encodeVaultKey(key: VaultKey): string {\n if (typeof key === 'number') {\n if (!Number.isFinite(key)) throw new VaultError(`primary key must be a finite number, received ${String(key)}`);\n\n return `n:${String(key)}`;\n }\n\n return `s:${encodeURIComponent(key)}`;\n}\n\nexport function encodeDbPrefix(dbName: string): string {\n return `${encodeURIComponent(dbName)}${SEP}`;\n}\n\nexport function encodeStorageKey(dbName: string, table: string, key: VaultKey): string {\n return `${encodeURIComponent(dbName)}${SEP}${encodeURIComponent(table)}${SEP}${encodeVaultKey(key)}`;\n}\n\nexport function encodeStorageTablePrefix(dbName: string, table: string): string {\n return `${encodeURIComponent(dbName)}${SEP}${encodeURIComponent(table)}${SEP}`;\n}\n\nexport function decodeStorageTableFromKey(dbName: string, storageKey: string | null): string | undefined {\n if (!storageKey) return undefined;\n\n const prefix = encodeDbPrefix(dbName);\n\n if (!storageKey.startsWith(prefix)) return undefined;\n\n const tail = storageKey.slice(prefix.length);\n const end = tail.indexOf(SEP);\n\n if (end === -1) return undefined;\n\n try {\n return decodeURIComponent(tail.slice(0, end));\n } catch {\n return undefined;\n }\n}\n\n/** `observe()` is Vault's single reactivity primitive: a snapshot now, then on mutations. */\nexport function createObserverHub<S extends AnySchema>(\n getAll: <K extends keyof S & string>(table: K) => Promise<RecordOf<S, K>[]>,\n) {\n const observers = new Map<string, Set<ObserverListener<unknown>>>();\n const revisions = new Map<string, number>();\n let disposed = false;\n\n const notify = <K extends keyof S & string>(table: K): void => {\n if (disposed) return;\n\n const revision = (revisions.get(table) ?? 0) + 1;\n revisions.set(table, revision);\n const listeners = observers.get(table);\n\n if (!listeners || listeners.size === 0) return;\n\n void getAll(table)\n .then((records) => {\n if (disposed || revisions.get(table) !== revision) return;\n\n const current = observers.get(table);\n\n if (!current || current.size === 0) return;\n\n for (const listener of current) {\n try {\n listener(records as unknown[]);\n } catch {\n /* observer listener errors are intentionally swallowed */\n }\n }\n })\n .catch(() => {\n /* observer source errors are intentionally swallowed */\n });\n };\n\n const observe = <K extends keyof S & string>(\n table: K,\n listener: (records: RecordOf<S, K>[]) => void,\n { immediate = true, signal }: { immediate?: boolean; signal?: AbortSignal } = {},\n ): (() => void) => {\n if (disposed) throw new VaultDisposedError('observer hub is disposed');\n\n if (signal?.aborted) return () => {};\n\n const wrapped = listener as ObserverListener<unknown>;\n const listeners = observers.get(table) ?? new Set<ObserverListener<unknown>>();\n\n observers.set(table, listeners);\n listeners.add(wrapped);\n\n if (immediate) notify(table);\n\n const stop = (): void => {\n signal?.removeEventListener('abort', stop);\n const current = observers.get(table);\n\n if (!current) return;\n\n current.delete(wrapped);\n\n if (current.size === 0) observers.delete(table);\n };\n\n signal?.addEventListener('abort', stop, { once: true });\n\n return stop;\n };\n\n return {\n dispose: () => {\n disposed = true;\n observers.clear();\n revisions.clear();\n },\n notify,\n observe,\n };\n}\n\nexport function getRecordKey<S extends AnySchema, K extends keyof S>(\n schema: S,\n table: K,\n value: RecordOf<S, K>,\n): KeyOf<S, K> {\n const keyField = String(schema[table].key);\n const keyValue = (value as Record<string, unknown>)[keyField];\n\n if (typeof keyValue !== 'number' && typeof keyValue !== 'string') {\n throw new VaultError(`record in table \"${String(table)}\" must have a string or finite-number key at \"${keyField}\"`);\n }\n\n if (typeof keyValue === 'number' && !Number.isFinite(keyValue)) {\n throw new VaultError(`record in table \"${String(table)}\" must have a finite-number key at \"${keyField}\"`);\n }\n\n return keyValue as KeyOf<S, K>;\n}\n"],"mappings":"gCAKA,IAAM,EAAM,KAMZ,SAAgB,EAAe,EAAuB,CACpD,GAAI,OAAO,GAAQ,SAAU,CAC3B,GAAI,CAAC,OAAO,SAAS,CAAG,EAAG,MAAM,IAAI,EAAA,WAAW,iDAAiD,OAAO,CAAG,GAAG,EAE9G,MAAO,KAAK,OAAO,CAAG,GACxB,CAEA,MAAO,KAAK,mBAAmB,CAAG,GACpC,CAEA,SAAgB,EAAe,EAAwB,CACrD,MAAO,GAAG,mBAAmB,CAAM,IAAI,GACzC,CAEA,SAAgB,EAAiB,EAAgB,EAAe,EAAuB,CACrF,MAAO,GAAG,mBAAmB,CAAM,IAAI,IAAM,mBAAmB,CAAK,IAAI,IAAM,EAAe,CAAG,GACnG,CAEA,SAAgB,EAAyB,EAAgB,EAAuB,CAC9E,MAAO,GAAG,mBAAmB,CAAM,IAAI,IAAM,mBAAmB,CAAK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CAAK,EAE3B,IAAM,MAAmB,CACvB,GAAQ,oBAAoB,QAAS,CAAI,EACzC,IAAM,EAAU,EAAU,IAAI,CAAK,EAE9B,IAEL,EAAQ,OAAO,CAAO,EAElB,EAAQ,OAAS,GAAG,EAAU,OAAO,CAAK,EAChD,EAIA,OAFA,GAAQ,iBAAiB,QAAS,EAAM,CAAE,KAAM,EAAK,CAAC,EAE/C,CACT,CAUA,CACF,CAEA,SAAgB,EACd,EACA,EACA,EACa,CACb,IAAM,EAAW,OAAO,EAAO,EAAM,CAAC,GAAG,EACnC,EAAY,EAAkC,GAEpD,GAAI,OAAO,GAAa,UAAY,OAAO,GAAa,SACtD,MAAM,IAAI,EAAA,WAAW,oBAAoB,OAAO,CAAK,EAAE,gDAAgD,EAAS,EAAE,EAGpH,GAAI,OAAO,GAAa,UAAY,CAAC,OAAO,SAAS,CAAQ,EAC3D,MAAM,IAAI,EAAA,WAAW,oBAAoB,OAAO,CAAK,EAAE,sCAAsC,EAAS,EAAE,EAG1G,OAAO,CACT"}
1
+ {"version":3,"file":"internal.cjs","names":[],"sources":["../src/internal.ts"],"sourcesContent":["import { VaultDisposedError, VaultError } from './errors';\nimport type { AnySchema, KeyOf, RecordOf, VaultKey } from './types';\n\ntype ObserverListener<T> = (records: T[]) => void;\n\nconst SEP = '\\x00';\n\n/**\n * Type-tagged keys make `1` and `'1'` distinct in string-keyed adapters while\n * keeping the same portable primary-key contract as IndexedDB.\n */\nexport function encodeVaultKey(key: VaultKey): string {\n if (typeof key === 'number') {\n if (!Number.isFinite(key)) throw new VaultError(`primary key must be a finite number, received ${String(key)}`);\n\n return `n:${String(key)}`;\n }\n\n return `s:${encodeURIComponent(key)}`;\n}\n\nexport function encodeDbPrefix(dbName: string): string {\n return `${encodeURIComponent(dbName)}${SEP}`;\n}\n\nexport function encodeStorageKey(dbName: string, table: string, key: VaultKey): string {\n return `${encodeURIComponent(dbName)}${SEP}${encodeURIComponent(table)}${SEP}${encodeVaultKey(key)}`;\n}\n\nexport function encodeStorageTablePrefix(dbName: string, table: string): string {\n return `${encodeURIComponent(dbName)}${SEP}${encodeURIComponent(table)}${SEP}`;\n}\n\nexport function decodeStorageTableFromKey(dbName: string, storageKey: string | null): string | undefined {\n if (!storageKey) return undefined;\n\n const prefix = encodeDbPrefix(dbName);\n\n if (!storageKey.startsWith(prefix)) return undefined;\n\n const tail = storageKey.slice(prefix.length);\n const end = tail.indexOf(SEP);\n\n if (end === -1) return undefined;\n\n try {\n return decodeURIComponent(tail.slice(0, end));\n } catch {\n return undefined;\n }\n}\n\n/** `observe()` is Vault's single reactivity primitive: a snapshot now, then on mutations. */\nexport function createObserverHub<S extends AnySchema>(\n getAll: <K extends keyof S & string>(table: K) => Promise<RecordOf<S, K>[]>,\n) {\n const observers = new Map<string, Set<ObserverListener<unknown>>>();\n const revisions = new Map<string, number>();\n let disposed = false;\n\n const notify = <K extends keyof S & string>(table: K): void => {\n if (disposed) return;\n\n const revision = (revisions.get(table) ?? 0) + 1;\n revisions.set(table, revision);\n const listeners = observers.get(table);\n\n if (!listeners || listeners.size === 0) return;\n\n void getAll(table)\n .then((records) => {\n if (disposed || revisions.get(table) !== revision) return;\n\n const current = observers.get(table);\n\n if (!current || current.size === 0) return;\n\n for (const listener of current) {\n try {\n listener(records as unknown[]);\n } catch {\n /* observer listener errors are intentionally swallowed */\n }\n }\n })\n .catch(() => {\n /* observer source errors are intentionally swallowed */\n });\n };\n\n const observe = <K extends keyof S & string>(\n table: K,\n listener: (records: RecordOf<S, K>[]) => void,\n { immediate = true, signal }: { immediate?: boolean; signal?: AbortSignal } = {},\n ): (() => void) => {\n if (disposed) throw new VaultDisposedError('observer hub is disposed');\n\n if (signal?.aborted) return () => {};\n\n const wrapped = listener as ObserverListener<unknown>;\n const listeners = observers.get(table) ?? new Set<ObserverListener<unknown>>();\n\n observers.set(table, listeners);\n listeners.add(wrapped);\n\n if (immediate) notify(table);\n\n const stop = (): void => {\n signal?.removeEventListener('abort', stop);\n const current = observers.get(table);\n\n if (!current) return;\n\n current.delete(wrapped);\n\n if (current.size === 0) observers.delete(table);\n };\n\n signal?.addEventListener('abort', stop, { once: true });\n\n return stop;\n };\n\n return {\n dispose: () => {\n disposed = true;\n observers.clear();\n revisions.clear();\n },\n notify,\n observe,\n };\n}\n\nexport function getRecordKey<S extends AnySchema, K extends keyof S>(\n schema: S,\n table: K,\n value: RecordOf<S, K>,\n): KeyOf<S, K> {\n const keyField = String(schema[table].key);\n const keyValue = (value as Record<string, unknown>)[keyField];\n\n if (typeof keyValue !== 'number' && typeof keyValue !== 'string') {\n throw new VaultError(`record in table \"${String(table)}\" must have a string or finite-number key at \"${keyField}\"`);\n }\n\n if (typeof keyValue === 'number' && !Number.isFinite(keyValue)) {\n throw new VaultError(`record in table \"${String(table)}\" must have a finite-number key at \"${keyField}\"`);\n }\n\n return keyValue as KeyOf<S, K>;\n}\n"],"mappings":"gCAKA,IAAM,EAAM,KAMZ,SAAgB,eAAe,EAAuB,CACpD,GAAI,OAAO,GAAQ,SAAU,CAC3B,GAAI,CAAC,OAAO,SAAS,CAAG,EAAG,MAAM,IAAI,EAAA,WAAW,iDAAiD,OAAO,CAAG,GAAG,EAE9G,MAAO,KAAK,OAAO,CAAG,GACxB,CAEA,MAAO,KAAK,mBAAmB,CAAG,GACpC,CAEA,SAAgB,eAAe,EAAwB,CACrD,MAAO,GAAG,mBAAmB,CAAM,IAAI,GACzC,CAEA,SAAgB,iBAAiB,EAAgB,EAAe,EAAuB,CACrF,MAAO,GAAG,mBAAmB,CAAM,IAAI,IAAM,mBAAmB,CAAK,IAAI,IAAM,eAAe,CAAG,GACnG,CAEA,SAAgB,yBAAyB,EAAgB,EAAuB,CAC9E,MAAO,GAAG,mBAAmB,CAAM,IAAI,IAAM,mBAAmB,CAAK,IAAI,GAC3E,CAEA,SAAgB,0BAA0B,EAAgB,EAA+C,CACvG,GAAI,CAAC,EAAY,OAEjB,IAAM,EAAS,eAAe,CAAM,EAEpC,GAAI,CAAC,EAAW,WAA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