@proto-kit/common 0.1.1-develop.191 → 0.1.1-develop.2024

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/dist/compiling/AtomicCompileHelper.d.ts +13 -0
  2. package/dist/compiling/AtomicCompileHelper.d.ts.map +1 -0
  3. package/dist/compiling/AtomicCompileHelper.js +40 -0
  4. package/dist/compiling/AtomicCompileHelper.js.map +1 -0
  5. package/dist/compiling/CompilableModule.d.ts +6 -0
  6. package/dist/compiling/CompilableModule.d.ts.map +1 -0
  7. package/dist/compiling/CompilableModule.js +2 -0
  8. package/dist/compiling/CompilableModule.js.map +1 -0
  9. package/dist/compiling/CompileRegistry.d.ts +26 -0
  10. package/dist/compiling/CompileRegistry.d.ts.map +1 -0
  11. package/dist/compiling/CompileRegistry.js +67 -0
  12. package/dist/compiling/CompileRegistry.js.map +1 -0
  13. package/dist/compiling/services/ChildVerificationKeyService.d.ts +10 -0
  14. package/dist/compiling/services/ChildVerificationKeyService.d.ts.map +1 -0
  15. package/dist/compiling/services/ChildVerificationKeyService.js +27 -0
  16. package/dist/compiling/services/ChildVerificationKeyService.js.map +1 -0
  17. package/dist/config/ChildContainerCreatable.d.ts +5 -0
  18. package/dist/config/ChildContainerCreatable.d.ts.map +1 -0
  19. package/dist/config/ChildContainerCreatable.js +2 -0
  20. package/dist/config/ChildContainerCreatable.js.map +1 -0
  21. package/dist/config/ChildContainerProvider.d.ts +5 -0
  22. package/dist/config/ChildContainerProvider.d.ts.map +1 -0
  23. package/dist/config/ChildContainerProvider.js +2 -0
  24. package/dist/config/ChildContainerProvider.js.map +1 -0
  25. package/dist/config/ConfigurableModule.d.ts +6 -2
  26. package/dist/config/ConfigurableModule.d.ts.map +1 -1
  27. package/dist/config/ConfigurableModule.js +5 -0
  28. package/dist/config/ConfigurableModule.js.map +1 -0
  29. package/dist/config/ModuleContainer.d.ts +70 -23
  30. package/dist/config/ModuleContainer.d.ts.map +1 -1
  31. package/dist/config/ModuleContainer.js +164 -31
  32. package/dist/config/ModuleContainer.js.map +1 -0
  33. package/dist/config/Startable.d.ts +4 -0
  34. package/dist/config/Startable.d.ts.map +1 -0
  35. package/dist/config/Startable.js +2 -0
  36. package/dist/config/Startable.js.map +1 -0
  37. package/dist/config/injectAlias.d.ts +18 -0
  38. package/dist/config/injectAlias.d.ts.map +1 -0
  39. package/dist/config/injectAlias.js +47 -0
  40. package/dist/config/injectAlias.js.map +1 -0
  41. package/dist/dependencyFactory/DependencyFactory.d.ts +14 -9
  42. package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
  43. package/dist/dependencyFactory/DependencyFactory.js +2 -96
  44. package/dist/dependencyFactory/DependencyFactory.js.map +1 -0
  45. package/dist/dependencyFactory/injectOptional.d.ts +16 -0
  46. package/dist/dependencyFactory/injectOptional.d.ts.map +1 -0
  47. package/dist/dependencyFactory/injectOptional.js +40 -0
  48. package/dist/dependencyFactory/injectOptional.js.map +1 -0
  49. package/dist/dummyVerificationKey.d.ts +3 -0
  50. package/dist/dummyVerificationKey.d.ts.map +1 -0
  51. package/dist/dummyVerificationKey.js +8 -0
  52. package/dist/dummyVerificationKey.js.map +1 -0
  53. package/dist/events/EventEmitter.d.ts +19 -0
  54. package/dist/events/EventEmitter.d.ts.map +1 -0
  55. package/dist/events/EventEmitter.js +35 -0
  56. package/dist/events/EventEmitter.js.map +1 -0
  57. package/dist/events/EventEmitterProxy.d.ts +18 -0
  58. package/dist/events/EventEmitterProxy.d.ts.map +1 -0
  59. package/dist/events/EventEmitterProxy.js +35 -0
  60. package/dist/events/EventEmitterProxy.js.map +1 -0
  61. package/dist/events/EventEmittingComponent.d.ts +9 -0
  62. package/dist/events/EventEmittingComponent.d.ts.map +1 -0
  63. package/dist/events/EventEmittingComponent.js +2 -0
  64. package/dist/events/EventEmittingComponent.js.map +1 -0
  65. package/dist/events/ReplayingSingleUseEventEmitter.d.ts +17 -0
  66. package/dist/events/ReplayingSingleUseEventEmitter.d.ts.map +1 -0
  67. package/dist/events/ReplayingSingleUseEventEmitter.js +34 -0
  68. package/dist/events/ReplayingSingleUseEventEmitter.js.map +1 -0
  69. package/dist/index.d.ts +23 -1
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +24 -2
  72. package/dist/index.js.map +1 -0
  73. package/dist/log.d.ts +37 -0
  74. package/dist/log.d.ts.map +1 -0
  75. package/dist/log.js +117 -0
  76. package/dist/log.js.map +1 -0
  77. package/dist/trees/InMemoryLinkedLeafStore.d.ts +21 -0
  78. package/dist/trees/InMemoryLinkedLeafStore.d.ts.map +1 -0
  79. package/dist/trees/InMemoryLinkedLeafStore.js +26 -0
  80. package/dist/trees/InMemoryLinkedLeafStore.js.map +1 -0
  81. package/dist/trees/InMemoryLinkedMerkleLeafStore.d.ts +7 -0
  82. package/dist/trees/InMemoryLinkedMerkleLeafStore.d.ts.map +1 -0
  83. package/dist/trees/InMemoryLinkedMerkleLeafStore.js +6 -0
  84. package/dist/trees/InMemoryLinkedMerkleLeafStore.js.map +1 -0
  85. package/dist/trees/InMemoryMerkleTreeStorage.d.ts +11 -0
  86. package/dist/trees/InMemoryMerkleTreeStorage.d.ts.map +1 -0
  87. package/dist/trees/InMemoryMerkleTreeStorage.js +13 -0
  88. package/dist/trees/InMemoryMerkleTreeStorage.js.map +1 -0
  89. package/dist/trees/LinkedMerkleTree.d.ts +345 -0
  90. package/dist/trees/LinkedMerkleTree.d.ts.map +1 -0
  91. package/dist/trees/LinkedMerkleTree.js +337 -0
  92. package/dist/trees/LinkedMerkleTree.js.map +1 -0
  93. package/dist/trees/LinkedMerkleTreeStore.d.ts +24 -0
  94. package/dist/trees/LinkedMerkleTreeStore.d.ts.map +1 -0
  95. package/dist/trees/LinkedMerkleTreeStore.js +2 -0
  96. package/dist/trees/LinkedMerkleTreeStore.js.map +1 -0
  97. package/dist/trees/MerkleTreeStore.d.ts +5 -0
  98. package/dist/trees/MerkleTreeStore.d.ts.map +1 -0
  99. package/dist/trees/MerkleTreeStore.js +2 -0
  100. package/dist/trees/MerkleTreeStore.js.map +1 -0
  101. package/dist/trees/MockAsyncMerkleStore.d.ts +9 -0
  102. package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -0
  103. package/dist/trees/MockAsyncMerkleStore.js +20 -0
  104. package/dist/trees/MockAsyncMerkleStore.js.map +1 -0
  105. package/dist/trees/RollupMerkleTree.d.ts +147 -0
  106. package/dist/trees/RollupMerkleTree.d.ts.map +1 -0
  107. package/dist/trees/RollupMerkleTree.js +218 -0
  108. package/dist/trees/RollupMerkleTree.js.map +1 -0
  109. package/dist/trees/VirtualMerkleTreeStore.d.ts +13 -0
  110. package/dist/trees/VirtualMerkleTreeStore.d.ts.map +1 -0
  111. package/dist/trees/VirtualMerkleTreeStore.js +18 -0
  112. package/dist/trees/VirtualMerkleTreeStore.js.map +1 -0
  113. package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts +288 -0
  114. package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts.map +1 -0
  115. package/dist/trees/lmt/AbstractLinkedMerkleTree.js +22 -0
  116. package/dist/trees/lmt/AbstractLinkedMerkleTree.js.map +1 -0
  117. package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts +21 -0
  118. package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts.map +1 -0
  119. package/dist/trees/lmt/InMemoryLinkedLeafStore.js +26 -0
  120. package/dist/trees/lmt/InMemoryLinkedLeafStore.js.map +1 -0
  121. package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.d.ts +7 -0
  122. package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.d.ts.map +1 -0
  123. package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.js +6 -0
  124. package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.js.map +1 -0
  125. package/dist/trees/lmt/LinkedLeafStore.d.ts +16 -0
  126. package/dist/trees/lmt/LinkedLeafStore.d.ts.map +1 -0
  127. package/dist/trees/lmt/LinkedLeafStore.js +2 -0
  128. package/dist/trees/lmt/LinkedLeafStore.js.map +1 -0
  129. package/dist/trees/lmt/LinkedLinkedStore.d.ts +16 -0
  130. package/dist/trees/lmt/LinkedLinkedStore.d.ts.map +1 -0
  131. package/dist/trees/lmt/LinkedLinkedStore.js +2 -0
  132. package/dist/trees/lmt/LinkedLinkedStore.js.map +1 -0
  133. package/dist/trees/lmt/LinkedMerkleTree.d.ts +11 -0
  134. package/dist/trees/lmt/LinkedMerkleTree.d.ts.map +1 -0
  135. package/dist/trees/lmt/LinkedMerkleTree.js +241 -0
  136. package/dist/trees/lmt/LinkedMerkleTree.js.map +1 -0
  137. package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts +113 -0
  138. package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts.map +1 -0
  139. package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js +113 -0
  140. package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js.map +1 -0
  141. package/dist/trees/lmt/LinkedMerkleTreeDatabase.d.ts +7 -0
  142. package/dist/trees/lmt/LinkedMerkleTreeDatabase.d.ts.map +1 -0
  143. package/dist/trees/lmt/LinkedMerkleTreeDatabase.js +2 -0
  144. package/dist/trees/lmt/LinkedMerkleTreeDatabase.js.map +1 -0
  145. package/dist/trees/lmt/LinkedMerkleTreeStore.d.ts +16 -0
  146. package/dist/trees/lmt/LinkedMerkleTreeStore.d.ts.map +1 -0
  147. package/dist/trees/lmt/LinkedMerkleTreeStore.js +2 -0
  148. package/dist/trees/lmt/LinkedMerkleTreeStore.js.map +1 -0
  149. package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts +74 -0
  150. package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts.map +1 -0
  151. package/dist/trees/lmt/LinkedMerkleTreeTypes.js +50 -0
  152. package/dist/trees/lmt/LinkedMerkleTreeTypes.js.map +1 -0
  153. package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts +11 -0
  154. package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts.map +1 -0
  155. package/dist/trees/sparse/InMemoryMerkleTreeStorage.js +13 -0
  156. package/dist/trees/sparse/InMemoryMerkleTreeStorage.js.map +1 -0
  157. package/dist/trees/sparse/MerkleTreeStore.d.ts +5 -0
  158. package/dist/trees/sparse/MerkleTreeStore.d.ts.map +1 -0
  159. package/dist/trees/sparse/MerkleTreeStore.js +2 -0
  160. package/dist/trees/sparse/MerkleTreeStore.js.map +1 -0
  161. package/dist/trees/sparse/MockAsyncMerkleStore.d.ts +9 -0
  162. package/dist/trees/sparse/MockAsyncMerkleStore.d.ts.map +1 -0
  163. package/dist/trees/sparse/MockAsyncMerkleStore.js +20 -0
  164. package/dist/trees/sparse/MockAsyncMerkleStore.js.map +1 -0
  165. package/dist/trees/sparse/RollupMerkleTree.d.ts +158 -0
  166. package/dist/trees/sparse/RollupMerkleTree.d.ts.map +1 -0
  167. package/dist/trees/sparse/RollupMerkleTree.js +330 -0
  168. package/dist/trees/sparse/RollupMerkleTree.js.map +1 -0
  169. package/dist/types.d.ts +62 -0
  170. package/dist/types.d.ts.map +1 -1
  171. package/dist/types.js +14 -1
  172. package/dist/types.js.map +1 -0
  173. package/dist/union/union.d.ts +177 -0
  174. package/dist/union/union.d.ts.map +1 -0
  175. package/dist/union/union.js +35 -0
  176. package/dist/union/union.js.map +1 -0
  177. package/dist/utils.d.ts +64 -1
  178. package/dist/utils.d.ts.map +1 -1
  179. package/dist/utils.js +165 -3
  180. package/dist/utils.js.map +1 -0
  181. package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +4 -3
  182. package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -1
  183. package/dist/zkProgrammable/ProvableMethodExecutionContext.js +2 -3
  184. package/dist/zkProgrammable/ProvableMethodExecutionContext.js.map +1 -0
  185. package/dist/zkProgrammable/ZkProgrammable.d.ts +23 -9
  186. package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
  187. package/dist/zkProgrammable/ZkProgrammable.js +34 -15
  188. package/dist/zkProgrammable/ZkProgrammable.js.map +1 -0
  189. package/dist/zkProgrammable/provableMethod.d.ts +8 -5
  190. package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
  191. package/dist/zkProgrammable/provableMethod.js +30 -15
  192. package/dist/zkProgrammable/provableMethod.js.map +1 -0
  193. package/jest.config.cjs +12 -1
  194. package/package.json +8 -7
  195. package/src/compiling/AtomicCompileHelper.ts +62 -0
  196. package/src/compiling/CompilableModule.ts +6 -0
  197. package/src/compiling/CompileRegistry.ts +74 -0
  198. package/src/compiling/services/ChildVerificationKeyService.ts +26 -0
  199. package/src/config/ChildContainerCreatable.ts +5 -0
  200. package/src/config/ChildContainerProvider.ts +5 -0
  201. package/src/config/ConfigurableModule.ts +15 -2
  202. package/src/config/ModuleContainer.ts +286 -58
  203. package/src/config/Startable.ts +3 -0
  204. package/src/config/injectAlias.ts +70 -0
  205. package/src/dependencyFactory/DependencyFactory.ts +34 -109
  206. package/src/dummyVerificationKey.ts +10 -0
  207. package/src/events/EventEmitter.ts +61 -0
  208. package/src/events/EventEmitterProxy.ts +81 -0
  209. package/src/events/EventEmittingComponent.ts +11 -0
  210. package/src/events/ReplayingSingleUseEventEmitter.ts +42 -0
  211. package/src/index.ts +23 -2
  212. package/src/log.ts +145 -0
  213. package/src/trees/lmt/AbstractLinkedMerkleTree.ts +102 -0
  214. package/src/trees/lmt/InMemoryLinkedLeafStore.ts +42 -0
  215. package/src/trees/lmt/LinkedLeafStore.ts +13 -0
  216. package/src/trees/lmt/LinkedMerkleTree.ts +335 -0
  217. package/src/trees/lmt/LinkedMerkleTreeCircuitOps.ts +188 -0
  218. package/src/trees/lmt/LinkedMerkleTreeTypes.ts +53 -0
  219. package/src/trees/sparse/InMemoryMerkleTreeStorage.ts +17 -0
  220. package/src/trees/sparse/MerkleTreeStore.ts +5 -0
  221. package/src/trees/sparse/MockAsyncMerkleStore.ts +30 -0
  222. package/src/trees/sparse/RollupMerkleTree.ts +512 -0
  223. package/src/types.ts +53 -2
  224. package/src/utils.ts +298 -3
  225. package/src/zkProgrammable/ProvableMethodExecutionContext.ts +6 -6
  226. package/src/zkProgrammable/ZkProgrammable.ts +72 -31
  227. package/src/zkProgrammable/provableMethod.ts +53 -24
  228. package/test/config/ContainerEvents.test.ts +65 -0
  229. package/test/config/ModuleContainer.test.ts +146 -15
  230. package/test/config/injectAlias.test.ts +28 -0
  231. package/test/trees/LinkedMerkleTree.test.ts +124 -0
  232. package/test/trees/LinkedMerkleTreeCircuitOps.test.ts +147 -0
  233. package/test/trees/MerkleTree.test.ts +251 -0
  234. package/test/tsconfig.json +5 -2
  235. package/test/zkProgrammable/ZkProgrammable.test.ts +145 -119
  236. package/tsconfig.json +1 -1
  237. package/LICENSE.md +0 -201
  238. package/tsconfig.test.json +0 -9
@@ -0,0 +1,13 @@
1
+ import { AreProofsEnabled, CompileArtifact } from "../zkProgrammable/ZkProgrammable";
2
+ export type ArtifactRecord = Record<string, CompileArtifact>;
3
+ export type CompileTarget = {
4
+ name: string;
5
+ compile: () => Promise<CompileArtifact>;
6
+ };
7
+ export declare class AtomicCompileHelper {
8
+ private readonly areProofsEnabled;
9
+ constructor(areProofsEnabled: AreProofsEnabled);
10
+ private compilationPromises;
11
+ compileContract(contract: CompileTarget, overrideProofsEnabled?: boolean): Promise<CompileArtifact>;
12
+ }
13
+ //# sourceMappingURL=AtomicCompileHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AtomicCompileHelper.d.ts","sourceRoot":"","sources":["../../src/compiling/AtomicCompileHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EAEhB,MAAM,kCAAkC,CAAC;AAK1C,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CACzC,CAAC;AAEF,qBAAa,mBAAmB;IACX,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAAhB,gBAAgB,EAAE,gBAAgB;IAEtE,OAAO,CAAC,mBAAmB,CAEpB;IAEM,eAAe,CAC1B,QAAQ,EAAE,aAAa,EACvB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAAC,eAAe,CAAC;CAmC5B"}
@@ -0,0 +1,40 @@
1
+ import { MOCK_VERIFICATION_KEY, } from "../zkProgrammable/ZkProgrammable";
2
+ import { isSubtypeOfName } from "../utils";
3
+ import { log } from "../log";
4
+ export class AtomicCompileHelper {
5
+ constructor(areProofsEnabled) {
6
+ this.areProofsEnabled = areProofsEnabled;
7
+ this.compilationPromises = {};
8
+ }
9
+ async compileContract(contract, overrideProofsEnabled) {
10
+ let newPromise = false;
11
+ const { name } = contract;
12
+ if (this.compilationPromises[name] === undefined) {
13
+ const proofsEnabled = overrideProofsEnabled ?? this.areProofsEnabled.areProofsEnabled;
14
+ // We only care about proofs enabled here if it's a contract, because
15
+ // in all other cases, ZkProgrammable already handles this switch, and we
16
+ // want to preserve the artifact layout (which might be more than one
17
+ // entry for ZkProgrammables)
18
+ if (proofsEnabled ||
19
+ !isSubtypeOfName(
20
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
21
+ contract, "SmartContract")) {
22
+ log.time(`Compiling ${name}`);
23
+ this.compilationPromises[name] = contract.compile();
24
+ newPromise = true;
25
+ }
26
+ else {
27
+ log.debug(`Compiling ${name} - mock`);
28
+ this.compilationPromises[name] = Promise.resolve({
29
+ verificationKey: MOCK_VERIFICATION_KEY,
30
+ });
31
+ }
32
+ }
33
+ const result = await this.compilationPromises[name];
34
+ if (newPromise) {
35
+ log.timeEnd.info(`Compiling ${name}`);
36
+ }
37
+ return result;
38
+ }
39
+ }
40
+ //# sourceMappingURL=AtomicCompileHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"At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C,IAAI,CAAC,CAAC;QACpD,IAAI,UAAU,EAAE;YACd,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;SACvC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import type { CompileRegistry } from "./CompileRegistry";
2
+ import type { ArtifactRecord } from "./AtomicCompileHelper";
3
+ export interface CompilableModule {
4
+ compile(registry: CompileRegistry): Promise<ArtifactRecord | void>;
5
+ }
6
+ //# sourceMappingURL=CompilableModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompilableModule.d.ts","sourceRoot":"","sources":["../../src/compiling/CompilableModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CACpE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CompilableModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompilableModule.js","sourceRoot":"","sources":["../../src/compiling/CompilableModule.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { AreProofsEnabled, CompileArtifact } from "../zkProgrammable/ZkProgrammable";
2
+ import { ArtifactRecord, CompileTarget } from "./AtomicCompileHelper";
3
+ /**
4
+ * The CompileRegistry compiles "compilable modules"
5
+ * (i.e. zkprograms, contracts or contractmodules)
6
+ * while making sure they don't get compiled twice in the same process in parallel.
7
+ */
8
+ export declare class CompileRegistry {
9
+ private readonly areProofsEnabled;
10
+ constructor(areProofsEnabled: AreProofsEnabled);
11
+ private compiler;
12
+ private artifacts;
13
+ private inForceProverBlock;
14
+ /**
15
+ * This function forces compilation even if the artifact itself is in the registry.
16
+ * Basically the statement is: The artifact along is not enough, we need to
17
+ * actually have the prover compiled.
18
+ * This is true for non-sideloaded circuit dependencies.
19
+ */
20
+ forceProverExists<R>(f: (registry: CompileRegistry) => Promise<R>): Promise<R>;
21
+ compile(target: CompileTarget, nameOverride?: string): Promise<CompileArtifact>;
22
+ getArtifact(name: string): CompileArtifact | undefined;
23
+ addArtifactsRaw(artifacts: ArtifactRecord): void;
24
+ getAllArtifacts(): ArtifactRecord;
25
+ }
26
+ //# sourceMappingURL=CompileRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompileRegistry.d.ts","sourceRoot":"","sources":["../../src/compiling/CompileRegistry.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,cAAc,EAEd,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAEa,eAAe;IAGxB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAAhB,gBAAgB,EAAE,gBAAgB;IAKrD,OAAO,CAAC,QAAQ,CAAsB;IAEtC,OAAO,CAAC,SAAS,CAAsB;IAEvC,OAAO,CAAC,kBAAkB,CAAS;IAEnC;;;;;OAKG;IACU,iBAAiB,CAAC,CAAC,EAC9B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3C,OAAO,CAAC,CAAC,CAAC;IAOA,OAAO,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,CAAC,EAAE,MAAM;IAU1D,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAItD,eAAe,CAAC,SAAS,EAAE,cAAc;IAOzC,eAAe;CAGvB"}
@@ -0,0 +1,67 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { inject, injectable, singleton } from "tsyringe";
14
+ import { AtomicCompileHelper, } from "./AtomicCompileHelper";
15
+ /**
16
+ * The CompileRegistry compiles "compilable modules"
17
+ * (i.e. zkprograms, contracts or contractmodules)
18
+ * while making sure they don't get compiled twice in the same process in parallel.
19
+ */
20
+ export let CompileRegistry = class CompileRegistry {
21
+ constructor(areProofsEnabled) {
22
+ this.areProofsEnabled = areProofsEnabled;
23
+ this.artifacts = {};
24
+ this.inForceProverBlock = false;
25
+ this.compiler = new AtomicCompileHelper(this.areProofsEnabled);
26
+ }
27
+ /**
28
+ * This function forces compilation even if the artifact itself is in the registry.
29
+ * Basically the statement is: The artifact along is not enough, we need to
30
+ * actually have the prover compiled.
31
+ * This is true for non-sideloaded circuit dependencies.
32
+ */
33
+ async forceProverExists(f) {
34
+ this.inForceProverBlock = true;
35
+ const result = await f(this);
36
+ this.inForceProverBlock = false;
37
+ return result;
38
+ }
39
+ async compile(target, nameOverride) {
40
+ const name = nameOverride ?? target.name;
41
+ if (this.artifacts[name] === undefined || this.inForceProverBlock) {
42
+ const artifact = await this.compiler.compileContract(target);
43
+ this.artifacts[name] = artifact;
44
+ return artifact;
45
+ }
46
+ return this.artifacts[name];
47
+ }
48
+ getArtifact(name) {
49
+ return this.artifacts[name];
50
+ }
51
+ addArtifactsRaw(artifacts) {
52
+ this.artifacts = {
53
+ ...this.artifacts,
54
+ ...artifacts,
55
+ };
56
+ }
57
+ getAllArtifacts() {
58
+ return this.artifacts;
59
+ }
60
+ };
61
+ CompileRegistry = __decorate([
62
+ injectable(),
63
+ singleton(),
64
+ __param(0, inject("AreProofsEnabled")),
65
+ __metadata("design:paramtypes", [Object])
66
+ ], CompileRegistry);
67
+ //# sourceMappingURL=CompileRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompileRegistry.js","sourceRoot":"","sources":["../../src/compiling/CompileRegistry.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAOzD,OAAO,EAEL,mBAAmB,GAEpB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AAGI,WAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YAEE,gBAAmD;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAO7C,cAAS,GAAmB,EAAE,CAAC;QAE/B,uBAAkB,GAAG,KAAK,CAAC;QAPjC,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACjE,CAAC;IAQD;;;;;OAKG;IACI,KAAK,CAAC,iBAAiB,CAC5B,CAA4C;QAE5C,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,MAAqB,EAAE,YAAqB;QAC/D,MAAM,IAAI,GAAG,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC;QACzC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,IAAI,CAAC,kBAAkB,EAAE;YACjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAC7D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;YAChC,OAAO,QAAQ,CAAC;SACjB;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAEM,WAAW,CAAC,IAAY;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAEM,eAAe,CAAC,SAAyB;QAC9C,IAAI,CAAC,SAAS,GAAG;YACf,GAAG,IAAI,CAAC,SAAS;YACjB,GAAG,SAAS;SACb,CAAC;IACJ,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF,CAAA;AArDY,eAAe;IAF3B,UAAU,EAAE;IACZ,SAAS,EAAE;IAGP,WAAA,MAAM,CAAC,kBAAkB,CAAC,CAAA;;GAFlB,eAAe,CAqD3B"}
@@ -0,0 +1,10 @@
1
+ import { CompileRegistry } from "../CompileRegistry";
2
+ export declare class ChildVerificationKeyService {
3
+ private compileRegistry?;
4
+ setCompileRegistry(registry: CompileRegistry): void;
5
+ getVerificationKey(name: string): {
6
+ data: string;
7
+ hash: import("o1js/dist/node/lib/provable/field").Field;
8
+ };
9
+ }
10
+ //# sourceMappingURL=ChildVerificationKeyService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChildVerificationKeyService.d.ts","sourceRoot":"","sources":["../../../src/compiling/services/ChildVerificationKeyService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,qBAEa,2BAA2B;IACtC,OAAO,CAAC,eAAe,CAAC,CAAkB;IAEnC,kBAAkB,CAAC,QAAQ,EAAE,eAAe;IAI5C,kBAAkB,CAAC,IAAI,EAAE,MAAM;;;;CAYvC"}
@@ -0,0 +1,27 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { injectable, Lifecycle, scoped } from "tsyringe";
8
+ export let ChildVerificationKeyService = class ChildVerificationKeyService {
9
+ setCompileRegistry(registry) {
10
+ this.compileRegistry = registry;
11
+ }
12
+ getVerificationKey(name) {
13
+ if (this.compileRegistry === undefined) {
14
+ throw new Error("CompileRegistry hasn't been set yet");
15
+ }
16
+ const artifact = this.compileRegistry.getArtifact(name);
17
+ if (artifact === undefined) {
18
+ throw new Error(`Verification Key for child program ${name} not found in registry`);
19
+ }
20
+ return artifact.verificationKey;
21
+ }
22
+ };
23
+ ChildVerificationKeyService = __decorate([
24
+ injectable(),
25
+ scoped(Lifecycle.ContainerScoped)
26
+ ], ChildVerificationKeyService);
27
+ //# sourceMappingURL=ChildVerificationKeyService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChildVerificationKeyService.js","sourceRoot":"","sources":["../../../src/compiling/services/ChildVerificationKeyService.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMlD,WAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAG/B,kBAAkB,CAAC,QAAyB;QACjD,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;IAClC,CAAC;IAEM,kBAAkB,CAAC,IAAY;QACpC,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;SACxD;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACxD,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,MAAM,IAAI,KAAK,CACb,sCAAsC,IAAI,wBAAwB,CACnE,CAAC;SACH;QACD,OAAO,QAAQ,CAAC,eAAe,CAAC;IAClC,CAAC;CACF,CAAA;AAnBY,2BAA2B;IAFvC,UAAU,EAAE;IACZ,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC;GACrB,2BAA2B,CAmBvC"}
@@ -0,0 +1,5 @@
1
+ import { ChildContainerProvider } from "./ChildContainerProvider";
2
+ export interface ChildContainerCreatable {
3
+ create: (childContainerProvider: ChildContainerProvider) => void;
4
+ }
5
+ //# sourceMappingURL=ChildContainerCreatable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChildContainerCreatable.d.ts","sourceRoot":"","sources":["../../src/config/ChildContainerCreatable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,CAAC,sBAAsB,EAAE,sBAAsB,KAAK,IAAI,CAAC;CAClE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ChildContainerCreatable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChildContainerCreatable.js","sourceRoot":"","sources":["../../src/config/ChildContainerCreatable.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { DependencyContainer } from "tsyringe";
2
+ export interface ChildContainerProvider {
3
+ (): DependencyContainer;
4
+ }
5
+ //# sourceMappingURL=ChildContainerProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChildContainerProvider.d.ts","sourceRoot":"","sources":["../../src/config/ChildContainerProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,IAAI,mBAAmB,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ChildContainerProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChildContainerProvider.js","sourceRoot":"","sources":["../../src/config/ChildContainerProvider.ts"],"names":[],"mappings":""}
@@ -1,12 +1,15 @@
1
- export type Preset<Config> = Config | ((...args: any[]) => Config);
1
+ import { ChildContainerProvider } from "./ChildContainerProvider";
2
+ import type { BaseModuleInstanceType } from "./ModuleContainer";
3
+ export type Preset<Config> = Config | ((...args: unknown[]) => Config);
2
4
  export type Presets<Config> = Record<string, Preset<Config>>;
3
5
  export interface Configurable<Config> {
4
6
  config: Config;
5
7
  }
8
+ export type NoConfig = Record<never, never>;
6
9
  /**
7
10
  * Used by various module sub-types that may need to be configured
8
11
  */
9
- export declare class ConfigurableModule<Config> implements Configurable<Config> {
12
+ export declare class ConfigurableModule<Config = NoConfig> implements BaseModuleInstanceType {
10
13
  /**
11
14
  * Store the config separately, so that we can apply additional
12
15
  * checks when retrieving it via the getter
@@ -14,6 +17,7 @@ export declare class ConfigurableModule<Config> implements Configurable<Config>
14
17
  protected currentConfig: Config | undefined;
15
18
  get config(): Config;
16
19
  set config(config: Config);
20
+ create(childContainerProvider: ChildContainerProvider): void;
17
21
  }
18
22
  export interface StaticConfigurableModule<Config> {
19
23
  presets: Presets<Config>;
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigurableModule.d.ts","sourceRoot":"","sources":["../../src/config/ConfigurableModule.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAC;AACnE,MAAM,MAAM,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAG7D,MAAM,WAAW,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AAsB,GAAG,IAAI;CAGpE;AAGD,MAAM,WAAW,wBAAwB,CAAC,MAAM;IAC9C,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1B"}
@@ -1,3 +1,4 @@
1
+ import { noop } from "../utils";
1
2
  const errors = {
2
3
  configNotSet: (moduleName) => new Error(`Trying to retrieve config of ${moduleName}, which was not yet set`),
3
4
  };
@@ -16,4 +17,8 @@ export class ConfigurableModule {
16
17
  set config(config) {
17
18
  this.currentConfig = config;
18
19
  }
20
+ create(childContainerProvider) {
21
+ noop();
22
+ }
19
23
  }
24
+ //# sourceMappingURL=ConfigurableModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigurableModule.js","sourceRoot":"","sources":["../../src/config/ConfigurableModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAKhC,MAAM,MAAM,GAAG;IACb,YAAY,EAAE,CAAC,UAAkB,EAAE,EAAE,CACnC,IAAI,KAAK,CACP,gCAAgC,UAAU,yBAAyB,CACpE;CACJ,CAAC;AAaF;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAS7B,+BAA+B;IAC/B,IAAW,MAAM;QACf,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE;YACpC,MAAM,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SAClD;QACD,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,iBAAiB;IACjB,IAAW,MAAM,CAAC,MAAc;QAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;IAC9B,CAAC;IAEM,MAAM,CAAC,sBAA8C;QAC1D,IAAI,EAAE,CAAC;IACT,CAAC;CACF"}
@@ -1,42 +1,65 @@
1
1
  import "reflect-metadata";
2
- import { InjectionToken } from "tsyringe";
3
- import { StringKeyOf, TypedClass } from "../types";
4
- import { DependencyFactory } from "../dependencyFactory/DependencyFactory";
5
- import { Configurable, ConfigurableModule } from "./ConfigurableModule";
2
+ import { DependencyContainer, InjectionToken } from "tsyringe";
3
+ import { MergeObjects, StringKeyOf, TypedClass } from "../types";
4
+ import { DependencyFactory, InferDependencies } from "../dependencyFactory/DependencyFactory";
5
+ import { EventEmitterProxy } from "../events/EventEmitterProxy";
6
+ import { Configurable, ConfigurableModule, NoConfig } from "./ConfigurableModule";
7
+ import { ChildContainerProvider } from "./ChildContainerProvider";
8
+ import { ChildContainerCreatable } from "./ChildContainerCreatable";
6
9
  export declare const ModuleContainerErrors: {
7
10
  configNotSetInContainer: (moduleName: string) => Error;
8
11
  onlyValidModuleNames: (moduleName: NonNullable<unknown>) => Error;
9
12
  unableToDecorateModule: (moduleName: InjectionToken<unknown>) => Error;
10
13
  nonModuleDependency: (runtimeModuleName: string) => Error;
11
14
  unknownDependency: (runtimeModuleName: string, name: string) => Error;
15
+ dependencyContainerNotSet: (className: string) => Error;
16
+ validModuleInstance: (moduleName: string, moduleTypeName: string) => Error;
12
17
  };
13
- export type BaseModuleType = TypedClass<Configurable<unknown>>;
18
+ export interface BaseModuleInstanceType extends ChildContainerCreatable, Configurable<unknown> {
19
+ }
20
+ export type BaseModuleType = TypedClass<BaseModuleInstanceType>;
14
21
  export interface ModulesRecord<ModuleType extends BaseModuleType = BaseModuleType> {
15
22
  [name: string]: ModuleType;
16
23
  }
17
24
  export type ModulesConfig<Modules extends ModulesRecord> = {
18
- [ConfigKey in StringKeyOf<Modules>]: InstanceType<Modules[ConfigKey]> extends Configurable<infer Config> ? Config : never;
25
+ [ConfigKey in StringKeyOf<Modules>]: InstanceType<Modules[ConfigKey]> extends Configurable<infer Config> ? Config extends NoConfig ? Config | undefined : Config : never;
19
26
  };
20
27
  /**
21
- * Parameters required when creating a module container instance
28
+ * This type make any config partial (i.e. optional) up to the first level
29
+ * So { Module: { a: { b: string } } }
30
+ * will become
31
+ * { Module?: { a?: { b: string } } }
32
+ * Note that b does not become optional, as we don't want nested objects to
33
+ * become unreasonably partialized (for example Field).
22
34
  */
23
- export interface ModuleContainerDefinition<Modules extends ModulesRecord> {
24
- modules: Modules;
25
- config?: ModulesConfig<Modules>;
35
+ export type RecursivePartial<T> = {
36
+ [Key in keyof T]?: Partial<T[Key]>;
37
+ };
38
+ export type FilterNeverValues<Type extends Record<string, unknown>> = {
39
+ [Key in keyof Type as Type[Key] extends never ? never : Key]: Type[Key];
40
+ };
41
+ export type DependenciesFromModules<Modules extends ModulesRecord> = FilterNeverValues<{
42
+ [Key in keyof Modules]: Modules[Key] extends TypedClass<DependencyFactory> ? InferDependencies<InstanceType<Modules[Key]>> : never;
43
+ }>;
44
+ export type ResolvableModules<Modules extends ModulesRecord> = MergeObjects<DependenciesFromModules<Modules>> & Modules;
45
+ export interface ModuleContainerLike {
46
+ get dependencyContainer(): DependencyContainer;
47
+ resolveOrFail<ModuleType>(moduleName: string, moduleType: TypedClass<ModuleType>): ModuleType;
26
48
  }
27
49
  /**
28
50
  * Reusable module container facilitating registration, resolution
29
51
  * configuration, decoration and validation of modules
30
52
  */
31
- export declare class ModuleContainer<Modules extends ModulesRecord> extends ConfigurableModule<unknown> {
32
- definition: ModuleContainerDefinition<Modules>;
53
+ export declare class ModuleContainer<Modules extends ModulesRecord> extends ConfigurableModule<ModulesConfig<Modules>> implements ModuleContainerLike {
54
+ definition: Modules;
33
55
  /**
34
56
  * Determines how often are modules decorated upon resolution
35
57
  * from the tsyringe DI container
36
58
  */
37
59
  private static readonly moduleDecorationFrequency;
38
- protected readonly container: import("tsyringe").DependencyContainer;
39
- constructor(definition: ModuleContainerDefinition<Modules>);
60
+ private providedContainer?;
61
+ private eventEmitterProxy;
62
+ constructor(definition: Modules);
40
63
  /**
41
64
  * @returns list of module names
42
65
  */
@@ -49,13 +72,16 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
49
72
  * @param containedModule
50
73
  */
51
74
  protected validateModule(moduleName: StringKeyOf<Modules>, containedModule: ConfigurableModule<unknown>): void;
75
+ protected get container(): DependencyContainer;
52
76
  /**
53
77
  * Assert that the iterated `moduleName` is of ModuleName type,
54
78
  * otherwise it may be just string e.g. when modules are iterated over
55
79
  * using e.g. a for loop.
56
80
  */
57
- assertIsValidModuleName(modules: Modules, moduleName: string): asserts moduleName is StringKeyOf<Modules>;
58
- isValidModuleName(modules: Modules, moduleName: number | string | symbol): asserts moduleName is StringKeyOf<Modules>;
81
+ assertIsValidModuleName(moduleName: string): asserts moduleName is StringKeyOf<Modules>;
82
+ isValidModuleName(modules: Modules, moduleName: number | string | symbol): moduleName is StringKeyOf<Modules>;
83
+ assertContainerInitialized(container: DependencyContainer | undefined): asserts container is DependencyContainer;
84
+ protected registerAliases(originalToken: string, clas: TypedClass<any>): void;
59
85
  /**
60
86
  * Register modules into the current container, and registers
61
87
  * a respective resolution hook in order to decorate the module
@@ -64,11 +90,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
64
90
  * @param modules
65
91
  */
66
92
  protected registerModules(modules: Modules): void;
67
- /**
68
- * Inject a set of dependencies using the given list of DependencyFactories
69
- * This method should be called during startup
70
- */
71
- protected registerDependencyFactories(factories: TypedClass<DependencyFactory>[]): void;
93
+ get events(): EventEmitterProxy<Modules>;
72
94
  /**
73
95
  * Register a non-module value into the current container
74
96
  * @param modules
@@ -83,6 +105,9 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
83
105
  * @param config
84
106
  */
85
107
  configure(config: ModulesConfig<Modules>): void;
108
+ configurePartial(config: RecursivePartial<ModulesConfig<Modules>>): void;
109
+ get config(): ModulesConfig<Modules>;
110
+ set config(config: ModulesConfig<Modules>);
86
111
  /**
87
112
  * Resolves a module from the current module container
88
113
  *
@@ -93,17 +118,39 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
93
118
  * @param moduleName
94
119
  * @returns
95
120
  */
96
- resolve<ResolvableModuleName extends StringKeyOf<Modules>>(moduleName: ResolvableModuleName): InstanceType<Modules[ResolvableModuleName]>;
97
- resolveOrFail<ModuleType>(moduleName: string, moduleType: TypedClass<ModuleType>): ModuleType;
121
+ resolve<KeyType extends StringKeyOf<ResolvableModules<Modules>>>(moduleName: KeyType): InstanceType<ResolvableModules<Modules>[KeyType]>;
122
+ resolveOrFail<ModuleType>(moduleName: string, moduleType?: TypedClass<ModuleType>): ModuleType;
98
123
  /**
99
124
  * Override this in the child class to provide custom
100
125
  * features or module checks
101
126
  */
102
127
  protected decorateModule(moduleName: StringKeyOf<Modules>, containedModule: InstanceType<Modules[StringKeyOf<Modules>]>): void;
128
+ private isDependencyFactory;
129
+ /**
130
+ * Inject a set of dependencies using the given list of DependencyFactories
131
+ * This method should be called during startup
132
+ */
133
+ protected initializeDependencyFactories(factories: StringKeyOf<Modules>[]): void;
134
+ /**
135
+ * Retrieves all dependencies generated by a particular dependencyfactory
136
+ * and injects them inside this modulecontainer's DI container.
137
+ * This will be automatically called for every module, but can also be called
138
+ * explicitly to initialize an extra factory
139
+ * @param factory
140
+ * @private
141
+ */
142
+ protected useDependencyFactory(factory: DependencyFactory): void;
103
143
  /**
104
144
  * Handle module resolution, e.g. by decorating resolved modules
105
145
  * @param moduleName
106
146
  */
107
147
  protected onAfterModuleResolution(moduleName: StringKeyOf<Modules>): void;
148
+ /**
149
+ * This is a placeholder for individual modules to override.
150
+ * This method will be called whenever the underlying container fully
151
+ * initialized
152
+ */
153
+ create(childContainerProvider: ChildContainerProvider): void;
154
+ get dependencyContainer(): DependencyContainer;
108
155
  }
109
156
  //# sourceMappingURL=ModuleContainer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModuleContainer.d.ts","sourceRoot":"","sources":["../../src/config/ModuleContainer.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAwB,cAAc,EAAa,MAAM,UAAU,CAAC;AAG3E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;A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