1
Fork 0

Add documentation.

This commit is contained in:
Bauke 2023-06-29 18:44:30 +02:00
parent 03d737b9cf
commit 009ff2e424
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
5 changed files with 40 additions and 0 deletions

View File

@ -1,3 +1,6 @@
/**
* Keys of feature names used in WebExtension storage.
*/
export enum Feature { export enum Feature {
AnonymizeUsernames = "anonymize-usernames", AnonymizeUsernames = "anonymize-usernames",
Autocomplete = "autocomplete", Autocomplete = "autocomplete",
@ -11,6 +14,9 @@ export enum Feature {
UsernameColors = "username-colors", UsernameColors = "username-colors",
} }
/**
* Keys of miscellaneous data stored in WebExtension storage.
*/
export enum Data { export enum Data {
EnabledFeatures = "enabled-features", EnabledFeatures = "enabled-features",
KnownGroups = "known-groups", KnownGroups = "known-groups",

View File

@ -8,6 +8,9 @@ export * from "./enums.js";
export * from "./username-color.js"; export * from "./username-color.js";
export * from "./user-label.js"; export * from "./user-label.js";
/**
* The data stored for the Hide Votes feature.
*/
export type HideVotesData = { export type HideVotesData = {
otherComments: boolean; otherComments: boolean;
otherTopics: boolean; otherTopics: boolean;
@ -15,6 +18,9 @@ export type HideVotesData = {
ownTopics: boolean; ownTopics: boolean;
}; };
/**
* All storage {@link Value}s stored in WebExtension storage.
*/
export const storageValues = { export const storageValues = {
[Data.EnabledFeatures]: createValue({ [Data.EnabledFeatures]: createValue({
deserialize: (input) => new Set(JSON.parse(input) as Feature[]), deserialize: (input) => new Set(JSON.parse(input) as Feature[]),
@ -65,8 +71,15 @@ export const storageValues = {
[Feature.UsernameColors]: collectUsernameColors(), [Feature.UsernameColors]: collectUsernameColors(),
}; };
/**
* Shorthand for the inferred shape of {@link storageValues}.
*/
type StorageValues = typeof storageValues; type StorageValues = typeof storageValues;
/**
* Return the {@link Value}-wrapped data associated with a particular key.
* @param key The key of the value to get from {@link storageValues}.
*/
export async function fromStorage<K extends keyof StorageValues>( export async function fromStorage<K extends keyof StorageValues>(
key: K, key: K,
): Promise<StorageValues[K]> { ): Promise<StorageValues[K]> {

View File

@ -1,3 +1,6 @@
/**
* The deserialize data function from version 1.1.2 and before.
*/
export function v112DeserializeData(data: Record<string, any>): { export function v112DeserializeData(data: Record<string, any>): {
userLabels: V112Settings["data"]["userLabels"]; userLabels: V112Settings["data"]["userLabels"];
usernameColors: V112Settings["data"]["usernameColors"]; usernameColors: V112Settings["data"]["usernameColors"];
@ -22,6 +25,9 @@ export function v112DeserializeData(data: Record<string, any>): {
return deserialized; return deserialized;
} }
/**
* The Settings data structure from version 1.1.2 and before.
*/
export type V112Settings = { export type V112Settings = {
[index: string]: any; [index: string]: any;
data: { data: {
@ -61,6 +67,9 @@ export type V112Settings = {
version: string; version: string;
}; };
/**
* A sample of the version 1.1.2 Settings data to use in testing.
*/
export const v112Sample: V112Settings = { export const v112Sample: V112Settings = {
data: { data: {
hideVotes: { hideVotes: {

View File

@ -2,6 +2,9 @@ import {createValue, type Value} from "@holllo/webextension-storage";
import browser from "webextension-polyfill"; import browser from "webextension-polyfill";
import {Feature} from "./enums.js"; import {Feature} from "./enums.js";
/**
* The data structure for a user label.
*/
export type UserLabel = { export type UserLabel = {
color: string; color: string;
id: number; id: number;
@ -10,6 +13,9 @@ export type UserLabel = {
username: string; username: string;
}; };
/**
* Shorthand for an array of {@link Value}-wrapped {@link UserLabel}s.
*/
export type UserLabelsData = Array<Value<UserLabel>>; export type UserLabelsData = Array<Value<UserLabel>>;
/** /**

View File

@ -2,12 +2,18 @@ import {type Value, createValue} from "@holllo/webextension-storage";
import browser from "webextension-polyfill"; import browser from "webextension-polyfill";
import {Feature} from "./enums.js"; import {Feature} from "./enums.js";
/**
* The data structure for a username color.
*/
export type UsernameColor = { export type UsernameColor = {
color: string; color: string;
id: number; id: number;
username: string; username: string;
}; };
/**
* Shorthand for an array of {@link Value}-wrapped {@link UsernameColor}s.
*/
export type UsernameColorsData = Array<Value<UsernameColor>>; export type UsernameColorsData = Array<Value<UsernameColor>>;
/** /**