@wocker/core 1.0.17-dev.2 → 1.0.17-dev.3

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.
@@ -9,4 +9,5 @@ export declare class Container {
9
9
  addModule<TInput = any>(type: Type<TInput>, module: Module): void;
10
10
  hasModule<TInput = any>(type: Type<TInput>): boolean;
11
11
  getModule<TInput = any>(type: Type<TInput>): Module<TInput>;
12
+ addProvider(type: Type, wrapper: InstanceWrapper): void;
12
13
  }
@@ -4,6 +4,7 @@ exports.Container = void 0;
4
4
  const cli_1 = require("@kearisp/cli");
5
5
  const InstanceWrapper_1 = require("./InstanceWrapper");
6
6
  const Module_1 = require("./Module");
7
+ const env_1 = require("../env");
7
8
  class Container {
8
9
  constructor() {
9
10
  this.modules = new Map();
@@ -24,5 +25,11 @@ class Container {
24
25
  }
25
26
  return module;
26
27
  }
28
+ addProvider(type, wrapper) {
29
+ const token = typeof type !== "string"
30
+ ? Reflect.getMetadata(env_1.INJECT_TOKEN_METADATA, type) || type
31
+ : type;
32
+ this.providers.set(token, wrapper);
33
+ }
27
34
  }
28
35
  exports.Container = Container;
@@ -5,18 +5,14 @@ import { InstanceWrapper } from "./InstanceWrapper";
5
5
  export declare class Module<TInput = any> {
6
6
  readonly container: Container;
7
7
  type: TInput;
8
- parent?: Module | undefined;
9
8
  imports: Map<any, InstanceWrapper>;
10
9
  controllers: Map<any, InstanceWrapper>;
11
10
  providers: Map<any, InstanceWrapper>;
12
11
  exports: Set<any>;
13
- constructor(container: Container, type: TInput, parent?: Module | undefined);
12
+ constructor(container: Container, type: TInput);
14
13
  get<TInput = any, TResult = TInput>(type: Type<TInput> | Function | string | symbol): TResult;
15
14
  getWrapper(type: any): InstanceWrapper | undefined;
16
- addImport(module: any): void;
17
15
  addProvider(provider: Provider, instance?: any): void;
18
- getProvider(): void;
19
- addInjection(): void;
20
16
  addController(type: any): void;
21
17
  addExport(type: any): void;
22
18
  }
@@ -4,10 +4,9 @@ exports.Module = void 0;
4
4
  const InstanceWrapper_1 = require("./InstanceWrapper");
5
5
  const env_1 = require("../env");
6
6
  class Module {
7
- constructor(container, type, parent) {
7
+ constructor(container, type) {
8
8
  this.container = container;
9
9
  this.type = type;
10
- this.parent = parent;
11
10
  this.imports = new Map();
12
11
  this.controllers = new Map();
13
12
  this.providers = new Map();
@@ -16,6 +15,12 @@ class Module {
16
15
  get(type) {
17
16
  const wrapper = this.getWrapper(type);
18
17
  if (!wrapper) {
18
+ if (typeof type === "function") {
19
+ throw new Error(`Provider "${type.prototype.constructor.name}" not found`);
20
+ }
21
+ else if (typeof type === "string") {
22
+ throw new Error(`Provider "${type}" not found`);
23
+ }
19
24
  throw new Error("Provider not found");
20
25
  }
21
26
  return wrapper.instance;
@@ -25,27 +30,15 @@ class Module {
25
30
  ? Reflect.getMetadata(env_1.INJECT_TOKEN_METADATA, type) || type
26
31
  : type;
27
32
  const wrapper = this.providers.get(token);
28
- if (!wrapper && this.parent) {
29
- return this.parent.getWrapper(type);
30
- }
31
33
  if (!wrapper) {
32
- return this.container.providers.get(type);
34
+ return this.container.providers.get(token);
33
35
  }
34
36
  return wrapper;
35
37
  }
36
- addImport(module) {
37
- // this.imports.add(module);
38
- }
39
38
  addProvider(provider, instance) {
40
39
  const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider, instance);
41
40
  this.providers.set(wrapper.token, wrapper);
42
41
  }
43
- getProvider() {
44
- //
45
- }
46
- addInjection() {
47
- //
48
- }
49
42
  addController(type) {
50
43
  this.controllers.set(type, new InstanceWrapper_1.InstanceWrapper(this, type));
51
44
  for (const name of Object.getOwnPropertyNames(type.prototype)) {
@@ -57,11 +50,13 @@ class Module {
57
50
  if (!command) {
58
51
  continue;
59
52
  }
60
- // console.log(">", name, command);
61
53
  }
62
54
  }
63
55
  addExport(type) {
64
- this.exports.add(type);
56
+ const token = typeof type !== "string"
57
+ ? Reflect.getMetadata(env_1.INJECT_TOKEN_METADATA, type) || type
58
+ : type;
59
+ this.exports.add(token);
65
60
  }
66
61
  }
67
62
  exports.Module = Module;
@@ -7,6 +7,7 @@ export declare abstract class Project {
7
7
  type: string;
8
8
  path: string;
9
9
  preset?: string;
10
+ presetMode?: "global" | "project";
10
11
  imageName?: string;
11
12
  dockerfile?: string;
12
13
  scripts?: string[];
@@ -9,6 +9,7 @@ class Project {
9
9
  this.type = data.type;
10
10
  this.path = data.path;
11
11
  this.preset = data.preset;
12
+ this.presetMode = data.presetMode;
12
13
  this.imageName = data.imageName;
13
14
  this.dockerfile = data.dockerfile;
14
15
  this.scripts = data.scripts;
@@ -177,6 +178,7 @@ class Project {
177
178
  type: this.type,
178
179
  path: this.path,
179
180
  preset: this.preset,
181
+ presetMode: this.presetMode,
180
182
  imageName: this.imageName,
181
183
  dockerfile: this.dockerfile,
182
184
  scripts: this.scripts,
@@ -14,7 +14,6 @@ require("reflect-metadata");
14
14
  const cli_1 = require("@kearisp/cli");
15
15
  const Container_1 = require("./Container");
16
16
  const Module_1 = require("./Module");
17
- const Logger_1 = require("./Logger");
18
17
  const env_1 = require("../env");
19
18
  class Scanner {
20
19
  constructor() {
@@ -74,7 +73,7 @@ class Scanner {
74
73
  if (isGlobal) {
75
74
  const wrapper = module.getWrapper(type);
76
75
  if (wrapper) {
77
- this.container.providers.set(type, wrapper);
76
+ this.container.addProvider(type, wrapper);
78
77
  }
79
78
  }
80
79
  });
@@ -85,10 +84,11 @@ class Scanner {
85
84
  return;
86
85
  }
87
86
  const cli = cliWrapper.instance;
88
- // Logger.unmute();
89
- Logger_1.Logger.info(">_<");
90
87
  for (const [, module] of this.container.modules) {
91
88
  for (const [type, controller] of module.controllers) {
89
+ if (!controller.instance) {
90
+ continue;
91
+ }
92
92
  const controllerCommands = [];
93
93
  const controllerCompletions = [];
94
94
  for (const name of Object.getOwnPropertyNames(type.prototype)) {
@@ -185,6 +185,7 @@ class Scanner {
185
185
  const provider = module.getWrapper(type);
186
186
  if (!provider) {
187
187
  // console.log(type, ">_<", provider);
188
+ return;
188
189
  }
189
190
  // @ts-ignore
190
191
  parentModule.providers.set(type, provider);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
- "version": "1.0.17-dev.2",
3
+ "version": "1.0.17-dev.3",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Core of the Wocker",
6
6
  "license": "MIT",