Fix packages/common

This commit is contained in:
Jerko Steiner 2019-09-15 17:50:20 +07:00
parent 69dd12375c
commit fea568b58a
33 changed files with 122 additions and 139 deletions

View File

@ -1,10 +1,10 @@
import React from 'react' import React from 'react'
export interface IButtonProps { export interface ButtonProps {
type: string // type: string
} }
export class Button extends React.PureComponent { export class Button extends React.PureComponent<ButtonProps> {
render() { render() {
return ( return (
<button>{this.props.children}</button> <button>{this.props.children}</button>

View File

@ -1,17 +1,17 @@
import React from 'react' import React from 'react'
import {connect} from 'react-redux' import {connect} from 'react-redux'
interface IComponentProps { interface ComponentProps {
value: string value: string
} }
interface IStateProps { interface StateProps {
value: string value: string
} }
export class Component export class Component
extends React.PureComponent<IComponentProps, IStateProps> { extends React.PureComponent<ComponentProps, StateProps> {
constructor(props: IComponentProps) { constructor(props: ComponentProps) {
super(props) super(props)
this.state = { this.state = {
value: props.value, value: props.value,
@ -37,7 +37,7 @@ extends React.PureComponent<IComponentProps, IStateProps> {
} }
} }
function mapStateToProps(state: any) { function mapStateToProps(state: {value: string}) {
return { return {
value: state.value, value: state.value,
} }

View File

@ -1,11 +1,11 @@
import {Modal as M, ModalBackground, ModalContent, ModalClose} from 'bloomer' import {Modal as M, ModalBackground, ModalContent, ModalClose} from 'bloomer'
import React from 'react' import React from 'react'
export interface IModalProps { export interface ModalProps {
isActive?: boolean isActive?: boolean
} }
export class Modal extends React.PureComponent<IModalProps> { export class Modal extends React.PureComponent<ModalProps> {
render() { render() {
return ( return (
<M isActive={this.props.isActive}> <M isActive={this.props.isActive}>

View File

@ -1,17 +1,17 @@
import { IUser, INewUser } from './user' import { UserProfile, NewUser } from './user'
import { ICredentials } from './auth' import { Credentials } from './auth'
export interface IAPIDef { export interface APIDef {
'/auth/register': { '/auth/register': {
'post': { 'post': {
body: INewUser body: NewUser
response: IUser response: UserProfile
} }
} }
'/auth/login': { '/auth/login': {
'post': { 'post': {
body: ICredentials body: Credentials
response: IUser response: UserProfile
} }
} }
'/auth/logout': { '/auth/logout': {

View File

@ -1,4 +1,4 @@
export interface IContext { export interface Context {
user?: { user?: {
id: number id: number
} }

View File

@ -1,9 +0,0 @@
type ILogFunction = (message: string, ...meta: any[]) => void
export interface ILogger {
error: ILogFunction
warn: ILogFunction
info: ILogFunction
debug: ILogFunction
verbose: ILogFunction
}

View File

@ -1,4 +0,0 @@
export interface IRole {
readonly id: number
readonly name: string
}

View File

@ -1,4 +1,4 @@
export interface ICredentials { export interface Credentials {
readonly username: string readonly username: string
readonly password: string readonly password: string
} }

View File

@ -1 +1 @@
export * from './ICredentials' export * from './Credentials'

View File

@ -1,25 +1,25 @@
import {createFilterProps} from './filterProps' import {createFilterProps} from './filterProps'
interface IEntity { interface Entity {
readonly id: number readonly id: number
} }
interface IPerson { interface Person {
readonly firstName: string readonly firstName: string
readonly lastName: string readonly lastName: string
} }
interface IPersonEntity extends IEntity, IPerson {} interface PersonEntity extends Entity, Person {}
describe('filterProps', () => { describe('filterProps', () => {
const p: IPersonEntity = { const p: PersonEntity = {
id: 1, id: 1,
firstName: 'John', firstName: 'John',
lastName: 'Smith', lastName: 'Smith',
} }
const filterProps = createFilterProps<IPerson>({ const filterProps = createFilterProps<Person>({
firstName: true, firstName: true,
lastName: true, lastName: true,
}) })

View File

@ -1,18 +1,15 @@
export * from './entities' export * from './APIDef'
export * from './IContext'
export * from './IAPIDef'
export * from './auth' export * from './auth'
export * from './ILogger' export * from './Context'
export * from './IRole' export * from './entities'
export * from './StringUtils'
export * from './filterProps' export * from './filterProps'
export * from './guard' export * from './guard'
export * from './indexBy' export * from './indexBy'
export * from './types' export * from './StringUtils'
export * from './without'
export * from './team' export * from './team'
export * from './types'
export * from './user' export * from './user'
export * from './without'
import * as entities from './entities' import * as entities from './entities'
export { entities } export { entities }

View File

@ -1,8 +1,7 @@
import {IContext} from './IContext' import {TeamService} from './team'
import {ITeamService} from './team' import {UserService} from './user'
import {IUserService} from './user'
export interface IRPCServices { export interface RPCServices {
userService: IUserService userService: UserService
teamService: ITeamService teamService: TeamService
} }

View File

@ -1,3 +0,0 @@
export interface ITeamCreateParams {
name: string
}

View File

@ -1,3 +0,0 @@
export interface ITeamRemoveParams {
id: number
}

View File

@ -1,30 +0,0 @@
import { RPCActions } from '@rondo.dev/jsonrpc'
import { keys } from 'ts-transformer-keys'
import { Team } from '../entities'
import { ITeamAddUserParams } from './ITeamAddUserParams'
import { ITeamCreateParams } from './ITeamCreateParams'
import { ITeamRemoveParams } from './ITeamRemoveParams'
import { ITeamUpdateParams } from './ITeamUpdateParams'
import { ITeamUsers } from './ITeamUsers'
import { IUserInTeam } from './IUserInTeam'
export interface ITeamService {
create(params: ITeamCreateParams): Promise<Team>
remove(params: ITeamRemoveParams): Promise<{id: number}>
update(params: ITeamUpdateParams): Promise<Team>
addUser(params: ITeamAddUserParams): Promise<IUserInTeam>
removeUser(params: ITeamAddUserParams): Promise<ITeamAddUserParams>
findOne(id: number): Promise<Team | undefined>
find(): Promise<Team[]>
findUsers(teamId: number): Promise<ITeamUsers>
}
export const TeamServiceMethods = keys<ITeamService>()
export type TeamActions = RPCActions<ITeamService, 'teamService'>

View File

@ -1,4 +0,0 @@
export interface ITeamUpdateParams {
id: number
name: string
}

View File

@ -1,6 +0,0 @@
import { IUserInTeam } from './IUserInTeam'
export interface ITeamUsers {
teamId: number
usersInTeam: IUserInTeam[]
}

View File

@ -1,4 +1,4 @@
export interface ITeamAddUserParams { export interface TeamAddUserParams {
teamId: number teamId: number
userId: number userId: number
roleId: number roleId: number

View File

@ -0,0 +1,3 @@
export interface TeamCreateParams {
name: string
}

View File

@ -0,0 +1,3 @@
export interface TeamRemoveParams {
id: number
}

View File

@ -0,0 +1,30 @@
import { RPCActions } from '@rondo.dev/jsonrpc'
import { keys } from 'ts-transformer-keys'
import { Team } from '../entities'
import { TeamAddUserParams } from './TeamAddUserParams'
import { TeamCreateParams } from './TeamCreateParams'
import { TeamRemoveParams } from './TeamRemoveParams'
import { TeamUpdateParams } from './TeamUpdateParams'
import { TeamUsers } from './TeamUsers'
import { UserInTeam } from './UserInTeam'
export interface TeamService {
create(params: TeamCreateParams): Promise<Team>
remove(params: TeamRemoveParams): Promise<{id: number}>
update(params: TeamUpdateParams): Promise<Team>
addUser(params: TeamAddUserParams): Promise<UserInTeam>
removeUser(params: TeamAddUserParams): Promise<TeamAddUserParams>
findOne(id: number): Promise<Team | undefined>
find(): Promise<Team[]>
findUsers(teamId: number): Promise<TeamUsers>
}
export const TeamServiceMethods = keys<TeamService>()
export type TeamActions = RPCActions<TeamService, 'teamService'>

View File

@ -0,0 +1,4 @@
export interface TeamUpdateParams {
id: number
name: string
}

View File

@ -0,0 +1,6 @@
import { UserInTeam } from './UserInTeam'
export interface TeamUsers {
teamId: number
usersInTeam: UserInTeam[]
}

View File

@ -1,4 +1,4 @@
export interface IUserInTeam { export interface UserInTeam {
teamId: number teamId: number
userId: number userId: number
displayName: string displayName: string

View File

@ -1,7 +1,7 @@
export * from './ITeamAddUserParams' export * from './TeamAddUserParams'
export * from './ITeamCreateParams' export * from './TeamCreateParams'
export * from './ITeamRemoveParams' export * from './TeamRemoveParams'
export * from './ITeamService' export * from './TeamService'
export * from './ITeamUpdateParams' export * from './TeamUpdateParams'
export * from './ITeamUsers' export * from './TeamUsers'
export * from './IUserInTeam' export * from './UserInTeam'

View File

@ -1,25 +1,25 @@
/** /**
* transform unknown into undefined * transform unknown into undefined
*/ */
export type TOptional<T> = T extends {} ? T : undefined export type Optional<T> = T extends {} ? T : undefined
export type TNonUndefinedPropertyNames<T> = { export type NonUndefinedPropertyNames<T> = {
[K in keyof T]: T[K] extends undefined ? never: K [K in keyof T]: T[K] extends undefined ? never: K
}[keyof T] }[keyof T]
export type TOnlyRequired<T> = Pick<T, TNonUndefinedPropertyNames<T>> export type OnlyRequired<T> = Pick<T, NonUndefinedPropertyNames<T>>
export type TNonUnknownPropertyNames<T> = { export type NonUnknownPropertyNames<T> = {
[K in keyof T]: T[K] extends {} ? K : never [K in keyof T]: T[K] extends {} ? K : never
}[keyof T] }[keyof T]
export type TOnlyDefined<T> = Pick<T, TNonUnknownPropertyNames<T>> export type OnlyDefined<T> = Pick<T, NonUnknownPropertyNames<T>>
/** /**
* Remove types from T that are not assignable to U * Remove types from T that are not assignable to U
* https://www.typescriptlang.org/docs/handbook/advanced-types.html * https://www.typescriptlang.org/docs/handbook/advanced-types.html
*/ */
export type TFilter<T, U> = T extends U ? T : never export type Filter<T, U> = T extends U ? T : never
export type TReadonlyRecord<K extends string | number | symbol, V> = export type ReadonlyRecord<K extends string | number | symbol, V> =
Readonly<Record<K, V>> Readonly<Record<K, V>>

View File

@ -1,6 +0,0 @@
import {ICredentials} from '../auth/ICredentials'
export interface INewUser extends ICredentials {
firstName: string
lastName: string
}

View File

@ -1,12 +0,0 @@
import { RPCActions } from '@rondo.dev/jsonrpc'
import { keys } from 'ts-transformer-keys'
import { IUser } from './IUser'
export interface IUserService {
getProfile(): Promise<IUser>
// TODO exposing search by email might be a security concern
findUserByEmail(email: string): Promise<IUser | undefined>
}
export const UserServiceMethods = keys<IUserService>()
export type UserActions = RPCActions<IUserService, 'userService'>

View File

@ -0,0 +1,6 @@
import {Credentials} from '../auth'
export interface NewUser extends Credentials {
firstName: string
lastName: string
}

View File

@ -1,4 +1,4 @@
export interface IUser { export interface UserProfile {
id: number id: number
username: string username: string
firstName: string firstName: string

View File

@ -0,0 +1,12 @@
import { RPCActions } from '@rondo.dev/jsonrpc'
import { keys } from 'ts-transformer-keys'
import { UserProfile } from './UserProfile'
export interface UserService {
getProfile(): Promise<UserProfile>
// TODO exposing search by email might be a security concern
findUserByEmail(email: string): Promise<UserProfile | undefined>
}
export const UserServiceMethods = keys<UserService>()
export type UserActions = RPCActions<UserService, 'userService'>

View File

@ -1,3 +1,3 @@
export * from './INewUser' export * from './NewUser'
export * from './IUserService' export * from './UserService'
export * from './IUser' export * from './UserProfile'

View File

@ -7,7 +7,7 @@ export function without<T, R extends Record<string, T>, K extends keyof R>(
if (key == k) { if (key == k) {
return obj return obj
} }
(obj as any)[k] = items[k] (obj as any)[k] = items[k] // eslint-disable-line
return obj return obj
}, {} as Pick<R, Exclude<keyof R, K>>) }, {} as Pick<R, Exclude<keyof R, K>>)
} }