@powersync/diagnostics 0.0.2 → 0.0.3
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 +23 -2
- 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 +8 -19
- package/lib/src/agent.js +8 -56
- package/lib/src/agent.js.map +1 -1
- package/lib/src/client.js +5 -4
- package/lib/src/client.js.map +1 -1
- package/lib/src/js-agent.d.ts +5 -13
- package/lib/src/js-agent.js +7 -8
- 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/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -10
- package/src/agent-server.ts +73 -0
- package/src/agent.ts +19 -84
- package/src/client.ts +5 -5
- package/src/js-agent.ts +16 -25
- package/src/node.ts +3 -3
- package/src/page.ts +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/diagnostics",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "PowerSync DevTools: a devframe definition that serves live PowerSync diagnostics as a Vite DevTools dock, a node dev server, and MCP tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/src/index.js",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"./node": {
|
|
30
30
|
"types": "./lib/src/node.d.ts",
|
|
31
31
|
"default": "./lib/src/node.js"
|
|
32
|
+
},
|
|
33
|
+
"./agent": {
|
|
34
|
+
"types": "./lib/src/agent.d.ts",
|
|
35
|
+
"default": "./lib/src/agent.js"
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
"author": "PowerSync",
|
|
@@ -50,8 +54,8 @@
|
|
|
50
54
|
},
|
|
51
55
|
"homepage": "https://docs.powersync.com",
|
|
52
56
|
"peerDependencies": {
|
|
53
|
-
"@powersync/common": "^2.
|
|
54
|
-
"@powersync/web": "^2.
|
|
57
|
+
"@powersync/common": "^2.5.0",
|
|
58
|
+
"@powersync/web": "^2.6.0",
|
|
55
59
|
"@vitejs/devtools-kit": ">=0.7.5",
|
|
56
60
|
"vite": ">=7.0.0"
|
|
57
61
|
},
|
|
@@ -70,20 +74,21 @@
|
|
|
70
74
|
}
|
|
71
75
|
},
|
|
72
76
|
"dependencies": {
|
|
73
|
-
"@devframes/agentic": "1.
|
|
74
|
-
"devframe": "1.
|
|
77
|
+
"@devframes/agentic": "^1.2.6",
|
|
78
|
+
"devframe": "^1.2.6",
|
|
75
79
|
"zod": "^4.6.5",
|
|
76
|
-
"@powersync/diagnostics-
|
|
77
|
-
"@powersync/diagnostics-
|
|
80
|
+
"@powersync/diagnostics-core": "0.0.3",
|
|
81
|
+
"@powersync/diagnostics-ui": "0.0.3"
|
|
78
82
|
},
|
|
79
83
|
"devDependencies": {
|
|
80
|
-
"@devframes/hub": "1.
|
|
84
|
+
"@devframes/hub": "^1.2.6",
|
|
81
85
|
"@types/node": "^24.0.0",
|
|
82
86
|
"@vitejs/devtools-kit": "^0.7.5",
|
|
83
87
|
"typescript": "^6.0.3",
|
|
84
88
|
"vite": "^7.3.6",
|
|
85
|
-
"@powersync/common": "2.
|
|
86
|
-
"@powersync/
|
|
89
|
+
"@powersync/common": "2.5.0",
|
|
90
|
+
"@powersync/shared-internals": "1.5.0",
|
|
91
|
+
"@powersync/web": "2.6.0"
|
|
87
92
|
},
|
|
88
93
|
"scripts": {
|
|
89
94
|
"build": "tsc -b",
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serving agents to a devframe node side over an RPC client: a dock script in a web page, or a
|
|
3
|
+
* node process.
|
|
4
|
+
*/
|
|
5
|
+
import type { DevframeRpcClient } from 'devframe/client';
|
|
6
|
+
import type {
|
|
7
|
+
ActionRequest,
|
|
8
|
+
DiagnosticsEvent,
|
|
9
|
+
QueryParams,
|
|
10
|
+
SdkIntegration,
|
|
11
|
+
Unsubscribe
|
|
12
|
+
} from '@powersync/diagnostics-core';
|
|
13
|
+
import { HEARTBEAT_MS } from './constants.js';
|
|
14
|
+
import './rpc-types.js';
|
|
15
|
+
|
|
16
|
+
/** Serves integrations to the node side over one RPC client. */
|
|
17
|
+
export interface AgentServer {
|
|
18
|
+
/** Announces `integration` as `sourceId` and starts forwarding its events. */
|
|
19
|
+
serve(sourceId: string, integration: SdkIntegration, sdk: string): Promise<void>;
|
|
20
|
+
/** Withdraws a served integration. */
|
|
21
|
+
release(sourceId: string): Promise<void>;
|
|
22
|
+
/** Releases everything served through this client. */
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Registers the page-side functions the node side calls (`powersync:page-*`) on `rpc`, and returns
|
|
28
|
+
* a server that announces integrations to it. Call once per RPC client.
|
|
29
|
+
*/
|
|
30
|
+
export function createAgentServer(rpc: DevframeRpcClient): AgentServer {
|
|
31
|
+
const served = new Map<string, { integration: SdkIntegration; stop: Unsubscribe }>();
|
|
32
|
+
// The node side only knows this client is alive while it hears from it.
|
|
33
|
+
const heartbeat = setInterval(() => {
|
|
34
|
+
for (const sourceId of served.keys()) void rpc.callEvent('powersync:page-heartbeat', sourceId);
|
|
35
|
+
}, HEARTBEAT_MS);
|
|
36
|
+
(heartbeat as { unref?: () => void }).unref?.();
|
|
37
|
+
|
|
38
|
+
const integrationFor = (sourceId: string): SdkIntegration => {
|
|
39
|
+
const entry = served.get(sourceId);
|
|
40
|
+
if (!entry) throw new Error(`No database "${sourceId}" is served here.`);
|
|
41
|
+
return entry.integration;
|
|
42
|
+
};
|
|
43
|
+
const register = (name: string, handler: (...args: any[]) => unknown) =>
|
|
44
|
+
rpc.client.register({ name, type: 'action', jsonSerializable: true, handler }, true);
|
|
45
|
+
register('powersync:page-query', (id: string, params: QueryParams) => integrationFor(id).runQuery(params));
|
|
46
|
+
register('powersync:page-schema', (id: string) => integrationFor(id).getSchema());
|
|
47
|
+
register('powersync:page-info', (id: string) => integrationFor(id).getInfo());
|
|
48
|
+
register('powersync:page-action', (id: string, request: ActionRequest) => integrationFor(id).action(request));
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
async serve(sourceId, integration, sdk) {
|
|
52
|
+
await rpc.call('powersync:page-register', sourceId, sdk);
|
|
53
|
+
const stop = await integration.observeEvents((event: DiagnosticsEvent) => {
|
|
54
|
+
void rpc.callEvent('powersync:page-event', sourceId, event);
|
|
55
|
+
});
|
|
56
|
+
served.set(sourceId, { integration, stop });
|
|
57
|
+
},
|
|
58
|
+
async release(sourceId) {
|
|
59
|
+
const entry = served.get(sourceId);
|
|
60
|
+
if (!entry) return;
|
|
61
|
+
served.delete(sourceId);
|
|
62
|
+
entry.stop();
|
|
63
|
+
await entry.integration.close();
|
|
64
|
+
await rpc.call('powersync:page-unregister', sourceId).catch(() => {});
|
|
65
|
+
},
|
|
66
|
+
async close() {
|
|
67
|
+
clearInterval(heartbeat);
|
|
68
|
+
for (const sourceId of [...served.keys()]) {
|
|
69
|
+
await this.release(sourceId);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
package/src/agent.ts
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* The agent for a JavaScript host: the `SdkIntegration` built over a live database. This is the
|
|
3
|
+
* package's `./agent` entry, for a host that opens the database and embeds the DevTools page itself;
|
|
4
|
+
* the dock and node entries build their agents here too.
|
|
4
5
|
*/
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type
|
|
6
|
+
import type { CommonPowerSyncDatabase } from '@powersync/common';
|
|
7
|
+
import type { CoreDiagnosticsEvent, SdkIntegration, Unsubscribe } from '@powersync/diagnostics-core';
|
|
8
|
+
import { JsAgent, type CoreEventSource } from './js-agent.js';
|
|
9
|
+
import type { BasePowerSyncDatabase } from '@powersync/shared-internals';
|
|
10
|
+
|
|
11
|
+
// The iframe hand-off and the protocol types an embedding host needs, so the host never imports the protocol package.
|
|
12
|
+
export { attachIframe } from '@powersync/diagnostics-core';
|
|
13
|
+
export type {
|
|
8
14
|
ActionRequest,
|
|
9
|
-
|
|
15
|
+
AttachIframeOptions,
|
|
10
16
|
DiagnosticsEvent,
|
|
11
|
-
QueryParams,
|
|
12
17
|
SdkIntegration,
|
|
13
|
-
|
|
18
|
+
SyncState
|
|
14
19
|
} from '@powersync/diagnostics-core';
|
|
15
|
-
import { HEARTBEAT_MS } from './constants.js';
|
|
16
|
-
import { JsAgent, type CoreEventSource } from './js-agent.js';
|
|
17
|
-
import './rpc-types.js';
|
|
18
20
|
|
|
19
21
|
/** The sync client broadcasts core diagnostics events on this channel (see `emitDiagnostics`). */
|
|
20
22
|
const CORE_EVENTS_CHANNEL = 'powersync-diagnostics-events';
|
|
21
23
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
interface DiagnosableDatabase extends CommonPowerSyncDatabase {
|
|
27
|
-
readonly connector: PowerSyncBackendConnector | null | undefined;
|
|
28
|
-
readonly connectionOptions: SyncOptions | null | undefined;
|
|
24
|
+
/** The SDK label for the database, or `fallback` on SDK releases that do not report it. */
|
|
25
|
+
export function databaseSdk(database: CommonPowerSyncDatabase, fallback: string): string {
|
|
26
|
+
return (database as Partial<BasePowerSyncDatabase>).sdkName ?? fallback;
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
/** Consumes the core diagnostics events the sync client broadcasts (from a worker or in-process). */
|
|
@@ -43,74 +41,11 @@ class BroadcastCoreEvents implements CoreEventSource {
|
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
/** Builds the JavaScript integration over a live database. */
|
|
44
|
+
/** Builds the JavaScript integration over a live database. The agent reads the connection from the database itself. */
|
|
47
45
|
export function createIntegration(database: CommonPowerSyncDatabase, sdk: string): SdkIntegration {
|
|
48
|
-
const db = database as
|
|
46
|
+
const db = database as BasePowerSyncDatabase;
|
|
49
47
|
return new JsAgent(db, {
|
|
50
48
|
sdk,
|
|
51
|
-
coreEvents: typeof BroadcastChannel === 'function' ? new BroadcastCoreEvents() : undefined
|
|
52
|
-
connection: {
|
|
53
|
-
getConnector: () => db.connector ?? null,
|
|
54
|
-
getConnectionOptions: () => db.connectionOptions ?? null
|
|
55
|
-
}
|
|
49
|
+
coreEvents: typeof BroadcastChannel === 'function' ? new BroadcastCoreEvents() : undefined
|
|
56
50
|
});
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
/** Serves integrations to the node side over one RPC client. */
|
|
60
|
-
export interface AgentServer {
|
|
61
|
-
/** Announces `integration` as `sourceId` and starts forwarding its events. */
|
|
62
|
-
serve(sourceId: string, integration: SdkIntegration, sdk: string): Promise<void>;
|
|
63
|
-
/** Withdraws a served integration. */
|
|
64
|
-
release(sourceId: string): Promise<void>;
|
|
65
|
-
/** Releases everything served through this client. */
|
|
66
|
-
close(): Promise<void>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Registers the page-side functions the node side calls (`powersync:page-*`) on `rpc`, and returns
|
|
71
|
-
* a server that announces integrations to it. Call once per RPC client.
|
|
72
|
-
*/
|
|
73
|
-
export function createAgentServer(rpc: DevframeRpcClient): AgentServer {
|
|
74
|
-
const served = new Map<string, { integration: SdkIntegration; stop: Unsubscribe }>();
|
|
75
|
-
// The node side only knows this client is alive while it hears from it.
|
|
76
|
-
const heartbeat = setInterval(() => {
|
|
77
|
-
for (const sourceId of served.keys()) void rpc.callEvent('powersync:page-heartbeat', sourceId);
|
|
78
|
-
}, HEARTBEAT_MS);
|
|
79
|
-
(heartbeat as { unref?: () => void }).unref?.();
|
|
80
|
-
|
|
81
|
-
const integrationFor = (sourceId: string): SdkIntegration => {
|
|
82
|
-
const entry = served.get(sourceId);
|
|
83
|
-
if (!entry) throw new Error(`No database "${sourceId}" is served here.`);
|
|
84
|
-
return entry.integration;
|
|
85
|
-
};
|
|
86
|
-
const register = (name: string, handler: (...args: any[]) => unknown) =>
|
|
87
|
-
rpc.client.register({ name, type: 'action', jsonSerializable: true, handler }, true);
|
|
88
|
-
register('powersync:page-query', (id: string, params: QueryParams) => integrationFor(id).runQuery(params));
|
|
89
|
-
register('powersync:page-schema', (id: string) => integrationFor(id).getSchema());
|
|
90
|
-
register('powersync:page-info', (id: string) => integrationFor(id).getInfo());
|
|
91
|
-
register('powersync:page-action', (id: string, request: ActionRequest) => integrationFor(id).action(request));
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
async serve(sourceId, integration, sdk) {
|
|
95
|
-
await rpc.call('powersync:page-register', sourceId, sdk);
|
|
96
|
-
const stop = await integration.observeEvents((event: DiagnosticsEvent) => {
|
|
97
|
-
void rpc.callEvent('powersync:page-event', sourceId, event);
|
|
98
|
-
});
|
|
99
|
-
served.set(sourceId, { integration, stop });
|
|
100
|
-
},
|
|
101
|
-
async release(sourceId) {
|
|
102
|
-
const entry = served.get(sourceId);
|
|
103
|
-
if (!entry) return;
|
|
104
|
-
served.delete(sourceId);
|
|
105
|
-
entry.stop();
|
|
106
|
-
await entry.integration.close();
|
|
107
|
-
await rpc.call('powersync:page-unregister', sourceId).catch(() => {});
|
|
108
|
-
},
|
|
109
|
-
async close() {
|
|
110
|
-
clearInterval(heartbeat);
|
|
111
|
-
for (const sourceId of [...served.keys()]) {
|
|
112
|
-
await this.release(sourceId);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
package/src/client.ts
CHANGED
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { DockClientScriptContext } from '@devframes/hub/client';
|
|
7
7
|
import { observeRegisteredDatabases } from '@powersync/web/devtools';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const SDK = '@powersync/web';
|
|
8
|
+
import { createIntegration, databaseSdk } from './agent.js';
|
|
9
|
+
import { createAgentServer } from './agent-server.js';
|
|
11
10
|
|
|
12
11
|
export default function setup(context: DockClientScriptContext): void {
|
|
13
12
|
const server = createAgentServer(context.rpc);
|
|
@@ -30,7 +29,8 @@ export default function setup(context: DockClientScriptContext): void {
|
|
|
30
29
|
return;
|
|
31
30
|
}
|
|
32
31
|
if (currentId) return;
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const sdk = databaseSdk(database, '@powersync/web');
|
|
33
|
+
currentId = `${sdk.replace(/^@powersync\//, '')}-${++counter}`;
|
|
34
|
+
void server.serve(currentId, createIntegration(database, sdk), sdk);
|
|
35
35
|
});
|
|
36
36
|
}
|
package/src/js-agent.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
CommonPowerSyncDatabase,
|
|
3
2
|
LogLevels,
|
|
4
3
|
LogRecord as SdkLogRecord,
|
|
5
|
-
PowerSyncBackendConnector,
|
|
6
4
|
SyncOptions,
|
|
7
5
|
SyncStatus,
|
|
8
6
|
SyncStreamSubscription
|
|
@@ -19,11 +17,11 @@ import type {
|
|
|
19
17
|
SchemaPayload,
|
|
20
18
|
SdkIntegration,
|
|
21
19
|
StreamActionArgs,
|
|
22
|
-
SyncState,
|
|
23
20
|
Unsubscribe,
|
|
24
21
|
UploadQueueState
|
|
25
22
|
} from '@powersync/diagnostics-core';
|
|
26
23
|
import { toStreamStates, toSyncState } from './sync-state.js';
|
|
24
|
+
import type { BasePowerSyncDatabase, InternalConnector } from '@powersync/shared-internals';
|
|
27
25
|
|
|
28
26
|
/** Delivers the SQLite core's diagnostics events to the agent. How they arrive is runtime-specific. */
|
|
29
27
|
export interface CoreEventSource {
|
|
@@ -31,24 +29,15 @@ export interface CoreEventSource {
|
|
|
31
29
|
dispose(): void;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
/**
|
|
35
|
-
* Read access to the live connection. The connector and options are not on the database's public
|
|
36
|
-
* interface, so the code that installs the agent (which can see the concrete database) hands them in.
|
|
37
|
-
*/
|
|
38
|
-
export interface ConnectionAccess {
|
|
39
|
-
getConnector(): PowerSyncBackendConnector | null;
|
|
40
|
-
getConnectionOptions(): SyncOptions | null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
32
|
export interface JsAgentOptions {
|
|
44
33
|
/** A label for the SDK behind this agent, e.g. `@powersync/web`. */
|
|
45
34
|
sdk?: string;
|
|
35
|
+
/** If known, the path to the database */
|
|
36
|
+
databasePath?: string;
|
|
46
37
|
/** Debounce for re-reading bucket stats after internal-table changes. */
|
|
47
38
|
bucketThrottleMs?: number;
|
|
48
39
|
/** Core diagnostics events (per-bucket `target_count`). Omit when core diagnostics are off. */
|
|
49
40
|
coreEvents?: CoreEventSource;
|
|
50
|
-
/** Read access to the live connection; omit if the runtime cannot expose it. */
|
|
51
|
-
connection?: ConnectionAccess;
|
|
52
41
|
}
|
|
53
42
|
|
|
54
43
|
/**
|
|
@@ -63,13 +52,13 @@ export class JsAgent implements SdkIntegration {
|
|
|
63
52
|
/** Debug subscriptions created through `action`, keyed by name + params, so they can be released. */
|
|
64
53
|
private streamHandles = new Map<string, SyncStreamSubscription>();
|
|
65
54
|
// Retained so reconnect / clear work after a disconnect, when the connection no longer exposes them.
|
|
66
|
-
private lastConnector:
|
|
55
|
+
private lastConnector: InternalConnector | null = null;
|
|
67
56
|
private lastConnectionOptions: SyncOptions | null = null;
|
|
68
57
|
// Per-bucket total operation counts from the core diagnostics stream (not stored in ps_buckets).
|
|
69
58
|
private bucketTargets = new Map<string, number>();
|
|
70
59
|
|
|
71
60
|
constructor(
|
|
72
|
-
private db:
|
|
61
|
+
private readonly db: BasePowerSyncDatabase,
|
|
73
62
|
private options: JsAgentOptions = {}
|
|
74
63
|
) {}
|
|
75
64
|
|
|
@@ -87,12 +76,10 @@ export class JsAgent implements SdkIntegration {
|
|
|
87
76
|
}
|
|
88
77
|
|
|
89
78
|
async getInfo(): Promise<ProtocolInfo> {
|
|
90
|
-
const connection = this.options.connection;
|
|
91
|
-
|
|
92
79
|
let endpoint: string | null = null;
|
|
93
80
|
let token: string | null = null;
|
|
94
81
|
try {
|
|
95
|
-
const credentials = await
|
|
82
|
+
const credentials = await this.db.connector?.fetchCredentials?.();
|
|
96
83
|
endpoint = credentials?.endpoint ?? null;
|
|
97
84
|
token = credentials?.token ?? null;
|
|
98
85
|
} catch {
|
|
@@ -114,7 +101,7 @@ export class JsAgent implements SdkIntegration {
|
|
|
114
101
|
// Non-fatal.
|
|
115
102
|
}
|
|
116
103
|
|
|
117
|
-
const connectionOptions =
|
|
104
|
+
const connectionOptions = this.db.connectionOptions ?? null;
|
|
118
105
|
return {
|
|
119
106
|
endpoint,
|
|
120
107
|
token,
|
|
@@ -123,7 +110,8 @@ export class JsAgent implements SdkIntegration {
|
|
|
123
110
|
params: connectionOptions?.params ?? null,
|
|
124
111
|
connected: this.db.currentStatus?.connected ?? false,
|
|
125
112
|
sqliteCoreVersion,
|
|
126
|
-
sdk: this.options.sdk ?? null
|
|
113
|
+
sdk: this.options.sdk ?? null,
|
|
114
|
+
databasePath: this.options.databasePath ?? null
|
|
127
115
|
};
|
|
128
116
|
}
|
|
129
117
|
|
|
@@ -345,17 +333,20 @@ export class JsAgent implements SdkIntegration {
|
|
|
345
333
|
}
|
|
346
334
|
|
|
347
335
|
private captureConnection(): void {
|
|
348
|
-
const
|
|
349
|
-
const connector = connection?.getConnector() ?? null;
|
|
336
|
+
const connector = this.db.connector ?? null;
|
|
350
337
|
if (connector) {
|
|
351
338
|
this.lastConnector = connector;
|
|
352
|
-
this.lastConnectionOptions =
|
|
339
|
+
this.lastConnectionOptions = this.db.connectionOptions ?? null;
|
|
353
340
|
}
|
|
354
341
|
}
|
|
355
342
|
|
|
356
343
|
private async reconnect(): Promise<void> {
|
|
357
344
|
if (this.lastConnector) {
|
|
358
|
-
await this.db.connect(
|
|
345
|
+
await this.db.connectionManager.connect(
|
|
346
|
+
this.lastConnector,
|
|
347
|
+
this.lastConnectionOptions ?? {},
|
|
348
|
+
this.db.schema.toJSON()
|
|
349
|
+
);
|
|
359
350
|
}
|
|
360
351
|
}
|
|
361
352
|
}
|
package/src/node.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { McpSetting } from 'devframe';
|
|
|
6
6
|
import { createDevServer } from 'devframe/adapters/dev';
|
|
7
7
|
import { buildOtpAuthUrl } from 'devframe/node/auth';
|
|
8
8
|
import type { CommonPowerSyncDatabase } from '@powersync/common';
|
|
9
|
-
import { createIntegration } from './agent.js';
|
|
9
|
+
import { createIntegration, databaseSdk } from './agent.js';
|
|
10
10
|
import { definition, registerIntegration, setSetupSdks } from './definition.js';
|
|
11
11
|
|
|
12
12
|
export interface EnableDiagnosticsOptions {
|
|
@@ -24,7 +24,7 @@ export interface EnableDiagnosticsOptions {
|
|
|
24
24
|
auth?: boolean;
|
|
25
25
|
/** Open the browser once the server is up. @default false */
|
|
26
26
|
open?: boolean;
|
|
27
|
-
/** A label for the SDK, shown in the UI. @default '
|
|
27
|
+
/** A label for the SDK, shown in the UI. @default the database's SDK name */
|
|
28
28
|
sdk?: string;
|
|
29
29
|
/** The source id shown in the UI. @default 'node-1' */
|
|
30
30
|
id?: string;
|
|
@@ -67,7 +67,7 @@ export async function enablePowerSyncDiagnostics(
|
|
|
67
67
|
db: CommonPowerSyncDatabase,
|
|
68
68
|
options: EnableDiagnosticsOptions = {}
|
|
69
69
|
): Promise<DiagnosticsServer> {
|
|
70
|
-
const sdk = options.sdk ?? '@powersync/node';
|
|
70
|
+
const sdk = options.sdk ?? databaseSdk(db, '@powersync/node');
|
|
71
71
|
const detach = await registerIntegration(options.id ?? 'node-1', createIntegration(db, sdk), sdk);
|
|
72
72
|
setSetupSdks(['node']);
|
|
73
73
|
const auth = options.auth ?? true;
|
package/src/page.ts
CHANGED
|
@@ -11,9 +11,7 @@ import {
|
|
|
11
11
|
type SdkIntegration
|
|
12
12
|
} from '@powersync/diagnostics-core';
|
|
13
13
|
import { observeRegisteredDatabases } from '@powersync/web/devtools';
|
|
14
|
-
import { createIntegration } from './agent.js';
|
|
15
|
-
|
|
16
|
-
const SDK = '@powersync/web';
|
|
14
|
+
import { createIntegration, databaseSdk } from './agent.js';
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
17
|
* Serves the app's first live database to any iframe that asks. Call once per page.
|
|
@@ -29,7 +27,7 @@ export function serveDiagnostics(): () => void {
|
|
|
29
27
|
for (const stop of stops) stop();
|
|
30
28
|
stops.clear();
|
|
31
29
|
void integration?.close();
|
|
32
|
-
integration = next ? createIntegration(next,
|
|
30
|
+
integration = next ? createIntegration(next, databaseSdk(next, '@powersync/web')) : null;
|
|
33
31
|
});
|
|
34
32
|
|
|
35
33
|
const onMessage = (event: MessageEvent) => {
|