miqro 1.9.3 → 3.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.
Files changed (75) hide show
  1. package/README.md +18 -37
  2. package/build/cli.js +6 -0
  3. package/build/cmd-map.d.ts +79 -0
  4. package/{dist/cli.js → build/cmd-map.js} +21 -43
  5. package/build/cmds/doc-json.d.ts +2 -0
  6. package/build/cmds/doc-json.js +17 -0
  7. package/build/cmds/doc-md.d.ts +2 -0
  8. package/{dist/cmds/doc-json.js → build/cmds/doc-md.js} +6 -5
  9. package/{dist → build}/cmds/handler-main-new.js +21 -15
  10. package/build/cmds/help.d.ts +1 -0
  11. package/build/cmds/help.js +9 -0
  12. package/{dist → build}/cmds/new-test.js +13 -2
  13. package/{dist → build}/cmds/new.js +20 -15
  14. package/{dist → build}/cmds/serve.d.ts +1 -1
  15. package/{dist → build}/cmds/serve.js +12 -7
  16. package/{dist → build}/cmds/start.d.ts +1 -1
  17. package/{dist → build}/cmds/start.js +1 -1
  18. package/build/utils/doc/json.d.ts +6 -0
  19. package/build/utils/doc/json.js +15 -0
  20. package/build/utils/doc/md.d.ts +18 -0
  21. package/build/utils/doc/md.js +129 -0
  22. package/{dist → build}/utils/index.d.ts +8 -5
  23. package/{dist → build}/utils/index.js +20 -14
  24. package/package.json +15 -16
  25. package/dist/cmds/db-console.d.ts +0 -2
  26. package/dist/cmds/db-console.js +0 -38
  27. package/dist/cmds/db-createmodel.d.ts +0 -2
  28. package/dist/cmds/db-createmodel.js +0 -37
  29. package/dist/cmds/db-dump-data.d.ts +0 -2
  30. package/dist/cmds/db-dump-data.js +0 -43
  31. package/dist/cmds/db-init.d.ts +0 -2
  32. package/dist/cmds/db-init.js +0 -38
  33. package/dist/cmds/db-makemigrations.d.ts +0 -2
  34. package/dist/cmds/db-makemigrations.js +0 -14
  35. package/dist/cmds/db-migrate.d.ts +0 -2
  36. package/dist/cmds/db-migrate.js +0 -12
  37. package/dist/cmds/db-push-data.d.ts +0 -2
  38. package/dist/cmds/db-push-data.js +0 -79
  39. package/dist/cmds/db-sync-makemigrations.d.ts +0 -2
  40. package/dist/cmds/db-sync-makemigrations.js +0 -14
  41. package/dist/cmds/doc-json.d.ts +0 -2
  42. package/dist/cmds/doc-md.d.ts +0 -2
  43. package/dist/cmds/doc-md.js +0 -234
  44. package/dist/cmds/test.d.ts +0 -2
  45. package/dist/cmds/test.js +0 -15
  46. package/dist/utils/db/automigrations/index.d.ts +0 -2
  47. package/dist/utils/db/automigrations/index.js +0 -121
  48. package/dist/utils/db/automigrations/migrate.d.ts +0 -45
  49. package/dist/utils/db/automigrations/migrate.js +0 -750
  50. package/dist/utils/db/index.d.ts +0 -20
  51. package/dist/utils/db/index.js +0 -127
  52. package/dist/utils/doc/index.d.ts +0 -18
  53. package/dist/utils/doc/index.js +0 -36
  54. /package/{dist → build}/cli.d.ts +0 -0
  55. /package/{dist → build}/cmds/config-bash.d.ts +0 -0
  56. /package/{dist → build}/cmds/config-bash.js +0 -0
  57. /package/{dist → build}/cmds/config-env.d.ts +0 -0
  58. /package/{dist → build}/cmds/config-env.js +0 -0
  59. /package/{dist → build}/cmds/config-init.d.ts +0 -0
  60. /package/{dist → build}/cmds/config-init.js +0 -0
  61. /package/{dist → build}/cmds/config.d.ts +0 -0
  62. /package/{dist → build}/cmds/config.js +0 -0
  63. /package/{dist → build}/cmds/handler-apiroute-new.d.ts +0 -0
  64. /package/{dist → build}/cmds/handler-apiroute-new.js +0 -0
  65. /package/{dist → build}/cmds/handler-main-new.d.ts +0 -0
  66. /package/{dist → build}/cmds/new-test.d.ts +0 -0
  67. /package/{dist → build}/cmds/new.d.ts +0 -0
  68. /package/{dist → build}/cmds/watch.d.ts +0 -0
  69. /package/{dist → build}/cmds/watch.js +0 -0
  70. /package/{dist → build}/cmds/wc-new.d.ts +0 -0
  71. /package/{dist → build}/cmds/wc-new.js +0 -0
  72. /package/{dist → build}/index.d.ts +0 -0
  73. /package/{dist → build}/index.js +0 -0
  74. /package/{dist → build}/utils/templates.d.ts +0 -0
  75. /package/{dist → build}/utils/templates.js +0 -0
@@ -0,0 +1,129 @@
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);
7
+ const pathList = Object.keys(jsonDOC);
8
+ let outMD = "";
9
+ for (const path of pathList) {
10
+ const pathData = jsonDOC[path];
11
+ const methods = Object.keys(pathData);
12
+ for (const method of methods) {
13
+ const apiData = pathData[method];
14
+ outMD += `## ${apiData.identifier}${args.showFilePath ? apiData.___filePath : ""}\n\n`;
15
+ if (apiData.name) {
16
+ outMD += `${apiData.name}\n\n`;
17
+ }
18
+ if (apiData.description) {
19
+ outMD += `${apiData.description}\n\n`;
20
+ }
21
+ outMD += `[${method}] ${path}\n\n`;
22
+ if (apiData.policy) {
23
+ outMD += `### policy\n\n`;
24
+ outMD += policyToString(apiData.policy);
25
+ }
26
+ if (apiData.request) {
27
+ const requestOutMD = parserToString(apiData.request);
28
+ outMD += requestOutMD !== "" ? `### request\n\n${requestOutMD}` : "";
29
+ }
30
+ if (apiData.response) {
31
+ const responseOutMD = parserToString(apiData.response);
32
+ outMD += responseOutMD !== "" ? `### response\n\n${responseOutMD}` : "";
33
+ }
34
+ }
35
+ }
36
+ return outMD;
37
+ }
38
+ exports.getMDDoc = getMDDoc;
39
+ function policyToString(policy) {
40
+ let outMD = "| groups | policy |\n";
41
+ outMD += "|--------|--------|\n";
42
+ outMD += `| ${(policy.groups instanceof Array ? policy.groups : [policy.groups]).join(",")} | ${policy.groupPolicy} |\n\n`;
43
+ return outMD;
44
+ }
45
+ function parserToString(parser) {
46
+ let outMD = "";
47
+ if (parser.params && typeof parser.params !== "boolean") {
48
+ outMD += `#### path params\n\n`;
49
+ outMD += parserPartToString(parser.params, parser.paramsMode);
50
+ }
51
+ if (parser.headers) {
52
+ outMD += `#### headers\n\n`;
53
+ outMD += parserPartToString(parser.headers, parser.headersMode);
54
+ }
55
+ if (parser.query && parser.query !== true) {
56
+ outMD += `#### query\n\n`;
57
+ outMD += parserPartToString(parser.query, parser.queryMode);
58
+ }
59
+ if (parser.body && parser.body !== true) {
60
+ outMD += `#### body\n\n`;
61
+ outMD += parserPartToString(parser.body, parser.bodyMode);
62
+ }
63
+ return outMD;
64
+ }
65
+ exports.parserToString = parserToString;
66
+ function parserPartToString(arg, mode) {
67
+ if (arg === false) {
68
+ return "not allowed";
69
+ }
70
+ let outMD = "";
71
+ let maxTabulation = 1;
72
+ const parsers = arg instanceof Array ? arg : [arg];
73
+ for (const parser of parsers) {
74
+ const ret = internalParserToString(parser);
75
+ if (ret.maxTabulation > maxTabulation) {
76
+ maxTabulation = ret.maxTabulation;
77
+ }
78
+ outMD += `| | ${getTabulation(ret.maxTabulation * 2)}\n`;
79
+ outMD += `|--------|--------${getTabulation(ret.maxTabulation * 2, true)}\n`;
80
+ outMD += `${ret.out}\n\n`;
81
+ }
82
+ return outMD;
83
+ }
84
+ function internalParserToString(parser, tabulation = 1) {
85
+ let outMD = "";
86
+ let maxTabulation = tabulation;
87
+ if (typeof parser === "string") {
88
+ outMD += `${getTabulation(tabulation)}${parser}|\n`;
89
+ }
90
+ else {
91
+ const attrNames = Object.keys(parser);
92
+ for (const name of attrNames) {
93
+ const p = parser[name];
94
+ if (typeof p === "string") {
95
+ outMD += `${getTabulation(tabulation)}${name} | ${p}|\n`;
96
+ }
97
+ else if (p.type === "nested") {
98
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}|\n`;
99
+ const ret = parserBaseNestedTypeToString(p, tabulation + 1);
100
+ if (maxTabulation < ret.maxTabulation) {
101
+ maxTabulation = ret.maxTabulation;
102
+ }
103
+ outMD += `${ret.out}`;
104
+ }
105
+ else if (p.type === "regex") {
106
+ outMD += `${getTabulation(tabulation)}${name} | ${p.regex}|\n`;
107
+ }
108
+ else {
109
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}|\n`;
110
+ }
111
+ }
112
+ }
113
+ return {
114
+ out: outMD,
115
+ maxTabulation
116
+ };
117
+ }
118
+ function parserBaseNestedTypeToString(arg, tabulation) {
119
+ const options = arg.nestedOptions && arg.nestedOptions.options ? arg.nestedOptions.options : {};
120
+ //const outMD = `${getTabulation(tabulation)}name | type |\n${getTabulation(tabulation)}--------|--------|\n`;
121
+ return internalParserToString(options, tabulation);
122
+ }
123
+ function getTabulation(n, header = false) {
124
+ let out = "";
125
+ for (let i = 0; i < n; i++) {
126
+ out += header ? "-|" : "| ";
127
+ }
128
+ return out;
129
+ }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { ExecSyncOptionsWithBufferEncoding } from "child_process";
3
3
  export declare const execSync: (cmd: string, options?: ExecSyncOptionsWithBufferEncoding) => void;
4
- export declare type Callback<T = any> = (...args: any[]) => T;
4
+ export type Callback<T = any> = (...args: any[]) => T;
5
5
  export declare const extractFlags: (args: string[], options?: {
6
6
  flags: {
7
7
  [name: string]: {
@@ -15,14 +15,17 @@ export declare const extractFlags: (args: string[], options?: {
15
15
  };
16
16
  files: string[];
17
17
  };
18
- export declare const mainCMD: (cmds: {
18
+ export declare function getUsage(cmds: CMDMap, usage: string): string;
19
+ interface CMDMap {
19
20
  [key: string]: {
20
21
  cb: Callback<void> | Callback<Promise<void>>;
21
22
  description: string;
22
- section?: string | undefined;
23
- tabs?: number | undefined;
23
+ section?: string;
24
+ tabs?: number;
24
25
  };
25
- }, usage: string, logger: Console | {
26
+ }
27
+ export declare const mainCMD: (cmds: CMDMap, usage: string, logger: Console | {
26
28
  error: (...args: any[]) => void;
27
29
  info: (...args: any[]) => void;
28
30
  }, cmdArg?: string, exit?: boolean) => void;
31
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mainCMD = exports.extractFlags = exports.execSync = void 0;
3
+ exports.mainCMD = exports.getUsage = exports.extractFlags = exports.execSync = void 0;
4
4
  const child_process_1 = require("child_process");
5
5
  const execSync = (cmd, options) => {
6
6
  console.log(cmd);
@@ -69,6 +69,24 @@ const getTabs = (n) => {
69
69
  }
70
70
  return ret;
71
71
  };
72
+ function getUsage(cmds, usage) {
73
+ let out = "";
74
+ out += `${usage}`;
75
+ out += `Available commands:\n\n`;
76
+ for (const cmd of Object.keys(cmds)) {
77
+ if (cmds[cmd].section) {
78
+ out += `\n==${cmds[cmd].section}==\n\n`;
79
+ }
80
+ //const description = cmds[cmd].description.split("\n").map(s => `${getTabs(/*cmds[cmd].tabs*/2)}${s}`).join("\n");
81
+ //const description = cmds[cmd].description.split("\n").map(s => `${getTabs(/*cmds[cmd].tabs*/1)}${s}`).join("\n");
82
+ const description = cmds[cmd].description.split("\n").map(s => `${getTabs(cmds[cmd].tabs)}${s}`).join("\n");
83
+ out += `${cmd}${description}\n`;
84
+ //logger.info(`${cmd}\n${description}`);
85
+ }
86
+ out += "\n";
87
+ return out;
88
+ }
89
+ exports.getUsage = getUsage;
72
90
  const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) => {
73
91
  const flow = async () => {
74
92
  try {
@@ -78,19 +96,7 @@ const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) =>
78
96
  if (e && e.message) {
79
97
  logger.error(e.message);
80
98
  }
81
- logger.info(`${usage}`);
82
- logger.info(`Available commands:\n`);
83
- for (const cmd of Object.keys(cmds)) {
84
- if (cmds[cmd].section) {
85
- logger.info(`\n==${cmds[cmd].section}==\n`);
86
- }
87
- //const description = cmds[cmd].description.split("\n").map(s => `${getTabs(/*cmds[cmd].tabs*/2)}${s}`).join("\n");
88
- //const description = cmds[cmd].description.split("\n").map(s => `${getTabs(/*cmds[cmd].tabs*/1)}${s}`).join("\n");
89
- const description = cmds[cmd].description.split("\n").map(s => `${getTabs(cmds[cmd].tabs)}${s}`).join("\n");
90
- logger.info(`${cmd}${description}`);
91
- //logger.info(`${cmd}\n${description}`);
92
- }
93
- logger.info("");
99
+ logger.info(getUsage(cmds, usage));
94
100
  if (exit) {
95
101
  process.exit(1);
96
102
  }
package/package.json CHANGED
@@ -1,36 +1,35 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "1.9.3",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
7
  "bin": {
8
- "miqro": "dist/cli.js"
8
+ "miqro": "build/cli.js"
9
9
  },
10
10
  "scripts": {
11
- "prepare": "npm run build",
12
- "prebuild": "rm -Rf dist;",
11
+ "prepare2": "npm run build",
12
+ "prebuild": "rm -Rf build;",
13
13
  "build": "tsc",
14
14
  "pretest": "npm run build",
15
- "test": "miqro-test test/*.test.js"
15
+ "test": "node --enable-source-maps --test test/",
16
+ "coverage": "node --enable-source-maps --experimental-test-coverage --test test/"
16
17
  },
17
18
  "author": "claukers",
18
19
  "license": "ISC",
19
20
  "dependencies": {
20
- "@miqro/core": "^1.7.3",
21
- "@miqro/parser": "^0.1.6",
22
- "@miqro/runner": "^1.2.9",
23
- "@miqro/test": "^0.2.8",
24
- "deep-diff": "1.0.2"
21
+ "@miqro/core": "^3.0.1",
22
+ "@miqro/parser": "^1.0.1",
23
+ "@miqro/runner": "^1.3.0"
25
24
  },
26
25
  "devDependencies": {
26
+ "@miqro/test": "^0.2.9",
27
27
  "@types/cookie": "0.4.1",
28
- "@types/deep-diff": "1.0.1",
29
- "@types/node": "17.0.23",
30
- "typescript": "4.7.4"
28
+ "@types/node": "^20.4.5",
29
+ "typescript": "5.0.4"
31
30
  },
32
31
  "engines": {
33
- "node": ">=14.0.0",
32
+ "node": ">=18.0.0",
34
33
  "npm": ">=6.0.0"
35
34
  }
36
35
  }
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] npx miqro db:console";
2
- export declare const main: () => void;
@@ -1,38 +0,0 @@
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 readline_1 = require("readline");
6
- const db_1 = require("../utils/db");
7
- exports.usage = "usage: [NODE_ENV=development] npx miqro db:console";
8
- const main = () => {
9
- if (process.argv.length !== 3) {
10
- throw new Error(`invalid number of args. ${exports.usage}`);
11
- }
12
- (0, core_1.loadConfig)();
13
- const logger = (0, core_1.getLogger)("db:console");
14
- const rl = (0, readline_1.createInterface)({
15
- input: process.stdin,
16
- output: process.stdout
17
- });
18
- const db = (0, db_1.loadSequelize)();
19
- const questionLoop = () => {
20
- rl.question('>', async (query) => {
21
- try {
22
- logger.info(`${query}`);
23
- const [result] = await db.query({
24
- query,
25
- values: []
26
- });
27
- logger.info(`${JSON.stringify(result, undefined, 4)}`);
28
- questionLoop();
29
- }
30
- catch (e) {
31
- logger.error(e);
32
- questionLoop();
33
- }
34
- });
35
- };
36
- questionLoop();
37
- };
38
- exports.main = main;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] npx miqro db:create:model <modelname>";
2
- export declare const main: () => void;
@@ -1,37 +0,0 @@
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 templates_1 = require("../utils/templates");
7
- const core_1 = require("@miqro/core");
8
- const db_1 = require("../utils/db");
9
- exports.usage = "usage: [NODE_ENV=development] npx miqro db:create:model <modelname>";
10
- const main = () => {
11
- const logger = console;
12
- const modelName = process.argv[3];
13
- if (process.argv.length !== 4) {
14
- throw new Error(exports.usage);
15
- }
16
- if (typeof modelName !== "string") {
17
- throw new Error(`<modelname> must be a string!`);
18
- }
19
- (0, core_1.loadConfig)();
20
- const config = (0, db_1.loadSequelizeRC)();
21
- // disable experimental typescript support
22
- const modelsFolder = config["models-path"];
23
- if (!(0, fs_1.existsSync)(modelsFolder)) {
24
- logger.warn(`models folder [${modelsFolder}] doesnt exists!`);
25
- logger.warn(`creating [${modelsFolder}]!`);
26
- (0, fs_1.mkdirSync)(modelsFolder, {
27
- recursive: true
28
- });
29
- }
30
- const modelPath = (0, path_1.resolve)(modelsFolder, `${modelName.toLowerCase()}.js`);
31
- if ((0, fs_1.existsSync)(modelPath)) {
32
- throw new Error(`${modelPath} already exists!`);
33
- }
34
- logger.info(`creating [${modelPath}]!`);
35
- (0, fs_1.writeFileSync)(modelPath, templates_1.templates.exampleModel(modelName));
36
- };
37
- exports.main = main;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] [LIMIT_COUNT=100] npx miqro db:dump:data <outfile>";
2
- export declare const main: () => Promise<void>;
@@ -1,43 +0,0 @@
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 path_1 = require("path");
6
- const fs_1 = require("fs");
7
- const db_1 = require("../utils/db");
8
- exports.usage = "usage: [NODE_ENV=development] [LIMIT_COUNT=100] npx miqro db:dump:data <outfile>";
9
- const main = async () => {
10
- const logger = console;
11
- const outfile = process.argv[3];
12
- if (process.argv.length !== 4) {
13
- throw new Error(`invalid number of args. ${exports.usage}`);
14
- }
15
- if (typeof outfile !== "string") {
16
- throw new Error(`<outfile> must be a string!`);
17
- }
18
- const [LIMIT] = (0, core_1.checkEnvVariables)(["LIMIT"], ["100"]);
19
- const limit = parseInt(LIMIT, 10);
20
- if (isNaN(limit) || limit <= 0) {
21
- throw new Error(`LIMIT must be a number grater than 0!`);
22
- }
23
- (0, core_1.loadConfig)();
24
- const db = (0, db_1.loadSequelize)();
25
- const out = {};
26
- logger.info(`beware that if the model is not implicitly defined in db.models it will be dumped.`);
27
- const models = Object.keys(db.models);
28
- for (const modelName of models) {
29
- let rows;
30
- let offset = 0;
31
- out[modelName] = [];
32
- while ((rows = await db.models[modelName].findAndCountAll({
33
- offset,
34
- limit
35
- })).rows.length > 0) {
36
- out[modelName] = out[modelName].concat(rows.rows);
37
- offset += limit;
38
- }
39
- }
40
- await db.close();
41
- (0, fs_1.writeFileSync)((0, path_1.resolve)(process.cwd(), outfile), JSON.stringify(out, undefined, 2));
42
- };
43
- exports.main = main;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] npx miqro db:init";
2
- export declare const main: () => void;
@@ -1,38 +0,0 @@
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
- const utils_1 = require("../utils");
8
- const db_1 = require("../utils/db");
9
- const templates_1 = require("../utils/templates");
10
- exports.usage = "usage: [NODE_ENV=development] npx miqro db:init";
11
- const main = () => {
12
- const logger = console;
13
- if (process.argv.length !== 3) {
14
- throw new Error(`invalid number of args. ${exports.usage}`);
15
- }
16
- const initEnvFile = (path, template) => {
17
- if (!(0, fs_1.existsSync)(path)) {
18
- logger.warn(`creating ${path} env file`);
19
- (0, fs_1.writeFileSync)(path, template);
20
- }
21
- else {
22
- logger.warn(`${path} already exists!. init will not create it.`);
23
- }
24
- };
25
- (0, core_1.loadConfig)();
26
- if ((0, db_1.initDBConfig)()) {
27
- const configPath = core_1.ConfigPathResolver.getConfigDirname();
28
- if (!(0, fs_1.existsSync)(configPath)) {
29
- logger.warn(`[${configPath}] doesnt exists!`);
30
- (0, fs_1.mkdirSync)(configPath, {
31
- recursive: true
32
- });
33
- }
34
- initEnvFile((0, path_1.resolve)(configPath, `db.env`), templates_1.templates.dbEnvFile);
35
- (0, utils_1.execSync)(`npm install sequelize --save`);
36
- }
37
- };
38
- exports.main = main;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] npx miqro db:make:migration";
2
- export declare const main: () => void;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const db_1 = require("../utils/db");
5
- const core_1 = require("@miqro/core");
6
- exports.usage = "usage: [NODE_ENV=development] npx miqro db:make:migration";
7
- const main = () => {
8
- if (process.argv.length !== 3) {
9
- throw new Error(`invalid number of args. ${exports.usage}`);
10
- }
11
- (0, core_1.loadConfig)();
12
- (0, db_1.makemigrations)();
13
- };
14
- exports.main = main;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] npx miqro db:migrate [...args]";
2
- export declare const main: () => void;
@@ -1,12 +0,0 @@
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 core_1 = require("@miqro/core");
6
- exports.usage = "usage: [NODE_ENV=development] npx miqro db:migrate [...args]";
7
- const main = () => {
8
- (0, core_1.loadConfig)();
9
- const args = process.argv.slice(3).join(" ");
10
- (0, utils_1.execSync)(`npx sequelize-cli db:migrate${args ? ` ${args}` : ""}`);
11
- };
12
- exports.main = main;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] [BULK_CREATE_COUNT=10] [BULK_CREATE_IGNORE_ERROR=true] npx miqro db:push:data <outfile> <modelA,..>";
2
- export declare const main: () => Promise<void>;
@@ -1,79 +0,0 @@
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 path_1 = require("path");
6
- const fs_1 = require("fs");
7
- const db_1 = require("../utils/db");
8
- exports.usage = "usage: [NODE_ENV=development] [BULK_CREATE_COUNT=10] [BULK_CREATE_IGNORE_ERROR=true] npx miqro db:push:data <outfile> <modelA,..>";
9
- const main = async () => {
10
- const outfile = process.argv[3];
11
- const models = process.argv[4];
12
- if (process.argv.length !== 5) {
13
- throw new Error(exports.usage);
14
- }
15
- if (typeof outfile !== "string") {
16
- throw new Error(`<outfile> must be a string!`);
17
- }
18
- if (typeof models !== "string") {
19
- throw new Error(`<modelA,..> must be a list of model names!`);
20
- }
21
- (0, core_1.loadConfig)();
22
- const [BULK_CREATE_COUNT, BULK_CREATE_IGNORE_ERROR] = (0, core_1.checkEnvVariables)(["BULK_CREATE_COUNT", "BULK_CREATE_IGNORE_ERROR"], ["10", "true"]);
23
- const bulkCount = parseInt(BULK_CREATE_COUNT, 10);
24
- if (isNaN(bulkCount) || bulkCount < 0) {
25
- throw new Error(`BULK_CREATE_COUNT must be a number grater or equal than 0!`);
26
- }
27
- const modelList = models.split(",").map(o => o.trim());
28
- const db = (0, db_1.loadSequelize)();
29
- const out = JSON.parse((0, fs_1.readFileSync)((0, path_1.resolve)(process.cwd(), outfile)).toString());
30
- for (const modelName of modelList) {
31
- if (out[modelName] && db.models[modelName]) {
32
- const list = out[modelName].map(i => {
33
- const ret = {};
34
- const attrs = Object.keys(i);
35
- for (const a of attrs) {
36
- ret[a] = i[a] && i[a].type === "Buffer" ? Buffer.from(i[a]) : i[a];
37
- }
38
- return ret;
39
- });
40
- if (bulkCount === 0) {
41
- for (const m of list) {
42
- try {
43
- await db.models[modelName].create(m);
44
- }
45
- catch (e) {
46
- if (BULK_CREATE_IGNORE_ERROR === "true") {
47
- console.error("error pushing");
48
- console.error(e.message);
49
- console.error("");
50
- }
51
- else {
52
- throw e;
53
- }
54
- }
55
- }
56
- }
57
- else {
58
- let current;
59
- while ((current = list.splice(0, bulkCount)).length > 0) {
60
- try {
61
- await db.models[modelName].bulkCreate(current);
62
- }
63
- catch (e) {
64
- if (BULK_CREATE_IGNORE_ERROR === "true") {
65
- console.error("error pushing");
66
- console.error(e.message);
67
- console.error("");
68
- }
69
- else {
70
- throw e;
71
- }
72
- }
73
- }
74
- }
75
- }
76
- }
77
- await db.close();
78
- };
79
- exports.main = main;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] npx miqro db:migration:forceclean";
2
- export declare const main: () => void;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = exports.usage = void 0;
4
- const db_1 = require("../utils/db");
5
- const core_1 = require("@miqro/core");
6
- exports.usage = "usage: [NODE_ENV=development] npx miqro db:migration:forceclean";
7
- const main = () => {
8
- if (process.argv.length !== 3) {
9
- throw new Error(`invalid number of args`);
10
- }
11
- (0, core_1.loadConfig)();
12
- (0, db_1.syncMakeMigrations)();
13
- };
14
- exports.main = main;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath>";
2
- export declare const main: () => void;
@@ -1,2 +0,0 @@
1
- export declare const usage = "usage: [NODE_ENV=development] npx miqro doc:md <api_folder> <subPath> <out.md>";
2
- export declare const main: () => void;