+++ /dev/null
-<!doctype html>
-<html lang="en-us">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
- <link rel="stylesheet" href="common/emscripten.css"/>
- <link rel="stylesheet" href="common/testing.css"/>
- <title>worker-promise (via ESM) tests</title>
- </head>
- <body>
- <header id='titlebar'><span>worker-promise (via ESM) tests</span></header>
- <!-- emscripten bits -->
- <figure id="module-spinner">
- <div class="spinner"></div>
- <div class='center'><strong>Initializing app...</strong></div>
- <div class='center'>
- On a slow internet connection this may take a moment. If this
- message displays for "a long time", intialization may have
- failed and the JavaScript console may contain clues as to why.
- </div>
- </figure>
- <div class="emscripten" id="module-status">Downloading...</div>
- <div class="emscripten">
- <progress value="0" max="100" id="module-progress" hidden='1'></progress>
- </div><!-- /emscripten bits -->
- <div>Most stuff on this page happens in the dev console.</div>
- <hr>
- <div id='test-output'></div>
- <script src="common/SqliteTestUtil.js"></script>
- <!--script src="demo-worker1-promiser.mjs"></script-->
- <script type="module">
- const T = globalThis.SqliteTestUtil;
- import {default as promiserFactory} from "./jswasm/sqlite3-worker1-promiser.mjs";
- console.log("promiserFactory =",promiserFactory);
- const promiserConfig = {
- debug: 1 ? undefined : (...args)=>console.debug('worker debug',...args),
- onunhandled: function(ev){
- error("Unhandled worker message:",ev.data);
- },
- onerror: function(ev){
- error("worker1 error:",ev);
- },
- /**
- The v1 interfaces uses an onready function. The v2 interface optionally
- accepts one but does not require it. If provided, it is called _before_
- the promise is resolved, and the promise is rejected if onready() throws.
- */
- onready: function(f){
- /* f === the function returned by promiserFactory().
- Ostensibly (f === workerPromise) but this function is
- called before the promiserFactory() Promise resolves, so
- before workerPromise is set. */
- console.warn("This is the v2 interface - you don't need an onready() function.");
- }
- };
- const workerPromise = await promiserFactory(promiserConfig)
- .then((func)=>{
- console.log("Init complete. Starting tests momentarily.");
- globalThis.sqlite3TestModule.setStatus(null)/*hide the HTML-side is-loading spinner*/;
- return func;
- });
-
- // Just to demonstrate rejection via onready() throwing:
- promiserFactory( function(f){
- throw new Error("Testing onready throw..");
- })
- .catch(e=>{ console.log("caught expected promise rejection:",e); });
-
-
-(async function(){
- const eOutput = document.querySelector('#test-output');
- const warn = console.warn.bind(console);
- const error = console.error.bind(console);
- const log = console.log.bind(console);
- const logHtml = async function(cssClass,...args){
- log.apply(this, args);
- const ln = document.createElement('div');
- if(cssClass) ln.classList.add(cssClass);
- ln.append(document.createTextNode(args.join(' ')));
- eOutput.append(ln);
- };
-
- let startTime;
- const testCount = async ()=>{
- logHtml("","Total test count:",T.counter+". Total time =",(performance.now() - startTime),"ms");
- };
-
- //why is this triggered even when we catch() a Promise?
- //window.addEventListener('unhandledrejection', function(event) {
- // warn('unhandledrejection',event);
- //});
-
-
- const wtest = async function(msgType, msgArgs, callback){
- if(2===arguments.length && 'function'===typeof msgArgs){
- callback = msgArgs;
- msgArgs = undefined;
- }
- const p = 1
- ? workerPromise({type: msgType, args:msgArgs})
- : workerPromise(msgType, msgArgs);
- return callback ? p.then(callback).finally(testCount) : p;
- };
-
- let sqConfig;
- const runTests = async function(){
- const dbFilename = '/testing2.sqlite3';
- startTime = performance.now();
-
- await wtest('config-get', (ev)=>{
- const r = ev.result;
- log('sqlite3.config subset:', r);
- T.assert('boolean' === typeof r.bigIntEnabled);
- sqConfig = r;
- });
- logHtml('',
- "Sending 'open' message and waiting for its response before continuing...");
-
- await wtest('open', {
- filename: dbFilename,
- simulateError: 0 /* if true, fail the 'open' */,
- }, function(ev){
- const r = ev.result;
- log("then open result",r);
- T.assert(ev.dbId === r.dbId)
- .assert(ev.messageId)
- .assert('string' === typeof r.vfs);
- promiserConfig.dbId = ev.dbId;
- }).then(runTests2);
- };
-
- const runTests2 = async function(){
- const mustNotReach = ()=>toss("This is not supposed to be reached.");
-
- await wtest('exec',{
- sql: ["create table t(a,b)",
- "insert into t(a,b) values(1,2),(3,4),(5,6)"
- ].join(';'),
- resultRows: [], columnNames: [],
- countChanges: sqConfig.bigIntEnabled ? 64 : true
- }, function(ev){
- ev = ev.result;
- T.assert(0===ev.resultRows.length)
- .assert(0===ev.columnNames.length)
- .assert(sqConfig.bigIntEnabled
- ? (3n===ev.changeCount)
- : (3===ev.changeCount));
- });
-
- await wtest('exec',{
- sql: 'select a a, b b from t order by a',
- resultRows: [], columnNames: [],
- }, function(ev){
- ev = ev.result;
- T.assert(3===ev.resultRows.length)
- .assert(1===ev.resultRows[0][0])
- .assert(6===ev.resultRows[2][1])
- .assert(2===ev.columnNames.length)
- .assert('b'===ev.columnNames[1]);
- });
-
- await wtest('exec',{
- sql: 'select a a, b b from t order by a',
- resultRows: [], columnNames: [],
- rowMode: 'object',
- countChanges: true
- }, function(ev){
- ev = ev.result;
- T.assert(3===ev.resultRows.length)
- .assert(1===ev.resultRows[0].a)
- .assert(6===ev.resultRows[2].b)
- .assert(0===ev.changeCount);
- });
-
- await wtest(
- 'exec',
- {sql:'intentional_error'},
- mustNotReach
- ).catch((e)=>{
- warn("Intentional error:",e);
- });
-
- await wtest('exec',{
- sql:'select 1 union all select 3',
- resultRows: []
- }, function(ev){
- ev = ev.result;
- T.assert(2 === ev.resultRows.length)
- .assert(1 === ev.resultRows[0][0])
- .assert(3 === ev.resultRows[1][0])
- .assert(undefined === ev.changeCount);
- });
-
- const resultRowTest1 = function f(ev){
- if(undefined === f.counter) f.counter = 0;
- if(null === ev.rowNumber){
- /* End of result set. */
- T.assert(undefined === ev.row)
- .assert(2===ev.columnNames.length)
- .assert('a'===ev.columnNames[0])
- .assert('B'===ev.columnNames[1]);
- }else{
- T.assert(ev.rowNumber > 0);
- ++f.counter;
- }
- log("exec() result row:",ev);
- T.assert(null === ev.rowNumber || 'number' === typeof ev.row.B);
- };
- await wtest('exec',{
- sql: 'select a a, b B from t order by a limit 3',
- callback: resultRowTest1,
- rowMode: 'object'
- }, function(ev){
- T.assert(3===resultRowTest1.counter);
- resultRowTest1.counter = 0;
- });
-
- const resultRowTest2 = function f(ev){
- if(null === ev.rowNumber){
- /* End of result set. */
- T.assert(undefined === ev.row)
- .assert(1===ev.columnNames.length)
- .assert('a'===ev.columnNames[0])
- }else{
- T.assert(ev.rowNumber > 0);
- f.counter = ev.rowNumber;
- }
- log("exec() result row:",ev);
- T.assert(null === ev.rowNumber || 'number' === typeof ev.row);
- };
- await wtest('exec',{
- sql: 'select a a from t limit 3',
- callback: resultRowTest2,
- rowMode: 0
- }, function(ev){
- T.assert(3===resultRowTest2.counter);
- });
-
- const resultRowTest3 = function f(ev){
- if(null === ev.rowNumber){
- T.assert(3===ev.columnNames.length)
- .assert('foo'===ev.columnNames[0])
- .assert('bar'===ev.columnNames[1])
- .assert('baz'===ev.columnNames[2]);
- }else{
- f.counter = ev.rowNumber;
- T.assert('number' === typeof ev.row);
- }
- };
- await wtest('exec',{
- sql: "select 'foo' foo, a bar, 'baz' baz from t limit 2",
- callback: resultRowTest3,
- columnNames: [],
- rowMode: '$bar'
- }, function(ev){
- log("exec() result row:",ev);
- T.assert(2===resultRowTest3.counter);
- });
-
- await wtest('exec',{
- sql:[
- 'pragma foreign_keys=0;',
- // ^^^ arbitrary query with no result columns
- 'select a, b from t order by a desc; select a from t;'
- // exec() only honors SELECT results from the first
- // statement with result columns (regardless of whether
- // it has any rows).
- ],
- rowMode: 1,
- resultRows: []
- },function(ev){
- const rows = ev.result.resultRows;
- T.assert(3===rows.length).
- assert(6===rows[0]);
- });
-
- await wtest('exec',{sql: 'delete from t where a>3'});
-
- await wtest('exec',{
- sql: 'select count(a) from t',
- resultRows: []
- },function(ev){
- ev = ev.result;
- T.assert(1===ev.resultRows.length)
- .assert(2===ev.resultRows[0][0]);
- });
-
- await wtest('export', function(ev){
- ev = ev.result;
- T.assert('string' === typeof ev.filename)
- .assert(ev.byteArray instanceof Uint8Array)
- .assert(ev.byteArray.length > 1024)
- .assert('application/x-sqlite3' === ev.mimetype);
- });
-
- /***** close() tests must come last. *****/
- await wtest('close',{},function(ev){
- T.assert('string' === typeof ev.result.filename);
- });
-
- await wtest('close', (ev)=>{
- T.assert(undefined === ev.result.filename);
- }).finally(()=>logHtml('',"That's all, folks!"));
- }/*runTests2()*/;
-
- runTests();
-})();
-</script>
- </body>
-</html>
Demonstration of the sqlite3 Worker API #1 Promiser: a Promise-based
proxy for for the sqlite3 Worker #1 API.
*/
-'use strict';
+//#if target=es6-module
+import {default as promiserFactory} from "./jswasm/sqlite3-worker1-promiser.mjs";
+//#else
+"use strict";
+const promiserFactory = globalThis.sqlite3Worker1Promiser.v2;
+delete globalThis.sqlite3Worker1Promiser;
+//#endif
(async function(){
const T = globalThis.SqliteTestUtil;
const eOutput = document.querySelector('#test-output');
logHtml("","Total test count:",T.counter+". Total time =",(performance.now() - startTime),"ms");
};
- //why is this triggered even when we catch() a Promise?
- //window.addEventListener('unhandledrejection', function(event) {
- // warn('unhandledrejection',event);
- //});
-
const promiserConfig = {
- worker: ()=>{
- const w = new Worker("jswasm/sqlite3-worker1.js");
- w.onerror = (event)=>error("worker.onerror",event);
- return w;
+//#ifnot target=es6-module
+ /**
+ The v1 interfaces uses an onready function. The v2 interface optionally
+ accepts one but does not require it. If provided, it is called _before_
+ the promise is resolved, and the promise is rejected if onready() throws.
+ */
+ onready: function(f){
+ /* f === the function returned by promiserFactory().
+ Ostensibly (f === workerPromise) but this function is
+ called before the promiserFactory() Promise resolves, so
+ before workerPromise is set. */
+ console.warn("This is the v2 interface - you don't need an onready() function.");
},
+//#endif
debug: 1 ? undefined : (...args)=>console.debug('worker debug',...args),
onunhandled: function(ev){
error("Unhandled worker message:",ev.data);
},
onerror: function(ev){
error("worker1 error:",ev);
- },
- onready: function(f){
- warn("This is the v2 interface - don't pass an onready() function.");
}
};
- const workerPromise = await globalThis.sqlite3Worker1Promiser.v2(promiserConfig)
+ const workerPromise = await promiserFactory(promiserConfig)
.then((func)=>{
- log("Init complete. Starting tests momentarily.");
+ console.log("Init complete. Starting tests momentarily.");
globalThis.sqlite3TestModule.setStatus(null)/*hide the HTML-side is-loading spinner*/;
return func;
});
- delete globalThis.sqlite3Worker1Promiser;
const wtest = async function(msgType, msgArgs, callback){
if(2===arguments.length && 'function'===typeof msgArgs){
-C wasm\spromiser.v2\sis\sessentially\sworking\sbut\sthe\sdemo\scode\sis\sdouble-loading\sthe\smodule\sfor\sas-yet-undetermined\sreasons.
-D 2024-03-07T17:56:08.872
+C Resolve\sduplicate\sloading\sof\spromiser\sv2\sdemo\scode\s(a\sside\seffect\sof\shaving\sdone\sprecisely\swhat\sit\swas\stold\sto\sdo).\sConsolidate\sdemo-worker1-promiser(-esm).html/(m)js\svariants\sinto\scentral\scopies\sprocessed\swith\sc-pp.
+D 2024-03-07T18:53:27.916
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c
F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb
F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
-F ext/wasm/GNUmakefile fc361b472fdbf1256931769339d6d6e866048f6fcdbbe4bc1a60bfe70034895f
+F ext/wasm/GNUmakefile 4bb4cf70a8153dd5b5fee17d724075c54174da630b424bbcf48c744633396f62
F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576
F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193
F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fe427645e1499618f5fa7bc670af850577d8bcc132df982078690c9bf8400baa
F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309
F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359
-F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js aff58bf96c253451af02194bf883e1c4851ef4ddbbff0cdd6cfca8f04231ec5d
+F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bd89edfe42a4d7122a6d6d405c5423cf00aabba1f76f6ea8e2dba9c628ddd91a
F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5
F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7
F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd
F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32e7be5bf
F ext/wasm/demo-jsstorage.html 409c4be4af5f207fb2877160724b91b33ea36a3cd8c204e8da1acb828ffe588e
F ext/wasm/demo-jsstorage.js 44e3ae7ec2483b6c511384c3c290beb6f305c721186bcf5398ca4e00004a06b8
-F ext/wasm/demo-worker1-promiser-esm.html 181039b54e1d88181626d7e157f0f8832a532cf5c0ff6a62607cdbcc746649f3
-F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98ab22f5786620b3354ed15f
-F ext/wasm/demo-worker1-promiser.js e4cd1089269d106dd3bd20684eaddcd176c73baa31867ba0e445c8e7e29160b5
+F ext/wasm/demo-worker1-promiser.c-pp.html 635cf90685805e21772a5f7a35d1ace80f98a9ef7c42ff04d7a125ddca7e5db8 w ext/wasm/demo-worker1-promiser.html
+F ext/wasm/demo-worker1-promiser.c-pp.js fcc628cb42fcfaf07d250477801de1e6deb1e319d003976612a0db8d76b9fccc w ext/wasm/demo-worker1-promiser.js
F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d
F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef
-F ext/wasm/dist.make 8a6e829868e88a67a82670c6bb5d7ffda5dc46aa3f227ba3563c346d246f96d5
+F ext/wasm/dist.make f2ce42305268fe33d4b50f6e4bb3daf4a60302a90736eee382f1b8af9ff32ec1
F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f
F ext/wasm/fiddle.make 3c2eace29255d6ddd219f5d8cc2728cb28b9fe717ea80b6062c2a6178947a16b
F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 0e272123ace55ed63fe86632671cca48e8965a28fc3625324984028729fc203f
-R c8505d5644abe3c20f07eb87db82c9ac
+P aa877ce0c3b3aa1accd6e5fcd722d1bfaa79bea28c04c6badd8a547cea4bbc63
+R defcc9933f81850986aa7430cee8afd6
U stephan
-Z 20c543fa694914574de31b908812d405
+Z bec63fded5235320bd7ff6ae8e1104cd
# Remove this line to create a well-formed Fossil manifest.