diff --git a/plugins/tiddlywiki/multiwikiserver/modules/command-mws-load.js b/plugins/tiddlywiki/multiwikiserver/modules/command-mws-load.js index 67b77c1eb..2a3c1173b 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/command-mws-load.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/command-mws-load.js @@ -41,7 +41,7 @@ function loadBackupArchive(archivePath) { const bagNames = fs.readdirSync(path.resolve(archivePath,"bags")).filter(filename => filename !== ".DS_Store"); for(const bagName of bagNames) { console.log(`Reading bag ${bagName}`); - $tw.sqlTiddlerStore.createBag(decodeURIComponent(bagName),"No description for " + bagName); + $tw.mws.store.createBag(decodeURIComponent(bagName),"No description for " + bagName); // Read the metadata const jsonInfo = JSON.parse(fs.readFileSync(path.resolve(archivePath,"bags",bagName,"meta/info.json"),"utf8")); if(fs.existsSync(path.resolve(archivePath,"bags",bagName,"tiddlers"))) { @@ -50,7 +50,7 @@ function loadBackupArchive(archivePath) { for(const tiddlerFilename of tiddlerFilenames) { const jsonTiddler = fs.readFileSync(path.resolve(archivePath,"bags",bagName,"tiddlers",tiddlerFilename),"utf8"), tiddler = JSON.parse(jsonTiddler); - $tw.sqlTiddlerStore.saveBagTiddler(tiddler,decodeURIComponent(bagName)); + $tw.mws.store.saveBagTiddler(tiddler,decodeURIComponent(bagName)); } } } @@ -58,7 +58,7 @@ function loadBackupArchive(archivePath) { const recipeNames = fs.readdirSync(path.resolve(archivePath,"recipes")).filter(filename => filename !== ".DS_Store"); for(const recipeName of recipeNames) { const jsonInfo = JSON.parse(fs.readFileSync(path.resolve(archivePath,"recipes",recipeName,"info.json"),"utf8")); - $tw.sqlTiddlerStore.createRecipe(decodeURIComponent(recipeName),jsonInfo.recipe.map(recipeLine => recipeLine[0]),"No description for " + recipeName); + $tw.mws.store.createRecipe(decodeURIComponent(recipeName),jsonInfo.recipe.map(recipeLine => recipeLine[0]),"No description for " + recipeName); } } diff --git a/plugins/tiddlywiki/multiwikiserver/modules/init.js b/plugins/tiddlywiki/multiwikiserver/modules/init.js index 97092e80c..13adcc003 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/init.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/init.js @@ -38,28 +38,30 @@ exports.startup = function() { var databasePath = path.resolve($tw.boot.wikiPath,"store/database.sqlite"); // Create and initialise the tiddler store var SqlTiddlerStore = require("$:/plugins/tiddlywiki/multiwikiserver/sql-tiddler-store.js").SqlTiddlerStore; - $tw.sqlTiddlerStore = new SqlTiddlerStore({ - databasePath: databasePath - }); + $tw.mws = { + store: new SqlTiddlerStore({ + databasePath: databasePath + }) + }; // Create docs bag and recipe - $tw.sqlTiddlerStore.createBag("docs","TiddlyWiki Documentation from https://tiddlywiki.com/"); - $tw.sqlTiddlerStore.createRecipe("docs",["docs"],"TiddlyWiki Documentation from https://tiddlywiki.com/"); - $tw.sqlTiddlerStore.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"tw5.com/tiddlers"),"docs"); - $tw.sqlTiddlerStore.createBag("dev-docs","TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/"); - $tw.sqlTiddlerStore.createRecipe("dev-docs",["dev-docs"],"TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/"); - $tw.sqlTiddlerStore.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"dev/tiddlers"),"dev-docs"); + $tw.mws.store.createBag("docs","TiddlyWiki Documentation from https://tiddlywiki.com/"); + $tw.mws.store.createRecipe("docs",["docs"],"TiddlyWiki Documentation from https://tiddlywiki.com/"); + $tw.mws.store.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"tw5.com/tiddlers"),"docs"); + $tw.mws.store.createBag("dev-docs","TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/"); + $tw.mws.store.createRecipe("dev-docs",["dev-docs"],"TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/"); + $tw.mws.store.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"dev/tiddlers"),"dev-docs"); // Create bags and recipes - $tw.sqlTiddlerStore.createBag("bag-alpha","A test bag"); - $tw.sqlTiddlerStore.createBag("bag-beta","Another test bag"); - $tw.sqlTiddlerStore.createBag("bag-gamma","A further test bag"); - $tw.sqlTiddlerStore.createRecipe("recipe-rho",["bag-alpha","bag-beta"],"First wiki"); - $tw.sqlTiddlerStore.createRecipe("recipe-sigma",["bag-alpha","bag-gamma"],"Second Wiki"); - $tw.sqlTiddlerStore.createRecipe("recipe-tau",["bag-alpha"],"Third Wiki"); - $tw.sqlTiddlerStore.createRecipe("recipe-upsilon",["bag-alpha","bag-gamma","bag-beta"],"Fourth Wiki"); + $tw.mws.store.createBag("bag-alpha","A test bag"); + $tw.mws.store.createBag("bag-beta","Another test bag"); + $tw.mws.store.createBag("bag-gamma","A further test bag"); + $tw.mws.store.createRecipe("recipe-rho",["bag-alpha","bag-beta"],"First wiki"); + $tw.mws.store.createRecipe("recipe-sigma",["bag-alpha","bag-gamma"],"Second Wiki"); + $tw.mws.store.createRecipe("recipe-tau",["bag-alpha"],"Third Wiki"); + $tw.mws.store.createRecipe("recipe-upsilon",["bag-alpha","bag-gamma","bag-beta"],"Fourth Wiki"); // Save tiddlers - $tw.sqlTiddlerStore.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Alpha"},"bag-alpha"); - $tw.sqlTiddlerStore.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Beta"},"bag-beta"); - $tw.sqlTiddlerStore.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Gamma"},"bag-gamma"); + $tw.mws.store.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Alpha"},"bag-alpha"); + $tw.mws.store.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Beta"},"bag-beta"); + $tw.mws.store.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Gamma"},"bag-gamma"); }; })(); diff --git a/plugins/tiddlywiki/multiwikiserver/modules/route-delete-recipe-tiddler.js b/plugins/tiddlywiki/multiwikiserver/modules/route-delete-recipe-tiddler.js index b16cbf47b..bedb1a8f2 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/route-delete-recipe-tiddler.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/route-delete-recipe-tiddler.js @@ -23,9 +23,9 @@ exports.handler = function(request,response,state) { var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]), bag_name = $tw.utils.decodeURIComponentSafe(state.params[1]), title = $tw.utils.decodeURIComponentSafe(state.params[2]); - var recipeBags = $tw.sqlTiddlerStore.getRecipeBags(recipe_name); + var recipeBags = $tw.mws.store.getRecipeBags(recipe_name); if(recipeBags.indexOf(bag_name) !== -1) { - $tw.sqlTiddlerStore.deleteTiddler(title,bag_name); + $tw.mws.store.deleteTiddler(title,bag_name); response.writeHead(204, "OK", { "Content-Type": "text/plain" }); diff --git a/plugins/tiddlywiki/multiwikiserver/modules/route-get-bag-tiddler.js b/plugins/tiddlywiki/multiwikiserver/modules/route-get-bag-tiddler.js index 2e278bd41..c5853b072 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/route-get-bag-tiddler.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/route-get-bag-tiddler.js @@ -23,7 +23,7 @@ exports.handler = function(request,response,state) { var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]), bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]), title = $tw.utils.decodeURIComponentSafe(state.params[2]), - result = bag_name === bag_name_2 && $tw.sqlTiddlerStore.getBagTiddler(title,bag_name); + result = bag_name === bag_name_2 && $tw.mws.store.getBagTiddler(title,bag_name); if(bag_name === bag_name_2 && result) { // If application/json is requested then this is an API request, and gets the response in JSON if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) { @@ -40,7 +40,7 @@ exports.handler = function(request,response,state) { } }); tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki"; - tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,bag_name,null); + tiddlerFields = $tw.mws.store.processCanonicalUriTiddler(tiddlerFields,bag_name,null); state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8"); } else { // This is not a JSON API request, we should return the raw tiddler content diff --git a/plugins/tiddlywiki/multiwikiserver/modules/route-get-bag.js b/plugins/tiddlywiki/multiwikiserver/modules/route-get-bag.js index c1f64c3a9..60848c33d 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/route-get-bag.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/route-get-bag.js @@ -22,7 +22,7 @@ exports.handler = function(request,response,state) { // Get the parameters var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]), bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]), - titles = bag_name === bag_name_2 && $tw.sqlTiddlerStore.getBagTiddlers(bag_name); + titles = bag_name === bag_name_2 && $tw.mws.store.getBagTiddlers(bag_name); if(bag_name === bag_name_2 && titles) { // If application/json is requested then this is an API request, and gets the response in JSON if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) { @@ -33,7 +33,7 @@ exports.handler = function(request,response,state) { "Content-Type": "text/html" }); // Render the html - var html = $tw.sqlTiddlerStore.adminWiki.renderTiddler("text/html","$:/plugins/tiddlywiki/multiwikiserver/templates/get-bags",{ + var html = $tw.mws.store.adminWiki.renderTiddler("text/html","$:/plugins/tiddlywiki/multiwikiserver/templates/get-bags",{ variables: { "bag-name": bag_name, "bag-titles": JSON.stringify(titles) diff --git a/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe-tiddler.js b/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe-tiddler.js index 4fa4fe78c..fcde7a297 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe-tiddler.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe-tiddler.js @@ -23,7 +23,7 @@ exports.handler = function(request,response,state) { var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]), recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]), title = $tw.utils.decodeURIComponentSafe(state.params[2]), - tiddlerInfo = recipe_name === recipe_name_2 && $tw.sqlTiddlerStore.getRecipeTiddler(title,recipe_name); + tiddlerInfo = recipe_name === recipe_name_2 && $tw.mws.store.getRecipeTiddler(title,recipe_name); if(recipe_name === recipe_name_2 && tiddlerInfo && tiddlerInfo.tiddler) { // If application/json is requested then this is an API request, and gets the response in JSON if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) { @@ -40,7 +40,7 @@ exports.handler = function(request,response,state) { } }); tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki"; - tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,null,recipe_name); + tiddlerFields = $tw.mws.store.processCanonicalUriTiddler(tiddlerFields,null,recipe_name); state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8"); } else { // This is not a JSON API request, we should return the raw tiddler content diff --git a/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe-tiddlers-json.js b/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe-tiddlers-json.js index f90d9d111..b1e7cc221 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe-tiddlers-json.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe-tiddlers-json.js @@ -24,11 +24,11 @@ exports.handler = function(request,response,state) { recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]); if(recipe_name === recipe_name_2) { // Get the tiddlers in the recipe - var recipeTiddlers = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name); + var recipeTiddlers = $tw.mws.store.getRecipeTiddlers(recipe_name); // Get a skinny version of each tiddler var tiddlers = []; $tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) { - var tiddlerInfo = $tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name); + var tiddlerInfo = $tw.mws.store.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name); tiddlers.push(Object.assign({},tiddlerInfo.tiddler,{text: undefined})); }); var text = JSON.stringify(tiddlers); diff --git a/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe.js b/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe.js index e4716f51f..64d095105 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/route-get-recipe.js @@ -26,9 +26,9 @@ exports.handler = function(request,response,state) { "Content-Type": "text/html" }); // Get the tiddlers in the recipe - var recipeTiddlers = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name); + var recipeTiddlers = $tw.mws.store.getRecipeTiddlers(recipe_name); // Render the template - var template = $tw.sqlTiddlerStore.adminWiki.renderTiddler("text/plain","$:/core/templates/tiddlywiki5.html",{ + var template = $tw.mws.store.adminWiki.renderTiddler("text/plain","$:/core/templates/tiddlywiki5.html",{ variables: { saveTiddlerFilter: ` $:/boot/boot.css @@ -50,10 +50,10 @@ exports.handler = function(request,response,state) { } response.write(template.substring(0,markerPos + marker.length)); $tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) { - var result = $tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name); + var result = $tw.mws.store.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name); if(result) { var tiddlerFields = result.tiddler; - tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,null,recipe_name); + tiddlerFields = $tw.mws.store.processCanonicalUriTiddler(tiddlerFields,null,recipe_name); response.write(JSON.stringify(tiddlerFields).replace(/