@powersync/nuxt 0.0.0-dev-20260128023420

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 (64) hide show
  1. package/LICENSE +201 -0
  2. package/README +374 -0
  3. package/dist/module.d.mts +39 -0
  4. package/dist/module.json +9 -0
  5. package/dist/module.mjs +160 -0
  6. package/dist/runtime/assets/powersync-icon.svg +14 -0
  7. package/dist/runtime/components/BucketsInspectorTab.d.vue.ts +3 -0
  8. package/dist/runtime/components/BucketsInspectorTab.vue +646 -0
  9. package/dist/runtime/components/BucketsInspectorTab.vue.d.ts +3 -0
  10. package/dist/runtime/components/ConfigInspectorTab.d.vue.ts +3 -0
  11. package/dist/runtime/components/ConfigInspectorTab.vue +121 -0
  12. package/dist/runtime/components/ConfigInspectorTab.vue.d.ts +3 -0
  13. package/dist/runtime/components/DataInspectorTab.d.vue.ts +3 -0
  14. package/dist/runtime/components/DataInspectorTab.vue +678 -0
  15. package/dist/runtime/components/DataInspectorTab.vue.d.ts +3 -0
  16. package/dist/runtime/components/LoadingSpinner.d.vue.ts +3 -0
  17. package/dist/runtime/components/LoadingSpinner.vue +12 -0
  18. package/dist/runtime/components/LoadingSpinner.vue.d.ts +3 -0
  19. package/dist/runtime/components/LogsTab.d.vue.ts +3 -0
  20. package/dist/runtime/components/LogsTab.vue +325 -0
  21. package/dist/runtime/components/LogsTab.vue.d.ts +3 -0
  22. package/dist/runtime/components/PowerSyncInstanceTab.d.vue.ts +3 -0
  23. package/dist/runtime/components/PowerSyncInstanceTab.vue +9 -0
  24. package/dist/runtime/components/PowerSyncInstanceTab.vue.d.ts +3 -0
  25. package/dist/runtime/components/SyncStatusTab.d.vue.ts +3 -0
  26. package/dist/runtime/components/SyncStatusTab.vue +272 -0
  27. package/dist/runtime/components/SyncStatusTab.vue.d.ts +3 -0
  28. package/dist/runtime/composables/useDiagnosticsLogger.d.ts +27 -0
  29. package/dist/runtime/composables/useDiagnosticsLogger.js +41 -0
  30. package/dist/runtime/composables/usePowerSyncInspector.d.ts +42 -0
  31. package/dist/runtime/composables/usePowerSyncInspector.js +19 -0
  32. package/dist/runtime/composables/usePowerSyncInspectorDiagnostics.d.ts +153 -0
  33. package/dist/runtime/composables/usePowerSyncInspectorDiagnostics.js +254 -0
  34. package/dist/runtime/composables/usePowerSyncKysely.d.ts +23 -0
  35. package/dist/runtime/composables/usePowerSyncKysely.js +7 -0
  36. package/dist/runtime/index.d.ts +9 -0
  37. package/dist/runtime/layouts/powersync-inspector-layout.d.vue.ts +13 -0
  38. package/dist/runtime/layouts/powersync-inspector-layout.vue +90 -0
  39. package/dist/runtime/layouts/powersync-inspector-layout.vue.d.ts +13 -0
  40. package/dist/runtime/pages/__powersync-inspector.d.vue.ts +3 -0
  41. package/dist/runtime/pages/__powersync-inspector.vue +153 -0
  42. package/dist/runtime/pages/__powersync-inspector.vue.d.ts +3 -0
  43. package/dist/runtime/plugin.client.d.ts +2 -0
  44. package/dist/runtime/plugin.client.js +11 -0
  45. package/dist/runtime/utils/AppSchema.d.ts +27 -0
  46. package/dist/runtime/utils/AppSchema.js +23 -0
  47. package/dist/runtime/utils/DynamicSchemaManager.d.ts +15 -0
  48. package/dist/runtime/utils/DynamicSchemaManager.js +91 -0
  49. package/dist/runtime/utils/JsSchemaGenerator.d.ts +8 -0
  50. package/dist/runtime/utils/JsSchemaGenerator.js +28 -0
  51. package/dist/runtime/utils/NuxtPowerSyncDatabase.d.ts +40 -0
  52. package/dist/runtime/utils/NuxtPowerSyncDatabase.js +117 -0
  53. package/dist/runtime/utils/RecordingStorageAdapter.d.ts +13 -0
  54. package/dist/runtime/utils/RecordingStorageAdapter.js +76 -0
  55. package/dist/runtime/utils/RustClientInterceptor.d.ts +24 -0
  56. package/dist/runtime/utils/RustClientInterceptor.js +102 -0
  57. package/dist/runtime/utils/TokenConnector.d.ts +14 -0
  58. package/dist/runtime/utils/TokenConnector.js +62 -0
  59. package/dist/runtime/utils/addImportsFrom.d.ts +1 -0
  60. package/dist/runtime/utils/addImportsFrom.js +4 -0
  61. package/dist/runtime/utils/index.d.ts +1 -0
  62. package/dist/runtime/utils/index.js +1 -0
  63. package/dist/types.d.mts +9 -0
  64. package/package.json +90 -0
@@ -0,0 +1,102 @@
1
+ import {
2
+ AbstractPowerSyncDatabase,
3
+ isStreamingSyncCheckpoint,
4
+ isStreamingSyncCheckpointComplete,
5
+ isStreamingSyncCheckpointDiff,
6
+ isStreamingSyncCheckpointPartiallyComplete,
7
+ isStreamingSyncData,
8
+ PowerSyncControlCommand,
9
+ SqliteBucketStorage,
10
+ SyncDataBucket
11
+ } from "@powersync/web";
12
+ export class RustClientInterceptor extends SqliteBucketStorage {
13
+ constructor(db, remote, schemaManager) {
14
+ super(db.value.database, AbstractPowerSyncDatabase.transactionMutex);
15
+ this.remote = remote;
16
+ this.schemaManager = schemaManager;
17
+ this.rdb = db.value.database;
18
+ }
19
+ rdb;
20
+ lastStartedCheckpoint = null;
21
+ tables = {};
22
+ async control(op, payload) {
23
+ const response = await super.control(op, payload);
24
+ if (op == PowerSyncControlCommand.PROCESS_TEXT_LINE) {
25
+ await this.processTextLine(payload);
26
+ } else if (op == PowerSyncControlCommand.PROCESS_BSON_LINE) {
27
+ await this.processBinaryLine(payload);
28
+ }
29
+ return response;
30
+ }
31
+ processTextLine(line) {
32
+ return this.processParsedLine(JSON.parse(line));
33
+ }
34
+ async processBinaryLine(line) {
35
+ const bson = await this.remote.getBSON();
36
+ await this.processParsedLine(bson.deserialize(line));
37
+ }
38
+ async processParsedLine(line) {
39
+ if (isStreamingSyncCheckpoint(line)) {
40
+ this.lastStartedCheckpoint = line.checkpoint;
41
+ await this.trackCheckpoint(line.checkpoint);
42
+ } else if (isStreamingSyncCheckpointDiff(line) && this.lastStartedCheckpoint) {
43
+ const diff = line.checkpoint_diff;
44
+ const newBuckets = /* @__PURE__ */ new Map();
45
+ for (const checksum of this.lastStartedCheckpoint.buckets) {
46
+ newBuckets.set(checksum.bucket, checksum);
47
+ }
48
+ for (const checksum of diff.updated_buckets) {
49
+ newBuckets.set(checksum.bucket, checksum);
50
+ }
51
+ for (const bucket of diff.removed_buckets) {
52
+ newBuckets.delete(bucket);
53
+ }
54
+ const newCheckpoint = {
55
+ last_op_id: diff.last_op_id,
56
+ buckets: [...newBuckets.values()],
57
+ write_checkpoint: diff.write_checkpoint
58
+ };
59
+ this.lastStartedCheckpoint = newCheckpoint;
60
+ await this.trackCheckpoint(newCheckpoint);
61
+ } else if (isStreamingSyncData(line)) {
62
+ const batch = { buckets: [SyncDataBucket.fromRow(line.data)] };
63
+ await this.rdb.writeTransaction(async (tx) => {
64
+ for (const bucket of batch.buckets) {
65
+ const size = JSON.stringify(bucket.data).length;
66
+ await tx.execute(
67
+ `UPDATE local_bucket_data SET
68
+ download_size = IFNULL(download_size, 0) + ?,
69
+ last_op = ?,
70
+ downloading = ?,
71
+ downloaded_operations = IFNULL(downloaded_operations, 0) + ?
72
+ WHERE id = ?`,
73
+ [size, bucket.next_after, bucket.has_more, bucket.data.length, bucket.bucket]
74
+ );
75
+ }
76
+ });
77
+ await this.schemaManager.value.updateFromOperations(batch);
78
+ } else if (isStreamingSyncCheckpointPartiallyComplete(line) || isStreamingSyncCheckpointComplete(line)) {
79
+ setTimeout(() => {
80
+ this.schemaManager.value.refreshSchema(this.rdb);
81
+ }, 60);
82
+ }
83
+ }
84
+ async trackCheckpoint(checkpoint) {
85
+ await this.rdb.writeTransaction(async (tx) => {
86
+ for (const bucket of checkpoint.buckets) {
87
+ await tx.execute(
88
+ `INSERT OR REPLACE INTO local_bucket_data(id, total_operations, last_op, download_size, downloading, downloaded_operations)
89
+ VALUES (
90
+ ?,
91
+ ?,
92
+ IFNULL((SELECT last_op FROM local_bucket_data WHERE id = ?), '0'),
93
+ IFNULL((SELECT download_size FROM local_bucket_data WHERE id = ?), 0),
94
+ IFNULL((SELECT downloading FROM local_bucket_data WHERE id = ?), TRUE),
95
+ IFNULL((SELECT downloaded_operations FROM local_bucket_data WHERE id = ?), TRUE)
96
+ )`,
97
+ [bucket.bucket, bucket.count, bucket.bucket, bucket.bucket, bucket.bucket, bucket.bucket]
98
+ );
99
+ }
100
+ });
101
+ }
102
+ }
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,62 @@
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(
23
+ "powersync_credentials",
24
+ JSON.stringify(credentials)
25
+ );
26
+ await this.connectFn();
27
+ } catch (e) {
28
+ this.clearCredentials();
29
+ throw e;
30
+ }
31
+ }
32
+ hasCredentials() {
33
+ return localStorage.getItem("powersync_credentials") != null;
34
+ }
35
+ clearCredentials() {
36
+ localStorage.removeItem("powersync_credentials");
37
+ }
38
+ }
39
+ function validateSecureContext(url) {
40
+ if (!location.href.startsWith("https:")) {
41
+ return;
42
+ }
43
+ const parsedUrl = new URL(url);
44
+ const secure = parsedUrl.protocol === "https:" || parsedUrl.hostname === "localhost" || parsedUrl.hostname === "127.0.0.1" || parsedUrl.hostname === "::1";
45
+ if (!secure) {
46
+ throw new Error(`Cannot connect to http endpoints from the hosted diagnostics app.
47
+ Run either the PowerSync endpoint on http://localhost, or the diagnostics app on http://localhost.`);
48
+ }
49
+ }
50
+ function checkJWT(token) {
51
+ const parts = token.split(".");
52
+ if (parts.length !== 3) {
53
+ throw new Error(
54
+ `Token must be a JWT: Expected 3 parts, got ${parts.length}`
55
+ );
56
+ }
57
+ const base64UrlRegex = /^[\w-]+$/;
58
+ const isBase64 = parts.every((part) => base64UrlRegex.test(part));
59
+ if (!isBase64) {
60
+ throw new Error(`Token must be a JWT: Not all parts are base64 encoded`);
61
+ }
62
+ }
@@ -0,0 +1 @@
1
+ export declare const addImportsFrom: (names: string[], from: string) => void;
@@ -0,0 +1,4 @@
1
+ import { addImports } from "@nuxt/kit";
2
+ export const addImportsFrom = (names, from) => {
3
+ addImports(names.map((name) => ({ name, from })));
4
+ };
@@ -0,0 +1 @@
1
+ export { NuxtPowerSyncDatabase } from './NuxtPowerSyncDatabase.js';
@@ -0,0 +1 @@
1
+ export { NuxtPowerSyncDatabase } from "./NuxtPowerSyncDatabase.js";
@@ -0,0 +1,9 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.mjs'
8
+
9
+ export { type PowerSyncNuxtModuleOptions } from './module.mjs'
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "@powersync/nuxt",
3
+ "version": "0.0.0-dev-20260128023420",
4
+ "publishConfig": {
5
+ "registry": "https://registry.npmjs.org/",
6
+ "access": "public"
7
+ },
8
+ "description": "PowerSync Nuxt module",
9
+ "license": "Apache-2.0",
10
+ "type": "module",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/powersync-ja/powersync-js.git"
14
+ },
15
+ "author": "POWERSYNC",
16
+ "bugs": {
17
+ "url": "https://github.com/powersync-ja/powersync-js/issues"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/types.d.mts",
22
+ "import": "./dist/module.mjs"
23
+ }
24
+ },
25
+ "main": "./dist/module.mjs",
26
+ "typesVersions": {
27
+ "*": {
28
+ ".": [
29
+ "./dist/types.d.mts"
30
+ ]
31
+ }
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "homepage": "https://docs.powersync.com",
37
+ "dependencies": {
38
+ "@iconify-json/carbon": "^1.2.13",
39
+ "@nuxt/devtools-kit": "^2.6.2",
40
+ "@nuxt/devtools-ui-kit": "^2.6.2",
41
+ "@nuxt/kit": "^4.0.3",
42
+ "@tanstack/vue-table": "^8.21.3",
43
+ "@vueuse/nuxt": "^13.9.0",
44
+ "consola": "^3.4.2",
45
+ "defu": "^6.1.4",
46
+ "fuse.js": "^7.1.0",
47
+ "mitt": "^3.0.1",
48
+ "reka-ui": "^2.5.0",
49
+ "shiki": "^3.13.0",
50
+ "unocss": "^66.5.2",
51
+ "unstorage": "^1.17.1"
52
+ },
53
+ "peerDependencies": {
54
+ "@journeyapps/wa-sqlite": "^1.2.6",
55
+ "@powersync/kysely-driver": "0.0.0-dev-20260128023420",
56
+ "@powersync/vue": "0.4.1",
57
+ "@powersync/web": "0.0.0-dev-20260128023420"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "@powersync/kysely-driver": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "devDependencies": {
65
+ "@journeyapps/wa-sqlite": "^1.4.0",
66
+ "@nuxt/module-builder": "^1.0.2",
67
+ "@nuxt/schema": "^4.1.2",
68
+ "@nuxt/test-utils": "^3.19.2",
69
+ "nuxt": "^4.1.2",
70
+ "vite-plugin-wasm": "^3.5.0",
71
+ "vitest": "^3.2.4",
72
+ "vue": "^3.5.20",
73
+ "vue-tsc": "^3.0.8",
74
+ "@powersync/kysely-driver": "0.0.0-dev-20260128023420",
75
+ "@powersync/vue": "0.4.1",
76
+ "@powersync/web": "0.0.0-dev-20260128023420"
77
+ },
78
+ "scripts": {
79
+ "prebuild": "nuxt-module-build prepare",
80
+ "build": "nuxt-module-build build",
81
+ "prebuild:prod": "nuxt-module-build prepare",
82
+ "build:prod": "nuxt-module-build build",
83
+ "clean": "rm -rf dist .nuxt",
84
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare",
85
+ "watch": "nuxt-module-build build --watch",
86
+ "test": "vitest run",
87
+ "test:watch": "vitest watch",
88
+ "test:exports": "attw --pack --profile=esm-only ."
89
+ }
90
+ }