Skip to content

Commit e79979d

Browse files
committed
feat(nodes): Directory, File, Parent, Root
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 4487470 commit e79979d

File tree

15 files changed

+392
-1
lines changed

15 files changed

+392
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file Type Tests - Directory
3+
* @module fst/nodes/tests/unit-d/Directory
4+
*/
5+
6+
import type * as TestSubject from '#nodes/directory'
7+
import type {
8+
Data,
9+
Parent
10+
} from '@flex-development/fst'
11+
import type { Optional } from '@flex-development/tutils'
12+
13+
describe('unit-d:nodes/Directory', () => {
14+
type Subject = TestSubject.default
15+
type SubjectData = TestSubject.DirectoryData
16+
17+
it('should extend Parent', () => {
18+
expectTypeOf<Subject>().toMatchTypeOf<Parent>()
19+
})
20+
21+
it('should match [data?: DirectoryData | undefined]', () => {
22+
expectTypeOf<Subject>()
23+
.toHaveProperty('data')
24+
.toEqualTypeOf<Optional<SubjectData>>()
25+
})
26+
27+
it('should match [name: string]', () => {
28+
expectTypeOf<Subject>().toHaveProperty('name').toEqualTypeOf<string>()
29+
})
30+
31+
it('should match [type: "directory"]', () => {
32+
expectTypeOf<Subject>().toHaveProperty('type').toEqualTypeOf<'directory'>()
33+
})
34+
35+
describe('DirectoryData', () => {
36+
it('should extend Data', () => {
37+
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
38+
})
39+
})
40+
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file Type Tests - File
3+
* @module fst/nodes/tests/unit-d/File
4+
*/
5+
6+
import type * as TestSubject from '#nodes/file'
7+
import type { Data, Literal } from '@flex-development/fst'
8+
import type { Optional } from '@flex-development/tutils'
9+
10+
describe('unit-d:nodes/File', () => {
11+
type Subject = TestSubject.default
12+
type SubjectData = TestSubject.FileData
13+
14+
it('should extend Literal', () => {
15+
expectTypeOf<Subject>().toMatchTypeOf<Literal>()
16+
})
17+
18+
it('should match [data?: FileData | undefined]', () => {
19+
expectTypeOf<Subject>()
20+
.toHaveProperty('data')
21+
.toEqualTypeOf<Optional<SubjectData>>()
22+
})
23+
24+
it('should match [name: string]', () => {
25+
expectTypeOf<Subject>().toHaveProperty('name').toEqualTypeOf<string>()
26+
})
27+
28+
it('should match [type: "file"]', () => {
29+
expectTypeOf<Subject>().toHaveProperty('type').toEqualTypeOf<'file'>()
30+
})
31+
32+
describe('FileData', () => {
33+
it('should extend Data', () => {
34+
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
35+
})
36+
})
37+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @file Type Tests - Parent
3+
* @module fst/nodes/tests/unit-d/Parent
4+
*/
5+
6+
import type TestSubject from '#nodes/parent'
7+
import type { Child, Node } from '@flex-development/fst'
8+
9+
describe('unit-d:nodes/Parent', () => {
10+
it('should extend Node', () => {
11+
expectTypeOf<TestSubject>().toMatchTypeOf<Node>()
12+
})
13+
14+
it('should match [children: Child[]]', () => {
15+
expectTypeOf<TestSubject>()
16+
.toHaveProperty('children')
17+
.toEqualTypeOf<Child[]>()
18+
})
19+
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file Type Tests - Root
3+
* @module fst/nodes/tests/unit-d/Root
4+
*/
5+
6+
import type * as TestSubject from '#nodes/root'
7+
import type { Data, Directory, File, Parent } from '@flex-development/fst'
8+
import type { Optional } from '@flex-development/tutils'
9+
10+
describe('unit-d:nodes/Root', () => {
11+
type Subject = TestSubject.default
12+
type SubjectData = TestSubject.RootData
13+
14+
it('should extend Parent', () => {
15+
expectTypeOf<Subject>().toMatchTypeOf<Parent>()
16+
})
17+
18+
it('should match [children: (Directory | File)[]]', () => {
19+
expectTypeOf<Subject>()
20+
.toHaveProperty('children')
21+
.toEqualTypeOf<(Directory | File)[]>()
22+
})
23+
24+
it('should match [data?: RootData | undefined]', () => {
25+
expectTypeOf<Subject>()
26+
.toHaveProperty('data')
27+
.toEqualTypeOf<Optional<SubjectData>>()
28+
})
29+
30+
it('should match [path: string]', () => {
31+
expectTypeOf<Subject>().toHaveProperty('path').toEqualTypeOf<string>()
32+
})
33+
34+
it('should match [type: "root"]', () => {
35+
expectTypeOf<Subject>().toHaveProperty('type').toEqualTypeOf<'root'>()
36+
})
37+
38+
describe('RootData', () => {
39+
it('should extend Data', () => {
40+
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
41+
})
42+
})
43+
})

src/nodes/directory.mts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @file Nodes - Directory
3+
* @module fst/nodes/Directory
4+
*/
5+
6+
import type { Data, File, Parent } from '@flex-development/fst'
7+
8+
/**
9+
* Info associated with directories.
10+
*
11+
* @see {@linkcode Data}
12+
*
13+
* @extends {Data}
14+
*/
15+
interface DirectoryData extends Data {}
16+
17+
/**
18+
* Node representing a directory.
19+
*
20+
* @see {@linkcode Parent}
21+
*
22+
* @extends {Parent}
23+
*/
24+
interface Directory extends Parent {
25+
/**
26+
* List of children.
27+
*
28+
* @see {@linkcode File}
29+
*/
30+
children: (Directory | File)[]
31+
32+
/**
33+
* Info from the ecosystem.
34+
*
35+
* @see {@linkcode DirectoryData}
36+
*/
37+
data?: DirectoryData | undefined
38+
39+
/**
40+
* Directory name (relative to parent).
41+
*
42+
* @example
43+
* 'src'
44+
*/
45+
name: string
46+
47+
/**
48+
* Node type.
49+
*/
50+
type: 'directory'
51+
}
52+
53+
export type { Directory as default, DirectoryData }

src/nodes/file.mts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @file Nodes - File
3+
* @module fst/nodes/File
4+
*/
5+
6+
import type { Data, Literal } from '@flex-development/fst'
7+
8+
/**
9+
* Info associated with files.
10+
*
11+
* @see {@linkcode Data}
12+
*
13+
* @extends {Data}
14+
*/
15+
interface FileData extends Data {}
16+
17+
/**
18+
* Node representing a file.
19+
*
20+
* @see {@linkcode Literal}
21+
*
22+
* @extends {Literal}
23+
*/
24+
interface File extends Literal {
25+
/**
26+
* Info from the ecosystem.
27+
*
28+
* @see {@linkcode FileData}
29+
*/
30+
data?: FileData | undefined
31+
32+
/**
33+
* File name (relative to parent).
34+
*
35+
* @example
36+
* 'index.mts'
37+
*/
38+
name: string
39+
40+
/**
41+
* Node type.
42+
*/
43+
type: 'file'
44+
45+
/**
46+
* File contents.
47+
*
48+
* @override
49+
*/
50+
value: string | null | undefined
51+
}
52+
53+
export type { File as default, FileData }

src/nodes/index.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
* @see https://github.com/syntax-tree/unist#nodes
55
*/
66

7+
export type { default as Directory, DirectoryData } from '#nodes/directory'
8+
export type { default as File, FileData } from '#nodes/file'
79
export type { default as Literal } from '#nodes/literal'
810
export type { default as Node } from '#nodes/node'
11+
export type { default as Parent } from '#nodes/parent'
12+
export type { default as Root, RootData } from '#nodes/root'

src/nodes/parent.mts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @file Nodes - Parent
3+
* @module fst/nodes/Parent
4+
*/
5+
6+
import type { Child, Node } from '@flex-development/fst'
7+
8+
/**
9+
* Abstract fst node that contains other fst nodes.
10+
*
11+
* @see {@linkcode Node}
12+
*
13+
* @extends {Node}
14+
*/
15+
interface Parent extends Node {
16+
/**
17+
* List of children.
18+
*
19+
* @see {@linkcode Child}
20+
*/
21+
children: Child[]
22+
}
23+
24+
export type { Parent as default }

src/nodes/root.mts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @file Nodes - Root
3+
* @module fst/nodes/Root
4+
*/
5+
6+
import type {
7+
Directory,
8+
DirectoryData,
9+
File,
10+
Parent
11+
} from '@flex-development/fst'
12+
13+
/**
14+
* Info associated with file system roots.
15+
*
16+
* @see {@linkcode DirectoryData}
17+
*
18+
* @extends {DirectoryData}
19+
*/
20+
interface RootData extends DirectoryData {}
21+
22+
/**
23+
* Node representing the root of a file system.
24+
*
25+
* @see {@linkcode Parent}
26+
*
27+
* @extends {Parent}
28+
*/
29+
interface Root extends Parent {
30+
/**
31+
* List of children.
32+
*
33+
* @see {@linkcode Directory}
34+
* @see {@linkcode File}
35+
*/
36+
children: (Directory | File)[]
37+
38+
/**
39+
* Info from the ecosystem.
40+
*
41+
* @see {@linkcode RootData}
42+
*/
43+
data?: RootData | undefined
44+
45+
/**
46+
* Path to root directory.
47+
*/
48+
path: string
49+
50+
/**
51+
* Node type.
52+
*/
53+
type: 'root'
54+
}
55+
export type { Root as default, RootData }

src/types/__tests__/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)