mas-server 2.0.47 → 2.0.52

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 (74) hide show
  1. package/.temp/merge/validType.ts +98 -0
  2. package/beforebuild.js +3 -0
  3. package/dist/index.js +8 -47
  4. package/dist/utils/apiDoc.js +17 -2
  5. package/dist/utils/createRouter.js +51 -0
  6. package/dist/utils/getRouterInfo.js +34 -0
  7. package/dist/utils/mas-encrypt.min.js +1 -3072
  8. package/dist/utils/validRouteData.js +1 -1
  9. package/dist/utils/validToken.js +1 -1
  10. package/dist/utils/validType.js +0 -17
  11. package/package.json +50 -51
  12. package/src/index.ts +20 -24
  13. package/src/typings/index.ts +5 -5
  14. package/src/utils/apiDoc.ts +18 -2
  15. package/src/utils/createRouter.ts +22 -0
  16. package/src/utils/getRouterInfo.ts +28 -0
  17. package/src/utils/readApi.ts +0 -2
  18. package/src/utils/validRouteData.ts +1 -2
  19. package/src/utils/validToken.ts +1 -1
  20. package/src/utils/validType.ts +0 -17
  21. package/test/apiTemplate/api.temp.ts +8 -3
  22. package/test/config/config.ts +1 -1
  23. package/test/config/defaultApiConfig.ts +7 -0
  24. package/test/config/docNav.ts +0 -0
  25. package/test/main.ts +1 -0
  26. package/test/scripts/beforeCreated.ts +2 -41
  27. package/test/scripts/createApiFile.ts +0 -1
  28. package/test/scripts/createApis.ts +0 -48
  29. package/test/scripts/getSqlFormType.ts +2 -13
  30. package/test/src/api/example/ArrValid.ts +11 -0
  31. package/test/src/api/example/per.ts +34 -0
  32. package/test/src/api/example/tip.ts +9 -0
  33. package/test/src/api/example/validReqData.ts +85 -0
  34. package/test/src/api/index.ts +8 -1
  35. package/test/src/debug.ts +3 -50
  36. package/test/src/sqlform.json +1 -1
  37. package/test/test.ts +0 -12
  38. package/test//345/276/205/345/274/200/345/217/221.md +12 -6
  39. package/tsconfig-build.json +20 -0
  40. package/tsconfig.json +1 -3
  41. package/.temp/validType.ts +0 -96
  42. package/dist/apiDoc/assets/empty-a6de4920.js +0 -1
  43. package/dist/apiDoc/assets/index-be53fe8f.css +0 -6
  44. package/dist/apiDoc/assets/index-f9ab4187.js +0 -1427
  45. package/dist/apiDoc/assets/jsoneditor-icons-45c98bf0.svg +0 -749
  46. package/dist/apiDoc/favicon.ico +0 -0
  47. package/dist/apiDoc/index.html +0 -15
  48. package/dist/utils/getRouteByApiSrc.js +0 -54
  49. package/test/config/api.config.ts +0 -3
  50. package/test/config/api.key.ts +0 -14
  51. package/test/src/api/curd/student/del.ts +0 -9
  52. package/test/src/api/curd/student/get.ts +0 -9
  53. package/test/src/api/curd/student/set.ts +0 -9
  54. package/test/src/api/per.ts +0 -6
  55. package/test/src/api/person/del.ts +0 -4
  56. package/test/src/api/person/get.ts +0 -4
  57. package/test/src/api/person/set.ts +0 -4
  58. package/test/src/api/test.ts +0 -7
  59. package/test/src/api/validtest/boolArr.ts +0 -4
  60. package/test/typings/studentSF.ts +0 -6
  61. package/test/typings/test11SF.ts +0 -1
  62. package/test/typings/test22SF.ts +0 -1
  63. package/test/typings/testformSF.ts +0 -1
  64. /package/.temp/{logs/.keep → .keep} +0 -0
  65. /package/{src/utils → .temp}/getRouteByApiSrc.ts +0 -0
  66. /package/.temp/{a.ts → merge/a.ts} +0 -0
  67. /package/.temp/{as.ts → merge/as.ts} +0 -0
  68. /package/.temp/{b.ts → merge/b.ts} +0 -0
  69. /package/.temp/{i.js → merge/i.js} +0 -0
  70. /package/{test/typings → .temp/merge/logs}/.keep +0 -0
  71. /package/.temp/{test.ts → merge/test.ts} +0 -0
  72. /package/.temp/{validType copy.ts → merge/validType copy.ts} +0 -0
  73. /package/.temp/{validTypeOptimize.ts → merge/validTypeOptimize.ts} +0 -0
  74. /package/{test/scripts → .temp}/updateRouter.ts +0 -0
@@ -0,0 +1,9 @@
1
+ import type { apiConfigTypeItem, masReq, masRes } from "@/index";
2
+ import masState from "@@/test/src/masState";
3
+ // 编写createSqlFormData.ts && npm run createSqlForm
4
+ // npm run createApi example/newApi
5
+ // npm run createApis student /example 根据student表创建 /example/student/get /example/student/set ...
6
+ export default async (req: masReq, res: masRes) => {
7
+ const { sql } = masState;
8
+ res.return("hello mas-server!");
9
+ };
@@ -0,0 +1,85 @@
1
+ import type { apiConfigTypeItem, masReq, masRes } from "@/index";
2
+ import masState from "@@/test/src/masState";
3
+
4
+ export const config: apiConfigTypeItem = {
5
+ name: "数据效验及响应示例接口",
6
+ methods: "post",
7
+ validFormat: {
8
+ name: String,
9
+ age: Number,
10
+ grade: [{ name: String, score: Number }],
11
+ desc: String,
12
+ family: {
13
+ mother: {
14
+ name: String,
15
+ age: Number,
16
+ },
17
+ fahter: {
18
+ name: String,
19
+ age: Number,
20
+ },
21
+ },
22
+ },
23
+ // 效验严格模式,默认不开启,开启则不能携带额外参数
24
+ validFormatStrict: false,
25
+ // 接口文档的请求示例
26
+ example: {
27
+ extra: "这是一个额外参数,如果开启严格模式且带上这个参数将会不通过效验",
28
+ name: "小蔡",
29
+ age: 18,
30
+ grade: [{ name: "篮球", score: 99 }],
31
+ desc: "两年半",
32
+ family: {
33
+ mother: {
34
+ name: "母坤",
35
+ age: 40,
36
+ },
37
+ fahter: {
38
+ name: "公坤",
39
+ age: 40,
40
+ },
41
+ },
42
+ },
43
+ // 响应示例
44
+ resExample: {
45
+ msg: "",
46
+ status: 1,
47
+ data: "hello!练习两年半的程序员",
48
+ },
49
+ validFormatDes: [
50
+ {
51
+ name: "extra",
52
+ des: "额外的参数",
53
+ type: String,
54
+ },
55
+ {
56
+ name: "name",
57
+ des: "姓名",
58
+ },
59
+ {
60
+ name: "age",
61
+ des: "年龄",
62
+ },
63
+ {
64
+ name: "grade",
65
+ des: "成绩",
66
+ },
67
+ {
68
+ name: "family",
69
+ des: "家庭情况",
70
+ },
71
+ ],
72
+ des: "详细数据效验及响应示例接口",
73
+ header: [
74
+ {
75
+ name: "boom",
76
+ type: String,
77
+ des: "一个可不传的请求头参数",
78
+ optional: true,
79
+ },
80
+ ],
81
+ };
82
+ export default async (req: masReq, res: masRes) => {
83
+ const { sql } = masState;
84
+ res.return("hello!练习两年半的程序员");
85
+ };
@@ -1,4 +1,11 @@
1
- import type { masReq, masRes } from "@/index";
1
+ import type { apiConfigTypeItem, masReq, masRes } from "@/index";
2
+ import masState from "../masState";
3
+
4
+ export const config: apiConfigTypeItem = {
5
+ name: "默认接口",
6
+ methods: "all",
7
+ };
2
8
  export default async (req: masReq, res: masRes) => {
9
+ const { sql } = masState;
3
10
  res.return("hello mas-server!");
4
11
  };
package/test/src/debug.ts CHANGED
@@ -4,53 +4,6 @@ import masState from "./masState";
4
4
  import * as sqlform from "./sqlform.json";
5
5
  import { createToken } from "@/index";
6
6
  const { sql } = masState;
7
- sql.debugMode = 1;
8
- // console.log("请求 http://localhost:8087/api/index");
9
- // axios
10
- // .post(
11
- // "http://localhost:8087/api/index",
12
- // {
13
- // name: { g: [1], jd: true },
14
- // age: 1,
15
- // },
16
- // { headers: { key: "false" } }
17
- // )
18
- // .then((res) => {
19
- // console.log("返回数据", res.data);
20
- // });
21
-
22
- // axios
23
- // .get("http://localhost:8087/api/per", {
24
- // headers: {
25
- // // token: createToken({ data: { a: 1 }, permission: ["user", "admin"] }),
26
- // },
27
- // })
28
- // .then((res) => {
29
- // console.log(res.data);
30
- // })
31
- // .catch((res) => {
32
- // console.log(res, "@");
33
- // });
34
- // axios
35
- // .post("http://localhost:8087/api/test", [{ params: { name: "111" } }])
36
- // .then((res) => {
37
- // console.log(res.data);
38
- // })
39
- // .catch((res) => {
40
- // console.log(res, "@");
41
- // });
42
-
43
- // axios.get("http://127.0.0.1:8087/apidoc/router").then((res) => {
44
- // console.log(res.data);
45
- // });
46
- // const { sql } = masState;
47
- // sql.debugMode = 2;
48
- // sql.select().use(sqlform.student).key(["name", "age"]).go();
49
- // axios
50
- // .post("http://localhost:8087/api/curd/get")
51
- // .then((res) => {
52
- // console.log(res.data);
53
- // })
54
- // .catch((res) => {
55
- // console.log(res, "@");
56
- // });
7
+ if (sql && Number.isInteger(sql.debugMode)) {
8
+ sql.debugMode = 2;
9
+ }
@@ -1 +1 @@
1
- {"student":["age","create_time","des","id","is_delete","name","update_time","@!student"]}
1
+ {"student":["age","create_time","des","id","is_delete","name","update_time","@!student"],"teacher":["age","create_time","id","is_delete","name","sex","update_time","@!teacher"]}
package/test/test.ts CHANGED
@@ -1,13 +1 @@
1
1
  import "module-alias/register";
2
-
3
- // import { createToken, validToken } from "@/index";
4
- // const token = createToken({
5
- // time: 10,
6
- // permission: ["admin", "www"],
7
- // data: { a: 1, b: 2 },
8
- // });
9
- // setTimeout(() => {
10
- // const tokenInfo = validToken({ token, permission: ["user", "admin"] });
11
- // console.log(token);
12
- // console.log(tokenInfo);
13
- // }, 1000);
@@ -1,14 +1,20 @@
1
1
  约定式接口读取 完成
2
2
  数据效验 完成
3
3
  masmysql引入 (massql set方法开发) 完成
4
- 权限管理,token生成
4
+ 权限管理,token生成 完成
5
5
  接口文档生成 完成
6
- 快捷创建接口
6
+ 快捷创建接口 完成
7
7
  生成sql类型 完成
8
- 错误处理
8
+ 错误处理 完成
9
+ cookie管理
10
+ 路由导航汉化
11
+ 接口文档体验优化
12
+ .vscode配置
13
+ 一键导出前端axios代码
14
+ 接口加载状态
15
+ 导航点击跳转 调试->调试
9
16
  特别说明:
10
- get请求和请求头的number参数会被转为string
17
+ get请求和请求头的number参数会被转为string,get请求无法发送和接收数组
11
18
  接口改名配置丢失
12
- 数据效验只支持对象形式
13
19
  只能接收{}或[]
14
- cookie管理
20
+ 请求参数必须是对象或数组
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "./tsconfigschema.json",
3
+ "compilerOptions": {
4
+ "strict": false,
5
+ "module": "commonjs",
6
+ "moduleResolution": "node",
7
+ "esModuleInterop": true,
8
+ "baseUrl": "./",
9
+ "rootDir": "src",
10
+ "outDir": "dist",
11
+ "paths": {
12
+ "@/*": ["src/*"],
13
+ "@@/*": ["./*"]
14
+ },
15
+ "target": "es6",
16
+ "lib": ["ES2021", "dom"],
17
+ "resolveJsonModule": true
18
+ },
19
+ "exclude": ["node_modules", "dist", "test", ".temp","beforebuild.js"]
20
+ }
package/tsconfig.json CHANGED
@@ -8,8 +8,6 @@
8
8
  "moduleResolution": "node",
9
9
  "esModuleInterop": true,
10
10
  "baseUrl": "./",
11
-
12
- "rootDir": "src",
13
11
  "outDir": "dist",
14
12
  "paths": {
15
13
  "@/*": ["src/*"],
@@ -19,5 +17,5 @@
19
17
  "lib": ["ES2021", "dom"],
20
18
  "resolveJsonModule": true
21
19
  },
22
- "exclude": ["node_modules", "dist", "test"]
20
+ "exclude": ["node_modules", "dist"]
23
21
  }
@@ -1,96 +0,0 @@
1
- type BasicTypeDescriptor =
2
- | StringConstructor
3
- | NumberConstructor
4
- | BooleanConstructor
5
- | ObjectConstructor;
6
- type TypeDescriptor = BasicTypeDescriptor | Array<any>;
7
-
8
- interface TypeMapping {
9
- [key: string]:
10
- | TypeDescriptor
11
- | TypeMapping
12
- | Array<TypeDescriptor | TypeMapping>;
13
- }
14
-
15
- function getTypeName(descriptor: TypeDescriptor): string {
16
- if (Array.isArray(descriptor)) {
17
- return "array";
18
- } else {
19
- return (descriptor as BasicTypeDescriptor).name.toLowerCase();
20
- }
21
- }
22
-
23
- function validType(obj: any, typeMapping: TypeMapping): boolean {
24
- for (const key in typeMapping) {
25
- if (!obj.hasOwnProperty(key)) {
26
- return false;
27
- }
28
-
29
- const targetType = typeMapping[key];
30
- const objValue = obj[key];
31
-
32
- if (Array.isArray(targetType)) {
33
- if (!Array.isArray(objValue)) {
34
- return false;
35
- }
36
-
37
- const arrayElementType = targetType[0];
38
-
39
- for (const element of objValue) {
40
- if (typeof arrayElementType === "object") {
41
- if (
42
- !validType(element, arrayElementType as TypeMapping) ||
43
- Object.keys(element).length !==
44
- Object.keys(arrayElementType as TypeMapping).length
45
- ) {
46
- return false;
47
- }
48
- } else {
49
- if (
50
- typeof element !== getTypeName(arrayElementType as TypeDescriptor)
51
- ) {
52
- return false;
53
- }
54
- }
55
- }
56
- } else if (typeof targetType === "object") {
57
- if (
58
- typeof objValue !== "object" ||
59
- Array.isArray(objValue) ||
60
- !validType(objValue, targetType as TypeMapping) ||
61
- Object.keys(objValue).length !==
62
- Object.keys(targetType as TypeMapping).length
63
- ) {
64
- return false;
65
- }
66
- } else {
67
- if (typeof objValue !== getTypeName(targetType as TypeDescriptor)) {
68
- return false;
69
- }
70
- }
71
- }
72
-
73
- return true;
74
- }
75
-
76
- // 示例
77
- console.log(validType({ a: 1, b: "s" }, { a: Number, b: String })); // 返回true
78
- console.log(validType({ a: [1, 2, 3], b: "s" }, { a: [Number], b: String })); // 返回true
79
- console.log(
80
- validType(
81
- { a: [{ a: 1 }, { a: 1 }, { a: 1 }], b: "s" },
82
- { a: [{ b: Number }], b: String }
83
- )
84
- ); // 返回true
85
- console.log(
86
- validType(
87
- {
88
- a: [
89
- { a: "1", b: 22 },
90
- { a: "1", b: 1 },
91
- ],
92
- },
93
- { a: [{ a: String, b: Number, c: Number }] }
94
- )
95
- ); // 返回false
96
- export {};
@@ -1 +0,0 @@
1
- import{_ as e}from"./index-f9ab4187.js";const r={};function t(c,n){return null}const o=e(r,[["render",t]]);export{o as default};