miqro 5.0.3 → 5.0.4

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
File without changes
@@ -1,4 +1,4 @@
1
- export declare const usage = "npx miqro <command> [args]";
1
+ export declare const usage = "npx miqro <command> [args]\n";
2
2
  export declare const CMD_MAP: {
3
3
  "new:api": {
4
4
  cb: () => void;
@@ -70,6 +70,16 @@ export declare const CMD_MAP: {
70
70
  cb: () => Promise<void>;
71
71
  description: string;
72
72
  };
73
+ "migration:up": {
74
+ tabs: number;
75
+ description: string;
76
+ cb: () => Promise<void>;
77
+ };
78
+ "migration:down": {
79
+ tabs: number;
80
+ description: string;
81
+ cb: () => Promise<void>;
82
+ };
73
83
  help: {
74
84
  cb: () => void;
75
85
  tabs: number;
package/build/cmd-map.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import { resolve } from "path";
2
- import { existsSync, mkdirSync, statSync, writeFileSync } from "fs";
2
+ import { existsSync, lstatSync, mkdirSync, statSync, writeFileSync } from "fs";
3
3
  import { apiRouteTemplate, gitignoreTemplate, mainTemplates, packageTemplate, templates, testTemplates } from "./utils/templates.js";
4
- import { App, ConfigPathResolver, LoggerHandler, Proxy, ReadBuffer, Static, loadConfig, normalizePath } from "@miqro/core";
4
+ import { App, ConfigPathResolver, LoggerHandler, Proxy, ReadBuffer, Static, getLogger, loadConfig, normalizePath } from "@miqro/core";
5
5
  import { getDOCJSON } from "./utils/doc/json.js";
6
6
  import { getMDDoc } from "./utils/doc/md.js";
7
7
  import { mainPath } from "@miqro/runner";
8
8
  import { setupWatch } from "./utils/watch.js";
9
9
  import { extractFlags, getUsage, execSync } from "./utils/exec.js";
10
- export const usage = "npx miqro <command> [args]";
10
+ import { migration } from "@miqro/query";
11
+ export const usage = "npx miqro <command> [args]\n";
11
12
  export const CMD_MAP = {
12
13
  ["new:api"]: {
13
14
  //section: "api development",
@@ -380,6 +381,68 @@ export const CMD_MAP = {
380
381
  console.log("serving " + directory + " on http://localhost:%s%s", PORT, path);
381
382
  }, description: `serve static files.`
382
383
  },
384
+ ["migration:up"]: {
385
+ tabs: 3,
386
+ description: "'up' on migrations in order.",
387
+ cb: async () => {
388
+ const usageMessage = (message) => `${message ? `${message}.\n` : ""}usage: npx miqro migration:up <db.js> <migrations-folder|migration-file>`;
389
+ if (process.argv.length < 5) {
390
+ throw new Error(usageMessage("invalid number of args"));
391
+ }
392
+ const dbJSPath = resolve(process.cwd(), process.argv[3]);
393
+ const migrationFolder = resolve(process.cwd(), process.argv[4]);
394
+ if (!existsSync(migrationFolder)) {
395
+ throw new Error(usageMessage(`invalid args. [${migrationFolder}] doesnt exists!`));
396
+ }
397
+ if (lstatSync(migrationFolder).isSymbolicLink()) {
398
+ throw new Error(usageMessage(`invalid args. [${migrationFolder}] simbolic links not supported.`));
399
+ }
400
+ if (!lstatSync(migrationFolder).isDirectory()) {
401
+ const db = (await import(dbJSPath)).default;
402
+ await db.connect();
403
+ await migration.init(db, getLogger("migrationUp"));
404
+ await migration.up.file(db, migrationFolder, getLogger("migrationUp"));
405
+ await db.disconnect();
406
+ }
407
+ else {
408
+ const db = (await import(dbJSPath)).default;
409
+ await db.connect();
410
+ await migration.up.folder(db, migrationFolder, getLogger("migrationUp"));
411
+ await db.disconnect();
412
+ }
413
+ }
414
+ },
415
+ ["migration:down"]: {
416
+ tabs: 3,
417
+ description: "'down' on migrations in reverse.",
418
+ cb: async () => {
419
+ const usageMessage = (message) => `${message ? `${message}.\n` : ""}usage: npx miqro migration:down <db.js> <migrations-folder|migration-file>`;
420
+ if (process.argv.length < 5) {
421
+ throw new Error(usageMessage("invalid number of args"));
422
+ }
423
+ const dbJSPath = resolve(process.cwd(), process.argv[3]);
424
+ const migrationFolder = resolve(process.cwd(), process.argv[4]);
425
+ if (!existsSync(migrationFolder)) {
426
+ throw new Error(usageMessage(`invalid args. [${migrationFolder}] doesnt exists!`));
427
+ }
428
+ if (lstatSync(migrationFolder).isSymbolicLink()) {
429
+ throw new Error(usageMessage(`invalid args. [${migrationFolder}] simbolic links not supported.`));
430
+ }
431
+ if (!lstatSync(migrationFolder).isDirectory()) {
432
+ const db = (await import(dbJSPath)).default;
433
+ await db.connect();
434
+ await migration.init(db, getLogger("migrationDown"));
435
+ await migration.down.file(db, migrationFolder, getLogger("migrationDown"));
436
+ await db.disconnect();
437
+ }
438
+ else {
439
+ const db = (await import(dbJSPath)).default;
440
+ await db.connect();
441
+ await migration.down.folder(db, migrationFolder, getLogger("migrationDown"));
442
+ await db.disconnect();
443
+ }
444
+ }
445
+ },
383
446
  ["help"]: {
384
447
  //section: "help",
385
448
  cb: () => {
@@ -8,36 +8,47 @@ export async function getMDDoc(args, logger) {
8
8
  const jsonDOC = await getDOCJSON(args, logger);
9
9
  const pathList = Object.keys(jsonDOC);
10
10
  let outMD = "";
11
+ const tableIndexItems = [];
11
12
  for (const path of pathList) {
12
13
  const pathData = jsonDOC[path];
13
14
  const methods = Object.keys(pathData);
14
15
  for (const method of methods) {
15
- const apiDataList = pathData[method];
16
- for (const apiData of apiDataList) {
17
- outMD += `## ${apiData.identifier}${args.showFilePath ? apiData.___filePath : ""}\n\n`;
18
- if (apiData.name) {
19
- outMD += `${apiData.name}\n\n`;
20
- }
21
- if (apiData.description) {
22
- outMD += `${apiData.description}\n\n`;
23
- }
24
- outMD += `[${method}] ${path}\n\n`;
25
- if (apiData.policy) {
26
- outMD += `### policy\n\n`;
27
- outMD += policyToString(apiData.policy);
28
- }
29
- if (apiData.request) {
30
- const requestOutMD = parserToString(apiData.request);
31
- outMD += requestOutMD !== "" ? `### request\n\n${requestOutMD}` : "";
32
- }
33
- if (apiData.response && typeof apiData.response !== "boolean") {
34
- const responseOutMD = parserToString(apiData.response);
35
- outMD += responseOutMD !== "" ? `### response\n\n${responseOutMD}` : "";
16
+ if (method) {
17
+ const apiDataList = pathData[method];
18
+ for (const apiData of apiDataList) {
19
+ tableIndexItems.push({
20
+ apiData
21
+ });
22
+ outMD += `## ${apiData.identifier}\n\n`;
23
+ outMD += `${args.showFilePath ? apiData.___filePath + "\n\n" : ""}`;
24
+ if (apiData.name) {
25
+ outMD += `${apiData.name}\n\n`;
26
+ }
27
+ if (apiData.description) {
28
+ outMD += `${apiData.description}\n\n`;
29
+ }
30
+ outMD += `[${method}] ${path}\n\n`;
31
+ if (apiData.policy) {
32
+ outMD += `### policy\n\n`;
33
+ outMD += policyToString(apiData.policy);
34
+ }
35
+ if (apiData.request) {
36
+ const requestOutMD = parserToString(apiData.request);
37
+ outMD += requestOutMD !== "" ? `### request\n\n${requestOutMD}` : "";
38
+ }
39
+ if (apiData.response && typeof apiData.response !== "boolean") {
40
+ const responseOutMD = parserToString(apiData.response);
41
+ outMD += responseOutMD !== "" ? `### response\n\n${responseOutMD}` : "";
42
+ }
36
43
  }
37
44
  }
38
45
  }
39
46
  }
40
- return outMD;
47
+ const indexTable = getIndexTable(tableIndexItems);
48
+ return `${indexTable}\n\n# endoints\n\n${outMD}`;
49
+ }
50
+ function getIndexTable(data) {
51
+ return `# endpoint list\n\n${data.map(api => `[${api.apiData.identifier}](#${api.apiData.identifier.toLocaleLowerCase()})${api.apiData.name || api.apiData.description ? `\n\n\t${api.apiData.name ? api.apiData.name + " " : ""}${api.apiData.description ? api.apiData.description : ""}` : ""}`).join("\n\n")}`;
41
52
  }
42
53
  function policyToString(policy) {
43
54
  let outMD = "| groups | policy |\n";
@@ -80,7 +91,7 @@ function parserPartToString(arg, mode) {
80
91
  if (ret.maxTabulation > maxTabulation) {
81
92
  maxTabulation = ret.maxTabulation;
82
93
  }
83
- outMD += `| name | type | description | ${getTabulation(ret.maxTabulation * 2)}\n`;
94
+ outMD += `| | | | ${getTabulation(ret.maxTabulation * 2)}\n`;
84
95
  outMD += `|--------|-------|-------|${getTabulation(ret.maxTabulation * 2, true)}\n`;
85
96
  outMD += `${ret.out}\n\n`;
86
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -19,8 +19,9 @@
19
19
  "author": "claukers",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
- "@miqro/core": "^5.0.10",
23
- "@miqro/parser": "^2.0.3",
22
+ "@miqro/core": "^5.0.11",
23
+ "@miqro/query": "^0.0.1",
24
+ "@miqro/parser": "^2.0.4",
24
25
  "@miqro/runner": "^2.0.1"
25
26
  },
26
27
  "devDependencies": {