Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions packages/perspective/index.d.ts
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>
Copy link
Contributor

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.

Copy link
Contributor Author

@segarman segarman Jul 16, 2018

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> over T[]
but happy to change if you want me to

Copy link
Contributor

@LukeSheard LukeSheard Jul 18, 2018

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.

}

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These might potentially be better as Enums rather than strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
4 changes: 3 additions & 1 deletion packages/perspective/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
},
"files": [
"src/*",
"build/*"
"build/*",
"index.d.ts"
],
"typings": "index.d.ts",
"scripts": {
"compile": "mkdir -p obj build build/wasm_async build/wasm_sync build/asmjs && (cd obj/ && emcmake cmake ../ && emmake make -j8)",
"perspective": "webpack --config src/config/perspective.asmjs.config.js & webpack --config src/config/perspective.wasm.config.js & webpack --config src/config/perspective.parallel.config.js & wait",
Expand Down