@powersync/diagnostics 0.0.0-dev-20261020125654 → 0.0.0-dev-20261112182545
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-BXfuXqfT.js +184 -0
- package/dist/devtools/assets/powersync-CpTiA65L.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
package/lib/src/page.js
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { PORT_MESSAGE, REQUEST_PORT_MESSAGE, exposeIntegration } from '@powersync/diagnostics-core';
|
|
8
8
|
import { observeRegisteredDatabases } from '@powersync/web/devtools';
|
|
9
|
-
import { createIntegration } from './agent.js';
|
|
10
|
-
const SDK = '@powersync/web';
|
|
9
|
+
import { createIntegration, databaseSdk } from './agent.js';
|
|
11
10
|
/**
|
|
12
11
|
* Serves the app's first live database to any iframe that asks. Call once per page.
|
|
13
12
|
* Returns a function that stops serving.
|
|
@@ -22,7 +21,7 @@ export function serveDiagnostics() {
|
|
|
22
21
|
stop();
|
|
23
22
|
stops.clear();
|
|
24
23
|
void integration?.close();
|
|
25
|
-
integration = next ? createIntegration(next,
|
|
24
|
+
integration = next ? createIntegration(next, databaseSdk(next, '@powersync/web')) : null;
|
|
26
25
|
});
|
|
27
26
|
const onMessage = (event) => {
|
|
28
27
|
if (event.data?.type !== REQUEST_PORT_MESSAGE) {
|
package/lib/src/page.js.map
CHANGED
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/page.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,YAAY,EACZ,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AE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAC1D,CAAC;IACJ,CAAC,CAAC;IACF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAE9C,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACjD,aAAa,EAAE,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,IAAI,EAAE,CAAC;QACjC,KAAK,WAAW,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useRozenitePluginAgentTool } from '@rozenite/agent-bridge';
|
|
3
|
+
import { ACTION_NAMES, ARGUMENT_DESCRIPTIONS, TOOL_DESCRIPTIONS } from '../tools.js';
|
|
4
|
+
import { PLUGIN_ID } from './protocol.js';
|
|
5
|
+
// The same tools the MCP endpoint offers on the web, for Rozenite's agent CLI and SDK.
|
|
6
|
+
const queryTool = {
|
|
7
|
+
name: 'query',
|
|
8
|
+
description: TOOL_DESCRIPTIONS.query,
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
sql: { type: 'string', description: ARGUMENT_DESCRIPTIONS.sql },
|
|
13
|
+
params: { type: 'array', description: ARGUMENT_DESCRIPTIONS.params }
|
|
14
|
+
},
|
|
15
|
+
required: ['sql']
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const schemaTool = {
|
|
19
|
+
name: 'schema',
|
|
20
|
+
description: TOOL_DESCRIPTIONS.schema,
|
|
21
|
+
inputSchema: { type: 'object', properties: {} },
|
|
22
|
+
readOnly: true
|
|
23
|
+
};
|
|
24
|
+
const infoTool = {
|
|
25
|
+
name: 'info',
|
|
26
|
+
description: TOOL_DESCRIPTIONS.info,
|
|
27
|
+
inputSchema: { type: 'object', properties: {} },
|
|
28
|
+
readOnly: true
|
|
29
|
+
};
|
|
30
|
+
const statusTool = {
|
|
31
|
+
name: 'status',
|
|
32
|
+
description: TOOL_DESCRIPTIONS.status,
|
|
33
|
+
inputSchema: { type: 'object', properties: {} },
|
|
34
|
+
readOnly: true
|
|
35
|
+
};
|
|
36
|
+
const uploadQueueTool = {
|
|
37
|
+
name: 'upload-queue',
|
|
38
|
+
description: TOOL_DESCRIPTIONS['upload-queue'],
|
|
39
|
+
inputSchema: { type: 'object', properties: {} },
|
|
40
|
+
readOnly: true
|
|
41
|
+
};
|
|
42
|
+
const actionTool = {
|
|
43
|
+
name: 'action',
|
|
44
|
+
description: TOOL_DESCRIPTIONS.action,
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
action: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
enum: ACTION_NAMES
|
|
51
|
+
},
|
|
52
|
+
args: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
description: ARGUMENT_DESCRIPTIONS.actionArgs
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
required: ['action']
|
|
58
|
+
},
|
|
59
|
+
destructive: true
|
|
60
|
+
};
|
|
61
|
+
function requireIntegration(integration) {
|
|
62
|
+
if (!integration)
|
|
63
|
+
throw new Error('The PowerSync database is not attached yet.');
|
|
64
|
+
return integration;
|
|
65
|
+
}
|
|
66
|
+
/** Registers the PowerSync agent tools for one database. */
|
|
67
|
+
export function usePowerSyncAgentTools(integration) {
|
|
68
|
+
const latest = useRef({
|
|
69
|
+
status: null,
|
|
70
|
+
uploadQueue: null
|
|
71
|
+
});
|
|
72
|
+
// The status tools answer from the latest pushed snapshots, as the MCP tools do.
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!integration)
|
|
75
|
+
return;
|
|
76
|
+
let stop = null;
|
|
77
|
+
let cancelled = false;
|
|
78
|
+
void integration
|
|
79
|
+
.observeEvents((event) => {
|
|
80
|
+
if (event.type === 'status')
|
|
81
|
+
latest.current.status = event.payload;
|
|
82
|
+
if (event.type === 'uploadQueue')
|
|
83
|
+
latest.current.uploadQueue = event.payload;
|
|
84
|
+
})
|
|
85
|
+
.then((unsubscribe) => {
|
|
86
|
+
if (cancelled)
|
|
87
|
+
unsubscribe();
|
|
88
|
+
else
|
|
89
|
+
stop = unsubscribe;
|
|
90
|
+
});
|
|
91
|
+
return () => {
|
|
92
|
+
cancelled = true;
|
|
93
|
+
stop?.();
|
|
94
|
+
};
|
|
95
|
+
}, [integration]);
|
|
96
|
+
const enabled = integration != null;
|
|
97
|
+
useRozenitePluginAgentTool({
|
|
98
|
+
pluginId: PLUGIN_ID,
|
|
99
|
+
tool: queryTool,
|
|
100
|
+
enabled,
|
|
101
|
+
handler: (params) => requireIntegration(integration).runQuery(params)
|
|
102
|
+
});
|
|
103
|
+
useRozenitePluginAgentTool({
|
|
104
|
+
pluginId: PLUGIN_ID,
|
|
105
|
+
tool: schemaTool,
|
|
106
|
+
enabled,
|
|
107
|
+
handler: () => requireIntegration(integration).getSchema()
|
|
108
|
+
});
|
|
109
|
+
useRozenitePluginAgentTool({
|
|
110
|
+
pluginId: PLUGIN_ID,
|
|
111
|
+
tool: infoTool,
|
|
112
|
+
enabled,
|
|
113
|
+
handler: () => requireIntegration(integration).getInfo()
|
|
114
|
+
});
|
|
115
|
+
useRozenitePluginAgentTool({
|
|
116
|
+
pluginId: PLUGIN_ID,
|
|
117
|
+
tool: statusTool,
|
|
118
|
+
enabled,
|
|
119
|
+
handler: () => latest.current.status
|
|
120
|
+
});
|
|
121
|
+
useRozenitePluginAgentTool({
|
|
122
|
+
pluginId: PLUGIN_ID,
|
|
123
|
+
tool: uploadQueueTool,
|
|
124
|
+
enabled,
|
|
125
|
+
handler: () => latest.current.uploadQueue
|
|
126
|
+
});
|
|
127
|
+
useRozenitePluginAgentTool({
|
|
128
|
+
pluginId: PLUGIN_ID,
|
|
129
|
+
tool: actionTool,
|
|
130
|
+
enabled,
|
|
131
|
+
handler: async (request) => {
|
|
132
|
+
await requireIntegration(integration).action(request);
|
|
133
|
+
return { ok: true };
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=agent-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tools.js","sourceRoot":"","sources":["../../../src/react-native/agent-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAkB,MAAM,wBAAwB,CAAC;AAQpF,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,uFAAuF;AAEvF,MAAM,SAAS,GAAc;IAC3B,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,iBAAiB,CAAC,KAAK;IACpC,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qBAAqB,CAAC,GAAG,EAAE;YAC/D,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,qBAAqB,CAAC,MAAM,EAAE;SACrE;QACD,QAAQ,EAAE,CAAC,KAAK,CAAC;KAClB;CACF,CAAC;AAEF,MAAM,UAAU,GAAc;IAC5B,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,iBAAiB,CAAC,MAAM;IACrC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;IAC/C,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF,MAAM,QAAQ,GAAc;IAC1B,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,iBAAiB,CAAC,I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;QACP,OAAO,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;KACzD,CAAC,CAAC;IACH,0BAA0B,CAAC;QACzB,QAAQ,EAAE,SAAS;QACnB,IAAI,EAAE,UAAU;QAChB,OAAO;QACP,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM;KACrC,CAAC,CAAC;IACH,0BAA0B,CAAC;QACzB,QAAQ,EAAE,SAAS;QACnB,IAAI,EAAE,eAAe;QACrB,OAAO;QACP,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW;KAC1C,CAAC,CAAC;IACH,0BAA0B,CAAC;QACzB,QAAQ,EAAE,SAAS;QACnB,IAAI,EAAE,UAAU;QAChB,OAAO;QACP,OAAO,EAAE,KAAK,EAAE,OAAsB,EAAE,EAAE;YACxC,MAAM,kBAAkB,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACtD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;QACtB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { ActionRequest, DiagnosticsEvent, ProtocolInfo, QueryParams, QueryResult, SchemaPayload } from '@powersync/diagnostics-core';
|
|
6
|
+
/** The Rozenite plugin id. Rozenite finds the plugin by this package name. */
|
|
7
|
+
export declare const PLUGIN_ID = "@powersync/diagnostics";
|
|
8
|
+
/** The message type that carries one {@link DiagnosticsEvent} from the app to the panel. */
|
|
9
|
+
export declare const EVENT_MESSAGE = "powersync:event";
|
|
10
|
+
/** Plugin messages, keyed by type. */
|
|
11
|
+
export type DevToolsEventMap = {
|
|
12
|
+
[EVENT_MESSAGE]: DiagnosticsEvent;
|
|
13
|
+
};
|
|
14
|
+
/** Methods the app serves to the panel. */
|
|
15
|
+
export type AppMethods = {
|
|
16
|
+
runQuery: (params: QueryParams) => Promise<QueryResult>;
|
|
17
|
+
getSchema: () => Promise<SchemaPayload>;
|
|
18
|
+
getInfo: () => Promise<ProtocolInfo>;
|
|
19
|
+
action: (request: ActionRequest) => Promise<void>;
|
|
20
|
+
/** Starts (or restarts) the event stream; the app pushes the current snapshots first. */
|
|
21
|
+
subscribe: () => Promise<void>;
|
|
22
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The Rozenite plugin id. Rozenite finds the plugin by this package name. */
|
|
2
|
+
export const PLUGIN_ID = '@powersync/diagnostics';
|
|
3
|
+
/** The message type that carries one {@link DiagnosticsEvent} from the app to the panel. */
|
|
4
|
+
export const EVENT_MESSAGE = 'powersync:event';
|
|
5
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/react-native/protocol.ts"],"names":[],"mappings":"AAaA,8EAA8E;AAC9E,MAAM,CAAC,MAAM,SAAS,GAAG,wBAAwB,CAAC;AAElD,4FAA4F;AAC5F,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CommonPowerSyncDatabase } from '@powersync/common';
|
|
2
|
+
/**
|
|
3
|
+
* Serves `database` to the PowerSync panel in React Native DevTools (through Rozenite), and to coding
|
|
4
|
+
* agents as Rozenite agent tools. Call it in a component that stays mounted, such as the app root.
|
|
5
|
+
* Pass `null` while the database is not created yet; DevTools attach once it is.
|
|
6
|
+
*/
|
|
7
|
+
export declare function usePowerSyncDevTools(database: CommonPowerSyncDatabase | null): void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { createRozeniteRpc, useRozeniteDevToolsClient } from '@rozenite/plugin-bridge';
|
|
3
|
+
import { createIntegration } from '../agent.js';
|
|
4
|
+
import { usePowerSyncAgentTools } from './agent-tools.js';
|
|
5
|
+
import { EVENT_MESSAGE, PLUGIN_ID } from './protocol.js';
|
|
6
|
+
const SDK = '@powersync/react-native';
|
|
7
|
+
/**
|
|
8
|
+
* Serves `database` to the PowerSync panel in React Native DevTools (through Rozenite), and to coding
|
|
9
|
+
* agents as Rozenite agent tools. Call it in a component that stays mounted, such as the app root.
|
|
10
|
+
* Pass `null` while the database is not created yet; DevTools attach once it is.
|
|
11
|
+
*/
|
|
12
|
+
export function usePowerSyncDevTools(database) {
|
|
13
|
+
const client = useRozeniteDevToolsClient({ pluginId: PLUGIN_ID });
|
|
14
|
+
const [integration, setIntegration] = useState(null);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!database)
|
|
17
|
+
return;
|
|
18
|
+
const created = createIntegration(database, SDK);
|
|
19
|
+
setIntegration(created);
|
|
20
|
+
return () => {
|
|
21
|
+
setIntegration(null);
|
|
22
|
+
void created.close();
|
|
23
|
+
};
|
|
24
|
+
}, [database]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!client || !integration)
|
|
27
|
+
return;
|
|
28
|
+
const rpc = createRozeniteRpc(client);
|
|
29
|
+
let stopEvents = null;
|
|
30
|
+
let closed = false;
|
|
31
|
+
const handlers = [
|
|
32
|
+
rpc.handle('runQuery', (params) => integration.runQuery(params)),
|
|
33
|
+
rpc.handle('getSchema', () => integration.getSchema()),
|
|
34
|
+
rpc.handle('getInfo', () => integration.getInfo()),
|
|
35
|
+
rpc.handle('action', (request) => integration.action(request)),
|
|
36
|
+
// A panel (re)opening asks for the stream; restarting it replays the current snapshots.
|
|
37
|
+
rpc.handle('subscribe', async () => {
|
|
38
|
+
stopEvents?.();
|
|
39
|
+
const unsubscribe = await integration.observeEvents((event) => client.send(EVENT_MESSAGE, event));
|
|
40
|
+
if (closed)
|
|
41
|
+
unsubscribe();
|
|
42
|
+
else
|
|
43
|
+
stopEvents = unsubscribe;
|
|
44
|
+
})
|
|
45
|
+
];
|
|
46
|
+
return () => {
|
|
47
|
+
closed = true;
|
|
48
|
+
for (const handler of handlers)
|
|
49
|
+
handler.remove();
|
|
50
|
+
stopEvents?.();
|
|
51
|
+
rpc.close();
|
|
52
|
+
};
|
|
53
|
+
}, [client, integration]);
|
|
54
|
+
usePowerSyncAgentTools(integration);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=usePowerSyncDevTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePowerSyncDevTools.js","sourceRoot":"","sources":["../../../src/react-native/usePowerSyncDevTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAGvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,SAAS,EAA0C,MAAM,eAAe,CAAC;AAEjG,MAAM,GAAG,GAAG,yBAAyB,CAAC;AAEtC;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAwC;IAC3E,MAAM,MAAM,GAAG,yBAAyB,CAAmB,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;IACpF,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC,CAAC;IAE5E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACjD,cAAc,CAAC,OAAO,CAAC,CAAC;QACxB,OAAO,GAAG,EAAE;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I,QAAQ;gBAAE,OAAO,CAAC,MAAM,EAAE,CAAC;YACjD,UAAU,EAAE,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,EAAE,CAAC;QACd,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1B,sBAAsB,CAAC,WAAW,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
export declare let usePowerSyncDevTools: (database: CommonPowerSyncDatabase | null) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export let usePowerSyncDevTools;
|
|
2
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3
|
+
usePowerSyncDevTools = require('./react-native/usePowerSyncDevTools.js').usePowerSyncDevTools;
|
|
4
|
+
}
|
|
5
|
+
else {
|
|
6
|
+
usePowerSyncDevTools = () => { };
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../../src/react-native.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,IAAI,oBAAwE,CAAC;AAEpF,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;IAC1C,oBAAoB,GAAG,OAAO,CAAC,wCAAwC,CAAC,CAAC,oBAAoB,CAAC;AAChG,CAAC;KAAM,CAAC;IACN,oBAAoB,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAClC,CAAC"}
|
package/lib/src/rpc-types.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface SourceInfo {
|
|
|
11
11
|
sdk: string | null;
|
|
12
12
|
}
|
|
13
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';
|
|
14
|
+
export type SetupSdk = 'web' | 'nuxt' | 'node' | 'react-native' | 'dart';
|
|
15
15
|
declare module 'devframe/types' {
|
|
16
16
|
/** Functions the node side serves; called by the UI, by agents over MCP, and by pages announcing a database. */
|
|
17
17
|
interface DevframeRpcServerFunctions {
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export declare const ACTION_NAMES: [ActionName, ...ActionName[]];
|
|
7
|
+
export declare const TOOL_DESCRIPTIONS: {
|
|
8
|
+
readonly query: "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.";
|
|
9
|
+
readonly schema: "The client schema as the PowerSync SQLite core receives it: tables, columns, indexes.";
|
|
10
|
+
readonly info: "Connection info of the PowerSync client: endpoint, user id, client id, connection method, core version.";
|
|
11
|
+
readonly status: "The latest sync status the PowerSync client reported: connected, downloading, progress, last sync, errors. Null until it has reported.";
|
|
12
|
+
readonly 'upload-queue': "Pending local changes waiting to upload, as last reported: count and size. Null until reported.";
|
|
13
|
+
readonly action: "Run a control action on the PowerSync client: reconnect, disconnect, clearData (wipes local data and re-syncs), requestCheckpoint, subscribeStream, unsubscribeStream.";
|
|
14
|
+
};
|
|
15
|
+
export declare const ARGUMENT_DESCRIPTIONS: {
|
|
16
|
+
readonly sql: "SQL to run against the local SQLite database.";
|
|
17
|
+
readonly params: "Positional parameters for `?` placeholders.";
|
|
18
|
+
readonly actionArgs: "Stream name and options, for subscribeStream and unsubscribeStream only: { name, params?, ttl?, priority? }.";
|
|
19
|
+
};
|
package/lib/src/tools.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// A record, so a new action name fails to compile until it is listed here.
|
|
2
|
+
const actions = {
|
|
3
|
+
reconnect: true,
|
|
4
|
+
disconnect: true,
|
|
5
|
+
clearData: true,
|
|
6
|
+
requestCheckpoint: true,
|
|
7
|
+
subscribeStream: true,
|
|
8
|
+
unsubscribeStream: true
|
|
9
|
+
};
|
|
10
|
+
export const ACTION_NAMES = Object.keys(actions);
|
|
11
|
+
export const TOOL_DESCRIPTIONS = {
|
|
12
|
+
query: '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.',
|
|
13
|
+
schema: 'The client schema as the PowerSync SQLite core receives it: tables, columns, indexes.',
|
|
14
|
+
info: 'Connection info of the PowerSync client: endpoint, user id, client id, connection method, core version.',
|
|
15
|
+
status: 'The latest sync status the PowerSync client reported: connected, downloading, progress, last sync, errors. Null until it has reported.',
|
|
16
|
+
'upload-queue': 'Pending local changes waiting to upload, as last reported: count and size. Null until reported.',
|
|
17
|
+
action: 'Run a control action on the PowerSync client: reconnect, disconnect, clearData (wipes local data and re-syncs), requestCheckpoint, subscribeStream, unsubscribeStream.'
|
|
18
|
+
};
|
|
19
|
+
export const ARGUMENT_DESCRIPTIONS = {
|
|
20
|
+
sql: 'SQL to run against the local SQLite database.',
|
|
21
|
+
params: 'Positional parameters for `?` placeholders.',
|
|
22
|
+
actionArgs: 'Stream name and options, for subscribeStream and unsubscribeStream only: { name, params?, ttl?, priority? }.'
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":"AAMA,2EAA2E;AAC3E,MAAM,OAAO,GAA6B;IACxC,SAAS,EAAE,IAAI;IACf,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,IAAI;IACf,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,IAAI;IACrB,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAkC,CAAC;AAElF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,KAAK,EACH,sMAAsM;IACxM,MAAM,EAAE,uFAAuF;IAC/F,IAAI,EAAE,yGAAyG;IAC/G,MAAM,EACJ,wIAAwI;IAC1I,cAAc,EAAE,iGAAiG;IACjH,MAAM,EACJ,wKAAwK;CAClK,CAAC;AAEX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,GAAG,EAAE,+CAA+C;IACpD,MAAM,EAAE,6CAA6C;IACrD,UAAU,EAAE,8GAA8G;CAClH,CAAC"}
|