miqro 3.0.1 → 4.0.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.
package/build/cli.js CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const cmd_map_1 = require("./cmd-map");
5
- const utils_1 = require("./utils");
6
- (0, utils_1.mainCMD)(cmd_map_1.CMDS, cmd_map_1.usage, console);
2
+ import { CMD_MAP, usage } from "./cmd-map.js";
3
+ import { mainCMD } from "./utils/index.js";
4
+ mainCMD(CMD_MAP, usage, console);
@@ -1,6 +1,6 @@
1
- import { main as help } from "./cmds/help";
1
+ import { main as help } from "./cmds/help.js";
2
2
  export declare const usage = "npx miqro <command> [args]";
3
- export declare const CMDS: {
3
+ export declare const CMD_MAP: {
4
4
  "new:api": {
5
5
  cb: () => void;
6
6
  tabs: number;
package/build/cmd-map.js CHANGED
@@ -1,60 +1,57 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CMDS = exports.usage = void 0;
4
- const start_1 = require("./cmds/start");
5
- const watch_1 = require("./cmds/watch");
6
- const new_1 = require("./cmds/new");
7
- const doc_json_1 = require("./cmds/doc-json");
8
- const doc_md_1 = require("./cmds/doc-md");
9
- const config_init_1 = require("./cmds/config-init");
10
- const config_1 = require("./cmds/config");
11
- const config_bash_1 = require("./cmds/config-bash");
12
- const config_env_1 = require("./cmds/config-env");
13
- const handler_apiroute_new_1 = require("./cmds/handler-apiroute-new");
14
- const new_test_1 = require("./cmds/new-test");
15
- const serve_1 = require("./cmds/serve");
16
- const help_1 = require("./cmds/help");
17
- const handler_main_new_1 = require("./cmds/handler-main-new");
18
- exports.usage = "npx miqro <command> [args]";
19
- exports.CMDS = {
1
+ import { main as start } from "./cmds/start.js";
2
+ import { main as watch } from "./cmds/watch.js";
3
+ import { mainTS as newTS } from "./cmds/new.js";
4
+ import { main as apiDocJSON } from "./cmds/doc-json.js";
5
+ import { main as apiDocMD } from "./cmds/doc-md.js";
6
+ import { main as configInit } from "./cmds/config-init.js";
7
+ import { main as config } from "./cmds/config.js";
8
+ import { main as configBash } from "./cmds/config-bash.js";
9
+ import { main as configEnv } from "./cmds/config-env.js";
10
+ import { main as newRoute } from "./cmds/handler-apiroute-new.js";
11
+ import { main as newTest } from "./cmds/new-test.js";
12
+ import { main as serve } from "./cmds/serve.js";
13
+ import { main as help } from "./cmds/help.js";
14
+ import { main as newMain } from "./cmds/handler-main-new.js";
15
+ export const usage = "npx miqro <command> [args]";
16
+ export const CMD_MAP = {
20
17
  ["new:api"]: {
21
18
  //section: "api development",
22
- cb: new_1.mainTS, tabs: 4, description: `create a new project.`
19
+ cb: newTS, tabs: 4, description: `create a new project.`
23
20
  },
24
21
  //["new:typescript"]: {cb: newTS, tabs: 4, description: `create a new typescript project.`},
25
22
  ["new:api:main"]: {
26
- //section: "http scafolding",
27
- cb: handler_main_new_1.main,
23
+ //section: "http scaffolding",
24
+ cb: newMain,
28
25
  tabs: 3,
29
26
  description: `creates a new main file.`
30
27
  },
31
- ["new:api:route"]: { cb: handler_apiroute_new_1.main, tabs: 3, description: `creates a new route.` },
32
- ["new:api:route:test"]: { cb: new_test_1.main, tabs: 2, description: `create new test.js file for an apirouter.` },
28
+ ["new:api:route"]: { cb: newRoute, tabs: 3, description: `creates a new route.` },
29
+ ["new:api:route:test"]: { cb: newTest, tabs: 2, description: `create new test.js file for an APIRouter.` },
33
30
  ["config"]: {
34
- //section: "config managment",
35
- cb: config_1.main,
31
+ //section: "config management",
32
+ cb: config,
36
33
  tabs: 4,
37
34
  description: `print config as a json.`
38
35
  },
39
36
  ["config:bash"]: {
40
- cb: config_bash_1.main,
37
+ cb: configBash,
41
38
  tabs: 3,
42
39
  description: `print config as a bash script.`
43
40
  },
44
41
  ["config:env"]: {
45
- cb: config_env_1.main,
42
+ cb: configEnv,
46
43
  tabs: 3,
47
44
  description: `print config as a env file.`
48
45
  },
49
- ["config:init"]: { cb: config_init_1.main, tabs: 3, description: `inits your config folder.` },
46
+ ["config:init"]: { cb: configInit, tabs: 3, description: `inits your config folder.` },
50
47
  ["doc"]: {
51
48
  //section: "api documentation",
52
49
  tabs: 4,
53
- cb: doc_json_1.main,
50
+ cb: apiDocJSON,
54
51
  description: `api folder auto doc as a json.`
55
52
  },
56
53
  ["doc:md"]: {
57
- cb: doc_md_1.main,
54
+ cb: apiDocMD,
58
55
  tabs: 4,
59
56
  description: `api folder auto doc as a markdown.`
60
57
  },
@@ -67,28 +64,28 @@ exports.CMDS = {
67
64
  ["start"]: {
68
65
  //section: "start helpers",
69
66
  tabs: 4,
70
- cb: start_1.main,
67
+ cb: start,
71
68
  description: `start script in cluster mode.`
72
69
  },
73
70
  ["cluster"]: {
74
71
  tabs: 4,
75
- cb: start_1.main,
72
+ cb: start,
76
73
  description: `alias for start command.`
77
74
  },
78
75
  ["watch"]: {
79
76
  //section: "watch",
80
- cb: watch_1.main,
77
+ cb: watch,
81
78
  tabs: 4,
82
79
  description: `watch folder for changes.`
83
80
  },
84
81
  ["serve"]: {
85
82
  //section: "serve static files",
86
83
  tabs: 4,
87
- cb: serve_1.main, description: `serve static files.`
84
+ cb: serve, description: `serve static files.`
88
85
  },
89
86
  ["help"]: {
90
87
  //section: "help",
91
- cb: help_1.main,
88
+ cb: help,
92
89
  tabs: 4, description: "prints this page"
93
90
  }
94
91
  };
@@ -1,18 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- exports.usage = "usage: [NODE_ENV=development] npx miqro config:bash";
6
- const main = () => {
1
+ import { loadConfig } from "@miqro/core";
2
+ export const usage = "usage: [NODE_ENV=development] npx miqro config:bash";
3
+ export const main = () => {
7
4
  const logger = console;
8
5
  if (process.argv.length !== 3) {
9
- throw new Error(`invalid number of args. ${exports.usage}`);
6
+ throw new Error(`invalid number of args. ${usage}`);
10
7
  }
11
- const configOut = (0, core_1.loadConfig)();
8
+ const configOut = loadConfig();
12
9
  const config = configOut.combined;
13
10
  const keys = Object.keys(config);
14
11
  for (const key of keys) {
15
12
  logger.info(`export ${key}=${config[key]}`);
16
13
  }
17
14
  };
18
- exports.main = main;
@@ -1,18 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- exports.usage = "usage: [NODE_ENV=development] npx miqro config:env";
6
- const main = () => {
1
+ import { loadConfig } from "@miqro/core";
2
+ export const usage = "usage: [NODE_ENV=development] npx miqro config:env";
3
+ export const main = () => {
7
4
  const logger = console;
8
5
  if (process.argv.length !== 3) {
9
- throw new Error(`invalid number of args. ${exports.usage}`);
6
+ throw new Error(`invalid number of args. ${usage}`);
10
7
  }
11
- const configOut = (0, core_1.loadConfig)();
8
+ const configOut = loadConfig();
12
9
  const config = configOut.combined;
13
10
  const keys = Object.keys(config);
14
11
  for (const key of keys) {
15
12
  logger.info(`${key}=${config[key]}`);
16
13
  }
17
14
  };
18
- exports.main = main;
@@ -1,35 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const core_1 = require("@miqro/core");
7
- const templates_1 = require("../utils/templates");
8
- exports.usage = "usage: [NODE_ENV=development] npx miqro config:init";
9
- const main = () => {
1
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
2
+ import { resolve } from "path";
3
+ import { ConfigPathResolver, loadConfig } from "@miqro/core";
4
+ import { templates } from "../utils/templates.js";
5
+ export const usage = "usage: [NODE_ENV=development] npx miqro config:init";
6
+ export const main = () => {
10
7
  const logger = console;
11
8
  if (process.argv.length !== 3) {
12
- throw new Error(`invalid number of args. ${exports.usage}`);
9
+ throw new Error(`invalid number of args. ${usage}`);
13
10
  }
14
- (0, core_1.loadConfig)();
15
- const configPath = core_1.ConfigPathResolver.getConfigDirname();
11
+ loadConfig();
12
+ const configPath = ConfigPathResolver.getConfigDirname();
16
13
  const initEnvFile = (path, template) => {
17
- if (!(0, fs_1.existsSync)(path)) {
14
+ if (!existsSync(path)) {
18
15
  logger.warn(`creating ${path} env file`);
19
- (0, fs_1.writeFileSync)(path, template);
16
+ writeFileSync(path, template);
20
17
  }
21
18
  else {
22
19
  logger.warn(`${path} already exists!. init will not create it.`);
23
20
  }
24
21
  };
25
- if (!(0, fs_1.existsSync)(configPath)) {
22
+ if (!existsSync(configPath)) {
26
23
  logger.warn(`[${configPath}] doesnt exists!`);
27
- (0, fs_1.mkdirSync)(configPath, {
24
+ mkdirSync(configPath, {
28
25
  recursive: true
29
26
  });
30
27
  }
31
- initEnvFile((0, path_1.resolve)(configPath, `log.env`), templates_1.templates.logEnvFile);
32
- initEnvFile((0, path_1.resolve)(configPath, `auth.env`), templates_1.templates.authEnvFile);
33
- initEnvFile((0, path_1.resolve)(configPath, `features.env`), templates_1.templates.featuresEnvFile);
28
+ initEnvFile(resolve(configPath, `log.env`), templates.logEnvFile);
29
+ initEnvFile(resolve(configPath, `auth.env`), templates.authEnvFile);
30
+ initEnvFile(resolve(configPath, `features.env`), templates.featuresEnvFile);
34
31
  };
35
- exports.main = main;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- exports.usage = "usage: [NODE_ENV=development] npx miqro config";
6
- const main = () => {
1
+ import { loadConfig } from "@miqro/core";
2
+ export const usage = "usage: [NODE_ENV=development] npx miqro config";
3
+ export const main = () => {
7
4
  const logger = console;
8
5
  if (process.argv.length !== 3) {
9
- throw new Error(`invalid number of args. ${exports.usage}`);
6
+ throw new Error(`invalid number of args. ${usage}`);
10
7
  }
11
- const configOut = (0, core_1.loadConfig)();
8
+ const configOut = loadConfig();
12
9
  const config = configOut.combined;
13
10
  logger.info(JSON.stringify(config, undefined, 2));
14
11
  };
15
- exports.main = main;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- const json_1 = require("../utils/doc/json");
6
- exports.usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath> [apiName]`;
7
- const main = async () => {
1
+ import { loadConfig } from "@miqro/core";
2
+ import { getDOCJSON } from "../utils/doc/json.js";
3
+ export const usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath> [apiName]`;
4
+ export const main = async () => {
8
5
  if (process.argv.length < 5 || process.argv.length > 6) {
9
- throw new Error(exports.usage);
6
+ throw new Error(usage);
10
7
  }
11
8
  const dirname = process.argv[3];
12
9
  const subPath = process.argv[4];
13
10
  const apiName = process.argv[5];
14
- (0, core_1.loadConfig)();
15
- console.log(JSON.stringify(await (0, json_1.getDOCJSON)({ dirname, subPath, apiName }), undefined, 2));
11
+ loadConfig();
12
+ console.log(JSON.stringify(await getDOCJSON({ dirname, subPath, apiName }), undefined, 2));
16
13
  };
17
- exports.main = main;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- const md_1 = require("../utils/doc/md");
6
- exports.usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath> [apiName]`;
7
- const main = async () => {
1
+ import { loadConfig } from "@miqro/core";
2
+ import { getMDDoc } from "../utils/doc/md.js";
3
+ export const usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath> [apiName]`;
4
+ export const main = async () => {
8
5
  if (process.argv.length < 5 || process.argv.length > 6) {
9
- throw new Error(exports.usage);
6
+ throw new Error(usage);
10
7
  }
11
8
  const dirname = process.argv[3];
12
9
  const subPath = process.argv[4];
13
10
  const apiName = process.argv[5];
14
- (0, core_1.loadConfig)();
15
- console.log(await (0, md_1.getMDDoc)({ dirname, subPath, apiName }));
11
+ loadConfig();
12
+ console.log(await getMDDoc({ dirname, subPath, apiName }));
16
13
  };
17
- exports.main = main;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
1
+ import { ConfigPathResolver, loadConfig } from "@miqro/core";
2
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
3
+ import { resolve } from "path";
7
4
  const templates = {
8
5
  ts: (noMethod = false) => noMethod ? `import { APIRoute } from "@miqro/core";
9
6
 
@@ -42,29 +39,28 @@ export default {
42
39
  };
43
40
  `
44
41
  };
45
- exports.usage = `usage: [NODE_ENV=development] npx miqro new:api:route <identifier ex: SRC_API_V1_HEALTH>`;
46
- const main = () => {
42
+ export const usage = `usage: [NODE_ENV=development] npx miqro new:api:route <identifier ex: SRC_API_V1_HEALTH>`;
43
+ export const main = () => {
47
44
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
48
- throw new Error(exports.usage);
45
+ throw new Error(usage);
49
46
  }
50
47
  const identifier = process.argv[3].toLocaleLowerCase();
51
48
  const split = identifier.split("_").map(s => s.trim()).filter(s => s);
52
49
  const dots = split.filter(s => s.indexOf(".") !== -1);
53
50
  if (dots.length > 0) {
54
- throw new Error(`identifier cannot contain dots\n${exports.usage}`);
51
+ throw new Error(`identifier cannot contain dots\n${usage}`);
55
52
  }
56
- (0, core_1.loadConfig)();
57
- const path = (0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
58
- const ext = (0, fs_1.existsSync)((0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
53
+ loadConfig();
54
+ const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
55
+ const ext = existsSync(resolve(ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
59
56
  const noMethod = ["post", "get", "put", "delete", "patch", "options"].indexOf(split[0].toLocaleLowerCase()) === -1;
60
- const filePath = (0, path_1.resolve)(path, `${split[0]}.${ext}`);
61
- if ((0, fs_1.existsSync)(filePath)) {
57
+ const filePath = resolve(path, `${split[0]}.${ext}`);
58
+ if (existsSync(filePath)) {
62
59
  throw new Error(`file ${filePath} already exists! doing nothing`);
63
60
  }
64
61
  console.log(`creating ${filePath}`);
65
- (0, fs_1.mkdirSync)(path, {
62
+ mkdirSync(path, {
66
63
  recursive: true
67
64
  });
68
- (0, fs_1.writeFileSync)(filePath, templates[ext](noMethod));
65
+ writeFileSync(filePath, templates[ext](noMethod));
69
66
  };
70
- exports.main = main;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
1
+ import { ConfigPathResolver, loadConfig } from "@miqro/core";
2
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
3
+ import { resolve } from "path";
7
4
  const mainTemplates = {
8
5
  ts: () => `import { APIRouter, Server, checkEnvVariables, getLogger, middleware } from "@miqro/core";
9
6
  import { resolve } from "path";
@@ -56,10 +53,10 @@ async function main() {
56
53
  main().catch(e => logger.error(e));
57
54
  `
58
55
  };
59
- exports.usage = `usage: [NODE_ENV=development] npx miqro new:api:main <identifier ex: NEW_APP>`;
60
- const main = () => {
56
+ export const usage = `usage: [NODE_ENV=development] npx miqro new:api:main <identifier ex: NEW_APP>`;
57
+ export const main = () => {
61
58
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
62
- throw new Error(exports.usage);
59
+ throw new Error(usage);
63
60
  }
64
61
  const identifier = process.argv[3].toLocaleLowerCase();
65
62
  const split = identifier.split("_");
@@ -67,18 +64,17 @@ const main = () => {
67
64
  if (dots.length > 0) {
68
65
  throw new Error(`identifier cannot contain dots\narguments: <identifier ex: SRC_MAIN>`);
69
66
  }
70
- (0, core_1.loadConfig)();
71
- const path = (0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
72
- const ext = (0, fs_1.existsSync)((0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
73
- const filePath = (0, path_1.resolve)(path, `${split[0]}.${ext}`);
74
- if ((0, fs_1.existsSync)(filePath)) {
67
+ loadConfig();
68
+ const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
69
+ const ext = existsSync(resolve(ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
70
+ const filePath = resolve(path, `${split[0]}.${ext}`);
71
+ if (existsSync(filePath)) {
75
72
  throw new Error(`file ${filePath} already exists! doing nothing`);
76
73
  }
77
74
  console.log(`creating ${filePath}`);
78
- (0, fs_1.mkdirSync)(path, {
75
+ mkdirSync(path, {
79
76
  recursive: true
80
77
  });
81
- (0, fs_1.writeFileSync)(filePath, mainTemplates[ext]());
78
+ writeFileSync(filePath, mainTemplates[ext]());
82
79
  console.log(`file ${filePath} created`);
83
80
  };
84
- exports.main = main;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
4
- const cmd_map_1 = require("../cmd-map");
5
- const utils_1 = require("../utils");
6
- function main() {
7
- console.log((0, utils_1.getUsage)(cmd_map_1.CMDS, cmd_map_1.usage));
1
+ import { CMD_MAP, usage } from "../cmd-map.js";
2
+ import { getUsage } from "../utils/index.js";
3
+ export function main() {
4
+ console.log(getUsage(CMD_MAP, usage));
8
5
  }
9
- exports.main = main;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- exports.usage = `usage: [NODE_ENV=development] npx miqro new:test <identifier ex: TEST_SOMEFILE>`;
1
+ import { ConfigPathResolver, loadConfig } from "@miqro/core";
2
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
3
+ import { resolve } from "path";
4
+ export const usage = `usage: [NODE_ENV=development] npx miqro new:test <identifier ex: TEST_SOMEFILE>`;
8
5
  const testTemplates = {
9
6
  js: (category) => `import { it } from "node:test";
10
7
  import { TestHelper } from "@miqro/test-http";
@@ -22,9 +19,9 @@ it("happy path health", async () => {
22
19
  });
23
20
  `
24
21
  };
25
- const main = () => {
22
+ export const main = () => {
26
23
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
27
- throw new Error(exports.usage);
24
+ throw new Error(usage);
28
25
  }
29
26
  const identifier = process.argv[3].toLocaleLowerCase();
30
27
  const split = identifier.split("_");
@@ -32,17 +29,16 @@ const main = () => {
32
29
  if (dots.length > 0) {
33
30
  throw new Error(`identifier cannot contain dots\narguments: <identifier ex: TEST_SOMETEST>`);
34
31
  }
35
- (0, core_1.loadConfig)();
36
- const path = (0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
37
- const filePath = (0, path_1.resolve)(path, `${split[0]}.test.js`);
38
- if ((0, fs_1.existsSync)(filePath)) {
32
+ loadConfig();
33
+ const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
34
+ const filePath = resolve(path, `${split[0]}.test.js`);
35
+ if (existsSync(filePath)) {
39
36
  throw new Error(`file ${filePath} already exists! doing nothing`);
40
37
  }
41
38
  console.log(`creating ${filePath}`);
42
- (0, fs_1.mkdirSync)(path, {
39
+ mkdirSync(path, {
43
40
  recursive: true
44
41
  });
45
- (0, fs_1.writeFileSync)(filePath, testTemplates.js(split[0]));
42
+ writeFileSync(filePath, testTemplates.js(split[0]));
46
43
  console.log(`file ${filePath} created`);
47
44
  };
48
- exports.main = main;
package/build/cmds/new.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mainTS = exports.usageTS = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const utils_1 = require("../utils");
1
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
2
+ import { resolve } from "path";
3
+ import { execSync } from "../utils/index.js";
7
4
  const gitignoreTemplate = {
8
5
  ts: () => `node_modules/
9
6
  dist/
@@ -52,28 +49,28 @@ const packageTemplate = {
52
49
  "author": ""
53
50
  }`
54
51
  };
55
- exports.usageTS = `usage: npx miqro new:api <identifier ex: NEW_APP>`;
56
- const mainTS = () => {
52
+ export const usageTS = `usage: npx miqro new:api <identifier ex: NEW_APP>`;
53
+ export const mainTS = () => {
57
54
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
58
- throw new Error(exports.usageTS);
55
+ throw new Error(usageTS);
59
56
  }
60
57
  const identifier = process.argv[3].toLocaleLowerCase();
61
- const appFolder = (0, path_1.resolve)(process.cwd(), identifier);
62
- if ((0, fs_1.existsSync)(appFolder)) {
58
+ const appFolder = resolve(process.cwd(), identifier);
59
+ if (existsSync(appFolder)) {
63
60
  throw new Error(`${appFolder} already exists!`);
64
61
  }
65
62
  console.log(`creating ${appFolder}`);
66
- (0, fs_1.mkdirSync)(appFolder, {
63
+ mkdirSync(appFolder, {
67
64
  recursive: true
68
65
  });
69
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, "package.json"), packageTemplate["ts"](identifier));
70
- (0, utils_1.execSync)(`npm install miqro --save-dev`, {
66
+ writeFileSync(resolve(appFolder, "package.json"), packageTemplate["ts"](identifier));
67
+ execSync(`npm install miqro --save-dev`, {
71
68
  cwd: appFolder
72
69
  });
73
- (0, utils_1.execSync)(`npm install @miqro/core --save`, {
70
+ execSync(`npm install @miqro/core --save`, {
74
71
  cwd: appFolder
75
72
  });
76
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, "tsconfig.json"), `{
73
+ writeFileSync(resolve(appFolder, "tsconfig.json"), `{
77
74
  "compileOnSave": true,
78
75
  "compilerOptions": {
79
76
  "lib": ["es2021"],
@@ -97,26 +94,26 @@ const mainTS = () => {
97
94
  "src"
98
95
  ]
99
96
  }`);
100
- (0, utils_1.execSync)(`npm install typescript --save-dev`, {
97
+ execSync(`npm install typescript --save-dev`, {
101
98
  cwd: appFolder
102
99
  });
103
- (0, utils_1.execSync)(`npm install @types/node --save-dev`, {
100
+ execSync(`npm install @types/node --save-dev`, {
104
101
  cwd: appFolder
105
102
  });
106
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, ".gitignore"), gitignoreTemplate.ts());
107
- (0, utils_1.execSync)(`npm install @miqro/test-http --save-dev`, {
103
+ writeFileSync(resolve(appFolder, ".gitignore"), gitignoreTemplate.ts());
104
+ execSync(`npm install @miqro/test-http --save-dev`, {
108
105
  cwd: appFolder
109
106
  });
110
- (0, utils_1.execSync)(`npx miqro new:api:main src_main`, {
107
+ execSync(`npx miqro new:api:main src_main`, {
111
108
  cwd: appFolder
112
109
  });
113
- (0, utils_1.execSync)(`npx miqro new:api:route src_api_health`, {
110
+ execSync(`npx miqro new:api:route src_api_health`, {
114
111
  cwd: appFolder
115
112
  });
116
- (0, fs_1.mkdirSync)((0, path_1.resolve)(appFolder, "test"), {
113
+ mkdirSync(resolve(appFolder, "test"), {
117
114
  recursive: true
118
115
  });
119
- (0, utils_1.execSync)(`npx miqro new:api:route:test test_api_health`, {
116
+ execSync(`npx miqro new:api:route:test test_api_health`, {
120
117
  cwd: appFolder
121
118
  });
122
119
  console.log("");
@@ -126,4 +123,3 @@ const mainTS = () => {
126
123
  console.log(`npm run start`);
127
124
  console.log("");
128
125
  };
129
- exports.mainTS = mainTS;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const core_1 = require("@miqro/core");
5
- const utils_1 = require("../utils");
6
- const url_1 = require("url");
7
- const fs_1 = require("fs");
8
- exports.usage = `usage: [NODE_ENV=development] npx miqro serve [directory=./] [path=/] [--index404 ./index.html] [--proxy-cert-ignore] [--port 8080] [--proxy /api=https://host/api]`;
9
- const main = async () => {
10
- const flags = (0, utils_1.extractFlags)(process.argv.slice(3), {
1
+ import { App, loadConfig, LoggerHandler, normalizePath, Proxy, ReadBuffer, Static } from "@miqro/core";
2
+ import { extractFlags } from "../utils/index.js";
3
+ import { URL } from "url";
4
+ import { existsSync, statSync } from "fs";
5
+ export const usage = `usage: [NODE_ENV=development] npx miqro serve [directory=./] [path=/] [--index404 ./index.html] [--proxy-cert-ignore] [--port 8080] [--proxy /api=https://host/api]`;
6
+ export const main = async () => {
7
+ const flags = extractFlags(process.argv.slice(3), {
11
8
  flags: {
12
9
  "help": {
13
10
  description: "get help page", hasValue: false
@@ -27,31 +24,31 @@ const main = async () => {
27
24
  }
28
25
  });
29
26
  if (flags.flags.help !== undefined) {
30
- console.log(exports.usage);
27
+ console.log(usage);
31
28
  process.exit(102);
32
29
  }
33
30
  if (flags.files.length > 2) {
34
- throw new Error(`invalid arguments.\n${exports.usage}`);
31
+ throw new Error(`invalid arguments.\n${usage}`);
35
32
  }
36
33
  if (flags.flags.index404 instanceof Array) {
37
- throw new Error(`invalid index404!.\n${exports.usage}`);
34
+ throw new Error(`invalid index404!.\n${usage}`);
38
35
  }
39
36
  if (flags.flags.port instanceof Array) {
40
- throw new Error(`invalid port!.\n${exports.usage}`);
37
+ throw new Error(`invalid port!.\n${usage}`);
41
38
  }
42
39
  let [directory, path] = flags.files;
43
40
  path = path ? path : "/";
44
41
  directory = directory ? directory : process.cwd();
45
- (0, core_1.loadConfig)();
42
+ loadConfig();
46
43
  const PORT = flags.flags.port ? flags.flags.port : (process.env.PORT ? process.env.PORT : 8080);
47
44
  if (PORT === undefined) {
48
- throw new Error(`invalid port!.\n${exports.usage}`);
45
+ throw new Error(`invalid port!.\n${usage}`);
49
46
  }
50
- if (!(0, fs_1.existsSync)(directory) || !(0, fs_1.statSync)(directory).isDirectory()) {
51
- throw new Error(`${directory} directory not found!\n${exports.usage}`);
47
+ if (!existsSync(directory) || !statSync(directory).isDirectory()) {
48
+ throw new Error(`${directory} directory not found!\n${usage}`);
52
49
  }
53
- const app = new core_1.App();
54
- app.use((0, core_1.LoggerHandler)());
50
+ const app = new App();
51
+ app.use(LoggerHandler());
55
52
  const proxyList = flags.flags.proxy instanceof Array ? flags.flags.proxy : [flags.flags.proxy];
56
53
  for (const proxy of proxyList) {
57
54
  if (proxy) {
@@ -59,18 +56,18 @@ const main = async () => {
59
56
  if (proxySplit.length !== 2) {
60
57
  throw new Error("proxy must be in the form. /path=proxy");
61
58
  }
62
- const proxyPath = (0, core_1.normalizePath)(proxySplit[0]);
63
- const proxyURL = new url_1.URL(proxySplit[1]);
64
- proxyURL.pathname = (0, core_1.normalizePath)(proxyURL.pathname);
65
- const proxyRouter = (0, core_1.Proxy)({
59
+ const proxyPath = normalizePath(proxySplit[0]);
60
+ const proxyURL = new URL(proxySplit[1]);
61
+ proxyURL.pathname = normalizePath(proxyURL.pathname);
62
+ const proxyRouter = Proxy({
66
63
  url: proxyURL.toString(), rejectUnauthorized: flags.flags["proxy-cert-ignore"] ? true : false
67
64
  });
68
65
  console.log("setting up proxy to %s on %s", proxyURL.toString(), proxyPath);
69
- proxyRouter.use((0, core_1.ReadBuffer)());
66
+ proxyRouter.use(ReadBuffer());
70
67
  app.use(proxyRouter, proxyPath);
71
68
  }
72
69
  }
73
- app.use((0, core_1.Static)({
70
+ app.use(Static({
74
71
  directory,
75
72
  list: true,
76
73
  index404: flags.flags.index404 ? flags.flags.index404 : undefined,
@@ -79,4 +76,3 @@ const main = async () => {
79
76
  await app.listen(PORT);
80
77
  console.log("serving " + directory + " on http://localhost:%s%s", PORT, path);
81
78
  };
82
- exports.main = main;
@@ -1,2 +1,2 @@
1
- export declare const usage = "usage: [NODE_ENV=development] CLUSTER_COUNT=os.cpus().length [DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
1
+ export declare const usage = "usage: CLUSTER_COUNT=os.cpus().length [CLUSTER_AUTO_BROADCAST=true|false] [CLUSTER_DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
2
2
  export declare const main: () => void;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const utils_1 = require("../utils");
5
- const runner_1 = require("@miqro/runner");
6
- const core_1 = require("@miqro/core");
7
- exports.usage = "usage: [NODE_ENV=development] CLUSTER_COUNT=os.cpus().length [DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
8
- const main = () => {
1
+ import { execSync } from "../utils/index.js";
2
+ import { mainPath } from "@miqro/runner";
3
+ import { loadConfig } from "@miqro/core";
4
+ export const usage = "usage: CLUSTER_COUNT=os.cpus().length [CLUSTER_AUTO_BROADCAST=true|false] [CLUSTER_DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
5
+ export const main = () => {
9
6
  if (process.argv.length <= 3) {
10
- throw new Error(`invalid number of args\n${exports.usage}`);
7
+ throw new Error(`invalid number of args\n${usage}`);
11
8
  }
12
- (0, core_1.loadConfig)();
13
- (0, utils_1.execSync)(`${process.argv[0]} ${(0, runner_1.mainPath)()} ${process.argv.slice(3).join(" ")}`);
9
+ loadConfig();
10
+ execSync(`${process.argv[0]} ${mainPath()} ${process.argv.slice(3).join(" ")}`);
14
11
  };
15
- exports.main = main;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const fs_1 = require("fs");
5
- const utils_1 = require("../utils");
1
+ import { existsSync, statSync, watch, watchFile } from "fs";
2
+ import { execSync } from "../utils/index.js";
6
3
  const usageMessage = (message) => `${message ? `${message}.\n` : ""}usage: npx miqro watch <directory> <cmd>`;
7
- exports.usage = usageMessage();
4
+ export const usage = usageMessage();
8
5
  function setupWatch(directory, cmd, timeout = 1000) {
9
- (0, fs_1.watchFile)(directory, () => {
6
+ watchFile(directory, () => {
10
7
  queueRunCMD(cmd, timeout);
11
8
  });
12
- (0, fs_1.watch)(directory, {
9
+ watch(directory, {
13
10
  recursive: true
14
11
  }, () => {
15
12
  queueRunCMD(cmd, timeout);
@@ -27,7 +24,7 @@ function queueRunCMD(cmd, timeout) {
27
24
  cmdTimeout = setTimeout(() => {
28
25
  running = true;
29
26
  try {
30
- (0, utils_1.execSync)(cmd, {
27
+ execSync(cmd, {
31
28
  cwd: process.cwd(),
32
29
  env: process.env
33
30
  });
@@ -38,17 +35,16 @@ function queueRunCMD(cmd, timeout) {
38
35
  running = false;
39
36
  }, timeout);
40
37
  }
41
- const main = () => {
38
+ export const main = () => {
42
39
  if (process.argv.length < 5) {
43
40
  throw new Error(usageMessage("invalid number of args"));
44
41
  }
45
42
  const directory = process.argv[3];
46
43
  const cmd = process.argv.slice(4).join(" ");
47
44
  const timeout = process.env.WATCH_TIMEOUT ? parseInt(process.env.WATCH_TIMEOUT, 10) : undefined;
48
- if (!(0, fs_1.existsSync)(directory) || !(0, fs_1.statSync)(directory).isDirectory()) {
45
+ if (!existsSync(directory) || !statSync(directory).isDirectory()) {
49
46
  throw new Error(usageMessage("directory not found!"));
50
47
  }
51
48
  console.log(`setting up watch on ${directory} with cmd ${cmd}`);
52
49
  setupWatch(directory, cmd, timeout);
53
50
  };
54
- exports.main = main;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mainTS = exports.usageTS = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const utils_1 = require("../utils");
1
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
2
+ import { resolve } from "path";
3
+ import { execSync } from "../utils/index.js";
7
4
  const indexHTML = {
8
5
  js: () => `<html>` +
9
6
  `<script type="text/javascript" src="app.bundle.min.js"></script>` +
@@ -58,22 +55,22 @@ const packageTemplate = {
58
55
  "license": "ISC"
59
56
  }`
60
57
  };
61
- exports.usageTS = `usage: npx miqro new:front <identifier ex: NEW_APP>`;
62
- const mainTS = () => {
58
+ export const usageTS = `usage: npx miqro new:front <identifier ex: NEW_APP>`;
59
+ export const mainTS = () => {
63
60
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
64
- throw new Error(exports.usageTS);
61
+ throw new Error(usageTS);
65
62
  }
66
63
  const identifier = process.argv[3].toLocaleLowerCase();
67
- const appFolder = (0, path_1.resolve)(process.cwd(), identifier);
68
- if ((0, fs_1.existsSync)(appFolder)) {
64
+ const appFolder = resolve(process.cwd(), identifier);
65
+ if (existsSync(appFolder)) {
69
66
  throw new Error(`${appFolder} already exists!`);
70
67
  }
71
68
  console.log(`creating ${appFolder}`);
72
- (0, fs_1.mkdirSync)(appFolder, {
69
+ mkdirSync(appFolder, {
73
70
  recursive: true
74
71
  });
75
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, "package.json"), packageTemplate["ts"](identifier));
76
- (0, utils_1.execSync)(`npm install miqro --save-dev`, {
72
+ writeFileSync(resolve(appFolder, "package.json"), packageTemplate["ts"](identifier));
73
+ execSync(`npm install miqro --save-dev`, {
77
74
  cwd: appFolder
78
75
  });
79
76
  /*execSync(
@@ -82,7 +79,7 @@ const mainTS = () => {
82
79
  cwd: appFolder
83
80
  }
84
81
  );*/
85
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, "tsconfig.json"), `{
82
+ writeFileSync(resolve(appFolder, "tsconfig.json"), `{
86
83
  "compileOnSave": true,
87
84
  "compilerOptions": {
88
85
  "lib": ["es2021", "dom"],
@@ -103,20 +100,19 @@ const mainTS = () => {
103
100
  "src"
104
101
  ]
105
102
  }`);
106
- (0, utils_1.execSync)(`npm install typescript --save-dev`, {
103
+ execSync(`npm install typescript --save-dev`, {
107
104
  cwd: appFolder
108
105
  });
109
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, ".gitignore"), gitignoreTemplate.ts());
110
- (0, utils_1.execSync)(`npm install webpack-cli --save-dev`, {
106
+ writeFileSync(resolve(appFolder, ".gitignore"), gitignoreTemplate.ts());
107
+ execSync(`npm install webpack-cli --save-dev`, {
111
108
  cwd: appFolder
112
109
  });
113
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, "webpack.config.js"), webpackconfig.ts());
114
- (0, fs_1.mkdirSync)((0, path_1.resolve)(appFolder, "src"));
115
- (0, fs_1.mkdirSync)((0, path_1.resolve)(appFolder, "public"));
116
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, "public", "index.html"), indexHTML.js());
117
- (0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, "src", "index" + (".tsx")), indexComponent.ts());
110
+ writeFileSync(resolve(appFolder, "webpack.config.js"), webpackconfig.ts());
111
+ mkdirSync(resolve(appFolder, "src"));
112
+ mkdirSync(resolve(appFolder, "public"));
113
+ writeFileSync(resolve(appFolder, "public", "index.html"), indexHTML.js());
114
+ writeFileSync(resolve(appFolder, "src", "index" + (".tsx")), indexComponent.ts());
118
115
  console.log(`new project created on ${appFolder}`);
119
116
  console.log(`cd ${identifier}`);
120
117
  console.log(`npm run start`);
121
118
  };
122
- exports.mainTS = mainTS;
package/build/index.d.ts CHANGED
@@ -0,0 +1 @@
1
+ export {};
package/build/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";
2
1
  console.warn("this package is just a development cli");
2
+ export {};
@@ -1,4 +1,4 @@
1
- import { RouterJSONDoc, Logger } from "@miqro/core";
1
+ import { Logger, RouterJSONDoc } from "@miqro/core";
2
2
  export declare const getDOCJSON: ({ dirname, subPath, apiName }: {
3
3
  apiName?: string | undefined;
4
4
  dirname: string;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDOCJSON = void 0;
4
- const core_1 = require("@miqro/core");
5
- const path_1 = require("path");
6
- const getDOCJSON = async ({ dirname, subPath, apiName }, logger) => {
1
+ import { APIRouter, ConfigPathResolver } from "@miqro/core";
2
+ import { resolve } from "path";
3
+ export const getDOCJSON = async ({ dirname, subPath, apiName }, logger) => {
7
4
  //const apiTraverse = traverseAPIRouteDir(basename(dirname).toUpperCase(), resolve(ConfigPathResolver.getBaseDirname(), dirname), subPath, undefined, logger);
8
- const router = await (0, core_1.APIRouter)({
5
+ const router = await APIRouter({
9
6
  apiName,
10
- dirname: (0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), dirname),
7
+ dirname: resolve(ConfigPathResolver.getBaseDirname(), dirname),
11
8
  path: subPath
12
9
  }, logger);
13
10
  return router.getJSONDoc();
14
11
  };
15
- exports.getDOCJSON = getDOCJSON;
@@ -1,5 +1,4 @@
1
- import { Logger } from "@miqro/core";
2
- import { ParserArgs, ParserMode } from "@miqro/parser";
1
+ import { Logger, ParserMode, SchemaProperties } from "@miqro/core";
3
2
  export declare function getMDDoc(args: {
4
3
  showFilePath?: boolean;
5
4
  apiName?: string;
@@ -7,12 +6,12 @@ export declare function getMDDoc(args: {
7
6
  subPath: string;
8
7
  }, logger?: Logger): Promise<string>;
9
8
  export declare function parserToString(parser: {
10
- headers?: ParserArgs | ParserArgs[];
9
+ headers?: string | SchemaProperties | SchemaProperties[];
11
10
  headersMode?: ParserMode;
12
- query?: ParserArgs | boolean | ParserArgs[];
11
+ query?: string | SchemaProperties | boolean | SchemaProperties[];
13
12
  queryMode?: ParserMode;
14
- params?: ParserArgs | boolean | ParserArgs[];
13
+ params?: string | SchemaProperties | boolean | SchemaProperties[];
15
14
  paramsMode?: ParserMode;
16
- body?: ParserArgs | boolean | ParserArgs[];
15
+ body?: string | SchemaProperties | boolean | SchemaProperties[];
17
16
  bodyMode?: ParserMode;
18
17
  }): string;
@@ -1,9 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parserToString = exports.getMDDoc = void 0;
4
- const json_1 = require("./json");
5
- async function getMDDoc(args, logger) {
6
- const jsonDOC = await (0, json_1.getDOCJSON)(args, logger);
1
+ import { getDOCJSON } from "./json.js";
2
+ /*interface SchemaProperties {
3
+ [key: string]: Schema | string;
4
+ }
5
+
6
+ type ParserMode = "add_extra" | "no_extra" | "remove_extra"*/
7
+ export async function getMDDoc(args, logger) {
8
+ const jsonDOC = await getDOCJSON(args, logger);
7
9
  const pathList = Object.keys(jsonDOC);
8
10
  let outMD = "";
9
11
  for (const path of pathList) {
@@ -35,14 +37,13 @@ async function getMDDoc(args, logger) {
35
37
  }
36
38
  return outMD;
37
39
  }
38
- exports.getMDDoc = getMDDoc;
39
40
  function policyToString(policy) {
40
41
  let outMD = "| groups | policy |\n";
41
42
  outMD += "|--------|--------|\n";
42
43
  outMD += `| ${(policy.groups instanceof Array ? policy.groups : [policy.groups]).join(",")} | ${policy.groupPolicy} |\n\n`;
43
44
  return outMD;
44
45
  }
45
- function parserToString(parser) {
46
+ export function parserToString(parser) {
46
47
  let outMD = "";
47
48
  if (parser.params && typeof parser.params !== "boolean") {
48
49
  outMD += `#### path params\n\n`;
@@ -62,21 +63,20 @@ function parserToString(parser) {
62
63
  }
63
64
  return outMD;
64
65
  }
65
- exports.parserToString = parserToString;
66
66
  function parserPartToString(arg, mode) {
67
67
  if (arg === false) {
68
68
  return "not allowed";
69
69
  }
70
70
  let outMD = "";
71
71
  let maxTabulation = 1;
72
- const parsers = arg instanceof Array ? arg : [arg];
72
+ const parsers = arg instanceof Array ? arg : typeof arg === "string" ? [arg] : [arg];
73
73
  for (const parser of parsers) {
74
74
  const ret = internalParserToString(parser);
75
75
  if (ret.maxTabulation > maxTabulation) {
76
76
  maxTabulation = ret.maxTabulation;
77
77
  }
78
- outMD += `| | ${getTabulation(ret.maxTabulation * 2)}\n`;
79
- outMD += `|--------|--------${getTabulation(ret.maxTabulation * 2, true)}\n`;
78
+ outMD += `| name | type | description | ${getTabulation(ret.maxTabulation * 2)}\n`;
79
+ outMD += `|--------|-------|-------|${getTabulation(ret.maxTabulation * 2, true)}\n`;
80
80
  outMD += `${ret.out}\n\n`;
81
81
  }
82
82
  return outMD;
@@ -91,22 +91,50 @@ function internalParserToString(parser, tabulation = 1) {
91
91
  const attrNames = Object.keys(parser);
92
92
  for (const name of attrNames) {
93
93
  const p = parser[name];
94
+ const description = typeof p === "string" ? "" : p.description ? p.description : "";
94
95
  if (typeof p === "string") {
95
96
  outMD += `${getTabulation(tabulation)}${name} | ${p}|\n`;
96
97
  }
97
- else if (p.type === "nested") {
98
- outMD += `${getTabulation(tabulation)}${name} | ${p.type}|\n`;
99
- const ret = parserBaseNestedTypeToString(p, tabulation + 1);
98
+ else if (p.type === "object") {
99
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}| ${description}|\n`;
100
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
100
101
  if (maxTabulation < ret.maxTabulation) {
101
102
  maxTabulation = ret.maxTabulation;
102
103
  }
103
104
  outMD += `${ret.out}`;
104
105
  }
106
+ else if (p.type === "dict") {
107
+ outMD += `${getTabulation(tabulation)}${name} | Dict\\<${p.dictType}\\>| ${description}|\n`;
108
+ if (p.dictType === "object") {
109
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
110
+ if (maxTabulation < ret.maxTabulation) {
111
+ maxTabulation = ret.maxTabulation;
112
+ }
113
+ outMD += `${ret.out}`;
114
+ }
115
+ }
116
+ else if (p.type === "array") {
117
+ outMD += `${getTabulation(tabulation)}${name} | Array\\<${p.arrayType}\\>| ${description}|\n`;
118
+ if (p.arrayType === "object") {
119
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
120
+ if (maxTabulation < ret.maxTabulation) {
121
+ maxTabulation = ret.maxTabulation;
122
+ }
123
+ outMD += `${ret.out}`;
124
+ }
125
+ }
105
126
  else if (p.type === "regex") {
106
- outMD += `${getTabulation(tabulation)}${name} | ${p.regex}|\n`;
127
+ outMD += `${getTabulation(tabulation)}${name} | ${p.regex}| ${description}|\n`;
128
+ }
129
+ else if (p.type === "enum") {
130
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}| ${description}|\n`;
131
+ outMD += `${getTabulation(tabulation + 1)}| ${p.enumValues?.join(",")}|\n`;
132
+ if (maxTabulation < tabulation + 1) {
133
+ maxTabulation = tabulation + 1;
134
+ }
107
135
  }
108
136
  else {
109
- outMD += `${getTabulation(tabulation)}${name} | ${p.type}|\n`;
137
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}| ${description}|\n`;
110
138
  }
111
139
  }
112
140
  }
@@ -115,10 +143,10 @@ function internalParserToString(parser, tabulation = 1) {
115
143
  maxTabulation
116
144
  };
117
145
  }
118
- function parserBaseNestedTypeToString(arg, tabulation) {
119
- const options = arg.nestedOptions && arg.nestedOptions.options ? arg.nestedOptions.options : {};
146
+ function parserBaseObjectTypeToString(arg, tabulation) {
147
+ const options = arg.properties ? arg.properties : {};
120
148
  //const outMD = `${getTabulation(tabulation)}name | type |\n${getTabulation(tabulation)}--------|--------|\n`;
121
- return internalParserToString(options, tabulation);
149
+ return internalParserToString(options, tabulation + 1);
122
150
  }
123
151
  function getTabulation(n, header = false) {
124
152
  let out = "";
@@ -1,4 +1,4 @@
1
- /// <reference types="node" />
1
+ /// <reference types="node" resolution-mode="require"/>
2
2
  import { ExecSyncOptionsWithBufferEncoding } from "child_process";
3
3
  export declare const execSync: (cmd: string, options?: ExecSyncOptionsWithBufferEncoding) => void;
4
4
  export type Callback<T = any> = (...args: any[]) => T;
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mainCMD = exports.getUsage = exports.extractFlags = exports.execSync = void 0;
4
- const child_process_1 = require("child_process");
5
- const execSync = (cmd, options) => {
1
+ import { execSync as cpExec } from "child_process";
2
+ export const execSync = (cmd, options) => {
6
3
  console.log(cmd);
7
- (0, child_process_1.execSync)(cmd, options ? { stdio: 'inherit', ...options } : { stdio: 'inherit' });
4
+ cpExec(cmd, options ? { stdio: 'inherit', ...options } : { stdio: 'inherit' });
8
5
  };
9
- exports.execSync = execSync;
10
6
  // noinspection SpellCheckingInspection
11
7
  const routeCMDModule = async (cmdArg, cmds, logger, exit = true) => {
12
8
  if (!cmdArg) {
@@ -31,7 +27,7 @@ const routeCMDModule = async (cmdArg, cmds, logger, exit = true) => {
31
27
  }
32
28
  }
33
29
  };
34
- const extractFlags = (args, options) => {
30
+ export const extractFlags = (args, options) => {
35
31
  const flags = Object.create(null);
36
32
  const files = [];
37
33
  for (let i = 0; i < args.length; i++) {
@@ -60,7 +56,6 @@ const extractFlags = (args, options) => {
60
56
  }
61
57
  return { flags, files };
62
58
  };
63
- exports.extractFlags = extractFlags;
64
59
  const getTabs = (n) => {
65
60
  n = n ? n : 1;
66
61
  let ret = "";
@@ -69,7 +64,7 @@ const getTabs = (n) => {
69
64
  }
70
65
  return ret;
71
66
  };
72
- function getUsage(cmds, usage) {
67
+ export function getUsage(cmds, usage) {
73
68
  let out = "";
74
69
  out += `${usage}`;
75
70
  out += `Available commands:\n\n`;
@@ -86,8 +81,7 @@ function getUsage(cmds, usage) {
86
81
  out += "\n";
87
82
  return out;
88
83
  }
89
- exports.getUsage = getUsage;
90
- const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) => {
84
+ export const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) => {
91
85
  const flow = async () => {
92
86
  try {
93
87
  await routeCMDModule(cmdArg, cmds, logger, exit);
@@ -106,4 +100,3 @@ const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) =>
106
100
  logger.error(e);
107
101
  });
108
102
  };
109
- exports.mainCMD = mainCMD;
@@ -1,18 +1,15 @@
1
- "use strict";
2
1
  // noinspection SpellCheckingInspection
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.templates = exports.authEnvFile = exports.dbEnvFile = exports.featuresEnvFile = exports.logEnvFile = void 0;
5
- exports.logEnvFile = `####################
2
+ export const logEnvFile = `####################
6
3
  ## logging
7
4
  LOG_LEVEL=info
8
5
  LOG_LEVEL_Database=error
9
6
  #LOG_FILE=./logs/dev.log
10
7
  `;
11
- exports.featuresEnvFile = `####################
8
+ export const featuresEnvFile = `####################
12
9
  ## features
13
10
  #MY_CUSTOM_FEATURE=false
14
11
  `;
15
- exports.dbEnvFile = `####################
12
+ export const dbEnvFile = `####################
16
13
  ## db
17
14
  DB_URI=sqlite://user:password@localhost:3306/devdb
18
15
  DB_POOL=false
@@ -23,7 +20,7 @@ DB_POOL_ACQUIRE=30000
23
20
  DB_POOL_IDLE=10000
24
21
  DB_STORAGE=./dev.sqlite3
25
22
  `;
26
- exports.authEnvFile = `####################
23
+ export const authEnvFile = `####################
27
24
  ## Auth
28
25
  TOKEN_LOCATION=header
29
26
  #TOKEN_LOCATION=query
@@ -140,13 +137,13 @@ const exampleModel = (modelName) => {
140
137
  };`;
141
138
  };
142
139
  // noinspection SpellCheckingInspection
143
- exports.templates = {
140
+ export const templates = {
144
141
  modelsIndex,
145
142
  dbConfig,
146
143
  sequelizerc,
147
144
  exampleModel,
148
- logEnvFile: exports.logEnvFile,
149
- authEnvFile: exports.authEnvFile,
150
- dbEnvFile: exports.dbEnvFile,
151
- featuresEnvFile: exports.featuresEnvFile
145
+ logEnvFile,
146
+ authEnvFile,
147
+ dbEnvFile,
148
+ featuresEnvFile
152
149
  };
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
7
+ "type": "module",
7
8
  "bin": {
8
9
  "miqro": "build/cli.js"
9
10
  },
@@ -18,12 +19,11 @@
18
19
  "author": "claukers",
19
20
  "license": "ISC",
20
21
  "dependencies": {
21
- "@miqro/core": "^3.0.4",
22
- "@miqro/parser": "^1.0.1",
23
- "@miqro/runner": "^1.3.0"
22
+ "@miqro/core": "^4.0.1",
23
+ "@miqro/parser": "^2.0.1",
24
+ "@miqro/runner": "^2.0.1"
24
25
  },
25
26
  "devDependencies": {
26
- "@miqro/test": "^0.2.9",
27
27
  "@types/cookie": "0.4.1",
28
28
  "@types/node": "^20.4.5",
29
29
  "typescript": "5.0.4"