New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Chore]: Technical: add types for processors #1798
Conversation
Signed-off-by: Daria Terekhova <daria.terekhova@actionengine.com>
325706a
to
e38cf98
Compare
src/processors/data-processor.ts
Outdated
@@ -58,20 +63,20 @@ const IGNORE_DATA_TYPES = Object.keys(AnalyzerDATA_TYPES).filter( | |||
|
|||
export const PARSE_FIELD_VALUE_FROM_STRING = { | |||
[ALL_FIELD_TYPES.boolean]: { | |||
valid: d => typeof d === 'boolean', | |||
parse: d => d === 'true' || d === 'True' || d === 'TRUE' || d === '1' | |||
valid: (d: any) => typeof d === 'boolean', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(d: unknown): boolean => typeof d === 'boolean'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/data-processor.ts
Outdated
valid: d => typeof d === 'boolean', | ||
parse: d => d === 'true' || d === 'True' || d === 'TRUE' || d === '1' | ||
valid: (d: any) => typeof d === 'boolean', | ||
parse: (d: any) => d === 'true' || d === 'True' || d === 'TRUE' || d === '1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(d: unknown): boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/data-processor.ts
Outdated
}, | ||
[ALL_FIELD_TYPES.integer]: { | ||
valid: d => parseInt(d, 10) === d, | ||
parse: d => parseInt(d, 10) | ||
valid: (d: any) => parseInt(d, 10) === d, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same below, use (d: unknown): boolean
for validate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/data-processor.ts
Outdated
valid: d => parseInt(d, 10) === d, | ||
parse: d => parseInt(d, 10) | ||
valid: (d: any) => parseInt(d, 10) === d, | ||
parse: (d: any) => parseInt(d, 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(value: unknown): number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/data-processor.ts
Outdated
sampleCount = 50 | ||
}: { | ||
fields: string[]; | ||
rows: any[][]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rows: unknown[][]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/data-processor.ts
Outdated
*/ | ||
function cleanUpFalsyCsvValue(rows) { | ||
function cleanUpFalsyCsvValue(rows: any[][]): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rows: unknown[][]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/data-processor.ts
Outdated
*/ | ||
export function parseCsvRowsByFieldType(rows, geoFieldIdx, field, i) { | ||
export function parseCsvRowsByFieldType( | ||
rows: any[][], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rows: unknown[][]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/data-processor.ts
Outdated
function findNonEmptyRowsAtField(rows, fieldIdx, total) { | ||
const sample = []; | ||
function findNonEmptyRowsAtField( | ||
rows: Record<number, unknown>[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rows: unknown[][]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/file-handler.ts
Outdated
@@ -47,25 +50,25 @@ const JSON_LOADER_OPTIONS = { | |||
] | |||
}; | |||
|
|||
export function isGeoJson(json) { | |||
export function isGeoJson(json: any): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use type guard here
isGeoJson(json: unknown): json is Feature | FeatureCollection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/file-handler.ts
Outdated
// json can be feature collection | ||
// or single feature | ||
return isPlainObject(json) && (isFeature(json) || isFeatureCollection(json)); | ||
} | ||
|
||
export function isFeature(json) { | ||
export function isFeature(json: any): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isFeature(json: unknown): json is Feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/file-handler.ts
Outdated
return json.type === 'Feature' && json.geometry; | ||
} | ||
|
||
export function isFeatureCollection(json) { | ||
export function isFeatureCollection(json: any): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isFeatureCollection(json: unknown): json is FeatureCollection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -47,25 +50,25 @@ const JSON_LOADER_OPTIONS = { | |||
] | |||
}; | |||
|
|||
export function isGeoJson(json) { | |||
export function isGeoJson(json: any): boolean { | |||
// json can be feature collection | |||
// or single feature | |||
return isPlainObject(json) && (isFeature(json) || isFeatureCollection(json)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add type isPlainObject(obj: unknown): obj is Record<string, unknown>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
src/processors/file-handler.ts
Outdated
return Array.isArray(json) && isPlainObject(json[0]); | ||
} | ||
|
||
export function isKeplerGlMap(json) { | ||
export function isKeplerGlMap(json: any): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type ValidKeplerGlMap = {
datasets: unknown
config: unknown
info: Record<string, string>
}
isKeplerGlMap(json: unknown): json is ValidKeplerGlMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
Signed-off-by: Evgeny Zhgulev <evgeny.zhgulev@actionengine.com>
src/processors/data-processor.ts
Outdated
}, | ||
[ALL_FIELD_TYPES.timestamp]: { | ||
valid: (d, field) => | ||
valid: (d: any, field: Field) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valid: (d: unknown, field: Field): boolean;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/processors/data-processor.ts
Outdated
}, | ||
[ALL_FIELD_TYPES.real]: { | ||
valid: d => parseFloat(d) === d, | ||
valid: (d: any) => parseFloat(d) === d, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(d: unknown): boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the last 2 comments and merge
Signed-off-by: Evgeny Zhgulev <evgeny.zhgulev@actionengine.com>
Signed-off-by: Evgeny Zhgulev <evgeny.zhgulev@actionengine.com>
Signed-off-by: Daria Terekhova daria.terekhova@actionengine.com