@wocker/core 1.0.29-beta.0 → 1.0.29-beta.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.
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.Container = void 0;
4
10
  const env_1 = require("../env");
5
- class Container {
11
+ const decorators_1 = require("../decorators");
12
+ let Container = class Container {
6
13
  constructor() {
7
14
  this.modules = new Map();
8
15
  this.moduleExportIndex = new Map();
@@ -52,5 +59,8 @@ class Container {
52
59
  moduleRef.replace(token, provider);
53
60
  });
54
61
  }
55
- }
62
+ };
56
63
  exports.Container = Container;
64
+ exports.Container = Container = __decorate([
65
+ (0, decorators_1.Injectable)("CORE_CONTAINER")
66
+ ], Container);
@@ -15,9 +15,14 @@ const Container_1 = require("./Container");
15
15
  const ModuleWrapper_1 = require("./ModuleWrapper");
16
16
  const CoreModule_1 = require("./CoreModule");
17
17
  const env_1 = require("../env");
18
+ const InstanceWrapper_1 = require("./InstanceWrapper");
18
19
  class Scanner {
19
20
  constructor(container) {
20
21
  this.container = container || new Container_1.Container();
22
+ this.container.globalProviders.set("CORE_CONTAINER", new InstanceWrapper_1.InstanceWrapper(new ModuleWrapper_1.ModuleWrapper(this.container, null), {
23
+ provide: "CORE_CONTAINER",
24
+ useValue: this.container
25
+ }));
21
26
  }
22
27
  scan(moduleDefinition) {
23
28
  return __awaiter(this, void 0, void 0, function* () {
@@ -2,6 +2,7 @@ export * from "./Command";
2
2
  export * from "./Completion";
3
3
  export * from "./Controller";
4
4
  export * from "./Description";
5
+ export * from "./Event";
5
6
  export * from "./Global";
6
7
  export * from "./Inject";
7
8
  export * from "./Injectable";
@@ -18,6 +18,7 @@ __exportStar(require("./Command"), exports);
18
18
  __exportStar(require("./Completion"), exports);
19
19
  __exportStar(require("./Controller"), exports);
20
20
  __exportStar(require("./Description"), exports);
21
+ __exportStar(require("./Event"), exports);
21
22
  __exportStar(require("./Global"), exports);
22
23
  __exportStar(require("./Inject"), exports);
23
24
  __exportStar(require("./Injectable"), exports);
package/lib/env.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const WOCKER_VERSION = "1.0.27";
1
+ export declare const WOCKER_VERSION = "1.0.29";
2
2
  export declare const WOCKER_VERSION_KEY = "__WOCKER_VERSION__";
3
3
  export declare const WOCKER_DATA_DIR: string;
4
4
  export declare const WOCKER_DATA_DIR_KEY = "__WOCKER_DATA_DIR__";
package/lib/env.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.ALIAS_METADATA = exports.ARGS_OLD_METADATA = exports.ARGS_METADATA = exports.LISTENER_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_METADATA = exports.DESCRIPTION_METADATA = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = exports.IS_CONTROLLER_METADATA = exports.PLUGIN_DIR_KEY = exports.FILE_SYSTEM_DRIVER_KEY = exports.WOCKER_DATA_DIR_KEY = exports.WOCKER_DATA_DIR = exports.WOCKER_VERSION_KEY = exports.WOCKER_VERSION = void 0;
7
7
  const os_1 = __importDefault(require("os"));
8
8
  const path_1 = __importDefault(require("path"));
9
- exports.WOCKER_VERSION = "1.0.27";
9
+ exports.WOCKER_VERSION = "1.0.29";
10
10
  exports.WOCKER_VERSION_KEY = "__WOCKER_VERSION__";
11
11
  exports.WOCKER_DATA_DIR = process.env.WS_DIR || path_1.default.join(os_1.default.homedir(), ".workspace");
12
12
  exports.WOCKER_DATA_DIR_KEY = "__WOCKER_DATA_DIR__";
@@ -34,6 +34,7 @@ export declare class FileSystem {
34
34
  readYAML(path: string): any;
35
35
  writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: FS.WriteFileOptions): void;
36
36
  writeJSON(path: string, data: any, options?: FS.WriteFileOptions): void;
37
+ writeYAML(path: string, data: any, options?: FS.WriteFileOptions): void;
37
38
  appendFile(path: string, data: string | Uint8Array, options?: FS.WriteFileOptions): void;
38
39
  rm(path: string, options?: FS.RmOptions): void;
39
40
  mv(src: string, dest: string): void;
@@ -102,6 +102,10 @@ class FileSystem {
102
102
  const json = JSON.stringify(data, null, 4);
103
103
  this.driver.writeFileSync(fullPath, json, options);
104
104
  }
105
+ writeYAML(path, data, options) {
106
+ const fullPath = this.path(path), yaml = yaml_1.default.stringify(data);
107
+ this.driver.writeFileSync(fullPath, yaml, options);
108
+ }
105
109
  appendFile(path, data, options) {
106
110
  const fullPath = this.path(path);
107
111
  this.driver.appendFileSync(fullPath, data, options);
@@ -1,8 +1,13 @@
1
+ import { Container } from "../core/Container";
1
2
  export type EventHandle = (...args: any[]) => Promise<void> | void;
2
3
  export declare class EventService {
4
+ protected readonly container: Container;
5
+ protected scanned: boolean;
3
6
  protected handles: {
4
7
  [event: string]: Set<EventHandle>;
5
8
  };
9
+ constructor(container: Container);
10
+ protected scanListeners(): void;
6
11
  on(event: string, handle: EventHandle): (() => void);
7
12
  off(event: string, handle: EventHandle): void;
8
13
  emit(event: string, ...args: any[]): Promise<void>;
@@ -5,6 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
8
11
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
12
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
13
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -17,10 +20,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
17
20
  Object.defineProperty(exports, "__esModule", { value: true });
18
21
  exports.EventService = void 0;
19
22
  const decorators_1 = require("../decorators");
23
+ // noinspection ES6PreferShortImport
24
+ const Container_1 = require("../core/Container");
25
+ const env_1 = require("../env");
20
26
  let EventService = class EventService {
21
- constructor() {
27
+ constructor(container) {
28
+ this.container = container;
29
+ this.scanned = false;
22
30
  this.handles = {};
23
31
  }
32
+ scanListeners() {
33
+ if (this.scanned) {
34
+ return;
35
+ }
36
+ for (const [, moduleWrapper] of this.container.modules) {
37
+ for (const [, controllerWrapper] of moduleWrapper.controllers) {
38
+ if (!controllerWrapper.instance)
39
+ continue;
40
+ const instance = controllerWrapper.instance;
41
+ const prototype = Object.getPrototypeOf(instance);
42
+ const methodNames = Object.getOwnPropertyNames(prototype).filter(name => typeof prototype[name] === "function" && name !== "constructor");
43
+ for (const methodName of methodNames) {
44
+ const eventNames = Reflect.getMetadata(env_1.LISTENER_METADATA, prototype[methodName]);
45
+ if (eventNames) {
46
+ for (const eventName of eventNames) {
47
+ this.on(eventName, instance[methodName].bind(instance));
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ this.scanned = true;
54
+ }
24
55
  on(event, handle) {
25
56
  if (!this.handles[event]) {
26
57
  this.handles[event] = new Set();
@@ -38,6 +69,7 @@ let EventService = class EventService {
38
69
  }
39
70
  emit(event, ...args) {
40
71
  return __awaiter(this, void 0, void 0, function* () {
72
+ this.scanListeners();
41
73
  if (!this.handles[event]) {
42
74
  return;
43
75
  }
@@ -49,5 +81,6 @@ let EventService = class EventService {
49
81
  };
50
82
  exports.EventService = EventService;
51
83
  exports.EventService = EventService = __decorate([
52
- (0, decorators_1.Injectable)("APP_EVENTS_SERVICE")
84
+ (0, decorators_1.Injectable)("APP_EVENTS_SERVICE"),
85
+ __metadata("design:paramtypes", [Container_1.Container])
53
86
  ], EventService);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
3
  "type": "commonjs",
4
- "version": "1.0.29-beta.0",
4
+ "version": "1.0.29-beta.1",
5
5
  "author": "Kris Papercut <krispcut@gmail.com>",
6
6
  "description": "Core of the Wocker",
7
7
  "license": "MIT",