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.
package/.temp/merge/a.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as fs from "fs";
2
- import path from "path";
3
- fs.writeFileSync(path.join(__dirname, "as.ts"), `export default{name:"test"}`);
4
- export {};
1
+ import * as fs from "fs";
2
+ import path from "path";
3
+ fs.writeFileSync(path.join(__dirname, "as.ts"), `export default{name:"test"}`);
4
+ export {};
package/.temp/merge/b.ts CHANGED
@@ -1,3 +1,3 @@
1
- import test from "./as";
2
- console.log(test);
3
- export {};
1
+ import test from "./as";
2
+ console.log(test);
3
+ export {};
package/.temp/merge/i.js CHANGED
@@ -1,103 +1,103 @@
1
- const express = require("express");
2
- const formidable = require('express-formidable');
3
- const cors = require('cors');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const { tip } = require("masutils");
7
- const configSchema = require('./config/config.schema');
8
- const state = require("./state");
9
- const beforeIndex = require('./utils/beforeCreate');
10
- const masmysql = require('masmysql');
11
- const { sql, setSqlConfig, getSqlFormKey } = require('masmysql');
12
- const createSqlForm = require("./utils/createSqlForm");
13
- const getDir = require("./utils/getDir");
14
- const createApi = require("./utils/createApi");
15
- const createApiFile = require("./utils/createApiFile");
16
- const createForm = (dirname) => {
17
- const config = require(path.join(dirname, "/config", "config.js"));
18
- const form = require(path.join(dirname, "/config", "/sqlform.config.js"));
19
- createSqlForm(config.sql, form);
20
- };
21
- const createCode = (dirname) => {
22
- createApi(dirname);
23
- };
24
- const createApis = (dirname) => {
25
- createApiFile(dirname);
26
- };
27
- let token = null;
28
- const getApp = (dirname) => {
29
- const app = express();
30
- const config = require(path.join(dirname, "/config", "config.js"));
31
- state.config = config;
32
- state.dirname = dirname;
33
- // 工具包
34
- const logs = require("./utils/logs");
35
- const quickSend = require('./utils/quickSend');
36
- token = require("./utils/token");
37
- const DataVerified = require("./utils/DataVerified");
38
- const masDoc = require("./utils/masDoc");
39
- const apiConfig = require(path.join(dirname, "/config", "/api.config.json"));
40
- // 处理数据库
41
- config.useSql && setSqlConfig(config.sql);
42
- config.useSql && sql.init();
43
- config.useSql && getSqlFormKey(dirname + "/src/$form.js");
44
- // 处理express
45
- config.cors && app.use(cors());
46
- app.use('/public', express.static(path.join(dirname, "/public")));
47
- config.apidoc && app.use('/masPublic', express.static(path.join(__dirname, "/public")));;
48
- app.use(formidable());
49
- app.use(quickSend);
50
- config.logs.open && app.use(require('express-ip')().getIpInfoMiddleware);
51
- config.logs.open && app.use(logs);
52
- config.token.open && app.use(token._main);
53
- app.use(DataVerified);
54
- masDoc(app, config);
55
- getDir('/api').map(item => {
56
- let model = require(dirname + `/src/${item}`);
57
- if (typeof model === "function") {
58
- if (apiConfig[item] && apiConfig[item].methods) {
59
- app[apiConfig[item].methods](item, model);
60
- } else {
61
- app.all(item, model);
62
- }
63
- }
64
- });
65
- app.all('/', async (req, res) => {
66
- const index = require(path.join(dirname, "/src/api", "index.js"));
67
- index(req, res);
68
- });
69
- app.all('*', (req, res) => {
70
- res.return(404, 0, 404);
71
- });
72
- setTimeout(() => {
73
- try {
74
- require(path.join(dirname + '/src/debug.js'));
75
- } catch (error) {
76
- tip("debug.js报错!!!");
77
- tip(error);
78
- }
79
- }, 1000);
80
- return app;
81
- };
82
- /**
83
- * @desc: 生成token
84
- * @param {*} data 要放入token的数据
85
- * @param {string} permission 角色权限
86
- * @param {number} time token过期时间,设置此项传入数据必须为json数据,单位为s,默认为0,不过期
87
- * @return {*}
88
- */
89
- function createToken(data, permission, time) {
90
- return token.createToken(data, time, permission, state.config);
91
- }
92
- module.exports = {
93
- getApp,
94
- configSchema: configSchema.configSchema,
95
- $sqlForm: configSchema.$sqlForm,
96
- beforeIndex,
97
- masmysql,
98
- createToken,
99
- sql,
100
- createForm,
101
- createCode,
102
- createApis
1
+ const express = require("express");
2
+ const formidable = require('express-formidable');
3
+ const cors = require('cors');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { tip } = require("masutils");
7
+ const configSchema = require('./config/config.schema');
8
+ const state = require("./state");
9
+ const beforeIndex = require('./utils/beforeCreate');
10
+ const masmysql = require('masmysql');
11
+ const { sql, setSqlConfig, getSqlFormKey } = require('masmysql');
12
+ const createSqlForm = require("./utils/createSqlForm");
13
+ const getDir = require("./utils/getDir");
14
+ const createApi = require("./utils/createApi");
15
+ const createApiFile = require("./utils/createApiFile");
16
+ const createForm = (dirname) => {
17
+ const config = require(path.join(dirname, "/config", "config.js"));
18
+ const form = require(path.join(dirname, "/config", "/sqlform.config.js"));
19
+ createSqlForm(config.sql, form);
20
+ };
21
+ const createCode = (dirname) => {
22
+ createApi(dirname);
23
+ };
24
+ const createApis = (dirname) => {
25
+ createApiFile(dirname);
26
+ };
27
+ let token = null;
28
+ const getApp = (dirname) => {
29
+ const app = express();
30
+ const config = require(path.join(dirname, "/config", "config.js"));
31
+ state.config = config;
32
+ state.dirname = dirname;
33
+ // 工具包
34
+ const logs = require("./utils/logs");
35
+ const quickSend = require('./utils/quickSend');
36
+ token = require("./utils/token");
37
+ const DataVerified = require("./utils/DataVerified");
38
+ const masDoc = require("./utils/masDoc");
39
+ const apiConfig = require(path.join(dirname, "/config", "/api.config.json"));
40
+ // 处理数据库
41
+ config.useSql && setSqlConfig(config.sql);
42
+ config.useSql && sql.init();
43
+ config.useSql && getSqlFormKey(dirname + "/src/$form.js");
44
+ // 处理express
45
+ config.cors && app.use(cors());
46
+ app.use('/public', express.static(path.join(dirname, "/public")));
47
+ config.apidoc && app.use('/masPublic', express.static(path.join(__dirname, "/public")));;
48
+ app.use(formidable());
49
+ app.use(quickSend);
50
+ config.logs.open && app.use(require('express-ip')().getIpInfoMiddleware);
51
+ config.logs.open && app.use(logs);
52
+ config.token.open && app.use(token._main);
53
+ app.use(DataVerified);
54
+ masDoc(app, config);
55
+ getDir('/api').map(item => {
56
+ let model = require(dirname + `/src/${item}`);
57
+ if (typeof model === "function") {
58
+ if (apiConfig[item] && apiConfig[item].methods) {
59
+ app[apiConfig[item].methods](item, model);
60
+ } else {
61
+ app.all(item, model);
62
+ }
63
+ }
64
+ });
65
+ app.all('/', async (req, res) => {
66
+ const index = require(path.join(dirname, "/src/api", "index.js"));
67
+ index(req, res);
68
+ });
69
+ app.all('*', (req, res) => {
70
+ res.return(404, 0, 404);
71
+ });
72
+ setTimeout(() => {
73
+ try {
74
+ require(path.join(dirname + '/src/debug.js'));
75
+ } catch (error) {
76
+ tip("debug.js报错!!!");
77
+ tip(error);
78
+ }
79
+ }, 1000);
80
+ return app;
81
+ };
82
+ /**
83
+ * @desc: 生成token
84
+ * @param {*} data 要放入token的数据
85
+ * @param {string} permission 角色权限
86
+ * @param {number} time token过期时间,设置此项传入数据必须为json数据,单位为s,默认为0,不过期
87
+ * @return {*}
88
+ */
89
+ function createToken(data, permission, time) {
90
+ return token.createToken(data, time, permission, state.config);
91
+ }
92
+ module.exports = {
93
+ getApp,
94
+ configSchema: configSchema.configSchema,
95
+ $sqlForm: configSchema.$sqlForm,
96
+ beforeIndex,
97
+ masmysql,
98
+ createToken,
99
+ sql,
100
+ createForm,
101
+ createCode,
102
+ createApis
103
103
  };
@@ -1,2 +1,2 @@
1
- import "./a";
2
- import "./b";
1
+ import "./a";
2
+ import "./b";
@@ -1,149 +1,149 @@
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
- import { getType } from "../src/utils/masUtils";
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 validTypeObj(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
-
31
- const objValue = obj[key];
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 (!validType(element, arrayElementType as TypeMapping)) {
42
- return false;
43
- }
44
- } else {
45
- if (
46
- typeof element !== getTypeName(arrayElementType as TypeDescriptor)
47
- ) {
48
- return false;
49
- }
50
- }
51
- }
52
- } else if (typeof targetType === "object") {
53
- if (
54
- typeof objValue !== "object" ||
55
- Array.isArray(objValue) ||
56
- !validType(objValue, targetType as TypeMapping)
57
- ) {
58
- return false;
59
- }
60
- } else {
61
- if (typeof objValue !== getTypeName(targetType as TypeDescriptor)) {
62
- return false;
63
- }
64
- }
65
- }
66
-
67
- return true;
68
- }
69
- function validTypeObjStrict(obj: any, typeMapping: TypeMapping): boolean {
70
- if (getType(typeMapping) == "object") {
71
- if (getType(obj) != "object") return false;
72
- if (Object.keys(obj).length != Object.keys(typeMapping).length) {
73
- return false;
74
- }
75
- }
76
-
77
- for (const key in typeMapping) {
78
- if (!obj?.hasOwnProperty(key)) {
79
- return false;
80
- }
81
-
82
- const targetType = typeMapping[key];
83
- const objValue = obj[key];
84
-
85
- if (Array.isArray(targetType)) {
86
- if (!Array.isArray(objValue)) {
87
- return false;
88
- }
89
-
90
- const arrayElementType = targetType[0];
91
-
92
- for (const element of objValue) {
93
- if (typeof arrayElementType === "object") {
94
- if (
95
- !validType(element, arrayElementType as TypeMapping) ||
96
- Object.keys(element).length !==
97
- Object.keys(arrayElementType as TypeMapping).length
98
- ) {
99
- return false;
100
- }
101
- } else {
102
- if (
103
- typeof element !== getTypeName(arrayElementType as TypeDescriptor)
104
- ) {
105
- return false;
106
- }
107
- }
108
- }
109
- } else if (typeof targetType === "object") {
110
- if (
111
- typeof objValue !== "object" ||
112
- Array.isArray(objValue) ||
113
- !validType(objValue, targetType as TypeMapping) ||
114
- Object.keys(objValue).length !==
115
- Object.keys(targetType as TypeMapping).length
116
- ) {
117
- return false;
118
- }
119
- } else {
120
- if (typeof objValue !== getTypeName(targetType as TypeDescriptor)) {
121
- return false;
122
- }
123
- }
124
- }
125
-
126
- return true;
127
- }
128
-
129
- export default function validType(
130
- obj: any,
131
- typeMapping: TypeMapping | TypeDescriptor,
132
- strict: boolean = false
133
- ): boolean {
134
- if (getType(typeMapping) == "function") {
135
- const typeT = typeMapping.toString().split(" ")[1].trimEnd();
136
- if (typeT == "Boolean()") {
137
- return getType(obj) == "boolean";
138
- } else if (typeT == "Number()") {
139
- return getType(obj) == "number";
140
- } else if (typeT == "String()") {
141
- return getType(obj) == "string";
142
- }
143
- } else {
144
- return strict
145
- ? validTypeObjStrict(obj, typeMapping as any)
146
- : validTypeObj(obj, typeMapping as any);
147
- }
148
- return false;
149
- }
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
+ import { getType } from "../src/utils/masUtils";
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 validTypeObj(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
+
31
+ const objValue = obj[key];
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 (!validType(element, arrayElementType as TypeMapping)) {
42
+ return false;
43
+ }
44
+ } else {
45
+ if (
46
+ typeof element !== getTypeName(arrayElementType as TypeDescriptor)
47
+ ) {
48
+ return false;
49
+ }
50
+ }
51
+ }
52
+ } else if (typeof targetType === "object") {
53
+ if (
54
+ typeof objValue !== "object" ||
55
+ Array.isArray(objValue) ||
56
+ !validType(objValue, targetType as TypeMapping)
57
+ ) {
58
+ return false;
59
+ }
60
+ } else {
61
+ if (typeof objValue !== getTypeName(targetType as TypeDescriptor)) {
62
+ return false;
63
+ }
64
+ }
65
+ }
66
+
67
+ return true;
68
+ }
69
+ function validTypeObjStrict(obj: any, typeMapping: TypeMapping): boolean {
70
+ if (getType(typeMapping) == "object") {
71
+ if (getType(obj) != "object") return false;
72
+ if (Object.keys(obj).length != Object.keys(typeMapping).length) {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ for (const key in typeMapping) {
78
+ if (!obj?.hasOwnProperty(key)) {
79
+ return false;
80
+ }
81
+
82
+ const targetType = typeMapping[key];
83
+ const objValue = obj[key];
84
+
85
+ if (Array.isArray(targetType)) {
86
+ if (!Array.isArray(objValue)) {
87
+ return false;
88
+ }
89
+
90
+ const arrayElementType = targetType[0];
91
+
92
+ for (const element of objValue) {
93
+ if (typeof arrayElementType === "object") {
94
+ if (
95
+ !validType(element, arrayElementType as TypeMapping) ||
96
+ Object.keys(element).length !==
97
+ Object.keys(arrayElementType as TypeMapping).length
98
+ ) {
99
+ return false;
100
+ }
101
+ } else {
102
+ if (
103
+ typeof element !== getTypeName(arrayElementType as TypeDescriptor)
104
+ ) {
105
+ return false;
106
+ }
107
+ }
108
+ }
109
+ } else if (typeof targetType === "object") {
110
+ if (
111
+ typeof objValue !== "object" ||
112
+ Array.isArray(objValue) ||
113
+ !validType(objValue, targetType as TypeMapping) ||
114
+ Object.keys(objValue).length !==
115
+ Object.keys(targetType as TypeMapping).length
116
+ ) {
117
+ return false;
118
+ }
119
+ } else {
120
+ if (typeof objValue !== getTypeName(targetType as TypeDescriptor)) {
121
+ return false;
122
+ }
123
+ }
124
+ }
125
+
126
+ return true;
127
+ }
128
+
129
+ export default function validType(
130
+ obj: any,
131
+ typeMapping: TypeMapping | TypeDescriptor,
132
+ strict: boolean = false
133
+ ): boolean {
134
+ if (getType(typeMapping) == "function") {
135
+ const typeT = typeMapping.toString().split(" ")[1].trimEnd();
136
+ if (typeT == "Boolean()") {
137
+ return getType(obj) == "boolean";
138
+ } else if (typeT == "Number()") {
139
+ return getType(obj) == "number";
140
+ } else if (typeT == "String()") {
141
+ return getType(obj) == "string";
142
+ }
143
+ } else {
144
+ return strict
145
+ ? validTypeObjStrict(obj, typeMapping as any)
146
+ : validTypeObj(obj, typeMapping as any);
147
+ }
148
+ return false;
149
+ }