-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add typing for perspective #157
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| declare module '@jpmorganchase/perspective' { | ||
| /**** object types ****/ | ||
| export enum TypeNames { | ||
| STRING = 'string', | ||
| FLOAT = 'float', | ||
| INTEGER = 'integer', | ||
| BOOLEAN = 'boolean', | ||
| DATE = 'date' | ||
| } | ||
|
|
||
| export type ValuesByType = { | ||
| [ key in TypeNames ]: Array<string> | ||
| } | ||
|
|
||
| export type ValueByType = { | ||
| TypeNames: Array<string> | ||
| } | ||
|
|
||
| export enum SortOrders { | ||
| ASC = 'asc', | ||
| ASC_ABS = 'asc abs', | ||
| DESC = 'desc', | ||
| DESC_ABS = 'desc abs', | ||
| NONE = 'none', | ||
| } | ||
|
|
||
| enum NUMBER_AGGREGATES { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These might potentially be better as Enums rather than strings?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are enums, or you mean to create a global enum with all of them and NUMBER, STRING, BOOLEAN to be just a subset of them?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking that maybe we can take the aggregate keywords and Enum those. But I couldn't find a nice way to make them all align up. Since these are private I'll take another look later and we can hoist them into private enums later.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks |
||
| ANY = 'any', | ||
| AVERAGE = 'avg', | ||
| COUNT = 'count', | ||
| DISTINCT_COUNT = 'distinct count', | ||
| DOMINANT = 'dominant', | ||
| FIRST = 'first', | ||
| LAST = 'last', | ||
| HIGH = 'high', | ||
| LOW = 'low', | ||
| MEAN = 'mean', | ||
| MEAN_COUNT = 'mean by count', | ||
| MEDIAN = 'median', | ||
| PCT_SUM_PARENT = 'pct sum parent', | ||
| PCT_SUM_TOTAL = 'pct sum grand total', | ||
| SUM = 'sum', | ||
| SUM_ABS = 'sum abs', | ||
| SUM_NOT_NULL = 'sum not null', | ||
| UNIQUE = 'unique' | ||
| } | ||
|
|
||
| enum STRING_AGGREGATES { | ||
| ANY = 'any', | ||
| COUNT = 'count', | ||
| DISTINCT_COUNT = 'distinct count', | ||
| DISTINCT_LEAF = 'distinct leaf', | ||
| DOMINANT = 'dominant', | ||
| FIRST = 'first', | ||
| LAST = 'last', | ||
| MEAN_COUNT = 'mean by count', | ||
| UNIQUE = 'unique' | ||
| } | ||
|
|
||
| enum BOOLEAN_AGGREGATES { | ||
| AND = 'and', | ||
| ANY = 'any', | ||
| COUNT = 'count', | ||
| DISTINCT_COUNT = 'distinct count', | ||
| DISTINCT_LEAF = 'distinct leaf', | ||
| DOMINANT = 'dominant', | ||
| FIRST = 'first', | ||
| LAST = 'last', | ||
| MEAN_COUNT = 'mean by count', | ||
| OR ='or', | ||
| UNIQUE = 'unique' | ||
| } | ||
|
|
||
| /**** Schema ****/ | ||
| type SchemaType = TypeNames | NUMBER_AGGREGATES | STRING_AGGREGATES | BOOLEAN_AGGREGATES; | ||
|
|
||
| export type Schema = { | ||
| [ key: string ]: TypeNames ; | ||
| } | ||
|
|
||
| /**** View ****/ | ||
| export type View = { | ||
| delete(): Promise<void>; | ||
| num_columns(): Promise<number>; | ||
| num_rows(): Promise<number>; | ||
| on_update(callback: UpdateCallback): void; | ||
| on_delete(callback: Function): void; | ||
| schema(): Promise<Schema>; | ||
| to_json(): Promise<Array<object>>; | ||
| to_csv(): Promise<string>; | ||
| } | ||
|
|
||
| /**** Table ****/ | ||
| export type UpdateCallback = (data: Array<object>) => void | ||
|
|
||
| export type TableData = string | Array<object> | { [key: string]: Array<object> } | { [key: string]: string } | ||
|
|
||
| export type TableOptions = { | ||
| index: string | ||
| } | ||
|
|
||
| export type AggregateConfig = { | ||
| column: string | Array<string>; | ||
| name?: string; | ||
| op: NUMBER_AGGREGATES | STRING_AGGREGATES | BOOLEAN_AGGREGATES; | ||
| }; | ||
|
|
||
| export type ViewConfig = { | ||
| row_pivot?: Array<string>; | ||
| column_pivot?: Array<string>; | ||
| sort?: Array<string>; | ||
| filter?: Array<Array<string>>; | ||
| aggregate: Array<AggregateConfig>; | ||
| }; | ||
|
|
||
| export type Table = { | ||
| add_computed(): Table; | ||
| columns(): Array<string>; | ||
| delete(): Promise<void>; | ||
| on_delete(callback: Function): void; | ||
| schema(): Promise<Schema>; | ||
| size(): Promise<number>; | ||
| update(TableData): void; | ||
| view(ViewConfig): View; | ||
| } | ||
|
|
||
| /**** perspective ****/ | ||
| export enum PerspectiveEvents { | ||
| PERSPECTIVE_READY = 'perspective-ready' | ||
| } | ||
|
|
||
| export type PerspectiveWorker = { | ||
| table(data: TableData, options?: TableOptions): Table; | ||
| } | ||
|
|
||
| type perspective = { | ||
| TYPE_AGGREGATES: ValuesByType, | ||
| TYPE_FILTERS: ValuesByType, | ||
| AGGREGATE_DEFAULTS: ValueByType, | ||
| FILTER_DEFAULTS: ValueByType, | ||
| SORT_ORDERS: SortOrders, | ||
| table(): Table, | ||
| worker(): PerspectiveWorker | ||
| } | ||
|
|
||
| const impl: perspective; | ||
|
|
||
| export default impl; | ||
| } | ||
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.
For primitives it's better to use string[] for arrays.
Uh oh!
There was an error while loading. Please reload this page.
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.
https://palantir.github.io/tslint/rules/array-type/
we use "generic" on our project, hence
Array<T>overT[]but happy to change if you want me to
Uh oh!
There was an error while loading. Please reload this page.
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.
Sure, since there's no tslint setup of similar and they're equivalent let's just go with this for now. We can always change later - I just normally go with
"array-simple"but consistency makes sense.