Cleanup and clarify

This commit is contained in:
jeremy@jermolene.com
2023-06-23 16:58:46 +01:00
parent 831fb3996d
commit 8690936805
6 changed files with 55 additions and 42 deletions
@@ -1,17 +1,20 @@
/*\ /*\
title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.js title: $:/plugins/tiddlywiki/sqlite3store/init-sqlite3.js
type: text/plain type: application/javascript
Startup code injected as raw markup at the bottom of the body section Initialise sqlite3 and then boot TiddlyWiki
This file is spliced into the HTML file to be executed after the boot kernel has been loaded.
\*/ \*/
(function() { (function() {
// Get the main tiddler store // Get the main tiddler store out of the HTML file
var storeEl = document.querySelector("script.tiddlywiki-tiddler-store"); var storeEl = document.querySelector("script.tiddlywiki-tiddler-store"),
var tiddlerStore = JSON.parse(storeEl.textContent); tiddlerStore = JSON.parse(storeEl.textContent);
// Helper to get a tiddler from the store by title
function getTiddler(title) { function getTiddler(title) {
for(var t=0; t<tiddlerStore.length; t++) { for(var t=0; t<tiddlerStore.length; t++) {
var tiddler = tiddlerStore[t]; var tiddler = tiddlerStore[t];
@@ -21,21 +24,16 @@ function getTiddler(title) {
} }
return undefined; return undefined;
} }
// Get the shadow tiddlers of this plugin
var thisPlugin = getTiddler("$:/plugins/tiddlywiki/sqlite3store"); var thisPlugin = getTiddler("$:/plugins/tiddlywiki/sqlite3store"),
thisPluginTiddlers = JSON.parse(thisPlugin.text).tiddlers;
var thisPluginTiddlers = JSON.parse(thisPlugin.text).tiddlers;
// Execute the sqlite3 module // Execute the sqlite3 module
var sqlite3js = thisPluginTiddlers["$:/plugins/tiddlywiki/sqlite3store/sqlite3.js"].text; var sqlite3js = thisPluginTiddlers["$:/plugins/tiddlywiki/sqlite3store/sqlite3.js"].text,
context = {
var context = { exports: {}
exports: {} };
};
$tw.utils.evalSandboxed(sqlite3js,context,"$:/plugins/tiddlywiki/sqlite3store/sqlite3.js",true); $tw.utils.evalSandboxed(sqlite3js,context,"$:/plugins/tiddlywiki/sqlite3store/sqlite3.js",true);
// Create a Blob URL for the wasm data
// Create a Blob URL for our wasm data
var sqlite3wasm = thisPluginTiddlers["$:/plugins/tiddlywiki/sqlite3store/sqlite3.wasm"].text; var sqlite3wasm = thisPluginTiddlers["$:/plugins/tiddlywiki/sqlite3store/sqlite3.wasm"].text;
var decodedData = window.atob(sqlite3wasm), var decodedData = window.atob(sqlite3wasm),
uInt8Array = new Uint8Array(decodedData.length); uInt8Array = new Uint8Array(decodedData.length);
@@ -43,11 +41,9 @@ for (var i = 0; i < decodedData.length; ++i) {
uInt8Array[i] = decodedData.charCodeAt(i); uInt8Array[i] = decodedData.charCodeAt(i);
} }
var blobUrl = URL.createObjectURL(new Blob([uInt8Array],{type: "application/wasm"})); var blobUrl = URL.createObjectURL(new Blob([uInt8Array],{type: "application/wasm"}));
// Pass sqlite an URLSearchParams object containing the Blob URL of our wasm data // Pass sqlite an URLSearchParams object containing the Blob URL of our wasm data
self.sqlite3InitModuleState.urlParams = new URLSearchParams(); self.sqlite3InitModuleState.urlParams = new URLSearchParams();
self.sqlite3InitModuleState.urlParams.set("sqlite3.wasm",blobUrl); self.sqlite3InitModuleState.urlParams.set("sqlite3.wasm",blobUrl);
// Initialise sqlite // Initialise sqlite
self.sqlite3InitModule().then((sqlite3)=>{ self.sqlite3InitModule().then((sqlite3)=>{
// Save a reference to the sqlite3 object // Save a reference to the sqlite3 object
@@ -61,4 +57,4 @@ self.sqlite3InitModule().then((sqlite3)=>{
}); });
})(); })();
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.js //# sourceURL=$:/plugins/tiddlywiki/sqlite3store/init-sqlite3.js
@@ -2,5 +2,5 @@ title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup/bottombody
tags: $:/tags/RawMarkupWikified/BottomBody tags: $:/tags/RawMarkupWikified/BottomBody
`<script>` `<script>`
{{$:/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.js}} {{$:/plugins/tiddlywiki/sqlite3store/init-sqlite3.js}}
`</script>` `</script>`
@@ -0,0 +1,7 @@
title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup-bottomhead
tags: $:/tags/RawMarkupWikified
`<script>`
{{$:/plugins/tiddlywiki/sqlite3store/suppress-boot.js}}
{{$:/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js}}
`</script>`
@@ -1,6 +0,0 @@
title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup
tags: $:/tags/RawMarkupWikified
`<script>`
{{$:/plugins/tiddlywiki/sqlite3store/rawmarkup.js}}
`</script>`
@@ -1,22 +1,15 @@
/*\ /*\
title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup.js title: $:/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js
type: text/plain type: application/javascript
Startup code injected as raw markup A sqlite3 implementation of a wiki store object
This file is spliced into the HTML file to be executed before the boot kernel has been loaded.
\*/ \*/
(function() { (function() {
// Initialse skeleton TiddlyWiki global because we run before bootprefix.js and boot.js
window.$tw = window.$tw || Object.create(null);
$tw.hooks = $tw.hooks || { names: {}};
$tw.boot = $tw.boot || {};
$tw.boot.preloadDirty = $tw.boot.preloadDirty || [];
// Tell TiddlyWiki not to boot itself
$tw.boot.suppressBoot = true;
$tw.Wiki = function(options) { $tw.Wiki = function(options) {
// Create a test database and store and retrieve some data // Create a test database and store and retrieve some data
var db = new $tw.sqlite3.oo1.DB("/tiddlywiki.sqlite3","ct"); var db = new $tw.sqlite3.oo1.DB("/tiddlywiki.sqlite3","ct");
@@ -480,4 +473,4 @@ $tw.Wiki = function(options) {
}; };
})(); })();
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/rawmarkup.js //# sourceURL=$:/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js
@@ -0,0 +1,23 @@
/*\
title: $:/plugins/tiddlywiki/sqlite3store/suppress-boot.js
type: application/javascript
Suppress the usual synchronous startup process so that it can instead be done within the callback from sqlite3 initialisation.
This file is spliced into the HTML file to be executed before the boot kernel has been loaded.
\*/
(function() {
// Initialse skeleton TiddlyWiki global because we run before bootprefix.js and boot.js
window.$tw = window.$tw || Object.create(null);
$tw.hooks = $tw.hooks || { names: {}};
$tw.boot = $tw.boot || {};
$tw.boot.preloadDirty = $tw.boot.preloadDirty || [];
// Tell TiddlyWiki not to boot itself
$tw.boot.suppressBoot = true;
})();
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/suppress-boot.js