From b875a296ffb56a74061b1dcda4cdfafc2aec781e Mon Sep 17 00:00:00 2001 From: Gaetan SENN Date: Mon, 28 May 2018 00:35:26 +0200 Subject: [PATCH 01/64] Added type definitions for imperium --- types/imperium/imperium-tests.ts | 21 ++++++++ types/imperium/index.d.ts | 93 ++++++++++++++++++++++++++++++++ types/imperium/tsconfig.json | 23 ++++++++ 3 files changed, 137 insertions(+) create mode 100644 types/imperium/imperium-tests.ts create mode 100644 types/imperium/index.d.ts create mode 100644 types/imperium/tsconfig.json diff --git a/types/imperium/imperium-tests.ts b/types/imperium/imperium-tests.ts new file mode 100644 index 0000000000..2f6cbaa8b4 --- /dev/null +++ b/types/imperium/imperium-tests.ts @@ -0,0 +1,21 @@ +import imperium from 'imperium' + +import { Imperium, ImperiumUnauthorizedError } from 'imperium' + +imperium.role('admin', async (req) => { + return req.session.role === 'admin' +}) + +imperium.role('user') + .can('seeUser', { user: '@' }) + .can('manageUser', { user: '@' }) + +imperium.role('admin') + .is('user', { user: '*' }) + +imperium.can('seeUser') +imperium.can(['seeUser', 'manageUser']) +imperium.can({ action: 'seeUser', user: ':userId' }) +imperium.can([{ action: 'manageUser', user: ':userId' }]) +imperium.is('admin') +imperium.is(['admin', 'user']) diff --git a/types/imperium/index.d.ts b/types/imperium/index.d.ts new file mode 100644 index 0000000000..2695e79574 --- /dev/null +++ b/types/imperium/index.d.ts @@ -0,0 +1,93 @@ +// Type definitions for imperium v2.0.2 +// Project: https://www.npmjs.org/package/mono-js/imperium +// Definitions by: Gaetan SENN +// Definitions: https://github.com/psnider/DefinitelyTyped/imperium +// TypeScript Version: 2.7 + +/// +/// + +declare module 'imperium' { + type ImperiumMiddleware = (req: Express.Request, res: Express.Response, next: Function) => Promise + type ImperiumGetAcl = (req: Express.Request) => Promise | Promise + type ImperiumActions = Array | String + type ImperiumContext = Array<'params' | 'query' | 'headers' | 'body'> + // Can contain when key that is evaluated during route action + type ImperiumRoleParams = { [key: string]: String } + + export class Imperium { + constructor() + + context: Array + roles: Roles + + // Add new role with specific ImperiumGetAcl + role(roleName: String, getAcl: ImperiumGetAcl): ImperiumRole + + // Return specific imperium role instance + role(roleName: String): ImperiumRole + + // Check if user has role + is(roleName: String): ImperiumMiddleware + + // Check if user has on of listed roles act like an OR + is(roleNames: Array): ImperiumMiddleware + + // Check if current user can do action + can(action: String): ImperiumMiddleware + + can(actions: Array): ImperiumMiddleware + + can(action: Action): ImperiumMiddleware + + can(actions: Array): ImperiumMiddleware + + private addRole(roleName: String, getAcl: ImperiumGetAcl): void + + private evaluateRouteActions(req: Express.Request, action: Array, context: ImperiumContext): ImperiumActions + + private evaluateRouteAction(req: Express.Request, expr: String, key: String, context: ImperiumContext): String + + private evaluateUserActions(req: Express.Request, roles: Array): Promise> + + private evaluateUserAction(action: ImperiumRoleParams, context: { [key: string]: Array }): { [key: string]: Array } + } + + interface Roles { + [key: string]: Role + } + + interface Role { + actions: Array + getAcl?: ImperiumGetAcl + } + + interface Action { + action: String + [key: string]: String + } + + export class ImperiumRole { + constructor(imperium: Imperium, roleName: String) + + // Imperium instance to retreive child role + imperium: Imperium + // Role name + roleName: String + // Contain all the actions for this specific role + role: Role + + /* Add action with specific params */ + can(action: String, params: ImperiumRoleParams): ImperiumRole + + /* Get actions of childRoleName and replace params */ + is(childRoleName: String, params: ImperiumRoleParams): ImperiumRole + } + + export class ImperiumUnauthorizedError extends Error { + constructor(message: String, status: number, context: any) + } + + const out: Imperium + export default out +} diff --git a/types/imperium/tsconfig.json b/types/imperium/tsconfig.json new file mode 100644 index 0000000000..597aae24fa --- /dev/null +++ b/types/imperium/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "imperium-tests.ts" + ] +} From a78b7f9d7e0b4be38aeb472c6100920c267e71bc Mon Sep 17 00:00:00 2001 From: Gaetan SENN Date: Mon, 28 May 2018 16:15:06 +0200 Subject: [PATCH 02/64] imperium: Add tslint and fix compilation --- types/imperium/imperium-tests.ts | 4 +- types/imperium/index.d.ts | 54 +++++++++++----------- types/imperium/tsconfig.json | 43 ++++++++--------- types/imperium/tslint.json | 79 ++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 49 deletions(-) create mode 100644 types/imperium/tslint.json diff --git a/types/imperium/imperium-tests.ts b/types/imperium/imperium-tests.ts index 2f6cbaa8b4..72fda8f52a 100644 --- a/types/imperium/imperium-tests.ts +++ b/types/imperium/imperium-tests.ts @@ -1,9 +1,9 @@ import imperium from 'imperium' -import { Imperium, ImperiumUnauthorizedError } from 'imperium' +import { Imperium, UnauthorizedError } from 'imperium' imperium.role('admin', async (req) => { - return req.session.role === 'admin' + return true }) imperium.role('user') diff --git a/types/imperium/index.d.ts b/types/imperium/index.d.ts index 2695e79574..f7f2191a3f 100644 --- a/types/imperium/index.d.ts +++ b/types/imperium/index.d.ts @@ -8,12 +8,14 @@ /// declare module 'imperium' { - type ImperiumMiddleware = (req: Express.Request, res: Express.Response, next: Function) => Promise - type ImperiumGetAcl = (req: Express.Request) => Promise | Promise - type ImperiumActions = Array | String - type ImperiumContext = Array<'params' | 'query' | 'headers' | 'body'> + import express = require('express') + + type Middleware = (req: express.Request, res: express.Response, next: Function) => Promise + type GetAcl = (req: express.Request) => Promise | Promise + type Actions = Array | String + type Context = Array<'params' | 'query' | 'headers' | 'body'> // Can contain when key that is evaluated during route action - type ImperiumRoleParams = { [key: string]: String } + type RoleParams = { [key: string]: String } export class Imperium { constructor() @@ -22,44 +24,44 @@ declare module 'imperium' { roles: Roles // Add new role with specific ImperiumGetAcl - role(roleName: String, getAcl: ImperiumGetAcl): ImperiumRole + role(roleName: String, getAcl: GetAcl): Role // Return specific imperium role instance - role(roleName: String): ImperiumRole + role(roleName: String): Role // Check if user has role - is(roleName: String): ImperiumMiddleware + is(roleName: String): Middleware // Check if user has on of listed roles act like an OR - is(roleNames: Array): ImperiumMiddleware + is(roleNames: Array): Middleware // Check if current user can do action - can(action: String): ImperiumMiddleware + can(action: String): Middleware - can(actions: Array): ImperiumMiddleware + can(actions: Array): Middleware - can(action: Action): ImperiumMiddleware + can(action: Action): Middleware - can(actions: Array): ImperiumMiddleware + can(actions: Array): Middleware - private addRole(roleName: String, getAcl: ImperiumGetAcl): void + private addRole(roleName: String, getAcl: GetAcl): void - private evaluateRouteActions(req: Express.Request, action: Array, context: ImperiumContext): ImperiumActions + private evaluateRouteActions(req: express.Request, action: Array, context: Context): Actions - private evaluateRouteAction(req: Express.Request, expr: String, key: String, context: ImperiumContext): String + private evaluateRouteAction(req: express.Request, expr: String, key: String, context: Context): String - private evaluateUserActions(req: Express.Request, roles: Array): Promise> + private evaluateUserActions(req: express.Request, roles: Array): Promise> - private evaluateUserAction(action: ImperiumRoleParams, context: { [key: string]: Array }): { [key: string]: Array } + private evaluateUserAction(action: RoleParams, context: { [key: string]: Array }): { [key: string]: Array } } interface Roles { - [key: string]: Role + [key: string]: RoleActions } - interface Role { + interface RoleActions { actions: Array - getAcl?: ImperiumGetAcl + getAcl?: GetAcl } interface Action { @@ -67,7 +69,7 @@ declare module 'imperium' { [key: string]: String } - export class ImperiumRole { + export class Role { constructor(imperium: Imperium, roleName: String) // Imperium instance to retreive child role @@ -75,16 +77,16 @@ declare module 'imperium' { // Role name roleName: String // Contain all the actions for this specific role - role: Role + role: RoleActions /* Add action with specific params */ - can(action: String, params: ImperiumRoleParams): ImperiumRole + can(action: String, params: RoleParams): Role /* Get actions of childRoleName and replace params */ - is(childRoleName: String, params: ImperiumRoleParams): ImperiumRole + is(childRoleName: String, params: RoleParams): Role } - export class ImperiumUnauthorizedError extends Error { + export class UnauthorizedError extends Error { constructor(message: String, status: number, context: any) } diff --git a/types/imperium/tsconfig.json b/types/imperium/tsconfig.json index 597aae24fa..98e23e4de8 100644 --- a/types/imperium/tsconfig.json +++ b/types/imperium/tsconfig.json @@ -1,23 +1,24 @@ { - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "imperium-tests.ts" - ] + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "imperium-tests.ts" + ] } diff --git a/types/imperium/tslint.json b/types/imperium/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/imperium/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +} From 9cb77195a439c097b6778f113c0c24c17eac02ef Mon Sep 17 00:00:00 2001 From: Gaetan SENN Date: Tue, 29 May 2018 11:33:45 +0200 Subject: [PATCH 03/64] imperium: Fix feedback from plantain-00 --- types/imperium/index.d.ts | 2 +- types/imperium/tsconfig.json | 2 +- types/imperium/tslint.json | 78 +----------------------------------- 3 files changed, 3 insertions(+), 79 deletions(-) diff --git a/types/imperium/index.d.ts b/types/imperium/index.d.ts index f7f2191a3f..cdfbf3da39 100644 --- a/types/imperium/index.d.ts +++ b/types/imperium/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for imperium v2.0.2 -// Project: https://www.npmjs.org/package/mono-js/imperium +// Project: https://www.npmjs.org/package/imperium // Definitions by: Gaetan SENN // Definitions: https://github.com/psnider/DefinitelyTyped/imperium // TypeScript Version: 2.7 diff --git a/types/imperium/tsconfig.json b/types/imperium/tsconfig.json index 98e23e4de8..c8563caffe 100644 --- a/types/imperium/tsconfig.json +++ b/types/imperium/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ diff --git a/types/imperium/tslint.json b/types/imperium/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/imperium/tslint.json +++ b/types/imperium/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } From 804f2e4a6ffae02cffffa104d7d4ce5048d8fb5d Mon Sep 17 00:00:00 2001 From: Peter Keuter Date: Tue, 29 May 2018 11:55:33 +0200 Subject: [PATCH 04/64] Add label render function --- types/recharts/index.d.ts | 10 +++++----- types/recharts/recharts-tests.tsx | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/types/recharts/index.d.ts b/types/recharts/index.d.ts index ecdcd1f420..1bbb1b158e 100644 --- a/types/recharts/index.d.ts +++ b/types/recharts/index.d.ts @@ -163,7 +163,7 @@ export interface AreaProps extends EventAttributes, Partial | ContentRenderer; dot?: boolean | object | React.ReactElement | ContentRenderer; - label?: boolean | object | React.ReactElement | LabelProps['content']; + label?: boolean | object | ContentRenderer | React.ReactElement | LabelProps['content']; hide?: boolean; layout?: LayoutType; baseLine?: number | any[]; @@ -207,7 +207,7 @@ export interface BarProps extends EventAttributes, Partial | ContentRenderer; data?: BarData[]; // see label section at http://recharts.org/#/en-US/api/Bar - label?: boolean | Label | React.SFC | React.ReactElement | ContentRenderer