import { Config } from "../client/config.ts"; import { DataStore } from "../client/data/datastore.ts"; import { MemoryKvPrimitives } from "../client/data/memory_kv_primitives.ts"; import { DataStoreMQ } from "../client/data/mq.datastore.ts"; import { ObjectIndex } from "../client/data/object_index.ts"; import { EventHook } from "../client/plugos/hooks/event.ts"; import { dataStoreReadSyscalls, dataStoreWriteSyscalls, } from "../client/plugos/syscalls/datastore.ts"; import { eventSyscalls } from "../client/plugos/syscalls/event.ts"; import { indexSyscalls } from "../client/plugos/syscalls/index.ts"; import { jsonschemaSyscalls } from "../client/plugos/syscalls/jsonschema.ts"; import { languageSyscalls } from "../client/plugos/syscalls/language.ts"; import { luaSyscalls } from "../client/space_lua/syscalls.ts"; import { markdownSyscalls } from "../client/plugos/syscalls/markdown.ts"; import { mqSyscalls } from "../client/plugos/syscalls/mq.ts"; import { spaceReadSyscalls, spaceWriteSyscalls, } from "../client/plugos/syscalls/space.ts"; import { systemSyscalls } from "../client/plugos/syscalls/system.ts"; import { System } from "../client/plugos/system.ts"; import { Space } from "../client/space.ts"; import { SpaceLuaEnvironment } from "../client/space_lua.ts"; import { DataStoreSpacePrimitives } from "../client/spaces/datastore_space_primitives.ts"; import { EventedSpacePrimitives } from "../client/spaces/evented_space_primitives.ts"; export function createMockSystem() { const system = new System(); const eventHook = new EventHook(); system.addHook(eventHook); const kv = new MemoryKvPrimitives(); const ds = new DataStore(kv); const spacePrimitives = new EventedSpacePrimitives( new DataStoreSpacePrimitives(kv), eventHook, ds, ); const space = new Space(spacePrimitives, eventHook); const mq = new DataStoreMQ(ds, eventHook); const config = new Config(); const clientMock: any = { space, config, eventedSpacePrimitives: spacePrimitives, }; const objectIndex = new ObjectIndex(ds, config, eventHook, mq); const clientSystemMock: any = { system: system, spaceLuaEnv: new SpaceLuaEnvironment(system, objectIndex), }; clientMock.clientSystem = clientSystemMock; system.registerSyscalls( [], eventSyscalls(eventHook, clientMock), spaceReadSyscalls(clientMock), spaceWriteSyscalls(clientMock), markdownSyscalls(clientMock), languageSyscalls(), jsonschemaSyscalls(), indexSyscalls(objectIndex, clientMock), luaSyscalls(system, () => clientSystemMock.spaceLuaEnv.env), mqSyscalls(mq), dataStoreReadSyscalls(ds, clientSystemMock), dataStoreWriteSyscalls(ds), systemSyscalls(clientMock, false), ); globalThis.syscall = (name: string, ...args: any): Promise => { return system.localSyscall(name, args); }; return { system, eventHook, config, kv, spacePrimitives, mq, ds, space, }; }