@@ -177,25 +177,25 @@ export type OrderedGraph = Graph<Ordered>
177
177
export type OrderedCodeBlock = CodeBlockProps & Ordered
178
178
179
179
export function isChoice < T extends Unordered | Ordered = Unordered > ( graph : Graph < T > ) : graph is Choice < T > {
180
- return Array . isArray ( ( graph as Choice ) . choices )
180
+ return graph && Array . isArray ( ( graph as Choice ) . choices )
181
181
}
182
182
183
183
export function isSequence < T extends Unordered | Ordered = Unordered > ( graph : Graph < T > ) : graph is Sequence < T > {
184
- return Array . isArray ( ( graph as Sequence ) . sequence )
184
+ return graph && Array . isArray ( ( graph as Sequence ) . sequence )
185
185
}
186
186
187
187
export function isParallel < T extends Unordered | Ordered = Unordered > ( graph : Graph < T > ) : graph is Parallel < T > {
188
- return Array . isArray ( ( graph as Parallel ) . parallel )
188
+ return graph && Array . isArray ( ( graph as Parallel ) . parallel )
189
189
}
190
190
191
191
export function isTitledSteps < T extends Unordered | Ordered = Unordered > ( graph : Graph < T > ) : graph is TitledSteps < T > {
192
192
const ts = graph as TitledSteps < T >
193
- return typeof ts . title === 'string' && Array . isArray ( ts . steps )
193
+ return ts && typeof ts . title === 'string' && Array . isArray ( ts . steps )
194
194
}
195
195
196
196
export function isSubTask < T extends Unordered | Ordered = Unordered > ( graph : Graph < T > ) : graph is SubTask < T > {
197
197
const subtask = graph as SubTask
198
- return typeof subtask . key === 'string' && typeof subtask . filepath === 'string'
198
+ return subtask && typeof subtask . key === 'string' && typeof subtask . filepath === 'string'
199
199
}
200
200
201
201
function sameCodeBlock ( a : CodeBlockProps , b : CodeBlockProps ) {
@@ -208,6 +208,15 @@ function sameCodeBlock(a: CodeBlockProps, b: CodeBlockProps) {
208
208
)
209
209
}
210
210
211
+ export function isEmpty ( A : Graph ) : boolean {
212
+ return (
213
+ ( isSequence ( A ) && A . sequence . length === 0 ) ||
214
+ ( isParallel ( A ) && A . parallel . length === 0 ) ||
215
+ ( isTitledSteps ( A ) && A . steps . length === 0 ) ||
216
+ ( isChoice ( A ) && A . choices . length === 0 )
217
+ )
218
+ }
219
+
211
220
export function sameGraph ( A : Graph , B : Graph ) {
212
221
if ( isChoice ( A ) ) {
213
222
return isChoice ( B ) && sameChoice ( A , B )
0 commit comments