nsgm-cli 2.1.19 → 2.1.21
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/client/components/Button.tsx +3 -3
- package/client/components/ClientProviders.tsx +12 -12
- package/client/components/LanguageSwitcher.tsx +26 -26
- package/client/components/SSRSafeAntdProvider.tsx +7 -7
- package/client/components/SuppressHydrationWarnings.tsx +30 -30
- package/client/components/__tests__/Button.test.tsx +12 -12
- package/client/layout/index.tsx +124 -124
- package/client/redux/reducers.ts +2 -2
- package/client/redux/store.ts +24 -24
- package/client/redux/template/manage/actions.ts +40 -40
- package/client/redux/template/manage/reducers.ts +32 -32
- package/client/redux/template/manage/types.ts +19 -19
- package/client/service/template/manage.ts +29 -29
- package/client/styled/common.ts +6 -6
- package/client/styled/layout/index.ts +17 -17
- package/client/styled/template/manage.ts +19 -19
- package/client/utils/common.ts +54 -54
- package/client/utils/cookie.ts +30 -30
- package/client/utils/fetch.ts +111 -111
- package/client/utils/i18n.ts +41 -41
- package/client/utils/menu.tsx +12 -12
- package/client/utils/navigation.ts +22 -22
- package/client/utils/sso.ts +124 -124
- package/client/utils/suppressWarnings.ts +17 -17
- package/generation/prettierrc +6 -0
- package/lib/args.js +19 -19
- package/lib/cli/app.d.ts +1 -1
- package/lib/cli/app.js +2 -2
- package/lib/cli/commands/build.d.ts +1 -1
- package/lib/cli/commands/build.js +9 -9
- package/lib/cli/commands/create.d.ts +1 -1
- package/lib/cli/commands/create.js +36 -36
- package/lib/cli/commands/delete.d.ts +1 -1
- package/lib/cli/commands/delete.js +55 -55
- package/lib/cli/commands/export.d.ts +1 -1
- package/lib/cli/commands/export.js +12 -12
- package/lib/cli/commands/help.d.ts +1 -1
- package/lib/cli/commands/help.js +29 -29
- package/lib/cli/commands/init.d.ts +1 -1
- package/lib/cli/commands/init.js +31 -31
- package/lib/cli/commands/server.d.ts +1 -1
- package/lib/cli/commands/server.js +12 -12
- package/lib/cli/commands/upgrade.d.ts +1 -1
- package/lib/cli/commands/upgrade.js +13 -13
- package/lib/cli/commands/version.d.ts +1 -1
- package/lib/cli/commands/version.js +7 -7
- package/lib/cli/index.d.ts +13 -13
- package/lib/cli/parser.d.ts +1 -1
- package/lib/cli/parser.js +12 -12
- package/lib/cli/registry.d.ts +1 -1
- package/lib/cli/types.d.ts +2 -2
- package/lib/cli/utils/console.d.ts +2 -2
- package/lib/cli/utils/console.js +22 -22
- package/lib/cli/utils/index.d.ts +2 -2
- package/lib/cli/utils/prompt.d.ts +1 -1
- package/lib/cli/utils/prompt.js +98 -98
- package/lib/constants.js +28 -28
- package/lib/generate.d.ts +2 -2
- package/lib/generate.js +19 -19
- package/lib/generate_create.d.ts +1 -1
- package/lib/generate_create.js +38 -38
- package/lib/generate_delete.js +63 -63
- package/lib/generate_init.js +94 -94
- package/lib/generators/base-generator.d.ts +1 -1
- package/lib/generators/base-generator.js +23 -23
- package/lib/generators/file-generator.js +15 -15
- package/lib/generators/generator-factory.d.ts +5 -5
- package/lib/generators/i18n-generator.d.ts +1 -1
- package/lib/generators/i18n-generator.js +127 -127
- package/lib/generators/page-generator.d.ts +1 -1
- package/lib/generators/page-generator.js +25 -25
- package/lib/generators/resolver-generator.d.ts +1 -1
- package/lib/generators/resolver-generator.js +27 -27
- package/lib/generators/schema-generator.d.ts +1 -1
- package/lib/generators/schema-generator.js +4 -4
- package/lib/generators/service-generator.d.ts +1 -1
- package/lib/generators/service-generator.js +29 -29
- package/lib/generators/sql-generator.d.ts +1 -1
- package/lib/generators/sql-generator.js +10 -10
- package/lib/index.js +23 -23
- package/lib/server/csrf.d.ts +3 -3
- package/lib/server/csrf.js +20 -20
- package/lib/server/db.d.ts +1 -1
- package/lib/server/db.js +21 -21
- package/lib/server/graphql.js +26 -26
- package/lib/server/plugins/date.d.ts +1 -1
- package/lib/server/plugins/date.js +6 -6
- package/lib/server/utils/graphql-cache.js +5 -5
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/utils/project-config.d.ts +1 -1
- package/lib/utils/project-config.js +20 -20
- package/lib/utils.js +3 -3
- package/package.json +1 -1
- package/pages/_app.tsx +62 -62
- package/pages/_document.tsx +15 -15
- package/pages/_error.tsx +26 -26
- package/pages/index.tsx +48 -48
- package/pages/login.tsx +64 -64
- package/pages/template/manage.tsx +175 -175
package/lib/server/db.js
CHANGED
|
@@ -17,7 +17,7 @@ const getMysqlConfig = () => {
|
|
|
17
17
|
mysqlConfig = require(curMysqlConfigPath);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
mysqlConfig = require(
|
|
20
|
+
mysqlConfig = require("../../mysql.config.js");
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
return mysqlConfig;
|
|
@@ -41,21 +41,21 @@ const createPool = ({ user, password, host, port, database }) => {
|
|
|
41
41
|
supportBigNumbers: true, // 支持大数字
|
|
42
42
|
});
|
|
43
43
|
// 监听连接池事件
|
|
44
|
-
pool.on(
|
|
45
|
-
console.log(
|
|
44
|
+
pool.on("connection", (connection) => {
|
|
45
|
+
console.log("数据库连接池新建连接:", connection.threadId);
|
|
46
46
|
});
|
|
47
|
-
pool.on(
|
|
48
|
-
console.error(
|
|
49
|
-
if (error.code ===
|
|
50
|
-
console.log(
|
|
47
|
+
pool.on("error", (error) => {
|
|
48
|
+
console.error("数据库连接池错误:", error);
|
|
49
|
+
if (error.code === "PROTOCOL_CONNECTION_LOST") {
|
|
50
|
+
console.log("数据库连接丢失,重新创建连接池");
|
|
51
51
|
pool = null;
|
|
52
52
|
createPool({ user, password, host, port, database });
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
|
-
console.log(
|
|
55
|
+
console.log("数据库连接池创建成功");
|
|
56
56
|
}
|
|
57
57
|
catch (error) {
|
|
58
|
-
console.error(
|
|
58
|
+
console.error("创建数据库连接池失败:", error);
|
|
59
59
|
throw error;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -70,7 +70,7 @@ const getPool = () => {
|
|
|
70
70
|
return createPool(mysqlOptions);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
throw new Error(
|
|
73
|
+
throw new Error("无法获取数据库配置");
|
|
74
74
|
};
|
|
75
75
|
// 执行查询(使用连接池)
|
|
76
76
|
const executeQuery = (sql, values = []) => {
|
|
@@ -80,7 +80,7 @@ const executeQuery = (sql, values = []) => {
|
|
|
80
80
|
// 使用 query 方法而不是 execute,更兼容各种SQL类型
|
|
81
81
|
poolInstance.query(sql, values, (error, results) => {
|
|
82
82
|
if (error) {
|
|
83
|
-
console.error(
|
|
83
|
+
console.error("SQL执行失败:", { sql, values, error: error.message });
|
|
84
84
|
reject(new Error(`SQL执行失败: ${error.message}`));
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
@@ -88,7 +88,7 @@ const executeQuery = (sql, values = []) => {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
catch (error) {
|
|
91
|
-
console.error(
|
|
91
|
+
console.error("获取数据库连接失败:", error);
|
|
92
92
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
93
93
|
reject(new Error(`数据库连接失败: ${errorMessage}`));
|
|
94
94
|
}
|
|
@@ -114,11 +114,11 @@ const closePool = () => {
|
|
|
114
114
|
if (pool) {
|
|
115
115
|
pool.end((error) => {
|
|
116
116
|
if (error) {
|
|
117
|
-
console.error(
|
|
117
|
+
console.error("关闭数据库连接池失败:", error);
|
|
118
118
|
reject(error);
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
|
-
console.log(
|
|
121
|
+
console.log("数据库连接池已关闭");
|
|
122
122
|
pool = null;
|
|
123
123
|
resolve();
|
|
124
124
|
}
|
|
@@ -132,7 +132,7 @@ const closePool = () => {
|
|
|
132
132
|
// 兼容旧的 getConnection 方法(已废弃,建议使用新的方法)
|
|
133
133
|
const mysqlConnect = ({ user, password, host, port, database }) => {
|
|
134
134
|
return new Promise((resolve, reject) => {
|
|
135
|
-
if (user !==
|
|
135
|
+
if (user !== "" && password !== "" && host !== "" && port !== 0 && database !== "") {
|
|
136
136
|
try {
|
|
137
137
|
const connection = mysql2_1.default.createConnection({ user, password, host, port, database });
|
|
138
138
|
connection.connect((err) => {
|
|
@@ -140,13 +140,13 @@ const mysqlConnect = ({ user, password, host, port, database }) => {
|
|
|
140
140
|
resolve(connection);
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
143
|
-
console.error(
|
|
143
|
+
console.error("err_mysqlConnect: ", err);
|
|
144
144
|
reject();
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
148
|
catch (e) {
|
|
149
|
-
console.error(
|
|
149
|
+
console.error("e_mysqlConnect: ", e);
|
|
150
150
|
reject();
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -166,20 +166,20 @@ const getConnection = () => {
|
|
|
166
166
|
mysqlConnect(mysqlOptions)
|
|
167
167
|
.then(resolve)
|
|
168
168
|
.catch((err) => {
|
|
169
|
-
console.error(
|
|
169
|
+
console.error("e_getConnection", err);
|
|
170
170
|
reject(err);
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
174
|
-
reject(new Error(
|
|
174
|
+
reject(new Error("localMysqlFlag is false"));
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
else {
|
|
178
|
-
reject(new Error(
|
|
178
|
+
reject(new Error("mysqlOptions is missing"));
|
|
179
179
|
}
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
|
-
return Promise.reject(new Error(
|
|
182
|
+
return Promise.reject(new Error("mysqlConfig is missing"));
|
|
183
183
|
};
|
|
184
184
|
exports.default = {
|
|
185
185
|
getMysqlConfig,
|
package/lib/server/graphql.js
CHANGED
|
@@ -12,9 +12,9 @@ const date_1 = __importDefault(require("./plugins/date"));
|
|
|
12
12
|
// 缓存已生成的 schema 和 resolvers
|
|
13
13
|
let cachedSchema = null;
|
|
14
14
|
let cachedResolvers = null;
|
|
15
|
-
const defaultPath = (0, path_1.resolve)(__dirname,
|
|
16
|
-
const typeDefFileName =
|
|
17
|
-
const resolverFileName =
|
|
15
|
+
const defaultPath = (0, path_1.resolve)(__dirname, "./modules/");
|
|
16
|
+
const typeDefFileName = "schema.js";
|
|
17
|
+
const resolverFileName = "resolver.js";
|
|
18
18
|
const curFolder = process.cwd();
|
|
19
19
|
const outModulesPath = (0, path_1.resolve)(`${curFolder}/server/modules/`);
|
|
20
20
|
const handleOutPlugins = () => {
|
|
@@ -31,7 +31,7 @@ const handleOutPlugins = () => {
|
|
|
31
31
|
return;
|
|
32
32
|
const stat = fs_1.default.statSync(resolverPath);
|
|
33
33
|
const isFile = stat.isFile();
|
|
34
|
-
if (isFile && (item.endsWith(
|
|
34
|
+
if (isFile && (item.endsWith(".js") || item.endsWith(".ts"))) {
|
|
35
35
|
const pluginModule = require(resolverPath);
|
|
36
36
|
result = {
|
|
37
37
|
...result,
|
|
@@ -41,28 +41,28 @@ const handleOutPlugins = () => {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
catch (error) {
|
|
44
|
-
console.warn(
|
|
44
|
+
console.warn("⚠️ Error loading plugins:", error);
|
|
45
45
|
}
|
|
46
46
|
return result;
|
|
47
47
|
};
|
|
48
48
|
function generateTypeDefsAndResolvers() {
|
|
49
49
|
// 如果已有缓存且在生产环境,直接返回缓存
|
|
50
|
-
if (process.env.NODE_ENV ===
|
|
50
|
+
if (process.env.NODE_ENV === "production" && cachedSchema && cachedResolvers) {
|
|
51
51
|
return {
|
|
52
52
|
schemaStr: cachedSchema,
|
|
53
53
|
resolvers: cachedResolvers,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
const querySchemes = [
|
|
57
|
-
const mutationSchemes = [
|
|
58
|
-
const subscriptionSchemes = [
|
|
56
|
+
const querySchemes = ["_: Boolean"];
|
|
57
|
+
const mutationSchemes = ["_: Boolean"];
|
|
58
|
+
const subscriptionSchemes = ["_: Boolean"];
|
|
59
59
|
const typeSchemes = [];
|
|
60
60
|
const resolvers = {
|
|
61
61
|
...date_1.default,
|
|
62
62
|
...handleOutPlugins(),
|
|
63
63
|
};
|
|
64
64
|
const scalars = lodash_1.default.keys(resolvers);
|
|
65
|
-
let scalarStr =
|
|
65
|
+
let scalarStr = "";
|
|
66
66
|
lodash_1.default.each(scalars, (item) => {
|
|
67
67
|
scalarStr += `scalar ${item}\n `;
|
|
68
68
|
});
|
|
@@ -87,13 +87,13 @@ function generateTypeDefsAndResolvers() {
|
|
|
87
87
|
if (schemaObj.default !== undefined)
|
|
88
88
|
schemaObj = schemaObj.default;
|
|
89
89
|
const { query, mutation, subscription, type } = schemaObj;
|
|
90
|
-
if (query && query !==
|
|
90
|
+
if (query && query !== "")
|
|
91
91
|
querySchemes.push(query);
|
|
92
|
-
if (mutation && mutation !==
|
|
92
|
+
if (mutation && mutation !== "")
|
|
93
93
|
mutationSchemes.push(mutation);
|
|
94
|
-
if (subscription && subscription !==
|
|
94
|
+
if (subscription && subscription !== "")
|
|
95
95
|
subscriptionSchemes.push(subscription);
|
|
96
|
-
if (type && type !==
|
|
96
|
+
if (type && type !== "")
|
|
97
97
|
typeSchemes.push(type);
|
|
98
98
|
}
|
|
99
99
|
catch (error) {
|
|
@@ -127,21 +127,21 @@ function generateTypeDefsAndResolvers() {
|
|
|
127
127
|
${scalarStr}
|
|
128
128
|
|
|
129
129
|
type Query {
|
|
130
|
-
${querySchemes.join(
|
|
130
|
+
${querySchemes.join("\n")}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
type Mutation {
|
|
134
|
-
${mutationSchemes.join(
|
|
134
|
+
${mutationSchemes.join("\n")}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
type Subscription {
|
|
138
|
-
${subscriptionSchemes.join(
|
|
138
|
+
${subscriptionSchemes.join("\n")}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
${typeSchemes.join(
|
|
141
|
+
${typeSchemes.join("\n")}
|
|
142
142
|
`;
|
|
143
143
|
// 在生产环境中缓存结果
|
|
144
|
-
if (process.env.NODE_ENV ===
|
|
144
|
+
if (process.env.NODE_ENV === "production") {
|
|
145
145
|
cachedSchema = schemaStr;
|
|
146
146
|
cachedResolvers = resolvers;
|
|
147
147
|
}
|
|
@@ -156,22 +156,22 @@ const handler = (command) => {
|
|
|
156
156
|
${scalarStrV}
|
|
157
157
|
|
|
158
158
|
type Query {
|
|
159
|
-
${querySchemesV?.join(
|
|
159
|
+
${querySchemesV?.join("\n") || "_: Boolean"}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
type Mutation {
|
|
163
|
-
${mutationSchemesV?.join(
|
|
163
|
+
${mutationSchemesV?.join("\n") || "_: Boolean"}
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
type Subscription {
|
|
167
|
-
${subscriptionSchemesV?.join(
|
|
167
|
+
${subscriptionSchemesV?.join("\n") || "_: Boolean"}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
${typeSchemesV?.join(
|
|
170
|
+
${typeSchemesV?.join("\n") || ""}
|
|
171
171
|
`;
|
|
172
|
-
if (command ===
|
|
173
|
-
console.log(
|
|
174
|
-
console.log(
|
|
172
|
+
if (command === "dev") {
|
|
173
|
+
console.log("schemaStr", schemaStr);
|
|
174
|
+
console.log("resolvers", resolversV);
|
|
175
175
|
}
|
|
176
176
|
// graphql-http 不再内置 graphiql,需手动集成 playground 或 altair,以下为基础 handler
|
|
177
177
|
return (0, express_1.createHandler)({
|
|
@@ -7,21 +7,21 @@ const dayjs_1 = __importDefault(require("dayjs"));
|
|
|
7
7
|
const language_1 = require("graphql/language");
|
|
8
8
|
const graphql_1 = require("graphql");
|
|
9
9
|
const customScalarDate = new graphql_1.GraphQLScalarType({
|
|
10
|
-
name:
|
|
11
|
-
description:
|
|
10
|
+
name: "Date",
|
|
11
|
+
description: "Date custom scalar type",
|
|
12
12
|
parseValue: (value) => {
|
|
13
13
|
const date = (0, dayjs_1.default)(value);
|
|
14
14
|
if (!date.isValid()) {
|
|
15
|
-
throw new Error(
|
|
15
|
+
throw new Error("Invalid date format");
|
|
16
16
|
}
|
|
17
17
|
return date.valueOf(); // Ensure this returns a number
|
|
18
18
|
},
|
|
19
19
|
serialize: (value) => {
|
|
20
20
|
const date = (0, dayjs_1.default)(value);
|
|
21
21
|
if (!date.isValid()) {
|
|
22
|
-
throw new Error(
|
|
22
|
+
throw new Error("Invalid date format");
|
|
23
23
|
}
|
|
24
|
-
return date.format(
|
|
24
|
+
return date.format("YYYY-MM-DD HH:mm:ss:SSS"); // Ensure this returns a string
|
|
25
25
|
},
|
|
26
26
|
parseLiteral: (ast) => {
|
|
27
27
|
if (ast.kind === language_1.Kind.INT) {
|
|
@@ -30,7 +30,7 @@ const customScalarDate = new graphql_1.GraphQLScalarType({
|
|
|
30
30
|
else if (ast.kind === language_1.Kind.STRING) {
|
|
31
31
|
const date = (0, dayjs_1.default)(ast.value);
|
|
32
32
|
if (!date.isValid()) {
|
|
33
|
-
throw new Error(
|
|
33
|
+
throw new Error("Invalid date format");
|
|
34
34
|
}
|
|
35
35
|
return date.valueOf();
|
|
36
36
|
}
|
|
@@ -7,7 +7,7 @@ const CACHE_TTL = 5 * 60 * 1000; // 5分钟
|
|
|
7
7
|
const graphqlCacheMiddleware = (req, res, next) => {
|
|
8
8
|
const { query, variables } = req.body || {};
|
|
9
9
|
// 只缓存查询操作,不缓存变更操作
|
|
10
|
-
if (!query || query.trim().startsWith(
|
|
10
|
+
if (!query || query.trim().startsWith("mutation")) {
|
|
11
11
|
return next();
|
|
12
12
|
}
|
|
13
13
|
const cacheKey = JSON.stringify({ query, variables });
|
|
@@ -15,14 +15,14 @@ const graphqlCacheMiddleware = (req, res, next) => {
|
|
|
15
15
|
// 检查缓存
|
|
16
16
|
const cached = queryCache.get(cacheKey);
|
|
17
17
|
if (cached && now - cached.timestamp < CACHE_TTL) {
|
|
18
|
-
console.log(
|
|
18
|
+
console.log("🚀 GraphQL cache hit for:", `${query.substring(0, 50)}...`);
|
|
19
19
|
return res.json(cached.data);
|
|
20
20
|
}
|
|
21
21
|
// 拦截响应以存储缓存
|
|
22
22
|
const originalSend = res.send;
|
|
23
23
|
res.send = function (body) {
|
|
24
24
|
try {
|
|
25
|
-
const data = typeof body ===
|
|
25
|
+
const data = typeof body === "string" ? JSON.parse(body) : body;
|
|
26
26
|
// 只缓存成功的查询结果
|
|
27
27
|
if (!data.errors) {
|
|
28
28
|
queryCache.set(cacheKey, {
|
|
@@ -34,7 +34,7 @@ const graphqlCacheMiddleware = (req, res, next) => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
catch (error) {
|
|
37
|
-
console.warn(
|
|
37
|
+
console.warn("⚠️ GraphQL cache error:", error);
|
|
38
38
|
}
|
|
39
39
|
originalSend.call(this, body);
|
|
40
40
|
};
|
|
@@ -53,7 +53,7 @@ function cleanExpiredCache() {
|
|
|
53
53
|
// 清空缓存的函数
|
|
54
54
|
const clearGraphQLCache = () => {
|
|
55
55
|
queryCache.clear();
|
|
56
|
-
console.log(
|
|
56
|
+
console.log("🧹 GraphQL cache cleared");
|
|
57
57
|
};
|
|
58
58
|
exports.clearGraphQLCache = clearGraphQLCache;
|
|
59
59
|
// 获取缓存统计
|