mesh-ioc 1.2.1 → 1.3.0

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.
@@ -14,6 +14,7 @@ export declare class Mesh {
14
14
  constant<T>(key: ServiceKey<T>, value: T): this;
15
15
  alias<T>(key: AbstractClass<T> | string, referenceKey: AbstractClass<T> | string): this;
16
16
  resolve<T>(key: ServiceKey<T>): T;
17
+ tryResolve<T>(key: ServiceKey<T>): T | undefined;
17
18
  connect<T>(value: T): T;
18
19
  use(fn: Middleware): this;
19
20
  scope(scopeId: string): Scope;
package/out/main/mesh.js CHANGED
@@ -28,6 +28,14 @@ class Mesh {
28
28
  return this;
29
29
  }
30
30
  resolve(key) {
31
+ const instance = this.tryResolve(key);
32
+ if (instance === undefined) {
33
+ const k = util_1.keyToString(key);
34
+ throw new errors_1.MeshBindingNotFound(this.name, k);
35
+ }
36
+ return instance;
37
+ }
38
+ tryResolve(key) {
31
39
  const k = util_1.keyToString(key);
32
40
  let instance = this.instances.get(k);
33
41
  if (instance) {
@@ -41,9 +49,9 @@ class Mesh {
41
49
  return instance;
42
50
  }
43
51
  if (this.parent) {
44
- return this.parent.resolve(key);
52
+ return this.parent.tryResolve(key);
45
53
  }
46
- throw new errors_1.MeshBindingNotFound(this.name, k);
54
+ return undefined;
47
55
  }
48
56
  connect(value) {
49
57
  const res = this.applyMiddleware(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mesh-ioc",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Mesh: Powerful and Lightweight IoC Library",
5
5
  "main": "out/main/index.js",
6
6
  "types": "out/main/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "test": "NODE_ENV=test mocha",
16
16
  "preversion": "npm run lint",
17
17
  "version": "npm run compile",
18
- "postversion": "npm publish --access=public"
18
+ "postversion": "npm publish --access=public && git push origin main --tags"
19
19
  },
20
20
  "pre-commit": [
21
21
  "lint"