aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data
diff options
context:
space:
mode:
authorCashew <52880648+Scrub1492@users.noreply.github.com>2023-12-19 12:44:40 +0900
committerGitHub <noreply@github.com>2023-12-19 03:44:40 +0000
commitc661eafa7d57c32e33e51dd6eb787b97832e97f0 (patch)
tree1a68a563f9f1960d528595d6b33f74cb506bd77e /ext/js/data
parenteb7bf9542c92ea7937d4b4a699ae2d47270da96b (diff)
Add some JSDoc annotations to describe code functionality. (#355)
* lesen-tan initial commit * update README.md * tidy up code * opt for Map<K, V> instead of Object * Document dev/* * add docs for deinflector.js * update deinflector example * Annotate * Revert "Merge branch 'development' of https://github.com/Scrub1492/lesen-tan into development" This reverts commit b92348f702bc031b36f24462adfa940d17f9ecdd, reversing changes made to 3255e6d963281af3533dcf1e893df39032d29fec. * Lint error fix * Lint error fix
Diffstat (limited to 'ext/js/data')
-rw-r--r--ext/js/data/anki-note-builder.js29
-rw-r--r--ext/js/data/database.js19
2 files changed, 45 insertions, 3 deletions
diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js
index 864bd2d4..80cc210a 100644
--- a/ext/js/data/anki-note-builder.js
+++ b/ext/js/data/anki-note-builder.js
@@ -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} */
@@ -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,
diff --git a/ext/js/data/database.js b/ext/js/data/database.js
index 8b9e7354..cb09a680 100644
--- a/ext/js/data/database.js
+++ b/ext/js/data/database.js
@@ -17,6 +17,7 @@
*/
/**
+ * Database class to store objects.
* @template {string} TObjectStoreName
*/
export class Database {
@@ -28,6 +29,7 @@ export class Database {
}
/**
+ * Opens the DB.
* @param {string} databaseName
* @param {number} version
* @param {import('database').StructureDefinition<TObjectStoreName>[]} structure
@@ -51,6 +53,7 @@ export class Database {
}
/**
+ * Closes the DB.
* @throws {Error}
*/
close() {
@@ -63,6 +66,7 @@ export class Database {
}
/**
+ * Returns true if DB opening is in process.
* @returns {boolean}
*/
isOpening() {
@@ -70,6 +74,7 @@ export class Database {
}
/**
+ * Returns true if the DB is open.
* @returns {boolean}
*/
isOpen() {
@@ -77,6 +82,7 @@ export class Database {
}
/**
+ * 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}
@@ -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) {
@@ -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>}
@@ -258,6 +267,7 @@ export class Database {
}
/**
+ * Delete items in bulk from the object store.
* @param {TObjectStoreName} objectStoreName
* @param {?string} indexName
* @param {IDBKeyRange} query
@@ -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>}
*/