mas-server 3.0.2 → 3.0.3

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.
@@ -1,81 +1,81 @@
1
- import { getType } from "../utils/masUtils";
2
-
3
- type BasicTypeDescriptor =
4
- | StringConstructor
5
- | NumberConstructor
6
- | BooleanConstructor
7
- | ObjectConstructor;
8
- type TypeDescriptor = BasicTypeDescriptor | Array<any>;
9
-
10
- interface TypeMapping {
11
- [key: string]:
12
- | TypeDescriptor
13
- | TypeMapping
14
- | Array<TypeDescriptor | TypeMapping>;
15
- }
16
- const vliadBase = (obj, typeMapping) => {
17
- return getType(obj) == (typeMapping as any).name.toLowerCase();
18
- };
19
- const validTypeObj = (obj: any, typeMapping: TypeMapping | TypeDescriptor) => {
20
- if (obj === null || obj === undefined) return false;
21
- let typeT = getType(typeMapping);
22
- if (typeT == "function") {
23
- return vliadBase(obj, typeMapping);
24
- } else if (typeT == "object") {
25
- if (getType(obj) !== "object") return false;
26
- for (let k in typeMapping) {
27
- if (obj[k] === null || obj[k] === undefined) return false;
28
- if (!validType(obj[k], typeMapping[k])) return false;
29
- }
30
- } else if (typeT == "array") {
31
- if (getType(obj) != "array") return false;
32
- if (obj.length === 0) return false;
33
- const typeMappingArrObj = typeMapping[0];
34
- if (!typeMappingArrObj) {
35
- throw new Error(`非法的效验格式 ${typeMapping} ${typeMappingArrObj}`);
36
- }
37
- if (getType(obj) != "array") return false;
38
- for (let v of obj) {
39
- if (!validTypeObj(v, typeMappingArrObj)) return false;
40
- }
41
- }
42
- return true;
43
- };
44
- const validTypeObjStrict = (
45
- obj: any,
46
- typeMapping: TypeMapping | TypeDescriptor
47
- ) => {
48
- if (obj === null || obj === undefined) return false;
49
- let typeT = getType(typeMapping);
50
- if (typeT == "function") {
51
- return vliadBase(obj, typeMapping);
52
- } else if (typeT == "object") {
53
- if (getType(obj) !== "object") return false;
54
- if (Object.keys(obj).length != Object.keys(typeT).length) return false;
55
- for (let k in typeMapping) {
56
- if (obj[k] === null || obj[k] === undefined) return false;
57
- if (!validType(obj[k], typeMapping[k])) return false;
58
- }
59
- } else if (typeT == "array") {
60
- if (getType(obj) != "array") return false;
61
- if (obj.length === 0) return false;
62
- const typeMappingArrObj = typeMapping[0];
63
- if (!typeMappingArrObj) {
64
- throw new Error(`非法的效验格式 ${typeMapping} ${typeMappingArrObj}`);
65
- }
66
- if (getType(obj) != "array") return false;
67
- for (let v of obj) {
68
- if (!validTypeObj(v, typeMappingArrObj)) return false;
69
- }
70
- }
71
- return true;
72
- };
73
- export default function validType(
74
- obj: any,
75
- typeMapping: TypeMapping | TypeDescriptor,
76
- strict: boolean = false
77
- ): boolean {
78
- return strict
79
- ? validTypeObjStrict(obj, typeMapping)
80
- : validTypeObj(obj, typeMapping);
81
- }
1
+ import { getType } from "../utils/masUtils";
2
+
3
+ type BasicTypeDescriptor =
4
+ | StringConstructor
5
+ | NumberConstructor
6
+ | BooleanConstructor
7
+ | ObjectConstructor;
8
+ type TypeDescriptor = BasicTypeDescriptor | Array<any>;
9
+
10
+ interface TypeMapping {
11
+ [key: string]:
12
+ | TypeDescriptor
13
+ | TypeMapping
14
+ | Array<TypeDescriptor | TypeMapping>;
15
+ }
16
+ const vliadBase = (obj, typeMapping) => {
17
+ return getType(obj) == (typeMapping as any).name.toLowerCase();
18
+ };
19
+ const validTypeObj = (obj: any, typeMapping: TypeMapping | TypeDescriptor) => {
20
+ if (obj === null || obj === undefined) return false;
21
+ let typeT = getType(typeMapping);
22
+ if (typeT == "function") {
23
+ return vliadBase(obj, typeMapping);
24
+ } else if (typeT == "object") {
25
+ if (getType(obj) !== "object") return false;
26
+ for (let k in typeMapping) {
27
+ if (obj[k] === null || obj[k] === undefined) return false;
28
+ if (!validType(obj[k], typeMapping[k])) return false;
29
+ }
30
+ } else if (typeT == "array") {
31
+ if (getType(obj) != "array") return false;
32
+ if (obj.length === 0) return false;
33
+ const typeMappingArrObj = typeMapping[0];
34
+ if (!typeMappingArrObj) {
35
+ throw new Error(`非法的效验格式 ${typeMapping} ${typeMappingArrObj}`);
36
+ }
37
+ if (getType(obj) != "array") return false;
38
+ for (let v of obj) {
39
+ if (!validTypeObj(v, typeMappingArrObj)) return false;
40
+ }
41
+ }
42
+ return true;
43
+ };
44
+ const validTypeObjStrict = (
45
+ obj: any,
46
+ typeMapping: TypeMapping | TypeDescriptor
47
+ ) => {
48
+ if (obj === null || obj === undefined) return false;
49
+ let typeT = getType(typeMapping);
50
+ if (typeT == "function") {
51
+ return vliadBase(obj, typeMapping);
52
+ } else if (typeT == "object") {
53
+ if (getType(obj) !== "object") return false;
54
+ if (Object.keys(obj).length != Object.keys(typeT).length) return false;
55
+ for (let k in typeMapping) {
56
+ if (obj[k] === null || obj[k] === undefined) return false;
57
+ if (!validType(obj[k], typeMapping[k])) return false;
58
+ }
59
+ } else if (typeT == "array") {
60
+ if (getType(obj) != "array") return false;
61
+ if (obj.length === 0) return false;
62
+ const typeMappingArrObj = typeMapping[0];
63
+ if (!typeMappingArrObj) {
64
+ throw new Error(`非法的效验格式 ${typeMapping} ${typeMappingArrObj}`);
65
+ }
66
+ if (getType(obj) != "array") return false;
67
+ for (let v of obj) {
68
+ if (!validTypeObj(v, typeMappingArrObj)) return false;
69
+ }
70
+ }
71
+ return true;
72
+ };
73
+ export default function validType(
74
+ obj: any,
75
+ typeMapping: TypeMapping | TypeDescriptor,
76
+ strict: boolean = false
77
+ ): boolean {
78
+ return strict
79
+ ? validTypeObjStrict(obj, typeMapping)
80
+ : validTypeObj(obj, typeMapping);
81
+ }
@@ -1,26 +1,26 @@
1
- import path from "path";
2
- import c from "ansi-colors";
3
- import * as fs from "fs";
4
- const createApiFile = (DIRNAME, tempPath) => {
5
- let argv = process.argv.slice(2);
6
- for (let dir of argv) {
7
- let dirname = dir;
8
- let dirpath: any = dir.split("/");
9
- dirpath = dirpath.slice(0, dirpath.length - 1).join("/");
10
- dir = path.join(DIRNAME, dir) + ".ts";
11
- dirpath = path.join(DIRNAME, dirpath);
12
- let isExist = fs.existsSync(dir);
13
- if (isExist) {
14
- console.info(c.yellow(`已存在!${dirname}`));
15
- continue;
16
- }
17
- isExist = fs.existsSync(dirpath);
18
- if (!isExist) fs.mkdirSync(dirpath, { recursive: true });
19
- fs.copyFileSync(tempPath, dir);
20
- console.info(c.green(`创建成功!${dirname}`));
21
- }
22
- };
23
- createApiFile(
24
- path.join(__dirname, "../src/api"),
25
- path.join(__dirname, "../apiTemplate/api.temp.ts")
26
- );
1
+ import path from "path";
2
+ import c from "ansi-colors";
3
+ import * as fs from "fs";
4
+ const createApiFile = (DIRNAME, tempPath) => {
5
+ let argv = process.argv.slice(2);
6
+ for (let dir of argv) {
7
+ let dirname = dir;
8
+ let dirpath: any = dir.split("/");
9
+ dirpath = dirpath.slice(0, dirpath.length - 1).join("/");
10
+ dir = path.join(DIRNAME, dir) + ".ts";
11
+ dirpath = path.join(DIRNAME, dirpath);
12
+ let isExist = fs.existsSync(dir);
13
+ if (isExist) {
14
+ console.info(c.yellow(`已存在!${dirname}`));
15
+ continue;
16
+ }
17
+ isExist = fs.existsSync(dirpath);
18
+ if (!isExist) fs.mkdirSync(dirpath, { recursive: true });
19
+ fs.copyFileSync(tempPath, dir);
20
+ console.info(c.green(`创建成功!${dirname}`));
21
+ }
22
+ };
23
+ createApiFile(
24
+ path.join(__dirname, "../src/api"),
25
+ path.join(__dirname, "../apiTemplate/api.temp.ts")
26
+ );
@@ -1,4 +1,4 @@
1
- // 先写入api.config.js和api.key.js
2
- import "./beforeCreated";
3
- // 运行express
4
- import "../main";
1
+ // 先写入api.config.js和api.key.js
2
+ import "./beforeCreated";
3
+ // 运行express
4
+ import "../main";
package/test/src/debug.ts CHANGED
@@ -2,4 +2,4 @@ import validType from "@/utils/validType";
2
2
  import axios from "axios";
3
3
  import * as sqlform from "./sqlform.json";
4
4
  import { createToken, getApiRouter } from "@/index";
5
- // console.log(getApiRouter(), "路由信息");
5
+ console.log(getApiRouter(), "路由信息");
package/test/test.ts CHANGED
@@ -1 +1 @@
1
- import "module-alias/register";
1
+ import "module-alias/register";
package/tsconfig.json CHANGED
@@ -1,21 +1,21 @@
1
- {
2
- "$schema": "./tsconfigschema.json",
3
- "compilerOptions": {
4
- // "noUnusedLocals": true,
5
- // "noUnusedParameters": true,
6
- "strict": false,
7
- "module": "commonjs",
8
- "moduleResolution": "node",
9
- "esModuleInterop": true,
10
- "baseUrl": "./",
11
- "outDir": "dist",
12
- "paths": {
13
- "@/*": ["src/*"],
14
- "@@/*": ["./*"]
15
- },
16
- "target": "es6",
17
- "lib": ["ES2021", "dom"],
18
- "resolveJsonModule": true
19
- },
20
- "exclude": ["node_modules", "dist"]
21
- }
1
+ {
2
+ "$schema": "./tsconfigschema.json",
3
+ "compilerOptions": {
4
+ // "noUnusedLocals": true,
5
+ // "noUnusedParameters": true,
6
+ "strict": false,
7
+ "module": "commonjs",
8
+ "moduleResolution": "node",
9
+ "esModuleInterop": true,
10
+ "baseUrl": "./",
11
+ "outDir": "dist",
12
+ "paths": {
13
+ "@/*": ["src/*"],
14
+ "@@/*": ["./*"]
15
+ },
16
+ "target": "es6",
17
+ "lib": ["ES2021", "dom"],
18
+ "resolveJsonModule": true
19
+ },
20
+ "exclude": ["node_modules", "dist"]
21
+ }