diff --git a/docs/backend_api/BackendScriptApi.html b/docs/backend_api/BackendScriptApi.html index c3924360a9..5618ff0d92 100644 --- a/docs/backend_api/BackendScriptApi.html +++ b/docs/backend_api/BackendScriptApi.html @@ -94,7 +94,7 @@

new B
Source:
@@ -240,7 +240,7 @@

Properties:
Source:
@@ -314,7 +314,7 @@
Type:
Source:
@@ -386,7 +386,7 @@
Type:
Source:
@@ -458,7 +458,7 @@
Type:
Source:
@@ -530,7 +530,7 @@
Type:
Source:
@@ -602,7 +602,7 @@
Type:
Source:
@@ -674,7 +674,7 @@
Type:
Source:
@@ -746,7 +746,7 @@
Type:
Source:
@@ -922,7 +922,7 @@
Parameters:
Source:
@@ -1441,7 +1441,7 @@
Properties
Source:
@@ -2075,7 +2075,7 @@
Properties
Source:
@@ -2602,7 +2602,7 @@
Properties
Source:
@@ -2803,7 +2803,7 @@
Parameters:
Source:
@@ -2985,7 +2985,7 @@
Parameters:
Source:
@@ -3186,7 +3186,7 @@
Parameters:
Source:
@@ -3337,7 +3337,7 @@
Parameters:
Source:
@@ -3538,7 +3538,7 @@
Parameters:
Source:
@@ -3640,7 +3640,7 @@

getAppInfo<
Source:
@@ -3701,7 +3701,7 @@

Returns:
-

getAttribute(attributeId) → {BAttribute|null}

+

getAttachment(attachmentId) → {BAttachment|null}

@@ -3741,7 +3741,7 @@
Parameters:
- 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:
+ + + + + + + + + + + + + + + + + + + + - + - - - + @@ -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:
+ + +
NameTypeDescription
rootNotebranchId -BNote +string - - <optional>
- - - - - -
specify calendar root note, normally leave empty to use the default calendar
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
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:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
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:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
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:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noteId + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +BNote +| + +null + + +
+
+ + + + + + + + + + + + + +

getNoteWithLabel(name, valueopt) → {BNote|null}

+ + + + + + +
+ Retrieves first note with given label name & value +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + -BNote -| -null + + + + + - - + + + + - + + + - + - -

getInstanceName() → {string|null}

- + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +string + + + + - + + 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:
- - - - - - - - - - - - - - - - - - - - - - +

getOptions() → {Array.<BOption>}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
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 @@
Parameters:
Source:
@@ -1738,7 +1738,7 @@
Parameters:
Source:
@@ -2157,7 +2157,7 @@
Properties
Source:
@@ -2312,7 +2312,7 @@
Parameters:
Source:
@@ -2469,7 +2469,7 @@
Parameters:
Source:
@@ -2624,7 +2624,7 @@
Parameters:
Source:
@@ -2730,7 +2730,7 @@

getAc
Source:
@@ -2840,7 +2840,7 @@

Source:
@@ -2946,7 +2946,7 @@

g
Source:
@@ -3052,7 +3052,7 @@

Source:
@@ -3162,7 +3162,7 @@

Source:
@@ -3268,7 +3268,7 @@

g
Source:
@@ -3379,7 +3379,7 @@

Source:
@@ -3534,7 +3534,7 @@
Parameters:
Source:
@@ -3689,7 +3689,7 @@
Parameters:
Source:
@@ -3796,7 +3796,7 @@

getIns
Source:
@@ -3898,7 +3898,7 @@

ge
Source:
@@ -4057,7 +4057,7 @@

Parameters:
Source:
@@ -4213,7 +4213,7 @@
Parameters:
Source:
@@ -4315,7 +4315,7 @@

getNot
Source:
@@ -4520,7 +4520,7 @@

Parameters:
Source:
@@ -4626,7 +4626,7 @@

getTodayN
Source:
@@ -4781,7 +4781,7 @@

Parameters:
Source:
@@ -4936,7 +4936,7 @@
Parameters:
Source:
@@ -5086,7 +5086,7 @@
Parameters:
Source:
@@ -5593,7 +5593,7 @@
Parameters:
Source:
@@ -5771,7 +5771,7 @@
Parameters:
Source:
@@ -5945,7 +5945,7 @@
Parameters:
Source:
@@ -6100,7 +6100,7 @@
Parameters:
Source:
@@ -6254,7 +6254,7 @@
Parameters:
Source:
@@ -6409,7 +6409,7 @@
Parameters:
Source:
@@ -6445,7 +6445,7 @@
Parameters:
-

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

+

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

@@ -6455,6 +6455,11 @@

runOnBack
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,204 @@

Parameters:
- script + func -string +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.<*> + + +
+
+ + + + + + + + + + + + + +

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:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -6522,7 +6715,7 @@
Parameters:
NameTypeDescription
func + + function +| + +string @@ -6509,7 +6702,7 @@
Parameters:
-
script to be executed on the backend(synchronous) function to be executed on the backend
-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. *