@fecommunity/reactpress-toolkit 1.0.0-beta.1 → 1.0.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.
Files changed (130) hide show
  1. package/README.md +405 -0
  2. package/dist/Article.d.ts +121 -0
  3. package/dist/Article.js +189 -0
  4. package/dist/Auth.d.ts +30 -0
  5. package/dist/Auth.js +59 -0
  6. package/dist/Category.d.ts +49 -0
  7. package/dist/Category.js +85 -0
  8. package/dist/Comment.d.ts +58 -0
  9. package/dist/Comment.js +98 -0
  10. package/dist/File.d.ts +40 -0
  11. package/dist/File.js +72 -0
  12. package/dist/HttpClient.d.ts +41 -0
  13. package/dist/HttpClient.js +94 -0
  14. package/dist/Knowledge.d.ts +76 -0
  15. package/dist/Knowledge.js +124 -0
  16. package/dist/Page.d.ts +58 -0
  17. package/dist/Page.js +98 -0
  18. package/dist/Search.d.ts +30 -0
  19. package/dist/Search.js +59 -0
  20. package/dist/Setting.d.ts +22 -0
  21. package/dist/Setting.js +46 -0
  22. package/dist/Smtp.d.ts +31 -0
  23. package/dist/Smtp.js +59 -0
  24. package/dist/Tag.d.ts +58 -0
  25. package/dist/Tag.js +98 -0
  26. package/dist/User.d.ts +41 -0
  27. package/dist/User.js +73 -0
  28. package/dist/View.d.ts +49 -0
  29. package/dist/View.js +85 -0
  30. package/dist/api/ApiInstance.d.ts +39 -0
  31. package/dist/api/ApiInstance.js +46 -0
  32. package/dist/api/Article.d.ts +44 -29
  33. package/dist/api/Article.js +42 -31
  34. package/dist/api/ArticleRoute.d.ts +201 -0
  35. package/dist/api/ArticleRoute.js +12 -0
  36. package/dist/api/Auth.d.ts +11 -6
  37. package/dist/api/Auth.js +10 -8
  38. package/dist/api/AuthRoute.d.ts +44 -0
  39. package/dist/api/AuthRoute.js +12 -0
  40. package/dist/api/Category.d.ts +20 -13
  41. package/dist/api/Category.js +18 -15
  42. package/dist/api/CategoryRoute.d.ts +79 -0
  43. package/dist/api/CategoryRoute.js +12 -0
  44. package/dist/api/Comment.d.ts +22 -14
  45. package/dist/api/Comment.js +20 -16
  46. package/dist/api/CommentRoute.d.ts +95 -0
  47. package/dist/api/CommentRoute.js +12 -0
  48. package/dist/api/File.d.ts +16 -10
  49. package/dist/api/File.js +14 -12
  50. package/dist/api/FileRoute.d.ts +63 -0
  51. package/dist/api/FileRoute.js +12 -0
  52. package/dist/api/Knowledge.d.ts +29 -19
  53. package/dist/api/Knowledge.js +27 -22
  54. package/dist/api/KnowledgeRoute.d.ts +125 -0
  55. package/dist/api/KnowledgeRoute.js +12 -0
  56. package/dist/api/Page.d.ts +23 -15
  57. package/dist/api/Page.js +21 -17
  58. package/dist/api/PageRoute.d.ts +95 -0
  59. package/dist/api/PageRoute.js +12 -0
  60. package/dist/api/Search.d.ts +12 -7
  61. package/dist/api/Search.js +11 -9
  62. package/dist/api/SearchRoute.d.ts +46 -0
  63. package/dist/api/SearchRoute.js +12 -0
  64. package/dist/api/Setting.d.ts +10 -6
  65. package/dist/api/Setting.js +8 -8
  66. package/dist/api/SettingRoute.d.ts +31 -0
  67. package/dist/api/SettingRoute.js +12 -0
  68. package/dist/api/Smtp.d.ts +14 -9
  69. package/dist/api/Smtp.js +12 -11
  70. package/dist/api/SmtpRoute.d.ts +47 -0
  71. package/dist/api/SmtpRoute.js +12 -0
  72. package/dist/api/Tag.d.ts +22 -14
  73. package/dist/api/Tag.js +20 -16
  74. package/dist/api/TagRoute.d.ts +95 -0
  75. package/dist/api/TagRoute.js +12 -0
  76. package/dist/api/User.d.ts +15 -8
  77. package/dist/api/User.js +13 -13
  78. package/dist/api/UserRoute.d.ts +60 -0
  79. package/dist/api/UserRoute.js +12 -0
  80. package/dist/api/View.d.ts +19 -12
  81. package/dist/api/View.js +17 -14
  82. package/dist/api/ViewRoute.d.ts +77 -0
  83. package/dist/api/ViewRoute.js +12 -0
  84. package/dist/api/httpClient.d.ts +5 -5
  85. package/dist/api/httpClient.js +4 -2
  86. package/dist/api/index.d.ts +13 -18
  87. package/dist/api/index.js +28 -41
  88. package/dist/api/instance.d.ts +47 -0
  89. package/dist/api/instance.js +71 -0
  90. package/dist/data-contracts.d.ts +245 -0
  91. package/dist/data-contracts.js +12 -0
  92. package/dist/index.d.ts +5 -9
  93. package/dist/index.js +16 -21
  94. package/dist/types/index.d.ts +245 -1
  95. package/dist/types/index.js +10 -17
  96. package/dist/utils/common.d.ts +1 -3
  97. package/dist/utils/common.js +5 -31
  98. package/dist/utils/http.js +4 -6
  99. package/dist/utils/index.d.ts +33 -2
  100. package/dist/utils/index.js +57 -18
  101. package/package.json +11 -6
  102. package/demos/simple.ts +0 -65
  103. package/scripts/generate-api-types.js +0 -571
  104. package/scripts/generate-swagger.js +0 -47
  105. package/scripts/organize-api.js +0 -136
  106. package/src/api/Article.ts +0 -186
  107. package/src/api/Auth.ts +0 -54
  108. package/src/api/Category.ts +0 -82
  109. package/src/api/Comment.ts +0 -95
  110. package/src/api/File.ts +0 -69
  111. package/src/api/Knowledge.ts +0 -122
  112. package/src/api/Page.ts +0 -95
  113. package/src/api/Search.ts +0 -54
  114. package/src/api/Setting.ts +0 -43
  115. package/src/api/Smtp.ts +0 -56
  116. package/src/api/Tag.ts +0 -95
  117. package/src/api/User.ts +0 -72
  118. package/src/api/View.ts +0 -82
  119. package/src/api/api-instance.ts +0 -69
  120. package/src/api/httpClient.ts +0 -140
  121. package/src/api/index.ts +0 -25
  122. package/src/index.ts +0 -18
  123. package/src/types/data-contracts.ts +0 -198
  124. package/src/types/index.ts +0 -4
  125. package/src/utils/common.ts +0 -108
  126. package/src/utils/http.ts +0 -52
  127. package/src/utils/index.ts +0 -5
  128. package/test-final.js +0 -56
  129. package/test-import.js +0 -34
  130. package/tsconfig.json +0 -20
@@ -1 +1,245 @@
1
- export * from './data-contracts';
1
+ export interface IUser {
2
+ name: string;
3
+ password: string;
4
+ avatar: string;
5
+ email: string;
6
+ role: string;
7
+ status: string;
8
+ type: string;
9
+ /** @format date-time */
10
+ createAt: string;
11
+ /** @format date-time */
12
+ updateAt: string;
13
+ }
14
+ export interface ISetting {
15
+ id: string;
16
+ i18n: string;
17
+ globalSetting: string;
18
+ systemUrl: string;
19
+ systemTitle: string;
20
+ systemSubTitle: string;
21
+ systemLogo: string;
22
+ systemBg: string;
23
+ systemFavicon: string;
24
+ systemNoticeInfo: string;
25
+ systemFooterInfo: string;
26
+ adminSystemUrl: string;
27
+ baiduAnalyticsId: string;
28
+ googleAnalyticsId: string;
29
+ seoKeyword: string;
30
+ seoDesc: string;
31
+ oss: string;
32
+ smtpHost: string;
33
+ smtpPort: string;
34
+ smtpUser: string;
35
+ smtpPass: string;
36
+ smtpFromUser: string;
37
+ /** @format date-time */
38
+ createAt: string;
39
+ /** @format date-time */
40
+ updateAt: string;
41
+ }
42
+ export interface I_SMTP {
43
+ id: string;
44
+ from: string;
45
+ to: string;
46
+ subject: string;
47
+ text: string;
48
+ html: string;
49
+ /** @format date-time */
50
+ createAt: string;
51
+ }
52
+ export interface IFile {
53
+ id: string;
54
+ originalname: string;
55
+ filename: string;
56
+ type: string;
57
+ size: number;
58
+ url: string;
59
+ /** @format date-time */
60
+ createAt: string;
61
+ }
62
+ export interface ITag {
63
+ label: string;
64
+ value: string;
65
+ articles: string[];
66
+ /** @format date-time */
67
+ createAt: string;
68
+ /** @format date-time */
69
+ updateAt: string;
70
+ }
71
+ export interface ICategory {
72
+ id: string;
73
+ label: string;
74
+ value: string;
75
+ articles: string[];
76
+ /** @format date-time */
77
+ createAt: string;
78
+ /** @format date-time */
79
+ updateAt: string;
80
+ }
81
+ export interface IArticle {
82
+ id: string;
83
+ title: string;
84
+ cover: string;
85
+ summary: string;
86
+ content: string;
87
+ html: string;
88
+ toc: string;
89
+ category: ICategory;
90
+ tags: string[];
91
+ status: string;
92
+ views: number;
93
+ likes: number;
94
+ isRecommended: boolean;
95
+ password: string;
96
+ needPassword: boolean;
97
+ isCommentable: boolean;
98
+ /** @format date-time */
99
+ publishAt: string;
100
+ /** @format date-time */
101
+ createAt: string;
102
+ /** @format date-time */
103
+ updateAt: string;
104
+ }
105
+ export interface IKnowledge {
106
+ id: string;
107
+ parentId: string;
108
+ order: number;
109
+ title: string;
110
+ cover: string;
111
+ summary: string;
112
+ content: string;
113
+ html: string;
114
+ toc: string;
115
+ status: string;
116
+ views: number;
117
+ likes: number;
118
+ isCommentable: boolean;
119
+ /** @format date-time */
120
+ publishAt: string;
121
+ /** @format date-time */
122
+ createAt: string;
123
+ /** @format date-time */
124
+ updateAt: string;
125
+ }
126
+ export interface IComment {
127
+ id: string;
128
+ name: string;
129
+ email: string;
130
+ avatar: string;
131
+ content: string;
132
+ html: string;
133
+ pass: boolean;
134
+ userAgent: string;
135
+ hostId: string;
136
+ url: string;
137
+ parentCommentId: string;
138
+ replyUserName: string;
139
+ replyUserEmail: string;
140
+ /** @format date-time */
141
+ createAt: string;
142
+ /** @format date-time */
143
+ updateAt: string;
144
+ }
145
+ export interface IPage {
146
+ id: string;
147
+ cover: string;
148
+ name: string;
149
+ path: string;
150
+ order: number;
151
+ content: string;
152
+ html: string;
153
+ toc: string;
154
+ status: string;
155
+ /** @format date-time */
156
+ publishAt: string;
157
+ views: number;
158
+ /** @format date-time */
159
+ createAt: string;
160
+ /** @format date-time */
161
+ updateAt: string;
162
+ }
163
+ export interface IView {
164
+ ip: string;
165
+ userAgent: string;
166
+ url: string;
167
+ count: number;
168
+ address: string;
169
+ browser: string;
170
+ engine: string;
171
+ os: string;
172
+ device: string;
173
+ /** @format date-time */
174
+ createAt: string;
175
+ /** @format date-time */
176
+ updateAt: string;
177
+ }
178
+ export declare type IUserControllerFindAllData = IUser[];
179
+ export declare type IUserControllerRegisterData = IUser[];
180
+ export declare type IUserControllerUpdateData = IUser[];
181
+ export declare type IUserControllerUpdatePasswordData = IUser[];
182
+ export declare type IAuthControllerLoginData = any;
183
+ export declare type IAuthControllerCreateBookData = any;
184
+ export declare type IAuthControllerLoginWithGithubData = any;
185
+ export declare type ISettingControllerUpdateData = ISetting[];
186
+ export declare type ISettingControllerFindAllData = any;
187
+ export declare type ISmtpControllerCreateData = I_SMTP[];
188
+ export declare type ISmtpControllerFindAllData = any;
189
+ export declare type ISmtpControllerDeleteByIdData = any;
190
+ export declare type IFileControllerUploadFileData = IFile[];
191
+ export declare type IFileControllerFindAllData = any;
192
+ export declare type IFileControllerFindByIdData = any;
193
+ export declare type IFileControllerDeleteByIdData = any;
194
+ export declare type ITagControllerCreateData = ITag[];
195
+ export declare type ITagControllerFindAllData = any;
196
+ export declare type ITagControllerFindByIdData = any;
197
+ export declare type ITagControllerUpdateByIdData = any;
198
+ export declare type ITagControllerDeleteByIdData = any;
199
+ export declare type ITagControllerGetArticleByIdData = any;
200
+ export declare type IArticleControllerCreateData = IArticle[];
201
+ export declare type IArticleControllerFindAllData = any;
202
+ export declare type IArticleControllerFindArticlesByCategoryData = any;
203
+ export declare type IArticleControllerFindArticlesByTagData = any;
204
+ export declare type IArticleControllerGetRecommendArticlesData = any;
205
+ export declare type IArticleControllerGetArchivesData = any;
206
+ export declare type IArticleControllerRecommendData = any;
207
+ export declare type IArticleControllerFindByIdData = any;
208
+ export declare type IArticleControllerUpdateByIdData = any;
209
+ export declare type IArticleControllerDeleteByIdData = any;
210
+ export declare type IArticleControllerCheckPasswordData = any;
211
+ export declare type IArticleControllerUpdateViewsByIdData = any;
212
+ export declare type IArticleControllerUpdateLikesByIdData = any;
213
+ export declare type ICategoryControllerCreateData = ICategory[];
214
+ export declare type ICategoryControllerFindAllData = any;
215
+ export declare type ICategoryControllerFindByIdData = any;
216
+ export declare type ICategoryControllerUpdateByIdData = any;
217
+ export declare type ICategoryControllerDeleteByIdData = any;
218
+ export declare type IKnowledgeControllerCreateBookData = IKnowledge[];
219
+ export declare type IKnowledgeControllerCreateChapterData = IKnowledge[];
220
+ export declare type IKnowledgeControllerDeleteByIdData = any;
221
+ export declare type IKnowledgeControllerUpdateByIdData = any;
222
+ export declare type IKnowledgeControllerFindByIdData = any;
223
+ export declare type IKnowledgeControllerFindAllData = any;
224
+ export declare type IKnowledgeControllerUpdateViewsByIdData = any;
225
+ export declare type IKnowledgeControllerUpdateLikesByIdData = any;
226
+ export declare type ICommentControllerCreateData = IComment[];
227
+ export declare type ICommentControllerFindAllData = any;
228
+ export declare type ICommentControllerFindByIdData = any;
229
+ export declare type ICommentControllerUpdateByIdData = any;
230
+ export declare type ICommentControllerDeleteByIdData = any;
231
+ export declare type ICommentControllerGetArticleCommentsData = any;
232
+ export declare type IPageControllerCreateData = IPage[];
233
+ export declare type IPageControllerFindAllData = any;
234
+ export declare type IPageControllerFindByIdData = any;
235
+ export declare type IPageControllerUpdateByIdData = any;
236
+ export declare type IPageControllerDeleteByIdData = any;
237
+ export declare type IPageControllerUpdateViewsByIdData = any;
238
+ export declare type IViewControllerCreateData = IView[];
239
+ export declare type IViewControllerFindAllData = any;
240
+ export declare type IViewControllerFindByUrlData = any;
241
+ export declare type IViewControllerFindByIdData = any;
242
+ export declare type IViewControllerDeleteByIdData = any;
243
+ export declare type ISearchControllerSearchArticleData = any;
244
+ export declare type ISearchControllerFindAllData = any;
245
+ export declare type ISearchControllerDeleteByIdData = any;
@@ -1,19 +1,12 @@
1
1
  "use strict";
2
- // 类型定义索引
3
- // 自动生成,请勿手动修改
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
- };
2
+ /* eslint-disable */
3
+ /* tslint:disable */
4
+ /*
5
+ * ---------------------------------------------------------------
6
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7
+ * ## ##
8
+ * ## AUTHOR: acacode ##
9
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10
+ * ---------------------------------------------------------------
11
+ */
18
12
  Object.defineProperty(exports, "__esModule", { value: true });
19
- __exportStar(require("./data-contracts"), exports);
@@ -1,8 +1,5 @@
1
1
  export declare const formatDate: (date: Date, format?: string) => string;
2
2
  export declare const deepClone: <T>(obj: T) => T;
3
- export declare const debounce: <T extends (...args: any[]) => any>(func: T, wait: number) => (...args: Parameters<T>) => void;
4
- export declare const throttle: <T extends (...args: any[]) => any>(func: T, limit: number) => (...args: Parameters<T>) => void;
5
- export declare const isApiError: (error: any) => error is ApiError;
6
3
  export interface ApiResponse<T = any> {
7
4
  code: number;
8
5
  message: string;
@@ -20,4 +17,5 @@ export declare class ApiError extends Error {
20
17
  code: number;
21
18
  details?: any;
22
19
  constructor(code: number, message: string, details?: any);
20
+ static isInstance(error: any): error is ApiError;
23
21
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // 通用工具函数
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ApiError = exports.isApiError = exports.throttle = exports.debounce = exports.deepClone = exports.formatDate = void 0;
4
+ exports.ApiError = exports.deepClone = exports.formatDate = void 0;
5
5
  // 日期格式化
6
6
  const formatDate = (date, format = 'YYYY-MM-DD') => {
7
7
  const year = date.getFullYear();
@@ -36,36 +36,6 @@ const deepClone = (obj) => {
36
36
  return obj;
37
37
  };
38
38
  exports.deepClone = deepClone;
39
- // 防抖函数
40
- const debounce = (func, wait) => {
41
- let timeout = null;
42
- return (...args) => {
43
- if (timeout) {
44
- clearTimeout(timeout);
45
- }
46
- timeout = setTimeout(() => {
47
- func(...args);
48
- }, wait);
49
- };
50
- };
51
- exports.debounce = debounce;
52
- // 节流函数
53
- const throttle = (func, limit) => {
54
- let inThrottle = false;
55
- return (...args) => {
56
- if (!inThrottle) {
57
- func(...args);
58
- inThrottle = true;
59
- setTimeout(() => (inThrottle = false), limit);
60
- }
61
- };
62
- };
63
- exports.throttle = throttle;
64
- // 检查是否为ApiError
65
- const isApiError = (error) => {
66
- return error instanceof ApiError || (error && typeof error === 'object' && 'code' in error && 'message' in error);
67
- };
68
- exports.isApiError = isApiError;
69
39
  // 错误处理
70
40
  class ApiError extends Error {
71
41
  constructor(code, message, details) {
@@ -74,5 +44,9 @@ class ApiError extends Error {
74
44
  this.details = details;
75
45
  this.name = 'ApiError';
76
46
  }
47
+ // 检查是否为 ApiError 实例
48
+ static isInstance(error) {
49
+ return error instanceof ApiError;
50
+ }
77
51
  }
78
52
  exports.ApiError = ApiError;
@@ -14,10 +14,10 @@ const createHttpClient = (baseURL) => {
14
14
  'Content-Type': 'application/json',
15
15
  },
16
16
  });
17
- // 请求拦截器
17
+ // 请求拦截器 - 修复类型错误
18
18
  instance.interceptors.request.use((config) => {
19
19
  // 添加认证令牌
20
- const token = typeof window !== 'undefined' ? localStorage.getItem('auth_token') : null;
20
+ const token = localStorage.getItem('auth_token');
21
21
  if (token && config.headers) {
22
22
  config.headers.Authorization = `Bearer ${token}`;
23
23
  }
@@ -32,10 +32,8 @@ const createHttpClient = (baseURL) => {
32
32
  // 统一错误处理
33
33
  if (error.response?.status === 401) {
34
34
  // 未授权处理
35
- if (typeof window !== 'undefined') {
36
- localStorage.removeItem('auth_token');
37
- window.location.href = '/login';
38
- }
35
+ localStorage.removeItem('auth_token');
36
+ window.location.href = '/login';
39
37
  }
40
38
  return Promise.reject(error.response?.data || error);
41
39
  });
@@ -1,2 +1,33 @@
1
- export * from './http';
2
- export * from './common';
1
+ /**
2
+ * Format a date to the specified format
3
+ * @param date - Date to format
4
+ * @param format - Format string (default: YYYY-MM-DD)
5
+ * @returns Formatted date string
6
+ */
7
+ export declare function formatDate(date: Date, format?: string): string;
8
+ /**
9
+ * Deep clone an object
10
+ * @param obj - Object to clone
11
+ * @returns Cloned object
12
+ */
13
+ export declare function deepClone<T>(obj: T): T;
14
+ /**
15
+ * Check if an error is an API error
16
+ * @param error - Error to check
17
+ * @returns True if it's an API error
18
+ */
19
+ export declare function isApiError(error: any): boolean;
20
+ /**
21
+ * API Error class
22
+ */
23
+ export declare class ApiError extends Error {
24
+ code: number;
25
+ details: any;
26
+ constructor(message: string, code?: number, details?: any);
27
+ /**
28
+ * Check if an object is an instance of ApiError
29
+ * @param error - Error to check
30
+ * @returns True if it's an ApiError instance
31
+ */
32
+ static isInstance(error: any): error is ApiError;
33
+ }
@@ -1,20 +1,59 @@
1
1
  "use strict";
2
- // 工具函数索引
3
- // 自动生成,请勿手动修改
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
- };
2
+ // Utility functions for ReactPress Toolkit
18
3
  Object.defineProperty(exports, "__esModule", { value: true });
19
- __exportStar(require("./http"), exports);
20
- __exportStar(require("./common"), exports);
4
+ exports.ApiError = exports.isApiError = exports.deepClone = exports.formatDate = void 0;
5
+ /**
6
+ * Format a date to the specified format
7
+ * @param date - Date to format
8
+ * @param format - Format string (default: YYYY-MM-DD)
9
+ * @returns Formatted date string
10
+ */
11
+ function formatDate(date, format = 'YYYY-MM-DD') {
12
+ const year = date.getFullYear();
13
+ const month = String(date.getMonth() + 1).padStart(2, '0');
14
+ const day = String(date.getDate()).padStart(2, '0');
15
+ return format
16
+ .replace('YYYY', String(year))
17
+ .replace('MM', month)
18
+ .replace('DD', day);
19
+ }
20
+ exports.formatDate = formatDate;
21
+ /**
22
+ * Deep clone an object
23
+ * @param obj - Object to clone
24
+ * @returns Cloned object
25
+ */
26
+ function deepClone(obj) {
27
+ return JSON.parse(JSON.stringify(obj));
28
+ }
29
+ exports.deepClone = deepClone;
30
+ /**
31
+ * Check if an error is an API error
32
+ * @param error - Error to check
33
+ * @returns True if it's an API error
34
+ */
35
+ function isApiError(error) {
36
+ return error && error.response && error.response.data;
37
+ }
38
+ exports.isApiError = isApiError;
39
+ /**
40
+ * API Error class
41
+ */
42
+ class ApiError extends Error {
43
+ constructor(message, code = 500, details = null) {
44
+ super(message);
45
+ this.name = 'ApiError';
46
+ this.code = code;
47
+ this.details = details;
48
+ }
49
+ /**
50
+ * Check if an object is an instance of ApiError
51
+ * @param error - Error to check
52
+ * @returns True if it's an ApiError instance
53
+ */
54
+ static isInstance(error) {
55
+ return error instanceof ApiError ||
56
+ (error && error.name === 'ApiError' && error.code !== undefined);
57
+ }
58
+ }
59
+ exports.ApiError = ApiError;
package/package.json CHANGED
@@ -1,19 +1,24 @@
1
1
  {
2
2
  "name": "@fecommunity/reactpress-toolkit",
3
- "version": "1.0.0-beta.1",
4
- "main": "index.js",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "files": [
6
+ "dist"
7
+ ],
5
8
  "keywords": [],
6
9
  "author": "",
7
10
  "license": "ISC",
8
11
  "description": "",
9
12
  "dependencies": {
13
+ "axios": "^1.12.2",
10
14
  "lodash": "^4.17.21",
11
- "swagger-typescript-api": "^12.0.4",
12
- "axios": "^1.12.2"
15
+ "swagger-typescript-api": "^12.0.4"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^24.5.2"
13
19
  },
14
20
  "scripts": {
15
21
  "generate": "node scripts/generate-swagger.js",
16
- "build": "tsc",
17
- "test": "node test-toolkit.js"
22
+ "build": "tsc"
18
23
  }
19
24
  }
package/demos/simple.ts DELETED
@@ -1,65 +0,0 @@
1
- // src/services/articleService.ts
2
- import api, { types, utils } from '@/api';
3
-
4
- // 文章服务层
5
- export class ArticleService {
6
- // 获取所有文章
7
- static async getAllArticles() {
8
- try {
9
- const articles = await api.article.findAll();
10
-
11
- // 格式化数据
12
- return articles.map(article => ({
13
- ...article,
14
- formattedDate: utils.formatDate(new Date(article.createdAt || Date.now())),
15
- }));
16
- } catch (error) {
17
- throw this.handleError(error, '获取文章列表失败');
18
- }
19
- }
20
-
21
- // 获取单篇文章
22
- static async getArticleById(id: string) {
23
- try {
24
- return await api.article.findById(id);
25
- } catch (error) {
26
- throw this.handleError(error, '获取文章失败');
27
- }
28
- }
29
-
30
- // 创建文章
31
- static async createArticle(articleData: Partial<types.IArticle>) {
32
- try {
33
- return await api.article.create(articleData);
34
- } catch (error) {
35
- throw this.handleError(error, '创建文章失败');
36
- }
37
- }
38
-
39
- // 更新文章
40
- static async updateArticle(id: string, updates: Partial<types.IArticle>) {
41
- try {
42
- return await api.article.updateById(id, updates);
43
- } catch (error) {
44
- throw this.handleError(error, '更新文章失败');
45
- }
46
- }
47
-
48
- // 删除文章
49
- static async deleteArticle(id: string) {
50
- try {
51
- return await api.article.deleteById(id);
52
- } catch (error) {
53
- throw this.handleError(error, '删除文章失败');
54
- }
55
- }
56
-
57
- // 统一错误处理
58
- private static handleError(error: unknown, defaultMessage: string) {
59
- if (utils.ApiError.isInstance(error)) {
60
- return error;
61
- }
62
-
63
- return new utils.ApiError(500, defaultMessage, error);
64
- }
65
- }