@proto-kit/common 0.1.1-develop.339 → 0.1.1-develop.455
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.
- package/dist/config/ConfigurableModule.d.ts +2 -1
- package/dist/config/ConfigurableModule.d.ts.map +1 -1
- package/dist/config/ModuleContainer.d.ts +35 -11
- package/dist/config/ModuleContainer.d.ts.map +1 -1
- package/dist/config/ModuleContainer.js +86 -19
- package/dist/dependencyFactory/DependencyFactory.d.ts +13 -9
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
- package/dist/dependencyFactory/DependencyFactory.js +1 -97
- package/dist/events/EventEmitter.d.ts +14 -0
- package/dist/events/EventEmitter.d.ts.map +1 -0
- package/dist/events/EventEmitter.js +35 -0
- package/dist/events/EventEmitterProxy.d.ts +17 -0
- package/dist/events/EventEmitterProxy.d.ts.map +1 -0
- package/dist/events/EventEmitterProxy.js +21 -0
- package/dist/events/EventEmittingComponent.d.ts +6 -0
- package/dist/events/EventEmittingComponent.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/trees/InMemoryMerkleTreeStorage.d.ts +11 -0
- package/dist/trees/InMemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/trees/InMemoryMerkleTreeStorage.js +12 -0
- package/dist/trees/MerkleTreeStore.d.ts +5 -0
- package/dist/trees/MerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/MerkleTreeStore.js +1 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts +9 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -0
- package/dist/trees/MockAsyncMerkleStore.js +19 -0
- package/dist/trees/RollupMerkleTree.d.ts +126 -0
- package/dist/trees/RollupMerkleTree.d.ts.map +1 -0
- package/dist/trees/RollupMerkleTree.js +216 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.d.ts +1 -1
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.js +4 -4
- package/dist/zkProgrammable/provableMethod.d.ts +1 -1
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
- package/dist/zkProgrammable/provableMethod.js +2 -2
- package/package.json +2 -2
- package/src/config/ConfigurableModule.ts +3 -1
- package/src/config/ModuleContainer.ts +150 -30
- package/src/dependencyFactory/DependencyFactory.ts +25 -114
- package/src/events/EventEmitter.ts +58 -0
- package/src/events/EventEmitterProxy.ts +57 -0
- package/src/events/EventEmittingComponent.ts +7 -0
- package/src/index.ts +7 -0
- package/src/trees/InMemoryMerkleTreeStorage.ts +17 -0
- package/src/trees/MerkleTreeStore.ts +5 -0
- package/src/trees/MockAsyncMerkleStore.ts +29 -0
- package/src/trees/RollupMerkleTree.ts +354 -0
- package/src/trees/VirtualMerkleTreeStore.ts +21 -0
- package/src/types.ts +12 -0
- package/src/zkProgrammable/ZkProgrammable.ts +5 -4
- package/src/zkProgrammable/provableMethod.ts +2 -2
- package/test/config/ContainerEvents.test.ts +86 -0
- package/test/config/ModuleContainer.test.ts +111 -6
- package/test/trees/MerkleTree.test.ts +105 -0
- package/dist/config/ChildContainerStartable.d.ts +0 -5
- package/dist/config/ChildContainerStartable.d.ts.map +0 -1
- /package/dist/{config/ChildContainerStartable.js → events/EventEmittingComponent.js} +0 -0
|
@@ -5,10 +5,11 @@ export type Presets<Config> = Record<string, Preset<Config>>;
|
|
|
5
5
|
export interface Configurable<Config> {
|
|
6
6
|
config: Config;
|
|
7
7
|
}
|
|
8
|
+
export type NoConfig = Record<string, never>;
|
|
8
9
|
/**
|
|
9
10
|
* Used by various module sub-types that may need to be configured
|
|
10
11
|
*/
|
|
11
|
-
export declare class ConfigurableModule<Config> implements BaseModuleInstanceType {
|
|
12
|
+
export declare class ConfigurableModule<Config = NoConfig> implements BaseModuleInstanceType {
|
|
12
13
|
/**
|
|
13
14
|
* Store the config separately, so that we can apply additional
|
|
14
15
|
* checks when retrieving it via the getter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurableModule.d.ts","sourceRoot":"","sources":["../../src/config/ConfigurableModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAUhE,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,YAAY,CAAC,MAAM;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,kBAAkB,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"ConfigurableModule.d.ts","sourceRoot":"","sources":["../../src/config/ConfigurableModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAUhE,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,YAAY,CAAC,MAAM;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE7C;;GAEG;AACH,qBAAa,kBAAkB,CAAC,MAAM,GAAG,QAAQ,CAC/C,YAAW,sBAAsB;IAEjC;;;OAGG;IACH,SAAS,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAG5C,IAAW,MAAM,IAAI,MAAM,CAK1B;IAGD,IAAW,MAAM,CAAC,MAAM,EAAE,MAAM,EAE/B;IAGM,MAAM,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,IAAI;CAGpE;AAGD,MAAM,WAAW,wBAAwB,CAAC,MAAM;IAC9C,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1B"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { DependencyContainer, InjectionToken } from "tsyringe";
|
|
3
|
-
import { StringKeyOf, TypedClass } from "../types";
|
|
4
|
-
import { DependencyFactory } from "../dependencyFactory/DependencyFactory";
|
|
5
|
-
import { Configurable, ConfigurableModule } from "./ConfigurableModule";
|
|
3
|
+
import { MergeObjects, StringKeyOf, TypedClass } from "../types";
|
|
4
|
+
import { DependencyFactory, InferDependencies } from "../dependencyFactory/DependencyFactory";
|
|
5
|
+
import { Configurable, ConfigurableModule, NoConfig } from "./ConfigurableModule";
|
|
6
6
|
import { ChildContainerProvider } from "./ChildContainerProvider";
|
|
7
7
|
import { ChildContainerCreatable } from "./ChildContainerCreatable";
|
|
8
|
+
import { EventEmitterProxy } from "../events/EventEmitterProxy";
|
|
8
9
|
export declare const ModuleContainerErrors: {
|
|
9
10
|
configNotSetInContainer: (moduleName: string) => Error;
|
|
10
11
|
onlyValidModuleNames: (moduleName: NonNullable<unknown>) => Error;
|
|
@@ -21,7 +22,10 @@ export interface ModulesRecord<ModuleType extends BaseModuleType = BaseModuleTyp
|
|
|
21
22
|
[name: string]: ModuleType;
|
|
22
23
|
}
|
|
23
24
|
export type ModulesConfig<Modules extends ModulesRecord> = {
|
|
24
|
-
[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;
|
|
26
|
+
};
|
|
27
|
+
export type RecursivePartial<T> = {
|
|
28
|
+
[Key in keyof T]?: T[Key] extends object ? RecursivePartial<T[Key]> : T[Key];
|
|
25
29
|
};
|
|
26
30
|
/**
|
|
27
31
|
* Parameters required when creating a module container instance
|
|
@@ -30,6 +34,13 @@ export interface ModuleContainerDefinition<Modules extends ModulesRecord> {
|
|
|
30
34
|
modules: Modules;
|
|
31
35
|
config?: ModulesConfig<Modules>;
|
|
32
36
|
}
|
|
37
|
+
export type FilterNeverValues<Type extends Record<string, unknown>> = {
|
|
38
|
+
[Key in keyof Type as Type[Key] extends never ? never : Key]: Type[Key];
|
|
39
|
+
};
|
|
40
|
+
export type DependenciesFromModules<Modules extends ModulesRecord> = FilterNeverValues<{
|
|
41
|
+
[Key in keyof Modules]: Modules[Key] extends TypedClass<DependencyFactory> ? InferDependencies<InstanceType<Modules[Key]>> : never;
|
|
42
|
+
}>;
|
|
43
|
+
export type ResolvableModules<Modules extends ModulesRecord> = MergeObjects<DependenciesFromModules<Modules>> & Modules;
|
|
33
44
|
/**
|
|
34
45
|
* Reusable module container facilitating registration, resolution
|
|
35
46
|
* configuration, decoration and validation of modules
|
|
@@ -42,6 +53,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
42
53
|
*/
|
|
43
54
|
private static readonly moduleDecorationFrequency;
|
|
44
55
|
private providedContainer?;
|
|
56
|
+
private eventEmitterProxy;
|
|
45
57
|
constructor(definition: ModuleContainerDefinition<Modules>);
|
|
46
58
|
/**
|
|
47
59
|
* @returns list of module names
|
|
@@ -62,7 +74,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
62
74
|
* using e.g. a for loop.
|
|
63
75
|
*/
|
|
64
76
|
assertIsValidModuleName(modules: Modules, moduleName: string): asserts moduleName is StringKeyOf<Modules>;
|
|
65
|
-
isValidModuleName(modules: Modules, moduleName: number | string | symbol):
|
|
77
|
+
isValidModuleName(modules: Modules, moduleName: number | string | symbol): moduleName is StringKeyOf<Modules>;
|
|
66
78
|
assertContainerInitialized(container: DependencyContainer | undefined): asserts container is DependencyContainer;
|
|
67
79
|
/**
|
|
68
80
|
* Register modules into the current container, and registers
|
|
@@ -72,11 +84,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
72
84
|
* @param modules
|
|
73
85
|
*/
|
|
74
86
|
protected registerModules(modules: Modules): void;
|
|
75
|
-
|
|
76
|
-
* Inject a set of dependencies using the given list of DependencyFactories
|
|
77
|
-
* This method should be called during startup
|
|
78
|
-
*/
|
|
79
|
-
protected registerDependencyFactories(factories: TypedClass<DependencyFactory>[]): void;
|
|
87
|
+
get events(): EventEmitterProxy<Modules>;
|
|
80
88
|
/**
|
|
81
89
|
* Register a non-module value into the current container
|
|
82
90
|
* @param modules
|
|
@@ -92,6 +100,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
92
100
|
* @param config
|
|
93
101
|
*/
|
|
94
102
|
configure(config: ModulesConfig<Modules>): void;
|
|
103
|
+
configurePartial(config: RecursivePartial<ModulesConfig<Modules>>): void;
|
|
95
104
|
set config(config: ModulesConfig<Modules>);
|
|
96
105
|
/**
|
|
97
106
|
* Resolves a module from the current module container
|
|
@@ -103,13 +112,28 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
103
112
|
* @param moduleName
|
|
104
113
|
* @returns
|
|
105
114
|
*/
|
|
106
|
-
resolve<
|
|
115
|
+
resolve<KeyType extends StringKeyOf<ResolvableModules<Modules>>>(moduleName: KeyType): InstanceType<ResolvableModules<Modules>[KeyType]>;
|
|
107
116
|
resolveOrFail<ModuleType>(moduleName: string, moduleType: TypedClass<ModuleType>): ModuleType;
|
|
108
117
|
/**
|
|
109
118
|
* Override this in the child class to provide custom
|
|
110
119
|
* features or module checks
|
|
111
120
|
*/
|
|
112
121
|
protected decorateModule(moduleName: StringKeyOf<Modules>, containedModule: InstanceType<Modules[StringKeyOf<Modules>]>): void;
|
|
122
|
+
private isDependencyFactory;
|
|
123
|
+
/**
|
|
124
|
+
* Inject a set of dependencies using the given list of DependencyFactories
|
|
125
|
+
* This method should be called during startup
|
|
126
|
+
*/
|
|
127
|
+
protected initializeDependencyFactories(factories: StringKeyOf<Modules>[]): void;
|
|
128
|
+
/**
|
|
129
|
+
* Retrieves all dependencies generated by a particular dependencyfactory
|
|
130
|
+
* and injects them inside this modulecontainer's DI container.
|
|
131
|
+
* This will be automatically called for every module, but can also be called
|
|
132
|
+
* explicitly to initialize an extra factory
|
|
133
|
+
* @param factory
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
136
|
+
protected useDependencyFactory(factory: DependencyFactory): void;
|
|
113
137
|
/**
|
|
114
138
|
* Handle module resolution, e.g. by decorating resolved modules
|
|
115
139
|
* @param moduleName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleContainer.d.ts","sourceRoot":"","sources":["../../src/config/ModuleContainer.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EACL,mBAAmB,
|
|
1
|
+
{"version":3,"file":"ModuleContainer.d.ts","sourceRoot":"","sources":["../../src/config/ModuleContainer.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EACL,mBAAmB,EAGnB,cAAc,EAMf,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CA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AO,CAAC,CAAC,CAAC;IAkB9D,OAAO,CAAC,mBAAmB;IAI3B;;;OAGG;IACH,SAAS,CAAC,6BAA6B,CAAC,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE;IAMzE;;;;;;;OAOG;IACH,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,iBAAiB;IAmCzD;;;OAGG;IACH,SAAS,CAAC,uBAAuB,CAAC,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC;IAwBlE;;;;OAIG;IACI,MAAM,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,IAAI;CAUpE"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import "reflect-metadata";
|
|
3
|
-
import { Lifecycle, } from "tsyringe";
|
|
3
|
+
import { instancePerContainerCachingFactory, isClassProvider, isFactoryProvider, isValueProvider, Lifecycle, } from "tsyringe";
|
|
4
4
|
import log from "loglevel";
|
|
5
|
-
import
|
|
5
|
+
import merge from "lodash/merge";
|
|
6
|
+
import { ConfigurableModule, } from "./ConfigurableModule";
|
|
7
|
+
import { EventEmitterProxy } from "../events/EventEmitterProxy";
|
|
6
8
|
const errors = {
|
|
7
9
|
configNotSetInContainer: (moduleName) => new Error(`Trying to get config of ${moduleName}, but it was not yet set in the module container`),
|
|
8
10
|
onlyValidModuleNames: (moduleName) => new Error(
|
|
@@ -31,6 +33,10 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
31
33
|
this.definition = definition;
|
|
32
34
|
// DI container holding all the registered modules
|
|
33
35
|
this.providedContainer = undefined;
|
|
36
|
+
this.eventEmitterProxy = undefined;
|
|
37
|
+
if (definition.config !== undefined) {
|
|
38
|
+
this.config = definition.config;
|
|
39
|
+
}
|
|
34
40
|
}
|
|
35
41
|
/**
|
|
36
42
|
* @returns list of module names
|
|
@@ -68,13 +74,13 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
68
74
|
* using e.g. a for loop.
|
|
69
75
|
*/
|
|
70
76
|
assertIsValidModuleName(modules, moduleName) {
|
|
71
|
-
this.isValidModuleName(modules, moduleName)
|
|
72
|
-
}
|
|
73
|
-
isValidModuleName(modules, moduleName) {
|
|
74
|
-
if (!Object.prototype.hasOwnProperty.call(modules, moduleName)) {
|
|
77
|
+
if (!this.isValidModuleName(modules, moduleName)) {
|
|
75
78
|
throw errors.onlyValidModuleNames(moduleName);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
81
|
+
isValidModuleName(modules, moduleName) {
|
|
82
|
+
return Object.prototype.hasOwnProperty.call(modules, moduleName);
|
|
83
|
+
}
|
|
78
84
|
assertContainerInitialized(container) {
|
|
79
85
|
if (container === undefined) {
|
|
80
86
|
throw errors.dependencyContainerNotSet(this.constructor.name);
|
|
@@ -98,14 +104,11 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
factories.forEach((factory) => {
|
|
107
|
-
this.container.resolve(factory).initDependencies(this.container);
|
|
108
|
-
});
|
|
107
|
+
get events() {
|
|
108
|
+
if (this.eventEmitterProxy === undefined) {
|
|
109
|
+
this.eventEmitterProxy = new EventEmitterProxy(this);
|
|
110
|
+
}
|
|
111
|
+
return this.eventEmitterProxy;
|
|
109
112
|
}
|
|
110
113
|
/**
|
|
111
114
|
* Register a non-module value into the current container
|
|
@@ -132,12 +135,14 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
132
135
|
* @param config
|
|
133
136
|
*/
|
|
134
137
|
configure(config) {
|
|
135
|
-
this.
|
|
138
|
+
this.config = config;
|
|
139
|
+
}
|
|
140
|
+
configurePartial(config) {
|
|
141
|
+
this.config = merge(this.currentConfig ?? {}, config);
|
|
136
142
|
}
|
|
137
143
|
// eslint-disable-next-line accessor-pairs
|
|
138
144
|
set config(config) {
|
|
139
|
-
super.config = config;
|
|
140
|
-
this.definition.config = config;
|
|
145
|
+
super.config = merge(this.currentConfig ?? {}, config);
|
|
141
146
|
}
|
|
142
147
|
/**
|
|
143
148
|
* Resolves a module from the current module container
|
|
@@ -165,12 +170,71 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
165
170
|
* features or module checks
|
|
166
171
|
*/
|
|
167
172
|
decorateModule(moduleName, containedModule) {
|
|
168
|
-
|
|
173
|
+
// Has to be super.config, getters behave really weird when subtyping
|
|
174
|
+
const config = super.config?.[moduleName];
|
|
169
175
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
170
176
|
if (!config) {
|
|
171
177
|
throw errors.configNotSetInContainer(moduleName.toString());
|
|
172
178
|
}
|
|
173
|
-
containedModule
|
|
179
|
+
if (containedModule instanceof ModuleContainer) {
|
|
180
|
+
containedModule.configure(config);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
containedModule.config = config;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
|
+
isDependencyFactory(type) {
|
|
188
|
+
return "dependencies" in type;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Inject a set of dependencies using the given list of DependencyFactories
|
|
192
|
+
* This method should be called during startup
|
|
193
|
+
*/
|
|
194
|
+
initializeDependencyFactories(factories) {
|
|
195
|
+
factories.forEach((factoryName) => {
|
|
196
|
+
this.resolve(factoryName);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Retrieves all dependencies generated by a particular dependencyfactory
|
|
201
|
+
* and injects them inside this modulecontainer's DI container.
|
|
202
|
+
* This will be automatically called for every module, but can also be called
|
|
203
|
+
* explicitly to initialize an extra factory
|
|
204
|
+
* @param factory
|
|
205
|
+
* @private
|
|
206
|
+
*/
|
|
207
|
+
useDependencyFactory(factory) {
|
|
208
|
+
const dependencies = factory.dependencies();
|
|
209
|
+
Object.entries(dependencies).forEach(([rawKey, declaration]) => {
|
|
210
|
+
const key = rawKey.charAt(0).toUpperCase() + rawKey.slice(1);
|
|
211
|
+
if (!this.container.isRegistered(key) ||
|
|
212
|
+
declaration.forceOverwrite === true) {
|
|
213
|
+
// Find correct provider type and call respective register
|
|
214
|
+
if (isValueProvider(declaration)) {
|
|
215
|
+
this.container.register(key, declaration);
|
|
216
|
+
}
|
|
217
|
+
else if (isFactoryProvider(declaration)) {
|
|
218
|
+
// this enables us to have a singletoned factory
|
|
219
|
+
// that returns the same instance for each resolve
|
|
220
|
+
this.container.register(key, {
|
|
221
|
+
useFactory: instancePerContainerCachingFactory(declaration.useFactory),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
else if (isClassProvider(declaration)) {
|
|
225
|
+
this.container.register(key, declaration, {
|
|
226
|
+
lifecycle: Lifecycle.Singleton,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
// Can never be reached
|
|
231
|
+
throw new Error("Above if-statement is exhaustive");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
log.debug(`Dependency ${key} already registered, skipping`);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
174
238
|
}
|
|
175
239
|
/**
|
|
176
240
|
* Handle module resolution, e.g. by decorating resolved modules
|
|
@@ -188,6 +252,9 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
188
252
|
container.reset();
|
|
189
253
|
return container;
|
|
190
254
|
});
|
|
255
|
+
if (this.isDependencyFactory(containedModule)) {
|
|
256
|
+
this.useDependencyFactory(containedModule);
|
|
257
|
+
}
|
|
191
258
|
}, { frequency: ModuleContainer.moduleDecorationFrequency });
|
|
192
259
|
}
|
|
193
260
|
/**
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClassProvider, FactoryProvider, ValueProvider } from "tsyringe";
|
|
2
2
|
import { TypedClass } from "../types";
|
|
3
|
+
import { BaseModuleInstanceType } from "../config/ModuleContainer";
|
|
4
|
+
export type DependencyDeclaration<Dependency> = ClassProvider<Dependency> | FactoryProvider<Dependency> | ValueProvider<Dependency>;
|
|
5
|
+
export type DependencyRecord = Record<string, DependencyDeclaration<unknown> & {
|
|
6
|
+
forceOverwrite?: boolean;
|
|
7
|
+
}>;
|
|
3
8
|
/**
|
|
4
9
|
* This is an abstract class for creating DependencyFactories, a pattern
|
|
5
10
|
* to bundle multiple smaller services into one and register them into the
|
|
@@ -11,14 +16,13 @@ import { TypedClass } from "../types";
|
|
|
11
16
|
*
|
|
12
17
|
* DependencyFactories are designed to only be used statically for sets of
|
|
13
18
|
* deps that are necessary for the sequencer to work.
|
|
14
|
-
*
|
|
15
|
-
* Every Factory need the @dependencyFactory annotation (which basically
|
|
16
|
-
* proxies @injectable()) and every method that returns a dependency has to be
|
|
17
|
-
* of the format `() => Dependency` and be annotated with @dependency.
|
|
18
19
|
*/
|
|
19
|
-
export
|
|
20
|
-
|
|
20
|
+
export interface DependencyFactory {
|
|
21
|
+
dependencies: () => DependencyRecord;
|
|
21
22
|
}
|
|
22
|
-
export
|
|
23
|
-
export
|
|
23
|
+
export type TypeFromDependencyDeclaration<Declaration extends DependencyDeclaration<unknown>> = Declaration extends DependencyDeclaration<infer Dependency> ? Dependency : never;
|
|
24
|
+
export type MapDependencyRecordToTypes<Record extends DependencyRecord> = {
|
|
25
|
+
[Key in keyof Record]: TypedClass<TypeFromDependencyDeclaration<Record[Key]>>;
|
|
26
|
+
};
|
|
27
|
+
export type InferDependencies<Class extends BaseModuleInstanceType> = Class extends DependencyFactory ? MapDependencyRecordToTypes<ReturnType<Class["dependencies"]>> : never;
|
|
24
28
|
//# sourceMappingURL=DependencyFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyFactory.d.ts","sourceRoot":"","sources":["../../src/dependencyFactory/DependencyFactory.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"DependencyFactory.d.ts","sourceRoot":"","sources":["../../src/dependencyFactory/DependencyFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACd,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,MAAM,MAAM,qBAAqB,CAAC,UAAU,IACxC,aAAa,CAAC,UAAU,CAAC,GACzB,eAAe,CAAC,UAAU,CAAC,GAC3B,aAAa,CAAC,UAAU,CAAC,CAAC;AAE9B,MAAM,MAAM,gBAAgB,GAAG,MAAM,CACnC,MAAM,EACN,qBAAqB,CAAC,OAAO,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAC9D,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,gBAAgB,CAAC;CACtC;AAED,MAAM,MAAM,6BAA6B,CACvC,WAAW,SAAS,qBAAqB,CAAC,OAAO,CAAC,IAChD,WAAW,SAAS,qBAAqB,CAAC,MAAM,UAAU,CAAC,GAAG,UAAU,GAAG,KAAK,CAAC;AAErF,MAAM,MAAM,0BAA0B,CAAC,MAAM,SAAS,gBAAgB,IAAI;KACvE,GAAG,IAAI,MAAM,MAAM,GAAG,UAAU,CAAC,6BAA6B,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;CAC9E,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,sBAAsB,IAChE,KAAK,SAAS,iBAAiB,GAC3B,0BAA0B,CAAC,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,GAC7D,KAAK,CAAC"}
|
|
@@ -1,97 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { log } from "../log";
|
|
3
|
-
const errors = {
|
|
4
|
-
descriptorUndefined: () => new Error("Descriptor of that dependency is undefined!"),
|
|
5
|
-
dependencyFactoryCalledDirectly: () => new Error("You cannot access the depdendency method directly, use container.resolve"),
|
|
6
|
-
};
|
|
7
|
-
const globalFactoryDependencies = new Map();
|
|
8
|
-
/**
|
|
9
|
-
* This is an abstract class for creating DependencyFactories, a pattern
|
|
10
|
-
* to bundle multiple smaller services into one and register them into the
|
|
11
|
-
* injection context.
|
|
12
|
-
*
|
|
13
|
-
* This can for example be a StorageDependencyFactory that creates dependencies
|
|
14
|
-
* like StateService, MerkleWitnessService, etc. So in general, services that
|
|
15
|
-
* are not ConfigurableModules, but still are their own logical unit.
|
|
16
|
-
*
|
|
17
|
-
* DependencyFactories are designed to only be used statically for sets of
|
|
18
|
-
* deps that are necessary for the sequencer to work.
|
|
19
|
-
*
|
|
20
|
-
* Every Factory need the @dependencyFactory annotation (which basically
|
|
21
|
-
* proxies @injectable()) and every method that returns a dependency has to be
|
|
22
|
-
* of the format `() => Dependency` and be annotated with @dependency.
|
|
23
|
-
*/
|
|
24
|
-
export class DependencyFactory {
|
|
25
|
-
initDependencies(container) {
|
|
26
|
-
const dependencies = globalFactoryDependencies.get(this.constructor.name) ?? {};
|
|
27
|
-
for (const [key, useFactory] of Object.entries(dependencies)) {
|
|
28
|
-
container.register(`${key}_singleton-prototype`, {
|
|
29
|
-
useFactory: useFactory.bind(this),
|
|
30
|
-
});
|
|
31
|
-
const upperCaseKey = key.charAt(0).toUpperCase() + key.slice(1);
|
|
32
|
-
container.register(upperCaseKey, {
|
|
33
|
-
useToken: `${key}_singleton-prototype`,
|
|
34
|
-
}, { lifecycle: Lifecycle.ContainerScoped });
|
|
35
|
-
log.debug(`Registered dependency ${upperCaseKey} from factory ${this.constructor.name}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// type DTypes = { [key: string]: TypedClass<unknown> }
|
|
40
|
-
// type Factories<T extends DTypes> = {
|
|
41
|
-
// [key in keyof T]: T[key] extends TypedClass<infer R> ? () => R : never
|
|
42
|
-
// }
|
|
43
|
-
//
|
|
44
|
-
// export abstract class DF2<Types extends DTypes> {
|
|
45
|
-
// public constructor(private factories: Factories<Types>) {
|
|
46
|
-
//
|
|
47
|
-
// }
|
|
48
|
-
// generateDependencies(): Types {
|
|
49
|
-
// let x = this.factories;
|
|
50
|
-
// return {} as Types;
|
|
51
|
-
// }
|
|
52
|
-
// }
|
|
53
|
-
// export function DF2C<T extends Types>(object: Factories<T>): T {
|
|
54
|
-
// const c = class C extends DF2<T>{
|
|
55
|
-
// generateDependencies(): T {
|
|
56
|
-
// return undefined;
|
|
57
|
-
// }
|
|
58
|
-
// }
|
|
59
|
-
// return new c();
|
|
60
|
-
// }
|
|
61
|
-
// class DF2I extends DF2<{x: typeof ConfigurableModule}> {
|
|
62
|
-
// constructor() {
|
|
63
|
-
// super({
|
|
64
|
-
// x: this.x
|
|
65
|
-
// });
|
|
66
|
-
// }
|
|
67
|
-
//
|
|
68
|
-
// x(): ConfigurableModule<any> {
|
|
69
|
-
// return {} as ConfigurableModule<any>;
|
|
70
|
-
// }
|
|
71
|
-
//
|
|
72
|
-
// }
|
|
73
|
-
export function dependency() {
|
|
74
|
-
return function decorator(target, key, descriptor) {
|
|
75
|
-
if (descriptor.value !== undefined) {
|
|
76
|
-
const className = target.constructor.name;
|
|
77
|
-
if (!globalFactoryDependencies.has(className)) {
|
|
78
|
-
globalFactoryDependencies.set(className, {});
|
|
79
|
-
}
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
81
|
-
globalFactoryDependencies.get(target.constructor.name)[key] =
|
|
82
|
-
descriptor.value;
|
|
83
|
-
descriptor.value = () => {
|
|
84
|
-
throw errors.dependencyFactoryCalledDirectly();
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
throw errors.descriptorUndefined();
|
|
89
|
-
}
|
|
90
|
-
return descriptor;
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
export function dependencyFactory() {
|
|
94
|
-
return function decorator(target) {
|
|
95
|
-
injectable()(target);
|
|
96
|
-
};
|
|
97
|
-
}
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventsRecord } from "./EventEmittingComponent";
|
|
2
|
+
export declare class EventEmitter<Events extends EventsRecord> {
|
|
3
|
+
private readonly listeners;
|
|
4
|
+
private readonly wildcardListeners;
|
|
5
|
+
emit<Key extends keyof Events>(event: Key, ...parameters: Events[Key]): void;
|
|
6
|
+
onAll(listener: (event: keyof Events, args: unknown[]) => void): void;
|
|
7
|
+
on<Key extends keyof Events>(event: Key, listener: (...args: Events[Key]) => void): void;
|
|
8
|
+
/**
|
|
9
|
+
* Primitive .off() with identity comparison for now.
|
|
10
|
+
* Could be replaced by returning an id in .on() and using that.
|
|
11
|
+
*/
|
|
12
|
+
off<Key extends keyof Events>(event: Key, listener: (...args: Events[Key]) => void): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=EventEmitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventEmitter.d.ts","sourceRoot":"","sources":["../../src/events/EventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAOxD,qBAAa,YAAY,CAAC,MAAM,SAAS,YAAY;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA+B;IAGzD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAGhB;IAEX,IAAI,CAAC,GAAG,SAAS,MAAM,MAAM,EAClC,KAAK,EAAE,GAAG,EACV,GAAG,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC;IAarB,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;IAIrE,EAAE,CAAC,GAAG,SAAS,MAAM,MAAM,EAChC,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;IAK1C;;;OAGG;IACI,GAAG,CAAC,GAAG,SAAS,MAAM,MAAM,EACjC,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;CAS3C"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class EventEmitter {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.listeners = {};
|
|
4
|
+
// eslint-disable-next-line putout/putout
|
|
5
|
+
this.wildcardListeners = [];
|
|
6
|
+
}
|
|
7
|
+
emit(event, ...parameters) {
|
|
8
|
+
const listeners = this.listeners[event];
|
|
9
|
+
if (listeners !== undefined) {
|
|
10
|
+
listeners.forEach((listener) => {
|
|
11
|
+
listener(...parameters);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
this.wildcardListeners.forEach((wildcardListener) => {
|
|
15
|
+
wildcardListener(event, parameters);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
onAll(listener) {
|
|
19
|
+
this.wildcardListeners.push(listener);
|
|
20
|
+
}
|
|
21
|
+
on(event, listener) {
|
|
22
|
+
var _a;
|
|
23
|
+
((_a = this.listeners)[event] ?? (_a[event] = [])).push(listener);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Primitive .off() with identity comparison for now.
|
|
27
|
+
* Could be replaced by returning an id in .on() and using that.
|
|
28
|
+
*/
|
|
29
|
+
off(event, listener) {
|
|
30
|
+
const events = this.listeners[event];
|
|
31
|
+
if (events !== undefined) {
|
|
32
|
+
this.listeners[event] = events.filter((candidate) => candidate !== listener);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BaseModuleType, ModuleContainer, ModulesRecord } from "../config/ModuleContainer";
|
|
2
|
+
import { StringKeyOf, UnionToIntersection } from "../types";
|
|
3
|
+
import { EventEmitter } from "./EventEmitter";
|
|
4
|
+
import { EventEmittingComponent, EventsRecord } from "./EventEmittingComponent";
|
|
5
|
+
export type CastToEventsRecord<Record> = Record extends EventsRecord ? Record : {};
|
|
6
|
+
export type ModuleEvents<ModuleType extends BaseModuleType> = InstanceType<ModuleType> extends EventEmittingComponent<infer Events> ? Events : InstanceType<ModuleType> extends ModuleContainer<infer NestedModules> ? CastToEventsRecord<ContainerEvents<NestedModules>> : EventsRecord;
|
|
7
|
+
export type ContainerEvents<Modules extends ModulesRecord> = {
|
|
8
|
+
[Key in StringKeyOf<Modules>]: ModuleEvents<Modules[Key]>;
|
|
9
|
+
};
|
|
10
|
+
export type FlattenObject<Target extends Record<string, EventsRecord>> = UnionToIntersection<Target[keyof Target]>;
|
|
11
|
+
export type FlattenedContainerEvents<Modules extends ModulesRecord> = FlattenObject<ContainerEvents<Modules>>;
|
|
12
|
+
export declare class EventEmitterProxy<Modules extends ModulesRecord> extends EventEmitter<CastToEventsRecord<FlattenedContainerEvents<Modules>>> {
|
|
13
|
+
private readonly container;
|
|
14
|
+
constructor(container: ModuleContainer<Modules>);
|
|
15
|
+
private isEventEmitter;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=EventEmitterProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventEmitterProxy.d.ts","sourceRoot":"","sources":["../../src/events/EventEmitterProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEhF,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,MAAM,SAAS,YAAY,GAChE,MAAM,GACN,EAAE,CAAC;AAEP,MAAM,MAAM,YAAY,CAAC,UAAU,SAAS,cAAc,IACxD,YAAY,CAAC,UAAU,CAAC,SAAS,sBAAsB,CAAC,MAAM,MAAM,CAAC,GACjE,MAAM,GACN,YAAY,CAAC,UAAU,CAAC,SAAS,eAAe,CAAC,MAAM,aAAa,CAAC,GACrE,kBAAkB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,GAClD,YAAY,CAAC;AAEnB,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,aAAa,IAAI;KAC1D,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IACnE,mBAAmB,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC;AAE5C,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,aAAa,IAChE,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;AAE1C,qBAAa,iBAAiB,CAC5B,OAAO,SAAS,aAAa,CAC7B,SAAQ,YAAY,CAAC,kBAAkB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC;IAgBvE,OAAO,CAAC,cAAc;CAMvB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EventEmitter } from "./EventEmitter";
|
|
2
|
+
export class EventEmitterProxy extends EventEmitter {
|
|
3
|
+
constructor(container) {
|
|
4
|
+
super();
|
|
5
|
+
this.container = container;
|
|
6
|
+
container.moduleNames.forEach((moduleName) => {
|
|
7
|
+
if (container.isValidModuleName(container.definition.modules, moduleName)) {
|
|
8
|
+
const module = container.resolve(moduleName);
|
|
9
|
+
if (this.isEventEmitter(module)) {
|
|
10
|
+
module.events.onAll((events, args) => {
|
|
11
|
+
this.emit(events, ...args);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
isEventEmitter(module) {
|
|
18
|
+
const emitter = module.events;
|
|
19
|
+
return emitter !== undefined && emitter instanceof EventEmitter;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EventEmitter } from "./EventEmitter";
|
|
2
|
+
export type EventsRecord = Record<string, unknown[]>;
|
|
3
|
+
export interface EventEmittingComponent<Events extends EventsRecord> {
|
|
4
|
+
events: EventEmitter<Events>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=EventEmittingComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventEmittingComponent.d.ts","sourceRoot":"","sources":["../../src/events/EventEmittingComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAErD,MAAM,WAAW,sBAAsB,CAAC,MAAM,SAAS,YAAY;IACjE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;CAC9B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,4 +9,11 @@ export * from "./zkProgrammable/provableMethod";
|
|
|
9
9
|
export * from "./utils";
|
|
10
10
|
export * from "./dependencyFactory/DependencyFactory";
|
|
11
11
|
export * from "./log";
|
|
12
|
+
export * from "./events/EventEmittingComponent";
|
|
13
|
+
export * from "./events/EventEmitter";
|
|
14
|
+
export * from "./trees/MerkleTreeStore";
|
|
15
|
+
export * from "./trees/InMemoryMerkleTreeStorage";
|
|
16
|
+
export * from "./trees/RollupMerkleTree";
|
|
17
|
+
export * from "./events/EventEmitterProxy";
|
|
18
|
+
export * from "./trees/MockAsyncMerkleStore";
|
|
12
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,3 +9,10 @@ export * from "./zkProgrammable/provableMethod";
|
|
|
9
9
|
export * from "./utils";
|
|
10
10
|
export * from "./dependencyFactory/DependencyFactory";
|
|
11
11
|
export * from "./log";
|
|
12
|
+
export * from "./events/EventEmittingComponent";
|
|
13
|
+
export * from "./events/EventEmitter";
|
|
14
|
+
export * from "./trees/MerkleTreeStore";
|
|
15
|
+
export * from "./trees/InMemoryMerkleTreeStorage";
|
|
16
|
+
export * from "./trees/RollupMerkleTree";
|
|
17
|
+
export * from "./events/EventEmitterProxy";
|
|
18
|
+
export * from "./trees/MockAsyncMerkleStore";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MerkleTreeStore } from "./MerkleTreeStore";
|
|
2
|
+
export declare class InMemoryMerkleTreeStorage implements MerkleTreeStore {
|
|
3
|
+
protected nodes: {
|
|
4
|
+
[key: number]: {
|
|
5
|
+
[key: string]: bigint;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
getNode(key: bigint, level: number): bigint | undefined;
|
|
9
|
+
setNode(key: bigint, level: number, value: bigint): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=InMemoryMerkleTreeStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryMerkleTreeStorage.d.ts","sourceRoot":"","sources":["../../src/trees/InMemoryMerkleTreeStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,yBAA0B,YAAW,eAAe;IAC/D,SAAS,CAAC,KAAK,EAAE;QACf,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACvB,CAAC;KACH,CAAM;IAEA,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIvD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAGhE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class InMemoryMerkleTreeStorage {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.nodes = {};
|
|
4
|
+
}
|
|
5
|
+
getNode(key, level) {
|
|
6
|
+
return this.nodes[level]?.[key.toString()];
|
|
7
|
+
}
|
|
8
|
+
setNode(key, level, value) {
|
|
9
|
+
var _a;
|
|
10
|
+
((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MerkleTreeStore.d.ts","sourceRoot":"","sources":["../../src/trees/MerkleTreeStore.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAE7D,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|