1
- import type { ReadonlyVisitor } from '@nestjs/cli/lib/compiler/interfaces/readonly-visitor.interface' ;
2
1
import { hasDecorators } from '@nestjs/graphql/dist/plugin/utils/ast-utils.js' ;
3
2
import * as ts from 'typescript' ;
4
3
5
4
const securedKeys = [ 'value' , 'canRead' , 'canEdit' ] ;
6
5
7
6
export class ResourceVisitor {
8
- constructor ( readonly readonly = false ) { }
7
+ constructor ( readonly = false ) {
8
+ this . readonly = readonly ;
9
+ }
9
10
10
- visit ( sf : ts . SourceFile , ctx : ts . TransformationContext , program : ts . Program ) {
11
+ /**
12
+ * @param sf {ts.SourceFile}
13
+ * @param ctx {ts.TransformationContext}
14
+ * @param program {ts.Program}
15
+ * @returns {ts.Node }
16
+ */
17
+ visit ( sf , ctx , program ) {
11
18
if ( ! sf . fileName . endsWith ( 'dto.ts' ) ) {
12
19
return sf ;
13
20
}
14
21
const { factory } = ctx ;
15
- const visitNode = ( node : ts . Node ) : ts . Node => {
22
+ /**
23
+ * @param node {ts.Node}
24
+ * @returns {ts.Node }
25
+ */
26
+ const visitNode = ( node ) => {
16
27
const decorators =
17
28
( ts . canHaveDecorators ( node ) && ts . getDecorators ( node ) ) || [ ] ;
18
29
if (
@@ -32,11 +43,13 @@ export class ResourceVisitor {
32
43
return ts . visitNode ( sf , visitNode ) ;
33
44
}
34
45
35
- private enhanceDtoClass (
36
- classNode : ts . ClassDeclaration ,
37
- program : ts . Program ,
38
- factory : ts . NodeFactory ,
39
- ) {
46
+ /**
47
+ * @param classNode {ts.ClassDeclaration}
48
+ * @param program {ts.Program}
49
+ * @param factory {ts.NodeFactory}
50
+ * @returns {ts.ClassDeclaration }
51
+ */
52
+ enhanceDtoClass ( classNode , program , factory ) {
40
53
const typeChecker = program . getTypeChecker ( ) ;
41
54
42
55
const classProps = typeChecker
@@ -61,11 +74,13 @@ export class ResourceVisitor {
61
74
] ) ;
62
75
}
63
76
64
- private createStaticPropArray (
65
- factory : ts . NodeFactory ,
66
- name : string ,
67
- members : ts . Symbol [ ] ,
68
- ) {
77
+ /**
78
+ * @param factory {ts.NodeFactory}
79
+ * @param name {string}
80
+ * @param members {ts.Symbol[]}
81
+ * @returns {ts.PropertyDeclaration }
82
+ */
83
+ createStaticPropArray ( factory , name , members ) {
69
84
return factory . createPropertyDeclaration (
70
85
[
71
86
factory . createModifier ( ts . SyntaxKind . StaticKeyword ) ,
@@ -80,11 +95,13 @@ export class ResourceVisitor {
80
95
) ;
81
96
}
82
97
83
- private updateClassMembers (
84
- factory : ts . NodeFactory ,
85
- classNode : ts . ClassDeclaration ,
86
- newMembers : readonly ts . ClassElement [ ] ,
87
- ) {
98
+ /**
99
+ * @param factory {ts.NodeFactory}
100
+ * @param classNode {ts.ClassDeclaration}
101
+ * @param newMembers {readonly ts.ClassElement[]}
102
+ * @returns {ts.ClassDeclaration }
103
+ */
104
+ updateClassMembers ( factory , classNode , newMembers ) {
88
105
return factory . updateClassDeclaration (
89
106
classNode ,
90
107
classNode . modifiers ,
@@ -96,16 +113,22 @@ export class ResourceVisitor {
96
113
}
97
114
}
98
115
99
- export class ResourceReadonlyVisitor implements ReadonlyVisitor {
100
- readonly key = '@cord/resources' ;
101
- private readonly visitor = new ResourceVisitor ( true ) ;
116
+ export class ResourceReadonlyVisitor {
117
+ key = '@cord/resources' ;
118
+ visitor = new ResourceVisitor ( true ) ;
102
119
103
120
get typeImports ( ) {
104
121
return { } ;
105
122
}
106
123
107
- visit ( program : ts . Program , sf : ts . SourceFile ) {
108
- const factoryHost = { factory : ts . factory } as any ;
124
+ /**
125
+ * @param program {ts.Program}
126
+ * @param sf {ts.SourceFile}
127
+ * @returns {ts.Node }
128
+ */
129
+ visit ( program , sf ) {
130
+ /** @type {* } */
131
+ const factoryHost = { factory : ts . factory } ;
109
132
return this . visitor . visit ( sf , factoryHost , program ) ;
110
133
}
111
134
0 commit comments