Fix packages/comments-common
This commit is contained in:
parent
7631f085ef
commit
73c27aec6a
@ -1,7 +1,7 @@
|
|||||||
import {relative} from 'path'
|
import {relative} from 'path'
|
||||||
|
|
||||||
export type TArgTypeName = 'string' | 'string[]' | 'number' | 'boolean'
|
export type ArgTypeName = 'string' | 'string[]' | 'number' | 'boolean'
|
||||||
export type TArgType<T extends TArgTypeName> =
|
export type ArgType<T extends ArgTypeName> =
|
||||||
T extends 'string'
|
T extends 'string'
|
||||||
? string
|
? string
|
||||||
: T extends 'string[]'
|
: T extends 'string[]'
|
||||||
@ -16,29 +16,29 @@ export const N_ONE_OR_MORE = '+'
|
|||||||
export const N_ZERO_OR_MORE = '*'
|
export const N_ZERO_OR_MORE = '*'
|
||||||
export const N_DEFAULT_VALUE = 1
|
export const N_DEFAULT_VALUE = 1
|
||||||
|
|
||||||
export type TNumberOfArgs = number | '+' | '*'
|
export type NumberOfArgs = number | '+' | '*'
|
||||||
|
|
||||||
export interface ArgParam<T extends TArgTypeName> {
|
export interface ArgParam<T extends ArgTypeName> {
|
||||||
alias?: string
|
alias?: string
|
||||||
description?: string
|
description?: string
|
||||||
default?: TArgType<T>
|
default?: ArgType<T>
|
||||||
choices?: Array<TArgType<T>>
|
choices?: Array<ArgType<T>>
|
||||||
required?: boolean
|
required?: boolean
|
||||||
positional?: boolean
|
positional?: boolean
|
||||||
n?: TNumberOfArgs
|
n?: NumberOfArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Argument<T extends TArgTypeName> extends ArgParam<T> {
|
export interface Argument<T extends ArgTypeName> extends ArgParam<T> {
|
||||||
type: T
|
type: T
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ArgsConfig {
|
export interface ArgsConfig {
|
||||||
[arg: string]: Argument<TArgTypeName>
|
[arg: string]: Argument<ArgTypeName>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TArgs<T extends ArgsConfig> = {
|
export type Args<T extends ArgsConfig> = {
|
||||||
[k in keyof T]: T[k] extends Argument<infer A> ?
|
[k in keyof T]: T[k] extends Argument<infer A> ?
|
||||||
TArgType<A> : never
|
ArgType<A> : never
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Iterator<T> {
|
interface Iterator<T> {
|
||||||
@ -72,7 +72,7 @@ function assert(cond: boolean, message: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultValue(type: TArgTypeName) {
|
function getDefaultValue(type: ArgTypeName) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'number':
|
case 'number':
|
||||||
return NaN
|
return NaN
|
||||||
@ -133,7 +133,7 @@ function extractArray(
|
|||||||
it: Iterator<string>,
|
it: Iterator<string>,
|
||||||
argument: string,
|
argument: string,
|
||||||
isPositional: boolean,
|
isPositional: boolean,
|
||||||
n: TNumberOfArgs = N_DEFAULT_VALUE,
|
n: NumberOfArgs = N_DEFAULT_VALUE,
|
||||||
): string[] {
|
): string[] {
|
||||||
function getLimit() {
|
function getLimit() {
|
||||||
const l = typeof n === 'number' ? n : Infinity
|
const l = typeof n === 'number' ? n : Infinity
|
||||||
@ -173,7 +173,7 @@ function help(command: string, config: ArgsConfig, desc = '') {
|
|||||||
function getArrayHelp(
|
function getArrayHelp(
|
||||||
k: string,
|
k: string,
|
||||||
required?: boolean,
|
required?: boolean,
|
||||||
n: TNumberOfArgs = N_DEFAULT_VALUE,
|
n: NumberOfArgs = N_DEFAULT_VALUE,
|
||||||
) {
|
) {
|
||||||
k = k.toUpperCase()
|
k = k.toUpperCase()
|
||||||
if (n === N_ZERO_OR_MORE) {
|
if (n === N_ZERO_OR_MORE) {
|
||||||
@ -194,7 +194,7 @@ function help(command: string, config: ArgsConfig, desc = '') {
|
|||||||
return required ? array.join(' ') : `[${array.join(' ')}]`
|
return required ? array.join(' ') : `[${array.join(' ')}]`
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDescription(argConfig: Argument<TArgTypeName>): string {
|
function getDescription(argConfig: Argument<ArgTypeName>): string {
|
||||||
const samples = []
|
const samples = []
|
||||||
if (argConfig.required) {
|
if (argConfig.required) {
|
||||||
samples.push('required')
|
samples.push('required')
|
||||||
@ -218,7 +218,7 @@ function help(command: string, config: ArgsConfig, desc = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getArgType(
|
function getArgType(
|
||||||
type: TArgTypeName, argument: string, required?: boolean, n?: TNumberOfArgs,
|
type: ArgTypeName, argument: string, required?: boolean, n?: NumberOfArgs,
|
||||||
): string {
|
): string {
|
||||||
return type === 'string[]'
|
return type === 'string[]'
|
||||||
? getArrayHelp(argument, required, n)
|
? getArrayHelp(argument, required, n)
|
||||||
@ -272,7 +272,7 @@ function help(command: string, config: ArgsConfig, desc = '') {
|
|||||||
.join('\n\n')
|
.join('\n\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function arg<T extends TArgTypeName>(
|
export function arg<T extends ArgTypeName>(
|
||||||
type: T,
|
type: T,
|
||||||
config: ArgParam<T> = {},
|
config: ArgParam<T> = {},
|
||||||
): Argument<T> {
|
): Argument<T> {
|
||||||
@ -290,7 +290,7 @@ export function argparse<T extends ArgsConfig>(
|
|||||||
log: (message: string) => void = console.log.bind(console),
|
log: (message: string) => void = console.log.bind(console),
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
parse(args: string[]): TArgs<T> {
|
parse(args: string[]): Args<T> {
|
||||||
const command = args[0]
|
const command = args[0]
|
||||||
args = args.slice(1)
|
args = args.slice(1)
|
||||||
const result: any = {} // eslint-disable-line
|
const result: any = {} // eslint-disable-line
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
// export * from './Component'
|
// export * from './Component'
|
||||||
export * from './Button'
|
export * from './Button'
|
||||||
export * from './IWithRouterProps'
|
|
||||||
export * from './Input'
|
export * from './Input'
|
||||||
export * from './Link'
|
export * from './Link'
|
||||||
export * from './Modal'
|
export * from './Modal'
|
||||||
@ -8,3 +7,4 @@ export * from './Redirect'
|
|||||||
export * from './ReturnHere'
|
export * from './ReturnHere'
|
||||||
export * from './TimeAgo'
|
export * from './TimeAgo'
|
||||||
export * from './withHistory'
|
export * from './withHistory'
|
||||||
|
export * from './WithRouterProps'
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import {Control, Field, Heading, Icon, Input} from 'bloomer'
|
import {Control, Field, Heading, Icon, Input} from 'bloomer'
|
||||||
import {CRUDChangeParams} from './CRUDActions'
|
import {CRUDChangeParams} from './CRUDActions'
|
||||||
|
|
||||||
export type TCRUDFieldType = 'text' | 'password' | 'number' | 'email' | 'tel'
|
export type CRUDFieldType = 'text' | 'password' | 'number' | 'email' | 'tel'
|
||||||
|
|
||||||
export interface CRUDFieldProps<T> {
|
export interface CRUDFieldProps<T> {
|
||||||
id?: number
|
id?: number
|
||||||
@ -12,22 +12,22 @@ export interface CRUDFieldProps<T> {
|
|||||||
label: string
|
label: string
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
name: keyof T & string
|
name: keyof T & string
|
||||||
type: TCRUDFieldType
|
type: CRUDFieldType
|
||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TCRUDErrors<T> = Partial<Record<keyof T & string, string>>
|
export type CRUDErrors<T> = Partial<Record<keyof T & string, string>>
|
||||||
|
|
||||||
export interface CRUDField<T> {
|
export interface CRUDField<T> {
|
||||||
Icon?: React.ComponentType
|
Icon?: React.ComponentType
|
||||||
label: string
|
label: string
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
name: keyof T & string
|
name: keyof T & string
|
||||||
type: TCRUDFieldType
|
type: CRUDFieldType
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CRUDFormProps<T> {
|
export interface CRUDFormProps<T> {
|
||||||
errors: TCRUDErrors<T>
|
errors: CRUDErrors<T>
|
||||||
id?: number
|
id?: number
|
||||||
item?: T
|
item?: T
|
||||||
error: string
|
error: string
|
||||||
|
|||||||
@ -15,10 +15,10 @@ export interface CRUDState<T extends CRUDEntity> {
|
|||||||
readonly ids: ReadonlyArray<number>
|
readonly ids: ReadonlyArray<number>
|
||||||
readonly byId: Record<number, T>
|
readonly byId: Record<number, T>
|
||||||
readonly status: CRUDStatus
|
readonly status: CRUDStatus
|
||||||
readonly form: CRUDForm<T>
|
readonly form: CRUDFormState<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CRUDForm<T extends CRUDEntity> {
|
export interface CRUDFormState<T extends CRUDEntity> {
|
||||||
readonly createItem: Pick<T, Exclude<keyof T, 'id'>>
|
readonly createItem: Pick<T, Exclude<keyof T, 'id'>>
|
||||||
readonly createErrors: Partial<Record<keyof T, string>>
|
readonly createErrors: Partial<Record<keyof T, string>>
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
|
import { Breadcrumb, BreadcrumbItem } from 'bloomer'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {Breadcrumb, BreadcrumbItem} from 'bloomer'
|
import { Link } from 'react-router-dom'
|
||||||
import {Link} from 'react-router-dom'
|
import { CrumbLink } from './CrumbLink'
|
||||||
import {CrumbLink} from './CrumbLink'
|
|
||||||
|
|
||||||
export interface CrumbProps {
|
export interface CrumbProps {
|
||||||
links: CrumbLink[]
|
links: CrumbLink[]
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {Crumb} from './Crumb'
|
import { MemoryRouter } from 'react-router-dom'
|
||||||
import {TestUtils} from '../test-utils'
|
import { TestUtils } from '../test-utils'
|
||||||
import {MemoryRouter} from 'react-router-dom'
|
import { Crumb } from './Crumb'
|
||||||
|
|
||||||
const t = new TestUtils()
|
const t = new TestUtils()
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,10 @@
|
|||||||
import {GetAllActions, Action} from '@rondo.dev/redux'
|
import { Action, GetAllActions } from '@rondo.dev/redux'
|
||||||
import {CrumbLink} from './CrumbLink'
|
import { CrumbsState } from './CrumbsState'
|
||||||
|
|
||||||
export interface Crumbs {
|
|
||||||
links: CrumbLink[]
|
|
||||||
current: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CrumbsAction = GetAllActions<CrumbsActions>
|
export type CrumbsAction = GetAllActions<CrumbsActions>
|
||||||
|
|
||||||
export class CrumbsActions {
|
export class CrumbsActions {
|
||||||
setCrumbs(breadcrumbs: Crumbs): Action<Crumbs, 'BREADCRUMBS_SET'> {
|
setCrumbs(breadcrumbs: CrumbsState): Action<CrumbsState, 'BREADCRUMBS_SET'> {
|
||||||
return {
|
return {
|
||||||
payload: breadcrumbs,
|
payload: breadcrumbs,
|
||||||
type: 'BREADCRUMBS_SET',
|
type: 'BREADCRUMBS_SET',
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import {Crumbs, CrumbsAction} from './CrumbsActions'
|
import { CrumbsAction } from './CrumbsActions'
|
||||||
|
import { CrumbsState } from './CrumbsState'
|
||||||
export interface CrumbsState extends Crumbs {
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultState: CrumbsState = {
|
const defaultState: CrumbsState = {
|
||||||
links: [],
|
links: [],
|
||||||
|
|||||||
6
packages/client/src/crumbs/CrumbsState.ts
Normal file
6
packages/client/src/crumbs/CrumbsState.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { CrumbLink } from "./CrumbLink";
|
||||||
|
|
||||||
|
export interface CrumbsState {
|
||||||
|
links: CrumbLink[]
|
||||||
|
current: string
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import * as Feature from './'
|
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {MemoryRouter} from 'react-router-dom'
|
import { MemoryRouter } from 'react-router-dom'
|
||||||
import {TestUtils} from '../test-utils'
|
import { TestUtils } from '../test-utils'
|
||||||
|
import * as Feature from './'
|
||||||
|
|
||||||
const t = new TestUtils()
|
const t = new TestUtils()
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { pack, TStateSelector } from '@rondo.dev/redux'
|
import { pack, SelectState } from '@rondo.dev/redux'
|
||||||
import { Crumb } from './Crumb'
|
import { Crumb } from './Crumb'
|
||||||
import { ICrumbsState } from './CrumbsReducer'
|
import { CrumbsState } from './CrumbsState'
|
||||||
|
|
||||||
export function configureCrumbs<State>(
|
export function configureCrumbs<State>(
|
||||||
getLocalState: TStateSelector<State, ICrumbsState>,
|
getLocalState: SelectState<State, CrumbsState>,
|
||||||
) {
|
) {
|
||||||
return pack(
|
return pack(
|
||||||
getLocalState,
|
getLocalState,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
export * from './configureCrumbs'
|
export * from './configureCrumbs'
|
||||||
export * from './Crumb'
|
export * from './Crumb'
|
||||||
|
export * from './CrumbLink'
|
||||||
export * from './CrumbsActions'
|
export * from './CrumbsActions'
|
||||||
export * from './CrumbsReducer'
|
export * from './CrumbsReducer'
|
||||||
|
export * from './CrumbsState'
|
||||||
export * from './HistoryCrumbs'
|
export * from './HistoryCrumbs'
|
||||||
export * from './CrumbLink'
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ export * from './crud'
|
|||||||
export * from './crumbs'
|
export * from './crumbs'
|
||||||
export * from './csrf'
|
export * from './csrf'
|
||||||
export * from './login'
|
export * from './login'
|
||||||
export * from './redux'
|
|
||||||
export * from './renderer'
|
export * from './renderer'
|
||||||
export * from './test-utils'
|
export * from './test-utils'
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
import { APIDef, Credentials, NewUser, UserProfile } from '@rondo.dev/common'
|
import { APIDef, Credentials, NewUser, UserProfile } from '@rondo.dev/common'
|
||||||
import { HTTPClient } from '@rondo.dev/http-client'
|
import { HTTPClient } from '@rondo.dev/http-client'
|
||||||
import { Action, AsyncAction, createPendingAction, TGetAction } from '@rondo.dev/redux'
|
import { Action, AsyncAction, createPendingAction, GetAction } from '@rondo.dev/redux'
|
||||||
|
|
||||||
export type TLoginAction =
|
export type LoginAction =
|
||||||
AsyncAction<UserProfile, 'LOGIN'>
|
AsyncAction<UserProfile, 'LOGIN'>
|
||||||
| AsyncAction<unknown, 'LOGIN_LOGOUT'>
|
| AsyncAction<unknown, 'LOGIN_LOGOUT'>
|
||||||
| AsyncAction<UserProfile, 'LOGIN_REGISTER'>
|
| AsyncAction<UserProfile, 'LOGIN_REGISTER'>
|
||||||
| Action<{redirectTo: string}, 'LOGIN_REDIRECT_SET'>
|
| Action<{redirectTo: string}, 'LOGIN_REDIRECT_SET'>
|
||||||
|
|
||||||
type TAction<T extends string> = TGetAction<TLoginAction, T>
|
type A<T extends string> = GetAction<LoginAction, T>
|
||||||
|
|
||||||
export const setRedirectTo = (
|
export const setRedirectTo = (
|
||||||
redirectTo: string,
|
redirectTo: string,
|
||||||
): Action<{redirectTo: string}, 'LOGIN_REDIRECT_SET'> => {
|
): A<'LOGIN_REDIRECT_SET'> => {
|
||||||
return {
|
return {
|
||||||
payload: {redirectTo},
|
payload: {redirectTo},
|
||||||
type: 'LOGIN_REDIRECT_SET',
|
type: 'LOGIN_REDIRECT_SET',
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import {UserProfile} from '@rondo.dev/common'
|
import {UserProfile} from '@rondo.dev/common'
|
||||||
import {TLoginAction} from './LoginActions'
|
import {LoginAction} from './LoginActions'
|
||||||
|
|
||||||
export interface LoginState {
|
export interface LoginState {
|
||||||
readonly error: string
|
readonly error: string
|
||||||
@ -17,7 +17,7 @@ const defaultState: LoginState = {
|
|||||||
|
|
||||||
export function Login(
|
export function Login(
|
||||||
state = defaultState,
|
state = defaultState,
|
||||||
action: TLoginAction,
|
action: LoginAction,
|
||||||
): LoginState {
|
): LoginState {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
// sync actions
|
// sync actions
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { Credentials } from '@rondo.dev/common'
|
import { Credentials } from '@rondo.dev/common'
|
||||||
import { pack, TStateSelector } from '@rondo.dev/redux'
|
import { pack, SelectState } from '@rondo.dev/redux'
|
||||||
import { bindActionCreators } from 'redux'
|
import { bindActionCreators } from 'redux'
|
||||||
import { LoginActions } from './LoginActions'
|
import { LoginActions } from './LoginActions'
|
||||||
import { LoginForm } from './LoginForm'
|
import { LoginForm } from './LoginForm'
|
||||||
import { ILoginState } from './LoginReducer'
|
import { LoginState } from './LoginReducer'
|
||||||
import { withForm } from './withForm'
|
import { withForm } from './withForm'
|
||||||
|
|
||||||
const defaultCredentials: Credentials = {
|
const defaultCredentials: Credentials = {
|
||||||
@ -12,7 +12,7 @@ const defaultCredentials: Credentials = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function configureLogin<State>(
|
export function configureLogin<State>(
|
||||||
getLocalState: TStateSelector<State, ILoginState>,
|
getLocalState: SelectState<State, LoginState>,
|
||||||
loginActions: LoginActions,
|
loginActions: LoginActions,
|
||||||
) {
|
) {
|
||||||
return pack(
|
return pack(
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
import { INewUser } from '@rondo.dev/common'
|
import { NewUser } from '@rondo.dev/common'
|
||||||
import { pack, TStateSelector } from '@rondo.dev/redux'
|
import { pack, SelectState } from '@rondo.dev/redux'
|
||||||
import { bindActionCreators } from 'redux'
|
import { bindActionCreators } from 'redux'
|
||||||
import { LoginActions } from './LoginActions'
|
import { LoginActions } from './LoginActions'
|
||||||
import { ILoginState } from './LoginReducer'
|
import { LoginState } from './LoginReducer'
|
||||||
import { RegisterForm } from './RegisterForm'
|
import { RegisterForm } from './RegisterForm'
|
||||||
import { withForm } from './withForm'
|
import { withForm } from './withForm'
|
||||||
|
|
||||||
const defaultCredentials: INewUser = {
|
const defaultCredentials: NewUser = {
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
firstName: '',
|
firstName: '',
|
||||||
@ -14,7 +14,7 @@ const defaultCredentials: INewUser = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function configureRegister<State>(
|
export function configureRegister<State>(
|
||||||
getLocalState: TStateSelector<State, ILoginState>,
|
getLocalState: SelectState<State, LoginState>,
|
||||||
loginActions: LoginActions,
|
loginActions: LoginActions,
|
||||||
) {
|
) {
|
||||||
return pack(
|
return pack(
|
||||||
|
|||||||
@ -5,14 +5,14 @@ import { StaticRouterContext } from 'react-router'
|
|||||||
import { StaticRouter } from 'react-router-dom'
|
import { StaticRouter } from 'react-router-dom'
|
||||||
import ssrPrepass from 'react-ssr-prepass'
|
import ssrPrepass from 'react-ssr-prepass'
|
||||||
import { Store } from 'redux'
|
import { Store } from 'redux'
|
||||||
import { IClientConfig } from './IClientConfig'
|
import { ClientConfig } from './ClientConfig'
|
||||||
import { IRenderer } from './IRenderer'
|
import { Renderer } from './Renderer'
|
||||||
|
|
||||||
interface ComponentWithFetchData {
|
interface ComponentWithFetchData {
|
||||||
fetchData(): Promise<unknown>
|
fetchData(): Promise<unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ServerRenderer<Props> implements IRenderer<Props> {
|
export class ServerRenderer<Props> implements Renderer<Props> {
|
||||||
constructor(
|
constructor(
|
||||||
readonly RootComponent: React.ComponentType<Props>,
|
readonly RootComponent: React.ComponentType<Props>,
|
||||||
) {}
|
) {}
|
||||||
@ -20,7 +20,7 @@ export class ServerRenderer<Props> implements IRenderer<Props> {
|
|||||||
url: string,
|
url: string,
|
||||||
store: Store<State>,
|
store: Store<State>,
|
||||||
props: Props,
|
props: Props,
|
||||||
config: IClientConfig,
|
config: ClientConfig,
|
||||||
host = '',
|
host = '',
|
||||||
headers: Record<string, string> = {},
|
headers: Record<string, string> = {},
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ interface UpdateTeamProps {
|
|||||||
team: Team
|
team: Team
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TTeamEditorProps = AddTeamProps | UpdateTeamProps
|
export type TeamEditorProps = AddTeamProps | UpdateTeamProps
|
||||||
|
|
||||||
export interface TeamEditorState {
|
export interface TeamEditorState {
|
||||||
// TODO use redux state for errors!
|
// TODO use redux state for errors!
|
||||||
@ -23,8 +23,8 @@ export interface TeamEditorState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TeamEditor
|
export class TeamEditor
|
||||||
extends React.PureComponent<TTeamEditorProps, TeamEditorState> {
|
extends React.PureComponent<TeamEditorProps, TeamEditorState> {
|
||||||
constructor(props: TTeamEditorProps) {
|
constructor(props: TeamEditorProps) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
error: '',
|
error: '',
|
||||||
@ -34,7 +34,7 @@ extends React.PureComponent<TTeamEditorProps, TeamEditorState> {
|
|||||||
getName(team?: Team) {
|
getName(team?: Team) {
|
||||||
return team ? team.name : ''
|
return team ? team.name : ''
|
||||||
}
|
}
|
||||||
componentWillReceiveProps(nextProps: TTeamEditorProps) {
|
componentWillReceiveProps(nextProps: TeamEditorProps) {
|
||||||
if (nextProps.type === 'update') {
|
if (nextProps.type === 'update') {
|
||||||
const {team} = nextProps
|
const {team} = nextProps
|
||||||
if (team !== (this.props as UpdateTeamProps).team) {
|
if (team !== (this.props as UpdateTeamProps).team) {
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { TeamActions, UserActions } from '@rondo.dev/common'
|
import { TeamActions, UserActions } from '@rondo.dev/common'
|
||||||
import { bindActionCreators, pack, TStateSelector } from '@rondo.dev/redux'
|
import { bindActionCreators, pack, SelectState } from '@rondo.dev/redux'
|
||||||
import { TeamManager } from './TeamManager'
|
import { TeamManager } from './TeamManager'
|
||||||
import { ITeamState } from './TeamReducer'
|
import { TeamState } from './TeamReducer'
|
||||||
|
|
||||||
export function configureTeam<State>(
|
export function configureTeam<State>(
|
||||||
getLocalState: TStateSelector<State, ITeamState>,
|
getLocalState: SelectState<State, TeamState>,
|
||||||
teamActions: TeamActions,
|
teamActions: TeamActions,
|
||||||
userActions: UserActions,
|
userActions: UserActions,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/* eslint @typescript-eslint/no-explicit-any: 0 */
|
/* eslint @typescript-eslint/no-explicit-any: 0 */
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import {createStore, TStateSelector, WaitMiddleware} from '@rondo.dev/redux'
|
import {createStore, SelectState, WaitMiddleware} from '@rondo.dev/redux'
|
||||||
import {Provider} from 'react-redux'
|
import {Provider} from 'react-redux'
|
||||||
import {
|
import {
|
||||||
Action,
|
Action,
|
||||||
@ -14,7 +14,7 @@ import {
|
|||||||
|
|
||||||
interface RenderParams<State, LocalState> {
|
interface RenderParams<State, LocalState> {
|
||||||
reducers: ReducersMapObject<State, any>
|
reducers: ReducersMapObject<State, any>
|
||||||
select: TStateSelector<State, LocalState>
|
select: SelectState<State, LocalState>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TestContainer extends React.Component<{}> {
|
export class TestContainer extends React.Component<{}> {
|
||||||
@ -74,7 +74,7 @@ export class TestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const withComponent = <Props extends {}>(
|
const withComponent = <Props extends {}>(
|
||||||
getComponent: (select: TStateSelector<State, LocalState>) =>
|
getComponent: (select: SelectState<State, LocalState>) =>
|
||||||
React.ComponentType<Props>,
|
React.ComponentType<Props>,
|
||||||
) => {
|
) => {
|
||||||
const Component = getComponent(select)
|
const Component = getComponent(select)
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { IDEMPOTENT_METHOD_REGEX } from './idempotent'
|
|||||||
import { createRpcService, ERROR_METHOD_NOT_FOUND, ERROR_SERVER, Request as RPCRequest, SuccessResponse } from './jsonrpc'
|
import { createRpcService, ERROR_METHOD_NOT_FOUND, ERROR_SERVER, Request as RPCRequest, SuccessResponse } from './jsonrpc'
|
||||||
import { FunctionPropertyNames } from './types'
|
import { FunctionPropertyNames } from './types'
|
||||||
|
|
||||||
export type TGetContext<Context> = (req: Request) => Promise<Context> | Context
|
export type GetContext<Context> = (req: Request) => Promise<Context> | Context
|
||||||
|
|
||||||
export interface RPCReturnType {
|
export interface RPCReturnType {
|
||||||
addService<T, F extends FunctionPropertyNames<T>>(
|
addService<T, F extends FunctionPropertyNames<T>>(
|
||||||
@ -31,7 +31,7 @@ async function defaultHook<A extends RPCRequest, R, Context>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function jsonrpc<Context>(
|
export function jsonrpc<Context>(
|
||||||
getContext: TGetContext<Context>,
|
getContext: GetContext<Context>,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
hook: <A extends RPCRequest, R>(
|
hook: <A extends RPCRequest, R>(
|
||||||
details: InvocationDetails<A, Context>,
|
details: InvocationDetails<A, Context>,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export type TId = number | string
|
export type Id = number | string
|
||||||
import {ArgumentTypes, FunctionPropertyNames, RetType} from './types'
|
import {ArgumentTypes, FunctionPropertyNames, RetType} from './types'
|
||||||
import {isPromise} from './isPromise'
|
import {isPromise} from './isPromise'
|
||||||
import {createError, ErrorResponse} from './error'
|
import {createError, ErrorResponse} from './error'
|
||||||
@ -63,14 +63,14 @@ export function getAllMethods<T>(obj: T): Array<FunctionPropertyNames<T>> {
|
|||||||
|
|
||||||
export interface Request<M extends string = any, A = any[]> {
|
export interface Request<M extends string = any, A = any[]> {
|
||||||
jsonrpc: '2.0'
|
jsonrpc: '2.0'
|
||||||
id: TId | null
|
id: Id | null
|
||||||
method: M
|
method: M
|
||||||
params: A
|
params: A
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SuccessResponse<T> {
|
export interface SuccessResponse<T> {
|
||||||
jsonrpc: '2.0'
|
jsonrpc: '2.0'
|
||||||
id: TId
|
id: Id
|
||||||
result: T
|
result: T
|
||||||
error: null
|
error: null
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,4 @@
|
|||||||
import {
|
import { AllActions, ResolvedActions, RPCActions, RPCActionsRecord, RPCClient, RPCReduxHandlers } from './types'
|
||||||
RPCActions,
|
|
||||||
RPCClient,
|
|
||||||
TResolvedActions,
|
|
||||||
TAllActions,
|
|
||||||
RPCReduxHandlers,
|
|
||||||
RPCActionsRecord,
|
|
||||||
} from './types'
|
|
||||||
|
|
||||||
export function createActions<T, ActionType extends string>(
|
export function createActions<T, ActionType extends string>(
|
||||||
client: RPCClient<T>,
|
client: RPCClient<T>,
|
||||||
@ -40,9 +33,9 @@ export function createReducer<
|
|||||||
|
|
||||||
const self = {
|
const self = {
|
||||||
withHandler<R extends RPCActionsRecord<ActionType>>(
|
withHandler<R extends RPCActionsRecord<ActionType>>(
|
||||||
handleAction: (state: State, action: TResolvedActions<R>) => State,
|
handleAction: (state: State, action: ResolvedActions<R>) => State,
|
||||||
): (state: State | undefined, action: TAllActions<R>) => State {
|
): (state: State | undefined, action: AllActions<R>) => State {
|
||||||
return (state: State = defaultState, action: TAllActions<R>): State => {
|
return (state: State = defaultState, action: AllActions<R>): State => {
|
||||||
if (action.type !== actionType) {
|
if (action.type !== actionType) {
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import Axios from 'axios'
|
|||||||
import {FunctionPropertyNames, RPCClient} from './types'
|
import {FunctionPropertyNames, RPCClient} from './types'
|
||||||
import {IDEMPOTENT_METHOD_REGEX} from './idempotent'
|
import {IDEMPOTENT_METHOD_REGEX} from './idempotent'
|
||||||
|
|
||||||
export type TRequestIdGenerator<T extends string | number> = () => T
|
export type GenerateRequestId<T extends string | number> = () => T
|
||||||
|
|
||||||
export const createNumberGenerator = (val: number) => () => ++val
|
export const createNumberGenerator = (val: number) => () => ++val
|
||||||
export const constantId = (val: string) => () => val
|
export const constantId = (val: string) => () => val
|
||||||
@ -11,7 +11,7 @@ export function createRemoteClient<T>(
|
|||||||
url: string,
|
url: string,
|
||||||
methods: Array<FunctionPropertyNames<T>>,
|
methods: Array<FunctionPropertyNames<T>>,
|
||||||
headers: Record<string, string> = {},
|
headers: Record<string, string> = {},
|
||||||
getNextRequestId: TRequestIdGenerator<string | number> = constantId('c'),
|
getNextRequestId: GenerateRequestId<string | number> = constantId('c'),
|
||||||
idempotentMethodRegex = IDEMPOTENT_METHOD_REGEX,
|
idempotentMethodRegex = IDEMPOTENT_METHOD_REGEX,
|
||||||
) {
|
) {
|
||||||
const axios = Axios.create()
|
const axios = Axios.create()
|
||||||
|
|||||||
@ -72,7 +72,7 @@ export interface RPCRejectedAction<
|
|||||||
method: Method
|
method: Method
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TRPCAction<
|
export type RPCAction<
|
||||||
T, ActionType extends string, Method extends string | number | symbol
|
T, ActionType extends string, Method extends string | number | symbol
|
||||||
> =
|
> =
|
||||||
RPCPendingAction<T, ActionType, Method>
|
RPCPendingAction<T, ActionType, Method>
|
||||||
@ -95,7 +95,7 @@ export type GetPendingAction<A> =
|
|||||||
: never
|
: never
|
||||||
|
|
||||||
type Values<T> = T[keyof T]
|
type Values<T> = T[keyof T]
|
||||||
export type TPendingActions<T> = GetPendingAction<RetType<Values<T>>>
|
export type PendingActions<T> = GetPendingAction<RetType<Values<T>>>
|
||||||
export type TResolvedActions<T> = GetResolvedAction<TPendingActions<T>>
|
export type ResolvedActions<T> = GetResolvedAction<PendingActions<T>>
|
||||||
export type TAllActions<T> = TPendingActions<T>
|
export type AllActions<T> = PendingActions<T>
|
||||||
| TResolvedActions<T> | GetRejectedAction<TPendingActions<T>>
|
| ResolvedActions<T> | GetRejectedAction<PendingActions<T>>
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import {PendingAction} from './PendingAction'
|
|||||||
import {ResolvedAction} from './ResolvedAction'
|
import {ResolvedAction} from './ResolvedAction'
|
||||||
import {RejectedAction} from './RejectedAction'
|
import {RejectedAction} from './RejectedAction'
|
||||||
|
|
||||||
export type TAsyncStatus = 'pending' | 'resolved' | 'rejected'
|
export type AsyncStatus = 'pending' | 'resolved' | 'rejected'
|
||||||
|
|
||||||
export type AsyncAction<T, ActionType extends string> =
|
export type AsyncAction<T, ActionType extends string> =
|
||||||
PendingAction<T, ActionType>
|
PendingAction<T, ActionType>
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'
|
|||||||
import TestUtils from 'react-dom/test-utils'
|
import TestUtils from 'react-dom/test-utils'
|
||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
import { createStore } from 'redux'
|
import { createStore } from 'redux'
|
||||||
import { pack, TStateSelector } from './pack'
|
import { pack, SelectState } from './pack'
|
||||||
|
|
||||||
describe('pack', () => {
|
describe('pack', () => {
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ describe('pack', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configurePureComponent<State>(
|
function configurePureComponent<State>(
|
||||||
getLocalState: TStateSelector<State, LocalState>,
|
getLocalState: SelectState<State, LocalState>,
|
||||||
) {
|
) {
|
||||||
return pack(
|
return pack(
|
||||||
getLocalState,
|
getLocalState,
|
||||||
@ -85,7 +85,7 @@ describe('pack', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configureFunctionalComponent<State>(
|
function configureFunctionalComponent<State>(
|
||||||
getLocalState: TStateSelector<State, LocalState>,
|
getLocalState: SelectState<State, LocalState>,
|
||||||
) {
|
) {
|
||||||
return pack(
|
return pack(
|
||||||
getLocalState,
|
getLocalState,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { connect, GetProps, MapDispatchToPropsParam, Matching, ResolveThunks } f
|
|||||||
/*
|
/*
|
||||||
* Select and return a part of the state
|
* Select and return a part of the state
|
||||||
*/
|
*/
|
||||||
export type TStateSelector<GlobalState, StateSlice>
|
export type SelectState<GlobalState, StateSlice>
|
||||||
= (state: GlobalState) => StateSlice
|
= (state: GlobalState) => StateSlice
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,7 +37,7 @@ export function pack<
|
|||||||
C extends React.ComponentType<
|
C extends React.ComponentType<
|
||||||
Matching<StateProps & ResolveThunks<DispatchProps>, GetProps<C>>>
|
Matching<StateProps & ResolveThunks<DispatchProps>, GetProps<C>>>
|
||||||
>(
|
>(
|
||||||
getLocalState: TStateSelector<State, LocalState>,
|
getLocalState: SelectState<State, LocalState>,
|
||||||
mapStateToProps: (state: LocalState) => StateProps,
|
mapStateToProps: (state: LocalState) => StateProps,
|
||||||
mapDispatchToProps: MapDispatchToPropsParam<DispatchProps, Props>,
|
mapDispatchToProps: MapDispatchToPropsParam<DispatchProps, Props>,
|
||||||
Component: C,
|
Component: C,
|
||||||
|
|||||||
1
packages/scripts/src/Command.ts
Normal file
1
packages/scripts/src/Command.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export type Command = (...argv: string[]) => unknown
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import {StdioOptions} from './Subprocess'
|
import { StdioOptions, Subprocess } from './Subprocess'
|
||||||
import {Subprocess} from './Subprocess'
|
|
||||||
|
|
||||||
describe('Subprocess', () => {
|
describe('Subprocess', () => {
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import {spawn} from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
|
|
||||||
export enum StdioOptions {
|
export enum StdioOptions {
|
||||||
PIPE = 'pipe',
|
PIPE = 'pipe',
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
export type TCommand = (...argv: string[]) => unknown
|
|
||||||
@ -1,13 +1,13 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
import { arg, argparse } from '@rondo.dev/argparse'
|
||||||
|
import { Command } from './Command'
|
||||||
import * as log from './log'
|
import * as log from './log'
|
||||||
import {TCommand} from './TCommand'
|
import { resolve } from './resolve'
|
||||||
import {argparse, arg} from '@rondo.dev/argparse'
|
|
||||||
import {resolve} from './resolve'
|
|
||||||
|
|
||||||
async function run(
|
async function run(
|
||||||
commandName: string,
|
commandName: string,
|
||||||
commandArgs: string[],
|
commandArgs: string[],
|
||||||
commands: Record<string, TCommand>,
|
commands: Record<string, Command>,
|
||||||
exit: (code: number) => void,
|
exit: (code: number) => void,
|
||||||
) {
|
) {
|
||||||
if (!(commandName in commands)) {
|
if (!(commandName in commands)) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import {getPathVariable, getPathSeparator, findNodeModules} from './modules'
|
import { platform } from 'os'
|
||||||
import {platform} from 'os'
|
import { findNodeModules, getPathSeparator, getPathVariable } from './modules'
|
||||||
|
|
||||||
describe('modules', () => {
|
describe('modules', () => {
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
import { platform } from 'os'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {platform} from 'os'
|
|
||||||
|
|
||||||
export function getPathSeparator(platformValue: string) {
|
export function getPathSeparator(platformValue: string) {
|
||||||
return platformValue === 'win32' ? ';' : ':'
|
return platformValue === 'win32' ? ';' : ':'
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
|
import { join } from 'path'
|
||||||
|
import { Command } from './Command'
|
||||||
import * as commands from './scripts'
|
import * as commands from './scripts'
|
||||||
import {join} from 'path'
|
|
||||||
import { TCommand } from './TCommand'
|
|
||||||
|
|
||||||
export type AvailableCommands = typeof commands & Record<string, TCommand>
|
export type AvailableCommands = typeof commands & Record<string, Command>
|
||||||
|
|
||||||
export async function resolve(cwd = process.cwd()): Promise<AvailableCommands> {
|
export async function resolve(cwd = process.cwd()): Promise<AvailableCommands> {
|
||||||
let extraScripts: Record<string, TCommand> = {}
|
let extraScripts: Record<string, Command> = {}
|
||||||
try {
|
try {
|
||||||
extraScripts = await import(join(cwd, './src/scripts'))
|
extraScripts = await import(join(cwd, './src/scripts'))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import {Subprocess} from './Subprocess'
|
import { getPathVariable } from './modules'
|
||||||
import {getPathVariable} from './modules'
|
import { Subprocess } from './Subprocess'
|
||||||
|
|
||||||
export async function run(command: string, args: string[], cwd?: string) {
|
export async function run(command: string, args: string[], cwd?: string) {
|
||||||
return new Subprocess(command, args, {
|
return new Subprocess(command, args, {
|
||||||
|
|||||||
@ -7,6 +7,9 @@
|
|||||||
{
|
{
|
||||||
"path": "../common/tsconfig.esm.json"
|
"path": "../common/tsconfig.esm.json"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "../client/tsconfig.esm.json"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "../jsonrpc/tsconfig.esm.json"
|
"path": "../jsonrpc/tsconfig.esm.json"
|
||||||
},
|
},
|
||||||
@ -29,4 +32,4 @@
|
|||||||
"path": "../validator/tsconfig.esm.json"
|
"path": "../validator/tsconfig.esm.json"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
},
|
},
|
||||||
"references": [
|
"references": [
|
||||||
{"path": "../common"},
|
{"path": "../common"},
|
||||||
|
{"path": "../client"},
|
||||||
{"path": "../jsonrpc"},
|
{"path": "../jsonrpc"},
|
||||||
{"path": "../logger"},
|
{"path": "../logger"},
|
||||||
{"path": "../config"},
|
{"path": "../config"},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user