@wocker/core 1.0.22-beta.3 → 1.0.22

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.
@@ -4,6 +4,7 @@ exports.ControllerWrapper = void 0;
4
4
  require("reflect-metadata");
5
5
  const InstanceWrapper_1 = require("./InstanceWrapper");
6
6
  const Route_1 = require("./Route");
7
+ const env_1 = require("../env");
7
8
  class ControllerWrapper extends InstanceWrapper_1.InstanceWrapper {
8
9
  constructor(module, type) {
9
10
  super(module, type);
@@ -12,7 +13,7 @@ class ControllerWrapper extends InstanceWrapper_1.InstanceWrapper {
12
13
  if (!this.type) {
13
14
  return;
14
15
  }
15
- this.description = Reflect.getMetadata("CONTROLLER_DESCRIPTION", this.type) || "";
16
+ this.description = Reflect.getMetadata(env_1.DESCRIPTION_METADATA, this.type) || "";
16
17
  for (const method of Object.getOwnPropertyNames(this.type.prototype)) {
17
18
  const route = new Route_1.Route(this.type, method);
18
19
  if (route.isCommand) {
package/lib/core/Route.js CHANGED
@@ -15,10 +15,10 @@ class Route {
15
15
  if (!descriptor) {
16
16
  return;
17
17
  }
18
- this.description = Reflect.getMetadata(env_1.COMMAND_DESCRIPTION_METADATA, descriptor.value) || "";
18
+ this.description = Reflect.getMetadata(env_1.DESCRIPTION_METADATA, descriptor.value) || "";
19
19
  this.commandNames = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value) || [];
20
20
  this.completions = Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || [];
21
- const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, this.type, this.method) || [], argsAliases = Reflect.getMetadata(env_1.ALIAS_METADATA, this.type, this.method) || {}, argsDescription = Reflect.getMetadata(env_1.ARGS_DESCRIPTION_METADATA, this.type, method) || {}, designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type.prototype, this.method) || [];
21
+ const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, this.type, this.method) || [], argsAliases = Reflect.getMetadata(env_1.ALIAS_METADATA, this.type, this.method) || {}, argsDescription = Reflect.getMetadata(env_1.DESCRIPTION_METADATA, this.type, method) || {}, designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type.prototype, this.method) || [];
22
22
  this.argsMeta = argsMeta;
23
23
  this.designTypes = designTypes;
24
24
  for (let i = 0; i < argsMeta.length; i++) {
@@ -1,6 +1 @@
1
- type Params = {
2
- command?: string;
3
- description?: string;
4
- };
5
- export declare const Controller: (params?: Params) => ClassDecorator;
6
- export {};
1
+ export declare const Controller: () => ClassDecorator;
@@ -1,17 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Controller = void 0;
4
- const Controller = (params) => {
5
- const { command, description } = params || {};
4
+ const Controller = () => {
6
5
  return (target) => {
7
6
  Reflect.defineMetadata("IS_CONTROLLER", true, target);
8
- if (description) {
9
- Reflect.defineMetadata("CONTROLLER_DESCRIPTION", description, target);
10
- }
11
- if (!command) {
12
- return;
13
- }
14
- // TODO:
15
7
  };
16
8
  };
17
9
  exports.Controller = Controller;
@@ -7,7 +7,7 @@ const Description = (description) => {
7
7
  return (target, propertyKey, descriptorOrIndex) => {
8
8
  // Class
9
9
  if (typeof target === "function" && typeof propertyKey === "undefined" && typeof descriptorOrIndex === "undefined") {
10
- Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, target);
10
+ Reflect.defineMetadata(env_1.DESCRIPTION_METADATA, description, target);
11
11
  return;
12
12
  }
13
13
  if (typeof target !== "object" || !propertyKey) {
@@ -15,16 +15,16 @@ const Description = (description) => {
15
15
  }
16
16
  // Property
17
17
  if (typeof descriptorOrIndex === "undefined") {
18
- Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, target, propertyKey);
18
+ Reflect.defineMetadata(env_1.DESCRIPTION_METADATA, description, target, propertyKey);
19
19
  return;
20
20
  }
21
21
  // Method
22
22
  if (typeof descriptorOrIndex !== "number") {
23
- Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, descriptorOrIndex.value);
23
+ Reflect.defineMetadata(env_1.DESCRIPTION_METADATA, description, descriptorOrIndex.value);
24
24
  return;
25
25
  }
26
26
  // Parameter
27
- Reflect.defineMetadata(env_1.ARGS_DESCRIPTION_METADATA, Object.assign(Object.assign({}, Reflect.getMetadata(env_1.ARGS_DESCRIPTION_METADATA, target.constructor, propertyKey) || {}), { [descriptorOrIndex]: description }), target.constructor, propertyKey);
27
+ Reflect.defineMetadata(env_1.DESCRIPTION_METADATA, Object.assign(Object.assign({}, Reflect.getMetadata(env_1.DESCRIPTION_METADATA, target.constructor, propertyKey) || {}), { [descriptorOrIndex]: description }), target.constructor, propertyKey);
28
28
  };
29
29
  };
30
30
  exports.Description = Description;
@@ -1,9 +1,9 @@
1
1
  import { MODULE_METADATA } from "../env";
2
2
  import { Provider } from "../types/Provider";
3
- export type ModuleConfig = {
3
+ export type ModuleMetadata = {
4
4
  [MODULE_METADATA.CONTROLLERS]?: any[];
5
5
  [MODULE_METADATA.PROVIDERS]?: Provider[];
6
6
  [MODULE_METADATA.IMPORTS]?: any[];
7
7
  [MODULE_METADATA.EXPORTS]?: any[];
8
8
  };
9
- export declare const Module: (config: ModuleConfig) => ClassDecorator;
9
+ export declare const Module: (config: ModuleMetadata) => ClassDecorator;
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
2
  import { Option as O } from "@kearisp/cli";
3
3
  type AliasOrParams = string | Partial<Omit<O, "name">>;
4
- export declare const Option: (name: string, params?: AliasOrParams) => ParameterDecorator;
4
+ export declare const Option: (name: string, aliasOrParams?: AliasOrParams) => ParameterDecorator;
5
5
  export {};
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Option = void 0;
4
4
  require("reflect-metadata");
5
5
  const env_1 = require("../env");
6
- const Option = (name, params) => {
6
+ const Option = (name, aliasOrParams) => {
7
7
  return (target, key, index) => {
8
8
  if (!key) {
9
9
  return;
@@ -12,7 +12,7 @@ const Option = (name, params) => {
12
12
  {
13
13
  type: "option",
14
14
  name,
15
- params: typeof params === "string" ? { alias: params } : params,
15
+ params: typeof aliasOrParams === "string" ? { alias: aliasOrParams } : aliasOrParams,
16
16
  index
17
17
  },
18
18
  ...Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, key) || []
@@ -1,2 +1 @@
1
- import "reflect-metadata";
2
1
  export declare const Param: (name: string) => ParameterDecorator;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Param = void 0;
4
- require("reflect-metadata");
5
4
  const env_1 = require("../env");
6
5
  const Param = (name) => {
7
6
  return (target, propertyKey, parameterIndex) => {
@@ -1,6 +1,6 @@
1
- import { ModuleConfig } from "./Module";
1
+ import { ModuleMetadata } from "./Module";
2
2
  import { PLUGIN_NAME_METADATA } from "../env";
3
- type PluginConfig = ModuleConfig & {
3
+ type PluginConfig = ModuleMetadata & {
4
4
  [PLUGIN_NAME_METADATA]: string;
5
5
  };
6
6
  export declare const Plugin: (config: PluginConfig) => ClassDecorator;
@@ -9,3 +9,8 @@ export * from "./Module";
9
9
  export * from "./Option";
10
10
  export * from "./Param";
11
11
  export * from "./Plugin";
12
+ export type {
13
+ /**
14
+ * @deprecated
15
+ */
16
+ ModuleMetadata as ModuleConfig } from "./Module";
package/lib/env.d.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  export declare const IS_GLOBAL_METADATA = "IS_GLOBAL";
2
2
  export declare const IS_MODULE_METADATA = "isModule";
3
3
  export declare const INJECTABLE_WATERMARK = "__injectable__";
4
- export declare const ARGS_META = "__ARGS__";
4
+ export declare const DESCRIPTION_METADATA = "__DESCRIPTION__";
5
5
  export declare const COMMAND_METADATA = "command";
6
- export declare const COMMAND_DESCRIPTION_METADATA = "__COMMAND_DESCRIPTION__";
7
6
  export declare const COMPLETION_METADATA = "completion";
8
7
  export declare const ARGS_METADATA = "__ARGS__";
9
8
  export declare const ALIAS_METADATA = "__ALIAS_METADATA__";
10
- export declare const ARGS_DESCRIPTION_METADATA = "__ARGS_DESCRIPTION__";
11
9
  export declare const OPTION_META = "__OPTION_META__";
12
10
  export declare const PARAMTYPES_METADATA = "design:paramtypes";
13
11
  export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
package/lib/env.js CHANGED
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.PLUGIN_DIR_KEY = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.OPTION_META = exports.ARGS_DESCRIPTION_METADATA = exports.ALIAS_METADATA = exports.ARGS_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_DESCRIPTION_METADATA = exports.COMMAND_METADATA = exports.ARGS_META = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = void 0;
3
+ exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.PLUGIN_DIR_KEY = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.OPTION_META = exports.ALIAS_METADATA = exports.ARGS_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_METADATA = exports.DESCRIPTION_METADATA = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = void 0;
4
4
  exports.IS_GLOBAL_METADATA = "IS_GLOBAL";
5
5
  exports.IS_MODULE_METADATA = "isModule";
6
6
  exports.INJECTABLE_WATERMARK = "__injectable__";
7
- exports.ARGS_META = "__ARGS__";
7
+ exports.DESCRIPTION_METADATA = "__DESCRIPTION__";
8
8
  exports.COMMAND_METADATA = "command";
9
- exports.COMMAND_DESCRIPTION_METADATA = "__COMMAND_DESCRIPTION__";
10
9
  exports.COMPLETION_METADATA = "completion";
11
10
  exports.ARGS_METADATA = "__ARGS__";
12
11
  exports.ALIAS_METADATA = "__ALIAS_METADATA__";
13
- exports.ARGS_DESCRIPTION_METADATA = "__ARGS_DESCRIPTION__";
14
12
  exports.OPTION_META = "__OPTION_META__";
15
13
  exports.PARAMTYPES_METADATA = "design:paramtypes";
16
14
  exports.SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
@@ -1,5 +1,5 @@
1
- import { EnvConfig, PickProperties } from "../types";
2
- import { PresetType } from "./Preset";
1
+ import { EnvConfig } from "../types";
2
+ import { PresetSource } from "./Preset";
3
3
  type ProjectData = {
4
4
  id: string;
5
5
  name?: string;
@@ -13,20 +13,26 @@ type PluginData = {
13
13
  };
14
14
  type PresetData = {
15
15
  name: string;
16
- source: PresetType;
16
+ source: PresetSource;
17
17
  path?: string;
18
18
  };
19
- export type AppConfigProperties = Omit<PickProperties<AppConfig>, "logLevel" | "plugins"> & {
20
- plugins?: (string | PluginData)[];
21
- logLevel?: AppConfig["logLevel"];
19
+ export type AppConfigProperties = {
20
+ debug?: boolean;
21
+ keystore?: string;
22
+ logLevel?: "off" | "info" | "warn" | "error";
23
+ plugins?: PluginData[];
24
+ presets?: PresetData[];
25
+ projects?: ProjectData[];
26
+ meta?: EnvConfig;
27
+ env?: EnvConfig;
22
28
  };
23
29
  export declare abstract class AppConfig {
24
30
  debug?: boolean;
25
31
  keystore?: string;
26
32
  logLevel: "off" | "info" | "warn" | "error";
27
33
  plugins: PluginData[];
28
- presets?: PresetData[];
29
- projects?: ProjectData[];
34
+ presets: PresetData[];
35
+ projects: ProjectData[];
30
36
  meta?: EnvConfig;
31
37
  env?: EnvConfig;
32
38
  protected constructor(data: AppConfigProperties);
@@ -35,7 +41,7 @@ export declare abstract class AppConfig {
35
41
  getProject(id: string): ProjectData | undefined;
36
42
  addProject(id: string, name: string, path: string): void;
37
43
  removeProject(id: string): void;
38
- registerPreset(name: string, source: PresetType, path?: string): void;
44
+ registerPreset(name: string, source: PresetSource, path?: string): void;
39
45
  unregisterPreset(name: string): void;
40
46
  hasMeta(name: string): boolean;
41
47
  getMeta(name: string): string | undefined;
@@ -47,7 +53,11 @@ export declare abstract class AppConfig {
47
53
  setEnv(name: string, value: string): void;
48
54
  unsetEnv(name: string): void;
49
55
  abstract save(): void;
56
+ /**
57
+ * @deprecated
58
+ */
50
59
  toJson(): AppConfigProperties;
60
+ toObject(): AppConfigProperties;
51
61
  toJsString(): string;
52
62
  toString(): string;
53
63
  }
@@ -16,7 +16,7 @@ const Preset_1 = require("./Preset");
16
16
  class AppConfig {
17
17
  constructor(data) {
18
18
  this.logLevel = "off";
19
- const { plugins = [] } = data, rest = __rest(data, ["plugins"]);
19
+ const { plugins = [], presets = [], projects = [] } = data, rest = __rest(data, ["plugins", "presets", "projects"]);
20
20
  Object.assign(this, rest);
21
21
  this.plugins = plugins.map((plugin) => {
22
22
  if (typeof plugin === "string") {
@@ -27,6 +27,8 @@ class AppConfig {
27
27
  }
28
28
  return plugin;
29
29
  });
30
+ this.presets = presets;
31
+ this.projects = projects;
30
32
  }
31
33
  addPlugin(name, env = "latest") {
32
34
  const plugin = this.plugins.find((plugin) => plugin.name === name);
@@ -77,21 +79,21 @@ class AppConfig {
77
79
  projectData.path = path;
78
80
  }
79
81
  removeProject(id) {
80
- if (!this.projects) {
82
+ if (this.projects.length === 0) {
81
83
  return;
82
84
  }
83
85
  this.projects = this.projects.filter((projectData) => {
84
86
  return projectData.id !== id;
85
87
  });
86
- if (this.projects.length === 0) {
87
- delete this.projects;
88
- }
89
88
  }
90
89
  registerPreset(name, source, path) {
91
- if (!this.presets) {
92
- this.presets = [];
90
+ if (source === Preset_1.PRESET_SOURCE_INTERNAL) {
91
+ return;
93
92
  }
94
93
  let presetData = this.presets.find((preset) => {
94
+ if (source === Preset_1.PRESET_SOURCE_EXTERNAL && preset.path === path) {
95
+ return true;
96
+ }
95
97
  return preset.name === name;
96
98
  });
97
99
  if (!presetData) {
@@ -110,15 +112,12 @@ class AppConfig {
110
112
  }
111
113
  }
112
114
  unregisterPreset(name) {
113
- if (!this.presets) {
115
+ if (this.presets.length === 0) {
114
116
  return;
115
117
  }
116
118
  this.presets = this.presets.filter((preset) => {
117
119
  return preset.name !== name;
118
120
  });
119
- if (this.presets.length === 0) {
120
- delete this.presets;
121
- }
122
121
  }
123
122
  hasMeta(name) {
124
123
  if (!this.meta) {
@@ -168,30 +167,30 @@ class AppConfig {
168
167
  delete this.env;
169
168
  }
170
169
  }
170
+ /**
171
+ * @deprecated
172
+ */
171
173
  toJson() {
172
- const json = {
174
+ return this.toObject();
175
+ }
176
+ toObject() {
177
+ return {
173
178
  debug: this.debug,
174
179
  logLevel: this.logLevel,
175
180
  keystore: this.keystore,
176
181
  plugins: this.plugins.length > 0 ? this.plugins : undefined,
177
- projects: this.projects,
178
- presets: this.presets,
182
+ presets: this.presets.length > 0 ? this.presets : undefined,
183
+ projects: this.projects.length > 0 ? this.projects : undefined,
179
184
  env: this.env,
180
185
  meta: this.meta
181
186
  };
182
- return Object.keys(json).reduce((res, key) => {
183
- if (typeof json[key] !== "undefined") {
184
- res[key] = json[key];
185
- }
186
- return res;
187
- }, {});
188
187
  }
189
188
  toJsString() {
190
- const json = JSON.stringify(this.toJson(), null, 4);
189
+ const json = JSON.stringify(this.toObject(), null, 4);
191
190
  return `// Wocker config\nexports.config = ${json};`;
192
191
  }
193
192
  toString() {
194
- return JSON.stringify(this.toJson(), null, 4);
193
+ return JSON.stringify(this.toObject(), null, 4);
195
194
  }
196
195
  }
197
196
  exports.AppConfig = AppConfig;
package/lib/makes/FS.js CHANGED
@@ -48,6 +48,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.FS = void 0;
49
49
  const fs_1 = __importDefault(require("fs"));
50
50
  const Path = __importStar(require("path"));
51
+ /* istanbul ignore next */
51
52
  /**
52
53
  * @deprecated
53
54
  */
@@ -27,7 +27,7 @@ export type PresetVariableConfig = TextOption | ConfirmOption | SelectOption;
27
27
  export type PresetProperties = PickProperties<Preset>;
28
28
  export declare abstract class Preset {
29
29
  name: string;
30
- source?: PresetType;
30
+ source?: PresetSource;
31
31
  version: string;
32
32
  type?: string;
33
33
  image?: string;
@@ -42,12 +42,16 @@ export declare abstract class Preset {
42
42
  volumes?: string[];
43
43
  volumeOptions?: string[];
44
44
  protected constructor(data: PresetProperties);
45
- abstract save(): Promise<void>;
46
- abstract delete(): Promise<void>;
45
+ abstract save(): void;
46
+ abstract delete(): void;
47
+ /**
48
+ * @deprecated
49
+ */
47
50
  toJSON(): PresetProperties;
51
+ toObject(): PresetProperties;
48
52
  }
49
- export declare const PRESET_SOURCE_INTERNAL = "internal";
50
- export declare const PRESET_SOURCE_EXTERNAL = "external";
51
- export declare const PRESET_SOURCE_GITHUB = "github";
52
- export type PresetType = typeof PRESET_SOURCE_INTERNAL | typeof PRESET_SOURCE_EXTERNAL | typeof PRESET_SOURCE_GITHUB;
53
+ export declare const PRESET_SOURCE_INTERNAL: "internal";
54
+ export declare const PRESET_SOURCE_EXTERNAL: "external";
55
+ export declare const PRESET_SOURCE_GITHUB: "github";
56
+ export type PresetSource = typeof PRESET_SOURCE_INTERNAL | typeof PRESET_SOURCE_EXTERNAL | typeof PRESET_SOURCE_GITHUB;
53
57
  export {};
@@ -15,18 +15,21 @@ class Preset {
15
15
  this.volumes = data.volumes;
16
16
  this.volumeOptions = data.volumeOptions;
17
17
  }
18
- // noinspection JSUnusedGlobalSymbols
18
+ /**
19
+ * @deprecated
20
+ */
19
21
  toJSON() {
22
+ return this.toObject();
23
+ }
24
+ toObject() {
20
25
  return {
21
26
  name: this.name,
22
27
  version: this.version,
23
28
  type: this.type,
24
- source: this.source,
25
29
  image: this.image,
26
30
  dockerfile: this.dockerfile,
27
31
  buildArgsOptions: this.buildArgsOptions,
28
32
  envOptions: this.envOptions,
29
- path: this.path,
30
33
  volumes: this.volumes,
31
34
  volumeOptions: this.volumeOptions
32
35
  };
@@ -1,4 +1,4 @@
1
- import { AppConfig } from "../makes";
1
+ import { AppConfig, PresetSource } from "../makes";
2
2
  export declare abstract class AppConfigService {
3
3
  abstract get config(): AppConfig;
4
4
  get version(): string;
@@ -13,5 +13,7 @@ export declare abstract class AppConfigService {
13
13
  getConfig(): AppConfig;
14
14
  addProject(id: string, name: string, path: string): void;
15
15
  removeProject(id: string): void;
16
+ registerPreset(name: string, source: PresetSource, path?: string): void;
17
+ unregisterPreset(name: string): void;
16
18
  save(): void;
17
19
  }
@@ -33,9 +33,19 @@ let AppConfigService = class AppConfigService {
33
33
  }
34
34
  addProject(id, name, path) {
35
35
  this.config.addProject(id, name, path);
36
+ this.config.save();
36
37
  }
37
38
  removeProject(id) {
38
39
  this.config.removeProject(id);
40
+ this.config.save();
41
+ }
42
+ registerPreset(name, source, path) {
43
+ this.config.registerPreset(name, source, path);
44
+ this.save();
45
+ }
46
+ unregisterPreset(name) {
47
+ this.config.unregisterPreset(name);
48
+ this.config.save();
39
49
  }
40
50
  save() {
41
51
  this.config.save();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
- "version": "1.0.22-beta.3",
3
+ "version": "1.0.22",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Core of the Wocker",
6
6
  "license": "MIT",
package/test/index.ts DELETED
@@ -1,6 +0,0 @@
1
- import {jest} from "@jest/globals";
2
- import {vol} from "memfs";
3
-
4
-
5
- jest.mock("fs", () => vol);
6
- jest.mock("fs/promises", () => vol.promises);