Open History to see the last commit
1import { TanStackDBError } from '@tanstack/db'
2
3export class PersistedCollectionCoreError extends TanStackDBError {
4 constructor(message: string) {
5 super(message)
6 this.name = `PersistedCollectionCoreError`
7 }
8}
9
10export class InvalidPersistedCollectionConfigError extends PersistedCollectionCoreError {
11 constructor(message: string) {
12 super(message)
13 this.name = `InvalidPersistedCollectionConfigError`
14 }
15}
16
17export class InvalidSyncConfigError extends InvalidPersistedCollectionConfigError {
18 constructor(details?: string) {
19 super(
20 details
21 ? `Invalid sync config: ${details}`
22 : `Invalid sync config: expected an object with a callable sync function`,
23 )
24 this.name = `InvalidSyncConfigError`
25 }
26}
27
28export class InvalidPersistedCollectionCoordinatorError extends InvalidPersistedCollectionConfigError {
29 constructor(methodName: string) {
30 super(
31 `Invalid persisted collection coordinator: missing required "${methodName}" method`,
32 )
33 this.name = `InvalidPersistedCollectionCoordinatorError`
34 }
35}
36
37export class InvalidPersistenceAdapterError extends InvalidPersistedCollectionConfigError {
38 constructor(methodName: string) {
39 super(
40 `Invalid persistence adapter: missing required "${methodName}" method`,
41 )
42 this.name = `InvalidPersistenceAdapterError`
43 }
44}
45
46export class InvalidPersistedStorageKeyError extends InvalidPersistedCollectionConfigError {
47 constructor(key: string | number) {
48 super(
49 `Invalid persisted storage key "${String(key)}": numeric keys must be finite`,
50 )
51 this.name = `InvalidPersistedStorageKeyError`
52 }
53}
54
55export class InvalidPersistedStorageKeyEncodingError extends InvalidPersistedCollectionConfigError {
56 constructor(encoded: string) {
57 super(
58 `Invalid persisted storage key encoding "${encoded}": expected prefix "n:" or "s:"`,
59 )
60 this.name = `InvalidPersistedStorageKeyEncodingError`
61 }
62}
63
64export class PersistenceUnavailableError extends PersistedCollectionCoreError {
65 constructor(details?: string) {
66 super(
67 details
68 ? `Persistence unavailable: ${details}`
69 : `Persistence unavailable in this runtime`,
70 )
71 this.name = `PersistenceUnavailableError`
72 }
73}