mirror of
https://github.com/zadam/trilium.git
synced 2025-10-29 01:06:36 +01:00
updated API docs
This commit is contained in:
@@ -38,9 +38,9 @@ const repository = require('./repository');
|
||||
const axios = require('axios');
|
||||
const dayjs = require('dayjs');
|
||||
const cloningService = require('./cloning');
|
||||
const ws = require('./ws.js');
|
||||
const appInfo = require('./app_info');
|
||||
const searchService = require('./search');
|
||||
const searchService = require('./search/services/search');
|
||||
const SearchContext = require("./search/search_context.js");
|
||||
|
||||
/**
|
||||
* This is the main backend API interface for scripts. It's published in the local "api" object.
|
||||
@@ -78,38 +78,31 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
/**
|
||||
* @method
|
||||
* @param {string} noteId
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.getNote = repository.getNote;
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {string} branchId
|
||||
* @returns {Promise<Branch|null>}
|
||||
* @returns {Branch|null}
|
||||
*/
|
||||
this.getBranch = repository.getBranch;
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {string} attributeId
|
||||
* @returns {Promise<Attribute|null>}
|
||||
* @returns {Attribute|null}
|
||||
*/
|
||||
this.getAttribute = repository.getAttribute;
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {string} imageId
|
||||
* @returns {Promise<Image|null>}
|
||||
*/
|
||||
this.getImage = repository.getImage;
|
||||
|
||||
/**
|
||||
* Retrieves first entity from the SQL's result set.
|
||||
*
|
||||
* @method
|
||||
* @param {string} SQL query
|
||||
* @param {Array.<?>} array of params
|
||||
* @returns {Promise<Entity|null>}
|
||||
* @returns {Entity|null}
|
||||
*/
|
||||
this.getEntity = repository.getEntity;
|
||||
|
||||
@@ -117,30 +110,38 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @method
|
||||
* @param {string} SQL query
|
||||
* @param {Array.<?>} array of params
|
||||
* @returns {Promise<Entity[]>}
|
||||
* @returns {Entity[]}
|
||||
*/
|
||||
this.getEntities = repository.getEntities;
|
||||
|
||||
/**
|
||||
* This is a powerful search method - you can search by attributes and their values, e.g.:
|
||||
* "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||
* "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||
*
|
||||
* @method
|
||||
* @param {string} searchString
|
||||
* @returns {Promise<Note[]>}
|
||||
* @param {string} query
|
||||
* @param {SearchContext} [searchContext]
|
||||
* @returns {Note[]}
|
||||
*/
|
||||
this.searchForNotes = searchService.searchForNotes;
|
||||
this.searchForNotes = (query, searchContext) => {
|
||||
searchContext = searchContext || new SearchContext();
|
||||
|
||||
const noteIds = searchService.findNotesWithQuery(query, searchContext)
|
||||
.map(sr => sr.noteId);
|
||||
|
||||
return repository.getNotes(noteIds);
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a powerful search method - you can search by attributes and their values, e.g.:
|
||||
* "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||
* "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||
*
|
||||
* @method
|
||||
* @param {string} searchString
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.searchForNote = async searchString => {
|
||||
const notes = await searchService.searchForNotes(searchString);
|
||||
this.searchForNote = searchString => {
|
||||
const notes = searchService.searchNoteEntities(searchString);
|
||||
|
||||
return notes.length > 0 ? notes[0] : null;
|
||||
};
|
||||
@@ -151,7 +152,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @method
|
||||
* @param {string} name - attribute name
|
||||
* @param {string} [value] - attribute value
|
||||
* @returns {Promise<Note[]>}
|
||||
* @returns {Note[]}
|
||||
*/
|
||||
this.getNotesWithLabel = attributeService.getNotesWithLabel;
|
||||
|
||||
@@ -161,7 +162,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @method
|
||||
* @param {string} name - attribute name
|
||||
* @param {string} [value] - attribute value
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.getNoteWithLabel = attributeService.getNoteWithLabel;
|
||||
|
||||
@@ -172,7 +173,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @param {string} noteId
|
||||
* @param {string} parentNoteId
|
||||
* @param {string} prefix - if branch will be create between note and parent note, set this prefix
|
||||
* @returns {Promise<void>}
|
||||
* @returns {void}
|
||||
*/
|
||||
this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent;
|
||||
|
||||
@@ -182,7 +183,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @method
|
||||
* @param {string} noteId
|
||||
* @param {string} parentNoteId
|
||||
* @returns {Promise<void>}
|
||||
* @returns {void}
|
||||
*/
|
||||
this.ensureNoteIsAbsentFromParent = cloningService.ensureNoteIsAbsentFromParent;
|
||||
|
||||
@@ -194,7 +195,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @param {string} noteId
|
||||
* @param {string} parentNoteId
|
||||
* @param {string} prefix - if branch will be create between note and parent note, set this prefix
|
||||
* @returns {Promise<void>}
|
||||
* @returns {void}
|
||||
*/
|
||||
this.toggleNoteInParent = cloningService.toggleNoteInParent;
|
||||
|
||||
@@ -211,9 +212,9 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @param {string} parentNoteId
|
||||
* @param {string} title
|
||||
* @param {string} content
|
||||
* @return {Promise<{note: Note, branch: Branch}>}
|
||||
* @return {{note: Note, branch: Branch}}
|
||||
*/
|
||||
this.createTextNote = async (parentNoteId, title, content = '') => await noteService.createNewNote({
|
||||
this.createTextNote = (parentNoteId, title, content = '') => noteService.createNewNote({
|
||||
parentNoteId,
|
||||
title,
|
||||
content,
|
||||
@@ -227,9 +228,9 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @param {string} parentNoteId
|
||||
* @param {string} title
|
||||
* @param {object} content
|
||||
* @return {Promise<{note: Note, branch: Branch}>}
|
||||
* @return {{note: Note, branch: Branch}}
|
||||
*/
|
||||
this.createDataNote = async (parentNoteId, title, content = {}) => await noteService.createNewNote({
|
||||
this.createDataNote = (parentNoteId, title, content = {}) => noteService.createNewNote({
|
||||
parentNoteId,
|
||||
title,
|
||||
content: JSON.stringify(content, null, '\t'),
|
||||
@@ -254,7 +255,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @method
|
||||
*
|
||||
* @param {CreateNewNoteParams} [params]
|
||||
* @returns {Promise<{note: Note, branch: Branch}>} object contains newly created entities note and branch
|
||||
* @returns {{note: Note, branch: Branch}} object contains newly created entities note and branch
|
||||
*/
|
||||
this.createNewNote = noteService.createNewNote;
|
||||
|
||||
@@ -276,19 +277,19 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @deprecated please use createNote() API method instead
|
||||
* @deprecated please use createNewNote() API method instead
|
||||
*
|
||||
* @param {string} parentNoteId - create new note under this parent
|
||||
* @param {string} title
|
||||
* @param {string} [content=""]
|
||||
* @param {CreateNoteExtraOptions} [extraOptions={}]
|
||||
* @returns {Promise<{note: Note, branch: Branch}>} object contains newly created entities note and branch
|
||||
* @returns {{note: Note, branch: Branch}} object contains newly created entities note and branch
|
||||
*/
|
||||
this.createNote = async (parentNoteId, title, content = "", extraOptions= {}) => {
|
||||
this.createNote = (parentNoteId, title, content = "", extraOptions= {}) => {
|
||||
extraOptions.parentNoteId = parentNoteId;
|
||||
extraOptions.title = title;
|
||||
|
||||
const parentNote = await repository.getNote(parentNoteId);
|
||||
const parentNote = repository.getNote(parentNoteId);
|
||||
|
||||
// code note type can be inherited, otherwise text is default
|
||||
extraOptions.type = parentNote.type === 'code' ? 'code' : 'text';
|
||||
@@ -303,19 +304,21 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
extraOptions.content = content;
|
||||
}
|
||||
|
||||
const {note, branch} = await noteService.createNewNote(extraOptions);
|
||||
return sql.transactional(() => {
|
||||
const {note, branch} = noteService.createNewNote(extraOptions);
|
||||
|
||||
for (const attr of extraOptions.attributes || []) {
|
||||
await attributeService.createAttribute({
|
||||
noteId: note.noteId,
|
||||
type: attr.type,
|
||||
name: attr.name,
|
||||
value: attr.value,
|
||||
isInheritable: !!attr.isInheritable
|
||||
});
|
||||
}
|
||||
for (const attr of extraOptions.attributes || []) {
|
||||
attributeService.createAttribute({
|
||||
noteId: note.noteId,
|
||||
type: attr.type,
|
||||
name: attr.name,
|
||||
value: attr.value,
|
||||
isInheritable: !!attr.isInheritable
|
||||
});
|
||||
}
|
||||
|
||||
return {note, branch};
|
||||
return {note, branch};
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -329,7 +332,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* Returns root note of the calendar.
|
||||
*
|
||||
* @method
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.getRootCalendarNote = dateNoteService.getRootCalendarNote;
|
||||
|
||||
@@ -338,7 +341,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
*
|
||||
* @method
|
||||
* @param {string} date in YYYY-MM-DD format
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.getDateNote = dateNoteService.getDateNote;
|
||||
|
||||
@@ -346,7 +349,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* Returns today's day note. If such note doesn't exist, it is created.
|
||||
*
|
||||
* @method
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.getTodayNote = dateNoteService.getTodayNote;
|
||||
|
||||
@@ -356,7 +359,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* @method
|
||||
* @param {string} date in YYYY-MM-DD format
|
||||
* @param {object} options - "startOfTheWeek" - either "monday" (default) or "sunday"
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.getWeekNote = dateNoteService.getWeekNote;
|
||||
|
||||
@@ -365,7 +368,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
*
|
||||
* @method
|
||||
* @param {string} date in YYYY-MM format
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.getMonthNote = dateNoteService.getMonthNote;
|
||||
|
||||
@@ -374,14 +377,13 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
*
|
||||
* @method
|
||||
* @param {string} year in YYYY format
|
||||
* @returns {Promise<Note|null>}
|
||||
* @returns {Note|null}
|
||||
*/
|
||||
this.getYearNote = dateNoteService.getYearNote;
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {string} parentNoteId - this note's child notes will be sorted
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
this.sortNotesAlphabetically = treeService.sortNotesAlphabetically;
|
||||
|
||||
@@ -403,12 +405,9 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* This functions wraps code which is supposed to be running in transaction. If transaction already
|
||||
* exists, then we'll use that transaction.
|
||||
*
|
||||
* This method is required only when script has label manualTransactionHandling, all other scripts are
|
||||
* transactional by default.
|
||||
*
|
||||
* @method
|
||||
* @param {function} func
|
||||
* @returns {Promise<?>} result of func callback
|
||||
* @returns {?} result of func callback
|
||||
*/
|
||||
this.transactional = sql.transactional;
|
||||
|
||||
@@ -443,7 +442,7 @@ module.exports = BackendScriptApi;
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a>
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
|
||||
Reference in New Issue
Block a user