Skip to content

Commit 68a9884

Browse files
committed
feat: hooks
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 97cdd15 commit 68a9884

37 files changed

+1441
-262
lines changed

README.md

Lines changed: 279 additions & 76 deletions
Large diffs are not rendered by default.

eslint.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ const config = [
4444
'sort-keys': 0
4545
}
4646
},
47+
{
48+
files: ['src/internal/__tests__/is-promise.spec.mts'],
49+
rules: {
50+
'unicorn/no-thenable': 0
51+
}
52+
},
4753
{
4854
files: ['src/lib/command.mts'],
4955
rules: {

src/enums/hooks.mts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @file Enums - hooks
3+
* @module kronk/enums/hooks
4+
*/
5+
6+
import type { KronkHookName } from '@flex-development/kronk'
7+
8+
/**
9+
* Default hook names.
10+
*
11+
* @see {@linkcode KronkHookName}
12+
*
13+
* @internal
14+
*
15+
* @enum {KronkHookName}
16+
*/
17+
const enum hooks {
18+
postAction = 'postAction',
19+
preAction = 'preAction',
20+
preCommand = 'preCommand'
21+
}
22+
23+
export default hooks

src/interfaces/__tests__/command.data.spec-d.mts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
HelpCommandData,
1616
HelpOptionData,
1717
HelpTextOptions,
18+
HooksData,
1819
List,
1920
OptionPriority,
2021
OptionsData,
@@ -59,12 +60,6 @@ describe('unit-d:interfaces/CommandData', () => {
5960
.toEqualTypeOf<Nilable<boolean>>()
6061
})
6162

62-
it('should match [done?: Action<any> | null | undefined]', () => {
63-
expectTypeOf<TestSubject>()
64-
.toHaveProperty('done')
65-
.toEqualTypeOf<Nilable<Action<any>>>()
66-
})
67-
6863
it('should match [examples?: ExamplesData | null | undefined]', () => {
6964
expectTypeOf<TestSubject>()
7065
.toHaveProperty('examples')
@@ -95,6 +90,12 @@ describe('unit-d:interfaces/CommandData', () => {
9590
.toEqualTypeOf<Nilable<HelpOptionData>>()
9691
})
9792

93+
it('should match [hooks?: HooksData | null | undefined]', () => {
94+
expectTypeOf<TestSubject>()
95+
.toHaveProperty('hooks')
96+
.toEqualTypeOf<Nilable<HooksData>>()
97+
})
98+
9899
it('should match [optionPriority?: OptionPriority | null | undefined]', () => {
99100
expectTypeOf<TestSubject>()
100101
.toHaveProperty('optionPriority')

src/interfaces/__tests__/command.metadata.spec-d.mts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import type {
88
default as TestSubject
99
} from '#interfaces/command.metadata'
1010
import type {
11+
Action,
1112
Argument,
1213
Command,
1314
CommandInfo,
1415
ExampleInfo,
1516
Help,
17+
HooksInfo,
1618
Option,
1719
VersionOption
1820
} from '@flex-development/kronk'
@@ -27,6 +29,12 @@ describe('unit-d:interfaces/CommandMetadata', () => {
2729
expectTypeOf<TestSubject>().toExtend<Expect>()
2830
})
2931

32+
it('should match [action: Action<any>]', () => {
33+
expectTypeOf<TestSubject>()
34+
.toHaveProperty('action')
35+
.toEqualTypeOf<Action<any>>()
36+
})
37+
3038
it('should match [aliases: Set<string>]', () => {
3139
expectTypeOf<TestSubject>()
3240
.toHaveProperty('aliases')
@@ -63,6 +71,12 @@ describe('unit-d:interfaces/CommandMetadata', () => {
6371
.toEqualTypeOf<Nilable<Option>>()
6472
})
6573

74+
it('should match [hooks: HooksInfo]', () => {
75+
expectTypeOf<TestSubject>()
76+
.toHaveProperty('hooks')
77+
.toEqualTypeOf<HooksInfo>()
78+
})
79+
6680
it('should match [options: Map<string, Option>]', () => {
6781
expectTypeOf<TestSubject>()
6882
.toHaveProperty('options')
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file Type Tests - HooksData
3+
* @module kronk/interfaces/tests/unit-d/HooksData
4+
*/
5+
6+
import type TestSubject from '#interfaces/hooks.data'
7+
import type {
8+
List,
9+
PostActionHook,
10+
PreActionHook,
11+
PreCommandHook
12+
} from '@flex-development/kronk'
13+
import type { Nilable, OptionalKeys } from '@flex-development/tutils'
14+
15+
describe('unit-d:interfaces/HooksData', () => {
16+
it('should have all optional keys', () => {
17+
expectTypeOf<OptionalKeys<TestSubject>>().toEqualTypeOf<keyof TestSubject>()
18+
})
19+
20+
it('should match [postAction?: PostActionHook | List<PostActionHook> | null | undefined]', () => {
21+
expectTypeOf<TestSubject>()
22+
.toHaveProperty('postAction')
23+
.toEqualTypeOf<Nilable<PostActionHook | List<PostActionHook>>>()
24+
})
25+
26+
it('should match [preAction?: PreActionHook | List<PreActionHook> | null | undefined]', () => {
27+
expectTypeOf<TestSubject>()
28+
.toHaveProperty('preAction')
29+
.toEqualTypeOf<Nilable<PreActionHook | List<PreActionHook>>>()
30+
})
31+
32+
it('should match [preCommand?: PreCommandHook | List<PreCommandHook> | null | undefined]', () => {
33+
expectTypeOf<TestSubject>()
34+
.toHaveProperty('preCommand')
35+
.toEqualTypeOf<Nilable<PreCommandHook | List<PreCommandHook>>>()
36+
})
37+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file Type Tests - HooksInfo
3+
* @module kronk/interfaces/tests/unit-d/HooksInfo
4+
*/
5+
6+
import type TestSubject from '#interfaces/hooks.info'
7+
import type {
8+
HooksData,
9+
PostActionHook,
10+
PreActionHook,
11+
PreCommandHook
12+
} from '@flex-development/kronk'
13+
import type { RequiredKeys } from '@flex-development/tutils'
14+
15+
describe('unit-d:interfaces/HooksInfo', () => {
16+
it('should extend HooksData', () => {
17+
expectTypeOf<TestSubject>().toExtend<HooksData>()
18+
})
19+
20+
it('should have all required keys', () => {
21+
expectTypeOf<RequiredKeys<TestSubject>>().toEqualTypeOf<keyof TestSubject>()
22+
})
23+
24+
it('should match [postAction: PostActionHook[]]', () => {
25+
expectTypeOf<TestSubject>()
26+
.toHaveProperty('postAction')
27+
.toEqualTypeOf<PostActionHook[]>()
28+
})
29+
30+
it('should match [preAction: PreActionHook[]]', () => {
31+
expectTypeOf<TestSubject>()
32+
.toHaveProperty('preAction')
33+
.toEqualTypeOf<PreActionHook[]>()
34+
})
35+
36+
it('should match [preCommand: PreCommandHook[]]', () => {
37+
expectTypeOf<TestSubject>()
38+
.toHaveProperty('preCommand')
39+
.toEqualTypeOf<PreCommandHook[]>()
40+
})
41+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @file Type Tests - KronkHookMap
3+
* @module kronk/interfaces/tests/unit-d/KronkHookMap
4+
*/
5+
6+
import type TestSubject from '#interfaces/kronk-hook.map'
7+
import type { Hook } from '@flex-development/kronk'
8+
9+
describe('unit-d:interfaces/KronkHookMap', () => {
10+
it('should match [postAction: Hook]', () => {
11+
expectTypeOf<TestSubject>()
12+
.toHaveProperty('postAction')
13+
.toEqualTypeOf<Hook>()
14+
})
15+
16+
it('should match [preAction: Hook]', () => {
17+
expectTypeOf<TestSubject>()
18+
.toHaveProperty('preAction')
19+
.toEqualTypeOf<Hook>()
20+
})
21+
22+
it('should match [preCommand: Hook]', () => {
23+
expectTypeOf<TestSubject>()
24+
.toHaveProperty('preCommand')
25+
.toEqualTypeOf<Hook>()
26+
})
27+
})

src/interfaces/__tests__/usage.data.spec-d.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
*/
55

66
import type TestSubject from '#interfaces/usage.data'
7-
import type { Nilable } from '@flex-development/tutils'
7+
import type { Nilable, OptionalKeys } from '@flex-development/tutils'
88

99
describe('unit-d:interfaces/UsageData', () => {
10+
it('should have all optional keys', () => {
11+
expectTypeOf<OptionalKeys<TestSubject>>().toEqualTypeOf<keyof TestSubject>()
12+
})
13+
1014
it('should match [arguments?: readonly string[] | string | null | undefined]', () => {
1115
expectTypeOf<TestSubject>()
1216
.toHaveProperty('arguments')

src/interfaces/__tests__/usage.info.mts renamed to src/interfaces/__tests__/usage.info.spec-d.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55

66
import type TestSubject from '#interfaces/usage.info'
77
import type { UsageData } from '@flex-development/kronk'
8-
import type { Nullable } from '@flex-development/tutils'
8+
import type { Nullable, RequiredKeys } from '@flex-development/tutils'
99

1010
describe('unit-d:interfaces/UsageInfo', () => {
1111
it('should extend UsageData', () => {
1212
expectTypeOf<TestSubject>().toExtend<UsageData>()
1313
})
1414

15+
it('should have all required keys', () => {
16+
expectTypeOf<RequiredKeys<TestSubject>>().toEqualTypeOf<keyof TestSubject>()
17+
})
18+
1519
it('should match [arguments: readonly string[]]', () => {
1620
expectTypeOf<TestSubject>()
1721
.toHaveProperty('arguments')

0 commit comments

Comments
 (0)