- attributeId |
+ attachmentId |
@@ -3798,7 +3798,7 @@ Parameters:
Source:
@@ -3834,7 +3834,7 @@ Returns:
-BAttribute
+BAttachment
|
null
@@ -3855,7 +3855,7 @@ Returns:
- getBranch(branchId) → {BBranch|null}
+ getAttribute(attributeId) → {BAttribute|null}
@@ -3895,7 +3895,7 @@ Parameters:
- branchId |
+ attributeId |
@@ -3952,7 +3952,7 @@ Parameters:
Source:
@@ -3988,7 +3988,7 @@ Returns:
-BBranch
+BAttribute
|
null
@@ -4009,17 +4009,13 @@ Returns:
- getDayNote(date, rootNoteopt) → {BNote|null}
+ getAttribute(attributeId) → {BAttribute|null}
-
- Returns day note for given date. If such note doesn't exist, it is created.
-
-
@@ -4041,8 +4037,6 @@ Parameters:
Type |
- Attributes |
-
@@ -4055,7 +4049,7 @@ Parameters:
- date |
+ attributeId |
@@ -4068,51 +4062,164 @@ Parameters:
|
-
-
-
-
-
- |
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+ -
+ Type
+
+ -
+
+BAttribute
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+
+
- in YYYY-MM-DD format |
- |
+
+
+
+ getBranch(branchId) → {BBranch|null}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+
+
+
+ Description |
+
+
+
+
- rootNote |
+ branchId |
-BNote
+string
|
-
-
- <optional>
-
-
-
-
-
- |
-
- specify calendar root note, normally leave empty to use the default calendar |
+ |
@@ -4153,7 +4260,7 @@ Parameters:
Source:
@@ -4182,52 +4289,1065 @@ Returns:
-
-
- -
- Type
-
- -
+
+
+ -
+ Type
+
+ -
+
+BBranch
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getDayNote(date, rootNoteopt) → {BNote|null}
+
+
+
+
+
+
+
+ Returns day note for given date. If such note doesn't exist, it is created.
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+ Attributes |
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ date |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ in YYYY-MM-DD format |
+
+
+
+
+
+
+ rootNote |
+
+
+
+
+
+BNote
+
+
+
+ |
+
+
+
+
+ <optional>
+
+
+
+
+
+ |
+
+
+
+
+ specify calendar root note, normally leave empty to use the default calendar |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+ -
+ Type
+
+ -
+
+BNote
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getEtapiToken(etapiTokenId) → {BEtapiToken|null}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ etapiTokenId |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+ -
+ Type
+
+ -
+
+BEtapiToken
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getEtapiTokens() → {Array.<BEtapiToken>}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+ -
+ Type
+
+ -
+
+Array.<BEtapiToken>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getInstanceName() → {string|null}
+
+
+
+
+
+
+
+ Instance name identifies particular Trilium instance. It can be useful for scripts
+if some action needs to happen on only one specific instance.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+ -
+ Type
+
+ -
+
+string
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getMonthNote(date, rootNoteopt) → {BNote|null}
+
+
+
+
+
+
+
+ Returns month note for given date. If such a note doesn't exist, it is created.
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+ Attributes |
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ date |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ in YYYY-MM format |
+
+
+
+
+
+
+ rootNote |
+
+
+
+
+
+BNote
+
+
+
+ |
+
+
+
+
+ <optional>
+
+
+
+
+
+ |
+
+
+
+
+ specify calendar root note, normally leave empty to use the default calendar |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+ -
+ Type
+
+ -
+
+BNote
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getNote(noteId) → {BNote|null}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ noteId |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+ -
+ Type
+
+ -
+
+BNote
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getNoteWithLabel(name, valueopt) → {BNote|null}
+
+
+
+
+
+
+
+ Retrieves first note with given label name & value
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+ Attributes |
+
+
-BNote
-|
-null
+ Description |
+
+
+
+
-
-
+
+
+ name |
+
-
+
+
+
+string
+
+ |
+
+
+
+
-
+
+ |
-
+
-
- getInstanceName() → {string|null}
-
+ attribute name |
+
+
+
+ value |
+
+
+
+
+string
-
- Instance name identifies particular Trilium instance. It can be useful for scripts
-if some action needs to happen on only one specific instance.
-
+
+ |
+
+
+
+ <optional>
+
+
+
+ |
+
+
+ attribute value |
+
+
+
+
@@ -4263,7 +5383,7 @@ getIns
- Source:
@@ -4299,7 +5419,7 @@ Returns:
-
-string
+BNote
|
null
@@ -4320,7 +5440,7 @@
Returns:
- getMonthNote(date, rootNoteopt) → {BNote|null}
+ getNotesWithLabel(name, valueopt) → {Array.<BNote>}
@@ -4328,7 +5448,7 @@ getMonthN
- Returns month note for given date. If such note doesn't exist, it is created.
+ Retrieves notes with given label name & value
@@ -4366,7 +5486,7 @@ Parameters:
- date |
+ name |
@@ -4390,20 +5510,20 @@ Parameters:
- | in YYYY-MM format |
+ attribute name |
- rootNote |
+ value |
-BNote
+string
@@ -4423,7 +5543,7 @@ Parameters:
- | specify calendar root note, normally leave empty to use the default calendar |
+ attribute value |
@@ -4464,7 +5584,7 @@ Parameters:
- Source:
@@ -4500,10 +5620,7 @@ Returns:
-
-BNote
-|
-
-null
+Array.<BNote>
@@ -4521,7 +5638,7 @@ Returns:
- getNote(noteId) → {BNote|null}
+ getOption(optionName) → {BOption|null}
@@ -4561,7 +5678,7 @@ Parameters:
- noteId |
+ optionName |
@@ -4618,7 +5735,7 @@ Parameters:
- Source:
@@ -4654,7 +5771,7 @@ Returns:
-
-BNote
+BOption
|
null
@@ -4675,115 +5792,19 @@
Returns:
- getNoteWithLabel(name, valueopt) → {BNote|null}
-
-
-
-
-
-
-
- Retrieves first note with given label name & value
-
-
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name |
-
-
- Type |
-
-
- Attributes |
-
-
-
-
- Description |
-
-
-
-
+ getOptions() → {Array.<BOption>}
-
-
- name |
-
-
-
-
-
-string
-
-
-
- |
-
-
-
-
-
-
-
-
- |
-
-
-
-
- attribute name |
-
-
-
-
- value |
-
-
-
-
-
-string
-
- |
-
-
-
- <optional>
-
-
-
- |
-
-
- attribute value |
-
-
-
-
@@ -4819,7 +5840,7 @@ Parameters:
- Source:
@@ -4855,10 +5876,7 @@ Returns:
-
-BNote
-|
-
-null
+Array.<BOption>
@@ -4876,17 +5894,13 @@ Returns:
- getNotesWithLabel(name, valueopt) → {Array.<BNote>}
+ getRevision(revisionId) → {BRevision|null}
-
- Retrieves notes with given label name & value
-
-
@@ -4908,8 +5922,6 @@ Parameters:
| Type |
- Attributes |
-
@@ -4922,38 +5934,7 @@ Parameters:
- name |
-
-
-
-
-
-string
-
-
-
- |
-
-
-
-
-
-
-
-
- |
-
-
-
-
- attribute name |
-
-
-
-
-
-
- value |
+ revisionId |
@@ -4966,20 +5947,10 @@ Parameters:
|
-
-
- <optional>
-
-
-
-
-
- |
-
- attribute value |
+ |
@@ -5020,7 +5991,7 @@ Parameters:
- Source:
@@ -5056,7 +6027,10 @@ Returns:
-
-Array.<BNote>
+BRevision
+|
+
+null
@@ -5126,7 +6100,7 @@ ge
- Source:
@@ -5296,7 +6270,7 @@ Parameters:
- Source:
@@ -5599,7 +6573,7 @@ Properties
- Source:
@@ -5664,7 +6638,7 @@ getYearNot
- 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 @@ Parameters:
- Source:
@@ -5953,7 +6927,7 @@ Parameters:
- Source:
@@ -6108,7 +7082,7 @@ Parameters:
- Source:
@@ -6175,7 +7149,7 @@ runOnFro
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 @@ Parameters:
- Source:
@@ -6457,7 +7431,7 @@ Parameters:
- Source:
@@ -6660,7 +7634,7 @@ Parameters:
- Source:
@@ -6862,7 +7836,7 @@ Parameters:
- Source:
@@ -7071,7 +8045,7 @@ Parameters:
- Source:
@@ -7417,7 +8391,7 @@ Properties
- Source:
@@ -7641,7 +8615,7 @@ Parameters:
- Source:
@@ -7797,7 +8771,7 @@ Parameters:
- Source:
@@ -7952,7 +8926,7 @@ Parameters:
- Source:
diff --git a/docs/backend_api/global.html b/docs/backend_api/global.html
index b110e0145c..5ce1f70df2 100644
--- a/docs/backend_api/global.html
+++ b/docs/backend_api/global.html
@@ -152,7 +152,7 @@ Type:
- Source:
@@ -612,7 +612,7 @@ Type:
- Source:
diff --git a/docs/backend_api/services_backend_script_api.js.html b/docs/backend_api/services_backend_script_api.js.html
index 61e8b1ef09..dedaa6f88d 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 @@ Source: services/backend_script_api.js
const branchService = require("./branches");
const exportService = require("./export/zip");
const syncMutex = require("./sync_mutex.js");
+const optionsService = require("./options");
/**
@@ -90,18 +91,18 @@ Source: services/backend_script_api.js
/**
* 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 @@ Source: services/backend_script_api.js
*/
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 @@ Source: services/backend_script_api.js
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 @@ Source: services/backend_script_api.js
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 @@ Source: services/backend_script_api.js
* @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 @@ Source: services/backend_script_api.js
/**
* 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 bec8e5b9f5..85072e6133 100644
--- a/docs/frontend_api/FrontendScriptApi.html
+++ b/docs/frontend_api/FrontendScriptApi.html
@@ -462,7 +462,7 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+ return value of the executed function on the backend
+
+
+
+
+
+ -
+ Type
+
+ -
+
+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:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ func |
+
+
+
+
+
function
+|
+
+string
@@ -6509,7 +6702,7 @@ Parameters:
- | script to be executed on the backend |
+ (synchronous) function to be executed on the backend |
@@ -6522,7 +6715,7 @@ Parameters:
-Array.<any>
+Array.<?>
@@ -6573,7 +6766,7 @@ Parameters:
Source:
@@ -6613,7 +6806,7 @@ Returns:
-Promise.<any>
+Promise.<*>
@@ -6733,7 +6926,7 @@ Parameters:
Source:
@@ -6889,7 +7082,7 @@ Parameters:
Source:
@@ -7044,7 +7237,7 @@ Parameters:
Source:
@@ -7195,7 +7388,7 @@ Parameters:
Source:
@@ -7350,7 +7543,7 @@ Parameters:
Source:
@@ -7509,7 +7702,7 @@ Parameters:
Source:
@@ -7646,7 +7839,7 @@ Parameters:
Source:
@@ -7801,7 +7994,7 @@ Parameters:
Source:
@@ -8033,7 +8226,7 @@ Properties
Source:
@@ -8215,7 +8408,7 @@ Parameters:
Source:
@@ -8375,7 +8568,7 @@ Parameters:
Source:
@@ -8467,7 +8660,7 @@ waitUn
Source:
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html
index 8069c92dd6..eded4a0c0c 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 @@ Source: services/frontend_script_api.js
}
/**
- * 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 @@ Source: services/frontend_script_api.js
* @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 bbdc2b9347..ba593f4c86 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.
*
| |