Skip to content

Commit 8f3461d

Browse files
authored
Merge pull request #160 from powersync-ja/remove-uuid-dependency
Remove uuid and react-native-get-random-values dependencies
2 parents 038e42a + 395ea24 commit 8f3461d

File tree

24 files changed

+50
-143
lines changed

24 files changed

+50
-143
lines changed

.changeset/heavy-dancers-drum.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@powersync/common': patch
3+
'@powersync/web': patch
4+
---
5+
6+
Remove uuid dependency

.changeset/proud-falcons-lay.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/react-native': patch
3+
---
4+
5+
Remove react-native-get-random-values dependency

demos/angular-supabase-todolist/angular.json

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"object-hash",
2525
"event-iterator",
2626
"can-ndjson-stream",
27-
"uuid",
2827
"lodash",
2928
"js-logger",
3029
"websocket"

demos/django-react-native-todolist/library/stores/AbstractStore.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Needed to import early for uuids
2-
import 'react-native-get-random-values';
31
import _ from 'lodash';
42
import { action, makeObservable, observable } from 'mobx';
53
import { AbstractModel } from '../models/AbstractModel';

demos/django-react-native-todolist/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"@react-navigation/drawer": "^6.6.15",
2020
"@react-navigation/native": "^6.1.17",
2121
"@supabase/supabase-js": "^2.42.4",
22-
"@types/react-native-get-random-values": "^1.8.2",
2322
"base-64": "^1.0.0",
2423
"expo": "~50.0.15",
2524
"expo-constants": "~15.4.5",
@@ -39,7 +38,6 @@
3938
"react-native-encrypted-storage": "^4.0.3",
4039
"react-native-fetch-api": "^3.0.0",
4140
"react-native-gesture-handler": "~2.14.1",
42-
"react-native-get-random-values": "~1.8.0",
4341
"react-native-polyfill-globals": "^3.1.0",
4442
"react-native-prompt-android": "^1.1.0",
4543
"react-native-reanimated": "~3.6.3",
@@ -52,7 +50,6 @@
5250
"react-navigation-stack": "^2.10.4",
5351
"text-encoding": "^0.7.0",
5452
"typed-async-storage": "^3.1.2",
55-
"uuid": "^9.0.1",
5653
"web-streams-polyfill": "^3.3.3"
5754
},
5855
"devDependencies": {

demos/example-electron/vite.renderer.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default defineConfig((env) => {
2626
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
2727
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
2828
include: [
29-
'@powersync/web > uuid',
3029
'@powersync/web > event-iterator',
3130
'@powersync/web > js-logger',
3231
'@powersync/web > lodash/throttle',

demos/example-nextjs/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@
3333
"react-dom": "^18.2.0",
3434
"remixicon": "^2.5.0",
3535
"shiki": "^0.10.1",
36-
"simplify-js": "^1.2.4",
37-
"uuid": "9.0.1"
36+
"simplify-js": "^1.2.4"
3837
},
3938
"devDependencies": {
4039
"@types/lodash": "^4.14.202",
4140
"@types/node": "^20.11.25",
4241
"@types/react": "^18.2.64",
4342
"@types/react-dom": "^18.2.21",
44-
"@types/uuid": "9.0.8",
4543
"autoprefixer": "^10.4.18",
4644
"babel-loader": "^9.1.3",
4745
"css-loader": "^6.10.0",

demos/example-vite/vite.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export default defineConfig({
1919
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
2020
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
2121
include: [
22-
'@powersync/web > uuid',
2322
'@powersync/web > event-iterator',
2423
'@powersync/web > js-logger',
2524
'@powersync/web > lodash/throttle',

demos/react-native-supabase-group-chat/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"react-native": "0.73.4",
5050
"react-native-fetch-api": "^3.0.0",
5151
"react-native-gesture-handler": "~2.14.1",
52-
"react-native-get-random-values": "~1.8.0",
5352
"react-native-pager-view": "6.2.3",
5453
"react-native-polyfill-globals": "^3.1.0",
5554
"react-native-reanimated": "~3.6.2",

demos/react-native-supabase-todolist/library/powersync/PhotoAttachmentQueue.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as FileSystem from 'expo-file-system';
2-
import { v4 as uuid } from 'uuid';
2+
import { randomUUID } from 'expo-crypto';
33
import { AppConfig } from '../supabase/AppConfig';
44
import { AbstractAttachmentQueue, AttachmentRecord, AttachmentState } from '@powersync/attachments';
55
import { TODO_TABLE } from './AppSchema';
@@ -23,7 +23,7 @@ export class PhotoAttachmentQueue extends AbstractAttachmentQueue {
2323
}
2424

2525
async newAttachmentRecord(record?: Partial<AttachmentRecord>): Promise<AttachmentRecord> {
26-
const photoId = record?.id ?? uuid();
26+
const photoId = record?.id ?? randomUUID();
2727
const filename = record?.filename ?? `${photoId}.jpg`;
2828
return {
2929
id: photoId,

demos/react-native-supabase-todolist/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"expo-build-properties": "~0.11.0",
2727
"expo-camera": "~14.0.3",
2828
"expo-constants": "~15.4.5",
29+
"expo-crypto": "~12.8.0",
2930
"expo-file-system": "^16.0.5",
3031
"expo-linking": "~6.2.2",
3132
"expo-modules-autolinking": "^1.5.1",
@@ -43,7 +44,6 @@
4344
"react-native-encrypted-storage": "^4.0.3",
4445
"react-native-fetch-api": "^3.0.0",
4546
"react-native-gesture-handler": "~2.14.1",
46-
"react-native-get-random-values": "~1.10.0",
4747
"react-native-polyfill-globals": "^3.1.0",
4848
"react-native-prompt-android": "^1.1.0",
4949
"react-native-reanimated": "~3.6.2",
@@ -55,7 +55,6 @@
5555
"react-native-vector-icons": "^10.0.0",
5656
"react-navigation-stack": "^2.10.4",
5757
"text-encoding": "^0.7.0",
58-
"uuid": "^9.0.1",
5958
"web-streams-polyfill": "^3.3.2"
6059
},
6160
"devDependencies": {
@@ -65,7 +64,6 @@
6564
"@types/base-64": "^1.0.2",
6665
"@types/lodash": "^4.14.202",
6766
"@types/react": "~18.2.57",
68-
"@types/uuid": "^9.0.1",
6967
"babel-preset-expo": "^10.0.1",
7068
"prettier": "^3.2.5",
7169
"typescript": "^5.3.3"

demos/react-supabase-todolist/vite.config.mts

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default defineConfig({
2626
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
2727
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
2828
include: [
29-
'@powersync/web > uuid',
3029
'@powersync/web > event-iterator',
3130
'@powersync/web > js-logger',
3231
'@powersync/web > lodash/throttle',

demos/vue-supabase-todolist/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"@vuelidate/core": "^2.0.3",
1818
"@vuelidate/validators": "^2.0.4",
1919
"js-logger": "^1.6.1",
20-
"uuid": "^9.0.1",
2120
"vue": "^3.4.21",
2221
"vue-router": "4",
2322
"vuetify": "^3.5.7"

demos/vue-supabase-todolist/vite.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export default defineConfig({
7979
// https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673
8080
exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
8181
include: [
82-
'@powersync/web > uuid',
8382
'@powersync/web > event-iterator',
8483
'@powersync/web > js-logger',
8584
'@powersync/web > lodash/throttle',

demos/yjs-react-supabase-text-collab/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"remixicon": "^2.5.0",
4545
"shiki": "^0.10.1",
4646
"simplify-js": "^1.2.4",
47-
"uuid": "9.0.1",
47+
"uuid": "^9.0.1",
4848
"y-prosemirror": "1.0.20",
4949
"y-protocols": "1.0.6",
5050
"yjs": "^13.6.14"

packages/common/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
"can-ndjson-stream": "^1.0.2",
3232
"event-iterator": "^2.0.0",
3333
"js-logger": "^1.6.1",
34-
"lodash": "^4.17.21",
35-
"uuid": "^9.0.1"
34+
"lodash": "^4.17.21"
3635
},
3736
"devDependencies": {
3837
"@types/lodash": "^4.14.197",

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { v4 as uuid } from 'uuid';
21
import { Mutex } from 'async-mutex';
32
import { DBAdapter, Transaction, extractTableUpdates } from '../../../db/DBAdapter';
43
import {
@@ -108,10 +107,10 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
108107
// To achieve this, we rename the bucket to a new temp name, and change all ops to remove.
109108
// By itself, this new bucket would ensure that the previous objects are deleted if they contain no more references.
110109
// If the old bucket is re-added, this new bucket would have no effect.
111-
const newName = `$delete_${bucket}_${uuid()}`;
112-
this.logger.debug('Deleting bucket', bucket);
113-
// This
114110
await this.writeTransaction(async (tx) => {
111+
const { uuid } = await tx.get<{ uuid: string }>('select uuid() as uuid');
112+
const newName = `$delete_${bucket}_${uuid}`;
113+
this.logger.debug('Deleting bucket', bucket);
115114
await tx.execute(
116115
`UPDATE ps_oplog SET op=${OpTypeEnum.REMOVE}, data=NULL WHERE op=${OpTypeEnum.PUT} AND superseded=0 AND bucket=?`,
117116
[bucket]
+6-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { v4 } from 'uuid';
2-
31
export interface Disposable {
42
dispose: () => Promise<void>;
53
}
@@ -13,26 +11,23 @@ export type BaseListener = {
1311
};
1412

1513
export class BaseObserver<T extends BaseListener = BaseListener> implements BaseObserverInterface<T> {
16-
protected listeners: { [id: string]: Partial<T> };
14+
protected listeners = new Set<Partial<T>>();
1715

18-
constructor() {
19-
this.listeners = {};
20-
}
16+
constructor() {}
2117

2218
/**
2319
* Register a listener for updates to the PowerSync client.
2420
*/
2521
registerListener(listener: Partial<T>): () => void {
26-
const id = v4();
27-
this.listeners[id] = listener;
22+
this.listeners.add(listener);
2823
return () => {
29-
delete this.listeners[id];
24+
this.listeners.delete(listener);
3025
};
3126
}
3227

3328
iterateListeners(cb: (listener: Partial<T>) => any) {
34-
for (const i in this.listeners) {
35-
cb(this.listeners[i]);
29+
for (const listener of this.listeners) {
30+
cb(listener);
3631
}
3732
}
3833
}

packages/react-native/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ This SDK requires HTTP streaming in order to function. The following `fetch` pol
4343
These are listed as peer dependencies and need to be added to the React Native project
4444

4545
```bash
46-
npx expo install react-native-fetch-api react-native-polyfill-globals react-native-url-polyfill text-encoding [email protected] base-64 [email protected]
46+
npx expo install react-native-fetch-api react-native-polyfill-globals react-native-url-polyfill text-encoding [email protected] base-64
4747
```
4848

4949
Enable the polyfills in React Native app with

packages/react-native/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"react": "*",
3333
"react-native": "*",
3434
"react-native-fetch-api": "^3.0.0",
35-
"react-native-get-random-values": "^1.9.0",
3635
"react-native-polyfill-globals": "^3.1.0",
3736
"react-native-url-polyfill": "^2.0.0",
3837
"text-encoding": "^0.7.0",

packages/web/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"vite-plugin-top-level-await": "^1.4.1",
4343
"vite-plugin-wasm": "^3.3.0",
4444
"vitest": "^1.3.1",
45-
"webdriverio": "^8.32.3"
45+
"webdriverio": "^8.32.3",
46+
"uuid": "^9.0.1"
4647
},
4748
"peerDependencies": {
4849
"@journeyapps/wa-sqlite": "~0.2.0"
@@ -52,7 +53,6 @@
5253
"async-mutex": "^0.4.0",
5354
"comlink": "^4.4.1",
5455
"js-logger": "^1.6.1",
55-
"lodash": "^4.17.21",
56-
"uuid": "^9.0.1"
56+
"lodash": "^4.17.21"
5757
}
5858
}

packages/web/src/worker/db/SharedWASQLiteDB.worker.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import '@journeyapps/wa-sqlite';
22

33
import * as Comlink from 'comlink';
4-
import { v4 as uuid } from 'uuid';
54

65
import { DBWorkerInterface, _openDB } from './open-db';
76

@@ -10,7 +9,7 @@ import { DBWorkerInterface, _openDB } from './open-db';
109
* are using it.
1110
*/
1211
type SharedDBWorkerConnection = {
13-
clientIds: Set<string>;
12+
clientIds: Set<number>;
1413
db: DBWorkerInterface;
1514
};
1615

@@ -19,13 +18,15 @@ const _self: SharedWorkerGlobalScope = self as any;
1918
const DBMap = new Map<string, SharedDBWorkerConnection>();
2019
const OPEN_DB_LOCK = 'open-wasqlite-db';
2120

21+
let nextClientId = 1;
22+
2223
const openDB = async (dbFileName: string): Promise<DBWorkerInterface> => {
2324
// Prevent multiple simultaneous opens from causing race conditions
2425
return navigator.locks.request(OPEN_DB_LOCK, async () => {
25-
const clientId = uuid();
26+
const clientId = nextClientId++;
2627

2728
if (!DBMap.has(dbFileName)) {
28-
const clientIds = new Set<string>();
29+
const clientIds = new Set<number>();
2930
const connection = await _openDB(dbFileName);
3031
DBMap.set(dbFileName, {
3132
clientIds,

packages/web/src/worker/db/open-db.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as SQLite from '@journeyapps/wa-sqlite';
22
import '@journeyapps/wa-sqlite';
33
import * as Comlink from 'comlink';
4-
import { v4 as uuid } from 'uuid';
54
import { QueryResult } from '@powersync/common';
65

76
export type WASQLExecuteResult = Omit<QueryResult, 'rows'> & {
@@ -26,6 +25,8 @@ export type OpenDB = (dbFileName: string) => DBWorkerInterface;
2625

2726
export type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];
2827

28+
let nextId = 1;
29+
2930
export async function _openDB(dbFileName: string): Promise<DBWorkerInterface> {
3031
const { default: moduleFactory } = await import('@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs');
3132
const module = await moduleFactory();
@@ -40,14 +41,14 @@ export async function _openDB(dbFileName: string): Promise<DBWorkerInterface> {
4041
/**
4142
* Listeners are exclusive to the DB connection.
4243
*/
43-
const listeners = new Map<string, OnTableChangeCallback>();
44+
const listeners = new Map<number, OnTableChangeCallback>();
4445

4546
sqlite3.register_table_onchange_hook(db, (opType: number, tableName: string, rowId: number) => {
4647
Array.from(listeners.values()).forEach((l) => l(opType, tableName, rowId));
4748
});
4849

4950
const registerOnTableChange = (callback: OnTableChangeCallback) => {
50-
const id = uuid();
51+
const id = nextId++;
5152
listeners.set(id, callback);
5253
return Comlink.proxy(() => {
5354
listeners.delete(id);

0 commit comments

Comments
 (0)