@vuu-ui/vuu-table-extras 3.3.10 → 3.3.11

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.3.10",
2
+ "version": "3.3.11",
3
3
  "author": "heswell",
4
4
  "main": "./src/index.js",
5
5
  "license": "Apache-2.0",
@@ -11,19 +11,19 @@
11
11
  "lezer-generate:column": "lezer-generator --output ./src/column-expression-input/column-language-parser/generated/column-parser.js ./src/column-expression-input/column-language-parser/grammar/column.grammar"
12
12
  },
13
13
  "devDependencies": {
14
- "@vuu-ui/vuu-filter-types": "3.3.10",
15
- "@vuu-ui/vuu-protocol-types": "3.3.10"
14
+ "@vuu-ui/vuu-filter-types": "3.3.11",
15
+ "@vuu-ui/vuu-protocol-types": "3.3.11"
16
16
  },
17
17
  "dependencies": {
18
- "@vuu-ui/vuu-codemirror": "3.3.10",
19
- "@vuu-ui/vuu-data-editing": "3.3.10",
20
- "@vuu-ui/vuu-data-react": "3.3.10",
21
- "@vuu-ui/vuu-data-types": "3.3.10",
22
- "@vuu-ui/vuu-table-types": "3.3.10",
23
- "@vuu-ui/vuu-popups": "3.3.10",
24
- "@vuu-ui/vuu-table": "3.3.10",
25
- "@vuu-ui/vuu-utils": "3.3.10",
26
- "@vuu-ui/vuu-ui-controls": "3.3.10",
18
+ "@vuu-ui/vuu-codemirror": "3.3.11",
19
+ "@vuu-ui/vuu-data-editing": "3.3.11",
20
+ "@vuu-ui/vuu-data-react": "3.3.11",
21
+ "@vuu-ui/vuu-data-types": "3.3.11",
22
+ "@vuu-ui/vuu-table-types": "3.3.11",
23
+ "@vuu-ui/vuu-popups": "3.3.11",
24
+ "@vuu-ui/vuu-table": "3.3.11",
25
+ "@vuu-ui/vuu-utils": "3.3.11",
26
+ "@vuu-ui/vuu-ui-controls": "3.3.11",
27
27
  "@lezer/lr": "1.4.2",
28
28
  "@salt-ds/core": "1.54.1",
29
29
  "@salt-ds/lab": "1.0.0-alpha.83",
@@ -1,5 +1,5 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { Button, Dialog, DialogActions, DialogContent, DialogHeader, FileDropZone, FileDropZoneIcon, FileDropZoneTrigger } from "@salt-ds/core";
2
+ import { Button, Dialog, DialogActions, DialogContent, DialogHeader, FileDropZone, FileDropZoneIcon, FileDropZoneTrigger, Text } from "@salt-ds/core";
3
3
  import { useComponentCssInjection } from "@salt-ds/styles";
4
4
  import { useWindow } from "@salt-ds/window";
5
5
  import { useCallback, useState } from "react";
@@ -20,7 +20,8 @@ const CsvUpload_CsvUpload = (props)=>{
20
20
  const { canImport, cancelImport, isProcessingFile, isImporting, importData, onDrop, onTriggerChange, schema, validation, error } = useCsvUpload(props);
21
21
  const fileErrors = validation?.errors.filter((e)=>e.column in validation.errorMap.fileErrors) ?? [];
22
22
  const hasErrors = !!error || validation && validation.errors.length > 0;
23
- const status = hasErrors ? "error" : validation ? "success" : void 0;
23
+ const isUploaded = canImport || isImporting;
24
+ const status = hasErrors ? "error" : isUploaded ? "success" : void 0;
24
25
  const handleCancel = useCallback(async ()=>{
25
26
  await cancelImport();
26
27
  if (!isControlledOpen) setInternalOpen(false);
@@ -39,39 +40,55 @@ const CsvUpload_CsvUpload = (props)=>{
39
40
  const content = /*#__PURE__*/ jsxs("div", {
40
41
  className: classBase,
41
42
  children: [
42
- /*#__PURE__*/ jsxs(FileDropZone, {
43
+ /*#__PURE__*/ jsx(FileDropZone, {
43
44
  className: `${classBase}-dropZone`,
44
45
  disabled: void 0 === schema || isProcessingFile || isImporting,
45
46
  onDrop: onDrop,
46
47
  status: status,
47
- children: [
48
- /*#__PURE__*/ jsx(FileDropZoneIcon, {}),
49
- validation && validation.errors.length > 0 ? /*#__PURE__*/ jsxs(Fragment, {
50
- children: [
51
- /*#__PURE__*/ jsx("div", {
52
- children: "Your file contains errors"
53
- }),
54
- fileErrors.length > 0 && /*#__PURE__*/ jsx("ul", {
55
- className: `${classBase}-errorList`,
56
- children: fileErrors.map((error, i)=>/*#__PURE__*/ jsx("li", {
57
- className: `${classBase}-errorItem`,
58
- children: error.message
59
- }, `${error.column}-${error.message}-${i}`))
60
- }),
61
- /*#__PURE__*/ jsx("div", {
62
- children: "Please rectify and reupload"
63
- })
64
- ]
65
- }) : /*#__PURE__*/ jsx("div", {
66
- children: "Drop a file here or"
67
- }),
68
- /*#__PURE__*/ jsx(FileDropZoneTrigger, {
69
- accept: ".csv,text/csv",
70
- onChange: onTriggerChange,
71
- children: "BROWSE FILES"
72
- }),
73
- children
74
- ]
48
+ children: isUploaded ? /*#__PURE__*/ jsxs(Fragment, {
49
+ children: [
50
+ /*#__PURE__*/ jsx(FileDropZoneIcon, {
51
+ status: "success"
52
+ }),
53
+ /*#__PURE__*/ jsx("strong", {
54
+ children: "Upload completed"
55
+ })
56
+ ]
57
+ }) : /*#__PURE__*/ jsxs(Fragment, {
58
+ children: [
59
+ /*#__PURE__*/ jsx(FileDropZoneIcon, {
60
+ status: hasErrors ? "error" : void 0
61
+ }),
62
+ validation && validation.errors.length > 0 ? /*#__PURE__*/ jsxs(Fragment, {
63
+ children: [
64
+ /*#__PURE__*/ jsx("div", {
65
+ children: "Your file contains errors"
66
+ }),
67
+ fileErrors.length > 0 && /*#__PURE__*/ jsx("ul", {
68
+ className: `${classBase}-errorList`,
69
+ children: fileErrors.map((error, i)=>/*#__PURE__*/ jsx("li", {
70
+ className: `${classBase}-errorItem`,
71
+ children: error.message
72
+ }, `${error.column}-${error.message}-${i}`))
73
+ }),
74
+ /*#__PURE__*/ jsx("div", {
75
+ children: "Please rectify and reupload"
76
+ })
77
+ ]
78
+ }) : /*#__PURE__*/ jsx("div", {
79
+ children: "Drop a file here or"
80
+ }),
81
+ /*#__PURE__*/ jsx(FileDropZoneTrigger, {
82
+ accept: ".csv,text/csv",
83
+ onChange: onTriggerChange,
84
+ children: "BROWSE FILES"
85
+ }),
86
+ /*#__PURE__*/ jsx(Text, {
87
+ children: "Only .csv files"
88
+ }),
89
+ children
90
+ ]
91
+ })
75
92
  }),
76
93
  error && (renderError ? renderError(error) : /*#__PURE__*/ jsxs("div", {
77
94
  className: `${classBase}-errors`,
@@ -1,4 +1,4 @@
1
- const CSV_HEADER_ROW_NUMBER = 1;
2
- const CSV_FIRST_DATA_ROW_NUMBER = 2;
1
+ const CSV_HEADER_ROW_NUMBER = 0;
2
+ const CSV_FIRST_DATA_ROW_NUMBER = 1;
3
3
  const MAX_ROWS_IN_CSV = 10000;
4
4
  export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, MAX_ROWS_IN_CSV };
@@ -15,6 +15,7 @@ var csv_errors_CsvValidationErrorEnum = /*#__PURE__*/ function(CsvValidationErro
15
15
  CsvValidationErrorEnum["MAX_ROWS_EXCEEDED"] = "MAX_ROWS_EXCEEDED";
16
16
  CsvValidationErrorEnum["EMPTY_NON_STRING_VALUE"] = "EMPTY_NON_STRING_VALUE";
17
17
  CsvValidationErrorEnum["TYPE_MISMATCH"] = "TYPE_MISMATCH";
18
+ CsvValidationErrorEnum["CUSTOM_VALIDATION"] = "CUSTOM_VALIDATION";
18
19
  return CsvValidationErrorEnum;
19
20
  }({});
20
21
  const createCsvErrorState = ()=>({
@@ -20,6 +20,10 @@ const validateCsvAgainstSchema = (parsed, tableSchema, options)=>{
20
20
  parsed.rows.forEach((rowValues, rowIndex)=>{
21
21
  const rowNum = rowIndex + CSV_FIRST_DATA_ROW_NUMBER;
22
22
  const typedRow = {};
23
+ const rawRow = parsed.header.reduce((acc, headerCol, idx)=>{
24
+ acc[headerCol] = rowValues[idx];
25
+ return acc;
26
+ }, {});
23
27
  parsed.header.forEach((columnName, columnIndex)=>{
24
28
  const rawValue = rowValues[columnIndex];
25
29
  const schemaType = schemaColumns.get(columnName);
@@ -33,6 +37,11 @@ const validateCsvAgainstSchema = (parsed, tableSchema, options)=>{
33
37
  return;
34
38
  }
35
39
  if (void 0 === value) return void addCsvRowError(errorState, rowNum, columnName, CsvValidationErrorEnum.TYPE_MISMATCH, `Value '${rawValue}' is not a valid ${toType}`, rawValue);
40
+ const customValidator = options?.validators?.[columnName];
41
+ if (customValidator) {
42
+ const validationResult = customValidator(rawValue, columnName, rawRow);
43
+ if (true !== validationResult) return void addCsvRowError(errorState, rowNum, columnName, CsvValidationErrorEnum.CUSTOM_VALIDATION, "string" == typeof validationResult ? validationResult : `Value '${rawValue}' failed custom validation.`, rawValue);
44
+ }
36
45
  typedRow[columnName] = value;
37
46
  });
38
47
  typedRows.push(typedRow);
@@ -5,7 +5,7 @@ import { parseCsv } from "./parse/csv-parse.js";
5
5
  import { validateCsvAgainstSchema } from "./parse/csv-schema-validation.js";
6
6
  import { buildRowErrorMessage, createUploadError, hasFileParseErrors, isCsvParseError, mergeValidationWithParseErrors, toErrorMessage } from "./parse/csv-upload-utils.js";
7
7
  import { CSV_FIRST_DATA_ROW_NUMBER } from "./parse/csv-constants.js";
8
- const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults })=>{
8
+ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, validators })=>{
9
9
  const { getServerAPI } = useData();
10
10
  const [validation, setValidation] = useState();
11
11
  const [sessionTable, setSessionTable] = useState();
@@ -140,7 +140,7 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
140
140
  if (rowNum < CSV_FIRST_DATA_ROW_NUMBER) continue;
141
141
  const existing = vuuMsgByRow.get(rowNum);
142
142
  const columnError = `${column}: ${message}`;
143
- vuuMsgByRow.set(rowNum, existing ? `${existing}; ${columnError}` : `Row ${rowNum}: ${columnError}`);
143
+ vuuMsgByRow.set(rowNum, existing ? `${existing}; ${columnError}` : `${0 === rowNum ? "Header" : `Row ${rowNum}`}: ${columnError}`);
144
144
  }
145
145
  const parsedRowCount = mergedValidation.rows.length;
146
146
  const unparsedErrorRows = [
@@ -174,7 +174,7 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
174
174
  if (isRpcError(result)) throw Error(result.errorMessage);
175
175
  if ("string" == typeof result) throw Error(result);
176
176
  } catch (error) {
177
- rpcErrors.push(`Row ${rowNum}: ${toErrorMessage(error)}`);
177
+ rpcErrors.push(`${0 === rowNum ? "Header" : `Row ${rowNum}`}: ${toErrorMessage(error)}`);
178
178
  }
179
179
  }
180
180
  if (rpcErrors.length > 0) throw Error(buildRowErrorMessage("Import failed", rpcErrors));
@@ -240,7 +240,8 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
240
240
  return;
241
241
  }
242
242
  const schemaValidation = validateCsvAgainstSchema(parsedCsv, schema, {
243
- maxRows
243
+ maxRows,
244
+ validators
244
245
  });
245
246
  if (Object.keys(schemaValidation.errorMap.fileErrors).length > 0) {
246
247
  setValidation(schemaValidation);
@@ -288,7 +289,8 @@ const useCsvUpload = ({ dataSource, importMode = "direct", importSchema, importT
288
289
  dataSource.table,
289
290
  table,
290
291
  endEditSessionAndNotify,
291
- schema
292
+ schema,
293
+ validators
292
294
  ]);
293
295
  const handleFiles = useCallback(async (files)=>{
294
296
  const file = files[0];
@@ -1,7 +1,7 @@
1
1
  import { type ReactNode } from "react";
2
2
  import type { RowDefaultDataItemValues, EditSession } from "@vuu-ui/vuu-data-editing";
3
3
  import type { CsvParseError, CsvParseOptions } from "./parse/csv-parse";
4
- import type { CsvValidationStructuredError } from "./parse/csv-schema-validation";
4
+ import type { CsvValidationStructuredError, CsvColumnValidator } from "./parse/csv-schema-validation";
5
5
  import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
6
6
  import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
7
7
  import type { CsvUploadTableData } from "./parse/csv-upload-utils";
@@ -60,6 +60,7 @@ export interface CsvUploadProps {
60
60
  parseOptions?: CsvParseOptions;
61
61
  importMode?: "direct" | "preview";
62
62
  rowDefaults?: RowDefaultDataItemValues;
63
+ validators?: Record<string, CsvColumnValidator>;
63
64
  /**
64
65
  * Custom renderer for the error panel.
65
66
  */
@@ -1,7 +1,7 @@
1
1
  export { CsvUpload, type CsvUploadError, type CsvUploadProps, type CsvUploadErrorResult, type CsvUploadErrors, type CsvUploadPhase, type CsvUploadImportedResult, type CsvUploadPreviewResult, type CsvUploadSessionEndReason, type CsvUploadSessionEndResult, type CsvUploadSessionTable, } from "./CsvUpload";
2
2
  export { useCsvUpload, type CsvUploadHookProps, type UseCsvUploadReturn, } from "./useCsvUpload";
3
3
  export { DataUploadPreview, type DataUploadPreviewProps, } from "./data-upload-preview/DataUploadPreview";
4
- export { validateCsvAgainstSchema, type CsvValidationOptions, type CsvValidationResult, } from "./parse/csv-schema-validation";
4
+ export { validateCsvAgainstSchema, type CsvColumnValidator, type CsvValidationOptions, type CsvValidationResult, } from "./parse/csv-schema-validation";
5
5
  export { parseCsv, type CsvParseOptions, type CsvParseResult, } from "./parse/csv-parse";
6
6
  export { CsvValidationErrorEnum, CsvParseErrorEnum, type CsvError, type CsvErrorMap, type CsvStructuredError, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, type CsvParseError, type CsvParseErrorMap, } from "./parse/csv-errors";
7
7
  export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, } from "./parse/csv-constants";
@@ -1,3 +1,3 @@
1
- export declare const CSV_HEADER_ROW_NUMBER = 1;
2
- export declare const CSV_FIRST_DATA_ROW_NUMBER = 2;
1
+ export declare const CSV_HEADER_ROW_NUMBER = 0;
2
+ export declare const CSV_FIRST_DATA_ROW_NUMBER = 1;
3
3
  export declare const MAX_ROWS_IN_CSV = 10000;
@@ -12,7 +12,8 @@ export declare enum CsvValidationErrorEnum {
12
12
  UNKNOWN_COLUMN = "UNKNOWN_COLUMN",
13
13
  MAX_ROWS_EXCEEDED = "MAX_ROWS_EXCEEDED",
14
14
  EMPTY_NON_STRING_VALUE = "EMPTY_NON_STRING_VALUE",
15
- TYPE_MISMATCH = "TYPE_MISMATCH"
15
+ TYPE_MISMATCH = "TYPE_MISMATCH",
16
+ CUSTOM_VALIDATION = "CUSTOM_VALIDATION"
16
17
  }
17
18
  export type CsvErrorMap<TError extends string> = {
18
19
  rowErrors: Record<number, Record<string, TError[]>>;
@@ -3,6 +3,7 @@ import type { VuuRowDataItemType } from "@vuu-ui/vuu-protocol-types";
3
3
  import type { CsvValidationError, CsvValidationErrorMap, CsvParseError } from "./csv-errors";
4
4
  import type { CsvParseResult } from "./csv-parse";
5
5
  export { CsvValidationErrorEnum, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, } from "./csv-errors";
6
+ export type CsvColumnValidator = (value: string, columnName: string, row: Record<string, string>) => boolean | string;
6
7
  export type CsvValidationResult = {
7
8
  columns: string[];
8
9
  errorMap: CsvValidationErrorMap;
@@ -12,5 +13,6 @@ export type CsvValidationResult = {
12
13
  };
13
14
  export type CsvValidationOptions = {
14
15
  maxRows?: number;
16
+ validators?: Record<string, CsvColumnValidator>;
15
17
  };
16
18
  export declare const validateCsvAgainstSchema: (parsed: CsvParseResult, tableSchema: TableSchema, options?: CsvValidationOptions) => CsvValidationResult;
@@ -1,5 +1,5 @@
1
1
  export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, } from "./csv-constants";
2
2
  export { CsvParseErrorEnum, CsvValidationErrorEnum, type CsvError, type CsvErrorMap, type CsvErrorState, type CsvParseError, type CsvParseErrorMap, type CsvStructuredError, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, addCsvFileError, addCsvRowError, createCsvErrorState, hasCsvErrors, } from "./csv-errors";
3
3
  export { parseCsv, type CsvParseOptions, type CsvParseResult, } from "./csv-parse";
4
- export { validateCsvAgainstSchema, type CsvValidationOptions, type CsvValidationResult, } from "./csv-schema-validation";
4
+ export { validateCsvAgainstSchema, type CsvColumnValidator, type CsvValidationOptions, type CsvValidationResult, } from "./csv-schema-validation";
5
5
  export { buildRowErrorMessage, executeBatchRpcCalls, hasFileParseErrors, isCsvParseError, mergeValidationWithParseErrors, normalizeTableData, toErrorMessage, toValidationErrorsFromParseRowErrors, type CsvUploadTableData, type RpcBatchResult, } from "./csv-upload-utils";
@@ -2,7 +2,7 @@ import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
2
2
  import { type RowDefaultDataItemValues } from "@vuu-ui/vuu-data-editing";
3
3
  import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
4
4
  import { type CsvParseOptions } from "./parse/csv-parse";
5
- import { type CsvValidationResult } from "./parse/csv-schema-validation";
5
+ import { type CsvValidationResult, type CsvColumnValidator } from "./parse/csv-schema-validation";
6
6
  import type { CsvUploadErrorResult, CsvUploadImportedResult, CsvUploadPreviewResult, CsvUploadSessionEndResult, CsvUploadSessionTable } from "./CsvUpload";
7
7
  export interface CsvUploadHookProps {
8
8
  dataSource: DataSource;
@@ -25,6 +25,7 @@ export interface CsvUploadHookProps {
25
25
  parseOptions?: CsvParseOptions;
26
26
  /** Default column values applied to every addRow call. Pass a stable reference — a new object triggers EditSession recreation. */
27
27
  rowDefaults?: RowDefaultDataItemValues;
28
+ validators?: Record<string, CsvColumnValidator>;
28
29
  }
29
30
  export type UseCsvUploadReturn = {
30
31
  canImport: boolean;
@@ -39,4 +40,4 @@ export type UseCsvUploadReturn = {
39
40
  validation: CsvValidationResult | undefined;
40
41
  error: CsvUploadErrorResult | undefined;
41
42
  };
42
- export declare const useCsvUpload: ({ dataSource, importMode, importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, }: CsvUploadHookProps) => UseCsvUploadReturn;
43
+ export declare const useCsvUpload: ({ dataSource, importMode, importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, validators, }: CsvUploadHookProps) => UseCsvUploadReturn;
@@ -1,7 +1,7 @@
1
1
  import { type ReactNode } from "react";
2
2
  import type { RowDefaultDataItemValues, EditSession } from "@vuu-ui/vuu-data-editing";
3
3
  import type { CsvParseError, CsvParseOptions } from "./parse/csv-parse";
4
- import type { CsvValidationStructuredError } from "./parse/csv-schema-validation";
4
+ import type { CsvValidationStructuredError, CsvColumnValidator } from "./parse/csv-schema-validation";
5
5
  import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
6
6
  import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
7
7
  import type { CsvUploadTableData } from "./parse/csv-upload-utils";
@@ -60,6 +60,7 @@ export interface CsvUploadProps {
60
60
  parseOptions?: CsvParseOptions;
61
61
  importMode?: "direct" | "preview";
62
62
  rowDefaults?: RowDefaultDataItemValues;
63
+ validators?: Record<string, CsvColumnValidator>;
63
64
  /**
64
65
  * Custom renderer for the error panel.
65
66
  */
@@ -1,7 +1,7 @@
1
1
  export { CsvUpload, type CsvUploadError, type CsvUploadProps, type CsvUploadErrorResult, type CsvUploadErrors, type CsvUploadPhase, type CsvUploadImportedResult, type CsvUploadPreviewResult, type CsvUploadSessionEndReason, type CsvUploadSessionEndResult, type CsvUploadSessionTable, } from "./CsvUpload";
2
2
  export { useCsvUpload, type CsvUploadHookProps, type UseCsvUploadReturn, } from "./useCsvUpload";
3
3
  export { DataUploadPreview, type DataUploadPreviewProps, } from "./data-upload-preview/DataUploadPreview";
4
- export { validateCsvAgainstSchema, type CsvValidationOptions, type CsvValidationResult, } from "./parse/csv-schema-validation";
4
+ export { validateCsvAgainstSchema, type CsvColumnValidator, type CsvValidationOptions, type CsvValidationResult, } from "./parse/csv-schema-validation";
5
5
  export { parseCsv, type CsvParseOptions, type CsvParseResult, } from "./parse/csv-parse";
6
6
  export { CsvValidationErrorEnum, CsvParseErrorEnum, type CsvError, type CsvErrorMap, type CsvStructuredError, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, type CsvParseError, type CsvParseErrorMap, } from "./parse/csv-errors";
7
7
  export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, } from "./parse/csv-constants";
@@ -1,3 +1,3 @@
1
- export declare const CSV_HEADER_ROW_NUMBER = 1;
2
- export declare const CSV_FIRST_DATA_ROW_NUMBER = 2;
1
+ export declare const CSV_HEADER_ROW_NUMBER = 0;
2
+ export declare const CSV_FIRST_DATA_ROW_NUMBER = 1;
3
3
  export declare const MAX_ROWS_IN_CSV = 10000;
@@ -12,7 +12,8 @@ export declare enum CsvValidationErrorEnum {
12
12
  UNKNOWN_COLUMN = "UNKNOWN_COLUMN",
13
13
  MAX_ROWS_EXCEEDED = "MAX_ROWS_EXCEEDED",
14
14
  EMPTY_NON_STRING_VALUE = "EMPTY_NON_STRING_VALUE",
15
- TYPE_MISMATCH = "TYPE_MISMATCH"
15
+ TYPE_MISMATCH = "TYPE_MISMATCH",
16
+ CUSTOM_VALIDATION = "CUSTOM_VALIDATION"
16
17
  }
17
18
  export type CsvErrorMap<TError extends string> = {
18
19
  rowErrors: Record<number, Record<string, TError[]>>;
@@ -3,6 +3,7 @@ import type { VuuRowDataItemType } from "@vuu-ui/vuu-protocol-types";
3
3
  import type { CsvValidationError, CsvValidationErrorMap, CsvParseError } from "./csv-errors";
4
4
  import type { CsvParseResult } from "./csv-parse";
5
5
  export { CsvValidationErrorEnum, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, } from "./csv-errors";
6
+ export type CsvColumnValidator = (value: string, columnName: string, row: Record<string, string>) => boolean | string;
6
7
  export type CsvValidationResult = {
7
8
  columns: string[];
8
9
  errorMap: CsvValidationErrorMap;
@@ -12,5 +13,6 @@ export type CsvValidationResult = {
12
13
  };
13
14
  export type CsvValidationOptions = {
14
15
  maxRows?: number;
16
+ validators?: Record<string, CsvColumnValidator>;
15
17
  };
16
18
  export declare const validateCsvAgainstSchema: (parsed: CsvParseResult, tableSchema: TableSchema, options?: CsvValidationOptions) => CsvValidationResult;
@@ -1,5 +1,5 @@
1
1
  export { CSV_FIRST_DATA_ROW_NUMBER, CSV_HEADER_ROW_NUMBER, } from "./csv-constants";
2
2
  export { CsvParseErrorEnum, CsvValidationErrorEnum, type CsvError, type CsvErrorMap, type CsvErrorState, type CsvParseError, type CsvParseErrorMap, type CsvStructuredError, type CsvValidationError, type CsvValidationErrorMap, type CsvValidationErrorType, type CsvValidationStructuredError, addCsvFileError, addCsvRowError, createCsvErrorState, hasCsvErrors, } from "./csv-errors";
3
3
  export { parseCsv, type CsvParseOptions, type CsvParseResult, } from "./csv-parse";
4
- export { validateCsvAgainstSchema, type CsvValidationOptions, type CsvValidationResult, } from "./csv-schema-validation";
4
+ export { validateCsvAgainstSchema, type CsvColumnValidator, type CsvValidationOptions, type CsvValidationResult, } from "./csv-schema-validation";
5
5
  export { buildRowErrorMessage, executeBatchRpcCalls, hasFileParseErrors, isCsvParseError, mergeValidationWithParseErrors, normalizeTableData, toErrorMessage, toValidationErrorsFromParseRowErrors, type CsvUploadTableData, type RpcBatchResult, } from "./csv-upload-utils";
@@ -2,7 +2,7 @@ import type { DataSource, TableSchema } from "@vuu-ui/vuu-data-types";
2
2
  import { type RowDefaultDataItemValues } from "@vuu-ui/vuu-data-editing";
3
3
  import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
4
4
  import { type CsvParseOptions } from "./parse/csv-parse";
5
- import { type CsvValidationResult } from "./parse/csv-schema-validation";
5
+ import { type CsvValidationResult, type CsvColumnValidator } from "./parse/csv-schema-validation";
6
6
  import type { CsvUploadErrorResult, CsvUploadImportedResult, CsvUploadPreviewResult, CsvUploadSessionEndResult, CsvUploadSessionTable } from "./CsvUpload";
7
7
  export interface CsvUploadHookProps {
8
8
  dataSource: DataSource;
@@ -25,6 +25,7 @@ export interface CsvUploadHookProps {
25
25
  parseOptions?: CsvParseOptions;
26
26
  /** Default column values applied to every addRow call. Pass a stable reference — a new object triggers EditSession recreation. */
27
27
  rowDefaults?: RowDefaultDataItemValues;
28
+ validators?: Record<string, CsvColumnValidator>;
28
29
  }
29
30
  export type UseCsvUploadReturn = {
30
31
  canImport: boolean;
@@ -39,4 +40,4 @@ export type UseCsvUploadReturn = {
39
40
  validation: CsvValidationResult | undefined;
40
41
  error: CsvUploadErrorResult | undefined;
41
42
  };
42
- export declare const useCsvUpload: ({ dataSource, importMode, importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, }: CsvUploadHookProps) => UseCsvUploadReturn;
43
+ export declare const useCsvUpload: ({ dataSource, importMode, importSchema, importTable, onImportSessionEnded, onImportSessionStarted, onError, onImported, onPreview, onProcessingStarted, maxRows, parseOptions, rowDefaults, validators, }: CsvUploadHookProps) => UseCsvUploadReturn;