@tanstack/offline-transactions 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/OfflineExecutor.cjs +141 -37
- package/dist/cjs/OfflineExecutor.cjs.map +1 -1
- package/dist/cjs/OfflineExecutor.d.cts +10 -1
- package/dist/cjs/api/OfflineAction.cjs +8 -1
- package/dist/cjs/api/OfflineAction.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/storage/IndexedDBAdapter.cjs +39 -0
- package/dist/cjs/storage/IndexedDBAdapter.cjs.map +1 -1
- package/dist/cjs/storage/IndexedDBAdapter.d.cts +8 -0
- package/dist/cjs/storage/LocalStorageAdapter.cjs +31 -0
- package/dist/cjs/storage/LocalStorageAdapter.cjs.map +1 -1
- package/dist/cjs/storage/LocalStorageAdapter.d.cts +8 -0
- package/dist/cjs/telemetry/tracer.cjs +1 -1
- package/dist/cjs/telemetry/tracer.cjs.map +1 -1
- package/dist/cjs/types.cjs.map +1 -1
- package/dist/cjs/types.d.cts +9 -4
- package/dist/esm/OfflineExecutor.d.ts +10 -1
- package/dist/esm/OfflineExecutor.js +141 -37
- package/dist/esm/OfflineExecutor.js.map +1 -1
- package/dist/esm/api/OfflineAction.js +8 -1
- package/dist/esm/api/OfflineAction.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/storage/IndexedDBAdapter.d.ts +8 -0
- package/dist/esm/storage/IndexedDBAdapter.js +39 -0
- package/dist/esm/storage/IndexedDBAdapter.js.map +1 -1
- package/dist/esm/storage/LocalStorageAdapter.d.ts +8 -0
- package/dist/esm/storage/LocalStorageAdapter.js +31 -0
- package/dist/esm/storage/LocalStorageAdapter.js.map +1 -1
- package/dist/esm/telemetry/tracer.js +1 -1
- package/dist/esm/telemetry/tracer.js.map +1 -1
- package/dist/esm/types.d.ts +9 -4
- package/dist/esm/types.js.map +1 -1
- package/package.json +12 -12
- package/src/OfflineExecutor.ts +200 -43
- package/src/api/OfflineAction.ts +14 -1
- package/src/index.ts +3 -0
- package/src/storage/IndexedDBAdapter.ts +47 -0
- package/src/storage/LocalStorageAdapter.ts +38 -0
- package/src/telemetry/tracer.ts +4 -9
- package/src/types.ts +19 -4
|
@@ -8,6 +8,44 @@ export class LocalStorageAdapter extends BaseStorageAdapter {
|
|
|
8
8
|
this.prefix = prefix
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Probe localStorage availability by attempting a test write.
|
|
13
|
+
* This catches private mode and other restrictions that block localStorage.
|
|
14
|
+
*/
|
|
15
|
+
static probe(): { available: boolean; error?: Error } {
|
|
16
|
+
// Check if localStorage exists
|
|
17
|
+
if (typeof localStorage === `undefined`) {
|
|
18
|
+
return {
|
|
19
|
+
available: false,
|
|
20
|
+
error: new Error(`localStorage is not available in this environment`),
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Try to actually write/read/delete to verify it works
|
|
25
|
+
try {
|
|
26
|
+
const testKey = `__offline-tx-probe__`
|
|
27
|
+
const testValue = `test`
|
|
28
|
+
|
|
29
|
+
localStorage.setItem(testKey, testValue)
|
|
30
|
+
const retrieved = localStorage.getItem(testKey)
|
|
31
|
+
localStorage.removeItem(testKey)
|
|
32
|
+
|
|
33
|
+
if (retrieved !== testValue) {
|
|
34
|
+
return {
|
|
35
|
+
available: false,
|
|
36
|
+
error: new Error(`localStorage read/write verification failed`),
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { available: true }
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
available: false,
|
|
44
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
11
49
|
private getKey(key: string): string {
|
|
12
50
|
return `${this.prefix}${key}`
|
|
13
51
|
}
|
package/src/telemetry/tracer.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
context,
|
|
6
|
-
type SpanContext,
|
|
7
|
-
} from "@opentelemetry/api"
|
|
8
|
-
|
|
9
|
-
const TRACER = trace.getTracer("@tanstack/offline-transactions", "0.0.1")
|
|
1
|
+
import { SpanStatusCode, context, trace } from "@opentelemetry/api"
|
|
2
|
+
import type { Span, SpanContext } from "@opentelemetry/api"
|
|
3
|
+
|
|
4
|
+
const TRACER = trace.getTracer(`@tanstack/offline-transactions`, `0.0.1`)
|
|
10
5
|
|
|
11
6
|
export interface SpanAttrs {
|
|
12
7
|
[key: string]: string | number | boolean | undefined
|
package/src/types.ts
CHANGED
|
@@ -69,6 +69,24 @@ export interface SerializedOfflineTransaction {
|
|
|
69
69
|
version: 1
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
// Storage diagnostics and mode
|
|
73
|
+
export type OfflineMode = `offline` | `online-only`
|
|
74
|
+
|
|
75
|
+
export type StorageDiagnosticCode =
|
|
76
|
+
| `STORAGE_AVAILABLE`
|
|
77
|
+
| `INDEXEDDB_UNAVAILABLE`
|
|
78
|
+
| `LOCALSTORAGE_UNAVAILABLE`
|
|
79
|
+
| `STORAGE_BLOCKED`
|
|
80
|
+
| `QUOTA_EXCEEDED`
|
|
81
|
+
| `UNKNOWN_ERROR`
|
|
82
|
+
|
|
83
|
+
export interface StorageDiagnostic {
|
|
84
|
+
code: StorageDiagnosticCode
|
|
85
|
+
mode: OfflineMode
|
|
86
|
+
message: string
|
|
87
|
+
error?: Error
|
|
88
|
+
}
|
|
89
|
+
|
|
72
90
|
export interface OfflineConfig {
|
|
73
91
|
collections: Record<string, Collection>
|
|
74
92
|
mutationFns: Record<string, OfflineMutationFn>
|
|
@@ -80,11 +98,8 @@ export interface OfflineConfig {
|
|
|
80
98
|
) => Array<OfflineTransaction>
|
|
81
99
|
onUnknownMutationFn?: (name: string, tx: OfflineTransaction) => void
|
|
82
100
|
onLeadershipChange?: (isLeader: boolean) => void
|
|
101
|
+
onStorageFailure?: (diagnostic: StorageDiagnostic) => void
|
|
83
102
|
leaderElection?: LeaderElection
|
|
84
|
-
otel?: {
|
|
85
|
-
endpoint: string
|
|
86
|
-
headers?: Record<string, string>
|
|
87
|
-
}
|
|
88
103
|
}
|
|
89
104
|
|
|
90
105
|
export interface StorageAdapter {
|