Skip to content

Commit f97d3b5

Browse files
committed
fix: remove string reducer
1 parent 3d717ba commit f97d3b5

File tree

4 files changed

+16
-115
lines changed

4 files changed

+16
-115
lines changed

src/example.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { count } from './input/count/domain-language'
66
import { group } from './input/group/domain-language'
77
import { string } from './input/string/domain-language'
88

9-
// TODO: remove string reducer
109
export const grant = string()
1110
.reference('GRANT')
1211
.description(

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

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { log, state, SYMBOL_LOG, SYMBOL_STATE } from '@escapace/fluent'
22
import { assert, describe, it } from 'vitest'
3-
import { type LookupValues, SYMBOL_INPUT_STRING } from '../../types'
3+
import { SYMBOL_INPUT_STRING } from '../../types'
44
import { string } from './domain-language'
55
import { reducer } from './reducer'
66
import { TypeAction } from './types'
@@ -92,7 +92,7 @@ describe('input/choice', () => {
9292

9393
const test4 = test3.option('--option')
9494

95-
assert.hasAllKeys(test4, [SYMBOL_LOG, SYMBOL_STATE, 'default', 'reducer', 'option', 'variable'])
95+
assert.hasAllKeys(test4, [SYMBOL_LOG, SYMBOL_STATE, 'default', 'option', 'variable'])
9696

9797
assert.deepEqual(log(test4), [
9898
{
@@ -120,7 +120,7 @@ describe('input/choice', () => {
120120

121121
const test5 = test4.variable('VARIABLE')
122122

123-
assert.hasAllKeys(test5, [SYMBOL_LOG, SYMBOL_STATE, 'default', 'reducer', 'option', 'variable'])
123+
assert.hasAllKeys(test5, [SYMBOL_LOG, SYMBOL_STATE, 'default', 'option', 'variable'])
124124

125125
assert.deepEqual(log(test5), [
126126
{
@@ -182,43 +182,5 @@ describe('input/choice', () => {
182182
type: SYMBOL_INPUT_STRING,
183183
variables: ['VARIABLE'],
184184
})
185-
186-
const function_ = (_: LookupValues<typeof test5>) => 1 as const
187-
188-
const test7 = test5.reducer(function_)
189-
190-
assert.hasAllKeys(test7, [SYMBOL_LOG, SYMBOL_STATE])
191-
192-
assert.deepEqual(log(test7), [
193-
{
194-
payload: function_,
195-
type: TypeAction.Reducer,
196-
},
197-
{
198-
payload: 'VARIABLE',
199-
type: TypeAction.Variable,
200-
},
201-
{
202-
payload: {
203-
name: '--option',
204-
},
205-
type: TypeAction.Option,
206-
},
207-
{ payload: undefined, type: TypeAction.Repeat },
208-
{ payload: 'ABC', type: TypeAction.Description },
209-
{ payload: reference, type: TypeAction.Reference },
210-
])
211-
212-
assert.deepEqual(state(test7), {
213-
default: undefined,
214-
description: 'ABC',
215-
isEmpty: false,
216-
options: ['--option'],
217-
reducer: state(test7).reducer,
218-
reference,
219-
repeat: true,
220-
type: SYMBOL_INPUT_STRING,
221-
variables: ['VARIABLE'],
222-
})
223185
})
224186
})

src/input/string/domain-language.ts

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
/* eslint-disable typescript/no-unsafe-argument */
21
import { builder, Options } from '@escapace/fluent'
32
import { filter, find, map, reverse, some } from 'lodash-es'
43
import { type Reference, SYMBOL_INPUT_STRING } from '../../types'
54
import { assert } from '../../utilities/assert'
6-
import { normalizeString } from '../../utilities/normalize'
7-
import { reducer as reducerDefault } from './reducer'
5+
import { reducer } from './reducer'
86
import {
97
type ActionDefault,
108
type ActionDescription,
119
type ActionOption,
12-
type ActionReducer,
1310
type ActionReference,
1411
type ActionRepeat,
1512
type Actions,
1613
type ActionVariable,
17-
type GenericInputStringReducer,
1814
type Settings,
1915
type State,
2016
TypeAction,
@@ -33,15 +29,6 @@ const fluentReducer = (log: Actions): State => {
3329

3430
const repeat = Boolean(find(log, ({ type }) => type === TypeAction.Repeat))
3531

36-
const reducerMaybe = (
37-
find(log, (action) => action.type === TypeAction.Reducer) as ActionReducer | undefined
38-
)?.payload
39-
40-
const reducer: GenericInputStringReducer =
41-
reducerMaybe === undefined
42-
? reducerDefault
43-
: (values, properties) => reducerMaybe(normalizeString(values, properties), properties)
44-
4532
const isEmpty =
4633
log.length === 0 ||
4734
!some(log, (action) => action.type === TypeAction.Option || action.type === TypeAction.Variable)
@@ -122,7 +109,7 @@ export const string = builder<Settings>([
122109
[Options.Type]: TypeAction.Repeat,
123110
},
124111
{
125-
[Options.Conflicts]: [TypeAction.Reducer, TypeAction.Default],
112+
[Options.Conflicts]: [TypeAction.Default],
126113
[Options.Dependencies]: [TypeAction.Description],
127114
[Options.Interface]: (dispatch, _, { options }) => ({
128115
option(value: string) {
@@ -142,7 +129,7 @@ export const string = builder<Settings>([
142129
[Options.Type]: TypeAction.Option,
143130
},
144131
{
145-
[Options.Conflicts]: [TypeAction.Reducer, TypeAction.Default],
132+
[Options.Conflicts]: [TypeAction.Default],
146133
[Options.Dependencies]: [TypeAction.Description],
147134
[Options.Interface]: (dispatch, _, { variables }) => ({
148135
variable(value: string) {
@@ -160,7 +147,7 @@ export const string = builder<Settings>([
160147
[Options.Type]: TypeAction.Variable,
161148
},
162149
{
163-
[Options.Conflicts]: [TypeAction.Reducer],
150+
[Options.Conflicts]: [],
164151
[Options.Dependencies]: [TypeAction.Description],
165152
[Options.Enabled]: (_, state) => !state.isEmpty,
166153
[Options.Interface]: (dispatch, _, { repeat }) => ({
@@ -178,22 +165,4 @@ export const string = builder<Settings>([
178165
[Options.Reducer]: fluentReducer,
179166
[Options.Type]: TypeAction.Default,
180167
},
181-
{
182-
[Options.Conflicts]: [TypeAction.Default],
183-
[Options.Enabled]: (_, state) => !state.isEmpty,
184-
[Options.Interface]: (dispatch) => ({
185-
reducer(value: GenericInputStringReducer) {
186-
assert.function(value)
187-
188-
return dispatch<ActionReducer>({
189-
payload: value,
190-
type: TypeAction.Reducer,
191-
})
192-
},
193-
}),
194-
[Options.Keys]: ['reducer'],
195-
[Options.Once]: true,
196-
[Options.Reducer]: fluentReducer,
197-
[Options.Type]: TypeAction.Reducer,
198-
},
199168
])

src/input/string/types.ts

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export declare const INPUT_STRING_REDUCER: unique symbol
2727
export enum TypeAction {
2828
Default,
2929
Description,
30-
Reducer,
3130
Option,
3231
Reference,
3332
Repeat,
@@ -54,11 +53,6 @@ export interface ActionDefault<T extends string | string[] = string | string[]>
5453
type: TypeAction.Default
5554
}
5655

57-
export interface ActionReducer<T = unknown> {
58-
payload: GenericInputStringReducer<T>
59-
type: TypeAction.Reducer
60-
}
61-
6256
export interface ActionVariable<T extends string = string> {
6357
payload: T
6458
type: TypeAction.Variable
@@ -72,13 +66,7 @@ export interface ActionOption<T extends string = string> {
7266
}
7367

7468
export type Actions = Array<
75-
| ActionDefault
76-
| ActionDescription
77-
| ActionOption
78-
| ActionReducer
79-
| ActionReference
80-
| ActionRepeat
81-
| ActionVariable
69+
ActionDefault | ActionDescription | ActionOption | ActionReference | ActionRepeat | ActionVariable
8270
>
8371

8472
export type LookupDefault<T extends Model<State, Actions>> = $.If<
@@ -93,7 +81,6 @@ export interface Interface<T extends Model<State, Actions>> extends FluentInterf
9381
option: <P extends string>(
9482
option: Exclude<P, $.Values<T['state']['options']>>,
9583
) => Next<Settings, T, ActionOption<P>>
96-
reducer: <U>(reducer: InputStringReducer<U, T>) => Next<Settings, T, ActionReducer<U>>
9784
reference: <U extends Reference>(reference: U) => Next<Settings, T, ActionReference<U>>
9885
repeat: () => Next<Settings, T, ActionRepeat>
9986
variable: <P extends string>(
@@ -152,7 +139,7 @@ export interface Specification<T extends Model<State>> {
152139
}
153140

154141
[TypeAction.Option]: {
155-
[Options.Conflicts]: typeof TypeAction.Default | typeof TypeAction.Reducer
142+
[Options.Conflicts]: typeof TypeAction.Default
156143
[Options.Dependencies]: typeof TypeAction.Description
157144
[Options.Enabled]: $.True
158145
[Options.Keys]: 'option'
@@ -161,7 +148,7 @@ export interface Specification<T extends Model<State>> {
161148
}
162149

163150
[TypeAction.Variable]: {
164-
[Options.Conflicts]: typeof TypeAction.Default | typeof TypeAction.Reducer
151+
[Options.Conflicts]: typeof TypeAction.Default
165152
[Options.Dependencies]: typeof TypeAction.Description
166153
[Options.Enabled]: $.True
167154
[Options.Keys]: 'variable'
@@ -170,22 +157,13 @@ export interface Specification<T extends Model<State>> {
170157
}
171158

172159
[TypeAction.Default]: {
173-
[Options.Conflicts]: typeof TypeAction.Reducer
160+
[Options.Conflicts]: never
174161
[Options.Dependencies]: typeof TypeAction.Description
175162
[Options.Enabled]: $.Equal<T['state']['isEmpty'], false>
176163
[Options.Keys]: 'default'
177164
[Options.Once]: $.True
178165
[Options.Type]: typeof TypeAction.Default
179166
}
180-
181-
[TypeAction.Reducer]: {
182-
[Options.Conflicts]: typeof TypeAction.Default
183-
[Options.Dependencies]: never
184-
[Options.Enabled]: $.Equal<T['state']['isEmpty'], false>
185-
[Options.Keys]: 'reducer'
186-
[Options.Once]: $.True
187-
[Options.Type]: typeof TypeAction.Reducer
188-
}
189167
}
190168

191169
declare module '@escapace/typelevel/hkt' {
@@ -197,17 +175,13 @@ declare module '@escapace/typelevel/hkt' {
197175
}
198176

199177
export type ReducerReducer<T extends Action[]> = $.If<
200-
$.Is.Never<Payload<$.Values<T>, TypeAction.Reducer>>,
178+
$.Is.Never<Payload<$.Values<T>, TypeAction.Repeat>>,
201179
$.If<
202-
$.Is.Never<Payload<$.Values<T>, TypeAction.Repeat>>,
203-
$.If<
204-
$.Is.Never<Payload<$.Values<T>, TypeAction.Default>>,
205-
GenericInputStringReducer<string | undefined>,
206-
GenericInputStringReducer<string>
207-
>,
208-
GenericInputStringReducer<string[]>
180+
$.Is.Never<Payload<$.Values<T>, TypeAction.Default>>,
181+
GenericInputStringReducer<string | undefined>,
182+
GenericInputStringReducer<string>
209183
>,
210-
GenericInputStringReducer<ReturnType<Payload<$.Values<T>, TypeAction.Reducer>>>
184+
GenericInputStringReducer<string[]>
211185
>
212186

213187
export interface Reducer<T extends Action[]> {
@@ -222,9 +196,6 @@ export interface Reducer<T extends Action[]> {
222196
isEmpty: false
223197
options: Array<Payload<$.Values<T>, TypeAction.Option> extends { name: infer U } ? U : never>
224198
}
225-
[TypeAction.Reducer]: {
226-
reducer: GenericInputStringReducer<ReturnType<Payload<$.Values<T>, TypeAction.Reducer>>>
227-
}
228199
[TypeAction.Reference]: {
229200
reference: Payload<$.Values<T>, TypeAction.Reference>
230201
}

0 commit comments

Comments
 (0)