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'
export interface IButtonProps {
type: string
export interface ButtonProps {
// type: string
}
export class Button extends React.PureComponent {
export class Button extends React.PureComponent<ButtonProps> {
render() {
return (
<button>{this.props.children}</button>

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
export interface IContext {
export interface Context {
user?: {
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 password: string
}

View File

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

View File

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

View File

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

View File

@ -1,8 +1,7 @@
import {IContext} from './IContext'
import {ITeamService} from './team'
import {IUserService} from './user'
import {TeamService} from './team'
import {UserService} from './user'
export interface IRPCServices {
userService: IUserService
teamService: ITeamService
export interface RPCServices {
userService: UserService
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
userId: 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
userId: number
displayName: string

View File

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

View File

@ -1,25 +1,25 @@
/**
* 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
}[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
}[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
* 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>>

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
username: 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 './IUserService'
export * from './IUser'
export * from './NewUser'
export * from './UserService'
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) {
return obj
}
(obj as any)[k] = items[k]
(obj as any)[k] = items[k] // eslint-disable-line
return obj
}, {} as Pick<R, Exclude<keyof R, K>>)
}