MCPcopy Create free account
hub / github.com/HelloCSV/HelloCSV / automaticFieldValidators

Function automaticFieldValidators

src/validators/index.ts:35–75  ·  view source on GitHub ↗
(
  columnDefinition: SheetColumnDefinition,
  allData: SheetState[]
)

Source from the content-addressed store, hash-verified

33}
34
35function automaticFieldValidators(
36 columnDefinition: SheetColumnDefinition,
37 allData: SheetState[]
38): ImporterValidatorDefinition[] {
39 const result: ImporterValidatorDefinition[] = [];
40
41 if (columnDefinition.type === 'enum') {
42 const { values, multiple } = columnDefinition.typeArguments as {
43 values: SelectOption<string>[];
44 multiple?: boolean;
45 };
46
47 const validValues = values.map((v) => v.value);
48
49 if (multiple) {
50 result.push({
51 values: validValues,
52 validate: 'multi_includes',
53 });
54 } else {
55 result.push({
56 values: validValues,
57 validate: 'includes',
58 });
59 }
60 }
61
62 if (columnDefinition.type === 'reference') {
63 const referenceData = extractReferenceColumnPossibleValues(
64 columnDefinition,
65 allData
66 );
67
68 result.push({
69 values: referenceData,
70 validate: 'includes',
71 });
72 }
73
74 return result;
75}
76
77async function validateSheet(
78 sheetDefinition: SheetDefinition,

Callers 1

validateSheetFunction · 0.85

Calls 2

pushMethod · 0.80

Tested by

no test coverage detected