Skip to content

Commit

Permalink
Merge branch 'dev' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Casheeew committed Dec 10, 2023
2 parents 56de831 + fa209b4 commit 15f2f6e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 11 deletions.
29 changes: 29 additions & 0 deletions ext/js/data/anki-note-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ import {TemplateRendererProxy} from '../templates/template-renderer-proxy.js';
import {yomitan} from '../yomitan.js';
import {AnkiUtil} from './anki-util.js';

/**
* Anki Note Builder Class.
*/
export class AnkiNoteBuilder {
/**
* Initiate an instance of AnkiNoteBuilder.
* @param {{japaneseUtil: import('../language/sandbox/japanese-util.js').JapaneseUtil}} details
* @example
* const japaneseUtil = new JapaneseUtil(null);
* const ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil});
*/
constructor({japaneseUtil}) {
/** @type {import('../language/sandbox/japanese-util.js').JapaneseUtil} */
Expand All @@ -40,8 +47,30 @@ export class AnkiNoteBuilder {
}

/**
* Creates an Anki note.
* @param {import('anki-note-builder').CreateNoteDetails} details
* @returns {Promise<import('anki-note-builder').CreateNoteResult>}
* @example
* const ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil});
* const details = {
* dictionaryEntry,
* mode: 'test',
* context,
* template,
* deckName: 'deckName',
* modelName: 'modelName',
* fields,
* tags: ['yomitan'],
* checkForDuplicates: true,
* duplicateScope: 'collection',
* duplicateScopeCheckAllModels: false,
* resultOutputMode: mode,
* glossaryLayoutMode: 'default',
* compactTags: false,
* requirements: [],
* mediaOptions: null
* };
* const {note: {fields: noteFields}, errors} = await ankiNoteBuilder.createNote(details);
*/
async createNote({
dictionaryEntry,
Expand Down
19 changes: 16 additions & 3 deletions ext/js/data/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

/**
* Database class to store objects.
* @template {string} TObjectStoreName
*/
export class Database {
Expand All @@ -28,6 +29,7 @@ export class Database {
}

/**
* Opens the DB.
* @param {string} databaseName
* @param {number} version
* @param {import('database').StructureDefinition<TObjectStoreName>[]} structure
Expand All @@ -51,6 +53,7 @@ export class Database {
}

/**
* Closes the DB.
* @throws {Error}
*/
close() {
Expand All @@ -63,20 +66,23 @@ export class Database {
}

/**
* Returns true if DB opening is in process.
* @returns {boolean}
*/
isOpening() {
return this._isOpening;
}

/**
* Returns true if the DB is open.
* @returns {boolean}
*/
isOpen() {
return this._db !== null;
}

/**
* Returns a new transaction with the given mode ("readonly" or "readwrite") and scope which can be a single object store name or an array of names.
* @param {string[]} storeNames
* @param {IDBTransactionMode} mode
* @returns {IDBTransaction}
Expand All @@ -90,10 +96,12 @@ export class Database {
}

/**
* Add items in bulk to the object store.
* *count* items will be added beginning from *start* index of *items* list.
* @param {TObjectStoreName} objectStoreName
* @param {unknown[]} items
* @param {number} start
* @param {number} count
* @param {unknown[]} items - List of items to add.
* @param {number} start - Start index. Added items begin at items[start].
* @param {number} count - Count of items to add.
* @returns {Promise<void>}
*/
bulkAdd(objectStoreName, items, start, count) {
Expand Down Expand Up @@ -244,6 +252,7 @@ export class Database {
}

/**
* Deletes records in store with the given key or in the given key range in query.
* @param {TObjectStoreName} objectStoreName
* @param {IDBValidKey|IDBKeyRange} key
* @returns {Promise<void>}
Expand All @@ -258,6 +267,7 @@ export class Database {
}

/**
* Delete items in bulk from the object store.
* @param {TObjectStoreName} objectStoreName
* @param {?string} indexName
* @param {IDBKeyRange} query
Expand Down Expand Up @@ -291,6 +301,9 @@ export class Database {
}

/**
* Attempts to delete the named database.
* If the database already exists and there are open connections that don't close in response to a versionchange event, the request will be blocked until all they close.
* If the request is successful request's result will be null.
* @param {string} databaseName
* @returns {Promise<void>}
*/
Expand Down
3 changes: 2 additions & 1 deletion ext/js/language/deinflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ export class Deinflector {
}

/**
* Deinflects a Japanese term to its dictionary form.
* Deinflects a Japanese term to all of its possible dictionary forms.
* @param {string} source - The source term to deinflect.
* @returns {import('translation-internal').Deinflection[]}
* @example
* const deinflector = new Deinflector(deinflectionReasons);
* // [{ term: '食べた', rules: 0, reasons: [] }, { term: '食べる', rules: 1, reasons: ['past'] }, { term: '食ぶ', rules: 2, reasons: ['potential', 'past'] }]
* console.log(deinflector.deinflect('食べさせられる'));
*/
deinflect(source) {
Expand Down
28 changes: 21 additions & 7 deletions ext/js/language/dictionary-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import {log, stringReverse} from '../core.js';
import {Database} from '../data/database.js';

/**
* This class represents the dictionary database.
*/
export class DictionaryDatabase {
constructor() {
/** @type {Database<import('dictionary-database').ObjectStoreName>} */
Expand Down Expand Up @@ -141,6 +144,7 @@ export class DictionaryDatabase {
}

/**
* Purges the database.
* @returns {Promise<boolean>}
*/
async purge() {
Expand All @@ -162,6 +166,7 @@ export class DictionaryDatabase {
}

/**
* Deletes a dictionary.
* @param {string} dictionaryName
* @param {number} progressRate
* @param {import('dictionary-database').DeleteDictionaryProgressCallback} onProgress
Expand Down Expand Up @@ -225,9 +230,10 @@ export class DictionaryDatabase {
}

/**
* @param {string[]} termList
* @param {import('dictionary-database').DictionarySet} dictionaries
* @param {import('dictionary-database').MatchType} matchType
* Find terms in bulk.
* @param {string[]} termList - The list of terms to find.
* @param {import('dictionary-database').DictionarySet} dictionaries - Dictionaries to find the terms from.
* @param {import('dictionary-database').MatchType} matchType - Matching type.
* @returns {Promise<import('dictionary-database').TermEntry[]>}
*/
findTermsBulk(termList, dictionaries, matchType) {
Expand Down Expand Up @@ -259,8 +265,9 @@ export class DictionaryDatabase {
}

/**
* @param {import('dictionary-database').TermExactRequest[]} termList
* @param {import('dictionary-database').DictionarySet} dictionaries
* Find exact terms in bulk.
* @param {import('dictionary-database').TermExactRequest[]} termList - The list of terms to find.
* @param {import('dictionary-database').DictionarySet} dictionaries - Dictionaries to find the term from.
* @returns {Promise<import('dictionary-database').TermEntry[]>}
*/
findTermsExactBulk(termList, dictionaries) {
Expand All @@ -270,6 +277,7 @@ export class DictionaryDatabase {
}

/**
* Find terms by sequence in bulk.
* @param {import('dictionary-database').DictionaryAndQueryRequest[]} items
* @returns {Promise<import('dictionary-database').TermEntry[]>}
*/
Expand All @@ -280,6 +288,7 @@ export class DictionaryDatabase {
}

/**
* Find term meta in bulk.
* @param {string[]} termList
* @param {import('dictionary-database').DictionarySet} dictionaries
* @returns {Promise<import('dictionary-database').TermMeta[]>}
Expand All @@ -291,8 +300,9 @@ export class DictionaryDatabase {
}

/**
* @param {string[]} kanjiList
* @param {import('dictionary-database').DictionarySet} dictionaries
* Find kanji in bulk.
* @param {string[]} kanjiList - The list of kanji to find.
* @param {import('dictionary-database').DictionarySet} dictionaries - Dictionaries to find from.
* @returns {Promise<import('dictionary-database').KanjiEntry[]>}
*/
findKanjiBulk(kanjiList, dictionaries) {
Expand All @@ -302,6 +312,7 @@ export class DictionaryDatabase {
}

/**
* Find kanji meta in bulk.
* @param {string[]} kanjiList
* @param {import('dictionary-database').DictionarySet} dictionaries
* @returns {Promise<import('dictionary-database').KanjiMeta[]>}
Expand All @@ -313,6 +324,7 @@ export class DictionaryDatabase {
}

/**
* Find tag meta in bulk.
* @param {import('dictionary-database').DictionaryAndQueryRequest[]} items
* @returns {Promise<(import('dictionary-database').Tag|undefined)[]>}
*/
Expand All @@ -323,6 +335,7 @@ export class DictionaryDatabase {
}

/**
* Find tag for title.
* @param {string} name
* @param {string} dictionary
* @returns {Promise<?import('dictionary-database').Tag>}
Expand All @@ -343,6 +356,7 @@ export class DictionaryDatabase {
}

/**
* Get dictionary metadata.
* @returns {Promise<import('dictionary-importer').Summary[]>}
*/
getDictionaryInfo() {
Expand Down

0 comments on commit 15f2f6e

Please sign in to comment.