....
This commit is contained in:
parent
3dab48f58b
commit
c869f0a880
1 changed files with 461 additions and 578 deletions
|
|
@ -4,24 +4,20 @@ import {
|
|||
ServerVersionMismatchError
|
||||
} from "../errors/errors";
|
||||
import type { SyncService } from "./sync-service";
|
||||
|
||||
export interface ServerConfigData {
|
||||
mergeableFileExtensions: string[];
|
||||
supportedApiVersion: number;
|
||||
isAuthenticated: boolean;
|
||||
}
|
||||
import type { PingResponse } from "./types/PingResponse";
|
||||
|
||||
export class ServerConfig {
|
||||
private config: Promise<ServerConfigData> | undefined;
|
||||
private config?: Promise<PingResponse>;
|
||||
|
||||
public constructor(private readonly syncService: SyncService) { }
|
||||
public constructor(private readonly syncService: SyncService) {}
|
||||
|
||||
private static validateConfig(config: ServerConfigData): void {
|
||||
private static validateConfig(config: PingResponse): void {
|
||||
if (config.supportedApiVersion !== SUPPORTED_API_VERSION) {
|
||||
const shouldUpgradeClient =
|
||||
config.supportedApiVersion > SUPPORTED_API_VERSION;
|
||||
throw new ServerVersionMismatchError(
|
||||
`Unsupported API version: ${config.supportedApiVersion}. Consider upgrading the ${shouldUpgradeClient ? "client" : "sync-server"
|
||||
`Unsupported API version: ${config.supportedApiVersion}. Consider upgrading the ${
|
||||
shouldUpgradeClient ? "client" : "sync-server"
|
||||
} to ensure compatibility`
|
||||
);
|
||||
}
|
||||
|
|
@ -33,11 +29,6 @@ export class ServerConfig {
|
|||
}
|
||||
}
|
||||
|
||||
// warm the cache
|
||||
public async initialize(): Promise<void> {
|
||||
await this.getConfig();
|
||||
}
|
||||
|
||||
public async checkConnection(): Promise<{
|
||||
isSuccessful: boolean;
|
||||
message: string;
|
||||
|
|
@ -59,7 +50,7 @@ export class ServerConfig {
|
|||
}
|
||||
}
|
||||
|
||||
public async getConfig(): Promise<ServerConfigData> {
|
||||
public async getConfig(): Promise<PingResponse> {
|
||||
if (!this.config) {
|
||||
const pending = this.syncService
|
||||
.ping()
|
||||
|
|
|
|||
Loading…
Reference in a new issue