2021-08-12 15:04:37 +02:00
|
|
|
import {
|
|
|
|
IClientInstance,
|
|
|
|
IClientInstanceStore,
|
|
|
|
INewClientInstance,
|
|
|
|
} from '../../lib/types/stores/client-instance-store';
|
|
|
|
import NotFoundError from '../../lib/error/notfound-error';
|
|
|
|
|
|
|
|
export default class FakeClientInstanceStore implements IClientInstanceStore {
|
|
|
|
instances: IClientInstance[] = [];
|
|
|
|
|
|
|
|
async bulkUpsert(instances: INewClientInstance[]): Promise<void> {
|
|
|
|
instances.forEach((i) => {
|
|
|
|
this.instances.push({ createdAt: new Date(), ...i });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete(
|
|
|
|
key: Pick<INewClientInstance, 'appName' | 'instanceId'>,
|
|
|
|
): Promise<void> {
|
|
|
|
this.instances.splice(
|
|
|
|
this.instances.findIndex(
|
|
|
|
(i) =>
|
|
|
|
i.instanceId === key.instanceId &&
|
|
|
|
i.appName === key.appName,
|
|
|
|
),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-09 22:32:48 +01:00
|
|
|
setLastSeen(): Promise<void> {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
async deleteAll(): Promise<void> {
|
|
|
|
this.instances = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteForApplication(appName: string): Promise<void> {
|
|
|
|
this.instances = this.instances.filter((i) => i.appName !== appName);
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy(): void {}
|
|
|
|
|
|
|
|
async exists(
|
|
|
|
key: Pick<INewClientInstance, 'appName' | 'instanceId'>,
|
|
|
|
): Promise<boolean> {
|
|
|
|
return this.instances.some(
|
|
|
|
(i) => i.appName === key.appName && i.instanceId === key.instanceId,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async get(
|
|
|
|
key: Pick<INewClientInstance, 'appName' | 'instanceId'>,
|
|
|
|
): Promise<IClientInstance> {
|
|
|
|
const instance = this.instances.find(
|
|
|
|
(i) => i.appName === key.appName && i.instanceId === key.instanceId,
|
|
|
|
);
|
|
|
|
if (instance) {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
throw new NotFoundError(`Could not find instance with key: ${key}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAll(): Promise<IClientInstance[]> {
|
|
|
|
return this.instances;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getByAppName(appName: string): Promise<IClientInstance[]> {
|
|
|
|
return this.instances.filter((i) => i.appName === appName);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getDistinctApplications(): Promise<string[]> {
|
|
|
|
const apps = new Set<string>();
|
|
|
|
this.instances.forEach((i) => apps.add(i.appName));
|
|
|
|
return Array.from(apps.values());
|
|
|
|
}
|
|
|
|
|
2022-12-16 12:16:51 +01:00
|
|
|
async getDistinctApplicationsCount(): Promise<number> {
|
|
|
|
return this.getDistinctApplications().then((apps) => apps.length);
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
async insert(details: INewClientInstance): Promise<void> {
|
|
|
|
this.instances.push({ createdAt: new Date(), ...details });
|
|
|
|
}
|
2023-01-30 12:01:44 +01:00
|
|
|
|
|
|
|
removeInstancesOlderThanTwoDays(): Promise<void> {
|
|
|
|
return Promise.resolve(undefined);
|
|
|
|
}
|
2021-08-12 15:04:37 +02:00
|
|
|
}
|