Skip to content

Commit 336b2d5

Browse files
committed
fix: count types
1 parent 25af532 commit 336b2d5

File tree

6 files changed

+126
-101
lines changed

6 files changed

+126
-101
lines changed

src/compose/get-options-variables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { compact, intersection, keys } from 'lodash-es'
22
import type { InputBooleanStateInitial } from '../input/boolean/types'
33
import type { InputChoiceStateInitial } from '../input/choice/types'
4-
import type { InputCountState } from '../input/count/types'
4+
import type { InputCountStateInitial } from '../input/count/types'
55
import type { InputGroupState } from '../input/group/types'
66
import type { InputStringStateInitial } from '../input/string/types'
77
import { type GenericOption, type GenericVariable, InputType, type Match } from '../types'
@@ -10,7 +10,7 @@ export const getOptionsVariables = (
1010
state:
1111
| InputBooleanStateInitial
1212
| InputChoiceStateInitial
13-
| InputCountState
13+
| InputCountStateInitial
1414
| InputGroupState
1515
| InputStringStateInitial,
1616
match: Match,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type {
1818
export type * from './command/types'
1919
export type * from './input/boolean/types'
2020
export type * from './input/choice/types'
21+
export type * from './input/count/types'
2122

2223
import { noop } from 'lodash-es'
2324
import { composeFactory } from './compose/compose-factory'

src/input/count/domain-language.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { assert, describe, it } from 'vitest'
33
import { SYMBOL_INPUT_COUNT } from '../../types'
44
import { count } from './domain-language'
55
import { reducer } from './reducer'
6-
import { TypeAction } from './types'
6+
import { InputCountTypeAction } from './types'
77

88
describe('input/count', () => {
99
it('domain-language', () => {
@@ -45,7 +45,7 @@ describe('input/count', () => {
4545
variables: [],
4646
})
4747

48-
assert.deepEqual(log(test1), [{ payload: reference, type: TypeAction.Reference }])
48+
assert.deepEqual(log(test1), [{ payload: reference, type: InputCountTypeAction.Reference }])
4949

5050
const test2 = test1.description('ABC')
5151

@@ -64,8 +64,8 @@ describe('input/count', () => {
6464
})
6565

6666
assert.deepEqual(log(test2), [
67-
{ payload: 'ABC', type: TypeAction.Description },
68-
{ payload: reference, type: TypeAction.Reference },
67+
{ payload: 'ABC', type: InputCountTypeAction.Description },
68+
{ payload: reference, type: InputCountTypeAction.Reference },
6969
])
7070

7171
const test3 = test2.option('-v', '-q')
@@ -90,10 +90,10 @@ describe('input/count', () => {
9090
decrease: '-q',
9191
increase: '-v',
9292
},
93-
type: TypeAction.Option,
93+
type: InputCountTypeAction.Option,
9494
},
95-
{ payload: 'ABC', type: TypeAction.Description },
96-
{ payload: reference, type: TypeAction.Reference },
95+
{ payload: 'ABC', type: InputCountTypeAction.Description },
96+
{ payload: reference, type: InputCountTypeAction.Reference },
9797
])
9898

9999
const test4 = test3.default(10)
@@ -113,16 +113,16 @@ describe('input/count', () => {
113113
})
114114

115115
assert.deepEqual(log(test4), [
116-
{ payload: 10, type: TypeAction.Default },
116+
{ payload: 10, type: InputCountTypeAction.Default },
117117
{
118118
payload: {
119119
decrease: '-q',
120120
increase: '-v',
121121
},
122-
type: TypeAction.Option,
122+
type: InputCountTypeAction.Option,
123123
},
124-
{ payload: 'ABC', type: TypeAction.Description },
125-
{ payload: reference, type: TypeAction.Reference },
124+
{ payload: 'ABC', type: InputCountTypeAction.Description },
125+
{ payload: reference, type: InputCountTypeAction.Reference },
126126
])
127127
})
128128
})

src/input/count/domain-language.ts

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,46 @@ import { assert } from '../../utilities/assert'
66
import { fallback } from '../../utilities/fallback'
77
import { reducer } from './reducer'
88
import {
9-
type ActionDefault,
10-
type ActionDescription,
11-
type ActionOption,
12-
type ActionReference,
13-
type Actions,
14-
type Settings,
15-
type State,
16-
TypeAction,
9+
type InputCountActionDefault,
10+
type InputCountActionDescription,
11+
type InputCountActionOption,
12+
type InputCountActionReference,
13+
type InputCountActions,
14+
type InputCountSettings,
15+
type InputCountState,
16+
InputCountTypeAction,
1717
} from './types'
1818

19-
const fluentReducer = (log: Actions): State => {
19+
const fluentReducer = (log: InputCountActions): InputCountState => {
2020
const reference = (
21-
find(log, (action) => action.type === TypeAction.Reference) as ActionReference | undefined
21+
find(log, (action) => action.type === InputCountTypeAction.Reference) as
22+
| InputCountActionReference
23+
| undefined
2224
)?.payload
2325

24-
const description = find(log, (action) => action.type === TypeAction.Description)?.payload
26+
const description = find(
27+
log,
28+
(action) => action.type === InputCountTypeAction.Description,
29+
)?.payload
2530

2631
const rlog = reverse([...log])
2732

2833
const _default = fallback(
2934
0,
30-
(find(log, (action) => action.type === TypeAction.Default) as ActionDefault | undefined)
31-
?.payload,
35+
(
36+
find(log, (action) => action.type === InputCountTypeAction.Default) as
37+
| InputCountActionDefault
38+
| undefined
39+
)?.payload,
3240
)
3341

34-
const isEmpty = log.length === 0 || !some(log, (action) => action.type === TypeAction.Option)
42+
const isEmpty =
43+
log.length === 0 || !some(log, (action) => action.type === InputCountTypeAction.Option)
3544

36-
const options = filter(rlog, ({ type }) => type === TypeAction.Option) as ActionOption[]
45+
const options = filter(
46+
rlog,
47+
({ type }) => type === InputCountTypeAction.Option,
48+
) as InputCountActionOption[]
3749

3850
const table = assign(
3951
{},
@@ -59,76 +71,76 @@ const fluentReducer = (log: Actions): State => {
5971
}
6072
}
6173

62-
export const count = builder<Settings>([
74+
export const count = builder<InputCountSettings>([
6375
{
6476
[Options.Interface]: (dispatch) => ({
6577
reference(reference: Reference) {
6678
assert.reference(reference)
6779

68-
return dispatch<ActionReference>({
80+
return dispatch<InputCountActionReference>({
6981
payload: reference,
70-
type: TypeAction.Reference,
82+
type: InputCountTypeAction.Reference,
7183
})
7284
},
7385
}),
7486
[Options.Keys]: ['reference'],
7587
[Options.Once]: true,
7688
[Options.Reducer]: fluentReducer,
77-
[Options.Type]: TypeAction.Reference,
89+
[Options.Type]: InputCountTypeAction.Reference,
7890
},
7991
{
80-
[Options.Dependencies]: [TypeAction.Reference],
92+
[Options.Dependencies]: [InputCountTypeAction.Reference],
8193
[Options.Interface]: (dispatch) => ({
8294
description(description: string) {
8395
assert.string(description)
8496

85-
return dispatch<ActionDescription>({
97+
return dispatch<InputCountActionDescription>({
8698
payload: description,
87-
type: TypeAction.Description,
99+
type: InputCountTypeAction.Description,
88100
})
89101
},
90102
}),
91103
[Options.Keys]: ['description'],
92104
[Options.Once]: true,
93105
[Options.Reducer]: fluentReducer,
94-
[Options.Type]: TypeAction.Description,
106+
[Options.Type]: InputCountTypeAction.Description,
95107
},
96108
{
97-
[Options.Conflicts]: [TypeAction.Default],
98-
[Options.Dependencies]: [TypeAction.Description],
109+
[Options.Conflicts]: [InputCountTypeAction.Default],
110+
[Options.Dependencies]: [InputCountTypeAction.Description],
99111
[Options.Interface]: (dispatch, _, { options }) => ({
100112
option(...value: [string | undefined, string | undefined]) {
101113
assert.inputDichotomousOption(value, options)
102114

103-
return dispatch<ActionOption>({
115+
return dispatch<InputCountActionOption>({
104116
payload: {
105117
decrease: value[1],
106118
increase: value[0],
107119
},
108-
type: TypeAction.Option,
120+
type: InputCountTypeAction.Option,
109121
})
110122
},
111123
}),
112124
[Options.Keys]: ['option'],
113125
[Options.Once]: false,
114126
[Options.Reducer]: fluentReducer,
115-
[Options.Type]: TypeAction.Option,
127+
[Options.Type]: InputCountTypeAction.Option,
116128
},
117129
{
118-
[Options.Dependencies]: [TypeAction.Option],
130+
[Options.Dependencies]: [InputCountTypeAction.Option],
119131
[Options.Interface]: (dispatch) => ({
120132
default(value: number) {
121133
assert.number(value)
122134

123-
return dispatch<ActionDefault>({
135+
return dispatch<InputCountActionDefault>({
124136
payload: value,
125-
type: TypeAction.Default,
137+
type: InputCountTypeAction.Default,
126138
})
127139
},
128140
}),
129141
[Options.Keys]: ['default'],
130142
[Options.Once]: true,
131143
[Options.Reducer]: fluentReducer,
132-
[Options.Type]: TypeAction.Default,
144+
[Options.Type]: InputCountTypeAction.Default,
133145
},
134146
])

src/input/count/reducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { filter, isEmpty, reduce } from 'lodash-es'
22
import { InputType } from '../../types'
3-
import type { DefaultInputCountReducer } from './types'
3+
import type { InputCountReducerDefault } from './types'
44

5-
export const reducer: DefaultInputCountReducer = (_values, properties) => {
5+
export const reducer: InputCountReducerDefault = (_values, properties) => {
66
const values = filter(_values, ({ type }) => type === InputType.Option)
77

88
return isEmpty(values)

0 commit comments

Comments
 (0)