From 4da4827bcbcdd1ef163f635d9b29416ff272b0bb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 12:48:14 -0500 Subject: Add JSDoc type annotations to project (rebased) --- types/dev/dictionary-validate.d.ts | 31 ++++++++++ types/dev/manifest.d.ts | 112 +++++++++++++++++++++++++++++++++++++ types/dev/schema-validate.d.ts | 24 ++++++++ types/dev/vm.d.ts | 59 +++++++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 types/dev/dictionary-validate.d.ts create mode 100644 types/dev/manifest.d.ts create mode 100644 types/dev/schema-validate.d.ts create mode 100644 types/dev/vm.d.ts (limited to 'types/dev') diff --git a/types/dev/dictionary-validate.d.ts b/types/dev/dictionary-validate.d.ts new file mode 100644 index 00000000..c39f4335 --- /dev/null +++ b/types/dev/dictionary-validate.d.ts @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import type * as SchemaValidate from './schema-validate'; + +export type Schema = SchemaValidate.Schema; + +export type Schemas = { + index: Schema; + kanjiBankV1: Schema; + kanjiBankV3: Schema; + kanjiMetaBankV3: Schema; + tagBankV3: Schema; + termBankV1: Schema; + termBankV3: Schema; + termMetaBankV3: Schema; +}; diff --git a/types/dev/manifest.d.ts b/types/dev/manifest.d.ts new file mode 100644 index 00000000..4fdf3b14 --- /dev/null +++ b/types/dev/manifest.d.ts @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +export type Manifest = { + manifest: chrome.runtime.Manifest; + defaultVariant: string; + variants: ManifestVariant[]; +}; + +export type ManifestVariant = { + name: string; + buildable?: boolean; + inherit?: string; + fileName?: string; + fileCopies?: string[]; + excludeFiles?: string[]; + modifications: Modification[]; +}; + +export type Modification = ( + ModificationReplace | + ModificationDelete | + ModificationSet | + ModificationAdd | + ModificationRemove | + ModificationSplice | + ModificationCopy | + ModificationMove +); + +export type ModificationReplace = { + action: 'replace'; + path: PropertyPath; + pattern: string; + patternFlags: string; + replacement: string; +}; + +export type ModificationDelete = { + action: 'delete'; + path: PropertyPath; +}; + +export type ModificationSet = { + action: 'set'; + path: PropertyPath; + value: unknown; + before?: string; + after?: string; + index?: number; + command?: Command; +}; + +export type ModificationAdd = { + action: 'add'; + path: PropertyPath; + items: unknown[]; +}; + +export type ModificationRemove = { + action: 'remove'; + path: PropertyPath; + item: unknown; +}; + +export type ModificationSplice = { + action: 'splice'; + path: PropertyPath; + start: number; + deleteCount: number; + items: unknown[]; +}; + +export type ModificationCopy = { + action: 'copy'; + path: PropertyPath; + newPath: PropertyPath; + before?: string; + after?: string; + index?: number; +}; + +export type ModificationMove = { + action: 'move'; + path: PropertyPath; + newPath: PropertyPath; + before?: string; + after?: string; + index?: number; +}; + +export type PropertyPath = (string | number)[]; + +export type Command = { + command: string; + args: string[]; + trim: boolean; +}; diff --git a/types/dev/schema-validate.d.ts b/types/dev/schema-validate.d.ts new file mode 100644 index 00000000..b30c8a04 --- /dev/null +++ b/types/dev/schema-validate.d.ts @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import type * as AjvModule from 'ajv'; + +export type ValidateMode = 'ajv' | null; + +export type Schema = unknown; + +export type Ajv = typeof AjvModule.default; diff --git a/types/dev/vm.d.ts b/types/dev/vm.d.ts new file mode 100644 index 00000000..f103de97 --- /dev/null +++ b/types/dev/vm.d.ts @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import type * as Translation from '../ext/translation'; + +export type PseudoURL = { + hash: string; + host: string; + hostname: string; + href: string; + toString(): string; + origin: string; + password: string; + pathname: string; + port: string; + protocol: string; + search: string; + searchParams: URLSearchParams; + username: string; + toJSON(): string; +}; + +export type VMAssert = { + deepStrictEqual: (actual: unknown, expected: unknown) => void; +}; + +export type PseudoChrome = { + runtime: { + getURL(path: string): string; + }; +}; + +export type PseudoFetchResponse = { + ok: boolean; + status: number; + statusText: string; + text(): Promise; + json(): Promise; +}; + +export type OptionsPresetObject = { + [key: string]: OptionsPreset; +}; + +export type OptionsPreset = Partial; -- cgit v1.2.3 From 4a14a0ff0105bf29f2f9368f175c0c17f54a1921 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 29 Nov 2023 20:14:22 -0500 Subject: Update manifest types --- dev/manifest-util.js | 16 ++++++++-------- types/dev/manifest.d.ts | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'types/dev') diff --git a/dev/manifest-util.js b/dev/manifest-util.js index 1efc8cfc..638706d8 100644 --- a/dev/manifest-util.js +++ b/dev/manifest-util.js @@ -36,8 +36,8 @@ function clone(value) { export class ManifestUtil { constructor() { const fileName = path.join(dirname, 'data', 'manifest-variants.json'); - const {manifest, variants, defaultVariant} = /** @type {import('dev/manifest').Manifest} */ (JSON.parse(fs.readFileSync(fileName, {encoding: 'utf8'}))); - /** @type {chrome.runtime.Manifest} */ + const {manifest, variants, defaultVariant} = /** @type {import('dev/manifest').ManifestConfig} */ (JSON.parse(fs.readFileSync(fileName, {encoding: 'utf8'}))); + /** @type {import('dev/manifest').Manifest} */ this._manifest = manifest; /** @type {import('dev/manifest').ManifestVariant[]} */ this._variants = variants; @@ -52,7 +52,7 @@ export class ManifestUtil { /** * @param {?string} [variantName] - * @returns {chrome.runtime.Manifest} + * @returns {import('dev/manifest').Manifest} */ getManifest(variantName) { if (typeof variantName === 'string') { @@ -88,7 +88,7 @@ export class ManifestUtil { } /** - * @param {chrome.runtime.Manifest} manifest + * @param {import('dev/manifest').Manifest} manifest * @returns {string} */ static createManifestString(manifest) { @@ -119,9 +119,9 @@ export class ManifestUtil { } /** - * @param {chrome.runtime.Manifest} manifest + * @param {import('dev/manifest').Manifest} manifest * @param {import('dev/manifest').Modification[]} modifications - * @returns {chrome.runtime.Manifest} + * @returns {import('dev/manifest').Manifest} */ _applyModifications(manifest, modifications) { if (Array.isArray(modifications)) { @@ -328,9 +328,9 @@ export class ManifestUtil { } /** - * @param {chrome.runtime.Manifest} manifest + * @param {import('dev/manifest').Manifest} manifest * @param {import('dev/manifest').ManifestVariant} variant - * @returns {chrome.runtime.Manifest} + * @returns {import('dev/manifest').Manifest} */ _createVariantManifest(manifest, variant) { let modifiedManifest = clone(manifest); diff --git a/types/dev/manifest.d.ts b/types/dev/manifest.d.ts index 4fdf3b14..e455208f 100644 --- a/types/dev/manifest.d.ts +++ b/types/dev/manifest.d.ts @@ -15,8 +15,10 @@ * along with this program. If not, see . */ -export type Manifest = { - manifest: chrome.runtime.Manifest; +export type Manifest = chrome.runtime.Manifest; + +export type ManifestConfig = { + manifest: Manifest; defaultVariant: string; variants: ManifestVariant[]; }; -- cgit v1.2.3 From 97bc188ca6beb2057ab734e791b1afe96b6e4650 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 3 Dec 2023 11:15:50 -0500 Subject: Remove unused types --- types/dev/vm.d.ts | 21 -------------------- types/ext/anki-templates.d.ts | 6 ------ types/ext/backend.d.ts | 33 -------------------------------- types/ext/event-listener-collection.d.ts | 6 ------ types/ext/offscreen.d.ts | 2 -- types/ext/request-builder.d.ts | 5 ----- types/ext/settings.d.ts | 2 -- 7 files changed, 75 deletions(-) (limited to 'types/dev') diff --git a/types/dev/vm.d.ts b/types/dev/vm.d.ts index f103de97..3eb0949f 100644 --- a/types/dev/vm.d.ts +++ b/types/dev/vm.d.ts @@ -17,27 +17,6 @@ import type * as Translation from '../ext/translation'; -export type PseudoURL = { - hash: string; - host: string; - hostname: string; - href: string; - toString(): string; - origin: string; - password: string; - pathname: string; - port: string; - protocol: string; - search: string; - searchParams: URLSearchParams; - username: string; - toJSON(): string; -}; - -export type VMAssert = { - deepStrictEqual: (actual: unknown, expected: unknown) => void; -}; - export type PseudoChrome = { runtime: { getURL(path: string): string; diff --git a/types/ext/anki-templates.d.ts b/types/ext/anki-templates.d.ts index c7e49905..5c40f406 100644 --- a/types/ext/anki-templates.d.ts +++ b/types/ext/anki-templates.d.ts @@ -47,12 +47,6 @@ export type MediaSimpleType = ( 'selectionText' ); -export type MediaType = ( - MediaSimpleType | - 'textFurigana' | - 'dictionaryMedia' -); - export type TextFuriganaSegment = { text: string; readingMode: TextFuriganaReadingMode; diff --git a/types/ext/backend.d.ts b/types/ext/backend.d.ts index 5f1bd83d..08cbf4b0 100644 --- a/types/ext/backend.d.ts +++ b/types/ext/backend.d.ts @@ -47,39 +47,6 @@ export type TabInfo = { url: string | null; }; -export type SettingModification = SettingModificationSet | SettingModificationDelete | SettingModificationSwap | SettingModificationSplice | SettingModificationPush; - -export type SettingModificationSet = { - action: 'set'; - path: string; - value: unknown; -}; - -export type SettingModificationDelete = { - action: 'delete'; - path: string; -}; - -export type SettingModificationSwap = { - action: 'swap'; - path1: string; - path2: string; -}; - -export type SettingModificationSplice = { - action: 'splice'; - path: string; - start: number; - deleteCount: number; - items: unknown[]; -}; - -export type SettingModificationPush = { - action: 'push'; - path: string; - items: unknown[]; -}; - export type FindTabsPredicate = (tabInfo: TabInfo) => boolean | Promise; export type InvokeWithProgressRequestMessage = ( diff --git a/types/ext/event-listener-collection.d.ts b/types/ext/event-listener-collection.d.ts index f22d6bcc..eee05658 100644 --- a/types/ext/event-listener-collection.d.ts +++ b/types/ext/event-listener-collection.d.ts @@ -69,12 +69,6 @@ export type AddEventListenerArgs = [ options?: AddEventListenerOptions | boolean, ]; -export type AddListenerArgs = [ - target: ExtensionEvent, - callback: TCallback, - ...args: TArgs[], -]; - export type OnArgs = [ target: EventDispatcher, eventName: string, diff --git a/types/ext/offscreen.d.ts b/types/ext/offscreen.d.ts index ddf7eadc..85bce1ff 100644 --- a/types/ext/offscreen.d.ts +++ b/types/ext/offscreen.d.ts @@ -24,8 +24,6 @@ import type * as Environment from './environment'; import type * as Translation from './translation'; import type * as Translator from './translator'; -export type MessageAny2 = Message; - export type Message = ( MessageDetailsMap[T] extends undefined ? {action: T} : diff --git a/types/ext/request-builder.d.ts b/types/ext/request-builder.d.ts index 8f375754..b231bcd7 100644 --- a/types/ext/request-builder.d.ts +++ b/types/ext/request-builder.d.ts @@ -15,9 +15,4 @@ * along with this program. If not, see . */ -export type FetchEventListeners = { - onBeforeSendHeaders: ((details: chrome.webRequest.WebRequestHeadersDetails) => (chrome.webRequest.BlockingResponse | void)) | null; - onErrorOccurred: ((details: chrome.webRequest.WebResponseErrorDetails) => void) | null; -}; - export type ProgressCallback = (complete: boolean) => void; diff --git a/types/ext/settings.d.ts b/types/ext/settings.d.ts index 19c4aa1f..8ce82b28 100644 --- a/types/ext/settings.d.ts +++ b/types/ext/settings.d.ts @@ -283,8 +283,6 @@ export type AnkiOptions = { downloadTimeout: number; }; -export type AnkiCardType = 'terms' | 'kanji'; - export type AnkiScreenshotOptions = { format: AnkiScreenshotFormat; quality: number; -- cgit v1.2.3