@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.
Files changed (56) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +138 -0
  3. package/lib/src/agent-server.d.ts +21 -0
  4. package/lib/src/agent-server.js +51 -0
  5. package/lib/src/agent-server.js.map +1 -0
  6. package/lib/src/agent.d.ts +11 -0
  7. package/lib/src/agent.js +30 -0
  8. package/lib/src/agent.js.map +1 -0
  9. package/lib/src/client.d.ts +7 -0
  10. package/lib/src/client.js +30 -0
  11. package/lib/src/client.js.map +1 -0
  12. package/lib/src/constants.d.ts +13 -0
  13. package/lib/src/constants.js +14 -0
  14. package/lib/src/constants.js.map +1 -0
  15. package/lib/src/definition.d.ts +16 -0
  16. package/lib/src/definition.js +421 -0
  17. package/lib/src/definition.js.map +1 -0
  18. package/lib/src/index.d.ts +4 -0
  19. package/lib/src/index.js +6 -0
  20. package/lib/src/index.js.map +1 -0
  21. package/lib/src/js-agent.d.ts +63 -0
  22. package/lib/src/js-agent.js +298 -0
  23. package/lib/src/js-agent.js.map +1 -0
  24. package/lib/src/node.d.ts +59 -0
  25. package/lib/src/node.js +40 -0
  26. package/lib/src/node.js.map +1 -0
  27. package/lib/src/page.d.ts +5 -0
  28. package/lib/src/page.js +50 -0
  29. package/lib/src/page.js.map +1 -0
  30. package/lib/src/rpc-types.d.ts +42 -0
  31. package/lib/src/rpc-types.js +2 -0
  32. package/lib/src/rpc-types.js.map +1 -0
  33. package/lib/src/sync-state.d.ts +4 -0
  34. package/lib/src/sync-state.js +53 -0
  35. package/lib/src/sync-state.js.map +1 -0
  36. package/lib/src/vite-static.d.ts +18 -0
  37. package/lib/src/vite-static.js +67 -0
  38. package/lib/src/vite-static.js.map +1 -0
  39. package/lib/src/vite.d.ts +27 -0
  40. package/lib/src/vite.js +43 -0
  41. package/lib/src/vite.js.map +1 -0
  42. package/lib/tsconfig.tsbuildinfo +1 -0
  43. package/package.json +98 -0
  44. package/src/agent-server.ts +73 -0
  45. package/src/agent.ts +58 -0
  46. package/src/client.ts +37 -0
  47. package/src/constants.ts +15 -0
  48. package/src/definition.ts +504 -0
  49. package/src/index.ts +7 -0
  50. package/src/js-agent.ts +378 -0
  51. package/src/node.ts +89 -0
  52. package/src/page.ts +61 -0
  53. package/src/rpc-types.ts +55 -0
  54. package/src/sync-state.ts +61 -0
  55. package/src/vite-static.ts +83 -0
  56. package/src/vite.ts +55 -0
@@ -0,0 +1,298 @@
1
+ import { toStreamStates, toSyncState } from './sync-state.js';
2
+ /**
3
+ * The JavaScript `SdkIntegration`: runs next to a live PowerSync database and answers the protocol
4
+ * from it. Every status change is pushed as mapped state; requests are answered by querying the
5
+ * live client. Hosts reach it through a bridge or call it directly when they share the page.
6
+ */
7
+ export class JsAgent {
8
+ db;
9
+ options;
10
+ handlers = new Set();
11
+ disposers = [];
12
+ started = false;
13
+ /** Debug subscriptions created through `action`, keyed by name + params, so they can be released. */
14
+ streamHandles = new Map();
15
+ // Retained so reconnect / clear work after a disconnect, when the connection no longer exposes them.
16
+ lastConnector = null;
17
+ lastConnectionOptions = null;
18
+ // Per-bucket total operation counts from the core diagnostics stream (not stored in ps_buckets).
19
+ bucketTargets = new Map();
20
+ constructor(db, options = {}) {
21
+ this.db = db;
22
+ this.options = options;
23
+ }
24
+ // --- SdkIntegration ---
25
+ async runQuery({ sql, params }) {
26
+ const records = await this.db.getAll(sql, params);
27
+ const columns = records.length > 0 ? Object.keys(records[0]) : [];
28
+ return { columns, rows: records.map((record) => columns.map((column) => record[column])) };
29
+ }
30
+ async getSchema() {
31
+ // The core payload: what the client already sends to `powersync_replace_schema`.
32
+ return this.db.schema.toJSON();
33
+ }
34
+ async getInfo() {
35
+ const connection = this.options.connection;
36
+ let endpoint = null;
37
+ let token = null;
38
+ try {
39
+ const credentials = await connection?.getConnector()?.fetchCredentials();
40
+ endpoint = credentials?.endpoint ?? null;
41
+ token = credentials?.token ?? null;
42
+ }
43
+ catch {
44
+ // Credentials are unavailable before connect().
45
+ }
46
+ let clientId = null;
47
+ try {
48
+ clientId = await this.db.getClientId();
49
+ }
50
+ catch {
51
+ // Non-fatal.
52
+ }
53
+ let sqliteCoreVersion = null;
54
+ try {
55
+ const [row] = await this.db.getAll('SELECT powersync_rs_version() AS v');
56
+ sqliteCoreVersion = row?.v ?? null;
57
+ }
58
+ catch {
59
+ // Non-fatal.
60
+ }
61
+ const connectionOptions = connection?.getConnectionOptions() ?? null;
62
+ return {
63
+ endpoint,
64
+ token,
65
+ clientId,
66
+ connectionMethod: connectionOptions?.connectionMethod ?? null,
67
+ params: connectionOptions?.params ?? null,
68
+ connected: this.db.currentStatus?.connected ?? false,
69
+ sqliteCoreVersion,
70
+ sdk: this.options.sdk ?? null
71
+ };
72
+ }
73
+ async observeEvents(handler) {
74
+ this.handlers.add(handler);
75
+ this.start();
76
+ // A late subscriber receives the present state at once.
77
+ this.replay(handler);
78
+ return () => {
79
+ this.handlers.delete(handler);
80
+ };
81
+ }
82
+ async action(request) {
83
+ switch (request.action) {
84
+ case 'disconnect':
85
+ await this.db.disconnect();
86
+ break;
87
+ case 'clearData':
88
+ await this.db.disconnectAndClear();
89
+ await this.reconnect();
90
+ break;
91
+ case 'reconnect':
92
+ await this.db.disconnect();
93
+ await this.reconnect();
94
+ break;
95
+ case 'requestCheckpoint': {
96
+ // Confirms the client is caught up right now. Needs `checkpointMode: 'requests'` on connect.
97
+ const checkpoint = await this.db.requestCheckpoint();
98
+ await checkpoint.waitForSync({ signal: AbortSignal.timeout(120_000) });
99
+ break;
100
+ }
101
+ case 'subscribeStream': {
102
+ const { name, params, ttl, priority } = request.args;
103
+ // TTL defaults to 0 so a forgotten debug subscription is evicted as soon as it is released.
104
+ const handle = await this.db.syncStream(name, params).subscribe({ ttl: ttl ?? 0, priority });
105
+ this.streamHandles.set(streamKey(name, params), handle);
106
+ break;
107
+ }
108
+ case 'unsubscribeStream': {
109
+ const { name, params } = request.args;
110
+ const key = streamKey(name, params);
111
+ this.streamHandles.get(key)?.unsubscribe();
112
+ this.streamHandles.delete(key);
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ async close() {
118
+ for (const handle of this.streamHandles.values()) {
119
+ handle.unsubscribe();
120
+ }
121
+ this.streamHandles.clear();
122
+ for (const dispose of this.disposers) {
123
+ dispose();
124
+ }
125
+ this.disposers = [];
126
+ this.handlers.clear();
127
+ this.started = false;
128
+ }
129
+ // --- push bridge ---
130
+ start() {
131
+ if (this.started) {
132
+ return;
133
+ }
134
+ this.started = true;
135
+ this.disposers.push(this.db.registerListener({
136
+ statusChanged: (status) => {
137
+ this.captureConnection();
138
+ this.pushStatus(status);
139
+ void this.pushUploadQueue();
140
+ void this.pushBuckets();
141
+ }
142
+ }));
143
+ this.captureConnection();
144
+ if (this.options.coreEvents) {
145
+ const source = this.options.coreEvents;
146
+ this.disposers.push(source.onEvent((event) => this.handleCoreEvent(event)));
147
+ this.disposers.push(() => source.dispose());
148
+ }
149
+ this.captureLogs();
150
+ // Re-read bucket stats and the upload queue when internal tables change, so a local write shows up
151
+ // before the sync status moves.
152
+ this.disposers.push(this.db.onChangeWithCallback({
153
+ onChange: () => {
154
+ void this.pushBuckets();
155
+ void this.pushUploadQueue();
156
+ }
157
+ }, { tables: ['ps_buckets', 'ps_oplog', 'ps_crud'], throttleMs: this.options.bucketThrottleMs ?? 300 }));
158
+ }
159
+ replay(handler) {
160
+ const status = this.db.currentStatus;
161
+ handler({ type: 'status', payload: toSyncState(status) });
162
+ handler({ type: 'streams', payload: toStreamStates(status) });
163
+ void this.readUploadQueue()
164
+ .then((payload) => handler({ type: 'uploadQueue', payload }))
165
+ .catch(() => { });
166
+ void this.readBuckets()
167
+ .then((payload) => handler({ type: 'buckets', payload }))
168
+ .catch(() => { });
169
+ }
170
+ emit(event) {
171
+ for (const handler of this.handlers) {
172
+ try {
173
+ handler(event);
174
+ }
175
+ catch {
176
+ // One failing subscriber must not break the others.
177
+ }
178
+ }
179
+ }
180
+ pushStatus(status) {
181
+ this.emit({ type: 'status', payload: toSyncState(status) });
182
+ this.emit({ type: 'streams', payload: toStreamStates(status) });
183
+ }
184
+ async readUploadQueue() {
185
+ const stats = await this.db.getUploadQueueStats(true);
186
+ return { count: stats.count, size: stats.size ?? null };
187
+ }
188
+ async pushUploadQueue() {
189
+ try {
190
+ this.emit({ type: 'uploadQueue', payload: await this.readUploadQueue() });
191
+ }
192
+ catch {
193
+ // Non-fatal: queue stats are best-effort.
194
+ }
195
+ }
196
+ async pushBuckets() {
197
+ try {
198
+ this.emit({ type: 'buckets', payload: await this.readBuckets() });
199
+ }
200
+ catch {
201
+ // Non-fatal: the diagnostic tables may not exist yet.
202
+ }
203
+ }
204
+ async readBuckets() {
205
+ const downloading = this.db.currentStatus?.downloading ?? false;
206
+ const withSize = 'SELECT name, count_at_last + count_since_last AS ops, downloaded_size AS size, last_op FROM ps_buckets ORDER BY name';
207
+ const withoutSize = 'SELECT name, count_at_last + count_since_last AS ops, last_op FROM ps_buckets ORDER BY name';
208
+ let rows;
209
+ try {
210
+ rows = await this.db.getAll(withSize);
211
+ }
212
+ catch {
213
+ // `downloaded_size` is absent on older cores.
214
+ rows = await this.db.getAll(withoutSize);
215
+ }
216
+ return rows.map((row) => {
217
+ const name = String(row.name);
218
+ return {
219
+ name,
220
+ downloadedOperations: Number(row.ops) || 0,
221
+ totalOperations: this.bucketTargets.get(name) ?? null,
222
+ downloadedSize: row.size == null ? null : Number(row.size),
223
+ lastOp: row.last_op == null ? null : String(row.last_op),
224
+ downloading
225
+ };
226
+ });
227
+ }
228
+ /** Wraps `db.logger.log` so every SDK log record is forwarded; restored on close. */
229
+ captureLogs() {
230
+ const logger = this.db.logger;
231
+ if (!logger || typeof logger.log !== 'function') {
232
+ return;
233
+ }
234
+ const original = logger.log.bind(logger);
235
+ logger.log = (record) => {
236
+ original(record);
237
+ try {
238
+ this.pushLog(record);
239
+ }
240
+ catch {
241
+ // Never let diagnostics break the app's logging.
242
+ }
243
+ };
244
+ this.disposers.push(() => {
245
+ logger.log = original;
246
+ });
247
+ }
248
+ pushLog(record) {
249
+ const entry = {
250
+ timestamp: Date.now(),
251
+ level: logLevelName(record.level),
252
+ message: record.message,
253
+ args: record.error == null ? undefined : [record.error instanceof Error ? record.error.message : record.error]
254
+ };
255
+ this.emit({ type: 'newLogs', payload: [entry] });
256
+ }
257
+ handleCoreEvent(event) {
258
+ this.emit({ type: 'core', payload: event });
259
+ if ('BucketStateChange' in event) {
260
+ for (const bucket of event.BucketStateChange.changes) {
261
+ this.bucketTargets.set(bucket.name, bucket.progress.target_count);
262
+ }
263
+ void this.pushBuckets();
264
+ }
265
+ }
266
+ captureConnection() {
267
+ const connection = this.options.connection;
268
+ const connector = connection?.getConnector() ?? null;
269
+ if (connector) {
270
+ this.lastConnector = connector;
271
+ this.lastConnectionOptions = connection?.getConnectionOptions() ?? null;
272
+ }
273
+ }
274
+ async reconnect() {
275
+ if (this.lastConnector) {
276
+ await this.db.connect(this.lastConnector, this.lastConnectionOptions ?? undefined);
277
+ }
278
+ }
279
+ }
280
+ function streamKey(name, params) {
281
+ return `${name}|${JSON.stringify(params ?? null)}`;
282
+ }
283
+ // The SDK's log levels. `typeof LogLevels` makes the compiler hold these to the values in
284
+ // `@powersync/common`, which stays a type-only import because it is an optional peer.
285
+ const LOG_LEVELS = { trace: 10, debug: 20, info: 30, warn: 40, error: 50 };
286
+ /** Maps a numeric SDK log level to its name. */
287
+ function logLevelName(level) {
288
+ if (level >= LOG_LEVELS.error)
289
+ return 'error';
290
+ if (level >= LOG_LEVELS.warn)
291
+ return 'warn';
292
+ if (level >= LOG_LEVELS.info)
293
+ return 'info';
294
+ if (level >= LOG_LEVELS.debug)
295
+ return 'debug';
296
+ return 'trace';
297
+ }
298
+ //# sourceMappingURL=js-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js-agent.js","sourceRoot":"","sources":["../../src/js-agent.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE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CACF;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,MAAgC;IAC/D,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,IAAI,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,0FAA0F;AAC1F,sFAAsF;AACtF,MAAM,UAAU,GAAqB,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AAE7F,gDAAgD;AAChD,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,KAAK,IAAI,UAAU,CAAC,KAAK;QAAE,OAAO,OAAO,CAAC;IAC9C,IAAI,KAAK,IAAI,UAAU,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;IAC5C,IAAI,KAAK,IAAI,UAAU,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;IAC5C,IAAI,KAAK,IAAI,UAAU,CAAC,KAAK;QAAE,OAAO,OAAO,CAAC;IAC9C,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * PowerSync DevTools for a node app: the database lives in this process, so this process hosts the
3
+ * dev server itself. Opens the diagnostics UI on a local port and exposes the MCP tools at `/__mcp`.
4
+ */
5
+ import type { McpSetting } from 'devframe';
6
+ import type { CommonPowerSyncDatabase } from '@powersync/common';
7
+ export interface EnableDiagnosticsOptions {
8
+ /**
9
+ * Port for the DevTools window. By default the OS picks a free port, so other websites cannot
10
+ * probe a known one. @default random
11
+ */
12
+ port?: number;
13
+ /** Bind host. @default 'localhost' */
14
+ host?: string;
15
+ /**
16
+ * Gate the window behind a code printed in the terminal, together with a link that carries it, so
17
+ * opening the link is enough. `false` trusts every local browser. @default true
18
+ */
19
+ auth?: boolean;
20
+ /** Open the browser once the server is up. @default false */
21
+ open?: boolean;
22
+ /** A label for the SDK, shown in the UI. @default '@powersync/node' */
23
+ sdk?: string;
24
+ /** The source id shown in the UI. @default 'node-1' */
25
+ id?: string;
26
+ /**
27
+ * The MCP endpoint at `<url>/__mcp`. By default it mounts once the tools exist and accepts only
28
+ * requests with a loopback `Origin` header; a request without one gets `403`. Pass
29
+ * `{ allowedOrigins: false }` for an MCP client that sends no `Origin` header, `false` to leave
30
+ * the endpoint off, or `{ authorization }` to require a bearer token. @default 'auto'
31
+ */
32
+ mcp?: McpSetting;
33
+ }
34
+ export interface DiagnosticsServer {
35
+ /** Where the UI is, e.g. `http://localhost:51234`. The base for `<url>/__mcp`. */
36
+ url: string;
37
+ /**
38
+ * The link to open in the browser. With `auth` on, it carries a one-time code (valid for five
39
+ * minutes, for one browser), so opening it trusts the browser. With `auth: false`, it equals `url`.
40
+ */
41
+ signInUrl: string;
42
+ /** Stops serving and detaches the database. */
43
+ close(): Promise<void>;
44
+ }
45
+ /**
46
+ * Serves live diagnostics for `db` from this process. Development only: call it behind your own
47
+ * environment check.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const db = new PowerSyncDatabase({ ... });
52
+ * if (process.env.NODE_ENV !== 'production') {
53
+ * const { enablePowerSyncDiagnostics } = await import('@powersync/diagnostics/node');
54
+ * const devtools = await enablePowerSyncDiagnostics(db);
55
+ * console.log(`PowerSync DevTools: ${devtools.signInUrl}`);
56
+ * }
57
+ * ```
58
+ */
59
+ export declare function enablePowerSyncDiagnostics(db: CommonPowerSyncDatabase, options?: EnableDiagnosticsOptions): Promise<DiagnosticsServer>;
@@ -0,0 +1,40 @@
1
+ import { createDevServer } from 'devframe/adapters/dev';
2
+ import { buildOtpAuthUrl } from 'devframe/node/auth';
3
+ import { createIntegration } from './agent.js';
4
+ import { definition, registerIntegration, setSetupSdks } from './definition.js';
5
+ /**
6
+ * Serves live diagnostics for `db` from this process. Development only: call it behind your own
7
+ * environment check.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const db = new PowerSyncDatabase({ ... });
12
+ * if (process.env.NODE_ENV !== 'production') {
13
+ * const { enablePowerSyncDiagnostics } = await import('@powersync/diagnostics/node');
14
+ * const devtools = await enablePowerSyncDiagnostics(db);
15
+ * console.log(`PowerSync DevTools: ${devtools.signInUrl}`);
16
+ * }
17
+ * ```
18
+ */
19
+ export async function enablePowerSyncDiagnostics(db, options = {}) {
20
+ const sdk = options.sdk ?? '@powersync/node';
21
+ const detach = await registerIntegration(options.id ?? 'node-1', createIntegration(db, sdk), sdk);
22
+ setSetupSdks(['node']);
23
+ const auth = options.auth ?? true;
24
+ const server = await createDevServer(definition, {
25
+ port: options.port ?? 0,
26
+ host: options.host,
27
+ auth,
28
+ openBrowser: options.open ?? false,
29
+ mcp: options.mcp ?? 'auto'
30
+ });
31
+ return {
32
+ url: server.origin,
33
+ signInUrl: auth ? buildOtpAuthUrl(server.origin) : server.origin,
34
+ async close() {
35
+ detach();
36
+ await server.close();
37
+ }
38
+ };
39
+ }
40
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA0ChF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,EAA2B,EAC3B,UAAoC,EAAE;IAEtC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,iBAAiB,CAAC;IAC7C,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,EAAE,IAAI,QAAQ,EAAE,iBAAiB,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAClG,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACvB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;IAClC,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,UAAU,EAAE;QAC/C,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC;QACvB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI;QACJ,WAAW,EAAE,OAAO,CAAC,IAAI,IAAI,KAAK;QAClC,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,MAAM;KAC3B,CAAC,CAAC;IACH,OAAO;QACL,GAAG,EAAE,MAAM,CAAC,MAAM;QAClB,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM;QAChE,KAAK,CAAC,KAAK;YACT,MAAM,EAAE,CAAC;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Serves the app's first live database to any iframe that asks. Call once per page.
3
+ * Returns a function that stops serving.
4
+ */
5
+ export declare function serveDiagnostics(): () => void;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The page side for hosts without a devframe hub: the app loads this module during development, and
3
+ * it serves the app's live database to any diagnostics UI iframe that asks over `postMessage`.
4
+ * Nuxt DevTools v3 uses it together with `./vite-static`. Nothing here reaches a production build:
5
+ * the host loads the module only in dev.
6
+ */
7
+ import { PORT_MESSAGE, REQUEST_PORT_MESSAGE, exposeIntegration } from '@powersync/diagnostics-core';
8
+ import { observeRegisteredDatabases } from '@powersync/web/devtools';
9
+ import { createIntegration } from './agent.js';
10
+ const SDK = '@powersync/web';
11
+ /**
12
+ * Serves the app's first live database to any iframe that asks. Call once per page.
13
+ * Returns a function that stops serving.
14
+ */
15
+ export function serveDiagnostics() {
16
+ let integration = null;
17
+ const stops = new Set();
18
+ const stopObserving = observeRegisteredDatabases((databases) => {
19
+ const next = databases[0] ?? null;
20
+ // The database changed (opened, or the previous one closed): drop the old integration.
21
+ for (const stop of stops)
22
+ stop();
23
+ stops.clear();
24
+ void integration?.close();
25
+ integration = next ? createIntegration(next, SDK) : null;
26
+ });
27
+ const onMessage = (event) => {
28
+ if (event.data?.type !== REQUEST_PORT_MESSAGE) {
29
+ return;
30
+ }
31
+ if (!integration) {
32
+ return;
33
+ }
34
+ // One dedicated channel per asking iframe, so several docks can attach at once.
35
+ const channel = new MessageChannel();
36
+ stops.add(exposeIntegration(integration, channel.port1));
37
+ event.source?.postMessage({ type: PORT_MESSAGE }, { targetOrigin: event.origin, transfer: [channel.port2] });
38
+ };
39
+ window.addEventListener('message', onMessage);
40
+ return () => {
41
+ window.removeEventListener('message', onMessage);
42
+ stopObserving();
43
+ for (const stop of stops)
44
+ stop();
45
+ void integration?.close();
46
+ };
47
+ }
48
+ // Loaded as a side-effect module: start serving as soon as the page loads it.
49
+ serveDiagnostics();
50
+ //# sourceMappingURL=page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/page.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EAElB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,GAAG,GAAG,gBAAgB,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,WAAW,GAA0B,IAAI,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAc,CAAC;IAEpC,MAAM,aAAa,GAAG,0BAA0B,CAAC,CAAC,SAAS,EAAE,EAAE;QAC7D,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QAClC,uFAAuF;QACvF,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ection, declared once so
3
+ * every `rpc.call` / `session.rpc.$call` is type-checked against the same contract. devframe types
4
+ * calls against these two registries; augmenting them is the documented way to add functions.
5
+ */
6
+ import type { ActionRequest, DiagnosticsEvent, ProtocolInfo, QueryParams, QueryResult, SchemaPayload, SyncState, UploadQueueState } from '@powersync/diagnostics-core';
7
+ /** A database served through the node side. */
8
+ export interface SourceInfo {
9
+ id: string;
10
+ /** A label for the SDK behind it, e.g. `@powersync/web`. */
11
+ sdk: string | null;
12
+ }
13
+ /** An SDK the UI's "no database" screens can explain, the same names the UI takes as `sdks`. */
14
+ export type SetupSdk = 'web' | 'nuxt' | 'node' | 'dart';
15
+ declare module 'devframe/types' {
16
+ /** Functions the node side serves; called by the UI, by agents over MCP, and by pages announcing a database. */
17
+ interface DevframeRpcServerFunctions {
18
+ 'powersync:sources': () => SourceInfo[];
19
+ 'powersync:setup-sdks': () => SetupSdk[] | null;
20
+ 'powersync:query': (params: QueryParams, sourceId?: string | null) => Promise<QueryResult>;
21
+ 'powersync:schema': (sourceId?: string | null) => Promise<SchemaPayload>;
22
+ 'powersync:info': (sourceId?: string | null) => Promise<ProtocolInfo>;
23
+ 'powersync:status': (sourceId?: string | null) => Promise<SyncState | null>;
24
+ 'powersync:upload-queue': (sourceId?: string | null) => Promise<UploadQueueState | null>;
25
+ 'powersync:action': (request: ActionRequest, sourceId?: string | null) => Promise<void>;
26
+ 'powersync:observe': (sourceId?: string | null) => void;
27
+ 'powersync:unobserve': () => void;
28
+ 'powersync:page-register': (sourceId: string, sdk: string | null) => void;
29
+ 'powersync:page-unregister': (sourceId: string) => void;
30
+ 'powersync:page-heartbeat': (sourceId: string) => void;
31
+ 'powersync:page-event': (sourceId: string, event: DiagnosticsEvent) => void;
32
+ }
33
+ /** Functions a connected page or app serves; called by the node side on the session that announced the database. */
34
+ interface DevframeRpcClientFunctions {
35
+ 'powersync:event': (sourceId: string, event: DiagnosticsEvent) => void;
36
+ 'powersync:sources-changed': (sources: SourceInfo[]) => void;
37
+ 'powersync:page-query': (sourceId: string, params: QueryParams) => Promise<QueryResult>;
38
+ 'powersync:page-schema': (sourceId: string) => Promise<SchemaPayload>;
39
+ 'powersync:page-info': (sourceId: string) => Promise<ProtocolInfo>;
40
+ 'powersync:page-action': (sourceId: string, request: ActionRequest) => Promise<void>;
41
+ }
42
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rpc-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-types.js","sourceRoot":"","sources":["../../src/rpc-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { SyncStatus } from '@powersync/common';
2
+ import type { StreamState, SyncState } from '@powersync/diagnostics-core';
3
+ export declare function toSyncState(status: SyncStatus): SyncState;
4
+ export declare function toStreamStates(status: SyncStatus): StreamState[];
@@ -0,0 +1,53 @@
1
+ /** Maps the SDK's live sync status onto the plain, serializable protocol shapes. */
2
+ function toProgress(progress) {
3
+ if (!progress) {
4
+ return null;
5
+ }
6
+ return {
7
+ downloadedOperations: progress.downloadedOperations,
8
+ totalOperations: progress.totalOperations
9
+ };
10
+ }
11
+ function toEpoch(date) {
12
+ return date ? date.getTime() : null;
13
+ }
14
+ function errorText(error) {
15
+ return error ? String(error.message ?? error) : null;
16
+ }
17
+ export function toSyncState(status) {
18
+ const priorities = (status.priorityStatusEntries ?? []).map((entry) => ({
19
+ priority: entry.priority,
20
+ lastSyncedAt: toEpoch(entry.lastSyncedAt),
21
+ hasSynced: entry.hasSynced ?? null
22
+ }));
23
+ return {
24
+ connected: status.connected,
25
+ connecting: status.connecting,
26
+ downloading: status.downloading,
27
+ uploading: status.uploading,
28
+ hasSynced: status.hasSynced ?? null,
29
+ lastSyncedAt: toEpoch(status.lastSyncedAt),
30
+ downloadProgress: toProgress(status.downloadProgress),
31
+ priorities,
32
+ downloadError: errorText(status.downloadError),
33
+ uploadError: errorText(status.uploadError)
34
+ };
35
+ }
36
+ export function toStreamStates(status) {
37
+ return (status.syncStreams ?? []).map((stream) => {
38
+ const subscription = stream.subscription;
39
+ return {
40
+ name: subscription.name,
41
+ priority: stream.priority,
42
+ active: subscription.active,
43
+ autoSubscribed: subscription.isDefault,
44
+ explicitlySubscribed: subscription.hasExplicitSubscription,
45
+ progress: toProgress(stream.progress),
46
+ params: subscription.parameters,
47
+ expiresAt: toEpoch(subscription.expiresAt),
48
+ hasSynced: subscription.hasSynced,
49
+ lastSyncedAt: toEpoch(subscription.lastSyncedAt)
50
+ };
51
+ });
52
+ }
53
+ //# sourceMappingURL=sync-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-state.js","sourceRoot":"","sources":["../../src/sync-state.ts"],"names":[],"mappings":"AAGA,oFAAoF;AAEpF,SAAS,UAAU,CAAC,QAAmD;IACrE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO;QACL,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB;QACnD,eAAe,EAAE,QAAQ,CAAC,eAAe;KAC1C,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,IAA6B;IAC5C,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACtC,CAAC;AAED,SAAS,SAAS,CAAC,KAA8C;IAC/D,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC5C,MAAM,UAAU,GAAoB,CAAC,MAAM,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAyB,EAAE,EAAE,CAAC,CAAC;QAC3G,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC;QACzC,SAAS,EAAE,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'vite';
2
+ export interface PowersyncStaticOptions {
3
+ /**
4
+ * URLs of scripts to run inside the UI page, added as `<script type="module">` tags. For a host
5
+ * that has to bridge something from its own environment into the page, such as its theme, without
6
+ * the UI knowing the host.
7
+ */
8
+ scripts?: string[];
9
+ }
10
+ /**
11
+ * Serves the diagnostics UI at {@link UI_ROUTE} from a plain Vite dev server, with no devframe hub.
12
+ *
13
+ * For hosts that embed the UI in their own iframe and hand it the integration over `postMessage`:
14
+ * Nuxt DevTools v3 does this, with `./page` loaded in the app. The UI is a static page outside the
15
+ * app's router, so no route guard or auth middleware applies to it. Serve-only; nothing reaches a
16
+ * production build.
17
+ */
18
+ export default function powersyncStatic(options?: PowersyncStaticOptions): Plugin;