alasql 4.1.3 → 4.1.4

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/README.md CHANGED
@@ -7,11 +7,11 @@
7
7
  [![OPEN open source software](https://img.shields.io/badge/Open--OSS-%E2%9C%94-brightgreen.svg)](http://open-oss.com)
8
8
  [![Release](https://img.shields.io/github/release/alasql/alasql.svg?label=npm&a)](https://www.npmjs.com/package/alasql)
9
9
  [![Stars](https://img.shields.io/github/stars/alasql/alasql.svg?label=Github%20%E2%98%85&a)](https://github.com/alasql/alasql)
10
- [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/alasql/alasql.svg)](http://isitmaintained.com/project/\n/alasql "Average time to resolve an issue")
10
+ [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/AlaSQL/alasql.svg)](http://isitmaintained.com/project/AlaSQL/alasql "Average time to resolve an issue")
11
11
  [![Coverage]( https://img.shields.io/codecov/c/github/alasql/alasql/develop.svg)](https://rawgit.com/alasql/alasql/develop/test/coverage/lcov-report/dist/alasql.fs.js.html)
12
- [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/328/badge)](https://bestpractices.coreinfrastructure.org/projects/328)
12
+ [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/AlaSQL/alasql/badge)](https://securityscorecards.dev/viewer/?uri=github.com/AlaSQL/alasql)
13
+ [![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/328/badge)](https://bestpractices.coreinfrastructure.org/projects/328)
13
14
  [![](https://data.jsdelivr.com/v1/package/npm/alasql/badge?style=rounded)](https://www.jsdelivr.com/package/npm/alasql)
14
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)
15
15
 
16
16
 
17
17
 
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.1.2 build: develop-c4d7c946 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.1.3 build: develop-04e3bf66 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.1.2
4
+ @version 4.1.3
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2023 Andrey Gershun & Mathias Wulff
@@ -1,2 +1,2 @@
1
- //! AlaSQL v4.1.2 build: develop-c4d7c946 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.1.3 build: develop-04e3bf66 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  !function(r,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():r.alasql=e()}(this,function(){function i(r,e,o){"function"==typeof(e=e||[])&&(scope=o,o=e,e=[]),"object"!=typeof e&&(e=[e]);var t=i.lastid++;i.buffer[t]=o,i.webworker.postMessage({id:t,sql:r,params:e})}var a;if(i.options={},i.options.progress=function(){},isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)},i.promise=function(){throw new Error("Please include a Promise/A+ library")},"undefined"!=typeof Promise&&(a=function(r,e,n,s){return new Promise(function(o,t){i(r,e,function(r,e){e?t(e):(n&&s&&!1!==i.options.progress&&i.options.progress(n,s),o(r))})})},i.promise=function(r,e){if("undefined"==typeof Promise)throw new Error("Please include a Promise/A+ library");if("string"==typeof r)return a(r,e);if(!isArray(r)||r.length<1||void 0!==e)throw new Error("Error in .promise parameters");var o=r;if(!(o.length<1)){for(var t,n,s=[],i=0;i<o.length;i++){if("string"==typeof(n=o[i])&&(n=[n]),!isArray(n)||n.length<1||2<n.length)throw new Error("Error in .promise parameter");t=n[0],n=n[1]||void 0,s.push(a(t,n,i,o.length))}return Promise.all(s)}}),i=i||!1)return i.worker=function(){throw new Error("Can find webworker in this enviroment")},"undefined"!=typeof Worker&&(i.worker=function(r,e,o){if(void 0===(r=!0===r?void 0:r))for(var t=document.getElementsByTagName("script"),n=0;n<t.length;n++){if("alasql-worker.js"===t[n].src.substr(-16).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-16)+"alasql.js";break}if("alasql-worker.min.js"===t[n].src.substr(-20).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-20)+"alasql.min.js";break}if("alasql.js"===t[n].src.substr(-9).toLowerCase()){r=t[n].src;break}if("alasql.min.js"===t[n].src.substr(-13).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-13)+"alasql.min.js";break}}if(void 0===r)throw new Error("Path to alasql.js is not specified");var s;!1!==r?(s=(s="importScripts('")+r+"');self.onmessage = function(event) {alasql(event.data.sql,event.data.params, function(data){postMessage({id:event.data.id, data:data});});}",s=new Blob([s],{type:"text/plain"}),i.webworker=new Worker(URL.createObjectURL(s)),i.webworker.onmessage=function(r){var e=r.data.id;i.buffer[e](r.data.data),delete i.buffer[e]},i.webworker.onerror=function(r){throw r},1<arguments.length&&i("REQUIRE "+e.map(function(r){return'"'+r+'"'}).join(","),[],o)):!1===r&&delete i.webworker}),i.lastid=0,i.buffer={},i.worker(),i;throw new Error("alasql was not found")});
package/dist/alasql.d.ts CHANGED
@@ -60,17 +60,28 @@ declare module 'alasql' {
60
60
  interface userDefinedFunction {
61
61
  (...x: any[]): any;
62
62
  }
63
+
63
64
  interface userDefinedFunctionLookUp {
64
65
  [x: string]: userDefinedFunction;
65
66
  }
67
+
66
68
  // see https://github.com/alasql/alasql/wiki/User%20Defined%20Functions
67
69
  interface userAggregator {
68
70
  (value: any, accumulator: any, stage: number): any;
69
71
  }
72
+
70
73
  interface userAggregatorLookUp {
71
74
  [x: string]: userAggregator;
72
75
  }
73
76
 
77
+ interface userFromFunction {
78
+ (dataReference: any, options: any, callback: any, index: any, query: any): any;
79
+ }
80
+
81
+ interface userFromFunctionLookUp {
82
+ [x: string]: userFromFunction;
83
+ }
84
+
74
85
  interface AlaSQL {
75
86
  options: AlaSQLOptions;
76
87
  error: Error;
@@ -78,11 +89,14 @@ declare module 'alasql' {
78
89
  parse(sql: any): AlaSQLAST;
79
90
  promise(sql: any, params?: any): Thenable<any>;
80
91
  fn: userDefinedFunctionLookUp;
92
+ from: userFromFunctionLookUp;
81
93
  aggr: userAggregatorLookUp;
82
94
  autoval(tablename: string, colname: string, getNext?: boolean): number;
83
95
  yy: {};
84
96
  setXLSX(xlsxlib: typeof xlsx): void;
85
97
  }
98
+
86
99
  const alasql: AlaSQL;
100
+
87
101
  export = alasql;
88
102
  }
package/dist/alasql.fs.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.1.2 build: develop-c4d7c946 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.1.3 build: develop-04e3bf66 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.1.2
4
+ @version 4.1.3
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2023 Andrey Gershun & Mathias Wulff
@@ -142,8 +142,8 @@ var alasql = function(sql, params, cb, scope) {
142
142
  Current version of alasql
143
143
  @constant {string}
144
144
  */
145
- alasql.version = '4.1.2';
146
- alasql.build = 'develop-c4d7c946';
145
+ alasql.version = '4.1.3';
146
+ alasql.build = 'develop-04e3bf66';
147
147
 
148
148
  /**
149
149
  Debug flag
@@ -3490,7 +3490,7 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
3490
3490
  });
3491
3491
  } else {
3492
3492
  if (/^[a-z]+:\/\//i.test(path)) {
3493
- fetchData(path, (x) => success(cutbom(x)), error, asy);
3493
+ fetchData(path, x => success(cutbom(x)), error, asy);
3494
3494
  } else {
3495
3495
  //If async callthen call async
3496
3496
  if (asy) {
@@ -3553,7 +3553,7 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
3553
3553
  Simply read file from HTTP request, like:
3554
3554
  SELECT * FROM TXT('http://alasql.org/README.md');
3555
3555
  */
3556
- fetchData(path, (x) => success(cutbom(x)), error, asy);
3556
+ fetchData(path, x => success(cutbom(x)), error, asy);
3557
3557
  }
3558
3558
  } else if (path instanceof Event) {
3559
3559
  /*
@@ -3594,13 +3594,13 @@ async function fetchData(path, success, error, async) {
3594
3594
 
3595
3595
  function getData(path, success, error) {
3596
3596
  return _fetch(path)
3597
- .then((response) => response.arrayBuffer())
3598
- .then((buf) => {
3597
+ .then(response => response.arrayBuffer())
3598
+ .then(buf => {
3599
3599
  var a = new Uint8Array(buf);
3600
- var b = [...a].map((e) => String.fromCharCode(e)).join('');
3600
+ var b = [...a].map(e => String.fromCharCode(e)).join('');
3601
3601
  success(b);
3602
3602
  })
3603
- .catch((e) => {
3603
+ .catch(e => {
3604
3604
  if (error) return error(e);
3605
3605
  console.error(e);
3606
3606
  throw e;
@@ -3622,7 +3622,7 @@ var loadBinaryFile = (utils.loadBinaryFile = function (
3622
3622
  path,
3623
3623
  runAsync,
3624
3624
  success,
3625
- error = (x) => {
3625
+ error = x => {
3626
3626
  throw x;
3627
3627
  }
3628
3628
  ) {
@@ -4866,9 +4866,9 @@ var promiseExec = function (sql, params, counterStep, counterTotal) {
4866
4866
 
4867
4867
  const sequentialPromiseResolver = (promiseData, Promise) => {
4868
4868
  var startingPoint = Promise.resolve([]);
4869
- promiseData.forEach((p) => {
4870
- startingPoint = startingPoint.then((previousResult) =>
4871
- promiseExec(p.sql, p.params, p.i, p.length).then((result) => [...previousResult, result])
4869
+ promiseData.forEach(p => {
4870
+ startingPoint = startingPoint.then(previousResult =>
4871
+ promiseExec(p.sql, p.params, p.i, p.length).then(result => [...previousResult, result])
4872
4872
  );
4873
4873
  });
4874
4874
 
@@ -5272,16 +5272,16 @@ yy.Statements = class Statements {
5272
5272
  }
5273
5273
 
5274
5274
  toString() {
5275
- return this.statements.map((st) => st.toString()).join('; ');
5275
+ return this.statements.map(st => st.toString()).join('; ');
5276
5276
  }
5277
5277
 
5278
5278
  // Compile array of statements into single statement
5279
5279
  compile(db) {
5280
- const statements = this.statements.map((st) => st.compile(db));
5280
+ const statements = this.statements.map(st => st.compile(db));
5281
5281
  return statements.length === 1
5282
5282
  ? statements[0]
5283
5283
  : (params, cb) => {
5284
- const res = statements.map((st) => st(params));
5284
+ const res = statements.map(st => st(params));
5285
5285
  if (cb) cb(res);
5286
5286
  return res;
5287
5287
  };
@@ -5973,7 +5973,7 @@ alasql.srch = {
5973
5973
  PROP(val, args, stope) {
5974
5974
 
5975
5975
  if (stope.mode === 'XML') {
5976
- const values = val.children.filter((v) => v.name.toUpperCase() === args[0].toUpperCase());
5976
+ const values = val.children.filter(v => v.name.toUpperCase() === args[0].toUpperCase());
5977
5977
 
5978
5978
  return {
5979
5979
  status: values.length ? 1 : -1,
@@ -6311,7 +6311,7 @@ alasql.srch = {
6311
6311
 
6312
6312
  ROW(val, args, stope, params) {
6313
6313
  var s = 'var y;return [';
6314
- s += args.map((arg) => arg.toJS('x', '')).join(',');
6314
+ s += args.map(arg => arg.toJS('x', '')).join(',');
6315
6315
  s += ']';
6316
6316
  var setfn = new Function('x,params,alasql', s);
6317
6317
  var rv = setfn(val, params, alasql);
@@ -8700,7 +8700,7 @@ yy.Select.prototype.compileGroup = function (query) {
8700
8700
  // if(col instanceof yy.Column) colas = col.columnid;
8701
8701
  // else colas = col.toString();
8702
8702
  // };
8703
- let colExpIfFunIdExists = (expression) => {
8703
+ let colExpIfFunIdExists = expression => {
8704
8704
  let colexpression = expression.args[0];
8705
8705
  return colexpression.toJS('p', tableid, defcols);
8706
8706
  };
@@ -8825,7 +8825,7 @@ yy.Select.prototype.compileGroup = function (query) {
8825
8825
  var colas = col.nick;
8826
8826
 
8827
8827
  var colexp = col.expression.toJS('p', tableid, defcols);
8828
- let colExpIfFunIdExists = (expression) => {
8828
+ let colExpIfFunIdExists = expression => {
8829
8829
  let colexpression = expression.args[0];
8830
8830
  return colexpression.toJS('p', tableid, defcols);
8831
8831
  };
@@ -11665,7 +11665,7 @@ stdlib.UPPER = stdlib.UCASE = function (s) {
11665
11665
  // Concatination of strings
11666
11666
  stdfn.CONCAT_WS = function () {
11667
11667
  var args = Array.prototype.slice.call(arguments);
11668
- args = args.filter((x) => !(x === null || typeof x === 'undefined'));
11668
+ args = args.filter(x => !(x === null || typeof x === 'undefined'));
11669
11669
  return args.slice(1, args.length).join(args[0] || '');
11670
11670
  };
11671
11671
 
@@ -12601,7 +12601,11 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12601
12601
  };
12602
12602
  }
12603
12603
  if (checkfn) {
12604
- table.checks.push({fn: checkfn, id: con.constraintid, fk: con.type === 'FOREIGN KEY'});
12604
+ table.checks.push({
12605
+ fn: checkfn,
12606
+ id: con.constraintid,
12607
+ fk: con.type === 'FOREIGN KEY',
12608
+ });
12605
12609
  }
12606
12610
  });
12607
12611
 
@@ -13991,7 +13995,9 @@ yy.WithSelect.prototype.execute = function (databaseid, params, cb) {
13991
13995
  var savedTables = [];
13992
13996
  self.withs.forEach(function (w) {
13993
13997
  savedTables.push(alasql.databases[databaseid].tables[w.name]);
13994
- var tb = (alasql.databases[databaseid].tables[w.name] = new Table({tableid: w.name}));
13998
+ var tb = (alasql.databases[databaseid].tables[w.name] = new Table({
13999
+ tableid: w.name,
14000
+ }));
13995
14001
  tb.data = w.select.execute(databaseid, params);
13996
14002
  });
13997
14003
 
@@ -15240,7 +15246,11 @@ yy.ShowColumns.prototype.execute = function (databaseid, params, cb) {
15240
15246
 
15241
15247
  if (table && table.columns) {
15242
15248
  var res = table.columns.map(function (col) {
15243
- return {columnid: col.columnid, dbtypeid: col.dbtypeid, dbsize: col.dbsize};
15249
+ return {
15250
+ columnid: col.columnid,
15251
+ dbtypeid: col.dbtypeid,
15252
+ dbsize: col.dbsize,
15253
+ };
15244
15254
  });
15245
15255
  if (cb) cb(res);
15246
15256
  return res;
@@ -16898,7 +16908,9 @@ alasql.into.XLSX = function (filename, opts, data, columns, cb) {
16898
16908
 
16899
16909
  if (opt.headers) {
16900
16910
  columns.forEach(function (col, idx) {
16901
- cells[alasql.utils.xlsnc(col0 + idx) + '' + i] = {v: col.columnid.trim()};
16911
+ cells[alasql.utils.xlsnc(col0 + idx) + '' + i] = {
16912
+ v: col.columnid.trim(),
16913
+ };
16902
16914
  });
16903
16915
  i++;
16904
16916
  }
@@ -17331,9 +17343,17 @@ function XLSXLSX(X, filename, opts, cb, idx, query) {
17331
17343
  // function processData(data) {
17332
17344
  if (data instanceof ArrayBuffer) {
17333
17345
  var arr = fixdata(data);
17334
- var workbook = X.read(btoa(arr), {type: 'base64', ...alasql.options.excel, ...opts});
17346
+ var workbook = X.read(btoa(arr), {
17347
+ type: 'base64',
17348
+ ...alasql.options.excel,
17349
+ ...opts,
17350
+ });
17335
17351
  } else {
17336
- var workbook = X.read(data, {type: 'binary', ...alasql.options.excel, ...opts});
17352
+ var workbook = X.read(data, {
17353
+ type: 'binary',
17354
+ ...alasql.options.excel,
17355
+ ...opts,
17356
+ });
17337
17357
  }
17338
17358
 
17339
17359
  var sheetid;
@@ -17851,7 +17871,7 @@ async function _databaseExists(name) {
17851
17871
 
17852
17872
  if (indexedDB.databases) {
17853
17873
  const dbs = await indexedDB.databases();
17854
- const db = dbs.find((db) => db.name === name);
17874
+ const db = dbs.find(db => db.name === name);
17855
17875
  // @ts-ignore
17856
17876
  return db || 0;
17857
17877
  }
@@ -17865,7 +17885,7 @@ async function _databaseExists(name) {
17865
17885
  resolve({name, version: req.result.version});
17866
17886
  };
17867
17887
 
17868
- req.onupgradeneeded = (evt) => {
17888
+ req.onupgradeneeded = evt => {
17869
17889
  evt.target.transaction.abort();
17870
17890
  resolve(0);
17871
17891
  };
@@ -17890,7 +17910,7 @@ IDB.showDatabases = function (like, cb) {
17890
17910
  return;
17891
17911
  }
17892
17912
 
17893
- indexedDB.databases().then((dblist) => {
17913
+ indexedDB.databases().then(dblist => {
17894
17914
  const res = [];
17895
17915
  const relike = like && new RegExp(like.value.replace(/\%/g, '.*'), 'g');
17896
17916
 
@@ -17905,7 +17925,7 @@ IDB.showDatabases = function (like, cb) {
17905
17925
  };
17906
17926
 
17907
17927
  IDB.createDatabase = async function (ixdbid, args, ifnotexists, dbid, cb) {
17908
- const found = await _databaseExists(ixdbid).catch((err) => {
17928
+ const found = await _databaseExists(ixdbid).catch(err => {
17909
17929
  if (cb) cb(null, err);
17910
17930
  throw err;
17911
17931
  });
@@ -17929,7 +17949,7 @@ IDB.createDatabase = async function (ixdbid, args, ifnotexists, dbid, cb) {
17929
17949
  };
17930
17950
 
17931
17951
  IDB.dropDatabase = async function (ixdbid, ifexists, cb) {
17932
- const found = await _databaseExists(ixdbid).catch((err) => {
17952
+ const found = await _databaseExists(ixdbid).catch(err => {
17933
17953
  if (cb) cb(null, err);
17934
17954
  throw err;
17935
17955
  });
@@ -17953,7 +17973,7 @@ IDB.dropDatabase = async function (ixdbid, ifexists, cb) {
17953
17973
  };
17954
17974
 
17955
17975
  IDB.attachDatabase = async function (ixdbid, dbid, args, params, cb) {
17956
- const found = await _databaseExists(ixdbid).catch((err) => {
17976
+ const found = await _databaseExists(ixdbid).catch(err => {
17957
17977
  if (cb) cb(null, err);
17958
17978
  throw err;
17959
17979
  });
@@ -17988,7 +18008,7 @@ IDB.attachDatabase = async function (ixdbid, dbid, args, params, cb) {
17988
18008
 
17989
18009
  IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
17990
18010
  const ixdbid = alasql.databases[databaseid].ixdbid;
17991
- const found = await _databaseExists(ixdbid).catch((err) => {
18011
+ const found = await _databaseExists(ixdbid).catch(err => {
17992
18012
  if (cb) cb(null, err);
17993
18013
  throw err;
17994
18014
  });
@@ -18009,7 +18029,7 @@ IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
18009
18029
  request.result.close();
18010
18030
  if (cb) cb(1);
18011
18031
  };
18012
- request.onerror = (evt) => {
18032
+ request.onerror = evt => {
18013
18033
  cb(null, evt);
18014
18034
  };
18015
18035
  request.onblocked = function (event) {
@@ -18022,7 +18042,7 @@ IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
18022
18042
 
18023
18043
  IDB.dropTable = async function (databaseid, tableid, ifexists, cb) {
18024
18044
  const ixdbid = alasql.databases[databaseid].ixdbid;
18025
- const found = await _databaseExists(ixdbid).catch((err) => {
18045
+ const found = await _databaseExists(ixdbid).catch(err => {
18026
18046
  if (cb) cb(null, err);
18027
18047
  throw err;
18028
18048
  });
@@ -18071,7 +18091,7 @@ IDB.intoTable = function (databaseid, tableid, value, columns, cb) {
18071
18091
  var db = alasql.databases[databaseid];
18072
18092
  var table = db.tables[tableid];
18073
18093
 
18074
- request.onupgradeneeded = (evt) => {
18094
+ request.onupgradeneeded = evt => {
18075
18095
  evt.target.transaction.abort();
18076
18096
  const err = new Error(
18077
18097
  `Cannot insert into table "${tableid}" because database "${databaseid}" does not exist`
@@ -18107,7 +18127,7 @@ IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
18107
18127
  const ixdbid = alasql.databases[databaseid].ixdbid;
18108
18128
  const request = indexedDB.open(ixdbid);
18109
18129
 
18110
- request.onupgradeneeded = (evt) => {
18130
+ request.onupgradeneeded = evt => {
18111
18131
  evt.target.transaction.abort();
18112
18132
  const err = new Error(
18113
18133
  `Cannot select from table "${tableid}" because database "${databaseid}" does not exist`
@@ -18124,7 +18144,7 @@ IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
18124
18144
  const cursor = cur.result;
18125
18145
  if (cursor) {
18126
18146
  // if keyPath(columns) is not present then we take the key and value as object.
18127
- const cursorValue = typeof cursor === Object ? cursor.value : { [cursor.key]: cursor.value };
18147
+ const cursorValue = typeof cursor === Object ? cursor.value : {[cursor.key]: cursor.value};
18128
18148
  res.push(cursorValue);
18129
18149
  cursor.continue();
18130
18150
  } else {
@@ -19163,7 +19183,9 @@ var saveAs =
19163
19183
  blob.type
19164
19184
  )
19165
19185
  ) {
19166
- return new Blob([String.fromCharCode(0xfeff), blob], {type: blob.type});
19186
+ return new Blob([String.fromCharCode(0xfeff), blob], {
19187
+ type: blob.type,
19188
+ });
19167
19189
  }
19168
19190
  return blob;
19169
19191
  },