@powersync/nuxt 0.0.0-dev-20260503073249 → 0.0.0-dev-20260504100448
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/dist/runtime/composables/usePowerSyncInspector.d.ts +0 -3
- package/dist/runtime/composables/usePowerSyncInspector.js +0 -2
- package/dist/runtime/utils/DynamicSchemaManager.d.ts +3 -2
- package/dist/runtime/utils/DynamicSchemaManager.js +26 -28
- package/dist/runtime/utils/NuxtPowerSyncDatabase.js +1 -9
- package/dist/runtime/utils/RustClientInterceptor.d.ts +3 -3
- package/dist/runtime/utils/RustClientInterceptor.js +15 -27
- package/package.json +7 -6
- package/dist/runtime/utils/RecordingStorageAdapter.d.ts +0 -13
- package/dist/runtime/utils/RecordingStorageAdapter.js +0 -58
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RecordingStorageAdapter } from '../utils/RecordingStorageAdapter.js';
|
|
2
1
|
import { DynamicSchemaManager } from '../utils/DynamicSchemaManager.js';
|
|
3
2
|
declare function getCurrentSchemaManager(): DynamicSchemaManager;
|
|
4
3
|
/**
|
|
@@ -9,7 +8,6 @@ declare function getCurrentSchemaManager(): DynamicSchemaManager;
|
|
|
9
8
|
*
|
|
10
9
|
* @returns An object containing:
|
|
11
10
|
* - `diagnosticsSchema` - The schema for diagnostics data collection. Use this to extend your app schema with diagnostic tables.
|
|
12
|
-
* - `RecordingStorageAdapter` - Used internally. Storage adapter class that records operations for diagnostic purposes.
|
|
13
11
|
* - `getCurrentSchemaManager()` - Used internally. Gets the current schema manager instance for dynamic schema operations.
|
|
14
12
|
*
|
|
15
13
|
* @example
|
|
@@ -36,7 +34,6 @@ export declare function usePowerSyncInspector(): {
|
|
|
36
34
|
data: import("@powersync/common").BaseColumnType<string | null>;
|
|
37
35
|
}>;
|
|
38
36
|
}>;
|
|
39
|
-
RecordingStorageAdapter: typeof RecordingStorageAdapter;
|
|
40
37
|
getCurrentSchemaManager: typeof getCurrentSchemaManager;
|
|
41
38
|
};
|
|
42
39
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DiagnosticsAppSchema } from "../utils/AppSchema.js";
|
|
2
|
-
import { RecordingStorageAdapter } from "../utils/RecordingStorageAdapter.js";
|
|
3
2
|
import { DynamicSchemaManager } from "../utils/DynamicSchemaManager.js";
|
|
4
3
|
let currentSchemaManager = null;
|
|
5
4
|
function getCurrentSchemaManager() {
|
|
@@ -13,7 +12,6 @@ export function usePowerSyncInspector() {
|
|
|
13
12
|
const diagnosticsSchema = DiagnosticsAppSchema;
|
|
14
13
|
return {
|
|
15
14
|
diagnosticsSchema,
|
|
16
|
-
RecordingStorageAdapter,
|
|
17
15
|
getCurrentSchemaManager
|
|
18
16
|
};
|
|
19
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { DBAdapter
|
|
1
|
+
import type { DBAdapter } from '@powersync/web';
|
|
2
2
|
import { Schema } from '@powersync/web';
|
|
3
|
+
import type { SyncDataBucketJSON } from '@powersync/common/internal/sync_protocol';
|
|
3
4
|
/**
|
|
4
5
|
* Record fields from downloaded data, then build a schema from it.
|
|
5
6
|
*/
|
|
@@ -8,7 +9,7 @@ export declare class DynamicSchemaManager {
|
|
|
8
9
|
private dirty;
|
|
9
10
|
constructor();
|
|
10
11
|
clear(): Promise<void>;
|
|
11
|
-
updateFromOperations(batch:
|
|
12
|
+
updateFromOperations(batch: SyncDataBucketJSON): Promise<void>;
|
|
12
13
|
refreshSchema(db: DBAdapter): Promise<void>;
|
|
13
14
|
buildSchema(): Schema;
|
|
14
15
|
schemaToString(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Column, ColumnType,
|
|
1
|
+
import { Column, ColumnType, Schema, Table } from "@powersync/web";
|
|
2
2
|
import { DiagnosticsAppSchema as AppSchema } from "./AppSchema.js";
|
|
3
3
|
import { JsSchemaGenerator } from "./JsSchemaGenerator.js";
|
|
4
4
|
export class DynamicSchemaManager {
|
|
@@ -15,34 +15,32 @@ export class DynamicSchemaManager {
|
|
|
15
15
|
}
|
|
16
16
|
async updateFromOperations(batch) {
|
|
17
17
|
let schemaDirty = false;
|
|
18
|
-
for (const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
schemaDirty = true;
|
|
43
|
-
}
|
|
44
|
-
table[key] = ColumnType.TEXT;
|
|
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;
|
|
45
42
|
}
|
|
43
|
+
table[key] = ColumnType.TEXT;
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
DEFAULT_SYNC_CLIENT_IMPLEMENTATION,
|
|
3
2
|
PowerSyncDatabase,
|
|
4
3
|
Schema,
|
|
5
4
|
SharedWebStreamingSyncImplementation,
|
|
6
|
-
SyncClientImplementation,
|
|
7
5
|
WebRemote,
|
|
8
6
|
WebStreamingSyncImplementation
|
|
9
7
|
} from "@powersync/web";
|
|
10
|
-
import { RecordingStorageAdapter } from "./RecordingStorageAdapter.js";
|
|
11
8
|
import { usePowerSyncInspector } from "../composables/usePowerSyncInspector.js";
|
|
12
9
|
import { useDiagnosticsLogger } from "../composables/useDiagnosticsLogger.js";
|
|
13
10
|
import { shallowRef } from "vue";
|
|
@@ -54,12 +51,7 @@ export class NuxtPowerSyncDatabase extends PowerSyncDatabase {
|
|
|
54
51
|
const { getCurrentSchemaManager } = usePowerSyncInspector();
|
|
55
52
|
const currentSchemaManager = getCurrentSchemaManager();
|
|
56
53
|
const schemaManager = currentSchemaManager || this.schemaManager;
|
|
57
|
-
const
|
|
58
|
-
const adapter = clientImplementation === SyncClientImplementation.RUST ? new RustClientInterceptor(
|
|
59
|
-
shallowRef(this),
|
|
60
|
-
new WebRemote(connector, logger),
|
|
61
|
-
shallowRef(schemaManager)
|
|
62
|
-
) : new RecordingStorageAdapter(
|
|
54
|
+
const adapter = new RustClientInterceptor(
|
|
63
55
|
shallowRef(this),
|
|
64
56
|
shallowRef(schemaManager)
|
|
65
57
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ColumnType, PowerSyncDatabase } from '@powersync/web';
|
|
2
2
|
import { PowerSyncControlCommand, SqliteBucketStorage } from '@powersync/web';
|
|
3
3
|
import type { DynamicSchemaManager } from './DynamicSchemaManager.js';
|
|
4
4
|
import type { ShallowRef } from 'vue';
|
|
@@ -10,12 +10,12 @@ import type { ShallowRef } from 'vue';
|
|
|
10
10
|
* `powersync_control` calls to decode sync lines and derive progress information.
|
|
11
11
|
*/
|
|
12
12
|
export declare class RustClientInterceptor extends SqliteBucketStorage {
|
|
13
|
-
private remote;
|
|
14
13
|
private schemaManager;
|
|
14
|
+
private bson?;
|
|
15
15
|
private rdb;
|
|
16
16
|
private lastStartedCheckpoint;
|
|
17
17
|
tables: Record<string, Record<string, ColumnType>>;
|
|
18
|
-
constructor(db: ShallowRef<PowerSyncDatabase>,
|
|
18
|
+
constructor(db: ShallowRef<PowerSyncDatabase>, schemaManager: ShallowRef<DynamicSchemaManager>);
|
|
19
19
|
control(op: PowerSyncControlCommand, payload: string | Uint8Array | ArrayBuffer | null): Promise<string>;
|
|
20
20
|
private processTextLine;
|
|
21
21
|
private processBinaryLine;
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AbstractPowerSyncDatabase,
|
|
3
|
-
isStreamingSyncCheckpoint,
|
|
4
|
-
isStreamingSyncCheckpointComplete,
|
|
5
|
-
isStreamingSyncCheckpointDiff,
|
|
6
|
-
isStreamingSyncCheckpointPartiallyComplete,
|
|
7
|
-
isStreamingSyncData,
|
|
8
|
-
PowerSyncControlCommand,
|
|
9
|
-
SqliteBucketStorage,
|
|
10
|
-
SyncDataBucket
|
|
11
|
-
} from "@powersync/web";
|
|
1
|
+
import { AbstractPowerSyncDatabase, PowerSyncControlCommand, SqliteBucketStorage } from "@powersync/web";
|
|
12
2
|
export class RustClientInterceptor extends SqliteBucketStorage {
|
|
13
|
-
constructor(db,
|
|
3
|
+
constructor(db, schemaManager) {
|
|
14
4
|
super(db.value.database, AbstractPowerSyncDatabase.transactionMutex);
|
|
15
|
-
this.remote = remote;
|
|
16
5
|
this.schemaManager = schemaManager;
|
|
17
6
|
this.rdb = db.value.database;
|
|
18
7
|
}
|
|
8
|
+
bson;
|
|
19
9
|
rdb;
|
|
20
10
|
lastStartedCheckpoint = null;
|
|
21
11
|
tables = {};
|
|
@@ -32,14 +22,14 @@ export class RustClientInterceptor extends SqliteBucketStorage {
|
|
|
32
22
|
return this.processParsedLine(JSON.parse(line));
|
|
33
23
|
}
|
|
34
24
|
async processBinaryLine(line) {
|
|
35
|
-
const bson = await
|
|
25
|
+
const bson = this.bson ??= await import("bson");
|
|
36
26
|
await this.processParsedLine(bson.deserialize(line));
|
|
37
27
|
}
|
|
38
28
|
async processParsedLine(line) {
|
|
39
|
-
if (
|
|
29
|
+
if ("checkpoint" in line) {
|
|
40
30
|
this.lastStartedCheckpoint = line.checkpoint;
|
|
41
31
|
await this.trackCheckpoint(line.checkpoint);
|
|
42
|
-
} else if (
|
|
32
|
+
} else if ("checkpoint_diff" in line && this.lastStartedCheckpoint) {
|
|
43
33
|
const diff = line.checkpoint_diff;
|
|
44
34
|
const newBuckets = /* @__PURE__ */ new Map();
|
|
45
35
|
for (const checksum of this.lastStartedCheckpoint.buckets) {
|
|
@@ -58,24 +48,22 @@ export class RustClientInterceptor extends SqliteBucketStorage {
|
|
|
58
48
|
};
|
|
59
49
|
this.lastStartedCheckpoint = newCheckpoint;
|
|
60
50
|
await this.trackCheckpoint(newCheckpoint);
|
|
61
|
-
} else if (
|
|
62
|
-
const
|
|
51
|
+
} else if ("data" in line) {
|
|
52
|
+
const bucket = line.data;
|
|
63
53
|
await this.rdb.writeTransaction(async (tx) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
`UPDATE local_bucket_data SET
|
|
54
|
+
const size = JSON.stringify(bucket.data).length;
|
|
55
|
+
await tx.execute(
|
|
56
|
+
`UPDATE local_bucket_data SET
|
|
68
57
|
download_size = IFNULL(download_size, 0) + ?,
|
|
69
58
|
last_op = ?,
|
|
70
59
|
downloading = ?,
|
|
71
60
|
downloaded_operations = IFNULL(downloaded_operations, 0) + ?
|
|
72
61
|
WHERE id = ?`,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
62
|
+
[size, bucket.next_after, bucket.has_more, bucket.data.length, bucket.bucket]
|
|
63
|
+
);
|
|
76
64
|
});
|
|
77
|
-
await this.schemaManager.value.updateFromOperations(
|
|
78
|
-
} else if (
|
|
65
|
+
await this.schemaManager.value.updateFromOperations(bucket);
|
|
66
|
+
} else if ("partial_checkpoint_complete" in line || "checkpoint_complete" in line) {
|
|
79
67
|
setTimeout(() => {
|
|
80
68
|
this.schemaManager.value.refreshSchema(this.rdb);
|
|
81
69
|
}, 60);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/nuxt",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20260504100448",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -48,13 +48,14 @@
|
|
|
48
48
|
"reka-ui": "^2.9.1",
|
|
49
49
|
"shiki": "^3.23.0",
|
|
50
50
|
"unocss": "^66.6.6",
|
|
51
|
-
"unstorage": "^1.17.4"
|
|
51
|
+
"unstorage": "^1.17.4",
|
|
52
|
+
"bson": "^6.10.4"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
55
|
"@journeyapps/wa-sqlite": "^1.7.0",
|
|
55
56
|
"@powersync/kysely-driver": "1.3.3",
|
|
56
57
|
"@powersync/vue": "0.5.1",
|
|
57
|
-
"@powersync/web": "0.0.0-dev-
|
|
58
|
+
"@powersync/web": "0.0.0-dev-20260504100448"
|
|
58
59
|
},
|
|
59
60
|
"peerDependenciesMeta": {
|
|
60
61
|
"@powersync/kysely-driver": {
|
|
@@ -66,15 +67,15 @@
|
|
|
66
67
|
"@nuxt/module-builder": "^1.0.2",
|
|
67
68
|
"@nuxt/schema": "^4.3.1",
|
|
68
69
|
"@nuxt/test-utils": "^4.0.0",
|
|
69
|
-
"bson": "^6.10.4",
|
|
70
70
|
"comlink": "^4.4.2",
|
|
71
71
|
"nuxt": "^4.3.1",
|
|
72
72
|
"vitest": "^3.2.4",
|
|
73
73
|
"vue": "^3.5.30",
|
|
74
74
|
"vue-tsc": "^3.2.5",
|
|
75
|
-
"@powersync/vue": "0.5.1",
|
|
76
75
|
"@powersync/kysely-driver": "1.3.3",
|
|
77
|
-
"@powersync/
|
|
76
|
+
"@powersync/vue": "0.5.1",
|
|
77
|
+
"@powersync/web": "0.0.0-dev-20260504100448",
|
|
78
|
+
"@powersync/common": "0.0.0-dev-20260504100448"
|
|
78
79
|
},
|
|
79
80
|
"scripts": {
|
|
80
81
|
"prebuild": "nuxt-module-build prepare",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Checkpoint, ColumnType, PowerSyncDatabase, SyncDataBatch } from '@powersync/web';
|
|
2
|
-
import { SqliteBucketStorage } from '@powersync/web';
|
|
3
|
-
import type { DynamicSchemaManager } from './DynamicSchemaManager.js';
|
|
4
|
-
import type { ShallowRef } from 'vue';
|
|
5
|
-
export declare class RecordingStorageAdapter extends SqliteBucketStorage {
|
|
6
|
-
private rdb;
|
|
7
|
-
private schemaManager;
|
|
8
|
-
tables: Record<string, Record<string, ColumnType>>;
|
|
9
|
-
constructor(db: ShallowRef<PowerSyncDatabase>, schemaManager: ShallowRef<DynamicSchemaManager>);
|
|
10
|
-
setTargetCheckpoint(checkpoint: Checkpoint): Promise<void>;
|
|
11
|
-
syncLocalDatabase(checkpoint: Checkpoint, priority?: number): Promise<import("@powersync/common").SyncLocalDatabaseResult>;
|
|
12
|
-
saveSyncData(batch: SyncDataBatch): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { AbstractPowerSyncDatabase, SqliteBucketStorage } from "@powersync/web";
|
|
2
|
-
export class RecordingStorageAdapter extends SqliteBucketStorage {
|
|
3
|
-
rdb;
|
|
4
|
-
schemaManager;
|
|
5
|
-
tables = {};
|
|
6
|
-
constructor(db, schemaManager) {
|
|
7
|
-
super(db.value.database, AbstractPowerSyncDatabase.transactionMutex);
|
|
8
|
-
this.rdb = db.value.database;
|
|
9
|
-
this.schemaManager = schemaManager.value;
|
|
10
|
-
}
|
|
11
|
-
async setTargetCheckpoint(checkpoint) {
|
|
12
|
-
await super.setTargetCheckpoint(checkpoint);
|
|
13
|
-
await this.rdb.writeTransaction(async (tx) => {
|
|
14
|
-
for (const bucket of checkpoint.buckets) {
|
|
15
|
-
await tx.execute(
|
|
16
|
-
`INSERT OR REPLACE INTO local_bucket_data(id, total_operations, last_op, download_size, downloading, downloaded_operations)
|
|
17
|
-
VALUES (
|
|
18
|
-
?,
|
|
19
|
-
?,
|
|
20
|
-
IFNULL((SELECT last_op FROM local_bucket_data WHERE id = ?), '0'),
|
|
21
|
-
IFNULL((SELECT download_size FROM local_bucket_data WHERE id = ?), 0),
|
|
22
|
-
IFNULL((SELECT downloading FROM local_bucket_data WHERE id = ?), TRUE),
|
|
23
|
-
IFNULL((SELECT downloaded_operations FROM local_bucket_data WHERE id = ?), TRUE)
|
|
24
|
-
)`,
|
|
25
|
-
[bucket.bucket, bucket.count, bucket.bucket, bucket.bucket, bucket.bucket, bucket.bucket]
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async syncLocalDatabase(checkpoint, priority) {
|
|
31
|
-
const r = await super.syncLocalDatabase(checkpoint, priority);
|
|
32
|
-
setTimeout(() => {
|
|
33
|
-
this.schemaManager.refreshSchema(this.rdb);
|
|
34
|
-
}, 60);
|
|
35
|
-
if (r.checkpointValid) {
|
|
36
|
-
await this.rdb.execute("UPDATE local_bucket_data SET downloading = FALSE");
|
|
37
|
-
}
|
|
38
|
-
return r;
|
|
39
|
-
}
|
|
40
|
-
async saveSyncData(batch) {
|
|
41
|
-
await super.saveSyncData(batch);
|
|
42
|
-
await this.rdb.writeTransaction(async (tx) => {
|
|
43
|
-
for (const bucket of batch.buckets) {
|
|
44
|
-
const size = JSON.stringify(bucket.data).length;
|
|
45
|
-
await tx.execute(
|
|
46
|
-
`UPDATE local_bucket_data SET
|
|
47
|
-
download_size = IFNULL(download_size, 0) + ?,
|
|
48
|
-
last_op = ?,
|
|
49
|
-
downloading = ?,
|
|
50
|
-
downloaded_operations = IFNULL(downloaded_operations, 0) + ?
|
|
51
|
-
WHERE id = ?`,
|
|
52
|
-
[size, bucket.next_after, bucket.has_more, bucket.data.length, bucket.bucket]
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
await this.schemaManager.updateFromOperations(batch);
|
|
57
|
-
}
|
|
58
|
-
}
|