@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,213 +0,0 @@
1
- import { usePowerSync, useStatus } from "@powersync/vue";
2
- import { ref, computed, readonly, onMounted, onUnmounted } from "vue";
3
- import { computedAsync } from "@vueuse/core";
4
- import { usePowerSyncInspector } from "./usePowerSyncInspector.js";
5
- const BUCKETS_QUERY = `
6
- WITH
7
- oplog_by_table AS
8
- (SELECT
9
- bucket,
10
- row_type,
11
- sum(length(ifnull(data, ''))) as data_size,
12
- sum(length(row_type) + length(row_id) + length(key) + 44) as metadata_size,
13
- count() as row_count
14
- FROM ps_oplog
15
- GROUP BY bucket, row_type),
16
-
17
- oplog_stats AS
18
- (SELECT
19
- bucket as bucket_id,
20
- sum(data_size) as data_size,
21
- sum(metadata_size) as metadata_size,
22
- sum(row_count) as row_count,
23
- json_group_array(row_type) tables
24
- FROM oplog_by_table
25
- GROUP BY bucket)
26
-
27
- SELECT
28
- local.id as name,
29
- ps_buckets.id as id,
30
- stats.tables,
31
- stats.data_size,
32
- stats.metadata_size,
33
- IFNULL(stats.row_count, 0) as row_count,
34
- local.download_size,
35
- local.downloaded_operations,
36
- local.total_operations,
37
- local.downloading
38
- FROM local_bucket_data local
39
- LEFT JOIN ps_buckets ON ps_buckets.name = local.id
40
- LEFT JOIN oplog_stats stats ON stats.bucket_id = ps_buckets.id`;
41
- const BUCKETS_QUERY_FAST = `
42
- SELECT
43
- local.id as name,
44
- ps_buckets.id as id,
45
- '[]' as tables,
46
- 0 as data_size,
47
- 0 as metadata_size,
48
- 0 as row_count,
49
- local.download_size,
50
- local.downloaded_operations,
51
- local.total_operations,
52
- local.downloading
53
- FROM local_bucket_data local
54
- LEFT JOIN ps_buckets ON ps_buckets.name = local.id`;
55
- const TABLES_QUERY = `
56
- SELECT row_type as name, count() as count, sum(length(data)) as size FROM ps_oplog GROUP BY row_type
57
- `;
58
- function formatBytes(bytes, decimals = 2) {
59
- if (!+bytes) return "0 Bytes";
60
- const k = 1024;
61
- const dm = decimals < 0 ? 0 : decimals;
62
- const sizes = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
63
- const i = Math.floor(Math.log(bytes) / Math.log(k));
64
- return `${Number.parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
65
- }
66
- export function usePowerSyncInspectorDiagnostics() {
67
- const db = usePowerSync();
68
- const syncStatus = useStatus();
69
- const { getCurrentSchemaManager } = usePowerSyncInspector();
70
- const isDiagnosticSchemaSetup = ref(true);
71
- const connectionOptions = computed(() => db.value.connectionOptions || null);
72
- const connector = computed(() => db.value.connector || null);
73
- const hasSynced = ref(syncStatus.value?.hasSynced || false);
74
- const isConnected = ref(syncStatus.value?.connected || false);
75
- const isSyncing = ref(false);
76
- const isDownloading = ref(syncStatus.value?.downloading || false);
77
- const isUploading = ref(syncStatus.value?.uploading || false);
78
- const lastSyncedAt = ref(syncStatus.value?.lastSyncedAt || null);
79
- const uploadError = ref(syncStatus.value?.uploadError || null);
80
- const downloadError = ref(syncStatus.value?.downloadError || null);
81
- const downloadProgressDetails = ref(syncStatus.value?.downloadProgress || null);
82
- const bucketRows = ref(null);
83
- const tableRows = ref(null);
84
- const uploadQueueStats = ref(null);
85
- const totals = computed(() => ({
86
- buckets: bucketRows.value?.length ?? 0,
87
- row_count: bucketRows.value?.reduce((total, row) => total + row.row_count, 0) ?? 0,
88
- downloaded_operations: bucketRows.value?.reduce((total, row) => total + row.downloaded_operations, 0),
89
- total_operations: bucketRows.value?.reduce((total, row) => total + row.total_operations, 0) ?? 0,
90
- data_size: formatBytes(bucketRows.value?.reduce((total, row) => total + row.data_size, 0) ?? 0),
91
- metadata_size: formatBytes(bucketRows.value?.reduce((total, row) => total + row.metadata_size, 0) ?? 0),
92
- download_size: formatBytes(bucketRows.value?.reduce((total, row) => total + row.download_size, 0) ?? 0)
93
- }));
94
- const userID = computedAsync(async () => {
95
- try {
96
- const token = (await connector.value.fetchCredentials())?.token;
97
- if (!token) return null;
98
- const [_head, body, _signature] = token.split(".");
99
- const payload = JSON.parse(atob(body ?? ""));
100
- return payload.sub;
101
- } catch {
102
- return null;
103
- }
104
- });
105
- const totalDownloadProgress = computed(() => {
106
- if (!hasSynced.value || isSyncing.value) {
107
- return ((syncStatus.value?.downloadProgress?.downloadedFraction ?? 0) * 100).toFixed(1);
108
- }
109
- return "100";
110
- });
111
- const uploadQueueSize = computed(() => formatBytes(uploadQueueStats.value?.size ?? 0));
112
- const uploadQueueCount = computed(() => uploadQueueStats.value?.count ?? 0);
113
- const clearData = async () => {
114
- await db.value?.disconnect();
115
- const connector2 = db.value.connector;
116
- const connectionOptions2 = db.value.connectionOptions;
117
- await db.value?.disconnectAndClear();
118
- const schemaManager = getCurrentSchemaManager();
119
- await schemaManager.clear();
120
- await schemaManager.refreshSchema(db.value.database);
121
- await db.value.connect(connector2, connectionOptions2);
122
- };
123
- async function refreshState() {
124
- if (db.value) {
125
- const { synced_at } = await db.value.get(
126
- "SELECT powersync_last_synced_at() as synced_at"
127
- );
128
- uploadQueueStats.value = await db.value?.getUploadQueueStats(true);
129
- if (synced_at != null && !syncStatus.value?.downloading) {
130
- bucketRows.value = await db.value.getAll(BUCKETS_QUERY);
131
- tableRows.value = await db.value.getAll(TABLES_QUERY);
132
- } else if (synced_at != null) {
133
- bucketRows.value = await db.value.getAll(BUCKETS_QUERY_FAST);
134
- if (tableRows.value == null) {
135
- tableRows.value = await db.value.getAll(TABLES_QUERY);
136
- }
137
- } else {
138
- bucketRows.value = await db.value.getAll(BUCKETS_QUERY_FAST);
139
- tableRows.value = null;
140
- }
141
- }
142
- }
143
- onMounted(async () => {
144
- if (!db.value) return;
145
- const unregisterListener = db.value.registerListener({
146
- statusChanged: (newStatus) => {
147
- hasSynced.value = !!newStatus.hasSynced;
148
- isConnected.value = !!newStatus.connected;
149
- isDownloading.value = !!newStatus.downloading;
150
- isUploading.value = !!newStatus.uploading;
151
- lastSyncedAt.value = newStatus.lastSyncedAt || null;
152
- uploadError.value = newStatus.uploadError || null;
153
- downloadError.value = newStatus.downloadError || null;
154
- downloadProgressDetails.value = newStatus.downloadProgress || null;
155
- if (newStatus?.hasSynced === void 0 || newStatus?.priorityStatusEntries?.length && newStatus.priorityStatusEntries.length > 0) {
156
- hasSynced.value = newStatus?.priorityStatusEntries.every((entry) => entry.hasSynced) ?? false;
157
- }
158
- if (newStatus?.downloading || newStatus?.uploading) {
159
- isSyncing.value = true;
160
- } else {
161
- isSyncing.value = false;
162
- }
163
- }
164
- });
165
- db.value.onChangeWithCallback(
166
- {
167
- async onChange(_event) {
168
- await refreshState();
169
- }
170
- },
171
- {
172
- tables: ["ps_oplog", "ps_buckets", "ps_data_local__local_bucket_data", "ps_crud"],
173
- throttleMs: 500
174
- }
175
- );
176
- try {
177
- await refreshState();
178
- } catch (error) {
179
- if (error.message === "no such table: local_bucket_data") {
180
- isDiagnosticSchemaSetup.value = false;
181
- }
182
- }
183
- onUnmounted(() => {
184
- unregisterListener();
185
- });
186
- });
187
- return {
188
- db,
189
- connector,
190
- connectionOptions,
191
- isDiagnosticSchemaSetup: readonly(isDiagnosticSchemaSetup),
192
- syncStatus: readonly(syncStatus),
193
- hasSynced: readonly(hasSynced),
194
- isConnected: readonly(isConnected),
195
- isSyncing: readonly(isSyncing),
196
- isDownloading: readonly(isDownloading),
197
- isUploading: readonly(isUploading),
198
- downloadError: readonly(downloadError),
199
- uploadError: readonly(uploadError),
200
- downloadProgressDetails: readonly(downloadProgressDetails),
201
- lastSyncedAt: readonly(lastSyncedAt),
202
- totalDownloadProgress: readonly(totalDownloadProgress),
203
- uploadQueueStats: readonly(uploadQueueStats),
204
- uploadQueueCount: readonly(uploadQueueCount),
205
- uploadQueueSize: readonly(uploadQueueSize),
206
- userID: readonly(userID),
207
- bucketRows: readonly(bucketRows),
208
- tableRows: readonly(tableRows),
209
- totals: readonly(totals),
210
- clearData,
211
- formatBytes
212
- };
213
- }
@@ -1,13 +0,0 @@
1
- declare var __VLS_20: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_20) => any;
4
- };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
6
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
- declare const _default: typeof __VLS_export;
8
- export default _default;
9
- type __VLS_WithSlots<T, S> = T & {
10
- new (): {
11
- $slots: S;
12
- };
13
- };
@@ -1,63 +0,0 @@
1
- <template>
2
- <div>
3
- <LoadingSpinner v-if="isCssLoading" />
4
-
5
- <div v-show="!isCssLoading" flex="~ relative col" p="6" h="screen" n-bg="base" class="ps-inspector-ui">
6
- <!-- Header with title and dark toggle -->
7
- <div flex="~ items-center justify-between" mb="3">
8
- <h1 flex="~ gap-2 items-center" text="3xl" font="bold">
9
- <img :src="iconUrl" alt="Powersync" w="10" h="10" />
10
- PowerSync Inspector
11
- </h1>
12
-
13
- <!-- Dark Mode Toggle -->
14
- <NDarkToggle v-slot="{ isDark, toggle }">
15
- <NButton n="sm" :icon="isDark.value ? 'carbon:moon' : 'carbon:sun'" @click="toggle">
16
- {{ isDark.value ? "Dark" : "Light" }}
17
- </NButton>
18
- </NDarkToggle>
19
- </div>
20
-
21
- <slot v-if="useDiagnostics" />
22
- <div v-else>
23
- <NTip n="red6 dark:red5" icon="carbon:warning-alt">
24
- Enable diagnostics in your Nuxt config to use the inspector.
25
- </NTip>
26
- </div>
27
- </div>
28
- </div>
29
- </template>
30
-
31
- <script setup>
32
- import { useRuntimeConfig } from "#imports";
33
- import { onMounted, ref } from "vue";
34
- import iconUrl from "./assets/powersync-icon.svg?url";
35
- const useDiagnostics = useRuntimeConfig().public.powerSyncModuleOptions.useDiagnostics ?? false;
36
- const isCssLoading = ref(true);
37
- onMounted(async () => {
38
- await waitForUnoCSS();
39
- isCssLoading.value = false;
40
- });
41
- const waitForUnoCSS = () => {
42
- return new Promise((resolve) => {
43
- const testEl = document.createElement("div");
44
- testEl.className = "w-10 h-10";
45
- testEl.style.position = "absolute";
46
- testEl.style.visibility = "hidden";
47
- testEl.style.pointerEvents = "none";
48
- document.body.appendChild(testEl);
49
- const checkStyles = () => {
50
- const computed = window.getComputedStyle(testEl);
51
- const width = computed.getPropertyValue("width");
52
- const height = computed.getPropertyValue("height");
53
- if (width === "40px" && height === "40px") {
54
- document.body.removeChild(testEl);
55
- resolve(void 0);
56
- } else {
57
- requestAnimationFrame(checkStyles);
58
- }
59
- };
60
- requestAnimationFrame(checkStyles);
61
- });
62
- };
63
- </script>
@@ -1,13 +0,0 @@
1
- declare var __VLS_20: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_20) => any;
4
- };
5
- declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
6
- declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
- declare const _default: typeof __VLS_export;
8
- export default _default;
9
- type __VLS_WithSlots<T, S> = T & {
10
- new (): {
11
- $slots: S;
12
- };
13
- };
@@ -1,3 +0,0 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
- declare const _default: typeof __VLS_export;
3
- export default _default;
@@ -1,119 +0,0 @@
1
- <template>
2
- <div flex="~ justify-between" border="b" border-color="gray-100" py="3" mb="3">
3
- <div flex="~ gap-2">
4
- <NTip
5
- :n="`${isConnected ? 'green' : isSyncing ? 'blue' : 'red'} xs`"
6
- :icon="`${isConnected ? 'carbon:plug-filled' : isSyncing ? 'carbon:plug' : 'carbon:connection-signal-off'}`"
7
- >
8
- Powersync is
9
- {{ isConnected ? "connected" : isSyncing ? "connecting..." : "disconnected" }}
10
- </NTip>
11
- <NTip
12
- :n="`${isSyncing ? 'blue' : hasSynced ? 'green' : 'yellow'} xs`"
13
- :icon="`${isSyncing ? 'carbon:data-unreal' : hasSynced ? 'carbon:checkmark-filled' : 'carbon:async'}`"
14
- >
15
- {{ isSyncing ? "Syncing" : hasSynced ? "Synced" : "Not Synced" }}
16
- </NTip>
17
- <NTip
18
- :n="`${isUploading ? 'green' : 'gray'} xs`"
19
- :icon="isUploading ? 'carbon:cloud-upload' : 'carbon:pause-outline'"
20
- >
21
- {{ isUploading ? "Uploading" : "Upload Idle" }}
22
- </NTip>
23
- <NTip
24
- :n="`${isDownloading ? 'green' : 'gray'} xs`"
25
- :icon="isDownloading ? 'carbon:cloud-download' : 'carbon:pause-outline'"
26
- >
27
- {{ isDownloading ? "Downloading" : "Download Idle" }}
28
- </NTip>
29
- <NBadge flex="~ gap-2 items-center" n="gray xs" icon="carbon:server-time">
30
- Last Synced:
31
- {{ lastSyncedFormatted }}
32
- </NBadge>
33
- <NBadge flex="~ gap-2 items-center" n="gray xs" icon="carbon:user-admin"> Logged in as: {{ userID }} </NBadge>
34
- </div>
35
-
36
- <div flex="~ gap-2">
37
- <NButton n="red sm" icon="carbon:clean" @click="resync"> Prune & Re-sync </NButton>
38
- <NDarkToggle />
39
- </div>
40
- </div>
41
-
42
- <div flex="~ gap-4">
43
- <NTip v-if="downloadError || uploadError" n="red sm" mb="3" icon="carbon:warning-hex-filled">
44
- {{ downloadError?.message ?? uploadError?.message }}
45
- </NTip>
46
- </div>
47
-
48
- <div flex="~ gap-2" mb="3">
49
- <NSelectTabs
50
- v-model="selectedTab"
51
- n="amber6 dark:amber5"
52
- cursor="pointer"
53
- :options="tabs"
54
- @update:model-value="handleTabChange"
55
- />
56
- </div>
57
-
58
- <!-- switching tabs -->
59
- <SyncStatusTab v-if="selectedTab === 'sync-status'" />
60
- <DataInspectorTab v-if="selectedTab === 'data'" />
61
- <ConfigInspectorTab v-if="selectedTab === 'config'" />
62
- <BucketsInspectorTab v-if="selectedTab === 'buckets'" />
63
- <LogsTab v-if="selectedTab === 'logs'" />
64
- <PowerSyncInstanceTab v-if="selectedTab === 'powersync-instance'" />
65
- </template>
66
-
67
- <script setup>
68
- import { ref, onMounted, computed } from "vue";
69
- import { useTimeAgo } from "@vueuse/core";
70
- import { definePageMeta, usePowerSyncInspectorDiagnostics, useRoute, useRouter } from "#imports";
71
- import SyncStatusTab from "../components/SyncStatusTab.vue";
72
- import DataInspectorTab from "../components/DataInspectorTab.vue";
73
- import ConfigInspectorTab from "../components/ConfigInspectorTab.vue";
74
- import LogsTab from "../components/LogsTab.vue";
75
- import BucketsInspectorTab from "../components/BucketsInspectorTab.vue";
76
- import PowerSyncInstanceTab from "../components/PowerSyncInstanceTab.vue";
77
- definePageMeta({
78
- layout: "powersync-inspector-layout"
79
- });
80
- const {
81
- db,
82
- isConnected,
83
- isSyncing,
84
- hasSynced,
85
- isDownloading,
86
- isUploading,
87
- downloadError,
88
- uploadError,
89
- lastSyncedAt,
90
- userID,
91
- clearData
92
- } = usePowerSyncInspectorDiagnostics();
93
- onMounted(async () => {
94
- await db.value?.waitForFirstSync();
95
- });
96
- const route = useRoute();
97
- const router = useRouter();
98
- const selectedTab = ref(route.query.tab || "sync-status");
99
- const handleTabChange = (tab) => {
100
- router.push({ query: { tab } });
101
- };
102
- const tabs = [
103
- { label: "Sync Status", value: "sync-status" },
104
- { label: "Data Inspector", value: "data" },
105
- { label: "Buckets Inspector", value: "buckets" },
106
- { label: "Config Inspector", value: "config" },
107
- { label: "Client Logs", value: "logs" }
108
- // { label: 'PowerSync Instance', value: 'powersync-instance' },
109
- ];
110
- const lastSyncedFormatted = computed(() => lastSyncedAt.value ? useTimeAgo(new Date(lastSyncedAt.value)) : "NA");
111
- const resync = async () => {
112
- await clearData();
113
- await db.value?.waitForFirstSync();
114
- };
115
- </script>
116
-
117
- <style>
118
- #__nuxt,#nuxt-test,body,html{background-color:transparent}
119
- </style>
@@ -1,3 +0,0 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
- declare const _default: typeof __VLS_export;
3
- export default _default;
@@ -1,27 +0,0 @@
1
- import { Schema, Table } from '@powersync/web';
2
- export declare const LOCAL_BUCKET_DATA_TABLE_NAME = "local_bucket_data";
3
- export declare const LOCAL_SCHEMA_TABLE_NAME = "local_schema";
4
- export declare const local_bucket_data: Table<{
5
- total_operations: import("@powersync/common").BaseColumnType<number | null>;
6
- last_op: import("@powersync/common").BaseColumnType<string | null>;
7
- download_size: import("@powersync/common").BaseColumnType<number | null>;
8
- downloaded_operations: import("@powersync/common").BaseColumnType<number | null>;
9
- downloading: import("@powersync/common").BaseColumnType<number | null>;
10
- }>;
11
- export declare const local_schema: Table<{
12
- data: import("@powersync/common").BaseColumnType<string | null>;
13
- }>;
14
- export declare const DiagnosticsAppSchema: Schema<{
15
- local_bucket_data: Table<{
16
- total_operations: import("@powersync/common").BaseColumnType<number | null>;
17
- last_op: import("@powersync/common").BaseColumnType<string | null>;
18
- download_size: import("@powersync/common").BaseColumnType<number | null>;
19
- downloaded_operations: import("@powersync/common").BaseColumnType<number | null>;
20
- downloading: import("@powersync/common").BaseColumnType<number | null>;
21
- }>;
22
- local_schema: Table<{
23
- data: import("@powersync/common").BaseColumnType<string | null>;
24
- }>;
25
- }>;
26
- export type Database = (typeof DiagnosticsAppSchema)['types'];
27
- export type LocalBucketData = Database['local_bucket_data'];
@@ -1,23 +0,0 @@
1
- import { column, Schema, Table } from "@powersync/web";
2
- export const LOCAL_BUCKET_DATA_TABLE_NAME = "local_bucket_data";
3
- export const LOCAL_SCHEMA_TABLE_NAME = "local_schema";
4
- export const local_bucket_data = new Table(
5
- {
6
- total_operations: column.integer,
7
- last_op: column.text,
8
- download_size: column.integer,
9
- downloaded_operations: column.integer,
10
- downloading: column.integer
11
- },
12
- { localOnly: true }
13
- );
14
- export const local_schema = new Table(
15
- {
16
- data: column.text
17
- },
18
- { localOnly: true }
19
- );
20
- export const DiagnosticsAppSchema = new Schema({
21
- local_bucket_data,
22
- local_schema
23
- });
@@ -1,16 +0,0 @@
1
- import type { DBAdapter } from '@powersync/web';
2
- import { Schema } from '@powersync/web';
3
- import type { SyncDataBucketJSON } from '@powersync/shared-internals/internal/sync_protocol';
4
- /**
5
- * Record fields from downloaded data, then build a schema from it.
6
- */
7
- export declare class DynamicSchemaManager {
8
- private tables;
9
- private dirty;
10
- constructor();
11
- clear(): Promise<void>;
12
- updateFromOperations(batch: SyncDataBucketJSON): Promise<void>;
13
- refreshSchema(db: DBAdapter): Promise<void>;
14
- buildSchema(): Schema;
15
- schemaToString(): string;
16
- }
@@ -1,82 +0,0 @@
1
- import { Column, ColumnType, ResolvedTable, Schema } from "@powersync/web";
2
- import { DiagnosticsAppSchema as AppSchema } from "./AppSchema.js";
3
- import { JsSchemaGenerator } from "./JsSchemaGenerator.js";
4
- export class DynamicSchemaManager {
5
- tables;
6
- dirty = false;
7
- constructor() {
8
- const tables = localStorage.getItem("powersync_dynamic_schema");
9
- this.tables = tables ? JSON.parse(tables) : {};
10
- }
11
- async clear() {
12
- this.tables = {};
13
- this.dirty = true;
14
- localStorage.removeItem("powersync_dynamic_schema");
15
- }
16
- async updateFromOperations(batch) {
17
- let schemaDirty = false;
18
- for (const op of batch.data) {
19
- if (op.op == "PUT" && op.data != null) {
20
- this.tables[op.object_type] ??= {};
21
- const table = this.tables[op.object_type];
22
- const data = JSON.parse(op.data);
23
- for (const [key, value] of Object.entries(data)) {
24
- if (key == "id") {
25
- continue;
26
- }
27
- if (table) {
28
- const existing = table[key];
29
- if (typeof value == "number" && Number.isInteger(value) && existing != ColumnType.REAL && existing != ColumnType.TEXT) {
30
- if (table[key] != ColumnType.INTEGER) {
31
- schemaDirty = true;
32
- }
33
- table[key] = ColumnType.INTEGER;
34
- } else if (typeof value == "number" && existing != ColumnType.TEXT) {
35
- if (table[key] != ColumnType.REAL) {
36
- schemaDirty = true;
37
- }
38
- table[key] = ColumnType.REAL;
39
- } else if (typeof value == "string") {
40
- if (table[key] != ColumnType.TEXT) {
41
- schemaDirty = true;
42
- }
43
- table[key] = ColumnType.TEXT;
44
- }
45
- }
46
- }
47
- }
48
- }
49
- if (schemaDirty) {
50
- localStorage.setItem("powersync_dynamic_schema", JSON.stringify(this.tables));
51
- this.dirty = true;
52
- }
53
- }
54
- async refreshSchema(db) {
55
- if (this.dirty) {
56
- const json = this.buildSchema().toJSON();
57
- await db.execute("SELECT powersync_replace_schema(?)", [JSON.stringify(json)]);
58
- this.dirty = false;
59
- }
60
- }
61
- buildSchema() {
62
- const base = AppSchema;
63
- const tables = [...base.tables];
64
- for (const [key, value] of Object.entries(this.tables)) {
65
- const table = new ResolvedTable({
66
- name: key,
67
- columns: Object.entries(value).map(
68
- ([cname, ctype]) => new Column({
69
- name: cname,
70
- type: ctype
71
- })
72
- )
73
- });
74
- tables.push(table);
75
- }
76
- return new Schema(tables);
77
- }
78
- schemaToString() {
79
- const filtered = this.buildSchema().tables.filter((table) => !table.localOnly);
80
- return new JsSchemaGenerator().generate(new Schema(filtered));
81
- }
82
- }
@@ -1,8 +0,0 @@
1
- import type { Schema } from '@powersync/web';
2
- export declare class JsSchemaGenerator {
3
- generate(schema: Schema): string;
4
- private generateTables;
5
- private generateTable;
6
- private generateColumn;
7
- private generateAppSchema;
8
- }
@@ -1,28 +0,0 @@
1
- export class JsSchemaGenerator {
2
- generate(schema) {
3
- const tables = schema.tables;
4
- return this.generateTables(tables) + "\n\n" + this.generateAppSchema(tables);
5
- }
6
- generateTables(tables) {
7
- return tables.map((table) => this.generateTable(table.name, table.columns)).join("\n\n");
8
- }
9
- generateTable(name, columns) {
10
- return `export const ${name} = new Table(
11
- {
12
- // id column (text) is automatically included
13
- ${columns.map((column) => this.generateColumn(column)).join(",\n ")}
14
- },
15
- { indexes: {} }
16
- );`;
17
- }
18
- generateColumn(column) {
19
- return `${column.name}: column.${column.type.toLowerCase()}`;
20
- }
21
- generateAppSchema(tables) {
22
- return `export const AppSchema = new Schema({
23
- ${tables.map((table) => table.name).join(",\n ")}
24
- });
25
-
26
- export type Database = (typeof AppSchema)['types'];`;
27
- }
28
- }
@@ -1,42 +0,0 @@
1
- import { WebPowerSyncDatabase, type DisconnectAndClearOptions, type PowerSyncBackendConnector, type WebPowerSyncDatabaseOptions, type SyncOptions, type CommonPowerSyncDatabase, type PowerSyncDatabaseConstructor } from '@powersync/web';
2
- import { type StreamingSyncImplementation, type CreateSyncImplementationOptions } from '@powersync/shared-internals';
3
- export declare class NuxtDatabaseImplementation extends WebPowerSyncDatabase {
4
- private schemaManager;
5
- private _connector;
6
- private useDiagnostics;
7
- get dbOptions(): WebPowerSyncDatabaseOptions;
8
- get connector(): PowerSyncBackendConnector | null;
9
- constructor(options: WebPowerSyncDatabaseOptions);
10
- protected generateSyncStreamImplementation(connector: PowerSyncBackendConnector, options: CreateSyncImplementationOptions): StreamingSyncImplementation;
11
- connect(connector: PowerSyncBackendConnector, options?: SyncOptions): Promise<void>;
12
- disconnect(): Promise<void>;
13
- disconnectAndClear(options?: DisconnectAndClearOptions): Promise<void>;
14
- }
15
- /**
16
- * An extended PowerSync database class that includes diagnostic capabilities for use with the PowerSync Inspector.
17
- *
18
- * This class automatically configures diagnostics when `useDiagnostics: true` is set in the module configuration.
19
- * It provides enhanced VFS support, schema management, and logging capabilities for the inspector.
20
- *
21
- * @example
22
- * ```typescript
23
- * import { NuxtPowerSyncDatabase } from '@powersync/nuxt'
24
- *
25
- * const db = new NuxtPowerSyncDatabase({
26
- * database: {
27
- * dbFilename: 'your-db-filename.sqlite',
28
- * },
29
- * schema: yourSchema,
30
- * })
31
- * ```
32
- *
33
- * @remarks
34
- * - When diagnostics are enabled, automatically uses cooperative sync VFS for improved compatibility
35
- * - Stores connector internally for inspector access
36
- * - Integrates with dynamic schema management for inspector features
37
- * - Automatically configures logging when diagnostics are enabled
38
- * - When diagnostics are disabled, behaves like a standard `PowerSyncDatabase`
39
- */
40
- export declare const NuxtPowerSyncDatabase: PowerSyncDatabaseConstructor<WebPowerSyncDatabaseOptions>;
41
- export interface NuxtPowerSyncDatabase extends CommonPowerSyncDatabase {
42
- }