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