sqlmath 2022.9.20 → 2022.11.20

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
@@ -1,9 +1,32 @@
1
1
  # Changelog
2
2
 
3
3
  # Todo
4
- - add dbtable-crud-operations dbtableOpenCsv, dbtableOpenJson
5
4
  - none
6
5
 
6
+ # v2022.11.20
7
+ - ci - auto-update version-number in main mjs-module
8
+ - editor - update codemirror-editor to v5.65.10
9
+ - doc - add api-doc
10
+ - doc - document quickstart-build, quickstart-website
11
+ - sqlmath - bugfix - fix function dbFileImportOrExport() throwing incorrect error
12
+ - chart - improve ergonomics to attach database and import csv/json
13
+ - demo - add hotkeys ctrl-o to open database, ctrl-s to save database
14
+ - demo - streamline charts sector, subsector, stock into single logic
15
+ - sqlmath - remove unused sqlite-extensions carray, csv from file sqlite3_ext.c
16
+ - chart - add chart-options xstep, ystep
17
+ - ci - update to nodejs v18
18
+ - chart - redesign tooltip
19
+ - chart - add xvalueConvert option juliandayToDate
20
+ - chart - add dbtable-crud-operations dbtableImportCsv, dbtableImportJson
21
+ - chart - add intraday, 1-min chart
22
+
23
+ # v2022.10.20
24
+ - demo - add chart tradebot_historical_backtrack
25
+ - chart - allow hiding series by clicking it in plot-area
26
+ - coverage - add test-coverage for function sqlmathWebworkerInit()
27
+ - chart - use different color for category - short
28
+ - sqlmath - re-enable sql-function squared()
29
+
7
30
  # v2022.9.20
8
31
  - sqlmath - bugfix - handle null seriesList, xlabelList, xdata, ydata
9
32
  - sqlmath - revamp str99 with sqlite3_str
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  # Status
5
- | Branch | [master<br>(v2022.9.20)](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>(v2022.11.20)](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) |
@@ -15,11 +15,20 @@
15
15
 
16
16
  1. [Web Demo](#web-demo)
17
17
 
18
- 2. [Package Listing](#package-listing)
18
+ 2. [Quickstart Build](#quickstart-build)
19
+ - [To build sqlmath:](#to-build-sqlmath)
19
20
 
20
- 3. [Changelog](#changelog)
21
+ 3. [Quickstart Website](#quickstart-website)
22
+ - [To serve your own sqlmath website:](#to-serve-your-own-sqlmath-website)
21
23
 
22
- 4. [License](#license)
24
+ 4. [Documentation](#documentation)
25
+ - [API Doc](#api-doc)
26
+
27
+ 5. [Package Listing](#package-listing)
28
+
29
+ 6. [Changelog](#changelog)
30
+
31
+ 7. [License](#license)
23
32
 
24
33
 
25
34
  <br><br>
@@ -29,6 +38,54 @@
29
38
  [![screenshot](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/screenshot_browser__2fsqlmath_2fbranch-beta_2findex.html.png)](https://sqlmath.github.io/sqlmath/index.html)
30
39
 
31
40
 
41
+ <br><br>
42
+ # Quickstart Build
43
+
44
+
45
+ <br><br>
46
+ ### To build sqlmath:
47
+ ```shell
48
+ #!/bin/sh
49
+
50
+ # git clone sqlmath repo
51
+ git clone https://github.com/sqlmath/sqlmath --branch=beta --single-branch
52
+ cd sqlmath
53
+
54
+ # build nodejs binary ./_binary_sqlmath_napi8_xxx_x64.node
55
+ npm run test2
56
+
57
+ # build webassembly binary ./sqlmath_wasm.wasm
58
+ sh jslint_ci.sh shCiBuildWasm
59
+ ```
60
+
61
+
62
+ <br><br>
63
+ # Quickstart Website
64
+
65
+
66
+ <br><br>
67
+ ### To serve your own sqlmath website:
68
+ ```shell
69
+ #!/bin/sh
70
+
71
+ # cd <sqlmath repo>
72
+
73
+ # serve website at http://localhost:8080/index.html
74
+ PORT=8080 sh jslint_ci.sh shHttpFileServer
75
+ ```
76
+
77
+
78
+ <br><br>
79
+ # Documentation
80
+
81
+
82
+ <br><br>
83
+ ### API Doc
84
+ - https://sqlmath.github.io/sqlmath/apidoc.html
85
+
86
+ [![screenshot](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/screenshot_browser__2f.artifact_2fapidoc.html.png)](https://sqlmath.github.io/sqlmath/apidoc.html)
87
+
88
+
32
89
  <br><br>
33
90
  # Package Listing
34
91
  ![screenshot_package_listing.svg](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/screenshot_package_listing.svg)
Binary file
Binary file
Binary file
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.9.1-beta";
168
+ let jslint_edition = "v2022.12.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.
@@ -2038,13 +2038,6 @@ async function jslint_cli({
2038
2038
  return;
2039
2039
  }
2040
2040
 
2041
- // PR-349 - Detect cli-option --mode-vim-plugin.
2042
-
2043
- mode_wrapper_vim = (
2044
- process_argv.slice(2).indexOf("--mode-vim-plugin") >= 0
2045
- || mode_wrapper_vim
2046
- );
2047
-
2048
2041
  // Normalize file relative to process.cwd().
2049
2042
 
2050
2043
  process_argv.slice(2).some(function (arg) {
package/package.json CHANGED
@@ -37,5 +37,5 @@
37
37
  "test2": "sh jslint_ci.sh shCiBase",
38
38
  "test_win32": "node -e \"require('child_process').spawn('C:\\\\Program Files\\\\Git\\\\bin\\\\bash.exe',['-c','npm run test' + ' ' + process.argv.slice(1).join(' ')],{stdio:['ignore',1,2]});\""
39
39
  },
40
- "version": "2022.9.20"
40
+ "version": "2022.11.20"
41
41
  }
package/sqlmath.mjs CHANGED
@@ -87,6 +87,7 @@ let debugInline = (function () {
87
87
  let sqlMessageDict = {}; // dict of web-worker-callbacks
88
88
  let sqlMessageId = 0;
89
89
  let sqlWorker;
90
+ let version = "v2022.11.20";
90
91
 
91
92
  function assertJsonEqual(aa, bb, message) {
92
93
 
@@ -110,7 +111,7 @@ function assertJsonEqual(aa, bb, message) {
110
111
 
111
112
  function assertNumericalEqual(aa, bb, message) {
112
113
 
113
- // This function will assert aa - bb <= Number.EPSILON
114
+ // This function will assert aa - bb <= Number.EPSILON.
114
115
 
115
116
  assertOrThrow(aa, "value cannot be 0 or falsy");
116
117
  if (!(Math.abs((aa - bb) / Math.max(aa, bb)) <= 256 * Number.EPSILON)) {
@@ -138,8 +139,10 @@ function assertOrThrow(condition, message) {
138
139
  }
139
140
 
140
141
  async function cCallAsync(baton, cFuncName, ...argList) {
141
- // this function will serialize <argList> to a c <baton>,
142
- // suitable for passing into napi
142
+
143
+ // This function will serialize <argList> to a c <baton>,
144
+ // suitable for passing into napi.
145
+
143
146
  let argi = 0;
144
147
  let errStack;
145
148
  assertOrThrow(
@@ -227,7 +230,9 @@ async function cCallAsync(baton, cFuncName, ...argList) {
227
230
  }
228
231
 
229
232
  function dbCallAsync(baton, cFuncName, db, ...argList) {
230
- // this function will call <cFuncName> using db <argList>[0]
233
+
234
+ // This function will call <cFuncName> using db <argList>[0].
235
+
231
236
  let __db = dbDeref(db);
232
237
  // increment __db.busy
233
238
  __db.busy += 1;
@@ -246,7 +251,9 @@ function dbCallAsync(baton, cFuncName, db, ...argList) {
246
251
  async function dbCloseAsync({
247
252
  db
248
253
  }) {
249
- // this function will close sqlite-database-connection <db>
254
+
255
+ // This function will close sqlite-database-connection <db>.
256
+
250
257
  let __db = dbDeref(db);
251
258
  // prevent segfault - do not close db if actions are pending
252
259
  assertOrThrow(
@@ -268,7 +275,9 @@ async function dbCloseAsync({
268
275
  }
269
276
 
270
277
  function dbDeref(db) {
271
- // this function will get private-object mapped to <db>
278
+
279
+ // This function will get private-object mapped to <db>.
280
+
272
281
  let __db = dbDict.get(db);
273
282
  assertOrThrow(__db?.connPool[0] > 0, "invalid or closed db");
274
283
  assertOrThrow(__db.busy >= 0, "invalid db.busy " + __db.busy);
@@ -283,8 +292,10 @@ function dbExecAndReturnLastBlobAsync({
283
292
  db,
284
293
  sql
285
294
  }) {
286
- // this function will exec <sql> in <db> and return last value retrieved
287
- // from execution as raw blob/buffer
295
+
296
+ // This function will exec <sql> in <db> and return last value retrieved
297
+ // from execution as raw blob/buffer.
298
+
288
299
  return dbExecAsync({
289
300
  bindList,
290
301
  db,
@@ -300,7 +311,9 @@ async function dbExecAsync({
300
311
  responseType,
301
312
  sql
302
313
  }) {
303
- // this function will exec <sql> in <db> and return <result>
314
+
315
+ // This function will exec <sql> in <db> and return <result>.
316
+
304
317
  let baton;
305
318
  let bindByKey;
306
319
  let bindListLength;
@@ -394,9 +407,15 @@ async function dbFileExportAsync({
394
407
  db,
395
408
  dbData,
396
409
  filename,
397
- modeExport = 1
410
+ modeExport = 1,
411
+ modeNoop
398
412
  }) {
399
- // This function will export <db> to <filename>
413
+
414
+ // This function will export <db> to <filename>.
415
+
416
+ if (modeNoop) {
417
+ return;
418
+ }
400
419
  if (IS_BROWSER) {
401
420
  filename = FILENAME_DBTMP;
402
421
  }
@@ -420,7 +439,9 @@ async function dbFileImportAsync({
420
439
  dbData,
421
440
  filename
422
441
  }) {
423
- // This function will import <filename> to <db>
442
+
443
+ // This function will import <filename> to <db>.
444
+
424
445
  await dbFileExportAsync({
425
446
  db,
426
447
  dbData,
@@ -430,7 +451,9 @@ async function dbFileImportAsync({
430
451
  }
431
452
 
432
453
  async function dbNoopAsync(...argList) {
433
- // this function will do nothing except return argList
454
+
455
+ // This function will do nothing except return argList.
456
+
434
457
  return await cCallAsync(undefined, "_dbNoop", ...argList);
435
458
  }
436
459
 
@@ -439,10 +462,11 @@ async function dbOpenAsync({
439
462
  dbData,
440
463
  filename,
441
464
  flags,
442
- rawPtr,
443
465
  threadCount = 1
444
466
  }) {
445
- // this function will open and return sqlite-database-connection <db>
467
+
468
+ // This function will open and return sqlite-database-connection <db>.
469
+
446
470
  // int sqlite3_open_v2(
447
471
  // const char *filename, /* Database filename (UTF-8) */
448
472
  // sqlite3 **ppDb, /* OUT: SQLite db handle */
@@ -461,16 +485,10 @@ async function dbOpenAsync({
461
485
  !dbData || isExternalBuffer(dbData),
462
486
  "dbData must be ArrayBuffer"
463
487
  );
464
- if (rawPtr) {
465
- rawPtr = [
466
- BigInt(rawPtr)
467
- ];
468
- threadCount = 1;
469
- }
470
488
  connPool = await Promise.all(Array.from(new Array(
471
489
  threadCount
472
490
  ), async function () {
473
- let ptr = rawPtr || await cCallAsync(
491
+ let ptr = await cCallAsync(
474
492
  undefined,
475
493
  "_dbOpen",
476
494
  // 0. const char *filename, Database filename (UTF-8)
@@ -486,7 +504,7 @@ async function dbOpenAsync({
486
504
  // 4. wasm-only - arraybuffer of raw sqlite-database to open in wasm
487
505
  dbData
488
506
  );
489
- ptr = rawPtr || [
507
+ ptr = [
490
508
  ptr[0].getBigInt64(4 + 4, true)
491
509
  ];
492
510
  dbFinalizationRegistry.register(db, {
@@ -505,7 +523,9 @@ async function dbOpenAsync({
505
523
  }
506
524
 
507
525
  function isExternalBuffer(buf) {
508
- // this function will check if <buf> is ArrayBuffer or SharedArrayBuffer
526
+
527
+ // This function will check if <buf> is ArrayBuffer or SharedArrayBuffer.
528
+
509
529
  return buf && (
510
530
  buf.constructor === ArrayBuffer
511
531
  || (
@@ -516,7 +536,9 @@ function isExternalBuffer(buf) {
516
536
  }
517
537
 
518
538
  function jsbatonCreate() {
519
- // this function will create buffer <baton>
539
+
540
+ // This function will create buffer <baton>.
541
+
520
542
  let baton = new DataView(new ArrayBuffer(1024));
521
543
  // offset nalloc, nused
522
544
  baton.setInt32(4, SQLITE_DATATYPE_OFFSET, true);
@@ -529,7 +551,9 @@ function jsbatonValuePush({
529
551
  externalbufferList,
530
552
  value
531
553
  }) {
532
- // this function will push <value> to buffer <baton>
554
+
555
+ // This function will push <value> to buffer <baton>.
556
+
533
557
  let nn;
534
558
  let nused;
535
559
  let tmp;
@@ -744,7 +768,9 @@ function jsbatonValueString({
744
768
  argi,
745
769
  baton
746
770
  }) {
747
- // this function will return string-value from <baton> at given <offset>
771
+
772
+ // This function will return string-value from <baton> at given <offset>.
773
+
748
774
  let offset = baton.getInt32(4 + 4 + argi * 8, true);
749
775
  return new TextDecoder().decode(new Uint8Array(
750
776
  baton.buffer,
@@ -787,7 +813,7 @@ function objectDeepCopyWithKeysSorted(obj) {
787
813
 
788
814
  async function sqlMessagePost(baton, cFuncName, ...argList) {
789
815
 
790
- // This function will post msg to <sqlWorker> and return result
816
+ // This function will post msg to <sqlWorker> and return result.
791
817
 
792
818
  let errStack;
793
819
  let id;
@@ -824,7 +850,7 @@ async function sqlMessagePost(baton, cFuncName, ...argList) {
824
850
  delete sqlMessageDict[id];
825
851
  // debug slow postMessage
826
852
  timeElapsed = Date.now() - timeElapsed;
827
- if (timeElapsed > 500) {
853
+ if (timeElapsed > 500 || cFuncName === "testTimeElapsed") {
828
854
  consoleError(
829
855
  "sqlMessagePost - " + JSON.stringify({
830
856
  cFuncName,
@@ -839,12 +865,17 @@ async function sqlMessagePost(baton, cFuncName, ...argList) {
839
865
  }
840
866
 
841
867
  async function sqlmathInit() {
868
+
869
+ // This function will init sqlmath.
870
+
842
871
  dbFinalizationRegistry = new FinalizationRegistry(function ({
843
872
  afterFinalization,
844
873
  ptr
845
874
  }) {
875
+
846
876
  // This function will auto-close any open sqlite3-db-pointer,
847
- // after its js-wrapper has been garbage-collected
877
+ // after its js-wrapper has been garbage-collected.
878
+
848
879
  cCallAsync(undefined, "_dbClose", ptr[0]);
849
880
  if (afterFinalization) {
850
881
  afterFinalization();
@@ -874,19 +905,46 @@ async function sqlmathInit() {
874
905
  }
875
906
 
876
907
  function sqlmathWebworkerInit({
877
- Worker
908
+ db,
909
+ modeTest
878
910
  }) {
879
911
 
912
+ // This function will init sqlmath web-worker.
913
+
880
914
  // Feature-detect browser.
881
915
 
916
+ let Worker = globalThis.Worker;
882
917
  IS_BROWSER = true;
883
- Worker = Worker || globalThis.Worker;
918
+ if (modeTest) {
919
+ Worker = function () {
920
+ return;
921
+ };
922
+ }
884
923
  sqlWorker = new Worker("sqlmath_wasm.js");
885
924
  sqlWorker.onmessage = function ({
886
925
  data
887
926
  }) {
888
927
  sqlMessageDict[data.id](data);
889
928
  };
929
+ if (modeTest) {
930
+ sqlWorker.postMessage = function (data) {
931
+ setTimeout(function () {
932
+ sqlWorker.onmessage({
933
+ data
934
+ });
935
+ });
936
+ };
937
+ // test cCallAsync handling-behavior
938
+ cCallAsync(undefined, "testTimeElapsed", true);
939
+ // test dbFileExportAsync handling-behavior
940
+ dbFileExportAsync({
941
+ db,
942
+ filename: "aa",
943
+ modeTest
944
+ });
945
+ // revert IS_BROWSER
946
+ IS_BROWSER = undefined;
947
+ }
890
948
  }
891
949
 
892
950
  await sqlmathInit({});
@@ -929,5 +987,6 @@ export {
929
987
  noop,
930
988
  objectDeepCopyWithKeysSorted,
931
989
  sqlmathInit,
932
- sqlmathWebworkerInit
990
+ sqlmathWebworkerInit,
991
+ version
933
992
  };