[TS] Completely remove Indexable from Vendetta

This commit is contained in:
Beef 2023-04-15 03:04:48 +01:00
parent 32b3a0295c
commit b271240f76
5 changed files with 18 additions and 21 deletions

20
src/def.d.ts vendored
View file

@ -124,8 +124,8 @@ interface ThemeData {
description?: string; description?: string;
authors?: Author[]; authors?: Author[];
spec: number; spec: number;
semanticColors?: Indexable<string[]>; semanticColors?: Record<string, string[]>;
rawColors?: Indexable<string>; rawColors?: Record<string, string>;
} }
interface Theme { interface Theme {
@ -292,8 +292,6 @@ interface FileManager {
DocumentsDirPath: string; DocumentsDirPath: string;
} }
type Indexable<Type> = { [index: string]: Type }
type EmitterEvent = "SET" | "GET" | "DEL"; type EmitterEvent = "SET" | "GET" | "DEL";
interface EmitterListenerData { interface EmitterListenerData {
@ -306,7 +304,7 @@ type EmitterListener = (
data: EmitterListenerData | any data: EmitterListenerData | any
) => any; ) => any;
type EmitterListeners = Indexable<Set<EmitterListener>>; type EmitterListeners = Record<string, Set<EmitterListener>>
interface Emitter { interface Emitter {
listeners: EmitterListeners; listeners: EmitterListeners;
@ -437,18 +435,18 @@ interface VendettaObject {
showInputAlert: (options: InputAlertProps) => void; showInputAlert: (options: InputAlertProps) => void;
}; };
assets: { assets: {
all: Indexable<Asset>; all: Record<string, Asset>;
find: (filter: (a: any) => void) => Asset | null | undefined; find: (filter: (a: any) => void) => Asset | null | undefined;
getAssetByName: (name: string) => Asset; getAssetByName: (name: string) => Asset;
getAssetByID: (id: number) => Asset; getAssetByID: (id: number) => Asset;
getAssetIDByName: (name: string) => number; getAssetIDByName: (name: string) => number;
}; };
// TODO: Make a vain attempt to type these // TODO: Make a vain attempt to type these
semanticColors: Indexable<any>; semanticColors: Record<string, any>;
rawColors: Indexable<any>; rawColors: Record<string, any>;
}; };
plugins: { plugins: {
plugins: Indexable<Plugin>; plugins: Record<string, Plugin>;
fetchPlugin: (id: string) => Promise<void>; fetchPlugin: (id: string) => Promise<void>;
installPlugin: (id: string, enabled?: boolean) => Promise<void>; installPlugin: (id: string, enabled?: boolean) => Promise<void>;
startPlugin: (id: string) => Promise<void>; startPlugin: (id: string) => Promise<void>;
@ -457,7 +455,7 @@ interface VendettaObject {
getSettings: (id: string) => JSX.Element; getSettings: (id: string) => JSX.Element;
}; };
themes: { themes: {
themes: Indexable<Theme>; themes: Record<string, Theme>;
fetchTheme: (id: string, selected?: boolean) => Promise<void>; fetchTheme: (id: string, selected?: boolean) => Promise<void>;
installTheme: (id: string) => Promise<void>; installTheme: (id: string) => Promise<void>;
selectTheme: (id: string) => Promise<void>; selectTheme: (id: string) => Promise<void>;
@ -490,7 +488,7 @@ interface VendettaObject {
interface VendettaPluginObject { interface VendettaPluginObject {
id: string; id: string;
manifest: PluginManifest; manifest: PluginManifest;
storage: Indexable<any>; storage: Record<string, any>;
} }
declare global { declare global {

View file

@ -1,4 +1,4 @@
import { Indexable, PluginManifest, Plugin } from "@types"; import { PluginManifest, Plugin } from "@types";
import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage"; import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
import { MMKVManager } from "@lib/native"; import { MMKVManager } from "@lib/native";
import settings from "@lib/settings"; import settings from "@lib/settings";
@ -11,8 +11,8 @@ type EvaledPlugin = {
settings: JSX.Element; settings: JSX.Element;
}; };
export const plugins = wrapSync(createStorage<Indexable<Plugin>>(createMMKVBackend("VENDETTA_PLUGINS"))); export const plugins = wrapSync(createStorage<Record<string, Plugin>>(createMMKVBackend("VENDETTA_PLUGINS")));
const loadedPlugins: Indexable<EvaledPlugin> = {}; const loadedPlugins: Record<string, EvaledPlugin> = {};
export async function fetchPlugin(id: string) { export async function fetchPlugin(id: string) {
if (!id.endsWith("/")) id += "/"; if (!id.endsWith("/")) id += "/";
@ -60,7 +60,7 @@ export async function evalPlugin(plugin: Plugin) {
id: plugin.id, id: plugin.id,
manifest: plugin.manifest, manifest: plugin.manifest,
// Wrapping this with wrapSync is NOT an option. // Wrapping this with wrapSync is NOT an option.
storage: await createStorage<Indexable<any>>(createMMKVBackend(plugin.id)), storage: await createStorage<Record<string, any>>(createMMKVBackend(plugin.id)),
}, },
logger: new logModule(`Vendetta » ${plugin.manifest.name}`), logger: new logModule(`Vendetta » ${plugin.manifest.name}`),
}; };

View file

@ -1,4 +1,4 @@
import { Indexable, Theme, ThemeData } from "@types"; import { Theme, ThemeData } from "@types";
import { findByProps } from "@metro/filters"; import { findByProps } from "@metro/filters";
import { ReactNative, chroma } from "@metro/common"; import { ReactNative, chroma } from "@metro/common";
import { instead } from "@lib/patcher"; import { instead } from "@lib/patcher";
@ -9,7 +9,7 @@ import { safeFetch } from "@utils";
// Somehow, this is late enough, though? // Somehow, this is late enough, though?
export const color = findByProps("SemanticColor"); export const color = findByProps("SemanticColor");
export const themes = wrapSync(createStorage<Indexable<Theme>>(createMMKVBackend("VENDETTA_THEMES"))); export const themes = wrapSync(createStorage<Record<string, Theme>>(createMMKVBackend("VENDETTA_THEMES")));
async function writeTheme(theme: Theme | {}) { async function writeTheme(theme: Theme | {}) {
if (typeof theme !== "object") throw new Error("Theme must be an object"); if (typeof theme !== "object") throw new Error("Theme must be an object");

View file

@ -1,8 +1,8 @@
import { Asset, Indexable } from "@types"; import { Asset } from "@types";
import { assets } from "@metro/common"; import { assets } from "@metro/common";
import { after } from "@lib/patcher"; import { after } from "@lib/patcher";
export const all: Indexable<Asset> = {}; export const all: Record<string, Asset> = {};
export function patchAssets() { export function patchAssets() {
const unpatch = after("registerAsset", assets, (args: Asset[], id: number) => { const unpatch = after("registerAsset", assets, (args: Asset[], id: number) => {

View file

@ -1,4 +1,3 @@
import { Indexable } from "@types";
import { ReactNative as RN } from "@metro/common"; import { ReactNative as RN } from "@metro/common";
import { useProxy } from "@lib/storage"; import { useProxy } from "@lib/storage";
import { HelpMessage, ErrorBoundary, Search } from "@ui/components"; import { HelpMessage, ErrorBoundary, Search } from "@ui/components";
@ -6,7 +5,7 @@ import { CardWrapper } from "@ui/settings/components/Card";
import settings from "@lib/settings"; import settings from "@lib/settings";
interface AddonPageProps<T> { interface AddonPageProps<T> {
items: Indexable<T & { id: string }>; items: Record<string, T & { id: string }>;
safeModeMessage: string; safeModeMessage: string;
safeModeExtras?: JSX.Element | JSX.Element[]; safeModeExtras?: JSX.Element | JSX.Element[];
card: React.ComponentType<CardWrapper<T>>; card: React.ComponentType<CardWrapper<T>>;