diff --git a/docs/backend_api/BNote.html b/docs/backend_api/BNote.html index 5fe97e3d17..6dabec0572 100644 --- a/docs/backend_api/BNote.html +++ b/docs/backend_api/BNote.html @@ -1588,7 +1588,7 @@
Parameters:
Source:
@@ -1835,7 +1835,7 @@
Parameters:
Source:
@@ -2081,7 +2081,7 @@
Parameters:
Source:
@@ -2316,7 +2316,7 @@
Parameters:
Source:
@@ -2432,7 +2432,7 @@

Source:
@@ -2653,7 +2653,7 @@
Parameters:
Source:
@@ -2848,7 +2848,7 @@

getAll
Source:
@@ -4207,7 +4207,7 @@

Parameters:
Source:
@@ -4386,7 +4386,7 @@
Parameters:
Source:
@@ -9019,7 +9019,7 @@
Parameters:
Source:
@@ -11329,7 +11329,7 @@
Parameters:
Source:
@@ -11435,7 +11435,7 @@

isH
Source:
@@ -12675,7 +12675,7 @@

Parameters:
Source:
@@ -12855,7 +12855,7 @@
Parameters:
Source:
@@ -13035,7 +13035,7 @@
Parameters:
Source:
@@ -13182,7 +13182,7 @@
Returns:
-

saveAttachment() → {BAttachment}

+

saveAttachment(matchBy) → {BAttachment}

@@ -13197,6 +13197,64 @@

saveAtt +

Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
matchBy + + +string + + + + + + attachmentId + + choose by which property we detect if to update an existing attachment. + Supported values are either 'attachmentId' (default) or 'title'
+ + @@ -13230,7 +13288,7 @@

saveAtt
Source:
@@ -13332,7 +13390,7 @@

saveRevis
Source:
@@ -13564,7 +13622,7 @@

Parameters:
Source:
@@ -14023,7 +14081,7 @@
Parameters:
Source:
@@ -14183,7 +14241,7 @@
Parameters:
Source:
@@ -14425,7 +14483,7 @@
Parameters:
Source:
@@ -14636,7 +14694,7 @@
Parameters:
Source:
@@ -14847,7 +14905,7 @@
Parameters:
Source:
diff --git a/docs/backend_api/BackendScriptApi.html b/docs/backend_api/BackendScriptApi.html index 73fbd12952..401f5a1c61 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:
@@ -352,7 +352,7 @@
Properties:
Source:
@@ -462,7 +462,7 @@
Properties:
Source:
@@ -572,7 +572,7 @@
Properties:
Source:
@@ -682,7 +682,7 @@
Properties:
Source:
@@ -792,7 +792,7 @@
Properties:
Source:
@@ -902,7 +902,7 @@
Properties:
Source:
@@ -1012,7 +1012,7 @@
Properties:
Source:
@@ -1040,6 +1040,161 @@

Methods

+

backupNow(backupName) → {Promise}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
backupName + + +string + + + + If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + +
+ - resolves once the backup is finished +
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + + +

createDataNote(parentNoteId, title, content) → {Object}

@@ -1188,7 +1343,7 @@
Parameters:
Source:
@@ -1691,7 +1846,7 @@
Properties
Source:
@@ -2311,7 +2466,7 @@
Properties
Source:
@@ -2817,7 +2972,7 @@
Properties:
Source:
@@ -3018,7 +3173,7 @@
Parameters:
Source:
@@ -3200,7 +3355,7 @@
Parameters:
Source:
@@ -3401,7 +3556,7 @@
Parameters:
Source:
@@ -3552,7 +3707,7 @@
Parameters:
Source:
@@ -3753,7 +3908,7 @@
Parameters:
Source:
@@ -3855,7 +4010,7 @@

getAppInfo<
Source:
@@ -4013,7 +4168,7 @@

Parameters:
Source:
@@ -4167,7 +4322,7 @@
Parameters:
Source:
@@ -4368,7 +4523,7 @@
Parameters:
Source:
@@ -4478,7 +4633,7 @@

getIns
Source:
@@ -4679,7 +4834,7 @@

Parameters:
Source:
@@ -4833,7 +4988,7 @@
Parameters:
Source:
@@ -5034,7 +5189,7 @@
Parameters:
Source:
@@ -5235,7 +5390,7 @@
Parameters:
Source:
@@ -5341,7 +5496,7 @@

ge
Source:
@@ -5511,7 +5666,7 @@

Parameters:
Source:
@@ -5814,7 +5969,7 @@
Properties
Source:
@@ -6015,7 +6170,7 @@
Parameters:
Source:
@@ -6168,7 +6323,7 @@
Parameters:
Source:
@@ -6323,7 +6478,7 @@
Parameters:
Source:
@@ -6508,7 +6663,7 @@
Parameters:
Source:
@@ -6672,7 +6827,7 @@
Parameters:
Source:
@@ -6875,7 +7030,7 @@
Parameters:
Source:
@@ -7077,7 +7232,7 @@
Parameters:
Source:
@@ -7286,7 +7441,7 @@
Parameters:
Source:
@@ -7629,7 +7784,7 @@
Properties:
Source:
@@ -7853,7 +8008,7 @@
Parameters:
Source:
@@ -8009,7 +8164,7 @@
Parameters:
Source:
@@ -8164,7 +8319,7 @@
Parameters:
Source:
diff --git a/docs/backend_api/becca_entities_bnote.js.html b/docs/backend_api/becca_entities_bnote.js.html index 8d3cd266b3..318afc1775 100644 --- a/docs/backend_api/becca_entities_bnote.js.html +++ b/docs/backend_api/becca_entities_bnote.js.html @@ -1184,14 +1184,8 @@

Source: becca/entities/bnote.js

/** @returns {BAttachment} */ getAttachmentByTitle(title) { - return sql.getRows(` - SELECT attachments.* - FROM attachments - WHERE ownerId = ? - AND title = ? - AND isDeleted = 0 - ORDER BY position`, [this.noteId, title]) - .map(row => new BAttachment(row))[0]; + // cannot use SQL to filter by title since it can be encrypted + return this.getAttachments().filter(attachment => attachment.title === title)[0]; } /** @@ -1663,24 +1657,32 @@

Source: becca/entities/bnote.js

} /** + * @param {string} matchBy - choose by which property we detect if to update an existing attachment. + * Supported values are either 'attachmentId' (default) or 'title' * @returns {BAttachment} */ - saveAttachment({attachmentId, role, mime, title, content, position}) { + saveAttachment({attachmentId, role, mime, title, content, position}, matchBy = 'attachmentId') { + if (!['attachmentId', 'title'].includes(matchBy)) { + throw new Error(`Unsupported value '${matchBy}' for matchBy param, has to be either 'attachmentId' or 'title'.`); + } + let attachment; - if (attachmentId) { + if (matchBy === 'title') { + attachment = this.getAttachmentByTitle(title); + } else if (matchBy === 'attachmentId' && attachmentId) { attachment = this.becca.getAttachmentOrThrow(attachmentId); - } else { - attachment = new BAttachment({ - ownerId: this.noteId, - title, - role, - mime, - isProtected: this.isProtected, - position - }); } + attachment = attachment || new BAttachment({ + ownerId: this.noteId, + title, + role, + mime, + isProtected: this.isProtected, + position + }); + content = content || ""; attachment.setContent(content, {forceSave: true}); diff --git a/docs/backend_api/becca_entities_brevision.js.html b/docs/backend_api/becca_entities_brevision.js.html index 009e72a2e4..b493ce8a0a 100644 --- a/docs/backend_api/becca_entities_brevision.js.html +++ b/docs/backend_api/becca_entities_brevision.js.html @@ -185,14 +185,8 @@

Source: becca/entities/brevision.js

/** @returns {BAttachment} */ getAttachmentByTitle(title) { - return sql.getRows(` - SELECT attachments.* - FROM attachments - WHERE ownerId = ? - AND title = ? - AND isDeleted = 0 - ORDER BY position`, [this.revisionId, title]) - .map(row => new BAttachment(row))[0]; + // cannot use SQL to filter by title since it can be encrypted + return this.getAttachments().filter(attachment => attachment.title === title)[0]; } beforeSaving() { diff --git a/docs/backend_api/services_backend_script_api.js.html b/docs/backend_api/services_backend_script_api.js.html index 4bc787c464..0f6b3c3ec5 100644 --- a/docs/backend_api/services_backend_script_api.js.html +++ b/docs/backend_api/services_backend_script_api.js.html @@ -47,7 +47,8 @@

Source: services/backend_script_api.js

const specialNotesService = require("./special_notes"); const branchService = require("./branches"); const exportService = require("./export/zip"); -const syncMutex = require("./sync_mutex.js"); +const syncMutex = require("./sync_mutex"); +const backupService = require("./backup"); /** * <p>This is the main backend API interface for scripts. All the properties and methods are published in the "api" object @@ -614,6 +615,13 @@

Source: services/backend_script_api.js

*/ this.runOutsideOfSync = syncMutex.doExclusively; + /** + * @method + * @param {string} backupName - If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file + * @returns {Promise} - resolves once the backup is finished + */ + this.backupNow = backupService.backupNow; + /** * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. * diff --git a/docs/frontend_api/FAttribute.html b/docs/frontend_api/FAttribute.html index 8956485710..c4f3cc0b9a 100644 --- a/docs/frontend_api/FAttribute.html +++ b/docs/frontend_api/FAttribute.html @@ -912,7 +912,7 @@
Returns:

diff --git a/docs/frontend_api/FBranch.html b/docs/frontend_api/FBranch.html index 3220829d1a..c624710502 100644 --- a/docs/frontend_api/FBranch.html +++ b/docs/frontend_api/FBranch.html @@ -1124,7 +1124,7 @@
Returns:

diff --git a/docs/frontend_api/FNote.html b/docs/frontend_api/FNote.html index 3e2ffb611c..4e9edf3e5f 100644 --- a/docs/frontend_api/FNote.html +++ b/docs/frontend_api/FNote.html @@ -6570,7 +6570,7 @@
Returns:
-

getSortedNotePathRecords(hoistedNoteIdopt) → {Array.<{isArchived: boolean, isInHoistedSubTree: boolean, isSearch: boolean, notePath: Array.<string>, isHidden: boolean}>}

+

getSortedNotePathRecords(hoistedNoteIdopt) → {Array.<{isArchived: boolean, isInHoistedSubTree: boolean, isSearch: boolean, notePath: Array.<string>, isHidden: boolean}>}

@@ -6723,7 +6723,7 @@
Returns:
-Array.<{isArchived: boolean, isInHoistedSubTree: boolean, isSearch: boolean, notePath: Array.<string>, isHidden: boolean}> +Array.<{isArchived: boolean, isInHoistedSubTree: boolean, isSearch: boolean, notePath: Array.<string>, isHidden: boolean}>
@@ -8690,7 +8690,7 @@
Returns:

diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html index 3b340b60af..ab2da083f1 100644 --- a/docs/frontend_api/FrontendScriptApi.html +++ b/docs/frontend_api/FrontendScriptApi.html @@ -293,7 +293,7 @@
Properties:
-BasicWidget +BasicWidget @@ -8356,7 +8356,7 @@
Returns:

diff --git a/docs/frontend_api/entities_fattachment.js.html b/docs/frontend_api/entities_fattachment.js.html index c49ab8dd2c..7b320d8954 100644 --- a/docs/frontend_api/entities_fattachment.js.html +++ b/docs/frontend_api/entities_fattachment.js.html @@ -80,7 +80,7 @@

Source: entities/fattachment.js


diff --git a/docs/frontend_api/entities_fattribute.js.html b/docs/frontend_api/entities_fattribute.js.html index 7daa67ff2e..7b1bd8625b 100644 --- a/docs/frontend_api/entities_fattribute.js.html +++ b/docs/frontend_api/entities_fattribute.js.html @@ -116,7 +116,7 @@

Source: entities/fattribute.js


diff --git a/docs/frontend_api/entities_fblob.js.html b/docs/frontend_api/entities_fblob.js.html index e98ee01c63..70d0dc3122 100644 --- a/docs/frontend_api/entities_fblob.js.html +++ b/docs/frontend_api/entities_fblob.js.html @@ -75,7 +75,7 @@

Source: entities/fblob.js


diff --git a/docs/frontend_api/entities_fbranch.js.html b/docs/frontend_api/entities_fbranch.js.html index f2049871d7..44268f7616 100644 --- a/docs/frontend_api/entities_fbranch.js.html +++ b/docs/frontend_api/entities_fbranch.js.html @@ -100,7 +100,7 @@

Source: entities/fbranch.js


diff --git a/docs/frontend_api/entities_fnote.js.html b/docs/frontend_api/entities_fnote.js.html index d6f68bcca2..4ccd4ac22a 100644 --- a/docs/frontend_api/entities_fnote.js.html +++ b/docs/frontend_api/entities_fnote.js.html @@ -1021,7 +1021,7 @@

Source: entities/fnote.js


diff --git a/docs/frontend_api/global.html b/docs/frontend_api/global.html index 518a2455d2..b474645766 100644 --- a/docs/frontend_api/global.html +++ b/docs/frontend_api/global.html @@ -91,11 +91,247 @@

+ + + +

Members

+ + + +

hoistedNoteId

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

note

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

noteId

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

notePath

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +

Methods

@@ -322,6 +558,157 @@
Returns:
+ + + + + +

(async) refreshWithNote(note) → {Promise.<void>}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
note + + +FNote + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<void> + + +
+
+ + + + + + + + @@ -337,7 +724,7 @@
Returns:

diff --git a/docs/frontend_api/index.html b/docs/frontend_api/index.html index 1fc84f3649..1a696bafb4 100644 --- a/docs/frontend_api/index.html +++ b/docs/frontend_api/index.html @@ -50,7 +50,7 @@


diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html index 3c978b25cb..350a4ba2f6 100644 --- a/docs/frontend_api/services_frontend_script_api.js.html +++ b/docs/frontend_api/services_frontend_script_api.js.html @@ -601,7 +601,7 @@

Source: services/frontend_script_api.js


diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 5854e002fd..3a47761a9d 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -19,7 +19,8 @@ const SpacedUpdate = require("./spaced_update"); const specialNotesService = require("./special_notes"); const branchService = require("./branches"); const exportService = require("./export/zip"); -const syncMutex = require("./sync_mutex.js"); +const syncMutex = require("./sync_mutex"); +const backupService = require("./backup"); /** *

This is the main backend API interface for scripts. All the properties and methods are published in the "api" object @@ -586,6 +587,13 @@ function BackendScriptApi(currentNote, apiParams) { */ this.runOutsideOfSync = syncMutex.doExclusively; + /** + * @method + * @param {string} backupName - If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file + * @returns {Promise} - resolves once the backup is finished + */ + this.backupNow = backupService.backupNow; + /** * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. *