miqro 1.5.5 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +42 -2
  2. package/dist/cli.js +8 -9
  3. package/dist/cli.js.map +1 -0
  4. package/dist/cmds/config-bash.js +1 -0
  5. package/dist/cmds/config-bash.js.map +1 -0
  6. package/dist/cmds/config-env.js +1 -0
  7. package/dist/cmds/config-env.js.map +1 -0
  8. package/dist/cmds/config-init.js +2 -0
  9. package/dist/cmds/config-init.js.map +1 -0
  10. package/dist/cmds/config.js +1 -0
  11. package/dist/cmds/config.js.map +1 -0
  12. package/dist/cmds/db-console.js +2 -0
  13. package/dist/cmds/db-console.js.map +1 -0
  14. package/dist/cmds/db-createmodel.js +4 -1
  15. package/dist/cmds/db-createmodel.js.map +1 -0
  16. package/dist/cmds/db-dump-data.js +2 -0
  17. package/dist/cmds/db-dump-data.js.map +1 -0
  18. package/dist/cmds/db-init.js +2 -0
  19. package/dist/cmds/db-init.js.map +1 -0
  20. package/dist/cmds/db-makemigrations.js +3 -0
  21. package/dist/cmds/db-makemigrations.js.map +1 -0
  22. package/dist/cmds/db-push-data.js +30 -4
  23. package/dist/cmds/db-push-data.js.map +1 -0
  24. package/dist/cmds/db-sync-makemigrations.js +3 -0
  25. package/dist/cmds/db-sync-makemigrations.js.map +1 -0
  26. package/dist/cmds/doc-json.js +1 -0
  27. package/dist/cmds/doc-json.js.map +1 -0
  28. package/dist/cmds/doc-md.js +53 -16
  29. package/dist/cmds/doc-md.js.map +1 -0
  30. package/dist/cmds/handler-apiroute-new.js +2 -36
  31. package/dist/cmds/handler-apiroute-new.js.map +1 -0
  32. package/dist/cmds/handler-main-new.d.ts +1 -2
  33. package/dist/cmds/handler-main-new.js +15 -22
  34. package/dist/cmds/handler-main-new.js.map +1 -0
  35. package/dist/cmds/new.d.ts +1 -3
  36. package/dist/cmds/new.js +8 -18
  37. package/dist/cmds/new.js.map +1 -0
  38. package/dist/cmds/start.js +4 -0
  39. package/dist/cmds/start.js.map +1 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.js +15 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/utils/db/automigrations/deep-diff/index.d.ts +24 -0
  44. package/dist/utils/db/automigrations/deep-diff/index.js +240 -0
  45. package/dist/utils/db/automigrations/deep-diff/index.js.map +1 -0
  46. package/dist/utils/db/automigrations/index.js +17 -0
  47. package/dist/utils/db/automigrations/index.js.map +1 -0
  48. package/dist/utils/db/automigrations/migrate.js +136 -17
  49. package/dist/utils/db/automigrations/migrate.js.map +1 -0
  50. package/dist/utils/db/index.d.ts +3 -3
  51. package/dist/utils/db/index.js +11 -1
  52. package/dist/utils/db/index.js.map +1 -0
  53. package/dist/utils/doc/index.d.ts +10 -8
  54. package/dist/utils/doc/index.js +4 -1
  55. package/dist/utils/doc/index.js.map +1 -0
  56. package/dist/utils/index.d.ts +2 -1
  57. package/dist/utils/index.js +2 -1
  58. package/dist/utils/index.js.map +1 -0
  59. package/dist/utils/templates.d.ts +2 -2
  60. package/dist/utils/templates.js +6 -0
  61. package/dist/utils/templates.js.map +1 -0
  62. package/package.json +9 -15
  63. package/src/cli.ts +62 -0
  64. package/src/cmds/config-bash.ts +18 -0
  65. package/src/cmds/config-env.ts +18 -0
  66. package/src/cmds/config-init.ts +35 -0
  67. package/src/cmds/config.ts +16 -0
  68. package/src/cmds/db-console.ts +35 -0
  69. package/src/cmds/db-createmodel.ts +44 -0
  70. package/src/cmds/db-dump-data.ts +44 -0
  71. package/src/cmds/db-init.ts +42 -0
  72. package/src/cmds/db-makemigrations.ts +12 -0
  73. package/src/cmds/db-push-data.ts +77 -0
  74. package/src/cmds/db-sync-makemigrations.ts +12 -0
  75. package/src/cmds/doc-json.ts +16 -0
  76. package/src/cmds/doc-md.ts +233 -0
  77. package/src/cmds/handler-apiroute-new.ts +67 -0
  78. package/src/cmds/handler-main-new.ts +85 -0
  79. package/src/cmds/new.ts +128 -0
  80. package/src/cmds/start.ts +16 -0
  81. package/src/index.ts +2 -0
  82. package/src/utils/db/automigrations/deep-diff/index.ts +264 -0
  83. package/src/utils/db/automigrations/index.ts +151 -0
  84. package/src/utils/db/automigrations/migrate.ts +888 -0
  85. package/src/utils/db/index.ts +128 -0
  86. package/src/utils/doc/index.ts +31 -0
  87. package/src/utils/index.ts +9 -0
  88. package/src/utils/templates.ts +189 -0
  89. package/tsconfig.json +32 -0
@@ -1,14 +1,16 @@
1
- import { Logger, Method, ParseOptions } from "@miqro/core";
1
+ import { SessionHandlerOptions, GroupPolicy, Logger, Method, ParseOptions } from "@miqro/core";
2
2
  export declare const getDOCJSON: ({ dirname, subPath }: {
3
3
  dirname: string;
4
4
  subPath: string;
5
5
  }, logger: Logger) => {
6
- path: string | string[];
7
- method: Method | Method[];
8
- description: string;
9
- params: false | ParseOptions | ParseOptions[];
10
- query: false | ParseOptions | ParseOptions[];
11
- body: false | ParseOptions | ParseOptions[];
12
- result: ParseOptions | ParseOptions[];
6
+ path?: string | string[];
7
+ method?: Method | Method[];
8
+ description?: string;
9
+ policy?: GroupPolicy;
10
+ session?: false | true | SessionHandlerOptions;
11
+ params?: false | ParseOptions | ParseOptions[];
12
+ query?: false | ParseOptions | ParseOptions[];
13
+ body?: false | ParseOptions | ParseOptions[];
14
+ result?: ParseOptions | ParseOptions[];
13
15
  featureName: string;
14
16
  }[];
@@ -7,10 +7,12 @@ const path_1 = require("path");
7
7
  const getDOCJSON = ({ dirname, subPath }, logger) => {
8
8
  const apiTraverse = (0, api_router_utils_1.traverseAPIRouteDir)((0, path_1.basename)(dirname).toUpperCase(), (0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), dirname), subPath, undefined, logger);
9
9
  const docJSON = Object.keys(apiTraverse).map(featureName => {
10
- const { path, method, description, params, query, body, result } = apiTraverse[featureName];
10
+ const { session, policy, path, method, description, params, query, body, result } = apiTraverse[featureName];
11
11
  return {
12
12
  path,
13
13
  method,
14
+ session: session ? typeof session === "function" ? true : session : false,
15
+ policy,
14
16
  params,
15
17
  description, query, body, result,
16
18
  featureName
@@ -19,3 +21,4 @@ const getDOCJSON = ({ dirname, subPath }, logger) => {
19
21
  return docJSON;
20
22
  };
21
23
  exports.getDOCJSON = getDOCJSON;
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/doc/index.ts"],"names":[],"mappings":";;;AAAA,sCAAmH;AACnH,gFAAgF;AAChF,+BAAyC;AAElC,MAAM,UAAU,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAAyC,EAAE,MAAc,EAWlG,EAAE;IACJ,MAAM,WAAW,GAAG,IAAA,sCAAmB,EAAC,IAAA,eAAQ,EAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,IAAA,cAAO,EAAC,yBAAkB,CAAC,cAAc,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC5J,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;QACzD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;QAC7G,OAAO;YACL,IAAI;YACJ,MAAM;YACN,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;YACzE,MAAM;YACN,MAAM;YACN,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM;YAChC,WAAW;SACZ,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAA;AA1BY,QAAA,UAAU,cA0BtB"}
@@ -1,2 +1,3 @@
1
+ /// <reference types="node" />
1
2
  import cp from "child_process";
2
- export declare const execSync: (cmd: string, options?: cp.ExecSyncOptionsWithBufferEncoding) => void;
3
+ export declare const execSync: (cmd: string, options?: cp.ExecSyncOptionsWithBufferEncoding | undefined) => void;
@@ -7,6 +7,7 @@ exports.execSync = void 0;
7
7
  const child_process_1 = __importDefault(require("child_process"));
8
8
  const execSync = (cmd, options) => {
9
9
  console.log(cmd);
10
- child_process_1.default.execSync(cmd, options ? Object.assign({ stdio: 'inherit' }, options) : { stdio: 'inherit' });
10
+ child_process_1.default.execSync(cmd, options ? { stdio: 'inherit', ...options } : { stdio: 'inherit' });
11
11
  };
12
12
  exports.execSync = execSync;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA+B;AAExB,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,OAA8C,EAAQ,EAAE;IAC5F,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,uBAAE,CAAC,QAAQ,CACT,GAAG,EACH,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAClE,CAAC;AACJ,CAAC,CAAA;AANY,QAAA,QAAQ,YAMpB"}
@@ -5,8 +5,8 @@ export declare const authEnvFile = "####################\n## Auth\nTOKEN_LOCATIO
5
5
  export declare const templates: {
6
6
  modelsIndex: string;
7
7
  dbConfig: string;
8
- sequelizerc: (typescript?: boolean) => string;
9
- exampleModel: (modelName: string, typescript?: boolean) => string;
8
+ sequelizerc: (typescript?: boolean | undefined) => string;
9
+ exampleModel: (modelName: string, typescript?: boolean | undefined) => string;
10
10
  logEnvFile: string;
11
11
  authEnvFile: string;
12
12
  dbEnvFile: string;
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // noinspection SpellCheckingInspection
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.templates = exports.authEnvFile = exports.dbEnvFile = exports.featuresEnvFile = exports.logEnvFile = void 0;
4
5
  exports.logEnvFile = `####################
@@ -32,6 +33,7 @@ TOKEN_HEADER=Authorization
32
33
  #TOKEN_VERIFY_ENDPOINT=
33
34
  TOKEN_VERIFY_ENDPOINT_METHOD=GET
34
35
  `;
36
+ // noinspection SpellCheckingInspection
35
37
  const modelsIndex = `'use strict';
36
38
 
37
39
  const fs = require('fs');
@@ -73,6 +75,7 @@ module.exports.sequelize = sequelize;
73
75
  module.exports.Sequelize = Sequelize;
74
76
 
75
77
  `;
78
+ // noinspection SpellCheckingInspection
76
79
  const dbConfig = `const { loadConfig, checkEnvVariables } = require("@miqro/core");
77
80
 
78
81
  loadConfig();
@@ -105,6 +108,7 @@ module.exports = {
105
108
  storage: process.env.DB_STORAGE
106
109
  };
107
110
  `;
111
+ // noinspection SpellCheckingInspection
108
112
  const sequelizerc = (typescript) => `const path = require("path");
109
113
 
110
114
  module.exports = {
@@ -165,6 +169,7 @@ module.exports = (sequelize: Sequelize): ${modelName.charAt(0).toUpperCase()}${m
165
169
  return ${modelName};
166
170
  };`;
167
171
  };
172
+ // noinspection SpellCheckingInspection
168
173
  exports.templates = {
169
174
  modelsIndex,
170
175
  dbConfig,
@@ -175,3 +180,4 @@ exports.templates = {
175
180
  dbEnvFile: exports.dbEnvFile,
176
181
  featuresEnvFile: exports.featuresEnvFile
177
182
  };
183
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/utils/templates.ts"],"names":[],"mappings":";AAAA,uCAAuC;;;AAE1B,QAAA,UAAU,GAAG;;;;;CAKzB,CAAC;AAEW,QAAA,eAAe,GAAG;;;CAG9B,CAAC;AAEW,QAAA,SAAS,GAAG;;;;;;;;;CASxB,CAAC;AAEW,QAAA,WAAW,GAAG;;;;;;;;;;CAU1B,CAAC;AAEF,uCAAuC;AACvC,MAAM,WAAW,GACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCD,CAAC;AACF,uCAAuC;AACvC,MAAM,QAAQ,GACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,CAAC;AACF,uCAAuC;AACvC,MAAM,WAAW,GAAG,CAAC,UAAoB,EAAU,EAAE,CACnD;;;;;;IAME,UAAU,CAAC,CAAC,CAAC,0DAA0D,CAAC,CAAC,CAAC,wDAAwD;;CAErI,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,UAAoB,EAAU,EAAE;IACvE,OAAO,UAAU,CAAC,CAAC,CAAC;;mBAEH,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;;;;cAI/D,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;cACrI,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,yBAAyB,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;;2CAEhH,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;UAC3F,SAAS,uBAAuB,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,SAAS;;;;;;;;;;;;;;IAcpH,SAAS;;SAEJ,SAAS;;WAEP,SAAS;;;;GAIjB,CAAC,CAAC,CAAC;UACI,SAAS,wBAAwB,SAAS;;;;;;;;;;IAUhD,SAAS;;SAEJ,SAAS;;WAEP,SAAS;GACjB,CAAC;AACJ,CAAC,CAAC;AAEF,uCAAuC;AAC1B,QAAA,SAAS,GAAG;IACvB,WAAW;IACX,QAAQ;IACR,WAAW;IACX,YAAY;IACZ,UAAU,EAAV,kBAAU;IACV,WAAW,EAAX,mBAAW;IACX,SAAS,EAAT,iBAAS;IACT,eAAe,EAAf,uBAAe;CAChB,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,9 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "1.5.5",
3
+ "version": "1.6.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/claukers/miqro.git"
10
- },
11
7
  "bin": {
12
8
  "miqro": "dist/cli.js"
13
9
  },
@@ -22,20 +18,18 @@
22
18
  "author": "claukers",
23
19
  "license": "ISC",
24
20
  "dependencies": {
25
- "@miqro/core": "^1.2.3",
26
- "@miqro/runner": "^1.1.5",
27
- "deep-diff": "^1.0.2"
21
+ "@miqro/core": "^1.3.1",
22
+ "@miqro/runner": "^1.1.6"
28
23
  },
29
24
  "devDependencies": {
30
- "@types/deep-diff": "^1.0.1",
31
25
  "@types/node": "^16.7.10",
32
- "@typescript-eslint/eslint-plugin": "^4.30.0",
33
- "@typescript-eslint/parser": "^4.30.0",
34
- "eslint": "^7.32.0",
35
- "typescript": "^4.4.2"
26
+ "@typescript-eslint/eslint-plugin": "^5.3.0",
27
+ "@typescript-eslint/parser": "^5.3.0",
28
+ "eslint": "^8.2.0",
29
+ "typescript": "^4.4.4"
36
30
  },
37
31
  "engines": {
38
- "node": "^10.0.0",
39
- "npm": "^6.0.0"
32
+ "node": ">=14.0.0",
33
+ "npm": ">=6.0.0"
40
34
  }
41
35
  }
package/src/cli.ts ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ //@miqro/core
3
+ import { CLIUtil } from "@miqro/core";
4
+ import { main as start } from "./cmds/start";
5
+ import { mainJS as newJS } from "./cmds/new";
6
+ import { mainTS as newTS } from "./cmds/new";
7
+ import { main as apiDocJSON } from "./cmds/doc-json";
8
+ import { main as apiDocMD } from "./cmds/doc-md";
9
+ import { main as configInit } from "./cmds/config-init";
10
+ import { main as config } from "./cmds/config";
11
+ import { main as configBash } from "./cmds/config-bash";
12
+ import { main as configEnv } from "./cmds/config-env";
13
+ //@miqro/handlers
14
+ import { main as newRoute } from "./cmds/handler-apiroute-new";
15
+ import { main as newMain } from "./cmds/handler-main-new";
16
+ //@miqro/database
17
+ import { main as dbInit } from "./cmds/db-init";
18
+ import { main as makeMigrations } from "./cmds/db-makemigrations";
19
+ import { main as syncMakeMigrations } from "./cmds/db-sync-makemigrations";
20
+ import { main as consoleCMD } from "./cmds/db-console";
21
+ import { main as createModel } from "./cmds/db-createmodel";
22
+ import { main as pushData } from "./cmds/db-push-data";
23
+ import { main as dumpData } from "./cmds/db-dump-data";
24
+
25
+ // noinspection SpellCheckingInspection
26
+ CLIUtil.cliFlow({
27
+
28
+ ["new"]: { section: "quick start", cb: newJS, description: "\t\t\t\tcreate a new project" },
29
+
30
+ ["new:main"]: { section: "http scafolding", cb: newMain, description: "\t\t\tcreates a new main file" },
31
+
32
+ ["new:typescript"]: { cb: newTS, description: "\t\t\tcreate a new typescript project" },
33
+
34
+ ["new:route"]: { cb: newRoute, description: "\t\t\tcreates a new route" },
35
+
36
+ ["config"]: { section: "config managment", cb: config, description: "\t\t\t\toutputs to stdout the config as a json" },
37
+ ["config:bash"]: {
38
+ cb: configBash,
39
+ description: "\t\t\toutputs to stdout the config as a bash script"
40
+ },
41
+ ["config:env"]: { cb: configEnv, description: "\t\t\toutputs to stdout the config as a env file" },
42
+ ["config:init"]: { cb: configInit, description: "\t\t\tinits your config folder" },
43
+
44
+ ["start"]: { section: "cluster start", cb: start, description: "\t\t\t\tstart a nodejs script in cluster mode and restart if crash." },
45
+
46
+ ["doc"]: { section: "api documentation", cb: apiDocJSON, description: "\t\t\t\toutputs to stdout an api folder auto doc as a json" },
47
+ ["doc:md"]: { cb: apiDocMD, description: "\t\t\t\toutputs to a file an api folder auto doc as a markdown" },
48
+
49
+ ["db:console"]: { section: "sequelize helpers", cb: consoleCMD, description: "\t\t\truns a readline interface that send the input as a query" },
50
+ ["db:dump:data"]: { cb: dumpData, description: "\t\t\tdump the data of the database (only defined models)" },
51
+ ["db:push:data"]: { cb: pushData, description: "\t\t\tpush a dump to the database" },
52
+ ["db:make:migration"]: {
53
+ cb: makeMigrations,
54
+ description: "\t\tseeks changes in your models and creates migrations"
55
+ },
56
+ ["db:make:migration:force:clean:state"]: {
57
+ cb: syncMakeMigrations,
58
+ description: "regenerate _current.json in the migrations folder to force the 'local' migration state to be the same as the current models."
59
+ },
60
+ ["db:init"]: { cb: dbInit, description: "\t\t\t\tinit sequelize configuration." },
61
+ ["db:create:model"]: { cb: createModel, description: "\t\t\tcreates an example model" }
62
+ }, "npx miqro <command> [args]", console);
@@ -0,0 +1,18 @@
1
+ import { loadConfig } from "@miqro/core";
2
+
3
+ export const main = (): void => {
4
+ const logger = console;
5
+
6
+ if (process.argv.length !== 3) {
7
+ throw new Error(`invalid number of args`);
8
+ }
9
+
10
+ const configOut = loadConfig();
11
+
12
+ const config = configOut.combined;
13
+ const keys = Object.keys(config);
14
+
15
+ for (const key of keys) {
16
+ logger.info(`export ${key}=${config[key]}`);
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ import { loadConfig } from "@miqro/core";
2
+
3
+ export const main = (): void => {
4
+ const logger = console;
5
+
6
+ if (process.argv.length !== 3) {
7
+ throw new Error(`invalid number of args`);
8
+ }
9
+
10
+ const configOut = loadConfig();
11
+
12
+ const config = configOut.combined;
13
+ const keys = Object.keys(config);
14
+
15
+ for (const key of keys) {
16
+ logger.info(`${key}=${config[key]}`);
17
+ }
18
+ }
@@ -0,0 +1,35 @@
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";
5
+
6
+ export const main = (): void => {
7
+ const logger = console;
8
+
9
+ if (process.argv.length !== 3) {
10
+ throw new Error(`invalid number of args`);
11
+ }
12
+
13
+ loadConfig();
14
+
15
+ const configPath = ConfigPathResolver.getConfigDirname();
16
+
17
+ const initEnvFile = (path: string, template: string): void => {
18
+ if (!existsSync(path)) {
19
+ logger.warn(`creating ${path} env file`);
20
+ writeFileSync(path, template);
21
+ } else {
22
+ logger.warn(`${path} already exists!. init will not create it.`);
23
+ }
24
+ };
25
+
26
+ if (!existsSync(configPath)) {
27
+ logger.warn(`[${configPath}] doesnt exists!`);
28
+ mkdirSync(configPath, {
29
+ recursive: true
30
+ });
31
+ }
32
+ initEnvFile(resolve(configPath, `log.env`), templates.logEnvFile);
33
+ initEnvFile(resolve(configPath, `auth.env`), templates.authEnvFile);
34
+ initEnvFile(resolve(configPath, `features.env`), templates.featuresEnvFile);
35
+ }
@@ -0,0 +1,16 @@
1
+ import { loadConfig } from "@miqro/core";
2
+
3
+ export const main = (): void => {
4
+ const logger = console;
5
+
6
+ if (process.argv.length !== 3) {
7
+ throw new Error(`invalid number of args`);
8
+ }
9
+
10
+ const configOut = loadConfig();
11
+
12
+ const config = configOut.combined;
13
+
14
+ logger.info(JSON.stringify(config, undefined, 2));
15
+ }
16
+
@@ -0,0 +1,35 @@
1
+ import { getLogger, loadConfig } from "@miqro/core";
2
+ import { createInterface } from "readline";
3
+ import { loadSequelize } from "../utils/db";
4
+
5
+ export const main = (): void => {
6
+ if (process.argv.length !== 3) {
7
+ throw new Error(`invalid number of args`);
8
+ }
9
+
10
+ loadConfig();
11
+
12
+ const logger = getLogger("db:console");
13
+ const rl = createInterface({
14
+ input: process.stdin,
15
+ output: process.stdout
16
+ });
17
+ const db = loadSequelize();
18
+ const questionLoop = () => {
19
+ rl.question('>', async (query) => {
20
+ try {
21
+ logger.info(`${query}`);
22
+ const [result] = await db.query({
23
+ query,
24
+ values: []
25
+ });
26
+ logger.info(`${JSON.stringify(result, undefined, 4)}`);
27
+ questionLoop();
28
+ } catch (e) {
29
+ logger.error(e);
30
+ questionLoop();
31
+ }
32
+ });
33
+ }
34
+ questionLoop();
35
+ }
@@ -0,0 +1,44 @@
1
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
2
+ import { resolve } from "path";
3
+ import { templates } from "../utils/templates";
4
+ import { ConfigPathResolver, loadConfig } from "@miqro/core";
5
+ import { loadSequelizeRC } from "../utils/db";
6
+
7
+ export const main = (): void => {
8
+ const logger = console;
9
+ const modelname = process.argv[3];
10
+
11
+ if (process.argv.length !== 4) {
12
+ throw new Error(`arguments: <modelname>`);
13
+ }
14
+
15
+ if (typeof modelname !== "string") {
16
+ throw new Error(`<modelname> must be a string!`);
17
+ }
18
+
19
+ loadConfig();
20
+
21
+ const config = loadSequelizeRC();
22
+
23
+ // disable experimental typescript support
24
+ const typescript = false; //existsSync(resolve(ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? true : false;
25
+ const modelsFolder = typescript ? resolve(ConfigPathResolver.getBaseDirname(), "src", "models") : config["models-path"];
26
+
27
+ if (!existsSync(modelsFolder)) {
28
+ logger.warn(`models folder [${modelsFolder}] doesnt exists!`);
29
+ logger.warn(`creating [${modelsFolder}]!`);
30
+ mkdirSync(modelsFolder, {
31
+ recursive: true
32
+ });
33
+ }
34
+
35
+ const modelPath = resolve(modelsFolder, `${modelname.toLowerCase()}${typescript ? ".ts" : ".js"}`);
36
+
37
+ if (existsSync(modelPath)) {
38
+ throw new Error(`${modelPath} already exists!`);
39
+ }
40
+ logger.info(`creating [${modelPath}]!`);
41
+
42
+ writeFileSync(modelPath, templates.exampleModel(modelname, typescript));
43
+
44
+ }
@@ -0,0 +1,44 @@
1
+ import { checkEnvVariables, SimpleMap, loadConfig } from "@miqro/core";
2
+ import { resolve } from "path";
3
+ import { writeFileSync } from "fs";
4
+ import { loadSequelize } from "../utils/db";
5
+
6
+ export const main = async (): Promise<void> => {
7
+ const logger = console;
8
+ const outfile = process.argv[3];
9
+ if (process.argv.length !== 4) {
10
+ throw new Error(`[LIMIT_COUNT=100] arguments: <outfile>`);
11
+ }
12
+
13
+ if (typeof outfile !== "string") {
14
+ throw new Error(`<outfile> must be a string!`);
15
+ }
16
+
17
+ const [LIMIT] = checkEnvVariables(["LIMIT"], ["100"]);
18
+ const limit = parseInt(LIMIT, 10);
19
+
20
+ if (isNaN(limit) || limit <= 0) {
21
+ throw new Error(`LIMIT must be a number grater than 0!`);
22
+ }
23
+
24
+ loadConfig();
25
+
26
+ const db = loadSequelize();
27
+ const out: SimpleMap<any[]> = {};
28
+ logger.info(`beware that if the model is not implicitly defined in db.models it will be dumped.`);
29
+ const models = Object.keys(db.models);
30
+ for (const modelName of models) {
31
+ let rows;
32
+ let offset = 0;
33
+ out[modelName] = [];
34
+ while ((rows = await db.models[modelName].findAndCountAll({
35
+ offset,
36
+ limit
37
+ })).rows.length > 0) {
38
+ out[modelName] = out[modelName].concat(rows.rows);
39
+ offset += limit;
40
+ }
41
+ }
42
+ await db.close();
43
+ writeFileSync(resolve(process.cwd(), outfile), JSON.stringify(out, undefined, 2));
44
+ }
@@ -0,0 +1,42 @@
1
+ import { ConfigPathResolver, loadConfig } from "@miqro/core";
2
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
3
+ import { resolve } from "path";
4
+ import { execSync } from "../utils";
5
+ import { initDBConfig } from "../utils/db";
6
+ import { templates } from "../utils/templates";
7
+
8
+ export const main = (): void => {
9
+ const logger = console;
10
+
11
+ if (process.argv.length !== 3) {
12
+ throw new Error(`invalid number of args`);
13
+ }
14
+
15
+ const initEnvFile = (path: string, template: string): void => {
16
+ if (!existsSync(path)) {
17
+ logger.warn(`creating ${path} env file`);
18
+ writeFileSync(path, template);
19
+ } else {
20
+ logger.warn(`${path} already exists!. init will not create it.`);
21
+ }
22
+ };
23
+
24
+ loadConfig();
25
+
26
+ if (initDBConfig()) {
27
+ const configPath = ConfigPathResolver.getConfigDirname();
28
+ if (!existsSync(configPath)) {
29
+ logger.warn(`[${configPath}] doesnt exists!`);
30
+ mkdirSync(configPath, {
31
+ recursive: true
32
+ });
33
+ }
34
+ initEnvFile(resolve(configPath, `db.env`), templates.dbEnvFile);
35
+ execSync(
36
+ `npm install sequelize --save`
37
+ );
38
+ execSync(
39
+ `npm install @miqro/core --save`
40
+ );
41
+ }
42
+ };
@@ -0,0 +1,12 @@
1
+ import { makemigrations } from "../utils/db";
2
+ import { loadConfig } from "@miqro/core";
3
+
4
+ export const main = (): void => {
5
+ if (process.argv.length !== 3) {
6
+ throw new Error(`invalid number of args`);
7
+ }
8
+
9
+ loadConfig();
10
+
11
+ makemigrations();
12
+ }
@@ -0,0 +1,77 @@
1
+ import { checkEnvVariables, SimpleMap, loadConfig } from "@miqro/core";
2
+ import { resolve } from "path";
3
+ import { readFileSync } from "fs";
4
+ import { loadSequelize } from "../utils/db";
5
+
6
+ export const main = async (): Promise<void> => {
7
+ const outfile = process.argv[3];
8
+ const models = process.argv[4];
9
+ if (process.argv.length !== 5) {
10
+ throw new Error(`[BULK_CREATE_COUNT=10] [BULK_CREATE_IGNORE_ERROR=true] arguments: <outfile> <modelA,..>`);
11
+ }
12
+
13
+ if (typeof outfile !== "string") {
14
+ throw new Error(`<outfile> must be a string!`);
15
+ }
16
+
17
+ if (typeof models !== "string") {
18
+ throw new Error(`<modelA,..> must be a list of model names!`);
19
+ }
20
+
21
+ loadConfig();
22
+
23
+ const [BULK_CREATE_COUNT, BULK_CREATE_IGNORE_ERROR] = checkEnvVariables(["BULK_CREATE_COUNT", "BULK_CREATE_IGNORE_ERROR"], ["10", "true"]);
24
+ const bulkCount = parseInt(BULK_CREATE_COUNT, 10);
25
+
26
+ if (isNaN(bulkCount) || bulkCount < 0) {
27
+ throw new Error(`BULK_CREATE_COUNT must be a number grater or equal than 0!`);
28
+ }
29
+
30
+ const modelList = models.split(",").map(o => o.trim());
31
+
32
+ const db = loadSequelize();
33
+ const out: SimpleMap<any[]> = JSON.parse(readFileSync(resolve(process.cwd(), outfile)).toString());
34
+ for (const modelName of modelList) {
35
+ if (out[modelName] && db.models[modelName]) {
36
+ const list = out[modelName].map(i => {
37
+ const ret: any = {};
38
+ const attrs = Object.keys(i);
39
+ for (const a of attrs) {
40
+ ret[a] = i[a] && i[a].type === "Buffer" ? Buffer.from(i[a]) : i[a];
41
+ }
42
+ return ret;
43
+ });
44
+ if (bulkCount === 0) {
45
+ for (const m of list) {
46
+ try {
47
+ await db.models[modelName].create(m);
48
+ } catch(e: any) {
49
+ if(BULK_CREATE_IGNORE_ERROR === "true") {
50
+ console.error("error pushing");
51
+ console.error(e.message);
52
+ console.error("");
53
+ } else {
54
+ throw e;
55
+ }
56
+ }
57
+ }
58
+ } else {
59
+ let current;
60
+ while ((current = list.splice(0, bulkCount)).length > 0) {
61
+ try {
62
+ await db.models[modelName].bulkCreate(current);
63
+ } catch(e: any) {
64
+ if(BULK_CREATE_IGNORE_ERROR === "true") {
65
+ console.error("error pushing");
66
+ console.error(e.message);
67
+ console.error("");
68
+ } else {
69
+ throw e;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ await db.close();
77
+ }
@@ -0,0 +1,12 @@
1
+ import { syncMakeMigrations } from "../utils/db";
2
+ import { loadConfig } from "@miqro/core";
3
+
4
+ export const main = (): void => {
5
+ if (process.argv.length !== 3) {
6
+ throw new Error(`invalid number of args`);
7
+ }
8
+
9
+ loadConfig();
10
+
11
+ syncMakeMigrations();
12
+ }
@@ -0,0 +1,16 @@
1
+ import { getLogger, loadConfig } from "@miqro/core";
2
+ import { getDOCJSON } from "../utils/doc";
3
+
4
+ export const main = (): void => {
5
+
6
+ if (process.argv.length !== 5) {
7
+ throw new Error(`arguments: <api_folder> <subPath>`);
8
+ }
9
+
10
+ const dirname = process.argv[3];
11
+ const subPath = process.argv[4];
12
+
13
+ loadConfig();
14
+
15
+ console.log(JSON.stringify(getDOCJSON({ dirname, subPath }, getLogger("miqro")), undefined, 2));
16
+ }