refactor(docs): use in-memory model

This commit is contained in:
Elian Doran 2025-04-02 22:18:28 +03:00
parent 3f0dbb9063
commit a3a2bf4484
No known key found for this signature in database
5 changed files with 104 additions and 141 deletions

View File

@ -1,6 +1,6 @@
{ {
"formatVersion": 2, "formatVersion": 2,
"appVersion": "0.92.4", "appVersion": "0.92.5-beta",
"files": [ "files": [
{ {
"isClone": false, "isClone": false,
@ -1433,28 +1433,28 @@
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "BlN9DFI679QC", "value": "vZWERwf8U3nx",
"isInheritable": false, "isInheritable": false,
"position": 10 "position": 10
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "vZWERwf8U3nx", "value": "4FahAwuGTAwC",
"isInheritable": false, "isInheritable": false,
"position": 20 "position": 20
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "4FahAwuGTAwC", "value": "0vhv7lsOLy82",
"isInheritable": false, "isInheritable": false,
"position": 30 "position": 30
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "0vhv7lsOLy82", "value": "BlN9DFI679QC",
"isInheritable": false, "isInheritable": false,
"position": 40 "position": 40
}, },
@ -3058,6 +3058,20 @@
"isInheritable": false, "isInheritable": false,
"position": 50 "position": 50
}, },
{
"type": "relation",
"name": "internalLink",
"value": "QxEyIjRBizuC",
"isInheritable": false,
"position": 60
},
{
"type": "relation",
"name": "internalLink",
"value": "UYuUB1ZekNQU",
"isInheritable": false,
"position": 70
},
{ {
"type": "label", "type": "label",
"name": "shareAlias", "name": "shareAlias",
@ -3085,20 +3099,6 @@
"value": "", "value": "",
"isInheritable": false, "isInheritable": false,
"position": 40 "position": 40
},
{
"type": "relation",
"name": "internalLink",
"value": "UYuUB1ZekNQU",
"isInheritable": false,
"position": 60
},
{
"type": "relation",
"name": "internalLink",
"value": "QxEyIjRBizuC",
"isInheritable": false,
"position": 70
} }
], ],
"format": "markdown", "format": "markdown",
@ -3231,14 +3231,14 @@
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "QxEyIjRBizuC", "value": "6f9hih2hXXZk",
"isInheritable": false, "isInheritable": false,
"position": 20 "position": 20
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "6f9hih2hXXZk", "value": "QxEyIjRBizuC",
"isInheritable": false, "isInheritable": false,
"position": 30 "position": 30
}, },
@ -3324,44 +3324,44 @@
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "6f9hih2hXXZk", "value": "QxEyIjRBizuC",
"isInheritable": false, "isInheritable": false,
"position": 10 "position": 10
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "4TIF1oA4VQRO", "value": "6f9hih2hXXZk",
"isInheritable": false, "isInheritable": false,
"position": 20 "position": 20
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "nRhnJkTT8cPs", "value": "4TIF1oA4VQRO",
"isInheritable": false, "isInheritable": false,
"position": 30 "position": 30
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "s8alTXmpFR61", "value": "nRhnJkTT8cPs",
"isInheritable": false, "isInheritable": false,
"position": 40 "position": 40
}, },
{
"type": "relation",
"name": "internalLink",
"value": "s8alTXmpFR61",
"isInheritable": false,
"position": 50
},
{ {
"type": "label", "type": "label",
"name": "iconClass", "name": "iconClass",
"value": "bx bx-code", "value": "bx bx-code",
"isInheritable": false, "isInheritable": false,
"position": 50 "position": 50
},
{
"type": "relation",
"name": "internalLink",
"value": "QxEyIjRBizuC",
"isInheritable": false,
"position": 60
} }
], ],
"format": "markdown", "format": "markdown",
@ -4091,48 +4091,62 @@
"type": "text", "type": "text",
"mime": "text/markdown", "mime": "text/markdown",
"attributes": [ "attributes": [
{
"type": "relation",
"name": "internalLink",
"value": "zEY4DaJG4YT5",
"isInheritable": false,
"position": 10
},
{
"type": "relation",
"name": "internalLink",
"value": "OFXdgB2nNk1F",
"isInheritable": false,
"position": 20
},
{
"type": "relation",
"name": "internalLink",
"value": "wX4HbRucYSDD",
"isInheritable": false,
"position": 30
},
{ {
"type": "relation", "type": "relation",
"name": "imageLink", "name": "imageLink",
"value": "EH6qNioOHeyT", "value": "EH6qNioOHeyT",
"isInheritable": false, "isInheritable": false,
"position": 50 "position": 10
}, },
{ {
"type": "relation", "type": "relation",
"name": "imageLink", "name": "imageLink",
"value": "xeZPrfi77XPu", "value": "xeZPrfi77XPu",
"isInheritable": false, "isInheritable": false,
"position": 60 "position": 20
}, },
{ {
"type": "relation", "type": "relation",
"name": "imageLink", "name": "imageLink",
"value": "N98UhifxrVpZ", "value": "N98UhifxrVpZ",
"isInheritable": false, "isInheritable": false,
"position": 30
},
{
"type": "relation",
"name": "internalLink",
"value": "BFs8mudNFgCS",
"isInheritable": false,
"position": 40
},
{
"type": "relation",
"name": "internalLink",
"value": "zEY4DaJG4YT5",
"isInheritable": false,
"position": 50
},
{
"type": "relation",
"name": "internalLink",
"value": "OFXdgB2nNk1F",
"isInheritable": false,
"position": 60
},
{
"type": "relation",
"name": "internalLink",
"value": "wX4HbRucYSDD",
"isInheritable": false,
"position": 70 "position": 70
}, },
{
"type": "relation",
"name": "internalLink",
"value": "BCkXAVs63Ttv",
"isInheritable": false,
"position": 80
},
{ {
"type": "label", "type": "label",
"name": "shareAlias", "name": "shareAlias",
@ -4146,20 +4160,6 @@
"value": "bx bxs-network-chart", "value": "bx bxs-network-chart",
"isInheritable": false, "isInheritable": false,
"position": 20 "position": 20
},
{
"type": "relation",
"name": "internalLink",
"value": "BFs8mudNFgCS",
"isInheritable": false,
"position": 80
},
{
"type": "relation",
"name": "internalLink",
"value": "BCkXAVs63Ttv",
"isInheritable": false,
"position": 90
} }
], ],
"format": "markdown", "format": "markdown",
@ -4190,19 +4190,19 @@
"type": "text", "type": "text",
"mime": "text/html", "mime": "text/html",
"attributes": [ "attributes": [
{
"type": "relation",
"name": "internalLink",
"value": "BCkXAVs63Ttv",
"isInheritable": false,
"position": 10
},
{ {
"type": "label", "type": "label",
"name": "iconClass", "name": "iconClass",
"value": "bx bxs-network-chart", "value": "bx bxs-network-chart",
"isInheritable": false, "isInheritable": false,
"position": 10 "position": 10
},
{
"type": "relation",
"name": "internalLink",
"value": "BCkXAVs63Ttv",
"isInheritable": false,
"position": 20
} }
], ],
"format": "markdown", "format": "markdown",
@ -5916,23 +5916,23 @@
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "iRwzGnHPzonm", "value": "bdUJEHsAPYQR",
"isInheritable": false, "isInheritable": false,
"position": 20 "position": 20
}, },
{
"type": "relation",
"name": "internalLink",
"value": "iRwzGnHPzonm",
"isInheritable": false,
"position": 30
},
{ {
"type": "label", "type": "label",
"name": "shareAlias", "name": "shareAlias",
"value": "note-map", "value": "note-map",
"isInheritable": false, "isInheritable": false,
"position": 30 "position": 30
},
{
"type": "relation",
"name": "internalLink",
"value": "bdUJEHsAPYQR",
"isInheritable": false,
"position": 40
} }
], ],
"format": "markdown", "format": "markdown",
@ -6887,21 +6887,21 @@
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "KSZ04uQ2D1St", "value": "_optionsTextNotes",
"isInheritable": false, "isInheritable": false,
"position": 10 "position": 10
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "_optionsTextNotes", "value": "_optionsCodeNotes",
"isInheritable": false, "isInheritable": false,
"position": 20 "position": 20
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "_optionsCodeNotes", "value": "KSZ04uQ2D1St",
"isInheritable": false, "isInheritable": false,
"position": 30 "position": 30
}, },
@ -6929,21 +6929,21 @@
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "gBbsAeiuUxI5", "value": "H0mM1lTxF9JI",
"isInheritable": false, "isInheritable": false,
"position": 70 "position": 70
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "N4IDkixaDG9C", "value": "gBbsAeiuUxI5",
"isInheritable": false, "isInheritable": false,
"position": 80 "position": 80
}, },
{ {
"type": "relation", "type": "relation",
"name": "internalLink", "name": "internalLink",
"value": "H0mM1lTxF9JI", "value": "N4IDkixaDG9C",
"isInheritable": false, "isInheritable": false,
"position": 90 "position": 90
}, },

View File

@ -7,7 +7,7 @@ import { initializeTranslations } from "./src/services/i18n.js";
import archiver, { type Archiver } from "archiver"; import archiver, { type Archiver } from "archiver";
import type { WriteStream } from "fs"; import type { WriteStream } from "fs";
import debounce from "./src/public/app/services/debounce.js"; import debounce from "./src/public/app/services/debounce.js";
import { extractZip, importData, initializeDatabase, startElectron } from "./electron-utils.js"; import { extractZip, initializeDatabase, startElectron } from "./electron-utils.js";
const NOTE_ID_USER_GUIDE = "pOsGYCXsbNQG"; const NOTE_ID_USER_GUIDE = "pOsGYCXsbNQG";
const markdownPath = path.join("docs", "User Guide"); const markdownPath = path.join("docs", "User Guide");
@ -16,8 +16,7 @@ const htmlPath = path.join("src", "public", "app", "doc_notes", "en", "User Guid
async function main() { async function main() {
await initializeTranslations(); await initializeTranslations();
const zipBuffer = await createImportZip(); const zipBuffer = await createImportZip();
await initializeDatabase(); await initializeDatabase(zipBuffer);
await importData(zipBuffer, NOTE_ID_USER_GUIDE, "User Guide", "The sub-children of this note are automatically synced.");
await startElectron(); await startElectron();
await registerHandlers(); await registerHandlers();
} }

View File

@ -3,12 +3,12 @@ import fs from "fs/promises";
import fsExtra from "fs-extra"; import fsExtra from "fs-extra";
import path from "path"; import path from "path";
export async function initializeDatabase() { export async function initializeDatabase(customDbBuffer?: Buffer) {
const sqlInit = (await import("./src/services/sql_init.js")).default; const sqlInit = (await import("./src/services/sql_init.js")).default;
cls.init(() => { cls.init(() => {
if (!sqlInit.isDbInitialized()) { if (!sqlInit.isDbInitialized()) {
sqlInit.createInitialDatabase(true); sqlInit.createInitialDatabase(true, customDbBuffer);
} }
}); });
} }
@ -17,48 +17,6 @@ export async function startElectron() {
await import("./electron-main.js"); await import("./electron-main.js");
} }
export function importData(input: Buffer, rootId: string, rootTitle: string, rootContent: string) {
return new Promise<void>((resolve, reject) => {
cls.init(async () => {
const beccaLoader = ((await import("./src/becca/becca_loader.js")).default);
const notes = ((await import("./src/services/notes.js")).default);
beccaLoader.load();
const becca = ((await import("./src/becca/becca.js")).default);
const utils = ((await import("./src/services/utils.js")).default);
const eraseService = ((await import("./src/services/erase.js")).default);
const deleteId = utils.randomString(10);
const existingNote = becca.getNote(rootId);
if (existingNote) {
existingNote.deleteNote(deleteId);
}
eraseService.eraseNotesWithDeleteId(deleteId);
const { note } = notes.createNewNoteWithTarget("into", "none_root", {
parentNoteId: "root",
noteId: rootId,
title: rootTitle,
content: rootContent,
type: "text"
});
const TaskContext = (await import("./src/services/task_context.js")).default;
const { importZip } = ((await import("./src/services/import/zip.js")).default);
const context = new TaskContext("no-report");
await importZip(context, input, note, { preserveIds: true });
const { runOnDemandChecks } = (await import("./src/services/consistency_checks.js")).default;
await runOnDemandChecks(true);
becca.reset();
beccaLoader.load();
resolve();
});
});
}
export async function extractZip(zipFilePath: string, outputPath: string) { export async function extractZip(zipFilePath: string, outputPath: string) {
const deferred = (await import("./src/services/utils.js")).deferred; const deferred = (await import("./src/services/utils.js")).deferred;

View File

@ -36,8 +36,8 @@
"electron:start-prod-nix-no-dir": "electron-rebuild --version 33.3.1 && npm run build:prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", "electron:start-prod-nix-no-dir": "electron-rebuild --version 33.3.1 && npm run build:prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"",
"electron:qstart": "npm run electron:switch && npm run electron:start", "electron:qstart": "npm run electron:switch && npm run electron:start",
"electron:switch": "electron-rebuild", "electron:switch": "electron-rebuild",
"docs:edit": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_ENV=dev TRILIUM_PORT=37741 electron ./electron-docs-main.ts .", "docs:edit": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_ENV=dev TRILIUM_INTEGRATION_TEST=memory-no-store TRILIUM_PORT=37741 electron ./electron-docs-main.ts .",
"docs:edit-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_PORT=37741 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-docs-main.ts .\"", "docs:edit-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_PORT=37741 TRILIUM_ENV=dev TRILIUM_INTEGRATION_TEST=memory-no-store nix-shell -p electron_33 --run \"electron ./electron-docs-main.ts .\"",
"demo:edit": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-demo TRILIUM_ENV=dev TRILIUM_INTEGRATION_TEST=memory-no-store TRILIUM_PORT=37741 electron ./electron-edit-demo.ts .", "demo:edit": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-demo TRILIUM_ENV=dev TRILIUM_INTEGRATION_TEST=memory-no-store TRILIUM_PORT=37741 electron ./electron-edit-demo.ts .",
"electron-forge:start": "npm run build:prepare-dist && cd ./build && electron-forge start", "electron-forge:start": "npm run build:prepare-dist && cd ./build && electron-forge start",
"electron-forge:make": "npm run build:prepare-dist && cross-env DEBUG=electron-windows-installer:* electron-forge make ./build", "electron-forge:make": "npm run build:prepare-dist && cross-env DEBUG=electron-windows-installer:* electron-forge make ./build",

View File

@ -64,13 +64,19 @@ async function initDbConnection() {
dbReady.resolve(); dbReady.resolve();
} }
async function createInitialDatabase(preserveIds?: boolean) { /**
* Applies the database schema, creating the necessary tables and importing the demo content.
*
* @param preserveIds `true` if the note IDs from the meta file should be preserved, or `false` to generate new ones (normal behaviour).
* @param customDbBuffer a custom database buffer to use, otherwise the default demo one is going to be used.
*/
async function createInitialDatabase(preserveIds?: boolean, customDbBuffer?: Buffer) {
if (isDbInitialized()) { if (isDbInitialized()) {
throw new Error("DB is already initialized"); throw new Error("DB is already initialized");
} }
const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, "utf-8"); const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, "utf-8");
const demoFile = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/demo.zip`); const demoFile = customDbBuffer ?? fs.readFileSync(`${resourceDir.DB_INIT_DIR}/demo.zip`);
let rootNote!: BNote; let rootNote!: BNote;