@hzab/data-model 2.0.3-alpha.0 → 2.1.0-alpha.0

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/package.json CHANGED
@@ -1,63 +1,76 @@
1
1
  {
2
2
  "name": "@hzab/data-model",
3
- "version": "2.0.3-alpha.0",
4
- "description": "data model",
5
- "main": "src",
6
- "scripts": {
7
- "dev": "npm run prepare && webpack serve -c ./config/webpack.config.js --env local",
8
- "build": "webpack -c ./config/webpack.config.js --env production",
9
- "version:alpha": "npm version prerelease --preid=alpha",
10
- "publish:alpha": "npm publish --tag alpha",
11
- "version:beta": "npm version prerelease --preid=beta",
12
- "publish:beta": "npm publish --tag beta",
13
- "version:patch": "npm version patch",
14
- "version:minior": "npm version minor",
15
- "version:major": "npm version major",
16
- "publish:stable": "npm publish --access public",
17
- "prepare": "husky install",
18
- "docs": "typedoc"
3
+ "version": "2.1.0-alpha.0",
4
+ "private": false,
5
+ "description": "数据模型 2.1:再导出 core + useDataModel;后继 API 与旧写法双轨",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "author": "CaiYansong",
9
+ "publishConfig": {
10
+ "access": "public"
19
11
  },
20
12
  "files": [
13
+ "dist",
21
14
  "src",
15
+ "README.md",
16
+ "LICENSE",
22
17
  "CHANGELOG.md"
23
18
  ],
24
- "keywords": [],
25
- "author": "CaiYansong",
26
- "license": "ISC",
27
- "devDependencies": {
28
- "@hzab/permissions": "^0.1.1",
29
- "@hzab/webpack-config": "^0.7.1",
30
- "@types/react": "^17.0.62",
31
- "@types/react-dom": "^17.0.20",
32
- "antd": "4.24.16",
33
- "axios": "1.13.6",
34
- "eslint": "^8.30.0",
35
- "js-cookie": "^3.0.5",
36
- "less": "^4.1.3",
37
- "mobx": "^6.7.0",
38
- "mobx-react": "^7.6.0",
39
- "react": "^17.0.2",
40
- "react-dom": "^17.0.2",
41
- "react-router-dom": "^6.14.1",
42
- "typedoc": "^0.24.8",
43
- "typescript": "^4.9.4"
19
+ "main": "./dist/index.cjs",
20
+ "module": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.cjs"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "sideEffects": [
31
+ "./dist/index.js",
32
+ "./dist/index.cjs"
33
+ ],
34
+ "dependencies": {
35
+ "axios": "^1.18.1",
36
+ "nanoid": "^3.3.15"
37
+ },
38
+ "engines": {
39
+ "node": ">=24"
44
40
  },
45
41
  "peerDependencies": {
46
- "axios": ">=1.6.2",
47
- "js-cookie": ">=3.0.5"
42
+ "js-cookie": "^3.0.5",
43
+ "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
48
44
  },
49
- "dependencies": {
50
- "dayjs": "^1.11.7",
51
- "axios": ">=1.6.2",
52
- "js-cookie": ">=3.0.5",
53
- "nanoid": "^3.3.7"
45
+ "peerDependenciesMeta": {
46
+ "js-cookie": {
47
+ "optional": true
48
+ }
54
49
  },
55
- "directories": {
56
- "lib": "lib"
50
+ "devDependencies": {
51
+ "@testing-library/react": "^16.3.3",
52
+ "@types/lodash-es": "^4.17.12",
53
+ "@types/node": "^24.0.0",
54
+ "@types/react": "^19.0.0",
55
+ "happy-dom": "^20.11.12",
56
+ "lodash-es": "^4.18.1",
57
+ "prettier": "^3.0.0",
58
+ "react": "^19.0.0",
59
+ "react-dom": "^19.2.8",
60
+ "tsup": "^8.5.1",
61
+ "typescript": "^5.9.3",
62
+ "vite": "^8.0.0",
63
+ "vitest": "^4.1.10",
64
+ "@hzab/data-model-core": "^2.1.0-alpha.0",
65
+ "@hzab/eslint-config": "^0.0.0",
66
+ "@hzab/vite-config": "^0.0.2-alpha.0",
67
+ "@hzab/typescript-config": "^0.0.0"
57
68
  },
58
- "lint-staged": {
59
- "**.{js,jsx,ts,tsx,css,scss,less,json,html}": [
60
- "prettier --write"
61
- ]
69
+ "scripts": {
70
+ "build": "tsup",
71
+ "typecheck": "tsc --noEmit -p tsconfig.json --rootDir .",
72
+ "test": "vitest run",
73
+ "lint": "eslint src --max-warnings=0",
74
+ "format:check": "prettier --check src"
62
75
  }
63
- }
76
+ }
package/src/hooks.ts CHANGED
@@ -1,38 +1,42 @@
1
- import { useMemo, useRef } from "react";
2
- import { merge } from "lodash";
3
- import DataModel, { DataModelOptions } from "./data-model";
4
-
5
- /**
6
- * useDataModel 选项接口
7
- */
8
- export interface UseDataModelOptions<T = any> {
9
- /** 动态数据监听的目标 */
10
- effectTargets?: any[];
11
- /** 动态的 params 数据,包含了 query */
12
- effectParams?: Partial<DataModelOptions<T>>;
13
- /** 动态的 query 数据 */
14
- effectQuery?: DataModelOptions<T>["query"];
15
- }
16
-
17
- /**
18
- * 解决 hooks 重复实例化导致 query 丢失的问题
19
- * @param {Object} initParams 初始参数
20
- * @param {Object} opt
21
- * @param {Object} opt.effectTargets 动态数据监听的目标
22
- * @param {Object} opt.effectParams 动态的 params 数据,包含了 query
23
- * @param {Object} opt.effectQuery 动态的 query 数据
24
- * @returns DataModel 实例
25
- */
26
- export const useDataModel = function <T = any>(initParams: DataModelOptions<T> = {}, opt: UseDataModelOptions<T> = {}) {
27
- const model = useRef<DataModel<T>>(new DataModel(initParams));
28
- return useMemo(() => {
29
- const { effectParams, effectQuery } = opt || {};
30
- if (effectParams) {
31
- merge(model.current, effectParams);
32
- }
33
- if (effectQuery) {
34
- merge(model.current.query, effectQuery);
35
- }
36
- return model.current;
37
- }, opt.effectTargets || []);
38
- };
1
+ import { useMemo, useRef } from "react";
2
+ import { merge } from "lodash-es";
3
+ import DataModel from "@hzab/data-model-core";
4
+ import type { DataModelOptions } from "@hzab/data-model-core";
5
+
6
+ /**
7
+ * useDataModel 选项接口
8
+ */
9
+ export interface UseDataModelOptions<T = any> {
10
+ /** 动态数据监听的目标 */
11
+ effectTargets?: any[];
12
+ /** 动态的 params 数据,包含了 query */
13
+ effectParams?: Partial<DataModelOptions<T>>;
14
+ /** 动态的 query 数据 */
15
+ effectQuery?: DataModelOptions<T>["query"];
16
+ }
17
+
18
+ /**
19
+ * 解决 hooks 重复实例化导致 query 丢失的问题
20
+ * @param {Object} initParams 初始参数
21
+ * @param {Object} opt
22
+ * @param {Object} opt.effectTargets 动态数据监听的目标
23
+ * @param {Object} opt.effectParams 动态的 params 数据,包含了 query
24
+ * @param {Object} opt.effectQuery 动态的 query 数据
25
+ * @returns DataModel 实例
26
+ */
27
+ export const useDataModel = function <T = any>(
28
+ initParams: DataModelOptions<T> = {},
29
+ opt: UseDataModelOptions<T> = {},
30
+ ) {
31
+ const model = useRef<DataModel<T>>(new DataModel<T>(initParams));
32
+ return useMemo(() => {
33
+ const { effectParams, effectQuery } = opt || {};
34
+ if (effectParams) {
35
+ merge(model.current, effectParams);
36
+ }
37
+ if (effectQuery) {
38
+ merge(model.current.query, effectQuery);
39
+ }
40
+ return model.current;
41
+ }, opt.effectTargets || []);
42
+ };
package/src/index.ts CHANGED
@@ -1,11 +1,14 @@
1
- import axios from "./axios";
2
- import DataModel from "./data-model";
3
-
4
- export * from "./axios";
5
- export * from "./data-model";
6
- export * from "./hooks";
7
- export * from "./type";
8
-
9
- export { axios, DataModel };
10
-
11
- export default DataModel;
1
+ /**
2
+ * 数据模型 2.1:再导出 `@hzab/data-model-core`(打进 dist,不单独发布),
3
+ * 并提供 `useDataModel`。后继 API 与旧写法双轨。
4
+ *
5
+ * 老页面 `import { useDataModel, DataModel, axios } from "@hzab/data-model"` 仍可用。
6
+ * 不要安装 `@hzab/data-model-core`(private,已被打进本包 dist)。
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+
11
+ export * from "@hzab/data-model-core";
12
+ export { useDataModel } from "./hooks";
13
+ export type { UseDataModelOptions } from "./hooks";
14
+ export { default } from "@hzab/data-model-core";