@graphysdk/data-import-utils 1.8.0 → 1.8.1-beta.1786024899180
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/LICENSE.md +17 -0
- package/README.md +11 -15
- package/dist/buffer.cjs +1 -1
- package/dist/buffer.mjs +4 -1
- package/dist/constants-BSk6SyUk.cjs +1 -0
- package/dist/constants-PA0Uh9bi.js +5 -0
- package/dist/csv.cjs +1 -1
- package/dist/csv.mjs +4 -1
- package/dist/file.cjs +1 -1
- package/dist/file.mjs +17 -1
- package/dist/format-detection-1kqWtVpP.cjs +1 -0
- package/dist/format-detection-MwlOpP6Y.js +18 -0
- package/dist/from-csv-Ccr_5k9u.cjs +1 -0
- package/dist/from-csv-CrQ_H-s5.js +5 -0
- package/dist/from-csv.d.ts +13 -0
- package/dist/from-json-DC712HdK.js +48 -0
- package/dist/from-json-lzRNXlod.cjs +1 -0
- package/dist/{json.d.ts → from-json.d.ts} +4 -18
- package/dist/from-spreadsheet-D2kWRyr3.js +79 -0
- package/dist/from-spreadsheet-EfBhqj2z.cjs +1 -0
- package/dist/from-spreadsheet.d.ts +20 -0
- package/dist/from-tsv-B02B59Ey.cjs +1 -0
- package/dist/from-tsv-CPj6UzXC.js +5 -0
- package/dist/from-tsv.d.ts +11 -0
- package/dist/index-buffer.d.ts +2 -0
- package/dist/index-csv.d.ts +2 -0
- package/dist/index-file.d.ts +2 -0
- package/dist/index-json.d.ts +3 -0
- package/dist/index-ods.d.ts +2 -0
- package/dist/index-text.d.ts +2 -0
- package/dist/index-tsv.d.ts +2 -0
- package/dist/index-url.d.ts +2 -0
- package/dist/index-xls.d.ts +2 -0
- package/dist/index-xlsx.d.ts +8 -0
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +8 -44
- package/dist/index.mjs +0 -1
- package/dist/json.cjs +1 -1
- package/dist/json.mjs +4 -1
- package/dist/map-rows-1hzHO_rN.cjs +1 -0
- package/dist/map-rows-GOmUltJ3.js +35 -0
- package/dist/ods.cjs +1 -1
- package/dist/ods.mjs +4 -1
- package/dist/parse-delimited-BSoFIVFq.cjs +1 -0
- package/dist/parse-delimited-qsjX5KAa.js +28 -0
- package/dist/parse-delimited.d.ts +7 -0
- package/dist/parse-file.d.ts +12 -0
- package/dist/parse-string-DpdSP3xh.cjs +1 -0
- package/dist/parse-string-VVlSsL2Y.js +47 -0
- package/dist/parse-string.d.ts +29 -0
- package/dist/parse-url.d.ts +14 -0
- package/dist/spreadsheet/cell-primitive.d.ts +7 -0
- package/dist/spreadsheet/load-workbook.d.ts +3 -0
- package/dist/spreadsheet/read-region.d.ts +39 -0
- package/dist/spreadsheet/workbook-index.d.ts +50 -0
- package/dist/text.cjs +1 -1
- package/dist/text.mjs +4 -1
- package/dist/tsv.cjs +1 -1
- package/dist/tsv.mjs +4 -1
- package/dist/{url.d.ts → types.d.ts} +18 -24
- package/dist/url.cjs +1 -1
- package/dist/url.mjs +87 -1
- package/dist/utils/build-columns.d.ts +10 -0
- package/dist/utils/column-index-to-property-key.d.ts +2 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/format-detection.d.ts +4 -0
- package/dist/utils/map-rows.d.ts +13 -0
- package/dist/utils/normalize-value.d.ts +12 -0
- package/dist/utils/url-validation.d.ts +2 -0
- package/dist/wire-data.types.d.ts +13 -0
- package/dist/xls.cjs +1 -1
- package/dist/xls.mjs +4 -1
- package/dist/xlsx.cjs +1 -1
- package/dist/xlsx.mjs +172 -1
- package/package.json +52 -38
- package/dist/README.md +0 -78
- package/dist/buffer.d.ts +0 -36
- package/dist/csv.d.ts +0 -32
- package/dist/file.d.ts +0 -42
- package/dist/ods.d.ts +0 -31
- package/dist/text.d.ts +0 -32
- package/dist/tsv.d.ts +0 -30
- package/dist/xls.d.ts +0 -32
- package/dist/xlsx.d.ts +0 -127
package/LICENSE.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
This software is available under any of the following licenses, at your option,
|
|
4
|
+
depending on which one's conditions you meet:
|
|
5
|
+
|
|
6
|
+
- **PolyForm Noncommercial 1.0.0** — for noncommercial use (personal,
|
|
7
|
+
charitable, educational, research, government).
|
|
8
|
+
See [licenses/PolyForm-NonCommercial-1.0.0.md](licenses/PolyForm-NonCommercial-1.0.0.md)
|
|
9
|
+
|
|
10
|
+
- **PolyForm Small Business 1.0.0** — free commercial use for organizations
|
|
11
|
+
under the size thresholds defined in the license.
|
|
12
|
+
See [licenses/PolyForm-Small-Business-1.0.0.md](licenses/PolyForm-Small-Business-1.0.0.md)
|
|
13
|
+
|
|
14
|
+
- **PolyForm Free Trial 1.0.0** — a 32-day evaluation for anyone else.
|
|
15
|
+
See [licenses/PolyForm-Free-Trial-1.0.0.md](licenses/PolyForm-Free-Trial-1.0.0.md)
|
|
16
|
+
|
|
17
|
+
For commercial use beyond these terms, contact [hello@graphy.dev](mailto:hello@graphy.dev) or visit [https://graphy.dev](https://graphy.dev).
|
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# `@graphysdk/data-import-utils`
|
|
2
2
|
|
|
3
|
-
Parse CSV, TSV, and spreadsheet files into the `{ columns, rows }` data shape
|
|
3
|
+
Parse CSV, TSV, JSON, and spreadsheet files into the `{ columns, rows }` data shape used by Graphy agents and chart configs.
|
|
4
|
+
|
|
5
|
+
## Docs
|
|
6
|
+
|
|
7
|
+
- [Data Import overview](https://docs.graphy.dev/data-import-utils)
|
|
8
|
+
- [Examples](https://docs.graphy.dev/data-import-utils/examples)
|
|
9
|
+
- [Agents SDK](https://docs.graphy.dev/agents/sdk/installation) — feed parsed data into `@graphysdk/agents-sdk`
|
|
4
10
|
|
|
5
11
|
## Installation
|
|
6
12
|
|
|
@@ -8,13 +14,7 @@ Parse CSV, TSV, and spreadsheet files into the `{ columns, rows }` data shape ex
|
|
|
8
14
|
pnpm add @graphysdk/data-import-utils
|
|
9
15
|
```
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`@graphysdk/core` is required:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
pnpm add @graphysdk/core
|
|
17
|
-
```
|
|
17
|
+
No npm org token and no `@graphysdk/core` dependency required.
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
@@ -24,7 +24,7 @@ pnpm add @graphysdk/core
|
|
|
24
24
|
import { fromFile } from '@graphysdk/data-import-utils/file';
|
|
25
25
|
|
|
26
26
|
const data = await fromFile('sales.csv');
|
|
27
|
-
const
|
|
27
|
+
const spreadsheet = await fromFile('report.xlsx', { sheet: 'Revenue' });
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
### Parse from a URL
|
|
@@ -33,7 +33,7 @@ const data = await fromFile('report.xlsx', { sheet: 'Revenue' });
|
|
|
33
33
|
import { fromURL } from '@graphysdk/data-import-utils/url';
|
|
34
34
|
|
|
35
35
|
const data = await fromURL('https://example.com/sales.csv');
|
|
36
|
-
const
|
|
36
|
+
const spreadsheet = await fromURL('https://example.com/report.xlsx', { sheet: 'Revenue' });
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
### Format-specific imports
|
|
@@ -48,7 +48,7 @@ import { fromXLS } from '@graphysdk/data-import-utils/xls';
|
|
|
48
48
|
import { fromODS } from '@graphysdk/data-import-utils/ods';
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
### Feeding into
|
|
51
|
+
### Feeding into agents-sdk
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
54
|
import { fromFile } from '@graphysdk/data-import-utils/file';
|
|
@@ -72,7 +72,3 @@ const result = await ai.generateGraph({
|
|
|
72
72
|
| XLSX | `fromXLSX()` | `ArrayBuffer` |
|
|
73
73
|
| XLS | `fromXLS()` | `ArrayBuffer` |
|
|
74
74
|
| ODS | `fromODS()` | `ArrayBuffer` |
|
|
75
|
-
|
|
76
|
-
## Docs
|
|
77
|
-
|
|
78
|
-
Full documentation: [https://docs.graphy.app/data-import-utils](https://docs.graphy.app/data-import-utils)
|
package/dist/buffer.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./parse-string-DpdSP3xh.cjs");exports.fromBuffer=e.fromBuffer;
|
package/dist/buffer.mjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { t as f } from "./parse-string-VVlSsL2Y.js";
|
|
2
|
+
export {
|
|
3
|
+
f as fromBuffer
|
|
4
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=1e5,r=5e6;Object.defineProperty(exports,"DEFAULT_MAX_CELLS",{enumerable:!0,get:function(){return r}});Object.defineProperty(exports,"DEFAULT_MAX_ROWS",{enumerable:!0,get:function(){return e}});
|
package/dist/csv.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./from-csv-Ccr_5k9u.cjs");exports.fromCSV=e.fromCSV;
|
package/dist/csv.mjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { t as r } from "./from-csv-CrQ_H-s5.js";
|
|
2
|
+
export {
|
|
3
|
+
r as fromCSV
|
|
4
|
+
};
|
package/dist/file.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./map-rows-1hzHO_rN.cjs"),t=require("./format-detection-1kqWtVpP.cjs"),u=require("./parse-string-DpdSP3xh.cjs");let d=require("node:fs/promises"),o=require("node:path");o=a.__toESM(o,1);var l=async(n,s)=>{if(typeof window<"u"&&typeof process>"u")throw new Error("fromFile is only available in Node.js environments. In the browser, read the file using the File API and pass the result to fromCSV (for text) or fromXLSX (for binary formats).");const i=o.default.extname(n).toLowerCase(),r=t.formatFromExtension(i);if(!r){const f=Object.keys(t.EXTENSION_MAP).join(", ");throw new Error(`Unsupported file extension "${i||"(none)"}". Supported: ${f}`)}const e=await(0,d.readFile)(n);return u.fromString(t.TEXT_FORMATS.has(r)?typeof e=="string"?e:e.toString("utf-8"):e instanceof Buffer?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,r,s)};exports.fromFile=l;
|
package/dist/file.mjs
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { n as s, r as i, t as a } from "./format-detection-MwlOpP6Y.js";
|
|
2
|
+
import { n as m } from "./parse-string-VVlSsL2Y.js";
|
|
3
|
+
import { readFile as p } from "node:fs/promises";
|
|
4
|
+
import d from "node:path";
|
|
5
|
+
var c = async (o, n) => {
|
|
6
|
+
if (typeof window < "u" && typeof process > "u") throw new Error("fromFile is only available in Node.js environments. In the browser, read the file using the File API and pass the result to fromCSV (for text) or fromXLSX (for binary formats).");
|
|
7
|
+
const t = d.extname(o).toLowerCase(), r = i(t);
|
|
8
|
+
if (!r) {
|
|
9
|
+
const f = Object.keys(a).join(", ");
|
|
10
|
+
throw new Error(`Unsupported file extension "${t || "(none)"}". Supported: ${f}`);
|
|
11
|
+
}
|
|
12
|
+
const e = await p(o);
|
|
13
|
+
return m(s.has(r) ? typeof e == "string" ? e : e.toString("utf-8") : e instanceof Buffer ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e, r, n);
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
c as fromFile
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var r=new Set(["csv","tsv","json"]),e={".csv":"csv",".tsv":"tsv",".tab":"tsv",".json":"json",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},n=t=>e[t.toLowerCase()];Object.defineProperty(exports,"EXTENSION_MAP",{enumerable:!0,get:function(){return e}});Object.defineProperty(exports,"TEXT_FORMATS",{enumerable:!0,get:function(){return r}});Object.defineProperty(exports,"formatFromExtension",{enumerable:!0,get:function(){return n}});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var t = /* @__PURE__ */ new Set([
|
|
2
|
+
"csv",
|
|
3
|
+
"tsv",
|
|
4
|
+
"json"
|
|
5
|
+
]), o = {
|
|
6
|
+
".csv": "csv",
|
|
7
|
+
".tsv": "tsv",
|
|
8
|
+
".tab": "tsv",
|
|
9
|
+
".json": "json",
|
|
10
|
+
".xlsx": "xlsx",
|
|
11
|
+
".xls": "xls",
|
|
12
|
+
".ods": "ods"
|
|
13
|
+
}, v = (s) => o[s.toLowerCase()];
|
|
14
|
+
export {
|
|
15
|
+
t as n,
|
|
16
|
+
v as r,
|
|
17
|
+
o as t
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=require("./parse-delimited-BSoFIVFq.cjs");var i=(e,r)=>t.parseDelimited(e,void 0,r);Object.defineProperty(exports,"fromCSV",{enumerable:!0,get:function(){return i}});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Data, DelimitedParseOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a CSV string into the `Data` shape expected by `generateGraph()`.
|
|
4
|
+
* The delimiter is auto-detected by PapaParse (comma, semicolon, pipe, tab, etc.).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const data = fromCSV('Name,Revenue\nAcme,1000\nGlobex,2000');
|
|
9
|
+
* const data = fromCSV('Name;Revenue\nAcme;1000\nGlobex;2000'); // semicolon-delimited
|
|
10
|
+
* sdk.generateGraph({ config: { data }, userPrompt: 'bar chart' });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const fromCSV: (input: string, options?: DelimitedParseOptions) => Data;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var w = (r, n) => {
|
|
2
|
+
const e = typeof r == "string" ? y(r, n) : r;
|
|
3
|
+
if (Array.isArray(e)) return c(e);
|
|
4
|
+
if (f(e)) return m(e);
|
|
5
|
+
throw new Error("Unsupported JSON dataset: expected an array of row objects or a { columns, rows } object.");
|
|
6
|
+
}, a = (r) => typeof r == "object" && r !== null && !Array.isArray(r), i = (r) => r == null ? null : typeof r == "number" ? Number.isFinite(r) ? r : null : typeof r == "string" ? r : typeof r == "boolean" ? String(r) : JSON.stringify(r), y = (r, n) => {
|
|
7
|
+
const e = n?.maxFileSize ?? 5, o = e * 1024 * 1024, t = new TextEncoder().encode(r).byteLength;
|
|
8
|
+
if (t > o) throw new Error(`Input size (${t} bytes) exceeds the maximum allowed size of ${o} bytes (${e} MB).`);
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(r);
|
|
11
|
+
} catch (s) {
|
|
12
|
+
throw new Error(`Invalid JSON: ${s instanceof Error ? s.message : "could not parse"}`);
|
|
13
|
+
}
|
|
14
|
+
}, c = (r) => {
|
|
15
|
+
const n = [], e = /* @__PURE__ */ new Set();
|
|
16
|
+
for (const o of r) {
|
|
17
|
+
if (!a(o)) throw new Error("Each JSON row must be an object mapping column names to values.");
|
|
18
|
+
for (const t of Object.keys(o)) e.has(t) || (e.add(t), n.push(t));
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
columns: n.map((o) => ({ key: o })),
|
|
22
|
+
rows: r.map((o) => {
|
|
23
|
+
const t = {};
|
|
24
|
+
for (const s of n) t[s] = i(o[s]);
|
|
25
|
+
return t;
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
}, f = (r) => a(r) && Array.isArray(r.columns) && Array.isArray(r.rows), m = (r) => {
|
|
29
|
+
const n = r.columns.map((e) => {
|
|
30
|
+
if (!a(e) || typeof e.key != "string" || e.key.length === 0) throw new Error('Each JSON column must be an object with a non-empty string "key".');
|
|
31
|
+
return e.label !== void 0 ? {
|
|
32
|
+
key: e.key,
|
|
33
|
+
label: String(e.label)
|
|
34
|
+
} : { key: e.key };
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
columns: n,
|
|
38
|
+
rows: r.rows.map((e) => {
|
|
39
|
+
if (!a(e)) throw new Error("Each JSON row must be an object mapping column keys to values.");
|
|
40
|
+
const o = {};
|
|
41
|
+
for (const t of n) o[t.key] = i(e[t.key]);
|
|
42
|
+
return o;
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
w as t
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=(r,n)=>{const e=typeof r=="string"?y(r,n):r;if(Array.isArray(e))return f(e);if(m(e))return w(e);throw new Error("Unsupported JSON dataset: expected an array of row objects or a { columns, rows } object.")},a=r=>typeof r=="object"&&r!==null&&!Array.isArray(r),i=r=>r==null?null:typeof r=="number"?Number.isFinite(r)?r:null:typeof r=="string"?r:typeof r=="boolean"?String(r):JSON.stringify(r),y=(r,n)=>{const e=n?.maxFileSize??5,o=e*1024*1024,t=new TextEncoder().encode(r).byteLength;if(t>o)throw new Error(`Input size (${t} bytes) exceeds the maximum allowed size of ${o} bytes (${e} MB).`);try{return JSON.parse(r)}catch(s){throw new Error(`Invalid JSON: ${s instanceof Error?s.message:"could not parse"}`)}},f=r=>{const n=[],e=new Set;for(const o of r){if(!a(o))throw new Error("Each JSON row must be an object mapping column names to values.");for(const t of Object.keys(o))e.has(t)||(e.add(t),n.push(t))}return{columns:n.map(o=>({key:o})),rows:r.map(o=>{const t={};for(const s of n)t[s]=i(o[s]);return t})}},m=r=>a(r)&&Array.isArray(r.columns)&&Array.isArray(r.rows),w=r=>{const n=r.columns.map(e=>{if(!a(e)||typeof e.key!="string"||e.key.length===0)throw new Error('Each JSON column must be an object with a non-empty string "key".');return e.label!==void 0?{key:e.key,label:String(e.label)}:{key:e.key}});return{columns:n,rows:r.rows.map(e=>{if(!a(e))throw new Error("Each JSON row must be an object mapping column keys to values.");const o={};for(const t of n)o[t.key]=i(e[t.key]);return o})}};Object.defineProperty(exports,"fromJSON",{enumerable:!0,get:function(){return c}});
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/** The `data` shape returned by all parsers — same as `GraphConfig['data']`. */
|
|
4
|
-
type Data = GraphConfig['data'];
|
|
5
|
-
/** Shared base options for all parsers. */
|
|
6
|
-
interface BaseParseOptions {
|
|
7
|
-
/** Locale for number parsing. Determines thousand/decimal separator conventions. @default 'EN_US' */
|
|
8
|
-
locale?: VizLocale;
|
|
9
|
-
/** Maximum allowed input size in megabytes. @default 5 */
|
|
10
|
-
maxFileSize?: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
1
|
+
import { BaseParseOptions, Data } from './types';
|
|
13
2
|
/** A JSON dataset given explicitly as `{ columns, rows }`; the declared column keys drive which fields each row contributes. */
|
|
14
|
-
interface JsonTable {
|
|
3
|
+
export interface JsonTable {
|
|
15
4
|
columns: ReadonlyArray<{
|
|
16
5
|
key: string;
|
|
17
6
|
label?: string;
|
|
@@ -19,7 +8,7 @@ interface JsonTable {
|
|
|
19
8
|
rows: ReadonlyArray<Record<string, unknown>>;
|
|
20
9
|
}
|
|
21
10
|
/** Accepted JSON dataset inputs: a raw JSON string, an array of row objects, or a `{ columns, rows }` table. */
|
|
22
|
-
type JsonInput = string | ReadonlyArray<Record<string, unknown>> | JsonTable;
|
|
11
|
+
export type JsonInput = string | ReadonlyArray<Record<string, unknown>> | JsonTable;
|
|
23
12
|
/**
|
|
24
13
|
* Parses a JSON dataset into the `Data` shape expected by `generateGraph()`. Accepts a raw JSON string, an
|
|
25
14
|
* array of row objects (columns are inferred as the union of keys, in first-seen order), or an explicit
|
|
@@ -33,7 +22,4 @@ type JsonInput = string | ReadonlyArray<Record<string, unknown>> | JsonTable;
|
|
|
33
22
|
* const data = fromJSON({ columns: [{ key: 'category' }], rows: [{ category: 'Q1' }] });
|
|
34
23
|
* ```
|
|
35
24
|
*/
|
|
36
|
-
declare const fromJSON: (input: JsonInput, options?: BaseParseOptions) => Data;
|
|
37
|
-
|
|
38
|
-
export { fromJSON };
|
|
39
|
-
export type { BaseParseOptions, JsonInput, JsonTable };
|
|
25
|
+
export declare const fromJSON: (input: JsonInput, options?: BaseParseOptions) => Data;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { n as y, t as C } from "./map-rows-GOmUltJ3.js";
|
|
2
|
+
import "./constants-PA0Uh9bi.js";
|
|
3
|
+
import b from "exceljs";
|
|
4
|
+
var v = (t) => {
|
|
5
|
+
const { value: e } = t;
|
|
6
|
+
if (e == null) return null;
|
|
7
|
+
if (typeof e == "number") return e;
|
|
8
|
+
if (typeof e == "string") return e === "" ? null : e;
|
|
9
|
+
if (typeof e == "boolean") return e ? 1 : 0;
|
|
10
|
+
if (e instanceof Date) return e.toISOString();
|
|
11
|
+
if (E(e)) {
|
|
12
|
+
if (typeof e.result == "number") return e.result;
|
|
13
|
+
if (typeof e.result == "string") return e.result === "" ? null : e.result;
|
|
14
|
+
if (typeof e.result == "boolean") return e.result ? 1 : 0;
|
|
15
|
+
if (e.result instanceof Date) return e.result.toISOString();
|
|
16
|
+
}
|
|
17
|
+
const r = t.text;
|
|
18
|
+
return r === "" ? null : r;
|
|
19
|
+
}, E = (t) => typeof t == "object" && t !== null && "formula" in t, R = [
|
|
20
|
+
"dataValidations",
|
|
21
|
+
"conditionalFormatting",
|
|
22
|
+
"sheetProtection"
|
|
23
|
+
];
|
|
24
|
+
async function $(t) {
|
|
25
|
+
const e = new b.Workbook();
|
|
26
|
+
return await e.xlsx.load(t, { ignoreNodes: R }), e;
|
|
27
|
+
}
|
|
28
|
+
var _ = (t, e) => f(t, e), A = (t, e) => f(t, e), I = (t, e) => f(t, e), k = (t, e) => {
|
|
29
|
+
if (e === void 0) return t.worksheets[0];
|
|
30
|
+
if (typeof e == "number") {
|
|
31
|
+
const n = t.worksheets[e];
|
|
32
|
+
if (!n) throw new Error(`Sheet index ${e} is out of range. Workbook has ${t.worksheets.length} sheet(s).`);
|
|
33
|
+
return n;
|
|
34
|
+
}
|
|
35
|
+
const r = t.getWorksheet(e);
|
|
36
|
+
if (!r) {
|
|
37
|
+
const n = t.worksheets.map((a) => `"${a.name}"`).join(", ");
|
|
38
|
+
throw new Error(`Sheet "${e}" not found. Available sheets: ${n}`);
|
|
39
|
+
}
|
|
40
|
+
return r;
|
|
41
|
+
}, f = async (t, e) => {
|
|
42
|
+
const r = (e?.maxFileSize ?? 5) * 1024 * 1024;
|
|
43
|
+
if (t.byteLength > r) throw new Error(`Input size (${t.byteLength} bytes) exceeds the maximum allowed size of ${r} bytes (${e?.maxFileSize ?? 5} MB).`);
|
|
44
|
+
const n = e?.locale ?? "EN_US", a = await $(t), s = k(a, e?.sheet);
|
|
45
|
+
if (!s || s.rowCount === 0) return {
|
|
46
|
+
columns: [],
|
|
47
|
+
rows: []
|
|
48
|
+
};
|
|
49
|
+
const l = s.columnCount;
|
|
50
|
+
if (l === 0) return {
|
|
51
|
+
columns: [],
|
|
52
|
+
rows: []
|
|
53
|
+
};
|
|
54
|
+
const g = s.getRow(1), w = [];
|
|
55
|
+
for (let o = 1; o <= l; o++) {
|
|
56
|
+
const m = g.getCell(o).value;
|
|
57
|
+
w.push(String(m ?? ""));
|
|
58
|
+
}
|
|
59
|
+
const h = y(w, l), x = e?.maxRows ?? 1e5, d = e?.maxCells ?? 5e6, S = [];
|
|
60
|
+
let i = 0, u = 0;
|
|
61
|
+
for (let o = 2; o <= s.rowCount; o++) {
|
|
62
|
+
if (i++, i > x) throw new Error(`Row limit exceeded: processed ${i} rows (maximum: ${x}). Use the maxRows option to increase the limit.`);
|
|
63
|
+
if (u += l, u > d) throw new Error(`Cell limit exceeded: processed ${u} cells (maximum: ${d}). Use the maxCells option to increase the limit.`);
|
|
64
|
+
const m = s.getRow(o), p = [];
|
|
65
|
+
for (let c = 1; c <= l; c++) p.push(v(m.getCell(c)));
|
|
66
|
+
S.push(p);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
columns: h,
|
|
70
|
+
rows: C(S, h, n)
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export {
|
|
74
|
+
v as a,
|
|
75
|
+
$ as i,
|
|
76
|
+
A as n,
|
|
77
|
+
_ as r,
|
|
78
|
+
I as t
|
|
79
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const m=require("./map-rows-1hzHO_rN.cjs"),P=require("./constants-BSk6SyUk.cjs");let w=require("exceljs");w=m.__toESM(w,1);var p=t=>{const{value:e}=t;if(e==null)return null;if(typeof e=="number")return e;if(typeof e=="string")return e===""?null:e;if(typeof e=="boolean")return e?1:0;if(e instanceof Date)return e.toISOString();if($(e)){if(typeof e.result=="number")return e.result;if(typeof e.result=="string")return e.result===""?null:e.result;if(typeof e.result=="boolean")return e.result?1:0;if(e.result instanceof Date)return e.result.toISOString()}const r=t.text;return r===""?null:r},$=t=>typeof t=="object"&&t!==null&&"formula"in t,k=["dataValidations","conditionalFormatting","sheetProtection"];async function C(t){const e=new w.default.Workbook;return await e.xlsx.load(t,{ignoreNodes:k}),e}var O=(t,e)=>d(t,e),R=(t,e)=>d(t,e),E=(t,e)=>d(t,e),j=(t,e)=>{if(e===void 0)return t.worksheets[0];if(typeof e=="number"){const n=t.worksheets[e];if(!n)throw new Error(`Sheet index ${e} is out of range. Workbook has ${t.worksheets.length} sheet(s).`);return n}const r=t.getWorksheet(e);if(!r){const n=t.worksheets.map(u=>`"${u.name}"`).join(", ");throw new Error(`Sheet "${e}" not found. Available sheets: ${n}`)}return r},d=async(t,e)=>{const r=(e?.maxFileSize??5)*1024*1024;if(t.byteLength>r)throw new Error(`Input size (${t.byteLength} bytes) exceeds the maximum allowed size of ${r} bytes (${e?.maxFileSize??5} MB).`);const n=e?.locale??"EN_US",u=await C(t),s=j(u,e?.sheet);if(!s||s.rowCount===0)return{columns:[],rows:[]};const l=s.columnCount;if(l===0)return{columns:[],rows:[]};const v=s.getRow(1),h=[];for(let o=1;o<=l;o++){const c=v.getCell(o).value;h.push(String(c??""))}const x=m.buildColumns(h,l),b=e?.maxRows??1e5,g=e?.maxCells??5e6,y=[];let i=0,a=0;for(let o=2;o<=s.rowCount;o++){if(i++,i>b)throw new Error(`Row limit exceeded: processed ${i} rows (maximum: ${b}). Use the maxRows option to increase the limit.`);if(a+=l,a>g)throw new Error(`Cell limit exceeded: processed ${a} cells (maximum: ${g}). Use the maxCells option to increase the limit.`);const c=s.getRow(o),S=[];for(let f=1;f<=l;f++)S.push(p(c.getCell(f)));y.push(S)}return{columns:x,rows:m.mapRows(y,x,n)}};Object.defineProperty(exports,"extractCellPrimitive",{enumerable:!0,get:function(){return p}});Object.defineProperty(exports,"fromODS",{enumerable:!0,get:function(){return E}});Object.defineProperty(exports,"fromXLS",{enumerable:!0,get:function(){return R}});Object.defineProperty(exports,"fromXLSX",{enumerable:!0,get:function(){return O}});Object.defineProperty(exports,"loadWorkbookFromXlsxBuffer",{enumerable:!0,get:function(){return C}});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Data, SpreadsheetParseOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parses an XLSX file into the `Data` shape expected by `generateGraph()`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const fromXLSX: (input: ArrayBuffer, options?: SpreadsheetParseOptions) => Promise<Data>;
|
|
6
|
+
/**
|
|
7
|
+
* Parses an XLS file into the `Data` shape expected by `generateGraph()`.
|
|
8
|
+
*
|
|
9
|
+
* **Note:** Uses ExcelJS which natively supports XLSX format. Modern `.xls` files
|
|
10
|
+
* (produced by Excel 2007+) that are actually XLSX will parse correctly.
|
|
11
|
+
* Genuine legacy binary XLS (BIFF) files are not supported.
|
|
12
|
+
*/
|
|
13
|
+
export declare const fromXLS: (input: ArrayBuffer, options?: SpreadsheetParseOptions) => Promise<Data>;
|
|
14
|
+
/**
|
|
15
|
+
* Parses an ODS (OpenDocument Spreadsheet) file into the `Data` shape expected by `generateGraph()`.
|
|
16
|
+
*
|
|
17
|
+
* **Note:** Uses ExcelJS which natively supports XLSX format. ODS files that are
|
|
18
|
+
* saved in XLSX-compatible format will parse correctly. Native ODS format is not supported.
|
|
19
|
+
*/
|
|
20
|
+
export declare const fromODS: (input: ArrayBuffer, options?: SpreadsheetParseOptions) => Promise<Data>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=require("./parse-delimited-BSoFIVFq.cjs");var i=(e,r)=>t.parseDelimited(e," ",r);Object.defineProperty(exports,"fromTSV",{enumerable:!0,get:function(){return i}});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Data, DelimitedParseOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a TSV string into the `Data` shape expected by `generateGraph()`.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const data = fromTSV('Name\tRevenue\nAcme\t1000');
|
|
8
|
+
* sdk.generateGraph({ config: { data }, userPrompt: 'bar chart' });
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const fromTSV: (input: string, options?: DelimitedParseOptions) => Data;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { fromXLSX } from './from-spreadsheet';
|
|
2
|
+
export { extractCellPrimitive } from './spreadsheet/cell-primitive';
|
|
3
|
+
export { loadWorkbookFromXlsxBuffer } from './spreadsheet/load-workbook';
|
|
4
|
+
export type { ReadSheetRegionOptions, ReadSheetRegionResult } from './spreadsheet/read-region';
|
|
5
|
+
export { DEFAULT_READ_REGION_MAX_CELLS, readIslandRegion, readSheetRegion } from './spreadsheet/read-region';
|
|
6
|
+
export type { BuildWorkbookIndexOptions, IslandEntry, SheetIndexEntry, WorkbookIndex, } from './spreadsheet/workbook-index';
|
|
7
|
+
export { buildWorkbookIndex, buildWorkbookIndexFromXlsxBuffer, DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS, WORKBOOK_INDEX_SCHEMA_VERSION, } from './spreadsheet/workbook-index';
|
|
8
|
+
export type { BaseParseOptions, SpreadsheetParseOptions } from './types';
|
package/dist/index.cjs
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,44 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
/** Binary formats that accept ArrayBuffer input. */
|
|
10
|
-
type BinaryFileFormat = 'xlsx' | 'xls' | 'ods';
|
|
11
|
-
/** Shared base options for all parsers. */
|
|
12
|
-
interface BaseParseOptions {
|
|
13
|
-
/** Locale for number parsing. Determines thousand/decimal separator conventions. @default 'EN_US' */
|
|
14
|
-
locale?: VizLocale;
|
|
15
|
-
/** Maximum allowed input size in megabytes. @default 5 */
|
|
16
|
-
maxFileSize?: number;
|
|
17
|
-
}
|
|
18
|
-
/** Options for CSV / TSV parsing. */
|
|
19
|
-
interface DelimitedParseOptions extends BaseParseOptions {
|
|
20
|
-
/** Whether the first row contains column headers. @default true */
|
|
21
|
-
hasHeader?: boolean;
|
|
22
|
-
}
|
|
23
|
-
/** Options for XLSX / XLS / ODS parsing. */
|
|
24
|
-
interface SpreadsheetParseOptions extends BaseParseOptions {
|
|
25
|
-
/** Sheet to parse — name (string) or 0-based index (number). @default 0 (first sheet) */
|
|
26
|
-
sheet?: string | number;
|
|
27
|
-
/** Maximum number of data rows to process. @default 100_000 */
|
|
28
|
-
maxRows?: number;
|
|
29
|
-
/** Maximum total cells to process. @default 5_000_000 */
|
|
30
|
-
maxCells?: number;
|
|
31
|
-
}
|
|
32
|
-
/** Options specific to URL fetching. */
|
|
33
|
-
interface URLParseOptions extends SpreadsheetParseOptions {
|
|
34
|
-
/** Custom headers to include in the fetch request. */
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
/** Whether the first row contains column headers. @default true */
|
|
37
|
-
hasHeader?: boolean;
|
|
38
|
-
/** Fetch timeout in milliseconds. @default 30_000 */
|
|
39
|
-
timeout?: number;
|
|
40
|
-
/** Optional external abort signal for cancellation. */
|
|
41
|
-
signal?: AbortSignal;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type { BaseParseOptions, BinaryFileFormat, Data, DelimitedParseOptions, FileFormat, SpreadsheetParseOptions, TextFileFormat, URLParseOptions };
|
|
1
|
+
/**
|
|
2
|
+
* Root entrypoint exports lightweight CSV/TSV parsers.
|
|
3
|
+
* For spreadsheet formats (XLSX, XLS, ODS), use format-specific sub-path imports:
|
|
4
|
+
* - `@graphysdk/data-import-utils/xlsx`
|
|
5
|
+
* - `@graphysdk/data-import-utils/file`
|
|
6
|
+
* - `@graphysdk/data-import-utils/url`
|
|
7
|
+
*/
|
|
8
|
+
export type { BaseParseOptions, BinaryFileFormat, Data, DelimitedParseOptions, FileFormat, SpreadsheetParseOptions, TextFileFormat, URLParseOptions, } from './types';
|
package/dist/index.mjs
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/json.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./from-json-lzRNXlod.cjs");exports.fromJSON=e.fromJSON;
|
package/dist/json.mjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { t as r } from "./from-json-DC712HdK.js";
|
|
2
|
+
export {
|
|
3
|
+
r as fromJSON
|
|
4
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var s=Object.create,i=Object.defineProperty,p=Object.getOwnPropertyDescriptor,b=Object.getOwnPropertyNames,f=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,v=(r,n,e,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(var t=b(n),a=0,o=t.length,l;a<o;a++)l=t[a],!_.call(r,l)&&l!==e&&i(r,l,{get:(c=>n[c]).bind(null,l),enumerable:!(u=p(n,l))||u.enumerable});return r},g=(r,n,e)=>(e=r!=null?s(f(r)):{},v(n||!r||!r.__esModule?i(e,"default",{value:r,enumerable:!0}):e,r)),d=r=>`c${r+1}`,O=(r,n)=>{const e=[];for(let u=0;u<n;u++){const t=r?.[u]?.trim(),a={key:d(u)};t&&(a.label=t),e.push(a)}return e},m=100,P=/[^\p{ASCII}]/u,y=/[\u2012\u2013\u2014\u2212](?=\d)/g,N=/\u00A0/g,j=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,R=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,E=new Set(["PT_PT","AR"]),h=(r,n="EN_US")=>{let e;if(P.test(r)?e=r.replace(y,"-").replace(N," ").trim():e=r.trim(),e==="")return null;if(e.length>m)return e;if(E.has(n)){if(R.test(e)){const u=e.replace(/\./g,"").replace(",","."),t=Number(u);if(Number.isFinite(t))return t}}else if(j.test(e)){const u=e.replace(/,/g,""),t=Number(u);if(Number.isFinite(t))return t}return e},w=(r,n,e)=>r.map(u=>{const t={};for(let a=0;a<n.length;a++){const o=n[a];if(!o)continue;const l=u[a];l==null||l===""?t[o.key]=null:typeof l=="number"?t[o.key]=l:t[o.key]=h(String(l),e)}return t});Object.defineProperty(exports,"__toESM",{enumerable:!0,get:function(){return g}});Object.defineProperty(exports,"buildColumns",{enumerable:!0,get:function(){return O}});Object.defineProperty(exports,"mapRows",{enumerable:!0,get:function(){return w}});
|