juxscript 1.1.240 → 1.1.243
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/index.js +7 -137
- package/lib/components/dataframe.ts +0 -569
- package/lib/components/tag.ts +68 -0
- package/lib/styles/shadcn.css +17 -5
- package/lib/utils/idgen.ts +6 -0
- package/package.json +5 -6
- package/index.d.ts +0 -239
- package/index.d.ts.map +0 -1
- package/lib/components/alert.d.ts +0 -36
- package/lib/components/alert.d.ts.map +0 -1
- package/lib/components/alert.js +0 -172
- package/lib/components/alert.ts +0 -219
- package/lib/components/app.d.ts +0 -89
- package/lib/components/app.d.ts.map +0 -1
- package/lib/components/app.js +0 -175
- package/lib/components/app.ts +0 -247
- package/lib/components/badge.d.ts +0 -26
- package/lib/components/badge.d.ts.map +0 -1
- package/lib/components/badge.js +0 -91
- package/lib/components/badge.ts +0 -118
- package/lib/components/base/Animations.d.ts +0 -36
- package/lib/components/base/Animations.d.ts.map +0 -1
- package/lib/components/base/Animations.js +0 -70
- package/lib/components/base/Animations.ts +0 -112
- package/lib/components/base/BaseComponent.d.ts +0 -294
- package/lib/components/base/BaseComponent.d.ts.map +0 -1
- package/lib/components/base/BaseComponent.js +0 -735
- package/lib/components/base/BaseComponent.ts +0 -884
- package/lib/components/base/FormInput.d.ts +0 -77
- package/lib/components/base/FormInput.d.ts.map +0 -1
- package/lib/components/base/FormInput.js +0 -171
- package/lib/components/base/FormInput.ts +0 -237
- package/lib/components/blueprint.d.ts +0 -40
- package/lib/components/blueprint.d.ts.map +0 -1
- package/lib/components/blueprint.js +0 -327
- package/lib/components/button.d.ts +0 -70
- package/lib/components/button.d.ts.map +0 -1
- package/lib/components/button.js +0 -177
- package/lib/components/button.ts +0 -237
- package/lib/components/card.d.ts +0 -35
- package/lib/components/card.d.ts.map +0 -1
- package/lib/components/card.js +0 -130
- package/lib/components/card.ts +0 -177
- package/lib/components/chart.d.ts +0 -49
- package/lib/components/chart.d.ts.map +0 -1
- package/lib/components/chart.js +0 -205
- package/lib/components/chart.ts +0 -254
- package/lib/components/checkbox.d.ts +0 -33
- package/lib/components/checkbox.d.ts.map +0 -1
- package/lib/components/checkbox.js +0 -202
- package/lib/components/checkbox.ts +0 -260
- package/lib/components/code.d.ts +0 -52
- package/lib/components/code.d.ts.map +0 -1
- package/lib/components/code.js +0 -201
- package/lib/components/code.ts +0 -260
- package/lib/components/container.d.ts +0 -60
- package/lib/components/container.d.ts.map +0 -1
- package/lib/components/container.js +0 -195
- package/lib/components/container.ts +0 -259
- package/lib/components/data.d.ts +0 -36
- package/lib/components/data.d.ts.map +0 -1
- package/lib/components/data.js +0 -110
- package/lib/components/data.ts +0 -135
- package/lib/components/dataframe/DataFrameSource.d.ts +0 -118
- package/lib/components/dataframe/DataFrameSource.d.ts.map +0 -1
- package/lib/components/dataframe/DataFrameSource.js +0 -421
- package/lib/components/dataframe/DataFrameSource.ts +0 -532
- package/lib/components/dataframe/ImportSettingsModal.d.ts +0 -60
- package/lib/components/dataframe/ImportSettingsModal.d.ts.map +0 -1
- package/lib/components/dataframe/ImportSettingsModal.js +0 -442
- package/lib/components/dataframe/ImportSettingsModal.ts +0 -531
- package/lib/components/dataframe.d.ts +0 -110
- package/lib/components/dataframe.d.ts.map +0 -1
- package/lib/components/dataframe.js +0 -470
- package/lib/components/datepicker.d.ts +0 -40
- package/lib/components/datepicker.d.ts.map +0 -1
- package/lib/components/datepicker.js +0 -193
- package/lib/components/datepicker.ts +0 -251
- package/lib/components/dialog.d.ts +0 -39
- package/lib/components/dialog.d.ts.map +0 -1
- package/lib/components/dialog.js +0 -131
- package/lib/components/dialog.ts +0 -178
- package/lib/components/divider.d.ts +0 -31
- package/lib/components/divider.d.ts.map +0 -1
- package/lib/components/divider.js +0 -72
- package/lib/components/divider.ts +0 -104
- package/lib/components/dropdown-menu.d.ts +0 -42
- package/lib/components/dropdown-menu.d.ts.map +0 -1
- package/lib/components/dropdown-menu.js +0 -177
- package/lib/components/dropdown-menu.ts +0 -214
- package/lib/components/dropdown.d.ts +0 -41
- package/lib/components/dropdown.d.ts.map +0 -1
- package/lib/components/dropdown.js +0 -136
- package/lib/components/dropdown.ts +0 -188
- package/lib/components/element.d.ts +0 -51
- package/lib/components/element.d.ts.map +0 -1
- package/lib/components/element.js +0 -209
- package/lib/components/element.ts +0 -271
- package/lib/components/event-chain.d.ts +0 -9
- package/lib/components/event-chain.d.ts.map +0 -1
- package/lib/components/event-chain.js +0 -33
- package/lib/components/fileupload.d.ts +0 -98
- package/lib/components/fileupload.d.ts.map +0 -1
- package/lib/components/fileupload.js +0 -351
- package/lib/components/fileupload.ts +0 -449
- package/lib/components/grid.d.ts +0 -88
- package/lib/components/grid.d.ts.map +0 -1
- package/lib/components/grid.js +0 -208
- package/lib/components/grid.ts +0 -295
- package/lib/components/heading.d.ts +0 -25
- package/lib/components/heading.d.ts.map +0 -1
- package/lib/components/heading.js +0 -83
- package/lib/components/heading.ts +0 -113
- package/lib/components/helpers.d.ts +0 -9
- package/lib/components/helpers.d.ts.map +0 -1
- package/lib/components/helpers.js +0 -30
- package/lib/components/helpers.ts +0 -41
- package/lib/components/hero.d.ts +0 -60
- package/lib/components/hero.d.ts.map +0 -1
- package/lib/components/hero.js +0 -239
- package/lib/components/hero.ts +0 -302
- package/lib/components/history/StateHistory.d.ts +0 -91
- package/lib/components/history/StateHistory.d.ts.map +0 -1
- package/lib/components/history/StateHistory.js +0 -154
- package/lib/components/history/StateHistory.ts +0 -200
- package/lib/components/icon.d.ts +0 -36
- package/lib/components/icon.d.ts.map +0 -1
- package/lib/components/icon.js +0 -135
- package/lib/components/icon.ts +0 -182
- package/lib/components/icons.d.ts +0 -25
- package/lib/components/icons.d.ts.map +0 -1
- package/lib/components/icons.js +0 -440
- package/lib/components/icons.ts +0 -464
- package/lib/components/image.d.ts +0 -42
- package/lib/components/image.d.ts.map +0 -1
- package/lib/components/image.js +0 -204
- package/lib/components/image.ts +0 -260
- package/lib/components/include.d.ts +0 -86
- package/lib/components/include.d.ts.map +0 -1
- package/lib/components/include.js +0 -238
- package/lib/components/include.ts +0 -281
- package/lib/components/input.d.ts +0 -85
- package/lib/components/input.d.ts.map +0 -1
- package/lib/components/input.js +0 -362
- package/lib/components/input.ts +0 -473
- package/lib/components/layer.d.ts +0 -72
- package/lib/components/layer.d.ts.map +0 -1
- package/lib/components/layer.js +0 -219
- package/lib/components/layer.ts +0 -304
- package/lib/components/link.d.ts +0 -41
- package/lib/components/link.d.ts.map +0 -1
- package/lib/components/link.js +0 -216
- package/lib/components/link.ts +0 -268
- package/lib/components/list.d.ts +0 -83
- package/lib/components/list.d.ts.map +0 -1
- package/lib/components/list.js +0 -314
- package/lib/components/list.ts +0 -423
- package/lib/components/loading.d.ts +0 -25
- package/lib/components/loading.d.ts.map +0 -1
- package/lib/components/loading.js +0 -76
- package/lib/components/loading.ts +0 -104
- package/lib/components/menu.d.ts +0 -38
- package/lib/components/menu.d.ts.map +0 -1
- package/lib/components/menu.js +0 -205
- package/lib/components/menu.ts +0 -279
- package/lib/components/modal.d.ts +0 -97
- package/lib/components/modal.d.ts.map +0 -1
- package/lib/components/modal.js +0 -463
- package/lib/components/modal.ts +0 -576
- package/lib/components/nav.d.ts +0 -46
- package/lib/components/nav.d.ts.map +0 -1
- package/lib/components/nav.js +0 -193
- package/lib/components/nav.ts +0 -261
- package/lib/components/paragraph.d.ts +0 -30
- package/lib/components/paragraph.d.ts.map +0 -1
- package/lib/components/paragraph.js +0 -93
- package/lib/components/paragraph.ts +0 -123
- package/lib/components/pen.d.ts +0 -125
- package/lib/components/pen.d.ts.map +0 -1
- package/lib/components/pen.js +0 -443
- package/lib/components/pen.ts +0 -567
- package/lib/components/progress.d.ts +0 -40
- package/lib/components/progress.d.ts.map +0 -1
- package/lib/components/progress.js +0 -116
- package/lib/components/progress.ts +0 -163
- package/lib/components/radio.d.ts +0 -43
- package/lib/components/radio.d.ts.map +0 -1
- package/lib/components/radio.js +0 -226
- package/lib/components/radio.ts +0 -303
- package/lib/components/registry.d.ts +0 -34
- package/lib/components/registry.d.ts.map +0 -1
- package/lib/components/registry.js +0 -163
- package/lib/components/registry.ts +0 -193
- package/lib/components/req.d.ts +0 -155
- package/lib/components/req.d.ts.map +0 -1
- package/lib/components/req.js +0 -253
- package/lib/components/req.ts +0 -303
- package/lib/components/script.d.ts +0 -14
- package/lib/components/script.d.ts.map +0 -1
- package/lib/components/script.js +0 -33
- package/lib/components/script.ts +0 -41
- package/lib/components/select.d.ts +0 -42
- package/lib/components/select.d.ts.map +0 -1
- package/lib/components/select.js +0 -209
- package/lib/components/select.ts +0 -281
- package/lib/components/sidebar.d.ts +0 -59
- package/lib/components/sidebar.d.ts.map +0 -1
- package/lib/components/sidebar.js +0 -298
- package/lib/components/sidebar.ts +0 -395
- package/lib/components/stack/BaseStack.d.ts +0 -65
- package/lib/components/stack/BaseStack.d.ts.map +0 -1
- package/lib/components/stack/BaseStack.js +0 -274
- package/lib/components/stack/BaseStack.ts +0 -328
- package/lib/components/stack/HStack.d.ts +0 -18
- package/lib/components/stack/HStack.d.ts.map +0 -1
- package/lib/components/stack/HStack.js +0 -22
- package/lib/components/stack/HStack.ts +0 -25
- package/lib/components/stack/VStack.d.ts +0 -19
- package/lib/components/stack/VStack.d.ts.map +0 -1
- package/lib/components/stack/VStack.js +0 -23
- package/lib/components/stack/VStack.ts +0 -26
- package/lib/components/stack/ZStack.d.ts +0 -18
- package/lib/components/stack/ZStack.d.ts.map +0 -1
- package/lib/components/stack/ZStack.js +0 -22
- package/lib/components/stack/ZStack.ts +0 -25
- package/lib/components/style.d.ts +0 -14
- package/lib/components/style.d.ts.map +0 -1
- package/lib/components/style.js +0 -33
- package/lib/components/style.ts +0 -41
- package/lib/components/switch.d.ts +0 -34
- package/lib/components/switch.d.ts.map +0 -1
- package/lib/components/switch.js +0 -209
- package/lib/components/switch.ts +0 -272
- package/lib/components/table.d.ts +0 -137
- package/lib/components/table.d.ts.map +0 -1
- package/lib/components/table.js +0 -1019
- package/lib/components/table.ts +0 -1225
- package/lib/components/tabs.d.ts +0 -53
- package/lib/components/tabs.d.ts.map +0 -1
- package/lib/components/tabs.js +0 -275
- package/lib/components/tabs.ts +0 -349
- package/lib/components/theme-toggle.d.ts +0 -45
- package/lib/components/theme-toggle.d.ts.map +0 -1
- package/lib/components/theme-toggle.js +0 -218
- package/lib/components/theme-toggle.ts +0 -297
- package/lib/components/tooltip.d.ts +0 -31
- package/lib/components/tooltip.d.ts.map +0 -1
- package/lib/components/tooltip.js +0 -112
- package/lib/components/tooltip.ts +0 -148
- package/lib/components/watcher.d.ts +0 -195
- package/lib/components/watcher.d.ts.map +0 -1
- package/lib/components/watcher.js +0 -241
- package/lib/components/watcher.ts +0 -261
- package/lib/components/write.d.ts +0 -107
- package/lib/components/write.d.ts.map +0 -1
- package/lib/components/write.js +0 -222
- package/lib/components/write.ts +0 -272
- package/lib/data/DataPipeline.d.ts +0 -113
- package/lib/data/DataPipeline.d.ts.map +0 -1
- package/lib/data/DataPipeline.js +0 -359
- package/lib/data/DataPipeline.ts +0 -452
- package/lib/facades/dataframe.jux +0 -0
- package/lib/globals.d.ts +0 -21
- package/lib/reactivity/state.d.ts +0 -36
- package/lib/reactivity/state.d.ts.map +0 -1
- package/lib/reactivity/state.js +0 -67
- package/lib/reactivity/state.ts +0 -78
- package/lib/storage/DataFrame.d.ts +0 -284
- package/lib/storage/DataFrame.d.ts.map +0 -1
- package/lib/storage/DataFrame.js +0 -1022
- package/lib/storage/DataFrame.ts +0 -1195
- package/lib/storage/DataFrameSource.d.ts +0 -158
- package/lib/storage/DataFrameSource.d.ts.map +0 -1
- package/lib/storage/DataFrameSource.js +0 -409
- package/lib/storage/DataFrameSource.ts +0 -556
- package/lib/storage/FileStorage.d.ts +0 -53
- package/lib/storage/FileStorage.d.ts.map +0 -1
- package/lib/storage/FileStorage.js +0 -80
- package/lib/storage/FileStorage.ts +0 -95
- package/lib/storage/IndexedDBDriver.d.ts +0 -75
- package/lib/storage/IndexedDBDriver.d.ts.map +0 -1
- package/lib/storage/IndexedDBDriver.js +0 -177
- package/lib/storage/IndexedDBDriver.ts +0 -226
- package/lib/storage/TabularDriver.d.ts +0 -118
- package/lib/storage/TabularDriver.d.ts.map +0 -1
- package/lib/storage/TabularDriver.js +0 -731
- package/lib/storage/TabularDriver.ts +0 -874
- package/lib/utils/codeparser.d.ts +0 -29
- package/lib/utils/codeparser.d.ts.map +0 -1
- package/lib/utils/codeparser.js +0 -409
- package/lib/utils/fetch.d.ts +0 -176
- package/lib/utils/fetch.d.ts.map +0 -1
- package/lib/utils/fetch.js +0 -427
- package/lib/utils/formatId.d.ts +0 -16
- package/lib/utils/formatId.d.ts.map +0 -1
- package/lib/utils/formatId.js +0 -27
- package/lib/utils/path-resolver.js +0 -23
package/lib/data/DataPipeline.js
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import { DataFrame } from '../storage/DataFrame.js';
|
|
2
|
-
import { TabularDriver } from '../storage/TabularDriver.js';
|
|
3
|
-
/**
|
|
4
|
-
* DataPipeline — Headless, promise-based data loading and transformation.
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* const df = await jux.gather('raw/myfile.xlsx').result();
|
|
8
|
-
* const df = await jux.gather('https://api.com/data', { bearer: 'xxx' }).result();
|
|
9
|
-
* const df = await jux.gather(myUpload).select('name').result();
|
|
10
|
-
* const df = await jux.gather([{a:1}, {b:2}]).result();
|
|
11
|
-
* await jux.gather(key).filter(r => r.active).intoTable(myTable);
|
|
12
|
-
*/
|
|
13
|
-
export class DataPipeline {
|
|
14
|
-
constructor(options = {}) {
|
|
15
|
-
this._pending = null;
|
|
16
|
-
this._transforms = [];
|
|
17
|
-
this._driver = new TabularDriver(options.dbName ?? 'jux-dataframes', options.storeName ?? 'frames');
|
|
18
|
-
this._gatherOptions = {};
|
|
19
|
-
}
|
|
20
|
-
/* ═══════════════════════════════════════════════════
|
|
21
|
-
* SMART SOURCE DETECTION
|
|
22
|
-
* ═══════════════════════════════════════════════════ */
|
|
23
|
-
/**
|
|
24
|
-
* Auto-detect source type and load accordingly.
|
|
25
|
-
*
|
|
26
|
-
* - string starting with http/https → URL fetch
|
|
27
|
-
* - string → IndexedDB storage key
|
|
28
|
-
* - File → parse file
|
|
29
|
-
* - Array → row objects
|
|
30
|
-
* - DataFrame → clone
|
|
31
|
-
* - object with .storageKey → FileUpload cached key
|
|
32
|
-
* - object with string keys + array values → column-oriented data
|
|
33
|
-
*/
|
|
34
|
-
from(source, options = {}) {
|
|
35
|
-
this._transforms = [];
|
|
36
|
-
this._gatherOptions = options;
|
|
37
|
-
// Update driver if custom db/store
|
|
38
|
-
if (options.dbName || options.storeName) {
|
|
39
|
-
this._driver = new TabularDriver(options.dbName ?? 'jux-dataframes', options.storeName ?? 'frames');
|
|
40
|
-
}
|
|
41
|
-
if (source instanceof DataFrame) {
|
|
42
|
-
this._pending = Promise.resolve(source.clone());
|
|
43
|
-
}
|
|
44
|
-
else if (Array.isArray(source)) {
|
|
45
|
-
this._pending = Promise.resolve(new DataFrame(source));
|
|
46
|
-
}
|
|
47
|
-
else if (typeof source === 'string') {
|
|
48
|
-
if (/^https?:\/\//i.test(source)) {
|
|
49
|
-
this._pending = this._loadFromUrl(source, options);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
this._pending = this._loadFromStorage(source);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if (source instanceof File) {
|
|
56
|
-
this._pending = this._loadFromFile(source, options);
|
|
57
|
-
}
|
|
58
|
-
else if (source && typeof source === 'object' && 'storageKey' in source) {
|
|
59
|
-
// FileUpload component with .cache() enabled
|
|
60
|
-
const key = source.storageKey;
|
|
61
|
-
if (!key) {
|
|
62
|
-
this._pending = Promise.reject(new Error('FileUpload has no cached storage key. Ensure .cache() is enabled and a file has been uploaded.'));
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
this._pending = this._loadFromStorage(key);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else if (source && typeof source === 'object' && !Array.isArray(source)) {
|
|
69
|
-
// Column-oriented: { col1: [...], col2: [...] }
|
|
70
|
-
this._pending = Promise.resolve(new DataFrame(source));
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this._pending = Promise.reject(new Error('Unrecognized source type passed to gather()'));
|
|
74
|
-
}
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
/* ═══════════════════════════════════════════════════
|
|
78
|
-
* EXPLICIT SOURCES (still available)
|
|
79
|
-
* ═══════════════════════════════════════════════════ */
|
|
80
|
-
fromStorage(key) {
|
|
81
|
-
this._transforms = [];
|
|
82
|
-
this._pending = this._loadFromStorage(key);
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
fromUrl(url, options = {}) {
|
|
86
|
-
this._transforms = [];
|
|
87
|
-
this._gatherOptions = options;
|
|
88
|
-
this._pending = this._loadFromUrl(url, options);
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
fromFile(file, options = {}) {
|
|
92
|
-
this._transforms = [];
|
|
93
|
-
this._pending = this._loadFromFile(file, options);
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
fromRows(rows, columns) {
|
|
97
|
-
this._transforms = [];
|
|
98
|
-
this._pending = Promise.resolve(new DataFrame(rows, { columns }));
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
fromColumns(columns) {
|
|
102
|
-
this._transforms = [];
|
|
103
|
-
this._pending = Promise.resolve(new DataFrame(columns));
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
fromJson(json) {
|
|
107
|
-
this._transforms = [];
|
|
108
|
-
const parsed = typeof json === 'string' ? JSON.parse(json) : json;
|
|
109
|
-
this._pending = Promise.resolve(new DataFrame(parsed));
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
fromUpload(upload) {
|
|
113
|
-
this._transforms = [];
|
|
114
|
-
const key = upload.storageKey;
|
|
115
|
-
if (!key) {
|
|
116
|
-
this._pending = Promise.reject(new Error('FileUpload has no cached storage key. Ensure .cache() is enabled and a file has been uploaded.'));
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this._pending = this._loadFromStorage(key);
|
|
120
|
-
}
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
/* ═══════════════════════════════════════════════════
|
|
124
|
-
* TRANSFORMS (chained, lazy — applied on terminal)
|
|
125
|
-
* ═══════════════════════════════════════════════════ */
|
|
126
|
-
transform(fn) {
|
|
127
|
-
this._transforms.push(fn);
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
select(...cols) {
|
|
131
|
-
return this.transform(df => df.select(...cols));
|
|
132
|
-
}
|
|
133
|
-
filter(predicate) {
|
|
134
|
-
return this.transform(df => df.filter(predicate));
|
|
135
|
-
}
|
|
136
|
-
sort(column, descending) {
|
|
137
|
-
return this.transform(df => df.sort(column, descending));
|
|
138
|
-
}
|
|
139
|
-
head(n = 5) {
|
|
140
|
-
return this.transform(df => df.head(n));
|
|
141
|
-
}
|
|
142
|
-
tail(n = 5) {
|
|
143
|
-
return this.transform(df => df.tail(n));
|
|
144
|
-
}
|
|
145
|
-
rename(mapping) {
|
|
146
|
-
return this.transform(df => df.rename(mapping));
|
|
147
|
-
}
|
|
148
|
-
withColumn(name, fn) {
|
|
149
|
-
return this.transform(df => df.withColumn(name, fn));
|
|
150
|
-
}
|
|
151
|
-
dropna(columns) {
|
|
152
|
-
return this.transform(df => df.dropna(columns));
|
|
153
|
-
}
|
|
154
|
-
dropDuplicates(columns) {
|
|
155
|
-
return this.transform(df => df.dropDuplicates(columns));
|
|
156
|
-
}
|
|
157
|
-
/* ═══════════════════════════════════════════════════
|
|
158
|
-
* TERMINAL OPERATIONS
|
|
159
|
-
* ═══════════════════════════════════════════════════ */
|
|
160
|
-
async result() {
|
|
161
|
-
if (!this._pending)
|
|
162
|
-
throw new Error('No data source specified. Call gather(source) or from*(source) first.');
|
|
163
|
-
let df = await this._pending;
|
|
164
|
-
for (const fn of this._transforms) {
|
|
165
|
-
df = fn(df);
|
|
166
|
-
}
|
|
167
|
-
return df;
|
|
168
|
-
}
|
|
169
|
-
async toRows() {
|
|
170
|
-
return (await this.result()).toRows();
|
|
171
|
-
}
|
|
172
|
-
async toArray(column) {
|
|
173
|
-
return (await this.result()).col(column);
|
|
174
|
-
}
|
|
175
|
-
async toDistinct(column) {
|
|
176
|
-
return (await this.result()).distinct(column);
|
|
177
|
-
}
|
|
178
|
-
async toOptions(labelKey, valueKey) {
|
|
179
|
-
const df = await this.result();
|
|
180
|
-
const vKey = valueKey ?? labelKey;
|
|
181
|
-
return df.toRows().map(row => ({
|
|
182
|
-
label: String(row[labelKey] ?? ''),
|
|
183
|
-
value: row[vKey]
|
|
184
|
-
}));
|
|
185
|
-
}
|
|
186
|
-
async toList(column) {
|
|
187
|
-
const df = await this.result();
|
|
188
|
-
return df.col(column).map(v => String(v ?? ''));
|
|
189
|
-
}
|
|
190
|
-
async intoTable(table, columnLabels) {
|
|
191
|
-
const df = await this.result();
|
|
192
|
-
const columnDefs = df.columns.map(col => ({
|
|
193
|
-
key: col,
|
|
194
|
-
label: columnLabels?.[col] ?? col
|
|
195
|
-
}));
|
|
196
|
-
table.columns(columnDefs).rows(df.toRows());
|
|
197
|
-
return df;
|
|
198
|
-
}
|
|
199
|
-
async intoDropdown(dropdown, labelKey, valueKey) {
|
|
200
|
-
const df = await this.result();
|
|
201
|
-
const vKey = valueKey ?? labelKey;
|
|
202
|
-
const opts = df.toRows().map(row => ({
|
|
203
|
-
label: String(row[labelKey] ?? ''),
|
|
204
|
-
value: row[vKey]
|
|
205
|
-
}));
|
|
206
|
-
dropdown.options(opts);
|
|
207
|
-
return df;
|
|
208
|
-
}
|
|
209
|
-
async intoList(list, column) {
|
|
210
|
-
const df = await this.result();
|
|
211
|
-
list.items(df.col(column).map((v) => String(v ?? '')));
|
|
212
|
-
return df;
|
|
213
|
-
}
|
|
214
|
-
async into(target, options = {}) {
|
|
215
|
-
const df = await this.result();
|
|
216
|
-
const rows = df.toRows();
|
|
217
|
-
if (typeof target.columns === 'function' && typeof target.rows === 'function') {
|
|
218
|
-
const cols = options.columns ?? df.columns;
|
|
219
|
-
const columnDefs = cols.map((col) => ({
|
|
220
|
-
key: col,
|
|
221
|
-
label: options.columnLabels?.[col] ?? col
|
|
222
|
-
}));
|
|
223
|
-
target.columns(columnDefs).rows(rows);
|
|
224
|
-
return df;
|
|
225
|
-
}
|
|
226
|
-
if (typeof target.fromData === 'function') {
|
|
227
|
-
target.fromData(rows);
|
|
228
|
-
return df;
|
|
229
|
-
}
|
|
230
|
-
if (typeof target.options === 'function') {
|
|
231
|
-
if (!options.labelKey) {
|
|
232
|
-
throw new Error('Cannot push into dropdown/select without labelKey. ' +
|
|
233
|
-
'Use .intoDropdown(target, labelKey, valueKey) or pass { labelKey, valueKey } to .into()');
|
|
234
|
-
}
|
|
235
|
-
const opts = rows.map(row => ({
|
|
236
|
-
label: String(row[options.labelKey] ?? ''),
|
|
237
|
-
value: row[options.valueKey ?? options.labelKey]
|
|
238
|
-
}));
|
|
239
|
-
target.options(opts);
|
|
240
|
-
return df;
|
|
241
|
-
}
|
|
242
|
-
if (typeof target.items === 'function') {
|
|
243
|
-
if (!options.labelKey) {
|
|
244
|
-
throw new Error('Cannot push into list without labelKey. ' +
|
|
245
|
-
'Use .intoList(target, column) or pass { labelKey } to .into()');
|
|
246
|
-
}
|
|
247
|
-
target.items(rows.map(row => String(row[options.labelKey] ?? '')));
|
|
248
|
-
return df;
|
|
249
|
-
}
|
|
250
|
-
throw new Error('Target does not have a recognized API (.columns/.rows, .fromData, .options, or .items)');
|
|
251
|
-
}
|
|
252
|
-
async store(key, metadata) {
|
|
253
|
-
const df = await this.result();
|
|
254
|
-
await this._driver.store(key, df, metadata);
|
|
255
|
-
return df;
|
|
256
|
-
}
|
|
257
|
-
/* ═══════════════════════════════════════════════════
|
|
258
|
-
* PRIVATE
|
|
259
|
-
* ═══════════════════════════════════════════════════ */
|
|
260
|
-
async _loadFromStorage(key) {
|
|
261
|
-
// Try by name first, then by id
|
|
262
|
-
let df = await this._driver.loadByName(key);
|
|
263
|
-
if (df)
|
|
264
|
-
return df;
|
|
265
|
-
df = await this._driver.load(key);
|
|
266
|
-
if (df)
|
|
267
|
-
return df;
|
|
268
|
-
throw new Error(`No data found in storage with key: "${key}"`);
|
|
269
|
-
}
|
|
270
|
-
async _loadFromUrl(url, options) {
|
|
271
|
-
const mimeType = options.mimeType ?? this._detectMimeType(url);
|
|
272
|
-
// Build headers from auth options
|
|
273
|
-
const headers = { ...options.headers };
|
|
274
|
-
if (options.bearer) {
|
|
275
|
-
headers['Authorization'] = `Bearer ${options.bearer}`;
|
|
276
|
-
}
|
|
277
|
-
if (options.apiKey) {
|
|
278
|
-
headers['x-api-key'] = options.apiKey;
|
|
279
|
-
}
|
|
280
|
-
if (mimeType === 'json') {
|
|
281
|
-
const response = await fetch(url, { headers });
|
|
282
|
-
if (!response.ok)
|
|
283
|
-
throw new Error(`Fetch failed: ${response.status} ${response.statusText}`);
|
|
284
|
-
const json = await response.json();
|
|
285
|
-
return new DataFrame(json);
|
|
286
|
-
}
|
|
287
|
-
// CSV/TSV — fetch with headers, then parse
|
|
288
|
-
if (Object.keys(headers).length > 0) {
|
|
289
|
-
const response = await fetch(url, { headers });
|
|
290
|
-
if (!response.ok)
|
|
291
|
-
throw new Error(`Fetch failed: ${response.status} ${response.statusText}`);
|
|
292
|
-
const text = await response.text();
|
|
293
|
-
return this._driver.parseCSV(text, {
|
|
294
|
-
autoDetectDelimiter: !options.delimiter,
|
|
295
|
-
delimiter: options.delimiter,
|
|
296
|
-
hasHeader: options.hasHeader ?? true,
|
|
297
|
-
headerRow: options.headerRow
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
return this._driver.fetch(url, {
|
|
301
|
-
autoDetectDelimiter: !options.delimiter,
|
|
302
|
-
delimiter: options.delimiter,
|
|
303
|
-
hasHeader: options.hasHeader ?? true,
|
|
304
|
-
headerRow: options.headerRow
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
async _loadFromFile(file, options) {
|
|
308
|
-
const isExcel = /\.(xlsx?|xls)$/i.test(file.name);
|
|
309
|
-
if (isExcel) {
|
|
310
|
-
const sheets = await this._driver.streamFileMultiSheet(file, {
|
|
311
|
-
headerRow: options.headerRow
|
|
312
|
-
});
|
|
313
|
-
const sheetNames = Object.keys(sheets);
|
|
314
|
-
if (sheetNames.length === 0)
|
|
315
|
-
throw new Error('No data found in file');
|
|
316
|
-
return sheets[sheetNames[0]];
|
|
317
|
-
}
|
|
318
|
-
const text = await file.text();
|
|
319
|
-
return this._driver.parseCSV(text, {
|
|
320
|
-
autoDetectDelimiter: !options.delimiter,
|
|
321
|
-
delimiter: options.delimiter,
|
|
322
|
-
hasHeader: options.hasHeader ?? true,
|
|
323
|
-
headerRow: options.headerRow
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
_detectMimeType(url) {
|
|
327
|
-
const lower = url.toLowerCase().split('?')[0];
|
|
328
|
-
if (lower.endsWith('.json'))
|
|
329
|
-
return 'json';
|
|
330
|
-
if (lower.endsWith('.tsv'))
|
|
331
|
-
return 'tsv';
|
|
332
|
-
if (lower.endsWith('.csv'))
|
|
333
|
-
return 'csv';
|
|
334
|
-
return 'auto';
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Factory function — primary entry point via jux.gather()
|
|
339
|
-
*
|
|
340
|
-
* Smart single-arg:
|
|
341
|
-
* jux.gather('raw/myfile.xlsx') // storage key
|
|
342
|
-
* jux.gather('https://api.com/data', { bearer: 'xxx' }) // URL with auth
|
|
343
|
-
* jux.gather(myUpload) // FileUpload
|
|
344
|
-
* jux.gather([{a:1}, {b:2}]) // inline rows
|
|
345
|
-
* jux.gather(existingDf) // clone DataFrame
|
|
346
|
-
*
|
|
347
|
-
* Explicit source:
|
|
348
|
-
* jux.gather().fromStorage(key)
|
|
349
|
-
* jux.gather().fromUrl(url, opts)
|
|
350
|
-
*/
|
|
351
|
-
export function gather(source, options) {
|
|
352
|
-
const pipe = new DataPipeline(options?.dbName || options?.storeName
|
|
353
|
-
? { dbName: options.dbName, storeName: options.storeName }
|
|
354
|
-
: {});
|
|
355
|
-
if (source !== undefined) {
|
|
356
|
-
pipe.from(source, options ?? {});
|
|
357
|
-
}
|
|
358
|
-
return pipe;
|
|
359
|
-
}
|