@duckdb/duckdb-wasm-shell 1.13.1-dev20.0 → 1.13.1-dev230.0

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/dist/shell.mjs CHANGED
@@ -1,5 +1,110 @@
1
+ // package.json
2
+ var name = "@duckdb/duckdb-wasm-shell";
3
+ var version = "1.13.1-dev230.0";
4
+ var description = "";
5
+ var author = "Andre Kohn <kohn.a@outlook.com>";
6
+ var license = "MPL-2.0";
7
+ var repository = {
8
+ type: "git",
9
+ url: "https://github.com/duckdb/duckdb-wasm.git"
10
+ };
11
+ var keywords = [
12
+ "sql",
13
+ "duckdb",
14
+ "relational",
15
+ "database",
16
+ "data",
17
+ "query",
18
+ "wasm",
19
+ "analytics",
20
+ "olap",
21
+ "arrow",
22
+ "parquet",
23
+ "json",
24
+ "csv"
25
+ ];
26
+ var dependencies = {
27
+ "@duckdb/duckdb-wasm": "^1.13.1-dev230.0",
28
+ xterm: "^4.17.0",
29
+ "xterm-addon-fit": "^0.5.0",
30
+ "xterm-addon-web-links": "^0.5.1",
31
+ "xterm-addon-webgl": "^0.11.4"
32
+ };
33
+ var devDependencies = {
34
+ esbuild: "^0.14.23",
35
+ eslint: "^8.9.0",
36
+ "eslint-plugin-jasmine": "^4.1.3",
37
+ "eslint-plugin-react": "^7.28.0",
38
+ jasmine: "^4.0.2",
39
+ "jasmine-core": "^4.0.1",
40
+ "jasmine-spec-reporter": "^7.0.0",
41
+ "make-dir": "^3.1.0",
42
+ prettier: "^2.5.1",
43
+ rimraf: "^3.0.2",
44
+ "wasm-pack": "^0.10.2"
45
+ };
46
+ var scripts = {
47
+ "install:wasmpack": "node ../../node_modules/wasm-pack/install.js",
48
+ "build:debug": "node bundle.mjs debug && tsc --emitDeclarationOnly",
49
+ "build:release": "node bundle.mjs release && tsc --emitDeclarationOnly",
50
+ lint: "eslint src"
51
+ };
52
+ var files = [
53
+ "dist",
54
+ "!dist/types/test"
55
+ ];
56
+ var main = "dist/shell.cjs";
57
+ var module = "dist/shell.mjs";
58
+ var types = "dist/shell.d.ts";
59
+ var jsdelivr = "dist/shell.cjs";
60
+ var unpkg = "dist/shell.mjs";
61
+ var sideEffects = false;
62
+ var exports = {
63
+ "./dist/shell_bg.wasm": "./dist/shell_bg.wasm",
64
+ "./dist/shell.js": "./dist/shell.js",
65
+ "./dist/shell.cjs": "./dist/shell.cjs",
66
+ "./dist/shell.mjs": "./dist/shell.mjs",
67
+ "./dist/shell": "./dist/shell.mjs",
68
+ ".": {
69
+ types: "./dist/shell.d.ts",
70
+ import: "./dist/shell.mjs",
71
+ require: "./dist/shell.cjs"
72
+ }
73
+ };
74
+ var package_default = {
75
+ name,
76
+ version,
77
+ description,
78
+ author,
79
+ license,
80
+ repository,
81
+ keywords,
82
+ dependencies,
83
+ devDependencies,
84
+ scripts,
85
+ files,
86
+ main,
87
+ module,
88
+ types,
89
+ jsdelivr,
90
+ unpkg,
91
+ sideEffects,
92
+ exports
93
+ };
94
+
95
+ // src/version.ts
96
+ var PACKAGE_NAME = package_default.name;
97
+ var PACKAGE_VERSION = package_default.version;
98
+ var VERSION_PARTS = package_default.version.split(".");
99
+ var PACKAGE_VERSION_MAJOR = VERSION_PARTS[0];
100
+ var PACKAGE_VERSION_MINOR = VERSION_PARTS[1];
101
+ var PACKAGE_VERSION_PATCH = VERSION_PARTS[2];
102
+
103
+ // src/shell.ts
104
+ import * as duckdb from "@duckdb/duckdb-wasm";
105
+
1
106
  // crate/pkg/shell.js
2
- import { getPlatformFeatures, PACKAGE_NAME, PACKAGE_VERSION } from "@duckdb/duckdb-wasm";
107
+ import { getPlatformFeatures, PACKAGE_NAME as PACKAGE_NAME2, PACKAGE_VERSION as PACKAGE_VERSION2 } from "@duckdb/duckdb-wasm";
3
108
  import { Terminal } from "xterm";
4
109
  import { FitAddon } from "xterm-addon-fit";
5
110
  import { WebLinksAddon } from "xterm-addon-web-links";
@@ -105,17 +210,17 @@ function debugString(val) {
105
210
  return `"${val}"`;
106
211
  }
107
212
  if (type == "symbol") {
108
- const description = val.description;
109
- if (description == null) {
213
+ const description2 = val.description;
214
+ if (description2 == null) {
110
215
  return "Symbol";
111
216
  } else {
112
- return `Symbol(${description})`;
217
+ return `Symbol(${description2})`;
113
218
  }
114
219
  }
115
220
  if (type == "function") {
116
- const name = val.name;
117
- if (typeof name == "string" && name.length > 0) {
118
- return `Function(${name})`;
221
+ const name2 = val.name;
222
+ if (typeof name2 == "string" && name2.length > 0) {
223
+ return `Function(${name2})`;
119
224
  } else {
120
225
  return "Function";
121
226
  }
@@ -193,6 +298,11 @@ function handleError(f, args) {
193
298
  function embed(elem, runtime, options) {
194
299
  wasm.embed(addHeapObject(elem), addHeapObject(runtime), addHeapObject(options));
195
300
  }
301
+ function write(text) {
302
+ var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
303
+ var len0 = WASM_VECTOR_LEN;
304
+ wasm.write(ptr0, len0);
305
+ }
196
306
  function writeln(text) {
197
307
  var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
198
308
  var len0 = WASM_VECTOR_LEN;
@@ -238,30 +348,30 @@ function passArray8ToWasm0(arg, malloc) {
238
348
  WASM_VECTOR_LEN = arg.length;
239
349
  return ptr;
240
350
  }
241
- function __wbg_adapter_195(arg0, arg1, arg2, arg3) {
351
+ function __wbg_adapter_199(arg0, arg1, arg2, arg3) {
242
352
  wasm.wasm_bindgen__convert__closures__invoke2_mut__h445be38df5ff7a40(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
243
353
  }
244
354
  var ShellInputContext = Object.freeze({ FileInput: 0, "0": "FileInput" });
245
355
  var WcWidth = Object.freeze({ Width0: 0, "0": "Width0", Width1: 1, "1": "Width1", Width2: 2, "2": "Width2" });
246
- async function load(module, imports) {
247
- if (typeof Response === "function" && module instanceof Response) {
356
+ async function load(module2, imports) {
357
+ if (typeof Response === "function" && module2 instanceof Response) {
248
358
  if (typeof WebAssembly.instantiateStreaming === "function") {
249
359
  try {
250
- return await WebAssembly.instantiateStreaming(module, imports);
360
+ return await WebAssembly.instantiateStreaming(module2, imports);
251
361
  } catch (e) {
252
- if (module.headers.get("Content-Type") != "application/wasm") {
362
+ if (module2.headers.get("Content-Type") != "application/wasm") {
253
363
  console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
254
364
  } else {
255
365
  throw e;
256
366
  }
257
367
  }
258
368
  }
259
- const bytes = await module.arrayBuffer();
369
+ const bytes = await module2.arrayBuffer();
260
370
  return await WebAssembly.instantiate(bytes, imports);
261
371
  } else {
262
- const instance = await WebAssembly.instantiate(module, imports);
372
+ const instance = await WebAssembly.instantiate(module2, imports);
263
373
  if (instance instanceof WebAssembly.Instance) {
264
- return { instance, module };
374
+ return { instance, module: module2 };
265
375
  } else {
266
376
  return instance;
267
377
  }
@@ -445,6 +555,12 @@ async function init(input) {
445
555
  return addHeapObject(ret);
446
556
  }, arguments);
447
557
  };
558
+ imports.wbg.__wbg_copyFileToBuffer_e4a7050307f57c30 = function() {
559
+ return handleError(function(arg0, arg1, arg2) {
560
+ var ret = getObject(arg0).copyFileToBuffer(getStringFromWasm0(arg1, arg2));
561
+ return addHeapObject(ret);
562
+ }, arguments);
563
+ };
448
564
  imports.wbg.__wbg_dropFiles_4d857401e3dd75ab = function() {
449
565
  return handleError(function(arg0) {
450
566
  var ret = getObject(arg0).dropFiles();
@@ -469,6 +585,12 @@ async function init(input) {
469
585
  return addHeapObject(ret);
470
586
  }, arguments);
471
587
  };
588
+ imports.wbg.__wbg_downloadFile_223fed31724de5a9 = function() {
589
+ return handleError(function(arg0, arg1, arg2, arg3) {
590
+ var ret = getObject(arg0).downloadFile(getStringFromWasm0(arg1, arg2), takeObject(arg3));
591
+ return addHeapObject(ret);
592
+ }, arguments);
593
+ };
472
594
  imports.wbg.__wbindgen_json_serialize = function(arg0, arg1) {
473
595
  const obj = getObject(arg1);
474
596
  var ret = JSON.stringify(obj === void 0 ? null : obj);
@@ -563,14 +685,14 @@ async function init(input) {
563
685
  getInt32Memory0()[arg0 / 4 + 0] = ptr0;
564
686
  };
565
687
  imports.wbg.__wbg_static_accessor_PACKAGE_NAME_da91149963a32187 = function(arg0) {
566
- var ret = PACKAGE_NAME;
688
+ var ret = PACKAGE_NAME2;
567
689
  var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
568
690
  var len0 = WASM_VECTOR_LEN;
569
691
  getInt32Memory0()[arg0 / 4 + 1] = len0;
570
692
  getInt32Memory0()[arg0 / 4 + 0] = ptr0;
571
693
  };
572
694
  imports.wbg.__wbg_static_accessor_PACKAGE_VERSION_8aa2f518d9081bf5 = function(arg0) {
573
- var ret = PACKAGE_VERSION;
695
+ var ret = PACKAGE_VERSION2;
574
696
  var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
575
697
  var len0 = WASM_VECTOR_LEN;
576
698
  getInt32Memory0()[arg0 / 4 + 1] = len0;
@@ -657,7 +779,7 @@ async function init(input) {
657
779
  const a = state0.a;
658
780
  state0.a = 0;
659
781
  try {
660
- return __wbg_adapter_195(a, state0.b, arg02, arg12);
782
+ return __wbg_adapter_199(a, state0.b, arg02, arg12);
661
783
  } finally {
662
784
  state0.a = a;
663
785
  }
@@ -754,20 +876,20 @@ async function init(input) {
754
876
  var ret = wasm.memory;
755
877
  return addHeapObject(ret);
756
878
  };
757
- imports.wbg.__wbindgen_closure_wrapper220 = function(arg0, arg1, arg2) {
879
+ imports.wbg.__wbindgen_closure_wrapper222 = function(arg0, arg1, arg2) {
758
880
  var ret = makeMutClosure(arg0, arg1, 4, __wbg_adapter_24);
759
881
  return addHeapObject(ret);
760
882
  };
761
- imports.wbg.__wbindgen_closure_wrapper905 = function(arg0, arg1, arg2) {
762
- var ret = makeMutClosure(arg0, arg1, 148, __wbg_adapter_27);
883
+ imports.wbg.__wbindgen_closure_wrapper918 = function(arg0, arg1, arg2) {
884
+ var ret = makeMutClosure(arg0, arg1, 150, __wbg_adapter_27);
763
885
  return addHeapObject(ret);
764
886
  };
765
887
  if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
766
888
  input = fetch(input);
767
889
  }
768
- const { instance, module } = await load(await input, imports);
890
+ const { instance, module: module2 } = await load(await input, imports);
769
891
  wasm = instance.exports;
770
- init.__wbindgen_wasm_module = module;
892
+ init.__wbindgen_wasm_module = module2;
771
893
  wasm.__wbindgen_start();
772
894
  return wasm;
773
895
  }
@@ -889,12 +1011,6 @@ var HistoryStore = class {
889
1011
  }
890
1012
  };
891
1013
 
892
- // src/utils/platform.ts
893
- var isNode = typeof navigator === "undefined" ? true : false;
894
- var userAgent = isNode ? "node" : navigator.userAgent;
895
- var isFirefox = userAgent.includes("Firefox");
896
- var isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
897
-
898
1014
  // src/utils/files.ts
899
1015
  function pickFiles(db) {
900
1016
  return new Promise((resolve, _reject) => {
@@ -904,13 +1020,13 @@ function pickFiles(db) {
904
1020
  const finish = async () => {
905
1021
  console.log(input.files);
906
1022
  closed = true;
907
- const files = input.files;
908
- for (let i = 0; i < files.length; ++i) {
909
- const file = files.item(i);
1023
+ const files2 = input.files;
1024
+ for (let i = 0; i < files2.length; ++i) {
1025
+ const file = files2.item(i);
910
1026
  await db.dropFile(file.name);
911
1027
  await db.registerFileHandle(file.name, file);
912
1028
  }
913
- resolve(files.length);
1029
+ resolve(files2.length);
914
1030
  };
915
1031
  const deferredFinish = async () => {
916
1032
  window.removeEventListener("focus", deferredFinish);
@@ -935,7 +1051,7 @@ function pickFiles(db) {
935
1051
 
936
1052
  // src/shell.ts
937
1053
  var hasWebGL = () => {
938
- if (isSafari) {
1054
+ if (duckdb.isSafari()) {
939
1055
  return false;
940
1056
  }
941
1057
  const canvas = document.createElement("canvas");
@@ -962,6 +1078,13 @@ var ShellRuntime = class {
962
1078
  }
963
1079
  return await pickFiles(this.database);
964
1080
  }
1081
+ async downloadFile(name2, buffer) {
1082
+ const blob = new Blob([buffer]);
1083
+ const link = document.createElement("a");
1084
+ link.href = URL.createObjectURL(blob);
1085
+ link.download = name2;
1086
+ link.click();
1087
+ }
965
1088
  async readClipboardText() {
966
1089
  return await navigator.clipboard.readText();
967
1090
  }
@@ -972,24 +1095,40 @@ var ShellRuntime = class {
972
1095
  this.history.push(value);
973
1096
  }
974
1097
  };
1098
+ function formatBytes(value) {
1099
+ const [multiple, k, suffix] = [1e3, "k", "B"];
1100
+ const exp = Math.log(value) / Math.log(multiple) | 0;
1101
+ const size = Number((value / Math.pow(multiple, exp)).toFixed(2));
1102
+ return `${size} ${exp ? `${k}MGTPEZY`[exp - 1] + suffix : `byte${size !== 1 ? "s" : ""}`}`;
1103
+ }
975
1104
  async function embed2(props) {
976
- await shell_default(props.wasmSource);
1105
+ await shell_default(props.shellModule);
977
1106
  const runtime = new ShellRuntime(props.container);
978
1107
  embed(props.container, runtime, {
979
1108
  backgroundColor: "#333",
980
1109
  withWebGL: hasWebGL()
981
1110
  });
982
1111
  props.container.onresize = runtime.resizeHandler;
1112
+ const TERM_BOLD = "\x1B[1m";
1113
+ const TERM_NORMAL = "\x1B[m";
1114
+ const TERM_CLEAR = "\x1B[2K\r";
1115
+ const progressHandler = (progress) => {
1116
+ if (progress.bytesTotal > 0) {
1117
+ const blocks = Math.floor(progress.bytesLoaded / progress.bytesTotal * 10);
1118
+ const bar = `${"#".repeat(blocks)}${"-".repeat(10 - blocks)}`;
1119
+ write(`${TERM_CLEAR}${TERM_BOLD}[ RUN ]${TERM_NORMAL} Loading ${bar}`);
1120
+ } else {
1121
+ write(`${TERM_CLEAR}${TERM_BOLD}[ RUN ]${TERM_NORMAL} Loading ${formatBytes(progress.bytesLoaded)}`);
1122
+ }
1123
+ };
1124
+ writeln(`${TERM_BOLD}[ RUN ]${TERM_NORMAL} Instantiating DuckDB`);
1125
+ runtime.database = await props.resolveDatabase(progressHandler);
1126
+ writeln(`${TERM_CLEAR}${TERM_BOLD}[ OK ]${TERM_NORMAL} Instantiating DuckDB`);
983
1127
  const step = async (label, work) => {
984
- const TERM_BOLD = "\x1B[1m";
985
- const TERM_NORMAL = "\x1B[m";
986
- writeln(`${TERM_BOLD}[ RUN ]${TERM_NORMAL} ${label}`);
1128
+ writeln(`${TERM_BOLD}[ RUN ]${TERM_NORMAL} ${label}`);
987
1129
  await work();
988
- writeln(`${TERM_BOLD}[ OK ]${TERM_NORMAL} ${label}`);
1130
+ writeln(`${TERM_BOLD}[ OK ]${TERM_NORMAL} ${label}`);
989
1131
  };
990
- await step("Resolving DuckDB", async () => {
991
- runtime.database = await props.resolveDatabase();
992
- });
993
1132
  await step("Loading Shell History", async () => {
994
1133
  await runtime.history.open();
995
1134
  const [hist, histCursor] = await runtime.history.load();
@@ -999,7 +1138,19 @@ async function embed2(props) {
999
1138
  configureDatabase(runtime.database);
1000
1139
  });
1001
1140
  }
1141
+
1142
+ // src/platform.ts
1143
+ function getJsDelivrModule() {
1144
+ const jsdelivr_dist_url = `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${PACKAGE_VERSION}/dist/`;
1145
+ return new URL(`${jsdelivr_dist_url}dist/shell_bg.wasm`);
1146
+ }
1002
1147
  export {
1003
- embed2 as embed
1148
+ PACKAGE_NAME,
1149
+ PACKAGE_VERSION,
1150
+ PACKAGE_VERSION_MAJOR,
1151
+ PACKAGE_VERSION_MINOR,
1152
+ PACKAGE_VERSION_PATCH,
1153
+ embed2 as embed,
1154
+ getJsDelivrModule
1004
1155
  };
1005
1156
  //# sourceMappingURL=shell.mjs.map