Skip to content

Commit f6c9a50

Browse files
Merge branch 'main' into capacitor-ios-stream
2 parents 0997ba6 + f39badb commit f6c9a50

49 files changed

Lines changed: 478 additions & 2845 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/cuddly-bobcats-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/common': patch
3+
---
4+
5+
Fix warnings about leaked subscriptions even though `unsubscribe()` was called.

.changeset/hungry-cycles-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/common': patch
3+
---
4+
5+
Make `js-logger` a regular dependency to avoid type issues.

.changeset/strange-items-fly.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@powersync/react-native': minor
3+
'@powersync/common': minor
4+
'@powersync/web': minor
5+
'@powersync/diagnostics-app': patch
6+
'@powersync/node': patch
7+
'@powersync/nuxt': patch
8+
---
9+
10+
Remove support for the JavaScript sync client. The default Rust client is the only option starting from this version.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// TypeScript definitions for sync lines sent by the PowerSync service. These aren't used in the implementation of
2+
// PowerSync SDKs, but we keep them around for:
3+
//
4+
// 1. Tests mocking the PowerSync service.
5+
// 2. The diagnostic app tracking schema updates and bucket sizes by decoding protocol messages.
6+
// 3. The nuxt SDK offering DevTools doing the same.
7+
//
8+
// Uses 2 and 3 should be replaced with the builtin diagnostic collection of the core extension eventually.
9+
10+
export type SyncDataBucketJSON = {
11+
bucket: string;
12+
has_more?: boolean;
13+
after?: string;
14+
next_after?: string;
15+
data: OplogEntryJSON[];
16+
};
17+
export interface OplogEntryJSON {
18+
checksum: number;
19+
data?: string;
20+
object_id?: string;
21+
object_type?: string;
22+
op_id: string;
23+
op: OpTypeJSON;
24+
subkey?: string;
25+
}
26+
export type OpTypeJSON = 'CLEAR' | 'MOVE' | 'PUT' | 'REMOVE';
27+
28+
/**
29+
* 64-bit unsigned integer stored as a string in base-10.
30+
*
31+
* Not sortable as a string.
32+
*/
33+
export type OpId = string;
34+
35+
export interface BucketChecksum {
36+
bucket: string;
37+
priority?: number;
38+
/**
39+
* 32-bit unsigned hash.
40+
*/
41+
checksum: number;
42+
43+
/**
44+
* Count of operations - informational only.
45+
*/
46+
count?: number;
47+
/**
48+
* The JavaScript client does not use this field, which is why it's defined to be `any`. We rely on the structure of
49+
* this interface to pass custom `BucketChecksum`s to the Rust client in unit tests, which so all fields need to be
50+
* present.
51+
*/
52+
subscriptions?: any;
53+
}
54+
55+
export interface Checkpoint {
56+
last_op_id: OpId;
57+
buckets: BucketChecksum[];
58+
write_checkpoint?: string;
59+
streams?: any[];
60+
}
61+
62+
export interface StreamingSyncCheckpoint {
63+
checkpoint: Checkpoint;
64+
}
65+
66+
export interface StreamingSyncCheckpointDiff {
67+
checkpoint_diff: {
68+
last_op_id: OpId;
69+
updated_buckets: BucketChecksum[];
70+
removed_buckets: string[];
71+
write_checkpoint?: string;
72+
};
73+
}
74+
75+
export interface StreamingSyncDataJSON {
76+
data: SyncDataBucketJSON;
77+
}
78+
79+
export interface StreamingSyncCheckpointComplete {
80+
checkpoint_complete: {
81+
last_op_id: OpId;
82+
};
83+
}
84+
85+
export interface StreamingSyncCheckpointPartiallyComplete {
86+
partial_checkpoint_complete: {
87+
priority: number;
88+
last_op_id: OpId;
89+
};
90+
}
91+
92+
export interface StreamingSyncKeepalive {
93+
/** If specified, token expires in this many seconds. */
94+
token_expires_in: number;
95+
}
96+
97+
export type StreamingSyncLine =
98+
| StreamingSyncDataJSON
99+
| StreamingSyncCheckpoint
100+
| StreamingSyncCheckpointDiff
101+
| StreamingSyncCheckpointComplete
102+
| StreamingSyncCheckpointPartiallyComplete
103+
| StreamingSyncKeepalive;

packages/common/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@
3030
"types": "./dist/index.d.cts",
3131
"require": "./dist/bundle.cjs"
3232
}
33+
},
34+
"./internal/sync_protocol": {
35+
"types": "./legacy/sync_protocol.d.ts"
3336
}
3437
},
3538
"author": "PowerSync",
3639
"license": "Apache-2.0",
3740
"files": [
3841
"lib",
3942
"dist",
40-
"src"
43+
"src",
44+
"legacy"
4145
],
4246
"repository": {
4347
"type": "git",
@@ -52,10 +56,11 @@
5256
"build:prod": "tsc -b && rollup -c rollup.config.mjs",
5357
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
5458
"test": "vitest",
55-
"test:exports": "attw --pack ."
59+
"test:exports": "attw --pack . --exclude-entrypoints internal/sync_protocol"
5660
},
5761
"dependencies": {
58-
"event-iterator": "^2.0.0"
62+
"event-iterator": "^2.0.0",
63+
"js-logger": "catalog:"
5964
},
6065
"devDependencies": {
6166
"@rollup/plugin-commonjs": "catalog:",
@@ -64,11 +69,9 @@
6469
"@rollup/plugin-node-resolve": "catalog:",
6570
"@types/node": "catalog:",
6671
"@types/uuid": "catalog:",
67-
"bson": "catalog:",
6872
"buffer": "^6.0.3",
6973
"cross-fetch": "^4.1.0",
7074
"estree-walker": "^3.0.3",
71-
"js-logger": "catalog:",
7275
"magic-string": "^0.30.21",
7376
"rollup": "catalog:",
7477
"rollup-plugin-dts": "catalog:",

packages/common/rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function defineBuild(isNode) {
3737
}
3838
],
3939
plugins,
40-
external: ['bson', isNode ? 'event-iterator' : undefined]
40+
external: [isNode ? 'event-iterator' : undefined]
4141
};
4242
}
4343

packages/common/src/client/ConnectionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class SyncStreamSubscriptionHandle implements SyncStreamSubscription {
368368

369369
constructor(readonly subscription: ActiveSubscription) {
370370
subscription.refcount++;
371-
_finalizer?.register(this, subscription);
371+
_finalizer?.register(this, subscription, this);
372372
}
373373

374374
get name() {

packages/common/src/client/sync/bucket/BucketStorageAdapter.ts

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,6 @@
11
import { BaseListener, BaseObserverInterface, Disposable } from '../../../utils/BaseObserver.js';
22
import { CrudBatch } from './CrudBatch.js';
3-
import { CrudEntry, OpId } from './CrudEntry.js';
4-
import { SyncDataBatch } from './SyncDataBatch.js';
5-
6-
export interface BucketDescription {
7-
name: string;
8-
priority: number;
9-
}
10-
11-
export interface Checkpoint {
12-
last_op_id: OpId;
13-
buckets: BucketChecksum[];
14-
write_checkpoint?: string;
15-
streams?: any[];
16-
}
17-
18-
export interface BucketState {
19-
bucket: string;
20-
op_id: string;
21-
}
22-
23-
export interface ChecksumCache {
24-
checksums: Map<string, { checksum: BucketChecksum; last_op_id: OpId }>;
25-
lastOpId: OpId;
26-
}
27-
28-
export interface SyncLocalDatabaseResult {
29-
ready: boolean;
30-
checkpointValid: boolean;
31-
checkpointFailures?: string[];
32-
}
33-
34-
export type SavedProgress = {
35-
atLast: number;
36-
sinceLast: number;
37-
};
38-
39-
export type BucketOperationProgress = Record<string, SavedProgress>;
40-
41-
export interface BucketChecksum {
42-
bucket: string;
43-
priority?: number;
44-
/**
45-
* 32-bit unsigned hash.
46-
*/
47-
checksum: number;
48-
49-
/**
50-
* Count of operations - informational only.
51-
*/
52-
count?: number;
53-
/**
54-
* The JavaScript client does not use this field, which is why it's defined to be `any`. We rely on the structure of
55-
* this interface to pass custom `BucketChecksum`s to the Rust client in unit tests, which so all fields need to be
56-
* present.
57-
*/
58-
subscriptions?: any;
59-
}
3+
import { CrudEntry } from './CrudEntry.js';
604

615
export enum PSInternalTable {
626
DATA = 'ps_data',
@@ -82,27 +26,14 @@ export interface BucketStorageListener extends BaseListener {
8226

8327
export interface BucketStorageAdapter extends BaseObserverInterface<BucketStorageListener>, Disposable {
8428
init(): Promise<void>;
85-
saveSyncData(batch: SyncDataBatch, fixedKeyFormat?: boolean): Promise<void>;
86-
removeBuckets(buckets: string[]): Promise<void>;
87-
setTargetCheckpoint(checkpoint: Checkpoint): Promise<void>;
8829

89-
startSession(): void;
90-
91-
getBucketStates(): Promise<BucketState[]>;
92-
getBucketOperationProgress(): Promise<BucketOperationProgress>;
9330
hasMigratedSubkeys(): Promise<boolean>;
9431
migrateToFixedSubkeys(): Promise<void>;
9532

96-
syncLocalDatabase(
97-
checkpoint: Checkpoint,
98-
priority?: number
99-
): Promise<{ checkpointValid: boolean; ready: boolean; failures?: any[] }>;
100-
10133
nextCrudItem(): Promise<CrudEntry | undefined>;
10234
hasCrud(): Promise<boolean>;
10335
getCrudBatch(limit?: number): Promise<CrudBatch | null>;
10436

105-
hasCompletedSync(): Promise<boolean>;
10637
updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
10738
getMaxOpId(): string;
10839

packages/common/src/client/sync/bucket/OpType.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/common/src/client/sync/bucket/OplogEntry.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)