@powersync/diagnostics 0.0.0-dev-20261020125654 → 0.0.0-dev-20261113122937
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 +50 -2
- package/dist/devtools/assets/powersync-CHeJS2lE.js +184 -0
- package/dist/devtools/assets/powersync-lB_i3nJt.css +1 -0
- package/dist/devtools/powersync.html +24 -0
- package/dist/rozenite.json +14 -0
- package/lib/src/agent.d.ts +3 -1
- package/lib/src/agent.js +36 -8
- package/lib/src/agent.js.map +1 -1
- package/lib/src/client.js +4 -4
- package/lib/src/client.js.map +1 -1
- package/lib/src/definition.js +11 -17
- package/lib/src/definition.js.map +1 -1
- package/lib/src/js-agent.d.ts +6 -13
- package/lib/src/js-agent.js +23 -10
- package/lib/src/js-agent.js.map +1 -1
- package/lib/src/node.d.ts +1 -1
- package/lib/src/node.js +2 -2
- package/lib/src/node.js.map +1 -1
- package/lib/src/page.js +2 -3
- package/lib/src/page.js.map +1 -1
- package/lib/src/react-native/agent-tools.d.ts +3 -0
- package/lib/src/react-native/agent-tools.js +137 -0
- package/lib/src/react-native/agent-tools.js.map +1 -0
- package/lib/src/react-native/protocol.d.ts +22 -0
- package/lib/src/react-native/protocol.js +5 -0
- package/lib/src/react-native/protocol.js.map +1 -0
- package/lib/src/react-native/usePowerSyncDevTools.d.ts +7 -0
- package/lib/src/react-native/usePowerSyncDevTools.js +56 -0
- package/lib/src/react-native/usePowerSyncDevTools.js.map +1 -0
- package/lib/src/react-native.d.ts +7 -0
- package/lib/src/react-native.js +8 -0
- package/lib/src/react-native.js.map +1 -0
- package/lib/src/rpc-types.d.ts +1 -1
- package/lib/src/tools.d.ts +19 -0
- package/lib/src/tools.js +24 -0
- package/lib/src/tools.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -13
- package/src/agent.ts +45 -17
- package/src/client.ts +4 -5
- package/src/definition.ts +11 -17
- package/src/js-agent.ts +33 -27
- package/src/node.ts +3 -3
- package/src/page.ts +2 -4
- package/src/react-native/agent-tools.ts +148 -0
- package/src/react-native/protocol.ts +33 -0
- package/src/react-native/usePowerSyncDevTools.ts +59 -0
- package/src/react-native.ts +14 -0
- package/src/rpc-types.ts +1 -1
- package/src/tools.ts +35 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between the app side (`usePowerSyncDevTools`) and the DevTools panel, carried over a
|
|
3
|
+
* Rozenite plugin channel. Calls go over Rozenite RPC; pushed events go as plain plugin messages.
|
|
4
|
+
*/
|
|
5
|
+
import type {
|
|
6
|
+
ActionRequest,
|
|
7
|
+
DiagnosticsEvent,
|
|
8
|
+
ProtocolInfo,
|
|
9
|
+
QueryParams,
|
|
10
|
+
QueryResult,
|
|
11
|
+
SchemaPayload
|
|
12
|
+
} from '@powersync/diagnostics-core';
|
|
13
|
+
|
|
14
|
+
/** The Rozenite plugin id. Rozenite finds the plugin by this package name. */
|
|
15
|
+
export const PLUGIN_ID = '@powersync/diagnostics';
|
|
16
|
+
|
|
17
|
+
/** The message type that carries one {@link DiagnosticsEvent} from the app to the panel. */
|
|
18
|
+
export const EVENT_MESSAGE = 'powersync:event';
|
|
19
|
+
|
|
20
|
+
/** Plugin messages, keyed by type. */
|
|
21
|
+
export type DevToolsEventMap = {
|
|
22
|
+
[EVENT_MESSAGE]: DiagnosticsEvent;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Methods the app serves to the panel. */
|
|
26
|
+
export type AppMethods = {
|
|
27
|
+
runQuery: (params: QueryParams) => Promise<QueryResult>;
|
|
28
|
+
getSchema: () => Promise<SchemaPayload>;
|
|
29
|
+
getInfo: () => Promise<ProtocolInfo>;
|
|
30
|
+
action: (request: ActionRequest) => Promise<void>;
|
|
31
|
+
/** Starts (or restarts) the event stream; the app pushes the current snapshots first. */
|
|
32
|
+
subscribe: () => Promise<void>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { createRozeniteRpc, useRozeniteDevToolsClient } from '@rozenite/plugin-bridge';
|
|
3
|
+
import type { CommonPowerSyncDatabase } from '@powersync/common';
|
|
4
|
+
import type { SdkIntegration, Unsubscribe } from '@powersync/diagnostics-core';
|
|
5
|
+
import { createIntegration } from '../agent.js';
|
|
6
|
+
import { usePowerSyncAgentTools } from './agent-tools.js';
|
|
7
|
+
import { EVENT_MESSAGE, PLUGIN_ID, type AppMethods, type DevToolsEventMap } from './protocol.js';
|
|
8
|
+
|
|
9
|
+
const SDK = '@powersync/react-native';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Serves `database` to the PowerSync panel in React Native DevTools (through Rozenite), and to coding
|
|
13
|
+
* agents as Rozenite agent tools. Call it in a component that stays mounted, such as the app root.
|
|
14
|
+
* Pass `null` while the database is not created yet; DevTools attach once it is.
|
|
15
|
+
*/
|
|
16
|
+
export function usePowerSyncDevTools(database: CommonPowerSyncDatabase | null): void {
|
|
17
|
+
const client = useRozeniteDevToolsClient<DevToolsEventMap>({ pluginId: PLUGIN_ID });
|
|
18
|
+
const [integration, setIntegration] = useState<SdkIntegration | null>(null);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!database) return;
|
|
22
|
+
const created = createIntegration(database, SDK);
|
|
23
|
+
setIntegration(created);
|
|
24
|
+
return () => {
|
|
25
|
+
setIntegration(null);
|
|
26
|
+
void created.close();
|
|
27
|
+
};
|
|
28
|
+
}, [database]);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!client || !integration) return;
|
|
32
|
+
const rpc = createRozeniteRpc<AppMethods>(client);
|
|
33
|
+
let stopEvents: Unsubscribe | null = null;
|
|
34
|
+
let closed = false;
|
|
35
|
+
|
|
36
|
+
const handlers = [
|
|
37
|
+
rpc.handle('runQuery', (params) => integration.runQuery(params)),
|
|
38
|
+
rpc.handle('getSchema', () => integration.getSchema()),
|
|
39
|
+
rpc.handle('getInfo', () => integration.getInfo()),
|
|
40
|
+
rpc.handle('action', (request) => integration.action(request)),
|
|
41
|
+
// A panel (re)opening asks for the stream; restarting it replays the current snapshots.
|
|
42
|
+
rpc.handle('subscribe', async () => {
|
|
43
|
+
stopEvents?.();
|
|
44
|
+
const unsubscribe = await integration.observeEvents((event) => client.send(EVENT_MESSAGE, event));
|
|
45
|
+
if (closed) unsubscribe();
|
|
46
|
+
else stopEvents = unsubscribe;
|
|
47
|
+
})
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
return () => {
|
|
51
|
+
closed = true;
|
|
52
|
+
for (const handler of handlers) handler.remove();
|
|
53
|
+
stopEvents?.();
|
|
54
|
+
rpc.close();
|
|
55
|
+
};
|
|
56
|
+
}, [client, integration]);
|
|
57
|
+
|
|
58
|
+
usePowerSyncAgentTools(integration);
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PowerSync DevTools for React Native apps, as a Rozenite plugin: a panel in React Native DevTools and
|
|
3
|
+
* agent tools for Rozenite's agent CLI. Production bundles get a no-op: the `require` below sits
|
|
4
|
+
* behind a check bundlers resolve at build time, so the DevTools code is left out.
|
|
5
|
+
*/
|
|
6
|
+
import type { CommonPowerSyncDatabase } from '@powersync/common';
|
|
7
|
+
|
|
8
|
+
export let usePowerSyncDevTools: (database: CommonPowerSyncDatabase | null) => void;
|
|
9
|
+
|
|
10
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
11
|
+
usePowerSyncDevTools = require('./react-native/usePowerSyncDevTools.js').usePowerSyncDevTools;
|
|
12
|
+
} else {
|
|
13
|
+
usePowerSyncDevTools = () => {};
|
|
14
|
+
}
|
package/src/rpc-types.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface SourceInfo {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** An SDK the UI's "no database" screens can explain, the same names the UI takes as `sdks`. */
|
|
25
|
-
export type SetupSdk = 'web' | 'nuxt' | 'node' | 'dart';
|
|
25
|
+
export type SetupSdk = 'web' | 'nuxt' | 'node' | 'react-native' | 'dart';
|
|
26
26
|
|
|
27
27
|
declare module 'devframe/types' {
|
|
28
28
|
/** Functions the node side serves; called by the UI, by agents over MCP, and by pages announcing a database. */
|
package/src/tools.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent tools every host offers: the devframe MCP functions and the Rozenite agent tools. Each host
|
|
3
|
+
* adds how its arguments are passed; the names and descriptions stay the same.
|
|
4
|
+
*/
|
|
5
|
+
import type { ActionName } from '@powersync/diagnostics-core';
|
|
6
|
+
|
|
7
|
+
// A record, so a new action name fails to compile until it is listed here.
|
|
8
|
+
const actions: Record<ActionName, true> = {
|
|
9
|
+
reconnect: true,
|
|
10
|
+
disconnect: true,
|
|
11
|
+
clearData: true,
|
|
12
|
+
requestCheckpoint: true,
|
|
13
|
+
subscribeStream: true,
|
|
14
|
+
unsubscribeStream: true
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const ACTION_NAMES = Object.keys(actions) as [ActionName, ...ActionName[]];
|
|
18
|
+
|
|
19
|
+
export const TOOL_DESCRIPTIONS = {
|
|
20
|
+
query:
|
|
21
|
+
'Run SQL against the 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.',
|
|
22
|
+
schema: 'The client schema as the PowerSync SQLite core receives it: tables, columns, indexes.',
|
|
23
|
+
info: 'Connection info of the PowerSync client: endpoint, user id, client id, connection method, core version.',
|
|
24
|
+
status:
|
|
25
|
+
'The latest sync status the PowerSync client reported: connected, downloading, progress, last sync, errors. Null until it has reported.',
|
|
26
|
+
'upload-queue': 'Pending local changes waiting to upload, as last reported: count and size. Null until reported.',
|
|
27
|
+
action:
|
|
28
|
+
'Run a control action on the PowerSync client: reconnect, disconnect, clearData (wipes local data and re-syncs), requestCheckpoint, subscribeStream, unsubscribeStream.'
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export const ARGUMENT_DESCRIPTIONS = {
|
|
32
|
+
sql: 'SQL to run against the local SQLite database.',
|
|
33
|
+
params: 'Positional parameters for `?` placeholders.',
|
|
34
|
+
actionArgs: 'Stream name and options, for subscribeStream and unsubscribeStream only: { name, params?, ttl?, priority? }.'
|
|
35
|
+
} as const;
|