0.1.6•Updated a month ago
import { PostgresClient } from "@infinity-beyond/modules/data_store/postgres.ts";
import type { TaskProcessor } from "@infinity-beyond/modules/delegation/task_processor.ts";
import type { Infinity } from "@infinity-beyond/modules/infinity.ts";
import type { Entity } from "@infinity-beyond/classes/data_types/entity/mod.ts";
import "https://deno.land/std@0.216.0/dotenv/load.ts";
import { randomUUID } from "node:crypto";
const SIGNATURE = Deno.env.get('SIGNATURE')!;
if(!SIGNATURE && !Deno.args.includes('build')) throw new Error('Signature value not found!\nPlease add the same secure `SIGNATURE` value to the environments of both the host and workers.');
interface State {
Environment: 'HOST' | 'PROCESSOR',
IS_PROCESSOR: boolean
IS_BUILDING: boolean
SIGNATURE: string
PROCESSOR?: TaskProcessor
PostgresClient: PostgresClient
Application?: Infinity
Entities: Map<string, Entity>
uuid: string
}
let PROCESSOR: TaskProcessor | undefined = undefined;
const State: State = {
Environment: "HOST",
IS_BUILDING: Deno.args.includes("build"),
PostgresClient: new PostgresClient(Deno.env.get('POSTGRES_URL')!),
get IS_PROCESSOR() {
return this.Environment == 'PROCESSOR';
},
get SIGNATURE() {
return SIGNATURE;
},
set PROCESSOR(processor: TaskProcessor) {
if(State.Application) throw new Error('A host and processor should not run in the same instance!');
PROCESSOR = processor;
},
get PROCESSOR(): TaskProcessor | undefined {
return PROCESSOR;
},
Entities: new Map(),
uuid: randomUUID()
}
if(!State.IS_BUILDING) await State.PostgresClient.Setup();
export default State;