-
Notifications
You must be signed in to change notification settings - Fork 280
/
create-type-node.ts
38 lines (33 loc) · 1.02 KB
/
create-type-node.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { freeze } from '../util/object-utils.js'
import { OperationNode } from './operation-node.js'
import { SchemableIdentifierNode } from './schemable-identifier-node.js'
import { ValueListNode } from './value-list-node.js'
import { ValueNode } from './value-node.js'
export type CreateTypeNodeParams = Omit<Partial<CreateTypeNode>, 'kind'>
export interface CreateTypeNode extends OperationNode {
readonly kind: 'CreateTypeNode'
readonly name: SchemableIdentifierNode
readonly enum?: ValueListNode
}
/**
* @internal
*/
export const CreateTypeNode = freeze({
is(node: OperationNode): node is CreateTypeNode {
return node.kind === 'CreateTypeNode'
},
create(name: SchemableIdentifierNode): CreateTypeNode {
return freeze({
kind: 'CreateTypeNode',
name,
})
},
cloneWithEnum(createType: CreateTypeNode, values: string[]): CreateTypeNode {
return freeze({
...createType,
enum: ValueListNode.create(
values.map((value) => ValueNode.createImmediate(value))
),
})
},
})