@powersync/diagnostics 0.0.1

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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +115 -0
  3. package/lib/src/agent.d.ts +32 -0
  4. package/lib/src/agent.js +77 -0
  5. package/lib/src/agent.js.map +1 -0
  6. package/lib/src/client.d.ts +7 -0
  7. package/lib/src/client.js +29 -0
  8. package/lib/src/client.js.map +1 -0
  9. package/lib/src/constants.d.ts +13 -0
  10. package/lib/src/constants.js +14 -0
  11. package/lib/src/constants.js.map +1 -0
  12. package/lib/src/definition.d.ts +10 -0
  13. package/lib/src/definition.js +406 -0
  14. package/lib/src/definition.js.map +1 -0
  15. package/lib/src/index.d.ts +4 -0
  16. package/lib/src/index.js +6 -0
  17. package/lib/src/index.js.map +1 -0
  18. package/lib/src/js-agent.d.ts +63 -0
  19. package/lib/src/js-agent.js +295 -0
  20. package/lib/src/js-agent.js.map +1 -0
  21. package/lib/src/node.d.ts +58 -0
  22. package/lib/src/node.js +38 -0
  23. package/lib/src/node.js.map +1 -0
  24. package/lib/src/page.d.ts +5 -0
  25. package/lib/src/page.js +50 -0
  26. package/lib/src/page.js.map +1 -0
  27. package/lib/src/rpc-types.d.ts +39 -0
  28. package/lib/src/rpc-types.js +2 -0
  29. package/lib/src/rpc-types.js.map +1 -0
  30. package/lib/src/sync-state.d.ts +4 -0
  31. package/lib/src/sync-state.js +53 -0
  32. package/lib/src/sync-state.js.map +1 -0
  33. package/lib/src/vite-static.d.ts +18 -0
  34. package/lib/src/vite-static.js +67 -0
  35. package/lib/src/vite-static.js.map +1 -0
  36. package/lib/src/vite.d.ts +21 -0
  37. package/lib/src/vite.js +42 -0
  38. package/lib/src/vite.js.map +1 -0
  39. package/lib/tsconfig.tsbuildinfo +1 -0
  40. package/package.json +94 -0
  41. package/src/agent.ts +115 -0
  42. package/src/client.ts +36 -0
  43. package/src/constants.ts +15 -0
  44. package/src/definition.ts +486 -0
  45. package/src/index.ts +7 -0
  46. package/src/js-agent.ts +373 -0
  47. package/src/node.ts +86 -0
  48. package/src/page.ts +61 -0
  49. package/src/rpc-types.ts +51 -0
  50. package/src/sync-state.ts +61 -0
  51. package/src/vite-static.ts +83 -0
  52. package/src/vite.ts +48 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # PowerSync DevTools
2
+
3
+ `@powersync/diagnostics` shows the live state of your app's [PowerSync](https://powersync.com) client while you develop: sync status, buckets, sync streams, the local database, the schema, and logs. Coding agents get the same data as MCP tools.
4
+
5
+ One implementation runs in several hosts:
6
+
7
+ | You have | Use | You get |
8
+ | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
9
+ | A Vite app (React, Vue, Svelte, …) with Vite DevTools | `@powersync/diagnostics/vite` | A **PowerSync** dock in Vite DevTools, and MCP tools at `/__devtools/__mcp` |
10
+ | A Nuxt app | [`@powersync/nuxt`](https://github.com/powersync-ja/powersync-js/tree/main/packages/nuxt) with `useDiagnostics: true` | A **PowerSync** tab or dock in Nuxt DevTools |
11
+ | A node app (`@powersync/node`) | `@powersync/diagnostics/node` | A DevTools window served by your process, and MCP tools at `/__mcp` |
12
+
13
+ The process that runs your app also serves the DevTools window. You start nothing else.
14
+
15
+ DevTools run in development only. Nothing from this package goes into a production build.
16
+
17
+ Full guide: [PowerSync DevTools](https://docs.powersync.com/tools/devtools-overview).
18
+
19
+ ## Vite
20
+
21
+ Install:
22
+
23
+ ```bash
24
+ pnpm add -D @powersync/diagnostics @vitejs/devtools
25
+ ```
26
+
27
+ Enable Vite DevTools and add the plugin:
28
+
29
+ ```ts
30
+ // vite.config.ts
31
+ import { defineConfig } from 'vite';
32
+ import powersyncDevtools from '@powersync/diagnostics/vite';
33
+
34
+ export default defineConfig({
35
+ // Vite >= 8.3. On Vite 7, spread `...(await DevTools())` from `@vitejs/devtools` into `plugins` instead.
36
+ devtools: true,
37
+ plugins: [powersyncDevtools()]
38
+ });
39
+ ```
40
+
41
+ To get per-bucket totals in the Buckets tab, enable the core diagnostics stream when you connect:
42
+
43
+ ```ts
44
+ await db.connect(connector, { diagnostics: true });
45
+ ```
46
+
47
+ Start the dev server and open your app. The first time, Vite DevTools asks you to confirm the browser with a code from your terminal. Then the dock at the bottom of the page shows a **PowerSync** entry.
48
+
49
+ Vite DevTools also runs during `vite build`. To keep it to the dev server, set `devtools: { apply: 'serve' }`.
50
+
51
+ Option: `powersyncDevtools({ title: 'PowerSync' })` sets the dock title.
52
+
53
+ ## Node
54
+
55
+ ```ts
56
+ import { PowerSyncDatabase } from '@powersync/node';
57
+ import { enablePowerSyncDiagnostics } from '@powersync/diagnostics/node';
58
+
59
+ const db = new PowerSyncDatabase({ schema, database: { dbFilename: 'app.db' } });
60
+ await db.connect(connector, { diagnostics: true });
61
+
62
+ if (process.env.NODE_ENV !== 'production') {
63
+ const devtools = await enablePowerSyncDiagnostics(db);
64
+ console.log(`PowerSync DevTools: ${devtools.signInUrl}`);
65
+ }
66
+ ```
67
+
68
+ Your process serves the DevTools window on a random free port. Open the printed link. It carries a one-time code, so the browser is trusted at once. The code is valid for five minutes and for one browser; after that, open `devtools.url` and the terminal prints a new link. Set `auth: false` to trust every local browser. MCP tools are at `<url>/__mcp`.
69
+
70
+ Options: `port` (default: a random free port), `host`, `auth` (default `true`), `open` (open the browser, default `false`), `sdk` and `id` (labels in the UI), `mcp` (see [MCP](#mcp)).
71
+
72
+ ## MCP
73
+
74
+ Every host exposes the same tools. Names are `powersync_<function>`. Arguments are positional, `arg0` first:
75
+
76
+ | Tool | Arguments | Returns |
77
+ | ------------------------ | --------------------------------------------------- | -------------------------------------------------------------------------------------------- |
78
+ | `powersync_sources` | | the attached databases (`id`, `sdk`) |
79
+ | `powersync_query` | `arg0: { sql, params? }`, `arg1: sourceId \| null` | `{ columns, rows }`, each row an array in column order |
80
+ | `powersync_schema` | `arg0: sourceId \| null` | the schema as the SQLite core receives it |
81
+ | `powersync_info` | `arg0: sourceId \| null` | endpoint, token, client id, method, core version |
82
+ | `powersync_status` | `arg0: sourceId \| null` | the latest reported sync status |
83
+ | `powersync_upload-queue` | `arg0: sourceId \| null` | the latest reported pending uploads: count and size |
84
+ | `powersync_action` | `arg0: { action, args? }`, `arg1: sourceId \| null` | runs reconnect, disconnect, clearData, requestCheckpoint, subscribeStream, unsubscribeStream |
85
+
86
+ Pass `null` for `sourceId` to use the first attached database.
87
+
88
+ The endpoint accepts requests with a loopback `Origin` header only. Browsers always send it; some MCP clients do not. To accept requests without it, keep the server on localhost and set:
89
+
90
+ | Host | Where |
91
+ | -------------------------- | ----------------------------------------------------------------------------------------------- |
92
+ | Vite (and Nuxt DevTools 4) | `devtools: { mcp: { allowedOrigins: false } }` in `vite.config.ts` (Vite DevTools' own setting) |
93
+ | Node app | `enablePowerSyncDiagnostics(db, { mcp: { allowedOrigins: false } })` |
94
+
95
+ The same `mcp` setting takes `false` to turn the endpoint off, or `{ authorization: '<bearer token>' }` to require a token. Example call:
96
+
97
+ ```bash
98
+ curl -X POST http://localhost:<port>/__mcp \
99
+ -H 'Origin: http://localhost:<port>' -H 'Content-Type: application/json' \
100
+ -H 'Accept: application/json, text/event-stream' \
101
+ -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"powersync_query","arguments":{"arg0":{"sql":"select count(*) as n from ps_oplog"},"arg1":null}}}'
102
+ ```
103
+
104
+ ## Requirements
105
+
106
+ - `@powersync/web >= 2.5` for browser apps, `@powersync/node` for node apps.
107
+ - Vite DevTools for the dock: Vite `>= 8.3` with `devtools: true`, or the `@vitejs/devtools` plugin on Vite 7.
108
+ - Node `>= 20.16` for the node entry.
109
+
110
+ ## Related packages
111
+
112
+ These are internal packages used by this package. Your app code does not depend on them.
113
+
114
+ - [`@powersync/diagnostics-core`](https://github.com/powersync-ja/powersync-js/tree/main/packages/diagnostics-core): the protocol (`SdkIntegration`).
115
+ - [`@powersync/diagnostics-ui`](https://github.com/powersync-ja/powersync-js/tree/main/packages/diagnostics-ui): the UI.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Pieces shared by every JavaScript host: building the agent over a live database, and serving
3
+ * agents to a devframe node side over an RPC client (a dock script in a web page, or a node process).
4
+ */
5
+ import type { DevframeRpcClient } from 'devframe/client';
6
+ import type { CommonPowerSyncDatabase, PowerSyncBackendConnector, SyncOptions } from '@powersync/common';
7
+ import type { SdkIntegration } from '@powersync/diagnostics-core';
8
+ import './rpc-types.js';
9
+ /**
10
+ * A live PowerSync JavaScript database the agent can serve: the SDK's database plus the connection
11
+ * accessors every SDK's database class exposes.
12
+ */
13
+ export interface DiagnosableDatabase extends CommonPowerSyncDatabase {
14
+ readonly connector: PowerSyncBackendConnector | null | undefined;
15
+ readonly connectionOptions: SyncOptions | null | undefined;
16
+ }
17
+ /** Builds the JavaScript integration over a live database. */
18
+ export declare function createIntegration(db: DiagnosableDatabase, sdk: string): SdkIntegration;
19
+ /** Serves integrations to the node side over one RPC client. */
20
+ export interface AgentServer {
21
+ /** Announces `integration` as `sourceId` and starts forwarding its events. */
22
+ serve(sourceId: string, integration: SdkIntegration, sdk: string): Promise<void>;
23
+ /** Withdraws a served integration. */
24
+ release(sourceId: string): Promise<void>;
25
+ /** Releases everything served through this client. */
26
+ close(): Promise<void>;
27
+ }
28
+ /**
29
+ * Registers the page-side functions the node side calls (`powersync:page-*`) on `rpc`, and returns
30
+ * a server that announces integrations to it. Call once per RPC client.
31
+ */
32
+ export declare function createAgentServer(rpc: DevframeRpcClient): AgentServer;
@@ -0,0 +1,77 @@
1
+ import { HEARTBEAT_MS } from './constants.js';
2
+ import { JsAgent } from './js-agent.js';
3
+ import './rpc-types.js';
4
+ /** The sync client broadcasts core diagnostics events on this channel (see `emitDiagnostics`). */
5
+ const CORE_EVENTS_CHANNEL = 'powersync-diagnostics-events';
6
+ /** Consumes the core diagnostics events the sync client broadcasts (from a worker or in-process). */
7
+ class BroadcastCoreEvents {
8
+ channel = new BroadcastChannel(CORE_EVENTS_CHANNEL);
9
+ onEvent(handler) {
10
+ const listener = (event) => handler(event.data);
11
+ this.channel.addEventListener('message', listener);
12
+ return () => this.channel.removeEventListener('message', listener);
13
+ }
14
+ dispose() {
15
+ this.channel.close();
16
+ }
17
+ }
18
+ /** Builds the JavaScript integration over a live database. */
19
+ export function createIntegration(db, sdk) {
20
+ return new JsAgent(db, {
21
+ sdk,
22
+ coreEvents: typeof BroadcastChannel === 'function' ? new BroadcastCoreEvents() : undefined,
23
+ connection: {
24
+ getConnector: () => db.connector ?? null,
25
+ getConnectionOptions: () => db.connectionOptions ?? null
26
+ }
27
+ });
28
+ }
29
+ /**
30
+ * Registers the page-side functions the node side calls (`powersync:page-*`) on `rpc`, and returns
31
+ * a server that announces integrations to it. Call once per RPC client.
32
+ */
33
+ export function createAgentServer(rpc) {
34
+ const served = new Map();
35
+ // The node side only knows this client is alive while it hears from it.
36
+ const heartbeat = setInterval(() => {
37
+ for (const sourceId of served.keys())
38
+ void rpc.callEvent('powersync:page-heartbeat', sourceId);
39
+ }, HEARTBEAT_MS);
40
+ heartbeat.unref?.();
41
+ const integrationFor = (sourceId) => {
42
+ const entry = served.get(sourceId);
43
+ if (!entry)
44
+ throw new Error(`No database "${sourceId}" is served here.`);
45
+ return entry.integration;
46
+ };
47
+ const register = (name, handler) => rpc.client.register({ name, type: 'action', jsonSerializable: true, handler }, true);
48
+ register('powersync:page-query', (id, params) => integrationFor(id).runQuery(params));
49
+ register('powersync:page-schema', (id) => integrationFor(id).getSchema());
50
+ register('powersync:page-info', (id) => integrationFor(id).getInfo());
51
+ register('powersync:page-action', (id, request) => integrationFor(id).action(request));
52
+ return {
53
+ async serve(sourceId, integration, sdk) {
54
+ await rpc.call('powersync:page-register', sourceId, sdk);
55
+ const stop = await integration.observeEvents((event) => {
56
+ void rpc.callEvent('powersync:page-event', sourceId, event);
57
+ });
58
+ served.set(sourceId, { integration, stop });
59
+ },
60
+ async release(sourceId) {
61
+ const entry = served.get(sourceId);
62
+ if (!entry)
63
+ return;
64
+ served.delete(sourceId);
65
+ entry.stop();
66
+ await entry.integration.close();
67
+ await rpc.call('powersync:page-unregister', sourceId).catch(() => { });
68
+ },
69
+ async close() {
70
+ clearInterval(heartbeat);
71
+ for (const sourceId of [...served.keys()]) {
72
+ await this.release(sourceId);
73
+ }
74
+ }
75
+ };
76
+ }
77
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAwB,MAAM,eAAe,CAAC;AAC9D,OAAO,gBAAgB,CAAC;AAExB,kGAAkG;AAClG,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAW3D,qGAAqG;AACrG,MAAM,mBAAmB;IACf,OAAO,GAAG,IAAI,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;IAE5D,OAAO,CAAC,OAA8C;QACpD,MAAM,QAAQ,GAAG,CAAC,KAAmB,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAA4B,CAAC,CAAC;QACtF,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACnD,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;IAED,OAAO;QACL,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF;AAED,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAAC,EAAuB,EAAE,GAAW;IACpE,OAAO,IAAI,OAAO,CAAC,EAAE,EAAE;QACrB,GAAG;QACH,UAAU,EAAE,OAAO,gBAAgB,K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,CAAC;QACxE,CAAC;QACD,KAAK,CAAC,KAAK;YACT,aAAa,CAAC,SAAS,CAAC,CAAC;YACzB,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;gBAC1C,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The dock client script for `@powersync/web` apps. The devframe hub imports this module into the
3
+ * app page with an already trusted RPC client. It watches the app's open databases and serves each
4
+ * to the node side, which the diagnostics UI and MCP tools call.
5
+ */
6
+ import type { DockClientScriptContext } from '@devframes/hub/client';
7
+ export default function setup(context: DockClientScriptContext): void;
@@ -0,0 +1,29 @@
1
+ import { observeRegisteredDatabases } from '@powersync/web/devtools';
2
+ import { createAgentServer, createIntegration } from './agent.js';
3
+ const SDK = '@powersync/web';
4
+ export default function setup(context) {
5
+ const server = createAgentServer(context.rpc);
6
+ let counter = 0;
7
+ let currentId = null;
8
+ // A closing tab cannot wait for the release to complete: withdraw first, the heartbeat is the backstop.
9
+ window.addEventListener('pagehide', () => {
10
+ if (currentId)
11
+ void context.rpc.call('powersync:page-unregister', currentId);
12
+ });
13
+ observeRegisteredDatabases((databases) => {
14
+ const database = databases[0] ?? null;
15
+ if (!database) {
16
+ // The database closed: withdraw it.
17
+ if (currentId) {
18
+ void server.release(currentId);
19
+ currentId = null;
20
+ }
21
+ return;
22
+ }
23
+ if (currentId)
24
+ return;
25
+ currentId = `web-${++counter}`;
26
+ void server.serve(currentId, createIntegration(database, SDK), SDK);
27
+ });
28
+ }
29
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAElE,MAAM,GAAG,GAAG,gBAAgB,CAAC;AAE7B,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAgC;IAC5D,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,SAAS,GAAkB,IAAI,CAAC;IAEpC,wGAAwG;IACxG,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,GAAG,EAAE;QACvC,IAAI,SAAS;YAAE,KAAK,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,2BAA2B,EAAE,SAAS,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;IAEH,0BAA0B,CAAC,CAAC,SAAS,EAAE,EAAE;QACvC,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QACtC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,oCAAoC;YACpC,IAAI,SAAS,EAAE,CAAC;gBACd,KAAK,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBAC/B,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,OAAO;QACT,CAAC;QACD,IAAI,SAAS;YAAE,OAAO;QACtB,SAAS,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC;QAC/B,KAAK,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,iBAAiB,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The route the diagnostics UI is served from. It is the devframe mount base of the `powersync`
3
+ * definition (`/__<id>/`), and the same path `./vite-static` serves for hosts without a devframe hub,
4
+ * so an embedding host can point an iframe at it either way.
5
+ */
6
+ export declare const UI_ROUTE = "/__powersync/";
7
+ /** The devframe definition id. RPC functions live in this scope: `powersync:<name>`. */
8
+ export declare const DEVFRAME_ID = "powersync";
9
+ /**
10
+ * How often a page or app that serves a database reports in to the node side. A closed tab cannot
11
+ * say it went, so a source silent for three beats counts as gone.
12
+ */
13
+ export declare const HEARTBEAT_MS = 2000;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The route the diagnostics UI is served from. It is the devframe mount base of the `powersync`
3
+ * definition (`/__<id>/`), and the same path `./vite-static` serves for hosts without a devframe hub,
4
+ * so an embedding host can point an iframe at it either way.
5
+ */
6
+ export const UI_ROUTE = '/__powersync/';
7
+ /** The devframe definition id. RPC functions live in this scope: `powersync:<name>`. */
8
+ export const DEVFRAME_ID = 'powersync';
9
+ /**
10
+ * How often a page or app that serves a database reports in to the node side. A closed tab cannot
11
+ * say it went, so a source silent for three beats counts as gone.
12
+ */
13
+ export const HEARTBEAT_MS = 2000;
14
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;AAExC,wFAAwF;AACxF,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { SdkIntegration, Unsubscribe } from '@powersync/diagnostics-core';
2
+ export type { SourceInfo } from './rpc-types.js';
3
+ /**
4
+ * Serves an integration that lives in this process (a node app's database). Events are pulled from
5
+ * it directly. Returns a function that detaches it.
6
+ */
7
+ export declare function registerIntegration(id: string, integration: SdkIntegration, sdk?: string | null): Promise<Unsubscribe>;
8
+ /** The built diagnostics UI (`@powersync/diagnostics-ui/dist/standalone`), served as the dock page. */
9
+ export declare function uiDistDir(): string;
10
+ export declare const definition: import("devframe").DevframeDefinition;