diff --git a/docs/backend_api/BackendScriptApi.html b/docs/backend_api/BackendScriptApi.html index c3924360a..5618ff0d9 100644 --- a/docs/backend_api/BackendScriptApi.html +++ b/docs/backend_api/BackendScriptApi.html @@ -94,7 +94,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -240,7 +240,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -314,7 +314,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -386,7 +386,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -458,7 +458,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -530,7 +530,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -602,7 +602,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -674,7 +674,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -746,7 +746,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -922,7 +922,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -1441,7 +1441,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2075,7 +2075,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2602,7 +2602,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2803,7 +2803,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2985,7 +2985,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3186,7 +3186,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3337,7 +3337,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3538,7 +3538,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3640,7 +3640,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3701,6 +3701,160 @@ JSON MIME type. See also createNewNote() for more options. +

getAttachment(attachmentId) → {BAttachment|null}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attachmentId + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +BAttachment +| + +null + + +
+
+ + + + + + + + + + + + +

getAttribute(attributeId) → {BAttribute|null}

@@ -3798,7 +3952,161 @@ JSON MIME type. See also createNewNote() for more options.
Source:
+ + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +BAttribute +| + +null + + +
+
+ + + + + + + + + + + + + +

getAttribute(attributeId) → {BAttribute|null}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
attributeId + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
@@ -3952,7 +4260,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -4153,7 +4461,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -4210,6 +4518,262 @@ JSON MIME type. See also createNewNote() for more options. +

getEtapiToken(etapiTokenId) → {BEtapiToken|null}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
etapiTokenId + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +BEtapiToken +| + +null + + +
+
+ + + + + + + + + + + + + +

getEtapiTokens() → {Array.<BEtapiToken>}

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<BEtapiToken> + + +
+
+ + + + + + + + + + + + +

getInstanceName() → {string|null}

@@ -4263,7 +4827,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4328,7 +4892,7 @@ if some action needs to happen on only one specific instance.
- Returns month note for given date. If such note doesn't exist, it is created. + Returns month note for given date. If such a note doesn't exist, it is created.
@@ -4464,7 +5028,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4618,7 +5182,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4819,7 +5383,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5020,7 +5584,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5074,6 +5638,416 @@ if some action needs to happen on only one specific instance. +

getOption(optionName) → {BOption|null}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
optionName + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +BOption +| + +null + + +
+
+ + + + + + + + + + + + + +

getOptions() → {Array.<BOption>}

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array.<BOption> + + +
+
+ + + + + + + + + + + + + +

getRevision(revisionId) → {BRevision|null}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
revisionId + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +BRevision +| + +null + + +
+
+ + + + + + + + + + + + +

getRootCalendarNote() → {BNote|null}

@@ -5126,7 +6100,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5296,7 +6270,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5599,7 +6573,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5664,7 +6638,7 @@ if some action needs to happen on only one specific instance.
- Returns year note for given year. If such note doesn't exist, it is created. + Returns year note for given year. If such a note doesn't exist, it is created.
@@ -5800,7 +6774,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5953,7 +6927,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -6108,7 +7082,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -6175,7 +7149,7 @@ if some action needs to happen on only one specific instance.
Executes given anonymous function on the frontend(s). -Internally this serializes the anonymous function into string and sends it to frontend(s) via WebSocket. +Internally, this serializes the anonymous function into string and sends it to frontend(s) via WebSocket. Note that there can be multiple connected frontend instances (e.g. in different tabs). In such case, all instances execute the given function.
@@ -6293,7 +7267,7 @@ instances execute the given function.
Source:
@@ -6457,7 +7431,7 @@ you need to make some DB changes, you need to surround your call with api.transa
Source:
@@ -6660,7 +7634,7 @@ you need to make some DB changes, you need to surround your call with api.transa
Source:
@@ -6862,7 +7836,7 @@ you need to make some DB changes, you need to surround your call with api.transa
Source:
@@ -7071,7 +8045,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -7417,7 +8391,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -7641,7 +8615,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -7797,7 +8771,7 @@ exists, then we'll use that transaction.
Source:
@@ -7952,7 +8926,7 @@ exists, then we'll use that transaction.
Source:
diff --git a/docs/backend_api/global.html b/docs/backend_api/global.html index b110e0145..5ce1f70df 100644 --- a/docs/backend_api/global.html +++ b/docs/backend_api/global.html @@ -152,7 +152,7 @@
Source:
@@ -612,7 +612,7 @@ not for direct use.
Source:
diff --git a/docs/backend_api/services_backend_script_api.js.html b/docs/backend_api/services_backend_script_api.js.html index 61e8b1ef0..dedaa6f88 100644 --- a/docs/backend_api/services_backend_script_api.js.html +++ b/docs/backend_api/services_backend_script_api.js.html @@ -48,6 +48,7 @@ const specialNotesService = require("./special_notes"); const branchService = require("./branches"); const exportService = require("./export/zip"); const syncMutex = require("./sync_mutex.js"); +const optionsService = require("./options"); /** @@ -90,18 +91,18 @@ function BackendScriptApi(currentNote, apiParams) { /** * Axios library for HTTP requests. See {@link https://axios-http.com} for documentation - * @type {axios} + * @type {axios} * @deprecated use native (browser compatible) fetch() instead */ this.axios = axios; /** - * day.js library for date manipulation. See {@link https://day.js.org} for documentation + * day.js library for date manipulation. See {@link https://day.js.org} for documentation * @type {dayjs} */ this.dayjs = dayjs; - /** + /** * xml2js library for XML parsing. See {@link https://github.com/Leonidas-from-XIV/node-xml2js} for documentation - * @type {xml2js} + * @type {xml2js} */ this.xml2js = xml2js; @@ -134,6 +135,53 @@ function BackendScriptApi(currentNote, apiParams) { */ this.getAttribute = attributeId => becca.getAttribute(attributeId); + /** + * @method + * @param {string} attachmentId + * @returns {BAttachment|null} + */ + this.getAttachment = attachmentId => becca.getAttachment(attachmentId); + + /** + * @method + * @param {string} revisionId + * @returns {BRevision|null} + */ + this.getRevision = revisionId => becca.getRevision(revisionId); + + /** + * @method + * @param {string} etapiTokenId + * @returns {BEtapiToken|null} + */ + this.getEtapiToken = etapiTokenId => becca.getEtapiToken(etapiTokenId); + + /** + * @method + * @returns {BEtapiToken[]} + */ + this.getEtapiTokens = () => becca.getEtapiTokens(); + + /** + * @method + * @param {string} optionName + * @returns {BOption|null} + */ + this.getOption = optionName => becca.getOption(optionName); + + /** + * @method + * @returns {BOption[]} + */ + this.getOptions = () => optionsService.getOptions(); + + /** + * @method + * @param {string} attributeId + * @returns {BAttribute|null} + */ + this.getAttribute = attributeId => becca.getAttribute(attributeId); + /** * This is a powerful search method - you can search by attributes and their values, e.g.: * "#dateModified =* MONTH AND #log". See {@link https://github.com/zadam/trilium/wiki/Search} for full documentation for all options @@ -402,7 +450,7 @@ function BackendScriptApi(currentNote, apiParams) { this.getWeekNote = dateNoteService.getWeekNote; /** - * Returns month note for given date. If such note doesn't exist, it is created. + * Returns month note for given date. If such a note doesn't exist, it is created. * * @method * @param {string} date in YYYY-MM format @@ -412,7 +460,7 @@ function BackendScriptApi(currentNote, apiParams) { this.getMonthNote = dateNoteService.getMonthNote; /** - * Returns year note for given year. If such note doesn't exist, it is created. + * Returns year note for given year. If such a note doesn't exist, it is created. * * @method * @param {string} year in YYYY format @@ -498,7 +546,7 @@ function BackendScriptApi(currentNote, apiParams) { * @method * @returns {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version */ - this.getAppInfo = () => appInfo + this.getAppInfo = () => appInfo; /** * Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated. @@ -589,7 +637,7 @@ function BackendScriptApi(currentNote, apiParams) { /** * Executes given anonymous function on the frontend(s). - * Internally this serializes the anonymous function into string and sends it to frontend(s) via WebSocket. + * Internally, this serializes the anonymous function into string and sends it to frontend(s) via WebSocket. * Note that there can be multiple connected frontend instances (e.g. in different tabs). In such case, all * instances execute the given function. * diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html index bec8e5b9f..85072e613 100644 --- a/docs/frontend_api/FrontendScriptApi.html +++ b/docs/frontend_api/FrontendScriptApi.html @@ -462,7 +462,7 @@ available in the JS frontend notes. You can use e.g. api.showMessage(api.s
Source:
@@ -1530,7 +1530,7 @@ See https://day.js.org for documentation
Source:
@@ -1738,7 +1738,7 @@ See https://day.js.org for documentation
Source:
@@ -2157,7 +2157,7 @@ See https://day.js.org for documentation
Source:
@@ -2312,7 +2312,7 @@ See https://day.js.org for documentation
Source:
@@ -2469,7 +2469,7 @@ See https://day.js.org for documentation
Source:
@@ -2624,7 +2624,7 @@ See https://day.js.org for documentation
Source:
@@ -2730,7 +2730,7 @@ See https://day.js.org for documentation
Source:
@@ -2840,7 +2840,7 @@ See https://day.js.org for documentation
Source:
@@ -2946,7 +2946,7 @@ See https://day.js.org for documentation
Source:
@@ -3052,7 +3052,7 @@ See https://day.js.org for documentation
Source:
@@ -3162,7 +3162,7 @@ See https://day.js.org for documentation
Source:
@@ -3268,7 +3268,7 @@ See https://day.js.org for documentation
Source:
@@ -3379,7 +3379,7 @@ implementation of actual widget type.
Source:
@@ -3534,7 +3534,7 @@ implementation of actual widget type.
Source:
@@ -3689,7 +3689,7 @@ implementation of actual widget type.
Source:
@@ -3796,7 +3796,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -3898,7 +3898,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4057,7 +4057,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4213,7 +4213,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4315,7 +4315,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4520,7 +4520,7 @@ otherwise (by e.g. createLink())
Source:
@@ -4626,7 +4626,7 @@ otherwise (by e.g. createLink())
Source:
@@ -4781,7 +4781,7 @@ otherwise (by e.g. createLink())
Source:
@@ -4936,7 +4936,7 @@ otherwise (by e.g. createLink())
Source:
@@ -5086,7 +5086,7 @@ otherwise (by e.g. createLink())
Source:
@@ -5593,7 +5593,7 @@ otherwise (by e.g. createLink())
Source:
@@ -5771,7 +5771,7 @@ otherwise (by e.g. createLink())
Source:
@@ -5945,7 +5945,7 @@ otherwise (by e.g. createLink())
Source:
@@ -6100,7 +6100,7 @@ otherwise (by e.g. createLink())
Source:
@@ -6254,7 +6254,7 @@ otherwise (by e.g. createLink())
Source:
@@ -6409,7 +6409,7 @@ otherwise (by e.g. createLink())
Source:
@@ -6445,7 +6445,7 @@ otherwise (by e.g. createLink()) -

runOnBackend(script, params) → {Promise.<any>}

+

runAsyncOnBackendWithManualTransactionHandling(func, params) → {Promise.<*>}

@@ -6455,6 +6455,11 @@ otherwise (by e.g. createLink())
Executes given anonymous function on the backend. Internally this serializes the anonymous function into string and sends it to backend via AJAX. +This function is meant for advanced needs where an async function is necessary. +In this case, the automatic request-scoped transaction management is not applied, +and you need to manually define transaction via api.transactional(). + +If you have a synchronous function, please use api.runOnBackend().
@@ -6490,16 +6495,16 @@ Internally this serializes the anonymous function into string and sends it to ba - script + func -string +function | -function +string @@ -6509,7 +6514,7 @@ Internally this serializes the anonymous function into string and sends it to ba - script to be executed on the backend + (synchronous) function to be executed on the backend @@ -6522,7 +6527,7 @@ Internally this serializes the anonymous function into string and sends it to ba -Array.<any> +Array.<?> @@ -6573,7 +6578,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -6613,7 +6618,195 @@ Internally this serializes the anonymous function into string and sends it to ba
-Promise.<any> +Promise.<*> + + +
+
+ + + + + + + + + + + + + +

runOnBackend(func, params) → {Promise.<*>}

+ + + + + + +
+ Executes given anonymous function on the backend. +Internally this serializes the anonymous function into string and sends it to backend via AJAX. +Please make sure that the supplied function is synchronous. Only sync functions will work correctly +with transaction management. If you really know what you're doing, you can call api.runAsyncOnBackendWithManualTransactionHandling() +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +function +| + +string + + + + (synchronous) function to be executed on the backend
params + + +Array.<?> + + + + list of parameters to the anonymous function to be sent to backend
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ return value of the executed function on the backend +
+ + + +
+
+ Type +
+
+ +Promise.<*>
@@ -6733,7 +6926,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -6889,7 +7082,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7044,7 +7237,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7195,7 +7388,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7350,7 +7543,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7509,7 +7702,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7646,7 +7839,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7801,7 +7994,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -8033,7 +8226,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -8215,7 +8408,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -8375,7 +8568,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -8467,7 +8660,7 @@ Typical use case is when a new note has been created, we should wait until it is
Source:
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html index 8069c92dd..eded4a0c0 100644 --- a/docs/frontend_api/services_frontend_script_api.js.html +++ b/docs/frontend_api/services_frontend_script_api.js.html @@ -206,36 +206,73 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain } /** - * Executes given anonymous function on the backend. - * Internally this serializes the anonymous function into string and sends it to backend via AJAX. - * - * @method - * @param {string|Function} script - script to be executed on the backend - * @param {Array<any>} params - list of parameters to the anonymous function to be sent to backend - * @returns {Promise<any>} return value of the executed function on the backend + * @private */ - this.runOnBackend = async (script, params = []) => { - if (typeof script === "function") { - script = script.toString(); + this.__runOnBackendInner = async (func, params, transactional) => { + if (typeof func === "function") { + func = func.toString(); } const ret = await server.post('script/exec', { - script: script, + script: func, params: prepareParams(params), startNoteId: startNote.noteId, currentNoteId: currentNote.noteId, originEntityName: "notes", // currently there's no other entity on the frontend which can trigger event - originEntityId: originEntity ? originEntity.noteId : null + originEntityId: originEntity ? originEntity.noteId : null, + transactional }, "script"); if (ret.success) { await ws.waitForMaxKnownEntityChangeId(); return ret.executionResult; - } - else { + } else { throw new Error(`server error: ${ret.error}`); } + } + + /** + * Executes given anonymous function on the backend. + * Internally this serializes the anonymous function into string and sends it to backend via AJAX. + * Please make sure that the supplied function is synchronous. Only sync functions will work correctly + * with transaction management. If you really know what you're doing, you can call api.runAsyncOnBackendWithManualTransactionHandling() + * + * @method + * @param {function|string} func - (synchronous) function to be executed on the backend + * @param {Array.<?>} params - list of parameters to the anonymous function to be sent to backend + * @returns {Promise<*>} return value of the executed function on the backend + */ + this.runOnBackend = async (func, params = []) => { + if (func?.constructor.name === "AsyncFunction" || func?.startsWith?.("async ")) { + toastService.showError("You're passing an async function to api.runOnBackend() which will likely not work as you intended. " + + "Either make the function synchronous (by removing 'async' keyword), or use api.runAsyncOnBackendWithManualTransactionHandling()"); + } + + return await this.__runOnBackendInner(func, params, true); + }; + + /** + * Executes given anonymous function on the backend. + * Internally this serializes the anonymous function into string and sends it to backend via AJAX. + * This function is meant for advanced needs where an async function is necessary. + * In this case, the automatic request-scoped transaction management is not applied, + * and you need to manually define transaction via api.transactional(). + * + * If you have a synchronous function, please use api.runOnBackend(). + * + * @method + * @param {function|string} func - (synchronous) function to be executed on the backend + * @param {Array.<?>} params - list of parameters to the anonymous function to be sent to backend + * @returns {Promise<*>} return value of the executed function on the backend + */ + this.runAsyncOnBackendWithManualTransactionHandling = async (func, params = []) => { + if (func?.constructor.name === "Function" || func?.startsWith?.("function")) { + toastService.showError("You're passing a synchronous function to api.runAsyncOnBackendWithManualTransactionHandling(), " + + "while you should likely use api.runOnBackend() instead."); + } + + return await this.__runOnBackendInner(func, params, false); }; /** @@ -528,7 +565,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain * @param {string} date - e.g. "2019-04-29" * @returns {Promise<FNote>} */ - this.getWeekNote = dateNotesService.getWeekNote; + this.getWeekNote = dateNotesService.getWeekNote; /** * Returns month-note. If it doesn't exist, it is automatically created. diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index bbdc2b934..ba593f4c8 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -20,6 +20,7 @@ const specialNotesService = require("./special_notes"); const branchService = require("./branches"); const exportService = require("./export/zip"); const syncMutex = require("./sync_mutex.js"); +const optionsService = require("./options"); /** @@ -62,18 +63,18 @@ function BackendScriptApi(currentNote, apiParams) { /** * Axios library for HTTP requests. See {@link https://axios-http.com} for documentation - * @type {axios} + * @type {axios} * @deprecated use native (browser compatible) fetch() instead */ this.axios = axios; /** - * day.js library for date manipulation. See {@link https://day.js.org} for documentation + * day.js library for date manipulation. See {@link https://day.js.org} for documentation * @type {dayjs} */ this.dayjs = dayjs; - /** + /** * xml2js library for XML parsing. See {@link https://github.com/Leonidas-from-XIV/node-xml2js} for documentation - * @type {xml2js} + * @type {xml2js} */ this.xml2js = xml2js; @@ -106,6 +107,53 @@ function BackendScriptApi(currentNote, apiParams) { */ this.getAttribute = attributeId => becca.getAttribute(attributeId); + /** + * @method + * @param {string} attachmentId + * @returns {BAttachment|null} + */ + this.getAttachment = attachmentId => becca.getAttachment(attachmentId); + + /** + * @method + * @param {string} revisionId + * @returns {BRevision|null} + */ + this.getRevision = revisionId => becca.getRevision(revisionId); + + /** + * @method + * @param {string} etapiTokenId + * @returns {BEtapiToken|null} + */ + this.getEtapiToken = etapiTokenId => becca.getEtapiToken(etapiTokenId); + + /** + * @method + * @returns {BEtapiToken[]} + */ + this.getEtapiTokens = () => becca.getEtapiTokens(); + + /** + * @method + * @param {string} optionName + * @returns {BOption|null} + */ + this.getOption = optionName => becca.getOption(optionName); + + /** + * @method + * @returns {BOption[]} + */ + this.getOptions = () => optionsService.getOptions(); + + /** + * @method + * @param {string} attributeId + * @returns {BAttribute|null} + */ + this.getAttribute = attributeId => becca.getAttribute(attributeId); + /** * This is a powerful search method - you can search by attributes and their values, e.g.: * "#dateModified =* MONTH AND #log". See {@link https://github.com/zadam/trilium/wiki/Search} for full documentation for all options @@ -374,7 +422,7 @@ function BackendScriptApi(currentNote, apiParams) { this.getWeekNote = dateNoteService.getWeekNote; /** - * Returns month note for given date. If such note doesn't exist, it is created. + * Returns month note for given date. If such a note doesn't exist, it is created. * * @method * @param {string} date in YYYY-MM format @@ -384,7 +432,7 @@ function BackendScriptApi(currentNote, apiParams) { this.getMonthNote = dateNoteService.getMonthNote; /** - * Returns year note for given year. If such note doesn't exist, it is created. + * Returns year note for given year. If such a note doesn't exist, it is created. * * @method * @param {string} year in YYYY format @@ -470,7 +518,7 @@ function BackendScriptApi(currentNote, apiParams) { * @method * @returns {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version */ - this.getAppInfo = () => appInfo + this.getAppInfo = () => appInfo; /** * Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated. @@ -561,7 +609,7 @@ function BackendScriptApi(currentNote, apiParams) { /** * Executes given anonymous function on the frontend(s). - * Internally this serializes the anonymous function into string and sends it to frontend(s) via WebSocket. + * Internally, this serializes the anonymous function into string and sends it to frontend(s) via WebSocket. * Note that there can be multiple connected frontend instances (e.g. in different tabs). In such case, all * instances execute the given function. *