local-lite 0.0.1 → 0.0.2
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/README.md +12 -0
- package/dist/core/client.d.ts +56 -3
- package/dist/core/client.js +212 -40
- package/dist/core/outbox-store.d.ts +32 -1
- package/dist/core/outbox-store.js +126 -2
- package/dist/core/query.d.ts +13 -0
- package/dist/core/query.js +150 -0
- package/dist/core/sync-worker.d.ts +16 -1
- package/dist/core/sync-worker.js +142 -4
- package/dist/core/types.d.ts +84 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/react/index.d.ts +19 -3
- package/dist/react/index.js +75 -4
- package/package.json +3 -3
package/dist/react/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLiveQuery = useLiveQuery;
|
|
4
4
|
exports.useOutboxStatus = useOutboxStatus;
|
|
5
|
+
exports.useSyncStatus = useSyncStatus;
|
|
6
|
+
exports.useSyncMetrics = useSyncMetrics;
|
|
5
7
|
const react_1 = require("react");
|
|
6
8
|
/**
|
|
7
9
|
* Hook to execute a live reactive table query that automatically re-runs
|
|
@@ -11,9 +13,9 @@ const react_1 = require("react");
|
|
|
11
13
|
* 1. Zero-SQL (all rows):
|
|
12
14
|
* const { data: todos } = useLiveQuery<Todo>(client, 'todos');
|
|
13
15
|
*
|
|
14
|
-
* 2. Declarative options (filtering & sorting without SQL):
|
|
16
|
+
* 2. Declarative options (filtering with rich operators & sorting without SQL):
|
|
15
17
|
* const { data: active } = useLiveQuery<Todo>(client, 'todos', {
|
|
16
|
-
* where: { completed: 0 },
|
|
18
|
+
* where: { completed: 0, priority: { $gte: 2 } },
|
|
17
19
|
* orderBy: 'created_at',
|
|
18
20
|
* order: 'desc'
|
|
19
21
|
* });
|
|
@@ -80,9 +82,9 @@ function useOutboxStatus(client) {
|
|
|
80
82
|
if (!client || !client.db)
|
|
81
83
|
return;
|
|
82
84
|
try {
|
|
83
|
-
const records = await client.
|
|
85
|
+
const records = await client.getOutboxRecords();
|
|
84
86
|
setPendingRecords(records || []);
|
|
85
|
-
setPendingCount((
|
|
87
|
+
setPendingCount(records.filter((r) => r.status === 'PENDING').length);
|
|
86
88
|
}
|
|
87
89
|
catch {
|
|
88
90
|
// Ignored if table doesn't exist yet
|
|
@@ -101,3 +103,72 @@ function useOutboxStatus(client) {
|
|
|
101
103
|
}, [client, refresh]);
|
|
102
104
|
return { pendingCount, pendingRecords, refresh };
|
|
103
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Hook that tracks real-time sync connectivity and sync worker activity (pushing/pulling).
|
|
108
|
+
*/
|
|
109
|
+
function useSyncStatus(client) {
|
|
110
|
+
const [status, setStatus] = (0, react_1.useState)({
|
|
111
|
+
isOnline: true,
|
|
112
|
+
isPushing: false,
|
|
113
|
+
isPulling: false,
|
|
114
|
+
pendingCount: 0,
|
|
115
|
+
});
|
|
116
|
+
(0, react_1.useEffect)(() => {
|
|
117
|
+
if (!client)
|
|
118
|
+
return;
|
|
119
|
+
// Fetch initial metrics
|
|
120
|
+
client.getMetrics().then((m) => {
|
|
121
|
+
setStatus({
|
|
122
|
+
isOnline: m.isOnline,
|
|
123
|
+
isPushing: m.isPushing,
|
|
124
|
+
isPulling: m.isPulling,
|
|
125
|
+
pendingCount: m.outboxPendingCount,
|
|
126
|
+
});
|
|
127
|
+
}).catch(() => { });
|
|
128
|
+
const unsubscribe = client.events.on('sync:status', (e) => {
|
|
129
|
+
setStatus(e);
|
|
130
|
+
});
|
|
131
|
+
return () => {
|
|
132
|
+
unsubscribe();
|
|
133
|
+
};
|
|
134
|
+
}, [client]);
|
|
135
|
+
return status;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Hook that provides real-time sync telemetry and engine performance metrics.
|
|
139
|
+
*/
|
|
140
|
+
function useSyncMetrics(client, pollIntervalMs = 3000) {
|
|
141
|
+
const [metrics, setMetrics] = (0, react_1.useState)(null);
|
|
142
|
+
const refresh = (0, react_1.useCallback)(async () => {
|
|
143
|
+
if (!client)
|
|
144
|
+
return;
|
|
145
|
+
try {
|
|
146
|
+
const data = await client.getMetrics();
|
|
147
|
+
setMetrics(data);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// Ignored
|
|
151
|
+
}
|
|
152
|
+
}, [client]);
|
|
153
|
+
(0, react_1.useEffect)(() => {
|
|
154
|
+
if (!client)
|
|
155
|
+
return;
|
|
156
|
+
refresh();
|
|
157
|
+
// Listen to sync events for immediate refresh
|
|
158
|
+
const unsubs = [
|
|
159
|
+
client.events.on('sync:push', () => refresh()),
|
|
160
|
+
client.events.on('sync:pull', () => refresh()),
|
|
161
|
+
client.events.on('sync:status', () => refresh()),
|
|
162
|
+
];
|
|
163
|
+
let timer;
|
|
164
|
+
if (pollIntervalMs > 0) {
|
|
165
|
+
timer = setInterval(refresh, pollIntervalMs);
|
|
166
|
+
}
|
|
167
|
+
return () => {
|
|
168
|
+
unsubs.forEach((u) => u());
|
|
169
|
+
if (timer)
|
|
170
|
+
clearInterval(timer);
|
|
171
|
+
};
|
|
172
|
+
}, [client, refresh, pollIntervalMs]);
|
|
173
|
+
return { metrics, refresh };
|
|
174
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "local-lite",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Never let a lost connection break a promise. Local-first sync that faithfully keeps data safe until you're back online.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -130,4 +130,4 @@
|
|
|
130
130
|
"dependencies": {
|
|
131
131
|
"uuid": "^14.0.3"
|
|
132
132
|
}
|
|
133
|
-
}
|
|
133
|
+
}
|