sqlmath 2023.4.22 → 2023.6.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,35 @@
3
3
  # Todo
4
4
  - none
5
5
 
6
+ # v2023.6.26
7
+ - sqlmath - fix broken interpolation in sql-function quantile().
8
+ - sqlmath - Add sql-function win_quantile1(), win_quantile2().
9
+ - sqlmath - Update sql-function win_slr2() to be vectorized.
10
+ - sqlmath - Add sql-function win_ema2().
11
+ - betadog - Add feature xema_xxx into ml model.
12
+ - sqlmath - Add sql-function win_slr().
13
+ - sqlmath - Add sql-function vec_win_slr_updatelast().
14
+ - sqlmath - Add sql-function vec_win_slr().
15
+ - sqlmath - Revamp struct Vector99.
16
+ - sqlmath - Add sql-function vec_concat().
17
+ - sqlmath - Add sql-function castrealornull().
18
+
19
+ # v2023.5.25
20
+ - ci - auto-update python version
21
+ - jslint - Add grammar for "export async function ...".
22
+ - sqlite - Remove hacky sqlite-extension-function.
23
+ - python - Migrate python-driver from pysqlite3 to cpython.
24
+ - jslint - Add grammar for regexp-named-capture-group and regexp-named-backreference.
25
+ - betadog - Reconcile differences with betadog.
26
+ - python - Successfully published first pypi package version sqlmath@v0.0.5.
27
+ - ci - Rename shell-function shRawLibFetch() to shRollupFetch().
28
+ - sqlmath - migrate build-ext from python to nodejs with parallel compile
29
+ - sqlmath - add python c-extension
30
+ - sqlmath - streamline macros SQLITE3_C2, SQLITE_H2, SQLITE3EXT_H2, SQLMATH_C2 in prepartion for python-c-extension
31
+ - sqlmath - add file zlib_rollup.c so sqlmath can be compiled without external zlib-dependency
32
+ - sqlmath - add sql-function avg_ema()
33
+ - sqlmath - add sql-function fill_forward()
34
+
6
35
  # v2023.4.22
7
36
  - sqlmath - rename sql-function percentile() to quantile()
8
37
  - ci - add shell-function shCiPreCustom2() to setup python in custom-ci
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  # Status
5
- | Branch | [master<br>(v2023.4.22)](https://github.com/sqlmath/sqlmath/tree/master) | [beta<br>(Web Demo)](https://github.com/sqlmath/sqlmath/tree/beta) | [alpha<br>(Development)](https://github.com/sqlmath/sqlmath/tree/alpha) |
5
+ | Branch | [master<br>(v2023.6.26)](https://github.com/sqlmath/sqlmath/tree/master) | [beta<br>(Web Demo)](https://github.com/sqlmath/sqlmath/tree/beta) | [alpha<br>(Development)](https://github.com/sqlmath/sqlmath/tree/alpha) |
6
6
  |--:|:--:|:--:|:--:|
7
7
  | CI | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Amaster) | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=beta)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Abeta) | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=alpha)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Aalpha) |
8
8
  | Coverage | [![coverage](https://sqlmath.github.io/sqlmath/branch-master/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-master/.artifact/coverage/index.html) | [![coverage](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/coverage/index.html) | [![coverage](https://sqlmath.github.io/sqlmath/branch-alpha/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-alpha/.artifact/coverage/index.html) |
@@ -30,6 +30,9 @@
30
30
 
31
31
  7. [License](#license)
32
32
 
33
+ 8. [Devops Instruction](#devops-instruction)
34
+ - [python pypi publish](#python-pypi-publish)
35
+
33
36
 
34
37
  <br><br>
35
38
  # Web Demo
@@ -106,3 +109,20 @@ PORT=8080 sh jslint_ci.sh shHttpFileServer
106
109
  - [indent.exe](indent.exe) is under [GPLv3 License](https://www.gnu.org/licenses/gpl-3.0.txt).
107
110
  - [sqlmath_jenks.c](sqlmath_jenks.c) is derived from [GPLv3 licensed CalcNaturalBreaks](https://www.geodms.nl/CalcNaturalBreaks).
108
111
  - Everything else is under MIT License.
112
+
113
+
114
+ <br><br>
115
+ # Devops Instruction
116
+
117
+
118
+ <br><br>
119
+ ### python pypi publish
120
+ ```shell
121
+ python -m build
122
+ #
123
+ twine upload --repository testpypi dist/sqlmath-2023.6.26*
124
+ py -m pip install --index-url https://test.pypi.org/simple/ sqlmath==2023.6.26
125
+ #
126
+ twine upload dist/sqlmath-2023.6.26*
127
+ pip install sqlmath==2023.6.26
128
+ ```
package/jslint.mjs CHANGED
@@ -165,7 +165,7 @@ let jslint_charset_ascii = (
165
165
  + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
166
166
  + "`abcdefghijklmnopqrstuvwxyz{|}~\u007f"
167
167
  );
168
- let jslint_edition = "v2022.4.1-beta";
168
+ let jslint_edition = "v2023.6.1-beta";
169
169
  let jslint_export; // The jslint object to be exported.
170
170
  let jslint_fudge = 1; // Fudge starting line and starting
171
171
  // ... column to 1.
@@ -1584,7 +1584,9 @@ ${name}<span class="apidocSignatureSpan">${signature}</span>
1584
1584
  ), "\n");
1585
1585
  return result;
1586
1586
  }));
1587
- // init module_list
1587
+
1588
+ // Init module_list.
1589
+
1588
1590
  module_list = await Promise.all(module_list.map(async function ({
1589
1591
  pathname
1590
1592
  }) {
@@ -1990,8 +1992,11 @@ async function jslint_cli({
1990
1992
  ).test(process_argv[1])
1991
1993
  || mode_cli
1992
1994
  )
1993
- && moduleUrl.fileURLToPath(import_meta_url)
1994
- === modulePath.resolve(process_argv[1])
1995
+ && (
1996
+ moduleUrl.fileURLToPath(import_meta_url)
1997
+ ===
1998
+ modulePath.resolve(process_argv[1])
1999
+ )
1995
2000
  )
1996
2001
  && !mode_cli
1997
2002
  ) {
@@ -2810,20 +2815,30 @@ function jslint_phase2_lex(state) {
2810
2815
  // Match a group that starts with left paren.
2811
2816
 
2812
2817
  char_after("(");
2813
- if (char === "?") {
2814
- char_after("?");
2815
- if (char === "=" || char === "!") {
2816
- char_after();
2817
- } else {
2818
- char_after(":");
2819
- }
2820
- } else if (char === ":") {
2818
+ switch (char) {
2819
+ case ":":
2821
2820
 
2822
2821
  // test_cause:
2823
2822
  // ["aa=/(:)/", "lex_regexp_group", "expected_a_before_b", ":", 6]
2824
2823
  // ["aa=/?/", "lex_regexp_group", "expected_a_before_b", "?", 5]
2825
2824
 
2826
2825
  warn_at("expected_a_before_b", line, column, "?", ":");
2826
+ break;
2827
+ case "?":
2828
+ char_after("?");
2829
+ switch (char) {
2830
+ case "!":
2831
+
2832
+ // PR-437 - Add grammar for regexp-named-capture-group.
2833
+
2834
+ case "<":
2835
+ case "=":
2836
+ char_after();
2837
+ break;
2838
+ default:
2839
+ char_after(":");
2840
+ }
2841
+ break;
2827
2842
  }
2828
2843
 
2829
2844
  // RegExp
@@ -2857,7 +2872,10 @@ function jslint_phase2_lex(state) {
2857
2872
  // ["aa=/\\/", "lex_regexp_group", "escape", "", 0]
2858
2873
 
2859
2874
  test_cause("escape");
2860
- char_after_escape("BbDdSsWw^${}[]():=!.|*+?");
2875
+
2876
+ // PR-437 - Add grammar for regexp-named-backreference.
2877
+
2878
+ char_after_escape("BbDdSsWw^${}[]():=!.|*+?k");
2861
2879
  break;
2862
2880
  case "^":
2863
2881
  if (snippet !== "^") {
@@ -3309,7 +3327,7 @@ function jslint_phase2_lex(state) {
3309
3327
  case "this": // Allow 'this'.
3310
3328
  case "trace": // Include jslint stack-trace in warnings.
3311
3329
  case "unordered": // Allow unordered cases, params, properties,
3312
- // ... and variables.
3330
+ // ... variables, and exports.
3313
3331
  case "variable": // Allow unordered const and let declarations
3314
3332
  // ... that are not at top of function-scope.
3315
3333
  case "white": // Allow messy whitespace.
@@ -6170,7 +6188,8 @@ function jslint_phase3_parse(state) {
6170
6188
  }
6171
6189
 
6172
6190
  function stmt_export() {
6173
- const the_export = token_now;
6191
+ let export_list = [];
6192
+ let the_export = token_now;
6174
6193
  let the_id;
6175
6194
  let the_name;
6176
6195
  let the_thing;
@@ -6214,9 +6233,13 @@ function jslint_phase3_parse(state) {
6214
6233
  export_dict.default = the_thing;
6215
6234
  the_export.expression.push(the_thing);
6216
6235
  } else {
6217
- if (token_nxt.id === "function") {
6236
+
6237
+ // PR-439 - Add grammar for "export async function ...".
6238
+
6239
+ if (token_nxt.id === "function" || token_nxt.id === "async") {
6218
6240
 
6219
6241
  // test_cause:
6242
+ // ["export async function aa(){}", "stmt_export", "freeze_exports", "async", 8]
6220
6243
  // ["export function aa(){}", "stmt_export", "freeze_exports", "function", 8]
6221
6244
 
6222
6245
  warn("freeze_exports");
@@ -6266,6 +6289,7 @@ function jslint_phase3_parse(state) {
6266
6289
  stop("expected_identifier_a");
6267
6290
  }
6268
6291
  the_id = token_nxt.id;
6292
+ export_list.push(token_nxt);
6269
6293
  the_name = token_global.context[the_id];
6270
6294
  if (the_name === undefined) {
6271
6295
 
@@ -6292,6 +6316,13 @@ function jslint_phase3_parse(state) {
6292
6316
  break;
6293
6317
  }
6294
6318
  }
6319
+
6320
+ // PR-439 - Check exported properties are ordered.
6321
+
6322
+ // test_cause:
6323
+ // ["export {bb, aa}", "check_ordered", "expected_a_b_before_c_d", "aa", 13]
6324
+
6325
+ check_ordered("export", export_list);
6295
6326
  advance("}");
6296
6327
  semicolon();
6297
6328
  } else {
@@ -6441,6 +6472,20 @@ function jslint_phase3_parse(state) {
6441
6472
  // }
6442
6473
 
6443
6474
  state.mode_module = true;
6475
+
6476
+ // PR-436 - Add grammar for side-effect import-statement.
6477
+
6478
+ if (token_nxt.id === "(string)") {
6479
+
6480
+ // test_cause:
6481
+ // ["import \"./aa.mjs\";", "stmt_import", "import_side_effect", "", 0]
6482
+
6483
+ test_cause("import_side_effect");
6484
+ warn("expected_a_b", token_nxt, "{", artifact());
6485
+ advance();
6486
+ semicolon();
6487
+ return the_import;
6488
+ }
6444
6489
  if (token_nxt.identifier) {
6445
6490
  name = token_nxt;
6446
6491
  advance();
@@ -11231,7 +11276,7 @@ function sentinel() {}
11231
11276
  if ((
11232
11277
  /^coverage-\d+?-\d+?-\d+?\.json$/
11233
11278
  ).test(file)) {
11234
- console.error("rm file " + coverageDir + file);
11279
+ consoleError("rm file " + coverageDir + file);
11235
11280
  await moduleFs.promises.unlink(coverageDir + file);
11236
11281
  }
11237
11282
  }));
@@ -11258,10 +11303,14 @@ function sentinel() {}
11258
11303
  }
11259
11304
  ).on("exit", resolve);
11260
11305
  });
11306
+ consoleError(
11307
+ `v8CoverageReportCreate - program exited with exitCode=${exitCode}`
11308
+ );
11261
11309
  }
11262
11310
 
11263
11311
  // 2. Merge JSON v8-coverage-files in <coverageDir>.
11264
11312
 
11313
+ consoleError("v8CoverageReportCreate - merging coverage files...");
11265
11314
  v8CoverageObj = await moduleFs.promises.readdir(coverageDir);
11266
11315
  v8CoverageObj = v8CoverageObj.filter(function (file) {
11267
11316
  return (
@@ -11333,6 +11382,7 @@ function sentinel() {}
11333
11382
 
11334
11383
  // 3. Create html-coverage-reports in <coverageDir>.
11335
11384
 
11385
+ consoleError("v8CoverageReportCreate - creating html-coverage-report...");
11336
11386
  fileDict = Object.create(null);
11337
11387
  await Promise.all(v8CoverageObj.result.map(async function ({
11338
11388
  functions,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "engines": {
12
12
  "node": ">=14"
13
13
  },
14
- "fileCount": 32,
14
+ "fileCount": 38,
15
15
  "homepage": "https://github.com/sqlmath/sqlmath",
16
16
  "keywords": [
17
17
  "data-science",
@@ -38,5 +38,5 @@
38
38
  },
39
39
  "shCiArtifactUpload": 1,
40
40
  "shCiNpmPublish": 1,
41
- "version": "2023.4.22"
41
+ "version": "2023.6.26"
42
42
  }
package/sqlmath.mjs CHANGED
@@ -61,6 +61,7 @@ let SQLITE_OPEN_TRANSIENT_DB = 0x00000400; /* VFS only */
61
61
  let SQLITE_OPEN_URI = 0x00000040; /* Ok for sqlite3_open_v2() */
62
62
  let SQLITE_OPEN_WAL = 0x00080000; /* VFS only */
63
63
  let cModule;
64
+ let cModulePath;
64
65
  let consoleError = console.error;
65
66
  let dbDict = new WeakMap(); // private-dict of sqlite-database-connections
66
67
  let dbFinalizationRegistry;
@@ -82,10 +83,21 @@ let debugInline = (function () {
82
83
  __consoleError = console.error; //jslint-ignore-line
83
84
  return debug;
84
85
  }());
86
+ let moduleChildProcess;
87
+ let moduleChildProcessSpawn;
88
+ let moduleFs;
89
+ let moduleFsInitResolveList;
90
+ let modulePath;
91
+ let moduleUrl;
92
+ let {
93
+ npm_config_mode_debug,
94
+ npm_config_mode_setup,
95
+ npm_config_mode_test
96
+ } = typeof process === "object" && process?.env;
85
97
  let sqlMessageDict = {}; // dict of web-worker-callbacks
86
98
  let sqlMessageId = 0;
87
99
  let sqlWorker;
88
- let version = "v2023.4.22";
100
+ let version = "v2023.6.26";
89
101
 
90
102
  function assertJsonEqual(aa, bb, message) {
91
103
 
@@ -227,6 +239,224 @@ async function cCallAsync(baton, cFuncName, ...argList) {
227
239
  }
228
240
  }
229
241
 
242
+ async function childProcessSpawn2(command, args, option) {
243
+
244
+ // This function will run child_process.spawn as a promise.
245
+
246
+ return await new Promise(function (resolve, reject) {
247
+ let bufList = [[], [], []];
248
+ let child;
249
+ let {
250
+ modeCapture,
251
+ modeDebug,
252
+ stdio
253
+ } = option;
254
+ if (modeDebug) {
255
+ consoleError(
256
+ `childProcessSpawn2 - ${command} ${JSON.stringify(args)}`
257
+ );
258
+ }
259
+ child = moduleChildProcessSpawn(
260
+ command,
261
+ args,
262
+ Object.assign({}, option, {
263
+ stdio: [
264
+ "ignore",
265
+ (
266
+ modeCapture
267
+ ? "pipe"
268
+ : stdio[1]
269
+ ),
270
+ (
271
+ modeCapture
272
+ ? "pipe"
273
+ : stdio[2]
274
+ )
275
+ ]
276
+ })
277
+ );
278
+ if (modeCapture) {
279
+ [
280
+ child.stdin, child.stdout, child.stderr
281
+ ].forEach(function (pipe, ii) {
282
+ if (ii === 0) {
283
+ return;
284
+ }
285
+ pipe.on("data", function (chunk) {
286
+ bufList[ii].push(chunk);
287
+ if (stdio[ii] !== "ignore") {
288
+ switch (ii) {
289
+ case 1:
290
+ process.stdout.write(chunk);
291
+ break;
292
+ case 2:
293
+ process.stderr.write(chunk);
294
+ break;
295
+ }
296
+ }
297
+ });
298
+ });
299
+ }
300
+ child.on("exit", function (exitCode) {
301
+ let resolve0 = resolve;
302
+ let stderr;
303
+ let stdout;
304
+ // coverage-hack
305
+ if (exitCode || npm_config_mode_test) {
306
+ resolve = reject;
307
+ }
308
+ // coverage-hack
309
+ if (npm_config_mode_test) {
310
+ resolve = resolve0;
311
+ }
312
+ [stdout, stderr] = bufList.slice(1).map(function (buf) {
313
+ return (
314
+ typeof modeCapture === "string"
315
+ ? Buffer.concat(buf).toString(modeCapture)
316
+ : Buffer.concat(buf)
317
+ );
318
+ });
319
+ resolve({exitCode, stderr, stdout});
320
+ });
321
+ });
322
+
323
+ }
324
+
325
+ async function ciBuildExt({
326
+ modeSkip,
327
+ process
328
+ }) {
329
+
330
+ // This function will build sqlmath from c.
331
+
332
+ let option;
333
+ option = {
334
+ binNodegyp: modulePath.resolve(
335
+ modulePath.dirname(process.execPath || ""),
336
+ "node_modules/npm/node_modules/node-gyp/bin/node-gyp.js"
337
+ ).replace("/bin/node_modules/", "/lib/node_modules/"),
338
+ isWin32: process.platform === "win32",
339
+ modeDebug: npm_config_mode_debug,
340
+ modeSkip,
341
+ process
342
+ };
343
+ await ciBuildExt2NodejsBuild(option);
344
+ }
345
+
346
+ async function ciBuildExt1NodejsConfigure({
347
+ binNodegyp,
348
+ modeDebug
349
+ }) {
350
+
351
+ // This function will setup posix/win32 env for building c-extension.
352
+
353
+ consoleError(`ciBuildExt1Nodejs - configure binding.gyp`);
354
+ await fsWriteFileUnlessTest("binding.gyp", JSON.stringify({
355
+ "target_defaults": {
356
+ "cflags": ["-Wextra", "-std=c11"],
357
+ "conditions": [
358
+ [
359
+ "OS == \u0027win\u0027",
360
+ {"defines": ["WIN32"]},
361
+ {"defines": ["HAVE_UNISTD_H"]}
362
+ ]
363
+ ],
364
+ // https://github.com/nodejs/node-gyp/blob/v9.3.1/gyp/pylib/gyp/MSVSSettings.py
365
+ "msvs_settings": {
366
+ "VCCLCompilerTool": {
367
+ "WarningLevel": 3
368
+ }
369
+ },
370
+ "xcode_settings": {"OTHER_CFLAGS": ["-Wextra", "-std=c11"]}
371
+ },
372
+ "targets": [
373
+ {
374
+ "cflags": [
375
+ "-Wno-all",
376
+ "-Wno-implicit-fallthrough",
377
+ "-Wno-unused-parameter"
378
+ ],
379
+ "sources": [
380
+ "build/SRC_ZLIB_BASE.c",
381
+ "build/SRC_SQLITE_BASE.c",
382
+ "build/SQLMATH_BASE.c"
383
+ ],
384
+ "target_name": "SRC_SQLITE_BASE",
385
+ "type": "static_library",
386
+ "xcode_settings": {"OTHER_CFLAGS": [
387
+ "-Wno-all",
388
+ "-Wno-implicit-fallthrough",
389
+ "-Wno-unused-parameter"
390
+ ]}
391
+ },
392
+ {
393
+ "sources": [
394
+ "build/SQLMATH_CUSTOM.c"
395
+ ],
396
+ "target_name": "SQLMATH_CUSTOM",
397
+ "type": "static_library"
398
+ },
399
+ {
400
+ "defines": ["SQLMATH_NODEJS_C2"],
401
+ "dependencies": [
402
+ "SQLMATH_CUSTOM",
403
+ "SRC_SQLITE_BASE"
404
+ ],
405
+ "sources": ["sqlmath_base.c"],
406
+ "target_name": "binding"
407
+ }
408
+ ]
409
+ }, undefined, 4) + "\n");
410
+ await childProcessSpawn2(
411
+ "sh",
412
+ [
413
+ "-c",
414
+ (`
415
+ (set -e
416
+ # node "${binNodegyp}" clean
417
+ node "${binNodegyp}" configure
418
+ )
419
+ `)
420
+ ],
421
+ {modeDebug, stdio: ["ignore", 1, 2]}
422
+ );
423
+ }
424
+
425
+ async function ciBuildExt2NodejsBuild({
426
+ binNodegyp,
427
+ modeDebug
428
+ }) {
429
+
430
+ // This function will archive <fileObj> into <fileLib>
431
+
432
+ if (!noop(
433
+ await fsExistsUnlessTest(cModulePath)
434
+ )) {
435
+ await ciBuildExt1NodejsConfigure({
436
+ binNodegyp,
437
+ modeDebug
438
+ });
439
+ }
440
+ consoleError(
441
+ `ciBuildExt2Nodejs - linking lib ${modulePath.resolve(cModulePath)}`
442
+ );
443
+ await childProcessSpawn2(
444
+ "sh",
445
+ [
446
+ "-c",
447
+ (`
448
+ (set -e
449
+ # rebuild binding
450
+ rm -rf build/Release/obj/SQLMATH_CUSTOM/
451
+ node "${binNodegyp}" build --release
452
+ mv build/Release/binding.node "${cModulePath}"
453
+ )
454
+ `)
455
+ ],
456
+ {modeDebug, stdio: ["ignore", 1, 2]}
457
+ );
458
+ }
459
+
230
460
  function dbCallAsync(baton, cFuncName, db, ...argList) {
231
461
 
232
462
  // This function will call <cFuncName> using db <argList>[0].
@@ -355,7 +585,7 @@ async function dbExecAsync({
355
585
  );
356
586
  modeRetry -= 1;
357
587
  await new Promise(function (resolve) {
358
- setTimeout(resolve, 5_000 * !process.env.npm_config_mode_test);
588
+ setTimeout(resolve, 5_000 * !npm_config_mode_test);
359
589
  });
360
590
  }
361
591
  }
@@ -540,6 +770,54 @@ async function dbOpenAsync({
540
770
  return db;
541
771
  }
542
772
 
773
+ async function fsCopyFileUnlessTest(file1, file2, mode) {
774
+
775
+ // This function will copy <file1> to <file2> unless <npm_config_mode_test> = 1.
776
+
777
+ if (npm_config_mode_test && mode !== "force") {
778
+ return;
779
+ }
780
+ await moduleFs.promises.copyFile(file1, file2, mode | 0);
781
+ }
782
+
783
+ async function fsExistsUnlessTest(file, mode) {
784
+
785
+ // This function will test if <file> exists unless <npm_config_mode_test> = 1.
786
+
787
+ if (npm_config_mode_test && mode !== "force") {
788
+ return false;
789
+ }
790
+ try {
791
+ await moduleFs.promises.access(file);
792
+ return true;
793
+ } catch (ignore) {
794
+ return false;
795
+ }
796
+ }
797
+
798
+ async function fsReadFileUnlessTest(file, mode, defaultData) {
799
+
800
+ // This function will read <data> from <file> unless <npm_config_mode_test> = 1.
801
+
802
+ if (npm_config_mode_test && mode !== "force") {
803
+ return defaultData;
804
+ }
805
+ return await moduleFs.promises.readFile(
806
+ file,
807
+ mode && mode.replace("force", "utf8")
808
+ );
809
+ }
810
+
811
+ async function fsWriteFileUnlessTest(file, data, mode) {
812
+
813
+ // This function will write <data> to <file> unless <npm_config_mode_test> = 1.
814
+
815
+ if (npm_config_mode_test && mode !== "force") {
816
+ return;
817
+ }
818
+ await moduleFs.promises.writeFile(file, data);
819
+ }
820
+
543
821
  function isExternalBuffer(buf) {
544
822
 
545
823
  // This function will check if <buf> is ArrayBuffer or SharedArrayBuffer.
@@ -797,6 +1075,44 @@ function jsbatonValueString({
797
1075
  ));
798
1076
  }
799
1077
 
1078
+ async function moduleFsInit() {
1079
+
1080
+ // This function will import nodejs builtin-modules if they have not yet been
1081
+ // imported.
1082
+
1083
+ // State 3 - Modules already imported.
1084
+
1085
+ if (moduleFs !== undefined) {
1086
+ return;
1087
+ }
1088
+
1089
+ // State 2 - Wait while modules are importing.
1090
+
1091
+ if (moduleFsInitResolveList !== undefined) {
1092
+ return new Promise(function (resolve) {
1093
+ moduleFsInitResolveList.push(resolve);
1094
+ });
1095
+ }
1096
+
1097
+ // State 1 - Start importing modules.
1098
+
1099
+ moduleFsInitResolveList = [];
1100
+ [
1101
+ moduleChildProcess,
1102
+ moduleFs,
1103
+ modulePath,
1104
+ moduleUrl
1105
+ ] = await Promise.all([
1106
+ import("child_process"),
1107
+ import("fs"),
1108
+ import("path"),
1109
+ import("url")
1110
+ ]);
1111
+ while (moduleFsInitResolveList.length > 0) {
1112
+ moduleFsInitResolveList.shift()();
1113
+ }
1114
+ }
1115
+
800
1116
  function noop(val) {
801
1117
 
802
1118
  // This function will do nothing except return <val>.
@@ -885,13 +1201,16 @@ async function sqlmathInit() {
885
1201
 
886
1202
  // This function will init sqlmath.
887
1203
 
888
- dbFinalizationRegistry = new FinalizationRegistry(function ({
1204
+ let moduleModule;
1205
+ dbFinalizationRegistry = (
1206
+ dbFinalizationRegistry
1207
+ ) || new FinalizationRegistry(function ({
889
1208
  afterFinalization,
890
1209
  ptr
891
1210
  }) {
892
1211
 
893
- // This function will auto-close any open sqlite3-db-pointer,
894
- // after its js-wrapper has been garbage-collected.
1212
+ // This function will auto-close any open sqlite3-db-pointer,
1213
+ // after its js-wrapper has been garbage-collected.
895
1214
 
896
1215
  cCallAsync(undefined, "_dbClose", ptr[0]);
897
1216
  if (afterFinalization) {
@@ -902,23 +1221,69 @@ async function sqlmathInit() {
902
1221
  // Feature-detect nodejs.
903
1222
 
904
1223
  if (
905
- typeof process === "object"
906
- && typeof process?.versions?.node === "string"
1224
+ !(
1225
+ typeof process === "object"
1226
+ && typeof process?.versions?.node === "string"
1227
+ )
1228
+ || cModule
907
1229
  ) {
908
- cModule = await import("module");
909
- cModule = cModule.createRequire(import.meta.url);
910
- cModule = cModule(
911
- "./_binary_sqlmath"
912
- + "_napi8"
913
- + "_" + process.platform
914
- + "_" + process.arch
915
- + ".node"
916
- );
917
- if (process.env.npm_config_mode_test) {
918
- // mock consoleError
919
- consoleError = noop;
1230
+ return;
1231
+ }
1232
+
1233
+ // Init moduleFs.
1234
+
1235
+ await moduleFsInit();
1236
+ moduleFsInit(); // coverage-hack
1237
+ moduleChildProcessSpawn = moduleChildProcess.spawn;
1238
+
1239
+ // Init moduleFs.
1240
+
1241
+ await moduleFsInit();
1242
+ moduleFsInit(); // coverage-hack
1243
+ moduleChildProcessSpawn = moduleChildProcess.spawn;
1244
+ cModulePath = moduleUrl.fileURLToPath(import.meta.url).replace(
1245
+ (/\bsqlmath\.mjs$/),
1246
+ `_sqlmath.napi6_${process.platform}_${process.arch}.node`
1247
+ );
1248
+
1249
+ // Import napi c-addon.
1250
+
1251
+ if (!npm_config_mode_setup) {
1252
+ moduleModule = await import("module");
1253
+ if (!cModule) {
1254
+ cModule = moduleModule.createRequire(cModulePath);
1255
+ cModule = cModule(cModulePath);
920
1256
  }
921
1257
  }
1258
+ if (npm_config_mode_test) {
1259
+
1260
+ // Mock consoleError.
1261
+
1262
+ consoleError = noop;
1263
+
1264
+ // Mock moduleChildProcessSpawn.
1265
+
1266
+ moduleChildProcessSpawn = function () {
1267
+ let child = {
1268
+ end: noop,
1269
+ on: function (onType, resolve) {
1270
+ switch (onType) {
1271
+ case "data":
1272
+ resolve(Buffer.alloc(0));
1273
+ return;
1274
+ default:
1275
+ resolve(0);
1276
+ }
1277
+ },
1278
+ setEncoding: noop,
1279
+ write: noop
1280
+ };
1281
+ child.stderr = child;
1282
+ child.stdin = child;
1283
+ child.stdout = child;
1284
+ return child;
1285
+ };
1286
+ }
922
1287
  }
923
1288
 
924
1289
  function sqlmathWebworkerInit({
@@ -964,7 +1329,9 @@ function sqlmathWebworkerInit({
964
1329
  }
965
1330
  }
966
1331
 
967
- await sqlmathInit({});
1332
+ sqlmathInit(); // coverage-hack
1333
+ await sqlmathInit();
1334
+ sqlmathInit(); // coverage-hack
968
1335
 
969
1336
  export {
970
1337
  SQLITE_MAX_LENGTH2,
@@ -992,6 +1359,8 @@ export {
992
1359
  assertJsonEqual,
993
1360
  assertNumericalEqual,
994
1361
  assertOrThrow,
1362
+ childProcessSpawn2,
1363
+ ciBuildExt,
995
1364
  dbCloseAsync,
996
1365
  dbExecAndReturnLastBlobAsync,
997
1366
  dbExecAndReturnLastJsonAsync,
@@ -1002,10 +1371,13 @@ export {
1002
1371
  dbNoopAsync,
1003
1372
  dbOpenAsync,
1004
1373
  debugInline,
1374
+ fsCopyFileUnlessTest,
1375
+ fsExistsUnlessTest,
1376
+ fsReadFileUnlessTest,
1377
+ fsWriteFileUnlessTest,
1005
1378
  jsbatonValueString,
1006
1379
  noop,
1007
1380
  objectDeepCopyWithKeysSorted,
1008
- sqlmathInit,
1009
1381
  sqlmathWebworkerInit,
1010
1382
  version
1011
1383
  };
Binary file
Binary file
Binary file