mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 19:37:07 +02:00
DARKNET: Darkweb Expansion Project & Bitnode (#2139)
This is BN15. It is a really big change; see the PR for all the details.
This commit is contained in:
committed by
GitHub
parent
a674633f6c
commit
6073964768
@@ -1,3 +1,5 @@
|
||||
import { exampleDarknetServerData } from "../DarkNet/Enums";
|
||||
import type { DarknetServerData } from "@nsdefs";
|
||||
import type { NetscriptContext } from "./APIWrapper";
|
||||
import { errorMessage } from "./ErrorMessages";
|
||||
|
||||
@@ -55,3 +57,20 @@ export function assertFunctionWithNSContext(
|
||||
): asserts v is () => void {
|
||||
if (typeof v !== "function") throw errorMessage(ctx, `${argName} expected to be a function ${debugType(v)}`, "TYPE");
|
||||
}
|
||||
|
||||
export function missingKey(expect: object, actual: unknown): string | false {
|
||||
if (typeof actual !== "object" || actual === null) {
|
||||
return `Expected to be an object, was ${actual === null ? "null" : typeof actual}.`;
|
||||
}
|
||||
for (const key in expect) {
|
||||
if (!(key in actual)) return `Property ${key} was expected but not present.`;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function assertDarknetServerData(ctx: NetscriptContext, data: unknown): asserts data is DarknetServerData {
|
||||
const error = missingKey(exampleDarknetServerData, data);
|
||||
if (error) {
|
||||
throw errorMessage(ctx, `Invalid darknet server data.\n${error}`, "TYPE");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user