diff --git a/docs/backend_api/BNote.html b/docs/backend_api/BNote.html index 5fe97e3d1..6dabec057 100644 --- a/docs/backend_api/BNote.html +++ b/docs/backend_api/BNote.html @@ -1588,7 +1588,7 @@ See addLabel, addRelation for more specific methods.
Source:
@@ -1835,7 +1835,7 @@ See addLabel, addRelation for more specific methods.
Source:
@@ -2081,7 +2081,7 @@ returned.
Source:
@@ -2316,7 +2316,7 @@ returned.
Source:
@@ -2432,7 +2432,7 @@ In the future, this functionality might get more generic and some of the require
Source:
@@ -2653,7 +2653,7 @@ In the future, this functionality might get more generic and some of the require
Source:
@@ -2848,7 +2848,7 @@ In the future, this functionality might get more generic and some of the require
Source:
@@ -4207,7 +4207,7 @@ In the future, this functionality might get more generic and some of the require
Source:
@@ -4386,7 +4386,7 @@ In the future, this functionality might get more generic and some of the require
Source:
@@ -9019,7 +9019,7 @@ This method can be significantly faster than the getAttribute()
Source:
@@ -11329,7 +11329,7 @@ This method can be significantly faster than the getAttribute()
Source:
@@ -11435,7 +11435,7 @@ This method can be significantly faster than the getAttribute()
Source:
@@ -12675,7 +12675,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -12855,7 +12855,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -13035,7 +13035,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -13182,7 +13182,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and ' -

saveAttachment() → {BAttachment}

+

saveAttachment(matchBy) → {BAttachment}

@@ -13197,6 +13197,64 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and ' +
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 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -13332,7 +13390,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -13564,7 +13622,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -14023,7 +14081,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -14183,7 +14241,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -14425,7 +14483,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -14636,7 +14694,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -14847,7 +14905,7 @@ This is a low-level method, for notes and branches use `note.deleteNote()` and '
Source:
diff --git a/docs/backend_api/BackendScriptApi.html b/docs/backend_api/BackendScriptApi.html index 73fbd1295..401f5a1c6 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:
@@ -352,7 +352,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -462,7 +462,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -572,7 +572,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -682,7 +682,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -792,7 +792,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -902,7 +902,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -1012,7 +1012,7 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote.
Source:
@@ -1040,6 +1040,161 @@ available in the JS backend notes. You can use e.g. api.log(api.startNote. +

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 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -1691,7 +1846,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2311,7 +2466,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2817,7 +2972,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3018,7 +3173,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3200,7 +3355,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3401,7 +3556,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3552,7 +3707,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3753,7 +3908,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3855,7 +4010,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -4013,7 +4168,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -4167,7 +4322,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -4368,7 +4523,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -4478,7 +4633,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4679,7 +4834,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4833,7 +4988,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5034,7 +5189,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5235,7 +5390,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5341,7 +5496,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5511,7 +5666,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5814,7 +5969,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -6015,7 +6170,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -6168,7 +6323,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -6323,7 +6478,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -6508,7 +6663,7 @@ instances execute the given function.
Source:
@@ -6672,7 +6827,7 @@ you need to make some DB changes, you need to surround your call with api.transa
Source:
@@ -6875,7 +7030,7 @@ you need to make some DB changes, you need to surround your call with api.transa
Source:
@@ -7077,7 +7232,7 @@ you need to make some DB changes, you need to surround your call with api.transa
Source:
@@ -7286,7 +7441,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -7629,7 +7784,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -7853,7 +8008,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -8009,7 +8164,7 @@ exists, then we'll use that transaction.
Source:
@@ -8164,7 +8319,7 @@ exists, then we'll use that transaction.
Source:
diff --git a/docs/backend_api/becca_entities_bnote.js.html b/docs/backend_api/becca_entities_bnote.js.html index 8d3cd266b..318afc177 100644 --- a/docs/backend_api/becca_entities_bnote.js.html +++ b/docs/backend_api/becca_entities_bnote.js.html @@ -1184,14 +1184,8 @@ class BNote extends AbstractBeccaEntity { /** @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 @@ class BNote extends AbstractBeccaEntity { } /** + * @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 009e72a2e..b493ce8a0 100644 --- a/docs/backend_api/becca_entities_brevision.js.html +++ b/docs/backend_api/becca_entities_brevision.js.html @@ -185,14 +185,8 @@ class BRevision extends AbstractBeccaEntity { /** @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 4bc787c46..0f6b3c3ec 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 @@ 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"); /** * <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 @@ 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. * diff --git a/docs/frontend_api/FAttribute.html b/docs/frontend_api/FAttribute.html index 895648571..c4f3cc0b9 100644 --- a/docs/frontend_api/FAttribute.html +++ b/docs/frontend_api/FAttribute.html @@ -912,7 +912,7 @@ and relation (representing named relationship between source and target note)
diff --git a/docs/frontend_api/FBranch.html b/docs/frontend_api/FBranch.html index 3220829d1..c62471050 100644 --- a/docs/frontend_api/FBranch.html +++ b/docs/frontend_api/FBranch.html @@ -1124,7 +1124,7 @@ parents.
diff --git a/docs/frontend_api/FNote.html b/docs/frontend_api/FNote.html index 3e2ffb611..4e9edf3e5 100644 --- a/docs/frontend_api/FNote.html +++ b/docs/frontend_api/FNote.html @@ -6570,7 +6570,7 @@ -

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 @@
-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 @@
diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html index 3b340b60a..ab2da083f 100644 --- a/docs/frontend_api/FrontendScriptApi.html +++ b/docs/frontend_api/FrontendScriptApi.html @@ -293,7 +293,7 @@ available in the JS frontend notes. You can use e.g. api.showMessage(api.s -BasicWidget +BasicWidget @@ -8356,7 +8356,7 @@ Typical use case is when a new note has been created, we should wait until it is
diff --git a/docs/frontend_api/entities_fattachment.js.html b/docs/frontend_api/entities_fattachment.js.html index c49ab8dd2..7b320d895 100644 --- a/docs/frontend_api/entities_fattachment.js.html +++ b/docs/frontend_api/entities_fattachment.js.html @@ -80,7 +80,7 @@ export default FAttachment;
diff --git a/docs/frontend_api/entities_fattribute.js.html b/docs/frontend_api/entities_fattribute.js.html index 7daa67ff2..7b1bd8625 100644 --- a/docs/frontend_api/entities_fattribute.js.html +++ b/docs/frontend_api/entities_fattribute.js.html @@ -116,7 +116,7 @@ export default FAttribute;
diff --git a/docs/frontend_api/entities_fblob.js.html b/docs/frontend_api/entities_fblob.js.html index e98ee01c6..70d0dc312 100644 --- a/docs/frontend_api/entities_fblob.js.html +++ b/docs/frontend_api/entities_fblob.js.html @@ -75,7 +75,7 @@
diff --git a/docs/frontend_api/entities_fbranch.js.html b/docs/frontend_api/entities_fbranch.js.html index f2049871d..44268f761 100644 --- a/docs/frontend_api/entities_fbranch.js.html +++ b/docs/frontend_api/entities_fbranch.js.html @@ -100,7 +100,7 @@ export default FBranch;
diff --git a/docs/frontend_api/entities_fnote.js.html b/docs/frontend_api/entities_fnote.js.html index d6f68bcca..4ccd4ac22 100644 --- a/docs/frontend_api/entities_fnote.js.html +++ b/docs/frontend_api/entities_fnote.js.html @@ -1021,7 +1021,7 @@ export default FNote;
diff --git a/docs/frontend_api/global.html b/docs/frontend_api/global.html index 518a2455d..b47464576 100644 --- a/docs/frontend_api/global.html +++ b/docs/frontend_api/global.html @@ -94,6 +94,242 @@ +

Members

+ + + +

hoistedNoteId

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

note

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

noteId

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

notePath

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

Methods

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

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

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
note + + +FNote + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<void> + + +
+
+ + + + + + + + @@ -337,7 +724,7 @@
diff --git a/docs/frontend_api/index.html b/docs/frontend_api/index.html index 1fc84f364..1a696bafb 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 3c978b25c..350a4ba2f 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 @@ export default FrontendScriptApi;
diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 5854e002f..3a47761a9 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. *