@powersync/diagnostics 0.0.0-dev-20261020125654
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 +201 -0
- package/README.md +138 -0
- package/lib/src/agent-server.d.ts +21 -0
- package/lib/src/agent-server.js +51 -0
- package/lib/src/agent-server.js.map +1 -0
- package/lib/src/agent.d.ts +11 -0
- package/lib/src/agent.js +30 -0
- package/lib/src/agent.js.map +1 -0
- package/lib/src/client.d.ts +7 -0
- package/lib/src/client.js +30 -0
- package/lib/src/client.js.map +1 -0
- package/lib/src/constants.d.ts +13 -0
- package/lib/src/constants.js +14 -0
- package/lib/src/constants.js.map +1 -0
- package/lib/src/definition.d.ts +16 -0
- package/lib/src/definition.js +421 -0
- package/lib/src/definition.js.map +1 -0
- package/lib/src/index.d.ts +4 -0
- package/lib/src/index.js +6 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/js-agent.d.ts +63 -0
- package/lib/src/js-agent.js +298 -0
- package/lib/src/js-agent.js.map +1 -0
- package/lib/src/node.d.ts +59 -0
- package/lib/src/node.js +40 -0
- package/lib/src/node.js.map +1 -0
- package/lib/src/page.d.ts +5 -0
- package/lib/src/page.js +50 -0
- package/lib/src/page.js.map +1 -0
- package/lib/src/rpc-types.d.ts +42 -0
- package/lib/src/rpc-types.js +2 -0
- package/lib/src/rpc-types.js.map +1 -0
- package/lib/src/sync-state.d.ts +4 -0
- package/lib/src/sync-state.js +53 -0
- package/lib/src/sync-state.js.map +1 -0
- package/lib/src/vite-static.d.ts +18 -0
- package/lib/src/vite-static.js +67 -0
- package/lib/src/vite-static.js.map +1 -0
- package/lib/src/vite.d.ts +27 -0
- package/lib/src/vite.js +43 -0
- package/lib/src/vite.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +98 -0
- package/src/agent-server.ts +73 -0
- package/src/agent.ts +58 -0
- package/src/client.ts +37 -0
- package/src/constants.ts +15 -0
- package/src/definition.ts +504 -0
- package/src/index.ts +7 -0
- package/src/js-agent.ts +378 -0
- package/src/node.ts +89 -0
- package/src/page.ts +61 -0
- package/src/rpc-types.ts +55 -0
- package/src/sync-state.ts +61 -0
- package/src/vite-static.ts +83 -0
- package/src/vite.ts +55 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PowerSync devframe definition: the node side every host mounts (a Vite DevTools dock, a node
|
|
3
|
+
* app's own dev server).
|
|
4
|
+
*
|
|
5
|
+
* It exposes `SdkIntegration` one RPC function per method. The databases it serves are *sources*:
|
|
6
|
+
* an integration living in this process (a node app), or a `RemoteIntegration` that forwards to a
|
|
7
|
+
* connected page or app which announced itself with `page-register`. UI clients subscribe with
|
|
8
|
+
* `observe` and receive pushed `DiagnosticsEvent`s; agents reach the same functions over MCP.
|
|
9
|
+
*/
|
|
10
|
+
import { createRequire } from 'node:module';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
import { defineDevframe, defineRpcFunction } from 'devframe';
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { DEVFRAME_ID, HEARTBEAT_MS, UI_ROUTE } from './constants.js';
|
|
15
|
+
/** Event types replayed to a UI that subscribes late. `logs` and `core` are not replayed. */
|
|
16
|
+
const SNAPSHOT_TYPES = new Set(['status', 'streams', 'buckets', 'uploadQueue']);
|
|
17
|
+
/**
|
|
18
|
+
* Calls into a page or app that serves a database over its own devframe connection. `sourceId` is
|
|
19
|
+
* the id the page serves it under, which differs from the id the node side lists when several pages
|
|
20
|
+
* announce the same one.
|
|
21
|
+
*/
|
|
22
|
+
class RemoteIntegration {
|
|
23
|
+
session;
|
|
24
|
+
sourceId;
|
|
25
|
+
constructor(session, sourceId) {
|
|
26
|
+
this.session = session;
|
|
27
|
+
this.sourceId = sourceId;
|
|
28
|
+
}
|
|
29
|
+
get closed() {
|
|
30
|
+
return this.session.rpc.$closed;
|
|
31
|
+
}
|
|
32
|
+
runQuery(params) {
|
|
33
|
+
return this.session.rpc.$call('powersync:page-query', this.sourceId, params);
|
|
34
|
+
}
|
|
35
|
+
getSchema() {
|
|
36
|
+
return this.session.rpc.$call('powersync:page-schema', this.sourceId);
|
|
37
|
+
}
|
|
38
|
+
getInfo() {
|
|
39
|
+
return this.session.rpc.$call('powersync:page-info', this.sourceId);
|
|
40
|
+
}
|
|
41
|
+
action(request) {
|
|
42
|
+
return this.session.rpc.$call('powersync:page-action', this.sourceId, request);
|
|
43
|
+
}
|
|
44
|
+
/** Events arrive as `page-event` pushes and are routed by the registry; nothing to subscribe here. */
|
|
45
|
+
async observeEvents() {
|
|
46
|
+
return () => { };
|
|
47
|
+
}
|
|
48
|
+
async close() { }
|
|
49
|
+
}
|
|
50
|
+
const sources = new Map();
|
|
51
|
+
/** The SDKs the entry point that mounted this definition can reach; `null` for all. */
|
|
52
|
+
let setupSdks = null;
|
|
53
|
+
/** UI sessions that asked for events, keyed by session id. */
|
|
54
|
+
const observers = new Map();
|
|
55
|
+
/** The id a page serves a database under, per session, to the id it is listed under here. */
|
|
56
|
+
const pageSources = new Map();
|
|
57
|
+
/** Runs while UIs observe, so a page that went away is dropped and announced without waiting for a call. */
|
|
58
|
+
let sweep;
|
|
59
|
+
const SWEEP_INTERVAL_MS = 2000;
|
|
60
|
+
const STALE_AFTER_MS = HEARTBEAT_MS * 3;
|
|
61
|
+
function pageKey(session, pageSourceId) {
|
|
62
|
+
return `${session.meta.id}:${pageSourceId}`;
|
|
63
|
+
}
|
|
64
|
+
function pageAlive(remote, source) {
|
|
65
|
+
if (remote.closed)
|
|
66
|
+
return false;
|
|
67
|
+
const lastSeen = source()?.lastSeen;
|
|
68
|
+
return lastSeen == null || Date.now() - lastSeen < STALE_AFTER_MS;
|
|
69
|
+
}
|
|
70
|
+
/** Every page numbers its databases from 1, so a second page announcing `web-1` is listed as `web-2`. */
|
|
71
|
+
function allocateSourceId(pageSourceId) {
|
|
72
|
+
const stem = pageSourceId.replace(/-\d+$/, '');
|
|
73
|
+
for (let number = 1;; number++) {
|
|
74
|
+
const candidate = `${stem}-${number}`;
|
|
75
|
+
const taken = sources.get(candidate);
|
|
76
|
+
if (!taken || !taken.alive())
|
|
77
|
+
return candidate;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function sourceInfos() {
|
|
81
|
+
return [...sources.values()].filter((source) => source.alive()).map((source) => ({ id: source.id, sdk: source.sdk }));
|
|
82
|
+
}
|
|
83
|
+
function liveSources() {
|
|
84
|
+
for (const [id, source] of sources) {
|
|
85
|
+
if (!source.alive()) {
|
|
86
|
+
removeSource(id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return [...sources.values()];
|
|
90
|
+
}
|
|
91
|
+
function notifySources() {
|
|
92
|
+
const list = sourceInfos();
|
|
93
|
+
for (const [sessionId, session] of observers) {
|
|
94
|
+
if (session.rpc.$closed) {
|
|
95
|
+
observers.delete(sessionId);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
void session.rpc.$callEvent('powersync:sources-changed', list);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function ensureSweep() {
|
|
102
|
+
if (sweep)
|
|
103
|
+
return;
|
|
104
|
+
sweep = setInterval(() => {
|
|
105
|
+
liveSources();
|
|
106
|
+
if (observers.size === 0 && sweep) {
|
|
107
|
+
clearInterval(sweep);
|
|
108
|
+
sweep = undefined;
|
|
109
|
+
}
|
|
110
|
+
}, SWEEP_INTERVAL_MS);
|
|
111
|
+
sweep.unref?.();
|
|
112
|
+
}
|
|
113
|
+
function pickSource(sourceId) {
|
|
114
|
+
const live = liveSources();
|
|
115
|
+
const source = sourceId ? live.find((candidate) => candidate.id === sourceId) : live[0];
|
|
116
|
+
if (!source) {
|
|
117
|
+
throw new Error(sourceId
|
|
118
|
+
? `No PowerSync database "${sourceId}" is attached.`
|
|
119
|
+
: 'No PowerSync database is attached. Open the app in a trusted browser tab, or call enablePowerSyncDiagnostics() in the node app.');
|
|
120
|
+
}
|
|
121
|
+
return source;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The latest pushed snapshot of one event type, for the request-style tools (MCP). The protocol has
|
|
125
|
+
* no request for these; the source pushes them on subscribe and on every change, and they are kept
|
|
126
|
+
* here. `null` until the source has reported.
|
|
127
|
+
*/
|
|
128
|
+
function latestSnapshot(sourceId, type) {
|
|
129
|
+
return pickSource(sourceId).snapshots.get(type)?.payload ?? null;
|
|
130
|
+
}
|
|
131
|
+
function pushEvent(session, sourceId, event) {
|
|
132
|
+
void session.rpc.$callEvent('powersync:event', sourceId, event);
|
|
133
|
+
}
|
|
134
|
+
function fanOut(sourceId, event) {
|
|
135
|
+
const source = sources.get(sourceId);
|
|
136
|
+
if (!source)
|
|
137
|
+
return;
|
|
138
|
+
if (SNAPSHOT_TYPES.has(event.type)) {
|
|
139
|
+
source.snapshots.set(event.type, event);
|
|
140
|
+
}
|
|
141
|
+
for (const [sessionId, session] of observers) {
|
|
142
|
+
if (session.rpc.$closed) {
|
|
143
|
+
observers.delete(sessionId);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
pushEvent(session, sourceId, event);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function addSource(source) {
|
|
150
|
+
sources.get(source.id)?.stop?.();
|
|
151
|
+
sources.set(source.id, source);
|
|
152
|
+
console.info(`[powersync-diagnostics] source attached: ${source.id} (${source.sdk ?? 'unknown sdk'})`);
|
|
153
|
+
notifySources();
|
|
154
|
+
}
|
|
155
|
+
function removeSource(sourceId) {
|
|
156
|
+
const source = sources.get(sourceId);
|
|
157
|
+
if (!source)
|
|
158
|
+
return;
|
|
159
|
+
source.stop?.();
|
|
160
|
+
sources.delete(sourceId);
|
|
161
|
+
for (const [key, id] of pageSources) {
|
|
162
|
+
if (id === sourceId)
|
|
163
|
+
pageSources.delete(key);
|
|
164
|
+
}
|
|
165
|
+
console.info(`[powersync-diagnostics] source detached: ${sourceId}`);
|
|
166
|
+
notifySources();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Serves an integration that lives in this process (a node app's database). Events are pulled from
|
|
170
|
+
* it directly. Returns a function that detaches it.
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* Names the SDKs this host can reach, so the UI's "no database" screens explain only those. Each entry
|
|
174
|
+
* point sets it: the Vite plugin, the node server, the Nuxt module.
|
|
175
|
+
*/
|
|
176
|
+
export function setSetupSdks(sdks) {
|
|
177
|
+
setupSdks = sdks?.length ? [...sdks] : null;
|
|
178
|
+
}
|
|
179
|
+
export async function registerIntegration(id, integration, sdk = null) {
|
|
180
|
+
const source = { id, sdk, integration, alive: () => true, lastSeen: null, snapshots: new Map() };
|
|
181
|
+
addSource(source);
|
|
182
|
+
source.stop = await integration.observeEvents((event) => fanOut(id, event));
|
|
183
|
+
return () => removeSource(id);
|
|
184
|
+
}
|
|
185
|
+
/** The built diagnostics UI (`@powersync/diagnostics-ui/dist/standalone`), served as the dock page. */
|
|
186
|
+
export function uiDistDir() {
|
|
187
|
+
const require = createRequire(import.meta.url);
|
|
188
|
+
const pkg = require.resolve('@powersync/diagnostics-ui/package.json');
|
|
189
|
+
return join(dirname(pkg), 'dist', 'standalone');
|
|
190
|
+
}
|
|
191
|
+
const packageJson = createRequire(import.meta.url)('../../package.json');
|
|
192
|
+
// --- argument schemas (Standard Schema through zod): validated on the wire and shown to agents ---
|
|
193
|
+
// Agents see positional arguments as `arg0`, `arg1`, ... and every one is advertised as required, so
|
|
194
|
+
// each description spells out that convention and which values may be null.
|
|
195
|
+
const sourceIdArg = z
|
|
196
|
+
.string()
|
|
197
|
+
.nullable()
|
|
198
|
+
.optional()
|
|
199
|
+
.describe('Id of the attached database, from powersync_sources. Null for the first one.');
|
|
200
|
+
const queryParamsArg = z
|
|
201
|
+
.object({
|
|
202
|
+
sql: z.string().describe('SQL to run against the local SQLite database.'),
|
|
203
|
+
params: z.array(z.unknown()).optional().describe('Positional parameters for `?` placeholders.')
|
|
204
|
+
})
|
|
205
|
+
.describe('The query.');
|
|
206
|
+
const actionRequestArg = z
|
|
207
|
+
.object({
|
|
208
|
+
action: z.enum([
|
|
209
|
+
'reconnect',
|
|
210
|
+
'disconnect',
|
|
211
|
+
'clearData',
|
|
212
|
+
'requestCheckpoint',
|
|
213
|
+
'subscribeStream',
|
|
214
|
+
'unsubscribeStream'
|
|
215
|
+
]),
|
|
216
|
+
args: z
|
|
217
|
+
.object({
|
|
218
|
+
name: z.string(),
|
|
219
|
+
params: z.record(z.string(), z.unknown()).optional(),
|
|
220
|
+
ttl: z.number().optional(),
|
|
221
|
+
priority: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]).optional()
|
|
222
|
+
})
|
|
223
|
+
.optional()
|
|
224
|
+
.describe('Stream name and options, for the stream actions only.')
|
|
225
|
+
})
|
|
226
|
+
.describe('The action to run.');
|
|
227
|
+
const anyResult = z.unknown();
|
|
228
|
+
export const definition = defineDevframe({
|
|
229
|
+
id: DEVFRAME_ID,
|
|
230
|
+
name: 'PowerSync',
|
|
231
|
+
version: packageJson.version,
|
|
232
|
+
packageName: packageJson.name,
|
|
233
|
+
importMetaUrl: import.meta.url,
|
|
234
|
+
homepage: 'https://docs.powersync.com',
|
|
235
|
+
description: 'Live diagnostics for the PowerSync client: sync status, buckets, streams, local data, schema and logs.',
|
|
236
|
+
// The PowerSync mark, shipped with the UI and served under the mount base.
|
|
237
|
+
icon: `${UI_ROUTE}powersync-icon.svg`,
|
|
238
|
+
clientAssets: uiDistDir(),
|
|
239
|
+
dock: {
|
|
240
|
+
category: 'app',
|
|
241
|
+
clientScript: {
|
|
242
|
+
// Runs in the app page: finds the live database and serves it to this node side.
|
|
243
|
+
importFrom: `${packageJson.name}/client`,
|
|
244
|
+
eager: true
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
setup(ctx) {
|
|
248
|
+
const ps = ctx.scope(DEVFRAME_ID);
|
|
249
|
+
const currentSession = () => {
|
|
250
|
+
const session = ctx.rpc.getCurrentRpcSession();
|
|
251
|
+
if (!session)
|
|
252
|
+
throw new Error('No RPC session for this call.');
|
|
253
|
+
return session;
|
|
254
|
+
};
|
|
255
|
+
// --- page / app facing: a connected client serves a database ---
|
|
256
|
+
ps.rpc.register(defineRpcFunction({
|
|
257
|
+
name: 'page-register',
|
|
258
|
+
type: 'action',
|
|
259
|
+
jsonSerializable: true,
|
|
260
|
+
handler: (pageSourceId, sdk) => {
|
|
261
|
+
const session = currentSession();
|
|
262
|
+
const id = allocateSourceId(pageSourceId);
|
|
263
|
+
pageSources.set(pageKey(session, pageSourceId), id);
|
|
264
|
+
const remote = new RemoteIntegration(session, pageSourceId);
|
|
265
|
+
addSource({
|
|
266
|
+
id,
|
|
267
|
+
sdk,
|
|
268
|
+
integration: remote,
|
|
269
|
+
alive: () => pageAlive(remote, () => sources.get(id)),
|
|
270
|
+
lastSeen: Date.now(),
|
|
271
|
+
snapshots: new Map()
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}));
|
|
275
|
+
ps.rpc.register(defineRpcFunction({
|
|
276
|
+
name: 'page-heartbeat',
|
|
277
|
+
type: 'event',
|
|
278
|
+
jsonSerializable: true,
|
|
279
|
+
handler: (pageSourceId) => {
|
|
280
|
+
const id = pageSources.get(pageKey(currentSession(), pageSourceId));
|
|
281
|
+
const source = id ? sources.get(id) : undefined;
|
|
282
|
+
if (source)
|
|
283
|
+
source.lastSeen = Date.now();
|
|
284
|
+
}
|
|
285
|
+
}));
|
|
286
|
+
ps.rpc.register(defineRpcFunction({
|
|
287
|
+
name: 'page-unregister',
|
|
288
|
+
type: 'action',
|
|
289
|
+
jsonSerializable: true,
|
|
290
|
+
handler: (pageSourceId) => {
|
|
291
|
+
const id = pageSources.get(pageKey(currentSession(), pageSourceId));
|
|
292
|
+
if (id)
|
|
293
|
+
removeSource(id);
|
|
294
|
+
}
|
|
295
|
+
}));
|
|
296
|
+
ps.rpc.register(defineRpcFunction({
|
|
297
|
+
name: 'page-event',
|
|
298
|
+
type: 'event',
|
|
299
|
+
jsonSerializable: true,
|
|
300
|
+
handler: (pageSourceId, event) => {
|
|
301
|
+
const id = pageSources.get(pageKey(currentSession(), pageSourceId));
|
|
302
|
+
if (id)
|
|
303
|
+
fanOut(id, event);
|
|
304
|
+
}
|
|
305
|
+
}));
|
|
306
|
+
// --- UI and agent facing: SdkIntegration, one function per method ---
|
|
307
|
+
ps.rpc.register(defineRpcFunction({
|
|
308
|
+
name: 'sources',
|
|
309
|
+
type: 'query',
|
|
310
|
+
jsonSerializable: true,
|
|
311
|
+
agent: { description: 'List the PowerSync databases attached to this dev server, with their ids and SDKs.' },
|
|
312
|
+
handler: () => {
|
|
313
|
+
liveSources();
|
|
314
|
+
return sourceInfos();
|
|
315
|
+
}
|
|
316
|
+
}));
|
|
317
|
+
ps.rpc.register(defineRpcFunction({
|
|
318
|
+
name: 'setup-sdks',
|
|
319
|
+
type: 'query',
|
|
320
|
+
jsonSerializable: true,
|
|
321
|
+
handler: () => setupSdks
|
|
322
|
+
}));
|
|
323
|
+
ps.rpc.register(defineRpcFunction({
|
|
324
|
+
name: 'query',
|
|
325
|
+
type: 'action',
|
|
326
|
+
jsonSerializable: true,
|
|
327
|
+
args: [queryParamsArg, sourceIdArg],
|
|
328
|
+
returns: anyResult,
|
|
329
|
+
agent: {
|
|
330
|
+
description: 'Run SQL against the attached PowerSync SQLite database. App tables are views; the sync client state is in the ps_* tables (ps_buckets, ps_oplog, ps_crud, ps_stream_subscriptions). Returns columns and rows. Arguments: arg0 = { sql, params? }, arg1 = database id or null for the first one.',
|
|
331
|
+
safety: 'action'
|
|
332
|
+
},
|
|
333
|
+
handler: (params, sourceId) => pickSource(sourceId).integration.runQuery(params)
|
|
334
|
+
}));
|
|
335
|
+
ps.rpc.register(defineRpcFunction({
|
|
336
|
+
name: 'schema',
|
|
337
|
+
type: 'query',
|
|
338
|
+
jsonSerializable: true,
|
|
339
|
+
args: [sourceIdArg],
|
|
340
|
+
returns: anyResult,
|
|
341
|
+
agent: {
|
|
342
|
+
description: 'The client schema as the PowerSync SQLite core receives it: tables, columns, indexes. Argument: arg0 = database id or null for the first one.'
|
|
343
|
+
},
|
|
344
|
+
handler: (sourceId) => pickSource(sourceId).integration.getSchema()
|
|
345
|
+
}));
|
|
346
|
+
ps.rpc.register(defineRpcFunction({
|
|
347
|
+
name: 'info',
|
|
348
|
+
type: 'query',
|
|
349
|
+
jsonSerializable: true,
|
|
350
|
+
args: [sourceIdArg],
|
|
351
|
+
returns: anyResult,
|
|
352
|
+
agent: {
|
|
353
|
+
description: 'Connection info of the PowerSync client: endpoint, user id, client id, connection method, core version. Argument: arg0 = database id or null for the first one.'
|
|
354
|
+
},
|
|
355
|
+
handler: (sourceId) => pickSource(sourceId).integration.getInfo()
|
|
356
|
+
}));
|
|
357
|
+
ps.rpc.register(defineRpcFunction({
|
|
358
|
+
name: 'status',
|
|
359
|
+
type: 'query',
|
|
360
|
+
jsonSerializable: true,
|
|
361
|
+
args: [sourceIdArg],
|
|
362
|
+
returns: anyResult,
|
|
363
|
+
agent: {
|
|
364
|
+
description: 'The latest sync status the PowerSync client reported: connected, downloading, progress, last sync, errors. Null until it has reported. Argument: arg0 = database id or null for the first one.'
|
|
365
|
+
},
|
|
366
|
+
handler: async (sourceId) => latestSnapshot(sourceId, 'status')
|
|
367
|
+
}));
|
|
368
|
+
ps.rpc.register(defineRpcFunction({
|
|
369
|
+
name: 'upload-queue',
|
|
370
|
+
type: 'query',
|
|
371
|
+
jsonSerializable: true,
|
|
372
|
+
args: [sourceIdArg],
|
|
373
|
+
returns: anyResult,
|
|
374
|
+
agent: {
|
|
375
|
+
description: 'Pending local changes waiting to upload, as last reported: count and size. Null until reported. Argument: arg0 = database id or null for the first one.'
|
|
376
|
+
},
|
|
377
|
+
handler: async (sourceId) => latestSnapshot(sourceId, 'uploadQueue')
|
|
378
|
+
}));
|
|
379
|
+
ps.rpc.register(defineRpcFunction({
|
|
380
|
+
name: 'action',
|
|
381
|
+
type: 'action',
|
|
382
|
+
jsonSerializable: true,
|
|
383
|
+
args: [actionRequestArg, sourceIdArg],
|
|
384
|
+
returns: anyResult,
|
|
385
|
+
agent: {
|
|
386
|
+
description: 'Run a control action on the PowerSync client: reconnect, disconnect, clearData (wipes local data and re-syncs), requestCheckpoint, subscribeStream, unsubscribeStream. Arguments: arg0 = { action, args? }, arg1 = database id or null for the first one.',
|
|
387
|
+
safety: 'destructive'
|
|
388
|
+
},
|
|
389
|
+
handler: (request, sourceId) => pickSource(sourceId).integration.action(request)
|
|
390
|
+
}));
|
|
391
|
+
// --- UI facing: pushed events ---
|
|
392
|
+
ps.rpc.register(defineRpcFunction({
|
|
393
|
+
name: 'observe',
|
|
394
|
+
type: 'action',
|
|
395
|
+
jsonSerializable: true,
|
|
396
|
+
handler: (sourceId) => {
|
|
397
|
+
const session = currentSession();
|
|
398
|
+
observers.set(session.meta.id, session);
|
|
399
|
+
ensureSweep();
|
|
400
|
+
const live = liveSources();
|
|
401
|
+
// The list first, so the UI knows which database the snapshots that follow belong to.
|
|
402
|
+
void session.rpc.$callEvent('powersync:sources-changed', sourceInfos());
|
|
403
|
+
const source = sourceId ? live.find((candidate) => candidate.id === sourceId) : live[0];
|
|
404
|
+
if (!source)
|
|
405
|
+
return;
|
|
406
|
+
for (const event of source.snapshots.values()) {
|
|
407
|
+
pushEvent(session, source.id, event);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}));
|
|
411
|
+
ps.rpc.register(defineRpcFunction({
|
|
412
|
+
name: 'unobserve',
|
|
413
|
+
type: 'action',
|
|
414
|
+
jsonSerializable: true,
|
|
415
|
+
handler: () => {
|
|
416
|
+
observers.delete(currentSession().meta.id);
|
|
417
|
+
}
|
|
418
|
+
}));
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
//# sourceMappingURL=definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../src/definition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,O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,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACxF,IAAI,CAAC,MAAM;oBAAE,OAAO;gBACpB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;oBAC9C,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC;SACF,CAAC,CACH,CAAC;QACF,EAAE,CAAC,GAAG,CAAC,QAAQ,CACb,iBAAiB,CAAC;YAChB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,QAAQ;YACd,gBAAgB,EAAE,IAAI;YACtB,OAAO,EAAE,GAAG,EAAE;gBACZ,SAAS,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC7C,CAAC;SACF,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/lib/src/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The PowerSync devframe definition and the node-side registry of served databases.
|
|
2
|
+
// Hosts mount it: `./vite` (Vite DevTools dock) and `./node` (a node app's dev server).
|
|
3
|
+
import './rpc-types.js';
|
|
4
|
+
export { definition, registerIntegration, setSetupSdks, uiDistDir } from './definition.js';
|
|
5
|
+
export { UI_ROUTE, DEVFRAME_ID } from './constants.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,wFAAwF;AACxF,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE3F,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { CommonPowerSyncDatabase, PowerSyncBackendConnector, SyncOptions } from '@powersync/common';
|
|
2
|
+
import type { ActionRequest, CoreDiagnosticsEvent, DiagnosticsEvent, ProtocolInfo, QueryParams, QueryResult, SchemaPayload, SdkIntegration, Unsubscribe } from '@powersync/diagnostics-core';
|
|
3
|
+
/** Delivers the SQLite core's diagnostics events to the agent. How they arrive is runtime-specific. */
|
|
4
|
+
export interface CoreEventSource {
|
|
5
|
+
onEvent(handler: (event: CoreDiagnosticsEvent) => void): Unsubscribe;
|
|
6
|
+
dispose(): void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Read access to the live connection. The connector and options are not on the database's public
|
|
10
|
+
* interface, so the code that installs the agent (which can see the concrete database) hands them in.
|
|
11
|
+
*/
|
|
12
|
+
export interface ConnectionAccess {
|
|
13
|
+
getConnector(): PowerSyncBackendConnector | null;
|
|
14
|
+
getConnectionOptions(): SyncOptions | null;
|
|
15
|
+
}
|
|
16
|
+
export interface JsAgentOptions {
|
|
17
|
+
/** A label for the SDK behind this agent, e.g. `@powersync/web`. */
|
|
18
|
+
sdk?: string;
|
|
19
|
+
/** Debounce for re-reading bucket stats after internal-table changes. */
|
|
20
|
+
bucketThrottleMs?: number;
|
|
21
|
+
/** Core diagnostics events (per-bucket `target_count`). Omit when core diagnostics are off. */
|
|
22
|
+
coreEvents?: CoreEventSource;
|
|
23
|
+
/** Read access to the live connection; omit if the runtime cannot expose it. */
|
|
24
|
+
connection?: ConnectionAccess;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The JavaScript `SdkIntegration`: runs next to a live PowerSync database and answers the protocol
|
|
28
|
+
* from it. Every status change is pushed as mapped state; requests are answered by querying the
|
|
29
|
+
* live client. Hosts reach it through a bridge or call it directly when they share the page.
|
|
30
|
+
*/
|
|
31
|
+
export declare class JsAgent implements SdkIntegration {
|
|
32
|
+
private db;
|
|
33
|
+
private options;
|
|
34
|
+
private handlers;
|
|
35
|
+
private disposers;
|
|
36
|
+
private started;
|
|
37
|
+
/** Debug subscriptions created through `action`, keyed by name + params, so they can be released. */
|
|
38
|
+
private streamHandles;
|
|
39
|
+
private lastConnector;
|
|
40
|
+
private lastConnectionOptions;
|
|
41
|
+
private bucketTargets;
|
|
42
|
+
constructor(db: CommonPowerSyncDatabase, options?: JsAgentOptions);
|
|
43
|
+
runQuery({ sql, params }: QueryParams): Promise<QueryResult>;
|
|
44
|
+
getSchema(): Promise<SchemaPayload>;
|
|
45
|
+
getInfo(): Promise<ProtocolInfo>;
|
|
46
|
+
observeEvents(handler: (event: DiagnosticsEvent) => void): Promise<Unsubscribe>;
|
|
47
|
+
action(request: ActionRequest): Promise<void>;
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
private start;
|
|
50
|
+
private replay;
|
|
51
|
+
private emit;
|
|
52
|
+
private pushStatus;
|
|
53
|
+
private readUploadQueue;
|
|
54
|
+
private pushUploadQueue;
|
|
55
|
+
private pushBuckets;
|
|
56
|
+
private readBuckets;
|
|
57
|
+
/** Wraps `db.logger.log` so every SDK log record is forwarded; restored on close. */
|
|
58
|
+
private captureLogs;
|
|
59
|
+
private pushLog;
|
|
60
|
+
private handleCoreEvent;
|
|
61
|
+
private captureConnection;
|
|
62
|
+
private reconnect;
|
|
63
|
+
}
|