move to vfs package

This commit is contained in:
tresabhi committed 2026-11-23 20:27:55 -06:00
1 parent ff1aadb774
commit a89c75509e
49 files changed
+125 -96

No files matched your search

-1
View File
@@ -7,7 +7,6 @@
"@blitzkit/i18n": "workspace:*",
"@blitzkit/protos": "workspace:*",
"@bufbuild/protobuf": "^2.9.0",
"@napi-rs/lzma": "^1.5.3",
"@octokit/plugin-throttling": "^11.0.1",
"@octokit/rest": "^22.0.0",
"@types/adm-zip": "^0.5.7",
+43
View File
@@ -0,0 +1,43 @@
export function Cache(disableInDev = false) {
const cache = new WeakMap<object, Map<string, Promise<unknown>>>();
return function <This, Arguments extends any[], Return>(
target: (this: This, ...args: Arguments) => Promise<Return>
// TODO: evaluate if we need context to make the error trace easier
// context: ClassMethodDecoratorContext<
// This,
// (this: This, ...args: Arguments) => Promise<Return>
// >,
) {
return async function replacementMethod(this: This, ...args: Arguments) {
const key = args.join("-");
let thisCache: Map<string, Promise<Return>>;
if (cache.has(this as object)) {
thisCache = cache.get(this as object) as Map<string, Promise<Return>>;
} else {
thisCache = new Map();
cache.set(this as object, thisCache);
}
const disabled = disableInDev && import.meta.env.DEV;
if (thisCache.has(key) && !disabled) {
return thisCache.get(key)!;
}
const promise = (async () => {
try {
return await target.apply(this, args);
} catch (error) {
thisCache!.delete(key);
throw error;
}
})();
thisCache.set(key, promise);
return promise;
};
};
}
+1 -1
View File
@@ -16,7 +16,7 @@ import { fetchPB } from "../../api";
import { fetchJSON } from "../../api/fetchJSON";
import { BlitzScripts } from "../../types/blitzScripts";
import { AbstractBlitzKitAPI } from "./abstract";
import { Cache } from "./server/0_base";
import { Cache } from "./cache";
export class ClientBlitzKitAPI extends AbstractBlitzKitAPI {
@Cache()
+3 -2
View File
@@ -1,11 +1,12 @@
import { AbstractBlitzKitAPI, AbstractVFS } from "@blitzkit/core";
import { AbstractBlitzKitAPI } from "@blitzkit/core";
import type { AbstractVFS } from "@blitzkit/vfs";
export async function createDynamicAPI(vfs: () => Promise<AbstractVFS>) {
let _api: AbstractBlitzKitAPI;
if (import.meta.env.SSR) {
const { ServerBlitzKitAPI } = await import(
"@blitzkit/core/src/blitzkit/api/server/index"
"@blitzkit/core/src/blitzkit/api/server"
);
_api = await new ServerBlitzKitAPI(await vfs()).init();
-1
View File
@@ -1,4 +1,3 @@
export * from "./abstract";
export * from "./client";
export * from "./dynamic";
export * from "./server";
@@ -17,7 +17,7 @@ import {
toUniqueId,
VehicleDefinitionList,
} from "@blitzkit/core";
import { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
import type { AbstractVFS } from "@blitzkit/vfs";
import locales from "@blitzkit/i18n/locales.json";
import {
ConsumableTankCategoryFilterCategory,
@@ -298,47 +298,3 @@ export abstract class ServerBlitzKitAPI0 extends AbstractBlitzKitAPI {
return { locales: collection } satisfies I18nString;
}
}
export function Cache(disableInDev = false) {
const cache = new WeakMap<object, Map<string, Promise<unknown>>>();
return function <This, Arguments extends any[], Return>(
target: (this: This, ...args: Arguments) => Promise<Return>
// TODO: evaluate if we need context to make the error trace easier
// context: ClassMethodDecoratorContext<
// This,
// (this: This, ...args: Arguments) => Promise<Return>
// >,
) {
return async function replacementMethod(this: This, ...args: Arguments) {
const key = args.join("-");
let thisCache: Map<string, Promise<Return>>;
if (cache.has(this as object)) {
thisCache = cache.get(this as object) as Map<string, Promise<Return>>;
} else {
thisCache = new Map();
cache.set(this as object, thisCache);
}
const disabled = disableInDev && import.meta.env.DEV;
if (thisCache.has(key) && !disabled) {
return thisCache.get(key)!;
}
const promise = (async () => {
try {
return await target.apply(this, args);
} catch (error) {
thisCache!.delete(key);
throw error;
}
})();
thisCache.set(key, promise);
return promise;
};
};
}
@@ -1,7 +1,7 @@
import { fetchGlossary } from "@blitzkit/core";
import locales from "@blitzkit/i18n/locales.json";
import { Avatar, Gallery } from "@blitzkit/protos";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI9 } from "./9_game";
export abstract class ServerBlitzKitAPI10 extends ServerBlitzKitAPI9 {
@@ -4,8 +4,8 @@ import type {
ConsumablesCommon,
OptionalDevices,
} from "../../../types";
import { AbstractVFS } from "../../vfs";
import { Cache } from "./0_base";
import type { AbstractVFS } from "@blitzkit/vfs";
import { Cache } from "../cache";
import { ServerBlitzKitAPI10 } from "./10_avatars";
export abstract class ServerBlitzKitAPI11 extends ServerBlitzKitAPI10 {
@@ -2,7 +2,7 @@ import { Strings } from "@blitzkit/i18n";
import locales from "@blitzkit/i18n/locales.json";
import { DeepPartial } from "@blitzkit/protos";
import { merge } from "lodash-es";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI11 } from "./11_scripts";
export abstract class ServerBlitzKitAPI12 extends ServerBlitzKitAPI11 {
@@ -46,7 +46,8 @@ import {
Unlock,
type VehicleAbility,
} from "@blitzkit/protos";
import { Cache, ServerBlitzKitAPI0 } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI0 } from "./0_base";
export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 {
// A gun the way a tank's turret or a vehicle ability builds it. `gun`
@@ -4,7 +4,7 @@ import {
type TankParameters,
} from "@blitzkit/core";
import { isEqual, times } from "lodash-es";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI1 } from "./1_tanks";
export abstract class ServerBlitzKitAPI2 extends ServerBlitzKitAPI1 {
@@ -18,7 +18,7 @@ import {
} from "@blitzkit/core";
import { Armor, Crew, ModelDefinitions, ProtoVector3 } from "@blitzkit/protos";
import { MathUtils, Vector3 as THREEVector3, Vector3Tuple } from "three";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI2 } from "./2_camouflages";
// The `front` and `back` tags hold "min max range" in degrees
@@ -1,5 +1,5 @@
import { MapDefinitions } from "@blitzkit/protos";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI3 } from "./3_models";
export abstract class ServerBlitzKitAPI4 extends ServerBlitzKitAPI3 {
@@ -1,5 +1,5 @@
import { EquipmentDefinitions, EquipmentSlot } from "@blitzkit/protos";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI4 } from "./4_maps";
export abstract class ServerBlitzKitAPI5 extends ServerBlitzKitAPI4 {
@@ -1,6 +1,6 @@
import { BlitzTankFilterDefinitionCategory } from "@blitzkit/core";
import { Consumable, ConsumableDefinitions } from "@blitzkit/protos";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI5 } from "./5_equipments";
export abstract class ServerBlitzKitAPI6 extends ServerBlitzKitAPI5 {
@@ -1,6 +1,6 @@
import { BlitzTankFilterDefinitionCategory } from "@blitzkit/core";
import { Provision, ProvisionDefinitions } from "@blitzkit/protos";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI6 } from "./6_consumables";
export abstract class ServerBlitzKitAPI7 extends ServerBlitzKitAPI6 {
@@ -1,7 +1,7 @@
import { BlitzTankClass } from "@blitzkit/core";
import { SkillDefinitions } from "@blitzkit/protos";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI7 } from "./7_provisions";
export abstract class ServerBlitzKitAPI8 extends ServerBlitzKitAPI7 {
@@ -1,7 +1,7 @@
import { AvailableNationsYaml } from "@blitzkit/core";
import { GameDefinitions } from "@blitzkit/protos";
import { Cache } from "./0_base";
import { Cache } from "../cache";
import { ServerBlitzKitAPI8 } from "./8_skills";
export abstract class ServerBlitzKitAPI9 extends ServerBlitzKitAPI8 {
-2
View File
@@ -11,7 +11,6 @@ export * from "./discoveredIdDefinitions";
export * from "./emblemURL";
export * from "./environment";
export * from "./eventManager";
export * from "./fetchWGCClientSource";
export * from "./getTimeDaysAgo";
export * from "./isExplosive";
export * from "./metaSortTank";
@@ -33,6 +32,5 @@ export * from "./tankNames";
export * from "./unionBoundingBox";
export * from "./uniqueGuns";
export * from "./unwrapBlitzkitResponse";
export * from "./vfs";
export * from "./votes";
export * from "./youtubers";
-1
View File
@@ -2,4 +2,3 @@ export * from "./gunTypeOrder";
export * from "./skills";
export * from "./tankClassOrder";
export * from "./treeTypeOrder";
export * from "./wgcClient";
-1
View File
@@ -6,5 +6,4 @@ export * from "./rts";
export * from "./sc2";
export * from "./scg";
export * from "./scpg";
export * from "./sevenZip";
export * from "./windows";
-1
View File
@@ -32,4 +32,3 @@ export * from "./vehicleDefinitionArmor";
export * from "./vehicleDefinitionList";
export * from "./vehicleDefinitions";
export * from "./vehicleFilter";
export * from "./wgcClient";
+1 -4
View File
@@ -4,6 +4,7 @@
"dependencies": {
"@blitzkit/core": "workspace:*",
"@blitzkit/i18n": "workspace:*",
"@blitzkit/vfs": "workspace:*",
"@gltf-transform/core": "^4.2.1",
"@gltf-transform/extensions": "^4.2.1",
"@gltf-transform/functions": "^4.2.1",
@@ -14,10 +15,8 @@
"@types/lodash-es": "^4.17.12",
"@types/lz4js": "^0.2.1",
"@types/progress": "^2.0.7",
"@types/steam-user": "^5.1.0",
"@types/three": "^0.180.0",
"crc": "^4.3.2",
"csv-parse": "^6.1.0",
"decompress": "^4.2.1",
"dotenv": "^17.2.3",
"esbuild": "^0.25.10",
@@ -28,10 +27,8 @@
"progress": "^2.0.3",
"puppeteer": "^24.22.3",
"sharp": "^0.34.4",
"steam-user": "^5.2.3",
"three": "^0.180.0",
"ts-proto": "^2.7.7",
"unzipit": "^1.4.3",
"yaml": "^2.8.1"
},
"type": "module"
+1 -1
View File
@@ -1,3 +1,3 @@
import { createClientVFS } from "@blitzkit/core/src/blitzkit/vfs/client";
import { createClientVFS } from "@blitzkit/vfs";
export const vfs = await createClientVFS();
+18
View File
@@ -0,0 +1,18 @@
{
"name": "@blitzkit/vfs",
"private": true,
"type": "module",
"main": "src/index.ts",
"dependencies": {
"@blitzkit/core": "workspace:*",
"@blitzkit/i18n": "workspace:*",
"@napi-rs/lzma": "^1.5.3",
"@types/bun": "^1.3.14",
"@types/steam-user": "^5.1.0",
"csv-parse": "^6.1.0",
"fast-xml-parser": "^5.3.2",
"steam-user": "^5.2.3",
"unzipit": "^1.4.3",
"yaml": "^2.8.1"
}
}
@@ -16,6 +16,7 @@ export abstract class AbstractVFS {
private xmlParser = new XMLParser();
private attributeXmlParser = new XMLParser({
ignoreAttributes: false,
// TODO: get this fuck ass thing out of here
// A lone child would otherwise parse to an object instead of a list
isArray: (name) => UPGRADE_PROGRESSION_LIST_TAGS.has(name),
});
@@ -1,5 +1,5 @@
import { assertSecret } from "@blitzkit/core";
import { fetchWGCClientSource } from "../fetchWGCClientSource";
import { fetchWGCClientSource } from "./fetchWGCClientSource";
import { AbstractVFS } from "./abstract";
import { LocalVFS } from "./local";
import { MixedVFS } from "./mixed";
File renamed without changes.
@@ -5,8 +5,8 @@ import {
WGC_CLIENT_URL,
WGC_METADATA_PROTOCOL_VERSION,
WGC_PATCHES_CHAIN_PROTOCOL_VERSION,
} from "../config/wgcClient";
import type { WGCClientMetadata, WGCPatchesChain } from "../types/wgcClient";
} from "./config/wgcClient";
import type { WGCClientMetadata, WGCPatchesChain } from "./types/wgcClient";
const parser = new XMLParser();
@@ -1,4 +1,6 @@
export * from "./abstract";
export * from "./client";
export * from "./fetchWGCClientSource";
export * from "./local";
export * from "./mixed";
export * from "./sevenZip";
File renamed without changes.
File renamed without changes.
@@ -6,7 +6,7 @@ import {
type SevenZipCoder,
type SevenZipFileInfo,
type SevenZipStreamsInfo,
} from "../../../streams/sevenZip";
} from "./streams";
import type { HTTPMultiRangeReader } from "./rangeReader";
const enum Method {
@@ -1,4 +1,4 @@
import { ReadStream } from "./buffer";
import { ReadStream } from "@blitzkit/core";
export const SEVEN_ZIP_SIGNATURE_HEADER_SIZE = 32;
File renamed without changes.
File renamed without changes.
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />
File renamed without changes.
-4
View File
@@ -9,10 +9,6 @@ export default defineConfig({
esbuild: { target: "es2022" },
build: { cssCodeSplit: false },
optimizeDeps: {
exclude: ["@napi-rs/lzma"],
},
css: {
modules: {
// Short hashed class names in production to shrink HTML; the leading _ keeps names that start with a digit valid
+1
View File
@@ -8,6 +8,7 @@
"@astrolib/seo": "^1.0.0-beta.8",
"@blitzkit/core": "workspace:*",
"@blitzkit/i18n": "workspace:*",
"@blitzkit/vfs": "workspace:*",
"@fontsource-variable/jetbrains-mono": "^5.3.0",
"@fontsource-variable/roboto-flex": "^5.3.0",
"@fontsource/inter": "^5.2.8",
+10 -3
View File
@@ -1,5 +1,12 @@
import { createDynamicAPI } from "@blitzkit/core";
export const api = await createDynamicAPI(() =>
import("../core/blitzkit/vfs").then(({ vfs }) => vfs),
);
export const api = await createDynamicAPI(async () => {
// rollup prunes imports in dead if branches, but not ones after an early throw
if (import.meta.env.SSR) {
const { vfs } = await import("../core/blitzkit/vfs");
return vfs;
}
throw new Error("VFS is server-only");
});
@@ -10,7 +10,7 @@ import {
type SC2,
type ScgPolygonGroups,
} from "@blitzkit/core";
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
import type { AbstractVFS } from "@blitzkit/vfs";
import {
Accessor,
Document,
@@ -1,5 +1,5 @@
import { VertexAttribute, type ComponentOf } from "@blitzkit/core";
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
import type { AbstractVFS } from "@blitzkit/vfs";
import {
MathUtils,
type Buffer,
+1 -1
View File
@@ -1,3 +1,3 @@
import { createClientVFS } from "@blitzkit/core/src/blitzkit/vfs/client";
import { createClientVFS } from "@blitzkit/vfs";
export const vfs = await createClientVFS();
@@ -5,7 +5,7 @@ import {
toUniqueId,
type VehicleDefinitionList,
} from "@blitzkit/core";
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
import type { AbstractVFS } from "@blitzkit/vfs";
import { Document, Node, NodeIO, Scene } from "@gltf-transform/core";
import type { APIContext } from "astro";
import { Sc2ComponentHandler } from "../../../core/blitzkit/sc2Components";
@@ -12,7 +12,7 @@ import {
type Textures,
type VehicleDefinitionList,
} from "@blitzkit/core";
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
import type { AbstractVFS } from "@blitzkit/vfs";
import {
Document,
Material,