Add WebSocket support (#12)

This commit is contained in:
Andras Schmelczer 2025-03-29 10:17:46 +00:00 committed by GitHub
commit 1aad0fce31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
68 changed files with 2581 additions and 996 deletions

View file

@ -18,6 +18,7 @@
"typescript": "5.8.2",
"uuid": "^11.1.0",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1"
"webpack-cli": "^6.0.1",
"bufferutil": "^4.0.9"
}
}
}

View file

@ -88,8 +88,7 @@ export class MockAgent extends MockClient {
public async act(): Promise<void> {
const options: (() => Promise<unknown>)[] = [
this.createFileAction.bind(this),
this.changeFetchChangesUpdateIntervalMsAction.bind(this)
this.createFileAction.bind(this)
];
if (this.client.getSettings().isSyncEnabled) {
@ -253,16 +252,6 @@ export class MockAgent extends MockClient {
return this.create(file, new TextEncoder().encode(` ${content} `));
}
private async changeFetchChangesUpdateIntervalMsAction(): Promise<void> {
this.client.logger.info(
`Decided to change fetchChangesUpdateIntervalMs`
);
return this.client.setSetting(
"fetchChangesUpdateIntervalMs",
Math.random() * 2000 + 100
);
}
private async disableSyncAction(): Promise<void> {
this.client.logger.info(`Decided to disable sync`);
await this.client.setSetting("isSyncEnabled", false);

View file

@ -1,4 +1,4 @@
import type { StoredDatabase } from "sync-client/dist/types/persistence/database";
import type { StoredDatabase } from "sync-client";
import { assert } from "../utils/assert";
import {
type RelativePath,
@ -23,9 +23,11 @@ export class MockClient implements FileSystemOperations {
};
public constructor(
private readonly initialSettings: Partial<SyncSettings>,
initialSettings: Partial<SyncSettings>,
protected readonly useSlowFileEvents: boolean
) {}
) {
this.data.settings = initialSettings;
}
public async init(
fetchImplementation: typeof globalThis.fetch
@ -39,16 +41,6 @@ export class MockClient implements FileSystemOperations {
fetch: fetchImplementation
});
await Promise.all(
Object.keys(this.initialSettings).map(async (key) => {
const settingKey = key as keyof SyncSettings; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
return this.client.setSetting(
settingKey,
this.initialSettings[settingKey]! // eslint-disable-line @typescript-eslint/no-non-null-assertion
);
})
);
await this.client.start();
}

View file

@ -5,8 +5,13 @@
"target": "ES2022",
"module": "CommonJS",
"esModuleInterop": true,
"lib": ["DOM", "ESNext"],
"lib": [
"DOM",
"ESNext"
],
"moduleResolution": "node"
},
"exclude": ["./dist"]
}
"exclude": [
"./dist"
]
}