@wocker/core 1.0.28 → 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* () {
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Controller = void 0;
4
+ const env_1 = require("../env");
4
5
  const Controller = () => {
5
6
  return (target) => {
6
- Reflect.defineMetadata("IS_CONTROLLER", true, target);
7
+ Reflect.defineMetadata(env_1.IS_CONTROLLER_METADATA, true, target);
7
8
  };
8
9
  };
9
10
  exports.Controller = Controller;
@@ -0,0 +1 @@
1
+ export declare const Event: (handle: string) => MethodDecorator;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Event = void 0;
4
+ const env_1 = require("../env");
5
+ const Event = (handle) => {
6
+ return (_target, _key, descriptor) => {
7
+ Reflect.defineMetadata(env_1.LISTENER_METADATA, [
8
+ ...Reflect.getMetadata(env_1.LISTENER_METADATA, descriptor.value) || [],
9
+ handle
10
+ ], descriptor.value);
11
+ };
12
+ };
13
+ exports.Event = Event;
@@ -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,15 +1,17 @@
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__";
5
5
  export declare const FILE_SYSTEM_DRIVER_KEY = "__FILE_SYSTEM_DRIVER_";
6
6
  export declare const PLUGIN_DIR_KEY = "PLUGIN_DIR";
7
+ export declare const IS_CONTROLLER_METADATA = "IS_CONTROLLER";
7
8
  export declare const IS_GLOBAL_METADATA = "IS_GLOBAL";
8
9
  export declare const IS_MODULE_METADATA = "isModule";
9
10
  export declare const INJECTABLE_WATERMARK = "__injectable__";
10
11
  export declare const DESCRIPTION_METADATA = "__DESCRIPTION__";
11
12
  export declare const COMMAND_METADATA = "command";
12
13
  export declare const COMPLETION_METADATA = "completion";
14
+ export declare const LISTENER_METADATA = "__LISTENER_METADATA__";
13
15
  export declare const ARGS_METADATA = "__ARGS_METADATA__";
14
16
  export declare const ARGS_OLD_METADATA = "__ARGS__";
15
17
  export declare const ALIAS_METADATA = "__ALIAS_METADATA__";
package/lib/env.js CHANGED
@@ -3,21 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
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.COMPLETION_METADATA = exports.COMMAND_METADATA = exports.DESCRIPTION_METADATA = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_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;
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__";
13
13
  exports.FILE_SYSTEM_DRIVER_KEY = "__FILE_SYSTEM_DRIVER_";
14
14
  exports.PLUGIN_DIR_KEY = "PLUGIN_DIR";
15
+ exports.IS_CONTROLLER_METADATA = "IS_CONTROLLER";
15
16
  exports.IS_GLOBAL_METADATA = "IS_GLOBAL";
16
17
  exports.IS_MODULE_METADATA = "isModule";
17
18
  exports.INJECTABLE_WATERMARK = "__injectable__";
18
19
  exports.DESCRIPTION_METADATA = "__DESCRIPTION__";
19
20
  exports.COMMAND_METADATA = "command";
20
21
  exports.COMPLETION_METADATA = "completion";
22
+ exports.LISTENER_METADATA = "__LISTENER_METADATA__";
21
23
  exports.ARGS_METADATA = "__ARGS_METADATA__";
22
24
  exports.ARGS_OLD_METADATA = "__ARGS__";
23
25
  exports.ALIAS_METADATA = "__ALIAS_METADATA__";
@@ -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,6 +1,15 @@
1
1
  import type Docker from "dockerode";
2
2
  import type { Container, ImageInfo, VolumeCreateResponse } from "dockerode";
3
3
  import { Duplex } from "node:stream";
4
+ export declare namespace DockerService {
5
+ type ImageLSOptions = {
6
+ tag?: string;
7
+ reference?: string[];
8
+ labels?: {
9
+ [key: string]: string;
10
+ };
11
+ };
12
+ }
4
13
  export declare namespace DockerServiceParams {
5
14
  type CreateContainer = {
6
15
  name: string;
@@ -30,13 +39,8 @@ export declare namespace DockerServiceParams {
30
39
  network?: string;
31
40
  aliases?: string[];
32
41
  };
33
- type ImageList = {
34
- tag?: string;
35
- reference?: string[];
36
- labels?: {
37
- [key: string]: string;
38
- };
39
- };
42
+ /** @deprecated */
43
+ type ImageList = DockerService.ImageLSOptions;
40
44
  type BuildImage = {
41
45
  version?: "1" | "2";
42
46
  tag: string;
@@ -68,8 +72,8 @@ export declare abstract class DockerService {
68
72
  abstract hasVolume(name: string): Promise<boolean>;
69
73
  abstract rmVolume(name: string): Promise<void>;
70
74
  abstract buildImage(params: DockerServiceParams.BuildImage): Promise<any>;
75
+ abstract imageLs(options?: DockerService.ImageLSOptions): Promise<ImageInfo[]>;
71
76
  abstract imageExists(tag: string): Promise<boolean>;
72
- abstract imageLs(options?: DockerServiceParams.ImageList): Promise<ImageInfo[]>;
73
77
  abstract imageRm(tag: string, force?: boolean): Promise<void>;
74
78
  abstract pullImage(tag: string): Promise<void>;
75
79
  abstract attach(name: string | Container): Promise<NodeJS.ReadWriteStream | null | undefined>;
@@ -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.28",
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",