miqro 1.7.6 → 1.7.10
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/dist/cli.js +2 -0
- package/dist/cmds/doc-md.js +14 -15
- package/dist/cmds/new-test.js +1 -3
- package/dist/cmds/new.js +10 -0
- package/dist/cmds/serve.d.ts +1 -0
- package/dist/cmds/serve.js +66 -0
- package/dist/utils/db/index.js +3 -2
- package/dist/utils/doc/index.d.ts +6 -5
- package/dist/utils/doc/index.js +11 -2
- package/package.json +5 -4
package/dist/cli.js
CHANGED
|
@@ -14,6 +14,7 @@ const config_bash_1 = require("./cmds/config-bash");
|
|
|
14
14
|
const config_env_1 = require("./cmds/config-env");
|
|
15
15
|
const handler_apiroute_new_1 = require("./cmds/handler-apiroute-new");
|
|
16
16
|
const new_test_1 = require("./cmds/new-test");
|
|
17
|
+
const serve_1 = require("./cmds/serve");
|
|
17
18
|
const handler_main_new_1 = require("./cmds/handler-main-new");
|
|
18
19
|
//@miqro/database
|
|
19
20
|
const db_init_1 = require("./cmds/db-init");
|
|
@@ -37,6 +38,7 @@ const db_dump_data_1 = require("./cmds/db-dump-data");
|
|
|
37
38
|
["config:env"]: { cb: config_env_1.main, description: "\t\t\toutputs to stdout the config as a env file" },
|
|
38
39
|
["config:init"]: { cb: config_init_1.main, description: "\t\t\tinits your config folder" },
|
|
39
40
|
["start"]: { section: "cluster start", cb: start_1.main, description: "\t\t\t\tstart a nodejs script in cluster mode and restart if crash." },
|
|
41
|
+
["serve"]: { section: "serve static files", cb: serve_1.main, description: "\t\t\t\tserve static files." },
|
|
40
42
|
["doc"]: { section: "api documentation", cb: doc_json_1.main, description: "\t\t\t\toutputs to stdout an api folder auto doc as a json" },
|
|
41
43
|
["doc:md"]: { cb: doc_md_1.main, description: "\t\t\t\toutputs to a file an api folder auto doc as a markdown" },
|
|
42
44
|
["test:new"]: { section: "testing", cb: new_test_1.main, description: "\t\t\tcreate new test.js file." },
|
package/dist/cmds/doc-md.js
CHANGED
|
@@ -105,7 +105,7 @@ const main = () => {
|
|
|
105
105
|
return range;
|
|
106
106
|
};
|
|
107
107
|
const parseOptionTable = (options, subName = "", tableHeaders = 0) => {
|
|
108
|
-
if (options) {
|
|
108
|
+
if (typeof options !== "boolean" && options) {
|
|
109
109
|
let padding = "";
|
|
110
110
|
for (let i = 0; i < tableHeaders; i++) {
|
|
111
111
|
padding += "| ";
|
|
@@ -155,13 +155,12 @@ const main = () => {
|
|
|
155
155
|
const param = doc.params instanceof Array ? doc.params : [doc.params];
|
|
156
156
|
const paramsTable = [];
|
|
157
157
|
for (const q of param) {
|
|
158
|
-
let paramTable = parseOptionTable(q);
|
|
159
|
-
// let paramsTable = parseOptionTable(doc.params);
|
|
158
|
+
let paramTable = typeof q === "string" ? `${q}` : parseOptionTable(q);
|
|
160
159
|
if (paramTable.split("\n").length > 1) {
|
|
161
|
-
paramTable = `### params${q && q.description ? ` (${q.description})` : ""}\n\n${paramTable}`;
|
|
160
|
+
paramTable = `### params${typeof q !== "boolean" && typeof q !== "string" && q && q.description ? ` (${q.description})` : ""}\n\n${paramTable}`;
|
|
162
161
|
}
|
|
163
162
|
else {
|
|
164
|
-
paramTable = paramTable === "" ? "" : `### params${q && q.description ? ` (${q.description})` : ""}: ${paramTable}`;
|
|
163
|
+
paramTable = paramTable === "" ? "" : `### params${typeof q !== "boolean" && typeof q !== "string" && q && q.description ? ` (${q.description})` : ""}: ${paramTable}`;
|
|
165
164
|
}
|
|
166
165
|
if (paramTable !== "") {
|
|
167
166
|
paramsTable.push(paramTable);
|
|
@@ -170,13 +169,13 @@ const main = () => {
|
|
|
170
169
|
const query = doc.query instanceof Array ? doc.query : [doc.query];
|
|
171
170
|
const queryTables = [];
|
|
172
171
|
for (const q of query) {
|
|
173
|
-
let queryTable = parseOptionTable(q);
|
|
172
|
+
let queryTable = typeof q === "string" ? `${q}` : parseOptionTable(q);
|
|
174
173
|
// let paramsTable = parseOptionTable(doc.params);
|
|
175
174
|
if (queryTable.split("\n").length > 1) {
|
|
176
|
-
queryTable = `### query${q && q.description ? ` (${q.description})` : ""}\n\n${queryTable}`;
|
|
175
|
+
queryTable = `### query${typeof q !== "boolean" && typeof q !== "string" && q && q.description ? ` (${q.description})` : ""}\n\n${queryTable}`;
|
|
177
176
|
}
|
|
178
177
|
else {
|
|
179
|
-
queryTable = queryTable === "" ? "" : `### query${q && q.description ? ` (${q.description})` : ""}: ${queryTable}`;
|
|
178
|
+
queryTable = queryTable === "" ? "" : `### query${typeof q !== "boolean" && typeof q !== "string" && q && q.description ? ` (${q.description})` : ""}: ${queryTable}`;
|
|
180
179
|
}
|
|
181
180
|
if (queryTable !== "") {
|
|
182
181
|
queryTables.push(queryTable);
|
|
@@ -190,29 +189,29 @@ const main = () => {
|
|
|
190
189
|
const body = doc.body instanceof Array ? doc.body : [doc.body];
|
|
191
190
|
const bodyTables = [];
|
|
192
191
|
for (const b of body) {
|
|
193
|
-
let bodyTable = parseOptionTable(b);
|
|
192
|
+
let bodyTable = typeof b === "string" ? `${b}` : parseOptionTable(b);
|
|
194
193
|
if (bodyTable.split("\n").length > 1) {
|
|
195
|
-
bodyTable = `### body${b && b.description ? ` (${b.description})` : ""}\n\n${bodyTable}`;
|
|
194
|
+
bodyTable = `### body${typeof b !== "boolean" && typeof b !== "string" && b && b.description ? ` (${b.description})` : ""}\n\n${bodyTable}`;
|
|
196
195
|
}
|
|
197
196
|
else {
|
|
198
|
-
bodyTable = bodyTable === "" ? "" : `### body${b && b.description ? ` (${b.description})` : ""}: ${bodyTable}`;
|
|
197
|
+
bodyTable = bodyTable === "" ? "" : `### body${typeof b !== "boolean" && typeof b !== "string" && b && b.description ? ` (${b.description})` : ""}: ${bodyTable}`;
|
|
199
198
|
}
|
|
200
199
|
if (bodyTable !== "") {
|
|
201
200
|
bodyTables.push(bodyTable);
|
|
202
201
|
}
|
|
203
202
|
}
|
|
204
|
-
const results = doc.
|
|
203
|
+
const results = doc.response instanceof Array ? doc.response : [doc.response];
|
|
205
204
|
const resultTables = [];
|
|
206
205
|
for (const r of results) {
|
|
207
206
|
if (!r) {
|
|
208
207
|
continue;
|
|
209
208
|
}
|
|
210
|
-
let resultsTable =
|
|
209
|
+
let resultsTable = r && typeof r !== "string" && typeof r !== "boolean" ? parseOptionTable(r) : r;
|
|
211
210
|
if (resultsTable.split("\n").length > 1) {
|
|
212
|
-
resultsTable = `### response${r.description ? ` (${r.description})` : ""}\n\n${resultsTable}`;
|
|
211
|
+
resultsTable = `### response${typeof r !== "boolean" && typeof r !== "string" && r.description ? ` (${r.description})` : ""}\n\n${resultsTable}`;
|
|
213
212
|
}
|
|
214
213
|
else {
|
|
215
|
-
resultsTable = resultsTable === "" ? "" : `### response${r.description ? ` (${r.description})` : ""}: ${resultsTable}`;
|
|
214
|
+
resultsTable = resultsTable === "" ? "" : `### response${typeof r !== "boolean" && typeof r !== "string" && r.description ? ` (${r.description})` : ""}: ${resultsTable}`;
|
|
216
215
|
}
|
|
217
216
|
if (resultsTable !== "") {
|
|
218
217
|
resultTables.push(resultsTable);
|
package/dist/cmds/new-test.js
CHANGED
|
@@ -5,9 +5,7 @@ const core_1 = require("@miqro/core");
|
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const testTemplates = {
|
|
8
|
-
js: (category) => `const
|
|
9
|
-
|
|
10
|
-
const options = {
|
|
8
|
+
js: (category) => `const options = {
|
|
11
9
|
category: "${category}",
|
|
12
10
|
before: async () => {
|
|
13
11
|
|
package/dist/cmds/new.js
CHANGED
|
@@ -4,6 +4,12 @@ exports.mainTS = exports.mainJS = void 0;
|
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
+
const gitignoreTemplate = {
|
|
8
|
+
ts: () => `node_modules/
|
|
9
|
+
dist/
|
|
10
|
+
`,
|
|
11
|
+
js: () => `node_modules/`
|
|
12
|
+
};
|
|
7
13
|
const packageTemplate = {
|
|
8
14
|
ts: (name) => `{
|
|
9
15
|
"name": "${name}",
|
|
@@ -95,6 +101,10 @@ const mainJS = (typescript = false) => {
|
|
|
95
101
|
(0, utils_1.execSync)(`npm install @types/node --save-dev`, {
|
|
96
102
|
cwd: appFolder
|
|
97
103
|
});
|
|
104
|
+
(0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, ".gitignore"), gitignoreTemplate.ts());
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
(0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, ".gitignore"), gitignoreTemplate.js());
|
|
98
108
|
}
|
|
99
109
|
(0, utils_1.execSync)(`npm install @miqro/test --save-dev`, {
|
|
100
110
|
cwd: appFolder
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const main: () => void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.main = void 0;
|
|
4
|
+
const core_1 = require("@miqro/core");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
const tokenize_match_1 = require("@miqro/core/dist/common/tokenize-match");
|
|
8
|
+
const main = () => {
|
|
9
|
+
const flags = (0, utils_1.extractFlags)(process.argv.slice(3), {
|
|
10
|
+
flags: {
|
|
11
|
+
"proxy": {
|
|
12
|
+
description: "proxy",
|
|
13
|
+
hasValue: true
|
|
14
|
+
},
|
|
15
|
+
"proxy-cert-ignore": {
|
|
16
|
+
description: "proxy ignore certs",
|
|
17
|
+
hasValue: false
|
|
18
|
+
},
|
|
19
|
+
"port": {
|
|
20
|
+
description: "port",
|
|
21
|
+
hasValue: true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (flags.files.length > 2) {
|
|
26
|
+
throw new Error(`invalid number of args\nusage: [PORT=8080] npx miqro serve [directory=./] [path=/]`);
|
|
27
|
+
}
|
|
28
|
+
if (flags.flags.port instanceof Array) {
|
|
29
|
+
throw new Error(`invalid number of args\nusage: [PORT=8080] npx miqro serve [directory=./] [path=/] [--port 8080] [--proxy /api=https://host/api]`);
|
|
30
|
+
}
|
|
31
|
+
let [directory, path] = flags.files;
|
|
32
|
+
path = path ? path : "/";
|
|
33
|
+
directory = directory ? directory : process.cwd();
|
|
34
|
+
(0, core_1.loadConfig)();
|
|
35
|
+
const PORT = flags.flags.port ? flags.flags.port : (process.env.PORT ? process.env.PORT : 8080);
|
|
36
|
+
if (PORT === undefined) {
|
|
37
|
+
throw new Error("port not defined");
|
|
38
|
+
}
|
|
39
|
+
const app = new core_1.App();
|
|
40
|
+
app.use((0, core_1.LoggerHandler)());
|
|
41
|
+
const proxyList = flags.flags.proxy instanceof Array ? flags.flags.proxy : [flags.flags.proxy];
|
|
42
|
+
for (const proxy of proxyList) {
|
|
43
|
+
if (proxy) {
|
|
44
|
+
const proxySplit = proxy.split("=");
|
|
45
|
+
if (proxySplit.length !== 2) {
|
|
46
|
+
throw new Error("proxy must be in the form. /path=proxy");
|
|
47
|
+
}
|
|
48
|
+
const proxyPath = (0, tokenize_match_1.normalizePath)(proxySplit[0]);
|
|
49
|
+
const proxyURL = new url_1.URL(proxySplit[1]);
|
|
50
|
+
proxyURL.pathname = (0, tokenize_match_1.normalizePath)(proxyURL.pathname);
|
|
51
|
+
app.use((0, core_1.ReadBuffer)());
|
|
52
|
+
app.use((0, core_1.Proxy)({
|
|
53
|
+
url: proxyURL.toString(),
|
|
54
|
+
rejectUnauthorized: !flags.flags.hasOwnProperty("proxy-cert-ignore")
|
|
55
|
+
}), proxyPath);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
app.use((0, core_1.Static)({
|
|
59
|
+
directory,
|
|
60
|
+
list: true
|
|
61
|
+
}), path);
|
|
62
|
+
app.listen(PORT, () => {
|
|
63
|
+
console.log("serving " + directory + " on " + path + " on port " + PORT);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
exports.main = main;
|
package/dist/utils/db/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const fs_1 = require("fs");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const templates_1 = require("../../utils/templates");
|
|
8
8
|
const core_1 = require("@miqro/core");
|
|
9
|
+
const parser_1 = require("@miqro/parser");
|
|
9
10
|
const logger = console;
|
|
10
11
|
const loadSequelizeRC = (sequelizercPath = core_1.ConfigPathResolver.getSequelizeRCFilePath(), logger) => {
|
|
11
12
|
// noinspection SpellCheckingInspection
|
|
@@ -20,12 +21,12 @@ const loadSequelizeRC = (sequelizercPath = core_1.ConfigPathResolver.getSequeliz
|
|
|
20
21
|
// noinspection SpellCheckingInspection
|
|
21
22
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
22
23
|
const sequelizerc = require(sequelizercPath);
|
|
23
|
-
return (0,
|
|
24
|
+
return (0, parser_1.parse)(sequelizerc, [
|
|
24
25
|
{ name: "config", type: "string", required: true },
|
|
25
26
|
{ name: "migrations-path", type: "string", required: true },
|
|
26
27
|
{ name: "seeders-path", type: "string", required: true },
|
|
27
28
|
{ name: "models-path", type: "string", required: true }
|
|
28
|
-
], "no_extra");
|
|
29
|
+
], "no_extra", sequelizercPath);
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
32
|
exports.loadSequelizeRC = loadSequelizeRC;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GroupPolicy, Logger, Method, SessionHandlerOptions } from "@miqro/core";
|
|
2
|
+
import { ParseOptions } from "@miqro/parser";
|
|
2
3
|
export declare const getDOCJSON: ({ dirname, subPath }: {
|
|
3
4
|
dirname: string;
|
|
4
5
|
subPath: string;
|
|
@@ -9,9 +10,9 @@ export declare const getDOCJSON: ({ dirname, subPath }: {
|
|
|
9
10
|
policy?: GroupPolicy;
|
|
10
11
|
headers?: ParseOptions | ParseOptions[];
|
|
11
12
|
session?: false | true | SessionHandlerOptions;
|
|
12
|
-
params?:
|
|
13
|
-
query?:
|
|
14
|
-
body?:
|
|
15
|
-
|
|
13
|
+
params?: boolean | ParseOptions | ParseOptions[] | string;
|
|
14
|
+
query?: boolean | ParseOptions | ParseOptions[] | string;
|
|
15
|
+
body?: boolean | ParseOptions | ParseOptions[] | string;
|
|
16
|
+
response?: ParseOptions | ParseOptions[] | string;
|
|
16
17
|
featureName: string;
|
|
17
18
|
}[];
|
package/dist/utils/doc/index.js
CHANGED
|
@@ -8,8 +8,17 @@ 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
10
|
const { path, method, options } = apiTraverse[featureName];
|
|
11
|
-
const { session, policy, description } = options ? options : {
|
|
12
|
-
|
|
11
|
+
const { session, policy, description } = options ? options : {
|
|
12
|
+
session: undefined,
|
|
13
|
+
policy: undefined,
|
|
14
|
+
description: undefined
|
|
15
|
+
};
|
|
16
|
+
const { params, query, body, headers } = options && options.request ? options.request : {
|
|
17
|
+
params: undefined,
|
|
18
|
+
query: undefined,
|
|
19
|
+
body: undefined,
|
|
20
|
+
headers: undefined
|
|
21
|
+
};
|
|
13
22
|
const result = options && options.response !== true ? options.response : undefined;
|
|
14
23
|
return {
|
|
15
24
|
path,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miqro",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
"author": "claukers",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@miqro/core": "^1.5.
|
|
21
|
-
"@miqro/
|
|
22
|
-
"@miqro/
|
|
20
|
+
"@miqro/core": "^1.5.8",
|
|
21
|
+
"@miqro/parser": "^0.0.3",
|
|
22
|
+
"@miqro/runner": "^1.2.5",
|
|
23
|
+
"@miqro/test": "^0.0.10",
|
|
23
24
|
"deep-diff": "1.0.2"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|