mesh-ioc 1.0.0 → 1.1.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.
@@ -0,0 +1,7 @@
1
+ import 'reflect-metadata';
2
+ import { DepMetadata } from '../types';
3
+ export declare const depMetadata: DepMetadata[];
4
+ export interface DepOptions {
5
+ key?: string;
6
+ }
7
+ export declare function dep(options?: DepOptions): (target: any, propertyName: string) => void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dep = exports.depMetadata = void 0;
4
+ require("reflect-metadata");
5
+ const errors_1 = require("../errors");
6
+ const mesh_1 = require("../mesh");
7
+ exports.depMetadata = [];
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
+ exports.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;
@@ -0,0 +1,7 @@
1
+ import { ServiceMetadata } from '../types';
2
+ export declare const svcMetadata: ServiceMetadata[];
3
+ export interface SvcOptions {
4
+ alias?: string;
5
+ metadata?: any;
6
+ }
7
+ export declare function service(options?: SvcOptions): (target: any) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.service = exports.svcMetadata = void 0;
4
+ exports.svcMetadata = [];
5
+ function service(options = {}) {
6
+ return function (target) {
7
+ exports.svcMetadata.push(Object.assign({ class: target }, options));
8
+ };
9
+ }
10
+ exports.service = service;
@@ -1,6 +1,6 @@
1
- export * from './bindings';
2
- export * from './decorators';
1
+ export * from './decorators/dep';
2
+ export * from './decorators/service';
3
3
  export * from './errors';
4
4
  export * from './mesh';
5
- export * from './metadata';
5
+ export * from './scope';
6
6
  export * from './types';
package/out/main/index.js CHANGED
@@ -10,9 +10,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./bindings"), exports);
14
- __exportStar(require("./decorators"), exports);
13
+ __exportStar(require("./decorators/dep"), exports);
14
+ __exportStar(require("./decorators/service"), exports);
15
15
  __exportStar(require("./errors"), exports);
16
16
  __exportStar(require("./mesh"), exports);
17
- __exportStar(require("./metadata"), exports);
17
+ __exportStar(require("./scope"), exports);
18
18
  __exportStar(require("./types"), exports);
@@ -1,6 +1,5 @@
1
- import { Binding } from './bindings';
2
1
  import { Scope } from './scope';
3
- import { AbstractClass, Middleware, ServiceConstructor, ServiceKey } from './types';
2
+ import { AbstractClass, Binding, Middleware, ServiceConstructor, ServiceKey } from './types';
4
3
  export declare const MESH_REF: unique symbol;
5
4
  export declare class Mesh {
6
5
  name: string;
@@ -1,6 +1,4 @@
1
- import { Binding } from './bindings';
2
- import { AbstractClass, ServiceConstructor, ServiceKey } from './types';
3
- export declare const MESH_REF: unique symbol;
1
+ import { AbstractClass, Binding, ServiceConstructor, ServiceKey } from './types';
4
2
  export declare class Scope {
5
3
  readonly name: string;
6
4
  bindings: Map<string, Binding<any>>;
package/out/main/scope.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Scope = exports.MESH_REF = void 0;
3
+ exports.Scope = void 0;
4
4
  const errors_1 = require("./errors");
5
5
  const util_1 = require("./util");
6
- exports.MESH_REF = Symbol.for('MESH_REF');
7
6
  class Scope {
8
7
  constructor(name, bindings = []) {
9
8
  this.name = name;
@@ -10,3 +10,27 @@ export declare type AbstractClass<T> = {
10
10
  };
11
11
  export declare type ServiceKey<T> = ServiceConstructor<T> | AbstractClass<T> | string;
12
12
  export declare type Middleware = (instance: any) => any;
13
+ export declare type Binding<T> = ConstantBinding<T> | ServiceBinding<T> | AliasBinding;
14
+ export declare type ConstantBinding<T> = {
15
+ type: 'constant';
16
+ value: T;
17
+ };
18
+ export declare type ServiceBinding<T> = {
19
+ type: 'service';
20
+ class: ServiceConstructor<T>;
21
+ };
22
+ export declare type AliasBinding = {
23
+ type: 'alias';
24
+ key: string;
25
+ };
26
+ export interface DepMetadata {
27
+ className: string;
28
+ propertyName: string;
29
+ designTypeName: string;
30
+ key: string;
31
+ }
32
+ export interface ServiceMetadata {
33
+ class: ServiceConstructor<any>;
34
+ alias?: string;
35
+ metadata?: any;
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mesh-ioc",
3
- "version": "1.0.0",
3
+ "version": "1.1.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",