remove last colon any for now

This commit is contained in:
Olivier Gagnon
2022-07-20 01:37:41 -04:00
parent b4e5829cf8
commit 0e74b1a5d6
+14 -14
View File
@@ -123,44 +123,44 @@ export function wrapAPI(
wrappedAPI: ExternalAPI, wrappedAPI: ExternalAPI,
workerScript: WorkerScript, workerScript: WorkerScript,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
namespace: any, namespace: object,
...tree: string[] ...tree: string[]
): WrappedNetscriptAPI { ): WrappedNetscriptAPI {
if (typeof namespace !== "object") throw new Error("Invalid namespace?"); if (typeof namespace !== "object") throw new Error("Invalid namespace?");
for (const property of Object.getOwnPropertyNames(namespace)) { for (const [key, value] of Object.entries(namespace)) {
switch (typeof namespace[property]) { switch (typeof value) {
case "function": { case "function": {
wrapFunction(helpers, wrappedAPI, workerScript, namespace[property], ...tree, property); wrapFunction(helpers, wrappedAPI, workerScript, value, ...tree, key);
break; break;
} }
case "object": { case "object": {
wrapAPI(helpers, wrappedAPI, workerScript, namespace[property], ...tree, property); wrapAPI(helpers, wrappedAPI, workerScript, value, ...tree, key);
break; break;
} }
default: { default: {
setNestedProperty(wrappedAPI, namespace[property], ...tree, property); setNestedProperty(wrappedAPI, value, ...tree, key);
} }
} }
} }
return wrappedAPI; return wrappedAPI;
} }
function setNestedProperty(root: any, value: any, ...tree: string[]): void { function setNestedProperty(root: object, value: unknown, ...tree: string[]): void {
let target = root; let target = root;
const key = tree.pop(); const key = tree.pop();
if (typeof key !== "string") { if (!key) {
throw new Error("Failure occured while wrapping netscript api (setNestedProperty)"); throw new Error("Failure occured while wrapping netscript api (setNestedProperty)");
} }
for (const branch of tree) { for (let branch of Object.values(target)) {
if (target[branch] === undefined) { if (branch === undefined) {
target[branch] = {}; branch = {};
} }
target = target[branch]; target = branch;
} }
target[key] = value; Object.assign(target, { [key]: value });
} }
function getNestedProperty(root: any, ...tree: string[]): any { function getNestedProperty(root: any, ...tree: string[]): unknown {
let target = root; let target = root;
for (const branch of tree) { for (const branch of tree) {
if (target[branch] === undefined) { if (target[branch] === undefined) {