mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
CODEBASE: Update SaveData type to be compatible with TS 5.9 and upgrade TS (#2457)
This commit is contained in:
2
electron/saveDataBinaryFormat.d.ts
vendored
2
electron/saveDataBinaryFormat.d.ts
vendored
@@ -1 +1 @@
|
|||||||
export declare const isBinaryFormat: (saveData: string | Uint8Array) => boolean;
|
export declare const isBinaryFormat: (saveData: string | Uint8Array<ArrayBuffer>) => boolean;
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ This function returns the save data.
|
|||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
getSaveData(): Promise<Uint8Array>;
|
getSaveData(): Promise<Uint8Array<ArrayBuffer>>;
|
||||||
```
|
```
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
Promise<Uint8Array>
|
Promise<Uint8Array<ArrayBuffer>>
|
||||||
|
|
||||||
## Remarks
|
## Remarks
|
||||||
|
|
||||||
|
|||||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -96,7 +96,7 @@
|
|||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
"react-refresh": "^0.18.0",
|
"react-refresh": "^0.18.0",
|
||||||
"style-loader": "^4.0.0",
|
"style-loader": "^4.0.0",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.9.3",
|
||||||
"webpack": "^5.100.2",
|
"webpack": "^5.100.2",
|
||||||
"webpack-cli": "^6.0.1",
|
"webpack-cli": "^6.0.1",
|
||||||
"webpack-dev-server": "^5.2.2",
|
"webpack-dev-server": "^5.2.2",
|
||||||
@@ -18081,9 +18081,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "5.8.3",
|
"version": "5.9.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||||
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
|
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
"react-refresh": "^0.18.0",
|
"react-refresh": "^0.18.0",
|
||||||
"style-loader": "^4.0.0",
|
"style-loader": "^4.0.0",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.9.3",
|
||||||
"webpack": "^5.100.2",
|
"webpack": "^5.100.2",
|
||||||
"webpack-cli": "^6.0.1",
|
"webpack-cli": "^6.0.1",
|
||||||
"webpack-dev-server": "^5.2.2",
|
"webpack-dev-server": "^5.2.2",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { exportScripts } from "./Terminal/commands/download";
|
|||||||
import { CONSTANTS } from "./Constants";
|
import { CONSTANTS } from "./Constants";
|
||||||
import { commitHash } from "./utils/helpers/commitHash";
|
import { commitHash } from "./utils/helpers/commitHash";
|
||||||
import { handleGetSaveDataInfoError } from "./utils/ErrorHandler";
|
import { handleGetSaveDataInfoError } from "./utils/ErrorHandler";
|
||||||
|
import { assertSaveData } from "./utils/TypeAssertion";
|
||||||
|
|
||||||
interface IReturnWebStatus extends IReturnStatus {
|
interface IReturnWebStatus extends IReturnStatus {
|
||||||
data?: Record<string, unknown>;
|
data?: Record<string, unknown>;
|
||||||
@@ -122,9 +123,7 @@ function initElectronBridge(): void {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
bridge.receive("get-save-info-request", (saveData: unknown) => {
|
bridge.receive("get-save-info-request", (saveData: unknown) => {
|
||||||
if (typeof saveData !== "string" && !(saveData instanceof Uint8Array)) {
|
assertSaveData(saveData);
|
||||||
throw new Error("Error while trying to get save info");
|
|
||||||
}
|
|
||||||
window.appSaveFns
|
window.appSaveFns
|
||||||
.getSaveInfo(saveData)
|
.getSaveInfo(saveData)
|
||||||
.then((saveInfo) => {
|
.then((saveInfo) => {
|
||||||
|
|||||||
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -1879,7 +1879,7 @@ export interface Singularity {
|
|||||||
* @remarks
|
* @remarks
|
||||||
* RAM cost: 1 GB * 16/4/1
|
* RAM cost: 1 GB * 16/4/1
|
||||||
*/
|
*/
|
||||||
getSaveData(): Promise<Uint8Array>;
|
getSaveData(): Promise<Uint8Array<ArrayBuffer>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backup game save.
|
* Backup game save.
|
||||||
|
|||||||
@@ -46,4 +46,4 @@ export interface IMinMaxRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Type of save data. The base64 format is string, the binary format is Uint8Array.
|
// Type of save data. The base64 format is string, the binary format is Uint8Array.
|
||||||
export type SaveData = string | Uint8Array;
|
export type SaveData = string | Uint8Array<ArrayBuffer>;
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ export function canUseBinaryFormat(): boolean {
|
|||||||
return "CompressionStream" in globalThis;
|
return "CompressionStream" in globalThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compress(dataString: string): Promise<Uint8Array> {
|
async function compress(dataString: string): Promise<Uint8Array<ArrayBuffer>> {
|
||||||
const compressedReadableStream = new Blob([dataString]).stream().pipeThrough(new CompressionStream("gzip"));
|
const compressedReadableStream = new Blob([dataString]).stream().pipeThrough(new CompressionStream("gzip"));
|
||||||
return new Uint8Array(await new Response(compressedReadableStream).arrayBuffer());
|
return new Uint8Array(await new Response(compressedReadableStream).arrayBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function decompress(binaryData: Uint8Array): Promise<string> {
|
async function decompress(binaryData: Uint8Array<ArrayBuffer>): Promise<string> {
|
||||||
const decompressedReadableStream = new Blob([binaryData]).stream().pipeThrough(new DecompressionStream("gzip"));
|
const decompressedReadableStream = new Blob([binaryData]).stream().pipeThrough(new DecompressionStream("gzip"));
|
||||||
const reader = decompressedReadableStream.pipeThrough(new TextDecoderStream("utf-8", { fatal: true })).getReader();
|
const reader = decompressedReadableStream.pipeThrough(new TextDecoderStream("utf-8", { fatal: true })).getReader();
|
||||||
let result = "";
|
let result = "";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Unknownify } from "../types";
|
import type { SaveData, Unknownify } from "../types";
|
||||||
|
|
||||||
// This function is empty because Unknownify<T> is a typesafe assertion on any object with no runtime checks needed.
|
// This function is empty because Unknownify<T> is a typesafe assertion on any object with no runtime checks needed.
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
@@ -89,3 +89,14 @@ export function assertNumberArray(unknownData: unknown, assertFinite = false): a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function assertSaveData(unknownData: unknown): asserts unknownData is SaveData {
|
||||||
|
if (typeof unknownData !== "string" && !(unknownData instanceof Uint8Array)) {
|
||||||
|
console.error(unknownData);
|
||||||
|
throw new Error(`Invalid save data. Its type is ${getFriendlyType(unknownData)}.`);
|
||||||
|
}
|
||||||
|
if (unknownData instanceof Uint8Array && !(unknownData.buffer instanceof ArrayBuffer)) {
|
||||||
|
console.error(unknownData);
|
||||||
|
throw new Error("Invalid save data. It's Uint8Array, but its buffer is not ArrayBuffer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user