assertOrThrow = function (passed, message) {
/*
* this function will throw err.<message> if <passed> is falsy
*/
let err;
if (passed) {
return;
}
err = (
(
message
&& typeof message.message === "string"
&& typeof message.stack === "string"
)
// if message is errObj, then leave as is
? message
: new Error(
typeof message === "string"
// if message is a string, then leave as is
? message
// else JSON.stringify message
: JSON.stringify(message, undefined, 4)
)
);
throw err;
}
n/a
coalesce = function (...argList) {
/*
* this function will coalesce null, undefined, or "" in <argList>
*/
let arg;
let ii;
ii = 0;
while (ii < argList.length) {
arg = argList[ii];
if (arg !== null && arg !== undefined && arg !== "") {
break;
}
ii += 1;
}
return arg;
}
n/a
default = function (moduleConfig) { if (initSqlJsPromise){ return initSqlJsPromise; } // If we're here, we've never called this function before initSqlJsPromise = new Promise((resolveModule, reject) => { // We are modularizing this manually because the current modularize setting in Emscripten has some issues: // https://github.com/kripken/emscripten/issues/5820 // The way to affect the loading of emcc compiled modules is to create a variable called `Module` and add // properties to it, like `preRun`, `postRun`, etc // We are using that to get notified when the WASM has finished loading. // Only then will we return our promise // If they passed in a moduleConfig object, use that // Otherwise, initialize Module to the empty object var Module = typeof moduleConfig !== 'undefined' ? moduleConfig : {}; // EMCC only allows for a single onAbort function (not an array of functions) // So if the user defined their own onAbort function, we remember it and call it var originalOnAbortFunction = Module['onAbort']; Module['onAbort'] = function (errorThatCausedAbort) { reject(new Error(errorThatCausedAbort)); if (originalOnAbortFunction){ originalOnAbortFunction(errorThatCausedAbort); } }; Module['postRun'] = Module['postRun'] || []; Module['postRun'].push(function () { // When Emscripted calls postRun, this promise resolves with the built Module resolveModule(Module); }); // There is a section of code in the emcc-generated code below that looks like this: // (Note that this is lowercase `module`) // if (typeof module !== 'undefined') { // module['exports'] = Module; // } // When that runs, it's going to overwrite our own modularization export efforts in shell-post.js! // The only way to tell emcc not to emit it is to pass the MODULARIZE=1 or MODULARIZE_INSTANCE=1 flags, // but that carries with it additional unnecessary baggage/bugs we don't want either. // So, we have three options: // 1) We undefine `module` // 2) We remember what `module['exports']` was at the beginning of this function and we restore it later // 3) We write a script to remove those lines of code as part of the Make process. // // Since those are the only lines of code that care about module, we will undefine it. It's the most straightforward // of the options, and has the side effect of reducing emcc's efforts to modify the module if its output were to change in the future. // That's a nice side effect since we're handling the modularization efforts ourselves var module = undefined; // The emcc-generated code and shell-post.js code goes below, // meaning that all of it runs inside of this promise. If anything throws an exception, our promise will abort // Copyright 2010 The Emscripten Authors. All rights reserved. // Emscripten is available under two separate licenses, the MIT license and the // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. // The Module object: Our interface to the outside world. We import // and export values on it. There are various ways Module can be used: // 1. Not defined. We create it here // 2. A function parameter, function(Module) { ..generated code.. } // 3. pre-run appended it, var Module = {}; ..generated code.. // 4. External script tag defines var Module. // We need to check if Module already exists (e.g. case 3 above). // Substitution will be replaced with actual code on later stage of the build, // this way Closure Compiler will not mangle it (e.g. case 4. above). // Note that if you want to run closure, and also to use Module // after the genera...
n/a
fsRmrfSync = function (dir) {
/*
* this function will sync "rm -rf" <dir>
*/
let child_process;
try {
child_process = require("child_process");
} catch (ignore) {
return;
}
child_process.spawnSync("rm", [
"-rf", dir
], {
stdio: [
"ignore", 1, 2
]
});
}
n/a
fsWriteFileWithMkdirpSync = function (file, data) {
/*
* this function will sync write <data> to <file> with "mkdir -p"
*/
let fs;
try {
fs = require("fs");
} catch (ignore) {
return;
}
// try to write file
try {
fs.writeFileSync(file, data);
} catch (ignore) {
// mkdir -p
require("child_process").spawnSync(
"mkdir",
[
"-p", require("path").dirname(file)
],
{
stdio: [
"ignore", 1, 2
]
}
);
// rewrite file
fs.writeFileSync(file, data);
}
}
n/a
functionOrNop = function (fnc) {
/*
* this function will if <fnc> exists,
* return <fnc>,
* else return <nop>
*/
return fnc || local.nop;
}
n/a
identity = function (val) {
/*
* this function will return <val>
*/
return val;
}
n/a
nop = function () {
/*
* this function will do nothing
*/
return;
}
n/a
objectAssignDefault = function (target, source) {
/*
* this function will if items from <target> are null, undefined, or "",
* then overwrite them with items from <source>
*/
target = target || {};
Object.keys(source || {}).forEach(function (key) {
if (
target[key] === null
|| target[key] === undefined
|| target[key] === ""
) {
target[key] = target[key] || source[key];
}
});
return target;
}
...
}).join(" ").replace((
/\u001b\[\d*m/g
), "") + "\n";
// scroll textarea to bottom
elem.scrollTop = elem.scrollHeight;
};
});
local.objectAssignDefault(local, globalThis.domOnEventDelegateDict);
globalThis.domOnEventDelegateDict = local;
}());
// run node js-env code - init-test
(function () {
...
querySelector = function (selectors) {
/*
* this function will return first dom-elem that match <selectors>
*/
return (
typeof document === "object" && document
&& typeof document.querySelector === "function"
&& document.querySelector(selectors)
) || {};
}
...
local.querySelector = function (selectors) {
/*
* this function will return first dom-elem that match <selectors>
*/
return (
typeof document === "object" && document
&& typeof document.querySelector === "function"
&& document.querySelector(selectors)
) || {};
};
local.querySelectorAll = function (selectors) {
/*
* this function will return dom-elem-list that match <selectors>
*/
return (
...
querySelectorAll = function (selectors) {
/*
* this function will return dom-elem-list that match <selectors>
*/
return (
typeof document === "object" && document
&& typeof document.querySelectorAll === "function"
&& Array.from(document.querySelectorAll(selectors))
) || [];
}
...
local.querySelectorAll = function (selectors) {
/*
* this function will return dom-elem-list that match <selectors>
*/
return (
typeof document === "object" && document
&& typeof document.querySelectorAll === "function"
&& Array.from(document.querySelectorAll(selectors))
) || [];
};
// require builtin
if (!local.isBrowser) {
local.assert = require("assert");
local.buffer = require("buffer");
local.child_process = require("child_process");
...
sqljsExec = function (msg) {
/*
* this function will post <msg> to worker and return a promise
*/
let callback;
let err;
// preserve stack-trace
err = new Error();
// normalize <msg>
if (typeof msg === "string") {
msg = {
sql: msg
};
}
msg = Object.assign({
action: "exec",
sql: "\n"
}, msg);
return new Promise(function (resolve, reject) {
callback = function (data) {
// if <data>.error, then prepend it to <err>.stack and reject
if (data.error) {
err.message = data.error;
err.stack = data.error + "\n" + err.stack;
reject(err);
return;
}
resolve(data);
};
// increment callbackId
callbackId = (callbackId | 0) + 1;
msg.id = callbackId;
callbackDict[msg.id] = callback;
worker.postMessage(msg);
});
}
n/a
async function (opt) {
/*
* this function will export table <opt>.sql "SELECT ... FROM ..."
* from sqlite3
*/
let csv;
let data;
if (typeof opt === "string") {
opt = {
exportType: "dict",
sql: opt
};
}
data = (
await local.sqljsExec(opt)
).results[0] || {
columns: [
"column_1"
],
values: []
};
switch (opt.exportType) {
case "csv":
break;
// export - list of dict
case "dict":
return data.values.map(function (list) {
let dict;
dict = {};
data.columns.forEach(function (key, ii) {
dict[key] = list[ii];
});
return dict;
});
// export - list of list
default:
return data;
}
/*
https://tools.ietf.org/html/rfc4180#section-2
2. Definition of the CSV Format
While there are various specifications and implementations for the
CSV format (for ex. [4], [5], [6] and [7]), there is no formal
specification in existence, which allows for a wide variety of
interpretations of CSV files. This section documents the format that
seems to be followed by most implementations:
1. Each record is located on a separate line, delimited by a line
break (CRLF). For example:
aaa,bbb,ccc CRLF
zzz,yyy,xxx CRLF
2. The last record in the file may or may not have an ending line
break. For example:
aaa,bbb,ccc CRLF
zzz,yyy,xxx
3. There maybe an optional header line appearing as the first line
of the file with the same format as normal record lines. This
header will contain names corresponding to the fields in the file
and should contain the same number of fields as the records in
the rest of the file (the presence or absence of the header line
should be indicated via the optional "header" parameter of this
MIME type). For example:
field_name,field_name,field_name CRLF
aaa,bbb,ccc CRLF
zzz,yyy,xxx CRLF
4. Within the header and each record, there may be one or more
fields, separated by commas. Each line should contain the same
number of fields throughout the file. Spaces are considered part
of a field and should not be ignored. The last field in the
record must not be followed by a comma. For example:
aaa,bbb,ccc
5. Each field may or may not be enclosed in double quotes (however
some programs, such as Microsoft Excel, do not use double quotes
at all). If fields are not enclosed with double quotes, then
double quotes may not appear inside the fields. For example:
"aaa","bbb","ccc" CRLF
zzz,yyy,xxx
6. Fields containing line breaks (CRLF), double quotes, and commas
should be enclosed in double-quotes. For example:
"aaa","b CRLF
bb","ccc" CRLF
zzz,yyy,xxx
7. If double-quotes are used to enclose fields, then a double-quote
appearing inside a field must be escaped by preceding it with
another double quote. For example:
"aaa","b""bb","ccc"
*/
csv = "";
/*
3. There maybe an optional header line appearing as the first line
of the file with the same format as normal record lines. This
header will contain names corresponding to the fields in the file
and should contain the same number of fields as the records in
the rest of the file (the presence or absence of the header line
should be indicated via the optional "header" parameter of this
MIME type). For example:
field_name,field_name,field_name CRLF
aaa,bbb,ccc CRLF
zzz,yyy,xxx CRLF
*/
data.values.unshift(data.columns);
data.values.forEach(function (row) {
csv += row.map(function (val) {
if (val === null) {
return "";
}
if (typeof val === "string") {
/*
7. If double-quotes are used to enclose fields, then a double-quote
appearing inside a field must be escaped by preceding it with
another double quote. For example:
"aaa...
n/a
async function (opt) {
/*
* this function will import table <opt>.csv or <opt>.values into sqlite3
*/
let byteLength;
let columns;
let csv;
let match;
let quote;
let rgx;
let row;
let rowLength;
let rowid;
let sqlCommand;
let sqlEnd;
let sqlExec;
let sqlInsert;
let sqlProgress;
let sqlSanitize;
let sqlStringify;
let tableName;
let timeStart;
let val;
let values;
sqlEnd = async function () {
/*
* this function will insert remaining rows into sqlite3
* and count inserted rows
*/
// insert remaining rows
sqlExec();
// handle null-case
if (!rowid) {
row = [
"column_1"
];
sqlInsert();
sqlExec();
}
// count inserted rows
return (
await local.sqljsExec({
sql: sqlSanitize("SELECT COUNT(*) FROM " + tableName + ";")
})
).results[0].values[0][0];
};
sqlExec = function () {
/*
* this function will exec <sqlCommand> in sqlite3
*/
let opt2;
if (!sqlCommand) {
return;
}
// init opt2
byteLength += sqlCommand.length;
opt2 = {
byteLength,
rowid
};
// exec <sqlCommand>
local.sqljsExec({
sql: sqlSanitize(
"INSERT INTO " + tableName + " VALUES\n"
+ sqlCommand.slice(0, -2)
+ ";"
)
}).then(function () {
sqlProgress(opt2);
});
// reset <sqlCommand>
sqlCommand = "";
};
sqlInsert = function () {
/*
* this function will insert <row> into sqlite3
*/
let ii;
let tmp;
// insert <columns>
if (!rowid && columns === "create") {
columns = row;
tmp = Array.from(row);
ii = 0;
while (ii < row.length) {
row[ii] = "column_" + (ii + 1);
ii += 1;
}
sqlInsert();
row = tmp;
}
// sql-stringify <row>
ii = 0;
while (ii < row.length) {
row[ii] = sqlStringify(row[ii]);
ii += 1;
}
// create table <tableName>
if (!rowid) {
rowLength = row.length;
local.sqljsExec({
sql: sqlSanitize(
"DROP TABLE IF EXISTS " + tableName + ";\n"
+ "CREATE TEMP TABLE " + tableName + " ("
+ row.join(" TEXT,") + " TEXT"
+ ");"
)
});
// reset <row>
row = [];
rowid += 1;
return;
}
if (row.length) {
// enforce <rowLength>
sqlCommand += "(";
ii = 0;
while (ii < rowLength) {
if (ii) {
sqlCommand += ",";
}
sqlCommand += row[ii] || "''";
ii += 1;
}
sqlCommand += "),\n";
// reset <row>
row = [];
rowid += 1;
}
// execute <sqlCommand>
if (sqlCommand.length && sqlCommand.length >= 0x100000) {
sqlExec();
return true;
}
};
sqlProgress = opt.sqlProgress || function (opt2) {
/*
* this function will give progress-updates
* when inserting large data (e.g. 100mb) into sqlite3
*/
console.error(
"sqljsTableImport"
+ " - " + (Date.now() - timeStart) + " ms"...
n/a
default = function (moduleConfig) { if (initSqlJsPromise){ return initSqlJsPromise; } // If we're here, we've never called this function before initSqlJsPromise = new Promise((resolveModule, reject) => { // We are modularizing this manually because the current modularize setting in Emscripten has some issues: // https://github.com/kripken/emscripten/issues/5820 // The way to affect the loading of emcc compiled modules is to create a variable called `Module` and add // properties to it, like `preRun`, `postRun`, etc // We are using that to get notified when the WASM has finished loading. // Only then will we return our promise // If they passed in a moduleConfig object, use that // Otherwise, initialize Module to the empty object var Module = typeof moduleConfig !== 'undefined' ? moduleConfig : {}; // EMCC only allows for a single onAbort function (not an array of functions) // So if the user defined their own onAbort function, we remember it and call it var originalOnAbortFunction = Module['onAbort']; Module['onAbort'] = function (errorThatCausedAbort) { reject(new Error(errorThatCausedAbort)); if (originalOnAbortFunction){ originalOnAbortFunction(errorThatCausedAbort); } }; Module['postRun'] = Module['postRun'] || []; Module['postRun'].push(function () { // When Emscripted calls postRun, this promise resolves with the built Module resolveModule(Module); }); // There is a section of code in the emcc-generated code below that looks like this: // (Note that this is lowercase `module`) // if (typeof module !== 'undefined') { // module['exports'] = Module; // } // When that runs, it's going to overwrite our own modularization export efforts in shell-post.js! // The only way to tell emcc not to emit it is to pass the MODULARIZE=1 or MODULARIZE_INSTANCE=1 flags, // but that carries with it additional unnecessary baggage/bugs we don't want either. // So, we have three options: // 1) We undefine `module` // 2) We remember what `module['exports']` was at the beginning of this function and we restore it later // 3) We write a script to remove those lines of code as part of the Make process. // // Since those are the only lines of code that care about module, we will undefine it. It's the most straightforward // of the options, and has the side effect of reducing emcc's efforts to modify the module if its output were to change in the future. // That's a nice side effect since we're handling the modularization efforts ourselves var module = undefined; // The emcc-generated code and shell-post.js code goes below, // meaning that all of it runs inside of this promise. If anything throws an exception, our promise will abort // Copyright 2010 The Emscripten Authors. All rights reserved. // Emscripten is available under two separate licenses, the MIT license and the // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. // The Module object: Our interface to the outside world. We import // and export values on it. There are various ways Module can be used: // 1. Not defined. We create it here // 2. A function parameter, function(Module) { ..generated code.. } // 3. pre-run appended it, var Module = {}; ..generated code.. // 4. External script tag defines var Module. // We need to check if Module already exists (e.g. case 3 above). // Substitution will be replaced with actual code on later stage of the build, // this way Closure Compiler will not mangle it (e.g. case 4. above). // Note that if you want to run closure, and also to use Module // after the genera...
n/a