@powersync/nuxt 1.0.0 → 2.1.0
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 +36 -59
- package/dist/module.d.mts +4 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +74 -64
- package/dist/runtime/assets/devtools-theme.d.ts +1 -0
- package/dist/runtime/assets/devtools-theme.js +33 -0
- package/dist/runtime/options.d.ts +13 -0
- package/dist/runtime/options.js +0 -0
- package/dist/runtime/plugin.client.js +8 -8
- package/package.json +10 -11
- package/dist/runtime/components/BucketsInspectorTab.d.vue.ts +0 -3
- package/dist/runtime/components/BucketsInspectorTab.vue +0 -544
- package/dist/runtime/components/BucketsInspectorTab.vue.d.ts +0 -3
- package/dist/runtime/components/ConfigInspectorTab.d.vue.ts +0 -3
- package/dist/runtime/components/ConfigInspectorTab.vue +0 -84
- package/dist/runtime/components/ConfigInspectorTab.vue.d.ts +0 -3
- package/dist/runtime/components/DataInspectorTab.d.vue.ts +0 -3
- package/dist/runtime/components/DataInspectorTab.vue +0 -564
- package/dist/runtime/components/DataInspectorTab.vue.d.ts +0 -3
- package/dist/runtime/components/LoadingSpinner.d.vue.ts +0 -3
- package/dist/runtime/components/LoadingSpinner.vue +0 -12
- package/dist/runtime/components/LoadingSpinner.vue.d.ts +0 -3
- package/dist/runtime/components/LogsTab.d.vue.ts +0 -3
- package/dist/runtime/components/LogsTab.vue +0 -273
- package/dist/runtime/components/LogsTab.vue.d.ts +0 -3
- package/dist/runtime/components/PowerSyncInstanceTab.d.vue.ts +0 -3
- package/dist/runtime/components/PowerSyncInstanceTab.vue +0 -7
- package/dist/runtime/components/PowerSyncInstanceTab.vue.d.ts +0 -3
- package/dist/runtime/components/SyncStatusTab.d.vue.ts +0 -3
- package/dist/runtime/components/SyncStatusTab.vue +0 -161
- package/dist/runtime/components/SyncStatusTab.vue.d.ts +0 -3
- package/dist/runtime/composables/usePowerSyncInspector.d.ts +0 -39
- package/dist/runtime/composables/usePowerSyncInspector.js +0 -17
- package/dist/runtime/composables/usePowerSyncInspectorDiagnostics.d.ts +0 -153
- package/dist/runtime/composables/usePowerSyncInspectorDiagnostics.js +0 -216
- package/dist/runtime/layouts/powersync-inspector-layout.d.vue.ts +0 -13
- package/dist/runtime/layouts/powersync-inspector-layout.vue +0 -63
- package/dist/runtime/layouts/powersync-inspector-layout.vue.d.ts +0 -13
- package/dist/runtime/pages/__powersync-inspector.d.vue.ts +0 -3
- package/dist/runtime/pages/__powersync-inspector.vue +0 -119
- package/dist/runtime/pages/__powersync-inspector.vue.d.ts +0 -3
- package/dist/runtime/utils/AppSchema.d.ts +0 -27
- package/dist/runtime/utils/AppSchema.js +0 -23
- package/dist/runtime/utils/DynamicSchemaManager.d.ts +0 -16
- package/dist/runtime/utils/DynamicSchemaManager.js +0 -82
- package/dist/runtime/utils/JsSchemaGenerator.d.ts +0 -8
- package/dist/runtime/utils/JsSchemaGenerator.js +0 -28
- package/dist/runtime/utils/NuxtPowerSyncDatabase.d.ts +0 -42
- package/dist/runtime/utils/NuxtPowerSyncDatabase.js +0 -97
- package/dist/runtime/utils/RustClientInterceptor.d.ts +0 -24
- package/dist/runtime/utils/RustClientInterceptor.js +0 -90
- package/dist/runtime/utils/TokenConnector.d.ts +0 -14
- package/dist/runtime/utils/TokenConnector.js +0 -57
- package/dist/runtime/utils/index.d.ts +0 -1
- package/dist/runtime/utils/index.js +0 -1
|
@@ -1,216 +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
|
-
import { SyncStatusSnapshot } from "@powersync/shared-internals";
|
|
6
|
-
const BUCKETS_QUERY = `
|
|
7
|
-
WITH
|
|
8
|
-
oplog_by_table AS
|
|
9
|
-
(SELECT
|
|
10
|
-
bucket,
|
|
11
|
-
row_type,
|
|
12
|
-
sum(length(ifnull(data, ''))) as data_size,
|
|
13
|
-
sum(length(row_type) + length(row_id) + length(key) + 44) as metadata_size,
|
|
14
|
-
count() as row_count
|
|
15
|
-
FROM ps_oplog
|
|
16
|
-
GROUP BY bucket, row_type),
|
|
17
|
-
|
|
18
|
-
oplog_stats AS
|
|
19
|
-
(SELECT
|
|
20
|
-
bucket as bucket_id,
|
|
21
|
-
sum(data_size) as data_size,
|
|
22
|
-
sum(metadata_size) as metadata_size,
|
|
23
|
-
sum(row_count) as row_count,
|
|
24
|
-
json_group_array(row_type) tables
|
|
25
|
-
FROM oplog_by_table
|
|
26
|
-
GROUP BY bucket)
|
|
27
|
-
|
|
28
|
-
SELECT
|
|
29
|
-
local.id as name,
|
|
30
|
-
ps_buckets.id as id,
|
|
31
|
-
stats.tables,
|
|
32
|
-
stats.data_size,
|
|
33
|
-
stats.metadata_size,
|
|
34
|
-
IFNULL(stats.row_count, 0) as row_count,
|
|
35
|
-
local.download_size,
|
|
36
|
-
local.downloaded_operations,
|
|
37
|
-
local.total_operations,
|
|
38
|
-
local.downloading
|
|
39
|
-
FROM local_bucket_data local
|
|
40
|
-
LEFT JOIN ps_buckets ON ps_buckets.name = local.id
|
|
41
|
-
LEFT JOIN oplog_stats stats ON stats.bucket_id = ps_buckets.id`;
|
|
42
|
-
const BUCKETS_QUERY_FAST = `
|
|
43
|
-
SELECT
|
|
44
|
-
local.id as name,
|
|
45
|
-
ps_buckets.id as id,
|
|
46
|
-
'[]' as tables,
|
|
47
|
-
0 as data_size,
|
|
48
|
-
0 as metadata_size,
|
|
49
|
-
0 as row_count,
|
|
50
|
-
local.download_size,
|
|
51
|
-
local.downloaded_operations,
|
|
52
|
-
local.total_operations,
|
|
53
|
-
local.downloading
|
|
54
|
-
FROM local_bucket_data local
|
|
55
|
-
LEFT JOIN ps_buckets ON ps_buckets.name = local.id`;
|
|
56
|
-
const TABLES_QUERY = `
|
|
57
|
-
SELECT row_type as name, count() as count, sum(length(data)) as size FROM ps_oplog GROUP BY row_type
|
|
58
|
-
`;
|
|
59
|
-
function formatBytes(bytes, decimals = 2) {
|
|
60
|
-
if (!+bytes) return "0 Bytes";
|
|
61
|
-
const k = 1024;
|
|
62
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
63
|
-
const sizes = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
64
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
65
|
-
return `${Number.parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
66
|
-
}
|
|
67
|
-
export function usePowerSyncInspectorDiagnostics() {
|
|
68
|
-
const db = usePowerSync();
|
|
69
|
-
const syncStatus = useStatus();
|
|
70
|
-
const { getCurrentSchemaManager } = usePowerSyncInspector();
|
|
71
|
-
const isDiagnosticSchemaSetup = ref(true);
|
|
72
|
-
const connectionOptions = computed(() => db.value.connectionOptions || null);
|
|
73
|
-
const connector = computed(() => db.value.connector || null);
|
|
74
|
-
const hasSynced = ref(syncStatus.value?.hasSynced || false);
|
|
75
|
-
const isConnected = ref(syncStatus.value?.connected || false);
|
|
76
|
-
const isSyncing = ref(false);
|
|
77
|
-
const isDownloading = ref(syncStatus.value?.downloading || false);
|
|
78
|
-
const isUploading = ref(syncStatus.value?.uploading || false);
|
|
79
|
-
const lastSyncedAt = ref(syncStatus.value?.lastSyncedAt || null);
|
|
80
|
-
const uploadError = ref(syncStatus.value?.uploadError || null);
|
|
81
|
-
const downloadError = ref(syncStatus.value?.downloadError || null);
|
|
82
|
-
const downloadProgressDetails = ref(syncStatus.value?.downloadProgress || null);
|
|
83
|
-
const bucketRows = ref(null);
|
|
84
|
-
const tableRows = ref(null);
|
|
85
|
-
const uploadQueueStats = ref(null);
|
|
86
|
-
const totals = computed(() => ({
|
|
87
|
-
buckets: bucketRows.value?.length ?? 0,
|
|
88
|
-
row_count: bucketRows.value?.reduce((total, row) => total + row.row_count, 0) ?? 0,
|
|
89
|
-
downloaded_operations: bucketRows.value?.reduce((total, row) => total + row.downloaded_operations, 0),
|
|
90
|
-
total_operations: bucketRows.value?.reduce((total, row) => total + row.total_operations, 0) ?? 0,
|
|
91
|
-
data_size: formatBytes(bucketRows.value?.reduce((total, row) => total + row.data_size, 0) ?? 0),
|
|
92
|
-
metadata_size: formatBytes(bucketRows.value?.reduce((total, row) => total + row.metadata_size, 0) ?? 0),
|
|
93
|
-
download_size: formatBytes(bucketRows.value?.reduce((total, row) => total + row.download_size, 0) ?? 0)
|
|
94
|
-
}));
|
|
95
|
-
const userID = computedAsync(async () => {
|
|
96
|
-
try {
|
|
97
|
-
const token = (await connector.value.fetchCredentials())?.token;
|
|
98
|
-
if (!token) return null;
|
|
99
|
-
const [_head, body, _signature] = token.split(".");
|
|
100
|
-
const payload = JSON.parse(atob(body ?? ""));
|
|
101
|
-
return payload.sub;
|
|
102
|
-
} catch {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
const totalDownloadProgress = computed(() => {
|
|
107
|
-
if (!hasSynced.value || isSyncing.value) {
|
|
108
|
-
return ((syncStatus.value?.downloadProgress?.downloadedFraction ?? 0) * 100).toFixed(1);
|
|
109
|
-
}
|
|
110
|
-
return "100";
|
|
111
|
-
});
|
|
112
|
-
const uploadQueueSize = computed(() => formatBytes(uploadQueueStats.value?.size ?? 0));
|
|
113
|
-
const uploadQueueCount = computed(() => uploadQueueStats.value?.count ?? 0);
|
|
114
|
-
const clearData = async () => {
|
|
115
|
-
await db.value?.disconnect();
|
|
116
|
-
const connector2 = db.value.connector;
|
|
117
|
-
const connectionOptions2 = db.value.connectionOptions;
|
|
118
|
-
await db.value?.disconnectAndClear();
|
|
119
|
-
const schemaManager = getCurrentSchemaManager();
|
|
120
|
-
await schemaManager.clear();
|
|
121
|
-
await schemaManager.refreshSchema(db.value.database);
|
|
122
|
-
await db.value.connect(connector2, connectionOptions2);
|
|
123
|
-
};
|
|
124
|
-
async function refreshState() {
|
|
125
|
-
if (db.value) {
|
|
126
|
-
const { status: rawStatus } = await db.value.get(
|
|
127
|
-
"SELECT powersync_offline_sync_status() as status"
|
|
128
|
-
);
|
|
129
|
-
const status = new SyncStatusSnapshot(JSON.parse(rawStatus), null);
|
|
130
|
-
const hasSyned = status.hasSynced;
|
|
131
|
-
uploadQueueStats.value = await db.value.getUploadQueueStats(true);
|
|
132
|
-
if (hasSyned && !syncStatus.value.downloading) {
|
|
133
|
-
bucketRows.value = await db.value.getAll(BUCKETS_QUERY);
|
|
134
|
-
tableRows.value = await db.value.getAll(TABLES_QUERY);
|
|
135
|
-
} else if (hasSyned) {
|
|
136
|
-
bucketRows.value = await db.value.getAll(BUCKETS_QUERY_FAST);
|
|
137
|
-
if (tableRows.value == null) {
|
|
138
|
-
tableRows.value = await db.value.getAll(TABLES_QUERY);
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
bucketRows.value = await db.value.getAll(BUCKETS_QUERY_FAST);
|
|
142
|
-
tableRows.value = null;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
onMounted(async () => {
|
|
147
|
-
if (!db.value) return;
|
|
148
|
-
const unregisterListener = db.value.registerListener({
|
|
149
|
-
statusChanged: (newStatus) => {
|
|
150
|
-
hasSynced.value = !!newStatus.hasSynced;
|
|
151
|
-
isConnected.value = !!newStatus.connected;
|
|
152
|
-
isDownloading.value = !!newStatus.downloading;
|
|
153
|
-
isUploading.value = !!newStatus.uploading;
|
|
154
|
-
lastSyncedAt.value = newStatus.lastSyncedAt || null;
|
|
155
|
-
uploadError.value = newStatus.uploadError || null;
|
|
156
|
-
downloadError.value = newStatus.downloadError || null;
|
|
157
|
-
downloadProgressDetails.value = newStatus.downloadProgress || null;
|
|
158
|
-
if (newStatus?.hasSynced === void 0 || newStatus?.priorityStatusEntries?.length && newStatus.priorityStatusEntries.length > 0) {
|
|
159
|
-
hasSynced.value = newStatus?.priorityStatusEntries.every((entry) => entry.hasSynced) ?? false;
|
|
160
|
-
}
|
|
161
|
-
if (newStatus?.downloading || newStatus?.uploading) {
|
|
162
|
-
isSyncing.value = true;
|
|
163
|
-
} else {
|
|
164
|
-
isSyncing.value = false;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
db.value.onChangeWithCallback(
|
|
169
|
-
{
|
|
170
|
-
async onChange(_event) {
|
|
171
|
-
await refreshState();
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
tables: ["ps_oplog", "ps_buckets", "ps_data_local__local_bucket_data", "ps_crud"],
|
|
176
|
-
throttleMs: 500
|
|
177
|
-
}
|
|
178
|
-
);
|
|
179
|
-
try {
|
|
180
|
-
await refreshState();
|
|
181
|
-
} catch (error) {
|
|
182
|
-
if (error.message === "no such table: local_bucket_data") {
|
|
183
|
-
isDiagnosticSchemaSetup.value = false;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
onUnmounted(() => {
|
|
187
|
-
unregisterListener();
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
return {
|
|
191
|
-
db,
|
|
192
|
-
connector,
|
|
193
|
-
connectionOptions,
|
|
194
|
-
isDiagnosticSchemaSetup: readonly(isDiagnosticSchemaSetup),
|
|
195
|
-
syncStatus: readonly(syncStatus),
|
|
196
|
-
hasSynced: readonly(hasSynced),
|
|
197
|
-
isConnected: readonly(isConnected),
|
|
198
|
-
isSyncing: readonly(isSyncing),
|
|
199
|
-
isDownloading: readonly(isDownloading),
|
|
200
|
-
isUploading: readonly(isUploading),
|
|
201
|
-
downloadError: readonly(downloadError),
|
|
202
|
-
uploadError: readonly(uploadError),
|
|
203
|
-
downloadProgressDetails: readonly(downloadProgressDetails),
|
|
204
|
-
lastSyncedAt: readonly(lastSyncedAt),
|
|
205
|
-
totalDownloadProgress: readonly(totalDownloadProgress),
|
|
206
|
-
uploadQueueStats: readonly(uploadQueueStats),
|
|
207
|
-
uploadQueueCount: readonly(uploadQueueCount),
|
|
208
|
-
uploadQueueSize: readonly(uploadQueueSize),
|
|
209
|
-
userID: readonly(userID),
|
|
210
|
-
bucketRows: readonly(bucketRows),
|
|
211
|
-
tableRows: readonly(tableRows),
|
|
212
|
-
totals: readonly(totals),
|
|
213
|
-
clearData,
|
|
214
|
-
formatBytes
|
|
215
|
-
};
|
|
216
|
-
}
|
|
@@ -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,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
|
-
}
|