chanjs 1.2.2 → 1.2.4

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/core/helper.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import knex from 'knex';
2
+ import merge from 'deepmerge';
2
3
 
3
4
  /**
4
5
  * @description 实例化一个类,并将该类的所有方法绑定到一个新的对象上。
@@ -97,4 +98,8 @@ export const zodValidator = (schemas) => (req, res, next) => {
97
98
  req[key] = result.data;
98
99
  }
99
100
  next();
100
- };
101
+ };
102
+
103
+
104
+ // 重新导出 deepmerge 的命名导出
105
+ export { default as merge } from 'deepmerge';
@@ -0,0 +1,27 @@
1
+ export default class Controller {
2
+ constructor() {
3
+ }
4
+
5
+ parseJsonFields(obj) {
6
+ const result = {};
7
+ for (const key in obj) {
8
+ if (!obj.hasOwnProperty(key)) continue;
9
+ const value = obj[key];
10
+ // 如果是字符串,并且看起来像 JSON(以 { 或 [ 开头)
11
+ if (typeof value === 'string' && (value.startsWith('{') || value.startsWith('['))) {
12
+ try {
13
+ result[key] = JSON.parse(value);
14
+ } catch (e) {
15
+ console.warn(`JSON parse failed for field: ${key}`, e);
16
+ result[key] = value; // 保留原始值
17
+ }
18
+ } else {
19
+ result[key] = value;
20
+ }
21
+ }
22
+
23
+ return result;
24
+ }
25
+
26
+
27
+ }
package/index.js CHANGED
@@ -5,6 +5,7 @@ import cors from "cors";
5
5
  import { pathToFileURL } from 'url'; // 新增顶部导入
6
6
  import config from "./core/config.js";
7
7
  import * as helper from "./core/helper.js";
8
+ import Controller from "./core/lib/controller.js";
8
9
  import Service from "./core/lib/service.js";
9
10
  import Cache from './core/lib/cache.js';
10
11
  import Task from "./core/lib/task.js";
@@ -18,6 +19,8 @@ class Chan {
18
19
  static modules = {};
19
20
  static plugins = {};
20
21
  static config = config;
22
+ static Controller = Controller;
23
+ static Service = Service;
21
24
  static Cache = Cache;
22
25
  static Task = Task;
23
26
  constructor() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chanjs",
4
- "version": "1.2.2",
4
+ "version": "1.2.4",
5
5
  "description": "chanjs基于express5 纯js研发的轻量级mvc框架。",
6
6
  "main": "index.js",
7
7
  "module": "index.js",
@@ -29,6 +29,7 @@
29
29
  "knex": "^3.1.0",
30
30
  "morgan": "^1.10.0",
31
31
  "mysql2": "^3.14.1",
32
- "schedule": "^0.5.0"
32
+ "schedule": "^0.5.0",
33
+ "deepmerge": "^4.3.1"
33
34
  }
34
35
  }