mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 18:50:41 +01:00
Merge branch 'feature/server_esm_part2' into feature/server_esm_part3
This commit is contained in:
@@ -63,7 +63,7 @@ interface Api {
|
||||
* Note where the script started executing (entrypoint).
|
||||
* As an analogy, in C this would be the file which contains the main() function of the current process.
|
||||
*/
|
||||
startNote?: BNote;
|
||||
startNote?: BNote | null;
|
||||
|
||||
/**
|
||||
* Note where the script is currently executing. This comes into play when your script is spread in multiple code
|
||||
@@ -76,7 +76,7 @@ interface Api {
|
||||
/**
|
||||
* Entity whose event triggered this execution
|
||||
*/
|
||||
originEntity?: AbstractBeccaEntity<any>;
|
||||
originEntity?: AbstractBeccaEntity<any> | null;
|
||||
|
||||
/**
|
||||
* Axios library for HTTP requests. See {@link https://axios-http.com} for documentation
|
||||
|
||||
@@ -3,8 +3,8 @@ import AbstractBeccaEntity from "../becca/entities/abstract_becca_entity.js";
|
||||
import BNote from "../becca/entities/bnote.js";
|
||||
|
||||
export interface ApiParams {
|
||||
startNote?: BNote;
|
||||
originEntity?: AbstractBeccaEntity<any>;
|
||||
startNote?: BNote | null;
|
||||
originEntity?: AbstractBeccaEntity<any> | null;
|
||||
pathParams?: string[],
|
||||
req?: Request,
|
||||
res?: Response
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
export default { buildDate:"2024-07-14T22:32:45+03:00", buildRevision: "b811f3d399aed7e740bd8e92ef7edc7d15de7038" };
|
||||
export default {
|
||||
buildDate: "2024-07-21T10:25:01Z",
|
||||
buildRevision: "715a952148ae6e83fda0886f5ceec8dc329972ae"
|
||||
};
|
||||
|
||||
@@ -95,10 +95,6 @@ function executeScript(script: string, params: ScriptParams, startNoteId: string
|
||||
throw new Error("Unable to determine script bundle.");
|
||||
}
|
||||
|
||||
if (!startNote || !originEntity) {
|
||||
throw new Error("Missing start note or origin entity.");
|
||||
}
|
||||
|
||||
return executeBundle(bundle, { startNote, originEntity });
|
||||
}
|
||||
|
||||
|
||||
@@ -33,11 +33,8 @@ const numericComparators: Record<string, Comparator<number>> = {
|
||||
function buildComparator(operator: string, comparedValue: string) {
|
||||
comparedValue = comparedValue.toLowerCase();
|
||||
|
||||
if (operator in numericComparators) {
|
||||
const floatValue = parseFloat(comparedValue);
|
||||
if (!isNaN(floatValue)) {
|
||||
return numericComparators[operator](floatValue);
|
||||
}
|
||||
if (operator in numericComparators && !isNaN(+comparedValue)) {
|
||||
return numericComparators[operator](parseFloat(comparedValue));
|
||||
}
|
||||
|
||||
if (operator in stringComparators) {
|
||||
|
||||
@@ -41,15 +41,13 @@ function updateEntities(entityChanges: EntityChangeRecord[], instanceId: string)
|
||||
atLeastOnePullApplied = true;
|
||||
}
|
||||
|
||||
if (entity) {
|
||||
updateEntity(entityChange, entity, instanceId, updateContext);
|
||||
}
|
||||
updateEntity(entityChange, entity, instanceId, updateContext);
|
||||
}
|
||||
|
||||
logUpdateContext(updateContext);
|
||||
}
|
||||
|
||||
function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string, updateContext: UpdateContext) {
|
||||
function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string, updateContext: UpdateContext) {
|
||||
if (!remoteEntityRow && remoteEC.entityName === 'options') {
|
||||
return; // can be undefined for options with isSynced=false
|
||||
}
|
||||
@@ -74,14 +72,13 @@ function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instan
|
||||
}
|
||||
}
|
||||
|
||||
function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string, updateContext: UpdateContext) {
|
||||
const localEC = sql.getRow<EntityChange>(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]);
|
||||
function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string, updateContext: UpdateContext) {
|
||||
const localEC = sql.getRow<EntityChange | undefined>(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]);
|
||||
const localECIsOlderOrSameAsRemote = (
|
||||
localEC && localEC.utcDateChanged && remoteEC.utcDateChanged &&
|
||||
localEC.utcDateChanged <= remoteEC.utcDateChanged);
|
||||
|
||||
if (!localEC.utcDateChanged || !remoteEC.utcDateChanged) {
|
||||
throw new Error("Missing date changed.");
|
||||
}
|
||||
|
||||
if (!localEC || localEC.utcDateChanged <= remoteEC.utcDateChanged) {
|
||||
if (!localEC || localECIsOlderOrSameAsRemote) {
|
||||
if (remoteEC.isErased) {
|
||||
if (localEC?.isErased) {
|
||||
eraseEntity(remoteEC); // make sure it's erased anyway
|
||||
@@ -104,7 +101,7 @@ function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow,
|
||||
}
|
||||
|
||||
if (!localEC
|
||||
|| localEC.utcDateChanged < remoteEC.utcDateChanged
|
||||
|| localECIsOlderOrSameAsRemote
|
||||
|| localEC.hash !== remoteEC.hash
|
||||
|| localEC.isErased !== remoteEC.isErased
|
||||
) {
|
||||
@@ -113,7 +110,7 @@ function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow,
|
||||
|
||||
return true;
|
||||
} else if ((localEC.hash !== remoteEC.hash || localEC.isErased !== remoteEC.isErased)
|
||||
&& localEC.utcDateChanged > remoteEC.utcDateChanged) {
|
||||
&& !localECIsOlderOrSameAsRemote) {
|
||||
// the change on our side is newer than on the other side, so the other side should update
|
||||
entityChangesService.putEntityChangeForOtherInstances(localEC);
|
||||
|
||||
@@ -140,7 +137,7 @@ function preProcessContent(remoteEC: EntityChange, remoteEntityRow: EntityRow) {
|
||||
}
|
||||
}
|
||||
|
||||
function updateNoteReordering(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string) {
|
||||
function updateNoteReordering(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string) {
|
||||
if (!remoteEntityRow) {
|
||||
throw new Error(`Empty note_reordering body for: ${JSON.stringify(remoteEC)}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user