diff --git a/src/Netscript/APIWrapper.ts b/src/Netscript/APIWrapper.ts index 430cb3b5d..05b21d51e 100644 --- a/src/Netscript/APIWrapper.ts +++ b/src/Netscript/APIWrapper.ts @@ -122,29 +122,24 @@ export function wrapAPI( helpers: INetscriptHelper, wrappedAPI: ExternalAPI, workerScript: WorkerScript, - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types namespace: object, ...tree: string[] ): WrappedNetscriptAPI { - if (typeof namespace !== "object") throw new Error("Invalid namespace?"); for (const [key, value] of Object.entries(namespace)) { - switch (typeof value) { - case "function": { - wrapFunction(helpers, wrappedAPI, workerScript, value, ...tree, key); - break; - } - case "object": { - wrapAPI(helpers, wrappedAPI, workerScript, value, ...tree, key); - break; - } - default: { - setNestedProperty(wrappedAPI, value, ...tree, key); - } + if (typeof value === "function") { + wrapFunction(helpers, wrappedAPI, workerScript, value, ...tree, key); + } else if (Array.isArray(value)) { + setNestedProperty(wrappedAPI, value, key); + } else if (typeof value === "object") { + wrapAPI(helpers, wrappedAPI, workerScript, value, ...tree, key); + } else { + setNestedProperty(wrappedAPI, value, ...tree, key); } } return wrappedAPI; } +// TODO: This doesn't even work properly. function setNestedProperty(root: object, value: unknown, ...tree: string[]): void { let target = root; const key = tree.pop(); diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index e48498c17..b4d578ac6 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -2596,5 +2596,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { const possibleLogs = Object.fromEntries([...getFunctionNames(ns, "")].map((a) => [a, true])); const wrappedNS = wrapAPI(helper, {}, workerScript, ns) as unknown as INS; + (wrappedNS as any).args = ns.args; + (wrappedNS as any).enums = ns.enums; return wrappedNS; }