juxscript 1.1.231 → 1.1.232

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.
@@ -0,0 +1,158 @@
1
+ import { DataFrame } from './DataFrame.js';
2
+ export interface SourceOptions {
3
+ dbName?: string;
4
+ storeName?: string;
5
+ persistToIndexedDB?: boolean;
6
+ inferTypes?: boolean;
7
+ maxFileSize?: number;
8
+ maxSheetSize?: number;
9
+ headerRow?: number;
10
+ delimiter?: string;
11
+ }
12
+ export interface APIOptions {
13
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
14
+ headers?: Record<string, string>;
15
+ body?: any;
16
+ credentials?: 'omit' | 'same-origin' | 'include';
17
+ dataPath?: string;
18
+ }
19
+ export interface StreamOptions {
20
+ mimeType?: string;
21
+ chunkSize?: number;
22
+ cacheToIndexedDB?: boolean;
23
+ }
24
+ export interface MultiSheetResult {
25
+ sheets: Map<string, DataFrame>;
26
+ sheetNames: string[];
27
+ activeSheet: string;
28
+ }
29
+ /**
30
+ * DataFrameSource - Data acquisition layer for DataFrames
31
+ *
32
+ * Responsibilities:
33
+ * - Load from files (CSV, TSV, Excel)
34
+ * - Load from URLs (fetch, stream)
35
+ * - Load from APIs (with auth, JSON traversal)
36
+ * - Load from IndexedDB
37
+ * - Load from inline data
38
+ * - Multi-sheet support
39
+ * - Progress callbacks
40
+ *
41
+ * This is a PURE data layer - no UI concerns
42
+ */
43
+ export declare class DataFrameSource {
44
+ private _driver;
45
+ private _options;
46
+ private _sheets;
47
+ private _activeSheet;
48
+ private _sourceName;
49
+ private _rawFile;
50
+ private _rawText;
51
+ constructor(options?: SourceOptions);
52
+ /**
53
+ * Load from a File object (CSV, TSV, Excel)
54
+ */
55
+ fromFile(file: File, onProgress?: (loaded: number, total: number | null) => void): Promise<DataFrame | MultiSheetResult>;
56
+ /**
57
+ * Fetch CSV/TSV from URL
58
+ */
59
+ fromUrl(url: string, onProgress?: (loaded: number, total: number | null) => void): Promise<DataFrame>;
60
+ /**
61
+ * Fetch data from API endpoint
62
+ * Supports JSON response with path traversal
63
+ */
64
+ fromAPI(url: string, options?: APIOptions): Promise<DataFrame>;
65
+ /**
66
+ * Traverse JSON path like "data.results" or "response.items[0].records"
67
+ */
68
+ private _traversePath;
69
+ /**
70
+ * Stream binary data from URL, auto-detect format from MIME type
71
+ */
72
+ fromStream(url: string, options?: StreamOptions, onProgress?: (loaded: number, total: number | null) => void): Promise<DataFrame | MultiSheetResult>;
73
+ private _cacheBlob;
74
+ /**
75
+ * Load from IndexedDB by key/name
76
+ */
77
+ fromStorage(key: string): Promise<DataFrame | null>;
78
+ /**
79
+ * List all stored DataFrames
80
+ */
81
+ listStored(): Promise<Array<{
82
+ id: string;
83
+ name: string;
84
+ rowCount: number;
85
+ timestamp: number;
86
+ }>>;
87
+ /**
88
+ * Create from inline data
89
+ */
90
+ fromData(data: Record<string, any>[] | Record<string, any[]>, name?: string): DataFrame;
91
+ /**
92
+ * Create empty DataFrame with specified columns
93
+ */
94
+ empty(columns: string[]): DataFrame;
95
+ /**
96
+ * Re-parse with different options
97
+ */
98
+ reimport(options: {
99
+ headerRow?: number;
100
+ delimiter?: string;
101
+ sheetName?: string;
102
+ }): Promise<DataFrame | MultiSheetResult>;
103
+ /**
104
+ * Get raw preview rows for header selection UI
105
+ */
106
+ getPreviewRows(maxRows?: number): Promise<{
107
+ row: number;
108
+ values: any[];
109
+ }[]>;
110
+ /**
111
+ * Get all sheet names
112
+ */
113
+ get sheetNames(): string[];
114
+ /**
115
+ * Get active sheet
116
+ */
117
+ get activeSheet(): string;
118
+ /**
119
+ * Set active sheet
120
+ */
121
+ setActiveSheet(name: string): DataFrame;
122
+ /**
123
+ * Get specific sheet by name
124
+ */
125
+ getSheet(name: string): DataFrame | undefined;
126
+ /**
127
+ * Get current DataFrame (active sheet)
128
+ */
129
+ get df(): DataFrame | null;
130
+ /**
131
+ * Get all sheets
132
+ */
133
+ get sheets(): Map<string, DataFrame>;
134
+ /**
135
+ * Save current DataFrame to IndexedDB
136
+ */
137
+ save(key?: string): Promise<string | null>;
138
+ /**
139
+ * Save all sheets
140
+ */
141
+ saveAll(prefix?: string): Promise<string[]>;
142
+ /**
143
+ * Delete from storage
144
+ */
145
+ deleteStored(key: string): Promise<void>;
146
+ /**
147
+ * Clear all data
148
+ */
149
+ clear(): void;
150
+ get sourceName(): string;
151
+ get hasRawData(): boolean;
152
+ get isExcel(): boolean;
153
+ }
154
+ /**
155
+ * Factory function
156
+ */
157
+ export declare function dataFrameSource(options?: SourceOptions): DataFrameSource;
158
+ //# sourceMappingURL=DataFrameSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataFrameSource.d.ts","sourceRoot":"","sources":["DataFrameSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,MAAM,WAAW,aAAa;IAE1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAG7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACvB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,C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IAAI,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAEnC;IAMD;;OAEG;IACG,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQhD;;OAEG;IACG,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAYjD;;OAEG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9C;;OAEG;IACH,KAAK,IAAI,IAAI;IAYb,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;CACJ;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,aAAkB,GAAG,eAAe,CAE5E"}
@@ -0,0 +1,409 @@
1
+ import { DataFrame } from './DataFrame.js';
2
+ import { TabularDriver } from './TabularDriver.js';
3
+ /**
4
+ * DataFrameSource - Data acquisition layer for DataFrames
5
+ *
6
+ * Responsibilities:
7
+ * - Load from files (CSV, TSV, Excel)
8
+ * - Load from URLs (fetch, stream)
9
+ * - Load from APIs (with auth, JSON traversal)
10
+ * - Load from IndexedDB
11
+ * - Load from inline data
12
+ * - Multi-sheet support
13
+ * - Progress callbacks
14
+ *
15
+ * This is a PURE data layer - no UI concerns
16
+ */
17
+ export class DataFrameSource {
18
+ constructor(options = {}) {
19
+ this._sheets = new Map();
20
+ this._activeSheet = '';
21
+ this._sourceName = '';
22
+ this._rawFile = null;
23
+ this._rawText = null;
24
+ this._options = {
25
+ dbName: options.dbName ?? 'jux-dataframes',
26
+ storeName: options.storeName ?? 'frames',
27
+ persistToIndexedDB: options.persistToIndexedDB ?? false,
28
+ inferTypes: options.inferTypes ?? true,
29
+ maxFileSize: options.maxFileSize ?? 50,
30
+ maxSheetSize: options.maxSheetSize ?? 100000,
31
+ headerRow: options.headerRow ?? 0,
32
+ delimiter: options.delimiter
33
+ };
34
+ this._driver = new TabularDriver(this._options.dbName, this._options.storeName);
35
+ }
36
+ /* ═══════════════════════════════════════════════════
37
+ * FROM FILE
38
+ * ═══════════════════════════════════════════════════ */
39
+ /**
40
+ * Load from a File object (CSV, TSV, Excel)
41
+ */
42
+ async fromFile(file, onProgress) {
43
+ const fileSizeMB = file.size / (1024 * 1024);
44
+ if (fileSizeMB > this._options.maxFileSize) {
45
+ throw new Error(`File too large (${fileSizeMB.toFixed(1)}MB). Max: ${this._options.maxFileSize}MB`);
46
+ }
47
+ this._rawFile = file;
48
+ this._sourceName = file.name;
49
+ const isExcel = /\.(xlsx?|xls)$/i.test(file.name);
50
+ if (isExcel) {
51
+ const sheets = await this._driver.streamFileMultiSheet(file, {
52
+ maxSheetSize: this._options.maxSheetSize,
53
+ headerRow: this._options.headerRow,
54
+ onProgress
55
+ });
56
+ this._sheets.clear();
57
+ const sheetNames = Object.keys(sheets);
58
+ sheetNames.forEach(name => {
59
+ this._sheets.set(name, sheets[name]);
60
+ });
61
+ this._activeSheet = sheetNames[0] || '';
62
+ if (this._options.persistToIndexedDB) {
63
+ await this._driver.store(file.name, sheets[sheetNames[0]], { source: file.name });
64
+ }
65
+ if (sheetNames.length > 1) {
66
+ return {
67
+ sheets: this._sheets,
68
+ sheetNames,
69
+ activeSheet: this._activeSheet
70
+ };
71
+ }
72
+ else {
73
+ return this._sheets.get(this._activeSheet);
74
+ }
75
+ }
76
+ else {
77
+ const text = await file.text();
78
+ this._rawText = text;
79
+ const df = this._driver.parseCSV(text, {
80
+ autoDetectDelimiter: !this._options.delimiter,
81
+ delimiter: this._options.delimiter,
82
+ headerRow: this._options.headerRow,
83
+ hasHeader: true
84
+ });
85
+ this._sheets.set('Sheet1', df);
86
+ this._activeSheet = 'Sheet1';
87
+ if (this._options.persistToIndexedDB) {
88
+ await this._driver.store(file.name, df, { source: file.name });
89
+ }
90
+ return df;
91
+ }
92
+ }
93
+ /* ═══════════════════════════════════════════════════
94
+ * FROM URL (Simple Fetch)
95
+ * ═══════════════════════════════════════════════════ */
96
+ /**
97
+ * Fetch CSV/TSV from URL
98
+ */
99
+ async fromUrl(url, onProgress) {
100
+ this._sourceName = url.split('/').pop() || url;
101
+ const df = await this._driver.fetch(url, {
102
+ autoDetectDelimiter: true,
103
+ hasHeader: true,
104
+ headerRow: this._options.headerRow,
105
+ onProgress
106
+ });
107
+ this._sheets.set('Sheet1', df);
108
+ this._activeSheet = 'Sheet1';
109
+ if (this._options.persistToIndexedDB) {
110
+ await this._driver.store(this._sourceName, df, { source: url });
111
+ }
112
+ return df;
113
+ }
114
+ /* ═══════════════════════════════════════════════════
115
+ * FROM API (JSON with traversal)
116
+ * ═══════════════════════════════════════════════════ */
117
+ /**
118
+ * Fetch data from API endpoint
119
+ * Supports JSON response with path traversal
120
+ */
121
+ async fromAPI(url, options = {}) {
122
+ const { method = 'GET', headers = {}, body, credentials = 'same-origin', dataPath } = options;
123
+ const fetchOptions = {
124
+ method,
125
+ headers: {
126
+ 'Accept': 'application/json',
127
+ ...headers
128
+ },
129
+ credentials
130
+ };
131
+ if (body && method !== 'GET') {
132
+ fetchOptions.body = typeof body === 'string' ? body : JSON.stringify(body);
133
+ if (!headers['Content-Type']) {
134
+ fetchOptions.headers['Content-Type'] = 'application/json';
135
+ }
136
+ }
137
+ const response = await fetch(url, fetchOptions);
138
+ if (!response.ok) {
139
+ throw new Error(`API request failed: ${response.status} ${response.statusText}`);
140
+ }
141
+ let data = await response.json();
142
+ // Traverse to data path if specified
143
+ if (dataPath) {
144
+ data = this._traversePath(data, dataPath);
145
+ }
146
+ // Convert to DataFrame
147
+ if (!Array.isArray(data)) {
148
+ throw new Error('API response must be an array of objects (or use dataPath to navigate to array)');
149
+ }
150
+ const df = new DataFrame(data, { inferTypes: this._options.inferTypes });
151
+ this._sourceName = url;
152
+ this._sheets.set('Sheet1', df);
153
+ this._activeSheet = 'Sheet1';
154
+ if (this._options.persistToIndexedDB) {
155
+ await this._driver.store(this._sourceName, df, { source: url });
156
+ }
157
+ return df;
158
+ }
159
+ /**
160
+ * Traverse JSON path like "data.results" or "response.items[0].records"
161
+ */
162
+ _traversePath(obj, path) {
163
+ const parts = path.split(/\.|\[|\]/).filter(Boolean);
164
+ let current = obj;
165
+ for (const part of parts) {
166
+ if (current === null || current === undefined) {
167
+ throw new Error(`Cannot traverse path '${path}': null at '${part}'`);
168
+ }
169
+ const index = Number(part);
170
+ if (!isNaN(index)) {
171
+ current = current[index];
172
+ }
173
+ else {
174
+ current = current[part];
175
+ }
176
+ }
177
+ return current;
178
+ }
179
+ /* ═══════════════════════════════════════════════════
180
+ * FROM STREAM (Binary data with MIME type)
181
+ * ═══════════════════════════════════════════════════ */
182
+ /**
183
+ * Stream binary data from URL, auto-detect format from MIME type
184
+ */
185
+ async fromStream(url, options = {}, onProgress) {
186
+ const { mimeType, cacheToIndexedDB = false } = options;
187
+ const response = await fetch(url);
188
+ if (!response.ok) {
189
+ throw new Error(`Stream request failed: ${response.status}`);
190
+ }
191
+ const contentType = mimeType || response.headers.get('content-type') || '';
192
+ const fileName = url.split('/').pop() || 'stream-data';
193
+ // Get the blob
194
+ const blob = await response.blob();
195
+ const file = new File([blob], fileName, { type: contentType });
196
+ // Cache to IndexedDB if requested
197
+ if (cacheToIndexedDB) {
198
+ // Store raw blob for potential re-parsing
199
+ await this._cacheBlob(fileName, blob);
200
+ }
201
+ // Parse based on content type
202
+ return this.fromFile(file, onProgress);
203
+ }
204
+ async _cacheBlob(name, blob) {
205
+ // Simple blob caching in IndexedDB
206
+ const db = await this._driver.open();
207
+ return new Promise((resolve, reject) => {
208
+ const tx = db.transaction('blobs', 'readwrite');
209
+ const store = tx.objectStore('blobs');
210
+ store.put({ name, blob, timestamp: Date.now() });
211
+ tx.oncomplete = () => resolve();
212
+ tx.onerror = () => reject(tx.error);
213
+ });
214
+ }
215
+ /* ═══════════════════════════════════════════════════
216
+ * FROM INDEXEDDB
217
+ * ═══════════════════════════════════════════════════ */
218
+ /**
219
+ * Load from IndexedDB by key/name
220
+ */
221
+ async fromStorage(key) {
222
+ const df = await this._driver.loadByName(key);
223
+ if (df) {
224
+ this._sourceName = key;
225
+ this._sheets.set('Sheet1', df);
226
+ this._activeSheet = 'Sheet1';
227
+ }
228
+ return df;
229
+ }
230
+ /**
231
+ * List all stored DataFrames
232
+ */
233
+ async listStored() {
234
+ return this._driver.list();
235
+ }
236
+ /* ═══════════════════════════════════════════════════
237
+ * FROM INLINE DATA
238
+ * ═══════════════════════════════════════════════════ */
239
+ /**
240
+ * Create from inline data
241
+ */
242
+ fromData(data, name = 'inline') {
243
+ const df = new DataFrame(data, { inferTypes: this._options.inferTypes });
244
+ this._sourceName = name;
245
+ this._sheets.set('Sheet1', df);
246
+ this._activeSheet = 'Sheet1';
247
+ return df;
248
+ }
249
+ /**
250
+ * Create empty DataFrame with specified columns
251
+ */
252
+ empty(columns) {
253
+ const data = {};
254
+ columns.forEach(c => { data[c] = []; });
255
+ return this.fromData(data, 'empty');
256
+ }
257
+ /* ═══════════════════════════════════════════════════
258
+ * RE-IMPORT / RE-PARSE
259
+ * ═══════════════════════════════════════════════════ */
260
+ /**
261
+ * Re-parse with different options
262
+ */
263
+ async reimport(options) {
264
+ if (this._rawFile) {
265
+ // Update options
266
+ if (options.headerRow !== undefined) {
267
+ this._options.headerRow = options.headerRow;
268
+ }
269
+ if (options.delimiter !== undefined) {
270
+ this._options.delimiter = options.delimiter;
271
+ }
272
+ return this.fromFile(this._rawFile);
273
+ }
274
+ else if (this._rawText) {
275
+ const df = this._driver.parseCSV(this._rawText, {
276
+ delimiter: options.delimiter || this._options.delimiter,
277
+ headerRow: options.headerRow ?? this._options.headerRow,
278
+ hasHeader: true
279
+ });
280
+ this._sheets.set(this._activeSheet, df);
281
+ return df;
282
+ }
283
+ throw new Error('No raw data available for reimport');
284
+ }
285
+ /**
286
+ * Get raw preview rows for header selection UI
287
+ */
288
+ async getPreviewRows(maxRows = 15) {
289
+ if (this._rawFile && /\.(xlsx?|xls)$/i.test(this._rawFile.name)) {
290
+ const rows = await this._driver.readRawExcelRows(this._rawFile, maxRows);
291
+ return rows.map(r => ({ row: r.sheetRow, values: r.values }));
292
+ }
293
+ else if (this._rawText) {
294
+ const lines = this._rawText.split('\n').slice(0, maxRows);
295
+ const delimiter = this._driver._detectDelimiter(this._rawText);
296
+ return lines.map((line, i) => ({
297
+ row: i,
298
+ values: this._driver._parseLine(line, delimiter)
299
+ }));
300
+ }
301
+ return [];
302
+ }
303
+ /* ═══════════════════════════════════════════════════
304
+ * MULTI-SHEET ACCESS
305
+ * ═══════════════════════════════════════════════════ */
306
+ /**
307
+ * Get all sheet names
308
+ */
309
+ get sheetNames() {
310
+ return Array.from(this._sheets.keys());
311
+ }
312
+ /**
313
+ * Get active sheet
314
+ */
315
+ get activeSheet() {
316
+ return this._activeSheet;
317
+ }
318
+ /**
319
+ * Set active sheet
320
+ */
321
+ setActiveSheet(name) {
322
+ if (!this._sheets.has(name)) {
323
+ throw new Error(`Sheet '${name}' not found`);
324
+ }
325
+ this._activeSheet = name;
326
+ return this._sheets.get(name);
327
+ }
328
+ /**
329
+ * Get specific sheet by name
330
+ */
331
+ getSheet(name) {
332
+ return this._sheets.get(name);
333
+ }
334
+ /**
335
+ * Get current DataFrame (active sheet)
336
+ */
337
+ get df() {
338
+ return this._sheets.get(this._activeSheet) || null;
339
+ }
340
+ /**
341
+ * Get all sheets
342
+ */
343
+ get sheets() {
344
+ return new Map(this._sheets);
345
+ }
346
+ /* ═══════════════════════════════════════════════════
347
+ * PERSISTENCE
348
+ * ═══════════════════════════════════════════════════ */
349
+ /**
350
+ * Save current DataFrame to IndexedDB
351
+ */
352
+ async save(key) {
353
+ const df = this.df;
354
+ if (!df)
355
+ return null;
356
+ const name = key || this._sourceName;
357
+ return this._driver.store(name, df);
358
+ }
359
+ /**
360
+ * Save all sheets
361
+ */
362
+ async saveAll(prefix) {
363
+ const ids = [];
364
+ for (const [sheetName, df] of this._sheets) {
365
+ const key = prefix ? `${prefix}_${sheetName}` : `${this._sourceName}_${sheetName}`;
366
+ const id = await this._driver.store(key, df);
367
+ ids.push(id);
368
+ }
369
+ return ids;
370
+ }
371
+ /**
372
+ * Delete from storage
373
+ */
374
+ async deleteStored(key) {
375
+ const tables = await this._driver.list();
376
+ const matching = tables.filter(t => t.name === key);
377
+ for (const table of matching) {
378
+ await this._driver.delete(table.id);
379
+ }
380
+ }
381
+ /**
382
+ * Clear all data
383
+ */
384
+ clear() {
385
+ this._sheets.clear();
386
+ this._activeSheet = '';
387
+ this._sourceName = '';
388
+ this._rawFile = null;
389
+ this._rawText = null;
390
+ }
391
+ /* ═══════════════════════════════════════════════════
392
+ * SOURCE INFO
393
+ * ═══════════════════════════════════════════════════ */
394
+ get sourceName() {
395
+ return this._sourceName;
396
+ }
397
+ get hasRawData() {
398
+ return this._rawFile !== null || this._rawText !== null;
399
+ }
400
+ get isExcel() {
401
+ return this._rawFile !== null && /\.(xlsx?|xls)$/i.test(this._rawFile.name);
402
+ }
403
+ }
404
+ /**
405
+ * Factory function
406
+ */
407
+ export function dataFrameSource(options = {}) {
408
+ return new DataFrameSource(options);
409
+ }