@@ -11,6 +11,7 @@ import {
11
11
EnumValueDefinition ,
12
12
DirectiveDefinition ,
13
13
ImportDefinition ,
14
+ AliasDefinition ,
14
15
} from "./definitions" ;
15
16
import { Document } from "./document" ;
16
17
import { Annotation , Name } from "./nodes" ;
@@ -33,6 +34,9 @@ export class Writer {
33
34
export type ObjectMap < T = any > = { [ key : string ] : T } ;
34
35
35
36
interface NamedParameters {
37
+ importDef ?: ImportDefinition ;
38
+ directive ?: DirectiveDefinition ;
39
+ alias ?: AliasDefinition ;
36
40
role ?: RoleDefinition ;
37
41
type ?: TypeDefinition ;
38
42
operations ?: OperationDefinition [ ] ;
@@ -47,8 +51,6 @@ interface NamedParameters {
47
51
enumValues ?: EnumValueDefinition [ ] ;
48
52
enumValue ?: EnumValueDefinition ;
49
53
union ?: UnionDefinition ;
50
- directive ?: DirectiveDefinition ;
51
- importDef ?: ImportDefinition ;
52
54
annotation ?: Annotation ;
53
55
}
54
56
@@ -73,16 +75,21 @@ export class Context {
73
75
imports : ImportDefinition [ ] ;
74
76
directives : DirectiveDefinition [ ] ;
75
77
directiveMap : Map < string , DirectiveDefinition > ;
78
+ aliases : AliasDefinition [ ] ;
76
79
interface : InterfaceDefinition ;
77
80
roles : RoleDefinition [ ] ;
78
81
types : TypeDefinition [ ] ;
79
82
enums : EnumDefinition [ ] ;
80
83
unions : UnionDefinition [ ] ;
81
- allTypes : Map < string , TypeDefinition | EnumDefinition | UnionDefinition > ;
84
+ allTypes : Map <
85
+ string ,
86
+ TypeDefinition | EnumDefinition | UnionDefinition | AliasDefinition
87
+ > ;
82
88
83
89
// Drill-down definitions
84
90
importDef ?: ImportDefinition ;
85
91
directive ?: DirectiveDefinition ;
92
+ alias ?: AliasDefinition ;
86
93
role ?: RoleDefinition ;
87
94
type ?: TypeDefinition ;
88
95
operations ?: OperationDefinition [ ] ;
@@ -112,6 +119,7 @@ export class Context {
112
119
this . imports = other . imports ;
113
120
this . directives = other . directives ;
114
121
this . directiveMap = other . directiveMap ;
122
+ this . aliases = other . aliases ;
115
123
this . interface = other . interface ;
116
124
this . roles = other . roles ;
117
125
this . enums = other . enums ;
@@ -125,12 +133,13 @@ export class Context {
125
133
} else {
126
134
this . namespace = new NamespaceDefinition (
127
135
undefined ,
128
- undefined ,
129
- new Name ( undefined , "" )
136
+ new Name ( undefined , "" ) ,
137
+ undefined
130
138
) ;
131
139
this . directives = new Array < DirectiveDefinition > ( ) ;
132
140
this . directiveMap = new Map < string , DirectiveDefinition > ( ) ;
133
141
this . imports = new Array < ImportDefinition > ( ) ;
142
+ this . aliases = new Array < AliasDefinition > ( ) ;
134
143
this . interface = new InterfaceDefinition ( ) ;
135
144
this . roles = new Array < RoleDefinition > ( ) ;
136
145
this . enums = new Array < EnumDefinition > ( ) ;
@@ -154,6 +163,9 @@ export class Context {
154
163
}
155
164
156
165
clone ( {
166
+ importDef,
167
+ directive,
168
+ alias,
157
169
role,
158
170
type,
159
171
operations,
@@ -168,14 +180,13 @@ export class Context {
168
180
enumValues,
169
181
enumValue,
170
182
union,
171
- directive,
172
- importDef,
173
183
annotation,
174
184
} : NamedParameters ) : Context {
175
185
var context = new Context ( this . config , undefined , this ) ;
176
186
177
187
context . importDef = importDef || this . importDef ;
178
188
context . directive = directive || this . directive ;
189
+ context . alias = alias || this . alias ;
179
190
context . role = role || this . role ;
180
191
context . type = type || this . type ;
181
192
context . operations = operations || this . operations ;
@@ -209,6 +220,11 @@ export class Context {
209
220
case Kind . ImportDefinition :
210
221
this . imports . push ( value as ImportDefinition ) ;
211
222
break ;
223
+ case Kind . AliasDefinition :
224
+ const alias = value as AliasDefinition ;
225
+ this . aliases . push ( alias ) ;
226
+ this . allTypes . set ( alias . name . value , alias ) ;
227
+ break ;
212
228
case Kind . InterfaceDefinition :
213
229
this . interface = value as InterfaceDefinition ;
214
230
break ;
@@ -261,6 +277,12 @@ export interface Visitor {
261
277
visitDirectiveAfter ( context : Context ) : void ;
262
278
visitDirectivesAfter ( context : Context ) : void ;
263
279
280
+ visitAliasesBefore ( context : Context ) : void ;
281
+ visitAliasBefore ( context : Context ) : void ;
282
+ visitAlias ( context : Context ) : void ;
283
+ visitAliasAfter ( context : Context ) : void ;
284
+ visitAliasesAfter ( context : Context ) : void ;
285
+
264
286
visitAllOperationsBefore ( context : Context ) : void ;
265
287
visitInterfaceBefore ( context : Context ) : void ;
266
288
visitInterface ( context : Context ) : void ;
@@ -419,6 +441,37 @@ export abstract class AbstractVisitor implements Visitor {
419
441
this . triggerCallbacks ( context , "DirectivesAfter" ) ;
420
442
}
421
443
444
+ public visitAliasesBefore ( context : Context ) : void {
445
+ this . triggerAliasesBefore ( context ) ;
446
+ }
447
+ public triggerAliasesBefore ( context : Context ) : void {
448
+ this . triggerCallbacks ( context , "AliasesBefore" ) ;
449
+ }
450
+ public visitAliasBefore ( context : Context ) : void {
451
+ this . triggerAliasBefore ( context ) ;
452
+ }
453
+ public triggerAliasBefore ( context : Context ) : void {
454
+ this . triggerCallbacks ( context , "AliasBefore" ) ;
455
+ }
456
+ public visitAlias ( context : Context ) : void {
457
+ this . triggerAlias ( context ) ;
458
+ }
459
+ public triggerAlias ( context : Context ) : void {
460
+ this . triggerCallbacks ( context , "Alias" ) ;
461
+ }
462
+ public visitAliasAfter ( context : Context ) : void {
463
+ this . triggerAliasBefore ( context ) ;
464
+ }
465
+ public triggerAliasAfter ( context : Context ) : void {
466
+ this . triggerCallbacks ( context , "AliasAfter" ) ;
467
+ }
468
+ public visitAliasesAfter ( context : Context ) : void {
469
+ this . triggerAliasesAfter ( context ) ;
470
+ }
471
+ public triggerAliasesAfter ( context : Context ) : void {
472
+ this . triggerCallbacks ( context , "AliasesAfter" ) ;
473
+ }
474
+
422
475
public visitAllOperationsBefore ( context : Context ) : void {
423
476
this . triggerAllOperationsBefore ( context ) ;
424
477
}
@@ -748,6 +801,11 @@ export class MultiVisitor extends AbstractVisitor {
748
801
visitor . visitDirectivesBefore ( context ) ;
749
802
} ) ;
750
803
}
804
+ public visitDirectiveBefore ( context : Context ) : void {
805
+ this . visitors . map ( ( visitor ) => {
806
+ visitor . visitDirectiveBefore ( context ) ;
807
+ } ) ;
808
+ }
751
809
public visitDirective ( context : Context ) : void {
752
810
this . visitors . map ( ( visitor ) => {
753
811
visitor . visitDirective ( context ) ;
@@ -768,12 +826,43 @@ export class MultiVisitor extends AbstractVisitor {
768
826
visitor . visitDirectiveParametersAfter ( context ) ;
769
827
} ) ;
770
828
}
829
+ public visitDirectiveAfter ( context : Context ) : void {
830
+ this . visitors . map ( ( visitor ) => {
831
+ visitor . visitDirectiveAfter ( context ) ;
832
+ } ) ;
833
+ }
771
834
public visitDirectivesAfter ( context : Context ) : void {
772
835
this . visitors . map ( ( visitor ) => {
773
836
visitor . visitDirectivesAfter ( context ) ;
774
837
} ) ;
775
838
}
776
839
840
+ public visitAliasesBefore ( context : Context ) : void {
841
+ this . visitors . map ( ( visitor ) => {
842
+ visitor . visitAliasesBefore ( context ) ;
843
+ } ) ;
844
+ }
845
+ public visitAliasBefore ( context : Context ) : void {
846
+ this . visitors . map ( ( visitor ) => {
847
+ visitor . visitAliasBefore ( context ) ;
848
+ } ) ;
849
+ }
850
+ public visitAlias ( context : Context ) : void {
851
+ this . visitors . map ( ( visitor ) => {
852
+ visitor . visitAlias ( context ) ;
853
+ } ) ;
854
+ }
855
+ public visitAliasAfter ( context : Context ) : void {
856
+ this . visitors . map ( ( visitor ) => {
857
+ visitor . visitAliasAfter ( context ) ;
858
+ } ) ;
859
+ }
860
+ public visitAliasesAfter ( context : Context ) : void {
861
+ this . visitors . map ( ( visitor ) => {
862
+ visitor . visitAliasesAfter ( context ) ;
863
+ } ) ;
864
+ }
865
+
777
866
public visitAllOperationsBefore ( context : Context ) : void {
778
867
this . visitors . map ( ( visitor ) => {
779
868
visitor . visitAllOperationsBefore ( context ) ;
0 commit comments