Merge pull request #1129 from bbassie/refactor/async-factory

Replace bootstrap methods with async factories
This commit is contained in:
Cooldude2606 authored and GitHub committed 2026-10-27 21:31:49 +00:00
commit e36a76acc5
18 files changed
+540 -281

No files matched your search

+2 -2
View File
@@ -435,7 +435,7 @@ export class DebugWsMessageEvent {
export class FactorioVersionsRequest {
declare ["constructor"]: typeof FactorioVersionsRequest;
static type = "request" as const;
static src = ["control", "instance"] as const;
static src = ["control", "host", "instance"] as const;
static dst = "controller" as const;
static permission = "core.external.get_factorio_versions" as const;
@@ -457,7 +457,7 @@ export class FactorioVersionsRequest {
export class LatestReleasesRequest {
declare ["constructor"]: typeof LatestReleasesRequest;
static type = "request" as const;
static src = ["control", "instance"] as const;
static src = ["control", "host", "instance"] as const;
static dst = "controller" as const;
static permission = "core.external.get_latest_releases" as const;
+10 -5
View File
@@ -17,11 +17,6 @@ export abstract class DatastoreProvider<
> {
abstract save(data: Map<K, V>): Promise<void>
abstract load(): Promise<Map<K, V>>
// Load data from the source and return it, this should be passed to the constructor of a datastore
async bootstrap() {
return [this, await this.load()] as const;
}
}
// Store all data in memory, used as a default and should be avoided
@@ -251,6 +246,11 @@ export class KeyValueDatastore<
K extends DatastoreKey,
V extends DatastoreValue,
> extends Datastore<K, V, [key: K, value: V, isDeleted?: boolean]> {
// Create a datastore populated with the data loaded from the provider
static async fromProvider<K extends DatastoreKey, V extends DatastoreValue>(provider: DatastoreProvider<K, V>) {
return new this(provider, await provider.load());
}
// Set the value in the datastore, be careful of race conditions if you await any functions before calling set
set(key: K, value: V) {
this.data.set(key, value);
@@ -316,6 +316,11 @@ export class SubscribableDatastore<
this.lastUpdatedAtMs = SubscribableDatastore.maxUpdatedAtMs(this.data.values());
}
// Create a datastore populated with the data loaded from the provider
static async fromProvider<V extends SubscribableValue>(provider: DatastoreProvider<V["id"], V>) {
return new this(provider, await provider.load());
}
async load() {
await super.load();
this.lastUpdatedAtMs = SubscribableDatastore.maxUpdatedAtMs(this.data.values());