@powersync/nuxt 0.0.0-dev-20260630144038 → 0.0.0-dev-20261015114518

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 (55) hide show
  1. package/README.md +36 -59
  2. package/dist/module.d.mts +4 -3
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +74 -64
  5. package/dist/runtime/assets/devtools-theme.d.ts +1 -0
  6. package/dist/runtime/assets/devtools-theme.js +33 -0
  7. package/dist/runtime/options.d.ts +13 -0
  8. package/dist/runtime/options.js +0 -0
  9. package/dist/runtime/plugin.client.js +8 -8
  10. package/package.json +13 -15
  11. package/dist/runtime/components/BucketsInspectorTab.d.vue.ts +0 -3
  12. package/dist/runtime/components/BucketsInspectorTab.vue +0 -544
  13. package/dist/runtime/components/BucketsInspectorTab.vue.d.ts +0 -3
  14. package/dist/runtime/components/ConfigInspectorTab.d.vue.ts +0 -3
  15. package/dist/runtime/components/ConfigInspectorTab.vue +0 -84
  16. package/dist/runtime/components/ConfigInspectorTab.vue.d.ts +0 -3
  17. package/dist/runtime/components/DataInspectorTab.d.vue.ts +0 -3
  18. package/dist/runtime/components/DataInspectorTab.vue +0 -564
  19. package/dist/runtime/components/DataInspectorTab.vue.d.ts +0 -3
  20. package/dist/runtime/components/LoadingSpinner.d.vue.ts +0 -3
  21. package/dist/runtime/components/LoadingSpinner.vue +0 -12
  22. package/dist/runtime/components/LoadingSpinner.vue.d.ts +0 -3
  23. package/dist/runtime/components/LogsTab.d.vue.ts +0 -3
  24. package/dist/runtime/components/LogsTab.vue +0 -273
  25. package/dist/runtime/components/LogsTab.vue.d.ts +0 -3
  26. package/dist/runtime/components/PowerSyncInstanceTab.d.vue.ts +0 -3
  27. package/dist/runtime/components/PowerSyncInstanceTab.vue +0 -7
  28. package/dist/runtime/components/PowerSyncInstanceTab.vue.d.ts +0 -3
  29. package/dist/runtime/components/SyncStatusTab.d.vue.ts +0 -3
  30. package/dist/runtime/components/SyncStatusTab.vue +0 -161
  31. package/dist/runtime/components/SyncStatusTab.vue.d.ts +0 -3
  32. package/dist/runtime/composables/usePowerSyncInspector.d.ts +0 -39
  33. package/dist/runtime/composables/usePowerSyncInspector.js +0 -17
  34. package/dist/runtime/composables/usePowerSyncInspectorDiagnostics.d.ts +0 -153
  35. package/dist/runtime/composables/usePowerSyncInspectorDiagnostics.js +0 -213
  36. package/dist/runtime/layouts/powersync-inspector-layout.d.vue.ts +0 -13
  37. package/dist/runtime/layouts/powersync-inspector-layout.vue +0 -63
  38. package/dist/runtime/layouts/powersync-inspector-layout.vue.d.ts +0 -13
  39. package/dist/runtime/pages/__powersync-inspector.d.vue.ts +0 -3
  40. package/dist/runtime/pages/__powersync-inspector.vue +0 -119
  41. package/dist/runtime/pages/__powersync-inspector.vue.d.ts +0 -3
  42. package/dist/runtime/utils/AppSchema.d.ts +0 -27
  43. package/dist/runtime/utils/AppSchema.js +0 -23
  44. package/dist/runtime/utils/DynamicSchemaManager.d.ts +0 -16
  45. package/dist/runtime/utils/DynamicSchemaManager.js +0 -82
  46. package/dist/runtime/utils/JsSchemaGenerator.d.ts +0 -8
  47. package/dist/runtime/utils/JsSchemaGenerator.js +0 -28
  48. package/dist/runtime/utils/NuxtPowerSyncDatabase.d.ts +0 -42
  49. package/dist/runtime/utils/NuxtPowerSyncDatabase.js +0 -105
  50. package/dist/runtime/utils/RustClientInterceptor.d.ts +0 -24
  51. package/dist/runtime/utils/RustClientInterceptor.js +0 -90
  52. package/dist/runtime/utils/TokenConnector.d.ts +0 -14
  53. package/dist/runtime/utils/TokenConnector.js +0 -57
  54. package/dist/runtime/utils/index.d.ts +0 -1
  55. package/dist/runtime/utils/index.js +0 -1
@@ -1,105 +0,0 @@
1
- import {
2
- WebPowerSyncDatabase,
3
- Schema,
4
- SharedWebStreamingSyncImplementation,
5
- WebRemote,
6
- WebStreamingSyncImplementation,
7
- LogLevels
8
- } from "@powersync/web";
9
- import { usePowerSyncInspector } from "../composables/usePowerSyncInspector.js";
10
- import { useDiagnosticsLogger } from "../composables/useDiagnosticsLogger.js";
11
- import { shallowRef } from "vue";
12
- import { useRuntimeConfig } from "#app";
13
- import { RustClientInterceptor } from "./RustClientInterceptor.js";
14
- export class NuxtDatabaseImplementation extends WebPowerSyncDatabase {
15
- schemaManager;
16
- _connector = null;
17
- useDiagnostics = false;
18
- get dbOptions() {
19
- return this.options;
20
- }
21
- get connector() {
22
- return this._connector ?? super.connector;
23
- }
24
- constructor(options) {
25
- const useDiagnostics = useRuntimeConfig().public.powerSyncModuleOptions.useDiagnostics ?? false;
26
- if (useDiagnostics) {
27
- const { logger } = useDiagnosticsLogger();
28
- const { getCurrentSchemaManager, diagnosticsSchema } = usePowerSyncInspector();
29
- const currentSchemaManager = getCurrentSchemaManager();
30
- if ("database" in options) {
31
- options.database.enableMultiTabs = true;
32
- options.broadcastLogs = true;
33
- }
34
- options.logger = logger;
35
- options.schema = new Schema([...options.schema.tables, ...diagnosticsSchema.tables]);
36
- super(options);
37
- this.schemaManager = currentSchemaManager;
38
- this.useDiagnostics = true;
39
- } else {
40
- super(options);
41
- this.useDiagnostics = false;
42
- }
43
- }
44
- generateSyncStreamImplementation(connector, options) {
45
- if (this.useDiagnostics) {
46
- const { logger } = useDiagnosticsLogger();
47
- const { getCurrentSchemaManager } = usePowerSyncInspector();
48
- const currentSchemaManager = getCurrentSchemaManager();
49
- const schemaManager = currentSchemaManager || this.schemaManager;
50
- const adapter = new RustClientInterceptor(
51
- shallowRef(this),
52
- shallowRef(schemaManager)
53
- );
54
- if (this.resolvedOpenOptions.enableMultiTabs) {
55
- if (!this.enableBroadcastLogs) {
56
- const warning = `
57
- Multiple tabs are enabled, but broadcasting of logs is disabled.
58
- Logs for shared sync worker will only be available in the shared worker context
59
- `;
60
- logger ? logger.log({ level: LogLevels.warn, message: warning }) : console.warn(warning);
61
- }
62
- return new SharedWebStreamingSyncImplementation({
63
- ...options,
64
- adapter,
65
- remote: new WebRemote(connector, logger),
66
- uploadCrud: async () => {
67
- await this.waitForReady();
68
- await connector.uploadData(this);
69
- },
70
- logger,
71
- db: this.database,
72
- logLevel: this.resolvedOpenOptions.databaseWorkerLogLevel ?? LogLevels.info,
73
- enableBroadcastLogs: this.enableBroadcastLogs
74
- });
75
- } else {
76
- return new WebStreamingSyncImplementation({
77
- ...options,
78
- adapter,
79
- remote: new WebRemote(connector, logger),
80
- uploadCrud: async () => {
81
- await this.waitForReady();
82
- await connector.uploadData(this);
83
- },
84
- identifier: "database" in this.options ? this.options.database.dbFilename : "diagnostics-sync",
85
- logger
86
- });
87
- }
88
- } else {
89
- return super.generateSyncStreamImplementation(connector, options);
90
- }
91
- }
92
- async connect(connector, options) {
93
- this._connector = connector;
94
- await super.connect(connector, options);
95
- }
96
- async disconnect() {
97
- this._connector = null;
98
- await super.disconnect();
99
- }
100
- async disconnectAndClear(options) {
101
- this._connector = null;
102
- await super.disconnectAndClear(options);
103
- }
104
- }
105
- export const NuxtPowerSyncDatabase = NuxtDatabaseImplementation;
@@ -1,24 +0,0 @@
1
- import type { ColumnType, PowerSyncDatabase } from '@powersync/web';
2
- import { PowerSyncControlCommand, SqliteBucketStorage } from '@powersync/shared-internals';
3
- import type { DynamicSchemaManager } from './DynamicSchemaManager.js';
4
- import type { ShallowRef } from 'vue';
5
- /**
6
- * Tracks per-byte and per-operation progress for the Rust client.
7
- *
8
- * While per-operation progress is reported by the SDK as well, we need those counters for each bucket. Since that
9
- * information is internal to the Rust client and inaccessible to JavaScript, this intercepts the raw
10
- * `powersync_control` calls to decode sync lines and derive progress information.
11
- */
12
- export declare class RustClientInterceptor extends SqliteBucketStorage {
13
- private schemaManager;
14
- private bson?;
15
- private rdb;
16
- private lastStartedCheckpoint;
17
- tables: Record<string, Record<string, ColumnType>>;
18
- constructor(db: ShallowRef<PowerSyncDatabase>, schemaManager: ShallowRef<DynamicSchemaManager>);
19
- control(op: PowerSyncControlCommand, payload: string | Uint8Array | ArrayBuffer | null): Promise<string>;
20
- private processTextLine;
21
- private processBinaryLine;
22
- private processParsedLine;
23
- private trackCheckpoint;
24
- }
@@ -1,90 +0,0 @@
1
- import { BasePowerSyncDatabase, PowerSyncControlCommand, SqliteBucketStorage } from "@powersync/shared-internals";
2
- export class RustClientInterceptor extends SqliteBucketStorage {
3
- constructor(db, schemaManager) {
4
- super(db.value.database, BasePowerSyncDatabase.transactionMutex);
5
- this.schemaManager = schemaManager;
6
- this.rdb = db.value.database;
7
- }
8
- bson;
9
- rdb;
10
- lastStartedCheckpoint = null;
11
- tables = {};
12
- async control(op, payload) {
13
- const response = await super.control(op, payload);
14
- if (op == PowerSyncControlCommand.PROCESS_TEXT_LINE) {
15
- await this.processTextLine(payload);
16
- } else if (op == PowerSyncControlCommand.PROCESS_BSON_LINE) {
17
- await this.processBinaryLine(payload);
18
- }
19
- return response;
20
- }
21
- processTextLine(line) {
22
- return this.processParsedLine(JSON.parse(line));
23
- }
24
- async processBinaryLine(line) {
25
- const bson = this.bson ??= await import("bson");
26
- await this.processParsedLine(bson.deserialize(line));
27
- }
28
- async processParsedLine(line) {
29
- if ("checkpoint" in line) {
30
- this.lastStartedCheckpoint = line.checkpoint;
31
- await this.trackCheckpoint(line.checkpoint);
32
- } else if ("checkpoint_diff" in line && this.lastStartedCheckpoint) {
33
- const diff = line.checkpoint_diff;
34
- const newBuckets = /* @__PURE__ */ new Map();
35
- for (const checksum of this.lastStartedCheckpoint.buckets) {
36
- newBuckets.set(checksum.bucket, checksum);
37
- }
38
- for (const checksum of diff.updated_buckets) {
39
- newBuckets.set(checksum.bucket, checksum);
40
- }
41
- for (const bucket of diff.removed_buckets) {
42
- newBuckets.delete(bucket);
43
- }
44
- const newCheckpoint = {
45
- last_op_id: diff.last_op_id,
46
- buckets: [...newBuckets.values()],
47
- write_checkpoint: diff.write_checkpoint
48
- };
49
- this.lastStartedCheckpoint = newCheckpoint;
50
- await this.trackCheckpoint(newCheckpoint);
51
- } else if ("data" in line) {
52
- const bucket = line.data;
53
- await this.rdb.writeTransaction(async (tx) => {
54
- const size = JSON.stringify(bucket.data).length;
55
- await tx.execute(
56
- `UPDATE local_bucket_data SET
57
- download_size = IFNULL(download_size, 0) + ?,
58
- last_op = ?,
59
- downloading = ?,
60
- downloaded_operations = IFNULL(downloaded_operations, 0) + ?
61
- WHERE id = ?`,
62
- [size, bucket.next_after, bucket.has_more, bucket.data.length, bucket.bucket]
63
- );
64
- });
65
- await this.schemaManager.value.updateFromOperations(bucket);
66
- } else if ("partial_checkpoint_complete" in line || "checkpoint_complete" in line) {
67
- setTimeout(() => {
68
- this.schemaManager.value.refreshSchema(this.rdb);
69
- }, 60);
70
- }
71
- }
72
- async trackCheckpoint(checkpoint) {
73
- await this.rdb.writeTransaction(async (tx) => {
74
- for (const bucket of checkpoint.buckets) {
75
- await tx.execute(
76
- `INSERT OR REPLACE INTO local_bucket_data(id, total_operations, last_op, download_size, downloading, downloaded_operations)
77
- VALUES (
78
- ?,
79
- ?,
80
- IFNULL((SELECT last_op FROM local_bucket_data WHERE id = ?), '0'),
81
- IFNULL((SELECT download_size FROM local_bucket_data WHERE id = ?), 0),
82
- IFNULL((SELECT downloading FROM local_bucket_data WHERE id = ?), TRUE),
83
- IFNULL((SELECT downloaded_operations FROM local_bucket_data WHERE id = ?), TRUE)
84
- )`,
85
- [bucket.bucket, bucket.count, bucket.bucket, bucket.bucket, bucket.bucket, bucket.bucket]
86
- );
87
- }
88
- });
89
- }
90
- }
@@ -1,14 +0,0 @@
1
- import type { AbstractPowerSyncDatabase, PowerSyncBackendConnector } from '@powersync/web';
2
- export interface Credentials {
3
- token: string;
4
- endpoint: string;
5
- }
6
- export declare class TokenConnector implements PowerSyncBackendConnector {
7
- private connectFn?;
8
- setConnectFunction(connectFn: () => Promise<void>): void;
9
- fetchCredentials(): any;
10
- uploadData(database: AbstractPowerSyncDatabase): Promise<void>;
11
- signIn(credentials: Credentials): Promise<void>;
12
- hasCredentials(): boolean;
13
- clearCredentials(): void;
14
- }
@@ -1,57 +0,0 @@
1
- export class TokenConnector {
2
- connectFn;
3
- // Inject the connect function to avoid circular dependency
4
- setConnectFunction(connectFn) {
5
- this.connectFn = connectFn;
6
- }
7
- fetchCredentials() {
8
- const value = localStorage.getItem("powersync_credentials");
9
- if (value == null) {
10
- return null;
11
- }
12
- return JSON.parse(value);
13
- }
14
- async uploadData(database) {
15
- const tx = await database.getNextCrudTransaction();
16
- await tx?.complete();
17
- }
18
- async signIn(credentials) {
19
- validateSecureContext(credentials.endpoint);
20
- checkJWT(credentials.token);
21
- try {
22
- localStorage.setItem("powersync_credentials", JSON.stringify(credentials));
23
- await this.connectFn();
24
- } catch (e) {
25
- this.clearCredentials();
26
- throw e;
27
- }
28
- }
29
- hasCredentials() {
30
- return localStorage.getItem("powersync_credentials") != null;
31
- }
32
- clearCredentials() {
33
- localStorage.removeItem("powersync_credentials");
34
- }
35
- }
36
- function validateSecureContext(url) {
37
- if (!location.href.startsWith("https:")) {
38
- return;
39
- }
40
- const parsedUrl = new URL(url);
41
- const secure = parsedUrl.protocol === "https:" || parsedUrl.hostname === "localhost" || parsedUrl.hostname === "127.0.0.1" || parsedUrl.hostname === "::1";
42
- if (!secure) {
43
- throw new Error(`Cannot connect to http endpoints from the hosted diagnostics app.
44
- Run either the PowerSync endpoint on http://localhost, or the diagnostics app on http://localhost.`);
45
- }
46
- }
47
- function checkJWT(token) {
48
- const parts = token.split(".");
49
- if (parts.length !== 3) {
50
- throw new Error(`Token must be a JWT: Expected 3 parts, got ${parts.length}`);
51
- }
52
- const base64UrlRegex = /^[\w-]+$/;
53
- const isBase64 = parts.every((part) => base64UrlRegex.test(part));
54
- if (!isBase64) {
55
- throw new Error(`Token must be a JWT: Not all parts are base64 encoded`);
56
- }
57
- }
@@ -1 +0,0 @@
1
- export { NuxtPowerSyncDatabase } from './NuxtPowerSyncDatabase.js';
@@ -1 +0,0 @@
1
- export { NuxtPowerSyncDatabase } from "./NuxtPowerSyncDatabase.js";