Skip to content

Commit

Permalink
feat(types)!: AnyNode, AnyParent, Child
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Apr 12, 2024
1 parent d75da6b commit 0948945
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Its `value` field is a `string`.

```ts
interface Parent extends unist.Parent {
children: (Comment | Content)[]
children: Child[]
}
```

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"@flex-development/mlly": "1.0.0-alpha.18",
"@flex-development/pathe": "2.0.0",
"@flex-development/tsconfig-utils": "2.0.2",
"@flex-development/unist-util-types": "1.2.0",
"@types/eslint": "8.56.2",
"@types/is-ci": "3.0.4",
"@types/mdast": "4.0.3",
Expand Down Expand Up @@ -130,6 +131,7 @@
"yaml-eslint-parser": "1.2.2"
},
"peerDependencies": {
"@flex-development/unist-util-types": ">=1.1.0",
"@types/mdast": ">=4.0.3",
"@types/unist": ">=3.0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/__tests__/position.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module docast/interfaces/tests/unit-d/Position
*/

import type Point from '../point'
import type { Point } from '@flex-development/docast'
import type TestSubject from '../position'

describe('unit-d:interfaces/Position', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module docast/interfaces/Position
*/

import type Point from './point'
import type { Point } from '@flex-development/docast'

/**
* Location of a node in a source [*file*][1].
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/__tests__/node.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module docast/nodes/tests/unit-d/Node
*/

import type { Data, Position } from '#src/interfaces'
import type { Data, Position } from '@flex-development/docast'
import type { Optional } from '@flex-development/tutils'
import type unist from 'unist'
import type TestSubject from '../node'
Expand Down
8 changes: 3 additions & 5 deletions src/nodes/__tests__/parent.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
* @module docast/nodes/tests/unit-d/Parent
*/

import type { Content } from '#src/content'
import type Comment from '../comment'
import type Node from '../node'
import type { Child, Node } from '@flex-development/docast'
import type TestSubject from '../parent'

describe('unit-d:nodes/Parent', () => {
it('should extend Node', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<Node>()
})

it('should match [children: (Comment | Content)[]]', () => {
it('should match [children: Child[]]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('children')
.toEqualTypeOf<(Comment | Content)[]>()
.toEqualTypeOf<Child[]>()
})
})
2 changes: 1 addition & 1 deletion src/nodes/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module docast/nodes/Node
*/

import type { Data, Position } from '#src/interfaces'
import type { Data, Position } from '@flex-development/docast'
import type { Optional } from '@flex-development/tutils'
import type unist from 'unist'

Expand Down
9 changes: 3 additions & 6 deletions src/nodes/parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* @module docast/nodes/Parent
*/

import type { Content } from '#src/content'
import type Comment from './comment'
import type Node from './node'
import type { Child, Node } from '@flex-development/docast'

/**
* Abstract docast node that contains other docast or mdast nodes.
Expand All @@ -18,10 +16,9 @@ interface Parent extends Node {
/**
* List of children.
*
* @see {@linkcode Comment}
* @see {@linkcode Content}
* @see {@linkcode Child}
*/
children: (Comment | Content)[]
children: Child[]
}

export type { Parent as default }
14 changes: 14 additions & 0 deletions src/types/__tests__/any-node.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file Type Tests - AnyNode
* @module docast/types/tests/unit-d/AnyNode
*/

import type { Root } from '@flex-development/docast'
import type { InclusiveDescendant } from '@flex-development/unist-util-types'
import type TestSubject from '../any-node'

describe('unit-d:types/AnyNode', () => {
it('should equal InclusiveDescendant<Root>', () => {
expectTypeOf<TestSubject>().toEqualTypeOf<InclusiveDescendant<Root>>()
})
})
14 changes: 14 additions & 0 deletions src/types/__tests__/any-parent.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file Type Tests - AnyParent
* @module docast/types/tests/unit-d/AnyParent
*/

import type { Root } from '@flex-development/docast'
import type { Parents } from '@flex-development/unist-util-types'
import type TestSubject from '../any-parent'

describe('unit-d:types/AnyParent', () => {
it('should equal Parents<Root>', () => {
expectTypeOf<TestSubject>().toEqualTypeOf<Parents<Root>>()
})
})
14 changes: 14 additions & 0 deletions src/types/__tests__/child.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file Type Tests - Child
* @module docast/types/tests/unit-d/Child
*/

import type { AnyParent } from '@flex-development/docast'
import type { Children } from '@flex-development/unist-util-types'
import type TestSubject from '../child'

describe('unit-d:types/Child', () => {
it('should equal Children<AnyParent>[number]', () => {
expectTypeOf<TestSubject>().toEqualTypeOf<Children<AnyParent>[number]>()
})
})
14 changes: 14 additions & 0 deletions src/types/any-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file Type Aliases - AnyNode
* @module docast/types/AnyNode
*/

import type { Root } from '@flex-development/docast'
import type { InclusiveDescendant } from '@flex-development/unist-util-types'

/**
* Union of nodes that can occur in docast.
*/
type AnyNode = InclusiveDescendant<Root>

export type { AnyNode as default }
18 changes: 18 additions & 0 deletions src/types/any-parent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file Type Aliases - AnyParent
* @module docast/types/AnyParent
*/

import type { Root } from '@flex-development/docast'
import type { Parents } from '@flex-development/unist-util-types'

/**
* Union of [*parents*][1] that are [*inclusive descendants*][2] of
* {@linkcode Root}.
*
* [1]: https://github.com/syntax-tree/unist#parent
* [2]: https://github.com/syntax-tree/unist#descendant
*/
type AnyParent = Parents<Root>

export type { AnyParent as default }
16 changes: 16 additions & 0 deletions src/types/child.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Type Aliases - Child
* @module docast/types/Child
*/

import type { AnyParent } from '@flex-development/docast'
import type { Children } from '@flex-development/unist-util-types'

/**
* Union of [*child*][1] nodes.
*
* [1]: https://github.com/syntax-tree/unist#child
*/
type Child = Children<AnyParent>[number]

export type { Child as default }
4 changes: 3 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
* @module docast/types
*/

export type {}
export type { default as AnyNode } from './any-node'
export type { default as AnyParent } from './any-parent'
export type { default as Child } from './child'
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ __metadata:
"@flex-development/pathe": "npm:2.0.0"
"@flex-development/tsconfig-utils": "npm:2.0.2"
"@flex-development/tutils": "npm:6.0.0-alpha.25"
"@flex-development/unist-util-types": "npm:1.2.0"
"@types/eslint": "npm:8.56.2"
"@types/is-ci": "npm:3.0.4"
"@types/mdast": "npm:4.0.3"
Expand Down Expand Up @@ -1282,6 +1283,7 @@ __metadata:
vitest: "npm:1.5.0"
yaml-eslint-parser: "npm:1.2.2"
peerDependencies:
"@flex-development/unist-util-types": ">=1.1.0"
"@types/mdast": ">=4.0.3"
"@types/unist": ">=3.0.2"
languageName: unknown
Expand Down Expand Up @@ -1653,6 +1655,15 @@ __metadata:
languageName: node
linkType: hard

"@flex-development/unist-util-types@npm:1.2.0":
version: 1.2.0
resolution: "@flex-development/unist-util-types@npm:1.2.0::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40flex-development%2Funist-util-types%2F1.2.0%2Fe73575356fb70910ec1467d05a02825d69997f22"
peerDependencies:
"@types/unist": ">=3.0.2"
checksum: 10/01f73462d6bbdb16a67aca5c77e2421fb260acc671d01628d3d1aa0debf044e226d468c033601c3bfb5cff6c47f030690d87e4e84c55ff1dcad513a4419cde0c
languageName: node
linkType: hard

"@gar/promisify@npm:^1.1.3":
version: 1.1.3
resolution: "@gar/promisify@npm:1.1.3"
Expand Down

0 comments on commit 0948945

Please sign in to comment.