@graphysdk/data-import-utils 1.8.0 → 1.8.1-beta.1786025839240

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.
Files changed (84) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +11 -15
  3. package/dist/buffer.cjs +1 -1
  4. package/dist/buffer.mjs +4 -1
  5. package/dist/constants-BSk6SyUk.cjs +1 -0
  6. package/dist/constants-PA0Uh9bi.js +5 -0
  7. package/dist/csv.cjs +1 -1
  8. package/dist/csv.mjs +4 -1
  9. package/dist/file.cjs +1 -1
  10. package/dist/file.mjs +17 -1
  11. package/dist/format-detection-1kqWtVpP.cjs +1 -0
  12. package/dist/format-detection-MwlOpP6Y.js +18 -0
  13. package/dist/from-csv-Ccr_5k9u.cjs +1 -0
  14. package/dist/from-csv-CrQ_H-s5.js +5 -0
  15. package/dist/from-csv.d.ts +13 -0
  16. package/dist/from-json-DC712HdK.js +48 -0
  17. package/dist/from-json-lzRNXlod.cjs +1 -0
  18. package/dist/{json.d.ts → from-json.d.ts} +4 -18
  19. package/dist/from-spreadsheet-D2kWRyr3.js +79 -0
  20. package/dist/from-spreadsheet-EfBhqj2z.cjs +1 -0
  21. package/dist/from-spreadsheet.d.ts +20 -0
  22. package/dist/from-tsv-B02B59Ey.cjs +1 -0
  23. package/dist/from-tsv-CPj6UzXC.js +5 -0
  24. package/dist/from-tsv.d.ts +11 -0
  25. package/dist/index-buffer.d.ts +2 -0
  26. package/dist/index-csv.d.ts +2 -0
  27. package/dist/index-file.d.ts +2 -0
  28. package/dist/index-json.d.ts +3 -0
  29. package/dist/index-ods.d.ts +2 -0
  30. package/dist/index-text.d.ts +2 -0
  31. package/dist/index-tsv.d.ts +2 -0
  32. package/dist/index-url.d.ts +2 -0
  33. package/dist/index-xls.d.ts +2 -0
  34. package/dist/index-xlsx.d.ts +8 -0
  35. package/dist/index.cjs +0 -1
  36. package/dist/index.d.ts +8 -44
  37. package/dist/index.mjs +0 -1
  38. package/dist/json.cjs +1 -1
  39. package/dist/json.mjs +4 -1
  40. package/dist/map-rows-1hzHO_rN.cjs +1 -0
  41. package/dist/map-rows-GOmUltJ3.js +35 -0
  42. package/dist/ods.cjs +1 -1
  43. package/dist/ods.mjs +4 -1
  44. package/dist/parse-delimited-BSoFIVFq.cjs +1 -0
  45. package/dist/parse-delimited-qsjX5KAa.js +28 -0
  46. package/dist/parse-delimited.d.ts +7 -0
  47. package/dist/parse-file.d.ts +12 -0
  48. package/dist/parse-string-DpdSP3xh.cjs +1 -0
  49. package/dist/parse-string-VVlSsL2Y.js +47 -0
  50. package/dist/parse-string.d.ts +29 -0
  51. package/dist/parse-url.d.ts +14 -0
  52. package/dist/spreadsheet/cell-primitive.d.ts +7 -0
  53. package/dist/spreadsheet/load-workbook.d.ts +3 -0
  54. package/dist/spreadsheet/read-region.d.ts +39 -0
  55. package/dist/spreadsheet/workbook-index.d.ts +50 -0
  56. package/dist/text.cjs +1 -1
  57. package/dist/text.mjs +4 -1
  58. package/dist/tsv.cjs +1 -1
  59. package/dist/tsv.mjs +4 -1
  60. package/dist/{url.d.ts → types.d.ts} +18 -24
  61. package/dist/url.cjs +1 -1
  62. package/dist/url.mjs +87 -1
  63. package/dist/utils/build-columns.d.ts +10 -0
  64. package/dist/utils/column-index-to-property-key.d.ts +2 -0
  65. package/dist/utils/constants.d.ts +6 -0
  66. package/dist/utils/format-detection.d.ts +4 -0
  67. package/dist/utils/map-rows.d.ts +13 -0
  68. package/dist/utils/normalize-value.d.ts +12 -0
  69. package/dist/utils/url-validation.d.ts +2 -0
  70. package/dist/wire-data.types.d.ts +13 -0
  71. package/dist/xls.cjs +1 -1
  72. package/dist/xls.mjs +4 -1
  73. package/dist/xlsx.cjs +1 -1
  74. package/dist/xlsx.mjs +172 -1
  75. package/package.json +52 -38
  76. package/dist/README.md +0 -78
  77. package/dist/buffer.d.ts +0 -36
  78. package/dist/csv.d.ts +0 -32
  79. package/dist/file.d.ts +0 -42
  80. package/dist/ods.d.ts +0 -31
  81. package/dist/text.d.ts +0 -32
  82. package/dist/tsv.d.ts +0 -30
  83. package/dist/xls.d.ts +0 -32
  84. package/dist/xlsx.d.ts +0 -127
package/dist/file.d.ts DELETED
@@ -1,42 +0,0 @@
1
- import { VizLocale, GraphConfig } from '@graphysdk/core/node';
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
- /** Options for CSV / TSV parsing. */
13
- interface DelimitedParseOptions extends BaseParseOptions {
14
- /** Whether the first row contains column headers. @default true */
15
- hasHeader?: boolean;
16
- }
17
- /** Options for XLSX / XLS / ODS parsing. */
18
- interface SpreadsheetParseOptions extends BaseParseOptions {
19
- /** Sheet to parse — name (string) or 0-based index (number). @default 0 (first sheet) */
20
- sheet?: string | number;
21
- /** Maximum number of data rows to process. @default 100_000 */
22
- maxRows?: number;
23
- /** Maximum total cells to process. @default 5_000_000 */
24
- maxCells?: number;
25
- }
26
- /** Options for `fromFile` — covers both delimited and spreadsheet formats. */
27
- type FileParseOptions = SpreadsheetParseOptions & Pick<DelimitedParseOptions, 'hasHeader'>;
28
-
29
- /**
30
- * Reads a file from disk and parses it into the `Data` shape expected by
31
- * `generateGraph()`. The format is auto-detected from the file extension.
32
- *
33
- * @example
34
- * ```ts
35
- * const data = await fromFile('sales.csv');
36
- * const data = await fromFile('report.xlsx', { sheet: 'Revenue' });
37
- * ```
38
- */
39
- declare const fromFile: (filePath: string, options?: FileParseOptions) => Promise<Data>;
40
-
41
- export { fromFile };
42
- export type { BaseParseOptions, Data, FileParseOptions, SpreadsheetParseOptions };
package/dist/ods.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import { VizLocale, GraphConfig } from '@graphysdk/core/node';
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
- /** Options for XLSX / XLS / ODS parsing. */
13
- interface SpreadsheetParseOptions extends BaseParseOptions {
14
- /** Sheet to parse — name (string) or 0-based index (number). @default 0 (first sheet) */
15
- sheet?: string | number;
16
- /** Maximum number of data rows to process. @default 100_000 */
17
- maxRows?: number;
18
- /** Maximum total cells to process. @default 5_000_000 */
19
- maxCells?: number;
20
- }
21
-
22
- /**
23
- * Parses an ODS (OpenDocument Spreadsheet) file into the `Data` shape expected by `generateGraph()`.
24
- *
25
- * **Note:** Uses ExcelJS which natively supports XLSX format. ODS files that are
26
- * saved in XLSX-compatible format will parse correctly. Native ODS format is not supported.
27
- */
28
- declare const fromODS: (input: ArrayBuffer, options?: SpreadsheetParseOptions) => Promise<Data>;
29
-
30
- export { fromODS };
31
- export type { BaseParseOptions, SpreadsheetParseOptions };
package/dist/text.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { VizLocale, GraphConfig } from '@graphysdk/core/node';
2
-
3
- /** The `data` shape returned by all parsers — same as `GraphConfig['data']`. */
4
- type Data = GraphConfig['data'];
5
- /** Text-based formats that accept string input. */
6
- type TextFileFormat = 'csv' | 'tsv' | 'json';
7
- /** Shared base options for all parsers. */
8
- interface BaseParseOptions {
9
- /** Locale for number parsing. Determines thousand/decimal separator conventions. @default 'EN_US' */
10
- locale?: VizLocale;
11
- /** Maximum allowed input size in megabytes. @default 5 */
12
- maxFileSize?: number;
13
- }
14
- /** Options for CSV / TSV parsing. */
15
- interface DelimitedParseOptions extends BaseParseOptions {
16
- /** Whether the first row contains column headers. @default true */
17
- hasHeader?: boolean;
18
- }
19
-
20
- /**
21
- * Parses a text string (CSV or TSV) into the `Data` shape expected by `generateGraph()`.
22
- *
23
- * @example
24
- * ```ts
25
- * const data = fromText(csvContent, 'csv');
26
- * const data = fromText(tsvContent, 'tsv', { hasHeader: false });
27
- * ```
28
- */
29
- declare const fromText: (input: string, format: TextFileFormat, options?: DelimitedParseOptions) => Data;
30
-
31
- export { fromText };
32
- export type { BaseParseOptions, Data, DelimitedParseOptions, TextFileFormat };
package/dist/tsv.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { VizLocale, GraphConfig } from '@graphysdk/core/node';
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
- /** Options for CSV / TSV parsing. */
13
- interface DelimitedParseOptions extends BaseParseOptions {
14
- /** Whether the first row contains column headers. @default true */
15
- hasHeader?: boolean;
16
- }
17
-
18
- /**
19
- * Parses a TSV string into the `Data` shape expected by `generateGraph()`.
20
- *
21
- * @example
22
- * ```ts
23
- * const data = fromTSV('Name\tRevenue\nAcme\t1000');
24
- * sdk.generateGraph({ config: { data }, userPrompt: 'bar chart' });
25
- * ```
26
- */
27
- declare const fromTSV: (input: string, options?: DelimitedParseOptions) => Data;
28
-
29
- export { fromTSV };
30
- export type { BaseParseOptions, DelimitedParseOptions };
package/dist/xls.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { VizLocale, GraphConfig } from '@graphysdk/core/node';
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
- /** Options for XLSX / XLS / ODS parsing. */
13
- interface SpreadsheetParseOptions extends BaseParseOptions {
14
- /** Sheet to parse — name (string) or 0-based index (number). @default 0 (first sheet) */
15
- sheet?: string | number;
16
- /** Maximum number of data rows to process. @default 100_000 */
17
- maxRows?: number;
18
- /** Maximum total cells to process. @default 5_000_000 */
19
- maxCells?: number;
20
- }
21
-
22
- /**
23
- * Parses an XLS file into the `Data` shape expected by `generateGraph()`.
24
- *
25
- * **Note:** Uses ExcelJS which natively supports XLSX format. Modern `.xls` files
26
- * (produced by Excel 2007+) that are actually XLSX will parse correctly.
27
- * Genuine legacy binary XLS (BIFF) files are not supported.
28
- */
29
- declare const fromXLS: (input: ArrayBuffer, options?: SpreadsheetParseOptions) => Promise<Data>;
30
-
31
- export { fromXLS };
32
- export type { BaseParseOptions, SpreadsheetParseOptions };
package/dist/xlsx.d.ts DELETED
@@ -1,127 +0,0 @@
1
- import { VizLocale, GraphConfig } from '@graphysdk/core/node';
2
- import ExcelJS from 'exceljs';
3
-
4
- /** The `data` shape returned by all parsers — same as `GraphConfig['data']`. */
5
- type Data = GraphConfig['data'];
6
- /** Shared base options for all parsers. */
7
- interface BaseParseOptions {
8
- /** Locale for number parsing. Determines thousand/decimal separator conventions. @default 'EN_US' */
9
- locale?: VizLocale;
10
- /** Maximum allowed input size in megabytes. @default 5 */
11
- maxFileSize?: number;
12
- }
13
- /** Options for XLSX / XLS / ODS parsing. */
14
- interface SpreadsheetParseOptions extends BaseParseOptions {
15
- /** Sheet to parse — name (string) or 0-based index (number). @default 0 (first sheet) */
16
- sheet?: string | number;
17
- /** Maximum number of data rows to process. @default 100_000 */
18
- maxRows?: number;
19
- /** Maximum total cells to process. @default 5_000_000 */
20
- maxCells?: number;
21
- }
22
-
23
- /**
24
- * Parses an XLSX file into the `Data` shape expected by `generateGraph()`.
25
- */
26
- declare const fromXLSX: (input: ArrayBuffer, options?: SpreadsheetParseOptions) => Promise<Data>;
27
-
28
- /**
29
- * Extracts a primitive value (`string | number | null`) from an ExcelJS cell.
30
- * Handles numbers, strings, booleans, dates, formulas, rich text, hyperlinks, and errors.
31
- * Shared by chart-oriented parsing (`fromXLSX`) and extract-oriented region reads.
32
- */
33
- declare const extractCellPrimitive: (cell: ExcelJS.Cell) => string | number | null;
34
-
35
- /** Loads an OOXML `.xlsx` buffer into an ExcelJS workbook (single-file extract pipeline). */
36
- declare function loadWorkbookFromXlsxBuffer(input: ArrayBuffer): Promise<ExcelJS.Workbook>;
37
-
38
- /** Bump when island rules or index shape changes (extract API stability). */
39
- declare const WORKBOOK_INDEX_SCHEMA_VERSION: 1;
40
- /** Default cap on total non-empty cells indexed across the workbook (aligns with {@link DEFAULT_MAX_CELLS}). */
41
- declare const DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS = 5000000;
42
- interface BuildWorkbookIndexOptions {
43
- /**
44
- * Abort if the workbook would exceed this many non-empty cells in total (memory / DoS guard).
45
- * @default {@link DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS}
46
- */
47
- maxNonEmptyCells?: number;
48
- }
49
- interface SheetIndexEntry {
50
- sheetName: string;
51
- /** 0-based order in the workbook. */
52
- sheetIndex: number;
53
- /** Inclusive 1-based Excel row/column indices; `null` when the sheet has no data cells. */
54
- rowMin: number | null;
55
- rowMax: number | null;
56
- colMin: number | null;
57
- colMax: number | null;
58
- nonEmptyCellCount: number;
59
- }
60
- interface IslandEntry {
61
- /**
62
- * Stable within a single file: `${sheetIndex}:${islandOrdinalOnSheet}`.
63
- * Consumers prefix with request-level `fileIndex` for multi-file UX.
64
- */
65
- localId: string;
66
- sheetIndex: number;
67
- sheetName: string;
68
- rowMin: number;
69
- rowMax: number;
70
- colMin: number;
71
- colMax: number;
72
- /** Number of non-empty cells in this island (4-connected region). */
73
- cellCount: number;
74
- }
75
- interface WorkbookIndex {
76
- schemaVersion: typeof WORKBOOK_INDEX_SCHEMA_VERSION;
77
- sheets: SheetIndexEntry[];
78
- islands: IslandEntry[];
79
- }
80
- /**
81
- * Deterministic structural index for one loaded workbook: per-sheet used bounds and
82
- * 4-connected **islands** of non-empty cells (using the same empty rules as {@link extractCellPrimitive}).
83
- */
84
- declare function buildWorkbookIndex(workbook: ExcelJS.Workbook, options?: BuildWorkbookIndexOptions): WorkbookIndex;
85
- /** Loads an `.xlsx` buffer and returns its structural index (no retained workbook handle). */
86
- declare function buildWorkbookIndexFromXlsxBuffer(input: ArrayBuffer, options?: BuildWorkbookIndexOptions): Promise<WorkbookIndex>;
87
-
88
- /** Default max cells returned by {@link readSheetRegion} (row-major fill). */
89
- declare const DEFAULT_READ_REGION_MAX_CELLS = 50000;
90
- interface ReadSheetRegionOptions {
91
- /** Stop after this many cells (complete rows only — no partial trailing row). @default {@link DEFAULT_READ_REGION_MAX_CELLS} */
92
- maxCells?: number;
93
- }
94
- interface ReadSheetRegionResult {
95
- sheetIndex: number;
96
- sheetName: string;
97
- /**
98
- * Inclusive 1-based Excel row for the first row in {@link rows} (always the requested `rowMin`).
99
- */
100
- rowMin: number;
101
- /**
102
- * Inclusive 1-based Excel row for the last row in {@link rows} (`rowMin + rows.length - 1`).
103
- * When {@link truncated} is false, this equals the requested `rowMax`.
104
- */
105
- rowMax: number;
106
- colMin: number;
107
- colMax: number;
108
- /** Row-major grid aligned to Excel indices; `rows[i]` is Excel row `rowMin + i`. */
109
- rows: Array<Array<string | number | null>>;
110
- truncated: boolean;
111
- returnedCellCount: number;
112
- }
113
- /**
114
- * Reads a rectangular region (1-based inclusive Excel row/column indices) using the same cell rules as {@link extractCellPrimitive}.
115
- * Enforces {@link ReadSheetRegionOptions.maxCells}; when exceeded, returns complete rows only and sets `truncated`.
116
- */
117
- declare function readSheetRegion(workbook: ExcelJS.Workbook, sheetIndex: number, bounds: {
118
- rowMin: number;
119
- rowMax: number;
120
- colMin: number;
121
- colMax: number;
122
- }, options?: ReadSheetRegionOptions): ReadSheetRegionResult;
123
- /** Reads exactly the bounding box of an island entry from {@link buildWorkbookIndex}. */
124
- declare function readIslandRegion(workbook: ExcelJS.Workbook, island: IslandEntry, options?: ReadSheetRegionOptions): ReadSheetRegionResult;
125
-
126
- export { DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS, DEFAULT_READ_REGION_MAX_CELLS, WORKBOOK_INDEX_SCHEMA_VERSION, buildWorkbookIndex, buildWorkbookIndexFromXlsxBuffer, extractCellPrimitive, fromXLSX, loadWorkbookFromXlsxBuffer, readIslandRegion, readSheetRegion };
127
- export type { BaseParseOptions, BuildWorkbookIndexOptions, IslandEntry, ReadSheetRegionOptions, ReadSheetRegionResult, SheetIndexEntry, SpreadsheetParseOptions, WorkbookIndex };