/ src / storage / blockedTags / index.ts
index.ts
 1  import { storage } from 'wxt/storage';
 2  
 3  import type { ToReadonly } from '@/types/util';
 4  import type { Logger } from '@/utils/logger';
 5  
 6  import { PhrasesBlocklistStorage } from '../phrasesBlocklist';
 7  import type { StorageMeta, StorageSyncMeta } from '../types';
 8  import { blockedTagsMigrations } from './migrations';
 9  import type { BlockedTags, RawBlockedTags } from './types';
10  
11  export type { IsBlockedFn as IsHaveBlockedTagsFn } from '../phrasesBlocklist';
12  export type { BlockedTags, RawBlockedTags } from './types';
13  
14  export interface BlockedTagsMeta extends StorageMeta, StorageSyncMeta {}
15  
16  export type ReadonlyBlockedTags = ToReadonly<BlockedTags>;
17  
18  const key = 'blockedTags' as const,
19  	metaKey = `${key}$` as const;
20  
21  export const blockedTagsVersion = 1;
22  
23  const fallbackValue: RawBlockedTags = '';
24  
25  const blockedTagsItem = storage.defineItem<RawBlockedTags, BlockedTagsMeta>(`local:${key}`, {
26  	version: blockedTagsVersion,
27  	fallback: fallbackValue,
28  	migrations: blockedTagsMigrations,
29  });
30  
31  export class BlockedTagsStorage extends PhrasesBlocklistStorage<typeof key, typeof metaKey> {
32  	static readonly KEY = key;
33  	static readonly META_KEY = metaKey;
34  	static readonly STORAGE = blockedTagsItem;
35  	static readonly MIGRATIONS = undefined;
36  	protected readonly logger: Logger;
37  	protected readonly version = blockedTagsVersion;
38  
39  	constructor(tabId: number | undefined, source: string, logger: Logger) {
40  		const childLogger = logger.getChildLogger('BlockedTagsStorage');
41  		super(tabId, source, childLogger, new.target.KEY, new.target.META_KEY, new.target.STORAGE);
42  		Object.setPrototypeOf(this, new.target.prototype);
43  		this.logger = childLogger;
44  	}
45  }