From e84967ae6c1f56016a64b879efba4040ee11160d Mon Sep 17 00:00:00 2001 From: dragonwocky <thedragonring.bod@gmail.com> Date: Fri, 24 Dec 2021 23:30:55 +1100 Subject: [PATCH] env jsdoc changes --- insert/env/env.mjs | 5 +---- insert/env/fs.mjs | 17 +++++++---------- insert/env/storage.mjs | 23 ++++++++++------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/insert/env/env.mjs b/insert/env/env.mjs index f5010b9..31f13bd 100644 --- a/insert/env/env.mjs +++ b/insert/env/env.mjs @@ -6,10 +6,7 @@ 'use strict'; -/** - * environment-specific methods and constants - * @module notion-enhancer/api/env - */ +/** environment-specific methods and constants */ /** * the environment/platform name code is currently being executed in diff --git a/insert/env/fs.mjs b/insert/env/fs.mjs index 6f913f9..35feb82 100644 --- a/insert/env/fs.mjs +++ b/insert/env/fs.mjs @@ -6,15 +6,12 @@ 'use strict'; -/** - * environment-specific file reading - * @module notion-enhancer/api/fs - */ +/** environment-specific file reading */ /** * get an absolute path to files within notion * @param {string} path - relative to the root notion/resources/app/ e.g. renderer/search.js - * @runtime electron + * @process electron */ export const notionPath = globalThis.__enhancerElectronApi.notionPath; @@ -28,7 +25,7 @@ export const localPath = (path) => `notion://www.notion.so/__notion-enhancer/${p /** * fetch and parse a json file's contents * @param {string} path - a url or within-the-enhancer filepath - * @param {object} [opts] - the second argument of a fetch() request + * @param {object=} opts - the second argument of a fetch() request * @returns {object} the json value of the requested file as a js object */ export const getJSON = (path, opts = {}) => { @@ -37,7 +34,7 @@ export const getJSON = (path, opts = {}) => { if (networkPath) return fetch(path, opts).then((res) => res.json()); try { return globalThis.__enhancerElectronApi.nodeRequire(`notion-enhancer/${path}`); - } catch (err) { + } catch { return fetch(localPath(path), opts).then((res) => res.json()); } }; @@ -45,7 +42,7 @@ export const getJSON = (path, opts = {}) => { /** * fetch a text file's contents * @param {string} path - a url or within-the-enhancer filepath - * @param {object} [opts] - the second argument of a fetch() request + * @param {object=} opts - the second argument of a fetch() request * @returns {string} the text content of the requested file */ export const getText = (path, opts = {}) => { @@ -55,7 +52,7 @@ export const getText = (path, opts = {}) => { try { const fs = globalThis.__enhancerElectronApi.nodeRequire('fs'); return fs.readFileSync(notionPath(`notion-enhancer/${path}`)); - } catch (err) { + } catch { return fetch(localPath(path), opts).then((res) => res.text()); } }; @@ -73,7 +70,7 @@ export const isFile = async (path) => { } else { try { fs.existsSync(notionPath(`notion-enhancer/${path}`)); - } catch (err) { + } catch { await fetch(localPath(path)); } } diff --git a/insert/env/storage.mjs b/insert/env/storage.mjs index 032436a..5cca13a 100644 --- a/insert/env/storage.mjs +++ b/insert/env/storage.mjs @@ -6,15 +6,12 @@ 'use strict'; -/** - * environment-specific data persistence - * @module notion-enhancer/api/storage - */ +/** environment-specific data persistence */ /** * get persisted data - * @param {array<string>} path - the path of keys to the value being fetched - * @param {*} [fallback] - a default value if the path is not matched + * @param {string[]} path - the path of keys to the value being fetched + * @param {unknown=} fallback - a default value if the path is not matched * @returns {Promise} value ?? fallback */ export const get = (path, fallback = undefined) => { @@ -23,8 +20,8 @@ export const get = (path, fallback = undefined) => { /** * persist data - * @param {array<string>} path - the path of keys to the value being set - * @param {*} value - the data to save + * @param {string[]} path - the path of keys to the value being set + * @param {unknown} value - the data to save * @returns {Promise} resolves when data has been saved */ export const set = (path, value) => { @@ -33,9 +30,9 @@ export const set = (path, value) => { /** * create a wrapper for accessing a partition of the storage - * @param {array<string>} namespace - the path of keys to prefix all storage requests with - * @param {function} [get] - the storage get function to be wrapped - * @param {function} [set] - the storage set function to be wrapped + * @param {string[]} namespace - the path of keys to prefix all storage requests with + * @param {function=} get - the storage get function to be wrapped + * @param {function=} set - the storage set function to be wrapped * @returns {object} an object with the wrapped get/set functions */ export const db = (namespace, getFunc = get, setFunc = set) => { @@ -67,6 +64,6 @@ export const removeChangeListener = (callback) => { * @callback onStorageChangeCallback * @param {object} event * @param {string} event.path- the path of keys to the changed value - * @param {string} [event.new] - the new value being persisted to the store - * @param {string} [event.old] - the previous value associated with the key + * @param {string=} event.new - the new value being persisted to the store + * @param {string=} event.old - the previous value associated with the key */