mesh-ioc 1.1.0 → 1.2.1

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/README.md CHANGED
@@ -6,7 +6,7 @@ Mesh IoC solves the problem of dependency management of application services. It
6
6
 
7
7
  ## Key features
8
8
 
9
- - 👗 Very slim — about 4KB minified, even less gzipped
9
+ - 👗 Very slim — about 2KB minified, few hundred bytes gzipped
10
10
  - ⚡️ Blazing fast
11
11
  - 🧩 Flexible and composable
12
12
  - 🌿 Ergonomic
@@ -1,5 +1,5 @@
1
1
  import { ServiceMetadata } from '../types';
2
- export declare const svcMetadata: ServiceMetadata[];
2
+ export declare const serviceMetadata: ServiceMetadata[];
3
3
  export interface SvcOptions {
4
4
  alias?: string;
5
5
  metadata?: any;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.service = exports.svcMetadata = void 0;
4
- exports.svcMetadata = [];
3
+ exports.service = exports.serviceMetadata = void 0;
4
+ exports.serviceMetadata = [];
5
5
  function service(options = {}) {
6
6
  return function (target) {
7
- exports.svcMetadata.push(Object.assign({ class: target }, options));
7
+ exports.serviceMetadata.push(Object.assign({ class: target }, options));
8
8
  };
9
9
  }
10
10
  exports.service = service;
@@ -1,5 +1,4 @@
1
1
  export * from './decorators/dep';
2
- export * from './decorators/service';
3
2
  export * from './errors';
4
3
  export * from './mesh';
5
4
  export * from './scope';
package/out/main/index.js CHANGED
@@ -11,7 +11,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./decorators/dep"), exports);
14
- __exportStar(require("./decorators/service"), exports);
15
14
  __exportStar(require("./errors"), exports);
16
15
  __exportStar(require("./mesh"), exports);
17
16
  __exportStar(require("./scope"), exports);
@@ -8,7 +8,7 @@ export declare class Mesh {
8
8
  childScopes: Map<string, Scope>;
9
9
  instances: Map<string, any>;
10
10
  middlewares: Middleware[];
11
- constructor(name?: string, parent?: Mesh | undefined);
11
+ constructor(name?: string, parent?: Mesh | undefined, scope?: Scope);
12
12
  service<T>(impl: ServiceConstructor<T>): this;
13
13
  service<T>(key: AbstractClass<T> | string, impl: ServiceConstructor<T>): this;
14
14
  constant<T>(key: ServiceKey<T>, value: T): this;
package/out/main/mesh.js CHANGED
@@ -6,13 +6,13 @@ const scope_1 = require("./scope");
6
6
  const util_1 = require("./util");
7
7
  exports.MESH_REF = Symbol.for('MESH_REF');
8
8
  class Mesh {
9
- constructor(name = 'default', parent = undefined) {
9
+ constructor(name = 'default', parent = undefined, scope) {
10
10
  this.name = name;
11
11
  this.parent = parent;
12
12
  this.childScopes = new Map();
13
13
  this.instances = new Map();
14
14
  this.middlewares = [];
15
- this.currentScope = new scope_1.Scope(name);
15
+ this.currentScope = scope !== null && scope !== void 0 ? scope : new scope_1.Scope(name);
16
16
  this.currentScope.constant('Mesh', this);
17
17
  }
18
18
  service(key, impl) {
@@ -65,8 +65,7 @@ class Mesh {
65
65
  createScope(scopeId, scopeName = scopeId) {
66
66
  const childScope = this.childScopes.get(scopeId);
67
67
  const newScope = new scope_1.Scope(scopeName, childScope !== null && childScope !== void 0 ? childScope : []);
68
- const mesh = new Mesh(scopeId, this);
69
- mesh.currentScope = newScope;
68
+ const mesh = new Mesh(scopeId, this, newScope);
70
69
  return mesh;
71
70
  }
72
71
  instantiate(binding) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mesh-ioc",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Mesh: Powerful and Lightweight IoC Library",
5
5
  "main": "out/main/index.js",
6
6
  "types": "out/main/index.d.ts",
@@ -1,14 +0,0 @@
1
- import { ServiceConstructor } from './types';
2
- export declare type Binding<T> = ConstantBinding<T> | ServiceBinding<T> | AliasBinding;
3
- export declare type ConstantBinding<T> = {
4
- type: 'constant';
5
- value: T;
6
- };
7
- export declare type ServiceBinding<T> = {
8
- type: 'service';
9
- class: ServiceConstructor<T>;
10
- };
11
- export declare type AliasBinding = {
12
- type: 'alias';
13
- key: string;
14
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- import 'reflect-metadata';
2
- export declare function dep(options?: DepOptions): (target: any, propertyName: string) => void;
3
- export interface DepOptions {
4
- key?: string;
5
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dep = void 0;
4
- require("reflect-metadata");
5
- const errors_1 = require("./errors");
6
- const mesh_1 = require("./mesh");
7
- const metadata_1 = require("./metadata");
8
- function dep(options = {}) {
9
- return function (target, propertyName) {
10
- var _a;
11
- const className = target.constructor.name;
12
- const designType = Reflect.getMetadata('design:type', target, propertyName);
13
- const key = (_a = options.key) !== null && _a !== void 0 ? _a : designType === null || designType === void 0 ? void 0 : designType.name;
14
- if (!key) {
15
- throw new errors_1.DepKeyNotInferred(className, propertyName);
16
- }
17
- metadata_1.depMetadata.push({
18
- className,
19
- propertyName,
20
- designTypeName: designType.name,
21
- key,
22
- });
23
- Object.defineProperty(target, propertyName, {
24
- get() {
25
- const mesh = this[mesh_1.MESH_REF];
26
- if (!mesh) {
27
- throw new errors_1.DepInstanceNotConnected(className, propertyName);
28
- }
29
- return mesh.resolve(key);
30
- }
31
- });
32
- };
33
- }
34
- exports.dep = dep;
@@ -1,7 +0,0 @@
1
- export declare const depMetadata: DepMetadata[];
2
- export interface DepMetadata {
3
- className: string;
4
- propertyName: string;
5
- designTypeName: string;
6
- key: string;
7
- }
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.depMetadata = void 0;
4
- exports.depMetadata = [];