@proto-kit/common 0.1.1-develop.267 → 0.1.1-develop.299
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/ChildContainerCreatable.d.ts +5 -0
- package/dist/config/ChildContainerCreatable.d.ts.map +1 -0
- package/dist/config/ChildContainerCreatable.js +1 -0
- package/dist/config/ChildContainerProvider.d.ts +5 -0
- package/dist/config/ChildContainerProvider.d.ts.map +1 -0
- package/dist/config/ChildContainerProvider.js +1 -0
- package/dist/config/ChildContainerStartable.d.ts +5 -0
- package/dist/config/ChildContainerStartable.d.ts.map +1 -0
- package/dist/config/ChildContainerStartable.js +1 -0
- package/dist/config/ConfigurableModule.d.ts +4 -1
- package/dist/config/ConfigurableModule.d.ts.map +1 -1
- package/dist/config/ConfigurableModule.js +5 -0
- package/dist/config/ModuleContainer.d.ts +18 -3
- package/dist/config/ModuleContainer.d.ts.map +1 -1
- package/dist/config/ModuleContainer.js +40 -6
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
- package/dist/dependencyFactory/DependencyFactory.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/log.js +1 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -1
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +1 -1
- package/dist/zkProgrammable/ProvableMethodExecutionContext.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/provableMethod.d.ts +1 -1
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/config/ChildContainerCreatable.ts +5 -0
- package/src/config/ChildContainerProvider.ts +5 -0
- package/src/config/ConfigurableModule.ts +13 -1
- package/src/config/ModuleContainer.ts +74 -7
- package/src/dependencyFactory/DependencyFactory.ts +5 -0
- package/src/index.ts +2 -0
- package/src/log.ts +1 -1
- package/src/utils.ts +8 -2
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +1 -1
- package/src/zkProgrammable/ZkProgrammable.ts +1 -1
- package/src/zkProgrammable/provableMethod.ts +1 -1
- package/test/zkProgrammable/ZkProgrammable.test.ts +1 -1
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChildContainerStartable.d.ts","sourceRoot":"","sources":["../../src/config/ChildContainerStartable.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 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ChildContainerProvider } from "./ChildContainerProvider";
|
|
2
|
+
import type { BaseModuleInstanceType } from "./ModuleContainer";
|
|
1
3
|
export type Preset<Config> = Config | ((...args: any[]) => Config);
|
|
2
4
|
export type Presets<Config> = Record<string, Preset<Config>>;
|
|
3
5
|
export interface Configurable<Config> {
|
|
@@ -6,7 +8,7 @@ export interface Configurable<Config> {
|
|
|
6
8
|
/**
|
|
7
9
|
* Used by various module sub-types that may need to be configured
|
|
8
10
|
*/
|
|
9
|
-
export declare class ConfigurableModule<Config> implements
|
|
11
|
+
export declare class ConfigurableModule<Config> implements BaseModuleInstanceType {
|
|
10
12
|
/**
|
|
11
13
|
* Store the config separately, so that we can apply additional
|
|
12
14
|
* checks when retrieving it via the getter
|
|
@@ -14,6 +16,7 @@ export declare class ConfigurableModule<Config> implements Configurable<Config>
|
|
|
14
16
|
protected currentConfig: Config | undefined;
|
|
15
17
|
get config(): Config;
|
|
16
18
|
set config(config: Config);
|
|
19
|
+
create(childContainerProvider: ChildContainerProvider): void;
|
|
17
20
|
}
|
|
18
21
|
export interface StaticConfigurableModule<Config> {
|
|
19
22
|
presets: Presets<Config>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurableModule.d.ts","sourceRoot":"","sources":["../../src/config/ConfigurableModule.ts"],"names":[],"mappings":"
|
|
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,CACpC,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,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
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
+
create(childContainerProvider) {
|
|
22
|
+
noop();
|
|
23
|
+
}
|
|
19
24
|
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { InjectionToken } from "tsyringe";
|
|
2
|
+
import { DependencyContainer, InjectionToken } from "tsyringe";
|
|
3
3
|
import { StringKeyOf, TypedClass } from "../types";
|
|
4
4
|
import { DependencyFactory } from "../dependencyFactory/DependencyFactory";
|
|
5
5
|
import { Configurable, ConfigurableModule } from "./ConfigurableModule";
|
|
6
|
+
import { ChildContainerProvider } from "./ChildContainerProvider";
|
|
7
|
+
import { ChildContainerCreatable } from "./ChildContainerCreatable";
|
|
6
8
|
export declare const ModuleContainerErrors: {
|
|
7
9
|
configNotSetInContainer: (moduleName: string) => Error;
|
|
8
10
|
onlyValidModuleNames: (moduleName: NonNullable<unknown>) => Error;
|
|
9
11
|
unableToDecorateModule: (moduleName: InjectionToken<unknown>) => Error;
|
|
10
12
|
nonModuleDependency: (runtimeModuleName: string) => Error;
|
|
11
13
|
unknownDependency: (runtimeModuleName: string, name: string) => Error;
|
|
14
|
+
dependencyContainerNotSet: (className: string) => Error;
|
|
15
|
+
validModuleInstance: (moduleName: string, moduleTypeName: string) => Error;
|
|
12
16
|
};
|
|
13
|
-
export
|
|
17
|
+
export interface BaseModuleInstanceType extends ChildContainerCreatable, Configurable<unknown> {
|
|
18
|
+
}
|
|
19
|
+
export type BaseModuleType = TypedClass<BaseModuleInstanceType>;
|
|
14
20
|
export interface ModulesRecord<ModuleType extends BaseModuleType = BaseModuleType> {
|
|
15
21
|
[name: string]: ModuleType;
|
|
16
22
|
}
|
|
@@ -35,7 +41,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
35
41
|
* from the tsyringe DI container
|
|
36
42
|
*/
|
|
37
43
|
private static readonly moduleDecorationFrequency;
|
|
38
|
-
|
|
44
|
+
private providedContainer?;
|
|
39
45
|
constructor(definition: ModuleContainerDefinition<Modules>);
|
|
40
46
|
/**
|
|
41
47
|
* @returns list of module names
|
|
@@ -49,6 +55,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
49
55
|
* @param containedModule
|
|
50
56
|
*/
|
|
51
57
|
protected validateModule(moduleName: StringKeyOf<Modules>, containedModule: ConfigurableModule<unknown>): void;
|
|
58
|
+
protected get container(): DependencyContainer;
|
|
52
59
|
/**
|
|
53
60
|
* Assert that the iterated `moduleName` is of ModuleName type,
|
|
54
61
|
* otherwise it may be just string e.g. when modules are iterated over
|
|
@@ -56,6 +63,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
56
63
|
*/
|
|
57
64
|
assertIsValidModuleName(modules: Modules, moduleName: string): asserts moduleName is StringKeyOf<Modules>;
|
|
58
65
|
isValidModuleName(modules: Modules, moduleName: number | string | symbol): asserts moduleName is StringKeyOf<Modules>;
|
|
66
|
+
assertContainerInitialized(container: DependencyContainer | undefined): asserts container is DependencyContainer;
|
|
59
67
|
/**
|
|
60
68
|
* Register modules into the current container, and registers
|
|
61
69
|
* a respective resolution hook in order to decorate the module
|
|
@@ -74,6 +82,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
74
82
|
* @param modules
|
|
75
83
|
*/
|
|
76
84
|
registerValue<Value>(modules: Record<string, Value>): void;
|
|
85
|
+
protected registerClasses(modules: Record<string, TypedClass<unknown>>): void;
|
|
77
86
|
/**
|
|
78
87
|
* Provide additional configuration after the ModuleContainer was created.
|
|
79
88
|
*
|
|
@@ -105,5 +114,11 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
|
|
|
105
114
|
* @param moduleName
|
|
106
115
|
*/
|
|
107
116
|
protected onAfterModuleResolution(moduleName: StringKeyOf<Modules>): void;
|
|
117
|
+
/**
|
|
118
|
+
* This is a placeholder for individual modules to override.
|
|
119
|
+
* This method will be called whenever the underlying container fully
|
|
120
|
+
* initialized
|
|
121
|
+
*/
|
|
122
|
+
create(childContainerProvider: ChildContainerProvider): void;
|
|
108
123
|
}
|
|
109
124
|
//# sourceMappingURL=ModuleContainer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleContainer.d.ts","sourceRoot":"","sources":["../../src/config/ModuleContainer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ModuleContainer.d.ts","sourceRoot":"","sources":["../../src/config/ModuleContainer.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EACL,mBAAmB,EAEnB,cAAc,EAEf,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E,OAAO,EAAE,YAAY,EA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B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC;IAYpC;;;OAGG;IACH,SAAS,CAAC,cAAc,CACtB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,eAAe,EAAE,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAY9D;;;OAGG;IACH,SAAS,CAAC,uBAAuB,CAAC,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC;IAoBlE;;;;OAIG;IACI,MAAM,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,IAAI;CAUpE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
1
2
|
import "reflect-metadata";
|
|
2
|
-
import {
|
|
3
|
+
import { Lifecycle, } from "tsyringe";
|
|
3
4
|
import log from "loglevel";
|
|
4
5
|
import { ConfigurableModule } from "./ConfigurableModule";
|
|
5
6
|
const errors = {
|
|
@@ -16,6 +17,8 @@ const errors = {
|
|
|
16
17
|
unknownDependency: (runtimeModuleName, name) => new Error(`Unable to register module: ${runtimeModuleName},
|
|
17
18
|
attempting to inject a dependency that is not registered
|
|
18
19
|
as a runtime module for this chain: ${name}`),
|
|
20
|
+
dependencyContainerNotSet: (className) => new Error(`DependencyContainer not set. Be sure to only call DI-related function in create() and not inside the constructor. (${className})`),
|
|
21
|
+
validModuleInstance: (moduleName, moduleTypeName) => new Error(`Incompatible module instance ("${moduleName}" not instanceof ${moduleTypeName})`),
|
|
19
22
|
};
|
|
20
23
|
export const ModuleContainerErrors = errors;
|
|
21
24
|
/**
|
|
@@ -27,9 +30,7 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
27
30
|
super();
|
|
28
31
|
this.definition = definition;
|
|
29
32
|
// DI container holding all the registered modules
|
|
30
|
-
this.
|
|
31
|
-
// register all provided modules when the container is created
|
|
32
|
-
this.registerModules(definition.modules);
|
|
33
|
+
this.providedContainer = undefined;
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* @returns list of module names
|
|
@@ -57,6 +58,10 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
57
58
|
}
|
|
58
59
|
});
|
|
59
60
|
}
|
|
61
|
+
get container() {
|
|
62
|
+
this.assertContainerInitialized(this.providedContainer);
|
|
63
|
+
return this.providedContainer;
|
|
64
|
+
}
|
|
60
65
|
/**
|
|
61
66
|
* Assert that the iterated `moduleName` is of ModuleName type,
|
|
62
67
|
* otherwise it may be just string e.g. when modules are iterated over
|
|
@@ -70,6 +75,11 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
70
75
|
throw errors.onlyValidModuleNames(moduleName);
|
|
71
76
|
}
|
|
72
77
|
}
|
|
78
|
+
assertContainerInitialized(container) {
|
|
79
|
+
if (container === undefined) {
|
|
80
|
+
throw errors.dependencyContainerNotSet(this.constructor.name);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
73
83
|
/**
|
|
74
84
|
* Register modules into the current container, and registers
|
|
75
85
|
* a respective resolution hook in order to decorate the module
|
|
@@ -82,7 +92,8 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
82
92
|
if (Object.prototype.hasOwnProperty.call(modules, moduleName)) {
|
|
83
93
|
this.assertIsValidModuleName(modules, moduleName);
|
|
84
94
|
log.debug(`Registering module: ${moduleName}`);
|
|
85
|
-
|
|
95
|
+
const definitionEntry = modules[moduleName];
|
|
96
|
+
this.container.register(moduleName, { useClass: definitionEntry }, { lifecycle: Lifecycle.ContainerScoped });
|
|
86
97
|
this.onAfterModuleResolution(moduleName);
|
|
87
98
|
}
|
|
88
99
|
}
|
|
@@ -107,6 +118,11 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
107
118
|
this.container.register(moduleName, { useValue });
|
|
108
119
|
});
|
|
109
120
|
}
|
|
121
|
+
registerClasses(modules) {
|
|
122
|
+
Object.entries(modules).forEach(([moduleName, useClass]) => {
|
|
123
|
+
this.container.register(moduleName, { useClass }, { lifecycle: Lifecycle.ContainerScoped });
|
|
124
|
+
});
|
|
125
|
+
}
|
|
110
126
|
/**
|
|
111
127
|
* Provide additional configuration after the ModuleContainer was created.
|
|
112
128
|
*
|
|
@@ -135,7 +151,7 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
135
151
|
const instance = this.container.resolve(moduleName);
|
|
136
152
|
const isValidModuleInstance = instance instanceof moduleType;
|
|
137
153
|
if (!isValidModuleInstance) {
|
|
138
|
-
throw
|
|
154
|
+
throw errors.validModuleInstance(moduleName, moduleType.name);
|
|
139
155
|
}
|
|
140
156
|
return instance;
|
|
141
157
|
}
|
|
@@ -162,8 +178,26 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
162
178
|
throw errors.unableToDecorateModule(containedModuleName);
|
|
163
179
|
}
|
|
164
180
|
this.decorateModule(moduleName, containedModule);
|
|
181
|
+
containedModule.create(() => {
|
|
182
|
+
const container = this.container.createChildContainer();
|
|
183
|
+
container.reset();
|
|
184
|
+
return container;
|
|
185
|
+
});
|
|
165
186
|
}, { frequency: ModuleContainer.moduleDecorationFrequency });
|
|
166
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* This is a placeholder for individual modules to override.
|
|
190
|
+
* This method will be called whenever the underlying container fully
|
|
191
|
+
* initialized
|
|
192
|
+
*/
|
|
193
|
+
create(childContainerProvider) {
|
|
194
|
+
this.providedContainer = childContainerProvider();
|
|
195
|
+
this.registerValue({
|
|
196
|
+
ChildContainerProvider: () => this.container.createChildContainer(),
|
|
197
|
+
});
|
|
198
|
+
// register all provided modules when the container is created
|
|
199
|
+
this.registerModules(this.definition.modules);
|
|
200
|
+
}
|
|
167
201
|
}
|
|
168
202
|
/**
|
|
169
203
|
* Determines how often are modules decorated upon resolution
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyFactory.d.ts","sourceRoot":"","sources":["../../src/dependencyFactory/DependencyFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAyB,MAAM,UAAU,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"DependencyFactory.d.ts","sourceRoot":"","sources":["../../src/dependencyFactory/DependencyFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAyB,MAAM,UAAU,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAqBtC;;;;;;;;;;;;;;;GAeG;AACH,8BAAsB,iBAAiB;IAC9B,gBAAgB,CAAC,SAAS,EAAE,mBAAmB;CAyBvD;AAuCD,wBAAgB,UAAU,wEAGjB,MAAM,sGAqBd;AAED,wBAAgB,iBAAiB,2EAMhC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { injectable, Lifecycle } from "tsyringe";
|
|
2
|
+
import { log } from "../log";
|
|
2
3
|
const errors = {
|
|
3
4
|
descriptorUndefined: () => new Error("Descriptor of that dependency is undefined!"),
|
|
4
5
|
dependencyFactoryCalledDirectly: () => new Error("You cannot access the depdendency method directly, use container.resolve"),
|
|
@@ -32,6 +33,7 @@ export class DependencyFactory {
|
|
|
32
33
|
container.register(upperCaseKey, {
|
|
33
34
|
useToken: `${key}_singleton-prototype`,
|
|
34
35
|
}, { lifecycle: Lifecycle.ContainerScoped });
|
|
36
|
+
log.debug(`Registered dependency ${upperCaseKey} from factory ${this.constructor.name}`);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./config/ModuleContainer";
|
|
2
2
|
export * from "./config/ConfigurableModule";
|
|
3
|
+
export * from "./config/ChildContainerProvider";
|
|
4
|
+
export * from "./config/ChildContainerCreatable";
|
|
3
5
|
export * from "./types";
|
|
4
6
|
export * from "./zkProgrammable/ZkProgrammable";
|
|
5
7
|
export * from "./zkProgrammable/ProvableMethodExecutionContext";
|
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,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"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./config/ModuleContainer";
|
|
2
2
|
export * from "./config/ConfigurableModule";
|
|
3
|
+
export * from "./config/ChildContainerProvider";
|
|
4
|
+
export * from "./config/ChildContainerCreatable";
|
|
3
5
|
export * from "./types";
|
|
4
6
|
export * from "./zkProgrammable/ZkProgrammable";
|
|
5
7
|
export * from "./zkProgrammable/ProvableMethodExecutionContext";
|
package/dist/log.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/unbound-method, putout/putout */
|
|
2
2
|
import loglevel from "loglevel";
|
|
3
|
-
import { Provable } from "
|
|
3
|
+
import { Provable } from "o1js";
|
|
4
4
|
function logProvable(logFunction, ...args) {
|
|
5
5
|
Provable.asProver(() => {
|
|
6
6
|
const prettyArguments = [];
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Field, FlexibleProvablePure } from "
|
|
1
|
+
import { Field, FlexibleProvablePure } from "o1js";
|
|
2
2
|
export declare function requireTrue(condition: boolean, errorOrFunction: Error | (() => Error)): void;
|
|
3
3
|
export declare function range(startOrEnd: number, end: number | undefined): number[];
|
|
4
4
|
/**
|
|
@@ -8,6 +8,7 @@ export declare function range(startOrEnd: number, end: number | undefined): numb
|
|
|
8
8
|
* @returns Dummy value for the given value type
|
|
9
9
|
*/
|
|
10
10
|
export declare function dummyValue<Value>(valueType: FlexibleProvablePure<Value>): Value;
|
|
11
|
+
export declare function noop(): void;
|
|
11
12
|
export interface ToFieldable {
|
|
12
13
|
toFields: () => Field[];
|
|
13
14
|
}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAEnD,wBAAgB,WAAW,CACzB,SAAS,EAAE,OAAO,EAClB,eAAe,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GACrC,IAAI,CAMN;AAED,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAS3E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAC9B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACrC,KAAK,CAMP;AAGD,wBAAgB,IAAI,IAAI,IAAI,CAAG;AAE/B,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,KAAK,EAAE,CAAC;CACzB"}
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Field } from "
|
|
1
|
+
import { Field } from "o1js";
|
|
2
2
|
export function requireTrue(condition, errorOrFunction) {
|
|
3
3
|
if (!condition) {
|
|
4
4
|
throw typeof errorOrFunction === "function"
|
|
@@ -25,3 +25,5 @@ export function dummyValue(valueType) {
|
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
26
26
|
return valueType.fromFields(fields);
|
|
27
27
|
}
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
|
+
export function noop() { }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProvableMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ProvableMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ProvableMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ProvableMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,MAAM,CAAC;AAIpD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAWvC,qBAAa,6BAA6B;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC;IAErB,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAE1C,KAAK,CAEhB,SAAS,SAAS,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KACtC,OAAO,CAAC,SAAS,CAAC;CAaxB;AAED;;;;GAIG;AACH,qBACa,8BAA8B;IAClC,EAAE,SAAc;IAEhB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,MAAM,EAAE,6BAA6B,CACN;IAItC;;;;;;OAMG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAI/D;;;;;OAKG;IACI,YAAY,CACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,WAAW,EAAE;IAYrB;;;;OAIG;IACI,WAAW;IAIlB,IAAW,UAAU,YAEpB;IAED,IAAW,UAAU,YAEpB;IAED;;OAEG;IACI,OAAO;;;;IAOd;;OAEG;IACI,KAAK;CAGb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZkProgrammable.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ZkProgrammable.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAUjE,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD;AAED,MAAM,WAAW,MAAM,CAAC,WAAW,EAAE,YAAY;IAC/C,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc,CAAC,WAAW,GAAG,SAAS,EAAE,YAAY,GAAG,IAAI;IAC1E,OAAO,EAAE,OAAO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,YAAY,CAAC,CAAC;CAC3D"}
|
|
@@ -2,7 +2,7 @@ import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext
|
|
|
2
2
|
import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
|
|
3
3
|
export type DecoratedMethod = (...args: unknown[]) => unknown;
|
|
4
4
|
export declare const mockProof = "mock-proof";
|
|
5
|
-
export declare function toProver(methodName: string, simulatedMethod: DecoratedMethod, isFirstParameterPublicInput: boolean, ...args: unknown[]): (this: ZkProgrammable<any, any>) => Promise<import("
|
|
5
|
+
export declare function toProver(methodName: string, simulatedMethod: DecoratedMethod, isFirstParameterPublicInput: boolean, ...args: unknown[]): (this: ZkProgrammable<any, any>) => Promise<import("o1js/dist/node/lib/proof_system").Proof<any, any>>;
|
|
6
6
|
/**
|
|
7
7
|
* Decorates a provable method on a 'prover class', depending on
|
|
8
8
|
* if proofs are enabled or not, either runs the respective zkProgram prover,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAI3E,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAE9D,eAAO,MAAM,SAAS,eAAe,CAAC;AAEtC,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,2BAA2B,EAAE,OAAO,EACpC,GAAG,IAAI,EAAE,OAAO,EAAE,UAGiB,eAAe,GAAG,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAI3E,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAE9D,eAAO,MAAM,SAAS,eAAe,CAAC;AAEtC,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,2BAA2B,EAAE,OAAO,EACpC,GAAG,IAAI,EAAE,OAAO,EAAE,UAGiB,eAAe,GAAG,EAAE,GAAG,CAAC,wEAyB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,2BAA2B,UAAO,EAClC,gBAAgB,GAAE,8BAEjB,wGAOa,MAAM,cACN,kBAAkB,wBA4CjC"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.1.1-develop.
|
|
6
|
+
"version": "0.1.1-develop.299+fbe92e3",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"dev": "tsc -p tsconfig.json --watch",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"typescript-memoize": "^1.1.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"
|
|
26
|
+
"o1js": "0.13.1",
|
|
27
27
|
"tsyringe": "^4.7.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@jest/globals": "^29.5.0",
|
|
31
31
|
"@types/lodash": "^4.14.194"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "fbe92e36c7103001875d853888ab3b6728936cc9"
|
|
34
34
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { noop } from "../utils";
|
|
2
|
+
|
|
3
|
+
import { ChildContainerProvider } from "./ChildContainerProvider";
|
|
4
|
+
import type { BaseModuleInstanceType } from "./ModuleContainer";
|
|
5
|
+
|
|
1
6
|
const errors = {
|
|
2
7
|
configNotSet: (moduleName: string) =>
|
|
3
8
|
new Error(
|
|
@@ -17,7 +22,9 @@ export interface Configurable<Config> {
|
|
|
17
22
|
/**
|
|
18
23
|
* Used by various module sub-types that may need to be configured
|
|
19
24
|
*/
|
|
20
|
-
export class ConfigurableModule<Config>
|
|
25
|
+
export class ConfigurableModule<Config>
|
|
26
|
+
implements BaseModuleInstanceType
|
|
27
|
+
{
|
|
21
28
|
/**
|
|
22
29
|
* Store the config separately, so that we can apply additional
|
|
23
30
|
* checks when retrieving it via the getter
|
|
@@ -36,6 +43,11 @@ export class ConfigurableModule<Config> implements Configurable<Config> {
|
|
|
36
43
|
public set config(config: Config) {
|
|
37
44
|
this.currentConfig = config;
|
|
38
45
|
}
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
public create(childContainerProvider: ChildContainerProvider): void {
|
|
49
|
+
noop();
|
|
50
|
+
}
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
// Helps ensure that the target class implements static presets
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
1
2
|
import "reflect-metadata";
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DependencyContainer,
|
|
6
|
+
Frequency,
|
|
7
|
+
InjectionToken,
|
|
8
|
+
Lifecycle,
|
|
9
|
+
} from "tsyringe";
|
|
4
10
|
import log from "loglevel";
|
|
5
11
|
|
|
6
12
|
import { StringKeyOf, TypedClass } from "../types";
|
|
7
13
|
import { DependencyFactory } from "../dependencyFactory/DependencyFactory";
|
|
8
14
|
|
|
9
15
|
import { Configurable, ConfigurableModule } from "./ConfigurableModule";
|
|
16
|
+
import { ChildContainerProvider } from "./ChildContainerProvider";
|
|
17
|
+
import { ChildContainerCreatable } from "./ChildContainerCreatable";
|
|
10
18
|
|
|
11
19
|
const errors = {
|
|
12
20
|
configNotSetInContainer: (moduleName: string) =>
|
|
@@ -35,12 +43,26 @@ const errors = {
|
|
|
35
43
|
attempting to inject a dependency that is not registered
|
|
36
44
|
as a runtime module for this chain: ${name}`
|
|
37
45
|
),
|
|
46
|
+
|
|
47
|
+
dependencyContainerNotSet: (className: string) =>
|
|
48
|
+
new Error(
|
|
49
|
+
`DependencyContainer not set. Be sure to only call DI-related function in create() and not inside the constructor. (${className})`
|
|
50
|
+
),
|
|
51
|
+
|
|
52
|
+
validModuleInstance: (moduleName: string, moduleTypeName: string) =>
|
|
53
|
+
new Error(
|
|
54
|
+
`Incompatible module instance ("${moduleName}" not instanceof ${moduleTypeName})`
|
|
55
|
+
),
|
|
38
56
|
};
|
|
39
57
|
|
|
40
58
|
export const ModuleContainerErrors = errors;
|
|
41
59
|
|
|
60
|
+
export interface BaseModuleInstanceType
|
|
61
|
+
extends ChildContainerCreatable,
|
|
62
|
+
Configurable<unknown> {}
|
|
63
|
+
|
|
42
64
|
// determines that a module should be configurable by default
|
|
43
|
-
export type BaseModuleType = TypedClass<
|
|
65
|
+
export type BaseModuleType = TypedClass<BaseModuleInstanceType>;
|
|
44
66
|
|
|
45
67
|
// allows to specify what kind of modules can be passed into a container
|
|
46
68
|
export interface ModulesRecord<
|
|
@@ -83,12 +105,10 @@ export class ModuleContainer<
|
|
|
83
105
|
private static readonly moduleDecorationFrequency: Frequency = "Once";
|
|
84
106
|
|
|
85
107
|
// DI container holding all the registered modules
|
|
86
|
-
|
|
108
|
+
private providedContainer?: DependencyContainer = undefined;
|
|
87
109
|
|
|
88
110
|
public constructor(public definition: ModuleContainerDefinition<Modules>) {
|
|
89
111
|
super();
|
|
90
|
-
// register all provided modules when the container is created
|
|
91
|
-
this.registerModules(definition.modules);
|
|
92
112
|
}
|
|
93
113
|
|
|
94
114
|
/**
|
|
@@ -127,6 +147,11 @@ export class ModuleContainer<
|
|
|
127
147
|
});
|
|
128
148
|
}
|
|
129
149
|
|
|
150
|
+
protected get container(): DependencyContainer {
|
|
151
|
+
this.assertContainerInitialized(this.providedContainer);
|
|
152
|
+
return this.providedContainer;
|
|
153
|
+
}
|
|
154
|
+
|
|
130
155
|
/**
|
|
131
156
|
* Assert that the iterated `moduleName` is of ModuleName type,
|
|
132
157
|
* otherwise it may be just string e.g. when modules are iterated over
|
|
@@ -148,6 +173,14 @@ export class ModuleContainer<
|
|
|
148
173
|
}
|
|
149
174
|
}
|
|
150
175
|
|
|
176
|
+
public assertContainerInitialized(
|
|
177
|
+
container: DependencyContainer | undefined
|
|
178
|
+
): asserts container is DependencyContainer {
|
|
179
|
+
if (container === undefined) {
|
|
180
|
+
throw errors.dependencyContainerNotSet(this.constructor.name);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
151
184
|
/**
|
|
152
185
|
* Register modules into the current container, and registers
|
|
153
186
|
* a respective resolution hook in order to decorate the module
|
|
@@ -162,9 +195,11 @@ export class ModuleContainer<
|
|
|
162
195
|
|
|
163
196
|
log.debug(`Registering module: ${moduleName}`);
|
|
164
197
|
|
|
198
|
+
const definitionEntry = modules[moduleName];
|
|
199
|
+
|
|
165
200
|
this.container.register(
|
|
166
201
|
moduleName,
|
|
167
|
-
{ useClass:
|
|
202
|
+
{ useClass: definitionEntry },
|
|
168
203
|
{ lifecycle: Lifecycle.ContainerScoped }
|
|
169
204
|
);
|
|
170
205
|
this.onAfterModuleResolution(moduleName);
|
|
@@ -196,6 +231,16 @@ export class ModuleContainer<
|
|
|
196
231
|
});
|
|
197
232
|
}
|
|
198
233
|
|
|
234
|
+
protected registerClasses(modules: Record<string, TypedClass<unknown>>) {
|
|
235
|
+
Object.entries(modules).forEach(([moduleName, useClass]) => {
|
|
236
|
+
this.container.register(
|
|
237
|
+
moduleName,
|
|
238
|
+
{ useClass },
|
|
239
|
+
{ lifecycle: Lifecycle.ContainerScoped }
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
199
244
|
/**
|
|
200
245
|
* Provide additional configuration after the ModuleContainer was created.
|
|
201
246
|
*
|
|
@@ -234,7 +279,7 @@ export class ModuleContainer<
|
|
|
234
279
|
const isValidModuleInstance = instance instanceof moduleType;
|
|
235
280
|
|
|
236
281
|
if (!isValidModuleInstance) {
|
|
237
|
-
throw
|
|
282
|
+
throw errors.validModuleInstance(moduleName, moduleType.name);
|
|
238
283
|
}
|
|
239
284
|
|
|
240
285
|
return instance;
|
|
@@ -271,8 +316,30 @@ export class ModuleContainer<
|
|
|
271
316
|
throw errors.unableToDecorateModule(containedModuleName);
|
|
272
317
|
}
|
|
273
318
|
this.decorateModule(moduleName, containedModule);
|
|
319
|
+
|
|
320
|
+
containedModule.create(() => {
|
|
321
|
+
const container = this.container.createChildContainer();
|
|
322
|
+
container.reset();
|
|
323
|
+
return container;
|
|
324
|
+
});
|
|
274
325
|
},
|
|
275
326
|
{ frequency: ModuleContainer.moduleDecorationFrequency }
|
|
276
327
|
);
|
|
277
328
|
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* This is a placeholder for individual modules to override.
|
|
332
|
+
* This method will be called whenever the underlying container fully
|
|
333
|
+
* initialized
|
|
334
|
+
*/
|
|
335
|
+
public create(childContainerProvider: ChildContainerProvider): void {
|
|
336
|
+
this.providedContainer = childContainerProvider();
|
|
337
|
+
|
|
338
|
+
this.registerValue({
|
|
339
|
+
ChildContainerProvider: () => this.container.createChildContainer(),
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// register all provided modules when the container is created
|
|
343
|
+
this.registerModules(this.definition.modules);
|
|
344
|
+
}
|
|
278
345
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DependencyContainer, injectable, Lifecycle } from "tsyringe";
|
|
2
2
|
|
|
3
3
|
import { TypedClass } from "../types";
|
|
4
|
+
import { log } from "../log";
|
|
4
5
|
|
|
5
6
|
const errors = {
|
|
6
7
|
descriptorUndefined: () =>
|
|
@@ -56,6 +57,10 @@ export abstract class DependencyFactory {
|
|
|
56
57
|
},
|
|
57
58
|
{ lifecycle: Lifecycle.ContainerScoped }
|
|
58
59
|
);
|
|
60
|
+
|
|
61
|
+
log.debug(
|
|
62
|
+
`Registered dependency ${upperCaseKey} from factory ${this.constructor.name}`
|
|
63
|
+
);
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./config/ModuleContainer";
|
|
2
2
|
export * from "./config/ConfigurableModule";
|
|
3
|
+
export * from "./config/ChildContainerProvider";
|
|
4
|
+
export * from "./config/ChildContainerCreatable";
|
|
3
5
|
export * from "./types";
|
|
4
6
|
export * from "./zkProgrammable/ZkProgrammable";
|
|
5
7
|
export * from "./zkProgrammable/ProvableMethodExecutionContext";
|
package/src/log.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Field, FlexibleProvablePure } from "
|
|
1
|
+
import { Field, FlexibleProvablePure } from "o1js";
|
|
2
2
|
|
|
3
3
|
export function requireTrue(
|
|
4
4
|
condition: boolean,
|
|
@@ -16,7 +16,10 @@ export function range(startOrEnd: number, end: number | undefined): number[] {
|
|
|
16
16
|
end = startOrEnd;
|
|
17
17
|
startOrEnd = 0;
|
|
18
18
|
}
|
|
19
|
-
return Array.from(
|
|
19
|
+
return Array.from(
|
|
20
|
+
{ length: end - startOrEnd },
|
|
21
|
+
(ignored, index) => index + startOrEnd
|
|
22
|
+
);
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
/**
|
|
@@ -35,6 +38,9 @@ export function dummyValue<Value>(
|
|
|
35
38
|
return valueType.fromFields(fields) as Value;
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
42
|
+
export function noop(): void {}
|
|
43
|
+
|
|
38
44
|
export interface ToFieldable {
|
|
39
45
|
toFields: () => Field[];
|
|
40
46
|
}
|
|
@@ -3,7 +3,7 @@ import "reflect-metadata";
|
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
4
4
|
import { jest } from "@jest/globals";
|
|
5
5
|
import { container } from "tsyringe";
|
|
6
|
-
import { Experimental, Field, Struct, Proof } from "
|
|
6
|
+
import { Experimental, Field, Struct, Proof } from "o1js";
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
mockProof,
|