1
1
import { Field , InterfaceType , ObjectType } from '@nestjs/graphql' ;
2
2
import { many , Many } from '@seedcompany/common' ;
3
3
import { stripIndent } from 'common-tags' ;
4
- import { EnumType , makeEnum } from '~/common' ;
4
+ import * as uuid from 'uuid' ;
5
+ import { EnumType , ID , IdField , makeEnum } from '~/common' ;
5
6
import { InlineMarkdownScalar } from '~/common/markdown.scalar' ;
6
7
import { Cell } from '~/common/xlsx.util' ;
7
8
@@ -13,6 +14,9 @@ export const PnpProblemSeverity = makeEnum({
13
14
14
15
@ObjectType ( )
15
16
export class PnpProblem {
17
+ @IdField ( )
18
+ readonly id : ID ;
19
+
16
20
@Field ( ( ) => PnpProblemSeverity )
17
21
readonly severity : PnpProblemSeverity ;
18
22
@@ -38,17 +42,30 @@ export class PnpProblem {
38
42
39
43
@InterfaceType ( )
40
44
export abstract class PnpExtractionResult {
45
+ constructor ( private readonly fileVersionId : ID < 'FileVersion' > ) { }
46
+
41
47
@Field ( ( ) => [ PnpProblem ] )
42
48
readonly problems : PnpProblem [ ] = [ ] ;
43
49
44
50
addProblem (
45
- problem : Omit < PnpProblem , 'groups' | 'source' > & {
51
+ problem : Omit < PnpProblem , 'id' | 'groups' | 'source' > & {
52
+ id ?: string ;
46
53
groups ?: Many < string > ;
47
54
source : Cell ;
48
55
} ,
49
56
) {
57
+ const id = ( problem . id ??
58
+ uuid . v5 (
59
+ [ this . fileVersionId , problem . message , problem . source . fqn ] . join ( '\0' ) ,
60
+ ID_NS ,
61
+ ) ) as ID ;
62
+
63
+ // Ignore dupes
64
+ if ( this . problems . some ( ( p ) => p . id === id ) ) return ;
65
+
50
66
this . problems . push ( {
51
67
...problem ,
68
+ id,
52
69
groups : [ problem . source . sheet . name , ...many ( problem . groups ?? [ ] ) ] ,
53
70
source : problem . source . fqn ,
54
71
} ) ;
@@ -58,3 +75,5 @@ export abstract class PnpExtractionResult {
58
75
export class PnpPlanningExtractionResult extends PnpExtractionResult { }
59
76
@ObjectType ( { implements : PnpExtractionResult } )
60
77
export class PnpProgressExtractionResult extends PnpExtractionResult { }
78
+
79
+ const ID_NS = 'bab2666a-a0f5-4168-977d-7ef6399503f9' ;
0 commit comments