1
1
import { inject , injectable , singleton } from "tsyringe" ;
2
2
import {
3
3
AreProofsEnabled ,
4
+ CompileArtifact ,
4
5
mapSequential ,
5
- MOCK_VERIFICATION_KEY ,
6
6
} from "@proto-kit/common" ;
7
7
8
- import {
9
- Artifact ,
10
- AtomicCompileHelper ,
11
- GenericCompileTarget ,
12
- } from "./AtomicCompileHelper" ;
8
+ import { ArtifactRecord , AtomicCompileHelper } from "./AtomicCompileHelper" ;
13
9
import { CompilableModule } from "./CompilableModule" ;
14
10
15
11
/**
@@ -29,61 +25,60 @@ export class CompileRegistry {
29
25
30
26
public compile : AtomicCompileHelper ;
31
27
32
- private artifacts : Record < string , Artifact | "compiled-but-no-artifact" > = { } ;
28
+ private artifacts : ArtifactRecord = { } ;
33
29
34
- public async compileModule < ReturnArtifact extends Artifact > (
35
- // TODO Make name inferred by the module token
36
- name : string ,
30
+ public async compileModule (
37
31
compile : (
38
- registry : CompileRegistry ,
32
+ compiler : AtomicCompileHelper ,
39
33
...args : unknown [ ]
40
- ) => GenericCompileTarget < ReturnArtifact > ,
34
+ ) => Promise < ArtifactRecord > ,
41
35
dependencies : Record < string , CompilableModule > = { }
42
- ) : Promise < ReturnArtifact | undefined > {
36
+ ) : Promise < ArtifactRecord | undefined > {
43
37
const collectedArtifacts = await mapSequential (
44
38
Object . entries ( dependencies ) ,
45
39
async ( [ depName , dep ] ) => {
46
40
if ( this . artifacts [ depName ] !== undefined ) {
47
41
return this . artifacts [ depName ] ;
48
42
}
49
- const artifact =
50
- ( await dep . compile ( this ) ) ?? "compiled-but-no-artifact" ;
51
- this . artifacts [ depName ] = artifact ;
43
+ const artifact = await dep . compile ( this ) ;
44
+ if ( artifact !== undefined ) {
45
+ this . artifacts = {
46
+ ...this . artifacts ,
47
+ ...artifact ,
48
+ } ;
49
+ }
52
50
return artifact ;
53
51
}
54
52
) ;
55
53
56
- const target = compile ( this , ...collectedArtifacts ) ;
57
- const artifact = await this . compile . program < ReturnArtifact > ( name , target ) ;
54
+ const artifacts = await compile ( this . compile , ...collectedArtifacts ) ;
58
55
59
- this . artifacts [ name ] = artifact ?? "compiled-but-no-artifact" ;
56
+ this . artifacts = {
57
+ ...this . artifacts ,
58
+ ...artifacts ,
59
+ } ;
60
60
61
- return artifact ;
61
+ return artifacts ;
62
62
}
63
63
64
- public getArtifact < ArtifactType extends Artifact > ( name : string ) {
64
+ public getArtifact ( name : string ) {
65
65
if ( this . artifacts [ name ] === undefined ) {
66
66
throw new Error (
67
67
`Artifact for ${ name } not available, did you compile it via the CompileRegistry?`
68
68
) ;
69
69
}
70
- if ( ! this . areProofsEnabled . areProofsEnabled ) {
71
- return MOCK_VERIFICATION_KEY ;
72
- }
73
70
74
- const artifact = this . artifacts [ name ] ;
75
- if ( artifact === "compiled-but-no-artifact" ) {
76
- throw new Error (
77
- `Module ${ name } didn't return the requested artifact even though proofs are enabled`
78
- ) ;
79
- }
80
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
81
- return artifact as ArtifactType ;
71
+ return this . artifacts [ name ] ;
72
+ }
73
+
74
+ public addArtifactsRaw ( artifacts : ArtifactRecord ) {
75
+ this . artifacts = {
76
+ ... this . artifacts ,
77
+ ... artifacts ,
78
+ } ;
82
79
}
83
80
84
- public addArtifactsRaw ( artifacts : Record < string , Artifact > ) {
85
- Object . entries ( artifacts ) . forEach ( ( [ key , value ] ) => {
86
- this . artifacts [ key ] = value ;
87
- } ) ;
81
+ public getAllArtifacts ( ) {
82
+ return this . artifacts ;
88
83
}
89
84
}
0 commit comments